华恒Mes鼎捷代码
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.

245 lines
8.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 ICSMODELDAL
  13. {
  14. #region AddandEdit
  15. public static void AddandEdit(ICSMODEL MODEL, 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.ICSMODEL.SingleOrDefault(a => a.ID == MODEL.ID);
  24. if (line == null)
  25. {
  26. isNew = true;
  27. line = new ICSMODEL();
  28. line.ID = AppConfig.GetGuid();
  29. }
  30. var codes = db.ICSMODEL.Where(a => a.MODELCODE == MODEL.MODELCODE && a.ID != line.ID);
  31. if (codes.ToList().Count > 0)
  32. {
  33. throw new Exception("产品别代码已存在");
  34. }
  35. line.MODELCODE = MODEL.MODELCODE;
  36. line.MODELDESC = MODEL.MODELDESC;
  37. line.MUSER = MODEL.MUSER;
  38. line.MUSERName = MODEL.MUSERName;
  39. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
  40. line.WorkPoint = AppConfig.WorkPointCode;
  41. if (isNew) db.ICSMODEL.InsertOnSubmit(line);
  42. db.SubmitChanges();
  43. db.Transaction.Commit();
  44. }
  45. catch (Exception ex)
  46. {
  47. db.Transaction.Rollback();
  48. throw new Exception(ex.Message);
  49. }
  50. }
  51. #endregion
  52. #region AddandEdit
  53. public static void AddandEdit(List<ICSINVOPPrice> inv, string Appconstr,String type)
  54. {
  55. FramDataContext db = new FramDataContext(Appconstr);
  56. db.Connection.Open();
  57. db.Transaction = db.Connection.BeginTransaction();
  58. try
  59. {
  60. if (type != "导入")
  61. {
  62. foreach (var MODEL in inv)
  63. {
  64. bool isNew = false;
  65. var line = db.ICSINVOPPrice.SingleOrDefault(a => a.id == MODEL.id);
  66. if (line == null)
  67. {
  68. isNew = true;
  69. line = new ICSINVOPPrice();
  70. line.id = AppConfig.GetGuid();
  71. }
  72. //判断存货编码和工序是否存在
  73. var INV_Exists = db.ICSINVENTORY.Where(a => a.INVCODE == MODEL.invcode).FirstOrDefault();
  74. if (INV_Exists == null)
  75. {
  76. throw new Exception("存货编码:" + MODEL.invcode + "不存在!");
  77. }
  78. var OP_Exists = db.ICSOP.Where(a => a.OPCODE == MODEL.opcode).FirstOrDefault();
  79. if (OP_Exists == null)
  80. {
  81. throw new Exception("工序编码:" + MODEL.opcode + "不存在!");
  82. }
  83. var codes = db.ICSINVOPPrice.Where(a => a.invcode == MODEL.invcode && a.id != line.id && a.opcode == MODEL.opcode);
  84. if (codes.ToList().Count > 0)
  85. {
  86. throw new Exception("存货编码:" + MODEL.invcode + ",对应的工序:" + MODEL.opcode + "已维护单价!");
  87. }
  88. line.invcode = MODEL.invcode;
  89. line.opcode = MODEL.opcode;
  90. line.Muser = MODEL.Muser;
  91. line.price = MODEL.price;
  92. line.Mtime = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
  93. if (isNew) db.ICSINVOPPrice.InsertOnSubmit(line);
  94. }
  95. }
  96. else {
  97. foreach (var MODEL in inv)
  98. {
  99. bool isNew = false;
  100. var line = db.ICSINVOPPrice.Where(a => a.invcode == MODEL.invcode && a.opcode == MODEL.opcode).FirstOrDefault();
  101. if (line == null)
  102. {
  103. isNew = true;
  104. line = new ICSINVOPPrice();
  105. line.id = AppConfig.GetGuid();
  106. }
  107. //判断存货编码和工序是否存在
  108. var INV_Exists = db.ICSINVENTORY.Where(a => a.INVCODE == MODEL.invcode).FirstOrDefault();
  109. if (INV_Exists == null)
  110. {
  111. throw new Exception("存货编码:" + MODEL.invcode + "不存在!");
  112. }
  113. var OP_Exists = db.ICSOP.Where(a => a.OPCODE == MODEL.opcode).FirstOrDefault();
  114. if (OP_Exists == null)
  115. {
  116. throw new Exception("工序编码:" + MODEL.opcode + "不存在!");
  117. }
  118. line.invcode = MODEL.invcode;
  119. line.opcode = MODEL.opcode;
  120. line.Muser = MODEL.Muser;
  121. line.price = MODEL.price;
  122. line.Mtime = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
  123. if (isNew) db.ICSINVOPPrice.InsertOnSubmit(line);
  124. }
  125. }
  126. db.SubmitChanges();
  127. db.Transaction.Commit();
  128. }
  129. catch (Exception ex)
  130. {
  131. db.Transaction.Rollback();
  132. throw new Exception(ex.Message);
  133. }
  134. }
  135. #endregion
  136. #region select
  137. public static ICSMODEL select(String guid, String Appconstr)
  138. {
  139. FramDataContext db = new FramDataContext(Appconstr);
  140. db.Connection.Open();
  141. db.Transaction = db.Connection.BeginTransaction();
  142. ICSMODEL entity = new ICSMODEL();
  143. try
  144. {
  145. var line = db.ICSMODEL.SingleOrDefault(a => a.ID == guid);
  146. return (ICSMODEL)line;
  147. }
  148. catch (Exception ex)
  149. {
  150. throw new Exception(ex.Message);
  151. }
  152. }
  153. #endregion
  154. #region select
  155. public static ICSINVOPPrice selectprice(String guid, String Appconstr)
  156. {
  157. FramDataContext db = new FramDataContext(Appconstr);
  158. db.Connection.Open();
  159. db.Transaction = db.Connection.BeginTransaction();
  160. ICSINVOPPrice entity = new ICSINVOPPrice();
  161. try
  162. {
  163. var line = db.ICSINVOPPrice.SingleOrDefault(a => a.id == guid);
  164. return (ICSINVOPPrice)line;
  165. }
  166. catch (Exception ex)
  167. {
  168. throw new Exception(ex.Message);
  169. }
  170. }
  171. #endregion
  172. #region delete
  173. public static void delete(List<String> guidList, List<String> codeList)
  174. {
  175. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  176. db.Connection.Open();
  177. db.Transaction = db.Connection.BeginTransaction();
  178. try
  179. {
  180. var line = db.ICSINVENTORY.Where(a => codeList.Contains(a.INVCLASS));
  181. if(line.Count()>0){
  182. throw new Exception("产品别已经关联存货档案无法删除!!");
  183. }
  184. var lines = db.ICSMODEL.Where(a => guidList.Contains(a.ID));
  185. db.ICSMODEL.DeleteAllOnSubmit(lines);
  186. db.SubmitChanges();
  187. db.Transaction.Commit();
  188. }
  189. catch (Exception ex)
  190. {
  191. db.Transaction.Rollback();
  192. throw ex;
  193. }
  194. }
  195. #endregion
  196. #region delete
  197. public static void deleteprice(List<String> guidList)
  198. {
  199. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  200. db.Connection.Open();
  201. db.Transaction = db.Connection.BeginTransaction();
  202. try
  203. {
  204. var lines = db.ICSINVOPPrice.Where(a => guidList.Contains(a.id));
  205. db.ICSINVOPPrice.DeleteAllOnSubmit(lines);
  206. db.SubmitChanges();
  207. db.Transaction.Commit();
  208. }
  209. catch (Exception ex)
  210. {
  211. db.Transaction.Rollback();
  212. throw ex;
  213. }
  214. }
  215. #endregion
  216. }
  217. }