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

543 lines
21 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using ICSSoft.Base.Config.DBHelper;
  6. using System.Data;
  7. using ICSSoft.Frame.Data.Entity;
  8. using System.Data.Linq;
  9. using System.Data.SqlClient;
  10. using ICSSoft.Base.Config.AppConfig;
  11. namespace ICSSoft.Frame.Data.DAL
  12. {
  13. public class ICSMO2LotDAL
  14. {
  15. #region 增加修改
  16. public static void AddAndEdit(List<FormICSMO2LotUIModel> equipmentInfoList, string dsconn)
  17. {
  18. FramDataContext db = new FramDataContext(dsconn);
  19. db.Connection.Open();
  20. db.Transaction = db.Connection.BeginTransaction();
  21. try
  22. {
  23. foreach (FormICSMO2LotUIModel equipmentInfo in equipmentInfoList)
  24. {
  25. bool isNew = false;
  26. var line = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == equipmentInfo.LotNO);
  27. if (line == null)
  28. {
  29. isNew = true;
  30. line = new ICSITEMLot();
  31. line.ID = AppConfig.GetGuid();
  32. line.LotNO = equipmentInfo.LotNO;
  33. }
  34. line.ItemCode = equipmentInfo.ItemCode;
  35. line.TransNO = equipmentInfo.TransNO;
  36. line.TransLine = equipmentInfo.TransLine;
  37. line.VENDORITEMCODE = equipmentInfo.VENDORITEMCODE;
  38. line.VENDORCODE = equipmentInfo.VENDORCODE;
  39. line.VenderLotNO = equipmentInfo.VenderLotNO;
  40. line.PRODUCTDATE = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss"); ;
  41. line.LOTQTY = equipmentInfo.LOTQTY;
  42. line.ACTIVE = "Y";//传入固定值
  43. line.Exdate = Convert.ToDateTime("2999-12-31 00:00:00.000");//传入固定值
  44. line.WorkPoint = AppConfig.WorkPointCode;//传入固定值
  45. line.MUSER = equipmentInfo.MUSER;
  46. line.MUSERName = equipmentInfo.MUSERName;
  47. line.MTIME = Convert.ToDateTime(equipmentInfo.MTIME);
  48. line.TYPE = equipmentInfo.TYPE;
  49. line.EATTRIBUTE1 = equipmentInfo.EATTRIBUTE1;
  50. line.PrintTimes = equipmentInfo.PrintTimes;
  51. line.lastPrintUSERID = equipmentInfo.lastPrintUSERID;
  52. line.lastPrintTime = equipmentInfo.lastPrintTime;
  53. line.VoucherNO = equipmentInfo.VoucherNO;
  54. line.VoucherRow = equipmentInfo.VoucherRow;
  55. line.EATTRIBUTE3 = equipmentInfo.EATTRIBUTE3;
  56. line.EATTRIBUTE6 = equipmentInfo.EATTRIBUTE6;
  57. line.EATTRIBUTE7 = equipmentInfo.EATTRIBUTE7;
  58. if (isNew)
  59. db.ICSITEMLot.InsertOnSubmit(line);
  60. db.SubmitChanges();
  61. }
  62. //foreach (WM_BarCode barcode in barcodeList)
  63. //{
  64. // WM_BarCode line1 = new WM_BarCode();
  65. // line1.guid = barcode.guid;
  66. // line1.SrcType = barcode.SrcType;
  67. // line1.Srcguid = barcode.Srcguid;
  68. // line1.RCVShipguid = barcode.RCVShipguid;
  69. // line1.BarCodeNo = barcode.BarCodeNo;
  70. // line1.BarCodeQty = barcode.BarCodeQty;
  71. // line1.ItemGuid = barcode.ItemGuid;
  72. // line1.ItemCode = barcode.ItemCode;
  73. // line1.ItemName = barcode.ItemName;
  74. // line1.MUSERCode = barcode.MUSERCode;
  75. // line1.MUSERName = barcode.MUSERName;
  76. // line1.MTIME = Convert.ToDateTime(barcode.MTIME);
  77. // line1.WorkPointCode = barcode.WorkPointCode;
  78. // line1.BarCodeStatus = barcode.BarCodeStatus;
  79. // //db.WM_BarCode.InsertOnSubmit(line1);
  80. // db.SubmitChanges();
  81. //}
  82. db.SubmitChanges();
  83. db.Transaction.Commit();
  84. }
  85. catch (Exception ex)
  86. {
  87. db.Transaction.Rollback();
  88. throw new Exception(ex.Message);
  89. }
  90. }
  91. public static void AddAndEditList(List<ICSITEMROUTE2OPLot> equipmentInfoList, string dsconn)
  92. {
  93. FramDataContext db = new FramDataContext(dsconn);
  94. db.Connection.Open();
  95. db.Transaction = db.Connection.BeginTransaction();
  96. try
  97. {
  98. int MaxSeqOnwip = 0;
  99. var lineOP = db.ICSLOTONWIP.Where(a => a.LOTNO == equipmentInfoList[0].LotNo);
  100. if (lineOP.Count() > 0)
  101. {
  102. MaxSeqOnwip = lineOP.Max(a => a.OPSEQ);
  103. }
  104. //阿威特生成请购只能在上工序完成并检验之后,不是派工完就可产生,因此工序变更时要管控次序>已请购次序
  105. string sql = @"
  106. SELECT ISNULL(MAX(B.OPSEQ),0) MAXOPSEQ FROM dbo.ICSMO2User A
  107. LEFT JOIN dbo.ICSITEMROUTE2OPLot B ON B.LotNo=A.LOTNO AND B.OPCODE=A.OPCODE
  108. WHERE A.LOTNO='{0}' AND A.PRLineID IS NOT NULL";
  109. sql = string.Format(sql, equipmentInfoList[0].LotNo);
  110. int MaxSeqPR = db.ExecuteQuery<int>(sql).ToList()[0];
  111. foreach (ICSITEMROUTE2OPLot equipmentInfo in equipmentInfoList)
  112. {
  113. var op = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == equipmentInfo.LotNo && a.OPCODE == equipmentInfo.OPCODE && a.ID != equipmentInfo.ID);
  114. if (op != null)
  115. {
  116. throw new Exception("工序代码:" + equipmentInfo.OPCODE + "已存在!");
  117. }
  118. var seq = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == equipmentInfo.LotNo && a.OPSEQ == equipmentInfo.OPSEQ && a.ID != equipmentInfo.ID);
  119. if (seq != null)
  120. {
  121. throw new Exception("工序次序:" + equipmentInfo.OPSEQ + "已存在!");
  122. }
  123. if (MaxSeqOnwip >= equipmentInfo.OPSEQ)
  124. {
  125. throw new Exception("工序次序:" + MaxSeqOnwip.ToString() + ",已报工,只能在此之后添加工序");
  126. }
  127. if (MaxSeqPR >= equipmentInfo.OPSEQ)
  128. {
  129. throw new Exception("工序次序:" + MaxSeqPR.ToString() + ",已产生请购,只能在此之后添加工序");
  130. }
  131. bool isNew = false;
  132. //var line = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.OPCODE == equipmentInfo.OPCODE && a.OPSEQ == equipmentInfo.OPSEQ && a.ROUTECODE == equipmentInfo.ROUTECODE && a.LotNo == equipmentInfo.LotNo);
  133. var line = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.ID == equipmentInfo.ID);
  134. if (line == null)
  135. {
  136. isNew = true;
  137. line = new ICSITEMROUTE2OPLot();
  138. line.ID = AppConfig.GetGuid();
  139. //line.LotNo = equipmentInfo.LotNo;
  140. line.OPCONTROL = equipmentInfo.OPCONTROL;
  141. line.OPTIONALOP = equipmentInfo.OPTIONALOP;
  142. line.IDMERGETYPE = equipmentInfo.IDMERGETYPE;
  143. }
  144. line.ROUTECODE = equipmentInfo.ROUTECODE;
  145. line.OPSEQ = equipmentInfo.OPSEQ;
  146. line.OPCODE = equipmentInfo.OPCODE;
  147. line.LotNo = equipmentInfo.LotNo;
  148. line.IDMERGERULE = equipmentInfo.IDMERGERULE;
  149. line.ITEMCODE = equipmentInfo.ITEMCODE;
  150. line.WorkPoint = equipmentInfo.WorkPoint;//传入固定值
  151. line.MUSER = equipmentInfo.MUSER;
  152. line.MUSERName = equipmentInfo.MUSERName;
  153. line.MTIME = Convert.ToDateTime(equipmentInfo.MTIME);
  154. line.EATTRIBUTE1 = equipmentInfo.EATTRIBUTE1;
  155. line.CtrlType = equipmentInfo.CtrlType;
  156. line.RouteMGR = equipmentInfo.RouteMGR;
  157. line.OPAttr = equipmentInfo.OPAttr;
  158. line.EQPCODE = equipmentInfo.EQPCODE;
  159. line.OPLVL = equipmentInfo.OPLVL;
  160. line.STIME = equipmentInfo.STIME;
  161. line.RTIME = equipmentInfo.RTIME;
  162. line.WTIME = equipmentInfo.WTIME;
  163. line.ISWWRW = equipmentInfo.ISWWRW;
  164. if (isNew)
  165. db.ICSITEMROUTE2OPLot.InsertOnSubmit(line);
  166. db.SubmitChanges();
  167. }
  168. db.SubmitChanges();
  169. db.Transaction.Commit();
  170. }
  171. catch (Exception ex)
  172. {
  173. db.Transaction.Rollback();
  174. throw new Exception(ex.Message);
  175. }
  176. }
  177. #endregion
  178. #region delete
  179. public static void delete(List<String> guidList)
  180. {
  181. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  182. db.Connection.Open();
  183. db.Transaction = db.Connection.BeginTransaction();
  184. try
  185. {
  186. var tempLines = db.ICSMO2User.Where(a => guidList.Contains(a.LOTNO));
  187. if (tempLines != null && tempLines.ToList().Count > 0)
  188. {
  189. throw new Exception("工单已有派工信息,无法删除!");
  190. }
  191. var lines = db.ICSITEMLot.Where(a => guidList.Contains(a.LotNO));
  192. db.ICSITEMLot.DeleteAllOnSubmit(lines);
  193. //删除 ICSITEMROUT2OPLot表中数据删除20190717ZM
  194. var _lines = db.ICSITEMROUTE2OPLot.Where(a => guidList.Contains(a.LotNo));
  195. db.ICSITEMROUTE2OPLot.DeleteAllOnSubmit(_lines);
  196. db.SubmitChanges();
  197. db.Transaction.Commit();
  198. }
  199. catch (Exception ex)
  200. {
  201. db.Transaction.Rollback();
  202. throw ex;
  203. }
  204. }
  205. //删除ICSITEMROUTE2OPLot表中数据ZM
  206. public static void deleteLot(List<String> guidList)
  207. {
  208. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  209. db.Connection.Open();
  210. db.Transaction = db.Connection.BeginTransaction();
  211. try
  212. {
  213. //var tempLines = db.ICSITEMROUTE2OPLot.Where(a => guidList.Contains(a.LotNo));
  214. //if (tempLines != null && tempLines.ToList().Count > 0)
  215. //{
  216. // throw new Exception("工单已有派工信息,无法删除!");
  217. //}
  218. var lines = db.ICSITEMROUTE2OPLot.Where(a => guidList.Contains(a.ID));
  219. db.ICSITEMROUTE2OPLot.DeleteAllOnSubmit(lines);
  220. db.SubmitChanges();
  221. db.Transaction.Commit();
  222. }
  223. catch (Exception ex)
  224. {
  225. db.Transaction.Rollback();
  226. throw ex;
  227. }
  228. }
  229. //删除ICSITEMROUTE2OPLot表中数据ZM
  230. public static void deleteLot(List<ICSITEMROUTE2OPLot> guidList)
  231. {
  232. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  233. db.Connection.Open();
  234. db.Transaction = db.Connection.BeginTransaction();
  235. try
  236. {
  237. foreach (var item in guidList)
  238. {
  239. var onwip = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == item.LotNo && a.ROUTECODE == item.ROUTECODE && a.OPSEQ == item.OPSEQ && a.OPCODE == item.OPCODE && a.WorkPoint == item.WorkPoint);
  240. if (onwip != null)
  241. {
  242. throw new Exception("已开工不能删除,工艺:" + item.ROUTECODE + ",次序:" + item.OPSEQ.ToString() + ",工序:" + item.OPCODE);
  243. }
  244. var users = db.ICSMO2User.Where(a => a.LOTNO == item.LotNo && a.RouteCode == item.ROUTECODE && a.OPCODE == item.OPCODE && a.WorkPoint == item.WorkPoint);
  245. db.ICSMO2User.DeleteAllOnSubmit(users);
  246. var lines = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == item.LotNo && a.ROUTECODE == item.ROUTECODE && a.OPCODE == item.OPCODE && a.WorkPoint == item.WorkPoint);
  247. db.ICSITEMROUTE2OPLot.DeleteAllOnSubmit(lines);
  248. }
  249. db.SubmitChanges();
  250. db.Transaction.Commit();
  251. }
  252. catch (Exception ex)
  253. {
  254. db.Transaction.Rollback();
  255. throw ex;
  256. }
  257. finally
  258. {
  259. db.Connection.Close();
  260. }
  261. }
  262. #endregion
  263. #region 工单是否已生成批次
  264. public static bool IsIncludingInMO2Lot(string moid)
  265. {
  266. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  267. db.Connection.Open();
  268. db.Transaction = db.Connection.BeginTransaction();
  269. try
  270. {
  271. //var line = db.ICSITEMLot.Where(a => a.ID == moid);
  272. var line = from a in db.ICSITEMLot
  273. join b in db.ICSMO on new { MOCODE = a.TransNO, MOSEQ = a.TransLine } equals new { b.MOCODE, b.MOSEQ }
  274. where b.ID == moid
  275. select a;
  276. if (line.ToList().Count > 0)
  277. return true;
  278. else
  279. return false;
  280. }
  281. catch (Exception ex)
  282. {
  283. db.Transaction.Rollback();
  284. throw ex;
  285. }
  286. }
  287. public static DataTable GetMO2LotInfo(List<string> list, string wp, string conn)
  288. {
  289. string sql = @"
  290. SELECT
  291. A.ID,A.MOCODE,A.MOSEQ,A.MOPLANQTY,A.ITEMCODE,A.MOVER,SUM(CASE WHEN ISNULL(B.TransNO,'')='' THEN 0 ELSE 1 END) AS FP
  292. FROM dbo.ICSMO A
  293. LEFT JOIN dbo.ICSITEMLot B ON A.MOCODE=B.TransNO AND A.MOSEQ=B.TransLine AND A.WorkPoint=B.WorkPoint
  294. WHERE A.ID IN (
  295. '{0}'
  296. ) AND A.WorkPoint='{1}'
  297. GROUP BY A.ID,A.MOCODE,A.MOSEQ,A.MOPLANQTY,A.ITEMCODE,A.MOVER,CASE WHEN ISNULL(B.TransNO,'')='' THEN 0 ELSE 1 END
  298. ";
  299. string IDs = string.Join("','", list);
  300. sql = string.Format(sql, IDs, wp);
  301. DataTable dt = DBHelper.ExecuteDataset(conn, CommandType.Text, sql).Tables[0];
  302. return dt;
  303. }
  304. #endregion
  305. public static DataTable searchForItem(string itemcode, string dsconn)
  306. {
  307. string sql = @"select guid,ItemName
  308. from Base_Inventory
  309. where ItemCode='{0}'";
  310. sql = string.Format(sql, itemcode);
  311. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  312. return dt;
  313. }
  314. public static DataTable SelectShiftTypeCode()
  315. {
  316. string sql = @"select SHIFTTYPECODE as [班制代码]
  317. from dbo.ICSSHIFTTYPE
  318. where 1=1";
  319. sql = string.Format(sql);
  320. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  321. return dt;
  322. }
  323. public static DataTable SelectShiftTypeId(string str)
  324. {
  325. string sql = @"select ID
  326. from dbo.ICSSHIFTTYPE
  327. where SHIFTTYPECODE='" + str + "'";
  328. sql = string.Format(sql);
  329. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  330. return dt;
  331. }
  332. #region delete
  333. public static void delete(string moid)
  334. {
  335. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  336. db.Connection.Open();
  337. db.Transaction = db.Connection.BeginTransaction();
  338. try
  339. {
  340. var lines = db.ICSITEMLot.Where(a => a.ID == moid);
  341. db.ICSITEMLot.DeleteAllOnSubmit(lines);
  342. db.SubmitChanges();
  343. db.Transaction.Commit();
  344. }
  345. catch (Exception ex)
  346. {
  347. db.Transaction.Rollback();
  348. throw ex;
  349. }
  350. }
  351. #endregion
  352. public static DataTable GetShiftCode()
  353. {
  354. try
  355. {
  356. string sql = @"select TOP 1 [SHIFTCODE]
  357. FROM [dbo].[ICSSHIFT] order by SHIFTCODE desc";
  358. return DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  359. }
  360. catch (Exception ex)
  361. {
  362. throw ex;
  363. }
  364. }
  365. public static DataTable GetShiftSeqCode()
  366. {
  367. try
  368. {
  369. string sql = @"select TOP 1 [SHIFTSEQ]
  370. FROM [dbo].[ICSSHIFT] order by [SHIFTTYPEID] desc";
  371. return DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  372. }
  373. catch (Exception ex)
  374. {
  375. throw ex;
  376. }
  377. }
  378. #region 工单是否已生成批次
  379. public static DataTable IsUsingMO(string MOCode, string MOSEQ)
  380. {
  381. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  382. db.Connection.Open();
  383. db.Transaction = db.Connection.BeginTransaction();
  384. try
  385. {
  386. string sql = @"SELECT COUNT(*) FROM ICSMOPickLog
  387. WHERE MOCODE='" + MOCode + "' AND MOSEQ='" + MOSEQ + "'";
  388. return DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  389. }
  390. catch (Exception ex)
  391. {
  392. db.Transaction.Rollback();
  393. throw ex;
  394. }
  395. }
  396. #endregion
  397. public static DataTable GetMO2Route(List<string> list, string wp, string conn)
  398. {
  399. // string _sql = @"
  400. // SELECT DISTINCT
  401. // a.ID,
  402. // a.ITEMCODE,
  403. // b.ROUTECODE,
  404. // e.OPCODE,
  405. // e.OPSEQ,
  406. // a.MOCODE,
  407. // a.MOSEQ,
  408. // a.MOPLANQTY,
  409. // e.OPAttr,
  410. // e.CtrlType,
  411. // e.RouteMGR
  412. // FROM ICSMO a
  413. // LEFT JOIN ICSMO2ROUTE b ON ( b.MOID = a.ID) AND b.WorkPoint=a.WorkPoint
  414. // LEFT JOIN ICSITEMROUTE2OP e ON e.ROUTECODE = b.ROUTECODE AND a.ITEMCODE=e.ITEMCODE AND e.WorkPoint=a.WorkPoint
  415. // WHERE
  416. // a.ID in ('{0}') AND a.WorkPoint='{1}'";
  417. // string IDs = string.Join("','", list);
  418. // _sql = string.Format(_sql, IDs, wp);
  419. // DataTable dt = DBHelper.ExecuteDataset(conn, CommandType.Text, _sql).Tables[0];
  420. string sql1 = @"
  421. SELECT DISTINCT
  422. mo.ID,
  423. mo.ITEMCODE,
  424. a.ROUTECODE,
  425. b.OPCODE,
  426. b.OPSEQ,
  427. mo.MOCODE,
  428. mo.MOSEQ,
  429. mo.MOPLANQTY,
  430. b.OPAttr,
  431. b.CtrlType,
  432. b.RouteMGR,
  433. ISNULL(c.OPCODE,'') AS
  434. FROM ICSMO mo
  435. LEFT JOIN ICSMO2ROUTE a ON ( a.MOID = mo.ID) AND a.WorkPoint=mo.WorkPoint
  436. LEFT JOIN ICSITEMROUTE2OP b ON b.ROUTECODE = a.ROUTECODE AND mo.ITEMCODE=b.ITEMCODE AND b.WorkPoint=mo.WorkPoint
  437. LEFT JOIN (
  438. SELECT a.ITEMCODE,a.OPCODE,a.EQPCODE,a.STIME,a.RTIME
  439. FROM ICSEQPSTP a
  440. WHERE ID=(SELECT MAX(ID) FROM ICSEQPSTP WHERE ITEMCODE=a.ITEMCODE AND OPCODE=a.OPCODE AND ISREF='是')
  441. ) c ON b.ITEMCODE=c.ITEMCODE AND b.OPCODE=c.OPCODE
  442. WHERE
  443. mo.ID in ('{0}') AND mo.WorkPoint='{1}'
  444. ";
  445. string IDs = string.Join("','", list);
  446. sql1 = string.Format(sql1, IDs, wp);
  447. DataTable dt = DBHelper.ExecuteDataset(conn, CommandType.Text, sql1).Tables[0];
  448. return dt;
  449. }
  450. public static void GetMO2Route(List<ICSITEMLot> listItemLot, List<ICSITEMROUTE2OPLot> listItemRouteOpLot, string conn)
  451. {
  452. FramDataContext db = new FramDataContext(conn);
  453. db.Connection.Open();
  454. db.Transaction = db.Connection.BeginTransaction();
  455. try
  456. {
  457. db.ICSITEMLot.InsertAllOnSubmit(listItemLot);
  458. db.SubmitChanges();
  459. db.ICSITEMROUTE2OPLot.InsertAllOnSubmit(listItemRouteOpLot);
  460. db.SubmitChanges();
  461. db.Transaction.Commit();
  462. db.Connection.Close();
  463. }
  464. catch (Exception ex)
  465. {
  466. db.Transaction.Rollback();
  467. throw ex;
  468. }
  469. }
  470. }
  471. }