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

4424 lines
170 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.DBHelper;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using ICSSoft.Base.Config.AppConfig;
  10. namespace ICSSoft.Frame.Data.DAL
  11. {
  12. public class ICSNCRDocDAL
  13. {
  14. #region 增加修改
  15. public static void AddPicture(ICSNCRDocPicture info, string dsconn)
  16. {
  17. FramDataContext db = new FramDataContext(dsconn);
  18. db.Connection.Open();
  19. db.Transaction = db.Connection.BeginTransaction();
  20. try
  21. {
  22. bool isNew = false;
  23. var line = db.ICSNCRDocPicture.SingleOrDefault(a => a.PicturePath == info.PicturePath && a.SecDocNO == info.SecDocNO);
  24. if (line != null)
  25. {
  26. return;
  27. }
  28. isNew = true;
  29. line = new ICSNCRDocPicture();
  30. line.ID = AppConfig.GetGuid();
  31. line.SecDocNO = info.SecDocNO;
  32. line.PicturenName = info.PicturenName;
  33. line.PicturePath = info.PicturePath;
  34. line.MUSER = AppConfig.UserId;
  35. line.MUSERName = AppConfig.UserName;
  36. line.MTIME = DateTime.Now;
  37. line.WorkPoint = AppConfig.WorkPointCode;
  38. line.EATTRIBUTE1 = info.EATTRIBUTE1;
  39. if (isNew)
  40. db.ICSNCRDocPicture.InsertOnSubmit(line);
  41. db.SubmitChanges();
  42. db.Transaction.Commit();
  43. }
  44. catch (Exception ex)
  45. {
  46. db.Transaction.Rollback();
  47. throw ex;
  48. }
  49. }
  50. public static ICSNCRDocRectify AddEditRectify(ICSNCRDocRectify info, string dsconn)
  51. {
  52. FramDataContext db = new FramDataContext(dsconn);
  53. db.Connection.Open();
  54. db.Transaction = db.Connection.BeginTransaction();
  55. try
  56. {
  57. bool isNew = false;
  58. if (string.IsNullOrEmpty(info.SecDocNO))
  59. {
  60. throw new Exception("纠正数据异常,请刷新。");
  61. }
  62. var line = db.ICSNCRDocRectify.SingleOrDefault(a => a.SecDocNO == info.SecDocNO);
  63. if (line == null)
  64. {
  65. isNew = true;
  66. line = new ICSNCRDocRectify();
  67. line.ID = AppConfig.GetGuid();
  68. }
  69. var codes = db.ICSNCRDocRectify.Where(a => a.SecDocNO == info.SecDocNO && a.ID != line.ID);
  70. if (codes.ToList().Count > 0)
  71. {
  72. throw new Exception("已存在纠正数据");
  73. }
  74. line.SecDocNO = info.SecDocNO;
  75. line.RectifyContect = info.RectifyContect;
  76. line.MUSER = AppConfig.UserId;
  77. line.MUSERName = AppConfig.UserName;
  78. line.MTIME = DateTime.Now;
  79. line.WorkPoint = AppConfig.WorkPointCode;
  80. line.EATTRIBUTE1 = info.EATTRIBUTE1;
  81. line.EATTRIBUTE2 = info.EATTRIBUTE2;
  82. line.Confirm = info.Confirm;
  83. line.ConfirmPerson = info.ConfirmPerson;
  84. line.ConfirmTime = info.ConfirmTime;
  85. if (isNew)
  86. {
  87. db.ICSNCRDocRectify.InsertOnSubmit(line);
  88. var NCR = db.ICSNCRDoc.SingleOrDefault(a => a.SecDocNO == info.SecDocNO);
  89. NCR.Rectify = line.ID;
  90. }
  91. db.SubmitChanges();
  92. db.Transaction.Commit();
  93. return (ICSNCRDocRectify)line;
  94. }
  95. catch (Exception ex)
  96. {
  97. db.Transaction.Rollback();
  98. throw ex;
  99. }
  100. }
  101. public static ICSNCRDocPrevention AddEditPrevention(ICSNCRDocPrevention info, string dsconn)
  102. {
  103. FramDataContext db = new FramDataContext(dsconn);
  104. db.Connection.Open();
  105. db.Transaction = db.Connection.BeginTransaction();
  106. try
  107. {
  108. bool isNew = false;
  109. if (string.IsNullOrEmpty(info.SecDocNO))
  110. {
  111. throw new Exception("数据异常,请刷新");
  112. }
  113. var line = db.ICSNCRDocPrevention.SingleOrDefault(a => a.SecDocNO == info.SecDocNO);
  114. if (line == null)
  115. {
  116. isNew = true;
  117. line = new ICSNCRDocPrevention();
  118. line.ID = AppConfig.GetGuid();
  119. }
  120. var codes = db.ICSNCRDocPrevention.Where(a => a.SecDocNO == info.SecDocNO && a.ID != line.ID);
  121. if (codes.ToList().Count > 0)
  122. {
  123. throw new Exception("已存在预防数据");
  124. }
  125. line.SecDocNO = info.SecDocNO;
  126. line.PreventionContect = info.PreventionContect;
  127. line.PlanComTime = info.PlanComTime;
  128. line.ActComTime = info.ActComTime;
  129. line.MUSER = AppConfig.UserId;
  130. line.MUSERName = AppConfig.UserName;
  131. line.MTIME = DateTime.Now;
  132. line.WorkPoint = AppConfig.WorkPointCode;
  133. line.EATTRIBUTE1 = info.EATTRIBUTE1;
  134. line.EATTRIBUTE2 = info.EATTRIBUTE2;
  135. line.ManagerConfirm = info.ManagerConfirm;
  136. line.Confirm = info.Confirm;
  137. line.ConfirmPerson = info.ConfirmPerson;
  138. line.ConfirmTime = info.ConfirmTime;
  139. if (isNew)
  140. {
  141. db.ICSNCRDocPrevention.InsertOnSubmit(line);
  142. var NCR = db.ICSNCRDoc.SingleOrDefault(a => a.SecDocNO == info.SecDocNO);
  143. NCR.Prevention = line.ID;
  144. }
  145. db.SubmitChanges();
  146. db.Transaction.Commit();
  147. return (ICSNCRDocPrevention)line;
  148. }
  149. catch (Exception ex)
  150. {
  151. db.Transaction.Rollback();
  152. throw ex;
  153. }
  154. }
  155. public static void EditPreventionActComTime(ICSNCRDocPrevention info, string dsconn)
  156. {
  157. FramDataContext db = new FramDataContext(dsconn);
  158. db.Connection.Open();
  159. db.Transaction = db.Connection.BeginTransaction();
  160. try
  161. {
  162. bool isNew = false;
  163. var line = db.ICSNCRDocPrevention.SingleOrDefault(a => a.ID == info.ID);
  164. if (line == null)
  165. {
  166. throw new Exception("预防数据不存在");
  167. }
  168. line.ActComTime = info.ActComTime;
  169. db.SubmitChanges();
  170. db.Transaction.Commit();
  171. }
  172. catch (Exception ex)
  173. {
  174. db.Transaction.Rollback();
  175. throw ex;
  176. }
  177. }
  178. public static void AddRectifyProcessLog(ICSNCRDocRectifyProcessLog info, string dsconn)
  179. {
  180. FramDataContext db = new FramDataContext(dsconn);
  181. db.Connection.Open();
  182. db.Transaction = db.Connection.BeginTransaction();
  183. try
  184. {
  185. var isNew = true;
  186. var line = new ICSNCRDocRectifyProcessLog();
  187. line.ID = AppConfig.GetGuid();
  188. line.SecDocNO = info.SecDocNO;
  189. line.DoType = info.DoType;
  190. line.RectifyID = info.RectifyID;
  191. line.SubmitDep = info.SubmitDep;
  192. line.SubmitPerson = info.SubmitPerson;
  193. line.CKStatus = info.CKStatus;
  194. line.MUSER = AppConfig.UserId;
  195. line.MUSERName = AppConfig.UserName;
  196. line.MTIME = DateTime.Now;
  197. line.WorkPoint = AppConfig.WorkPointCode;
  198. line.EATTRIBUTE1 = info.EATTRIBUTE1;
  199. line.EATTRIBUTE2 = info.EATTRIBUTE2;
  200. if (isNew)
  201. db.ICSNCRDocRectifyProcessLog.InsertOnSubmit(line);
  202. db.SubmitChanges();
  203. db.Transaction.Commit();
  204. }
  205. catch (Exception ex)
  206. {
  207. db.Transaction.Rollback();
  208. throw ex;
  209. }
  210. }
  211. public static void AddRectifyProcessLog_Type(string SecdocNo, string DoType, int seq, string dsconn)
  212. {
  213. FramDataContext db = new FramDataContext(dsconn);
  214. db.Connection.Open();
  215. db.Transaction = db.Connection.BeginTransaction();
  216. try
  217. {
  218. var isNew = true;
  219. var line = new ICSNCRDocRectifyProcessLog();
  220. line.ID = AppConfig.GetGuid();
  221. var info = db.ICSNCRDocRectifyProcess.SingleOrDefault(a => a.Seq == seq && a.SecDocNO == SecdocNo);
  222. if (info != null)
  223. {
  224. line.SecDocNO = info.SecDocNO;
  225. line.DoType = DoType;
  226. line.RectifyID = info.ID;
  227. line.SubmitDep = info.SubmitDep;
  228. line.SubmitPerson = info.SubmitPerson;
  229. line.CKStatus = info.CKStatus;
  230. line.MUSER = AppConfig.UserId;
  231. line.MUSERName = AppConfig.UserName;
  232. line.MTIME = DateTime.Now;
  233. line.WorkPoint = AppConfig.WorkPointCode;
  234. line.EATTRIBUTE1 = info.EATTRIBUTE1;
  235. line.EATTRIBUTE2 = info.EATTRIBUTE2;
  236. if (isNew)
  237. db.ICSNCRDocRectifyProcessLog.InsertOnSubmit(line);
  238. db.SubmitChanges();
  239. db.Transaction.Commit();
  240. }
  241. }
  242. catch (Exception ex)
  243. {
  244. db.Transaction.Rollback();
  245. throw ex;
  246. }
  247. }
  248. public static void AddPreventionProcessLog(ICSNCRDocPreventionProcessLog info, string dsconn)
  249. {
  250. FramDataContext db = new FramDataContext(dsconn);
  251. db.Connection.Open();
  252. db.Transaction = db.Connection.BeginTransaction();
  253. try
  254. {
  255. var isNew = true;
  256. var line = new ICSNCRDocPreventionProcessLog();
  257. line.ID = AppConfig.GetGuid();
  258. line.SecDocNO = info.SecDocNO;
  259. line.DoType = info.DoType;
  260. line.PreventionID = info.PreventionID;
  261. line.SubmitDep = info.SubmitDep;
  262. line.SubmitPerson = info.SubmitPerson;
  263. line.PendingDepartment = info.PendingDepartment;
  264. line.MUSER = AppConfig.UserId;
  265. line.MUSERName = AppConfig.UserName;
  266. line.MTIME = DateTime.Now;
  267. line.WorkPoint = AppConfig.WorkPointCode;
  268. line.EATTRIBUTE1 = info.EATTRIBUTE1;
  269. line.EATTRIBUTE2 = info.EATTRIBUTE2;
  270. if (isNew)
  271. db.ICSNCRDocPreventionProcessLog.InsertOnSubmit(line);
  272. db.SubmitChanges();
  273. db.Transaction.Commit();
  274. }
  275. catch (Exception ex)
  276. {
  277. db.Transaction.Rollback();
  278. throw ex;
  279. }
  280. }
  281. public static String CreateNCR(ICSNCRDoc lineNew, string Appconstr)
  282. {
  283. FramDataContext db = new FramDataContext(Appconstr);
  284. db.Connection.Open();
  285. db.Transaction = db.Connection.BeginTransaction();
  286. try
  287. {
  288. #region ICSNCRDoc
  289. bool isNew = true;
  290. var line = new ICSNCRDoc(); ;
  291. line.ID = AppConfig.GetGuid();
  292. var codes = db.ICSNCRDoc.Where(a => a.SecDocNO == lineNew.SecDocNO);
  293. if (codes.ToList().Count > 0)
  294. {
  295. throw new Exception("此参数类型已存在");
  296. }
  297. // var codesLOT = db.ICSNCRDoc.Where(a => a.SrcDocInfo == lineNew.SrcDocInfo);
  298. // if (codesLOT.ToList().Count > 0)
  299. // {
  300. // throw new Exception("此批号已申请NCR");
  301. // }
  302. line.OPCode = lineNew.OPCode;
  303. line.SecDocNO = lineNew.SecDocNO;
  304. if (string.IsNullOrEmpty(lineNew.SecDocCreateDep))
  305. {
  306. line.SecDocCreateDep = selectDepByUserCode(lineNew.SecDocCreateUser, Appconstr);
  307. }
  308. else
  309. {
  310. line.SecDocCreateDep = lineNew.SecDocCreateDep;
  311. }
  312. line.SecDocCreateTime = lineNew.SecDocCreateTime;
  313. line.SecDocCreateUser = lineNew.SecDocCreateUser;
  314. line.SecDocCreateUserName = lineNew.SecDocCreateUserName;
  315. line.SecDocNO = lineNew.SecDocNO;
  316. line.SecDocOKTime = lineNew.SecDocOKTime;
  317. line.SecDocSeq = lineNew.SecDocSeq;
  318. line.SecDocStatus = lineNew.SecDocStatus;
  319. line.SecDocType = lineNew.SecDocType;
  320. line.SrcDocInfo = lineNew.SrcDocInfo;
  321. line.TimeLimit = lineNew.TimeLimit;
  322. line.ToPostList = lineNew.ToPostList;
  323. line.ToUserList = lineNew.ToUserList;
  324. line.TreatResult = lineNew.TreatResult;
  325. line.TreatWay = lineNew.TreatWay;
  326. line.VendorDesc = lineNew.VendorDesc;
  327. line.VendorState = lineNew.VendorState;
  328. line.DefectType = lineNew.DefectType;
  329. line.BadReason = lineNew.BadReason;
  330. line.CCPostList = lineNew.CCPostList;
  331. line.CCUserList = lineNew.CCUserList;
  332. line.ContentDesc = lineNew.ContentDesc;
  333. line.EATTRIBUTE1 = lineNew.EATTRIBUTE1;
  334. line.EATTRIBUTE2 = lineNew.EATTRIBUTE2;
  335. line.EATTRIBUTE3 = lineNew.EATTRIBUTE3;
  336. line.EATTRIBUTE4 = lineNew.EATTRIBUTE4;
  337. line.EQPCode = lineNew.EQPCode;
  338. line.ErrorType = lineNew.ErrorType;
  339. line.IsNeedPrevention = lineNew.IsNeedPrevention;
  340. line.TreatCost = lineNew.TreatCost;
  341. line.ItemCode = lineNew.ItemCode;
  342. line.LOTNO = lineNew.LOTNO;
  343. line.OKUserList = lineNew.OKUserList;
  344. line.OPCode = lineNew.OPCode;
  345. line.Urgent = "一般";
  346. line.IsCPIR = lineNew.IsCPIR;
  347. line.CPIRItemType = lineNew.CPIRItemType;
  348. //部件:物料描述取'-'之前的
  349. //Base_Inventory item = ICSBase_InventoryDAL.select(lineNew.ItemCode, Appconstr);
  350. //if (item != null && string.IsNullOrEmpty(lineNew.Partment))
  351. //{
  352. // string[] desc = item.ItemName.Split('-');
  353. // if (desc != null && desc.Count() > 0)
  354. // {
  355. // line.Partment = desc[0];
  356. // }
  357. // else
  358. // {
  359. // line.Partment = lineNew.Partment;
  360. // }
  361. //}
  362. //else
  363. //{
  364. // line.Partment = lineNew.Partment;
  365. //}
  366. if (string.IsNullOrEmpty(lineNew.Point))
  367. {
  368. line.Point = SelectPoint(line.SrcDocInfo);
  369. }
  370. else
  371. {
  372. line.Point = lineNew.Point;
  373. }
  374. line.Prevention = lineNew.Prevention;
  375. if (!string.IsNullOrEmpty(lineNew.ProjectCode))
  376. {
  377. line.ProjectCode = lineNew.ProjectCode;
  378. }
  379. else
  380. {
  381. if (!string.IsNullOrEmpty(line.SrcDocInfo))
  382. {
  383. string Pro = GetAPSProjectCode(line.SrcDocInfo, Appconstr);//抓取派工表 项目号
  384. if (string.IsNullOrEmpty(Pro))
  385. {
  386. line.ProjectCode = "NA";
  387. }
  388. else
  389. {
  390. line.ProjectCode = Pro;
  391. }
  392. }
  393. else
  394. {
  395. line.ProjectCode = "NA";
  396. }
  397. }
  398. line.Qty = lineNew.Qty;
  399. line.ReadUserList = lineNew.ReadUserList;
  400. line.RealCauseAnalysis = lineNew.RealCauseAnalysis;
  401. line.ReasonDesc = lineNew.ReasonDesc;
  402. line.Rectify = lineNew.Rectify;
  403. line.OPCode = lineNew.OPCode;
  404. if (line.Qty < 1)
  405. {
  406. throw new Exception("NCR数量不能小于1");
  407. }
  408. if (string.IsNullOrEmpty(line.ItemCode) && string.IsNullOrEmpty(line.LOTNO) && string.IsNullOrEmpty(line.ContentDesc) && string.IsNullOrEmpty(line.SrcDocInfo))
  409. {
  410. throw new Exception("无内容,无法申请NCR");
  411. }
  412. //炉号
  413. //if (string.IsNullOrEmpty(lineNew.Furnace) && !string.IsNullOrEmpty(line.SrcDocInfo))
  414. //{
  415. // line.Furnace = GetInvLotFurnaceStrNew(line.SrcDocInfo, Appconstr, "炉号");
  416. //}
  417. //else
  418. //{
  419. // line.Furnace = lineNew.Furnace;
  420. //}
  421. line.PZLJMOCode = lineNew.PZLJMOCode;
  422. line.GongShiFei = lineNew.GongShiFei;
  423. line.CaiLiaoFei = lineNew.CaiLiaoFei;
  424. line.IsWX = lineNew.IsWX;
  425. try
  426. {
  427. if (string.IsNullOrEmpty(lineNew.EATTRIBUTE5))
  428. {
  429. //供应商编码
  430. line.EATTRIBUTE5 = GetInvLotFurnaceStrNew(line.SrcDocInfo, Appconstr, "供应商编码");
  431. }
  432. else
  433. {
  434. string Supply_Item = GetInvLotFurnaceStrNew(line.SrcDocInfo, Appconstr, "供应商编码");
  435. if (!string.IsNullOrEmpty(Supply_Item))
  436. {
  437. List<string> SSI = new List<string>(Supply_Item.Split(','));
  438. List<string> SSWX = new List<string>(lineNew.EATTRIBUTE5.Split(','));
  439. List<string> Supply_List = SSI.Union(SSWX).ToList<string>();
  440. line.EATTRIBUTE5 = string.Join(",", Supply_List);
  441. }
  442. else
  443. {
  444. line.EATTRIBUTE5 = lineNew.EATTRIBUTE5;
  445. }
  446. }
  447. }
  448. catch (Exception ex)
  449. {
  450. }
  451. //暂停lot
  452. ZanTingLot(line.SrcDocInfo, line.OPCode,Appconstr);
  453. line.EATTRIBUTE6 = lineNew.EATTRIBUTE6;
  454. line.EATTRIBUTE7 = lineNew.EATTRIBUTE7;
  455. line.EATTRIBUTE8 = lineNew.EATTRIBUTE8;
  456. line.IsTuiLiao = lineNew.IsTuiLiao;
  457. if (lineNew.NGQty == null)
  458. {
  459. line.NGQty = lineNew.Qty;
  460. }
  461. line.MUSER = AppConfig.UserId;
  462. line.MUSERName = AppConfig.UserName;
  463. line.MTIME = DateTime.Now;
  464. line.WorkPoint = AppConfig.WorkPointCode;
  465. if (isNew)
  466. db.ICSNCRDoc.InsertOnSubmit(line);
  467. db.SubmitChanges();
  468. #endregion
  469. //#region ICSNCRDocDoDetail
  470. //linedoNew.SecDocID = line.ID;
  471. //linedoNew.SecDocNO = line.SecDocNO;
  472. //linedoNew.SecDocSeq = line.SecDocSeq;
  473. //linedoNew.DoUser = line.SecDocCreateUser;
  474. //linedoNew.DoUserName = line.SecDocCreateUserName;
  475. //linedoNew.DoTIME = line.SecDocCreateTime;
  476. //linedoNew.ReadUsers = "";
  477. //AddandEditICSNCRDocDoDetail(linedoNew, db);
  478. //#endregion
  479. db.Transaction.Commit();
  480. return line.ID;
  481. }
  482. catch (Exception ex)
  483. {
  484. db.Transaction.Rollback();
  485. throw new Exception(ex.Message);
  486. }
  487. }
  488. //0913生产报工_批次判退回NCR
  489. public static String CreateNCRS(ICSNCRDoc lineNew, string Appconstr)
  490. {
  491. FramDataContext db = new FramDataContext(Appconstr);
  492. db.Connection.Open();
  493. db.Transaction = db.Connection.BeginTransaction();
  494. try
  495. {
  496. #region ICSNCRDoc
  497. bool isNew = true;
  498. var line = new ICSNCRDoc(); ;
  499. line.ID = AppConfig.GetGuid();
  500. var codes = db.ICSNCRDoc.Where(a => a.SecDocNO == lineNew.SecDocNO);
  501. if (codes.ToList().Count > 0)
  502. {
  503. throw new Exception("此参数类型已存在");
  504. }
  505. // var codesLOT = db.ICSNCRDoc.Where(a => a.SrcDocInfo == lineNew.SrcDocInfo);
  506. // if (codesLOT.ToList().Count > 0)
  507. // {
  508. // throw new Exception("此批号已申请NCR");
  509. // }
  510. line.OPCode = lineNew.OPCode;
  511. line.SecDocNO = lineNew.SecDocNO;
  512. if (string.IsNullOrEmpty(lineNew.SecDocCreateDep))
  513. {
  514. line.SecDocCreateDep = selectDepByUserCode(lineNew.SecDocCreateUser, Appconstr);
  515. }
  516. else
  517. {
  518. line.SecDocCreateDep = lineNew.SecDocCreateDep;
  519. }
  520. line.SecDocCreateTime = lineNew.SecDocCreateTime;
  521. line.SecDocCreateUser = lineNew.SecDocCreateUser;
  522. line.SecDocCreateUserName = lineNew.SecDocCreateUserName;
  523. line.SecDocNO = lineNew.SecDocNO;
  524. line.SecDocOKTime = lineNew.SecDocOKTime;
  525. line.SecDocSeq = lineNew.SecDocSeq;
  526. line.SecDocStatus = lineNew.SecDocStatus;
  527. line.SecDocType = lineNew.SecDocType;
  528. line.SrcDocInfo = lineNew.SrcDocInfo;
  529. line.TimeLimit = lineNew.TimeLimit;
  530. line.ToPostList = lineNew.ToPostList;
  531. line.ToUserList = lineNew.ToUserList;
  532. line.TreatResult = lineNew.TreatResult;
  533. line.TreatWay = lineNew.TreatWay;
  534. line.VendorDesc = lineNew.VendorDesc;
  535. line.VendorState = lineNew.VendorState;
  536. line.DefectType = lineNew.DefectType;
  537. line.BadReason = lineNew.BadReason;
  538. line.CCPostList = lineNew.CCPostList;
  539. line.CCUserList = lineNew.CCUserList;
  540. line.ContentDesc = lineNew.ContentDesc;
  541. line.EATTRIBUTE1 = lineNew.EATTRIBUTE1;
  542. line.EATTRIBUTE2 = lineNew.EATTRIBUTE2;
  543. line.EATTRIBUTE3 = lineNew.EATTRIBUTE3;
  544. line.EATTRIBUTE4 = lineNew.EATTRIBUTE4;
  545. line.EQPCode = lineNew.EQPCode;
  546. line.ErrorType = lineNew.ErrorType;
  547. line.IsNeedPrevention = lineNew.IsNeedPrevention;
  548. line.TreatCost = lineNew.TreatCost;
  549. line.ItemCode = lineNew.ItemCode;
  550. line.LOTNO = lineNew.LOTNO;
  551. line.OKUserList = lineNew.OKUserList;
  552. line.OPCode = lineNew.OPCode;
  553. line.Urgent = "一般";
  554. line.IsCPIR = lineNew.IsCPIR;
  555. line.CPIRItemType = lineNew.CPIRItemType;
  556. if (string.IsNullOrEmpty(lineNew.Point))
  557. {
  558. line.Point = SelectPoint(line.SrcDocInfo);
  559. }
  560. else
  561. {
  562. line.Point = lineNew.Point;
  563. }
  564. line.Prevention = lineNew.Prevention;
  565. if (!string.IsNullOrEmpty(lineNew.ProjectCode))
  566. {
  567. line.ProjectCode = lineNew.ProjectCode;
  568. }
  569. else
  570. {
  571. if (!string.IsNullOrEmpty(line.SrcDocInfo))
  572. {
  573. string Pro = GetAPSProjectCode(line.SrcDocInfo, Appconstr);//抓取派工表 项目号
  574. if (string.IsNullOrEmpty(Pro))
  575. {
  576. line.ProjectCode = "NA";
  577. }
  578. else
  579. {
  580. line.ProjectCode = Pro;
  581. }
  582. }
  583. else
  584. {
  585. line.ProjectCode = "NA";
  586. }
  587. }
  588. line.Qty = lineNew.Qty;
  589. line.ReadUserList = lineNew.ReadUserList;
  590. line.RealCauseAnalysis = lineNew.RealCauseAnalysis;
  591. line.ReasonDesc = lineNew.ReasonDesc;
  592. line.Rectify = lineNew.Rectify;
  593. line.OPCode = lineNew.OPCode;
  594. if (line.Qty < 1)
  595. {
  596. throw new Exception("NCR数量不能小于1");
  597. }
  598. if (string.IsNullOrEmpty(line.ItemCode) && string.IsNullOrEmpty(line.LOTNO) && string.IsNullOrEmpty(line.ContentDesc) && string.IsNullOrEmpty(line.SrcDocInfo))
  599. {
  600. throw new Exception("无内容,无法申请NCR");
  601. }
  602. line.PZLJMOCode = lineNew.PZLJMOCode;
  603. line.GongShiFei = lineNew.GongShiFei;
  604. line.CaiLiaoFei = lineNew.CaiLiaoFei;
  605. line.IsWX = lineNew.IsWX;
  606. try
  607. {
  608. if (string.IsNullOrEmpty(lineNew.EATTRIBUTE5))
  609. {
  610. //供应商编码
  611. line.EATTRIBUTE5 = GetInvLotFurnaceStrNew(line.SrcDocInfo, Appconstr, "供应商编码");
  612. }
  613. else
  614. {
  615. string Supply_Item = GetInvLotFurnaceStrNew(line.SrcDocInfo, Appconstr, "供应商编码");
  616. if (!string.IsNullOrEmpty(Supply_Item))
  617. {
  618. List<string> SSI = new List<string>(Supply_Item.Split(','));
  619. List<string> SSWX = new List<string>(lineNew.EATTRIBUTE5.Split(','));
  620. List<string> Supply_List = SSI.Union(SSWX).ToList<string>();
  621. line.EATTRIBUTE5 = string.Join(",", Supply_List);
  622. }
  623. else
  624. {
  625. line.EATTRIBUTE5 = lineNew.EATTRIBUTE5;
  626. }
  627. }
  628. }
  629. catch (Exception ex)
  630. {
  631. }
  632. //暂停lot
  633. // ZanTingLot(line.SrcDocInfo, line.OPCode, Appconstr);
  634. line.EATTRIBUTE6 = lineNew.EATTRIBUTE6;
  635. line.EATTRIBUTE7 = lineNew.EATTRIBUTE7;
  636. line.EATTRIBUTE8 = lineNew.EATTRIBUTE8;
  637. line.IsTuiLiao = lineNew.IsTuiLiao;
  638. if (lineNew.NGQty == null)
  639. {
  640. line.NGQty = lineNew.Qty;
  641. }
  642. line.MUSER = AppConfig.UserId;
  643. line.MUSERName = AppConfig.UserName;
  644. line.MTIME = DateTime.Now;
  645. line.WorkPoint = AppConfig.WorkPointCode;
  646. if (isNew)
  647. db.ICSNCRDoc.InsertOnSubmit(line);
  648. db.SubmitChanges();
  649. #endregion
  650. //#region ICSNCRDocDoDetail
  651. //linedoNew.SecDocID = line.ID;
  652. //linedoNew.SecDocNO = line.SecDocNO;
  653. //linedoNew.SecDocSeq = line.SecDocSeq;
  654. //linedoNew.DoUser = line.SecDocCreateUser;
  655. //linedoNew.DoUserName = line.SecDocCreateUserName;
  656. //linedoNew.DoTIME = line.SecDocCreateTime;
  657. //linedoNew.ReadUsers = "";
  658. //AddandEditICSNCRDocDoDetail(linedoNew, db);
  659. //#endregion
  660. db.Transaction.Commit();
  661. return line.ID;
  662. }
  663. catch (Exception ex)
  664. {
  665. db.Transaction.Rollback();
  666. throw new Exception(ex.Message);
  667. }
  668. }
  669. //public static void AddandEditICSNCRDocDoDetail(ICSNCRDocDoDetail lineNew, FramDataContext db)
  670. //{
  671. // bool isNew = false;
  672. // var line = db.ICSNCRDocDoDetail.SingleOrDefault(a => a.ID == lineNew.ID);
  673. // if (line == null)
  674. // {
  675. // isNew = true;
  676. // line = new ICSNCRDocDoDetail();
  677. // line.ID = AppConfig.GetGuid();
  678. // }
  679. // line.SecDocID = lineNew.SecDocID;
  680. // line.SecDocNO = lineNew.SecDocNO;
  681. // line.SecDocSeq = lineNew.SecDocSeq;
  682. // line.DepCode = lineNew.DepCode;
  683. // line.DoUser = lineNew.DoUser;
  684. // line.DoUserName = lineNew.DoUserName;
  685. // line.DoTIME = lineNew.DoTIME;
  686. // line.ReadUsers = lineNew.ReadUsers;
  687. // line.EATTRIBUTE1 = lineNew.EATTRIBUTE1;
  688. // line.MUSER = AppConfig.UserCode;
  689. // line.MUSERName = AppConfig.UserName;
  690. // line.MTIME = DateTime.Now;
  691. // line.WorkPoint = AppConfig.WorkPointCode;
  692. // if (isNew)
  693. // db.ICSNCRDocDoDetail.InsertOnSubmit(line);
  694. // db.SubmitChanges();
  695. //}
  696. public static string AddEditNCR(ICSNCRDoc lineNew, string Appconstr)
  697. {
  698. FramDataContext db = new FramDataContext(Appconstr);
  699. db.Connection.Open();
  700. db.Transaction = db.Connection.BeginTransaction();
  701. try
  702. {
  703. bool isNew = false;
  704. var line = db.ICSNCRDoc.SingleOrDefault(a => a.ID == lineNew.ID);
  705. if (line == null)
  706. {
  707. line = new ICSNCRDoc(); ;
  708. line.ID = AppConfig.GetGuid();
  709. }
  710. var codes = db.ICSNCRDoc.Where(a => a.SecDocNO == lineNew.SecDocNO && a.ID != line.ID);
  711. if (codes.ToList().Count > 0)
  712. {
  713. throw new Exception("此参数类型已存在");
  714. }
  715. line.SecDocNO = lineNew.SecDocNO;
  716. if (isNew)
  717. {
  718. if (string.IsNullOrEmpty(lineNew.SecDocCreateDep))
  719. {
  720. line.SecDocCreateDep = selectDepByUserCode(lineNew.SecDocCreateUser, Appconstr);
  721. }
  722. else
  723. {
  724. line.SecDocCreateDep = lineNew.SecDocCreateDep;
  725. }
  726. line.SecDocCreateTime = DateTime.Now;
  727. line.SecDocCreateUser = AppConfig.UserCode;
  728. line.SecDocCreateUserName = AppConfig.UserName;
  729. }
  730. line.SecDocNO = lineNew.SecDocNO;
  731. line.SecDocOKTime = lineNew.SecDocOKTime;
  732. line.SecDocSeq = lineNew.SecDocSeq;
  733. line.SecDocStatus = lineNew.SecDocStatus;
  734. line.SecDocType = lineNew.SecDocType;
  735. line.SrcDocInfo = lineNew.SrcDocInfo;
  736. line.TimeLimit = lineNew.TimeLimit;
  737. line.ToPostList = lineNew.ToPostList;
  738. line.ToUserList = lineNew.ToUserList;
  739. line.TreatResult = lineNew.TreatResult;
  740. line.TreatWay = lineNew.TreatWay;
  741. line.VendorDesc = lineNew.VendorDesc;
  742. line.VendorState = lineNew.VendorState;
  743. line.DefectType = lineNew.DefectType;
  744. line.BadReason = lineNew.BadReason;
  745. line.CCPostList = lineNew.CCPostList;
  746. line.CCUserList = lineNew.CCUserList;
  747. line.ContentDesc = lineNew.ContentDesc;
  748. line.EATTRIBUTE1 = lineNew.EATTRIBUTE1;
  749. line.EATTRIBUTE2 = lineNew.EATTRIBUTE2;
  750. line.EATTRIBUTE3 = lineNew.EATTRIBUTE3;
  751. line.EATTRIBUTE4 = lineNew.EATTRIBUTE4;
  752. line.EQPCode = lineNew.EQPCode;
  753. line.ErrorType = lineNew.ErrorType;
  754. line.IsNeedPrevention = lineNew.IsNeedPrevention;
  755. line.TreatCost = lineNew.TreatCost;
  756. line.ItemCode = lineNew.ItemCode;
  757. line.LOTNO = lineNew.LOTNO;
  758. line.OKUserList = lineNew.OKUserList;
  759. line.OPCode = lineNew.OPCode;
  760. line.Urgent = lineNew.Urgent;
  761. //line.Partment = lineNew.Partment;
  762. line.CPIRItemType = lineNew.CPIRItemType;
  763. line.IsCPIR = lineNew.IsCPIR;
  764. if (isNew)
  765. {
  766. //部件:物料描述取'-'之前的
  767. //Base_Inventory item = ICSBase_InventoryDAL.select(lineNew.ItemCode, Appconstr);
  768. //if (item != null && string.IsNullOrEmpty(lineNew.Partment))
  769. //{
  770. // string[] desc = item.ItemName.Split('-');
  771. // if (desc != null && desc.Count() > 0)
  772. // {
  773. // line.Partment = desc[0];
  774. // }
  775. // else
  776. // {
  777. // line.Partment = lineNew.Partment;
  778. // }
  779. //}
  780. //else
  781. //{
  782. // line.Partment = lineNew.Partment;
  783. //}
  784. }
  785. else
  786. {
  787. line.Partment = lineNew.Partment;
  788. }
  789. if (isNew && string.IsNullOrEmpty(lineNew.Point))
  790. {
  791. line.Point = SelectPoint(line.SrcDocInfo);
  792. }
  793. else { line.Point = lineNew.Point; }
  794. line.Prevention = lineNew.Prevention;
  795. if (isNew)
  796. {
  797. if (!string.IsNullOrEmpty(lineNew.ProjectCode))
  798. {
  799. line.ProjectCode = lineNew.ProjectCode;
  800. }
  801. else
  802. {
  803. line.ProjectCode = "NA";
  804. }
  805. }
  806. else
  807. {
  808. line.ProjectCode = lineNew.ProjectCode;
  809. }
  810. line.Qty = lineNew.Qty;
  811. line.ReadUserList = lineNew.ReadUserList;
  812. line.RealCauseAnalysis = lineNew.RealCauseAnalysis;
  813. line.ReasonDesc = lineNew.ReasonDesc;
  814. line.Rectify = lineNew.Rectify;
  815. line.ManagerConfirm = lineNew.ManagerConfirm;
  816. //炉号
  817. line.Furnace = lineNew.Furnace;
  818. line.PZLJMOCode = lineNew.PZLJMOCode;
  819. line.GongShiFei = lineNew.GongShiFei;
  820. line.CaiLiaoFei = lineNew.CaiLiaoFei;
  821. line.IsWX = lineNew.IsWX;
  822. line.EATTRIBUTE5 = lineNew.EATTRIBUTE5;
  823. line.EATTRIBUTE6 = lineNew.EATTRIBUTE6;
  824. line.EATTRIBUTE7 = lineNew.EATTRIBUTE7;
  825. line.EATTRIBUTE8 = lineNew.EATTRIBUTE8;
  826. line.IsTuiLiao = lineNew.IsTuiLiao;
  827. line.NGQty = lineNew.NGQty;
  828. line.MUSER = AppConfig.UserId;
  829. line.MUSERName = AppConfig.UserName;
  830. line.MTIME = DateTime.Now;
  831. line.WorkPoint = AppConfig.WorkPointCode;
  832. if (isNew)
  833. db.ICSNCRDoc.InsertOnSubmit(line);
  834. db.SubmitChanges();
  835. db.Transaction.Commit();
  836. return line.ID;
  837. }
  838. catch (Exception ex)
  839. {
  840. db.Transaction.Rollback();
  841. throw new Exception(ex.Message);
  842. }
  843. }
  844. public static void Edit_ICSNCRDocRectifyProcess(ICSNCRDocRectifyProcess Info, string Appconstr)
  845. {
  846. FramDataContext db = new FramDataContext(Appconstr);
  847. db.Connection.Open();
  848. db.Transaction = db.Connection.BeginTransaction();
  849. try
  850. {
  851. bool isNew = false;
  852. var line = db.ICSNCRDocRectifyProcess.SingleOrDefault(a => a.ID == Info.ID);
  853. if (line == null)
  854. {
  855. return;
  856. }
  857. line.SubmitTime = Info.SubmitTime;
  858. line.SubmitDep = Info.SubmitDep;
  859. line.SubmitPerson = Info.SubmitPerson;
  860. line.SubmitStatus = Info.SubmitStatus;
  861. line.LimitTime = Info.LimitTime;
  862. line.ConfirmStatus = Info.ConfirmStatus;
  863. line.CKStatus = Info.CKStatus;
  864. line.MUSER = AppConfig.UserId;
  865. line.MUSERName = AppConfig.UserName;
  866. line.MTIME = DateTime.Now;
  867. line.WorkPoint = AppConfig.WorkPointCode;
  868. line.EATTRIBUTE1 = Info.EATTRIBUTE1;
  869. line.EATTRIBUTE2 = Info.EATTRIBUTE2;
  870. if (isNew) db.ICSNCRDocRectifyProcess.InsertOnSubmit(line);
  871. db.SubmitChanges();
  872. db.Transaction.Commit();
  873. }
  874. catch (Exception ex)
  875. {
  876. db.Transaction.Rollback();
  877. throw new Exception(ex.Message);
  878. }
  879. }
  880. public static void Edit_ICSNCRDocPreventionProcess(ICSNCRDocPreventionProcess Info, string Appconstr)
  881. {
  882. FramDataContext db = new FramDataContext(Appconstr);
  883. db.Connection.Open();
  884. db.Transaction = db.Connection.BeginTransaction();
  885. try
  886. {
  887. bool isNew = false;
  888. var line = db.ICSNCRDocPreventionProcess.SingleOrDefault(a => a.ID == Info.ID);
  889. if (line == null)
  890. {
  891. return;
  892. }
  893. line.SubmitTime = Info.SubmitTime;
  894. line.SubmitDep = Info.SubmitDep;
  895. line.SubmitPerson = Info.SubmitPerson;
  896. line.SubmitStatus = Info.SubmitStatus;
  897. line.LimitTime = Info.LimitTime;
  898. line.PendingDepartment = Info.PendingDepartment;
  899. line.ConfirmStatus = Info.ConfirmStatus;
  900. line.MUSER = AppConfig.UserId;
  901. line.MUSERName = AppConfig.UserName;
  902. line.MTIME = DateTime.Now;
  903. line.WorkPoint = AppConfig.WorkPointCode;
  904. line.EATTRIBUTE1 = Info.EATTRIBUTE1;
  905. line.EATTRIBUTE2 = Info.EATTRIBUTE2;
  906. if (isNew) db.ICSNCRDocPreventionProcess.InsertOnSubmit(line);
  907. db.SubmitChanges();
  908. db.Transaction.Commit();
  909. }
  910. catch (Exception ex)
  911. {
  912. db.Transaction.Rollback();
  913. throw new Exception(ex.Message);
  914. }
  915. }
  916. public static void UpdateRectifyProcessDate(DateTime DD, string SecDocNO, int seq, String Appconstr)
  917. {
  918. FramDataContext db = new FramDataContext(Appconstr);
  919. db.Connection.Open();
  920. db.Transaction = db.Connection.BeginTransaction();
  921. try
  922. {
  923. bool isNew = false;
  924. var line = db.ICSNCRDocRectifyProcess.SingleOrDefault(a => a.SecDocNO == SecDocNO && a.Seq == seq);
  925. if (line == null)
  926. {
  927. return;
  928. }
  929. line.LimitTime = DD;
  930. line.MUSER = AppConfig.UserId;
  931. line.MUSERName = AppConfig.UserName;
  932. line.MTIME = DateTime.Now;
  933. line.WorkPoint = AppConfig.WorkPointCode;
  934. db.SubmitChanges();
  935. db.Transaction.Commit();
  936. }
  937. catch (Exception ex)
  938. {
  939. db.Transaction.Rollback();
  940. throw new Exception(ex.Message);
  941. }
  942. }
  943. public static void UpdatePreventionProcessDate(DateTime DD, string SecDocNO, int seq, String Appconstr)
  944. {
  945. FramDataContext db = new FramDataContext(Appconstr);
  946. db.Connection.Open();
  947. db.Transaction = db.Connection.BeginTransaction();
  948. try
  949. {
  950. bool isNew = false;
  951. var line = db.ICSNCRDocPreventionProcess.SingleOrDefault(a => a.SecDocNO == SecDocNO && a.Seq == seq);
  952. if (line == null)
  953. {
  954. return;
  955. }
  956. line.LimitTime = DD;
  957. line.MUSER = AppConfig.UserId;
  958. line.MUSERName = AppConfig.UserName;
  959. line.MTIME = DateTime.Now;
  960. line.WorkPoint = AppConfig.WorkPointCode;
  961. db.SubmitChanges();
  962. db.Transaction.Commit();
  963. }
  964. catch (Exception ex)
  965. {
  966. db.Transaction.Rollback();
  967. throw new Exception(ex.Message);
  968. }
  969. }
  970. public static ICSNCRDocRectifyBonusPenalty AddEditRectifyBonusPenalty(ICSNCRDocRectifyBonusPenalty info, string dsconn)
  971. {
  972. FramDataContext db = new FramDataContext(dsconn);
  973. db.Connection.Open();
  974. db.Transaction = db.Connection.BeginTransaction();
  975. try
  976. {
  977. bool isNew = false;
  978. var line = db.ICSNCRDocRectifyBonusPenalty.SingleOrDefault(a => a.ID == info.ID);
  979. if (line == null)
  980. {
  981. isNew = true;
  982. line = new ICSNCRDocRectifyBonusPenalty();
  983. line.ID = AppConfig.GetGuid();
  984. }
  985. var codes = db.ICSNCRDocRectifyBonusPenalty.Where(a => a.SecDocNO == info.SecDocNO &&
  986. a.Type == info.Type && a.ResponsibleDep == info.ResponsibleDep &&
  987. a.ResponsiblePerson == info.ResponsiblePerson && a.ResponsibleAmount == info.ResponsibleAmount &&
  988. a.ID != line.ID);
  989. if (codes.ToList().Count > 0)
  990. {
  991. throw new Exception("已存在纠正奖惩数据");
  992. }
  993. line.SecDocNO = info.SecDocNO;
  994. line.ResponsibleAmount = info.ResponsibleAmount;
  995. line.ResponsibleDep = info.ResponsibleDep;
  996. line.ResponsiblePerson = info.ResponsiblePerson;
  997. line.Type = info.Type;
  998. line.MUSER = AppConfig.UserId;
  999. line.MUSERName = AppConfig.UserName;
  1000. line.MTIME = DateTime.Now;
  1001. line.WorkPoint = AppConfig.WorkPointCode;
  1002. line.EATTRIBUTE1 = info.EATTRIBUTE1;
  1003. line.EATTRIBUTE2 = info.EATTRIBUTE2;
  1004. if (isNew)
  1005. {
  1006. db.ICSNCRDocRectifyBonusPenalty.InsertOnSubmit(line);
  1007. }
  1008. db.SubmitChanges();
  1009. db.Transaction.Commit();
  1010. return (ICSNCRDocRectifyBonusPenalty)line;
  1011. }
  1012. catch (Exception ex)
  1013. {
  1014. db.Transaction.Rollback();
  1015. throw ex;
  1016. }
  1017. }
  1018. public static void UpdateNCR_ToUserList(string ID, string ToUserList, String Appconstr)
  1019. {
  1020. FramDataContext db = new FramDataContext(Appconstr);
  1021. db.Connection.Open();
  1022. db.Transaction = db.Connection.BeginTransaction();
  1023. try
  1024. {
  1025. var line = db.ICSNCRDoc.SingleOrDefault(a => a.ID == ID);
  1026. if (line == null)
  1027. {
  1028. throw new Exception("无该NCR数据;");
  1029. }
  1030. line.ToUserList = ToUserList;
  1031. line.MUSER = AppConfig.UserId;
  1032. line.MUSERName = AppConfig.UserName;
  1033. line.MTIME = DateTime.Now;
  1034. line.WorkPoint = AppConfig.WorkPointCode;
  1035. db.SubmitChanges();
  1036. db.Transaction.Commit();
  1037. }
  1038. catch (Exception ex)
  1039. {
  1040. db.Transaction.Rollback();
  1041. throw new Exception(ex.Message);
  1042. }
  1043. }
  1044. public static void UpdateNCR_DoPerson(string SecDocNo, string DoPerson, String Appconstr)
  1045. {
  1046. FramDataContext db = new FramDataContext(Appconstr);
  1047. db.Connection.Open();
  1048. db.Transaction = db.Connection.BeginTransaction();
  1049. try
  1050. {
  1051. if (DoPerson != "demo")
  1052. {
  1053. var line = db.ICSNCRDoc.SingleOrDefault(a => a.SecDocNO == SecDocNo);
  1054. if (line == null)
  1055. {
  1056. throw new Exception("无该NCR数据;");
  1057. }
  1058. if (string.IsNullOrEmpty(line.EATTRIBUTE3) && !line.ToUserList.Contains(DoPerson))
  1059. {
  1060. if (string.IsNullOrEmpty(line.EATTRIBUTE3))
  1061. {
  1062. line.EATTRIBUTE3 = DoPerson;
  1063. }
  1064. else
  1065. {
  1066. line.EATTRIBUTE3 = line.EATTRIBUTE3 + "," + DoPerson;
  1067. }
  1068. line.MUSER = AppConfig.UserId;
  1069. line.MUSERName = AppConfig.UserName;
  1070. line.MTIME = DateTime.Now;
  1071. line.WorkPoint = AppConfig.WorkPointCode;
  1072. }
  1073. db.SubmitChanges();
  1074. db.Transaction.Commit();
  1075. }
  1076. }
  1077. catch (Exception ex)
  1078. {
  1079. db.Transaction.Rollback();
  1080. throw new Exception(ex.Message);
  1081. }
  1082. }
  1083. //报废 lot
  1084. public static void BaoFeiLot(string LotnoList, String Appconstr)
  1085. {
  1086. FramDataContext db = new FramDataContext(Appconstr);
  1087. db.Connection.Open();
  1088. db.Transaction = db.Connection.BeginTransaction();
  1089. try
  1090. {
  1091. if (!string.IsNullOrEmpty(LotnoList))
  1092. {
  1093. string[] lots = LotnoList.Split(',');
  1094. for (int i = 0; i < lots.Length; i++)
  1095. {
  1096. if (!string.IsNullOrEmpty(lots[i]))
  1097. {
  1098. //var molot = db.ICSMO2Lot.FirstOrDefault(a => a.LOTNO == lots[i]);
  1099. //if (molot != null )
  1100. //{
  1101. // molot.LOTStatus = "报废";
  1102. // db.SubmitChanges();
  1103. //}
  1104. }
  1105. }
  1106. db.Transaction.Commit();
  1107. }
  1108. }
  1109. catch (Exception ex)
  1110. {
  1111. db.Transaction.Rollback();
  1112. throw new Exception(ex.Message);
  1113. }
  1114. }
  1115. //恢复 新增 lot
  1116. public static void HuiFuLot(string LotnoList, String Appconstr)
  1117. {
  1118. List<string> LotList = new List<string>();
  1119. FramDataContext db = new FramDataContext(Appconstr);
  1120. db.Connection.Open();
  1121. db.Transaction = db.Connection.BeginTransaction();
  1122. try
  1123. {
  1124. if (!string.IsNullOrEmpty(LotnoList))
  1125. {
  1126. string[] lots = LotnoList.Split(',');
  1127. for (int i = 0; i < lots.Length; i++)
  1128. {
  1129. if (!string.IsNullOrEmpty(lots[i]))
  1130. {
  1131. //var molot = db.ICSMO2Lot.FirstOrDefault(a => a.LOTNO == lots[i]);
  1132. //if (molot != null )
  1133. //{
  1134. // molot.LOTStatus = "新增";
  1135. // db.SubmitChanges();
  1136. // LotList.Add(molot.LOTNO);
  1137. // // 对应的整机lot也要恢复新增
  1138. // string mocode = molot.MOCODE;
  1139. // //裸阀工单
  1140. // var mo = db.ICSMO.FirstOrDefault(a => a.MOCODE == mocode && a.ITEMCODE.Length == 10 && a.ITEMCODE.Substring(0, 2) == "11");
  1141. // if (mo != null && !string.IsNullOrEmpty(mo.ProjectCode))
  1142. // {
  1143. // //整机工单
  1144. // var moZJ = db.ICSMO.Where(a => a.ProjectCode == mo.ProjectCode && a.ITEMCODE.Length == 10 && a.ITEMCODE.Substring(0, 2) == "10");
  1145. // if (moZJ != null && moZJ.Count() > 0)
  1146. // {
  1147. // foreach (ICSMO mm in moZJ)
  1148. // {
  1149. // string ZJLot = mm.MOCODE + lots[i].Substring(lots[i].Length - 4, 4);
  1150. // var ZJLot_entity = db.ICSMO2Lot.SingleOrDefault(a => a.LOTNO == ZJLot);
  1151. // if (ZJLot_entity != null)
  1152. // {
  1153. // ZJLot_entity.LOTStatus = "新增";
  1154. // db.SubmitChanges();
  1155. // LotList.Add(ZJLot_entity.LOTNO);
  1156. // }
  1157. // }
  1158. // }
  1159. // }
  1160. //}
  1161. }
  1162. }
  1163. db.Transaction.Commit();
  1164. InsertZTLOTLog(LotList, "新增", Appconstr);
  1165. }
  1166. }
  1167. catch (Exception ex)
  1168. {
  1169. db.Transaction.Rollback();
  1170. throw new Exception(ex.Message);
  1171. }
  1172. }
  1173. //暂停 lot
  1174. public static void ZanTingLot(string LotnoList, string OPCodeList,String Appconstr)
  1175. {
  1176. List<string> LotList = new List<string>();
  1177. FramDataContext db = new FramDataContext(Appconstr);
  1178. db.Connection.Open();
  1179. db.Transaction = db.Connection.BeginTransaction();
  1180. try
  1181. {
  1182. if (!string.IsNullOrEmpty(LotnoList))
  1183. {
  1184. string[] lots = LotnoList.Split(',');
  1185. string[] OPs = OPCodeList.Split(',');
  1186. for (int i = 0; i < lots.Length; i++)
  1187. {
  1188. if (!string.IsNullOrEmpty(lots[i]))
  1189. {
  1190. //var molot = db.ICSMO2Lot.FirstOrDefault(a => a.LotNO == lots[i]);
  1191. var molot = db.ICSLOTSIMULATION.FirstOrDefault(a => a.LOTNO == lots[i]&&a.OPCODE==OPs[i]);
  1192. //SELECT TOP 10 LOTStatus FROM ICSLOTSIMULATION WHERE LOTNO='' AND OPCODE='';
  1193. if (molot != null)
  1194. {
  1195. molot.LOTStatus = "暂停";
  1196. db.SubmitChanges();
  1197. LotList.Add(molot.LOTNO);
  1198. // 对应的整机lot也要暂停
  1199. //string mocode = molot.TransNO;
  1200. //裸阀工单
  1201. //var mo = db.ICSMO.FirstOrDefault(a => a.MOCODE == mocode && a.ITEMCODE.Length == 10 && a.ITEMCODE.Substring(0, 2) == "11");
  1202. //var mo = db.ICSMO.FirstOrDefault(a => a.MOCODE == mocode && a.MOSEQ==molot.TransLine);
  1203. //if (mo != null && !string.IsNullOrEmpty(mo.ProjectCode))
  1204. //{
  1205. // //整机工单
  1206. // //var moZJ = db.ICSMO.Where(a => a.ProjectCode == mo.ProjectCode && a.ITEMCODE.Length == 10 && a.ITEMCODE.Substring(0, 2) == "10");
  1207. // var moZJ = db.ICSMO.Where(a => a.ProjectCode == mo.ProjectCode && a.ITEMCODE.Length == 10 && a.ITEMCODE.Substring(0, 2) == "10");
  1208. // if (moZJ != null && moZJ.Count() > 0)
  1209. // {
  1210. // foreach (ICSMO mm in moZJ)
  1211. // {
  1212. // string ZJLot = mm.MOCODE + lots[i].Substring(lots[i].Length - 4, 4);
  1213. // //var ZJLot_entity = db.ICSMO2Lot.SingleOrDefault(a => a.LOTNO == ZJLot);
  1214. // var ZJLot_entity = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == ZJLot);
  1215. // if (ZJLot_entity != null)
  1216. // {
  1217. // //ZJLot_entity.LOTStatus = "暂停";
  1218. // //db.SubmitChanges();
  1219. // //LotList.Add(ZJLot_entity.LOTNO);
  1220. // }
  1221. // }
  1222. // }
  1223. //}
  1224. }
  1225. }
  1226. }
  1227. db.Transaction.Commit();
  1228. InsertZTLOTLog(LotList,"暂停",Appconstr);
  1229. }
  1230. }
  1231. catch (Exception ex)
  1232. {
  1233. db.Transaction.Rollback();
  1234. throw new Exception(ex.Message);
  1235. }
  1236. }
  1237. private static void InsertZTLOTLog(List<string> LotList, string Type,string Appconstr)
  1238. {
  1239. FramDataContext db = new FramDataContext(Appconstr);
  1240. db.Connection.Open();
  1241. db.Transaction = db.Connection.BeginTransaction();
  1242. try
  1243. {
  1244. if (LotList != null && LotList.Count > 0)
  1245. {
  1246. foreach (string lotno in LotList)
  1247. {
  1248. ICSZanTingLotLog line = new ICSZanTingLotLog();
  1249. line.ID = AppConfig.GetGuid();
  1250. line.LotNo = lotno;
  1251. line.EATTRIBUTE1 = Type;
  1252. line.MUSER = AppConfig.UserCode;
  1253. line.MUSERName = AppConfig.UserName;
  1254. line.MTIME = DateTime.Now;
  1255. line.WorkPoint = AppConfig.WorkPointCode;
  1256. db.ICSZanTingLotLog.InsertOnSubmit(line);
  1257. db.SubmitChanges();
  1258. }
  1259. db.Transaction.Commit();
  1260. }
  1261. }
  1262. catch (Exception ex)
  1263. {
  1264. db.Transaction.Rollback();
  1265. throw new Exception(ex.Message);
  1266. }
  1267. }
  1268. //更新是否需要对外单,五大类栏位
  1269. public static void UpdateNCR_CPIR(string SecDocNo, string IsCPIR, string ItemType, String Appconstr)
  1270. {
  1271. FramDataContext db = new FramDataContext(Appconstr);
  1272. db.Connection.Open();
  1273. db.Transaction = db.Connection.BeginTransaction();
  1274. try
  1275. {
  1276. var line = db.ICSNCRDoc.SingleOrDefault(a => a.SecDocNO == SecDocNo);
  1277. if (line == null)
  1278. {
  1279. throw new Exception("无该NCR数据;");
  1280. }
  1281. line.IsCPIR = IsCPIR;
  1282. line.CPIRItemType = ItemType;
  1283. line.MUSER = AppConfig.UserId;
  1284. line.MUSERName = AppConfig.UserName;
  1285. line.MTIME = DateTime.Now;
  1286. line.WorkPoint = AppConfig.WorkPointCode;
  1287. db.SubmitChanges();
  1288. db.Transaction.Commit();
  1289. }
  1290. catch (Exception ex)
  1291. {
  1292. db.Transaction.Rollback();
  1293. throw new Exception(ex.Message);
  1294. }
  1295. }
  1296. public static void UPDatePZLJMOCode(string MOCode,string SecDocNo, String Appconstr)
  1297. {
  1298. FramDataContext db = new FramDataContext(Appconstr);
  1299. db.Connection.Open();
  1300. db.Transaction = db.Connection.BeginTransaction();
  1301. try
  1302. {
  1303. var line = db.ICSNCRDoc.SingleOrDefault(a => a.SecDocNO == SecDocNo);
  1304. if (line == null)
  1305. {
  1306. throw new Exception("无该NCR数据;");
  1307. }
  1308. line.PZLJMOCode = MOCode;
  1309. db.SubmitChanges();
  1310. db.Transaction.Commit();
  1311. }
  1312. catch (Exception ex)
  1313. {
  1314. db.Transaction.Rollback();
  1315. throw new Exception(ex.Message);
  1316. }
  1317. }
  1318. //lotno 减去NGQTY
  1319. public static void SetLotNGQTY(string LotnoList, decimal NGQty, string opcode, String Appconstr)
  1320. {
  1321. FramDataContext db = new FramDataContext(Appconstr);
  1322. db.Connection.Open();
  1323. db.Transaction = db.Connection.BeginTransaction();
  1324. try
  1325. {
  1326. if (!string.IsNullOrEmpty(LotnoList))
  1327. {
  1328. int NG = Convert.ToInt32(Convert.ToDouble(NGQty));
  1329. string[] lots = LotnoList.Split(',');
  1330. lots = lots.Distinct().ToArray();//去重
  1331. for (int i = 0; i < lots.Length; i++)
  1332. {
  1333. if (!string.IsNullOrEmpty(lots[i]) && lots[i].StartsWith("MO") && !string.IsNullOrEmpty(opcode))
  1334. {
  1335. var molot = db.ICSLOTSIMULATION.FirstOrDefault(a => a.LOTNO == lots[i]);
  1336. if (molot != null)
  1337. {
  1338. if (molot.GOODQTY >= NG)
  1339. {
  1340. molot.GOODQTY = molot.GOODQTY - NG;
  1341. molot.NGQTY = molot.LOTQTY - molot.GOODQTY;
  1342. }
  1343. else
  1344. {
  1345. molot.GOODQTY = 0;
  1346. molot.NGQTY = molot.LOTQTY;
  1347. }
  1348. db.SubmitChanges();
  1349. }
  1350. string[] oplist = opcode.Split(',');
  1351. oplist = oplist.Distinct().ToArray();//去重
  1352. for (int j = 0; j < oplist.Count(); j++)
  1353. {
  1354. string Str_OPCODE = oplist[i];
  1355. var mowip = db.ICSLOTONWIP.Where(a => a.LOTNO == lots[i] && a.OPCODE == Str_OPCODE);
  1356. if (mowip != null)
  1357. {
  1358. foreach (ICSLOTONWIP ww in mowip)
  1359. {
  1360. if (ww.GOODQTY >= NG)
  1361. {
  1362. ww.GOODQTY = ww.GOODQTY - NG;
  1363. ww.NGQTY = (int)ww.LOTQTY - ww.GOODQTY;
  1364. }
  1365. else
  1366. {
  1367. ww.GOODQTY = 0;
  1368. ww.NGQTY = (int)ww.LOTQTY;
  1369. }
  1370. }
  1371. }
  1372. db.SubmitChanges();
  1373. }
  1374. }
  1375. }
  1376. db.Transaction.Commit();
  1377. }
  1378. }
  1379. catch (Exception ex)
  1380. {
  1381. db.Transaction.Rollback();
  1382. throw new Exception(ex.Message);
  1383. }
  1384. }
  1385. #endregion
  1386. #region 查询
  1387. public static ICSNCRDoc select(String ID, String Appconstr)
  1388. {
  1389. FramDataContext db = new FramDataContext(Appconstr);
  1390. db.Connection.Open();
  1391. db.Transaction = db.Connection.BeginTransaction();
  1392. try
  1393. {
  1394. var line = db.ICSNCRDoc.SingleOrDefault(a => a.ID == ID);
  1395. return (ICSNCRDoc)line;
  1396. }
  1397. catch (Exception ex)
  1398. {
  1399. throw new Exception(ex.Message);
  1400. }
  1401. }
  1402. public static ICSNCRDoc selectBySrcDocInfo(String SrcDocInfo, String Appconstr)
  1403. {
  1404. FramDataContext db = new FramDataContext(Appconstr);
  1405. db.Connection.Open();
  1406. db.Transaction = db.Connection.BeginTransaction();
  1407. try
  1408. {
  1409. var line = db.ICSNCRDoc.Where(a => a.SrcDocInfo == SrcDocInfo);
  1410. if (line != null && line.Count() > 0)
  1411. {
  1412. return (ICSNCRDoc)line.First();
  1413. }
  1414. return null;
  1415. }
  1416. catch (Exception ex)
  1417. {
  1418. throw new Exception(ex.Message);
  1419. }
  1420. }
  1421. public static FormICSNCRDataUIModel select_FormICSNCRDataUIModel(String SecDocNO, String Appconstr)
  1422. {
  1423. FramDataContext db = new FramDataContext(Appconstr);
  1424. db.Connection.Open();
  1425. db.Transaction = db.Connection.BeginTransaction();
  1426. try
  1427. {
  1428. FormICSNCRDataUIModel model = new FormICSNCRDataUIModel();
  1429. model.Entity_ICSNCRDoc = selectBySecDocNO(SecDocNO, Appconstr);
  1430. if (model.Entity_ICSNCRDoc != null)
  1431. {
  1432. model.NCRNumber = model.Entity_ICSNCRDoc.SecDocNO;
  1433. }
  1434. else
  1435. { model.NCRNumber = ""; }
  1436. // model.Entity_DoDetail = selectDoDetailBySecDocNO(SecDocNO, db);
  1437. model.Entity_Rectify = SelectRectifyBySecDocNO(SecDocNO, db);
  1438. model.Entity_RectifyBonusPenaltylist = SelectRectifyBonusPenaltyBySecDocNO(SecDocNO, db);
  1439. model.Entity_RectifyProcesslist = SelectRectifyProcessBySecDocNO(SecDocNO, db);
  1440. model.Entity_Prevention = SelectPreventionBySecDocNO(SecDocNO, db);
  1441. model.Entity_PreventionProcesslist = SelectPreventionProcessBySecDocNO(SecDocNO, db);
  1442. model.Entity_Picturelist = SelectPictureBySecDocNO(SecDocNO, db);
  1443. model.PreventionProNamelist = SelectPreventionProName(SecDocNO, Appconstr);
  1444. model.RectifyProNamelist = SelectRectifyProName(SecDocNO, Appconstr);
  1445. return model;
  1446. }
  1447. catch (Exception ex)
  1448. {
  1449. throw new Exception(ex.Message);
  1450. }
  1451. }
  1452. public static ICSNCRDoc selectBySecDocNO(String SecDocNO, String Appconstr)
  1453. {
  1454. FramDataContext db = new FramDataContext(Appconstr);
  1455. db.Connection.Open();
  1456. db.Transaction = db.Connection.BeginTransaction();
  1457. try
  1458. {
  1459. var line = db.ICSNCRDoc.Where(a => a.SecDocNO == SecDocNO);
  1460. if (line != null && line.Count() > 0)
  1461. return (ICSNCRDoc)line.First();
  1462. else
  1463. return null;
  1464. }
  1465. catch (Exception ex)
  1466. {
  1467. throw new Exception(ex.Message);
  1468. }
  1469. }
  1470. public static string selectDepByUserCode(String userCode, String Appconstr)
  1471. {
  1472. FramDataContext db = new FramDataContext(Appconstr);
  1473. db.Connection.Open();
  1474. db.Transaction = db.Connection.BeginTransaction();
  1475. try
  1476. {
  1477. //var Dep = db.ICSUserInfo.SingleOrDefault(a => a.WorkNo == userCode);
  1478. //if (Dep != null)
  1479. //{
  1480. // return Dep.DeptNO;
  1481. //}
  1482. //else
  1483. return "";
  1484. }
  1485. catch (Exception ex)
  1486. {
  1487. return "";
  1488. }
  1489. }
  1490. //public static ICSNCRDocDoDetail selectDoDetailBySecDocNO(String SecDocNO, String Appconstr)
  1491. //{
  1492. // FramDataContext db = new FramDataContext(Appconstr);
  1493. // db.Connection.Open();
  1494. // db.Transaction = db.Connection.BeginTransaction();
  1495. // try
  1496. // {
  1497. // var line = db.ICSNCRDocDoDetail.Where(a => a.SecDocNO == SecDocNO);
  1498. // if (line != null && line.Count() > 0)
  1499. // return (ICSNCRDocDoDetail)line.First();
  1500. // else
  1501. // return null;
  1502. // }
  1503. // catch (Exception ex)
  1504. // {
  1505. // throw new Exception(ex.Message);
  1506. // }
  1507. //}
  1508. //public static ICSNCRDocDoDetail selectDoDetailBySecDocNO(String SecDocNO, FramDataContext db)
  1509. //{
  1510. // try
  1511. // {
  1512. // var line = db.ICSNCRDocDoDetail.Where(a => a.SecDocNO == SecDocNO);
  1513. // if (line != null && line.Count() > 0)
  1514. // return (ICSNCRDocDoDetail)line.First();
  1515. // else
  1516. // return null;
  1517. // }
  1518. // catch (Exception ex)
  1519. // {
  1520. // throw new Exception(ex.Message);
  1521. // }
  1522. //}
  1523. public static ICSNCRDocRectify SelectRectifyBySecDocNO(String SecDocNO, String Appconstr)
  1524. {
  1525. FramDataContext db = new FramDataContext(Appconstr);
  1526. db.Connection.Open();
  1527. db.Transaction = db.Connection.BeginTransaction();
  1528. try
  1529. {
  1530. var line = db.ICSNCRDocRectify.Where(a => a.SecDocNO == SecDocNO);
  1531. if (line != null && line.Count() > 0)
  1532. return (ICSNCRDocRectify)line.First();
  1533. else
  1534. return null;
  1535. }
  1536. catch (Exception ex)
  1537. {
  1538. throw new Exception(ex.Message);
  1539. }
  1540. }
  1541. public static ICSNCRDocRectify SelectRectifyBySecDocNO(String SecDocNO, FramDataContext db)
  1542. {
  1543. try
  1544. {
  1545. var line = db.ICSNCRDocRectify.Where(a => a.SecDocNO == SecDocNO);
  1546. if (line != null && line.Count() > 0)
  1547. return (ICSNCRDocRectify)line.First();
  1548. else
  1549. return null;
  1550. }
  1551. catch (Exception ex)
  1552. {
  1553. throw new Exception(ex.Message);
  1554. }
  1555. }
  1556. public static List<NCRDocRectifyProcessModel> SelectRectifyProcessBySecDocNO(String SecDocNO, String Appconstr)
  1557. {
  1558. FramDataContext db = new FramDataContext(Appconstr);
  1559. db.Connection.Open();
  1560. db.Transaction = db.Connection.BeginTransaction();
  1561. List<NCRDocRectifyProcessModel> entitylist = new List<NCRDocRectifyProcessModel>();
  1562. try
  1563. {
  1564. var line = db.ICSNCRDocRectifyProcess.Where(a => a.SecDocNO == SecDocNO).OrderBy(a => a.Seq);
  1565. if (line != null && line.Count() > 0)
  1566. {
  1567. foreach (var item in line)
  1568. {
  1569. NCRDocRectifyProcessModel Model = new NCRDocRectifyProcessModel();
  1570. Model.Entity_RectifyProcess = (ICSNCRDocRectifyProcess)item;
  1571. string User = "";
  1572. var vv = db.Sys_EnumValues.SingleOrDefault(a => a.EnumKey == "076" && a.EnumText == Model.Entity_RectifyProcess.ProcessName);
  1573. if (vv != null)
  1574. {
  1575. User = vv.Define1 + "," + vv.Define5;
  1576. }
  1577. Model.RectifyUser = User;
  1578. entitylist.Add(Model);
  1579. }
  1580. return entitylist;
  1581. }
  1582. else
  1583. {
  1584. return null;
  1585. }
  1586. }
  1587. catch (Exception ex)
  1588. {
  1589. throw new Exception(ex.Message);
  1590. }
  1591. }
  1592. public static List<NCRDocRectifyProcessModel> SelectRectifyProcessBySecDocNO(String SecDocNO, FramDataContext db)
  1593. {
  1594. List<NCRDocRectifyProcessModel> entitylist = new List<NCRDocRectifyProcessModel>();
  1595. try
  1596. {
  1597. var line = db.ICSNCRDocRectifyProcess.Where(a => a.SecDocNO == SecDocNO).OrderBy(a => a.Seq);
  1598. if (line != null && line.Count() > 0)
  1599. {
  1600. foreach (var item in line)
  1601. {
  1602. NCRDocRectifyProcessModel Model = new NCRDocRectifyProcessModel();
  1603. Model.Entity_RectifyProcess = (ICSNCRDocRectifyProcess)item;
  1604. string User = "";
  1605. var vv = db.Sys_EnumValues.SingleOrDefault(a => a.EnumKey == "076" && a.EnumText == Model.Entity_RectifyProcess.ProcessName);
  1606. if (vv != null)
  1607. {
  1608. User = vv.Define1 + "," + vv.Define5;
  1609. }
  1610. Model.RectifyUser = User;
  1611. entitylist.Add(Model);
  1612. }
  1613. return entitylist;
  1614. }
  1615. else
  1616. {
  1617. return null;
  1618. }
  1619. }
  1620. catch (Exception ex)
  1621. {
  1622. throw new Exception(ex.Message);
  1623. }
  1624. }
  1625. public static List<ICSNCRDocRectifyBonusPenalty> SelectRectifyBonusPenaltyBySecDocNO(String SecDocNO, String Appconstr)
  1626. {
  1627. FramDataContext db = new FramDataContext(Appconstr);
  1628. db.Connection.Open();
  1629. db.Transaction = db.Connection.BeginTransaction();
  1630. List<ICSNCRDocRectifyBonusPenalty> entitylist = new List<ICSNCRDocRectifyBonusPenalty>();
  1631. try
  1632. {
  1633. var line = db.ICSNCRDocRectifyBonusPenalty.Where(a => a.SecDocNO == SecDocNO).OrderBy(a => a.MTIME);
  1634. if (line != null && line.Count() > 0)
  1635. {
  1636. foreach (var item in line)
  1637. {
  1638. entitylist.Add((ICSNCRDocRectifyBonusPenalty)item);
  1639. }
  1640. return entitylist;
  1641. }
  1642. else
  1643. {
  1644. return null;
  1645. }
  1646. }
  1647. catch (Exception ex)
  1648. {
  1649. throw new Exception(ex.Message);
  1650. }
  1651. }
  1652. public static List<ICSNCRDocRectifyBonusPenalty> SelectRectifyBonusPenaltyBySecDocNO(String SecDocNO, FramDataContext db)
  1653. {
  1654. List<ICSNCRDocRectifyBonusPenalty> entitylist = new List<ICSNCRDocRectifyBonusPenalty>();
  1655. try
  1656. {
  1657. var line = db.ICSNCRDocRectifyBonusPenalty.Where(a => a.SecDocNO == SecDocNO).OrderBy(a => a.MTIME);
  1658. if (line != null && line.Count() > 0)
  1659. {
  1660. foreach (var item in line)
  1661. {
  1662. entitylist.Add((ICSNCRDocRectifyBonusPenalty)item);
  1663. }
  1664. return entitylist;
  1665. }
  1666. else
  1667. {
  1668. return null;
  1669. }
  1670. }
  1671. catch (Exception ex)
  1672. {
  1673. throw new Exception(ex.Message);
  1674. }
  1675. }
  1676. public static ICSNCRDocPrevention SelectPreventionBySecDocNO(String SecDocNO, String Appconstr)
  1677. {
  1678. FramDataContext db = new FramDataContext(Appconstr);
  1679. db.Connection.Open();
  1680. db.Transaction = db.Connection.BeginTransaction();
  1681. try
  1682. {
  1683. var line = db.ICSNCRDocPrevention.Where(a => a.SecDocNO == SecDocNO);
  1684. if (line != null && line.Count() > 0)
  1685. return (ICSNCRDocPrevention)line.First();
  1686. else
  1687. return null;
  1688. }
  1689. catch (Exception ex)
  1690. {
  1691. throw new Exception(ex.Message);
  1692. }
  1693. }
  1694. public static ICSNCRDocPrevention SelectPreventionBySecDocNO(String SecDocNO, FramDataContext db)
  1695. {
  1696. try
  1697. {
  1698. var line = db.ICSNCRDocPrevention.Where(a => a.SecDocNO == SecDocNO);
  1699. if (line != null && line.Count() > 0)
  1700. return (ICSNCRDocPrevention)line.First();
  1701. else
  1702. return null;
  1703. }
  1704. catch (Exception ex)
  1705. {
  1706. throw new Exception(ex.Message);
  1707. }
  1708. }
  1709. public static List<NCRDocPreventionProcessModel> SelectPreventionProcessBySecDocNO(String SecDocNO, String Appconstr)
  1710. {
  1711. FramDataContext db = new FramDataContext(Appconstr);
  1712. db.Connection.Open();
  1713. db.Transaction = db.Connection.BeginTransaction();
  1714. List<NCRDocPreventionProcessModel> entitylist = new List<NCRDocPreventionProcessModel>();
  1715. try
  1716. {
  1717. var line = db.ICSNCRDocPreventionProcess.Where(a => a.SecDocNO == SecDocNO).OrderBy(a => a.Seq);
  1718. if (line != null && line.Count() > 0)
  1719. {
  1720. foreach (var item in line)
  1721. {
  1722. NCRDocPreventionProcessModel Model = new NCRDocPreventionProcessModel();
  1723. Model.Entity_PreventionProcess = (ICSNCRDocPreventionProcess)item;
  1724. string user = "";
  1725. var vv = db.Sys_EnumValues.SingleOrDefault(a => a.EnumKey == "076" && a.EnumText == Model.Entity_PreventionProcess.ProcessName);
  1726. if (vv != null)
  1727. {
  1728. user = vv.Define1 + "," + vv.Define5;
  1729. }
  1730. Model.PreventionUser = user;
  1731. entitylist.Add(Model);
  1732. }
  1733. return entitylist;
  1734. }
  1735. else
  1736. {
  1737. return null;
  1738. }
  1739. }
  1740. catch (Exception ex)
  1741. {
  1742. throw new Exception(ex.Message);
  1743. }
  1744. }
  1745. public static List<NCRDocPreventionProcessModel> SelectPreventionProcessBySecDocNO(String SecDocNO, FramDataContext db)
  1746. {
  1747. List<NCRDocPreventionProcessModel> entitylist = new List<NCRDocPreventionProcessModel>();
  1748. try
  1749. {
  1750. var line = db.ICSNCRDocPreventionProcess.Where(a => a.SecDocNO == SecDocNO).OrderBy(a => a.Seq);
  1751. if (line != null && line.Count() > 0)
  1752. {
  1753. foreach (var item in line)
  1754. {
  1755. NCRDocPreventionProcessModel Model = new NCRDocPreventionProcessModel();
  1756. Model.Entity_PreventionProcess = (ICSNCRDocPreventionProcess)item;
  1757. string user = "";
  1758. var vv = db.Sys_EnumValues.SingleOrDefault(a => a.EnumKey == "076" && a.EnumText == Model.Entity_PreventionProcess.ProcessName);
  1759. if (vv != null)
  1760. {
  1761. user = vv.Define1 + "," + vv.Define5;
  1762. }
  1763. Model.PreventionUser = user;
  1764. entitylist.Add(Model);
  1765. }
  1766. return entitylist;
  1767. }
  1768. else
  1769. {
  1770. return null;
  1771. }
  1772. }
  1773. catch (Exception ex)
  1774. {
  1775. throw new Exception(ex.Message);
  1776. }
  1777. }
  1778. public static List<ICSNCRDocPicture> SelectPictureBySecDocNO(String SecDocNO, String Appconstr)
  1779. {
  1780. FramDataContext db = new FramDataContext(Appconstr);
  1781. db.Connection.Open();
  1782. db.Transaction = db.Connection.BeginTransaction();
  1783. List<ICSNCRDocPicture> entitylist = new List<ICSNCRDocPicture>();
  1784. try
  1785. {
  1786. var line = db.ICSNCRDocPicture.Where(a => a.SecDocNO == SecDocNO).OrderBy(a => a.MTIME);
  1787. if (line != null && line.Count() > 0)
  1788. {
  1789. foreach (var item in line)
  1790. {
  1791. entitylist.Add((ICSNCRDocPicture)item);
  1792. }
  1793. return entitylist;
  1794. }
  1795. else
  1796. {
  1797. return null;
  1798. }
  1799. }
  1800. catch (Exception ex)
  1801. {
  1802. throw new Exception(ex.Message);
  1803. }
  1804. }
  1805. public static List<ICSNCRDocPicture> SelectPictureBySecDocNO(String SecDocNO, FramDataContext db)
  1806. {
  1807. List<ICSNCRDocPicture> entitylist = new List<ICSNCRDocPicture>();
  1808. try
  1809. {
  1810. var line = db.ICSNCRDocPicture.Where(a => a.SecDocNO == SecDocNO).OrderBy(a => a.MTIME);
  1811. if (line != null && line.Count() > 0)
  1812. {
  1813. foreach (var item in line)
  1814. {
  1815. entitylist.Add((ICSNCRDocPicture)item);
  1816. }
  1817. return entitylist;
  1818. }
  1819. else
  1820. {
  1821. return null;
  1822. }
  1823. }
  1824. catch (Exception ex)
  1825. {
  1826. throw new Exception(ex.Message);
  1827. }
  1828. }
  1829. public static bool IsExistRectifyLog(String SecDocNO, String Appconstr)
  1830. {
  1831. FramDataContext db = new FramDataContext(Appconstr);
  1832. db.Connection.Open();
  1833. db.Transaction = db.Connection.BeginTransaction();
  1834. try
  1835. {
  1836. var line = db.ICSNCRDocRectifyProcessLog.Where(a => a.SecDocNO == SecDocNO);
  1837. if (line != null && line.Count() > 0)
  1838. return true;
  1839. else
  1840. return false;
  1841. }
  1842. catch (Exception ex)
  1843. {
  1844. throw new Exception(ex.Message);
  1845. }
  1846. }
  1847. public static bool IsExistPreventionLog(String SecDocNO, String Appconstr)
  1848. {
  1849. FramDataContext db = new FramDataContext(Appconstr);
  1850. db.Connection.Open();
  1851. db.Transaction = db.Connection.BeginTransaction();
  1852. try
  1853. {
  1854. var line = db.ICSNCRDocPreventionProcessLog.Where(a => a.SecDocNO == SecDocNO);
  1855. if (line != null && line.Count() > 0)
  1856. return true;
  1857. else
  1858. return false;
  1859. }
  1860. catch (Exception ex)
  1861. {
  1862. throw new Exception(ex.Message);
  1863. }
  1864. }
  1865. public static bool IsOPBefore(String LotNo, String OP, String OP_CURRENT, String Appconstr)
  1866. {
  1867. try
  1868. {
  1869. string sql = @"SELECT mo.ITEMCODE, lot.LOTQTY ,OP.OPSEQ OPSEQ,OP2.OPSEQ OP_C_SEQ
  1870. FROM ICSMO2Lot lot Left Join ICSMO mo on lot.MoCode = mo.MoCode
  1871. left join ICSMO2ROUTE route on mo.mocode=route.mocode
  1872. left join icsitemroute2op op on route.ROUTECODE=op.routecode and op.itemcode=mo.itemcode and op.opcode='{1}'
  1873. left join icsitemroute2op op2 on route.ROUTECODE=op2.routecode and op2.itemcode=mo.itemcode and op2.opcode='{2}'
  1874. WHERE LOT.LOTNO='{0}'
  1875. ";
  1876. sql = string.Format(sql, LotNo, OP, OP_CURRENT);
  1877. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  1878. if (dt != null && dt.Rows.Count > 0)
  1879. {
  1880. if (!string.IsNullOrEmpty(dt.Rows[0]["OPSEQ"].ToString()) && !string.IsNullOrEmpty(dt.Rows[0]["OP_C_SEQ"].ToString()))
  1881. {
  1882. if (dt.Rows[0]["ITEMCODE"].ToString().Substring(0, 2) == "11")
  1883. {
  1884. int seq = Convert.ToInt32(dt.Rows[0]["OPSEQ"].ToString());
  1885. int seq_c = Convert.ToInt32(dt.Rows[0]["OP_C_SEQ"].ToString());
  1886. if (seq >= seq_c)
  1887. {
  1888. return true;
  1889. }
  1890. }
  1891. }
  1892. }
  1893. return false;
  1894. }
  1895. catch (Exception ex)
  1896. {
  1897. return false;
  1898. }
  1899. }
  1900. public static String QualityEngineer(string type, String Appconstr)
  1901. {
  1902. FramDataContext db = new FramDataContext(Appconstr);
  1903. db.Connection.Open();
  1904. db.Transaction = db.Connection.BeginTransaction();
  1905. try
  1906. {
  1907. string usercode = "";
  1908. List<string> Users = new List<string>();
  1909. var line = db.Sys_EnumValues.Where(a => a.EnumKey == "083" && a.EnumValue == type && a.StartFlag == true);
  1910. if (line != null && line.Count() > 0)
  1911. {
  1912. foreach (Sys_EnumValues item in line)
  1913. {
  1914. if (!(Users.Contains(item.EnumText)))
  1915. {
  1916. Users.Add(item.EnumText);
  1917. }
  1918. }
  1919. for (int j = 0; j < Users.Count; j++)
  1920. {
  1921. usercode += Users[j] + ",";
  1922. }
  1923. usercode = usercode.TrimEnd(',');
  1924. return usercode;
  1925. }
  1926. else
  1927. return "";
  1928. }
  1929. catch (Exception ex)
  1930. {
  1931. throw new Exception(ex.Message);
  1932. }
  1933. }
  1934. public static bool IsConfirmAllRectify(String SecDocNO, String Appconstr)
  1935. {
  1936. FramDataContext db = new FramDataContext(Appconstr);
  1937. db.Connection.Open();
  1938. db.Transaction = db.Connection.BeginTransaction();
  1939. try
  1940. {
  1941. var line = db.ICSNCRDocRectifyProcess.Where(a => a.SecDocNO == SecDocNO).OrderByDescending(a => a.Seq);
  1942. if (line != null && line.Count() > 0)
  1943. {
  1944. string confirmStatus = line.FirstOrDefault().ConfirmStatus;
  1945. if (confirmStatus == "关闭")
  1946. {
  1947. return true;
  1948. }
  1949. else
  1950. { return false; }
  1951. }
  1952. else { return false; }
  1953. }
  1954. catch (Exception ex)
  1955. {
  1956. throw new Exception(ex.Message);
  1957. }
  1958. }
  1959. public static bool IsSubmitAllRectify(String SecDocNO, String Appconstr)
  1960. {
  1961. FramDataContext db = new FramDataContext(Appconstr);
  1962. db.Connection.Open();
  1963. db.Transaction = db.Connection.BeginTransaction();
  1964. try
  1965. {
  1966. var line = db.ICSNCRDocRectifyProcess.Where(a => a.SecDocNO == SecDocNO).OrderByDescending(a => a.Seq);
  1967. if (line != null && line.Count() > 0)
  1968. {
  1969. string SubmitStatus = line.FirstOrDefault().SubmitStatus;
  1970. if (SubmitStatus == "已提交")
  1971. {
  1972. return true;
  1973. }
  1974. else
  1975. { return false; }
  1976. }
  1977. else { return false; }
  1978. }
  1979. catch (Exception ex)
  1980. {
  1981. throw new Exception(ex.Message);
  1982. }
  1983. }
  1984. public static bool IsConfirmAllPrevention(String SecDocNO, String Appconstr)
  1985. {
  1986. FramDataContext db = new FramDataContext(Appconstr);
  1987. db.Connection.Open();
  1988. db.Transaction = db.Connection.BeginTransaction();
  1989. try
  1990. {
  1991. ICSNCRDoc SecDoc = selectBySecDocNO(SecDocNO, Appconstr);
  1992. if (SecDoc != null && SecDoc.IsNeedPrevention == "是")
  1993. {
  1994. var line = db.ICSNCRDocPreventionProcess.Where(a => a.SecDocNO == SecDocNO).OrderByDescending(a => a.Seq);
  1995. if (line != null && line.Count() > 0)
  1996. {
  1997. string confirmStatus = line.FirstOrDefault().ConfirmStatus;
  1998. if (confirmStatus == "同意关闭")
  1999. {
  2000. return true;
  2001. }
  2002. }
  2003. }
  2004. return false;
  2005. }
  2006. catch (Exception ex)
  2007. {
  2008. throw new Exception(ex.Message);
  2009. }
  2010. }
  2011. public static bool IsSubmitAllPrevention(String SecDocNO, String Appconstr)
  2012. {
  2013. FramDataContext db = new FramDataContext(Appconstr);
  2014. db.Connection.Open();
  2015. db.Transaction = db.Connection.BeginTransaction();
  2016. try
  2017. {
  2018. ICSNCRDoc SecDoc = selectBySecDocNO(SecDocNO, Appconstr);
  2019. if (SecDoc != null && SecDoc.IsNeedPrevention == "是")
  2020. {
  2021. var line = db.ICSNCRDocPreventionProcess.Where(a => a.SecDocNO == SecDocNO).OrderByDescending(a => a.Seq);
  2022. if (line != null && line.Count() > 0)
  2023. {
  2024. string SubmitStatus = line.FirstOrDefault().SubmitStatus;
  2025. if (SubmitStatus == "已提交")
  2026. {
  2027. return true;
  2028. }
  2029. }
  2030. }
  2031. return false;
  2032. }
  2033. catch (Exception ex)
  2034. {
  2035. throw new Exception(ex.Message);
  2036. }
  2037. }
  2038. public static List<Sys_EnumValues> SelectRoute(String Appconstr)
  2039. {
  2040. FramDataContext db = new FramDataContext(Appconstr);
  2041. db.Connection.Open();
  2042. db.Transaction = db.Connection.BeginTransaction();
  2043. List<Sys_EnumValues> list = new List<Sys_EnumValues>();
  2044. try
  2045. {
  2046. var line = db.Sys_EnumValues.Where(a => a.EnumKey == "076").OrderBy(a => a.Define2);
  2047. if (line != null && line.Count() > 0)
  2048. {
  2049. foreach (var item in line)
  2050. {
  2051. list.Add((Sys_EnumValues)item);
  2052. }
  2053. return list;
  2054. }
  2055. else
  2056. {
  2057. return null;
  2058. }
  2059. }
  2060. catch (Exception ex)
  2061. {
  2062. throw new Exception(ex.Message);
  2063. }
  2064. }
  2065. public static Sys_EnumValues SelectPreventionMail(List<NCRDocPreventionProcessModel> list, String Appconstr)
  2066. {
  2067. FramDataContext db = new FramDataContext(Appconstr);
  2068. db.Connection.Open();
  2069. db.Transaction = db.Connection.BeginTransaction();
  2070. try
  2071. {
  2072. if (list != null && list.Count() > 0)
  2073. {
  2074. foreach (NCRDocPreventionProcessModel item in list)
  2075. {
  2076. if (string.IsNullOrEmpty(item.Entity_PreventionProcess.SubmitStatus))
  2077. {
  2078. var line = db.Sys_EnumValues.SingleOrDefault(a => a.EnumKey == "076" && a.EnumText == item.Entity_PreventionProcess.ProcessName);
  2079. if (line != null)
  2080. { return line; }
  2081. }
  2082. }
  2083. return null;
  2084. }
  2085. else
  2086. {
  2087. return null;
  2088. }
  2089. }
  2090. catch (Exception ex)
  2091. {
  2092. return null;
  2093. }
  2094. }
  2095. public static Sys_EnumValues SelectRectifyMail(List<NCRDocRectifyProcessModel> list, String Appconstr)
  2096. {
  2097. FramDataContext db = new FramDataContext(Appconstr);
  2098. db.Connection.Open();
  2099. db.Transaction = db.Connection.BeginTransaction();
  2100. try
  2101. {
  2102. if (list != null && list.Count() > 0)
  2103. {
  2104. foreach (NCRDocRectifyProcessModel item in list)
  2105. {
  2106. if (string.IsNullOrEmpty(item.Entity_RectifyProcess.SubmitStatus))
  2107. {
  2108. var line = db.Sys_EnumValues.SingleOrDefault(a => a.EnumKey == "076" && a.EnumText == item.Entity_RectifyProcess.ProcessName);
  2109. if (line != null)
  2110. { return line; }
  2111. }
  2112. }
  2113. return null;
  2114. }
  2115. else
  2116. {
  2117. return null;
  2118. }
  2119. }
  2120. catch (Exception ex)
  2121. {
  2122. return null;
  2123. }
  2124. }
  2125. public static Sys_EnumValues SelectPreventionMail_Final(String ProcessName, String Appconstr)
  2126. {
  2127. FramDataContext db = new FramDataContext(Appconstr);
  2128. db.Connection.Open();
  2129. db.Transaction = db.Connection.BeginTransaction();
  2130. try
  2131. {
  2132. var line = db.Sys_EnumValues.SingleOrDefault(a => a.EnumKey == "076" && a.EnumText == ProcessName);
  2133. if (line != null)
  2134. { return line; }
  2135. }
  2136. catch (Exception ex)
  2137. {
  2138. return null;
  2139. }
  2140. return null;
  2141. }
  2142. public static Sys_EnumValues SelectRectifyMail_Final(String ProcessName, String Appconstr)
  2143. {
  2144. FramDataContext db = new FramDataContext(Appconstr);
  2145. db.Connection.Open();
  2146. db.Transaction = db.Connection.BeginTransaction();
  2147. try
  2148. {
  2149. var line = db.Sys_EnumValues.SingleOrDefault(a => a.EnumKey == "076" && a.EnumText == ProcessName);
  2150. if (line != null)
  2151. { return line; }
  2152. }
  2153. catch (Exception ex)
  2154. {
  2155. return null;
  2156. }
  2157. return null;
  2158. }
  2159. public static string SelectPoint(string Lotno)
  2160. {
  2161. string Point = "";
  2162. try
  2163. {
  2164. if (Lotno.Substring(0, 2) == "MO")
  2165. {
  2166. string sql = @" select EQP.Address from ICSLOTSIMULATION lots
  2167. left join ICSEquipment EQP on lots.EQPCODE=EQP.EQPCODE
  2168. where lotno = '" + Lotno + "' ";
  2169. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  2170. if (dt != null && dt.Rows.Count > 0)
  2171. {
  2172. Point = dt.Rows[0]["Address"].ToString();
  2173. }
  2174. }
  2175. else
  2176. {
  2177. string sql = @" select b.RcvLineSrcPOSrcDocNo
  2178. from dbo.WM_BarCode a
  2179. left join WM_RCVShip b on a.RCVShipguid=b.guid
  2180. where a.BarCodeNo ='" + Lotno + "' ";
  2181. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  2182. if (dt != null && dt.Rows.Count > 0)
  2183. {
  2184. Point = dt.Rows[0]["RcvLineSrcPOSrcDocNo"].ToString();
  2185. }
  2186. }
  2187. return Point;
  2188. }
  2189. catch (Exception ex)
  2190. {
  2191. return "";
  2192. }
  2193. }
  2194. public static string GetQualityEngineerType(string DocTypeID, string OPCode, string itemcode, string LOTNO, string Appconstr)
  2195. {
  2196. FramDataContext db = new FramDataContext(Appconstr);
  2197. db.Connection.Open();
  2198. db.Transaction = db.Connection.BeginTransaction();
  2199. try
  2200. {
  2201. var line = db.ICSSecDocType.SingleOrDefault(a => a.guid == DocTypeID);
  2202. if (line != null)
  2203. {
  2204. if (line.DocTypeCode.Contains("JJ"))
  2205. {
  2206. return "机加";
  2207. }
  2208. if (line.DocTypeCode.Contains("ZP"))
  2209. {
  2210. if (itemcode.Substring(0, 2) == "11")
  2211. {
  2212. if (!string.IsNullOrEmpty(LOTNO) && !string.IsNullOrEmpty(OPCode))
  2213. {
  2214. if (ICSNCRDocDAL.IsOPBefore(LOTNO, "SY", OPCode, Appconstr))
  2215. {
  2216. return "阀门试压工序前";
  2217. }
  2218. else
  2219. { return "阀门试压工序后"; }
  2220. }
  2221. else
  2222. {
  2223. return "装配";
  2224. }
  2225. }
  2226. else
  2227. {
  2228. return "阀门试压工序后";
  2229. }
  2230. }
  2231. if (line.DocTypeCode.Contains("CK"))
  2232. {
  2233. return "仓库";
  2234. }
  2235. }
  2236. return "";
  2237. }
  2238. catch (Exception ex)
  2239. {
  2240. return "";
  2241. }
  2242. }
  2243. public static List<String> SelectPreventionProName(String SecDocNO, String Appconstr)
  2244. {
  2245. try
  2246. {
  2247. List<string> namelist = new List<string>();
  2248. string sql = @" SELECT VV.Define1 name
  2249. from ICSNCRDocPreventionProcess pro
  2250. inner join Sys_EnumValues vv on pro.ProcessName=vv.EnumText and EnumKey='076'
  2251. where 1=1
  2252. and pro.SecDocNO='{0}'
  2253. and VV.Define1!=''
  2254. union
  2255. SELECT VV.Define5 name
  2256. from ICSNCRDocPreventionProcess pro
  2257. inner join Sys_EnumValues vv on pro.ProcessName=vv.EnumText and EnumKey='076'
  2258. where 1=1
  2259. and pro.SecDocNO='{0}'
  2260. and VV.Define5!='' ";
  2261. sql = string.Format(sql, SecDocNO);
  2262. DataTable dt = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql).Tables[0];
  2263. if (dt != null && dt.Rows.Count > 0)
  2264. {
  2265. foreach (DataRow dr in dt.Rows)
  2266. {
  2267. namelist.Add(dr["name"].ToString());
  2268. }
  2269. return namelist;
  2270. }
  2271. return null;
  2272. }
  2273. catch (Exception ex)
  2274. {
  2275. return null;
  2276. }
  2277. }
  2278. public static List<String> SelectRectifyProName(String SecDocNO, String Appconstr)
  2279. {
  2280. try
  2281. {
  2282. List<string> namelist = new List<string>();
  2283. string sql = @" SELECT VV.Define1 name
  2284. from ICSNCRDocRectifyProcess pro
  2285. inner join Sys_EnumValues vv on pro.ProcessName=vv.EnumText and EnumKey='076'
  2286. where 1=1
  2287. and pro.SecDocNO='{0}'
  2288. and VV.Define1!=''
  2289. union
  2290. SELECT VV.Define5 name
  2291. from ICSNCRDocRectifyProcess pro
  2292. inner join Sys_EnumValues vv on pro.ProcessName=vv.EnumText and EnumKey='076'
  2293. where 1=1
  2294. and pro.SecDocNO='{0}'
  2295. and VV.Define5!='' ";
  2296. sql = string.Format(sql, SecDocNO);
  2297. DataTable dt = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql).Tables[0];
  2298. if (dt != null && dt.Rows.Count > 0)
  2299. {
  2300. foreach (DataRow dr in dt.Rows)
  2301. {
  2302. namelist.Add(dr["name"].ToString());
  2303. }
  2304. return namelist;
  2305. }
  2306. return null;
  2307. }
  2308. catch (Exception ex)
  2309. {
  2310. return null;
  2311. }
  2312. }
  2313. public static DataTable GetReCheck(string LotList, DateTime Mtime, String Appconstr)
  2314. {
  2315. try
  2316. {
  2317. string Str_Where = "";
  2318. if (!string.IsNullOrEmpty(LotList))
  2319. {
  2320. LotList = LotList.Replace(",", "','");
  2321. }
  2322. else
  2323. {
  2324. throw new Exception("无Lot");
  2325. }
  2326. if (Mtime != null)
  2327. {
  2328. Str_Where += @" and ckDateTime >'" + Mtime.ToString("yyyy-MM-dd HH:mm:ss") + @"' ";
  2329. }
  2330. Str_Where += @" and LOTNO in ('" + LotList + @"') ";
  2331. string sql = @"
  2332. DECLARE @WG NVARCHAR ( 20 ),@CJ NVARCHAR ( 20 )
  2333. SET @WG = '{0}'
  2334. SET @CJ = '{1}'
  2335. select result.*
  2336. ,case when ISNULL( Result ,'')='' then (cast(DATEDIFF(mi, GETDATE(), DATEADD( hh, 4, MTIME )) /60 as NVARCHAR) +':'+
  2337. RIGHT('00'+CAST(ABS(DATEDIFF(mi, GETDATE(), DATEADD( hh, 4, MTIME )) %60 )AS nvarchar(50) ),2) ) else '' end remainingTime,'' AS participant from (
  2338. SELECT DISTINCT CAST
  2339. ( 0 AS BIT ) AS isSelect,c.ID,
  2340. a.LOTNO,
  2341. a.LOTSEQ,
  2342. a.MOCODE,
  2343. d.ProjectCode,
  2344. e.ItemCode,
  2345. e.ItemName,
  2346. e.ItemStd,
  2347. b.MTIME,
  2348. f.[Address],
  2349. CASE
  2350. c.CKResult
  2351. WHEN '1' THEN
  2352. ''
  2353. WHEN '0' THEN
  2354. ''
  2355. END AS Result,
  2356. CASE
  2357. WHEN c.LOTNO IS NOT NULL THEN
  2358. @WG ELSE @CJ
  2359. END AS Status,
  2360. a.LOTQTY ,ck.EATTRIBUTE1 AS ISOk
  2361. --,h.SecDocNO,h.ID SecDocID,g.DocTypeCode,h.SecDocSeq,g.DocTypePath
  2362. ,CASE WHEN c.CKResult='1' THEN null else ISNULL(ff.SecDocNo, h.SecDocNO) end SecDocNO
  2363. ,ISNULL(ff.ID, h.ID) SecDocID,ISNULL(gg.DocTypeCode, g.DocTypeCode) DocTypeCode
  2364. ,ISNULL(ff.SecDocSeq, h.SecDocSeq) SecDocSeq,ISNULL(gg.DocTypePath, g.DocTypePath) DocTypePath
  2365. ,case when ff.SecDocNo is not null and ff.SecDocNo!='' then '1' when h.SecDocNo is not null and h.SecDocNo!='' then '0' else '' end SecDocNoTrue
  2366. --,case when c.LOTNO IS NULL then '{2}' ELSE c.EATTRIBUTE3 END AS participant
  2367. -- ,isnull((case when ISNULL( c.LOTNO ,'')!='' then c.EATTRIBUTE3 WHEN val.Define4='N' THEN '{2}' ELSE '' END),'') AS participant
  2368. ,'' RcvLineInvLotFurnace
  2369. ,c.mtime ckDateTime
  2370. FROM
  2371. ICSMO2Lot a
  2372. INNER JOIN ICSLOTSIMULATION b ON a.LOTNO= b.LOTNO
  2373. LEFT JOIN ICSEquipment f ON b.EQPCODE = f.EQPCode
  2374. LEFT JOIN ( SELECT * FROM ICSQualityCKDATA WHERE Type = '' ) c ON a.LOTNO= c.LOTNO
  2375. LEFT JOIN ICSMO d ON a.MOCODE= d.MOCODE
  2376. LEFT JOIN Base_Inventory e ON d.ITEMCODE= e.ITEMCODE
  2377. LEFT JOIN ICSQualityCKDATA ck ON a.MOCODE = ck.MOCODE AND a.LOTNO=ck.LOTNO AND ck.EATTRIBUTE1=''
  2378. LEFT JOIN (select * from (select ROW_NUMBER()over(partition by LOTNO order by mtime desc) rowId,*
  2379. from ICSSecDoc ck ) as AuctionRecords
  2380. where rowId=1) h ON a.LOTNO=h.LOTNO
  2381. left join ICSSecDocType g on h.SecDocType = g.guid
  2382. LEFT JOIN (select * from (select ROW_NUMBER()over(partition by SrcDocInfo order by mtime desc) rowId,*
  2383. from ICSNCRDoc ck --where ck.NCR.SecDocCreateTime>='2020-03-30 00:00:00'
  2384. ) as AuctionRecords
  2385. where rowId=1) ff ON CHARINDEX ( a.lotno , ff.SrcDocInfo )>0
  2386. left join ICSSecDocType gg on ff.SecDocType = gg.guid
  2387. -- left join Sys_EnumValues val ON EnumKey='082' AND EnumText='{3}' AND Define2=''
  2388. WHERE 1=1
  2389. --b.MTIME >= dateadd(day,-30,GETDATE())
  2390. AND b.IsCom= 1
  2391. AND ( e.ItemCode LIKE '12%' OR e.ItemCode LIKE '13%' OR e.ItemCode LIKE '16%' OR e.ItemCode LIKE '14%' )
  2392. AND (
  2393. e.ItemCode NOT LIKE '1222%'
  2394. AND e.ItemCode NOT LIKE '1233%'
  2395. AND e.ItemCode NOT LIKE '1232%'
  2396. AND e.ItemCode NOT LIKE '1231%'
  2397. and e.ItemCode NOT LIKE '1223%'
  2398. and e.ItemCode NOT LIKE '1248%'
  2399. ) and (e.ItemName NOT LIKE '%%' and e.ItemName NOT LIKE '%%')
  2400. union all
  2401. SELECT distinct
  2402. CAST( 0 AS BIT ) AS isSelect,c.ID,
  2403. a.LOTNO,
  2404. a.LOTSEQ,
  2405. a.MOCODE,
  2406. b.ProjectCode,
  2407. d.ItemCode,
  2408. d.ItemName,
  2409. d.ItemStd,
  2410. a.MTIME,
  2411. q.[Address],
  2412. CASE
  2413. k.CKResult
  2414. WHEN '1' THEN
  2415. ''
  2416. WHEN '0' THEN
  2417. ''
  2418. END AS Result,
  2419. CASE
  2420. WHEN k.LOTNO IS NOT NULL THEN
  2421. @WG ELSE @CJ
  2422. END AS Status,
  2423. a.LOTQTY ,ck.EATTRIBUTE1 AS ISOk
  2424. --,h.SecDocNO,h.ID SecDocID,g.DocTypeCode,h.SecDocSeq,g.DocTypePath
  2425. ,ISNULL(ff.SecDocNo, h.SecDocNO) SecDocNO,ISNULL(ff.ID, h.ID) SecDocID,ISNULL(gg.DocTypeCode, g.DocTypeCode) DocTypeCode
  2426. ,ISNULL(ff.SecDocSeq, h.SecDocSeq) SecDocSeq,ISNULL(gg.DocTypePath, g.DocTypePath) DocTypePath
  2427. ,case when ff.SecDocNo is not null and ff.SecDocNo!='' then '1' when h.SecDocNo is not null and h.SecDocNo!='' then '0' else '' end SecDocNoTrue
  2428. --,case when k.LOTNO IS NULL then '{2}' ELSE k.EATTRIBUTE3 END AS participant
  2429. -- ,isnull((case when ISNULL( k.LOTNO ,'')!='' then k.EATTRIBUTE3 WHEN val.Define4='N' THEN '{2}' ELSE '' END),'') AS participant
  2430. ,'' RcvLineInvLotFurnace
  2431. ,k.mtime ckDateTime
  2432. FROM
  2433. ICSLOTSIMULATION a
  2434. LEFT JOIN ICSMO b ON a.MOCODE = b.MOCODE
  2435. LEFT JOIN ICSROUTE c ON a.ROUTECODE = c.ROUTECODE
  2436. LEFT JOIN Base_Inventory d ON a.ITEMCODE = d.ITEMCODE
  2437. LEFT JOIN ( SELECT ITEMCODE,ROUTECODE,OPCODE,OPSEQ FROM ICSITEMROUTE2OP) e ON e.ITEMCODE = a.ITEMCODE
  2438. AND e.ROUTECODE = a.ROUTECODE
  2439. AND e.OPSEQ = (SELECT MIN(OPSEQ) FROM ICSITEMROUTE2OP WHERE ITEMCODE = a.ITEMCODE AND ROUTECODE = a.ROUTECODE
  2440. AND OPSEQ > (SELECT OPSEQ FROM ICSITEMROUTE2OP WHERE ITEMCODE = a.ITEMCODE AND ROUTECODE = a.ROUTECODE AND OPCODE = a.OPCODE))
  2441. LEFT JOIN ICSOP f ON a.OPCODE = f.OPCODE
  2442. LEFT JOIN ICSEquipment q ON a.EQPCODE = q.EQPCode
  2443. LEFT JOIN ( SELECT * FROM ICSQualityCKDATA WHERE Type = '' ) k ON k.LOTNO= a.LOTNO
  2444. LEFT JOIN ICSQualityCKDATA ck ON a.MOCODE = ck.MOCODE AND a.LOTNO=ck.LOTNO AND ck.EATTRIBUTE1=''
  2445. LEFT JOIN (select * from (select ROW_NUMBER()over(partition by LOTNO order by mtime desc) rowId,*
  2446. from ICSSecDoc ck ) as AuctionRecords
  2447. where rowId=1) h ON a.LOTNO=h.LOTNO
  2448. left join ICSSecDocType g on h.SecDocType = g.guid
  2449. LEFT JOIN (select * from (select ROW_NUMBER()over(partition by SrcDocInfo order by mtime desc) rowId,*
  2450. from ICSNCRDoc ck --where ck.NCR.SecDocCreateTime>='2020-03-30 00:00:00'
  2451. ) as AuctionRecords
  2452. where rowId=1) ff ON CHARINDEX ( a.lotno , ff.SrcDocInfo )>0
  2453. left join ICSSecDocType gg on ff.SecDocType = gg.guid
  2454. -- left join Sys_EnumValues val ON EnumKey='082' AND EnumText='{3}' AND Define2=''
  2455. where a.CollectStatus = 'COLLECT_END' AND e.OPCODE = 'DB' AND a.ISCOM <> 1 --And a.mtime >= dateadd(day,-30,GETDATE())
  2456. and (d.ItemName NOT LIKE '%%' AND d.ItemName NOT LIKE '%%') --And a.mtime >= dateadd(day,-30,GETDATE())
  2457. and e.ItemCode NOT LIKE '1223%'
  2458. and e.ItemCode NOT LIKE '1248%'
  2459. ) result where 1=1 ";
  2460. sql += Str_Where + @" ORDER BY Status,result.MTIME ASC";
  2461. sql = string.Format(sql, "已检验", "未检验", "", "");
  2462. DataTable dt = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql).Tables[0];
  2463. if (dt != null && dt.Rows.Count > 0)
  2464. {
  2465. return dt;
  2466. }
  2467. else
  2468. {
  2469. return null;
  2470. }
  2471. }
  2472. catch (Exception ex)
  2473. {
  2474. return null;
  2475. }
  2476. }
  2477. public static string GetCustomerCode(string RCVNO, String Appconstr)
  2478. {
  2479. try
  2480. {
  2481. string sql = @" select top 1 RcvSupplierCode from WM_RCVShip where rcvdocno ='" + RCVNO + "' ";
  2482. DataTable dt = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql).Tables[0];
  2483. if (dt != null && dt.Rows.Count > 0)
  2484. {
  2485. return dt.Rows[0][0].ToString();
  2486. }
  2487. else
  2488. {
  2489. return "";
  2490. }
  2491. }
  2492. catch (Exception ex)
  2493. {
  2494. return "";
  2495. }
  2496. }
  2497. public static Sys_EnumValues SelectToUserListMail(String ToUserList, String Appconstr)
  2498. {
  2499. FramDataContext db = new FramDataContext(Appconstr);
  2500. db.Connection.Open();
  2501. db.Transaction = db.Connection.BeginTransaction();
  2502. try
  2503. {
  2504. var line = db.Sys_EnumValues.Where(a => a.EnumKey == "083" && a.EnumText == ToUserList);
  2505. if (line != null && line.Count() > 0)
  2506. { return (Sys_EnumValues)line.First(); }
  2507. }
  2508. catch (Exception ex)
  2509. {
  2510. return null;
  2511. }
  2512. return null;
  2513. }
  2514. public static Sys_EnumValues SelectMailCopy(String Appconstr)
  2515. {
  2516. FramDataContext db = new FramDataContext(Appconstr);
  2517. db.Connection.Open();
  2518. db.Transaction = db.Connection.BeginTransaction();
  2519. try
  2520. {
  2521. var line = db.Sys_EnumValues.Where(a => a.EnumKey == "083" && a.EnumValue == "NCR邮件推送人");
  2522. if (line != null && line.Count() > 0)
  2523. { return (Sys_EnumValues)line.First(); }
  2524. }
  2525. catch (Exception ex)
  2526. {
  2527. return null;
  2528. }
  2529. return null;
  2530. }
  2531. public static Sys_EnumValues SelectSetDatePersonListMail(String Appconstr)
  2532. {
  2533. FramDataContext db = new FramDataContext(Appconstr);
  2534. db.Connection.Open();
  2535. db.Transaction = db.Connection.BeginTransaction();
  2536. try
  2537. {
  2538. var line = db.Sys_EnumValues.Where(a => a.EnumKey == "083" && a.EnumValue == "设置时间");
  2539. if (line != null && line.Count() > 0)
  2540. { return (Sys_EnumValues)line.First(); }
  2541. }
  2542. catch (Exception ex)
  2543. {
  2544. return null;
  2545. }
  2546. return null;
  2547. }
  2548. public static string selectTypeByEQPCode(string EQPCode, String Appconstr)
  2549. {
  2550. try
  2551. {
  2552. string sql = @" select Top 1 Define2 from Sys_EnumValues where enumkey='082' and EnumText!='demo' and Define1='" + EQPCode + "' ";
  2553. DataTable dt = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql).Tables[0];
  2554. if (dt != null && dt.Rows.Count > 0)
  2555. {
  2556. return dt.Rows[0][0].ToString();
  2557. }
  2558. else
  2559. {
  2560. return "";
  2561. }
  2562. }
  2563. catch (Exception ex)
  2564. {
  2565. return "";
  2566. }
  2567. }
  2568. public static DataTable GetUserList(String Appconstr)
  2569. {
  2570. try
  2571. {
  2572. string sql = @"
  2573. select distinct ename from ICSUserInfo
  2574. --select distinct deptno from ICSUserInfo where deptno!=''
  2575. ";
  2576. DataTable dt = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql).Tables[0];
  2577. if (dt != null && dt.Rows.Count > 0)
  2578. {
  2579. return dt;
  2580. }
  2581. else
  2582. {
  2583. return null;
  2584. }
  2585. }
  2586. catch (Exception ex)
  2587. {
  2588. return null;
  2589. }
  2590. }
  2591. public static DataTable GetUserDepList(String Appconstr)
  2592. {
  2593. try
  2594. {
  2595. string sql = @" select * from(select distinct deptno 部门 from ICSUserInfo where deptno!='' union select 'N/A' ) dd order by 1 ";
  2596. DataTable dt = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql).Tables[0];
  2597. if (dt != null && dt.Rows.Count > 0)
  2598. {
  2599. return dt;
  2600. }
  2601. else
  2602. {
  2603. return null;
  2604. }
  2605. }
  2606. catch (Exception ex)
  2607. {
  2608. return null;
  2609. }
  2610. }
  2611. public static DataTable GetUserGHList(String Appconstr)
  2612. {
  2613. try
  2614. {
  2615. string sql = @"
  2616. select * from(
  2617. select distinct workno , ename ,deptno from ICSUserInfo
  2618. union select 'N/A','N/A','N/A'
  2619. ) dd
  2620. order by 1
  2621. ";
  2622. DataTable dt = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql).Tables[0];
  2623. if (dt != null && dt.Rows.Count > 0)
  2624. {
  2625. return dt;
  2626. }
  2627. else
  2628. {
  2629. return null;
  2630. }
  2631. }
  2632. catch (Exception ex)
  2633. {
  2634. return null;
  2635. }
  2636. }
  2637. public static bool IsLastOP(String LotNo, string OPcode, String Appconstr)
  2638. {
  2639. try
  2640. {
  2641. string sql = @"
  2642. SELECT top 1 a.LOTNO,k.opcode,opseq
  2643. FROM ICSMO2Lot a
  2644. LEFT JOIN ICSMO d ON a.MOCODE=d.MOCODE
  2645. LEFT JOIN ICSMO2Route e ON d.MOCODE=e.MOCODE
  2646. left join ICSITEMROUTE2OP k on k.ItemCode = d.ItemCode ANd k.ROUTECODE = e.RouteCode
  2647. WHERE a.LOTNO='" + LotNo + @"' order by opseq desc
  2648. ";
  2649. DataTable dt = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql).Tables[0];
  2650. if (dt != null && dt.Rows.Count > 0)
  2651. {
  2652. if (dt.Rows[0]["opcode"].ToString() == OPcode)
  2653. { return true; }
  2654. }
  2655. return false;
  2656. }
  2657. catch (Exception ex)
  2658. {
  2659. return false;
  2660. }
  2661. }
  2662. public static string WXOpcodeCK(String LotNo, string OPcode, String Appconstr)
  2663. {
  2664. try
  2665. {
  2666. string sqlPR = string.Format(@"SELECT a.*
  2667. FROM ICSCreatePR a
  2668. INNER JOIN (SELECT TOP 1 a.MOCODE,a.LOTNO,k.opcode,opseq
  2669. FROM ICSMO2Lot a
  2670. LEFT JOIN ICSMO d ON a.MOCODE=d.MOCODE
  2671. LEFT JOIN ICSMO2Route e ON d.MOCODE=e.MOCODE
  2672. left join ICSITEMROUTE2OP k on k.ItemCode = d.ItemCode ANd k.ROUTECODE = e.RouteCode
  2673. LEFT JOIN ICSLOTSIMULATION f ON f.LOTNO= a.LOTNO AND k.opcode=f.OPCODE
  2674. WHERE a.LOTNO='{0}'
  2675. AND OPSEQ>( SELECT OPSEQ FROM ICSITEMROUTE2OP
  2676. WHERE ItemCode = d.ItemCode ANd ROUTECODE = e.RouteCode AND OPCODE='{1}')
  2677. order by opseq) b ON a.ProductDocNo=b.MOCODE AND a.opcode=b.opcode", LotNo, OPcode);
  2678. DataTable dtPR = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sqlPR).Tables[0];
  2679. if (dtPR != null && dtPR.Rows.Count > 0)
  2680. {
  2681. return dtPR.Rows[0]["OPCode"].ToString();
  2682. }
  2683. return "";
  2684. }
  2685. catch (Exception ex)
  2686. {
  2687. return "";
  2688. }
  2689. }
  2690. public static DataTable GetToUserList(String Appconstr)
  2691. {
  2692. try
  2693. {
  2694. string sql = @"
  2695. SELECT DISTINCT ToUserList ,UU.USERNAME FROM ICSNCRDoc NN
  2696. LEFT JOIN SYS_USER UU ON NN.ToUserList=UU.USERCODE
  2697. WHERE ISNULL(ToUserList,'')!=''
  2698. UNION SELECT '',''
  2699. order by 1,2
  2700. ";
  2701. DataTable dt = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql).Tables[0];
  2702. if (dt != null && dt.Rows.Count > 0)
  2703. {
  2704. return dt;
  2705. }
  2706. else
  2707. {
  2708. return null;
  2709. }
  2710. }
  2711. catch (Exception ex)
  2712. {
  2713. return null;
  2714. }
  2715. }
  2716. public static string IsCurrentDoPersonORToUserList(String SecDocNO, string CurrentUser, String Appconstr)
  2717. {
  2718. FramDataContext db = new FramDataContext(Appconstr);
  2719. db.Connection.Open();
  2720. db.Transaction = db.Connection.BeginTransaction();
  2721. try
  2722. {
  2723. var line = db.ICSNCRDoc.Where(a => a.SecDocNO == SecDocNO);
  2724. if (line != null && line.Count() > 0)
  2725. {
  2726. foreach (ICSNCRDoc item in line)
  2727. {
  2728. string ToUserist = item.ToUserList;
  2729. if (ToUserist.Contains(CurrentUser) || (!string.IsNullOrEmpty(item.EATTRIBUTE3) && item.EATTRIBUTE3.Contains(CurrentUser)))
  2730. {
  2731. return "";
  2732. }
  2733. else
  2734. {
  2735. //if (!string.IsNullOrEmpty(item.EATTRIBUTE3))
  2736. //{
  2737. // var line2 = db.Sys_User.Where(a => a.UserCode == item.EATTRIBUTE3);
  2738. // if (line2 != null && line2.Count() > 0)
  2739. // {
  2740. // return SecDocNO + "当前处理人是:" + line2.First().UserName + ",当前账号不能处理。";
  2741. // }
  2742. // else
  2743. // {
  2744. // return SecDocNO + "当前处理人账号是:" + item.EATTRIBUTE3 + ",当前账号不能处理。";
  2745. // }
  2746. //}
  2747. //else
  2748. //{
  2749. // return "OK";
  2750. //}
  2751. return "OK";
  2752. }
  2753. }
  2754. }
  2755. }
  2756. catch (Exception ex)
  2757. {
  2758. return "";
  2759. }
  2760. return "";
  2761. }
  2762. public static string GetCanYuRenList(String Appconstr)
  2763. {
  2764. try
  2765. {
  2766. string sql = @" select isnull(EnumText,'') CanYuRen from Sys_EnumValues where EnumKey ='083' and EnumValue='参与人' ";
  2767. DataTable dt = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql).Tables[0];
  2768. if (dt != null && dt.Rows.Count > 0)
  2769. {
  2770. return dt.Rows[0][0].ToString();
  2771. }
  2772. else
  2773. {
  2774. return "";
  2775. }
  2776. }
  2777. catch (Exception ex)
  2778. {
  2779. return "";
  2780. }
  2781. }
  2782. public static string GetAPSProjectCode(string Lotno, String Appconstr)
  2783. {
  2784. try
  2785. {
  2786. string sql = @" select 子项目号 from [10.29.1.129].[aps_middb].dbo.peg_result_all_by_column
  2787. inner join icsmo mo on isnull(,'')=mo.mocode
  2788. inner join icsmo2lot lot on lot.mocode=mo.mocode
  2789. WHERE is not null
  2790. and CHARINDEX(lot.lotno,'" + Lotno + @"' )!=0 ";
  2791. DataTable dt = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql).Tables[0];
  2792. if (dt != null && dt.Rows.Count > 0)
  2793. {
  2794. return dt.Rows[0][0].ToString();
  2795. }
  2796. else
  2797. {
  2798. return "";
  2799. }
  2800. }
  2801. catch (Exception ex)
  2802. {
  2803. return "";
  2804. }
  2805. }
  2806. public static List<NCR_SupplyModel> GetNCR_GongYingShang(String SecDocNO, List<string> TypeList, NCRCPIRModel CPIR, String Appconstr)
  2807. {
  2808. try
  2809. {
  2810. List<string> GYS = new List<string>();
  2811. List<NCR_SupplyModel> GYSModel = new List<NCR_SupplyModel>();
  2812. //10 11 料开头的
  2813. if (!string.IsNullOrEmpty(CPIR.ItemCode) &&
  2814. (CPIR.ItemCode.Substring(0, 2) == "10" || CPIR.ItemCode.Substring(0, 2) == "11"))
  2815. {
  2816. //1、抓取上料表
  2817. string SLItemsql = "";
  2818. if (TypeList != null && TypeList.Count > 0)
  2819. {
  2820. SLItemsql = " and ( 1=2 ";
  2821. foreach (string item in TypeList)
  2822. {
  2823. switch (item)
  2824. {
  2825. case "阀体": SLItemsql += " or a.INVCODE like '130101%' "; break;
  2826. case "阀帽": SLItemsql += " or a.INVCODE like '130102%' "; break;
  2827. case "球座组件": SLItemsql += " or a.INVCODE like '1249%' "; break;
  2828. case "阀杆": SLItemsql += " or a.INVCODE like '130402%' "; break;
  2829. case "螺柱": SLItemsql += " or a.INVCODE like '140402%' "; break;
  2830. case "螺母": SLItemsql += " or a.INVCODE like '140403%' "; break;
  2831. default: SLItemsql += " or a.INVCODE like '" + item + "%' "; break;
  2832. }
  2833. }
  2834. SLItemsql += " ) ";
  2835. }
  2836. string lotno = CPIR.SrcDocInfo;
  2837. lotno = lotno.Replace(",", "','");
  2838. string sqlSL = @" SELECT DISTINCT
  2839. RcvSupplierCode AS ,
  2840. supp.name ,
  2841. rcv.RcvLineSrcPOSrcDocNo as ,
  2842. rcv.RcvLineSrcPOSrcDocLineNo as
  2843. FROM ICSMO mo
  2844. left join ICSLOTONWIPITEM a on mo.MoCode = a.MoCode
  2845. LEFT JOIN Base_Inventory b ON a.ITEMCODE = b.ItemCode
  2846. LEFT JOIN Base_Inventory c ON a.INVCODE = c.ItemCode
  2847. LEFT JOIN ICSROUTE d ON a.ROUTECODE = d.ROUTECODE
  2848. LEFT JOIN ICSOP e ON a.OPCODE = e.OPCODE
  2849. LEFT JOIN WM_BarCode bar ON bar.BarCodeNo=a.INVLOTNO --AND a.INVLOTNO LIKE 'RCV%'
  2850. LEFT JOIN WM_InitialInvtory Invtory ON Invtory.guid=bar.Srcguid
  2851. LEFT JOIN WM_RCVShip rcv ON bar.RCVShipguid=rcv.guid
  2852. LEFT JOIN [10.29.1.115].[ATW].dbo.[CBO_Project] project(NOLOCK) ON project.Code=mo.ProjectCode
  2853. LEFT JOIN [10.29.1.115].[ATW].dbo.SM_SOLine SOLine ON soline.Project = project.ID
  2854. AND soline.DescFlexField_PrivateDescSeg17 is NOT NULL and soline.DescFlexField_PrivateDescSeg17!=''
  2855. left join (select ss.Code,ss_t.name from [10.29.1.115].[ATW].dbo.CBO_Supplier ss
  2856. left join [10.29.1.115].[ATW].dbo.CBO_Supplier_Trl ss_t on ss.id=ss_t.id ) supp on supp.code=RcvSupplierCode
  2857. where 1=1 And a.LOTNO <>''
  2858. and (a.INVLOTNO in ('{0}') OR a.LOTNO in ('{0}'))
  2859. {1}
  2860. UNION
  2861. SELECT DISTINCT
  2862. RcvSupplierCode AS ,
  2863. supp.name ,
  2864. rcv.RcvLineSrcPOSrcDocNo as ,
  2865. rcv.RcvLineSrcPOSrcDocLineNo as
  2866. FROM ICSMO mo
  2867. INNER join ICSLOTONWIPITEMHistory a on mo.MoCode = a.MoCode
  2868. LEFT JOIN Base_Inventory b ON a.ITEMCODE = b.ItemCode
  2869. LEFT JOIN Base_Inventory c ON a.INVCODE = c.ItemCode
  2870. LEFT JOIN ICSROUTE d ON a.ROUTECODE = d.ROUTECODE
  2871. LEFT JOIN ICSOP e ON a.OPCODE = e.OPCODE
  2872. LEFT JOIN WM_BarCode bar ON bar.BarCodeNo=a.INVLOTNO --AND a.INVLOTNO LIKE 'RCV%'
  2873. LEFT JOIN WM_InitialInvtory Invtory ON Invtory.guid=bar.Srcguid
  2874. LEFT JOIN WM_RCVShip rcv ON bar.RCVShipguid=rcv.guid
  2875. LEFT JOIN [10.29.1.115].[ATW].dbo.[CBO_Project] project(NOLOCK) ON project.Code=mo.ProjectCode
  2876. LEFT JOIN [10.29.1.115].[ATW].dbo.SM_SOLine SOLine ON soline.Project = project.ID
  2877. AND soline.DescFlexField_PrivateDescSeg17 is NOT NULL and soline.DescFlexField_PrivateDescSeg17!=''
  2878. left join (select ss.Code,ss_t.name from [10.29.1.115].[ATW].dbo.CBO_Supplier ss
  2879. left join [10.29.1.115].[ATW].dbo.CBO_Supplier_Trl ss_t on ss.id=ss_t.id ) supp on supp.code=RcvSupplierCode
  2880. where 1=1 And a.LOTNO <>''
  2881. and (a.INVLOTNO in ('{0}') OR a.LOTNO in ('{0}')) {1}";
  2882. sqlSL = string.Format(sqlSL, lotno, SLItemsql);
  2883. DataTable dtsl = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sqlSL).Tables[0];
  2884. if (dtsl != null && dtsl.Rows.Count > 0)
  2885. {
  2886. foreach (DataRow item in dtsl.Rows)
  2887. {
  2888. if (!string.IsNullOrEmpty(item["供应商编码"].ToString().Trim()) && !GYS.Contains(item["供应商编码"].ToString().Trim()))
  2889. {
  2890. GYS.Add(item["供应商编码"].ToString());
  2891. NCR_SupplyModel supp = new NCR_SupplyModel();
  2892. supp.SupplyCode = item["供应商编码"].ToString();
  2893. supp.SupplyName = item["供应商名称"].ToString();
  2894. supp.PONo = item["采购单号"].ToString();
  2895. supp.POLineNo = item["采购单行号"].ToString();
  2896. GYSModel.Add(supp);
  2897. }
  2898. }
  2899. }
  2900. }
  2901. //2、查炉号的方式 查供应商
  2902. if (GYS == null || GYS.Count == 0)
  2903. {
  2904. string[] LotList = null;
  2905. string GYSLL = "";
  2906. if (!string.IsNullOrEmpty(CPIR.SrcDocInfo))
  2907. {
  2908. LotList = CPIR.SrcDocInfo.Split(',');
  2909. }
  2910. if (LotList != null)
  2911. {
  2912. foreach (string lot in LotList)
  2913. {
  2914. //通过查炉号的方式 查供应商
  2915. DataTable dt_GY = GetInvLotFurnaceStr(lot, TypeList, Appconstr);
  2916. if (dt_GY != null && dt_GY.Rows.Count > 0)
  2917. {
  2918. for (int i = 0; i < dt_GY.Rows.Count; i++)
  2919. {
  2920. DataRow dr = dt_GY.Rows[i];
  2921. if (!GYS.Contains(dr["供应商编码"].ToString()) && !string.IsNullOrEmpty(dr["供应商编码"].ToString()))
  2922. {
  2923. GYS.Add(dr["供应商编码"].ToString());
  2924. NCR_SupplyModel supp = new NCR_SupplyModel();
  2925. supp.SupplyCode = dr["供应商编码"].ToString();
  2926. supp.SupplyName = dr["供应商名称"].ToString();
  2927. supp.PONo = dr["采购单号"].ToString();
  2928. supp.POLineNo = dr["采购单行号"].ToString();
  2929. GYSModel.Add(supp);
  2930. }
  2931. }
  2932. }
  2933. }
  2934. }
  2935. }
  2936. //3、查NCR责任人中写的供应商 //填写的是简称,不抓了。
  2937. if (GYS == null || GYS.Count == 0)
  2938. {
  2939. return null;
  2940. }
  2941. else
  2942. {
  2943. return GYSModel;
  2944. }
  2945. }
  2946. catch (Exception ex)
  2947. {
  2948. return null;
  2949. }
  2950. }
  2951. public static NCRCPIRModel GetNCR_CPIR(ICSNCRDoc NCR, String Appconstr)
  2952. {
  2953. NCRCPIRModel item=new NCRCPIRModel ();
  2954. try
  2955. {
  2956. item.SecDocNO=NCR.SecDocNO;
  2957. item.ContentDesc=NCR.ContentDesc;
  2958. item.ErrorType=NCR.ErrorType;
  2959. item.Furnace=NCR.Furnace;
  2960. item.ItemCode=NCR.ItemCode;
  2961. item.Point=NCR.Point;
  2962. item.ProjectCode=NCR.ProjectCode;
  2963. item.Qty=NCR.Qty;
  2964. item.SecDocCreateTime=NCR.SecDocCreateTime;
  2965. item.SrcDocInfo=NCR.SrcDocInfo;
  2966. string sql = @"
  2967. SELECT
  2968. d.itemname ,
  2969. (SELECT max(LimitTime) FROM ICSNCRDocRectifyProcess WHERE SecDocNO = a.SecDocNO GROUP BY SecDocNO)
  2970. FROM ICSNCRDoc a
  2971. LEFT JOIN Base_Inventory d ON a.itemcode = d.itemcode
  2972. WHERE a.SECDOCNO='" + NCR.SecDocNO + @"'
  2973. ";
  2974. DataTable dt = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql).Tables[0];
  2975. if (dt != null && dt.Rows.Count>0)
  2976. {
  2977. item.ItemName = dt.Rows[0]["物料描述"].ToString();
  2978. if (!string.IsNullOrEmpty(dt.Rows[0]["要求完成日期"].ToString()))
  2979. {
  2980. item.RequirDate = Convert.ToDateTime(dt.Rows[0]["要求完成日期"].ToString());
  2981. }
  2982. }
  2983. return item;
  2984. }
  2985. catch (Exception ex)
  2986. {
  2987. return null;
  2988. }
  2989. }
  2990. public static List<string> GerNCRGYS(string SecDocNo, String Appconstr)
  2991. {
  2992. return null;
  2993. }
  2994. #region 返回供应商
  2995. private static DataTable GetInvLotFurnaceStr(string LotNo, List<string> TypeList, string dsconn)
  2996. {
  2997. string InvLotFurnaceStr = "";
  2998. string InvLotStr = "";
  2999. List<string> BarNoList = new List<string>();
  3000. //ICSInvLotFurnaceDAL.GetBarNoList(LotNo, BarNoList, dsconn);
  3001. DataTable dt = GetInvLotFurnace(BarNoList,TypeList, dsconn);
  3002. if (dt != null && dt.Rows.Count > 0)
  3003. {
  3004. return dt;
  3005. }
  3006. else
  3007. {
  3008. return null;
  3009. }
  3010. }
  3011. #endregion
  3012. #region 返回供应商New/炉号New
  3013. public static string GetInvLotFurnaceStrNew(string LotNo, string dsconn,string colsName)
  3014. {
  3015. string InvLotFurnaceStr = "";
  3016. string InvLotStr = "";
  3017. string[] lotlist = LotNo.Split(',');
  3018. for (int i = 0; i < lotlist.Length; i++)
  3019. {
  3020. List<string> BarNoList = new List<string>();
  3021. //ICSInvLotFurnaceDAL.GetBarNoList(lotlist[i], BarNoList, dsconn);
  3022. //DataTable dt = ICSInvLotFurnaceDAL.GetInvLotFurnace(BarNoList, dsconn);
  3023. //if (dt != null && dt.Rows.Count > 0)
  3024. //{
  3025. // foreach (DataRow dr in dt.Rows)
  3026. // {
  3027. // if (!("," + InvLotFurnaceStr).Contains("," + dr[colsName].ToString() + ","))
  3028. // {
  3029. // InvLotFurnaceStr += dr[colsName].ToString() + ",";
  3030. // }
  3031. // }
  3032. //}
  3033. }
  3034. return InvLotFurnaceStr.TrimEnd(',');
  3035. }
  3036. #endregion
  3037. #region 根据批次代码查询
  3038. public static DataTable GetInvLotFurnace(List<string> BarNoList, List<string> TypeList, string dsconn)
  3039. {
  3040. string Itemsql = "";
  3041. if (TypeList != null && TypeList.Count > 0)
  3042. {
  3043. Itemsql = " and ( 1=2 ";
  3044. foreach (string item in TypeList)
  3045. {
  3046. switch (item)
  3047. {
  3048. case "阀体": Itemsql += " or 物料编码 like '130101%' "; break;
  3049. case "阀帽": Itemsql += " or 物料编码 like '130102%' "; break;
  3050. case "球座组件": Itemsql += " or 物料编码 like '1249%' "; break;
  3051. case "阀杆": Itemsql += " or 物料编码 like '130402%' "; break;
  3052. case "螺柱": Itemsql += " or 物料编码 like '140402%' "; break;
  3053. case "螺母": Itemsql += " or 物料编码 like '140403%' "; break;
  3054. default: Itemsql += " or 物料编码 like '" + item + "%' "; break;
  3055. }
  3056. }
  3057. Itemsql += " ) ";
  3058. }
  3059. string sql = @" select * from GetInvLotFurnace where [条码] in ({0}) {1} ";
  3060. string lotNoStr = "";
  3061. if (BarNoList.Count > 0)
  3062. {
  3063. foreach (string str in BarNoList)
  3064. {
  3065. lotNoStr += "'" + str + "',";
  3066. }
  3067. lotNoStr = lotNoStr.TrimEnd(',');
  3068. sql = string.Format(sql, lotNoStr,Itemsql);
  3069. return DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  3070. }
  3071. else
  3072. {
  3073. return new DataTable();
  3074. }
  3075. }
  3076. #endregion
  3077. #region 获取下一道工序
  3078. public static string GetCurrentOPCode(string LotNO)
  3079. {
  3080. string sql = @"
  3081. SELECT distinct
  3082. '' as isSelect,
  3083. a.ID,
  3084. lot.LOTNO,
  3085. b.MOPLANQTY as MoQty,
  3086. lot.MOCODE,
  3087. lot.LOTSEQ,
  3088. lot.LOTStatus,
  3089. d.ITEMCODE,
  3090. c.ROUTECODE,
  3091. '' as OPCODE,
  3092. CAST(a.ISCOM AS BIT) AS ISCOM,
  3093. a.ISHOLD,
  3094. a.SHELFNO,
  3095. b.MOSEQ,
  3096. '' as CollectStatus,
  3097. b.MODESC,
  3098. c.ROUTEDESC,
  3099. d.ItemName,
  3100. e.OPCODE AS NEXTOPCODE,
  3101. f.OPDESC,
  3102. g.OPDESC AS NEXTOPDESC
  3103. FROM ICSMO2Lot lot
  3104. LEFT JOIN ICSLOTSIMULATION a on lot.LotNo = a.LotNo and a.MoCode = lot.MoCode
  3105. LEFT JOIN ICSMO b ON lot.MOCODE = b.MOCODE
  3106. LEFT JOIN ICSMO2Route k on b.MOCODE = k.MOCODE
  3107. LEFT JOIN ICSROUTE c ON k.ROUTECODE = c.ROUTECODE
  3108. LEFT JOIN Base_Inventory d ON b.ITEMCODE = d.ITEMCODE
  3109. inner JOIN ( SELECT ITEMCODE,ROUTECODE,OPCODE,OPSEQ FROM ICSITEMROUTE2OP) e ON e.ITEMCODE = b.ITEMCODE
  3110. AND e.ROUTECODE = k.ROUTECODE
  3111. AND e.OPSEQ = (SELECT MIN(OPSEQ) FROM ICSITEMROUTE2OP WHERE ITEMCODE = b.ITEMCODE AND ROUTECODE = k.ROUTECODE )
  3112. LEFT JOIN ICSOP f ON a.OPCODE = f.OPCODE
  3113. LEFT JOIN ICSOP g ON e.OPCODE = g.OPCODE
  3114. WHERE
  3115. 1=1 and a.ID IS NULL And lot.LOTNO = '" + LotNO + @"'
  3116. union
  3117. SELECT distinct
  3118. '' as isSelect,
  3119. a.ID,
  3120. a.LOTNO,
  3121. b.MOPLANQTY as MoQty,
  3122. a.MOCODE,
  3123. a.LOTSEQ,
  3124. a.LOTStatus,
  3125. a.ITEMCODE,
  3126. a.ROUTECODE,
  3127. a.OPCODE,
  3128. CAST(a.ISCOM AS BIT) AS ISCOM,
  3129. a.ISHOLD,
  3130. a.SHELFNO,
  3131. a.MOSEQ,
  3132. case when a.CollectStatus = 'COLLECT_BEGIN' then '' else '' end as CollectStatus,
  3133. b.MODESC,
  3134. c.ROUTEDESC,
  3135. d.ItemName,
  3136. e.OPCODE AS NEXTOPCODE,
  3137. f.OPDESC,
  3138. g.OPDESC AS NEXTOPDESC
  3139. FROM
  3140. ICSLOTSIMULATION a
  3141. LEFT JOIN ICSMO b ON a.MOCODE = b.MOCODE
  3142. LEFT JOIN ICSROUTE c ON a.ROUTECODE = c.ROUTECODE
  3143. LEFT JOIN Base_Inventory d ON a.ITEMCODE = d.ITEMCODE
  3144. LEFT JOIN ( SELECT ITEMCODE,ROUTECODE,OPCODE,OPSEQ FROM ICSITEMROUTE2OP) e ON e.ITEMCODE = a.ITEMCODE
  3145. AND e.ROUTECODE = a.ROUTECODE
  3146. AND e.OPSEQ = (SELECT MIN(OPSEQ) FROM ICSITEMROUTE2OP WHERE ITEMCODE = a.ITEMCODE AND ROUTECODE = a.ROUTECODE
  3147. AND OPSEQ > (SELECT OPSEQ FROM ICSITEMROUTE2OP WHERE ITEMCODE = a.ITEMCODE AND ROUTECODE = a.ROUTECODE AND OPCODE = a.OPCODE))
  3148. LEFT JOIN ICSOP f ON a.OPCODE = f.OPCODE
  3149. LEFT JOIN ICSOP g ON e.OPCODE = g.OPCODE
  3150. WHERE
  3151. 1=1 And a.LOTNO = '" + LotNO + "'";
  3152. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  3153. if (data != null && data.Rows.Count > 0)
  3154. {
  3155. if (data.Rows[0]["CollectStatus"].ToString() == "未开工")
  3156. {
  3157. return data.Rows[0]["NEXTOPCODE"].ToString();
  3158. }
  3159. else if (data.Rows[0]["CollectStatus"].ToString() == "开始")
  3160. {
  3161. return data.Rows[0]["OPCODE"].ToString();
  3162. }
  3163. else if (data.Rows[0]["CollectStatus"].ToString() == "结束" && !string.IsNullOrEmpty(data.Rows[0]["NEXTOPCODE"].ToString()))
  3164. {
  3165. return data.Rows[0]["NEXTOPCODE"].ToString();
  3166. }
  3167. else
  3168. {
  3169. return GetNextOpCodeByModel(LotNO);
  3170. }
  3171. }
  3172. else
  3173. {
  3174. return GetNextOpCodeByModel(LotNO);
  3175. }
  3176. }
  3177. public static string GetNextOpCodeByModel(string LotNO)
  3178. {
  3179. string sql = @"
  3180. SELECT distinct
  3181. '' as isSelect,
  3182. a.ID,
  3183. lot.LOTNO,
  3184. b.MOPLANQTY as MoQty,
  3185. lot.MOCODE,
  3186. lot.LOTSEQ,
  3187. lot.LOTStatus,
  3188. d.ITEMCODE,
  3189. c.ROUTECODE,
  3190. '' as OPCODE,
  3191. CAST(a.ISCOM AS BIT) AS ISCOM,
  3192. a.ISHOLD,
  3193. a.SHELFNO,
  3194. b.MOSEQ,
  3195. '' as CollectStatus,
  3196. b.MODESC,
  3197. c.ROUTEDESC,
  3198. d.ItemName,
  3199. e.OPCODE AS NEXTOPCODE,
  3200. f.OPDESC,
  3201. g.OPDESC AS NEXTOPDESC
  3202. FROM ICSMO2Lot lot
  3203. LEFT JOIN ICSLOTSIMULATION a on lot.LotNo = a.LotNo and a.MoCode = lot.MoCode
  3204. LEFT JOIN ICSMO b ON lot.MOCODE = b.MOCODE
  3205. LEFT JOIN ICSMO2Route k on b.MOCODE = k.MOCODE
  3206. LEFT JOIN ICSROUTE c ON k.ROUTECODE = c.ROUTECODE
  3207. LEFT JOIN Base_Inventory d ON b.ITEMCODE = d.ITEMCODE
  3208. LEFT JOIN ( SELECT MODELCODE,ROUTECODE,OPCODE,OPSEQ FROM ICSMODELROUTE2OP) e ON e.MODELCODE = d.ItemMainCategoryCode
  3209. AND e.ROUTECODE = k.ROUTECODE
  3210. AND e.OPSEQ = (SELECT MIN(OPSEQ) FROM ICSMODELROUTE2OP WHERE MODELCODE = d.ItemMainCategoryCode AND ROUTECODE = k.ROUTECODE )
  3211. LEFT JOIN ICSOP f ON a.OPCODE = f.OPCODE
  3212. LEFT JOIN ICSOP g ON e.OPCODE = g.OPCODE
  3213. WHERE
  3214. 1=1 And a.ID is null and lot.LOTNO = '" + LotNO + @"'
  3215. union
  3216. SELECT distinct
  3217. '' as isSelect,
  3218. a.ID,
  3219. a.LOTNO,
  3220. b.MOPLANQTY as MoQty,
  3221. a.MOCODE,
  3222. a.LOTSEQ,
  3223. a.LOTStatus,
  3224. a.ITEMCODE,
  3225. a.ROUTECODE,
  3226. a.OPCODE,
  3227. CAST(a.ISCOM AS BIT) AS ISCOM,
  3228. a.ISHOLD,
  3229. a.SHELFNO,
  3230. a.MOSEQ,
  3231. case when a.CollectStatus = 'COLLECT_BEGIN' then '' else '' end as CollectStatus,
  3232. b.MODESC,
  3233. c.ROUTEDESC,
  3234. d.ItemName,
  3235. e.OPCODE AS NEXTOPCODE,
  3236. f.OPDESC,
  3237. g.OPDESC AS NEXTOPDESC
  3238. FROM
  3239. ICSLOTSIMULATION a
  3240. LEFT JOIN ICSMO b ON a.MOCODE = b.MOCODE
  3241. LEFT JOIN ICSROUTE c ON a.ROUTECODE = c.ROUTECODE
  3242. LEFT JOIN Base_Inventory d ON a.ITEMCODE = d.ITEMCODE
  3243. LEFT JOIN ( SELECT MODELCODE,ROUTECODE,OPCODE,OPSEQ FROM ICSMODELROUTE2OP) e ON e.MODELCODE = d.ItemMainCategoryCode
  3244. AND e.ROUTECODE = a.ROUTECODE
  3245. AND e.OPSEQ = (SELECT MIN(OPSEQ) FROM ICSMODELROUTE2OP WHERE MODELCODE = d.ItemMainCategoryCode AND ROUTECODE = a.ROUTECODE
  3246. AND OPSEQ > (SELECT OPSEQ FROM ICSMODELROUTE2OP WHERE MODELCODE = d.ItemMainCategoryCode AND ROUTECODE = a.ROUTECODE AND OPCODE = a.OPCODE))
  3247. LEFT JOIN ICSOP f ON a.OPCODE = f.OPCODE
  3248. LEFT JOIN ICSOP g ON e.OPCODE = g.OPCODE
  3249. WHERE
  3250. 1=1 And a.LOTNO = '" + LotNO + "'";
  3251. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  3252. if (data != null && data.Rows.Count > 0)
  3253. {
  3254. if (data.Rows[0]["CollectStatus"].ToString() == "未开工")
  3255. {
  3256. return data.Rows[0]["NEXTOPCODE"].ToString();
  3257. }
  3258. else if (data.Rows[0]["CollectStatus"].ToString() == "开始")
  3259. {
  3260. return data.Rows[0]["OPCODE"].ToString();
  3261. }
  3262. else if (data.Rows[0]["CollectStatus"].ToString() == "结束")
  3263. {
  3264. return data.Rows[0]["NEXTOPCODE"].ToString();
  3265. }
  3266. }
  3267. return "";
  3268. }
  3269. public static string GetUserName(String UserCode, String Appconstr)
  3270. {
  3271. FramDataContext db = new FramDataContext(Appconstr);
  3272. db.Connection.Open();
  3273. db.Transaction = db.Connection.BeginTransaction();
  3274. try
  3275. {
  3276. var line = db.Sys_User.Where(a => a.UserCode == UserCode);
  3277. if (line != null && line.Count() > 0)
  3278. {
  3279. Sys_User UU = (Sys_User)line.First();
  3280. return UU.UserName;
  3281. }
  3282. }
  3283. catch (Exception ex)
  3284. {
  3285. return "";
  3286. }
  3287. return "";
  3288. }
  3289. public static string GetCurrentUserDep(String UserCode, String Appconstr)
  3290. {
  3291. string CurrentUserDep = "";
  3292. try
  3293. {
  3294. string sql = @"
  3295. SELECT EnumText
  3296. FROM
  3297. Sys_EnumValues vv
  3298. WHERE
  3299. 1 = 1
  3300. AND ( CHARINDEX( '{0}', vv.Define1 ) != 0 OR CHARINDEX( '{0}', vv.Define5 ) != 0 )
  3301. AND vv.EnumKey= '076'
  3302. and EnumText!=''
  3303. UNION
  3304. SELECT EnumText
  3305. FROM
  3306. Sys_EnumValues vv
  3307. LEFT JOIN (
  3308. SELECT workno
  3309. FROM ICSUserInfo
  3310. WHERE
  3311. deptno IN (
  3312. SELECT items
  3313. FROM
  3314. [dbo].[splitl] (
  3315. ( SELECT TOP 1 EATTRIBUTE1 FROM ICSUserInfo WHERE workno = '{0}'
  3316. AND EATTRIBUTE1 != '' AND EATTRIBUTE1 IS NOT NULL AND deptno != '' ),
  3317. ','
  3318. ))
  3319. ) uu ON 1 = 1
  3320. WHERE
  3321. 1 = 1
  3322. AND ( CHARINDEX( uu.workno, vv.Define1 ) != 0 OR CHARINDEX( uu.workno, vv.Define5 ) != 0 )
  3323. AND vv.EnumKey= '076'
  3324. and EnumText!=''
  3325. ";
  3326. sql = string.Format(sql, UserCode);
  3327. DataTable data = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql).Tables[0];
  3328. if (data != null && data.Rows.Count > 0)
  3329. {
  3330. for (int i = 0; i < data.Rows.Count; i++)
  3331. {
  3332. CurrentUserDep += "," + data.Rows[i]["EnumText"].ToString().Trim();
  3333. }
  3334. }
  3335. return CurrentUserDep;
  3336. }
  3337. catch (Exception ex)
  3338. {
  3339. return "";
  3340. }
  3341. return "";
  3342. }
  3343. #endregion
  3344. public static List<NCRProcessBackModel> listPBackLog(String SecDocNO, string Type, String Appconstr)
  3345. {
  3346. FramDataContext db = new FramDataContext(Appconstr);
  3347. db.Connection.Open();
  3348. db.Transaction = db.Connection.BeginTransaction();
  3349. List<NCRProcessBackModel> list = new List<NCRProcessBackModel>();
  3350. try
  3351. {
  3352. // var line = db.ICSNCRDocPreventionProcessLog.Where(a => a.DoType == Type && a.SecDocNO == SecDocNO).OrderByDescending(a => a.MTIME);
  3353. var line = from a in db.ICSNCRDocPreventionProcessLog
  3354. where a.SecDocNO == SecDocNO && a.DoType == Type
  3355. orderby a.MTIME
  3356. select new
  3357. {
  3358. ProcessName = db.ICSNCRDocPreventionProcess.Where
  3359. (b => b.ID == a.PreventionID && b.SecDocNO == a.SecDocNO).
  3360. Select(b => b.ProcessName).FirstOrDefault(),
  3361. a.EATTRIBUTE2,
  3362. a.MTIME
  3363. };
  3364. if (line != null && line.Count() > 0)
  3365. {
  3366. foreach (var item in line)
  3367. {
  3368. NCRProcessBackModel model = new NCRProcessBackModel();
  3369. model.Department = item.ProcessName;
  3370. model.BackContect = item.EATTRIBUTE2;
  3371. model.BackTime = item.MTIME;
  3372. list.Add(model);
  3373. }
  3374. return list;
  3375. }
  3376. }
  3377. catch (Exception ex)
  3378. {
  3379. return null;
  3380. }
  3381. return null;
  3382. }
  3383. public static List<NCRProcessBackModel> listRBackLog(String SecDocNO, string Type, String Appconstr)
  3384. {
  3385. FramDataContext db = new FramDataContext(Appconstr);
  3386. db.Connection.Open();
  3387. db.Transaction = db.Connection.BeginTransaction();
  3388. List<NCRProcessBackModel> list = new List<NCRProcessBackModel>();
  3389. try
  3390. {
  3391. var line = from a in db.ICSNCRDocRectifyProcessLog
  3392. where a.SecDocNO == SecDocNO && a.DoType == Type
  3393. orderby a.MTIME
  3394. select new
  3395. {
  3396. ProcessName = db.ICSNCRDocRectifyProcess.Where
  3397. (b => b.ID == a.RectifyID && b.SecDocNO == a.SecDocNO).
  3398. Select(b => b.ProcessName).FirstOrDefault(),
  3399. a.EATTRIBUTE2,
  3400. a.MTIME
  3401. };
  3402. if (line != null && line.Count() > 0)
  3403. {
  3404. foreach (var item in line)
  3405. {
  3406. NCRProcessBackModel model = new NCRProcessBackModel();
  3407. model.Department = item.ProcessName;
  3408. model.BackContect = item.EATTRIBUTE2;
  3409. model.BackTime = item.MTIME;
  3410. list.Add(model);
  3411. }
  3412. return list;
  3413. }
  3414. }
  3415. catch (Exception ex)
  3416. {
  3417. return null;
  3418. }
  3419. return null;
  3420. }
  3421. public static string CheckPZLJMO(String MOCode, String Appconstr)
  3422. {
  3423. try
  3424. {
  3425. string sql = @"
  3426. SELECT
  3427. LOT.LOTNO,
  3428. ISNULL( chk.CKRESULT, 0 ) CKResult
  3429. FROM
  3430. ICSMO2Lot lot
  3431. LEFT JOIN (
  3432. SELECT *
  3433. FROM
  3434. ( SELECT ROW_NUMBER () OVER ( partition BY LOTNO ORDER BY mtime DESC ) rowId,*
  3435. FROM ICSQualityCKDATA ck WHERE type = '' ) AS AuctionRecords
  3436. WHERE
  3437. rowId = 1
  3438. ) chk ON lot.lotno = chk.lotno
  3439. WHERE
  3440. lot.mocode = '" + MOCode + @"' ";
  3441. DataTable dt = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql).Tables[0];
  3442. if (dt != null && dt.Rows.Count > 0)
  3443. {
  3444. DataRow[] drs = dt.Select(" CKResult=0 ");
  3445. if (drs != null && drs.Length > 0)
  3446. {
  3447. return MOCode + "未全部检验合格,不能关闭NCR";
  3448. }
  3449. else
  3450. {
  3451. return "";
  3452. }
  3453. }
  3454. else
  3455. {
  3456. return "未找到" + MOCode+"工单批号检验数据";
  3457. }
  3458. }
  3459. catch (Exception ex)
  3460. {
  3461. return ex.Message;
  3462. }
  3463. }
  3464. //public static ICSQualityCKDATA GetLastWXCK(string lotno, string opcode, string Appconstr)
  3465. //{
  3466. // FramDataContext db = new FramDataContext(Appconstr);
  3467. // db.Connection.Open();
  3468. // db.Transaction = db.Connection.BeginTransaction();
  3469. // try
  3470. // {
  3471. // var line = db.ICSQualityCKDATA.Where(a => a.LOTNO == lotno && a.OPCode == opcode && a.Type == "外协").OrderByDescending(a => a.MTIME);
  3472. // if (line != null && line.Count() > 0)
  3473. // { return (ICSQualityCKDATA)line.First(); }
  3474. // }
  3475. // catch (Exception ex)
  3476. // {
  3477. // return null;
  3478. // }
  3479. // return null;
  3480. //}
  3481. #endregion
  3482. #region 删除
  3483. #endregion
  3484. #region AddandEditList
  3485. public static void AddPreventionProcessList(List<ICSNCRDocPreventionProcess> InfoList, string Appconstr)
  3486. {
  3487. FramDataContext db = new FramDataContext(Appconstr);
  3488. db.Connection.Open();
  3489. db.Transaction = db.Connection.BeginTransaction();
  3490. try
  3491. {
  3492. foreach (ICSNCRDocPreventionProcess Info in InfoList)
  3493. {
  3494. bool isNew = false;
  3495. var line = db.ICSNCRDocPreventionProcess.SingleOrDefault(a => a.SecDocNO == Info.SecDocNO && a.Seq == Info.Seq);
  3496. if (line == null)
  3497. {
  3498. isNew = true;
  3499. line = new ICSNCRDocPreventionProcess();
  3500. line.ID = AppConfig.GetGuid();
  3501. }
  3502. else
  3503. {
  3504. throw new Exception("已存在预防流程数据");
  3505. }
  3506. line.SecDocNO = Info.SecDocNO;
  3507. line.Seq = Info.Seq;
  3508. line.PreventionID = Info.PreventionID;
  3509. line.ProcessName = Info.ProcessName;
  3510. line.EATTRIBUTE1 = Info.EATTRIBUTE1;
  3511. line.EATTRIBUTE2 = Info.EATTRIBUTE2;
  3512. line.LimitTime = Info.LimitTime;
  3513. line.MUSER = AppConfig.UserId;
  3514. line.MUSERName = AppConfig.UserName;
  3515. line.MTIME = DateTime.Now;
  3516. line.WorkPoint = AppConfig.WorkPointCode;
  3517. if (isNew) db.ICSNCRDocPreventionProcess.InsertOnSubmit(line);
  3518. db.SubmitChanges();
  3519. }
  3520. db.Transaction.Commit();
  3521. }
  3522. catch (Exception ex)
  3523. {
  3524. db.Transaction.Rollback();
  3525. throw new Exception(ex.Message);
  3526. }
  3527. }
  3528. public static void AddRectifyProcessList(List<ICSNCRDocRectifyProcess> InfoList, string Appconstr)
  3529. {
  3530. FramDataContext db = new FramDataContext(Appconstr);
  3531. db.Connection.Open();
  3532. db.Transaction = db.Connection.BeginTransaction();
  3533. try
  3534. {
  3535. foreach (ICSNCRDocRectifyProcess Info in InfoList)
  3536. {
  3537. bool isNew = false;
  3538. var line = db.ICSNCRDocRectifyProcess.SingleOrDefault(a => a.SecDocNO == Info.SecDocNO && a.Seq == Info.Seq);
  3539. if (line == null)
  3540. {
  3541. isNew = true;
  3542. line = new ICSNCRDocRectifyProcess();
  3543. line.ID = AppConfig.GetGuid();
  3544. }
  3545. else
  3546. {
  3547. throw new Exception("已存在纠正流程数据");
  3548. }
  3549. line.SecDocNO = Info.SecDocNO;
  3550. line.Seq = Info.Seq;
  3551. line.SubmitTime = Info.SubmitTime;
  3552. line.SubmitDep = Info.SubmitDep;
  3553. line.SubmitPerson = Info.SubmitPerson;
  3554. line.SubmitStatus = Info.SubmitStatus;
  3555. line.ConfirmStatus = Info.CKStatus;
  3556. line.EATTRIBUTE1 = Info.EATTRIBUTE1;
  3557. line.EATTRIBUTE2 = Info.EATTRIBUTE2;
  3558. line.RectifyID = Info.RectifyID;
  3559. line.ProcessName = Info.ProcessName;
  3560. line.CKStatus = Info.CKStatus;
  3561. line.LimitTime = Info.LimitTime;
  3562. line.MUSER = AppConfig.UserId;
  3563. line.MUSERName = AppConfig.UserName;
  3564. line.MTIME = DateTime.Now;
  3565. line.WorkPoint = AppConfig.WorkPointCode;
  3566. if (isNew) db.ICSNCRDocRectifyProcess.InsertOnSubmit(line);
  3567. db.SubmitChanges();
  3568. }
  3569. db.Transaction.Commit();
  3570. }
  3571. catch (Exception ex)
  3572. {
  3573. db.Transaction.Rollback();
  3574. throw new Exception(ex.Message);
  3575. }
  3576. }
  3577. public static void EditRectifyProcessList(List<ICSNCRDocRectifyProcess> InfoList, String SecDocNo, string Appconstr)
  3578. {
  3579. FramDataContext db = new FramDataContext(Appconstr);
  3580. db.Connection.Open();
  3581. db.Transaction = db.Connection.BeginTransaction();
  3582. try
  3583. {
  3584. if (IsExistRectifyLog(SecDocNo, Appconstr))
  3585. {
  3586. throw new Exception("已存在纠正流程记录数据");
  3587. }
  3588. else
  3589. {
  3590. var lineolds = db.ICSNCRDocRectifyProcess.Where(a => a.SecDocNO == SecDocNo);
  3591. if (lineolds != null)
  3592. {
  3593. db.ICSNCRDocRectifyProcess.DeleteAllOnSubmit(lineolds);
  3594. db.SubmitChanges();
  3595. }
  3596. if (InfoList != null && InfoList.Count > 0)
  3597. {
  3598. foreach (ICSNCRDocRectifyProcess Info in InfoList)
  3599. {
  3600. bool isNew = false;
  3601. var line = db.ICSNCRDocRectifyProcess.SingleOrDefault(a => a.SecDocNO == Info.SecDocNO && a.Seq == Info.Seq);
  3602. if (line == null)
  3603. {
  3604. isNew = true;
  3605. line = new ICSNCRDocRectifyProcess();
  3606. line.ID = AppConfig.GetGuid();
  3607. }
  3608. else
  3609. {
  3610. throw new Exception("已存在纠正流程数据");
  3611. }
  3612. line.SecDocNO = Info.SecDocNO;
  3613. line.Seq = Info.Seq;
  3614. line.EATTRIBUTE1 = Info.EATTRIBUTE1;
  3615. line.EATTRIBUTE2 = Info.EATTRIBUTE2;
  3616. line.RectifyID = Info.RectifyID;
  3617. line.CKStatus = Info.CKStatus;
  3618. line.ProcessName = Info.ProcessName;
  3619. line.LimitTime = Info.LimitTime;
  3620. line.MUSER = AppConfig.UserId;
  3621. line.MUSERName = AppConfig.UserName;
  3622. line.MTIME = DateTime.Now;
  3623. line.WorkPoint = AppConfig.WorkPointCode;
  3624. if (isNew) db.ICSNCRDocRectifyProcess.InsertOnSubmit(line);
  3625. db.SubmitChanges();
  3626. }
  3627. }
  3628. db.Transaction.Commit();
  3629. }
  3630. }
  3631. catch (Exception ex)
  3632. {
  3633. db.Transaction.Rollback();
  3634. throw new Exception(ex.Message);
  3635. }
  3636. }
  3637. public static void EditPreventionProcessList(List<ICSNCRDocPreventionProcess> InfoList, String SecDocNo, string Appconstr)
  3638. {
  3639. FramDataContext db = new FramDataContext(Appconstr);
  3640. db.Connection.Open();
  3641. db.Transaction = db.Connection.BeginTransaction();
  3642. try
  3643. {
  3644. if (IsExistPreventionLog(SecDocNo, Appconstr))
  3645. {
  3646. throw new Exception("已存在预防流程记录数据");
  3647. }
  3648. else
  3649. {
  3650. var lineolds = db.ICSNCRDocPreventionProcess.Where(a => a.SecDocNO == SecDocNo);
  3651. if (lineolds != null)
  3652. {
  3653. db.ICSNCRDocPreventionProcess.DeleteAllOnSubmit(lineolds);
  3654. db.SubmitChanges();
  3655. }
  3656. if (InfoList != null && InfoList.Count > 0)
  3657. {
  3658. foreach (ICSNCRDocPreventionProcess Info in InfoList)
  3659. {
  3660. bool isNew = false;
  3661. var line = db.ICSNCRDocPreventionProcess.SingleOrDefault(a => a.SecDocNO == Info.SecDocNO && a.Seq == Info.Seq);
  3662. if (line == null)
  3663. {
  3664. isNew = true;
  3665. line = new ICSNCRDocPreventionProcess();
  3666. line.ID = AppConfig.GetGuid();
  3667. }
  3668. else
  3669. {
  3670. throw new Exception("已存在预防流程数据");
  3671. }
  3672. line.SecDocNO = Info.SecDocNO;
  3673. line.Seq = Info.Seq;
  3674. line.EATTRIBUTE1 = Info.EATTRIBUTE1;
  3675. line.EATTRIBUTE2 = Info.EATTRIBUTE2;
  3676. line.PreventionID = Info.PreventionID;
  3677. line.ProcessName = Info.ProcessName;
  3678. line.LimitTime = Info.LimitTime;
  3679. line.MUSER = AppConfig.UserId;
  3680. line.MUSERName = AppConfig.UserName;
  3681. line.MTIME = DateTime.Now;
  3682. line.WorkPoint = AppConfig.WorkPointCode;
  3683. if (isNew) db.ICSNCRDocPreventionProcess.InsertOnSubmit(line);
  3684. db.SubmitChanges();
  3685. }
  3686. }
  3687. db.Transaction.Commit();
  3688. }
  3689. }
  3690. catch (Exception ex)
  3691. {
  3692. db.Transaction.Rollback();
  3693. throw new Exception(ex.Message);
  3694. }
  3695. }
  3696. #endregion
  3697. #region 退料
  3698. //public static void AddUpdateNCRTuiLiao( List<ICSNCRDocTuiLiao> List,String Appconstr)
  3699. //{
  3700. // FramDataContext db = new FramDataContext(Appconstr);
  3701. // db.Connection.Open();
  3702. // db.Transaction = db.Connection.BeginTransaction();
  3703. // try
  3704. // {
  3705. // foreach (ICSNCRDocTuiLiao Info in List)
  3706. // {
  3707. // bool isNew = false;
  3708. // var line = db.ICSNCRDocTuiLiao.SingleOrDefault(a => a.ID == Info.ID );
  3709. // if (line == null)
  3710. // {
  3711. // isNew = true;
  3712. // line = new ICSNCRDocTuiLiao();
  3713. // line.ID = AppConfig.GetGuid();
  3714. // }
  3715. // line.SecDocNo = Info.SecDocNo;
  3716. // line.Qty = Info.Qty;
  3717. // line.IssueDoc = Info.IssueDoc;
  3718. // line.ItemCode = Info.ItemCode;
  3719. // line.LotNo = Info.LotNo;
  3720. // line.MOCode = Info.MOCode;
  3721. // line.NewLotNo = Info.NewLotNo;
  3722. // line.EATTRIBUTE1 = Info.EATTRIBUTE1;//炉号
  3723. // line.EATTRIBUTE2 = Info.EATTRIBUTE2;
  3724. // line.EATTRIBUTE3 = Info.EATTRIBUTE3;
  3725. // line.MUSER = AppConfig.UserId;
  3726. // line.MUSERName = AppConfig.UserName;
  3727. // line.MTIME = DateTime.Now;
  3728. // line.WorkPoint = AppConfig.WorkPointCode;
  3729. // if (isNew) db.ICSNCRDocTuiLiao.InsertOnSubmit(line);
  3730. // db.SubmitChanges();
  3731. // }
  3732. // db.Transaction.Commit();
  3733. // }
  3734. // catch (Exception ex)
  3735. // {
  3736. // db.Transaction.Rollback();
  3737. // throw new Exception(ex.Message);
  3738. // }
  3739. //}
  3740. //public static void NCRTuiLiaoToWMShip(string SecDocNo, String Appconstr)
  3741. //{
  3742. // FramDataContext db = new FramDataContext(Appconstr);
  3743. // db.Connection.Open();
  3744. // db.Transaction = db.Connection.BeginTransaction();
  3745. // try
  3746. // {
  3747. // bool isNew = true;
  3748. // int MaxLine=0;
  3749. // string DocNo ="";
  3750. // List<WM_RCVShip> Infolist = new List<WM_RCVShip>();
  3751. // var line = db.ICSNCRDocTLRelation.Where(a => a.SecDocNo == SecDocNo).OrderByDescending(a => a.LineNo);
  3752. // var TuiLiaoLine = from a in db.ICSNCRDocTuiLiao
  3753. // join b in db.ICSNCRDocTLRelation
  3754. // on new { SecDocNo = a.SecDocNo, ID = a.ID } equals new { SecDocNo = b.SecDocNo, ID = b.TuiLiaoID } into dd
  3755. // from bb in dd.DefaultIfEmpty()
  3756. // join c in db.Base_Inventory on a.ItemCode equals c.ItemCode
  3757. // where a.SecDocNo == SecDocNo
  3758. // select new
  3759. // {
  3760. // SecDocNo = a.SecDocNo,
  3761. // ID = a.ID,
  3762. // DocNo = bb.DocNo,
  3763. // LineNo = bb.LineNo,
  3764. // Qty = a.Qty,
  3765. // ItemCode = a.ItemCode,
  3766. // ItemName = c.ItemName,
  3767. // ItemID = c.ItemID,
  3768. // LuHoa = a.EATTRIBUTE1
  3769. // };
  3770. // if (line != null && line.Count() > 0)
  3771. // {
  3772. // MaxLine = Convert.ToInt32(line.First().LineNo);
  3773. // DocNo = line.First().DocNo;
  3774. // }
  3775. // else
  3776. // {
  3777. // //生成新退料单号
  3778. // string LBCodePer = "RL" + AppConfig.GetSeverDateTime("yyyy-MM-dd").ToString("yyyyMMdd");
  3779. // string NewLBCodeNo = GetSerialCode(AppConfig.AppConnectString, "ICSNCRDocTLRelation", "DocNo", LBCodePer, 4);
  3780. // DocNo = NewLBCodeNo;
  3781. // }
  3782. // if (TuiLiaoLine != null && TuiLiaoLine.Count() > 0)
  3783. // {
  3784. // foreach (var item in TuiLiaoLine)
  3785. // {
  3786. // if (string.IsNullOrEmpty(item.LineNo))
  3787. // {
  3788. // MaxLine = MaxLine + 10;
  3789. // string NewLineNo = MaxLine.ToString();
  3790. // var newline = db.ICSNCRDocTLRelation.SingleOrDefault(a => a.SecDocNo == SecDocNo && a.LineNo == NewLineNo);
  3791. // if (newline != null)
  3792. // {
  3793. // throw new Exception("退料行号异常:" + NewLineNo);
  3794. // }
  3795. // else
  3796. // {
  3797. // newline = new ICSNCRDocTLRelation();
  3798. // }
  3799. // newline.ID = AppConfig.GetGuid();
  3800. // newline.DocNo = DocNo;
  3801. // newline.LineNo = NewLineNo;
  3802. // newline.SecDocNo = SecDocNo;
  3803. // newline.TuiLiaoID = item.ID;
  3804. // newline.MTIME = DateTime.Now;
  3805. // newline.MUSER = AppConfig.UserCode;
  3806. // newline.MUSERName = AppConfig.UserName;
  3807. // newline.WorkPoint = AppConfig.WorkPointCode;
  3808. // if (isNew) db.ICSNCRDocTLRelation.InsertOnSubmit(newline);
  3809. // #region WM_RCVShip
  3810. // WM_RCVShip entity = new WM_RCVShip();
  3811. // entity = new WM_RCVShip();
  3812. // entity.guid = AppConfig.GetGuid();
  3813. // entity.RcvDocNo = DocNo;
  3814. // entity.RcvDocBusinessDate = DateTime.Now;
  3815. // entity.RcvDocStatus = "0";
  3816. // entity.RcvOrgID = 1001606030000019;
  3817. // entity.RcvOrgCode = "01";
  3818. // entity.RcvOrgName = "无锡智能自控工程股份有限公司";
  3819. // entity.RcvDocTypeName = "退料单";
  3820. // entity.RcvLineNo = MaxLine;
  3821. // entity.RcvLineItemMasterID = item.ItemID;
  3822. // entity.RcvLineItemMasterCode = item.ItemCode;
  3823. // entity.RcvLineItemMasterName = item.ItemName;
  3824. // entity.RcvLineStoreUOMID = 0;
  3825. // entity.RcvLineStoreUOMCode = "";
  3826. // entity.RcvLineStoreUOMName = "";
  3827. // entity.RcvLineStoreQty = item.Qty;
  3828. // entity.barcodeSumQty = 0;
  3829. // entity.barcodeSumNo = 0;
  3830. // entity.RcvLineInvLotFurnace = item.LuHoa;
  3831. // entity.isEff = true;
  3832. // entity.isDel = false;
  3833. // entity.WorkPointCode = AppConfig.WorkPointCode;
  3834. // entity.MUSERCode = AppConfig.UserCode;
  3835. // entity.MUSERName = AppConfig.UserName;
  3836. // entity.MTIME = Convert.ToDateTime(AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss").ToString());
  3837. // Infolist.Add(entity);
  3838. // #endregion
  3839. // }
  3840. // }
  3841. // if (Infolist != null && Infolist.Count > 0)
  3842. // {
  3843. // WM_RCVShipDAL.AddMISList(Infolist, Appconstr);
  3844. // }
  3845. // db.SubmitChanges();
  3846. // db.Transaction.Commit();
  3847. // }
  3848. // }
  3849. // catch (Exception ex)
  3850. // {
  3851. // db.Transaction.Rollback();
  3852. // throw new Exception(ex.Message);
  3853. // }
  3854. //}
  3855. #endregion
  3856. }
  3857. }