123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- 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;
- }
- /// <summary>
- /// 批量新增
- /// </summary>
- /// <param name="pros"></param>
- /// <param name="userCode"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public int Adds(IEnumerable<Productionplan> pros, string userCode, ref string errorinfo)
- {
- try
- {
- string sqldel = $"delete from productionplan ";
- CurrDb.ExecuteBySql(sqldel);
- CurrDb.InsertFor<Productionplan>(pros, userCode);
- var sql = "select @@identity;";
- var id = Convert.ToInt32(CurrDb.FindList<string>(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<Productionplan>(sql).FirstOrDefault();
- }
- public IEnumerable<WorkingProcedure> GetWorkMac()
- {
- string sql = "select distinct MachineType from WorkingProcedure";
- return CurrDb.FindList<WorkingProcedure>(sql);
- }
- /// <summary>
- /// 检查导入计划的机种在UPH里是否存在
- /// </summary>
- /// <param name="pros"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public int CheckSame(List<Productionplan> pros, ref Object errorinfo)
- {
- var workMac = GetWorkMac();
- List<Same> works = new List<Same>();
- foreach (var item in workMac)
- {
- works.Add(new Same { Customer = item.MachineType, Floor = item.Floor, Park = item.Park });
- }
- List<Same> pps = new List<Same>();
- 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<Same> list3 = new List<Same>();
- list3 = pps.Except(works).ToList();
- //List<string> works = new List<string>();
- //foreach(var item in workMac)
- //{
- // works.Add(item.MachineType);
- //}
- //List<string> pps = new List<string>();
- //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<string> list3 = new List<string>();
- //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;
- }
- }
- }
|