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

4175 lines
203 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. using Newtonsoft.Json;
  11. using System.Net;
  12. using System.IO;
  13. using ICSSoft.Entity;
  14. using ICSSoft.Entity.mom_order;
  15. using ICSSoft.Entity.Dispatchlist;
  16. using ICSSoft.Entity.PU_ArrivalVouch;
  17. using ICSSoft.Entity.TransVouch;
  18. using ICSSoft.Entity.mom_orderdetail;
  19. namespace ICSSoft.Frame.Data.DAL
  20. {
  21. public class ICSWareHouseLotInfoDAL
  22. {
  23. static string message = System.Configuration.ConfigurationSettings.AppSettings["SysIsOpen"].ToString();
  24. static string APIURL = System.Configuration.ConfigurationSettings.AppSettings["APIURL"].ToString();
  25. static string IStockIN = APIURL + "APICreateRdrecord01";
  26. static string IInvOut = APIURL + "APICreateRdrecord11";
  27. //static string IInvOutPick = APIURL + "APICreateRdrecord11ByMaterial";
  28. static string IInvTrans = APIURL + "APIConfimTranVouch";
  29. //static string IInvTransMO = APIURL + "APICreateTransVouch";
  30. static string IDispatch = APIURL + "APICreateRdrecord32";
  31. static string IStockINForMO = APIURL + "APICreateRdrecord10";
  32. static string IOtherOut = ""; //System.Configuration.ConfigurationSettings.AppSettings["IOtherOut"].ToString();
  33. /// <summary>
  34. /// 获取货位信息
  35. /// </summary>
  36. /// <param name="StackCode"></param>
  37. /// <param name="workpointCode"></param>
  38. /// <returns></returns>
  39. public static DataTable GetBinCode(string LotNO, string WorkPoint, string dsconn)
  40. {
  41. string sql = @"SELECT B.BinCode FROM ICSWareHouseInfo B LEFT JOIN ICSITEMLot A ON A.ItemCode = B.INVCode
  42. WHERE A.LotNO = '{0}' AND A.WorkPoint = '{1}' ORDER BY B.QTY DESC ";
  43. sql = string.Format(sql, LotNO, WorkPoint);
  44. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  45. return dt;
  46. }
  47. /// <summary>
  48. /// 验证库位信息
  49. /// </summary>
  50. /// <param name="StackCode"></param>
  51. /// <param name="workpointCode"></param>
  52. /// <returns></returns>
  53. public static DataTable CheckStackCode(string StackCode, string workpointCode, string dsconn)
  54. {
  55. string sql = @"select A.StackCode,B.StorageCode from ICSStack A
  56. LEFT JOIN ICSStorage B
  57. ON B.Serial=A.Storage_Serial
  58. WHERE A.StackCode='{0}' AND A.WorkPoint='{1}'";
  59. sql = string.Format(sql, StackCode, workpointCode);
  60. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  61. return dt;
  62. }
  63. /// <summary>
  64. /// 验证条码信息(采购上架)
  65. /// </summary>
  66. /// <param name="lotNo"></param>
  67. /// <param name="workpointCode"></param>
  68. /// <returns></returns>
  69. public static DataTable CheckLotNoForStockIn(string lotNo, string workpointCode, string dsconn)
  70. {
  71. string sql = @"
  72. select A.LotNO,A.TYPE,
  73. '' AS LogLot,
  74. D.LotNO AS BarCode,
  75. A.EATTRIBUTE2,
  76. C.cInvCode from ICSITEMLot A
  77. LEFT JOIN ICSPOArrive C
  78. ON A.TransNO=C.cCode AND A.TransLine=C.irowno
  79. LEFT JOIN ICSWareHouseLotInfo D
  80. ON D.LotNO=A.LotNO
  81. where A.LotNO='{0}' and A.WorkPoint='{1}'";
  82. sql = string.Format(sql, lotNo, workpointCode);
  83. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  84. return dt;
  85. }
  86. /// <summary>
  87. /// 验证条码信息(半成品/成品上架)
  88. /// </summary>
  89. /// <param name="lotNo"></param>
  90. /// <param name="workpointCode"></param>
  91. /// <param name="dsconn"></param>
  92. /// <returns></returns>
  93. public static DataTable CheckLotNoForMOIn(string lotNo, string workpointCode, string dsconn)
  94. {
  95. string sql = @"select A.LotNO,A.TYPE,D.LotNO AS BarCode,A.TransNO,B.MOCODE,E.ISCOM,G.Result,G.TResult from ICSITEMLot A
  96. LEFT JOIN ICSMO B
  97. ON B.MOCODE=A.TransNO AND B.MOSEQ=A.TransLine
  98. LEFT JOIN ICSWareHouseLotInfo D
  99. ON D.LotNO=A.LotNO
  100. LEFT JOIN ICSLOTSIMULATION E
  101. ON E.LOTNO=A.LotNO
  102. LEFT JOIN ICSLOTONWIP F
  103. ON F.LOTNO=E.LOTNO AND F.OPCODE=E.OPCODE
  104. LEFT JOIN ICSLOTONWIPCheck G
  105. ON G.ONWIPID=F.ID
  106. where A.LotNO='{0}' and A.WorkPoint='{1}' AND A.TYPE=''";
  107. sql = string.Format(sql, lotNo, workpointCode);
  108. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  109. return dt;
  110. }
  111. /// <summary>
  112. /// 采购入库
  113. /// </summary>
  114. /// <param name="barcodeList"></param>
  115. /// <param name="bincodeList"></param>
  116. /// <param name="wrokpointCode"></param>
  117. /// <param name="dsconn"></param>
  118. /// <returns></returns>
  119. public static bool StockIn(SqlConnection sqlConnection, SqlTransaction trans, string[] barcodeList, string[] bincodeList, string userCode, string userName, string wrokpointCode, string Type, string ScanType, string dsconn)
  120. {
  121. string sql = "";
  122. string BarCode = "";
  123. string BinCode = "";
  124. string cBarCode = "";
  125. int result = 0;
  126. string ConnectString = dsconn;
  127. bool isSuccess = true;
  128. SqlCommand cmd = new SqlCommand();
  129. cmd.Connection = sqlConnection;
  130. cmd.Transaction = trans;
  131. for (int i = 0; i < barcodeList.Length; i++)
  132. {
  133. try
  134. {
  135. BarCode = barcodeList[i];
  136. BinCode = bincodeList[i];
  137. if (cBarCode == "")
  138. {
  139. cBarCode += "'" + BarCode + "'";
  140. }
  141. else
  142. {
  143. cBarCode += ",'" + BarCode + "'";
  144. }
  145. #region 获取仓库库位信息
  146. string WHGuid = "";
  147. string BinGuid = "";
  148. string WHCode = "";
  149. sql = @"select A.Serial,B.Serial AS WHGUID,B.StorageCode from ICSStack A
  150. INNER JOIN ICSStorage B
  151. on B.Serial=A.Storage_Serial
  152. where StackCode='{0}'";
  153. sql = string.Format(sql, BinCode);
  154. DataTable dt = SQlReturnData(sql, cmd);
  155. if (dt.Rows.Count == 0)
  156. {
  157. throw new Exception("获取仓库信息失败!");
  158. }
  159. else
  160. {
  161. WHGuid = dt.Rows[0]["WHGUID"].ToString();
  162. BinGuid = dt.Rows[0]["Serial"].ToString();
  163. WHCode = dt.Rows[0]["StorageCode"].ToString();
  164. }
  165. #endregion
  166. #region 获取物料信息
  167. string INVCode = "";
  168. string INVGuid = "";
  169. decimal LotQTY = 0;
  170. string TransNo = "";
  171. string TransLine = "";
  172. string cVenCode = "";
  173. DateTime ReceDate = DateTime.Now;
  174. sql = @"SELECT DISTINCT A.TransNO, A.TransLine, B.INVCODE, B.ID, A.LOTQTY, A.PRODUCTDATE, A.VENDORCODE, A.EATTRIBUTE2,
  175. C.EATTRIBUTE6, ISNULL(A.EATTRIBUTE3,0) AS EATTRIBUTE3, ISNULL(A.EATTRIBUTE4,0) AS EATTRIBUTE4
  176. FROM ICSITEMLot A LEFT JOIN ICSINVENTORY B ON A.ItemCode = B.INVCODE LEFT JOIN ICSINVInfo C ON C.INVCODE = A.ItemCode
  177. WHERE LotNO = '{0}' ";
  178. sql = string.Format(sql, BarCode);
  179. dt = SQlReturnData(sql, cmd);
  180. if (dt.Rows.Count == 0)
  181. {
  182. throw new Exception("获取物料信息失败");
  183. }
  184. else
  185. {
  186. INVCode = dt.Rows[0]["INVCODE"].ToString();
  187. INVGuid = dt.Rows[0]["ID"].ToString();
  188. if (dt.Rows[0]["EATTRIBUTE6"].ToString() == "免检" || dt.Rows[0]["EATTRIBUTE2"].ToString() == "合格" || dt.Rows[0]["EATTRIBUTE2"].ToString() == "让步")
  189. {
  190. LotQTY = Convert.ToDecimal(dt.Rows[0]["LOTQTY"].ToString());
  191. }
  192. else
  193. {
  194. throw new Exception("条码" + BarCode + "尚未检验或者为不合格,无法入库!");
  195. }
  196. #region
  197. //else
  198. //{
  199. // if (Convert.ToDecimal(dt.Rows[0]["EATTRIBUTE3"].ToString()) == 0)
  200. // {
  201. // throw new Exception("条码" + BarCode + "尚未进行检验数据录入或合格数为0,无法入库!");
  202. // }
  203. // else
  204. // {
  205. // LotQTY = Convert.ToDecimal(dt.Rows[0]["EATTRIBUTE3"].ToString());
  206. // }
  207. //}
  208. #endregion
  209. ReceDate = Convert.ToDateTime(dt.Rows[0]["PRODUCTDATE"].ToString());
  210. TransNo = dt.Rows[0]["TransNO"].ToString();
  211. TransLine = dt.Rows[0]["TransLine"].ToString();
  212. cVenCode = dt.Rows[0]["VENDORCODE"].ToString();
  213. }
  214. #endregion
  215. #region 存入ICSWareHouseInfo表
  216. sql = @"select * from ICSWareHouseInfo
  217. where INVCode='{0}' AND WHCode='{1}' AND BinCode='{2}'";
  218. sql = string.Format(sql, INVCode, WHCode, BinCode);
  219. dt = SQlReturnData(sql, cmd);
  220. if (dt.Rows.Count == 0)
  221. {
  222. sql = @"insert into ICSWareHouseInfo
  223. Values
  224. ('{0}','{1}','{2}','{3}','{4}','{5}',{6},'{7}','{8}','{9}','{10}','')";
  225. sql = string.Format(sql, WHGuid, WHCode, BinGuid, BinCode, INVGuid, INVCode, LotQTY, wrokpointCode, userCode, userName, DateTime.Now);
  226. cmd.CommandText = sql;
  227. result = cmd.ExecuteNonQuery();
  228. if (isSuccess && result <= 0)
  229. {
  230. throw new Exception("库存主表存入失败!");
  231. }
  232. }
  233. else
  234. {
  235. sql = @"update ICSWareHouseInfo
  236. set QTY=QTY+{0},MTIME='{1}'
  237. where INVCode='{2}' AND WHCode='{3}' AND BinCode='{4}'";
  238. sql = string.Format(sql, LotQTY, DateTime.Now, INVCode, WHCode, BinCode);
  239. cmd.CommandText = sql;
  240. result = cmd.ExecuteNonQuery();
  241. if (isSuccess && result <= 0)
  242. {
  243. throw new Exception("库存主表更新失败");
  244. }
  245. }
  246. #endregion
  247. #region 存入ICSWareHouseLotInfo表
  248. sql = @"insert into ICSWareHouseLotInfo
  249. Values
  250. (NEWID(),'{0}','{1}','{2}','{3}','{4}','{5}','{6}',{7},GETDATE(),'{8}','{9}','{10}',GETDATE(),'','','')";
  251. sql = string.Format(sql, BarCode, WHGuid, WHCode, BinGuid, BinCode, INVGuid, INVCode, LotQTY, wrokpointCode, userCode, userName);
  252. cmd.CommandText = sql;
  253. result = cmd.ExecuteNonQuery();
  254. if (isSuccess && result <= 0)
  255. {
  256. throw new Exception("库存子表存入失败");
  257. }
  258. #endregion
  259. #region 存入ICSWareHouseLotInfoLog表(日志)
  260. sql = @"insert into ICSWareHouseLotInfoLog
  261. Values
  262. (NEWID(),'{0}','{1}','{2}','{3}',null,null,'{4}','{5}'
  263. ,{6},null,'{7}','','{8}','{9}',GETDATE(),'{10}','','','','','')";
  264. sql = string.Format(sql, TransNo, TransLine, INVCode, BarCode, WHCode, BinCode, LotQTY, Type, userCode, userName, wrokpointCode);
  265. cmd.CommandText = sql;
  266. result = cmd.ExecuteNonQuery();
  267. if (isSuccess && result <= 0)
  268. {
  269. throw new Exception("日志存入失败");
  270. }
  271. #endregion
  272. }
  273. catch (Exception ex)
  274. {
  275. throw new Exception(ex.Message);
  276. }
  277. }
  278. if (message == "Open")
  279. {
  280. #region 接口调用
  281. try
  282. {
  283. sql = @"SELECT A.VENDORCODE, A.TransNO, B.WHCode, C.ErpID AS WBS, A.ItemCode, B.LotQty, A.VenderLotNO, C.ERPAutoid AS Free1, A.EATTRIBUTE3 * A.LOTQTY iNum
  284. FROM ICSITEMLot A INNER JOIN ICSWareHouseLotInfo B ON B.LotNO = A.LotNO
  285. INNER JOIN ICSPOArrive C ON C.cCode = A.TransNO AND C.irowno = A.TransLine AND Free3 = ''
  286. WHERE A.LotNO IN ({0}) ORDER BY A.TransNO ";
  287. sql = string.Format(sql, cBarCode);
  288. DataTable dt = SQlReturnData(sql, cmd);
  289. List<PU_ArrivalVouch> contextlist = new List<PU_ArrivalVouch>();
  290. PU_ArrivalVouch context = new PU_ArrivalVouch();
  291. List<PU_ArrivalVouchs> contextlists = new List<PU_ArrivalVouchs>();
  292. PU_ArrivalVouchs contexts = new PU_ArrivalVouchs();
  293. string POCode = "";
  294. string WareHouse = "";
  295. for (int i = 0; i < dt.Rows.Count; i++)
  296. {
  297. if (POCode != dt.Rows[i]["TransNO"].ToString() || WareHouse != dt.Rows[i]["WHCode"].ToString())
  298. {
  299. if (i > 0)
  300. {
  301. context.list = contextlists;
  302. contextlist.Add(context);
  303. }
  304. context = new PU_ArrivalVouch();
  305. POCode = dt.Rows[i]["TransNO"].ToString();
  306. WareHouse = dt.Rows[i]["WHCode"].ToString();
  307. context.cWhCode = dt.Rows[i]["WHCode"].ToString();
  308. context.ID = dt.Rows[i]["WBS"].ToString(); ;
  309. context.UserCode = userCode;
  310. context.IsReturn = "0";
  311. contextlists = new List<PU_ArrivalVouchs>();
  312. }
  313. contexts = new PU_ArrivalVouchs();
  314. contexts.cInvCode = dt.Rows[i]["ItemCode"].ToString();
  315. contexts.iQuantity = Convert.ToDecimal(dt.Rows[i]["LotQty"].ToString());
  316. contexts.cBatch = dt.Rows[i]["VenderLotNO"].ToString();
  317. contexts.AutoID = dt.Rows[i]["Free1"].ToString();
  318. contexts.iNum = Convert.ToDecimal(dt.Rows[i]["iNum"].ToString());
  319. contextlists.Add(contexts);
  320. if (i == dt.Rows.Count - 1)
  321. {
  322. context.list = contextlists;
  323. contextlist.Add(context);
  324. }
  325. }
  326. string Istr = JsonConvert.SerializeObject(contextlist);
  327. string iresult = HttpPost(IStockIN, Istr);
  328. Result StockInResult = new Result();
  329. StockInResult = JsonConvert.DeserializeObject<Result>(iresult);
  330. if (StockInResult.code != "200")
  331. {
  332. throw new Exception(StockInResult.msg);
  333. }
  334. }
  335. catch (Exception ex)
  336. {
  337. throw new Exception(ex.Message);
  338. }
  339. #endregion
  340. }
  341. return isSuccess;
  342. }
  343. /// <summary>
  344. /// 半成品入库
  345. /// </summary>
  346. /// <param name="sqlConnection"></param>
  347. /// <param name="trans"></param>
  348. /// <param name="pocodeList"></param>
  349. /// <param name="porowList"></param>
  350. /// <param name="poqtyList"></param>
  351. /// <param name="barcodeList"></param>
  352. /// <param name="bincodeList"></param>
  353. /// <param name="wrokpointCode"></param>
  354. /// <param name="Type"></param>
  355. /// <param name="ScanType"></param>
  356. /// <param name="dsconn"></param>
  357. /// <returns></returns>
  358. public static bool StockInForMo(SqlConnection sqlConnection, SqlTransaction trans, string[] barcodeList, string[] bincodeList, string userCode, string userName, string wrokpointCode, string Type, string ScanType, string dsconn)
  359. {
  360. string sql = "";
  361. string BarCode = "";
  362. string BinCode = "";
  363. string cBarCode = "";
  364. int result = 0;
  365. string ConnectString = dsconn;
  366. bool isSuccess = true;
  367. SqlCommand cmd = new SqlCommand();
  368. cmd.Connection = sqlConnection;
  369. cmd.Transaction = trans;
  370. try
  371. {
  372. for (int i = 0; i < barcodeList.Length; i++)
  373. {
  374. BarCode = barcodeList[i];
  375. BinCode = bincodeList[i];
  376. if (cBarCode == "")
  377. {
  378. cBarCode += "'" + BarCode + "'";
  379. }
  380. else
  381. {
  382. cBarCode += ",'" + BarCode + "'";
  383. }
  384. #region 获取仓库库位信息
  385. string WHGuid = "";
  386. string BinGuid = "";
  387. string WHCode = "";
  388. sql = @"select A.Serial,B.Serial AS WHGUID,B.StorageCode from ICSStack A
  389. INNER JOIN ICSStorage B
  390. on B.Serial=A.Storage_Serial
  391. where StackCode='{0}'";
  392. sql = string.Format(sql, BinCode);
  393. DataTable dt = SQlReturnData(sql, cmd);
  394. if (dt.Rows.Count == 0)
  395. {
  396. throw new Exception("获取仓库信息失败!");
  397. }
  398. else
  399. {
  400. WHGuid = dt.Rows[0]["WHGUID"].ToString();
  401. BinGuid = dt.Rows[0]["Serial"].ToString();
  402. WHCode = dt.Rows[0]["StorageCode"].ToString();
  403. }
  404. #endregion
  405. #region 获取物料信息
  406. string INVCode = "";
  407. string INVGuid = "";
  408. decimal LotQTY = 0;
  409. string TransNo = "";
  410. string TransLine = "";
  411. DateTime ReceDate = DateTime.Now;
  412. sql = @"select A.TransNO
  413. ,A.TransLine
  414. ,B.INVCODE
  415. ,B.ID,A.LOTQTY
  416. ,A.PRODUCTDATE
  417. from ICSITEMLot A
  418. left join ICSINVENTORY B
  419. on A.ItemCode=B.INVCODE
  420. where LotNO='{0}'";
  421. sql = string.Format(sql, BarCode);
  422. dt = SQlReturnData(sql, cmd);
  423. if (dt.Rows.Count == 0)
  424. {
  425. throw new Exception("获取物料信息失败!");
  426. }
  427. else
  428. {
  429. INVCode = dt.Rows[0]["INVCODE"].ToString();
  430. INVGuid = dt.Rows[0]["ID"].ToString();
  431. LotQTY = Convert.ToDecimal(dt.Rows[0]["LOTQTY"].ToString());
  432. ReceDate = Convert.ToDateTime(dt.Rows[0]["PRODUCTDATE"].ToString());
  433. TransNo = dt.Rows[0]["TransNO"].ToString();
  434. TransLine = dt.Rows[0]["TransLine"].ToString();
  435. }
  436. #endregion
  437. #region 存入ICSWareHouseInfo表
  438. sql = @"select * from ICSWareHouseInfo
  439. where INVCode='{0}' AND WHGUID='{1}' AND BinGUID='{2}'";
  440. sql = string.Format(sql, INVCode, WHGuid, BinGuid);
  441. dt = SQlReturnData(sql, cmd);
  442. if (dt.Rows.Count == 0)
  443. {
  444. sql = @"insert into ICSWareHouseInfo
  445. Values
  446. ('{0}','{1}','{2}','{3}','{4}','{5}',{6},'{7}','{8}','{9}','{10}','')";
  447. sql = string.Format(sql, WHGuid, WHCode, BinGuid, BinCode, INVGuid, INVCode, LotQTY, wrokpointCode, userCode, userName, DateTime.Now);
  448. cmd.CommandText = sql;
  449. result = cmd.ExecuteNonQuery();
  450. if (isSuccess && result <= 0)
  451. {
  452. throw new Exception("库存主表存入失败!");
  453. }
  454. }
  455. else
  456. {
  457. sql = @"update ICSWareHouseInfo
  458. set QTY=QTY+{0},MTIME='{1}'
  459. where INVCode='{2}' AND WHGUID='{3}' AND BinGUID='{4}'";
  460. sql = string.Format(sql, LotQTY, DateTime.Now, INVCode, WHGuid, BinGuid);
  461. cmd.CommandText = sql;
  462. result = cmd.ExecuteNonQuery();
  463. if (isSuccess && result <= 0)
  464. {
  465. throw new Exception("库存主表更新失败!");
  466. }
  467. }
  468. #endregion
  469. #region 存入ICSWareHouseLotInfo表
  470. sql = @"insert into ICSWareHouseLotInfo
  471. Values
  472. (NEWID(),'{0}','{1}','{2}','{3}','{4}','{5}','{10}',{6},GETDATE(),'{7}','{8}','{9}',GETDATE(),'','','')";
  473. sql = string.Format(sql, BarCode, WHGuid, WHCode, BinGuid, BinCode, INVGuid, LotQTY, wrokpointCode, userCode, userName, INVCode);
  474. cmd.CommandText = sql;
  475. result = cmd.ExecuteNonQuery();
  476. if (isSuccess && result <= 0)
  477. {
  478. throw new Exception("库存子表存入失败!");
  479. }
  480. #endregion
  481. #region 存入ICSWareHouseLotInfoLog表(日志)
  482. sql = @"insert into ICSWareHouseLotInfoLog
  483. Values
  484. (NEWID(),'{0}','{1}','{2}','{3}',null,null,'{4}','{5}'
  485. ,{6},null,'{7}','()','{8}','{9}',GETDATE(),'{10}','','','','','')";
  486. sql = string.Format(sql, TransNo, TransLine, INVCode, BarCode, WHCode, BinCode, LotQTY, Type, userCode, userName, wrokpointCode);
  487. cmd.CommandText = sql;
  488. result = cmd.ExecuteNonQuery();
  489. if (isSuccess && result <= 0)
  490. {
  491. throw new Exception("日志表存入失败!");
  492. }
  493. #endregion
  494. }
  495. }
  496. catch (Exception ex)
  497. {
  498. throw new Exception(ex.Message);
  499. }
  500. if (message == "Open")
  501. {
  502. #region 接口调用
  503. try
  504. {
  505. sql = @"select A.EATTRIBUTE2
  506. ,A.EATTRIBUTE1
  507. ,B.LotNO
  508. ,A.MOCODE
  509. ,A.MOSEQ
  510. ,C.WHCode
  511. ,B.ItemCode
  512. ,C.LotQty
  513. ,B.VenderLotNO
  514. ,ISNULL(B.EATTRIBUTE3,1) AS EATTRIBUTE3
  515. ,A.CUSITEMCODE
  516. from ICSMO A
  517. LEFT JOIN ICSITEMLot B
  518. ON B.TransNO=A.MOCODE AND B.TransLine=A.MOSEQ
  519. LEFT JOIN ICSWareHouseLotInfo C
  520. ON C.LotNO=B.LotNO
  521. WHERE C.LotNO IN ({0})";
  522. sql = string.Format(sql, cBarCode);
  523. DataTable dt = SQlReturnData(sql, cmd);
  524. List<mom_order> contextlist = new List<mom_order>();
  525. mom_order context = new mom_order();
  526. List<ICSSoft.Entity.mom_order.mom_orderdetail> contextlists = new List<ICSSoft.Entity.mom_order.mom_orderdetail>();
  527. ICSSoft.Entity.mom_order.mom_orderdetail contexts = new ICSSoft.Entity.mom_order.mom_orderdetail();
  528. string MOCODE = "";
  529. string WareHouse = "";
  530. string DeptCode = "";
  531. for (int i = 0; i < dt.Rows.Count; i++)
  532. {
  533. if (MOCODE != dt.Rows[i]["MOCODE"].ToString() || WareHouse != dt.Rows[i]["WHCode"].ToString()
  534. || DeptCode != dt.Rows[i]["CUSITEMCODE"].ToString())
  535. {
  536. if (i > 0)
  537. {
  538. context.list = contextlists;
  539. contextlist.Add(context);
  540. }
  541. context = new mom_order();
  542. MOCODE = dt.Rows[i]["MOCODE"].ToString();
  543. WareHouse = dt.Rows[i]["WHCode"].ToString();
  544. DeptCode = dt.Rows[i]["CUSITEMCODE"].ToString();
  545. context.MoCode = dt.Rows[i]["MOCODE"].ToString();
  546. context.cWhCode = dt.Rows[i]["WHCode"].ToString();
  547. context.MoId = dt.Rows[i]["EATTRIBUTE2"].ToString();
  548. context.UserCode = userCode;
  549. context.IsReturn = "0";
  550. context.MDeptCode = dt.Rows[i]["CUSITEMCODE"].ToString(); ;
  551. contextlists = new List<ICSSoft.Entity.mom_order.mom_orderdetail>();
  552. }
  553. contexts = new ICSSoft.Entity.mom_order.mom_orderdetail();
  554. contexts.cInvCode = dt.Rows[i]["ItemCode"].ToString();
  555. contexts.iQuantity = Convert.ToDecimal(dt.Rows[i]["LotQty"].ToString());
  556. contexts.cBatch = dt.Rows[i]["VenderLotNO"].ToString();
  557. contexts.MoDId = dt.Rows[i]["EATTRIBUTE1"].ToString();
  558. contexts.SortSeq = dt.Rows[i]["MOSEQ"].ToString();
  559. contexts.iNum = Convert.ToDecimal(dt.Rows[i]["LotQty"].ToString()) * Convert.ToDecimal(dt.Rows[i]["EATTRIBUTE3"].ToString());
  560. contextlists.Add(contexts);
  561. if (i == dt.Rows.Count - 1)
  562. {
  563. context.list = contextlists;
  564. contextlist.Add(context);
  565. }
  566. }
  567. string Istr = JsonConvert.SerializeObject(contextlist);
  568. string iresult = HttpPost(IStockINForMO, Istr);
  569. Result MOInResult = new Result();
  570. MOInResult = JsonConvert.DeserializeObject<Result>(iresult);
  571. if (MOInResult.code != "200")
  572. {
  573. throw new Exception(MOInResult.msg);
  574. }
  575. }
  576. catch (Exception ex)
  577. {
  578. throw new Exception(ex.Message);
  579. }
  580. #endregion
  581. }
  582. return isSuccess;
  583. }
  584. /// <summary>
  585. /// SQL执行方法
  586. /// </summary>
  587. /// <param name="SQl"></param>
  588. /// <param name="cmd"></param>
  589. /// <returns></returns>
  590. public static DataTable SQlReturnData(string SQl, SqlCommand cmd)
  591. {
  592. DataTable dt = new DataTable();
  593. cmd.CommandText = SQl;
  594. SqlDataAdapter dr = new System.Data.SqlClient.SqlDataAdapter();
  595. dr.SelectCommand = cmd;
  596. dr.Fill(dt);
  597. return dt;
  598. }
  599. /// <summary>
  600. /// 验证采购退货单信息(采购退货)
  601. /// </summary>
  602. /// <param name="lotNo"></param>
  603. /// <param name="workpointCode"></param>
  604. /// <returns></returns>
  605. public static DataTable CheckPOCode(string cCode, string workpointCode, string dsconn)
  606. {
  607. string sql = @"select * from ICSPOArrive
  608. where cCode='{0}'
  609. AND Free3='退'
  610. AND WorkPoint='{1}'
  611. ORDER BY irowno";
  612. sql = string.Format(sql, cCode, workpointCode);
  613. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  614. return dt;
  615. }
  616. /// <summary>
  617. /// 获取采购退货信息(采购退货)
  618. /// </summary>
  619. /// <param name="POCode"></param>
  620. /// <param name="workpointCode"></param>
  621. /// <param name="dsconn"></param>
  622. /// <returns></returns>
  623. public static DataTable GetPOReturnData(string POCode, string workpointCode, string dsconn)
  624. {
  625. string sql = @"SELECT A.cCode AS POCode, A.irowno AS PORow, A.cInvCode AS INVCODE, B.INVNAME AS INVNAME,
  626. B.INVSTD AS INVSTD, ISNULL(A.iQuantity,0) AS RequestQty, ISNULL(A.INQty,0) AS Inqty,
  627. B.INVUOM AS INVUOM, A.Batch, A.cWhCode FROM ICSPOArrive A
  628. LEFT JOIN ICSINVENTORY B ON B.INVCODE=A.cInvCode WHERE A.cCode = '{0}' AND A.WorkPoint = '{1}'
  629. ORDER BY INVCODE ";
  630. sql = string.Format(sql, POCode, workpointCode);
  631. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  632. return dt;
  633. }
  634. /// <summary>
  635. /// 验证条码信息(采购退货)
  636. /// </summary>
  637. /// <param name="BarCode"></param>
  638. /// <param name="workpointCode"></param>
  639. /// <param name="dsconn"></param>
  640. /// <returns></returns>
  641. public static DataTable CheckLotnoForReturn(string BarCode, string workpointCode, string dsconn)
  642. {
  643. string sql = @"select A.LotNO
  644. ,B.LotNO AS WHLotno
  645. ,B.INVCode
  646. ,B.BinCode
  647. ,C.INVNAME
  648. ,C.INVSTD
  649. ,C.INVUOM
  650. ,B.LotQty
  651. ,B.WHCode
  652. ,A.EATTRIBUTE3
  653. ,ISNULL(A.VenderLotNO,'') AS VenderLotNO
  654. from ICSITEMLot A
  655. left join ICSWareHouseLotInfo B
  656. ON B.LotNO=A.LotNO
  657. LEFT JOIN ICSINVENTORY C
  658. ON C.INVCODE=B.INVCode
  659. WHERE A.LotNO='{0}' AND A.WorkPoint='{1}'";
  660. sql = string.Format(sql, BarCode, workpointCode);
  661. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  662. return dt;
  663. }
  664. /// <summary>
  665. /// 验证条码信息(工单领料)
  666. /// </summary>
  667. /// <param name="BarCode"></param>
  668. /// <param name="workpointCode"></param>
  669. /// <param name="dsconn"></param>
  670. /// <returns></returns>
  671. public static DataTable CheckLotnoForMOOut(string BarCode, string workpointCode, string dsconn)
  672. {
  673. string sql = @"select ISNULL(D.cBatchProperty6,'') as cBatchProperty6
  674. ,ISNULL(D.cDefine22,'') as cDefine22
  675. ,ISNULL(D.cDefine24,'') as cDefine24
  676. ,A.LotNO
  677. ,B.LotNO AS WHLotno
  678. ,B.INVCode
  679. ,B.BinCode
  680. ,C.INVNAME
  681. ,C.INVSTD
  682. ,C.INVUOM
  683. ,B.LotQty
  684. ,B.WHCode
  685. ,A.EATTRIBUTE3
  686. ,ISNULL(A.VenderLotNO,'') AS VenderLotNO
  687. from ICSITEMLot A
  688. left join ICSWareHouseLotInfo B
  689. ON B.LotNO=A.LotNO
  690. LEFT JOIN ICSINVENTORY C
  691. ON C.INVCODE=B.INVCode
  692. LEFT JOIN ICSPOArrive D
  693. ON D.cCode=A.TransNO AND D.irowno=A.TransLine
  694. WHERE A.LotNO='{0}' AND A.WorkPoint='{1}'";
  695. sql = string.Format(sql, BarCode, workpointCode);
  696. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  697. return dt;
  698. }
  699. /// <summary>
  700. /// 验证条码信息(移库)
  701. /// </summary>
  702. /// <param name="BarCode"></param>
  703. /// <param name="workpointCode"></param>
  704. /// <param name="dsconn"></param>
  705. /// <returns></returns>
  706. public static DataTable CheckLotnoForStackTrans(string BarCode, string workpointCode, string dsconn)
  707. {
  708. string sql = @"select A.LotNO
  709. ,B.LotNO AS WHLotno,B.INVCode
  710. ,B.BinCode
  711. ,C.INVNAME
  712. ,C.INVSTD
  713. ,C.INVUOM
  714. ,B.LotQty
  715. ,B.WHCode
  716. from ICSITEMLot A
  717. left join ICSWareHouseLotInfo B
  718. ON B.LotNO=A.LotNO
  719. LEFT JOIN ICSINVENTORY C
  720. ON C.INVCODE=B.INVCode
  721. WHERE A.LotNO='{0}' AND A.WorkPoint='{1}'";
  722. sql = string.Format(sql, BarCode, workpointCode);
  723. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  724. return dt;
  725. }
  726. /// <summary>
  727. /// 验证库位信息(移库)
  728. /// </summary>
  729. /// <param name="BarCode"></param>
  730. /// <param name="workpointCode"></param>
  731. /// <param name="dsconn"></param>
  732. /// <returns></returns>
  733. public static DataTable CheckBinCodeForStackTrans(string BinCode, string workpointCode, string dsconn)
  734. {
  735. string sql = @"SELECT A.LotNO, B.LotNO AS WHLotno, B.BinCode, C.INVNAME, C.INVSTD, C.INVUOM, B.LotQty, B.WHCode,A.ItemCode
  736. FROM ICSITEMLot A INNER JOIN ICSWareHouseLotInfo B ON B.LotNO = A.LotNO
  737. LEFT JOIN ICSINVENTORY C ON C.INVCODE = B.INVCode WHERE B.BinCode = '{0}' AND A.WorkPoint = '{1}' AND B.LotQty > 0 ";
  738. sql = string.Format(sql, BinCode, workpointCode);
  739. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  740. return dt;
  741. }
  742. /// <summary>
  743. /// 验证箱号信息(移库)
  744. /// </summary>
  745. /// <param name="BarCode"></param>
  746. /// <param name="workpointCode"></param>
  747. /// <param name="dsconn"></param>
  748. /// <returns></returns>
  749. public static DataTable CheckBoxnoForStackTrans(string BarCode, string workpointCode, string dsconn)
  750. {
  751. string sql = @"select A.LotNO
  752. ,B.LotNO AS WHLotno
  753. ,B.BinCode
  754. ,C.INVNAME
  755. ,C.INVSTD
  756. ,C.INVUOM
  757. ,B.LotQty
  758. ,B.WHCode
  759. from ICSITEMLot A
  760. left join ICSWareHouseLotInfo B
  761. ON B.LotNO=A.LotNO
  762. LEFT JOIN ICSINVENTORY C
  763. ON C.INVCODE=B.INVCode
  764. LEFT JOIN ICSPalletLotNO E
  765. ON E.LotNO=B.LotNO
  766. WHERE E.PalletCode='{0}' AND A.WorkPoint='{1}'";
  767. sql = string.Format(sql, BarCode, workpointCode);
  768. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  769. return dt;
  770. }
  771. /// <summary>
  772. /// 验证销售出库条码信息
  773. /// </summary>
  774. /// <param name="SOCode"></param>
  775. /// <param name="BarCode"></param>
  776. /// <param name="dsconn"></param>
  777. /// <returns></returns>
  778. public static DataTable CheckLotnoForSO(string SOCode, string BarCode, string workpointCode, string dsconn)
  779. {
  780. string sql = @"select A.LotNO
  781. ,B.LotNO AS WHLotno
  782. ,B.INVCode
  783. ,B.BinCode
  784. ,C.INVNAME
  785. ,C.INVSTD
  786. ,C.INVUOM
  787. ,B.LotQty AS LotQty
  788. ,B.WHCode
  789. ,A.VenderLotNO
  790. ,A.EATTRIBUTE3
  791. from ICSITEMLot A
  792. left join ICSWareHouseLotInfo B
  793. ON B.LotNO=A.LotNO
  794. LEFT JOIN ICSINVENTORY C
  795. ON C.INVCODE=B.INVCode
  796. WHERE A.LotNO='{1}' AND A.WorkPoint='{2}'";
  797. sql = string.Format(sql, SOCode, BarCode, workpointCode);
  798. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  799. return dt;
  800. }
  801. /// <summary>
  802. /// 验证销售退库条码信息
  803. /// </summary>
  804. /// <param name="SOCode"></param>
  805. /// <param name="BarCode"></param>
  806. /// <param name="dsconn"></param>
  807. /// <returns></returns>
  808. public static DataTable CheckLotnoForSOReturn(string BarCode, string workpointCode, string dsconn)
  809. {
  810. string sql = @" select B.DispatchCode
  811. ,B.DispatchRow
  812. ,A.LotNO
  813. ,A.ItemCode
  814. ,C.INVNAME
  815. ,C.INVSTD
  816. ,C.INVUOM
  817. ,A.LotQty
  818. ,A.EATTRIBUTE3
  819. ,A.VenderLotNO
  820. ,B.cBatch
  821. ,B.WHCode
  822. from ICSITEMLot A
  823. LEFT JOIN ICSSODispatch B
  824. ON B.DispatchCode=A.TransNO AND B.DispatchRow=A.TransLine
  825. LEFT JOIN ICSINVENTORY C
  826. ON C.INVCODE=A.ItemCode
  827. WHERE A.LotNO='{0}' AND A.WorkPoint='{1}'";
  828. sql = string.Format(sql, BarCode, workpointCode);
  829. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  830. return dt;
  831. }
  832. /// <summary>
  833. /// 采购退货
  834. /// </summary>
  835. /// <param name="POCode"></param>
  836. /// <param name="porowList"></param>
  837. /// <param name="poqtyList"></param>
  838. /// <param name="barcodeList"></param>
  839. /// <param name="barcodeqtyList"></param>
  840. /// <param name="workpointCode"></param>
  841. /// <param name="Type"></param>
  842. /// <param name="dsconn"></param>
  843. /// <returns></returns>
  844. public static bool StockReturn(SqlConnection sqlConnection, SqlTransaction trans, string cCode, string[] irownoList, string[] inqtyList, string[] barcoderowList, string[] barcodeList, string[] barcodeqtyList, string userCode, string userName, string workpointCode, string Type, string dsconn)
  845. {
  846. string sql = "";
  847. string BarCode = "";
  848. decimal BarCodeQty = 0;
  849. string BarCodeRow = "";
  850. string Errormessage = "";
  851. string cBarCode = "";
  852. string irowno = "";
  853. decimal INQty = 0;
  854. string ConnectString = dsconn;
  855. int result = 0;
  856. bool isSuccess = true;
  857. SqlCommand cmd = new SqlCommand();
  858. cmd.Connection = sqlConnection;
  859. cmd.Transaction = trans;
  860. try
  861. {
  862. for (int i = 0; i < irownoList.Length; i++)
  863. {
  864. #region 更新ICSPOArrive表
  865. irowno = irownoList[i];
  866. INQty = Convert.ToDecimal(inqtyList[i]);
  867. sql = @"update ICSPOArrive set INQty=INQty+{0}
  868. where cCode='{1}' AND irowno='{2}' AND WorkPoint='{3}'";
  869. sql = string.Format(sql, INQty, cCode, irowno, workpointCode);
  870. cmd.CommandText = sql;
  871. result = cmd.ExecuteNonQuery();
  872. if (isSuccess && result <= 0)
  873. {
  874. throw new Exception("采购订单表更新失败!");
  875. }
  876. #endregion
  877. }
  878. for (int i = 0; i < barcodeList.Length; i++)
  879. {
  880. if (cBarCode == "")
  881. {
  882. cBarCode += "'" + barcodeList[i] + "'";
  883. }
  884. {
  885. cBarCode += ",'" + barcodeList[i] + "'";
  886. }
  887. BarCode = barcodeList[i];
  888. BarCodeQty = Convert.ToDecimal(barcodeqtyList[i]);
  889. BarCodeRow = barcoderowList[i];
  890. #region 获取仓库库位等信息
  891. string INVCode = "";
  892. string BinCode = "";
  893. string WHCode = "";
  894. string TranNo = "";
  895. string TranLine = "";
  896. sql = @"select WHCode
  897. ,BinCode
  898. ,INVCode
  899. ,B.TransNO
  900. ,B.TransLine
  901. from ICSWareHouseLotInfo A
  902. left join ICSITEMLot B
  903. on B.LotNO=A.LotNO
  904. where A.LotNO='{0}' AND A.WorkPoint='{1}'";
  905. sql = string.Format(sql, BarCode, workpointCode);
  906. DataTable dt = SQlReturnData(sql, cmd);
  907. if (dt.Rows.Count == 0)
  908. {
  909. throw new Exception("获取仓库信息失败!");
  910. }
  911. else
  912. {
  913. INVCode = dt.Rows[0]["INVCode"].ToString();
  914. BinCode = dt.Rows[0]["BinCode"].ToString();
  915. WHCode = dt.Rows[0]["WHCode"].ToString();
  916. TranNo = dt.Rows[0]["TransNO"].ToString();
  917. TranLine = dt.Rows[0]["TransLine"].ToString();
  918. }
  919. #endregion
  920. #region 更新ICSWareHouseInfo表
  921. sql = @"update ICSWareHouseInfo
  922. set QTY=QTY-{0},MTIME='{1}'
  923. where INVCode='{2}' AND WHCode='{3}' AND BinCode='{4}'";
  924. sql = string.Format(sql, BarCodeQty, DateTime.Now, INVCode, WHCode, BinCode);
  925. cmd.CommandText = sql;
  926. result = cmd.ExecuteNonQuery();
  927. if (isSuccess && result <= 0)
  928. {
  929. throw new Exception("库存主表更新失败!");
  930. }
  931. #endregion
  932. #region 更新ICSWareHouseLotInfo表
  933. sql = @"update ICSWareHouseLotInfo set LotQty=LotQty-{0}
  934. where LotNO='{1}'";
  935. sql = string.Format(sql, BarCodeQty, BarCode);
  936. cmd.CommandText = sql;
  937. result = cmd.ExecuteNonQuery();
  938. if (isSuccess && result <= 0)
  939. {
  940. throw new Exception("库存子表更新失败!");
  941. }
  942. #endregion
  943. #region 存入ICSWareHouseLotInfoLog表(日志)
  944. sql = @"insert into ICSWareHouseLotInfoLog
  945. Values
  946. (NEWID(),'{0}','{1}','{2}','{3}','{4}','{5}',null,null
  947. ,{6},null,'{7}','退','{8}','{9}',GETDATE(),'{10}','','','','','')";
  948. sql = string.Format(sql, cCode, BarCodeRow, INVCode, BarCode, WHCode, BinCode, BarCodeQty, Type, userCode, userName, workpointCode);
  949. cmd.CommandText = sql;
  950. result = cmd.ExecuteNonQuery();
  951. if (isSuccess && result <= 0)
  952. {
  953. throw new Exception("日志表存入失败!");
  954. }
  955. #endregion
  956. }
  957. }
  958. catch (Exception ex)
  959. {
  960. throw new Exception(ex.Message);
  961. }
  962. if (message == "Open")
  963. {
  964. #region 接口调用
  965. try
  966. {
  967. sql = @"SELECT A.VENDORCODE, B.TransNO, B.FRMStorageCODE AS WHCode, C.ErpID AS WBS, A.ItemCode,
  968. B.TransQTY, A.VenderLotNO, C.ERPAutoid AS Free1, A.EATTRIBUTE3 * B.TransQTY iNum FROM ICSITEMLot A
  969. INNER JOIN ICSWareHouseLotInfoLog B ON B.LotNO = A.LotNO AND B.BusinessCode = '退' AND B.EATTRIBUTE5 = ''
  970. INNER JOIN ICSPOArrive C ON C.cCode = B.TransNO AND C.irowno = B.TransLine AND Free3 = '退'
  971. WHERE A.LotNO IN ({0}) ORDER BY A.TransNO ";
  972. sql = string.Format(sql, cBarCode);
  973. DataTable dt = SQlReturnData(sql, cmd);
  974. List<PU_ArrivalVouch> contextlist = new List<PU_ArrivalVouch>();
  975. PU_ArrivalVouch context = new PU_ArrivalVouch();
  976. List<PU_ArrivalVouchs> contextlists = new List<PU_ArrivalVouchs>();
  977. PU_ArrivalVouchs contexts = new PU_ArrivalVouchs();
  978. string POCode = "";
  979. string WareHouse = "";
  980. for (int i = 0; i < dt.Rows.Count; i++)
  981. {
  982. if (POCode != dt.Rows[i]["TransNO"].ToString() || WareHouse != dt.Rows[i]["WHCode"].ToString())
  983. {
  984. if (i > 0)
  985. {
  986. context.list = contextlists;
  987. contextlist.Add(context);
  988. }
  989. context = new PU_ArrivalVouch();
  990. POCode = dt.Rows[i]["TransNO"].ToString();
  991. WareHouse = dt.Rows[i]["WHCode"].ToString();
  992. context.cWhCode = dt.Rows[i]["WHCode"].ToString();
  993. context.ID = dt.Rows[i]["WBS"].ToString(); ;
  994. context.UserCode = userCode;
  995. context.IsReturn = "1";
  996. contextlists = new List<PU_ArrivalVouchs>();
  997. }
  998. contexts = new PU_ArrivalVouchs();
  999. contexts.cInvCode = dt.Rows[i]["ItemCode"].ToString();
  1000. contexts.iQuantity = Convert.ToDecimal(dt.Rows[i]["TransQTY"].ToString());
  1001. contexts.cBatch = dt.Rows[i]["VenderLotNO"].ToString();
  1002. contexts.AutoID = dt.Rows[i]["Free1"].ToString();
  1003. contexts.iNum = Convert.ToDecimal(dt.Rows[i]["iNum"].ToString());
  1004. contextlists.Add(contexts);
  1005. if (i == dt.Rows.Count - 1)
  1006. {
  1007. context.list = contextlists;
  1008. contextlist.Add(context);
  1009. }
  1010. }
  1011. sql = @"UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE5 = '已回写'
  1012. where LotNO in ({0}) AND BusinessCode='退'";
  1013. sql = string.Format(sql, cBarCode);
  1014. cmd.CommandText = sql;
  1015. result = cmd.ExecuteNonQuery();
  1016. if (isSuccess && result <= 0)
  1017. {
  1018. throw new Exception("日志表更新失败!");
  1019. }
  1020. string Istr = JsonConvert.SerializeObject(contextlist);
  1021. string iresult = HttpPost(IStockIN, Istr);
  1022. Result StockInResult = new Result();
  1023. StockInResult = JsonConvert.DeserializeObject<Result>(iresult);
  1024. if (StockInResult.code != "200")
  1025. {
  1026. throw new Exception(StockInResult.msg);
  1027. }
  1028. }
  1029. catch (Exception ex)
  1030. {
  1031. throw new Exception(ex.Message);
  1032. }
  1033. #endregion
  1034. }
  1035. return isSuccess;
  1036. }
  1037. /// <summary>
  1038. /// 验证调拨申请单号
  1039. /// </summary>
  1040. /// <param name="TransferNo"></param>
  1041. /// <param name="workpointCode"></param>
  1042. /// <param name="dsconn"></param>
  1043. /// <returns></returns>
  1044. public static DataTable CheckTransferNoMO(string TransferNo, string TransferLine, string workpointCode, string dsconn)
  1045. {
  1046. string sql = @"SELECT a.MOCODE,
  1047. a.SEQ AS TransferLine
  1048. FROM
  1049. ICSMOBOM a
  1050. where a.WorkPoint = '{0}' AND a.MOCODE='{1}' AND a.SEQ='{2}' ORDER BY a.SEQ,a.MOBOMLINE";
  1051. sql = string.Format(sql, workpointCode, TransferNo, TransferLine);
  1052. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  1053. return dt;
  1054. }
  1055. /// <summary>
  1056. /// 获取调拨申请单信息
  1057. /// </summary>
  1058. /// <param name="TransferNo"></param>
  1059. /// <param name="workpointCode"></param>
  1060. /// <param name="dsconn"></param>
  1061. /// <returns></returns>
  1062. public static DataTable GetTransferDataMO(string TransferNo, string TransferLine, string workpointCode, string dsconn)
  1063. {
  1064. string sql = @"SELECT a.MOCODE,
  1065. a.SEQ AS ,
  1066. a.MOBOMLINE AS TransferLine,
  1067. a.MOBITEMCODE AS ITEMCODE,
  1068. a.MOBITEMNAME AS INVNAME,
  1069. c.INVSTD AS INVSTD,
  1070. a.MOBITEMQTY AS PLANQTY,
  1071. ISNULL(b.HasQuantity, 0) AS ACTQTY
  1072. ,c.INVUOM AS INVUOM
  1073. ,'' AS FROMStorageCode
  1074. ,'' AS TOStorageCode
  1075. FROM
  1076. ICSMOBOM a
  1077. left join ICSMOPickLog b
  1078. on b.MOCODE=a.MOCODE and b.MOSEQ=a.MOBOMLINE And b.SEQ=a.SEQ AND b.EATTRIBUTE1=''
  1079. left join ICSINVENTORY c
  1080. on c.INVCODE=a.MOBITEMCODE
  1081. where a.WorkPoint = '{0}' AND a.MOCODE='{1}' AND a.SEQ='{2}' ORDER BY a.SEQ,a.MOBOMLINE";
  1082. sql = string.Format(sql, workpointCode, TransferNo, TransferLine);
  1083. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  1084. return dt;
  1085. }
  1086. //验证ICSMaterial表状态
  1087. public static DataTable CheckMaterialStatus(string VouchCode, string workpointCode, string dsconn)
  1088. {
  1089. string sql = @"SELECT PickingSTATUS FROM ICSMaterial
  1090. where VouchCode='{0}' and WorkPoint='{1}'";
  1091. sql = string.Format(sql, VouchCode, workpointCode);
  1092. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  1093. return dt;
  1094. }
  1095. /// <summary>
  1096. /// 验证调拨申请单号
  1097. /// </summary>
  1098. /// <param name="TransferNo"></param>
  1099. /// <param name="workpointCode"></param>
  1100. /// <param name="dsconn"></param>
  1101. /// <returns></returns>
  1102. public static DataTable CheckTransferNo(string TransferNo, string workpointCode, string dsconn)
  1103. {
  1104. string sql = @"select * from ICSTransVouchs
  1105. where TransferNO='{0}' and WorkPoint='{1}'
  1106. ORDER BY TransferLine ";
  1107. sql = string.Format(sql, TransferNo, workpointCode);
  1108. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  1109. return dt;
  1110. }
  1111. /// <summary>
  1112. /// 获取调拨申请单信息
  1113. /// </summary>
  1114. /// <param name="TransferNo"></param>
  1115. /// <param name="workpointCode"></param>
  1116. /// <param name="dsconn"></param>
  1117. /// <returns></returns>
  1118. public static DataTable GetTransferData(string TransferNo, string workpointCode, string dsconn)
  1119. {
  1120. string sql = @"select TransferLine
  1121. ,FROMStorageCode
  1122. ,TOStorageCode
  1123. ,ITEMCODE
  1124. ,B.INVNAME
  1125. ,B.INVSTD
  1126. ,A.PLANQTY
  1127. ,A.ACTQTY
  1128. ,B.INVUOM
  1129. ,A.EATTRIBUTE4
  1130. ,ISNULL(A.cTVBatch,'') AS cTVBatch
  1131. from ICSTransVouchs A
  1132. LEFT JOIN ICSINVENTORY B
  1133. ON B.INVCODE=A.ITEMCODE
  1134. where TransferNO='{0}' AND A.WorkPoint='{1}'";
  1135. sql = string.Format(sql, TransferNo, workpointCode);
  1136. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  1137. return dt;
  1138. }
  1139. /// <summary>
  1140. /// 物料调拨
  1141. /// </summary>
  1142. /// <param name="POCode"></param>
  1143. /// <param name="porowList"></param>
  1144. /// <param name="poqtyList"></param>
  1145. /// <param name="barcodeList"></param>
  1146. /// <param name="barcodeqtyList"></param>
  1147. /// <param name="workpointCode"></param>
  1148. /// <param name="Type"></param>
  1149. /// <param name="dsconn"></param>
  1150. /// <returns></returns>
  1151. public static bool WareHouseTrans(SqlConnection sqlConnection, SqlTransaction trans, string POCode, string[] porowList, string[] poqtyList, string[] barcoderowList, string[] barcodeList, string[] barcodeqtyList, string[] bincodeList, string userCode, string userName, string workpointCode, string Type, string dsconn)
  1152. {
  1153. string sql = "";
  1154. string BarCode = "";
  1155. decimal BarCodeQty = 0;
  1156. string cBarCode = "";
  1157. string BarCodeRow = "";
  1158. string Errormessage = "";
  1159. string PORow = "";
  1160. decimal POQty = 0;
  1161. string NewBinCode = "";
  1162. string ConnectString = dsconn;
  1163. int result = 0;
  1164. bool isSuccess = true;
  1165. SqlCommand cmd = new SqlCommand();
  1166. cmd.Connection = sqlConnection;
  1167. cmd.Transaction = trans;
  1168. try
  1169. {
  1170. for (int i = 0; i < porowList.Length; i++)
  1171. {
  1172. #region 更新ICSTransVouchs表
  1173. PORow = porowList[i];
  1174. POQty = Convert.ToDecimal(poqtyList[i]);
  1175. sql = @"update ICSTransVouchs
  1176. set ACTQTY=ACTQTY+{0}
  1177. where TransferNO='{1}' AND TransferLine='{2}'
  1178. and WorkPoint='{3}'";
  1179. sql = string.Format(sql, POQty, POCode, PORow, workpointCode);
  1180. cmd.CommandText = sql;
  1181. result = cmd.ExecuteNonQuery();
  1182. if (isSuccess && result <= 0)
  1183. {
  1184. throw new Exception("调拨申请单已调拨数量更新失败!");
  1185. }
  1186. #endregion
  1187. }
  1188. for (int i = 0; i < barcodeList.Length; i++)
  1189. {
  1190. BarCode = barcodeList[i];
  1191. BarCodeQty = Convert.ToDecimal(barcodeqtyList[i]);
  1192. BarCodeRow = barcoderowList[i];
  1193. NewBinCode = bincodeList[i];
  1194. if (cBarCode == "")
  1195. {
  1196. cBarCode += "'" + barcodeList[i] + "'";
  1197. }
  1198. else
  1199. {
  1200. cBarCode += ",'" + barcodeList[i] + "'";
  1201. }
  1202. string INVCode = "";
  1203. string OldBinCode = "";
  1204. string NewWHCode = "";
  1205. string OldWHCode = "";
  1206. string TranNo = "";
  1207. string TranLine = "";
  1208. #region 获取调拨申请单目标仓库信息
  1209. sql = @"select TOStorageCode from ICSTransVouchs
  1210. where TransferNO='{0}' AND WorkPoint='{1}'";
  1211. sql = string.Format(sql, POCode, workpointCode);
  1212. DataTable dt = SQlReturnData(sql, cmd);
  1213. if (dt.Rows.Count == 0)
  1214. {
  1215. throw new Exception("获取调拨申请单信息失败!");
  1216. }
  1217. else
  1218. {
  1219. NewWHCode = dt.Rows[0]["TOStorageCode"].ToString();
  1220. }
  1221. #endregion
  1222. #region 获取仓库库位等信息
  1223. sql = @"select WHCode
  1224. ,BinCode
  1225. ,INVCode
  1226. ,B.TransNO
  1227. ,B.TransLine
  1228. from ICSWareHouseLotInfo A
  1229. left join ICSITEMLot B
  1230. on B.LotNO=A.LotNO
  1231. where A.LotNO='{0}' AND A.WorkPoint='{1}'";
  1232. sql = string.Format(sql, BarCode, workpointCode);
  1233. dt = SQlReturnData(sql, cmd);
  1234. if (dt.Rows.Count == 0)
  1235. {
  1236. throw new Exception("获取仓库信息失败!");
  1237. }
  1238. else
  1239. {
  1240. INVCode = dt.Rows[0]["INVCode"].ToString();
  1241. OldBinCode = dt.Rows[0]["BinCode"].ToString();
  1242. OldWHCode = dt.Rows[0]["WHCode"].ToString();
  1243. TranNo = dt.Rows[0]["TransNO"].ToString();
  1244. TranLine = dt.Rows[0]["TransLine"].ToString();
  1245. }
  1246. #endregion
  1247. #region 更新ICSWareHouseInfo表
  1248. sql = @"update ICSWareHouseInfo
  1249. set QTY=QTY-{0},MTIME='{1}'
  1250. where INVCode='{2}' AND WHCode='{3}' AND BinCode='{4}'";
  1251. sql = string.Format(sql, BarCodeQty, DateTime.Now, INVCode, OldWHCode, OldBinCode);
  1252. cmd.CommandText = sql;
  1253. result = cmd.ExecuteNonQuery();
  1254. if (isSuccess && result <= 0)
  1255. {
  1256. throw new Exception("库存主表库存扣减失败!");
  1257. }
  1258. sql = @"select * from ICSWareHouseInfo
  1259. where WHCode='{0}' AND BinCode='{1}' AND INVCode='{2}'";
  1260. sql = string.Format(sql, NewWHCode, NewBinCode, INVCode);
  1261. dt = SQlReturnData(sql, cmd);
  1262. if (dt.Rows.Count != 0)
  1263. {
  1264. sql = @"update ICSWareHouseInfo
  1265. set QTY=QTY+{0},MTIME='{1}'
  1266. where INVCode='{2}' AND WHCode='{3}' AND BinCode='{4}'";
  1267. sql = string.Format(sql, BarCodeQty, DateTime.Now, INVCode, NewWHCode, NewBinCode);
  1268. cmd.CommandText = sql;
  1269. result = cmd.ExecuteNonQuery();
  1270. if (isSuccess && result <= 0)
  1271. {
  1272. throw new Exception("库存主表数量增加失败!");
  1273. }
  1274. }
  1275. else
  1276. {
  1277. sql = @"INSERT INTO dbo.ICSWareHouseInfo
  1278. ( WHGUID ,WHCode ,BinGUID ,BinCode ,INVGUID ,
  1279. INVCode ,QTY ,WorkPoint ,MUSER ,MUSERName ,
  1280. MTIME ,EATTRIBUTE1)
  1281. SELECT A.Serial,'{0}',B.Serial,'{1}',C.ID,'{2}',{3},'{4}','{5}','{6}','{7}','' FROM ICSStorage A
  1282. LEFT JOIN ICSStack B
  1283. ON B.Storage_Serial=A.Serial
  1284. LEFT JOIN ICSINVENTORY C
  1285. ON C.WorkPoint=B.WorkPoint
  1286. WHERE A.StorageCode='{0}' AND
  1287. B.StackCode='{1}' AND
  1288. C.INVCODE='{2}'";
  1289. sql = string.Format(sql, NewWHCode, NewBinCode, INVCode, BarCodeQty, workpointCode, userCode, userName, DateTime.Now);
  1290. cmd.CommandText = sql;
  1291. result = cmd.ExecuteNonQuery();
  1292. if (isSuccess && result <= 0)
  1293. {
  1294. throw new Exception("库存主表存入失败!");
  1295. }
  1296. }
  1297. #endregion
  1298. #region 更新ICSWareHouseLotInfo表
  1299. sql = @"update ICSWareHouseLotInfo set
  1300. WHGUID=(select Serial from ICSStorage where StorageCode='{0}'),
  1301. WHCode='{0}',
  1302. BinGUID=(select Serial from ICSStack where StackCode='{1}'),
  1303. BinCode='{1}'
  1304. where LotNO='{2}'";
  1305. sql = string.Format(sql, NewWHCode, NewBinCode, BarCode);
  1306. cmd.CommandText = sql;
  1307. result = cmd.ExecuteNonQuery();
  1308. if (isSuccess && result <= 0)
  1309. {
  1310. throw new Exception("库存子表更新失败!");
  1311. }
  1312. #endregion
  1313. #region 存入ICSWareHouseLotInfoLog表(日志)
  1314. sql = @"insert into ICSWareHouseLotInfoLog
  1315. Values
  1316. (NEWID(),'{0}','{1}','{2}','{3}','{11}','{12}','{4}','{5}'
  1317. ,{6},null,'{7}','','{8}','{9}',GETDATE(),'{10}','','','','','')";
  1318. sql = string.Format(sql, POCode, BarCodeRow, INVCode, BarCode, NewWHCode, NewBinCode, BarCodeQty, Type, userCode, userName, workpointCode, OldWHCode, OldBinCode);
  1319. cmd.CommandText = sql;
  1320. result = cmd.ExecuteNonQuery();
  1321. if (isSuccess && result <= 0)
  1322. {
  1323. throw new Exception("日志存入失败!");
  1324. }
  1325. #endregion
  1326. }
  1327. }
  1328. catch (Exception ex)
  1329. {
  1330. throw new Exception(ex.Message);
  1331. }
  1332. if (message == "Open")
  1333. {
  1334. #region 接口调用
  1335. try
  1336. {
  1337. sql = @"select A.TransferNO
  1338. ,A.ITEMCODE
  1339. ,B.TransQTY
  1340. ,A.EATTRIBUTE1 ,A.EATTRIBUTE2,A.FROMStorageCode,A.TOStorageCode
  1341. ,C.VenderLotNO AS Batch
  1342. ,C.EATTRIBUTE3
  1343. from ICSTransVouchs A
  1344. inner join ICSWareHouseLotInfoLog B
  1345. on B.TransNO=A.TransferNO AND B.TransLine=A.TransferLine
  1346. LEFT JOIN ICSITEMLot C
  1347. ON C.LotNO=B.LotNO
  1348. WHERE B.LotNO IN ({0}) AND B.BusinessCode=''
  1349. AND B.EATTRIBUTE5 = ''";
  1350. sql = string.Format(sql, cBarCode);
  1351. DataTable dt = SQlReturnData(sql, cmd);
  1352. if (dt == null || dt.Rows.Count <= 0)
  1353. return false;
  1354. List<TransVouch> contextlist = new List<TransVouch>();
  1355. TransVouch context = new TransVouch();
  1356. List<TransVouchs> contextlists = new List<TransVouchs>();
  1357. TransVouchs contexts = new TransVouchs();
  1358. context.UserCode = userCode;
  1359. context.ID = dt.Rows[0]["EATTRIBUTE2"].ToString();
  1360. context.cTVCode = dt.Rows[0]["TransferNO"].ToString();
  1361. context.UserCode = userCode;
  1362. for (int i = 0; i < dt.Rows.Count; i++)
  1363. {
  1364. contexts = new TransVouchs();
  1365. contexts.cInvCode = dt.Rows[i]["ITEMCODE"].ToString();
  1366. contexts.iQuantity = Convert.ToDecimal(dt.Rows[i]["TransQTY"].ToString());
  1367. contexts.AutoID = dt.Rows[i]["EATTRIBUTE1"].ToString();
  1368. contexts.cTVBatch = dt.Rows[i]["Batch"].ToString();
  1369. contexts.iNum = Convert.ToDecimal(dt.Rows[i]["TransQTY"].ToString()) * Convert.ToDecimal(dt.Rows[i]["EATTRIBUTE3"].ToString());
  1370. contextlists.Add(contexts);
  1371. }
  1372. context.list = contextlists;
  1373. contextlist.Add(context);
  1374. sql = @"UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE5='已回写'
  1375. where LotNO in ({0}) AND BusinessCode=''
  1376. AND EATTRIBUTE5 = ''";
  1377. sql = string.Format(sql, cBarCode);
  1378. cmd.CommandText = sql;
  1379. result = cmd.ExecuteNonQuery();
  1380. if (isSuccess && result <= 0)
  1381. {
  1382. throw new Exception("日志表更新失败!");
  1383. }
  1384. string Istr = JsonConvert.SerializeObject(contextlist);
  1385. string iresult = HttpPost(IInvTrans, Istr);
  1386. Result INVTransResult = new Result();
  1387. INVTransResult = JsonConvert.DeserializeObject<Result>(iresult);
  1388. if (INVTransResult.code != "200")
  1389. {
  1390. throw new Exception(INVTransResult.msg);
  1391. }
  1392. }
  1393. catch (Exception ex)
  1394. {
  1395. throw new Exception(ex.Message);
  1396. }
  1397. #endregion
  1398. }
  1399. return isSuccess;
  1400. }
  1401. /// <summary>
  1402. /// 验证材料出申请单信息(工单)
  1403. /// </summary>
  1404. /// <param name="VouchCode"></param>
  1405. /// <param name="WorkPointCode"></param>
  1406. /// <param name="dsconn"></param>
  1407. /// <returns></returns>
  1408. public static DataTable CheckVouchCode(string VouchCode, string WorkPointCode, string dsconn)
  1409. {
  1410. string sql = @" SELECT d.MOTYPE,d.REMOITEMDESC,a.MOCODE,
  1411. a.SEQ AS ,
  1412. a.MOBOMLINE AS ,
  1413. a.MOBITEMCODE AS ,
  1414. a.MOBITEMNAME AS ,
  1415. c.INVSTD AS ,
  1416. a.MOBITEMQTY AS ,
  1417. ISNULL(b.HasQuantity, 0) AS
  1418. ,c.INVUOM AS
  1419. FROM ICSMOBOM a
  1420. left join ICSMOPickLog b
  1421. on b.MOCODE=a.MOCODE and b.MOSEQ=a.SEQ And b.SEQ=a.MOBOMLINE AND b.EATTRIBUTE1=''
  1422. left join ICSINVENTORY c
  1423. on c.INVCODE=a.MOBITEMCODE
  1424. left join ICSMO d
  1425. on d.MOCODE=a.MOCODE AND d.MOSEQ=a.SEQ
  1426. where a.WorkPoint = '{0}' AND a.MOCODE='{1}' ORDER BY a.SEQ, a.MOBOMLINE";
  1427. sql = string.Format(sql, WorkPointCode, VouchCode);
  1428. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  1429. return dt;
  1430. }
  1431. /// <summary>
  1432. /// 验证材料出申请单信息(领料单)
  1433. /// </summary>
  1434. /// <param name="VouchCode"></param>
  1435. /// <param name="WorkPointCode"></param>
  1436. /// <param name="dsconn"></param>
  1437. /// <returns></returns>
  1438. public static DataTable CheckMaterialPickCode(string VouchCode, string WorkPointCode, string dsconn)
  1439. {
  1440. string sql = @" SELECT a.VouchCode,
  1441. a.VouchRow AS ,
  1442. a.InvCode AS ,
  1443. b.INVNAME AS ,
  1444. b.INVSTD AS ,
  1445. a.Quantity AS ,
  1446. ISNULL(a.HasQuantity, 0) AS
  1447. ,b.INVUOM AS
  1448. ,c.PickingSTATUS AS
  1449. FROM ICSMaterialPick a
  1450. left join ICSINVENTORY b
  1451. on b.INVCODE=a.InvCode
  1452. left join ICSMaterial c
  1453. on c.VouchCode=a.VouchCode
  1454. where a.WorkPoint = '{0}' AND a.VouchCode='{1}' AND MoveType=''
  1455. Order BY VouchRow";
  1456. sql = string.Format(sql, WorkPointCode, VouchCode);
  1457. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  1458. return dt;
  1459. }
  1460. /// <summary>
  1461. /// 验证材料出申请单信息
  1462. /// </summary>
  1463. /// <param name="VouchCode"></param>
  1464. /// <param name="WorkPointCode"></param>
  1465. /// <param name="dsconn"></param>
  1466. /// <returns></returns>
  1467. public static DataTable CheckVouchCodePick(string VouchCode, string WorkPointCode, string dsconn)
  1468. {
  1469. string sql = @"SELECT a.VouchCode AS MOCODE,
  1470. a.VouchRow AS ,
  1471. a.VouchRow AS ,
  1472. a.SubInvCode AS ,
  1473. c.INVNAME AS ,
  1474. c.INVSTD AS ,
  1475. a.Quantity AS ,
  1476. ISNULL(a.HasQuantity, 0) AS
  1477. ,c.INVUOM AS
  1478. FROM
  1479. ICSMaterialPick a
  1480. left join ICSINVENTORY c
  1481. on c.INVCODE=a.SubInvCode
  1482. where a.WorkPoint = '{0}' AND a.VouchCode='{1}' AND a.MoveType='' ORDER BY a.VouchRow";
  1483. sql = string.Format(sql, WorkPointCode, VouchCode);
  1484. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  1485. return dt;
  1486. }
  1487. /// <summary>
  1488. /// 获取销售出库单信息
  1489. /// </summary>
  1490. /// <param name="SOCode"></param>
  1491. /// <param name="WrokPointCode"></param>
  1492. /// <param name="dsconn"></param>
  1493. /// <returns></returns>
  1494. public static DataTable CheckSOCode(string SOCode, string WorkPointCode, string dsconn)
  1495. {
  1496. string sql = @"select DispatchRow
  1497. ,A.InvCode
  1498. ,INVNAME
  1499. ,INVSTD
  1500. ,ISNULL(Quantity,0) AS Quantity
  1501. ,ISNULL(HasQuantity,0) AS HasQuantity
  1502. ,INVUOM
  1503. ,WHCode
  1504. ,A.cBatch
  1505. from ICSSODispatch A
  1506. LEFT JOIN ICSINVENTORY B
  1507. ON B.INVCODE=A.InvCode
  1508. where DispatchCode='{0}' AND A.WorkPoint='{1}'
  1509. AND Type=''
  1510. ORDER BY DispatchRow";
  1511. sql = string.Format(sql, SOCode, WorkPointCode);
  1512. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  1513. return dt;
  1514. }
  1515. /// <summary>
  1516. /// 获取销售退库单信息
  1517. /// </summary>
  1518. /// <param name="SOCode"></param>
  1519. /// <param name="WorkPointCode"></param>
  1520. /// <param name="dsconn"></param>
  1521. /// <returns></returns>
  1522. public static DataTable CheckSOCodeForReturn(string SOCode, string WorkPointCode, string dsconn)
  1523. {
  1524. string sql = @"select DispatchRow
  1525. ,A.InvCode
  1526. ,INVNAME
  1527. ,INVSTD
  1528. ,ISNULL(Quantity,0) AS Quantity
  1529. ,ISNULL(HasQuantity,0) AS HasQuantity
  1530. ,INVUOM
  1531. ,WHCode
  1532. ,A.cBatch
  1533. from ICSSODispatch A
  1534. LEFT JOIN ICSINVENTORY B
  1535. ON B.INVCODE=A.InvCode
  1536. where DispatchCode='{0}' AND A.WorkPoint='{1}'
  1537. AND Type='退' AND A.Class=''
  1538. ORDER BY DispatchRow";
  1539. sql = string.Format(sql, SOCode, WorkPointCode);
  1540. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  1541. return dt;
  1542. }
  1543. /// <summary>
  1544. /// 材料出库(领料单)
  1545. /// </summary>
  1546. /// <param name="POCode"></param>
  1547. /// <param name="porowList"></param>
  1548. /// <param name="poqtyList"></param>
  1549. /// <param name="barcodeList"></param>
  1550. /// <param name="barcodeqtyList"></param>
  1551. /// <param name="bincodeList"></param>
  1552. /// <param name="userCodt"></param>
  1553. /// <param name="workpointCode"></param>
  1554. /// <param name="Type"></param>
  1555. /// <param name="dsconn"></param>
  1556. /// <returns></returns>
  1557. public static bool WareHouseMterialOut(SqlConnection sqlConnection, SqlTransaction trans, string POCode, string[] porowList, string[] poqtyList, string[] barcodeRowList, string[] barcodeList, string[] barcodeqtyList, string SubmitUserName, string userCode, string userName, string workpointCode, string Type, string dsconn)
  1558. {
  1559. string sql = "";
  1560. string BarCode = "";
  1561. decimal BarCodeQty = 0;
  1562. string BarCodeRow = "";
  1563. string Errormessage = "";
  1564. string POMainRow = "";
  1565. string PORow = "";
  1566. decimal POQty = 0;
  1567. string NewBinCode = "";
  1568. string ConnectString = dsconn;
  1569. int result = 0;
  1570. bool isSuccess = true;
  1571. SqlCommand cmd = new SqlCommand();
  1572. cmd.Connection = sqlConnection;
  1573. cmd.Transaction = trans;
  1574. try
  1575. {
  1576. for (int i = 0; i < porowList.Length; i++)
  1577. {
  1578. #region 更新ICSMaterialPick表已领数量
  1579. PORow = porowList[i];
  1580. POQty = Convert.ToDecimal(poqtyList[i]);
  1581. sql = @"Update ICSMaterialPick set HasQuantity=HasQuantity+{0}
  1582. where VouchCode='{1}' AND VouchRow='{2}' AND WorkPoint='{3}' AND MoveType=''";
  1583. sql = string.Format(sql, POQty, POCode, PORow, workpointCode);
  1584. cmd.CommandText = sql;
  1585. result = cmd.ExecuteNonQuery();
  1586. if (isSuccess && result <= 0)
  1587. {
  1588. throw new Exception("领料单表更新失败!");
  1589. }
  1590. #endregion
  1591. }
  1592. for (int i = 0; i < barcodeList.Length; i++)
  1593. {
  1594. BarCode = barcodeList[i];
  1595. BarCodeQty = Convert.ToDecimal(barcodeqtyList[i]);
  1596. BarCodeRow = barcodeRowList[i];
  1597. string INVCode = "";
  1598. string WHCode = "";
  1599. string BinCode = "";
  1600. string TranNo = "";
  1601. string TranLine = "";
  1602. #region 获取仓库库位等信息
  1603. sql = @"select WHCode
  1604. ,BinCode
  1605. ,INVCode
  1606. ,B.TransNO
  1607. ,B.TransLine
  1608. from ICSWareHouseLotInfo A
  1609. left join ICSITEMLot B
  1610. on B.LotNO=A.LotNO
  1611. where A.LotNO='{0}' AND A.WorkPoint='{1}'";
  1612. sql = string.Format(sql, BarCode, workpointCode);
  1613. DataTable dt = SQlReturnData(sql, cmd);
  1614. if (dt.Rows.Count == 0)
  1615. {
  1616. throw new Exception("获取仓库信息失败!");
  1617. }
  1618. else
  1619. {
  1620. INVCode = dt.Rows[0]["INVCode"].ToString();
  1621. BinCode = dt.Rows[0]["BinCode"].ToString();
  1622. WHCode = dt.Rows[0]["WHCode"].ToString();
  1623. TranNo = dt.Rows[0]["TransNO"].ToString();
  1624. TranLine = dt.Rows[0]["TransLine"].ToString();
  1625. }
  1626. #endregion
  1627. #region 更新ICSWareHouseInfo表
  1628. sql = @"update ICSWareHouseInfo
  1629. set QTY=QTY-{0},MTIME='{1}'
  1630. where INVCode='{2}' AND WHCode='{3}' AND BinCode='{4}'";
  1631. sql = string.Format(sql, BarCodeQty, DateTime.Now, INVCode, WHCode, BinCode);
  1632. cmd.CommandText = sql;
  1633. result = cmd.ExecuteNonQuery();
  1634. if (isSuccess && result <= 0)
  1635. {
  1636. throw new Exception("库存主表更新失败!");
  1637. }
  1638. #endregion
  1639. #region 更新ICSWareHouseLotInfo表
  1640. sql = @"update ICSWareHouseLotInfo
  1641. set LotQty=LotQty-{0}
  1642. where LotNO='{1}'
  1643. and WorkPoint='{2}'";
  1644. sql = string.Format(sql, BarCodeQty, BarCode, workpointCode);
  1645. cmd.CommandText = sql;
  1646. result = cmd.ExecuteNonQuery();
  1647. if (isSuccess && result <= 0)
  1648. {
  1649. throw new Exception("库存子表更新失败!");
  1650. }
  1651. #endregion
  1652. #region 存入ICSWareHouseLotInfoLog表(日志)
  1653. sql = @"insert into ICSWareHouseLotInfoLog
  1654. Values
  1655. (NEWID(),'{0}','{1}','{2}','{3}','{9}','{10}','',''
  1656. ,{4},null,'{5}','','{6}','{7}',GETDATE(),'{8}','','','','','')";
  1657. sql = string.Format(sql, POCode, BarCodeRow, INVCode, BarCode, BarCodeQty, Type, userCode, userName, workpointCode, WHCode, BinCode);
  1658. cmd.CommandText = sql;
  1659. result = cmd.ExecuteNonQuery();
  1660. if (isSuccess && result <= 0)
  1661. {
  1662. throw new Exception("日志表存入失败!");
  1663. }
  1664. #endregion
  1665. }
  1666. }
  1667. catch (Exception ex)
  1668. {
  1669. throw new Exception(ex.Message);
  1670. }
  1671. if (message == "Open")
  1672. {
  1673. #region 接口调用
  1674. try
  1675. {
  1676. string IBarCodeList = "";
  1677. for (int i = 0; i < barcodeList.Length; i++)
  1678. {
  1679. if (IBarCodeList == "")
  1680. {
  1681. IBarCodeList += "'" + barcodeList[i] + "'";
  1682. }
  1683. else
  1684. {
  1685. IBarCodeList += ",'" + barcodeList[i] + "'";
  1686. }
  1687. }
  1688. sql = @"select C.FRMStorageCODE
  1689. ,A.OutCategory
  1690. ,C.ITEMCODE
  1691. ,D.VenderLotNO
  1692. ,C.TransQTY
  1693. ,D.EATTRIBUTE3
  1694. ,B.Dept
  1695. ,B.RDCode,a.MEMO
  1696. ,A.VENDORCODE,A.VouchCode
  1697. from ICSMaterial A
  1698. LEFT JOIN ICSMaterialPick B
  1699. ON B.VouchCode=A.VouchCode
  1700. LEFT JOIN ICSWareHouseLotInfoLog C
  1701. ON C.TransNO=B.VouchCode AND C.TransLine=B.VouchRow
  1702. LEFT JOIN ICSITEMLot D
  1703. ON D.LotNO=C.LotNO
  1704. WHERE C.LotNO IN ({0}) AND C.WorkPoint='{1}' AND C.BusinessCode=''
  1705. AND C.EATTRIBUTE5=''";
  1706. sql = string.Format(sql, IBarCodeList, workpointCode);
  1707. DataTable dt = SQlReturnData(sql, cmd);
  1708. List<ICSSoft.Entity.mom_orderdetail.mom_orderdetail> contextlist = new List<ICSSoft.Entity.mom_orderdetail.mom_orderdetail>();
  1709. ICSSoft.Entity.mom_orderdetail.mom_orderdetail context = new ICSSoft.Entity.mom_orderdetail.mom_orderdetail();
  1710. List<mom_moallocate> contextlists = new List<mom_moallocate>();
  1711. mom_moallocate contexts = new mom_moallocate();
  1712. List<root> rootlist = new List<root>();
  1713. root rootinfo = new root();
  1714. string WareHouse = "";
  1715. string Dept = "";
  1716. decimal AssQTY = 0;
  1717. for (int i = 0; i < dt.Rows.Count; i++)
  1718. {
  1719. AssQTY = Convert.ToDecimal(dt.Rows[i]["TransQTY"]) * Convert.ToDecimal(dt.Rows[i]["EATTRIBUTE3"]);
  1720. if (WareHouse != dt.Rows[i]["FRMStorageCODE"].ToString()
  1721. || Dept != dt.Rows[i]["Dept"].ToString())
  1722. {
  1723. if (i > 0)
  1724. {
  1725. context.list = contextlists;
  1726. contextlist.Add(context);
  1727. }
  1728. context = new ICSSoft.Entity.mom_orderdetail.mom_orderdetail();
  1729. WareHouse = dt.Rows[i]["FRMStorageCODE"].ToString();
  1730. Dept = dt.Rows[i]["Dept"].ToString();
  1731. context.UserCode = userCode;
  1732. context.cWhCode = dt.Rows[i]["FRMStorageCODE"].ToString();
  1733. context.IsReturn = "0";
  1734. context.cRdCode = dt.Rows[i]["OutCategory"].ToString();
  1735. context.cBatch = dt.Rows[i]["Dept"].ToString();
  1736. context.cDefine1 = dt.Rows[i]["RDCode"].ToString();
  1737. context.cDefine2 = SubmitUserName;
  1738. context.cDefine9 = dt.Rows[i]["VENDORCODE"].ToString();
  1739. context.cDefine10 = dt.Rows[i]["VouchCode"].ToString();
  1740. context.MEMO = dt.Rows[i]["MEMO"].ToString();
  1741. contextlists = new List<mom_moallocate>();
  1742. }
  1743. contexts = new mom_moallocate();
  1744. contexts.cInvCode = dt.Rows[i]["ITEMCODE"].ToString();
  1745. contexts.iQuantity = Convert.ToDecimal(dt.Rows[i]["TransQTY"].ToString());
  1746. contexts.cBatch = dt.Rows[i]["VenderLotNO"].ToString();
  1747. contexts.iNum = AssQTY;
  1748. contextlists.Add(contexts);
  1749. if (i == dt.Rows.Count - 1)
  1750. {
  1751. context.list = contextlists;
  1752. contextlist.Add(context);
  1753. }
  1754. }
  1755. rootinfo.NoSourceBills = contextlist;
  1756. rootlist.Add(rootinfo);
  1757. sql = @"UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE5='已回写'
  1758. where LotNO in ({0}) AND BusinessCode=''
  1759. UPDATE ICSMaterial SET EATTRIBUTE1='{1}'
  1760. WHERE VouchCode='{2}' AND WorkPoint='{3}'";
  1761. sql = string.Format(sql, IBarCodeList, SubmitUserName, POCode, workpointCode);
  1762. cmd.CommandText = sql;
  1763. result = cmd.ExecuteNonQuery();
  1764. if (isSuccess && result <= 0)
  1765. {
  1766. throw new Exception("日志表更新失败!");
  1767. }
  1768. //Root root = new Root();
  1769. //root.Bills = contextlist;
  1770. //root.RedBills = null;
  1771. //string Istr = JsonConvert.SerializeObject(root);
  1772. string Istr = JsonConvert.SerializeObject(rootinfo);
  1773. string iresult = HttpPost(IInvOut, Istr);
  1774. Result INVOUTResult = new Result();
  1775. INVOUTResult = JsonConvert.DeserializeObject<Result>(iresult);
  1776. if (INVOUTResult.code != "200")
  1777. {
  1778. throw new Exception(INVOUTResult.msg);
  1779. }
  1780. }
  1781. catch (Exception ex)
  1782. {
  1783. throw new Exception(ex.Message);
  1784. }
  1785. #endregion
  1786. }
  1787. return isSuccess;
  1788. }
  1789. /// <summary>
  1790. /// 材料出库(工单)
  1791. /// </summary>
  1792. /// <param name="sqlConnection"></param>
  1793. /// <param name="trans"></param>
  1794. /// <param name="POCode"></param>
  1795. /// <param name="pomainrowlist"></param>
  1796. /// <param name="porowList"></param>
  1797. /// <param name="poqtyList"></param>
  1798. /// <param name="barcodeRowList"></param>
  1799. /// <param name="barcodeList"></param>
  1800. /// <param name="barcodeqtyList"></param>
  1801. /// <param name="rateList"></param>
  1802. /// <param name="userCode"></param>
  1803. /// <param name="userName"></param>
  1804. /// <param name="workpointCode"></param>
  1805. /// <param name="Type"></param>
  1806. /// <param name="dsconn"></param>
  1807. /// <returns></returns>
  1808. public static bool WareHouseMOMterialOut(SqlConnection sqlConnection, SqlTransaction trans, string POCode, string[] pomainrowlist, string[] porowList, string[] poqtyList, string[] barcodeRowList, string[] barcodeList, string[] barcodeqtyList, string userCode, string userName, string workpointCode, string Type, string dsconn)
  1809. {
  1810. string sql = "";
  1811. string BarCode = "";
  1812. decimal BarCodeQty = 0;
  1813. string BarCodeRow = "";
  1814. string Errormessage = "";
  1815. string POMainRow = "";
  1816. string PORow = "";
  1817. decimal POQty = 0;
  1818. string NewBinCode = "";
  1819. string ConnectString = dsconn;
  1820. int result = 0;
  1821. bool isSuccess = true;
  1822. SqlCommand cmd = new SqlCommand();
  1823. cmd.Connection = sqlConnection;
  1824. cmd.Transaction = trans;
  1825. try
  1826. {
  1827. for (int i = 0; i < porowList.Length; i++)
  1828. {
  1829. #region 更新ICSMOPickLog表
  1830. POMainRow = pomainrowlist[i];
  1831. PORow = porowList[i];
  1832. POQty = Convert.ToDecimal(poqtyList[i]);
  1833. sql = @"select * from ICSMOPickLog
  1834. where MOCODE='{0}' AND SEQ='{3}' AND MOSEQ='{1}' AND WorkPoint='{2}' AND EATTRIBUTE1=''";
  1835. sql = string.Format(sql, POCode, POMainRow, workpointCode, PORow);
  1836. DataTable dt = SQlReturnData(sql, cmd);
  1837. if (dt.Rows.Count != 0)
  1838. {
  1839. sql = @"update ICSMOPickLog
  1840. set HasQuantity=ISNULL(HasQuantity,0)+{0}
  1841. where MOCODE='{4}' AND MOSEQ='{1}' AND SEQ='{2}'
  1842. and WorkPoint='{3}' AND EATTRIBUTE1=''";
  1843. sql = string.Format(sql, POQty, POMainRow, PORow, workpointCode, POCode);
  1844. }
  1845. else
  1846. {
  1847. sql = @"Insert into ICSMOPickLog
  1848. VALUES
  1849. ('{0}',(select ITEMCODE from ICSMOBOM where MOCODE='{0}' AND SEQ='{1}' AND MOBOMLINE='{5}')
  1850. ,'{5}',(select MOBITEMCODE from ICSMOBOM where MOCODE='{0}' AND SEQ='{1}' AND MOBOMLINE='{5}')
  1851. ,'{1}',{2},'','{3}',GETDATE(),'{4}')";
  1852. sql = string.Format(sql, POCode, POMainRow, POQty, userCode, workpointCode, PORow);
  1853. }
  1854. cmd.CommandText = sql;
  1855. result = cmd.ExecuteNonQuery();
  1856. if (isSuccess && result <= 0)
  1857. {
  1858. throw new Exception("领料单表更新失败!");
  1859. }
  1860. #endregion
  1861. }
  1862. for (int i = 0; i < barcodeList.Length; i++)
  1863. {
  1864. BarCode = barcodeList[i];
  1865. BarCodeQty = Convert.ToDecimal(barcodeqtyList[i]);
  1866. BarCodeRow = barcodeRowList[i];
  1867. string INVCode = "";
  1868. string WHCode = "";
  1869. string BinCode = "";
  1870. string TranNo = "";
  1871. string TranLine = "";
  1872. #region 获取仓库库位等信息
  1873. sql = @"select WHCode
  1874. ,BinCode
  1875. ,INVCode
  1876. ,B.TransNO
  1877. ,B.TransLine
  1878. from ICSWareHouseLotInfo A
  1879. left join ICSITEMLot B
  1880. on B.LotNO=A.LotNO
  1881. where A.LotNO='{0}' AND A.WorkPoint='{1}'";
  1882. sql = string.Format(sql, BarCode, workpointCode);
  1883. DataTable dt = SQlReturnData(sql, cmd);
  1884. if (dt.Rows.Count == 0)
  1885. {
  1886. throw new Exception("获取仓库信息失败!");
  1887. }
  1888. else
  1889. {
  1890. INVCode = dt.Rows[0]["INVCode"].ToString();
  1891. BinCode = dt.Rows[0]["BinCode"].ToString();
  1892. WHCode = dt.Rows[0]["WHCode"].ToString();
  1893. TranNo = dt.Rows[0]["TransNO"].ToString();
  1894. TranLine = dt.Rows[0]["TransLine"].ToString();
  1895. }
  1896. #endregion
  1897. #region 更新ICSWareHouseInfo表
  1898. sql = @"update ICSWareHouseInfo
  1899. set QTY=QTY-{0},MTIME='{1}'
  1900. where INVCode='{2}' AND WHCode='{3}' AND BinCode='{4}'";
  1901. sql = string.Format(sql, BarCodeQty, DateTime.Now, INVCode, WHCode, BinCode);
  1902. cmd.CommandText = sql;
  1903. result = cmd.ExecuteNonQuery();
  1904. if (isSuccess && result <= 0)
  1905. {
  1906. throw new Exception("库存主表更新失败!");
  1907. }
  1908. #endregion
  1909. #region 更新ICSWareHouseLotInfo表
  1910. sql = @"update ICSWareHouseLotInfo
  1911. set LotQty=LotQty-{0}
  1912. where LotNO='{1}'
  1913. and WorkPoint='{2}'";
  1914. sql = string.Format(sql, BarCodeQty, BarCode, workpointCode);
  1915. cmd.CommandText = sql;
  1916. result = cmd.ExecuteNonQuery();
  1917. if (isSuccess && result <= 0)
  1918. {
  1919. throw new Exception("库存子表更新失败!");
  1920. }
  1921. #endregion
  1922. #region 存入ICSWareHouseLotInfoLog表(日志)
  1923. sql = @"insert into ICSWareHouseLotInfoLog
  1924. Values
  1925. (NEWID(),'{0}','{1}','{2}','{3}','{9}','{10}','',''
  1926. ,{4},null,'{5}','','{6}','{7}',GETDATE(),'{8}','','','','','')";
  1927. sql = string.Format(sql, POCode, BarCodeRow, INVCode, BarCode, BarCodeQty, Type, userCode, userName, workpointCode, WHCode, BinCode);
  1928. cmd.CommandText = sql;
  1929. result = cmd.ExecuteNonQuery();
  1930. if (isSuccess && result <= 0)
  1931. {
  1932. throw new Exception("日志表存入失败!");
  1933. }
  1934. #endregion
  1935. }
  1936. }
  1937. catch (Exception ex)
  1938. {
  1939. throw new Exception(ex.Message);
  1940. }
  1941. if (message == "Open")
  1942. {
  1943. #region 接口调用
  1944. try
  1945. {
  1946. string IBarCodeList = "";
  1947. for (int i = 0; i < barcodeList.Length; i++)
  1948. {
  1949. if (IBarCodeList == "")
  1950. {
  1951. IBarCodeList += "'" + barcodeList[i] + "'";
  1952. }
  1953. else
  1954. {
  1955. IBarCodeList += ",'" + barcodeList[i] + "'";
  1956. }
  1957. }
  1958. sql = @"select A.MOCODE,A.MOSEQ,A.ITEMCODE,A.EATTRIBUTE1
  1959. ,B.MOBITEMECN,B.MOBITEMCODE AS BOMITEMCODE,B.MOBOMLINE
  1960. ,C.FRMStorageCODE,C.TransQTY,D.VenderLotNO,D.EATTRIBUTE3
  1961. ,A.MOVER
  1962. from ICSMO A
  1963. INNER JOIN ICSMOBOM B
  1964. ON B.MOCODE=A.MOCODE AND B.SEQ=A.MOSEQ
  1965. INNER JOIN ICSWareHouseLotInfoLog C
  1966. ON C.TransNO=A.MOCODE AND C.TransLine=A.MOSEQ AND B.MOBITEMCODE=C.ITEMCODE AND C.BusinessCode=''
  1967. INNER JOIN ICSITEMLot D
  1968. ON D.LotNO=C.LotNO
  1969. WHERE A.MOCODE='{0}'
  1970. AND C.EATTRIBUTE5 = ''
  1971. ORDER BY MOSEQ,ITEMCODE,FRMStorageCODE,VenderLotNO";
  1972. sql = string.Format(sql, POCode);
  1973. DataTable dt = SQlReturnData(sql, cmd);
  1974. List<ICSSoft.Entity.mom_orderdetail.mom_orderdetail> contextlist = new List<ICSSoft.Entity.mom_orderdetail.mom_orderdetail>();
  1975. ICSSoft.Entity.mom_orderdetail.mom_orderdetail context = new ICSSoft.Entity.mom_orderdetail.mom_orderdetail();
  1976. List<mom_moallocate> contextlists = new List<mom_moallocate>();
  1977. mom_moallocate contexts = new mom_moallocate();
  1978. List<root> rootlist = new List<root>();
  1979. root rootinfo = new root();
  1980. string WareHouse = "";
  1981. string SEQ = "";
  1982. string ITEMCODE = "";
  1983. decimal AssQTY = 0;
  1984. for (int i = 0; i < dt.Rows.Count; i++)
  1985. {
  1986. AssQTY = Convert.ToDecimal(dt.Rows[i]["EATTRIBUTE3"]) * Convert.ToDecimal(dt.Rows[i]["TransQTY"]);
  1987. if (WareHouse != dt.Rows[i]["FRMStorageCODE"].ToString()
  1988. || SEQ != dt.Rows[i]["MOSEQ"].ToString()
  1989. || ITEMCODE != dt.Rows[i]["ITEMCODE"].ToString())
  1990. {
  1991. if (i > 0)
  1992. {
  1993. context.list = contextlists;
  1994. contextlist.Add(context);
  1995. }
  1996. context = new ICSSoft.Entity.mom_orderdetail.mom_orderdetail();
  1997. WareHouse = dt.Rows[i]["FRMStorageCODE"].ToString();
  1998. SEQ = dt.Rows[i]["MOSEQ"].ToString();
  1999. ITEMCODE = dt.Rows[i]["ITEMCODE"].ToString();
  2000. context.MoDId = dt.Rows[i]["EATTRIBUTE1"].ToString();
  2001. context.UserCode = userCode;
  2002. context.cWhCode = dt.Rows[i]["FRMStorageCODE"].ToString();
  2003. context.IsReturn = "0";
  2004. context.MoCode = POCode;
  2005. context.SortSeq = dt.Rows[i]["MOSEQ"].ToString();
  2006. contextlists = new List<mom_moallocate>();
  2007. }
  2008. contexts = new mom_moallocate();
  2009. contexts.AllocateId = dt.Rows[i]["MOBITEMECN"].ToString();
  2010. contexts.cInvCode = dt.Rows[i]["BOMITEMCODE"].ToString();
  2011. contexts.iQuantity = Convert.ToDecimal(dt.Rows[i]["TransQTY"].ToString());
  2012. contexts.cBatch = dt.Rows[i]["VenderLotNO"].ToString();
  2013. contexts.iNum = AssQTY;
  2014. contexts.MoLotCode = dt.Rows[i]["MOVER"].ToString();
  2015. contextlists.Add(contexts);
  2016. if (i == dt.Rows.Count - 1)
  2017. {
  2018. context.list = contextlists;
  2019. contextlist.Add(context);
  2020. }
  2021. }
  2022. rootinfo.Bills = contextlist;
  2023. rootlist.Add(rootinfo);
  2024. sql = @"UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE5='已回写'
  2025. where LotNO in ({0}) AND BusinessCode=''";
  2026. sql = string.Format(sql, IBarCodeList);
  2027. cmd.CommandText = sql;
  2028. result = cmd.ExecuteNonQuery();
  2029. if (isSuccess && result <= 0)
  2030. {
  2031. throw new Exception("日志表更新失败!");
  2032. }
  2033. //Root root = new Root();
  2034. //root.Bills = contextlist;
  2035. //root.RedBills = null;
  2036. //string Istr = JsonConvert.SerializeObject(root);
  2037. string Istr = JsonConvert.SerializeObject(rootinfo);
  2038. string iresult = HttpPost(IInvOut, Istr);
  2039. Result INVOUTResult = new Result();
  2040. INVOUTResult = JsonConvert.DeserializeObject<Result>(iresult);
  2041. if (INVOUTResult.code != "200")
  2042. {
  2043. throw new Exception(INVOUTResult.msg);
  2044. }
  2045. }
  2046. catch (Exception ex)
  2047. {
  2048. throw new Exception(ex.Message);
  2049. }
  2050. #endregion
  2051. }
  2052. return isSuccess;
  2053. }
  2054. /// <summary>
  2055. /// 销售出库
  2056. /// </summary>
  2057. /// <param name="sqlConnection"></param>
  2058. /// <param name="trans"></param>
  2059. /// <param name="POCode"></param>
  2060. /// <param name="porowList"></param>
  2061. /// <param name="poqtyList"></param>
  2062. /// <param name="barcodeList"></param>
  2063. /// <param name="barcodeqtyList"></param>
  2064. /// <param name="userCode"></param>
  2065. /// <param name="workpointCode"></param>
  2066. /// <param name="Type"></param>
  2067. /// <param name="dsconn"></param>
  2068. /// <returns></returns>
  2069. public static bool WareHouseDisPatchOut(SqlConnection sqlConnection, SqlTransaction trans, string POCode, string[] porowList, string[] poqtyList, string[] barcoderowList, string[] barcodeList, string[] barcodeqtyList, string userCode, string userName, string workpointCode, string Type, string dsconn)
  2070. {
  2071. string sql = "";
  2072. string BarCode = "";
  2073. decimal BarCodeQty = 0;
  2074. string BarCodeRow = "";
  2075. string Errormessage = "";
  2076. string PORow = "";
  2077. decimal POQty = 0;
  2078. string NewBinCode = "";
  2079. string IBarCodeList = "";
  2080. string cBarCode = "";
  2081. string ConnectString = dsconn;
  2082. int result = 0;
  2083. bool isSuccess = true;
  2084. SqlCommand cmd = new SqlCommand();
  2085. cmd.Connection = sqlConnection;
  2086. cmd.Transaction = trans;
  2087. try
  2088. {
  2089. for (int i = 0; i < porowList.Length; i++)
  2090. {
  2091. #region 更新ICSSODispatch表
  2092. PORow = porowList[i];
  2093. POQty = Convert.ToDecimal(poqtyList[i]);
  2094. sql = @"update ICSSODispatch
  2095. set HasQuantity=ISNULL(HasQuantity,0)+{0}
  2096. where DispatchCode='{1}' AND DispatchRow='{2}' AND WorkPoint='{3}'";
  2097. sql = string.Format(sql, POQty, POCode, PORow, workpointCode);
  2098. cmd.CommandText = sql;
  2099. result = cmd.ExecuteNonQuery();
  2100. if (isSuccess && result <= 0)
  2101. {
  2102. throw new Exception("销售订单已发数量更新失败!");
  2103. }
  2104. #endregion
  2105. }
  2106. for (int i = 0; i < barcodeList.Length; i++)
  2107. {
  2108. if (IBarCodeList == "")
  2109. {
  2110. IBarCodeList += "'" + barcodeList[i] + "'";
  2111. }
  2112. else
  2113. {
  2114. IBarCodeList += ",'" + barcodeList[i] + "'";
  2115. }
  2116. BarCode = barcodeList[i];
  2117. BarCodeQty = Convert.ToDecimal(barcodeqtyList[i]);
  2118. BarCodeRow = barcoderowList[i];
  2119. if (cBarCode == "")
  2120. {
  2121. cBarCode += "'" + barcodeList[i] + "'";
  2122. }
  2123. else
  2124. {
  2125. cBarCode += ",'" + barcodeList[i] + "'";
  2126. }
  2127. string INVCode = "";
  2128. string WHCode = "";
  2129. string BinCode = "";
  2130. string TranNo = "";
  2131. string TranLine = "";
  2132. #region 获取仓库库位等信息
  2133. sql = @"select WHCode
  2134. ,BinCode
  2135. ,INVCode
  2136. ,B.TransNO
  2137. ,B.TransLine
  2138. from ICSWareHouseLotInfo A
  2139. left join ICSITEMLot B
  2140. on B.LotNO=A.LotNO
  2141. where A.LotNO='{0}' AND A.WorkPoint='{1}'";
  2142. sql = string.Format(sql, BarCode, workpointCode);
  2143. DataTable dt = SQlReturnData(sql, cmd);
  2144. if (dt.Rows.Count == 0)
  2145. {
  2146. throw new Exception("获取仓库信息失败!");
  2147. }
  2148. else
  2149. {
  2150. INVCode = dt.Rows[0]["INVCode"].ToString();
  2151. BinCode = dt.Rows[0]["BinCode"].ToString();
  2152. WHCode = dt.Rows[0]["WHCode"].ToString();
  2153. TranNo = dt.Rows[0]["TransNO"].ToString();
  2154. TranLine = dt.Rows[0]["TransLine"].ToString();
  2155. }
  2156. #endregion
  2157. #region 更新ICSWareHouseInfo表
  2158. sql = @"update ICSWareHouseInfo
  2159. set QTY=QTY-{0},MTIME='{1}'
  2160. where INVCode='{2}' AND WHCode='{3}' AND BinCode='{4}'";
  2161. sql = string.Format(sql, BarCodeQty, DateTime.Now, INVCode, WHCode, BinCode);
  2162. cmd.CommandText = sql;
  2163. result = cmd.ExecuteNonQuery();
  2164. if (isSuccess && result <= 0)
  2165. {
  2166. throw new Exception("库存主表数量扣减失败!");
  2167. }
  2168. #endregion
  2169. #region 更新ICSWareHouseLotInfo表
  2170. sql = @"update ICSWareHouseLotInfo
  2171. set LotQty=LotQty-{0}
  2172. where LotNO='{1}'
  2173. and WorkPoint='{2}'";
  2174. sql = string.Format(sql, BarCodeQty, BarCode, workpointCode);
  2175. cmd.CommandText = sql;
  2176. result = cmd.ExecuteNonQuery();
  2177. if (isSuccess && result <= 0)
  2178. {
  2179. throw new Exception("库存子表数量扣减失败!");
  2180. }
  2181. #endregion
  2182. #region 存入ICSWareHouseLotInfoLog表(日志)
  2183. sql = @"insert into ICSWareHouseLotInfoLog
  2184. Values
  2185. (NEWID(),'{0}','{1}','{2}','{3}','{9}','{10}','',''
  2186. ,{4},null,'{5}','','{6}','{7}',GETDATE(),'{8}','','','','','')";
  2187. sql = string.Format(sql, POCode, BarCodeRow, INVCode, BarCode, BarCodeQty, Type, userCode, userName, workpointCode, WHCode, BinCode);
  2188. cmd.CommandText = sql;
  2189. result = cmd.ExecuteNonQuery();
  2190. if (isSuccess && result <= 0)
  2191. {
  2192. throw new Exception("日志表存入失败!");
  2193. }
  2194. #endregion
  2195. }
  2196. }
  2197. catch (Exception ex)
  2198. {
  2199. throw new Exception(ex.Message);
  2200. }
  2201. if (message == "Open")
  2202. {
  2203. #region 接口调用
  2204. try
  2205. {
  2206. sql = @"select A.Term1
  2207. ,A.DispatchCode
  2208. ,B.FRMStorageCODE
  2209. ,A.Term2
  2210. ,B.TransQTY
  2211. ,C.VenderLotNO AS Batch
  2212. ,C.ItemCode
  2213. ,C.EATTRIBUTE3
  2214. ,case when (c.EATTRIBUTE6 like '02%' or c.EATTRIBUTE6 like 'qichu%')
  2215. then c.VoucherNO else arr.cDefine22 end cBatchProperty7 ----cBatchProperty7
  2216. ,case when (c.EATTRIBUTE6 like '02%' or c.EATTRIBUTE6 like 'qichu%')
  2217. then c.TwoMUSER else arr.cBatchProperty6 end cBatchProperty6 ------cBatchProperty6
  2218. from ICSSODispatch A
  2219. INNER JOIN ICSWareHouseLotInfoLog B
  2220. ON B.TransNO=A.DispatchCode AND B.TransLine=A.DispatchRow
  2221. AND B.BusinessCode='' AND B.EATTRIBUTE5=''
  2222. INNER JOIN ICSITEMLot C
  2223. ON C.LotNO=B.LotNO
  2224. left join ICSITEMLot item on item.LotNO=c.EATTRIBUTE6
  2225. left join ICSPOArrive arr on arr.cCode=item.TransNO and arr.irowno=item.TransLine
  2226. WHERE B.LotNO IN ({0}) AND A.DispatchCode='{1}'";
  2227. sql = string.Format(sql, cBarCode, POCode);
  2228. DataTable dt = SQlReturnData(sql, cmd);
  2229. List<Dispatchlist> contextlist = new List<Dispatchlist>();
  2230. Dispatchlist context = new Dispatchlist();
  2231. List<Dispatchlists> contextlists = new List<Dispatchlists>();
  2232. Dispatchlists contexts = new Dispatchlists();
  2233. string SOCode = "";
  2234. string WareHouse = "";
  2235. decimal AssQTY = 0;
  2236. for (int i = 0; i < dt.Rows.Count; i++)
  2237. {
  2238. AssQTY = Convert.ToDecimal(dt.Rows[i]["EATTRIBUTE3"]) * Convert.ToDecimal(dt.Rows[i]["TransQTY"]);
  2239. if (SOCode != dt.Rows[i]["DispatchCode"].ToString()
  2240. || WareHouse != dt.Rows[i]["FRMStorageCODE"].ToString())
  2241. {
  2242. if (i > 0)
  2243. {
  2244. context.list = contextlists;
  2245. contextlist.Add(context);
  2246. }
  2247. context = new Dispatchlist();
  2248. SOCode = dt.Rows[i]["DispatchCode"].ToString();
  2249. WareHouse = dt.Rows[i]["FRMStorageCODE"].ToString();
  2250. context.DLID = dt.Rows[i]["Term1"].ToString();
  2251. context.cDLCode = dt.Rows[i]["DispatchCode"].ToString();
  2252. context.cWhCode = dt.Rows[i]["FRMStorageCODE"].ToString();
  2253. context.UserCode = userCode;
  2254. context.IsReturn = "0";
  2255. contextlists = new List<Dispatchlists>();
  2256. }
  2257. contexts = new Dispatchlists();
  2258. contexts.iDLsID = dt.Rows[i]["Term2"].ToString();
  2259. contexts.cInvCode = dt.Rows[i]["ItemCode"].ToString();
  2260. contexts.iQuantity = Convert.ToDecimal(dt.Rows[i]["TransQTY"].ToString());
  2261. contexts.cBatch = dt.Rows[i]["Batch"].ToString();
  2262. contexts.iNum = AssQTY;
  2263. contexts.cBatchProperty6 = dt.Rows[i]["cBatchProperty6"].ToString();
  2264. contexts.cBatchProperty7 = dt.Rows[i]["cBatchProperty7"].ToString();
  2265. contextlists.Add(contexts);
  2266. if (i == dt.Rows.Count - 1)
  2267. {
  2268. context.list = contextlists;
  2269. contextlist.Add(context);
  2270. }
  2271. }
  2272. sql = @"UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE5='已回写'
  2273. where LotNO in ({0}) AND BusinessCode=''";
  2274. sql = string.Format(sql, IBarCodeList);
  2275. cmd.CommandText = sql;
  2276. result = cmd.ExecuteNonQuery();
  2277. if (isSuccess && result <= 0)
  2278. {
  2279. throw new Exception("日志表更新失败!");
  2280. }
  2281. string Istr = JsonConvert.SerializeObject(contextlist);
  2282. string iresult = HttpPost(IDispatch, Istr);
  2283. Result DispatchResult = new Result();
  2284. DispatchResult = JsonConvert.DeserializeObject<Result>(iresult);
  2285. if (DispatchResult.code != "200")
  2286. {
  2287. throw new Exception(DispatchResult.msg);
  2288. }
  2289. }
  2290. catch (Exception ex)
  2291. {
  2292. throw new Exception(ex.Message);
  2293. }
  2294. #endregion
  2295. }
  2296. return isSuccess;
  2297. }
  2298. /// <summary>
  2299. /// 销售退库
  2300. /// </summary>
  2301. /// <param name="sqlConnection"></param>
  2302. /// <param name="trans"></param>
  2303. /// <param name="POCode"></param>
  2304. /// <param name="porowList"></param>
  2305. /// <param name="poqtyList"></param>
  2306. /// <param name="barcodeList"></param>
  2307. /// <param name="barcodeqtyList"></param>
  2308. /// <param name="userCode"></param>
  2309. /// <param name="workpointCode"></param>
  2310. /// <param name="Type"></param>
  2311. /// <param name="dsconn"></param>
  2312. /// <returns></returns>
  2313. public static bool WareHouseDisPatchIN(SqlConnection sqlConnection, SqlTransaction trans, string POCode, string[] porowList, string[] barcodeList, string[] barcodeqtyList, string[] stackcodeList, string userCode, string userName, string workpointCode, string Type, string dsconn)
  2314. {
  2315. string sql = "";
  2316. string cBarCode = "";
  2317. string PORow = "";
  2318. decimal BarCodeQty = 0;
  2319. string BarCode = "";
  2320. string BinCode = "";
  2321. string BinGUID = "";
  2322. string WHCODE = "";
  2323. string WHGUID = "";
  2324. string INVGUID = "";
  2325. string INVCODE = "";
  2326. string ConnectString = dsconn;
  2327. int result = 0;
  2328. bool isSuccess = true;
  2329. SqlCommand cmd = new SqlCommand();
  2330. cmd.Connection = sqlConnection;
  2331. cmd.Transaction = trans;
  2332. try
  2333. {
  2334. for (int i = 0; i < porowList.Length; i++)
  2335. {
  2336. #region 更新ICSSODispatch表
  2337. PORow = porowList[i];
  2338. BarCodeQty = Convert.ToDecimal(barcodeqtyList[i]);
  2339. BarCode = barcodeList[i];
  2340. BinCode = stackcodeList[i];
  2341. if (cBarCode == "")
  2342. {
  2343. cBarCode += "'" + BarCode + "'";
  2344. }
  2345. else
  2346. {
  2347. cBarCode += ",'" + BarCode + "'";
  2348. }
  2349. sql = @"update ICSSODispatch
  2350. set HasQuantity=ISNULL(HasQuantity,0)+{0}
  2351. where DispatchCode='{1}' AND DispatchRow='{2}' AND WorkPoint='{3}'";
  2352. sql = string.Format(sql, BarCodeQty, POCode, PORow, workpointCode);
  2353. cmd.CommandText = sql;
  2354. result = cmd.ExecuteNonQuery();
  2355. if (isSuccess && result <= 0)
  2356. {
  2357. throw new Exception("销售订单表已退数量更新失败!");
  2358. }
  2359. #endregion
  2360. #region 获取仓库信息
  2361. sql = @"select A.Serial AS BinGUID
  2362. ,B.Serial AS WHGUID
  2363. ,B.StorageCode AS WHCODE
  2364. from ICSStack A
  2365. LEFT JOIN ICSStorage B
  2366. ON B.Serial=A.Storage_Serial
  2367. where A.StackCode='{0}' AND A.WorkPoint='{1}'";
  2368. sql = string.Format(sql, BinCode, workpointCode);
  2369. DataTable dt = SQlReturnData(sql, cmd);
  2370. if (dt.Rows.Count > 0)
  2371. {
  2372. BinGUID = dt.Rows[0]["BinGUID"].ToString();
  2373. WHGUID = dt.Rows[0]["WHGUID"].ToString();
  2374. WHCODE = dt.Rows[0]["WHCODE"].ToString();
  2375. }
  2376. else
  2377. {
  2378. throw new Exception("仓库信息获取失败");
  2379. }
  2380. #endregion
  2381. #region 获取物料信息
  2382. sql = @"SELECT A.INVCODE,A.ID
  2383. FROM ICSINVENTORY A
  2384. LEFT JOIN ICSITEMLot B
  2385. ON B.ItemCode=A.INVCODE
  2386. WHERE B.LotNO='{0}' AND A.WorkPoint='{1}'";
  2387. sql = string.Format(sql, BarCode, workpointCode);
  2388. dt = SQlReturnData(sql, cmd);
  2389. if (dt.Rows.Count > 0)
  2390. {
  2391. INVGUID = dt.Rows[0]["ID"].ToString();
  2392. INVCODE = dt.Rows[0]["INVCODE"].ToString();
  2393. }
  2394. else
  2395. {
  2396. throw new Exception("物料信息获取失败!");
  2397. }
  2398. #endregion
  2399. #region 更新ICSWareHouseInfo表
  2400. sql = @"IF EXISTS (SELECT * FROM ICSWareHouseInfo WHERE WHCode='{0}' AND BinCode='{1}'
  2401. AND INVCode=(SELECT ItemCode FROM ICSITEMLot WHERE LotNO='{2}'))
  2402. UPDATE ICSWareHouseInfo SET QTY=QTY+{3}
  2403. WHERE WHCode='{0}' AND BinCode='{1}' AND INVCode=(SELECT ItemCode FROM ICSITEMLot WHERE LotNO='{2}')
  2404. ELSE
  2405. INSERT INTO ICSWareHouseInfo
  2406. VALUES
  2407. ('{4}','{0}','{5}','{1}','{6}','{7}',{3},'{8}','{9}','{10}',GETDATE(),'' )";
  2408. sql = string.Format(sql, WHCODE, BinCode, BarCode, BarCodeQty, WHGUID, BinGUID, INVGUID, INVCODE
  2409. , workpointCode, userCode, userName);
  2410. cmd.CommandText = sql;
  2411. result = cmd.ExecuteNonQuery();
  2412. if (isSuccess && result <= 0)
  2413. {
  2414. throw new Exception("库存主表数量更新失败!");
  2415. }
  2416. #endregion
  2417. #region 更新ICSWareHouseLotInfo表
  2418. sql = @"select * from ICSWareHouseLotInfo
  2419. where LotNO='{0}' AND WorkPoint='{1}'";
  2420. sql = string.Format(sql, BarCode, workpointCode);
  2421. dt = SQlReturnData(sql, cmd);
  2422. if (dt.Rows.Count != 0)
  2423. {
  2424. throw new Exception("条码已经入库!");
  2425. }
  2426. sql = @"insert into ICSWareHouseLotInfo
  2427. Values
  2428. (NEWID(),'{0}','{1}','{2}','{3}','{4}','{5}','{6}',{7}
  2429. ,GETDATE(),'{8}','{9}','{10}',GETDATE(),'',NULL,NULL)";
  2430. sql = string.Format(sql, BarCode, WHGUID, WHCODE, BinGUID, BinCode, INVGUID, INVCODE, BarCodeQty
  2431. , workpointCode, userCode, userName);
  2432. cmd.CommandText = sql;
  2433. result = cmd.ExecuteNonQuery();
  2434. if (isSuccess && result <= 0)
  2435. {
  2436. throw new Exception("库存子表数量更新失败!");
  2437. }
  2438. #endregion
  2439. #region 更新ICSWareHouseLotInfoLog表
  2440. sql = @"insert into ICSWareHouseLotInfoLog
  2441. VALUES
  2442. (NEWID(),'{0}','{1}','{2}','{3}','','','{4}','{5}'
  2443. ,{6},NULL,'{7}','退','{8}','{9}',GETDATE(),'{10}',NULL,NULL,NULL,NULL,'')";
  2444. sql = string.Format(sql, POCode, PORow, INVCODE, BarCode, WHCODE, BinCode, BarCodeQty, Type
  2445. , userCode, userName, workpointCode);
  2446. cmd.CommandText = sql;
  2447. result = cmd.ExecuteNonQuery();
  2448. if (isSuccess && result <= 0)
  2449. {
  2450. throw new Exception("日志表表存入失败!");
  2451. }
  2452. #endregion
  2453. }
  2454. if (message == "Open")
  2455. {
  2456. #region 接口调用
  2457. try
  2458. {
  2459. sql = @"select A.Term1
  2460. ,A.DispatchCode
  2461. ,B.TOStorageCODE
  2462. ,A.Term2
  2463. ,B.TransQTY
  2464. ,C.VenderLotNO AS Batch
  2465. ,C.ItemCode
  2466. ,C.EATTRIBUTE3
  2467. from ICSSODispatch A
  2468. INNER JOIN ICSWareHouseLotInfoLog B
  2469. ON B.TransNO=A.DispatchCode AND B.TransLine=A.DispatchRow AND B.BusinessCode='退' AND B.EATTRIBUTE5=''
  2470. INNER JOIN ICSITEMLot C
  2471. ON C.LotNO=B.LotNO
  2472. WHERE B.LotNO IN ({0})";
  2473. sql = string.Format(sql, cBarCode);
  2474. DataTable dt = SQlReturnData(sql, cmd);
  2475. List<Dispatchlist> contextlist = new List<Dispatchlist>();
  2476. Dispatchlist context = new Dispatchlist();
  2477. List<Dispatchlists> contextlists = new List<Dispatchlists>();
  2478. Dispatchlists contexts = new Dispatchlists();
  2479. string SOCode = "";
  2480. string WareHouse = "";
  2481. decimal AssQTY = 0;
  2482. for (int i = 0; i < dt.Rows.Count; i++)
  2483. {
  2484. AssQTY = Convert.ToDecimal(dt.Rows[i]["EATTRIBUTE3"]) * Convert.ToDecimal(dt.Rows[i]["TransQTY"]);
  2485. if (SOCode != dt.Rows[i]["DispatchCode"].ToString()
  2486. || WareHouse != dt.Rows[i]["TOStorageCODE"].ToString())
  2487. {
  2488. if (i > 0)
  2489. {
  2490. context.list = contextlists;
  2491. contextlist.Add(context);
  2492. }
  2493. context = new Dispatchlist();
  2494. SOCode = dt.Rows[i]["DispatchCode"].ToString();
  2495. WareHouse = dt.Rows[i]["TOStorageCODE"].ToString();
  2496. context.DLID = dt.Rows[i]["Term1"].ToString();
  2497. context.cDLCode = dt.Rows[i]["DispatchCode"].ToString();
  2498. context.cWhCode = dt.Rows[i]["TOStorageCODE"].ToString();
  2499. context.UserCode = userCode;
  2500. context.IsReturn = "1";
  2501. contextlists = new List<Dispatchlists>();
  2502. }
  2503. contexts = new Dispatchlists();
  2504. contexts.iDLsID = dt.Rows[i]["Term2"].ToString();
  2505. contexts.cInvCode = dt.Rows[i]["ItemCode"].ToString();
  2506. contexts.iQuantity = Convert.ToDecimal(dt.Rows[i]["TransQTY"].ToString());
  2507. contexts.cBatch = dt.Rows[i]["Batch"].ToString();
  2508. contexts.iNum = AssQTY;
  2509. contextlists.Add(contexts);
  2510. if (i == dt.Rows.Count - 1)
  2511. {
  2512. context.list = contextlists;
  2513. contextlist.Add(context);
  2514. }
  2515. }
  2516. sql = @"UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE5='已回写'
  2517. where LotNO in ({0}) AND BusinessCode='退'";
  2518. sql = string.Format(sql, cBarCode);
  2519. cmd.CommandText = sql;
  2520. result = cmd.ExecuteNonQuery();
  2521. if (isSuccess && result <= 0)
  2522. {
  2523. throw new Exception("日志表更新失败!");
  2524. }
  2525. string Istr = JsonConvert.SerializeObject(contextlist);
  2526. string iresult = HttpPost(IDispatch, Istr);
  2527. Result DispatchResult = new Result();
  2528. DispatchResult = JsonConvert.DeserializeObject<Result>(iresult);
  2529. if (DispatchResult.code != "200")
  2530. {
  2531. throw new Exception(DispatchResult.msg);
  2532. }
  2533. }
  2534. catch (Exception ex)
  2535. {
  2536. throw new Exception(ex.Message);
  2537. }
  2538. #endregion
  2539. }
  2540. }
  2541. catch (Exception ex)
  2542. {
  2543. throw new Exception(ex.Message);
  2544. }
  2545. return isSuccess;
  2546. }
  2547. /// <summary>
  2548. /// 物料退料
  2549. /// </summary>
  2550. /// <param name="POCode"></param>
  2551. /// <param name="porowList"></param>
  2552. /// <param name="poqtyList"></param>
  2553. /// <param name="barcodeList"></param>
  2554. /// <param name="barcodeqtyList"></param>
  2555. /// <param name="userCode"></param>
  2556. /// <param name="workpointCode"></param>
  2557. /// <param name="Type"></param>
  2558. /// <param name="dsconn"></param>
  2559. /// <returns></returns>
  2560. public static bool MaterialIN(SqlConnection sqlConnection, SqlTransaction trans, string[] pocodeList, string[] porowList, string[] poqtyList, string[] barcoderowList, string[] barcodeList, string[] barcodeqtyList, string[] bincodelist, string userCode, string userName, string workpointCode, string Type, string VouchType, string dsconn)
  2561. {
  2562. string sql = "";
  2563. string BarCode = "";
  2564. decimal BarCodeQty = 0;
  2565. string BarCodeRow = "";
  2566. string Errormessage = "";
  2567. string PORow = "";
  2568. string POCode = "";
  2569. decimal POQty = 0;
  2570. string IBarCodeList = "";
  2571. string NewBinCode = "";
  2572. string ConnectString = dsconn;
  2573. int result = 0;
  2574. bool isSuccess = true;
  2575. SqlCommand cmd = new SqlCommand();
  2576. cmd.Connection = sqlConnection;
  2577. cmd.Transaction = trans;
  2578. try
  2579. {
  2580. for (int i = 0; i < porowList.Length; i++)
  2581. {
  2582. #region 更新ICSMaterialPick表
  2583. POCode = pocodeList[i];
  2584. PORow = porowList[i];
  2585. POQty = Convert.ToDecimal(poqtyList[i]);
  2586. sql = @"update ICSMaterialPick
  2587. set HasQuantity=ISNULL(HasQuantity,0)+{0}
  2588. where VouchCode='{1}' AND VouchRow='{2}'
  2589. and WorkPoint='{3}'";
  2590. sql = string.Format(sql, POQty, POCode, PORow, workpointCode);
  2591. cmd.CommandText = sql;
  2592. result = cmd.ExecuteNonQuery();
  2593. if (isSuccess && result <= 0)
  2594. {
  2595. throw new Exception("退料表已退数量更新失败!");
  2596. }
  2597. #endregion
  2598. if (VouchType != "MRO")
  2599. {
  2600. #region 扣减领料单已领数量
  2601. sql = @"update ICSMOPickLog set HasQuantity=HasQuantity-{2}
  2602. where MOCODE=
  2603. (select MOCODE from ICSMaterialPick where VouchCode='{0}' and VouchRow='{1}')
  2604. AND MOSEQ=
  2605. (select MORow from ICSMaterialPick where VouchCode='{0}' and VouchRow='{1}')
  2606. AND MOBITEMCODE=
  2607. (SELECT SubInvCode FROM ICSMaterialPick where VouchCode='{0}' and VouchRow='{1}')
  2608. AND WorkPoint='{3}'";
  2609. sql = string.Format(sql, POCode, PORow, POQty, workpointCode);
  2610. cmd.CommandText = sql;
  2611. result = cmd.ExecuteNonQuery();
  2612. if (isSuccess && result <= 0)
  2613. {
  2614. throw new Exception("领料表已领数量扣减失败!");
  2615. }
  2616. }
  2617. #endregion
  2618. }
  2619. for (int i = 0; i < barcodeList.Length; i++)
  2620. {
  2621. if (IBarCodeList == "")
  2622. {
  2623. IBarCodeList += "'" + barcodeList[i] + "'";
  2624. }
  2625. else
  2626. {
  2627. IBarCodeList += ",'" + barcodeList[i] + "'";
  2628. }
  2629. BarCode = barcodeList[i];
  2630. BarCodeQty = Convert.ToDecimal(barcodeqtyList[i]);
  2631. BarCodeRow = barcoderowList[i];
  2632. NewBinCode = bincodelist[i];
  2633. string INVCode = "";
  2634. string WHCode = "";
  2635. string TranNo = "";
  2636. string TranLine = "";
  2637. #region 获取仓库库位等信息
  2638. sql = @"select ItemCode
  2639. ,TransNO
  2640. ,TransLine
  2641. from ICSITEMLot
  2642. where LotNO='{0}' AND WorkPoint='{1}'";
  2643. sql = string.Format(sql, BarCode, workpointCode);
  2644. DataTable dt = SQlReturnData(sql, cmd);
  2645. if (dt.Rows.Count == 0)
  2646. {
  2647. throw new Exception("获取条码信息失败!");
  2648. }
  2649. else
  2650. {
  2651. INVCode = dt.Rows[0]["ItemCode"].ToString();
  2652. TranNo = dt.Rows[0]["TransNO"].ToString();
  2653. TranLine = dt.Rows[0]["TransLine"].ToString();
  2654. }
  2655. sql = @"select B.StorageCode
  2656. from ICSStack A
  2657. LEFT JOIN ICSStorage B
  2658. ON B.Serial=A.Storage_Serial
  2659. where StackCode='{0}'";
  2660. sql = string.Format(sql, NewBinCode);
  2661. dt = SQlReturnData(sql, cmd);
  2662. if (dt.Rows.Count == 0)
  2663. {
  2664. throw new Exception("获取仓库信息失败!");
  2665. }
  2666. else
  2667. {
  2668. WHCode = dt.Rows[0]["StorageCode"].ToString();
  2669. }
  2670. #endregion
  2671. #region 更新ICSWareHouseInfo表
  2672. sql = @"update ICSWareHouseInfo
  2673. set QTY=QTY+{0},MTIME='{1}'
  2674. where INVCode='{2}' AND WHCode='{3}' AND BinCode='{4}'";
  2675. sql = string.Format(sql, BarCodeQty, DateTime.Now, INVCode, WHCode, NewBinCode);
  2676. cmd.CommandText = sql;
  2677. result = cmd.ExecuteNonQuery();
  2678. if (isSuccess && result <= 0)
  2679. {
  2680. sql = @"insert into ICSWareHouseInfo
  2681. values
  2682. ((select Serial from ICSStorage where StorageCode='{0}')
  2683. ,'{0}'
  2684. ,(SELECT Serial FROM ICSStack WHERE StackCode='{1}')
  2685. ,'{1}'
  2686. ,(SELECT ID FROM ICSINVENTORY WHERE INVCODE='{2}')
  2687. ,'{2}',{3},'{4}','{5}','{6}',GETDATE(),NULL)";
  2688. sql = string.Format(sql, WHCode, NewBinCode, INVCode, BarCodeQty, workpointCode, userCode, userName);
  2689. cmd.CommandText = sql;
  2690. result = cmd.ExecuteNonQuery();
  2691. if (isSuccess && result <= 0)
  2692. {
  2693. throw new Exception("库存主表存入失败!");
  2694. }
  2695. }
  2696. #endregion
  2697. #region 更新ICSWareHouseLotInfo表
  2698. sql = @"insert into ICSWareHouseLotInfo
  2699. Values
  2700. (NEWID(),'{0}',
  2701. (select Serial from ICSStorage where StorageCode='{1}'),
  2702. '{1}',
  2703. (SELECT Serial FROM ICSStack WHERE StackCode='{2}'),
  2704. '{2}',
  2705. (SELECT ID FROM ICSINVENTORY WHERE INVCODE='{3}'),
  2706. '{3}',{4},GETDATE(),'{5}','{6}','{7}',GETDATE(),'','','')";
  2707. sql = string.Format(sql, BarCode, WHCode, NewBinCode, INVCode, BarCodeQty, workpointCode, userCode, userName);
  2708. cmd.CommandText = sql;
  2709. result = cmd.ExecuteNonQuery();
  2710. if (isSuccess && result <= 0)
  2711. {
  2712. throw new Exception("库存子表数量增加失败!");
  2713. }
  2714. #endregion
  2715. #region 存入ICSWareHouseLotInfoLog表(日志)
  2716. sql = @"insert into ICSWareHouseLotInfoLog
  2717. Values
  2718. (NEWID(),'{0}','{1}','{2}','{3}','','','{9}','{10}'
  2719. ,{4},null,'{5}','退','{6}','{7}',GETDATE(),'{8}','','','','','')";
  2720. sql = string.Format(sql, TranNo, TranLine, INVCode, BarCode, BarCodeQty, Type, userCode, userName, workpointCode, WHCode, NewBinCode);
  2721. cmd.CommandText = sql;
  2722. result = cmd.ExecuteNonQuery();
  2723. if (isSuccess && result <= 0)
  2724. {
  2725. throw new Exception("日志表存入失败!");
  2726. }
  2727. #endregion
  2728. }
  2729. }
  2730. catch (Exception ex)
  2731. {
  2732. throw new Exception(ex.Message);
  2733. }
  2734. if (message == "Open")
  2735. {
  2736. #region 接口调用
  2737. try
  2738. {
  2739. string CodeList = "";
  2740. for (int i = 0; i < pocodeList.Length; i++)
  2741. {
  2742. if (CodeList == "")
  2743. {
  2744. CodeList += "'" + pocodeList[i] + "'";
  2745. }
  2746. else
  2747. {
  2748. CodeList += ",'" + pocodeList[i] + "'";
  2749. }
  2750. }
  2751. sql = @"select A.MOCODE,A.MORow AS MOSEQ,A.InvCode AS ITEMCODE,E.EATTRIBUTE1,A.VoucherNO
  2752. ,B.MOBITEMECN,B.MOBITEMCODE,B.SEQ
  2753. ,C.TOStorageCODE,C.TransQTY,D.VenderLotNO AS VenderLotNO
  2754. ,D.EATTRIBUTE3,F.OutCategory,E.MOVER,C.ItemCode AS CItemCode,f.MEMO,a.Dept
  2755. from ICSMaterialPick A
  2756. INNER JOIN ICSWareHouseLotInfoLog C
  2757. ON C.TransNO=A.VouchCode AND C.TransLine=A.VouchRow
  2758. AND C.BusinessCode='退' AND C.EATTRIBUTE5=''
  2759. LEFT JOIN ICSMO E
  2760. ON E.MOCODE=A.MOCode AND E.MOSEQ=A.MORow
  2761. LEFT JOIN ICSMOBOM B
  2762. ON B.MOCODE=A.MOCODE AND B.SEQ=A.MORow AND B.MOBITEMCODE=A.SubInvCode
  2763. LEFT JOIN ICSITEMLot D
  2764. ON D.LotNO=C.LotNO
  2765. LEFT JOIN ICSMaterial F
  2766. ON F.VouchCode=A.VouchCode
  2767. WHERE A.VouchCode in ({0})
  2768. ORDER BY MOSEQ,E.ITEMCODE,TOStorageCODE,VenderLotNO";
  2769. sql = string.Format(sql, CodeList);
  2770. DataTable dt = SQlReturnData(sql, cmd);
  2771. decimal ASSQTY = 0;
  2772. List<ICSSoft.Entity.mom_orderdetail.mom_orderdetail> contextlist = new List<ICSSoft.Entity.mom_orderdetail.mom_orderdetail>();
  2773. List<mom_moallocate> contextlists = new List<mom_moallocate>();
  2774. List<ICSSoft.Entity.mom_orderdetail.mom_orderdetail> contextlistMO = new List<ICSSoft.Entity.mom_orderdetail.mom_orderdetail>();
  2775. List<mom_moallocate> contextlistsMO = new List<mom_moallocate>();
  2776. if (VouchType == "MRO")
  2777. {
  2778. #region 无来源单据的退料单
  2779. ICSSoft.Entity.mom_orderdetail.mom_orderdetail context = new ICSSoft.Entity.mom_orderdetail.mom_orderdetail();
  2780. mom_moallocate contexts = new mom_moallocate();
  2781. string WareHouse = "";
  2782. string SEQ = "";
  2783. string ITEMCODE = "";
  2784. for (int i = 0; i < dt.Rows.Count; i++)
  2785. {
  2786. ASSQTY = Convert.ToDecimal(dt.Rows[i]["TransQTY"].ToString()) * Convert.ToDecimal(dt.Rows[i]["EATTRIBUTE3"].ToString());
  2787. if (WareHouse != dt.Rows[i]["TOStorageCODE"].ToString()
  2788. || ITEMCODE != dt.Rows[i]["ITEMCODE"].ToString())
  2789. {
  2790. if (i > 0)
  2791. {
  2792. context.list = contextlists;
  2793. contextlist.Add(context);
  2794. }
  2795. context = new ICSSoft.Entity.mom_orderdetail.mom_orderdetail();
  2796. WareHouse = dt.Rows[i]["TOStorageCODE"].ToString();
  2797. ITEMCODE = dt.Rows[i]["ITEMCODE"].ToString();
  2798. context.UserCode = userCode;
  2799. context.cWhCode = dt.Rows[i]["TOStorageCODE"].ToString();
  2800. context.IsReturn = "1";
  2801. context.cRdCode = dt.Rows[i]["OutCategory"].ToString();
  2802. context.MEMO = dt.Rows[i]["MEMO"].ToString();
  2803. context.cBatch = dt.Rows[i]["Dept"].ToString();
  2804. contextlists = new List<mom_moallocate>();
  2805. }
  2806. contexts = new mom_moallocate();
  2807. contexts.cInvCode = dt.Rows[i]["CItemCode"].ToString();
  2808. contexts.iQuantity = Convert.ToDecimal(dt.Rows[i]["TransQTY"].ToString());
  2809. contexts.cBatch = dt.Rows[i]["VenderLotNO"].ToString();
  2810. contexts.iNum = ASSQTY;
  2811. contextlists.Add(contexts);
  2812. if (i == dt.Rows.Count - 1)
  2813. {
  2814. context.list = contextlists;
  2815. contextlist.Add(context);
  2816. }
  2817. }
  2818. #endregion
  2819. }
  2820. else
  2821. {
  2822. #region 工单退料单
  2823. ICSSoft.Entity.mom_orderdetail.mom_orderdetail contextMO = new ICSSoft.Entity.mom_orderdetail.mom_orderdetail();
  2824. mom_moallocate contextsMO = new mom_moallocate();
  2825. string WareHouseMO = "";
  2826. string SEQMO = "";
  2827. string ITEMCODEMO = "";
  2828. for (int i = 0; i < dt.Rows.Count; i++)
  2829. {
  2830. ASSQTY = Convert.ToDecimal(dt.Rows[i]["TransQTY"].ToString()) * Convert.ToDecimal(dt.Rows[i]["EATTRIBUTE3"].ToString());
  2831. if (WareHouseMO != dt.Rows[i]["TOStorageCODE"].ToString()
  2832. || SEQMO != dt.Rows[i]["MOSEQ"].ToString()
  2833. || ITEMCODEMO != dt.Rows[i]["ITEMCODE"].ToString())
  2834. {
  2835. if (i > 0)
  2836. {
  2837. contextMO.list = contextlistsMO;
  2838. contextlistMO.Add(contextMO);
  2839. }
  2840. contextMO = new ICSSoft.Entity.mom_orderdetail.mom_orderdetail();
  2841. WareHouseMO = dt.Rows[i]["TOStorageCODE"].ToString();
  2842. SEQMO = dt.Rows[i]["MOSEQ"].ToString();
  2843. ITEMCODEMO = dt.Rows[i]["ITEMCODE"].ToString();
  2844. contextMO.MoDId = dt.Rows[i]["EATTRIBUTE1"].ToString();
  2845. contextMO.MoCode = dt.Rows[i]["MOCODE"].ToString();
  2846. contextMO.SortSeq = dt.Rows[i]["MOSEQ"].ToString();
  2847. contextMO.UserCode = userCode;
  2848. contextMO.cWhCode = dt.Rows[i]["TOStorageCODE"].ToString();
  2849. contextMO.IsReturn = "1";
  2850. contextlistsMO = new List<mom_moallocate>();
  2851. }
  2852. contextsMO = new mom_moallocate();
  2853. contextsMO.AllocateId = dt.Rows[i]["MOBITEMECN"].ToString();
  2854. contextsMO.cInvCode = dt.Rows[i]["MOBITEMCODE"].ToString();
  2855. contextsMO.iQuantity = Convert.ToDecimal(dt.Rows[i]["TransQTY"].ToString());
  2856. contextsMO.cBatch = dt.Rows[i]["VenderLotNO"].ToString();
  2857. contextsMO.iNum = ASSQTY;
  2858. contextsMO.MoLotCode = dt.Rows[i]["MOVER"].ToString();
  2859. contextlistsMO.Add(contextsMO);
  2860. if (i == dt.Rows.Count - 1)
  2861. {
  2862. contextMO.list = contextlistsMO;
  2863. contextlistMO.Add(contextMO);
  2864. }
  2865. }
  2866. #endregion
  2867. }
  2868. List<root> rootlist = new List<root>();
  2869. root rootinfo = new root();
  2870. rootinfo.Bills = contextlistMO;
  2871. rootinfo.NoSourceBills = contextlist;
  2872. rootlist.Add(rootinfo);
  2873. sql = @"UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE5='已回写'
  2874. where LotNO in ({0}) AND BusinessCode='退'";
  2875. sql = string.Format(sql, IBarCodeList);
  2876. cmd.CommandText = sql;
  2877. result = cmd.ExecuteNonQuery();
  2878. if (isSuccess && result <= 0)
  2879. {
  2880. throw new Exception("日志表更新失败!");
  2881. }
  2882. //Root root = new Root();
  2883. //root.Bills = contextlistMO;
  2884. //root.RedBills = contextlist;
  2885. //string IstrMO = JsonConvert.SerializeObject(root);
  2886. string IstrMO = JsonConvert.SerializeObject(rootinfo);
  2887. string iresultMO = HttpPost(IInvOut, IstrMO);
  2888. Result INVINResultMO = new Result();
  2889. INVINResultMO = JsonConvert.DeserializeObject<Result>(iresultMO);
  2890. if (INVINResultMO.code != "200")
  2891. {
  2892. throw new Exception(INVINResultMO.msg);
  2893. }
  2894. // List<ZYPDAServiceForINVOut.mom_orderdetail> contextList = new List<ZYPDAServiceForINVOut.mom_orderdetail>();
  2895. // List<ZYPDAServiceForINVOut.mom_moallocate> contextLists = new List<ZYPDAServiceForINVOut.mom_moallocate>();
  2896. // ZYPDAServiceForINVOut.mom_orderdetail context = new ZYPDAServiceForINVOut.mom_orderdetail();
  2897. // ZYPDAServiceForINVOut.mom_moallocate contexts = new ZYPDAServiceForINVOut.mom_moallocate();
  2898. // string WareHouse = "";
  2899. // for (int i = 0; i < dt.Rows.Count; i++)
  2900. // {
  2901. // if (WareHouse != dt.Rows[i]["TOStorageCODE"].ToString())
  2902. // {
  2903. // if (i > 0)
  2904. // {
  2905. // context.bodyList = contextLists.ToArray();
  2906. // contextList.Add(context);
  2907. // }
  2908. // context = new ZYPDAServiceForINVOut.mom_orderdetail();
  2909. // WareHouse = dt.Rows[i]["TOStorageCODE"].ToString();
  2910. // context.MoCode = dt.Rows[i]["MOCODE"].ToString();
  2911. // context.SortSeq = dt.Rows[i]["SEQ"].ToString();
  2912. // context.UserCode = userCode;
  2913. // context.cWhCode = dt.Rows[i]["TOStorageCODE"].ToString();
  2914. // context.ItemCode = dt.Rows[i]["InvCode"].ToString();
  2915. // contextLists = new List<ZYPDAServiceForINVOut.mom_moallocate>();
  2916. // }
  2917. // contexts = new ZYPDAServiceForINVOut.mom_moallocate();
  2918. // contexts.AllocateId = dt.Rows[i]["MOBITEMECN"].ToString();
  2919. // contexts.cInvCode = dt.Rows[i]["BOMITEMCODE"].ToString();
  2920. // contexts.iQuantity = Convert.ToDecimal(dt.Rows[i]["TransQTY"].ToString());
  2921. // contexts.cBatch = dt.Rows[i]["VenderLotNO"].ToString();
  2922. // //contexts.modid = dt.Rows[i]["Free1"].ToString();
  2923. // contextLists.Add(contexts);
  2924. // if (i == dt.Rows.Count - 1)
  2925. // {
  2926. // context.bodyList = contextLists.ToArray();
  2927. // contextList.Add(context);
  2928. // }
  2929. // }
  2930. // ZYPDAServiceForINVOut.Imom2Rd11Client client = new ZYPDAServiceForINVOut.Imom2Rd11Client();
  2931. // ZYPDAServiceForINVOut.Result cresult = new ZYPDAServiceForINVOut.Result();
  2932. // sql = @"UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE5='已回写'
  2933. // where LotNO in ({0}) AND BusinessCode='物料退料'";
  2934. // sql = string.Format(sql, IBarCodeList);
  2935. // cmd.CommandText = sql;
  2936. // result = cmd.ExecuteNonQuery();
  2937. // if (isSuccess && result <= 0)
  2938. // {
  2939. // throw new Exception("日志表更新失败!");
  2940. // }
  2941. // cresult = client.InsertRd11(contextList.ToArray(), "1");
  2942. // if (cresult.IsSuccess == false)
  2943. // {
  2944. // throw new Exception(cresult.MESSAGE);
  2945. // }
  2946. }
  2947. catch (Exception ex)
  2948. {
  2949. throw new Exception(ex.Message);
  2950. }
  2951. #endregion
  2952. }
  2953. return isSuccess;
  2954. }
  2955. /// <summary>
  2956. /// 移库扫描
  2957. /// </summary>
  2958. /// <param name="sqlConnection"></param>
  2959. /// <param name="trans"></param>
  2960. /// <param name="oldBinCodeList"></param>
  2961. /// <param name="newBinCodeList"></param>
  2962. /// <param name="barcodeList"></param>
  2963. /// <param name="barcodeqtyList"></param>
  2964. /// <param name="userCode"></param>
  2965. /// <param name="workpointCode"></param>
  2966. /// <param name="Type"></param>
  2967. /// <param name="dsconn"></param>
  2968. /// <returns></returns>
  2969. public static bool StackTransfer(SqlConnection sqlConnection, SqlTransaction trans, string[] oldBinCodeList, string[] newBinCodeList, string[] barcodeList, string[] barcodeqtyList, string userCode, string userName, string workpointCode, string Type, string dsconn)
  2970. {
  2971. string sql = "";
  2972. string BarCode = "";
  2973. decimal BarCodeQty = 0;
  2974. string NewBinCode = "";
  2975. string OldBinCode = "";
  2976. string ConnectString = dsconn;
  2977. int result = 0;
  2978. bool isSuccess = true;
  2979. SqlCommand cmd = new SqlCommand();
  2980. cmd.Connection = sqlConnection;
  2981. cmd.Transaction = trans;
  2982. try
  2983. {
  2984. for (int i = 0; i < barcodeList.Length; i++)
  2985. {
  2986. BarCode = barcodeList[i];
  2987. BarCodeQty = Convert.ToDecimal(barcodeqtyList[i].ToString());
  2988. NewBinCode = newBinCodeList[i];
  2989. OldBinCode = oldBinCodeList[i];
  2990. string INVCode = "";
  2991. string WHCode = "";
  2992. string TranNo = "";
  2993. string TranLine = "";
  2994. #region 获取仓库库位等信息
  2995. sql = @"select WHCode
  2996. ,BinCode
  2997. ,INVCode
  2998. ,B.TransNO
  2999. ,B.TransLine
  3000. from ICSWareHouseLotInfo A
  3001. left join ICSITEMLot B
  3002. on B.LotNO=A.LotNO
  3003. where A.LotNO='{0}' AND A.WorkPoint='{1}'";
  3004. sql = string.Format(sql, BarCode, workpointCode);
  3005. DataTable dt = SQlReturnData(sql, cmd);
  3006. if (dt.Rows.Count == 0)
  3007. {
  3008. throw new Exception("获取仓库信息失败!");
  3009. }
  3010. else
  3011. {
  3012. INVCode = dt.Rows[0]["INVCode"].ToString();
  3013. WHCode = dt.Rows[0]["WHCode"].ToString();
  3014. TranNo = dt.Rows[0]["TransNO"].ToString();
  3015. TranLine = dt.Rows[0]["TransLine"].ToString();
  3016. }
  3017. #endregion
  3018. #region 更新ICSWareHouseInfo表
  3019. sql = @"update ICSWareHouseInfo
  3020. set QTY=QTY-{0},MTIME='{1}'
  3021. where INVCode='{2}' AND WHCode='{3}' AND BinCode='{4}'";
  3022. sql = string.Format(sql, BarCodeQty, DateTime.Now, INVCode, WHCode, OldBinCode);
  3023. cmd.CommandText = sql;
  3024. result = cmd.ExecuteNonQuery();
  3025. if (isSuccess && result <= 0)
  3026. {
  3027. throw new Exception("库存主表数量扣减失败!");
  3028. }
  3029. sql = @"select * from ICSWareHouseInfo
  3030. where WHCode='{0}' AND BinCode='{1}' AND INVCode='{2}'";
  3031. sql = string.Format(sql, WHCode, NewBinCode, INVCode);
  3032. dt = SQlReturnData(sql, cmd);
  3033. if (dt.Rows.Count != 0)
  3034. {
  3035. sql = @"update ICSWareHouseInfo
  3036. set QTY=QTY+{0},MTIME='{1}'
  3037. where INVCode='{2}' AND WHCode='{3}' AND BinCode='{4}'";
  3038. sql = string.Format(sql, BarCodeQty, DateTime.Now, INVCode, WHCode, NewBinCode);
  3039. cmd.CommandText = sql;
  3040. result = cmd.ExecuteNonQuery();
  3041. if (isSuccess && result <= 0)
  3042. {
  3043. throw new Exception("库存主表数量增加失败!");
  3044. }
  3045. }
  3046. else
  3047. {
  3048. sql = @"INSERT INTO dbo.ICSWareHouseInfo
  3049. ( WHGUID ,WHCode ,BinGUID ,BinCode ,INVGUID ,
  3050. INVCode ,QTY ,WorkPoint ,MUSER ,MUSERName ,
  3051. MTIME ,EATTRIBUTE1)
  3052. SELECT A.Serial,'{0}',B.Serial,'{1}',C.ID,'{2}',{3},'{4}','{5}','{6}','{7}','' FROM ICSStorage A
  3053. LEFT JOIN ICSStack B
  3054. ON B.Storage_Serial=A.Serial
  3055. LEFT JOIN ICSINVENTORY C
  3056. ON C.WorkPoint=B.WorkPoint
  3057. WHERE A.StorageCode='{0}' AND
  3058. B.StackCode='{1}' AND
  3059. C.INVCODE='{2}'";
  3060. sql = string.Format(sql, WHCode, NewBinCode, INVCode, BarCodeQty, workpointCode, userCode, userName, DateTime.Now);
  3061. cmd.CommandText = sql;
  3062. result = cmd.ExecuteNonQuery();
  3063. if (isSuccess && result <= 0)
  3064. {
  3065. throw new Exception("库存主表数量存入失败!");
  3066. }
  3067. }
  3068. #endregion
  3069. #region 更新ICSWareHouseLotInfo表
  3070. sql = @"update ICSWareHouseLotInfo set
  3071. BinGUID=(select Serial from ICSStack where StackCode='{0}'),
  3072. BinCode='{0}'
  3073. where LotNO='{1}'";
  3074. sql = string.Format(sql, NewBinCode, BarCode);
  3075. cmd.CommandText = sql;
  3076. result = cmd.ExecuteNonQuery();
  3077. if (isSuccess && result <= 0)
  3078. {
  3079. throw new Exception("库存子表数量更新失败!");
  3080. }
  3081. #endregion
  3082. #region 存入ICSWareHouseLotInfoLog表(日志)
  3083. sql = @"insert into ICSWareHouseLotInfoLog
  3084. Values
  3085. (NEWID(),'{0}','{1}','{2}','{3}','{4}','{5}','{6}'
  3086. ,'{7}',{8},null,'{9}','','{10}','{11}',GETDATE(),'{12}','','','','','')";
  3087. sql = string.Format(sql, TranNo, TranLine, INVCode, BarCode, WHCode, OldBinCode, WHCode, NewBinCode, BarCodeQty, Type, userCode, userName, workpointCode);
  3088. cmd.CommandText = sql;
  3089. result = cmd.ExecuteNonQuery();
  3090. if (isSuccess && result <= 0)
  3091. {
  3092. throw new Exception("日志表存入失败!");
  3093. }
  3094. #endregion
  3095. }
  3096. return isSuccess;
  3097. }
  3098. catch (Exception ex)
  3099. {
  3100. throw new Exception(ex.Message);
  3101. }
  3102. }
  3103. /// <summary>
  3104. /// 验证盘点单号信息
  3105. /// </summary>
  3106. /// <param name="CheckNo"></param>
  3107. /// <param name="WorkPointCode"></param>
  3108. /// <param name="dsconn"></param>
  3109. /// <returns></returns>
  3110. public static DataTable CheckCheckNo(string CheckNo, string WorkPointCode, string dsconn)
  3111. {
  3112. string sql = @"select * from ICSToCheck
  3113. where ToCheckNO='{0}' AND WorkPoint='{1}'";
  3114. sql = string.Format(sql, CheckNo, WorkPointCode);
  3115. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  3116. return dt;
  3117. }
  3118. /// <summary>
  3119. /// 验证盘点条码信息
  3120. /// </summary>
  3121. /// <param name="CheckNo"></param>
  3122. /// <param name="BarCode"></param>
  3123. /// <param name="WorkPointCode"></param>
  3124. /// <param name="dsconn"></param>
  3125. /// <returns></returns>
  3126. public static DataTable CheckLotnoForCheck(string CheckNo, string BarCode, string WorkPointCode, string dsconn)
  3127. {
  3128. DataTable dts = new DataTable();
  3129. #region 获取盘点单物料及仓库信息
  3130. string sql = @"select ItemCode,StorageCode from ICSToCheck
  3131. where ToCheckNO='{0}' AND WorkPoint='{1}'";
  3132. sql = string.Format(sql, CheckNo, WorkPointCode);
  3133. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  3134. if (dt.Rows.Count > 0)
  3135. {
  3136. for (int i = 0; i < dt.Rows.Count; i++)
  3137. {
  3138. sql = @"select WHCode
  3139. ,BinCode
  3140. ,A.LotNO
  3141. ,A.INVCode
  3142. ,B.INVNAME
  3143. ,B.INVSTD
  3144. ,A.LotQty
  3145. ,D.LOTQTY AS ItemLotQTY
  3146. ,ISNULL(BarCodeQty,0) AS BarCodeQty
  3147. ,B.INVUOM
  3148. from ICSWareHouseLotInfo A
  3149. left join ICSINVENTORY B
  3150. on B.INVCODE=A.INVCode
  3151. LEFT JOIN ICSToChecks C
  3152. ON C.BarCode=A.LotNO
  3153. left join ICSITEMLot D
  3154. ON D.LOTNO=A.LotNO
  3155. where A.LotNO='{0}' AND A.INVCode='{1}' AND A.WHCode='{2}' AND A.WorkPoint='{3}'";
  3156. sql = string.Format(sql, BarCode, dt.Rows[i]["ItemCode"].ToString(), dt.Rows[i]["StorageCode"].ToString(), WorkPointCode);
  3157. DataTable lotdt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  3158. if (lotdt.Rows.Count != 0)
  3159. {
  3160. dts = lotdt.Copy();
  3161. }
  3162. }
  3163. }
  3164. #endregion
  3165. return dts;
  3166. }
  3167. /// <summary>
  3168. /// 盘点扫描
  3169. /// </summary>
  3170. /// <param name="sqlConnection"></param>
  3171. /// <param name="trans"></param>
  3172. /// <param name="CheckNo"></param>
  3173. /// <param name="BarCodeList"></param>
  3174. /// <param name="BarCodeQtyList"></param>
  3175. /// <param name="UserCode"></param>
  3176. /// <param name="WorkPointCode"></param>
  3177. /// <param name="Type"></param>
  3178. /// <param name="EditType"></param>
  3179. /// <param name="dsconn"></param>
  3180. /// <returns></returns>
  3181. public static bool CheckIn(SqlConnection sqlConnection, SqlTransaction trans, string CheckNo, string[] BarCodeList, string[] BarCodeQtyList, string userCode, string userName, string WorkPointCode, string Type, string EditType, string dsconn)
  3182. {
  3183. string sql = "";
  3184. string BarCode = "";
  3185. decimal BarCodeQty = 0;
  3186. decimal ItemLotQTY = 0;
  3187. string ConnectString = dsconn;
  3188. int result = 0;
  3189. bool isSuccess = true;
  3190. SqlCommand cmd = new SqlCommand();
  3191. cmd.Connection = sqlConnection;
  3192. cmd.Transaction = trans;
  3193. try
  3194. {
  3195. for (int i = 0; i < BarCodeList.Length; i++)
  3196. {
  3197. BarCode = BarCodeList[i];
  3198. BarCodeQty = Convert.ToDecimal(BarCodeQtyList[i].ToString());
  3199. string INVCode = "";
  3200. string WHCode = "";
  3201. string TranNo = "";
  3202. string TranLine = "";
  3203. decimal LotQty = 0;
  3204. string BinCode = "";
  3205. #region 获取仓库库位等信息
  3206. sql = @"select WHCode
  3207. ,A.LotQty
  3208. ,BinCode
  3209. ,INVCode
  3210. ,B.TransNO
  3211. ,B.TransLine
  3212. from ICSWareHouseLotInfo A
  3213. left join ICSITEMLot B
  3214. on B.LotNO=A.LotNO
  3215. where A.LotNO='{0}' AND A.WorkPoint='{1}'";
  3216. sql = string.Format(sql, BarCode, WorkPointCode);
  3217. DataTable dt = SQlReturnData(sql, cmd);
  3218. if (dt.Rows.Count == 0)
  3219. {
  3220. throw new Exception("获取仓库信息失败!");
  3221. }
  3222. else
  3223. {
  3224. LotQty = Convert.ToDecimal(dt.Rows[0]["LotQty"].ToString());
  3225. INVCode = dt.Rows[0]["INVCode"].ToString();
  3226. WHCode = dt.Rows[0]["WHCode"].ToString();
  3227. TranNo = dt.Rows[0]["TransNO"].ToString();
  3228. TranLine = dt.Rows[0]["TransLine"].ToString();
  3229. BinCode = dt.Rows[0]["BinCode"].ToString();
  3230. }
  3231. #endregion
  3232. #region 更新ICSToCheck表
  3233. sql = @"update ICSToCheck set ActualQty=ActualQty+{0}
  3234. where ToCheckNO='{1}' AND ItemCode='{2}' AND StorageCode='{3}' AND WorkPoint='{4}'";
  3235. sql = string.Format(sql, BarCodeQty, CheckNo, INVCode, WHCode, WorkPointCode);
  3236. cmd.CommandText = sql;
  3237. result = cmd.ExecuteNonQuery();
  3238. if (isSuccess && result <= 0)
  3239. {
  3240. throw new Exception("盘点主表实盘数量增加失败!");
  3241. }
  3242. #endregion
  3243. #region 更新ICSToChecks表
  3244. sql = @"select * from ICSToChecks where BarCode='{0}'";
  3245. sql = string.Format(sql, BarCode);
  3246. dt = SQlReturnData(sql, cmd);
  3247. if (dt.Rows.Count == 0)
  3248. {
  3249. sql = @"insert into ICSToChecks
  3250. values
  3251. (NEWID(),'{0}','{1}',{7},{2},'{3}',GETDATE(),'{4}','{5}','','{6}','insert','{6}',GETDATE())";
  3252. sql = string.Format(sql, INVCode, BarCode, BarCodeQty, userName, WorkPointCode, CheckNo, userCode, LotQty);
  3253. cmd.CommandText = sql;
  3254. result = cmd.ExecuteNonQuery();
  3255. if (isSuccess && result <= 0)
  3256. {
  3257. throw new Exception("盘点子表存入失败!");
  3258. }
  3259. }
  3260. else
  3261. {
  3262. sql = @"update ICSToChecks
  3263. set BarCodeQty={0},Status='Update'
  3264. ,Updater='{1}',UpdateTime=GETDATE()
  3265. where BarCode='{2}'
  3266. update ICSToCheck
  3267. set ActualQty=ActualQty-{3}
  3268. where ToCheckNO='{4}' and ItemCode='{5}' and StorageCode='{6}'
  3269. update ICSToCheck
  3270. set ActualQty=ActualQty+{0}
  3271. where ToCheckNO='{4}' and ItemCode='{5}' and StorageCode='{6}'";
  3272. sql = string.Format(sql, BarCodeQty, userCode, BarCode, Convert.ToDecimal(dt.Rows[0]["BarCodeQty"].ToString()), CheckNo, INVCode, WHCode);
  3273. cmd.CommandText = sql;
  3274. result = cmd.ExecuteNonQuery();
  3275. if (isSuccess && result <= 0)
  3276. {
  3277. throw new Exception("盘点子表复盘数量更新失败!");
  3278. }
  3279. }
  3280. #endregion
  3281. if (EditType == "修正")
  3282. {
  3283. #region 检查原条码数量
  3284. sql = @"select LotQty from ICSWareHouseLotInfo
  3285. where LotNO='{0}' AND WorkPoint='{1}'";
  3286. sql = string.Format(sql, BarCode, WorkPointCode);
  3287. DataTable lotdt = SQlReturnData(sql, cmd);
  3288. ItemLotQTY = Convert.ToDecimal(lotdt.Rows[0]["LotQty"]);
  3289. #endregion
  3290. #region 更新ICSWareHouseInfo表
  3291. sql = @"update ICSWareHouseInfo
  3292. set QTY=QTY-{0},MTIME='{1}'
  3293. where INVCode='{2}' AND WHCode='{3}' AND BinCode='{4}'
  3294. update ICSWareHouseInfo
  3295. set QTY=QTY+{5},MTIME='{1}'
  3296. where INVCode='{2}' AND WHCode='{3}' AND BinCode='{4}'";
  3297. sql = string.Format(sql, LotQty, DateTime.Now, INVCode, WHCode, BinCode, BarCodeQty);
  3298. cmd.CommandText = sql;
  3299. result = cmd.ExecuteNonQuery();
  3300. if (isSuccess && result <= 0)
  3301. {
  3302. throw new Exception("库存主表库存调整失败!");
  3303. }
  3304. #endregion
  3305. #region 更新ICSWareHouseLotInfo表
  3306. sql = @"update ICSWareHouseLotInfo set
  3307. LotQty={0}
  3308. where LotNO='{1}'";
  3309. sql = string.Format(sql, BarCodeQty, BarCode);
  3310. cmd.CommandText = sql;
  3311. result = cmd.ExecuteNonQuery();
  3312. if (isSuccess && result <= 0)
  3313. {
  3314. throw new Exception("库存表库存调整失败!");
  3315. }
  3316. #endregion
  3317. #region 存入ICSWareHouseLotInfoLog表(日志)
  3318. if (BarCodeQty > ItemLotQTY)
  3319. {
  3320. sql = @"insert into ICSWareHouseLotInfoLog(ID,TransNO,TransLine,ITEMCODE,LotNO,FRMStorageCODE,FRMStackCODE,TOStorageCODE,TOStackCODE,TransQTY,TransType,BusinessCode,MUSER,MUSERName,MTIME,WorkPoint)
  3321. Values
  3322. (NEWID(),'{0}','{1}','{2}','{3}','{4}','{5}',null,null,'{6}','','','{7}','{8}',GETDATE(),'{9}')";
  3323. }
  3324. else
  3325. {
  3326. sql = @"insert into ICSWareHouseLotInfoLog(ID,TransNO,TransLine,ITEMCODE,LotNO,FRMStorageCODE,FRMStackCODE,TOStorageCODE,TOStackCODE,TransQTY,TransType,BusinessCode,MUSER,MUSERName,MTIME,WorkPoint)
  3327. Values
  3328. (NEWID(),'{0}','{1}','{2}','{3}','{4}','{5}',null,null,'{6}','','','{7}','{8}',GETDATE(),'{9}')";
  3329. }
  3330. sql = string.Format(sql, CheckNo, "1", INVCode, BarCode, WHCode, BinCode, BarCodeQty - ItemLotQTY, userCode, userName, WorkPointCode);
  3331. cmd.CommandText = sql;
  3332. result = cmd.ExecuteNonQuery();
  3333. if (isSuccess && result <= 0)
  3334. {
  3335. throw new Exception("日志表存入失败!");
  3336. }
  3337. #endregion
  3338. }
  3339. }
  3340. return isSuccess;
  3341. }
  3342. catch (Exception ex)
  3343. {
  3344. throw new Exception(ex.Message);
  3345. }
  3346. }
  3347. /// <summary>
  3348. /// 验证条码信息(其他出库)
  3349. /// </summary>
  3350. /// <param name="lotNo"></param>
  3351. /// <param name="workpointCode"></param>
  3352. /// <param name="dsconn"></param>
  3353. /// <returns></returns>
  3354. public static DataTable CheckLotNoForOtherOut(string lotNo, string workpointCode, string dsconn)
  3355. {
  3356. string sql = @"select LotNO from ICSWareHouseLotInfo
  3357. WHERE LotNO='{0}' AND WorkPoint='{1}'";
  3358. sql = string.Format(sql, lotNo, workpointCode);
  3359. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  3360. return dt;
  3361. }
  3362. /// <summary>
  3363. /// 验证条码信息(其他入库)
  3364. /// </summary>
  3365. /// <param name="lotNo"></param>
  3366. /// <param name="workpointCode"></param>
  3367. /// <param name="dsconn"></param>
  3368. /// <returns></returns>
  3369. public static DataTable CheckLotNoForOtherIN(string TransferNO, string lotNo, string workpointCode, string dsconn)
  3370. {
  3371. string sql = @"select A.LotNO,B.cCode from ICSITEMLot A
  3372. LEFT JOIN ICSRdrecord09s B
  3373. ON B.cCode=A.TransNO AND B.iRSRowNO=A.TransLine AND FREE3='入'
  3374. WHERE A.LotNO='{0}' AND A.WorkPoint='{1}' AND B.cCode='{2}'";
  3375. sql = string.Format(sql, lotNo, workpointCode, TransferNO);
  3376. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  3377. return dt;
  3378. }
  3379. /// <summary>
  3380. /// 验证物料退料库位信息
  3381. /// </summary>
  3382. /// <param name="Stack"></param>
  3383. /// <param name="WHCode"></param>
  3384. /// <param name="workpointCode"></param>
  3385. /// <param name="dsconn"></param>
  3386. /// <returns></returns>
  3387. public static DataTable CheckStackCodeForBack(string Stack, string workpointCode, string dsconn)
  3388. {
  3389. string sql = @"select B.StorageCode from ICSStack A
  3390. LEFT JOIN ICSStorage B
  3391. ON B.Serial=A.Storage_Serial
  3392. WHERE StackCode='{0}' AND A.WorkPoint='{1}'";
  3393. sql = string.Format(sql, Stack, workpointCode);
  3394. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  3395. return dt;
  3396. }
  3397. /// <summary>
  3398. /// 获取其他出库单源头单据信息
  3399. /// </summary>
  3400. /// <param name="TransferNO"></param>
  3401. /// <param name="workpointCode"></param>
  3402. /// <param name="dsconn"></param>
  3403. /// <returns></returns>
  3404. public static DataTable CheckCodeForOtherOut(string TransferNO, string workpointCode, string dsconn)
  3405. {
  3406. string sql = @"select iRSRowNO
  3407. ,cInvCode
  3408. ,B.INVNAME
  3409. ,B.INVSTD
  3410. ,ISNULL(A.iQuantity,0) AS iQuantity
  3411. ,ISNULL(A.iFQuantity,0) AS iFQuantity
  3412. ,B.INVUOM
  3413. ,A.cWhCode
  3414. from ICSRdrecord09s A
  3415. LEFT JOIN ICSINVENTORY B
  3416. ON B.INVCODE=A.cInvCode
  3417. WHERE cCode='{0}' AND Free3='出'";
  3418. sql = string.Format(sql, TransferNO);
  3419. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  3420. return dt;
  3421. }
  3422. /// <summary>
  3423. /// 获取条码信息(其他出库)
  3424. /// </summary>
  3425. /// <param name="BarCode"></param>
  3426. /// <param name="WorkPointCode"></param>
  3427. /// <param name="dsconn"></param>
  3428. /// <returns></returns>
  3429. public static DataTable GetLotDataForOtherOut(string BarCode, string WorkPointCode, string dsconn)
  3430. {
  3431. string sql = @"select A.LotNO
  3432. ,A.WHCode
  3433. ,A.INVCode
  3434. ,B.INVNAME
  3435. ,ISNULL(A.LotQty,0) AS LotQty
  3436. ,A.BinCode
  3437. from ICSWareHouseLotInfo A
  3438. left join ICSINVENTORY B
  3439. ON B.INVCODE=A.INVCode
  3440. WHERE A.LotNO='{0}' AND A.WorkPoint='{1}'";
  3441. sql = string.Format(sql, BarCode, WorkPointCode);
  3442. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  3443. return dt;
  3444. }
  3445. /// <summary>
  3446. /// 获取条码信息(其他入库)
  3447. /// </summary>
  3448. /// <param name="BarCode"></param>
  3449. /// <param name="WorkPointCode"></param>
  3450. /// <param name="dsconn"></param>
  3451. /// <returns></returns>
  3452. public static DataTable GetLotDataForOtherIN(string BarCode, string WorkPointCode, string dsconn)
  3453. {
  3454. string sql = @"select A.LotNO
  3455. ,C.cWhCode
  3456. ,A.ItemCode
  3457. ,B.INVNAME
  3458. ,ISNULL(A.LotQty,0) AS LotQty
  3459. from ICSITEMLot A
  3460. left join ICSINVENTORY B
  3461. ON B.INVCODE=A.ItemCode
  3462. left join ICSRdrecord09s C
  3463. on C.cCode=A.TransNO AND C.iRSRowNO=A.TransLine AND FREE3='入'
  3464. WHERE A.LotNO='{0}' AND A.WorkPoint='{1}'";
  3465. sql = string.Format(sql, BarCode, WorkPointCode);
  3466. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  3467. return dt;
  3468. }
  3469. /// <summary>
  3470. /// 其他出库
  3471. /// </summary>
  3472. /// <param name="POCode"></param>
  3473. /// <param name="porowList"></param>
  3474. /// <param name="poqtyList"></param>
  3475. /// <param name="barcodeList"></param>
  3476. /// <param name="barcodeqtyList"></param>
  3477. /// <param name="bincodeList"></param>
  3478. /// <param name="userCodt"></param>
  3479. /// <param name="workpointCode"></param>
  3480. /// <param name="Type"></param>
  3481. /// <param name="dsconn"></param>
  3482. /// <returns></returns>
  3483. public static bool WareHouseOtherOut(SqlConnection sqlConnection, SqlTransaction trans, string[] barcodeList, string OutType, string userCode, string userName, string workpointCode, string Type, string dsconn)
  3484. {
  3485. string sql = "";
  3486. string BarCode = "";
  3487. string cBarCode = "";
  3488. string Errormessage = "";
  3489. decimal LotQTY = 0;
  3490. string ConnectString = dsconn;
  3491. int result = 0;
  3492. bool isSuccess = true;
  3493. SqlCommand cmd = new SqlCommand();
  3494. cmd.Connection = sqlConnection;
  3495. cmd.Transaction = trans;
  3496. try
  3497. {
  3498. for (int i = 0; i < barcodeList.Length; i++)
  3499. {
  3500. BarCode = barcodeList[i];
  3501. if (cBarCode == "")
  3502. {
  3503. cBarCode += "'" + barcodeList[i] + "'";
  3504. }
  3505. else
  3506. {
  3507. cBarCode += ",'" + barcodeList[i] + "'";
  3508. }
  3509. string INVCode = "";
  3510. string WHCode = "";
  3511. string BinCode = "";
  3512. string TranNo = "";
  3513. string TranLine = "";
  3514. #region 获取仓库库位等信息
  3515. sql = @"select WHCode
  3516. ,BinCode
  3517. ,INVCode
  3518. ,A.LotQty
  3519. ,B.TransNO
  3520. ,B.TransLine
  3521. from ICSWareHouseLotInfo A
  3522. left join ICSITEMLot B
  3523. on B.LotNO=A.LotNO
  3524. where A.LotNO='{0}' AND A.WorkPoint='{1}'";
  3525. sql = string.Format(sql, BarCode, workpointCode);
  3526. DataTable dt = SQlReturnData(sql, cmd);
  3527. if (dt.Rows.Count == 0)
  3528. {
  3529. throw new Exception("获取仓库信息失败!");
  3530. }
  3531. else
  3532. {
  3533. LotQTY = Convert.ToDecimal(dt.Rows[0]["LotQty"].ToString());
  3534. INVCode = dt.Rows[0]["INVCode"].ToString();
  3535. BinCode = dt.Rows[0]["BinCode"].ToString();
  3536. WHCode = dt.Rows[0]["WHCode"].ToString();
  3537. TranNo = dt.Rows[0]["TransNO"].ToString();
  3538. TranLine = dt.Rows[0]["TransLine"].ToString();
  3539. }
  3540. #endregion
  3541. #region 更新ICSWareHouseInfo表
  3542. sql = @"update ICSWareHouseInfo
  3543. set QTY=QTY-{0},MTIME='{1}'
  3544. where INVCode='{2}' AND WHCode='{3}' AND BinCode='{4}'";
  3545. sql = string.Format(sql, LotQTY, DateTime.Now, INVCode, WHCode, BinCode);
  3546. cmd.CommandText = sql;
  3547. result = cmd.ExecuteNonQuery();
  3548. if (isSuccess && result <= 0)
  3549. {
  3550. throw new Exception("库存主表更新失败!");
  3551. }
  3552. #endregion
  3553. #region 更新ICSWareHouseLotInfo表
  3554. sql = @"update ICSWareHouseLotInfo
  3555. set LotQty=LotQty-{0}
  3556. where LotNO='{1}'
  3557. and WorkPoint='{2}'";
  3558. sql = string.Format(sql, LotQTY, BarCode, workpointCode);
  3559. cmd.CommandText = sql;
  3560. result = cmd.ExecuteNonQuery();
  3561. if (isSuccess && result <= 0)
  3562. {
  3563. throw new Exception("库存子表更新失败!");
  3564. }
  3565. #endregion
  3566. #region 存入ICSWareHouseLotInfoLog表(日志)
  3567. sql = @"insert into ICSWareHouseLotInfoLog
  3568. Values
  3569. (NEWID(),'{0}','{1}','{2}','{3}','{9}','{10}','',''
  3570. ,{4},null,'{5}','','{6}','{7}',GETDATE(),'{8}','','','','','')";
  3571. sql = string.Format(sql, "", "", INVCode, BarCode, LotQTY, Type, userCode, userName, workpointCode, WHCode, BinCode);
  3572. cmd.CommandText = sql;
  3573. result = cmd.ExecuteNonQuery();
  3574. if (isSuccess && result <= 0)
  3575. {
  3576. throw new Exception("日志表存入失败!");
  3577. }
  3578. #endregion
  3579. }
  3580. }
  3581. catch (Exception ex)
  3582. {
  3583. throw new Exception(ex.Message);
  3584. }
  3585. if (message == "Open")
  3586. {
  3587. #region WEBAPI接口调用
  3588. // try
  3589. // {
  3590. // sql = @"select INVCode,WHCode,A.LotQty,B.VenderLotNO from ICSWareHouseLotInfo A
  3591. // LEFT JOIN ICSITEMLot B
  3592. // ON B.LotNO=A.LotNO
  3593. // where A.LotNO in ({0})
  3594. // Order by INVCode,WHCode";
  3595. // sql = string.Format(sql, cBarCode);
  3596. // DataTable dt = SQlReturnData(sql, cmd);
  3597. // List<RdRecord09> contextlist = new List<RdRecord09>();
  3598. // RdRecord09 context = new RdRecord09();
  3599. // List<rdrecords09> contextlists = new List<rdrecords09>();
  3600. // rdrecords09 contexts = new rdrecords09();
  3601. // string WareHouse = "";
  3602. // string ItemCode = "";
  3603. // for (int i = 0; i < dt.Rows.Count; i++)
  3604. // {
  3605. // if (WareHouse != dt.Rows[i]["WHCode"].ToString() || ItemCode != dt.Rows[i]["INVCode"].ToString())
  3606. // {
  3607. // if (i > 0)
  3608. // {
  3609. // context.list = contextlists;
  3610. // contextlist.Add(context);
  3611. // }
  3612. // context = new RdRecord09();
  3613. // WareHouse = dt.Rows[0]["WHCode"].ToString();
  3614. // ItemCode = dt.Rows[0]["INVCode"].ToString();
  3615. // context.cWhCode = dt.Rows[0]["WHCode"].ToString();
  3616. // context.cRdCode = OutType;
  3617. // context.UserCode = userCode;
  3618. // contextlists = new List<rdrecords09>();
  3619. // }
  3620. // contexts = new rdrecords09();
  3621. // contexts.iQuantity = Convert.ToDecimal(dt.Rows[0]["LotQty"].ToString());
  3622. // contexts.cInvCode = dt.Rows[0]["INVCode"].ToString();
  3623. // contextlists.Add(contexts);
  3624. // if (i == dt.Rows.Count - 1)
  3625. // {
  3626. // context.list = contextlists;
  3627. // contextlist.Add(context);
  3628. // }
  3629. // }
  3630. // string Istr = JsonConvert.SerializeObject(contextlist);
  3631. // string iresult = HttpPost(IOtherOut, Istr);
  3632. // Result OtherOutResult = new Result();
  3633. // OtherOutResult = JsonConvert.DeserializeObject<Result>(iresult);
  3634. // if (OtherOutResult.code != "200")
  3635. // {
  3636. // throw new Exception(OtherOutResult.msg);
  3637. // }
  3638. // }
  3639. // catch (Exception ex)
  3640. // {
  3641. // throw new Exception(ex.Message);
  3642. // }
  3643. #endregion
  3644. }
  3645. return isSuccess;
  3646. }
  3647. /// <summary>
  3648. /// 验证条码信息(物料退料)
  3649. /// </summary>
  3650. /// <param name="BarCode"></param>
  3651. /// <param name="workpointCode"></param>
  3652. /// <param name="dsconn"></param>
  3653. /// <returns></returns>
  3654. public static DataTable CheckLotnoForINVIN(string BarCode, string workpointCode, string dsconn)
  3655. {
  3656. string sql = @"select A.VouchCode
  3657. ,A.VouchRow
  3658. ,A.InvCode
  3659. ,C.INVNAME
  3660. ,C.INVSTD
  3661. ,D.LOTNO AS WHLOTNO
  3662. ,ISNULL(B.LOTQTY,0) LOTQTY
  3663. ,ISNULL(A.Quantity,0) Quantity
  3664. ,ISNULL(A.HasQuantity,0) HasQuantity
  3665. ,C.INVUOM
  3666. ,A.WHCode
  3667. ,ISNULL(E.IsMROItem,0) AS IsMROItem
  3668. from ICSMaterialPick A
  3669. LEFT JOIN ICSITEMLot B
  3670. ON B.TransNO=A.VouchCode AND B.TransLine=A.VouchRow
  3671. LEFT JOIN ICSINVENTORY C
  3672. ON C.INVCODE=A.InvCode
  3673. LEFT JOIN ICSWareHouseLotInfo D
  3674. ON D.LOTNO=B.LOTNO
  3675. LEFT JOIN ICSMaterial E
  3676. ON E.VouchCode=A.VouchCode
  3677. WHERE B.LotNO='{0}' AND A.WorkPoint='{1}' AND A.MoveType='退'";
  3678. sql = string.Format(sql, BarCode, workpointCode);
  3679. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  3680. return dt;
  3681. }
  3682. /// <summary>
  3683. /// 获取其他入库单源头单据信息
  3684. /// </summary>
  3685. /// <param name="TransferNO"></param>
  3686. /// <param name="workpointCode"></param>
  3687. /// <param name="dsconn"></param>
  3688. /// <returns></returns>
  3689. public static DataTable CheckCodeForOtherIN(string TransferNO, string workpointCode, string dsconn)
  3690. {
  3691. string sql = @"select iRSRowNO
  3692. ,cInvCode
  3693. ,B.INVNAME
  3694. ,B.INVSTD
  3695. ,ISNULL(A.iQuantity,0) AS iQuantity
  3696. ,ISNULL(A.iFQuantity,0) AS iFQuantity
  3697. ,B.INVUOM
  3698. ,A.cWhCode
  3699. from ICSRdrecord09s A
  3700. LEFT JOIN ICSINVENTORY B
  3701. ON B.INVCODE=A.cInvCode
  3702. WHERE cCode='{0}' AND Free3='入'";
  3703. sql = string.Format(sql, TransferNO);
  3704. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  3705. return dt;
  3706. }
  3707. /// <summary>
  3708. /// 获取用户信息
  3709. /// </summary>
  3710. /// <param name="UserCode"></param>
  3711. /// <param name="WorkPoint"></param>
  3712. /// <param name="dsconn"></param>
  3713. /// <returns></returns>
  3714. public static DataTable GetUserInfo(string UserCode, string WorkPoint, string dsconn)
  3715. {
  3716. string sql = @"select UserCode,UserName from Sys_User
  3717. where UserCode='{0}' AND WorkPointCode='{1}'";
  3718. sql = string.Format(sql, UserCode, WorkPoint);
  3719. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  3720. return dt;
  3721. }
  3722. /// <summary>
  3723. /// 其他入库
  3724. /// </summary>
  3725. /// <param name="POCode"></param>
  3726. /// <param name="porowList"></param>
  3727. /// <param name="poqtyList"></param>
  3728. /// <param name="barcodeList"></param>
  3729. /// <param name="barcodeqtyList"></param>
  3730. /// <param name="bincodeList"></param>
  3731. /// <param name="userCodt"></param>
  3732. /// <param name="workpointCode"></param>
  3733. /// <param name="Type"></param>
  3734. /// <param name="dsconn"></param>
  3735. /// <returns></returns>
  3736. public static bool WareHouseOtherIN(SqlConnection sqlConnection, SqlTransaction trans, string POCode, string[] porowList, string[] poqtyList, string[] barcodeRowList, string[] barcodeList, string[] barcodeqtyList, string[] bincodelist, string userCode, string userName, string workpointCode, string Type, string dsconn)
  3737. {
  3738. string sql = "";
  3739. string BarCode = "";
  3740. decimal BarCodeQty = 0;
  3741. string BarCodeRow = "";
  3742. string cBarCode = "";
  3743. string Errormessage = "";
  3744. string PORow = "";
  3745. decimal POQty = 0;
  3746. string NewBinCode = "";
  3747. string ConnectString = dsconn;
  3748. int result = 0;
  3749. bool isSuccess = true;
  3750. SqlCommand cmd = new SqlCommand();
  3751. cmd.Connection = sqlConnection;
  3752. cmd.Transaction = trans;
  3753. try
  3754. {
  3755. for (int i = 0; i < porowList.Length; i++)
  3756. {
  3757. #region 更新ICSRdrecord09s表
  3758. PORow = porowList[i];
  3759. POQty = Convert.ToDecimal(poqtyList[i]);
  3760. sql = @"update ICSRdrecord09s set iQuantity=iQuantity+{0}
  3761. where cCode='{1}' and iRSRowNO='{2}'";
  3762. sql = string.Format(sql, POQty, POCode, PORow);
  3763. cmd.CommandText = sql;
  3764. result = cmd.ExecuteNonQuery();
  3765. if (isSuccess && result <= 0)
  3766. {
  3767. throw new Exception("源头单据更新失败!");
  3768. }
  3769. #endregion
  3770. }
  3771. for (int i = 0; i < barcodeList.Length; i++)
  3772. {
  3773. string INVCode = "";
  3774. string WHCode = "";
  3775. string BinCode = "";
  3776. string TranNo = "";
  3777. string TranLine = "";
  3778. BarCode = barcodeList[i];
  3779. BarCodeQty = Convert.ToDecimal(barcodeqtyList[i]);
  3780. BarCodeRow = barcodeRowList[i];
  3781. BinCode = bincodelist[i];
  3782. if (cBarCode == "")
  3783. {
  3784. cBarCode += "'" + barcodeList[i] + "'";
  3785. }
  3786. else
  3787. {
  3788. cBarCode += ",'" + barcodeList[i] + "'";
  3789. }
  3790. #region 获取仓库库位等信息
  3791. sql = @"select A.cWhCode
  3792. ,B.ItemCode
  3793. ,B.TransNO
  3794. ,B.TransLine
  3795. from ICSRdrecord09s A
  3796. left join ICSITEMLot B
  3797. on B.TransNO=A.cCode AND B.TransLine=A.iRSRowNO
  3798. where B.LotNO='{0}' AND B.WorkPoint='{1}'";
  3799. sql = string.Format(sql, BarCode, workpointCode);
  3800. DataTable dt = SQlReturnData(sql, cmd);
  3801. if (dt.Rows.Count == 0)
  3802. {
  3803. throw new Exception("获取仓库信息失败!");
  3804. }
  3805. else
  3806. {
  3807. INVCode = dt.Rows[0]["ItemCode"].ToString();
  3808. WHCode = dt.Rows[0]["cWhCode"].ToString();
  3809. TranNo = dt.Rows[0]["TransNO"].ToString();
  3810. TranLine = dt.Rows[0]["TransLine"].ToString();
  3811. }
  3812. #endregion
  3813. #region 更新ICSWareHouseInfo表
  3814. sql = @"update ICSWareHouseInfo
  3815. set QTY=QTY+{0},MTIME='{1}'
  3816. where INVCode='{2}' AND WHCode='{3}' AND BinCode='{4}'";
  3817. sql = string.Format(sql, BarCodeQty, DateTime.Now, INVCode, WHCode, BinCode);
  3818. cmd.CommandText = sql;
  3819. result = cmd.ExecuteNonQuery();
  3820. if (isSuccess && result <= 0)
  3821. {
  3822. sql = @"insert into ICSWareHouseInfo
  3823. values
  3824. ((select Serial from ICSStorage where StorageCode='{0}')
  3825. ,'{0}'
  3826. ,(SELECT Serial FROM ICSStack WHERE StackCode='{1}')
  3827. ,'{1}'
  3828. ,(SELECT ID FROM ICSINVENTORY WHERE INVCODE='{2}')
  3829. ,'{2}',{3},'{4}','{5}','{6}',GETDATE(),NULL)";
  3830. sql = string.Format(sql, WHCode, BinCode, INVCode, BarCodeQty, workpointCode, userCode, userName);
  3831. cmd.CommandText = sql;
  3832. result = cmd.ExecuteNonQuery();
  3833. if (isSuccess && result <= 0)
  3834. {
  3835. throw new Exception("库存主表存入失败!");
  3836. }
  3837. }
  3838. #endregion
  3839. #region 更新ICSWareHouseLotInfo表
  3840. sql = @"update ICSWareHouseLotInfo
  3841. set LotQty=LotQty+{0}
  3842. where LotNO='{1}'
  3843. and WorkPoint='{2}'";
  3844. sql = string.Format(sql, BarCodeQty, BarCode, workpointCode);
  3845. cmd.CommandText = sql;
  3846. result = cmd.ExecuteNonQuery();
  3847. if (isSuccess && result <= 0)
  3848. {
  3849. sql = @"insert into ICSWareHouseLotInfo
  3850. Values
  3851. (NEWID(),'{0}',
  3852. (select Serial from ICSStorage where StorageCode='{1}'),
  3853. '{1}',
  3854. (SELECT Serial FROM ICSStack WHERE StackCode='{2}'),
  3855. '{2}',
  3856. (SELECT ID FROM ICSINVENTORY WHERE INVCODE='{3}'),
  3857. '{3}',{4},GETDATE(),'{5}','{6}','{7}',GETDATE(),'','','')";
  3858. sql = string.Format(sql, BarCode, WHCode, BinCode, INVCode, BarCodeQty, workpointCode, userCode, userName);
  3859. cmd.CommandText = sql;
  3860. result = cmd.ExecuteNonQuery();
  3861. if (isSuccess && result <= 0)
  3862. {
  3863. throw new Exception("库存子表存入失败!");
  3864. }
  3865. }
  3866. #endregion
  3867. #region 存入ICSWareHouseLotInfoLog表(日志)
  3868. sql = @"insert into ICSWareHouseLotInfoLog
  3869. Values
  3870. (NEWID(),'{0}','{1}','{2}','{3}','','','{9}','{10}'
  3871. ,{4},null,'{5}','','{6}','{7}',GETDATE(),'{8}','','','','','')";
  3872. sql = string.Format(sql, POCode, BarCodeRow, INVCode, BarCode, BarCodeQty, Type, userCode, userName, workpointCode, WHCode, BinCode);
  3873. cmd.CommandText = sql;
  3874. result = cmd.ExecuteNonQuery();
  3875. if (isSuccess && result <= 0)
  3876. {
  3877. throw new Exception("日志表存入失败!");
  3878. }
  3879. #endregion
  3880. }
  3881. }
  3882. catch (Exception ex)
  3883. {
  3884. throw new Exception(ex.Message);
  3885. }
  3886. if (message == "Open")
  3887. {
  3888. #region 接口调用
  3889. // try
  3890. // {
  3891. // sql = @"select ID,
  3892. // cCode,
  3893. // cWhCode,
  3894. // cInvCode,
  3895. // AutoID,
  3896. // cBatch
  3897. // from ICSRdrecord09s
  3898. // where cCode='{0}' AND Free3='入'
  3899. // ORDER BY iRSRowNO";
  3900. // sql = string.Format(sql, POCode);
  3901. // DataTable dt = SQlReturnData(sql, cmd);
  3902. // List<ZYPDAServiceForOtherIN.Rdrecord08> contextList = new List<ZYPDAServiceForOtherIN.Rdrecord08>();
  3903. // List<ZYPDAServiceForOtherIN.Rdrecords08> contextLists = new List<ZYPDAServiceForOtherIN.Rdrecords08>();
  3904. // ZYPDAServiceForOtherIN.Rdrecord08 context = new ZYPDAServiceForOtherIN.Rdrecord08();
  3905. // ZYPDAServiceForOtherIN.Rdrecords08 contexts = new ZYPDAServiceForOtherIN.Rdrecords08();
  3906. // string WareHouse = "";
  3907. // for (int i = 0; i < dt.Rows.Count; i++)
  3908. // {
  3909. // if (WareHouse != dt.Rows[i]["cWhCode"].ToString())
  3910. // {
  3911. // if (i > 0)
  3912. // {
  3913. // context.bodyList = contextLists.ToArray();
  3914. // contextList.Add(context);
  3915. // }
  3916. // context = new ZYPDAServiceForOtherIN.Rdrecord08();
  3917. // WareHouse = dt.Rows[i]["cWhCode"].ToString();
  3918. // context.ID = dt.Rows[i]["ID"].ToString();
  3919. // context.cCode = dt.Rows[i]["cCode"].ToString();
  3920. // context.cWhCode = dt.Rows[i]["cWhCode"].ToString();
  3921. // context.UserCode = userCode;
  3922. // contextLists = new List<ZYPDAServiceForOtherIN.Rdrecords08>();
  3923. // }
  3924. // contexts = new ZYPDAServiceForOtherIN.Rdrecords08();
  3925. // contexts.cInvCode = dt.Rows[i]["cInvCode"].ToString();
  3926. // contexts.iQuantity = Convert.ToDecimal(poqtyList[i].ToString());
  3927. // contexts.cBatch = dt.Rows[i]["cBatch"].ToString();
  3928. // contexts.AutoID = dt.Rows[i]["AutoID"].ToString();
  3929. // contextLists.Add(contexts);
  3930. // if (i == dt.Rows.Count - 1)
  3931. // {
  3932. // context.bodyList = contextLists.ToArray();
  3933. // contextList.Add(context);
  3934. // }
  3935. // }
  3936. // ZYPDAServiceForOtherIN.VerifiRd08Client client = new ZYPDAServiceForOtherIN.VerifiRd08Client();
  3937. // ZYPDAServiceForOtherIN.Result cresult = new ZYPDAServiceForOtherIN.Result();
  3938. // cresult = client.Verifi08(contextList.ToArray());
  3939. // if (cresult.IsSuccess == false)
  3940. // {
  3941. // throw new Exception(cresult.MESSAGE);
  3942. // }
  3943. // }
  3944. // catch (Exception ex)
  3945. // {
  3946. // throw new Exception(ex.Message);
  3947. // }
  3948. #endregion
  3949. }
  3950. return isSuccess;
  3951. }
  3952. /// <summary>
  3953. /// 先进先出批次管控
  3954. /// </summary>
  3955. /// <param name="LotNo"></param>
  3956. /// <param name="WorkPoitCode"></param>
  3957. /// <param name="dsconn"></param>
  3958. /// <returns></returns>
  3959. public static string CanOut(string LotNo, string WorkPoitCode, string dsconn)
  3960. {
  3961. try
  3962. {
  3963. string sql = @"DECLARE @CountNO INT
  3964. SET @CountNO=(
  3965. SELECT
  3966. COUNT(LotNO)
  3967. FROM
  3968. ICSWareHouseLotInfo a
  3969. WHERE CONVERT(varchar(100), MTIME, 23)<(SELECT CONVERT(varchar(100), MTIME, 23) FROM ICSWareHouseLotInfo WHERE INVCode=a.INVCode AND LotNO='{0}' AND WorkPoint='{1}' AND ISNULL(LotQty,0)>0)
  3970. AND WorkPoint='{1}' AND ISNULL(LotQty,0)>0
  3971. )
  3972. IF @CountNO>0
  3973. BEGIN
  3974. SELECT TOP 1 CASE EnumValue WHEN '0000501' THEN '1' WHEN '0000502' THEN '2' ELSE '3' END AS Type
  3975. FROM Sys_EnumValues
  3976. WHERE EnumKey='00005' AND StartFlag='1'
  3977. ORDER BY ID DESC
  3978. END
  3979. ELSE
  3980. BEGIN
  3981. SELECT @CountNO
  3982. END";
  3983. //0 - 已经是最早的批次
  3984. //1 - 不管控
  3985. //2 - 提醒
  3986. //3 - 限制
  3987. sql = string.Format(sql, LotNo, WorkPoitCode);
  3988. DataTable whDt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  3989. if (whDt == null || whDt.Rows.Count == 0)
  3990. {
  3991. throw new Exception("查询管控信息失败!!");
  3992. }
  3993. else
  3994. return whDt.Rows[0][0].ToString();
  3995. }
  3996. catch (Exception ex)
  3997. {
  3998. throw new Exception(ex.Message);
  3999. }
  4000. }
  4001. /// <summary>
  4002. /// 接口调用方法
  4003. /// </summary>
  4004. /// <param name="url"></param>
  4005. /// <param name="body"></param>
  4006. /// <returns></returns>
  4007. public static string HttpPost(string url, string body)
  4008. {
  4009. try
  4010. {
  4011. Encoding encoding = Encoding.UTF8;
  4012. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  4013. request.Method = "POST";
  4014. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  4015. request.ContentType = "application/json; charset=utf-8";
  4016. byte[] buffer = encoding.GetBytes(body);
  4017. request.ContentLength = buffer.Length;
  4018. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  4019. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  4020. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  4021. {
  4022. return reader.ReadToEnd();
  4023. }
  4024. }
  4025. catch (WebException ex)
  4026. {
  4027. var res = (HttpWebResponse)ex.Response;
  4028. StringBuilder sb = new StringBuilder();
  4029. StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
  4030. sb.Append(sr.ReadToEnd());
  4031. //string ssb = sb.ToString();
  4032. throw new Exception(sb.ToString());
  4033. }
  4034. }
  4035. #region
  4036. public static DataTable FormINVSer(string INVCode, string WorkPoint, string dsconn)
  4037. {
  4038. string sql = @"select A.WHCode
  4039. , A.BinCode
  4040. , A.INVCode
  4041. , B.INVNAME
  4042. , B.INVSTD
  4043. , A.LotQty
  4044. ,C.BinQTY
  4045. ,D.WHLotQTY
  4046. ,E.VenderLotNO
  4047. from ICSWareHouseLotInfo A
  4048. LEFT JOIN ICSINVENTORY B
  4049. ON B.INVCODE=A.INVCode
  4050. LEFT JOIN ICSITEMLot E
  4051. ON E.LotNO=A.LotNO
  4052. LEFT JOIN (select SUM(LotQty) as BinQTY,BinCode from ICSWareHouseLotInfo
  4053. where BinCode IN
  4054. (select BinCode from ICSWareHouseLotInfo
  4055. where INVCode=
  4056. (select INVCode from ICSWareHouseLotInfo
  4057. where LotNO='{0}'
  4058. AND WorkPoint='{1}')
  4059. AND WorkPoint='{1}')
  4060. AND INVCode=
  4061. (select INVCode from ICSWareHouseLotInfo
  4062. where LotNO='{0}'
  4063. AND WorkPoint='{1}') GROUP BY BinCode) C
  4064. ON C.BinCode=A.BinCode
  4065. LEFT JOIN (select Sum(LotQty) AS WHLotQTY,INVCode from ICSWareHouseLotInfo
  4066. where INVCode =
  4067. (select INVCode from ICSWareHouseLotInfo
  4068. where LotNO='{0}'
  4069. AND WorkPoint='{1}') GROUP BY INVCode) D
  4070. ON D.INVCode=A.INVCode
  4071. WHERE A.INVCode=
  4072. (select ItemCode from ICSITEMLot
  4073. where LotNO='{0}'
  4074. AND WorkPoint='{1}')
  4075. AND A.WorkPoint='{1}' AND A.LotQty > 0";
  4076. sql = string.Format(sql, INVCode, WorkPoint);
  4077. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  4078. return dt;
  4079. }
  4080. public static DataTable FormBinSer(string BinCode, string WorkPoint, string dsconn)
  4081. {
  4082. string sql = @"SELECT A.WHCode, A.BinCode, A.INVCode, B.INVNAME, B.INVSTD, A.LotQty, B.INVUOM,C.VenderLotNO
  4083. FROM ICSWareHouseLotInfo A LEFT JOIN ICSINVENTORY B ON A.INVCode = B.INVCODE
  4084. LEFT JOIN ICSITEMLot C ON C.LotNO=A.LotNO
  4085. WHERE 1=1 AND A.BinCode = '{0}' AND A.WorkPoint = '{1}' AND A.LotQty > 0 ";
  4086. sql = string.Format(sql, BinCode, WorkPoint);
  4087. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  4088. return dt;
  4089. }
  4090. public static DataTable FormLotSer(string LotNO, string WorkPoint, string dsconn)
  4091. {
  4092. string sql = @"SELECT A.WHCode, A.BinCode, A.INVCode, B.INVNAME, B.INVSTD, A.LotQty, B.INVUOM,
  4093. QTY = (SELECT SUM(C.QTY) FROM ICSWareHouseInfo C LEFT JOIN ICSWareHouseLotInfo D ON C.INVCode = D.INVCode
  4094. WHERE 1=1 AND D.LotNO = '{0}' AND D.WorkPoint = '{1}')
  4095. FROM ICSWareHouseLotInfo A LEFT JOIN ICSINVENTORY B ON A.INVCode = B.INVCODE
  4096. WHERE 1=1 AND A.LotNO = '{0}' AND A.WorkPoint = '{1}' ";
  4097. sql = string.Format(sql, LotNO, WorkPoint);
  4098. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  4099. return dt;
  4100. }
  4101. #endregion
  4102. }
  4103. }