using Cksoft.Data; using DllEapEntity; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DllEapDal.OFILM { public class ProductPlanDal { private IDatabase CurrDb = null; public ProductPlanDal(IDatabase db) { CurrDb = db; } /// /// 批量新增 /// /// /// /// /// public int Adds(IEnumerable pros, string userCode, ref string errorinfo) { try { string sqldel = $"delete from productionplan "; 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 Productionplan getMin() { string sql = "select min(planTime) planTime from productionplan"; return CurrDb.FindList(sql).FirstOrDefault(); } public IEnumerable GetWorkMac() { string sql = "select distinct MachineType from WorkingProcedure"; return CurrDb.FindList(sql); } /// /// 检查导入计划的机种在UPH里是否存在 /// /// /// /// public int CheckSame(List pros, ref Object errorinfo) { var workMac = GetWorkMac(); List works = new List(); foreach (var item in workMac) { works.Add(new Same { Customer = item.MachineType, Floor = item.Floor, Park = item.Park }); } List pps = new List(); var result = from r in pros group r by new { r.Customer, r.Floor, r.Park } into g where g.Count() > 1 select g; //遍历分组结果集 foreach (var item in result) { pps.Add(new Same {Customer= item.Key.Customer,Floor=item.Key.Floor,Park=item.Key.Park }); } List list3 = new List(); list3 = pps.Except(works).ToList(); //List works = new List(); //foreach(var item in workMac) //{ // works.Add(item.MachineType); //} //List pps = new List(); //var result = from r in pros // group r by new { r.Customer,r.Floor,r.Park } into g // where g.Count() > 1 // select g; ////遍历分组结果集 //foreach (var item in result) //{ // pps.Add(item.Key.Customer); //} //List list3 = new List(); //list3= pps.Except(works).ToList(); if (list3.Count() >= 1) { errorinfo = list3; return -2; } return 1; } } public class Same { public string Customer { get; set; } public string Floor { get; set; } public string Park { get; set; } public override int GetHashCode() { return this.Customer.GetHashCode(); } public override bool Equals(object obj) { return this.Customer == (obj as Same).Customer; } } }