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

162 lines
5.7 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. namespace ICSSoft.Frame.Data.DAL
  11. {
  12. public class ICSINVInfoDAL
  13. {
  14. #region AddandEdit
  15. public static void AddandEdit(ICSINVInfo inventoryLot, 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. ICSINVInfo line = db.ICSINVInfo.SingleOrDefault(a => a.INVCODE == inventoryLot.INVCODE && a.WorkPoint == AppConfig.WorkPointCode);
  24. if (inventoryLot.ID == "")//新增
  25. {
  26. if (line != null)
  27. {
  28. throw new Exception(inventoryLot.INVCODE + "物料编码已存在");
  29. }
  30. isNew = true;
  31. line = new ICSINVInfo();
  32. line.ID = AppConfig.GetGuid();
  33. }
  34. line.INVCODE = inventoryLot.INVCODE;
  35. line.INVNAME = inventoryLot.INVNAME;
  36. line.EATTRIBUTE5 = inventoryLot.EATTRIBUTE5;
  37. //line.EATTRIBUTE6 = inventoryLot.EATTRIBUTE6;
  38. line.MUSER = inventoryLot.MUSER;
  39. line.MUSERName = inventoryLot.MUSERName;
  40. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
  41. line.WorkPoint = AppConfig.WorkPointCode;
  42. if (isNew)
  43. {
  44. db.ICSINVInfo.InsertOnSubmit(line);
  45. }
  46. db.SubmitChanges();
  47. db.Transaction.Commit();
  48. }
  49. catch (Exception ex)
  50. {
  51. db.Transaction.Rollback();
  52. throw new Exception(ex.Message);
  53. }
  54. }
  55. #endregion
  56. #region 新增和修改List
  57. public static string AddList(List<ICSINVInfo> InfoList, List<string> listLvL, string dsconn)
  58. {
  59. FramDataContext db = new FramDataContext(dsconn);
  60. db.Connection.Open();
  61. db.Transaction = db.Connection.BeginTransaction();
  62. try
  63. {
  64. string str = "";
  65. foreach (ICSINVInfo info in InfoList)
  66. {
  67. var code = db.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == info.INVCODE && a.WorkPoint == AppConfig.WorkPointCode);
  68. if (code == null)
  69. {
  70. str += "存货编码:" + info.INVCODE + "不存在" + "\r\n";
  71. continue;
  72. }
  73. if (!listLvL.Contains(info.EATTRIBUTE5))
  74. {
  75. str += "存货编码:" + info.INVCODE + "不存在此产品等级" + info.EATTRIBUTE5 + "\r\n";
  76. continue;
  77. }
  78. bool isNew = false;
  79. var line = db.ICSINVInfo.SingleOrDefault(a => a.INVCODE == info.INVCODE && a.WorkPoint == AppConfig.WorkPointCode);
  80. if (line == null)
  81. {
  82. isNew = true;
  83. line = new ICSINVInfo();
  84. line.ID = AppConfig.GetGuid();
  85. }
  86. line.INVCODE = info.INVCODE;
  87. line.INVNAME = info.INVNAME;
  88. line.EATTRIBUTE1 = info.EATTRIBUTE1;
  89. line.EATTRIBUTE5 = info.EATTRIBUTE5;
  90. line.EATTRIBUTE4 = info.EATTRIBUTE4;
  91. line.EATTRIBUTE6 = info.EATTRIBUTE6;
  92. line.MUSER = AppConfig.UserCode;
  93. line.MUSERName = AppConfig.UserName;
  94. line.MTIME = DateTime.Now;
  95. line.WorkPoint = AppConfig.WorkPointCode;
  96. if (isNew)
  97. db.ICSINVInfo.InsertOnSubmit(line);
  98. db.SubmitChanges();
  99. }
  100. db.Transaction.Commit();
  101. return str;
  102. }
  103. catch (Exception ex)
  104. {
  105. db.Transaction.Rollback();
  106. throw ex;
  107. }
  108. }
  109. #endregion
  110. #region select
  111. public static ICSINVInfo select(String guid, String Appconstr)
  112. {
  113. FramDataContext db = new FramDataContext(Appconstr);
  114. db.Connection.Open();
  115. db.Transaction = db.Connection.BeginTransaction();
  116. ICSINVENTORY entity = new ICSINVENTORY();
  117. try
  118. {
  119. var line = db.ICSINVInfo.SingleOrDefault(a => a.ID == guid);
  120. return (ICSINVInfo)line;
  121. }
  122. catch (Exception ex)
  123. {
  124. throw new Exception(ex.Message);
  125. }
  126. }
  127. #endregion
  128. #region delete
  129. public static void delete(List<String> guidList, List<string> codeList)
  130. {
  131. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  132. db.Connection.Open();
  133. db.Transaction = db.Connection.BeginTransaction();
  134. try
  135. {
  136. var lines = db.ICSINVInfo.Where(a => guidList.Contains(a.ID) && a.WorkPoint == AppConfig.WorkPointCode);
  137. db.ICSINVInfo.DeleteAllOnSubmit(lines);
  138. db.SubmitChanges();
  139. db.Transaction.Commit();
  140. }
  141. catch (Exception ex)
  142. {
  143. db.Transaction.Rollback();
  144. throw ex;
  145. }
  146. }
  147. #endregion
  148. }
  149. }