using Yw.DAL.SQLite;
|
|
namespace HStation.DAL.SQLite
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public partial class AssetsPumpPartMain : BaseDAL_Sorter<Entity.AssetsPumpPartMain>, IAssetsPumpPartMain
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public override ConnectionConfig ConnectionConfig
|
{
|
get { return Assets.ConfigHelper.SQLiteConnectionConfig; }
|
}
|
|
//插入拓展
|
public long InsertsEx(Entity.AssetsPumpPartMain part, List<Entity.AssetsPumpPropContent> AssetsPumpPropContents, Entity.AssetsPumpMainAndPartMapping partmap)
|
{
|
if (part == null)
|
{
|
return default;
|
}
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
try
|
{
|
db.BeginTran();
|
var result = db.Insertable(part).ExecuteReturnSnowflakeId();
|
if (result < 0)
|
{
|
db.RollbackTran();
|
return default;
|
}
|
else
|
{
|
if (partmap != null)
|
{
|
partmap.PartID = result;
|
var mainandpartmap = db.Insertable(partmap).ExecuteReturnSnowflakeId();
|
if (mainandpartmap < 0)
|
{
|
db.RollbackTran();
|
return default;
|
}
|
else
|
{
|
if (AssetsPumpPropContents != null)
|
{
|
foreach (var item in AssetsPumpPropContents)
|
{
|
item.PartID = result;
|
}
|
var content = db.Insertable(AssetsPumpPropContents).ExecuteReturnSnowflakeId();
|
if (content < 0)
|
{
|
db.RollbackTran();
|
return default;
|
}
|
}
|
}
|
}
|
}
|
|
db.CommitTran();
|
return result;
|
}
|
catch (Exception ex)
|
{
|
db.RollbackTran();
|
throw;
|
}
|
}
|
}
|
|
//编辑拓展
|
public bool UpdateEx(Entity.AssetsPumpPartMain part, List<Entity.AssetsPumpPropContent> AssetsPumpPropContents)
|
{
|
if (part == null)
|
{
|
return default;
|
}
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
try
|
{
|
db.BeginTran();
|
var result = db.Updateable(part).ExecuteCommandHasChange();
|
if (!result)
|
{
|
db.RollbackTran();
|
return default;
|
}
|
else
|
{
|
if (AssetsPumpPropContents != null)
|
{
|
bool iscountiue = false;
|
foreach (var item in AssetsPumpPropContents)
|
{
|
// 查询数据库中是否存在相应的记录
|
var isHave = db.Queryable<Entity.AssetsPumpPropContent>()
|
.Any(x => x.ID == item.ID);
|
if (isHave)
|
{
|
// 更新记录
|
var updateResult = db.Updateable(item)
|
.Where(x => x.ID == item.ID)
|
.ExecuteCommandHasChange();
|
iscountiue = updateResult;
|
}
|
else
|
{
|
// 插入新记录
|
var insertResult = db.Insertable(item).ExecuteReturnEntity();
|
}
|
}
|
// var propresult = db.Updateable(AssetsPumpPropContents).ExecuteCommandHasChange();
|
if (!iscountiue)
|
{
|
db.RollbackTran();
|
return default;
|
}
|
}
|
}
|
db.CommitTran();
|
return result;
|
}
|
catch (Exception ex)
|
{
|
db.RollbackTran();
|
throw;
|
}
|
}
|
}
|
|
//删除拓展 (删除产品表及属性表)
|
public bool DeleteEx(Entity.AssetsPumpPartMain part, List<Entity.AssetsPumpPropContent> AssetsPumpPropContents)
|
{
|
if (part == null)
|
{
|
return default;
|
}
|
using (var db = new SqlSugarClient(ConnectionConfig))
|
{
|
try
|
{
|
db.BeginTran();
|
var result = db.Deleteable(part).ExecuteCommand() > 0;
|
if (!result)
|
{
|
db.RollbackTran();
|
return default;
|
}
|
else
|
{
|
if (AssetsPumpPropContents != null)
|
{
|
var propresult = db.Deleteable(AssetsPumpPropContents).ExecuteCommand() > 0;
|
if (!propresult)
|
{
|
db.RollbackTran();
|
return default;
|
}
|
}
|
}
|
db.CommitTran();
|
return result;
|
}
|
catch (Exception ex)
|
{
|
db.RollbackTran();
|
throw;
|
}
|
}
|
}
|
}
|
}
|