using Cksoft.Data; using DllEapEntity; using DllEapEntity.Dtos; using DllEapEntity.OFILM; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DllEapDal.OFILM { public class EquipmentnumberDal { private IDatabase CurrDb = null; public EquipmentnumberDal(IDatabase db) { CurrDb = db; } 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; var entities = CurrDb.FindListForCondition(filter, ref errorinfo); if (entities != null) { return entities.Count(); } return 0; } public Equipmentnumber Get(int id) { var pro = CurrDb.FindEntityFor(id); return pro; } /// /// 添加WorkingProcedure并返回Id /// /// /// /// public int Add(Equipmentnumber pro, string userCode, ref string errorinfo) { //var entities = CurrDb.FindListForCondition($" and a.equipmentmodel='{pro.Equipmentmodel}' and a.threeFloor='{pro.ThreeFloor}' ", ref errorinfo); //if (entities != null && entities.Count() > 0) //{ // errorinfo = "已存在相同园区,机种,工段,作业内容,请确认"; // return -1; //} CurrDb.InsertFor(pro, userCode); var sql = "select @@identity;"; var id = Convert.ToInt32(CurrDb.FindList(sql).FirstOrDefault() ?? "-1"); return id; } /// /// 批量新增 /// /// /// /// /// public int Adds(IEnumerable pros, string userCode, ref string errorinfo) { try { string sqldel = $"delete from Equipmentnumber "; CurrDb.ExecuteBySql(sqldel); CurrDb.InsertFor(pros, userCode); var sql = "select @@identity;"; var id = Convert.ToInt32(CurrDb.FindList(sql).FirstOrDefault() ?? "-1"); return id; } catch (Exception e) { errorinfo = e.ToString(); return -1; } } /// /// /// /// /// /// /// public int Update(Equipmentnumber role, string userCode, ref string errorinfo) { //var entities = CurrDb.FindListForCondition($" and a.park='{role.Park}' and a.MachineType='{role.MachineType}' and a.workshopSection='{role.WorkshopSection}' and a.assignmentContent='{role.AssignmentContent}' " + // $"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 IEnumerable getWorkingProcedure(int id) { var sql = $"select * from Equipmentnumber 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 GetEquipmentnumberExprort(string filter, string sortField, string sortOrder, int take) { var sql = $"select * from Equipmentnumber limit {take}"; IEnumerable dtos = CurrDb.FindList(sql).Take(take); if (dtos == null || dtos.Count() <= 0) return null; return dtos; } /// /// 分页获取设备型号,园区,楼层 /// /// /// /// /// /// /// public IEnumerable getEquipmentmodel(int start, int length, string order, string sort, string filter) { string sql = $@"select * from ( (select id,equipmentmodel,accounting,'三号园区' as park,'2#1F' as floor,IFNULL(threeSecFir,0) as score from equipmentnumber) UNION (select id,equipmentmodel,accounting,'未来城' as park,'A1#1F' as floor,IFNULL(futureCity,0) as score from equipmentnumber) UNION (select id,equipmentmodel,accounting,'未来城' as park,'A1#3F' as floor,IFNULL(futureCityThird,0) as score from equipmentnumber) UNION (select id,equipmentmodel,accounting,'二号园区' as park,'A1#1F' as floor,IFNULL(secfirstFir,0) as score from equipmentnumber) UNION (select id,equipmentmodel,accounting,'二号园区' as park,'A1#2F' as floor,IFNULL(secFirstSec,0) as score from equipmentnumber) UNION (select id,equipmentmodel,accounting,'二号园区' as park,'A1#3F' as floor,IFNULL(secFirstThird,0) as score from equipmentnumber) UNION (select id,equipmentmodel,accounting,'二号园区' as park,'A2#1F' as floor,IFNULL(secSecFirst,0) as score from equipmentnumber) UNION (select id,equipmentmodel,accounting,'二号园区' as park,'A2#2F' as floor,IFNULL(secSecSec,0) as score from equipmentnumber) )tt where 1=1 {filter} order by equipmentmodel,park limit {start - 1},{length}"; IEnumerable dtos = CurrDb.FindList(sql); if (dtos == null || dtos.Count() <= 0) return null; return dtos; } public IEnumerable> GetMultipleSelects(string filter) { var sql = "select ID value,equipmentmodel label from equipmentnumber"; var entities = CurrDb.FindList>(sql); return entities; } } }