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

579 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. //9.4
  35. line.MOPLANENDDATE = equipmentInfo.MOPLANENDDATE;
  36. line.MOPLANSTARTDATE = equipmentInfo.MOPLANSTARTDATE;
  37. line.MCODE = equipmentInfo.MCODE;
  38. line.TransNO = equipmentInfo.TransNO;
  39. line.TransLine = equipmentInfo.TransLine;
  40. line.VENDORITEMCODE = equipmentInfo.VENDORITEMCODE;
  41. line.VENDORCODE = equipmentInfo.VENDORCODE;
  42. line.VenderLotNO = equipmentInfo.VenderLotNO;
  43. line.PRODUCTDATE = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss"); ;
  44. line.LOTQTY = equipmentInfo.LOTQTY;
  45. line.ACTIVE = "Y";//传入固定值
  46. line.Exdate = Convert.ToDateTime("2999-12-31 00:00:00.000");//传入固定值
  47. line.WorkPoint = "6000";//传入固定值
  48. line.MUSER = equipmentInfo.MUSER;
  49. line.MUSERName = equipmentInfo.MUSERName;
  50. line.MTIME = Convert.ToDateTime(equipmentInfo.MTIME);
  51. line.TYPE = equipmentInfo.TYPE;
  52. line.EATTRIBUTE1 = equipmentInfo.EATTRIBUTE1;
  53. line.PrintTimes = equipmentInfo.PrintTimes;
  54. line.lastPrintUSERID = equipmentInfo.lastPrintUSERID;
  55. line.lastPrintTime = equipmentInfo.lastPrintTime;
  56. line.VoucherNO = equipmentInfo.VoucherNO;
  57. line.VoucherRow = equipmentInfo.VoucherRow;
  58. line.EATTRIBUTE3 = equipmentInfo.EATTRIBUTE3;
  59. line.EATTRIBUTE6 = equipmentInfo.EATTRIBUTE6;
  60. line.EATTRIBUTE7 = equipmentInfo.EATTRIBUTE7;
  61. // line.EATTRIBUTE2 = "已分批";
  62. #region 修改ICSMO表EATTRIBUTE2栏位将该行工单标记为已分批
  63. var lines = db.ICSMO.SingleOrDefault(a => a.MOCODE == line.TransNO && a.MOSEQ == line.TransLine);
  64. if (lines != null)
  65. {
  66. lines.EATTRIBUTE2 = "已分批";
  67. //db.SubmitChanges();
  68. }
  69. #endregion
  70. if (isNew)
  71. db.ICSITEMLot.InsertOnSubmit(line);
  72. db.SubmitChanges();
  73. }
  74. //foreach (WM_BarCode barcode in barcodeList)
  75. //{
  76. // WM_BarCode line1 = new WM_BarCode();
  77. // line1.guid = barcode.guid;
  78. // line1.SrcType = barcode.SrcType;
  79. // line1.Srcguid = barcode.Srcguid;
  80. // line1.RCVShipguid = barcode.RCVShipguid;
  81. // line1.BarCodeNo = barcode.BarCodeNo;
  82. // line1.BarCodeQty = barcode.BarCodeQty;
  83. // line1.ItemGuid = barcode.ItemGuid;
  84. // line1.ItemCode = barcode.ItemCode;
  85. // line1.ItemName = barcode.ItemName;
  86. // line1.MUSERCode = barcode.MUSERCode;
  87. // line1.MUSERName = barcode.MUSERName;
  88. // line1.MTIME = Convert.ToDateTime(barcode.MTIME);
  89. // line1.WorkPointCode = barcode.WorkPointCode;
  90. // line1.BarCodeStatus = barcode.BarCodeStatus;
  91. // //db.WM_BarCode.InsertOnSubmit(line1);
  92. // db.SubmitChanges();
  93. //}
  94. db.SubmitChanges();
  95. db.Transaction.Commit();
  96. }
  97. catch (Exception ex)
  98. {
  99. db.Transaction.Rollback();
  100. throw new Exception(ex.Message);
  101. }
  102. }
  103. public static void AddAndEditList(List<ICSITEMROUTE2OPLot> equipmentInfoList, string dsconn)
  104. {
  105. FramDataContext db = new FramDataContext(dsconn);
  106. db.Connection.Open();
  107. db.Transaction = db.Connection.BeginTransaction();
  108. try
  109. {
  110. foreach (ICSITEMROUTE2OPLot equipmentInfo in equipmentInfoList)
  111. {
  112. var op = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == equipmentInfo.LotNo && a.OPCODE == equipmentInfo.OPCODE && a.ID != equipmentInfo.ID);
  113. if (op!=null)
  114. {
  115. throw new Exception("工序代码:" + equipmentInfo.OPCODE + "已存在!");
  116. }
  117. var seq = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == equipmentInfo.LotNo && a.OPSEQ == equipmentInfo.OPSEQ && a.ID != equipmentInfo.ID);
  118. if (seq != null)
  119. {
  120. throw new Exception("工序次序:" + equipmentInfo.OPSEQ + "已存在!");
  121. }
  122. bool isNew = false;
  123. //var line = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.OPCODE == equipmentInfo.OPCODE && a.OPSEQ == equipmentInfo.OPSEQ && a.ROUTECODE == equipmentInfo.ROUTECODE && a.LotNo == equipmentInfo.LotNo);
  124. var line = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.ID == equipmentInfo.ID);
  125. if (line == null)
  126. {
  127. isNew = true;
  128. line = new ICSITEMROUTE2OPLot();
  129. line.ID = AppConfig.GetGuid();
  130. //line.LotNo = equipmentInfo.LotNo;
  131. line.OPCONTROL = equipmentInfo.OPCONTROL;
  132. line.OPTIONALOP = equipmentInfo.OPTIONALOP;
  133. line.IDMERGETYPE = equipmentInfo.IDMERGETYPE;
  134. }
  135. line.ROUTECODE = equipmentInfo.ROUTECODE;
  136. line.OPSEQ = equipmentInfo.OPSEQ;
  137. line.OPCODE = equipmentInfo.OPCODE;
  138. line.LotNo = equipmentInfo.LotNo;
  139. line.IDMERGERULE = equipmentInfo.IDMERGERULE;
  140. line.ITEMCODE = equipmentInfo.ITEMCODE;
  141. line.WorkPoint = equipmentInfo.WorkPoint;//传入固定值
  142. line.MUSER = equipmentInfo.MUSER;
  143. line.MUSERName = equipmentInfo.MUSERName;
  144. line.MTIME = Convert.ToDateTime(equipmentInfo.MTIME);
  145. line.EATTRIBUTE1 = equipmentInfo.EATTRIBUTE1;
  146. if (isNew)
  147. db.ICSITEMROUTE2OPLot.InsertOnSubmit(line);
  148. db.SubmitChanges();
  149. }
  150. db.SubmitChanges();
  151. db.Transaction.Commit();
  152. }
  153. catch (Exception ex)
  154. {
  155. db.Transaction.Rollback();
  156. throw new Exception(ex.Message);
  157. }
  158. }
  159. #endregion
  160. #region delete
  161. public static void delete(List<String> guidList)
  162. {
  163. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  164. db.Connection.Open();
  165. db.Transaction = db.Connection.BeginTransaction();
  166. try
  167. {
  168. var tempLines = db.ICSMO2User.Where(a => guidList.Contains(a.LOTNO));
  169. if (tempLines != null && tempLines.ToList().Count > 0)
  170. {
  171. throw new Exception("工单已有派工信息,无法删除!");
  172. }
  173. var lines = db.ICSITEMLot.Where(a => guidList.Contains(a.LotNO));
  174. db.ICSITEMLot.DeleteAllOnSubmit(lines);
  175. //删除 ICSITEMROUT2OPLot表中数据删除20190717ZM
  176. var _lines = db.ICSITEMROUTE2OPLot.Where(a => guidList.Contains(a.LotNo));
  177. db.ICSITEMROUTE2OPLot.DeleteAllOnSubmit(_lines);
  178. db.SubmitChanges();
  179. db.Transaction.Commit();
  180. }
  181. catch (Exception ex)
  182. {
  183. db.Transaction.Rollback();
  184. throw ex;
  185. }
  186. }
  187. //删除ICSITEMROUTE2OPLot表中数据ZM
  188. public static void deleteLot(List<String> guidList)
  189. {
  190. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  191. db.Connection.Open();
  192. db.Transaction = db.Connection.BeginTransaction();
  193. try
  194. {
  195. //var tempLines = db.ICSITEMROUTE2OPLot.Where(a => guidList.Contains(a.LotNo));
  196. //if (tempLines != null && tempLines.ToList().Count > 0)
  197. //{
  198. // throw new Exception("工单已有派工信息,无法删除!");
  199. //}
  200. var lines = db.ICSITEMROUTE2OPLot.Where(a => guidList.Contains(a.ID));
  201. db.ICSITEMROUTE2OPLot.DeleteAllOnSubmit(lines);
  202. db.SubmitChanges();
  203. db.Transaction.Commit();
  204. }
  205. catch (Exception ex)
  206. {
  207. db.Transaction.Rollback();
  208. throw ex;
  209. }
  210. }
  211. //删除ICSITEMROUTE2OPLot表中数据ZM
  212. public static void deleteLot(List<ICSITEMROUTE2OPLot> guidList)
  213. {
  214. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  215. db.Connection.Open();
  216. db.Transaction = db.Connection.BeginTransaction();
  217. try
  218. {
  219. foreach (var item in guidList)
  220. {
  221. var users = db.ICSMO2User.Where(a => a.LOTNO == item.LotNo && a.OPCODE == item.OPCODE);
  222. db.ICSMO2User.DeleteAllOnSubmit(users);
  223. var lines = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo==item.LotNo && a.OPCODE==item.OPCODE);
  224. db.ICSITEMROUTE2OPLot.DeleteAllOnSubmit(lines);
  225. }
  226. db.SubmitChanges();
  227. db.Transaction.Commit();
  228. }
  229. catch (Exception ex)
  230. {
  231. db.Transaction.Rollback();
  232. throw ex;
  233. }
  234. }
  235. #endregion
  236. #region 工单是否已生成批次
  237. public static bool IsIncludingInMO2Lot(string moid)
  238. {
  239. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  240. db.Connection.Open();
  241. db.Transaction = db.Connection.BeginTransaction();
  242. try
  243. {
  244. //var line = db.ICSITEMLot.Where(a => a.ID == moid);
  245. var line = from a in db.ICSITEMLot
  246. join b in db.ICSMO on new { MOCODE = a.TransNO, MOSEQ=a.TransLine } equals new { b.MOCODE, b.MOSEQ }
  247. where b.ID==moid
  248. select a;
  249. if (line.ToList().Count > 0)
  250. return true;
  251. else
  252. return false;
  253. }
  254. catch (Exception ex)
  255. {
  256. db.Transaction.Rollback();
  257. throw ex;
  258. }
  259. }
  260. #endregion
  261. public static DataTable searchForItem(string itemcode, string dsconn)
  262. {
  263. string sql = @"select guid,ItemName
  264. from Base_Inventory
  265. where ItemCode='{0}'";
  266. sql = string.Format(sql, itemcode);
  267. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  268. return dt;
  269. }
  270. public static DataTable SelectShiftTypeCode()
  271. {
  272. string sql = @"select SHIFTTYPECODE as [班制代码]
  273. from dbo.ICSSHIFTTYPE
  274. where 1=1";
  275. sql = string.Format(sql);
  276. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  277. return dt;
  278. }
  279. public static DataTable SelectShiftTypeId(string str)
  280. {
  281. string sql = @"select ID
  282. from dbo.ICSSHIFTTYPE
  283. where SHIFTTYPECODE='" + str + "'";
  284. sql = string.Format(sql);
  285. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  286. return dt;
  287. }
  288. #region delete
  289. public static void delete(string moid)
  290. {
  291. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  292. db.Connection.Open();
  293. db.Transaction = db.Connection.BeginTransaction();
  294. try
  295. {
  296. var lines = db.ICSITEMLot.Where(a => a.ID == moid);
  297. db.ICSITEMLot.DeleteAllOnSubmit(lines);
  298. db.SubmitChanges();
  299. db.Transaction.Commit();
  300. }
  301. catch (Exception ex)
  302. {
  303. db.Transaction.Rollback();
  304. throw ex;
  305. }
  306. }
  307. #endregion
  308. public static DataTable GetShiftCode()
  309. {
  310. try
  311. {
  312. string sql = @"select TOP 1 [SHIFTCODE]
  313. FROM [dbo].[ICSSHIFT] order by SHIFTCODE desc";
  314. return DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  315. }
  316. catch (Exception ex)
  317. {
  318. throw ex;
  319. }
  320. }
  321. public static DataTable GetShiftSeqCode()
  322. {
  323. try
  324. {
  325. string sql = @"select TOP 1 [SHIFTSEQ]
  326. FROM [dbo].[ICSSHIFT] order by [SHIFTTYPEID] desc";
  327. return DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  328. }
  329. catch (Exception ex)
  330. {
  331. throw ex;
  332. }
  333. }
  334. #region 工单是否已生成批次
  335. public static DataTable IsUsingMO(string MOCode, string MOSEQ)
  336. {
  337. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  338. db.Connection.Open();
  339. db.Transaction = db.Connection.BeginTransaction();
  340. try
  341. {
  342. string sql = @"SELECT COUNT(*) FROM ICSMOPickLog
  343. WHERE MOCODE='" + MOCode + "' AND MOSEQ='" + MOSEQ + "'";
  344. return DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  345. }
  346. catch (Exception ex)
  347. {
  348. db.Transaction.Rollback();
  349. throw ex;
  350. }
  351. }
  352. #endregion
  353. #region 工单是否已生下发
  354. public static DataTable IsSendMO(string MOCode, string MOSEQ)
  355. {
  356. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  357. db.Connection.Open();
  358. db.Transaction = db.Connection.BeginTransaction();
  359. try
  360. {
  361. string sql = @"SELECT MOSTATUS FROM ICSMO
  362. WHERE MOCODE='" + MOCode + "' AND MOSEQ='" + MOSEQ + "'";
  363. return DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  364. }
  365. catch (Exception ex)
  366. {
  367. db.Transaction.Rollback();
  368. throw ex;
  369. }
  370. }
  371. #endregion
  372. #region 一键分批 8.19
  373. public static void OP2LotAddAndEdit(List<ICSITEMLot> lotinfolist, List<ICSITEMROUTE2OPLot> oplotinfolist, string dsconn)
  374. {
  375. FramDataContext db = new FramDataContext(dsconn);
  376. db.Connection.Open();
  377. db.Transaction = db.Connection.BeginTransaction();
  378. try
  379. {
  380. #region 新增ICSITEMLot表
  381. foreach (ICSITEMLot info in lotinfolist)
  382. {
  383. bool isNew = false;
  384. var line = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == info.LotNO);
  385. if (line == null)
  386. {
  387. isNew = true;
  388. line = new ICSITEMLot();
  389. line.ID = info.ID;
  390. line.LotNO = info.LotNO;
  391. }
  392. // line.ItemCODE = info.ItemCODE;
  393. line.MCODE = info.MCODE;
  394. //line.MCODE = "";
  395. line.TransNO = info.TransNO;
  396. line.TransLine = info.TransLine;
  397. line.VENDORITEMCODE = info.VENDORITEMCODE;
  398. line.VENDORCODE = info.VENDORCODE;
  399. line.VenderLotNO = info.VenderLotNO;
  400. line.PRODUCTDATE = info.PRODUCTDATE;
  401. line.LOTQTY = info.LOTQTY;
  402. line.ACTIVE = info.ACTIVE;//传入固定值
  403. line.Exdate = info.Exdate;//传入固定值
  404. line.WorkPoint = info.WorkPoint;
  405. line.MUSER = info.MUSER;
  406. line.MUSERName = info.MUSERName;
  407. line.MTIME = Convert.ToDateTime(info.MTIME);
  408. line.TYPE = info.TYPE;
  409. line.EATTRIBUTE1 = info.EATTRIBUTE1;
  410. line.MOPLANSTARTDATE = info.MOPLANSTARTDATE;
  411. line.MOPLANENDDATE = info.MOPLANENDDATE;
  412. if (isNew)
  413. db.ICSITEMLot.InsertOnSubmit(line);
  414. db.SubmitChanges();
  415. }
  416. #endregion
  417. #region 新增ICSItemRoute2OPLot表
  418. foreach (ICSITEMROUTE2OPLot info in oplotinfolist)
  419. {
  420. var line = new ICSITEMROUTE2OPLot();
  421. line.ID = info.ID;
  422. line.LotNo = info.LotNo;
  423. line.ITEMCODE = info.ITEMCODE;
  424. line.ROUTECODE = info.ROUTECODE;
  425. line.OPCODE = info.OPCODE;
  426. line.OPSEQ = info.OPSEQ;
  427. line.OPCONTROL = info.OPCONTROL;
  428. line.OPTIONALOP = info.OPTIONALOP;
  429. line.IDMERGERULE = info.IDMERGERULE;
  430. line.IDMERGETYPE = info.IDMERGETYPE;
  431. line.WorkPoint = info.WorkPoint;
  432. line.MUSER = info.MUSER;
  433. line.MUSERName = info.MUSERName;
  434. line.MTIME = Convert.ToDateTime(info.MTIME);
  435. line.EATTRIBUTE1 = info.EATTRIBUTE1;
  436. db.ICSITEMROUTE2OPLot.InsertOnSubmit(line);
  437. }
  438. #endregion
  439. #region 修改ICSMO表EATTRIBUTE2栏位将该行工单标记为已分批
  440. foreach (ICSITEMLot info in lotinfolist)
  441. {
  442. var line = db.ICSMO.SingleOrDefault(a => a.MOCODE == info.TransNO && a.MOSEQ == info.TransLine);
  443. if (line != null)
  444. {
  445. line.EATTRIBUTE2 = "已分批";
  446. db.SubmitChanges();
  447. }
  448. }
  449. #endregion
  450. db.Transaction.Commit();
  451. }
  452. catch (Exception ex)
  453. {
  454. db.Transaction.Rollback();
  455. throw new Exception(ex.Message);
  456. }
  457. }
  458. #endregion
  459. public static bool IsPG(string mocode,string moseq) {
  460. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  461. db.Connection.Open();
  462. ICSMO2User user = db.ICSMO2User.Where(a => a.MOCODE == mocode&&a.MOSEQ==Convert.ToInt32(moseq)).FirstOrDefault();
  463. if (user!=null) {
  464. return true;
  465. }
  466. else {
  467. return false;
  468. }
  469. }
  470. public static bool IsKG(string mocode,string moseq)
  471. {
  472. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  473. db.Connection.Open();
  474. ICSLOTSIMULATION user = db.ICSLOTSIMULATION.Where(a => a.MOCODE == mocode&& a.MOSEQ == Convert.ToInt32(moseq)).FirstOrDefault();
  475. if (user != null)
  476. {
  477. return true;
  478. }
  479. else
  480. {
  481. return false;
  482. }
  483. }
  484. }
  485. }