using Cksoft.Data; using System; using System.Collections.Generic; using System.Text; using DllEapEntity.PM; using System.Linq; namespace DllEapDal { public class PMSchemaDal { private IDatabase CurrDb; public PMSchemaDal(IDatabase db) { CurrDb = db; } public IEnumerable Get() { var models = CurrDb.FindList(); return models; } public IEnumerable Get(int start, int length, string order, string sort, string filter, string errorinfo) { var pros = CurrDb.FindListForCondition($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo); return pros; } public int GetCount(string filter) { string errorinfo = string.Empty; //string sql = $"select count(1) from ProgramRule a where 1=1 {filter}"; var entities = CurrDb.FindListForCondition(filter, ref errorinfo); if (entities != null) { return entities.Count(); } return 0; } public PMSchema Get(int id) { var pro = CurrDb.FindEntityFor(id); return pro; } public IEnumerable getpmmachine(int id) { var sql = $"select * from pmmachine where pmid={id}"; var pro = CurrDb.FindList(sql); return pro; } /// /// 添加角色并返回角色Id /// /// /// /// public int Add(PMSchema pro, string userCode, ref string errorinfo) { var entities = CurrDb.FindListForCondition($" and a.FCode='{pro.FCode}' ", ref errorinfo); if (entities != null && entities.Count() > 0) { errorinfo = "方案已存在,请确认"; return -1; } pro.RecCode = pro.ModCode = userCode; pro.RecTime = pro.ModTime = DateTime.Now; string sql = $"insert into PMSchema(FCode,FName,Remark,RecCode,RecTime," + $"ModCode,ModTime,Maintenance,TimeSpan) values('{pro.FCode}'," + $"'{pro.FName}','{pro.Remark}','{pro.RecCode}'," + $"'{pro.RecTime.ToString("yyyy-MM-dd HH:mm:ss")}','{pro.ModCode}'," + $"'{pro.ModTime.ToString("yyyy-MM-dd HH:mm:ss")}','{pro.Maintenance}','{pro.TimeSpan}');"; sql += "select @@identity;"; var id = Convert.ToInt32(CurrDb.FindList(sql).FirstOrDefault() ?? "-1"); return id; } public int Update(PMSchema role, string userCode, ref string errorinfo) { var entities = CurrDb.FindListForCondition($" and a.FCode='{role.FCode}' " + $"and a.ID<>{role.ID}", ref errorinfo); if (entities != null && entities.Count() > 0) { errorinfo = "已存在相同的方案,请确认"; return -1; } if (CurrDb.UpdateFor(role, userCode) < 0) { return -1; } return role.ID; } public int Delete(int id, ref string msg) { var sql = $"delete from pmmachine where pmid={id}"; if (CurrDb.ExecuteBySql(sql) < 0) { msg = "删除保养中间表失败"; return -1; } if (CurrDb.DeleteFor(id) < 0) { msg = "删除失败"; return -1; } msg = string.Empty; return 1; } } }