锐腾搅拌上料功能
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.

219 lines
9.0 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.AppConfig;
  7. using System.Data;
  8. using System.Data.Sql;
  9. using System.Data.Linq;
  10. using System.Data.SqlClient;
  11. namespace ICSSoft.Frame.Data.DAL
  12. {
  13. public class ICSINVENTORYDAL
  14. {
  15. #region AddandEdit
  16. public static void AddandEdit(ICSINVENTORY inventoryLot, string Appconstr)
  17. {
  18. //FramDataContext db = new FramDataContext(Appconstr);
  19. //db.Connection.Open();
  20. //db.Transaction = db.Connection.BeginTransaction();
  21. SqlConnection conn = new System.Data.SqlClient.SqlConnection(Appconstr);
  22. conn.Open();
  23. SqlTransaction sqlTran = conn.BeginTransaction();
  24. SqlCommand cmd = new SqlCommand();
  25. cmd.CommandTimeout = 180;
  26. cmd.Transaction = sqlTran;
  27. cmd.Connection = conn;
  28. try
  29. {
  30. string sql = @"UPDATE ICSINVENTORY SET INVMACHINETYPE='{0}',INVCONTROLTYPE='{5}',MUSER='{1}',MUSERName='{2}',MTIME='{3}'
  31. WHERE ID='{4}'";
  32. sql = string.Format(sql, inventoryLot.INVMACHINETYPE, inventoryLot.MUSER, inventoryLot.MUSERName, inventoryLot.MTIME, inventoryLot.ID, inventoryLot.INVCONTROLTYPE);
  33. cmd.CommandText = sql;
  34. int result = cmd.ExecuteNonQuery();
  35. if (result <= 0)
  36. {
  37. throw new Exception("修改失败");
  38. }
  39. cmd.Transaction.Commit();
  40. //bool isNew = false;
  41. //var line = db.ICSINVENTORY.SingleOrDefault(a => a.ID == inventoryLot.ID);
  42. //if (line == null)
  43. //{
  44. // isNew = true;
  45. // line = new ICSINVENTORY();
  46. // line.ID = AppConfig.GetGuid();
  47. //}
  48. //var codes = db.ICSINVENTORY.Where(a => a.INVCODE == inventoryLot.INVCODE && a.ID != line.ID);
  49. //if (codes.ToList().Count > 0)
  50. //{
  51. // throw new Exception("存货编码已存在");
  52. //}
  53. //line.INVCODE = inventoryLot.INVCODE;
  54. //line.INVNAME = inventoryLot.INVNAME;
  55. //line.INVDESC = inventoryLot.INVDESC;
  56. //line.INVUOM = inventoryLot.INVUOM;
  57. //line.INVTYPE = inventoryLot.INVTYPE;
  58. //line.INVCLASS = inventoryLot.INVCLASS;
  59. //line.INVMACHINETYPE = inventoryLot.INVMACHINETYPE;
  60. //line.INVVOLUME = inventoryLot.INVVOLUME;
  61. //line.INVMODELCODE = inventoryLot.INVMODELCODE;
  62. //line.INVEXPORTIMPORT = inventoryLot.INVEXPORTIMPORT;
  63. //line.INVMODELGROUP = inventoryLot.INVMODELGROUP;
  64. //line.INVGROUP = inventoryLot.INVGROUP;
  65. //line.INVGROUPDESC = inventoryLot.INVGROUPDESC;
  66. //line.INVCONTROLTYPE = inventoryLot.INVCONTROLTYPE;
  67. //line.MUSER = inventoryLot.MUSER;
  68. //line.MUSERName = inventoryLot.MUSERName;
  69. //line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
  70. //line.WorkPoint = AppConfig.WorkPointCode;
  71. //line.EATTRIBUTE1 = null;
  72. //line.INVPARSETYPE = inventoryLot.INVPARSETYPE;
  73. //line.CHECKSTATUS = inventoryLot.CHECKSTATUS;
  74. //line.INVCHECKTYPE = inventoryLot.INVCHECKTYPE;
  75. //line.SNLENGTH = inventoryLot.SNLENGTH;
  76. //line.VENDORCODE = inventoryLot.VENDORCODE;
  77. //line.ROHS = inventoryLot.ROHS;
  78. //line.NeedVendor = inventoryLot.NeedVendor;
  79. //line.INVShelfLife = inventoryLot.INVShelfLife;
  80. //line.INVCARTONQTY = inventoryLot.INVCARTONQTY;
  81. //line.ITEMBURNINQTY = inventoryLot.ITEMBURNINQTY;
  82. //line.ELECTRICCURRENTMINVALUE = inventoryLot.ELECTRICCURRENTMINVALUE;
  83. //line.ELECTRICCURRENTMAXVALUE = inventoryLot.ELECTRICCURRENTMAXVALUE;
  84. //line.PCBACOUNT = inventoryLot.PCBACOUNT;
  85. //line.CHKITEMOP = inventoryLot.CHKITEMOP;
  86. //line.ISSMT = inventoryLot.ISSMT;
  87. //if (isNew) db.ICSINVENTORY.InsertOnSubmit(line);
  88. //db.SubmitChanges();
  89. //db.Transaction.Commit();
  90. }
  91. catch (Exception ex)
  92. {
  93. cmd.Transaction.Rollback();
  94. //db.Transaction.Rollback();
  95. throw new Exception(ex.Message);
  96. }
  97. }
  98. #endregion
  99. #region select
  100. public static ICSINVENTORY select(String guid, String Appconstr)
  101. {
  102. FramDataContext db = new FramDataContext(Appconstr);
  103. db.Connection.Open();
  104. db.Transaction = db.Connection.BeginTransaction();
  105. ICSINVENTORY entity = new ICSINVENTORY();
  106. try
  107. {
  108. var line = db.ICSINVENTORY.SingleOrDefault(a => a.ID == guid);
  109. return (ICSINVENTORY)line;
  110. }
  111. catch (Exception ex)
  112. {
  113. throw new Exception(ex.Message);
  114. }
  115. }
  116. #endregion
  117. #region delete
  118. public static void delete(List<String> guidList,List<string> codeList)
  119. {
  120. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  121. db.Connection.Open();
  122. db.Transaction = db.Connection.BeginTransaction();
  123. try
  124. {
  125. var lines = db.ICSINVENTORY.Where(a => guidList.Contains(a.ID));
  126. var line = db.ICSITEMROUTE2OP.Where(a => codeList.Contains(a.ITEMCODE));
  127. if (line.Count() != 0)
  128. {
  129. throw new Exception("存货编码在产品、途程和工序的关系维护中已经使用,无法删除!");
  130. }
  131. var line1 = db.ICSITEM2ROUTE.Where(a => codeList.Contains(a.ITEMCODE));
  132. if (line1.Count() != 0)
  133. {
  134. throw new Exception("存货编码在产品和途程的关系维护中已经使用,无法删除!");
  135. }
  136. var line2 = db.ICSSBOM.Where(a => codeList.Contains(a.ITEMCODE));
  137. if (line2.Count() != 0)
  138. {
  139. throw new Exception("存货编码在标准BOM中已经使用,无法删除!");
  140. }
  141. var line3 = db.ICSOPBOM.Where(a => codeList.Contains(a.ITEMCODE));
  142. if (line3.Count() != 0)
  143. {
  144. throw new Exception("存货编码在工序BOM中已经使用,无法删除!");
  145. }
  146. var line4 = db.ICSOPBOMDETAIL.Where(a => codeList.Contains(a.ITEMCODE));
  147. if (line4.Count() != 0)
  148. {
  149. throw new Exception("存货编码在工序BOM详细信息中已经使用,无法删除!");
  150. }
  151. var line5 = db.ICSShipToStock.Where(a => codeList.Contains(a.ITEMCODE));
  152. if (line5.Count() != 0)
  153. {
  154. throw new Exception("存货编码在免检物料表中已经使用,无法删除!");
  155. }
  156. var line6 = db.ICSINVReceiptDetail.Where(a => codeList.Contains(a.ITEMCODE));
  157. if (line6.Count() != 0)
  158. {
  159. throw new Exception("存货编码在入库单详细表中已经使用,无法删除!");
  160. }
  161. var line7 = db.ICSWareHouseLotInfo.Where(a => codeList.Contains(a.INVCode));
  162. if (line7.Count() != 0)
  163. {
  164. throw new Exception("存货编码在物料,产品批次的库存信息中已经使用,无法删除!");
  165. }
  166. var line8 = db.ICSInvTransferDetail.Where(a => codeList.Contains(a.ITEMCODE));
  167. if (line8.Count() != 0)
  168. {
  169. throw new Exception("存货编码在库存移转单详细表中已经使用,无法删除!");
  170. }
  171. db.ICSINVENTORY.DeleteAllOnSubmit(lines);
  172. db.SubmitChanges();
  173. db.Transaction.Commit();
  174. }
  175. catch (Exception ex)
  176. {
  177. db.Transaction.Rollback();
  178. throw ex;
  179. }
  180. }
  181. #endregion
  182. #region find
  183. public static string find(String guid, String Appconstr)
  184. {
  185. FramDataContext db = new FramDataContext(Appconstr);
  186. db.Connection.Open();
  187. db.Transaction = db.Connection.BeginTransaction();
  188. ICSINVENTORY entity = new ICSINVENTORY();
  189. try
  190. {
  191. var line = db.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == guid);
  192. return line.INVCONTROLTYPE;
  193. }
  194. catch (Exception ex)
  195. {
  196. throw new Exception(ex.Message);
  197. }
  198. }
  199. #endregion
  200. }
  201. }