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

518 lines
17 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.DAL;
  6. using ICSSoft.Frame.Data.Entity;
  7. namespace ICSSoft.Frame.Data.BLL
  8. {
  9. public class ICSCollectBLL
  10. {
  11. public static void Save(string Appconstr, ICSLOTSIMULATION simulation)
  12. {
  13. FramDataContext db = new FramDataContext(Appconstr);
  14. db.Connection.Open();
  15. db.Transaction = db.Connection.BeginTransaction();
  16. try
  17. {
  18. if (string.IsNullOrWhiteSpace(Appconstr))
  19. throw new Exception("连接字符串不能为空!");
  20. //校验传入数据是否符合采集要求
  21. ICSCollectDAL.CheckInfo(db, simulation);
  22. bool IsFirst = false;
  23. //保存数据
  24. if (ICSCollectDAL.ISAutoSAVE(simulation.OPCODE, db)){
  25. ICSCollectDAL.AutoSave(db, simulation);
  26. }
  27. else
  28. ICSCollectDAL.Save(db, simulation);
  29. db.SubmitChanges();
  30. db.Transaction.Commit();
  31. db.Connection.Close();
  32. }
  33. catch (Exception ex)
  34. {
  35. db.Transaction.Rollback();
  36. db.Connection.Close();
  37. throw ex;
  38. }
  39. }
  40. public static string SaveList(string Appconstr, List<ICSLOTSIMULATION> infolist, List<ICSPO_PoMain> polist, List<ICSWareHouseLotInfoLog> loglist)
  41. {
  42. string errormessage = "";
  43. FramDataContext db = new FramDataContext(Appconstr);
  44. db.Connection.Open();
  45. db.Transaction = db.Connection.BeginTransaction();
  46. try
  47. {
  48. if (string.IsNullOrWhiteSpace(Appconstr))
  49. throw new Exception("连接字符串不能为空!");
  50. foreach (ICSLOTSIMULATION info in infolist)
  51. {
  52. //校验传入数据是否符合采集要求
  53. string opmessage = ICSCollectDAL.CheckInfoWW(db, info);
  54. //校验工艺路线是否有新增工序且未派工
  55. string routemessage = ICSCollectDAL.CheckRoute(db, info);
  56. if (opmessage == "" && routemessage == "")
  57. {
  58. //保存数据
  59. ICSCollectDAL.Save(db, info);
  60. }
  61. else
  62. {
  63. errormessage += opmessage + routemessage;
  64. }
  65. }
  66. //采购订单已发数量更新
  67. foreach (ICSPO_PoMain info in polist)
  68. {
  69. ICSCollectDAL.UpdatePOInfo(db, info);
  70. }
  71. //日志表条码对应采购订单信息记录
  72. foreach (ICSWareHouseLotInfoLog info in loglist)
  73. {
  74. ICSCollectDAL.AddLogInfo(db, info);
  75. }
  76. db.SubmitChanges();
  77. db.Transaction.Commit();
  78. db.Connection.Close();
  79. return errormessage;
  80. }
  81. catch (Exception ex)
  82. {
  83. db.Transaction.Rollback();
  84. db.Connection.Close();
  85. throw ex;
  86. }
  87. }
  88. public static void CheckListEnd(string Appconstr, List<ICSLOTSIMULATION> infolist)
  89. {
  90. FramDataContext db = new FramDataContext(Appconstr);
  91. db.Connection.Open();
  92. db.Transaction = db.Connection.BeginTransaction();
  93. try
  94. {
  95. if (string.IsNullOrWhiteSpace(Appconstr))
  96. throw new Exception("连接字符串不能为空!");
  97. //foreach (ICSLOTSIMULATION info in infolist)
  98. //{
  99. // //校验传入数据是否符合采集要求
  100. // ICSCollectDAL.CheckInfo(db, info);
  101. // //保存数据
  102. // ICSCollectDAL.Save(db, info);
  103. //}
  104. //批量委外自动开工完工
  105. ICSCollectDAL.CheckListEnd(db, infolist);
  106. db.SubmitChanges();
  107. db.Transaction.Commit();
  108. db.Connection.Close();
  109. }
  110. catch (Exception ex)
  111. {
  112. db.Transaction.Rollback();
  113. db.Connection.Close();
  114. throw ex;
  115. }
  116. }
  117. public static void SaveListEnd(string Appconstr, List<ICSLOTSIMULATION> infolist)
  118. {
  119. FramDataContext db = new FramDataContext(Appconstr);
  120. db.Connection.Open();
  121. db.Transaction = db.Connection.BeginTransaction();
  122. try
  123. {
  124. if (string.IsNullOrWhiteSpace(Appconstr))
  125. throw new Exception("连接字符串不能为空!");
  126. //foreach (ICSLOTSIMULATION info in infolist)
  127. //{
  128. // //校验传入数据是否符合采集要求
  129. // ICSCollectDAL.CheckInfo(db, info);
  130. // //保存数据
  131. // ICSCollectDAL.Save(db, info);
  132. //}
  133. //批量委外自动开工完工
  134. ICSCollectDAL.CheckAutoOP(db, infolist);
  135. db.SubmitChanges();
  136. db.Transaction.Commit();
  137. db.Connection.Close();
  138. }
  139. catch (Exception ex)
  140. {
  141. db.Transaction.Rollback();
  142. db.Connection.Close();
  143. throw ex;
  144. }
  145. }
  146. public static void Transfer(string Appconstr, ICSLOTSIMULATION simulation)
  147. {
  148. FramDataContext db = new FramDataContext(Appconstr);
  149. db.Connection.Open();
  150. db.Transaction = db.Connection.BeginTransaction();
  151. try
  152. {
  153. if (string.IsNullOrWhiteSpace(Appconstr))
  154. throw new Exception("连接字符串不能为空!");
  155. //校验传入数据是否符合采集要求
  156. ICSCollectDAL.CheckTransferInfo(db, simulation);
  157. //保存数据
  158. ICSCollectDAL.Transfer(db, simulation);
  159. db.SubmitChanges();
  160. db.Transaction.Commit();
  161. db.Connection.Close();
  162. }
  163. catch (Exception ex)
  164. {
  165. db.Transaction.Rollback();
  166. db.Connection.Close();
  167. throw ex;
  168. }
  169. }
  170. public static void SaveItem(string Appconstr, ICSLOTONWIPITEM simulation)
  171. {
  172. FramDataContext db = new FramDataContext(Appconstr);
  173. db.Connection.Open();
  174. db.Transaction = db.Connection.BeginTransaction();
  175. try
  176. {
  177. if (string.IsNullOrWhiteSpace(Appconstr))
  178. throw new Exception("连接字符串不能为空!");
  179. //校验传入数据是否符合采集要求
  180. ICSCollectDAL.CheckItemInfo(db, simulation);
  181. //保存数据
  182. ICSCollectDAL.SaveItem(db, simulation);
  183. db.SubmitChanges();
  184. db.Transaction.Commit();
  185. db.Connection.Close();
  186. }
  187. catch (Exception ex)
  188. {
  189. db.Transaction.Rollback();
  190. db.Connection.Close();
  191. throw ex;
  192. }
  193. }
  194. public static void Pause(string Appconstr, ICSLOTSIMULATION simulation)
  195. {
  196. FramDataContext db = new FramDataContext(Appconstr);
  197. db.Connection.Open();
  198. db.Transaction = db.Connection.BeginTransaction();
  199. try
  200. {
  201. if (string.IsNullOrWhiteSpace(Appconstr))
  202. throw new Exception("连接字符串不能为空!");
  203. //校验传入数据是否符合采集要求
  204. ICSLOTSIMULATION sim = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO && a.OPCODE == simulation.OPCODE);
  205. if (sim == null)
  206. {
  207. throw new Exception("该批次工序不是在制品不可暂停!");
  208. }
  209. else if (sim.CollectStatus.Equals("COLLECT_END"))
  210. {
  211. throw new Exception("该工序已经完工,不能暂停!");
  212. }
  213. else if (sim.LOTStatus.Equals("暂停"))
  214. {
  215. throw new Exception("该批次工序已经暂停!");
  216. }
  217. sim.EATTRIBUTE2 = simulation.EATTRIBUTE2;
  218. //保存数据
  219. ICSLOTSIMULATION lotsimulation = sim;
  220. lotsimulation.MUSER = simulation.MUSER;
  221. lotsimulation.MUSERName = simulation.MUSERName;
  222. ICSCollectDAL.Pause(db, lotsimulation);
  223. db.SubmitChanges();
  224. db.Transaction.Commit();
  225. db.Connection.Close();
  226. }
  227. catch (Exception ex)
  228. {
  229. db.Transaction.Rollback();
  230. db.Connection.Close();
  231. throw ex;
  232. }
  233. }
  234. public static void CancelPause(string Appconstr, ICSLOTSIMULATION simulation)
  235. {
  236. FramDataContext db = new FramDataContext(Appconstr);
  237. db.Connection.Open();
  238. db.Transaction = db.Connection.BeginTransaction();
  239. try
  240. {
  241. if (string.IsNullOrWhiteSpace(Appconstr))
  242. throw new Exception("连接字符串不能为空!");
  243. //保存数据
  244. ICSCollectDAL.CancelPause(db, simulation);
  245. db.SubmitChanges();
  246. db.Transaction.Commit();
  247. db.Connection.Close();
  248. }
  249. catch (Exception ex)
  250. {
  251. db.Transaction.Rollback();
  252. db.Connection.Close();
  253. throw ex;
  254. }
  255. }
  256. //结算料费
  257. public static void Calculate(string Appconstr, List<string> list)
  258. {
  259. FramDataContext db = new FramDataContext(Appconstr);
  260. db.Connection.Open();
  261. db.Transaction = db.Connection.BeginTransaction();
  262. try
  263. {
  264. if (string.IsNullOrWhiteSpace(Appconstr))
  265. throw new Exception("连接字符串不能为空!");
  266. //保存数据
  267. ICSCollectDAL.Calculate(db, list, "不合格");
  268. db.SubmitChanges();
  269. db.Transaction.Commit();
  270. db.Connection.Close();
  271. }
  272. catch (Exception ex)
  273. {
  274. db.Transaction.Rollback();
  275. db.Connection.Close();
  276. throw ex;
  277. }
  278. }
  279. //第一次判定
  280. public static void FirstResult(string Appconstr, List<ICSLOTONWIPCheck> list, List<string> idList)
  281. {
  282. FramDataContext db = new FramDataContext(Appconstr);
  283. db.Connection.Open();
  284. db.Transaction = db.Connection.BeginTransaction();
  285. try
  286. {
  287. if (string.IsNullOrWhiteSpace(Appconstr))
  288. throw new Exception("连接字符串不能为空!");
  289. //保存数据
  290. ICSCollectDAL.FirstResult(db, list, idList);
  291. db.SubmitChanges();
  292. db.Transaction.Commit();
  293. db.Connection.Close();
  294. }
  295. catch (Exception ex)
  296. {
  297. db.Transaction.Rollback();
  298. db.Connection.Close();
  299. throw ex;
  300. }
  301. }
  302. //第二次判定
  303. public static void SecondResult(string Appconstr, List<ICSLOTONWIPCheck> list, List<string> idList)
  304. {
  305. FramDataContext db = new FramDataContext(Appconstr);
  306. db.Connection.Open();
  307. db.Transaction = db.Connection.BeginTransaction();
  308. try
  309. {
  310. if (string.IsNullOrWhiteSpace(Appconstr))
  311. throw new Exception("连接字符串不能为空!");
  312. //保存数据
  313. ICSCollectDAL.SecondResult(db, list, idList);
  314. db.SubmitChanges();
  315. db.Transaction.Commit();
  316. db.Connection.Close();
  317. }
  318. catch (Exception ex)
  319. {
  320. db.Transaction.Rollback();
  321. db.Connection.Close();
  322. throw ex;
  323. }
  324. }
  325. #region 获取跟踪单当前的采集信息
  326. public static ICSLOTSIMULATION GetSimInfoByLotNo(string LotNo, string dsconn)
  327. {
  328. try
  329. {
  330. return ICSCollectDAL.GetSimInfoByLotNo(LotNo, dsconn);
  331. }
  332. catch (Exception ex)
  333. {
  334. throw ex;
  335. }
  336. }
  337. #endregion
  338. #region 检查当前检验的工序是否是委外工(True:委外,Flase:非委外)
  339. public static bool GetLotOPInfoByCode(string LotNo, string OPCode, string dsconn)
  340. {
  341. try
  342. {
  343. return ICSCollectDAL.GetLotOPInfoByCode(LotNo, OPCode, dsconn);
  344. }
  345. catch (Exception ex)
  346. {
  347. throw ex;
  348. }
  349. }
  350. #endregion
  351. public static void TResult(string Appconstr, List<ICSLOTONWIPCheck> list)
  352. {
  353. FramDataContext db = new FramDataContext(Appconstr);
  354. db.Connection.Open();
  355. db.Transaction = db.Connection.BeginTransaction();
  356. try
  357. {
  358. if (string.IsNullOrWhiteSpace(Appconstr))
  359. throw new Exception("连接字符串不能为空!");
  360. //保存数据
  361. ICSCollectDAL.TResult(db, list);
  362. db.SubmitChanges();
  363. db.Transaction.Commit();
  364. db.Connection.Close();
  365. }
  366. catch (Exception ex)
  367. {
  368. db.Transaction.Rollback();
  369. db.Connection.Close();
  370. throw ex;
  371. }
  372. }
  373. #region GetModel
  374. public static ICSLOTONWIPCheck GetModel(string id, string dsconn)
  375. {
  376. try
  377. {
  378. return ICSCollectDAL.GetModel(id, dsconn);
  379. }
  380. catch (Exception ex)
  381. {
  382. throw ex;
  383. }
  384. }
  385. #endregion
  386. #region AddPDF
  387. public static void AddPDF(string id, string fname, string dsconn)
  388. {
  389. try
  390. {
  391. ICSCollectDAL.AddPDF(id, fname, dsconn);
  392. }
  393. catch (Exception ex)
  394. {
  395. throw ex;
  396. }
  397. }
  398. #endregion
  399. public static void RResult(string Appconstr, List<ICSLOTONWIPCheck> list)
  400. {
  401. FramDataContext db = new FramDataContext(Appconstr);
  402. db.Connection.Open();
  403. db.Transaction = db.Connection.BeginTransaction();
  404. try
  405. {
  406. if (string.IsNullOrWhiteSpace(Appconstr))
  407. throw new Exception("连接字符串不能为空!");
  408. //保存数据
  409. ICSCollectDAL.RResult(db, list);
  410. db.SubmitChanges();
  411. db.Transaction.Commit();
  412. db.Connection.Close();
  413. }
  414. catch (Exception ex)
  415. {
  416. db.Transaction.Rollback();
  417. db.Connection.Close();
  418. throw ex;
  419. }
  420. }
  421. //删除开工未完工的记录
  422. public static void DataDelete(string Appconstr, List<FormICSCollectDataDeleteUIModel> infolist, List<FormICSCollectWWDataDeleteUIModel> wwinfolist)
  423. {
  424. FramDataContext db = new FramDataContext(Appconstr);
  425. db.Connection.Open();
  426. db.Transaction = db.Connection.BeginTransaction();
  427. try
  428. {
  429. if (string.IsNullOrWhiteSpace(Appconstr))
  430. throw new Exception("连接字符串不能为空!");
  431. if (infolist.Count != 0)
  432. {
  433. ICSCollectDAL.DataDelete(db, infolist);
  434. }
  435. if (wwinfolist.Count != 0)
  436. {
  437. ICSCollectDAL.DataDeleteForWW(db, wwinfolist);
  438. }
  439. db.Transaction.Commit();
  440. db.Connection.Close();
  441. }
  442. catch (Exception ex)
  443. {
  444. db.Transaction.Rollback();
  445. db.Connection.Close();
  446. throw ex;
  447. }
  448. }
  449. #region 判断第二次检验是否与第一次检验相同(True:相同;False:不同)
  450. public static string CheckFSDifferent(string Appconstr, List<ICSLOTONWIPCheck> infolist, List<string> LotNO, List<string> OPCode)
  451. {
  452. FramDataContext db = new FramDataContext(Appconstr);
  453. db.Connection.Open();
  454. db.Transaction = db.Connection.BeginTransaction();
  455. try
  456. {
  457. string Result = ICSCollectDAL.CheckFSDifferent(db, infolist, LotNO, OPCode);
  458. db.Connection.Close();
  459. return Result;
  460. }
  461. catch (Exception ex)
  462. {
  463. db.Connection.Close();
  464. throw new Exception(ex.Message);
  465. }
  466. }
  467. #endregion
  468. }
  469. }