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

317 lines
14 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 ICSSoft.Base.Config.DBHelper;
  9. namespace ICSSoft.Frame.Data.DAL
  10. {
  11. public class ICSOPBOMDETAILDAL
  12. {
  13. private FramDataContext _domainDataProvider = null;
  14. public ICSOPBOMDETAILDAL(FramDataContext domainDataProvider)
  15. {
  16. this._domainDataProvider = domainDataProvider;
  17. }
  18. //新增 修改
  19. public static void Add(List<ICSOPBOMDETAIL> tbInfoList, string dsconn)
  20. {
  21. FramDataContext db = new FramDataContext(dsconn);
  22. db.Connection.Open();
  23. db.Transaction = db.Connection.BeginTransaction();
  24. try
  25. {
  26. foreach (ICSOPBOMDETAIL tbinfo in tbInfoList)
  27. {
  28. bool isNew = false;
  29. var line = db.ICSOPBOMDETAIL.SingleOrDefault(a => a.OPID == tbinfo.OPID&&a.OPBOMVER==tbinfo.OPBOMVER&&a.ACTIONTYPE==tbinfo.ACTIONTYPE&&a.WorkPoint==tbinfo.WorkPoint);
  30. if (line == null)
  31. {
  32. isNew = true;
  33. line = new ICSOPBOMDETAIL();
  34. line.OBITEMCODE = tbinfo.OBITEMCODE;
  35. line.ITEMCODE = tbinfo.ITEMCODE;
  36. line.OBCODE = tbinfo.OBCODE;
  37. line.OPBOMVER = tbinfo.OPBOMVER;
  38. line.OPID = tbinfo.OPID;
  39. line.ACTIONTYPE = tbinfo.ACTIONTYPE;
  40. line.WorkPoint = tbinfo.WorkPoint;
  41. }
  42. line.ITEMID = tbinfo.ITEMID;
  43. line.OPCODE = tbinfo.OPCODE;
  44. line.OBITEMNAME = tbinfo.OBITEMNAME;
  45. line.OBITEMECN = tbinfo.OBITEMECN;
  46. line.OBITEMUOM = tbinfo.OBITEMUOM;
  47. line.OBITEMQTY = tbinfo.OBITEMQTY;
  48. line.OBSITEMCODE = tbinfo.OBSITEMCODE;
  49. line.OBITEMVER = tbinfo.OBITEMVER;
  50. line.OBITEMTYPE = tbinfo.OBITEMTYPE;
  51. line.OBITEMCONTYPE = tbinfo.OBITEMCONTYPE;
  52. line.OBITEMEFFTIME = tbinfo.OBITEMEFFTIME;
  53. line.OBITEMINVTIME = tbinfo.OBITEMINVTIME;
  54. line.ISITEMCHECK = tbinfo.ISITEMCHECK;
  55. line.ITEMCHECKVALUE = tbinfo.ITEMCHECKVALUE;
  56. line.MUSER = tbinfo.MUSER;
  57. line.MUSERName = tbinfo.MUSERName;
  58. line.MTIME = tbinfo.MTIME;
  59. line.EATTRIBUTE1 = tbinfo.EATTRIBUTE1;
  60. line.CHECKSTATUS = tbinfo.CHECKSTATUS;
  61. line.OBITEMSEQ = tbinfo.OBITEMSEQ;
  62. line.OBPARSETYPE = tbinfo.OBPARSETYPE;
  63. line.OBCHECKTYPE = tbinfo.OBCHECKTYPE;
  64. line.OBVALID = tbinfo.OBVALID;
  65. line.SNLENGTH = tbinfo.SNLENGTH;
  66. line.NeedVendor = tbinfo.NeedVendor
  67. ;
  68. if (isNew)
  69. db.ICSOPBOMDETAIL.InsertOnSubmit(line);
  70. db.SubmitChanges();
  71. }
  72. db.Transaction.Commit();
  73. }
  74. catch (Exception ex)
  75. {
  76. db.Transaction.Rollback();
  77. throw ex;
  78. }
  79. }
  80. public static void deleteInfo(string dsconn, List<string> codeList)
  81. {
  82. FramDataContext db = new FramDataContext(dsconn);
  83. db.Connection.Open();
  84. db.Transaction = db.Connection.BeginTransaction();
  85. try
  86. {
  87. var lines = db.ICSOPBOMDETAIL.Where(a => codeList.Contains(a.ITEMCODE) && codeList.Contains(a.OBCODE) && codeList.Contains(a.OPBOMVER) && codeList.Contains(a.OBITEMCODE) && codeList.Contains(a.WorkPoint) && codeList.Contains(a.ACTIONTYPE.ToString()));
  88. db.ICSOPBOMDETAIL.DeleteAllOnSubmit(lines);
  89. db.SubmitChanges();
  90. db.Transaction.Commit();
  91. }
  92. catch (Exception ex)
  93. {
  94. db.Transaction.Rollback();
  95. throw ex;
  96. }
  97. }
  98. public List<ICSOPBOMDETAIL> QueryOPBOMDetail(string itemCode, string OPID, string BOMCode, string BOMVersion, string routeCode, string OPCode, int actiontype)
  99. {
  100. return QueryOPBOMDetail(itemCode, OPID, BOMCode, BOMVersion, routeCode, OPCode, actiontype, false);
  101. }
  102. public List<ICSOPBOMDETAIL> QueryOPBOMDetail(string itemCode, string OPID, string BOMCode, string BOMVersion, string routeCode, string OPCode, int actiontype, bool onlyValid)
  103. {
  104. string selectSql = "select * from icsopbomdetail a left outer join Base_Inventory b ";
  105. selectSql += "on a.workpoint = b.workpoint ";
  106. selectSql += "and a.itemcode = b.invcode ";
  107. selectSql += "where 1=1 ";
  108. if (actiontype >= 0)
  109. {
  110. selectSql += "and ActionType = " + actiontype.ToString() + " ";
  111. }
  112. string tmpString = string.Empty;
  113. if ((itemCode != string.Empty) && (itemCode.Trim() != string.Empty))
  114. {
  115. tmpString += " and a.itemcode ='" + itemCode.Trim() + "'";
  116. }
  117. if ((OPID != string.Empty) && (OPID.Trim() != string.Empty))
  118. {
  119. tmpString += " and a.opid ='" + OPID.Trim() + "'";
  120. }
  121. if ((BOMCode != string.Empty) && (BOMCode.Trim() != string.Empty))
  122. {
  123. tmpString += " and a.obcode ='" + BOMCode.Trim() + "'";
  124. }
  125. if ((BOMVersion != string.Empty) && (BOMVersion.Trim() != string.Empty))
  126. {
  127. tmpString += " and a.opbomver ='" + BOMVersion.Trim() + "'";
  128. }
  129. if ((OPCode != string.Empty) && (OPCode.Trim() != string.Empty))
  130. {
  131. tmpString += " and a.opcode ='" + OPCode.Trim() + "'";
  132. }
  133. if ((routeCode != string.Empty) && (routeCode.Trim() != string.Empty))
  134. {
  135. tmpString += " and a.opcode in (select opcode from icsitemroute2op where routecode ='" + routeCode.Trim() + "' and workpoint='" + AppConfig.WorkPointCode+"') ";
  136. tmpString += " and a.obcode in (select obcode from icsopbom where obroute ='" + routeCode.Trim() + "' and workpoint='" + AppConfig.WorkPointCode+"') ";
  137. }
  138. tmpString += " and a.workpoint='" + AppConfig.WorkPointCode+"'";
  139. if (onlyValid)
  140. {
  141. tmpString += " and a.obvalid = 1 ";
  142. }
  143. List<ICSOPBOMDETAIL> list = this._domainDataProvider.ExecuteQuery<ICSOPBOMDETAIL>(tmpString).ToList();
  144. return list;
  145. }
  146. public List<ICSOPBOMDETAIL> QueryOPBOMDetail(string itemCode, string mCode, string OPID, string BOMCode, string BOMVersion, string routeCode, string OPCode, int actiontype, bool onlyValid)
  147. {
  148. string selectSql = "select * from icsopbomdetail a left outer join Base_Inventory b ";
  149. selectSql += "on a.workpoint = b.workpoint ";
  150. selectSql += "and a.itemcode = b.invcode ";
  151. selectSql += "where 1=1 ";
  152. if (actiontype >= 0)
  153. {
  154. selectSql += "and ActionType = " + actiontype.ToString() + " ";
  155. }
  156. selectSql += " {0}";
  157. string tmpString = string.Empty;
  158. if ((itemCode != string.Empty) && (itemCode.Trim() != string.Empty))
  159. {
  160. tmpString += " and a.itemcode ='" + itemCode.Trim() + "'";
  161. }
  162. if ((mCode != string.Empty) && (mCode.Trim() != string.Empty))
  163. {
  164. tmpString += " and (a.OBITEMCODE ='" + mCode.Trim()
  165. + "' or a.obsitemcode ='" + mCode.Trim() + "')";
  166. }
  167. if ((OPID != string.Empty) && (OPID.Trim() != string.Empty))
  168. {
  169. tmpString += " and a.opid ='" + OPID.Trim() + "'";
  170. }
  171. if ((BOMCode != string.Empty) && (BOMCode.Trim() != string.Empty))
  172. {
  173. tmpString += " and a.obcode ='" + BOMCode.Trim() + "'";
  174. }
  175. if ((BOMVersion != string.Empty) && (BOMVersion.Trim() != string.Empty))
  176. {
  177. tmpString += " and a.opbomver ='" + BOMVersion.Trim() + "'";
  178. }
  179. if ((OPCode != string.Empty) && (OPCode.Trim() != string.Empty))
  180. {
  181. tmpString += " and a.opcode ='" + OPCode.Trim() + "'";
  182. }
  183. if ((routeCode != string.Empty) && (routeCode.Trim() != string.Empty))
  184. {
  185. tmpString += " and a.opcode in (select opcode from icsitemroute2op where routecode ='" + routeCode.Trim() + "' and workpoint='" + AppConfig.WorkPointCode+"') ";
  186. tmpString += " and a.obcode in (select obcode from icsopbom where obroute ='" + routeCode.Trim() + "' and workpoint='" + AppConfig.WorkPointCode+"') ";
  187. }
  188. tmpString += " and a.workpoint='" + AppConfig.WorkPointCode+"'";
  189. if (onlyValid)
  190. {
  191. tmpString += " and a.obvalid = 1 ";
  192. }
  193. List<ICSOPBOMDETAIL> list = this._domainDataProvider.ExecuteQuery<ICSOPBOMDETAIL>(tmpString).ToList();
  194. return list;
  195. }
  196. public List<ICSOPBOMDETAIL> QueryOPBOMDetail(string itemCode, string OPID, string BOMCode, string BOMVersion, string routeCode, string OPCode, bool check, bool onlyValid)
  197. {
  198. string selectSql = "select * from ICSopbomdetail where actiontype = 1 {0}";
  199. string tmpString = string.Empty;
  200. if ((itemCode != string.Empty) && (itemCode.Trim() != string.Empty))
  201. {
  202. tmpString += " and itemcode ='" + itemCode.Trim() + "'";
  203. }
  204. if ((OPID != string.Empty) && (OPID.Trim() != string.Empty))
  205. {
  206. tmpString += " and opid ='" + OPID.Trim() + "'";
  207. }
  208. if ((BOMCode != string.Empty) && (BOMCode.Trim() != string.Empty))
  209. {
  210. tmpString += " and obcode ='" + BOMCode.Trim() + "'";
  211. }
  212. if ((BOMVersion != string.Empty) && (BOMVersion.Trim() != string.Empty))
  213. {
  214. tmpString += " and opbomver ='" + BOMVersion.Trim() + "'";
  215. }
  216. if ((OPCode != string.Empty) && (OPCode.Trim() != string.Empty))
  217. {
  218. tmpString += " and opcode ='" + OPCode.Trim() + "'";
  219. }
  220. if (check == true)
  221. {
  222. tmpString += " and OBITEMCONTYPE='item_control_keyparts'";
  223. }
  224. if ((routeCode != string.Empty) && (routeCode.Trim() != string.Empty))
  225. {
  226. tmpString += " and opcode in (select opcode from icsitemroute2op where routecode ='" + routeCode.Trim() + "' and workPoint='" + AppConfig.WorkPointCode + "')";
  227. tmpString += " and obcode in (select obcode from icsopbom where obroute ='" + routeCode.Trim() + "' and workPoint='" + AppConfig.WorkPointCode + "') ";
  228. }
  229. if (onlyValid)
  230. {
  231. tmpString += " and icsopbomdetail.obvalid = 1 ";
  232. }
  233. tmpString += " and workPoint='" + AppConfig.WorkPointCode+"'";
  234. tmpString += "order by obitemseq";
  235. return this._domainDataProvider.ExecuteQuery<ICSOPBOMDETAIL>(String.Format(selectSql, tmpString)).ToList();
  236. }
  237. public List<ICSOPBOMDETAIL> GetOPBOMDetails(string moCode, string routeCode, string opCode, bool check, bool onlyValid)
  238. {
  239. ICSMO currentMO = this._domainDataProvider.ICSMO.SingleOrDefault<ICSMO>(a => a.MOBOM == moCode && a.WorkPoint == AppConfig.WorkPointCode);
  240. if (currentMO == null)
  241. {
  242. throw new Exception("$Error_MONotExisted");
  243. }
  244. ICSOPBOMDAL dal = new ICSOPBOMDAL(this._domainDataProvider);
  245. ICSOPBOM currentOPBOM = dal.GetOPBOMByRouteCode(currentMO.ITEMCODE, routeCode, currentMO.MOVER);
  246. return this.QueryOPBOMDetail(currentOPBOM.ITEMCODE, string.Empty, currentOPBOM.OBCODE, currentOPBOM.OPBOMVER, currentOPBOM.OBROUTE, opCode,check, onlyValid);
  247. }
  248. public List<ICSOPBOMDETAIL> QueryOPDropBOMDetail(string itemCode, string OPID, string BOMCode, string BOMVersion, string routeCode, string OPCode)
  249. {
  250. string selectSql = "select * from icsopbomdetail where actiontype= 1 " + " {0}";
  251. string tmpString = string.Empty;
  252. if ((itemCode != string.Empty) && (itemCode.Trim() != string.Empty))
  253. {
  254. tmpString += " and itemcode ='" + itemCode.Trim() + "'";
  255. }
  256. if ((OPID != string.Empty) && (OPID.Trim() != string.Empty))
  257. {
  258. tmpString += " and opid ='" + OPID.Trim() + "'";
  259. }
  260. if ((BOMCode != string.Empty) && (BOMCode.Trim() != string.Empty))
  261. {
  262. tmpString += " and obcode ='" + BOMCode.Trim() + "'";
  263. }
  264. if ((BOMVersion != string.Empty) && (BOMVersion.Trim() != string.Empty))
  265. {
  266. tmpString += " and opbomver ='" + BOMVersion.Trim() + "'";
  267. }
  268. if ((OPCode != string.Empty) && (OPCode.Trim() != string.Empty))
  269. {
  270. tmpString += " and opcode ='" + OPCode.Trim() + "'";
  271. }
  272. if ((routeCode != string.Empty) && (routeCode.Trim() != string.Empty))
  273. {
  274. tmpString += " and opcode in (select opcode from icsitemroute2op where routecode ='" + routeCode.Trim() + "' and WorkPoint='"+AppConfig.WorkPointCode+"')";
  275. }
  276. tmpString += " and WorkPoint='"+AppConfig.WorkPointCode+"'";
  277. return this._domainDataProvider.ExecuteQuery<ICSOPBOMDETAIL>(String.Format(selectSql, tmpString)).ToList();
  278. }
  279. }
  280. }