using Cksoft.Data; using Cksoft.Unity; using DllEapEntity; using DllEapEntity.Dtos; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DllEapDal.OFILM { public class OfdisconDal { private IDatabase CurrDb = null; public OfdisconDal(IDatabase db) { CurrDb = db; } public IEnumerable Get(int start, int length, string order, string sort, string filter, string errorinfo) { try { var pros = CurrDb.FindListForCondition($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo); return pros; } catch (Exception ex) { Console.WriteLine(ex.ToString() + ex.StackTrace); return null; } } public int GetCount(string filter) { string errorinfo = string.Empty; var entities = CurrDb.FindListForCondition(filter, ref errorinfo); if (entities != null) { return entities.Count(); } return 0; } public Ofdiscon Get(int id) { var pro = CurrDb.FindEntityFor(id); return pro; } /// /// 添加WorkingProcedure并返回Id /// /// /// /// public int Add(Ofdiscon pro, string userCode, ref string errorinfo) { var entities = CurrDb.FindListForCondition($" and a.plantid='{pro.plantid}' and a.pcode='{pro.pcode}' ", ref errorinfo); if (entities != null && entities.Count() > 0) { errorinfo = "已存在相同厂房ID、工序,请确认!"; return -1; } CurrDb.InsertFor(pro, userCode); var sql = "select @@identity;"; var id = Convert.ToInt32(CurrDb.FindList(sql).FirstOrDefault() ?? "-1"); return id; } /// /// /// /// /// /// /// public int Update(Ofdiscon role, string userCode, ref string errorinfo) { var entities = CurrDb.FindListForCondition($" and a.plantid='{role.plantid}' and a.pcode='{role.pcode}' " + $"and a.ID<>{role.id}", ref errorinfo); if (entities != null && entities.Count() > 0) { errorinfo = "已存在相同厂房ID、工序,请确认"; return -1; } if (CurrDb.UpdateFor(role, userCode) < 0) { return -1; } return role.id; } public IEnumerable getWorkingProcedure(int id) { var sql = $"select * from Ofdiscon where ID={id}"; return CurrDb.FindList(sql); } public int Delete(int id, ref string msg) { if (CurrDb.DeleteFor(id) < 0) { msg = "删除失败"; return -1; } msg = string.Empty; return 1; } public IEnumerable GetOfdisconExprort(int take) { var sql = $"select * from Ofdiscon limit {take}"; IEnumerable dtos = CurrDb.FindList(sql).Take(take); if (dtos == null || dtos.Count() <= 0) return null; return dtos; } } }