ProductPlanDal.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using Cksoft.Data;
  2. using DllEapEntity;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. namespace DllEapDal.OFILM
  8. {
  9. public class ProductPlanDal
  10. {
  11. private IDatabase CurrDb = null;
  12. public ProductPlanDal(IDatabase db)
  13. {
  14. CurrDb = db;
  15. }
  16. /// <summary>
  17. /// 批量新增
  18. /// </summary>
  19. /// <param name="pros"></param>
  20. /// <param name="userCode"></param>
  21. /// <param name="errorinfo"></param>
  22. /// <returns></returns>
  23. public int Adds(IEnumerable<Productionplan> pros, string userCode, ref string errorinfo)
  24. {
  25. try
  26. {
  27. string sqldel = $"delete from productionplan ";
  28. CurrDb.ExecuteBySql(sqldel);
  29. CurrDb.InsertFor<Productionplan>(pros, userCode);
  30. var sql = "select @@identity;";
  31. var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
  32. return id;
  33. }
  34. catch (Exception e)
  35. {
  36. errorinfo = e.ToString();
  37. return -1;
  38. }
  39. }
  40. public Productionplan getMin()
  41. {
  42. string sql = "select min(planTime) planTime from productionplan";
  43. return CurrDb.FindList<Productionplan>(sql).FirstOrDefault();
  44. }
  45. public IEnumerable<WorkingProcedure> GetWorkMac()
  46. {
  47. string sql = "select distinct MachineType from WorkingProcedure";
  48. return CurrDb.FindList<WorkingProcedure>(sql);
  49. }
  50. /// <summary>
  51. /// 检查导入计划的机种在UPH里是否存在
  52. /// </summary>
  53. /// <param name="pros"></param>
  54. /// <param name="errorinfo"></param>
  55. /// <returns></returns>
  56. public int CheckSame(List<Productionplan> pros, ref Object errorinfo)
  57. {
  58. var workMac = GetWorkMac();
  59. List<Same> works = new List<Same>();
  60. foreach (var item in workMac)
  61. {
  62. works.Add(new Same { Customer = item.MachineType, Floor = item.Floor, Park = item.Park });
  63. }
  64. List<Same> pps = new List<Same>();
  65. var result = from r in pros
  66. group r by new { r.Customer, r.Floor, r.Park } into g
  67. where g.Count() > 1
  68. select g;
  69. //遍历分组结果集
  70. foreach (var item in result)
  71. {
  72. pps.Add(new Same {Customer= item.Key.Customer,Floor=item.Key.Floor,Park=item.Key.Park });
  73. }
  74. List<Same> list3 = new List<Same>();
  75. list3 = pps.Except(works).ToList();
  76. //List<string> works = new List<string>();
  77. //foreach(var item in workMac)
  78. //{
  79. // works.Add(item.MachineType);
  80. //}
  81. //List<string> pps = new List<string>();
  82. //var result = from r in pros
  83. // group r by new { r.Customer,r.Floor,r.Park } into g
  84. // where g.Count() > 1
  85. // select g;
  86. ////遍历分组结果集
  87. //foreach (var item in result)
  88. //{
  89. // pps.Add(item.Key.Customer);
  90. //}
  91. //List<string> list3 = new List<string>();
  92. //list3= pps.Except(works).ToList();
  93. if (list3.Count() >= 1)
  94. {
  95. errorinfo = list3;
  96. return -2;
  97. }
  98. return 1;
  99. }
  100. }
  101. public class Same
  102. {
  103. public string Customer { get; set; }
  104. public string Floor { get; set; }
  105. public string Park { get; set; }
  106. public override int GetHashCode()
  107. {
  108. return this.Customer.GetHashCode();
  109. }
  110. public override bool Equals(object obj)
  111. {
  112. return this.Customer == (obj as Same).Customer;
  113. }
  114. }
  115. }