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

705 lines
27 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using ICSSoft.Frame.Data.Entity;
  6. using ICSSoft.Base.Config.AppConfig;
  7. using System.Data;
  8. using ICSSoft.Base.Config.DBHelper;
  9. using System.Data.SqlClient;
  10. namespace ICSSoft.Frame.Data.DAL
  11. {
  12. public class ICSHeatTreatmentDAL
  13. {
  14. #region 新增炉号
  15. public static void AddAndEditList(List<ICSOpFile> equipmentInfoList,string Transno,string dsconn)
  16. {
  17. FramDataContext db = new FramDataContext(dsconn);
  18. db.Connection.Open();
  19. db.Transaction = db.Connection.BeginTransaction();
  20. try
  21. {
  22. foreach (ICSOpFile equipmentInfo in equipmentInfoList)
  23. {
  24. //var op = db.ICSOpFile.SingleOrDefault(a => a.ID == equipmentInfo.ID );
  25. //if (op != null)
  26. //{
  27. // throw new Exception("单据号:" + equipmentInfo.TransNO + "已存在!");
  28. //}
  29. bool isNew = false;
  30. var line = db.ICSOpFile.SingleOrDefault(a => a.ID == equipmentInfo.ID);
  31. if (line == null)
  32. {
  33. isNew = true;
  34. line = new ICSOpFile();
  35. line.ID = AppConfig.GetGuid();
  36. }
  37. if (!string.IsNullOrWhiteSpace(equipmentInfo.MOCODE))
  38. {
  39. var opcode = db.ICSOP.SingleOrDefault(a => a.OPCODE == equipmentInfo.EATTRIBUTE4.TrimEnd(';'));
  40. if (opcode != null)
  41. {
  42. if (opcode.OPDESC.Contains("渗碳"))
  43. {
  44. #region 工序:渗碳
  45. var mo1 = db.ICSOpFile.Where(a => a.EQPCode == equipmentInfo.EQPCode.TrimEnd(';') && a.EATTRIBUTE1 == "炉号" && a.TransNO.Length <= 8).OrderByDescending(a => a.TransNO);
  46. if (Transno == null)
  47. {
  48. if (mo1 != null && mo1.Count() > 0)
  49. {
  50. string code = mo1.FirstOrDefault().TransNO;
  51. line.TransNO = equipmentInfo.EQPCode.TrimEnd(';') + (Convert.ToInt32(code.Substring(code.Length - 3)) + 1).ToString().PadLeft(3, '0');
  52. }
  53. else
  54. {
  55. line.TransNO = equipmentInfo.EQPCode.TrimEnd(';') + "001";
  56. }
  57. }
  58. else
  59. {
  60. line.TransNO = Transno;
  61. }
  62. #endregion
  63. }
  64. else
  65. {
  66. #region 工序:其他
  67. var mo1 = db.ICSOpFile.Where(a => a.EQPCode == equipmentInfo.EQPCode.TrimEnd(';') && a.EATTRIBUTE1 == "炉号" && a.TransNO.Length > 8).OrderByDescending(a => a.TransNO);
  68. if (Transno == null)
  69. {
  70. if (mo1 != null && mo1.Count() > 0)
  71. {
  72. string code = mo1.FirstOrDefault().TransNO;
  73. line.TransNO = equipmentInfo.EQPCode.TrimEnd(';') + (Convert.ToInt32(code.Substring(code.Length - 6)) + 1).ToString().PadLeft(6, '0');
  74. }
  75. else
  76. {
  77. line.TransNO = equipmentInfo.EQPCode.TrimEnd(';') + "000001";
  78. }
  79. }
  80. else
  81. {
  82. line.TransNO = Transno;
  83. }
  84. #endregion
  85. }
  86. }
  87. //line.LOTNOs = equipmentInfo.LOTNOs;
  88. if (equipmentInfo.LOTNOs == null)
  89. {
  90. throw new Exception("产品产品跟踪单号不能为空");
  91. }
  92. else
  93. {
  94. line.LOTNOs = equipmentInfo.LOTNOs.TrimEnd(';');
  95. }
  96. line.MOCODE = equipmentInfo.MOCODE.TrimEnd(';');
  97. line.MOSEQ = equipmentInfo.MOSEQ.TrimEnd(';');
  98. line.EQPCode = equipmentInfo.EQPCode.TrimEnd(';');
  99. line.EATTRIBUTE2 = equipmentInfo.EATTRIBUTE2.TrimEnd(';');//零件号
  100. line.EATTRIBUTE3 = equipmentInfo.EATTRIBUTE3.TrimEnd(';');//设备号
  101. line.EATTRIBUTE4 = equipmentInfo.EATTRIBUTE4.TrimEnd(';');//工序
  102. }
  103. else
  104. {
  105. var opcodes = db.ICSOP.SingleOrDefault(a => a.OPCODE == equipmentInfo.EATTRIBUTE4);
  106. if (opcodes != null)
  107. {
  108. if (opcodes.OPDESC.Contains("渗碳"))
  109. {
  110. #region 工序:渗碳
  111. var mo1 = db.ICSOpFile.Where(a => a.EQPCode == equipmentInfo.EQPCode && a.EATTRIBUTE1 == "炉号"&&a.TransNO.Length<=8).OrderByDescending(a => a.TransNO);
  112. if (mo1 != null && mo1.Count() > 0)
  113. {
  114. string code = mo1.FirstOrDefault().TransNO;
  115. line.TransNO = equipmentInfo.EQPCode + (Convert.ToInt32(code.Substring(code.Length - 3)) + 1).ToString().PadLeft(3, '0');
  116. }
  117. else
  118. {
  119. line.TransNO = equipmentInfo.EQPCode + "001";
  120. }
  121. #endregion
  122. }
  123. else
  124. {
  125. #region 工序:其他
  126. var mo1 = db.ICSOpFile.Where(a => a.EQPCode == equipmentInfo.EQPCode && a.EATTRIBUTE1 == "炉号"&&a.TransNO.Length>8).OrderByDescending(a => a.TransNO);
  127. if (mo1 != null && mo1.Count() > 0)
  128. {
  129. string code = mo1.FirstOrDefault().TransNO;
  130. line.TransNO = equipmentInfo.EQPCode + (Convert.ToInt32(code.Substring(code.Length - 6)) + 1).ToString().PadLeft(6, '0');
  131. }
  132. else
  133. {
  134. line.TransNO = equipmentInfo.EQPCode + "000001";
  135. }
  136. #endregion
  137. }
  138. }
  139. line.EQPCode = equipmentInfo.EQPCode;
  140. line.EATTRIBUTE2 = equipmentInfo.EATTRIBUTE2;
  141. line.EATTRIBUTE4 = equipmentInfo.EATTRIBUTE4;
  142. }
  143. line.WorkPoint = equipmentInfo.WorkPoint;//传入固定值
  144. line.MUSER = equipmentInfo.MUSER;
  145. line.MUSERName = equipmentInfo.MUSERName;
  146. line.MTIME = Convert.ToDateTime(equipmentInfo.MTIME);
  147. line.EATTRIBUTE1 = "炉号";
  148. line.EATTRIBUTE5 = equipmentInfo.EATTRIBUTE5;
  149. if (isNew)
  150. db.ICSOpFile.InsertOnSubmit(line);
  151. db.SubmitChanges();
  152. }
  153. db.SubmitChanges();
  154. db.Transaction.Commit();
  155. }
  156. catch (Exception ex)
  157. {
  158. db.Transaction.Rollback();
  159. throw new Exception(ex.Message);
  160. }
  161. }
  162. #endregion
  163. #region 新增试样号
  164. public static void AddSample(List<ICSOpFile> equipmentInfoList, string ID,string Transno,int flag, string dsconn)
  165. {
  166. FramDataContext db = new FramDataContext(dsconn);
  167. db.Connection.Open();
  168. db.Transaction = db.Connection.BeginTransaction();
  169. try
  170. {
  171. foreach (ICSOpFile equipmentInfo in equipmentInfoList)
  172. {
  173. //var op = db.ICSOpFile.SingleOrDefault(a => a.ID == equipmentInfo.ID);
  174. //if (op != null)
  175. //{
  176. // throw new Exception("单据号:" + equipmentInfo.TransNO + "已存在!");
  177. //}
  178. bool isNew = false;
  179. var line = db.ICSOpFile.SingleOrDefault(a => a.ID == equipmentInfo.ID);
  180. if (line == null)
  181. {
  182. isNew = true;
  183. line = new ICSOpFile();
  184. line.ID = equipmentInfo.ID;
  185. }
  186. if (flag == 1)
  187. {
  188. var mo2 = db.ICSOpFile.Where(a => a.TransNO.Substring(0, Transno.Length) == Transno && a.EATTRIBUTE1 == "试样号").OrderByDescending(a => a.TransNO);
  189. if (mo2 != null && mo2.Count() > 0)
  190. {
  191. string code1 = mo2.FirstOrDefault().TransNO;
  192. line.TransNO = Transno + "-" + (Convert.ToInt32(code1.Substring(code1.LastIndexOf("-") + 1)) + 1).ToString().PadLeft(1, '0');
  193. }
  194. else
  195. {
  196. line.TransNO = Transno + "-" + "1";
  197. }
  198. }
  199. else
  200. {
  201. line.TransNO = Transno;
  202. }
  203. line.MOCODE = equipmentInfo.MOCODE.TrimEnd(';');
  204. line.MOSEQ = equipmentInfo.MOSEQ.TrimEnd(';');
  205. line.EQPCode = equipmentInfo.EQPCode.TrimEnd(';');
  206. line.LOTNOs = equipmentInfo.LOTNOs.TrimEnd(';');
  207. line.WorkPoint = equipmentInfo.WorkPoint;//传入固定值
  208. line.MUSER = equipmentInfo.MUSER;
  209. line.MUSERName = equipmentInfo.MUSERName;
  210. line.MTIME = Convert.ToDateTime(equipmentInfo.MTIME);
  211. line.EATTRIBUTE1 = "试样号";
  212. line.EATTRIBUTE2 = equipmentInfo.EATTRIBUTE2.TrimEnd(';');//零件号
  213. line.EATTRIBUTE3 = equipmentInfo.EATTRIBUTE3.TrimEnd(';');//设备名称
  214. line.EATTRIBUTE4 = equipmentInfo.EATTRIBUTE4.TrimEnd(';');//工序
  215. line.EATTRIBUTE5 = equipmentInfo.EATTRIBUTE5;
  216. if (isNew)
  217. db.ICSOpFile.InsertOnSubmit(line);
  218. db.SubmitChanges();
  219. }
  220. db.SubmitChanges();
  221. db.Transaction.Commit();
  222. }
  223. catch (Exception ex)
  224. {
  225. db.Transaction.Rollback();
  226. throw new Exception(ex.Message);
  227. }
  228. }
  229. #endregion
  230. #region select
  231. public static ICSToCheck select(String guid, String Appconstr)
  232. {
  233. FramDataContext db = new FramDataContext(Appconstr);
  234. db.Connection.Open();
  235. db.Transaction = db.Connection.BeginTransaction();
  236. try
  237. {
  238. var line = db.ICSToCheck.SingleOrDefault(a => a.Serial == guid);
  239. return (ICSToCheck)line;
  240. }
  241. catch (Exception ex)
  242. {
  243. throw new Exception(ex.Message);
  244. }
  245. }
  246. #endregion
  247. #region FindAll
  248. public static DataTable FindAll(string Appconstr)
  249. {
  250. try
  251. {
  252. string sql = @"SELECT
  253. a.TransNO as TransNO,
  254. c.EnumText as FileType,
  255. b.FileName,
  256. b.MUSERName,
  257. b.MTIME
  258. FROM ICSOpFile a
  259. LEFT JOIN ICSOpFileDetail b ON a.TransNO=b.TransNO
  260. , Sys_EnumValues c
  261. WHERE c.EnumKey='00007'
  262. ";
  263. return DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql).Tables[0];
  264. }
  265. catch (Exception ex)
  266. {
  267. throw ex;
  268. }
  269. }
  270. #endregion
  271. #region delete
  272. public static void delete(string ToCheckNO, string Appconstr)
  273. {
  274. SqlConnection conn = new SqlConnection(Appconstr);
  275. conn.Open();
  276. SqlCommand cmd = new SqlCommand();
  277. SqlTransaction trans = conn.BeginTransaction();
  278. cmd.Transaction = trans;
  279. cmd.Connection = conn;
  280. try
  281. {
  282. string sqls = @"DELETE dbo.ICSToChecks WHERE ToCheckNO='" + ToCheckNO + "'";
  283. cmd.CommandType = CommandType.Text;
  284. cmd.CommandText = sqls;
  285. cmd.ExecuteNonQuery();
  286. string sql = @"DELETE dbo.ICSToCheck WHERE ToCheckNO='" + ToCheckNO + "'";
  287. cmd.CommandType = CommandType.Text;
  288. cmd.CommandText = sql;
  289. cmd.ExecuteNonQuery();
  290. trans.Commit();
  291. }
  292. catch (Exception ex)
  293. {
  294. trans.Rollback();
  295. throw ex;
  296. }
  297. }
  298. #endregion
  299. #region 保存PDF
  300. public static void AddPDF(string id, string transno,string filetype,string fname, string dsconn)
  301. {
  302. FramDataContext db = new FramDataContext(dsconn);
  303. db.Connection.Open();
  304. db.Transaction = db.Connection.BeginTransaction();
  305. try
  306. {
  307. bool isNew = false;
  308. var line = db.ICSOpFileDetail.SingleOrDefault(a => a.TransNO == transno && a.FileType == filetype);
  309. if (line == null)
  310. {
  311. isNew = true;
  312. line = new ICSOpFileDetail();
  313. line.ID = AppConfig.GetGuid();
  314. }
  315. line.TransNO = transno;
  316. line.FileName = fname;
  317. line.FileType = filetype;
  318. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  319. line.MUSER = AppConfig.UserId;
  320. line.MUSERName = AppConfig.UserName;
  321. line.WorkPoint = AppConfig.WorkPointCode;
  322. if (isNew)
  323. db.ICSOpFileDetail.InsertOnSubmit(line);
  324. db.SubmitChanges();
  325. db.Transaction.Commit();
  326. }
  327. catch (Exception ex)
  328. {
  329. db.Transaction.Rollback();
  330. throw new Exception(ex.Message);
  331. }
  332. }
  333. #endregion
  334. #region 保存PDF
  335. public static void AddINPDF(string INCode, string tFileName, string dsconn)
  336. {
  337. FramDataContext db = new FramDataContext(dsconn);
  338. db.Connection.Open();
  339. db.Transaction = db.Connection.BeginTransaction();
  340. try
  341. {
  342. var line = db.ICSINFile.SingleOrDefault(a => a.INCode == INCode);
  343. line.tFileName = tFileName;
  344. if (line == null)
  345. {
  346. db.ICSINFile.InsertOnSubmit(line);
  347. }
  348. db.SubmitChanges();
  349. db.Transaction.Commit();
  350. }
  351. catch (Exception ex)
  352. {
  353. db.Transaction.Rollback();
  354. throw new Exception(ex.Message);
  355. }
  356. }
  357. #endregion
  358. #region 删除PDF
  359. public static void DeletePDF(string TransNO, string dsconn)
  360. {
  361. FramDataContext db = new FramDataContext(dsconn);
  362. db.Connection.Open();
  363. db.Transaction = db.Connection.BeginTransaction();
  364. try
  365. {
  366. var line = db.ICSOpFileDetail.Single(a => a.TransNO == TransNO);
  367. if (line != null)
  368. {
  369. db.ICSOpFileDetail.DeleteOnSubmit(line);
  370. }
  371. db.SubmitChanges();
  372. db.Transaction.Commit();
  373. }
  374. catch (Exception ex)
  375. {
  376. db.Transaction.Rollback();
  377. throw new Exception(ex.Message);
  378. }
  379. }
  380. public static void DeletePDFAll(string TransNO, string dsconn)
  381. {
  382. SqlConnection conn = new SqlConnection(dsconn);
  383. SqlCommand com = conn.CreateCommand();
  384. SqlTransaction tran;
  385. conn.Open();
  386. tran = conn.BeginTransaction();
  387. com.Transaction = tran;
  388. try
  389. {
  390. string sql = @"DELETE FROM ICSOpFileDetail WHERE TransNO = '" + TransNO + "'";
  391. com.CommandText = sql;
  392. com.ExecuteNonQuery();
  393. com.Transaction.Commit();
  394. }
  395. catch (Exception ex)
  396. {
  397. com.Transaction.Rollback();
  398. throw ex;
  399. }
  400. }
  401. public static void DeletePDF1(string id, string dsconn)
  402. {
  403. FramDataContext db = new FramDataContext(dsconn);
  404. db.Connection.Open();
  405. db.Transaction = db.Connection.BeginTransaction();
  406. try
  407. {
  408. var line = db.ICSOpFileDetail.SingleOrDefault(a => a.ID == id);
  409. if (line != null)
  410. {
  411. db.ICSOpFileDetail.DeleteOnSubmit(line);
  412. }
  413. db.SubmitChanges();
  414. db.Transaction.Commit();
  415. }
  416. catch (Exception ex)
  417. {
  418. db.Transaction.Rollback();
  419. throw new Exception(ex.Message);
  420. }
  421. }
  422. public static void DeleteINPDF(string id, string dsconn)
  423. {
  424. FramDataContext db = new FramDataContext(dsconn);
  425. db.Connection.Open();
  426. db.Transaction = db.Connection.BeginTransaction();
  427. try
  428. {
  429. var line = db.ICSINFile.SingleOrDefault(a => a.ID == id);
  430. line.tFileName = "";
  431. //db.ICSINFile.InsertOnSubmit(line);
  432. db.SubmitChanges();
  433. db.Transaction.Commit();
  434. }
  435. catch (Exception ex)
  436. {
  437. db.Transaction.Rollback();
  438. throw new Exception(ex.Message);
  439. }
  440. }
  441. #endregion
  442. public static ICSOpFileDetail GetModel1(string id, string dsconn)
  443. {
  444. FramDataContext db = new FramDataContext(dsconn);
  445. db.Connection.Open();
  446. db.Transaction = db.Connection.BeginTransaction();
  447. try
  448. {
  449. var line = db.ICSOpFileDetail.SingleOrDefault(a => a.ID == id);
  450. if (line != null)
  451. {
  452. return line;
  453. }
  454. return null;
  455. }
  456. catch (Exception ex)
  457. {
  458. db.Transaction.Rollback();
  459. throw new Exception(ex.Message);
  460. }
  461. }
  462. public static ICSOpFileDetail GetModel(string TransNO, string dsconn)
  463. {
  464. FramDataContext db = new FramDataContext(dsconn);
  465. db.Connection.Open();
  466. db.Transaction = db.Connection.BeginTransaction();
  467. try
  468. {
  469. var line = db.ICSOpFileDetail.SingleOrDefault(a => a.TransNO == TransNO);
  470. if (line != null)
  471. {
  472. return line;
  473. }
  474. return null;
  475. }
  476. catch (Exception ex)
  477. {
  478. db.Transaction.Rollback();
  479. throw new Exception(ex.Message);
  480. }
  481. }
  482. public static DataTable GetModeldt(string TransNO, string Appconstr)
  483. {
  484. try
  485. {
  486. string lineSql = @"SELECT FileName FROM dbo.ICSOpFileDetail WHERE TransNO = '" + TransNO + "'";
  487. return DBHelper.ExecuteDataset(Appconstr, CommandType.Text, lineSql).Tables[0];
  488. }
  489. catch (Exception ex)
  490. {
  491. throw new Exception(ex.Message);
  492. }
  493. }
  494. public static ICSINFile GetINModel(string id, string dsconn)
  495. {
  496. FramDataContext db = new FramDataContext(dsconn);
  497. db.Connection.Open();
  498. db.Transaction = db.Connection.BeginTransaction();
  499. try
  500. {
  501. var line = db.ICSINFile.SingleOrDefault(a => a.ID == id);
  502. if (line != null)
  503. {
  504. return line;
  505. }
  506. return null;
  507. }
  508. catch (Exception ex)
  509. {
  510. db.Transaction.Rollback();
  511. throw new Exception(ex.Message);
  512. }
  513. }
  514. public static DataTable Check(string BarCode, string ToCheckNo, string Appconstr)
  515. {
  516. try
  517. {
  518. string lineSql = @"SELECT a.ItemCode
  519. FROM ICSToCheck a
  520. left join ICSWareHouseLotInfo b on a.ItemCode=b.INVCode
  521. WHERE b.LotNO = '" + BarCode + "'and a.ToCheckNO='" + ToCheckNo + "'";
  522. return DBHelper.ExecuteDataset(Appconstr, CommandType.Text, lineSql).Tables[0];
  523. }
  524. catch (Exception ex)
  525. {
  526. throw new Exception(ex.Message);
  527. }
  528. }
  529. public static DataTable CheckNo(string BarCode, string Appconstr)
  530. {
  531. try
  532. {
  533. string lineSql = @"SELECT LotNO,WHCode FROM dbo.ICSWareHouseLotInfo WHERE LotNO = '" + BarCode + "'";
  534. return DBHelper.ExecuteDataset(Appconstr, CommandType.Text, lineSql).Tables[0];
  535. }
  536. catch (Exception ex)
  537. {
  538. throw new Exception(ex.Message);
  539. }
  540. }
  541. private static DataTable SQlReturnData(SqlCommand cmd)
  542. {
  543. DataTable dt = new DataTable();
  544. SqlDataAdapter dr = new System.Data.SqlClient.SqlDataAdapter();
  545. dr.SelectCommand = cmd;
  546. dr.Fill(dt);
  547. return dt;
  548. }
  549. private static void SaveGetrdIDandAutoID(string connectstring, string returnTxt, string IDtype, string cAcc_id, int rowCount, out int id, out int autoID)
  550. {
  551. try
  552. {
  553. string str = @"DECLARE @ID int
  554. DECLARE @DID int
  555. SET @ID = 0
  556. SET @DID = 0
  557. IF NOT EXISTS (SELECT * FROM ufsystem..ua_identity WHERE cacc_id = '{0}' AND cVouchType = '{1}')
  558. INSERT INTO ufsystem..ua_identity(cAcc_Id,cVouchType,iFatherId,iChildId) VALUES('{0}','{1}',1,1)
  559. SELECT @ID = ifatherID + 1 ,@DID = ichildID + {2}
  560. FROM ufsystem..ua_identity
  561. WHERE cVouchType = '{1}'
  562. AND cAcc_id = '{0}'
  563. UPDATE ufsystem..ua_identity
  564. SET ifatherID = ifatherID + 1,ichildID = ichildID + {2}
  565. WHERE cVouchType = '{1}' AND cAcc_id = '{0}'
  566. select @ID as ID,@DID as DID";
  567. str = string.Format(str, cAcc_id, IDtype, rowCount.ToString());
  568. DataTable dt = DBHelper.ExecuteDataset(connectstring, CommandType.Text, str).Tables[0];
  569. if (dt.Rows.Count == 0)
  570. {
  571. throw new Exception("ID取得失败");
  572. }
  573. id = Convert.ToInt32(dt.Rows[0]["ID"]);
  574. autoID = Convert.ToInt32(dt.Rows[0]["DID"]);
  575. }
  576. catch (Exception ex)
  577. {
  578. throw new Exception(returnTxt + ex.Message);
  579. }
  580. }
  581. #region 删除
  582. public static void delete(List<string> guidList, string Appconstr)
  583. {
  584. SqlConnection conn = new SqlConnection(Appconstr);
  585. conn.Open();
  586. SqlCommand cmd = new SqlCommand();
  587. SqlTransaction trans = conn.BeginTransaction();
  588. cmd.Transaction = trans;
  589. cmd.Connection = conn;
  590. try
  591. {
  592. foreach(var guid in guidList)
  593. {
  594. string sql = @"DELETE FROM ICSOpFile WHERE TransNO='{0}' and WorkPoint='{1}'
  595. DELETE FROM ICSOpFileDetail WHERE TransNO='{0}' AND WorkPoint='{1}'";
  596. sql = string.Format(sql,guid,AppConfig.WorkPointCode);
  597. cmd.CommandText = sql;
  598. cmd.ExecuteNonQuery();
  599. }
  600. cmd.Transaction.Commit();
  601. }
  602. catch (Exception ex)
  603. {
  604. trans.Rollback();
  605. throw ex;
  606. }
  607. }
  608. #endregion
  609. public static void AddINList(List<ICSINFile> datas, string dsconn)
  610. {
  611. FramDataContext db = new FramDataContext(dsconn);
  612. db.Connection.Open();
  613. db.Transaction = db.Connection.BeginTransaction();
  614. try
  615. {
  616. foreach (ICSINFile data in datas)
  617. {
  618. bool isNew = false;
  619. var line = db.ICSINFile.SingleOrDefault(a => a.ID == data.ID);
  620. if (line == null)
  621. {
  622. isNew = true;
  623. line = new ICSINFile();
  624. line.ID = data.ID;
  625. }
  626. line.INCode = data.INCode;
  627. line.VenBatch = data.VenBatch;
  628. line.VenderLotNO = data.VenderLotNO;
  629. line.LotNOs = data.LotNOs;
  630. line.WorkPoint = data.WorkPoint;
  631. line.MUSER = data.MUSER;
  632. line.MUSERName = data.MUSERName;
  633. line.MTIME = data.MTIME;
  634. if (isNew)
  635. db.ICSINFile.InsertOnSubmit(line);
  636. db.SubmitChanges();
  637. }
  638. db.SubmitChanges();
  639. db.Transaction.Commit();
  640. }
  641. catch (Exception ex)
  642. {
  643. db.Transaction.Rollback();
  644. throw new Exception(ex.Message);
  645. }
  646. }
  647. #region 删除
  648. public static void deleteIN(List<String> guidList)
  649. {
  650. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  651. db.Connection.Open();
  652. db.Transaction = db.Connection.BeginTransaction();
  653. try
  654. {
  655. var lines = db.ICSINFile.Where(a => guidList.Contains(a.ID));
  656. db.ICSINFile.DeleteAllOnSubmit(lines);
  657. db.SubmitChanges();
  658. db.Transaction.Commit();
  659. }
  660. catch (Exception ex)
  661. {
  662. db.Transaction.Rollback();
  663. throw ex;
  664. }
  665. }
  666. #endregion
  667. }
  668. }