using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace IStation.DAL
{
///
/// Epanet文件
///
public partial class EpanetFile : CorpTraceDAL
{
///
///
///
public override ConnectionConfig ConnectionConfig
{
get { return ConfigHelper.DefaultConnectionConfig; }
}
///
/// 通过 BelongType 和 BelongID 获取
///
public List GetByBelongTypeAndBelongID(long CorpID, string BelongType, long BelongID)
{
using (var db = new SqlSugarClient(ConnectionConfig))
{
return db.Queryable()
.Where(x => x.CorpID == CorpID && x.BelongType == BelongType && x.BelongID == BelongID).ToList();
}
}
///
/// 更新存储编码
///
public bool UpdateStorageCode(long CorpID, long ID, string StorageCode, long UpdateUserID, DateTime UpdateTime)
{
using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
{
return db.Updateable()
.SetColumns(x => x.StorageCode == StorageCode)
.SetColumns(x => x.UpdateUserID == UpdateUserID)
.SetColumns(x => x.UpdateTime == UpdateTime)
.Where(x => x.CorpID == CorpID && x.ID == ID)
.ExecuteCommand() > 0;
}
}
///
/// 更新设置
///
public bool UpdateSettings(long CorpID, long ID, string Settings, long UpdateUserID, DateTime UpdateTime)
{
using (SqlSugarClient db = new SqlSugarClient(ConnectionConfig))
{
return db.Updateable()
.SetColumns(x => x.Settings == Settings)
.SetColumns(x => x.UpdateUserID == UpdateUserID)
.SetColumns(x => x.UpdateTime == UpdateTime)
.Where(x => x.CorpID == CorpID && x.ID == ID)
.ExecuteCommand() > 0;
}
}
///
/// 设置工作文件
///
public bool SetWorking(long CorpID, string BelongType, long BelongID, long ID, long UpdateUserID, DateTime UpdateTime)
{
using (var db = new SqlSugarClient(ConnectionConfig))
{
try
{
db.BeginTran();
var bol = db.Updateable()
.SetColumns(x => x.IsWorking == true)
.SetColumns(x => x.UpdateUserID == UpdateUserID)
.SetColumns(x => x.UpdateTime == UpdateTime)
.Where(x => x.CorpID == CorpID && x.BelongType == BelongType && x.BelongID == BelongID && x.ID == ID).ExecuteCommand() > 0;
if (!bol)
{
db.RollbackTran();
return false;
}
db.Updateable()
.SetColumns(x => x.IsWorking == false)
.SetColumns(x => x.UpdateUserID == UpdateUserID)
.SetColumns(x => x.UpdateTime == UpdateTime)
.Where(x => x.CorpID == CorpID && x.BelongType==BelongType&&x.BelongID==BelongID && x.ID != ID).ExecuteCommand();
db.CommitTran();
return true;
}
catch
{
db.RollbackTran();
throw;
}
}
}
}
}