using Yw.DAL.PostgreSql; namespace HStation.DAL.PostgreSql { /// /// /// public partial class XhsProject : BaseDAL_Paras_Flags_TagName_TreeSorter, IXhsProject { /// /// /// public override ConnectionConfig ConnectionConfig { get { return Xhs.ConfigHelper.PostgreSqlConnectionConfig; } } /// /// 插入拓展 /// public long InsertEx(Entity.XhsProject project, Entity.XhsProjectSite site) { if (project == null) { return default; } using (var db = new SqlSugarClient(ConnectionConfig)) { try { db.BeginTran(); if (project.ID < 1) { project.ID = db.Insertable(project).ExecuteReturnSnowflakeId(); if (project.ID < 1) { db.RollbackTran(); return default; } } else { var bol = db.Insertable(project).ExecuteCommand() > 0; if (!bol) { db.RollbackTran(); return default; } } if (site != null) { site.ProjectID = project.ID; if (site.ID < 1) { site.ID = db.Insertable(site).ExecuteReturnSnowflakeId(); if (site.ID < 1) { db.RollbackTran(); return default; } } else { var bol = db.Insertable(site).ExecuteCommand() >= 0; if (!bol) { db.RollbackTran(); return default; } } } return project.ID; } catch { db.RollbackTran(); throw; } } } /// /// 编辑拓展 /// public bool UpdateEx(Entity.XhsProject project, Entity.XhsProjectSite site) { if (project == null) { return false; } if (project.ID < 1) { return false; } using (var db = new SqlSugarClient(ConnectionConfig)) { try { db.BeginTran(); var bol = db.Updateable(project).ExecuteCommandHasChange(); if (!bol) { db.RollbackTran(); return false; } if (site != null) { site.ProjectID = project.ID; if (site.ID < 1) { db.RollbackTran(); return false; } bol = db.Updateable(site).ExecuteCommandHasChange(); if (!bol) { db.RollbackTran(); return false; } } return true; } catch { db.RollbackTran(); throw; } } } /// /// 更新开始时间 /// public virtual bool UpdateStartTime(long ID, DateTime StartTime) { using (SqlSugarClient db = new(ConnectionConfig)) { return db.Updateable() .SetColumns(x => x.StartTime == StartTime) .Where(x => x.ID == ID) .ExecuteCommand() > 0; } } /// /// 更新结束时间 /// public virtual bool UpdateEndTime(long ID, DateTime EndTime) { using (SqlSugarClient db = new(ConnectionConfig)) { return db.Updateable() .SetColumns(x => x.EndTime == EndTime) .Where(x => x.ID == ID) .ExecuteCommand() > 0; } } /// /// 通过 ID 删除 (拓展) /// public bool DeleteExByID(long ID) { if (ID < 1) { return false; } using (var db = new SqlSugarClient(ConnectionConfig)) { try { db.BeginTran(); var bol = db.Deleteable().Where(x => x.ID == ID).ExecuteCommandHasChange(); if (!bol) { db.RollbackTran(); return false; } db.Deleteable().Where(x => x.ProjectID == ID).ExecuteCommandHasChange(); db.CommitTran(); return true; } catch { db.RollbackTran(); throw; } } } } }