锐腾搅拌上料功能
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
5.9 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using ICSSoft.Frame.Data.Entity;
  6. using ICSSoft.Base.Config.DBHelper;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using ICSSoft.Base.Config.AppConfig;
  10. namespace ICSSoft.Frame.Data.DAL
  11. {
  12. public class ICSItemBackDAL
  13. {
  14. #region AddandEdit
  15. public static void AddandEdit(ICSItemBack vendorLot, string Appconstr)
  16. {
  17. FramDataContext db = new FramDataContext(Appconstr);
  18. db.Connection.Open();
  19. db.Transaction = db.Connection.BeginTransaction();
  20. try
  21. {
  22. bool isNew = false;
  23. var line = db.ICSItemBack.SingleOrDefault(a => a.ID == vendorLot.ID);
  24. if (line == null)
  25. {
  26. isNew = true;
  27. line = new ICSItemBack();
  28. line.ID = AppConfig.GetGuid();
  29. line.STATUS = vendorLot.STATUS;
  30. }
  31. var codes = db.ICSItemBack.Where(a => a.MOCODE == vendorLot.MOCODE && a.MOSEQ == vendorLot.MOSEQ && a.INVCode == vendorLot.INVCode && a.STATUS == vendorLot.STATUS && a.ID != line.ID);
  32. if (codes != null && codes.Count() > 0)
  33. {
  34. throw new Exception("该工单行下此物料已存在,请入库后再新建或直接修改数量!");
  35. }
  36. line.MOCODE = vendorLot.MOCODE;
  37. line.MOSEQ = vendorLot.MOSEQ;
  38. line.INVCode = vendorLot.INVCode;
  39. line.QTY = vendorLot.QTY;
  40. line.MEMO = vendorLot.MEMO;
  41. line.MUSER = AppConfig.UserCode;
  42. line.MUSERName = AppConfig.UserName;
  43. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
  44. line.WorkPoint = AppConfig.WorkPointCode;
  45. line.EATTRIBUTE1 = vendorLot.EATTRIBUTE1;
  46. if (isNew) db.ICSItemBack.InsertOnSubmit(line);
  47. db.SubmitChanges();
  48. db.Transaction.Commit();
  49. }
  50. catch (Exception ex)
  51. {
  52. db.Transaction.Rollback();
  53. throw new Exception(ex.Message);
  54. }
  55. }
  56. #endregion
  57. #region AddandEditList
  58. public static void AddandEditList(List<ICSItemBack> vendorLotList, string Appconstr)
  59. {
  60. FramDataContext db = new FramDataContext(Appconstr);
  61. db.Connection.Open();
  62. db.Transaction = db.Connection.BeginTransaction();
  63. try
  64. {
  65. foreach (var vendorLot in vendorLotList)
  66. {
  67. bool isNew = false;
  68. var line = db.ICSItemBack.SingleOrDefault(a => a.ID == vendorLot.ID);
  69. if (line == null)
  70. {
  71. isNew = true;
  72. line = new ICSItemBack();
  73. line.ID = AppConfig.GetGuid();
  74. line.STATUS = vendorLot.STATUS;
  75. }
  76. var codes = db.ICSItemBack.Where(a => a.MOCODE == vendorLot.MOCODE && a.MOSEQ == vendorLot.MOSEQ && a.INVCode == vendorLot.INVCode && a.STATUS == vendorLot.STATUS && a.ID != line.ID);
  77. if (codes != null && codes.Count() > 0)
  78. {
  79. throw new Exception("该工单行下此物料已存在,请入库后再新建或直接修改数量!");
  80. }
  81. line.MOCODE = vendorLot.MOCODE;
  82. line.MOSEQ = vendorLot.MOSEQ;
  83. line.INVCode = vendorLot.INVCode;
  84. line.QTY = vendorLot.QTY;
  85. line.MEMO = vendorLot.MEMO;
  86. line.MUSER = AppConfig.UserCode;
  87. line.MUSERName = AppConfig.UserName;
  88. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
  89. line.WorkPoint = AppConfig.WorkPointCode;
  90. line.EATTRIBUTE1 = vendorLot.EATTRIBUTE1;
  91. if (isNew) db.ICSItemBack.InsertOnSubmit(line);
  92. }
  93. db.SubmitChanges();
  94. db.Transaction.Commit();
  95. }
  96. catch (Exception ex)
  97. {
  98. db.Transaction.Rollback();
  99. throw new Exception(ex.Message);
  100. }
  101. }
  102. #endregion
  103. #region select
  104. public static ICSItemBack select(String guid, String Appconstr)
  105. {
  106. FramDataContext db = new FramDataContext(Appconstr);
  107. db.Connection.Open();
  108. db.Transaction = db.Connection.BeginTransaction();
  109. ICSItemBack entity = new ICSItemBack();
  110. try
  111. {
  112. var line = db.ICSItemBack.SingleOrDefault(a => a.ID == guid);
  113. return (ICSItemBack)line;
  114. }
  115. catch (Exception ex)
  116. {
  117. throw new Exception(ex.Message);
  118. }
  119. }
  120. #endregion
  121. #region delete
  122. public static void delete(List<String> guidList,List<string> codeList)
  123. {
  124. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  125. db.Connection.Open();
  126. db.Transaction = db.Connection.BeginTransaction();
  127. try
  128. {
  129. var lines = db.ICSItemBack.Where(a => guidList.Contains(a.ID));
  130. //var line = db.ICSRES.Where(a => codeList.Contains(a.DCTCODE));
  131. //if(line.Count()!=0){
  132. // throw new Exception("DCT指令在资源维护已经使用,无法删除!");
  133. //}
  134. db.ICSItemBack.DeleteAllOnSubmit(lines);
  135. db.SubmitChanges();
  136. db.Transaction.Commit();
  137. }
  138. catch (Exception ex)
  139. {
  140. db.Transaction.Rollback();
  141. throw ex;
  142. }
  143. }
  144. #endregion
  145. }
  146. }