华恒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.

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