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

568 lines
28 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 ICSSoft.Base.Config.AppConfig;
  9. using System.Data.SqlClient;
  10. using Newtonsoft.Json;
  11. using ICSSoft.Entity;
  12. using System.Net;
  13. using System.IO;
  14. using ICSSoft.Entity.AssemVouch;
  15. namespace ICSSoft.Frame.Data.DAL
  16. {
  17. public class ICSWBSSpecailTransferDAL
  18. {
  19. static string message = System.Configuration.ConfigurationSettings.AppSettings["IsOpen"].ToString();
  20. static string APIURL = System.Configuration.ConfigurationSettings.AppSettings["APIURL"].ToString();
  21. static string IAssemVouch = APIURL + "APIConfirmAssemVouch";
  22. public static void AddAndEdit(List<ICSWBSSpecialTransfer> InfoList, string dsconn)
  23. {
  24. FramDataContext db = new FramDataContext(dsconn);
  25. db.Connection.Open();
  26. db.Transaction = db.Connection.BeginTransaction();
  27. try
  28. {
  29. foreach (ICSWBSSpecialTransfer TransferInfo in InfoList)
  30. {
  31. var line = new ICSWBSSpecialTransfer();
  32. line.ProjectType = TransferInfo.ProjectType;
  33. line.WareHouseCode = TransferInfo.WareHouseCode;
  34. line.LotNo = TransferInfo.LotNo;
  35. line.BATCHNew = TransferInfo.BATCHNew;
  36. line.BATCHOld = TransferInfo.BATCHOld;
  37. line.INVCOENew = TransferInfo.INVCOENew;
  38. line.INVCOEOld = TransferInfo.INVCOEOld;
  39. line.TransferReason = TransferInfo.TransferReason;
  40. line.MUSER = TransferInfo.MUSER;
  41. line.MUSERNAME = TransferInfo.MUSERNAME;
  42. line.MTIME = TransferInfo.MTIME;
  43. line.WorkPoint = TransferInfo.WorkPoint;
  44. line.EATTRIBUTE1 = TransferInfo.EATTRIBUTE1;
  45. db.ICSWBSSpecialTransfer.InsertOnSubmit(line);
  46. db.SubmitChanges();
  47. }
  48. db.Transaction.Commit();
  49. }
  50. catch (Exception ex)
  51. {
  52. db.Transaction.Rollback();
  53. throw ex;
  54. }
  55. }
  56. public static void UpdateTransfer(string ItemCode, string WbsOld, string WbsNew, string TransferQTY, string WareHouse, string dsonn)
  57. {
  58. string sql = @"select * from ICSWBS
  59. WHERE ItemCode='" + ItemCode + "'";
  60. sql += " AND WBSCode='" + WbsNew + "'";
  61. sql = string.Format(sql);
  62. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  63. if (dt.Rows.Count == 0)
  64. {
  65. sql = @"Insert into ICSWBS VALUES
  66. ('" + ItemCode + "','" + WbsNew + "','" + TransferQTY + "','" + WareHouse + "','" + AppConfig.WorkPointCode + "','" + AppConfig.UserId + "','" + AppConfig.UserName + "','" + DateTime.Now + "','')";
  67. }
  68. else
  69. {
  70. sql = @"Update ICSWBS set ItemNumber=ItemNumber+" + TransferQTY + " where WBSCode='" + WbsNew + "'";
  71. }
  72. DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql);
  73. string strsql = @"Update ICSWBS set ItemNumber=ItemNumber-" + TransferQTY + " where WBSCode='" + WbsOld + "'";
  74. DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, strsql);
  75. }
  76. #region 非标件WBS转换
  77. public static void UpdateWBS(SqlConnection sqlConnection, SqlTransaction trans, string LotCod, string QtyCode, string IDCode, string dsconn)
  78. {
  79. decimal LotQTY = 0;
  80. string LotNo = "";
  81. string NewLotNo = "";
  82. string cIDCode = "";
  83. string TransID = "";
  84. string invcode = "";
  85. string batch = "";
  86. string MinvId = "";//物料ID
  87. string sql = "";
  88. int result = 0;
  89. string[] Lotcodelist = LotCod.Split(',');
  90. string[] QtyCodeList = QtyCode.Split(',');
  91. string[] IDCodeList = IDCode.Split(',');
  92. SqlCommand cmd = new SqlCommand();
  93. cmd.Connection = sqlConnection;
  94. cmd.Transaction = trans;
  95. try
  96. {
  97. for (int i = 0; i < IDCodeList.Length; i++)
  98. {
  99. if (cIDCode == "")
  100. {
  101. cIDCode += "'" + IDCodeList[i] + "'";
  102. }
  103. else
  104. {
  105. cIDCode += ",'" + IDCodeList[i] + "'";
  106. }
  107. }
  108. sql = @"select C.LotNO
  109. ,A.TransNO
  110. ,A.TransLine
  111. ,B.INVCODE
  112. ,C.INVCOENew
  113. ,ISNULL(B.LotQty, 0) as LOTQTY
  114. ,B.WHCode
  115. ,A.VenderLotNO
  116. ,C.BATCHNew,ISNULL(A.EATTRIBUTE3, 0.00) EATTRIBUTE3
  117. from ICSWBSSpecialTransfer C
  118. LEFT JOIN ICSITEMLot A ON C.LotNo=A.LotNO AND A.WorkPoint=C.WorkPoint
  119. LEFT JOIN ICSWareHouseLotInfo B ON A.LotNO=B.LotNO AND A.WorkPoint=B.WorkPoint
  120. WHERE C.ID IN ({0}) AND A.WorkPoint='{1}'
  121. ORDER BY A.VenderLotNO,B.INVCODE ";
  122. sql = string.Format(sql, cIDCode, AppConfig.WorkPointCode);
  123. DataTable dw = SQlReturnData(sql, cmd);
  124. if (dw == null || dw.Rows.Count <= 0)
  125. return;
  126. List<AssemVouch> contextlist = new List<AssemVouch>();
  127. AssemVouch context = new AssemVouch();
  128. List<AssemVouchs> contextlists = new List<AssemVouchs>();
  129. AssemVouchs contexts = new AssemVouchs();
  130. string cWBC = "";
  131. string cBatch = "";
  132. string transfer = "";
  133. string cInvcode = "";
  134. for (int i = 0; i < dw.Rows.Count; i++)
  135. {
  136. if (i > 0)
  137. {
  138. context.list = contextlists;
  139. contextlist.Add(context);
  140. }
  141. context = new AssemVouch();
  142. context.UserCode = AppConfig.UserCode;
  143. context.cTVCode = dw.Rows[i]["TransNO"].ToString();
  144. context.cIWhCode = dw.Rows[i]["WHCode"].ToString();
  145. context.cOWhCode = dw.Rows[i]["WHCode"].ToString();
  146. context.UserCode = AppConfig.UserCode;
  147. contextlists = new List<AssemVouchs>();
  148. contexts = new AssemVouchs();
  149. //批号
  150. if (dw.Rows[i]["BATCHNew"].ToString() == "")
  151. {
  152. contexts.cTVBatchAfter = dw.Rows[i]["VenderLotNO"].ToString();
  153. }
  154. else
  155. {
  156. contexts.cTVBatchAfter = dw.Rows[i]["BATCHNew"].ToString();
  157. }
  158. contexts.cTVBatchBefore = dw.Rows[i]["VenderLotNO"].ToString();
  159. //料品
  160. if (dw.Rows[i]["INVCOENew"].ToString() == "")
  161. {
  162. contexts.cInvCodeAfter = dw.Rows[i]["INVCODE"].ToString();
  163. }
  164. else
  165. {
  166. contexts.cInvCodeAfter = dw.Rows[i]["INVCOENew"].ToString();
  167. }
  168. contexts.cInvCodeBefore = dw.Rows[i]["INVCODE"].ToString();
  169. contexts.iQuantity = Convert.ToDecimal(dw.Rows[i]["LOTQTY"].ToString());
  170. contexts.iNum = Convert.ToDecimal(dw.Rows[i]["LOTQTY"].ToString()) * Convert.ToDecimal(dw.Rows[i]["EATTRIBUTE3"].ToString());
  171. contexts.cWhCode = dw.Rows[i]["WHCode"].ToString();
  172. contexts.bAVType = "转换";
  173. contextlists.Add(contexts);
  174. if (i == dw.Rows.Count - 1)
  175. {
  176. context.list = contextlists;
  177. contextlist.Add(context);
  178. }
  179. }
  180. sql = @"UPDATE ICSWBSSpecialTransfer SET LotStatus = '已审核' WHERE ID IN ({0}) AND WorkPoint = '{1}' ";
  181. sql = string.Format(sql, cIDCode, AppConfig.WorkPointCode);
  182. cmd.CommandText = sql;
  183. result = cmd.ExecuteNonQuery();
  184. if (result <= 0)
  185. {
  186. throw new Exception("审核状态更新失败!");
  187. }
  188. for (int i = 0; i < IDCodeList.Length; i++)
  189. {
  190. LotNo = Lotcodelist[i];
  191. TransID = IDCodeList[i];
  192. LotQTY = Convert.ToDecimal(QtyCodeList[i]);
  193. string sqltr = @"select LotNo,NewLotNo,INVCOENew,INVCOEOld,BATCHNew,BATCHOld,WareHouseCode from ICSWBSSpecialTransfer
  194. where ID='{0}'AND WorkPoint='{1}'";
  195. sqltr = string.Format(sqltr, TransID, AppConfig.WorkPointCode);
  196. DataTable dttr = SQlReturnData(sqltr, cmd);
  197. if (dttr != null || dttr.Rows.Count != 0)
  198. {
  199. invcode = dttr.Rows[0]["INVCOENew"].ToString();
  200. batch = dttr.Rows[0]["BATCHNew"].ToString();
  201. NewLotNo = dttr.Rows[0]["NewLotNo"].ToString();
  202. }
  203. #region 物料更新
  204. if (invcode != "")
  205. {
  206. string WHGUID = "";
  207. string WHCode = "";
  208. string BinGUID = "";
  209. string BinCode = "";
  210. string INVGUID = "";
  211. string INVCode = "";
  212. sql = @"select ID,INVCODE from ICSINVENTORY
  213. where INVCODE='{0}'AND WorkPoint='{1}'";
  214. sql = string.Format(sql, invcode, AppConfig.WorkPointCode);
  215. DataTable dtc = DBHelper.ExecuteDataset(AppConfig.GetDataBaseConnectStringByKey("[DB.SYS]"), CommandType.Text, sql).Tables[0];
  216. if (dtc.Rows.Count > 0)
  217. {
  218. MinvId = dtc.Rows[0]["ID"].ToString();
  219. }
  220. string sqlv = @"select * from ICSWareHouseLotInfo
  221. where lotNO='{0}'AND WorkPoint='{1}'";
  222. sqlv = string.Format(sqlv, LotNo, AppConfig.WorkPointCode);
  223. DataTable dtv = SQlReturnData(sqlv, cmd);
  224. if (dtv != null || dtv.Rows.Count != 0)
  225. {
  226. WHGUID = dtv.Rows[0]["WHGUID"].ToString();
  227. WHCode = dtv.Rows[0]["WHCode"].ToString();
  228. BinGUID = dtv.Rows[0]["BinGUID"].ToString();
  229. BinCode = dtv.Rows[0]["BinCode"].ToString();
  230. INVGUID = dtv.Rows[0]["INVGUID"].ToString();
  231. INVCode = dtv.Rows[0]["INVCode"].ToString();
  232. }
  233. //原库存主表
  234. string sqls = @"select * from ICSWareHouseInfo
  235. where INVGUID='{0}' AND WHGUID='{1}' AND BinGUID='{2}' AND WorkPoint='{3}'";
  236. sqls = string.Format(sqls, INVGUID, WHGUID, BinGUID, AppConfig.WorkPointCode);
  237. DataTable dt = SQlReturnData(sqls, cmd);
  238. //目标库存主表
  239. string sqly = @"select * from ICSWareHouseInfo
  240. where INVGUID='{0}' AND WHGUID='{1}' AND BinGUID='{2}' AND WorkPoint='{3}'";
  241. sqly = string.Format(sqly, MinvId, WHGUID, BinGUID, AppConfig.WorkPointCode);
  242. DataTable dy = SQlReturnData(sqly, cmd);
  243. //更新原库存数据
  244. if (dt.Rows.Count != 0)
  245. {
  246. #region 更新原条码ICSWareHouseLotInfo表
  247. string sqln = @"Update ICSWareHouseLotInfo
  248. SET LotQty=0 WHERE LotNO='" + LotNo + "' AND WorkPoint='" + AppConfig.WorkPointCode + "'";
  249. sqln = string.Format(sqln);
  250. cmd.CommandText = sqln;
  251. result = cmd.ExecuteNonQuery();
  252. if (result <= 0)
  253. {
  254. throw new Exception("库存物料更新失败!");
  255. }
  256. #endregion
  257. string sqlw = @"Update ICSWareHouseInfo
  258. SET QTY=QTY-{0} where INVGUID='{1}' AND WHGUID='{2}' AND BinGUID='{3}' AND WorkPoint='{4}'";
  259. sqlw = string.Format(sqlw, LotQTY, INVGUID, WHGUID, BinGUID, AppConfig.WorkPointCode);
  260. cmd.CommandText = sqlw;
  261. result = cmd.ExecuteNonQuery();
  262. if (result <= 0)
  263. {
  264. throw new Exception("库存主表物料更新失败!");
  265. }
  266. #region 存入ICSWareHouseLotInfoLog表(日志)
  267. sql = @"insert into ICSWareHouseLotInfoLog
  268. Values
  269. (NEWID(),'{0}','{1}','{2}','{3}','{9}','{10}','',''
  270. ,{4},null,'{5}','','{6}','{7}',GETDATE(),'{8}','','','','','')";
  271. sql = string.Format(sql, "", "", INVCode, LotNo, LotQTY, "形态", AppConfig.UserCode, AppConfig.UserName, AppConfig.WorkPointCode, WHCode, BinCode);
  272. cmd.CommandText = sql;
  273. result = cmd.ExecuteNonQuery();
  274. if (result <= 0)
  275. {
  276. throw new Exception("日志表存入失败!");
  277. }
  278. #endregion
  279. }
  280. //更新目标库存数据
  281. if (dy.Rows.Count != 0)
  282. {
  283. string sqlh = @"Update ICSWareHouseInfo
  284. SET QTY=QTY+{0} where INVGUID='{1}' AND WHGUID='{2}' AND BinGUID='{3}' AND WorkPoint='{4}'";
  285. sqlh = string.Format(sqlh, LotQTY, MinvId, WHGUID, BinGUID, AppConfig.WorkPointCode);
  286. cmd.CommandText = sqlh;
  287. result = cmd.ExecuteNonQuery();
  288. if (result <= 0)
  289. {
  290. throw new Exception("库存主表物料更新失败!");
  291. }
  292. #region 存入ICSWareHouseLotInfo表
  293. sql = @"insert into ICSWareHouseLotInfo
  294. Values
  295. (NEWID(),'{0}','{1}','{2}','{3}','{4}','{5}','{6}',{7},GETDATE(),'{9}','{10}','{11}',GETDATE(),'{13}','','')";
  296. sql = string.Format(sql, NewLotNo, WHGUID, WHCode, BinGUID, BinCode, MinvId, invcode, LotQTY, DateTime.Now, AppConfig.WorkPointCode, AppConfig.UserCode, AppConfig.UserName, DateTime.Now, "形态转换", 0);
  297. cmd.CommandText = sql;
  298. result = cmd.ExecuteNonQuery();
  299. if (result <= 0)
  300. {
  301. throw new Exception("库存物料更新失败!");
  302. }
  303. #endregion
  304. #region 存入ICSWareHouseLotInfoLog表(日志)
  305. sql = @"insert into ICSWareHouseLotInfoLog
  306. Values
  307. (NEWID(),'{0}','{1}','{2}','{3}','{9}','{10}','',''
  308. ,{4},null,'{5}','','{6}','{7}',GETDATE(),'{8}','','','','','')";
  309. sql = string.Format(sql, "", "", INVCode, NewLotNo, LotQTY, "形态", AppConfig.UserCode, AppConfig.UserName, AppConfig.WorkPointCode, WHCode, BinCode);
  310. cmd.CommandText = sql;
  311. result = cmd.ExecuteNonQuery();
  312. if (result <= 0)
  313. {
  314. throw new Exception("日志表存入失败!");
  315. }
  316. #endregion
  317. }
  318. //更新目标库存数据
  319. if (dy.Rows.Count == 0)
  320. {
  321. #region 存入ICSWareHouseLotInfo表
  322. sql = @"insert into ICSWareHouseLotInfo
  323. Values
  324. (NEWID(),'{0}','{1}','{2}','{3}','{4}','{5}','{6}',{7},GETDATE(),'{9}','{10}','{11}',GETDATE(),'{13}','','')";
  325. sql = string.Format(sql, NewLotNo, WHGUID, WHCode, BinGUID, BinCode, MinvId, invcode, LotQTY, DateTime.Now, AppConfig.WorkPointCode, AppConfig.UserCode, AppConfig.UserName, DateTime.Now, "形态转换", 0);
  326. cmd.CommandText = sql;
  327. result = cmd.ExecuteNonQuery();
  328. if (result <= 0)
  329. {
  330. throw new Exception("库存物料更新失败!");
  331. }
  332. #endregion
  333. #region 更新原条码ICSWareHouseLotInfo表
  334. string sqln = @"Update ICSWareHouseLotInfo
  335. SET LotQty=0 WHERE LotNO='" + LotNo + "' AND WorkPoint='" + AppConfig.WorkPointCode + "'";
  336. sqln = string.Format(sqln);
  337. cmd.CommandText = sqln;
  338. result = cmd.ExecuteNonQuery();
  339. if (result <= 0)
  340. {
  341. throw new Exception("库存物料更新失败!");
  342. }
  343. #endregion
  344. #region 存入ICSWareHouseInfo表
  345. sql = @"insert into ICSWareHouseInfo
  346. Values
  347. ('{0}','{1}','{2}','{3}','{4}','{5}',{6},'{7}','{8}','{9}','{10}','')";
  348. sql = string.Format(sql, WHGUID, WHCode, BinGUID, BinCode, MinvId, invcode, LotQTY, AppConfig.WorkPointCode, AppConfig.UserCode, AppConfig.UserName, DateTime.Now);
  349. cmd.CommandText = sql;
  350. result = cmd.ExecuteNonQuery();
  351. if (result <= 0)
  352. {
  353. throw new Exception("库存主表存入失败!");
  354. }
  355. #endregion
  356. #region 存入ICSWareHouseLotInfoLog表(日志)
  357. sql = @"insert into ICSWareHouseLotInfoLog
  358. Values
  359. (NEWID(),'{0}','{1}','{2}','{3}','{9}','{10}','',''
  360. ,{4},null,'{5}','','{6}','{7}',GETDATE(),'{8}','','','','','')";
  361. sql = string.Format(sql, "", "", invcode, NewLotNo, LotQTY, "形态", AppConfig.UserCode, AppConfig.UserName, AppConfig.WorkPointCode, WHCode, BinCode);
  362. cmd.CommandText = sql;
  363. result = cmd.ExecuteNonQuery();
  364. if (result <= 0)
  365. {
  366. throw new Exception("日志表存入失败!");
  367. }
  368. #endregion
  369. }
  370. }
  371. #endregion
  372. #region 批次更新
  373. // if (batch!="")
  374. // {
  375. // sql = @"Update ICSITEMLot
  376. // SET VenderLotNO='" + batch + "' WHERE LotNO='" + LotNo + "'AND WorkPoint='" + AppConfig.WorkPointCode + "'";
  377. // sql = string.Format(sql);
  378. // cmd.CommandText = sql;
  379. // result = cmd.ExecuteNonQuery();
  380. // if (result <= 0)
  381. // {
  382. // throw new Exception("条码批次更新失败!");
  383. // }
  384. // }
  385. #endregion
  386. }
  387. if (message == "true")
  388. {
  389. #region 接口调用
  390. string Istr = JsonConvert.SerializeObject(contextlist);
  391. string iresult = HttpPost(IAssemVouch, Istr);
  392. Result INVDismResult = new Result();
  393. INVDismResult = JsonConvert.DeserializeObject<Result>(iresult);
  394. if (INVDismResult.code != "200")
  395. {
  396. throw new Exception(INVDismResult.msg);
  397. }
  398. }
  399. }
  400. catch (Exception ex)
  401. {
  402. throw new Exception(ex.Message);
  403. }
  404. #endregion
  405. }
  406. #endregion
  407. #region 更新WMS
  408. public static void UpdateTransWMS(SqlConnection sqlConnection, SqlTransaction trans, List<ICSWBSSpecialTransfer> InfoList, List<ICSITEMLot> lotList, string dsconn)
  409. {
  410. string sql = "";
  411. int result = 0;
  412. FramDataContext db = new FramDataContext(dsconn);
  413. db.Connection.Open();
  414. db.Transaction = db.Connection.BeginTransaction();
  415. try
  416. {
  417. foreach (ICSWBSSpecialTransfer TransferInfo in InfoList)
  418. {
  419. bool isNew = false;
  420. var line = db.ICSWBSSpecialTransfer.SingleOrDefault(a => a.ID == TransferInfo.ID && a.WorkPoint == AppConfig.WorkPointCode);
  421. if (line == null)
  422. {
  423. isNew = true;
  424. line = new ICSWBSSpecialTransfer();
  425. }
  426. line.ProjectType = TransferInfo.ProjectType;
  427. line.WareHouseCode = TransferInfo.WareHouseCode;
  428. line.LotNo = TransferInfo.LotNo;
  429. line.WBSCodeOld = TransferInfo.WBSCodeOld;
  430. line.WBSCodeNew = TransferInfo.WBSCodeNew;
  431. line.TransferReason = TransferInfo.TransferReason;
  432. line.INVCOEOld = TransferInfo.INVCOEOld;
  433. line.INVCOENew = TransferInfo.INVCOENew;
  434. line.BATCHOld = TransferInfo.BATCHOld;
  435. line.BATCHNew =TransferInfo.BATCHNew;
  436. line.LotStatus = TransferInfo.LotStatus;
  437. line.NewLotNo = TransferInfo.NewLotNo;
  438. line.MUSER = AppConfig.UserCode;
  439. line.MUSERNAME = AppConfig.UserName;
  440. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  441. line.WorkPoint = AppConfig.WorkPointCode;
  442. if (isNew)
  443. {
  444. db.ICSWBSSpecialTransfer.InsertOnSubmit(line);
  445. }
  446. db.SubmitChanges();
  447. }
  448. foreach (ICSITEMLot info in lotList)
  449. {
  450. var inv = db.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == info.MCODE && a.WorkPoint == AppConfig.WorkPointCode);
  451. if (inv == null)
  452. throw new Exception("物料不存在!");
  453. var lines = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == info.LotNO && a.WorkPoint == AppConfig.WorkPointCode);
  454. if (lines != null)
  455. throw new Exception("条码已存在!");
  456. bool isNew = false;
  457. var line = db.ICSITEMLot.SingleOrDefault(a => a.ID == info.ID && a.WorkPoint == AppConfig.WorkPointCode);
  458. if (line == null)
  459. {
  460. isNew = true;
  461. line = new ICSITEMLot();
  462. line.ID = AppConfig.GetGuid();
  463. }
  464. line.LotNO = info.LotNO;
  465. line.MCODE = info.MCODE;
  466. line.TransNO = info.TransNO;
  467. line.TransLine = info.TransLine;
  468. line.VENDORITEMCODE = info.VENDORITEMCODE;
  469. line.VENDORCODE = info.VENDORCODE;
  470. line.VenderLotNO = info.VenderLotNO;
  471. line.PRODUCTDATE = info.PRODUCTDATE;
  472. line.LOTQTY = info.LOTQTY;
  473. line.EATTRIBUTE3 = info.LOTQTY;
  474. line.EATTRIBUTE4 = 0;
  475. line.ACTIVE = info.ACTIVE;
  476. line.Exdate = info.Exdate;
  477. line.TYPE = "形态转换";
  478. line.EATTRIBUTE3 = info.EATTRIBUTE3;
  479. line.MUSER = AppConfig.UserCode;
  480. line.MUSERName = AppConfig.UserName;
  481. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  482. line.WorkPoint = AppConfig.WorkPointCode;
  483. if (isNew)
  484. {
  485. db.ICSITEMLot.InsertOnSubmit(line);
  486. }
  487. db.SubmitChanges();
  488. }
  489. db.Transaction.Commit();
  490. }
  491. catch (Exception ex)
  492. {
  493. db.Transaction.Rollback();
  494. throw ex;
  495. }
  496. }
  497. #endregion
  498. /// <summary>
  499. /// 接口调用方法
  500. /// </summary>
  501. /// <param name="url"></param>
  502. /// <param name="body"></param>
  503. /// <returns></returns>
  504. public static string HttpPost(string url, string body)
  505. {
  506. try
  507. {
  508. Encoding encoding = Encoding.UTF8;
  509. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  510. request.Method = "POST";
  511. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  512. request.ContentType = "application/json; charset=utf-8";
  513. byte[] buffer = encoding.GetBytes(body);
  514. request.ContentLength = buffer.Length;
  515. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  516. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  517. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  518. {
  519. return reader.ReadToEnd();
  520. }
  521. }
  522. catch (WebException ex)
  523. {
  524. var res = (HttpWebResponse)ex.Response;
  525. StringBuilder sb = new StringBuilder();
  526. StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
  527. sb.Append(sr.ReadToEnd());
  528. //string ssb = sb.ToString();
  529. throw new Exception(sb.ToString());
  530. }
  531. }
  532. public static DataTable SQlReturnData(string SQl, SqlCommand cmd)
  533. {
  534. DataTable dt = new DataTable();
  535. cmd.CommandText = SQl;
  536. SqlDataAdapter dr = new System.Data.SqlClient.SqlDataAdapter();
  537. dr.SelectCommand = cmd;
  538. dr.Fill(dt);
  539. return dt;
  540. }
  541. }
  542. }