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.

4805 lines
311 KiB

1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
1 year ago
12 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
11 months ago
11 months ago
1 year ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.Linq;
  9. using System.Net.Http;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace ICSSoft.DataProject
  13. {
  14. /// <summary>
  15. /// 使用中
  16. /// 更新库存表、日志表
  17. /// </summary>
  18. public class ICSWareHouseLotInfoService
  19. {
  20. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  21. /// <summary>
  22. /// 分批
  23. /// </summary>
  24. /// <param name="Identification"></param>
  25. /// <param name="TransCode"></param>
  26. /// <param name="TransSequence"></param>
  27. /// <param name="LotNo"></param>
  28. /// <param name="Quantity"></param>
  29. /// <param name="User"></param>
  30. /// <param name="WorkPoint"></param>
  31. /// <param name="TransType"></param>
  32. /// <param name="BusinessCode"></param>
  33. /// <param name="cmd"></param>
  34. public static void WareHouseLotInfoInBatches(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
  35. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID = "")
  36. {
  37. }
  38. /// <summary>
  39. /// 添加库存
  40. /// </summary>
  41. /// <param name="LocationCode"></param>
  42. /// <param name="LotNo"></param>
  43. /// <param name="Quantity"></param>
  44. /// <param name="User"></param>
  45. /// <param name="WorkPoint"></param>
  46. /// <param name="TransType"></param>
  47. /// <param name="BusinessCode"></param>
  48. /// <param name="cmd"></param>
  49. /// <param name="jointLotNo"></param>
  50. public static void WareHouseLotInfoUp(string Identification, string LocationCode, string LotNo, string Quantity, string User,
  51. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string LogID,string jointLotNo, string TransCode, string TransSequence)
  52. {
  53. try
  54. {
  55. #region 正常入库
  56. ///添加库存(原条码退回,更新库存;新条码直接入库)
  57. //stirng locationcode = "";
  58. string sql = string.Empty;
  59. string locationcode = "";
  60. if (BusinessCode != TransTypeEnum.SalesReturnBack.GetDescription<DBValue>())
  61. {
  62. if (string.IsNullOrWhiteSpace(LogID))
  63. {
  64. sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  65. BEGIN
  66. RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
  67. RETURN
  68. END ";
  69. }
  70. else
  71. {
  72. sql = @"SELECT LocationCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  73. sql = string.Format(sql, LotNo, WorkPoint);
  74. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  75. if (dt == null || dt.Rows.Count <= 0)
  76. {
  77. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
  78. }
  79. locationcode = dt.Rows[0]["LocationCode"].ToString();
  80. }
  81. }
  82. if (BusinessCode == TransTypeEnum.MOStockINByProductNoTrans.GetDescription<DBValue>())
  83. {
  84. sql += @" IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  85. BEGIN
  86. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  87. RETURN
  88. END
  89. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  90. BEGIN
  91. IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity=0)
  92. BEGIN
  93. UPDATE a SET a.Quantity=ISNULL(a.Quantity,0)+'{3}',WarehouseCode=e.WarehouseCode,LocationCode=d.LocationCode
  94. From ICSWareHouseLotInfo a
  95. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  96. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  97. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  98. END
  99. ELSE IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.LocationCode='{4}')
  100. BEGIN
  101. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
  102. WHERE LotNo='{0}' AND WorkPoint='{1}'
  103. END
  104. ELSE IF('" + locationcode + @"' != '{4}')
  105. BEGIN
  106. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo395"), "{4}", locationcode) + @"', 16, 1);
  107. RETURN
  108. END
  109. END
  110. ELSE
  111. BEGIN
  112. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  113. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  114. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  115. BEGIN
  116. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  117. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  118. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}' AND il.LocationCode='{4}')
  119. BEGIN
  120. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  121. RETURN
  122. END
  123. END
  124. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  125. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  126. FROM ICSInventoryLot a
  127. LEFT JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  128. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  129. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  130. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  131. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  132. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  133. END";
  134. }
  135. else
  136. {
  137. sql += @" IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  138. BEGIN
  139. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  140. RETURN
  141. END
  142. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  143. BEGIN
  144. IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity=0)
  145. BEGIN
  146. UPDATE a SET a.Quantity=ISNULL(a.Quantity,0)+'{3}',WarehouseCode=e.WarehouseCode,LocationCode=d.LocationCode
  147. From ICSWareHouseLotInfo a
  148. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  149. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  150. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  151. END
  152. ELSE IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.LocationCode='{4}')
  153. BEGIN
  154. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
  155. WHERE LotNo='{0}' AND WorkPoint='{1}'
  156. END
  157. ELSE IF('" + locationcode + @"' != '{4}')
  158. BEGIN
  159. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo395"), "{4}", locationcode) + @"', 16, 1);
  160. RETURN
  161. END
  162. END
  163. ELSE
  164. BEGIN
  165. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  166. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  167. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  168. BEGIN
  169. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  170. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  171. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}' AND il.LocationCode='{4}')
  172. BEGIN
  173. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  174. RETURN
  175. END
  176. END
  177. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  178. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  179. FROM ICSInventoryLot a
  180. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  181. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  182. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  183. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  184. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  185. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  186. END";
  187. }
  188. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode);
  189. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  190. {
  191. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  192. }
  193. if (BusinessCode == TransTypeEnum.MOStockINByProductNoTrans.GetDescription<DBValue>())
  194. {
  195. ///添加日志
  196. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  197. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  198. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  199. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  200. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  201. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  202. '','',c.WarehouseCode,c.LocationCode,'{6}',
  203. '','0','{4}','{5}','0','',
  204. '','','',f.F_Account ,f.F_RealName ,
  205. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  206. FROM ICSInventoryLot a
  207. LEFT JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  208. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  209. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  210. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  211. ";
  212. }
  213. else
  214. {
  215. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  216. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  217. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  218. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  219. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  220. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  221. '','',c.WarehouseCode,c.LocationCode,'{6}',
  222. '','0','{4}','{5}','0','',
  223. '','','',f.F_Account ,f.F_RealName ,
  224. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  225. FROM ICSInventoryLot a
  226. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  227. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  228. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  229. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  230. ";
  231. }
  232. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
  233. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  234. {
  235. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  236. }
  237. #endregion
  238. #region 管控方式是"料品"时
  239. ControlMode mode = ICSControlModeService.GetControlMode();
  240. if (mode.itemCode.Equals("ControlMode02"))
  241. {
  242. //查询是否存在料品管控的条码
  243. string sqlStrNew = @"SELECT a.ID,
  244. con.ContainerCode,
  245. con.ContainerName,
  246. a.LotNo,
  247. a.InvCode,
  248. inv.InvName,
  249. inv.InvStd,
  250. inv.InvUnit,-- {0}
  251. inv.AmountUnit,
  252. ext.ID AS ExtensionID,
  253. ext.ProjectCode,
  254. ext.Version,
  255. ext.BatchCode,
  256. ext.Brand,
  257. ext.cFree1,
  258. ext.cFree2,
  259. ext.cFree3,
  260. ext.cFree4,
  261. ext.cFree5,
  262. ext.cFree6,
  263. ext.cFree7,
  264. ext.cFree8,
  265. ext.cFree9,
  266. ext.cFree10,
  267. a.MUSER AS [ USER ],
  268. a.MTIME AS [ MTime ]
  269. FROM
  270. ICSInventoryLot a
  271. LEFT JOIN ICSContainerLot conlot ON a.LotNo = conlot.LotNo AND a.WorkPoint = conlot.WorkPoint
  272. LEFT JOIN ICSContainer con ON conlot.ContainerID = con.ID AND conlot.WorkPoint = con.WorkPoint
  273. INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint
  274. INNER JOIN ICSExtension ext ON a.ExtensionID = ext.ID AND a.WorkPoint = ext.WorkPoint
  275. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  276. sqlStrNew = string.Format(sqlStrNew, jointLotNo, WorkPoint);
  277. DataTable table = DBHelper.SQlReturnData(sqlStrNew, cmd);
  278. string json = JsonConvert.SerializeObject(table);
  279. List<LotNoMode> modelNew = JsonConvert.DeserializeObject<List<LotNoMode>>(json);
  280. //当不存在料品管控条码时,生成新条码
  281. if (!(modelNew.Count > 0))
  282. {
  283. //获取旧条码的信息
  284. string jsonStr = ICSControlModeService.QueryLotNo(LotNo, WorkPoint);
  285. List<LotNoMode> model = JsonConvert.DeserializeObject<List<LotNoMode>>(jsonStr);
  286. //在条码表中插入一条新数据,在条码表中插入一条新数据,并在库存表中添加新数据
  287. LotNoMode lotNoMode = model[0];
  288. CreateLotNo(jointLotNo, Quantity, "", "", WorkPoint, Identification, User, lotNoMode.InvCode, BusinessCode, lotNoMode.ProjectCode, lotNoMode.BatchCode,
  289. lotNoMode.Version, lotNoMode.Brand, lotNoMode.cFree1, lotNoMode.cFree2, lotNoMode.cFree3, lotNoMode.cFree4, lotNoMode.cFree5, lotNoMode.cFree6, lotNoMode.cFree7,
  290. lotNoMode.cFree8, lotNoMode.cFree9, lotNoMode.cFree10, cmd, language, LocationCode, LotNo);
  291. }
  292. try
  293. {
  294. //合并前日志
  295. WareHouseLotInfoLog(Identification, jointLotNo, User, WorkPoint, "2",
  296. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(),"", cmd, language);
  297. //更新目标条码库存
  298. WareHouseLotInfoMerge(Identification, jointLotNo, LotNo, Quantity, User, WorkPoint, "2",
  299. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  300. //合并后日志
  301. WareHouseLotInfoLog(Identification, jointLotNo, User, WorkPoint, "2",
  302. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), "",cmd, language);
  303. }
  304. catch (Exception)
  305. {
  306. throw;
  307. }
  308. }
  309. #endregion
  310. #region 成品(生产)入库,倒冲
  311. if (BusinessCode.Equals(TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>()))
  312. {
  313. #region sql
  314. sql = @"-- 1.创建临时表 初始单据数据 maintemp
  315. SELECT
  316. c.MOCode AS TransCode,
  317. a.MODetailID AS DetailID,
  318. a.InvCode,
  319. b.InvName,
  320. b.InvStd,
  321. a.ParentQuantity/c.Quantity*{2} AS Quantity,
  322. a.Amount,
  323. a.Sequence AS TransSequence,
  324. a.IssueQuantity,
  325. c.Sequence,
  326. inv.InvUnit,
  327. 0 AS LocationQty,
  328. inv.AmountUnit,
  329. a.ExtensionID,
  330. a.WorkPoint,
  331. ext.ProjectCode,
  332. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  333. ext.Version,
  334. ext.Brand,
  335. ext.cFree1,
  336. ext.cFree2,
  337. ext.cFree3,
  338. ext.cFree4,
  339. ext.cFree5,
  340. ext.cFree6,
  341. ext.cFree7,
  342. ext.cFree8,
  343. ext.cFree9,
  344. ext.cFree10
  345. INTO #maintemp
  346. FROM
  347. ICSMOPick a
  348. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  349. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  350. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  351. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  352. INNER JOIN (
  353. SELECT a.MOCode,a.Sequence,a.WorkPoint
  354. FROM ICSMO a
  355. INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.MOCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
  356. INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
  357. WHERE c.LotNo='{0}' AND c.WorkPoint='{1}'
  358. ) temp ON c.MOCode=temp.MOCode AND a.WorkPoint=temp.WorkPoint AND c.Sequence=temp.Sequence
  359. WHERE a.SupplyType='1'
  360. GROUP BY c.MOCode,a.ParentQuantity,a.Quantity,c.Quantity,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID,a.WorkPoint,inv.BatchEnable,a.MODetailID,a.Amount,a.Sequence,a.IssueQuantity,inv.InvName,inv.InvCode,inv.InvUnit,inv.AmountUnit,c.Sequence,
  361. ext.ProjectCode,ext.BatchCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10;
  362. select * into #resulttemp from #maintemp
  363. ALTER TABLE #resulttemp ADD LotNo VARCHAR(50)
  364. delete from #resulttemp
  365. -- 2.maintemp barcodetemp
  366. select a.lotno,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime into #barcodetemp from ICSWareHouseLotInfo a LEFT JOIN
  367. (select #maintemp.invcode from #maintemp group by #maintemp.InvCode) b on a.invcode = b.invcode where a.Quantity-a.lockQuantity>0 ORDER BY a.MTIME ASC
  368. -- 3.maintemp ID barcodetemp
  369. BEGIN
  370. DECLARE @transSequence int;--
  371. DECLARE @qty int;--
  372. DECLARE @needqty int;--
  373. DECLARE @lotno VARCHAR(50);--
  374. DECLARE @DetailID VARCHAR(50);--ID
  375. DECLARE tempCursor CURSOR FOR (select transSequence,DetailID from #maintemp); --tempCursor
  376. OPEN tempCursor; --
  377. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID; --
  378. WHILE @@fetch_status=0
  379. BEGIN
  380. select @needqty=Quantity from #maintemp where transSequence = @transSequence AND DetailID = @DetailID
  381. PRINT @transSequence
  382. WHILE @needqty>0
  383. BEGIN
  384. select top 1 @qty = isnull(quantity,0),@lotno = isnull(lotno,'') from #barcodetemp a
  385. RIGHT JOIN (select invcode from #maintemp where transSequence = @transSequence AND DetailID = @DetailID) b on a.invcode=b.invcode ORDER BY mtime
  386. BEGIN
  387. IF(@needqty-@qty>=0 and ISNULL(@lotno, '')<>'')
  388. BEGIN
  389. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  390. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  391. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  392. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  393. ISNULL(Amount, 0), InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@qty,ISNULL(AmountUnit, ''),
  394. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  395. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  396. delete from #barcodetemp where lotno = @lotno
  397. SET @needqty=@needqty-@qty
  398. END
  399. ELSE IF(@needqty-@qty<0 and ISNULL(@lotno, '')<>'')
  400. BEGIN
  401. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  402. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  403. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  404. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  405. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@needqty,ISNULL(AmountUnit, ''),
  406. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  407. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  408. update #barcodetemp set quantity = @qty-@needqty where lotno = @lotno
  409. SET @needqty=@needqty-@qty
  410. END
  411. ELSE
  412. BEGIN
  413. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  414. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  415. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  416. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  417. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,0,ISNULL(AmountUnit, ''),
  418. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  419. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  420. SET @needqty=0
  421. END
  422. END
  423. END
  424. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID;
  425. END
  426. CLOSE tempCursor
  427. DEALLOCATE tempCursor
  428. END
  429. select TransCode,LotNo,LocationQty AS Quantity,InvCode,DetailID,Sequence,TransSequence from #resulttemp
  430. --select * from #resulttemp
  431. DROP table #maintemp
  432. DROP table #resulttemp
  433. DROP table #barcodetemp";
  434. #endregion
  435. sql = String.Format(sql,LotNo,WorkPoint, Quantity);
  436. DataTable table = DBHelper.SQlReturnData(sql,cmd);
  437. string json = JsonConvert.SerializeObject(table);
  438. List<DownItemModel> downItemModels = JsonConvert.DeserializeObject<List<DownItemModel>>(json);
  439. foreach (DownItemModel model in downItemModels)
  440. {
  441. if (model != null && model.LotNo == null || "" == model.LotNo)
  442. {
  443. throw new Exception(language.GetNameByCode("WMSAPIInfo201"));
  444. }
  445. WareHouseLotInfoDown(Identification,model.TransCode,model.Sequence + "~" + model.TransSequence,model.LotNo,model.Quantity,User,WorkPoint,"12",BusinessCode,cmd,language,"","");
  446. //回写已领数量
  447. sql = @"UPDATE ICSMOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + model.Quantity+") WHERE MODetailID='{0}' AND Sequence='{1}' AND WorkPoint='{2}'";
  448. sql = String.Format(sql,model.DetailID,model.TransSequence,WorkPoint);
  449. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  450. {
  451. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  452. }
  453. }
  454. }
  455. #endregion
  456. #region 委外入库,倒冲
  457. if (BusinessCode.Equals(TransTypeEnum.OutsourcingReceiveDoc.GetDescription<DBValue>()))
  458. {
  459. #region sql
  460. sql = @"-- 1.创建临时表 初始单据数据 maintemp
  461. SELECT
  462. c.OOCode AS TransCode,
  463. a.OODetailID AS DetailID,
  464. a.InvCode,
  465. b.InvName,
  466. b.InvStd,
  467. a.ParentQuantity/c.Quantity*{2} AS Quantity,
  468. a.Amount,
  469. a.Sequence AS TransSequence,
  470. a.IssueQuantity,
  471. c.Sequence,
  472. inv.InvUnit,
  473. 0 AS LocationQty,
  474. inv.AmountUnit,
  475. a.ExtensionID,
  476. a.WorkPoint,
  477. ext.ProjectCode,
  478. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  479. ext.Version,
  480. ext.Brand,
  481. ext.cFree1,
  482. ext.cFree2,
  483. ext.cFree3,
  484. ext.cFree4,
  485. ext.cFree5,
  486. ext.cFree6,
  487. ext.cFree7,
  488. ext.cFree8,
  489. ext.cFree9,
  490. ext.cFree10
  491. INTO #maintemp
  492. FROM
  493. ICSOOPick a
  494. inner join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  495. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  496. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  497. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  498. INNER JOIN (
  499. SELECT a.OOCode,a.Sequence,a.WorkPoint
  500. FROM ICSOutsourcingOrder a
  501. INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.OOCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
  502. INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
  503. WHERE c.LotNo='{0}' AND c.WorkPoint='{1}'
  504. ) temp ON c.OOCode=temp.OOCode AND a.WorkPoint=temp.WorkPoint AND c.Sequence=temp.Sequence
  505. WHERE a.SupplyType='1'
  506. GROUP BY c.OOCode,a.ParentQuantity,a.Quantity,c.Quantity,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID,a.WorkPoint,inv.BatchEnable,a.OODetailID,a.Amount,a.Sequence,a.IssueQuantity,inv.InvName,inv.InvCode,inv.InvUnit,inv.AmountUnit,c.Sequence,
  507. ext.ProjectCode,ext.BatchCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10;
  508. select * into #resulttemp from #maintemp
  509. ALTER TABLE #resulttemp ADD LotNo VARCHAR(50)
  510. delete from #resulttemp
  511. -- 2.maintemp barcodetemp
  512. select a.lotno,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime into #barcodetemp from ICSWareHouseLotInfo a LEFT JOIN
  513. (select #maintemp.invcode from #maintemp group by #maintemp.InvCode) b on a.invcode = b.invcode where a.Quantity-a.lockQuantity>0 ORDER BY a.MTIME ASC
  514. -- 3.maintemp ID barcodetemp
  515. BEGIN
  516. DECLARE @transSequence int;--
  517. DECLARE @qty int;--
  518. DECLARE @needqty int;--
  519. DECLARE @lotno VARCHAR(50);--
  520. DECLARE @DetailID VARCHAR(50);--ID
  521. DECLARE tempCursor CURSOR FOR (select transSequence,DetailID from #maintemp); --tempCursor
  522. OPEN tempCursor; --
  523. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID; --
  524. WHILE @@fetch_status=0
  525. BEGIN
  526. select @needqty=Quantity from #maintemp where transSequence = @transSequence AND DetailID = @DetailID
  527. PRINT @transSequence
  528. WHILE @needqty>0
  529. BEGIN
  530. select top 1 @qty = isnull(quantity,0),@lotno = isnull(lotno,'') from #barcodetemp a
  531. RIGHT JOIN (select invcode from #maintemp where transSequence = @transSequence AND DetailID = @DetailID) b on a.invcode=b.invcode ORDER BY mtime
  532. BEGIN
  533. IF(@needqty-@qty>=0 and ISNULL(@lotno, '')<>'')
  534. BEGIN
  535. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  536. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  537. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  538. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  539. ISNULL(Amount, 0), InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@qty,ISNULL(AmountUnit, ''),
  540. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  541. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  542. delete from #barcodetemp where lotno = @lotno
  543. SET @needqty=@needqty-@qty
  544. END
  545. ELSE IF(@needqty-@qty<0 and ISNULL(@lotno, '')<>'')
  546. BEGIN
  547. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  548. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  549. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  550. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  551. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@needqty,ISNULL(AmountUnit, ''),
  552. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  553. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  554. update #barcodetemp set quantity = @qty-@needqty where lotno = @lotno
  555. SET @needqty=@needqty-@qty
  556. END
  557. ELSE
  558. BEGIN
  559. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  560. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  561. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  562. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  563. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,0,ISNULL(AmountUnit, ''),
  564. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  565. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  566. SET @needqty=0
  567. END
  568. END
  569. END
  570. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID;
  571. END
  572. CLOSE tempCursor
  573. DEALLOCATE tempCursor
  574. END
  575. select TransCode,LotNo,LocationQty AS Quantity,InvCode,DetailID,Sequence,TransSequence from #resulttemp
  576. --select * from #resulttemp
  577. DROP table #maintemp
  578. DROP table #resulttemp
  579. DROP table #barcodetemp";
  580. #endregion
  581. sql = String.Format(sql, LotNo, WorkPoint, Quantity);
  582. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  583. string json = JsonConvert.SerializeObject(table);
  584. List<DownItemModel> downItemModels = JsonConvert.DeserializeObject<List<DownItemModel>>(json);
  585. foreach (DownItemModel model in downItemModels)
  586. {
  587. if (model != null && model.LotNo == null || "" == model.LotNo)
  588. {
  589. throw new Exception(language.GetNameByCode("WMSAPIInfo201"));
  590. }
  591. WareHouseLotInfoDown(Identification, model.TransCode, model.Sequence + "~" + model.TransSequence, model.LotNo, model.Quantity, User, WorkPoint, "13", BusinessCode, cmd, language,"","");
  592. //回写已领数量
  593. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + model.Quantity+") WHERE OODetailID='{0}' AND Sequence='{1}' AND WorkPoint='{2}'";
  594. sql = String.Format(sql, model.DetailID, model.TransSequence, WorkPoint);
  595. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  596. {
  597. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  598. }
  599. }
  600. }
  601. #endregion
  602. }
  603. catch (Exception)
  604. {
  605. throw;
  606. }
  607. }
  608. /// <summary>
  609. /// 添加库存(奥美专用)
  610. /// </summary>
  611. /// <param name="LocationCode"></param>
  612. /// <param name="LotNo"></param>
  613. /// <param name="Quantity"></param>
  614. /// <param name="User"></param>
  615. /// <param name="WorkPoint"></param>
  616. /// <param name="TransType"></param>
  617. /// <param name="BusinessCode"></param>
  618. /// <param name="cmd"></param>
  619. /// <param name="jointLotNo"></param>
  620. public static void WareHouseLotInfoUpAM(string Identification, string LocationCode, string LotNo, string Quantity, string User,
  621. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string LogID, string jointLotNo,string TransCode,string TransSequence)
  622. {
  623. try
  624. {
  625. #region 正常入库
  626. ///添加库存(原条码退回,更新库存;新条码直接入库)
  627. //stirng locationcode = "";
  628. string sql = string.Empty;
  629. string locationcode = "";
  630. string newlocationcode = "";
  631. string amount = "";
  632. //string sqql = @"select a.Amount FROM ICSInventoryLot a
  633. // WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  634. //sqql = string.Format(sqql, LotNo, WorkPoint);
  635. //DataTable dtaa = DBHelper.SQlReturnData(sqql, cmd);
  636. //amount = dtaa.Rows[0]["Amount"].ToString();
  637. //string cheksql = @"select d.EATTRIBUTE1 FROM ICSInventoryLot a
  638. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  639. // INNER JOIN ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  640. // WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and d.AmountEnable='1'";
  641. //cheksql = string.Format(cheksql, LotNo, WorkPoint);
  642. //DataTable dta = DBHelper.SQlReturnData(cheksql, cmd);
  643. //if (dta.Rows.Count > 0)
  644. //{
  645. // Quantity = (decimal.Parse(Quantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  646. //}
  647. if (BusinessCode != TransTypeEnum.SalesReturnBack.GetDescription<DBValue>())
  648. {
  649. if (string.IsNullOrWhiteSpace(LogID))
  650. {
  651. sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  652. BEGIN
  653. RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
  654. RETURN
  655. END ";
  656. }
  657. else
  658. {
  659. sql = @"SELECT LocationCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  660. sql = string.Format(sql, LotNo, WorkPoint);
  661. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  662. if (dt == null || dt.Rows.Count <= 0)
  663. {
  664. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
  665. }
  666. locationcode = dt.Rows[0]["LocationCode"].ToString();
  667. }
  668. }
  669. if(BusinessCode == TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>())
  670. {
  671. sql = @"SELECT FromLocationCode FROM ICSWareHouseLotInfoLog a WHERE LotNo='{0}' AND WorkPoint='{1}' AND ID='{2}'";
  672. sql = string.Format(sql, LotNo, WorkPoint,LogID);
  673. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  674. if (dt == null || dt.Rows.Count <= 0)
  675. {
  676. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
  677. }
  678. newlocationcode = dt.Rows[0]["FromLocationCode"].ToString();
  679. sql += @" IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  680. BEGIN
  681. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  682. RETURN
  683. END
  684. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  685. BEGIN
  686. IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity=0)
  687. BEGIN
  688. UPDATE a SET a.Quantity=ISNULL(a.Quantity,0)+'{3}',WarehouseCode=e.WarehouseCode,LocationCode=d.LocationCode
  689. From ICSWareHouseLotInfo a
  690. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  691. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  692. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  693. END
  694. ELSE IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.LocationCode=(select a.FromLocationCode FROM ICSWareHouseLotInfoLog a WHERE a.LotNo='CP-41100212' AND a.WorkPoint='UFDATA_999_2021' AND a.id='{5}'
  695. AND a.FromLocationCode='" + locationcode + @"'))
  696. BEGIN
  697. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
  698. WHERE LotNo='{0}' AND WorkPoint='{1}'
  699. END
  700. ELSE
  701. BEGIN
  702. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo395"), "{4}", locationcode) + @"', 16, 1);
  703. RETURN
  704. END
  705. END
  706. ELSE
  707. BEGIN
  708. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  709. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  710. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  711. BEGIN
  712. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  713. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  714. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}' AND il.LocationCode='{4}')
  715. BEGIN
  716. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  717. RETURN
  718. END
  719. END
  720. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  721. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  722. FROM ICSInventoryLot a
  723. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  724. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  725. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  726. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  727. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  728. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  729. END";
  730. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, newlocationcode, LogID);
  731. }
  732. else if (BusinessCode == TransTypeEnum.MOStockINByProductNoTrans.GetDescription<DBValue>())
  733. {
  734. sql += @" IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  735. BEGIN
  736. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  737. RETURN
  738. END
  739. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  740. BEGIN
  741. IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity=0)
  742. BEGIN
  743. UPDATE a SET a.Quantity=ISNULL(a.Quantity,0)+'{3}',WarehouseCode=e.WarehouseCode,LocationCode=d.LocationCode
  744. From ICSWareHouseLotInfo a
  745. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  746. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  747. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  748. END
  749. ELSE IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.LocationCode='{4}')
  750. BEGIN
  751. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
  752. WHERE LotNo='{0}' AND WorkPoint='{1}'
  753. END
  754. ELSE IF('" + locationcode + @"' != '{4}')
  755. BEGIN
  756. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo395"), "{4}", locationcode) + @"', 16, 1);
  757. RETURN
  758. END
  759. END
  760. ELSE
  761. BEGIN
  762. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  763. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  764. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  765. BEGIN
  766. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  767. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  768. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}' AND il.LocationCode='{4}')
  769. BEGIN
  770. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  771. RETURN
  772. END
  773. END
  774. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  775. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  776. FROM ICSInventoryLot a
  777. LEFT JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  778. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  779. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  780. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  781. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  782. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  783. END";
  784. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode);
  785. }
  786. else
  787. {
  788. sql += @" IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  789. BEGIN
  790. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  791. RETURN
  792. END
  793. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  794. BEGIN
  795. IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity=0)
  796. BEGIN
  797. UPDATE a SET a.Quantity=ISNULL(a.Quantity,0)+'{3}',WarehouseCode=e.WarehouseCode,LocationCode=d.LocationCode
  798. From ICSWareHouseLotInfo a
  799. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  800. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  801. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  802. END
  803. ELSE IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.LocationCode='{4}')
  804. BEGIN
  805. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
  806. WHERE LotNo='{0}' AND WorkPoint='{1}'
  807. END
  808. ELSE IF('" + locationcode + @"' != '{4}')
  809. BEGIN
  810. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo395"), "{4}", locationcode) + @"', 16, 1);
  811. RETURN
  812. END
  813. END
  814. ELSE
  815. BEGIN
  816. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  817. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  818. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  819. BEGIN
  820. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  821. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  822. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}' AND il.LocationCode='{4}')
  823. BEGIN
  824. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  825. RETURN
  826. END
  827. END
  828. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  829. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  830. FROM ICSInventoryLot a
  831. --INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  832. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  833. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  834. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  835. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  836. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  837. END";
  838. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode);
  839. }
  840. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  841. {
  842. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  843. }
  844. if (BusinessCode == TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>())
  845. {
  846. ///添加日志
  847. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  848. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  849. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  850. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  851. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  852. SELECT NEWID(),'{3}','{8}','{9}',a.LotNo ,a.InvCode ,
  853. '','',c.WarehouseCode,c.LocationCode,'{6}',
  854. '','0','{4}','{5}','0','',
  855. '','','',f.F_Account ,f.F_RealName ,
  856. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  857. FROM ICSInventoryLot a
  858. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  859. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  860. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  861. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  862. ";
  863. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID,TransCode,TransSequence);
  864. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  865. {
  866. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  867. }
  868. }
  869. else if (BusinessCode == TransTypeEnum.MOStockINByProduct.GetDescription<DBValue>())
  870. {
  871. ///添加日志
  872. sql = @"IF EXISTS(SELECT 1 FROM ICSInventoryLot lot WHERE lot.LotNo='{0}' AND lot.WorkPoint='{1}' AND lot.Type=19)
  873. BEGIN
  874. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  875. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  876. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  877. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  878. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  879. SELECT NEWID(),'{3}','','',a.LotNo ,a.InvCode ,
  880. '','',c.WarehouseCode,c.LocationCode,'{6}',
  881. '','0','{4}','{5}','0','',
  882. '','','',f.F_Account ,f.F_RealName ,
  883. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  884. FROM ICSInventoryLot a
  885. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  886. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  887. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  888. END
  889. ELSE
  890. BEGIN
  891. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  892. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  893. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  894. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  895. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  896. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  897. '','',c.WarehouseCode,c.LocationCode,'{6}',
  898. '','0','{4}','{5}','0','',
  899. '','','',f.F_Account ,f.F_RealName ,
  900. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  901. FROM ICSInventoryLot a
  902. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  903. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  904. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  905. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  906. END
  907. ";
  908. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
  909. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  910. {
  911. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  912. }
  913. }
  914. else if (BusinessCode == TransTypeEnum.MOStockINByProductNoTrans.GetDescription<DBValue>())
  915. {
  916. ///添加日志
  917. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  918. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  919. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  920. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  921. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  922. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  923. '','',c.WarehouseCode,c.LocationCode,'{6}',
  924. '','0','{4}','{5}','0','',
  925. '','','',f.F_Account ,f.F_RealName ,
  926. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  927. FROM ICSInventoryLot a
  928. LEFT JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  929. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  930. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  931. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  932. ";
  933. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
  934. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  935. {
  936. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  937. }
  938. }
  939. else if (BusinessCode == TransTypeEnum.OOStockINByProduct.GetDescription<DBValue>())
  940. {
  941. ///添加日志
  942. sql = @"IF EXISTS(SELECT 1 FROM ICSInventoryLot lot WHERE lot.LotNo='{0}' AND lot.WorkPoint='{1}' AND lot.Type=19)
  943. BEGIN
  944. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  945. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  946. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  947. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  948. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  949. SELECT NEWID(),'{3}','','',a.LotNo ,a.InvCode ,
  950. '','',c.WarehouseCode,c.LocationCode,'{6}',
  951. '','0','{4}','{5}','0','',
  952. '','','',f.F_Account ,f.F_RealName ,
  953. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  954. FROM ICSInventoryLot a
  955. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  956. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  957. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  958. END
  959. ELSE
  960. BEGIN
  961. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  962. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  963. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  964. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  965. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  966. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  967. '','',c.WarehouseCode,c.LocationCode,'{6}',
  968. '','0','{4}','{5}','0','',
  969. '','','',f.F_Account ,f.F_RealName ,
  970. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  971. FROM ICSInventoryLot a
  972. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  973. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  974. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  975. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  976. END
  977. ";
  978. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
  979. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  980. {
  981. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  982. }
  983. }
  984. else
  985. {
  986. ///添加日志
  987. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  988. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  989. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  990. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  991. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  992. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  993. '','',c.WarehouseCode,c.LocationCode,'{6}',
  994. '','0','{4}','{5}','0','',
  995. '','','',f.F_Account ,f.F_RealName ,
  996. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  997. FROM ICSInventoryLot a
  998. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  999. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1000. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1001. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1002. ";
  1003. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
  1004. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1005. {
  1006. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1007. }
  1008. }
  1009. #endregion
  1010. #region 管控方式是"料品"时
  1011. ControlMode mode = ICSControlModeService.GetControlMode();
  1012. if (mode.itemCode.Equals("ControlMode02"))
  1013. {
  1014. //查询是否存在料品管控的条码
  1015. string sqlStrNew = @"SELECT a.ID,
  1016. con.ContainerCode,
  1017. con.ContainerName,
  1018. a.LotNo,
  1019. a.InvCode,
  1020. inv.InvName,
  1021. inv.InvStd,
  1022. inv.InvUnit,-- {0}
  1023. inv.AmountUnit,
  1024. ext.ID AS ExtensionID,
  1025. ext.ProjectCode,
  1026. ext.Version,
  1027. ext.BatchCode,
  1028. ext.Brand,
  1029. ext.cFree1,
  1030. ext.cFree2,
  1031. ext.cFree3,
  1032. ext.cFree4,
  1033. ext.cFree5,
  1034. ext.cFree6,
  1035. ext.cFree7,
  1036. ext.cFree8,
  1037. ext.cFree9,
  1038. ext.cFree10,
  1039. a.MUSER AS [ USER ],
  1040. a.MTIME AS [ MTime ]
  1041. FROM
  1042. ICSInventoryLot a
  1043. LEFT JOIN ICSContainerLot conlot ON a.LotNo = conlot.LotNo AND a.WorkPoint = conlot.WorkPoint
  1044. LEFT JOIN ICSContainer con ON conlot.ContainerID = con.ID AND conlot.WorkPoint = con.WorkPoint
  1045. INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint
  1046. INNER JOIN ICSExtension ext ON a.ExtensionID = ext.ID AND a.WorkPoint = ext.WorkPoint
  1047. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1048. sqlStrNew = string.Format(sqlStrNew, jointLotNo, WorkPoint);
  1049. DataTable table = DBHelper.SQlReturnData(sqlStrNew, cmd);
  1050. string json = JsonConvert.SerializeObject(table);
  1051. List<LotNoMode> modelNew = JsonConvert.DeserializeObject<List<LotNoMode>>(json);
  1052. //当不存在料品管控条码时,生成新条码
  1053. if (!(modelNew.Count > 0))
  1054. {
  1055. //获取旧条码的信息
  1056. string jsonStr = ICSControlModeService.QueryLotNo(LotNo, WorkPoint);
  1057. List<LotNoMode> model = JsonConvert.DeserializeObject<List<LotNoMode>>(jsonStr);
  1058. //在条码表中插入一条新数据,在条码表中插入一条新数据,并在库存表中添加新数据
  1059. LotNoMode lotNoMode = model[0];
  1060. CreateLotNo(jointLotNo, Quantity, "", "", WorkPoint, Identification, User, lotNoMode.InvCode, BusinessCode, lotNoMode.ProjectCode, lotNoMode.BatchCode,
  1061. lotNoMode.Version, lotNoMode.Brand, lotNoMode.cFree1, lotNoMode.cFree2, lotNoMode.cFree3, lotNoMode.cFree4, lotNoMode.cFree5, lotNoMode.cFree6, lotNoMode.cFree7,
  1062. lotNoMode.cFree8, lotNoMode.cFree9, lotNoMode.cFree10, cmd, language, LocationCode, LotNo);
  1063. }
  1064. try
  1065. {
  1066. //合并前日志
  1067. WareHouseLotInfoLog(Identification, jointLotNo, User, WorkPoint, "2",
  1068. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(), "", cmd, language);
  1069. //更新目标条码库存
  1070. WareHouseLotInfoMerge(Identification, jointLotNo, LotNo, Quantity, User, WorkPoint, "2",
  1071. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  1072. //合并后日志
  1073. WareHouseLotInfoLog(Identification, jointLotNo, User, WorkPoint, "2",
  1074. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), "", cmd, language);
  1075. }
  1076. catch (Exception)
  1077. {
  1078. throw;
  1079. }
  1080. }
  1081. #endregion
  1082. #region 成品(生产)入库,倒冲
  1083. if (BusinessCode.Equals(TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>()))
  1084. {
  1085. #region sql
  1086. sql = @"-- 1.创建临时表 初始单据数据 maintemp
  1087. SELECT
  1088. c.MOCode AS TransCode,
  1089. a.MODetailID AS DetailID,
  1090. a.InvCode,
  1091. b.InvName,
  1092. b.InvStd,
  1093. a.ParentQuantity/c.Quantity*{2} AS Quantity,
  1094. a.Amount,
  1095. a.Sequence AS TransSequence,
  1096. a.IssueQuantity,
  1097. c.Sequence,
  1098. inv.InvUnit,
  1099. 0 AS LocationQty,
  1100. inv.AmountUnit,
  1101. a.ExtensionID,
  1102. a.WorkPoint,
  1103. ext.ProjectCode,
  1104. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  1105. ext.Version,
  1106. ext.Brand,
  1107. ext.cFree1,
  1108. ext.cFree2,
  1109. ext.cFree3,
  1110. ext.cFree4,
  1111. ext.cFree5,
  1112. ext.cFree6,
  1113. ext.cFree7,
  1114. ext.cFree8,
  1115. ext.cFree9,
  1116. ext.cFree10
  1117. INTO #maintemp
  1118. FROM
  1119. ICSMOPick a
  1120. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  1121. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1122. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1123. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1124. INNER JOIN (
  1125. SELECT a.MOCode,a.Sequence,a.WorkPoint
  1126. FROM ICSMO a
  1127. INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.MOCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
  1128. INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
  1129. WHERE c.LotNo='{0}' AND c.WorkPoint='{1}'
  1130. ) temp ON c.MOCode=temp.MOCode AND a.WorkPoint=temp.WorkPoint AND c.Sequence=temp.Sequence
  1131. WHERE a.SupplyType='1'
  1132. GROUP BY c.MOCode,a.ParentQuantity,a.Quantity,c.Quantity,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID,a.WorkPoint,inv.BatchEnable,a.MODetailID,a.Amount,a.Sequence,a.IssueQuantity,inv.InvName,inv.InvCode,inv.InvUnit,inv.AmountUnit,c.Sequence,
  1133. ext.ProjectCode,ext.BatchCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10;
  1134. select * into #resulttemp from #maintemp
  1135. ALTER TABLE #resulttemp ADD LotNo VARCHAR(50)
  1136. delete from #resulttemp
  1137. -- 2.maintemp barcodetemp
  1138. select a.lotno,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime into #barcodetemp from ICSWareHouseLotInfo a LEFT JOIN
  1139. (select #maintemp.invcode from #maintemp group by #maintemp.InvCode) b on a.invcode = b.invcode where a.Quantity-a.lockQuantity>0 ORDER BY a.MTIME ASC
  1140. -- 3.maintemp ID barcodetemp
  1141. BEGIN
  1142. DECLARE @transSequence int;--
  1143. DECLARE @qty int;--
  1144. DECLARE @needqty int;--
  1145. DECLARE @lotno VARCHAR(50);--
  1146. DECLARE @DetailID VARCHAR(50);--ID
  1147. DECLARE tempCursor CURSOR FOR (select transSequence,DetailID from #maintemp); --tempCursor
  1148. OPEN tempCursor; --
  1149. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID; --
  1150. WHILE @@fetch_status=0
  1151. BEGIN
  1152. select @needqty=Quantity from #maintemp where transSequence = @transSequence AND DetailID = @DetailID
  1153. PRINT @transSequence
  1154. WHILE @needqty>0
  1155. BEGIN
  1156. select top 1 @qty = isnull(quantity,0),@lotno = isnull(lotno,'') from #barcodetemp a
  1157. RIGHT JOIN (select invcode from #maintemp where transSequence = @transSequence AND DetailID = @DetailID) b on a.invcode=b.invcode ORDER BY mtime
  1158. BEGIN
  1159. IF(@needqty-@qty>=0 and ISNULL(@lotno, '')<>'')
  1160. BEGIN
  1161. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  1162. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  1163. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  1164. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  1165. ISNULL(Amount, 0), InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@qty,ISNULL(AmountUnit, ''),
  1166. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  1167. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  1168. delete from #barcodetemp where lotno = @lotno
  1169. SET @needqty=@needqty-@qty
  1170. END
  1171. ELSE IF(@needqty-@qty<0 and ISNULL(@lotno, '')<>'')
  1172. BEGIN
  1173. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  1174. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  1175. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  1176. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  1177. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@needqty,ISNULL(AmountUnit, ''),
  1178. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  1179. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  1180. update #barcodetemp set quantity = @qty-@needqty where lotno = @lotno
  1181. SET @needqty=@needqty-@qty
  1182. END
  1183. ELSE
  1184. BEGIN
  1185. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  1186. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  1187. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  1188. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  1189. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,0,ISNULL(AmountUnit, ''),
  1190. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  1191. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  1192. SET @needqty=0
  1193. END
  1194. END
  1195. END
  1196. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID;
  1197. END
  1198. CLOSE tempCursor
  1199. DEALLOCATE tempCursor
  1200. END
  1201. select TransCode,LotNo,LocationQty AS Quantity,InvCode,DetailID,Sequence,TransSequence from #resulttemp
  1202. --select * from #resulttemp
  1203. DROP table #maintemp
  1204. DROP table #resulttemp
  1205. DROP table #barcodetemp";
  1206. #endregion
  1207. sql = String.Format(sql, LotNo, WorkPoint, Quantity);
  1208. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  1209. string json = JsonConvert.SerializeObject(table);
  1210. List<DownItemModel> downItemModels = JsonConvert.DeserializeObject<List<DownItemModel>>(json);
  1211. foreach (DownItemModel model in downItemModels)
  1212. {
  1213. if (model != null && model.LotNo == null || "" == model.LotNo)
  1214. {
  1215. throw new Exception(language.GetNameByCode("WMSAPIInfo201"));
  1216. }
  1217. WareHouseLotInfoDown(Identification, model.TransCode, model.Sequence + "~" + model.TransSequence, model.LotNo, model.Quantity, User, WorkPoint, "12", BusinessCode, cmd, language, "", "");
  1218. //回写已领数量
  1219. sql = @"UPDATE ICSMOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + model.Quantity + ") WHERE MODetailID='{0}' AND Sequence='{1}' AND WorkPoint='{2}'";
  1220. sql = String.Format(sql, model.DetailID, model.TransSequence, WorkPoint);
  1221. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1222. {
  1223. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1224. }
  1225. }
  1226. }
  1227. #endregion
  1228. #region 委外入库,倒冲
  1229. if (BusinessCode.Equals(TransTypeEnum.OutsourcingReceiveDoc.GetDescription<DBValue>()))
  1230. {
  1231. #region sql
  1232. sql = @"-- 1.创建临时表 初始单据数据 maintemp
  1233. SELECT
  1234. c.OOCode AS TransCode,
  1235. a.OODetailID AS DetailID,
  1236. a.InvCode,
  1237. b.InvName,
  1238. b.InvStd,
  1239. a.ParentQuantity/c.Quantity*{2} AS Quantity,
  1240. a.Amount,
  1241. a.Sequence AS TransSequence,
  1242. a.IssueQuantity,
  1243. c.Sequence,
  1244. inv.InvUnit,
  1245. 0 AS LocationQty,
  1246. inv.AmountUnit,
  1247. a.ExtensionID,
  1248. a.WorkPoint,
  1249. ext.ProjectCode,
  1250. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  1251. ext.Version,
  1252. ext.Brand,
  1253. ext.cFree1,
  1254. ext.cFree2,
  1255. ext.cFree3,
  1256. ext.cFree4,
  1257. ext.cFree5,
  1258. ext.cFree6,
  1259. ext.cFree7,
  1260. ext.cFree8,
  1261. ext.cFree9,
  1262. ext.cFree10
  1263. INTO #maintemp
  1264. FROM
  1265. ICSOOPick a
  1266. inner join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  1267. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1268. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1269. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1270. INNER JOIN (
  1271. SELECT a.OOCode,a.Sequence,a.WorkPoint
  1272. FROM ICSOutsourcingOrder a
  1273. INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.OOCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
  1274. INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
  1275. WHERE c.LotNo='{0}' AND c.WorkPoint='{1}'
  1276. ) temp ON c.OOCode=temp.OOCode AND a.WorkPoint=temp.WorkPoint AND c.Sequence=temp.Sequence
  1277. WHERE a.SupplyType='1'
  1278. GROUP BY c.OOCode,a.ParentQuantity,a.Quantity,c.Quantity,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID,a.WorkPoint,inv.BatchEnable,a.OODetailID,a.Amount,a.Sequence,a.IssueQuantity,inv.InvName,inv.InvCode,inv.InvUnit,inv.AmountUnit,c.Sequence,
  1279. ext.ProjectCode,ext.BatchCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10;
  1280. select * into #resulttemp from #maintemp
  1281. ALTER TABLE #resulttemp ADD LotNo VARCHAR(50)
  1282. delete from #resulttemp
  1283. -- 2.maintemp barcodetemp
  1284. select a.lotno,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime into #barcodetemp from ICSWareHouseLotInfo a LEFT JOIN
  1285. (select #maintemp.invcode from #maintemp group by #maintemp.InvCode) b on a.invcode = b.invcode where a.Quantity-a.lockQuantity>0 ORDER BY a.MTIME ASC
  1286. -- 3.maintemp ID barcodetemp
  1287. BEGIN
  1288. DECLARE @transSequence int;--
  1289. DECLARE @qty int;--
  1290. DECLARE @needqty int;--
  1291. DECLARE @lotno VARCHAR(50);--
  1292. DECLARE @DetailID VARCHAR(50);--ID
  1293. DECLARE tempCursor CURSOR FOR (select transSequence,DetailID from #maintemp); --tempCursor
  1294. OPEN tempCursor; --
  1295. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID; --
  1296. WHILE @@fetch_status=0
  1297. BEGIN
  1298. select @needqty=Quantity from #maintemp where transSequence = @transSequence AND DetailID = @DetailID
  1299. PRINT @transSequence
  1300. WHILE @needqty>0
  1301. BEGIN
  1302. select top 1 @qty = isnull(quantity,0),@lotno = isnull(lotno,'') from #barcodetemp a
  1303. RIGHT JOIN (select invcode from #maintemp where transSequence = @transSequence AND DetailID = @DetailID) b on a.invcode=b.invcode ORDER BY mtime
  1304. BEGIN
  1305. IF(@needqty-@qty>=0 and ISNULL(@lotno, '')<>'')
  1306. BEGIN
  1307. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  1308. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  1309. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  1310. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  1311. ISNULL(Amount, 0), InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@qty,ISNULL(AmountUnit, ''),
  1312. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  1313. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  1314. delete from #barcodetemp where lotno = @lotno
  1315. SET @needqty=@needqty-@qty
  1316. END
  1317. ELSE IF(@needqty-@qty<0 and ISNULL(@lotno, '')<>'')
  1318. BEGIN
  1319. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  1320. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  1321. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  1322. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  1323. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@needqty,ISNULL(AmountUnit, ''),
  1324. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  1325. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  1326. update #barcodetemp set quantity = @qty-@needqty where lotno = @lotno
  1327. SET @needqty=@needqty-@qty
  1328. END
  1329. ELSE
  1330. BEGIN
  1331. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  1332. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  1333. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  1334. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  1335. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,0,ISNULL(AmountUnit, ''),
  1336. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  1337. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  1338. SET @needqty=0
  1339. END
  1340. END
  1341. END
  1342. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID;
  1343. END
  1344. CLOSE tempCursor
  1345. DEALLOCATE tempCursor
  1346. END
  1347. select TransCode,LotNo,LocationQty AS Quantity,InvCode,DetailID,Sequence,TransSequence from #resulttemp
  1348. --select * from #resulttemp
  1349. DROP table #maintemp
  1350. DROP table #resulttemp
  1351. DROP table #barcodetemp";
  1352. #endregion
  1353. sql = String.Format(sql, LotNo, WorkPoint, Quantity);
  1354. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  1355. string json = JsonConvert.SerializeObject(table);
  1356. List<DownItemModel> downItemModels = JsonConvert.DeserializeObject<List<DownItemModel>>(json);
  1357. foreach (DownItemModel model in downItemModels)
  1358. {
  1359. if (model != null && model.LotNo == null || "" == model.LotNo)
  1360. {
  1361. throw new Exception(language.GetNameByCode("WMSAPIInfo201"));
  1362. }
  1363. WareHouseLotInfoDown(Identification, model.TransCode, model.Sequence + "~" + model.TransSequence, model.LotNo, model.Quantity, User, WorkPoint, "13", BusinessCode, cmd, language, "", "");
  1364. //回写已领数量
  1365. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + model.Quantity + ") WHERE OODetailID='{0}' AND Sequence='{1}' AND WorkPoint='{2}'";
  1366. sql = String.Format(sql, model.DetailID, model.TransSequence, WorkPoint);
  1367. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1368. {
  1369. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1370. }
  1371. }
  1372. }
  1373. #endregion
  1374. }
  1375. catch (Exception)
  1376. {
  1377. throw;
  1378. }
  1379. }
  1380. /// <summary>
  1381. /// 减少库存
  1382. /// </summary>
  1383. /// <param name="Identification"></param>
  1384. /// <param name="TransCode"></param>
  1385. /// <param name="TransSequence"></param>
  1386. /// <param name="LotNo"></param>
  1387. /// <param name="Quantity"></param>
  1388. /// <param name="User"></param>
  1389. /// <param name="WorkPoint"></param>
  1390. /// <param name="TransType"></param>
  1391. /// <param name="BusinessCode"></param>
  1392. /// <param name="cmd"></param>
  1393. public static DataTable WareHouseLotInfoDown(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
  1394. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string LogID, string MergeID = "")
  1395. {
  1396. decimal LotQTYYY = 0;
  1397. decimal LotQTY = 0;
  1398. string LotEnable = "";
  1399. string chekEnable = "";
  1400. string DisPrintEnable = "";
  1401. string PrintEnable = "";
  1402. string sql = "";
  1403. string lotstr = "";
  1404. int result = 0;
  1405. List<string> NewBarCodeList = new List<string>();
  1406. DataTable dtLotno = new DataTable();
  1407. DataTable lstDt = new DataTable();
  1408. DataTable ZLtable = new DataTable();
  1409. try
  1410. {
  1411. //检验是否分批
  1412. sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  1413. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  1414. where a.LotNo='{0}' and a.WorkPoint='{1}'
  1415. ";
  1416. sql = string.Format(sql, LotNo, WorkPoint);
  1417. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1418. if (dt.Rows.Count == 0)
  1419. {
  1420. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  1421. }
  1422. else
  1423. {
  1424. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  1425. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  1426. }
  1427. string cheksql = @"IF NOT EXISTS(select b.F_ItemCode as Code ,b.F_ItemName as Name,b.F_EnabledMark AS Enable ,b.F_IsDefault AS DisPrintEnable
  1428. from Sys_SRM_Items a
  1429. left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  1430. where a.F_EnCode='TransBatch' and b.F_ItemCode='{0}' )
  1431. BEGIN
  1432. RAISERROR('" + language.GetNameByCode("WMSAPIInfo470") + @"',16,1);
  1433. RETURN
  1434. END
  1435. select b.F_ItemCode as Code ,b.F_ItemName as Name,b.F_EnabledMark AS Enable ,b.F_IsDefault AS DisPrintEnable
  1436. from Sys_SRM_Items a
  1437. left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  1438. where a.F_EnCode='TransBatch' and b.F_ItemCode='{0}'
  1439. ";
  1440. cheksql = string.Format(cheksql, BusinessCode);
  1441. DataTable chekdt = DBHelper.SQlReturnData(cheksql, cmd);
  1442. if (chekdt.Rows.Count == 0)
  1443. {
  1444. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  1445. }
  1446. else
  1447. {
  1448. chekEnable = chekdt.Rows[0]["Enable"].ToString();
  1449. DisPrintEnable = chekdt.Rows[0]["DisPrintEnable"].ToString();
  1450. }
  1451. sql = @"select Quantity from ICSWareHouseLotInfo
  1452. where LotNO='{0}' AND WorkPoint='{1}'";
  1453. sql = string.Format(sql, LotNo, WorkPoint);
  1454. DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
  1455. LotQTYYY = Convert.ToDecimal(dtt.Rows[0]["Quantity"]);
  1456. LotQTY = Convert.ToDecimal(Quantity);
  1457. if (!LotEnable.Equals("False")&&!chekEnable.Equals("False") && LotQTYYY - LotQTY > 0)
  1458. {
  1459. ZLtable = ICSControlModeService.GetZL();
  1460. if (ZLtable == null)
  1461. {
  1462. throw new Exception(language.GetNameByCode("WMSAPIInfo471"));
  1463. }
  1464. for (int i = 0; i < ZLtable.Rows.Count; i++)
  1465. {
  1466. string zlName = ZLtable.Rows[i]["Name"].ToString();
  1467. string zlTransCode = ZLtable.Rows[i]["BusinessCode"].ToString();
  1468. string Enable = ZLtable.Rows[i]["Enable"].ToString();
  1469. if (zlTransCode.Equals(BusinessCode))
  1470. {
  1471. if (Enable.Equals("True"))
  1472. {
  1473. ///更新日志
  1474. sql = @"
  1475. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and transtype='15')
  1476. BEGIN
  1477. RAISERROR('" + language.GetNameByCode("WMSAPIInfo472") + @"',16,1);
  1478. RETURN
  1479. END
  1480. UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE2='1' WHERE LotNo='{0}' AND WorkPoint='{1}' and transtype='15'
  1481. ";
  1482. sql = string.Format(sql, LotNo, WorkPoint, LogID);
  1483. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1484. {
  1485. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"占料标识更新失败!");
  1486. }
  1487. ///更新库存
  1488. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}',LockQuantity=ISNULL(LockQuantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1489. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity-LockQuantity<0)
  1490. BEGIN
  1491. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1492. RETURN
  1493. END";
  1494. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1495. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1496. {
  1497. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1498. }
  1499. }
  1500. else
  1501. {
  1502. ///更新库存
  1503. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-ISNULL(LockQuantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1504. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity-LockQuantity<0)
  1505. BEGIN
  1506. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1507. RETURN
  1508. END";
  1509. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1510. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1511. {
  1512. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1513. }
  1514. }
  1515. }
  1516. }
  1517. ///分批前添加日志
  1518. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1519. BEGIN
  1520. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1521. RETURN
  1522. END
  1523. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1524. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1525. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1526. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1527. MTIME,WorkPoint,EATTRIBUTE1)
  1528. SELECT NEWID(),'{3}','{7}','{8}',a.LotNo ,a.InvCode ,
  1529. c.WarehouseCode,c.LocationCode,'','',c.Quantity+{6},
  1530. '','0','{4}','31','0','',
  1531. '','','',f.F_Account ,f.F_RealName ,
  1532. SYSDATETIME() ,a.WorkPoint ,''
  1533. FROM ICSInventoryLot a
  1534. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1535. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1536. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1537. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1538. ";
  1539. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, TransCode, TransSequence);
  1540. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1541. {
  1542. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1543. }
  1544. #region 获取分批后的条码(lotstr)
  1545. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  1546. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  1547. sql = string.Format(sql, LotNo, WorkPoint);
  1548. dt = DBHelper.SQlReturnData(sql, cmd);
  1549. if (dt.Rows.Count == 0)
  1550. {
  1551. lotstr = LotNo + "-" + 1;
  1552. }
  1553. else
  1554. {
  1555. lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  1556. }
  1557. NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  1558. #endregion
  1559. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  1560. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  1561. Quantity,Amount,ExtensionID,Type,PrintTimes,
  1562. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  1563. WorkPoint,EATTRIBUTE1)
  1564. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  1565. '{2}',a.Amount/a.Quantity*Quantity,a.ExtensionID,a.Type,a.PrintTimes,
  1566. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  1567. a.WorkPoint ,'{1}'
  1568. From ICSInventoryLot a
  1569. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  1570. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  1571. cmd.CommandText = sql;
  1572. result = cmd.ExecuteNonQuery();
  1573. if (result <= 0)
  1574. {
  1575. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  1576. }
  1577. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1578. select NEWID(),'{0}',WarehouseCode,LocationCode,InvCode,'0',InDate,LockQuantity
  1579. ,MUSER,MUSERName,GETDATE(),'{3}',''
  1580. from ICSWareHouseLotInfo
  1581. where LotNO='{1}' AND WorkPoint='{3}'";
  1582. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  1583. cmd.CommandText = sql;
  1584. result = cmd.ExecuteNonQuery();
  1585. if (result <= 0)
  1586. {
  1587. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  1588. }
  1589. //插入条码单据表
  1590. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1591. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  1592. FROM ICSInventoryLot a
  1593. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1594. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1595. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1596. sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
  1597. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1598. {
  1599. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  1600. }
  1601. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1602. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1603. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1604. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1605. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  1606. SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
  1607. c.WarehouseCode,c.LocationCode,'','','{6}',
  1608. '','0','{7}','{8}','0','',
  1609. '','','',f.F_Account ,f.F_RealName ,
  1610. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  1611. FROM ICSInventoryLot a
  1612. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1613. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1614. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1615. ";
  1616. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr);
  1617. cmd.CommandText = sql;
  1618. result = cmd.ExecuteNonQuery();
  1619. if (result <= 0)
  1620. {
  1621. throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
  1622. }
  1623. if (PrintEnable.Equals("True")&& DisPrintEnable.Equals("True"))
  1624. {
  1625. sql = @"select A.LotNO AS OLDLotNo , C.Quantity AS OLDLotQty, A.eattribute1 as LotNo, B.Quantity AS LotQty ,b.InvCode,d.InvStd,d.InvName,b.MTime,A.TransCode
  1626. from ICSWareHouseLotInfolog A
  1627. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  1628. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  1629. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  1630. where A.lotno ='{0}' and a.workpoint='{1}' and a.BusinessCode='{2}'
  1631. ";
  1632. sql = string.Format(sql, lotstr, WorkPoint,BusinessCode);
  1633. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  1634. lstDt=dtLotno;
  1635. }
  1636. ///添加日志
  1637. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1638. BEGIN
  1639. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1640. RETURN
  1641. END
  1642. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1643. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1644. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1645. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1646. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  1647. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1648. c.WarehouseCode,c.LocationCode,'','',c.Quantity,
  1649. '','0','{7}','32','0','',
  1650. '','','',f.F_Account ,f.F_RealName ,
  1651. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  1652. FROM ICSInventoryLot a
  1653. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1654. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1655. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1656. ";
  1657. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  1658. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1659. {
  1660. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1661. }
  1662. #endregion
  1663. }
  1664. else
  1665. {
  1666. NewBarCodeList.Add(LotNo);
  1667. ///添加日志
  1668. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1669. BEGIN
  1670. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1671. RETURN
  1672. END
  1673. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1674. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1675. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1676. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1677. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  1678. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1679. c.WarehouseCode,c.LocationCode,'','','{6}',
  1680. '','0','{7}','{8}','0','',
  1681. '','','',f.F_Account ,f.F_RealName ,
  1682. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  1683. FROM ICSInventoryLot a
  1684. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1685. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1686. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1687. ";
  1688. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  1689. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1690. {
  1691. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1692. }
  1693. ZLtable = ICSControlModeService.GetZL();
  1694. if (ZLtable == null)
  1695. {
  1696. throw new Exception(language.GetNameByCode("WMSAPIInfo471"));
  1697. }
  1698. for (int i = 0; i < ZLtable.Rows.Count; i++)
  1699. {
  1700. string zlTransCode = ZLtable.Rows[i]["BusinessCode"].ToString();
  1701. string Enable = ZLtable.Rows[i]["Enable"].ToString();
  1702. if (zlTransCode.Equals(BusinessCode))
  1703. {
  1704. if (Enable.Equals("True"))
  1705. {
  1706. ///更新日志
  1707. sql = @"
  1708. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and transtype='15')
  1709. BEGIN
  1710. RAISERROR('" + language.GetNameByCode("WMSAPIInfo472") + @"',16,1);
  1711. RETURN
  1712. END
  1713. UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE2='1' WHERE LotNo='{0}' AND WorkPoint='{1}' and transtype='15'
  1714. ";
  1715. sql = string.Format(sql, LotNo, WorkPoint, LogID);
  1716. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1717. {
  1718. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"占料标识更新失败!");
  1719. }
  1720. ///更新库存
  1721. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}',LockQuantity=ISNULL(LockQuantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1722. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity-LockQuantity<0)
  1723. BEGIN
  1724. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1725. RETURN
  1726. END";
  1727. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1728. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1729. {
  1730. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1731. }
  1732. }
  1733. else
  1734. {
  1735. ///更新库存
  1736. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1737. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity-LockQuantity<0)
  1738. BEGIN
  1739. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1740. RETURN
  1741. END";
  1742. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1743. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1744. {
  1745. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1746. }
  1747. }
  1748. }
  1749. }
  1750. /////更新库存
  1751. //sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1752. // IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  1753. // BEGIN
  1754. // RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1755. // RETURN
  1756. // END";
  1757. //sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1758. //if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1759. //{
  1760. // throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1761. //}
  1762. }
  1763. }
  1764. catch (Exception)
  1765. {
  1766. throw;
  1767. }
  1768. return lstDt;
  1769. }
  1770. /// <summary>
  1771. /// 减少库存(奥美专用)
  1772. /// </summary>
  1773. /// <param name="Identification"></param>
  1774. /// <param name="TransCode"></param>
  1775. /// <param name="TransSequence"></param>
  1776. /// <param name="LotNo"></param>
  1777. /// <param name="Quantity"></param>
  1778. /// <param name="User"></param>
  1779. /// <param name="WorkPoint"></param>
  1780. /// <param name="TransType"></param>
  1781. /// <param name="BusinessCode"></param>
  1782. /// <param name="cmd"></param>
  1783. public static DataTable AMWareHouseLotInfoDown(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
  1784. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string LogID, string MergeID = "")
  1785. {
  1786. decimal LotQTYYY = 0;
  1787. decimal LotQTY = 0;
  1788. string LotEnable = "";
  1789. string chekEnable = "";
  1790. string DisPrintEnable = "";
  1791. string PrintEnable = "";
  1792. string sql = "";
  1793. string lotstr = "";
  1794. int result = 0;
  1795. List<string> NewBarCodeList = new List<string>();
  1796. DataTable dtLotno = new DataTable();
  1797. DataTable lstDt = new DataTable();
  1798. DataTable ZLtable = new DataTable();
  1799. try
  1800. {
  1801. string amount = "";
  1802. //string sqql = @"select a.Amount FROM ICSInventoryLot a
  1803. // WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1804. //sqql = string.Format(sqql, LotNo, WorkPoint);
  1805. //DataTable dtaa = DBHelper.SQlReturnData(sqql, cmd);
  1806. //amount = dtaa.Rows[0]["Amount"].ToString();
  1807. //string chekksql = @"select c.EATTRIBUTE1 FROM ICSMOPick a
  1808. // INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  1809. // INNER JOIN ICSInventory c on a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  1810. // WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}' and c.AmountEnable='1'";
  1811. //chekksql = string.Format(chekksql, TransCode, WorkPoint, Quantity, TransSequence);
  1812. //DataTable dta = DBHelper.SQlReturnData(chekksql, cmd);
  1813. //if (dta.Rows.Count > 0)
  1814. //{
  1815. // Quantity = (decimal.Parse(Quantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  1816. //}
  1817. //检验是否分批
  1818. sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  1819. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  1820. where a.LotNo='{0}' and a.WorkPoint='{1}'
  1821. ";
  1822. sql = string.Format(sql, LotNo, WorkPoint);
  1823. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1824. if (dt.Rows.Count == 0)
  1825. {
  1826. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  1827. }
  1828. else
  1829. {
  1830. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  1831. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  1832. }
  1833. string cheksql = @"IF NOT EXISTS(select b.F_ItemCode as Code ,b.F_ItemName as Name,b.F_EnabledMark AS Enable ,b.F_IsDefault AS DisPrintEnable
  1834. from Sys_SRM_Items a
  1835. left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  1836. where a.F_EnCode='TransBatch' and b.F_ItemCode='{0}' )
  1837. BEGIN
  1838. RAISERROR('" + language.GetNameByCode("WMSAPIInfo470") + @"',16,1);
  1839. RETURN
  1840. END
  1841. select b.F_ItemCode as Code ,b.F_ItemName as Name,b.F_EnabledMark AS Enable ,b.F_IsDefault AS DisPrintEnable
  1842. from Sys_SRM_Items a
  1843. left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  1844. where a.F_EnCode='TransBatch' and b.F_ItemCode='{0}'
  1845. ";
  1846. cheksql = string.Format(cheksql, BusinessCode);
  1847. DataTable chekdt = DBHelper.SQlReturnData(cheksql, cmd);
  1848. if (chekdt.Rows.Count == 0)
  1849. {
  1850. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  1851. }
  1852. else
  1853. {
  1854. chekEnable = chekdt.Rows[0]["Enable"].ToString();
  1855. DisPrintEnable = chekdt.Rows[0]["DisPrintEnable"].ToString();
  1856. }
  1857. sql = @"select Quantity from ICSWareHouseLotInfo
  1858. where LotNO='{0}' AND WorkPoint='{1}'";
  1859. sql = string.Format(sql, LotNo, WorkPoint);
  1860. DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
  1861. LotQTYYY = Convert.ToDecimal(dtt.Rows[0]["Quantity"]);
  1862. LotQTY = Convert.ToDecimal(Quantity);
  1863. if (!LotEnable.Equals("False") && !chekEnable.Equals("False") && LotQTYYY - LotQTY > 0)
  1864. {
  1865. ZLtable = ICSControlModeService.GetZL();
  1866. if (ZLtable == null)
  1867. {
  1868. throw new Exception(language.GetNameByCode("WMSAPIInfo471"));
  1869. }
  1870. for (int i = 0; i < ZLtable.Rows.Count; i++)
  1871. {
  1872. string zlName = ZLtable.Rows[i]["Name"].ToString();
  1873. string zlTransCode = ZLtable.Rows[i]["BusinessCode"].ToString();
  1874. string Enable = ZLtable.Rows[i]["Enable"].ToString();
  1875. if (zlTransCode.Equals(BusinessCode))
  1876. {
  1877. if (Enable.Equals("True"))
  1878. {
  1879. ///更新日志
  1880. sql = @"
  1881. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and transtype='15')
  1882. BEGIN
  1883. RAISERROR('" + language.GetNameByCode("WMSAPIInfo472") + @"',16,1);
  1884. RETURN
  1885. END
  1886. UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE2='1' WHERE LotNo='{0}' AND WorkPoint='{1}' and transtype='15'
  1887. ";
  1888. sql = string.Format(sql, LotNo, WorkPoint, LogID);
  1889. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1890. {
  1891. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"占料标识更新失败!");
  1892. }
  1893. ///更新库存
  1894. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}',LockQuantity=ISNULL(LockQuantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1895. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity-LockQuantity<0)
  1896. BEGIN
  1897. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1898. RETURN
  1899. END";
  1900. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1901. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1902. {
  1903. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1904. }
  1905. }
  1906. else
  1907. {
  1908. ///更新库存
  1909. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-ISNULL(LockQuantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1910. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity-LockQuantity<0)
  1911. BEGIN
  1912. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1913. RETURN
  1914. END";
  1915. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1916. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1917. {
  1918. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1919. }
  1920. }
  1921. }
  1922. }
  1923. ///分批前添加日志
  1924. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1925. BEGIN
  1926. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1927. RETURN
  1928. END
  1929. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1930. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1931. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1932. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1933. MTIME,WorkPoint,EATTRIBUTE1)
  1934. SELECT NEWID(),'{3}','{7}','{8}',a.LotNo ,a.InvCode ,
  1935. c.WarehouseCode,c.LocationCode,'','',c.Quantity+{6},
  1936. '','0','{4}','31','0','',
  1937. '','','',f.F_Account ,f.F_RealName ,
  1938. SYSDATETIME() ,a.WorkPoint ,''
  1939. FROM ICSInventoryLot a
  1940. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1941. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1942. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1943. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1944. ";
  1945. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, TransCode, TransSequence);
  1946. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1947. {
  1948. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1949. }
  1950. #region 获取分批后的条码(lotstr)
  1951. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  1952. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  1953. sql = string.Format(sql, LotNo, WorkPoint);
  1954. dt = DBHelper.SQlReturnData(sql, cmd);
  1955. if (dt.Rows.Count == 0)
  1956. {
  1957. lotstr = LotNo + "-" + 1;
  1958. }
  1959. else
  1960. {
  1961. lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  1962. }
  1963. NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  1964. #endregion
  1965. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  1966. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  1967. Quantity,Amount,ExtensionID,Type,PrintTimes,
  1968. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  1969. WorkPoint,EATTRIBUTE1)
  1970. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  1971. '{2}',a.Amount/a.Quantity*Quantity,a.ExtensionID,a.Type,a.PrintTimes,
  1972. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  1973. a.WorkPoint ,'{1}'
  1974. From ICSInventoryLot a
  1975. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  1976. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  1977. cmd.CommandText = sql;
  1978. result = cmd.ExecuteNonQuery();
  1979. if (result <= 0)
  1980. {
  1981. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  1982. }
  1983. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1984. select NEWID(),'{0}',WarehouseCode,LocationCode,InvCode,'0',InDate,LockQuantity
  1985. ,MUSER,MUSERName,GETDATE(),'{3}',''
  1986. from ICSWareHouseLotInfo
  1987. where LotNO='{1}' AND WorkPoint='{3}'";
  1988. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  1989. cmd.CommandText = sql;
  1990. result = cmd.ExecuteNonQuery();
  1991. if (result <= 0)
  1992. {
  1993. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  1994. }
  1995. //插入条码单据表
  1996. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1997. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  1998. FROM ICSInventoryLot a
  1999. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2000. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2001. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  2002. sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
  2003. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2004. {
  2005. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  2006. }
  2007. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2008. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2009. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2010. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2011. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  2012. SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
  2013. c.WarehouseCode,c.LocationCode,'','','{6}',
  2014. '','0','{7}','{8}','0','',
  2015. '','','',f.F_Account ,f.F_RealName ,
  2016. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  2017. FROM ICSInventoryLot a
  2018. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2019. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2020. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2021. ";
  2022. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr);
  2023. cmd.CommandText = sql;
  2024. result = cmd.ExecuteNonQuery();
  2025. if (result <= 0)
  2026. {
  2027. throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
  2028. }
  2029. if (PrintEnable.Equals("True") && DisPrintEnable.Equals("True"))
  2030. {
  2031. sql = @"select A.LotNO AS OLDLotNo , C.Quantity AS OLDLotQty, A.eattribute1 as LotNo, B.Quantity AS LotQty ,b.InvCode,d.InvStd,d.InvName,b.MTime,A.TransCode
  2032. from ICSWareHouseLotInfolog A
  2033. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  2034. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  2035. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  2036. where A.lotno ='{0}' and a.workpoint='{1}' and a.BusinessCode='{2}'
  2037. ";
  2038. sql = string.Format(sql, lotstr, WorkPoint, BusinessCode);
  2039. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  2040. lstDt = dtLotno;
  2041. }
  2042. ///添加日志
  2043. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2044. BEGIN
  2045. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2046. RETURN
  2047. END
  2048. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2049. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2050. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2051. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2052. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  2053. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  2054. c.WarehouseCode,c.LocationCode,'','',c.Quantity,
  2055. '','0','{7}','32','0','',
  2056. '','','',f.F_Account ,f.F_RealName ,
  2057. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  2058. FROM ICSInventoryLot a
  2059. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2060. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2061. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2062. ";
  2063. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  2064. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2065. {
  2066. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2067. }
  2068. #endregion
  2069. }
  2070. else
  2071. {
  2072. NewBarCodeList.Add(LotNo);
  2073. ///添加日志
  2074. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2075. BEGIN
  2076. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2077. RETURN
  2078. END
  2079. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2080. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2081. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2082. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2083. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  2084. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  2085. c.WarehouseCode,c.LocationCode,'','','{6}',
  2086. '','0','{7}','{8}','0','',
  2087. '','','',f.F_Account ,f.F_RealName ,
  2088. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  2089. FROM ICSInventoryLot a
  2090. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2091. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2092. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2093. ";
  2094. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  2095. log.Debug("出库增加日志:" + sql);
  2096. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2097. {
  2098. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2099. }
  2100. ZLtable = ICSControlModeService.GetZL();
  2101. if (ZLtable == null)
  2102. {
  2103. throw new Exception(language.GetNameByCode("WMSAPIInfo471"));
  2104. }
  2105. for (int i = 0; i < ZLtable.Rows.Count; i++)
  2106. {
  2107. string zlTransCode = ZLtable.Rows[i]["BusinessCode"].ToString();
  2108. string Enable = ZLtable.Rows[i]["Enable"].ToString();
  2109. if (zlTransCode.Equals(BusinessCode))
  2110. {
  2111. if (Enable.Equals("True"))
  2112. {
  2113. ///更新日志
  2114. sql = @"
  2115. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and transtype='15')
  2116. BEGIN
  2117. RAISERROR('" + language.GetNameByCode("WMSAPIInfo472") + @"',16,1);
  2118. RETURN
  2119. END
  2120. UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE2='1' WHERE LotNo='{0}' AND WorkPoint='{1}' and transtype='15'
  2121. ";
  2122. sql = string.Format(sql, LotNo, WorkPoint, LogID);
  2123. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2124. {
  2125. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"占料标识更新失败!");
  2126. }
  2127. ///更新库存
  2128. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}',LockQuantity=ISNULL(LockQuantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  2129. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity-LockQuantity<0)
  2130. BEGIN
  2131. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  2132. RETURN
  2133. END";
  2134. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2135. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2136. {
  2137. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  2138. }
  2139. }
  2140. else
  2141. {
  2142. ///更新库存
  2143. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  2144. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity-LockQuantity<0)
  2145. BEGIN
  2146. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  2147. RETURN
  2148. END";
  2149. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2150. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2151. {
  2152. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  2153. }
  2154. }
  2155. }
  2156. }
  2157. /////更新库存
  2158. //sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  2159. // IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  2160. // BEGIN
  2161. // RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  2162. // RETURN
  2163. // END";
  2164. //sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2165. //if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2166. //{
  2167. // throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  2168. //}
  2169. }
  2170. }
  2171. catch (Exception)
  2172. {
  2173. throw;
  2174. }
  2175. return lstDt;
  2176. }
  2177. /// <summary>
  2178. /// 无源头调拨
  2179. /// </summary>
  2180. /// <param name="LocationCode"></param>
  2181. /// <param name="LotNo"></param>
  2182. /// <param name="Quantity"></param>
  2183. /// <param name="User"></param>
  2184. /// <param name="WorkPoint"></param>
  2185. /// <param name="TransType"></param>
  2186. /// <param name="BusinessCode"></param>
  2187. /// <param name="cmd"></param>
  2188. public static DataTable WareHouseLotInfoNoTransfer(string Identification, string WarehouseCode, string LocationCode,
  2189. string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID)
  2190. {
  2191. decimal LotQTYYY = 0;
  2192. decimal LotQTY = 0;
  2193. String LotEnable = "";
  2194. String PrintEnable = "";
  2195. String ToWareHouseCode = "";
  2196. String ToLocationCode = "";
  2197. string lotstr = "";
  2198. int result = 0;
  2199. DataTable dtLotno = new DataTable();
  2200. DataTable lstDt = new DataTable();
  2201. List<string> NewBarCodeList = new List<string>();
  2202. try
  2203. {
  2204. //检验是否分批
  2205. string sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  2206. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  2207. where a.LotNo='{0}' and a.WorkPoint='{1}'
  2208. ";
  2209. sql = string.Format(sql, LotNo, WorkPoint);
  2210. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2211. if (dt.Rows.Count == 0)
  2212. {
  2213. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  2214. }
  2215. else
  2216. {
  2217. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  2218. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  2219. }
  2220. sql = @"select Quantity from ICSWareHouseLotInfo
  2221. where LotNO='{0}' AND WorkPoint='{1}'";
  2222. sql = string.Format(sql, LotNo, WorkPoint);
  2223. DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
  2224. LotQTYYY = Convert.ToDecimal(dtt.Rows[0]["Quantity"]);
  2225. LotQTY = Convert.ToDecimal(Quantity);
  2226. if (!LotEnable.Equals("False") && LotQTYYY - LotQTY > 0)
  2227. {
  2228. ///更新库存
  2229. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  2230. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  2231. BEGIN
  2232. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  2233. RETURN
  2234. END";
  2235. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2236. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2237. {
  2238. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  2239. }
  2240. ///分批前添加日志
  2241. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2242. BEGIN
  2243. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2244. RETURN
  2245. END
  2246. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2247. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2248. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2249. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2250. MTIME,WorkPoint,EATTRIBUTE1)
  2251. SELECT NEWID(),'{3}','','',a.LotNo ,a.InvCode ,
  2252. c.WarehouseCode,c.LocationCode,'','',c.Quantity+{6},
  2253. '','0','{4}','31','0','',
  2254. '','','',f.F_Account ,f.F_RealName ,
  2255. SYSDATETIME() ,a.WorkPoint ,''
  2256. FROM ICSInventoryLot a
  2257. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2258. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2259. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2260. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2261. ";
  2262. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity);
  2263. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2264. {
  2265. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2266. }
  2267. #region 获取分批后的条码(lotstr)
  2268. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  2269. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  2270. sql = string.Format(sql, LotNo, WorkPoint);
  2271. dt = DBHelper.SQlReturnData(sql, cmd);
  2272. if (dt.Rows.Count == 0)
  2273. {
  2274. lotstr = LotNo + "-" + 1;
  2275. }
  2276. else
  2277. {
  2278. lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  2279. }
  2280. NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  2281. #endregion
  2282. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  2283. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  2284. Quantity,Amount,ExtensionID,Type,PrintTimes,
  2285. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  2286. WorkPoint,EATTRIBUTE1)
  2287. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  2288. '{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes,
  2289. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  2290. a.WorkPoint ,'{1}'
  2291. From ICSInventoryLot a
  2292. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  2293. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  2294. cmd.CommandText = sql;
  2295. result = cmd.ExecuteNonQuery();
  2296. if (result <= 0)
  2297. {
  2298. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  2299. }
  2300. #endregion
  2301. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2302. select NEWID(),'{0}','{4}','{5}',InvCode,'{2}',InDate,LockQuantity
  2303. ,MUSER,MUSERName,GETDATE(),'{3}',''
  2304. from ICSWareHouseLotInfo
  2305. where LotNO='{1}' AND WorkPoint='{3}'";
  2306. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint, WarehouseCode, LocationCode);
  2307. cmd.CommandText = sql;
  2308. result = cmd.ExecuteNonQuery();
  2309. if (result <= 0)
  2310. {
  2311. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  2312. }
  2313. //插入条码单据表
  2314. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  2315. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  2316. FROM ICSInventoryLot a
  2317. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2318. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2319. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  2320. sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
  2321. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2322. {
  2323. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  2324. }
  2325. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2326. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2327. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2328. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2329. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  2330. SELECT NEWID(),'{3}','','','{8}' ,a.InvCode ,
  2331. c.WarehouseCode,c.LocationCode,'{9}','{10}','{4}',
  2332. '','0','{5}','{6}','0','',
  2333. '','','',f.F_Account ,f.F_RealName ,
  2334. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  2335. FROM ICSInventoryLot a
  2336. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2337. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2338. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2339. ";
  2340. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, Quantity, TransType, BusinessCode, MergeID, lotstr, WarehouseCode, LocationCode);
  2341. cmd.CommandText = sql;
  2342. result = cmd.ExecuteNonQuery();
  2343. if (result <= 0)
  2344. {
  2345. throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
  2346. }
  2347. ///添加日志
  2348. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2349. BEGIN
  2350. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2351. RETURN
  2352. END
  2353. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2354. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2355. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2356. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2357. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  2358. SELECT NEWID(),'{3}','','',a.LotNo ,a.InvCode ,
  2359. c.WarehouseCode,c.LocationCode,'','',c.Quantity,
  2360. '','0','{5}','32','0','',
  2361. '','','',f.F_Account ,f.F_RealName ,
  2362. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  2363. FROM ICSInventoryLot a
  2364. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2365. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2366. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2367. ";
  2368. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, Quantity, TransType, BusinessCode, MergeID);
  2369. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2370. {
  2371. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2372. }
  2373. if (PrintEnable.Equals("True"))
  2374. {
  2375. sql = @"select A.LotNO AS OLDLotNo , C.Quantity AS OLDLotQty, A.eattribute1 as LotNO, B.Quantity AS LotQty ,b.InvCode,d.INVSTD,d.INVNAME,b.MTIME,A.TransCode
  2376. from ICSWareHouseLotInfolog A
  2377. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  2378. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  2379. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  2380. where a.BusinessCode ='105'
  2381. and A.lotno like'{0}%' and a.workpoint='{1}'
  2382. ";
  2383. sql = string.Format(sql, LotNo, WorkPoint);
  2384. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  2385. lstDt = dtLotno;
  2386. }
  2387. }
  2388. else
  2389. {
  2390. ///添加日志
  2391. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2392. BEGIN
  2393. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2394. RETURN
  2395. END
  2396. IF EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE WarehouseCode='{7}' AND LocationCode='{8}' AND WorkPoint='{1}' AND LotNo = '{0}')
  2397. BEGIN
  2398. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo355")) + @"',16,1);
  2399. RETURN
  2400. END
  2401. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2402. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2403. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2404. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2405. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  2406. SELECT NEWID(),'{3}','','',a.LotNo ,a.InvCode ,
  2407. c.WarehouseCode,c.LocationCode,'{7}','{8}',{4},
  2408. '','0','{5}','{6}','0','',
  2409. '','','',f.F_Account ,f.F_RealName ,
  2410. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  2411. FROM ICSInventoryLot a
  2412. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2413. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2414. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2415. ";
  2416. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode, MergeID);
  2417. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2418. {
  2419. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2420. }
  2421. ///更新库存
  2422. sql = @"UPDATE ICSWareHouseLotInfo SET WareHouseCode='{2}',LocationCode='{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  2423. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  2424. BEGIN
  2425. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  2426. RETURN
  2427. END";
  2428. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode);
  2429. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2430. {
  2431. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  2432. }
  2433. }
  2434. }
  2435. catch (Exception)
  2436. {
  2437. throw;
  2438. }
  2439. return lstDt;
  2440. }
  2441. /// <summary>
  2442. /// 修改库存
  2443. /// </summary>
  2444. /// <param name="Identification"></param>
  2445. /// <param name="TransCode"></param>
  2446. /// <param name="TransSequence"></param>
  2447. /// <param name="LotNo"></param>
  2448. /// <param name="Quantity"></param>
  2449. /// <param name="User"></param>
  2450. /// <param name="WorkPoint"></param>
  2451. /// <param name="TransType"></param>
  2452. /// <param name="cmd"></param>
  2453. public static void WareHouseLotInfoUpdate(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
  2454. string WorkPoint, string TransType,string CheckKind, SqlCommand cmd, Dictionary<string, string> language)
  2455. {
  2456. try
  2457. {
  2458. ///添加日志
  2459. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2460. BEGIN
  2461. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2462. RETURN
  2463. END
  2464. IF EXISTS(SELECT id FROM ICSInventoryLot WHERE LotNo='{0}' AND Quantity<'{9}')
  2465. BEGIN
  2466. RAISERROR(' {0} !',16,1);
  2467. RETURN
  2468. END
  2469. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2470. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2471. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2472. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2473. MTIME,WorkPoint,EATTRIBUTE1)
  2474. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  2475. a.WarehouseCode,a.LocationCode,'','',a.Quantity,
  2476. '{8}','0','{6}','{7}','0','',
  2477. '','','',f.F_Account ,f.F_RealName ,
  2478. SYSDATETIME() ,a.WorkPoint ,''
  2479. FROM ICSWareHouseLotInfo a
  2480. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2481. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2482. ";
  2483. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, TransTypeEnum.LOTCheckBefore.GetDescription<DBValue>(), CheckKind, Quantity);
  2484. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2485. {
  2486. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2487. }
  2488. ///更新库存
  2489. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity='{2}',LockQuantity=LockQuantity-{2} WHERE LotNo='{0}' AND WorkPoint='{1}'";
  2490. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2491. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2492. {
  2493. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  2494. }
  2495. ///更新库存
  2496. sql = @"UPDATE ICSCheck SET Status='2' WHERE CHeckCode='{0}' AND WorkPoint='{1}'";
  2497. sql = string.Format(sql, TransCode, WorkPoint);
  2498. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2499. {
  2500. throw new Exception("盘点状态更新失败!");//"库存更新失败!");
  2501. }
  2502. ///添加日志
  2503. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2504. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2505. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2506. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2507. MTIME,WorkPoint,EATTRIBUTE1)
  2508. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  2509. a.WarehouseCode,a.LocationCode,'','',a.Quantity,
  2510. '{8}','0','{6}','{7}','0','',
  2511. '','','',f.F_Account ,f.F_RealName ,
  2512. SYSDATETIME() ,a.WorkPoint ,''
  2513. FROM ICSWareHouseLotInfo a
  2514. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2515. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2516. ";
  2517. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, TransTypeEnum.LOTCheckAfter.GetDescription<DBValue>(), CheckKind);
  2518. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2519. {
  2520. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2521. }
  2522. }
  2523. catch (Exception)
  2524. {
  2525. throw;
  2526. }
  2527. }
  2528. /// <summary>
  2529. /// 调拨
  2530. /// </summary>
  2531. /// <param name="LocationCode"></param>
  2532. /// <param name="LotNo"></param>
  2533. /// <param name="Quantity"></param>
  2534. /// <param name="User"></param>
  2535. /// <param name="WorkPoint"></param>
  2536. /// <param name="TransType"></param>
  2537. /// <param name="BusinessCode"></param>
  2538. /// <param name="cmd"></param>
  2539. public static DataTable WareHouseLotInfoTransfer(string Identification, string TransCode, string TransSequence, string WarehouseCode, string LocationCode,
  2540. string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID)
  2541. {
  2542. decimal LotQTYYY = 0;
  2543. decimal LotQTY = 0;
  2544. String LotEnable = "";
  2545. String PrintEnable = "";
  2546. string lotstr = "";
  2547. int result = 0;
  2548. DataTable dtLotno = new DataTable();
  2549. DataTable lstDt = new DataTable();
  2550. List<string> NewBarCodeList = new List<string>();
  2551. try
  2552. {
  2553. //检验是否分批
  2554. string sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  2555. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  2556. where a.LotNo='{0}' and a.WorkPoint='{1}'
  2557. ";
  2558. sql = string.Format(sql, LotNo, WorkPoint);
  2559. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2560. if (dt.Rows.Count == 0)
  2561. {
  2562. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  2563. }
  2564. else
  2565. {
  2566. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  2567. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  2568. }
  2569. sql = @"select Quantity from ICSWareHouseLotInfo
  2570. where LotNO='{0}' AND WorkPoint='{1}'";
  2571. sql = string.Format(sql, LotNo, WorkPoint);
  2572. DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
  2573. LotQTYYY = Convert.ToDecimal(dtt.Rows[0]["Quantity"]);
  2574. LotQTY = Convert.ToDecimal(Quantity);
  2575. if (!LotEnable.Equals("False") && LotQTYYY - LotQTY > 0)//增加数量判断
  2576. {
  2577. ///更新库存
  2578. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  2579. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  2580. BEGIN
  2581. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  2582. RETURN
  2583. END";
  2584. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2585. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2586. {
  2587. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  2588. }
  2589. ///分批前添加日志
  2590. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2591. BEGIN
  2592. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2593. RETURN
  2594. END
  2595. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2596. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2597. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2598. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2599. MTIME,WorkPoint,EATTRIBUTE1)
  2600. SELECT NEWID(),'{3}','{7}','{8}',a.LotNo ,a.InvCode ,
  2601. c.WarehouseCode,c.LocationCode,'','',c.Quantity+{6},
  2602. '','0','{4}','31','0','',
  2603. '','','',f.F_Account ,f.F_RealName ,
  2604. SYSDATETIME() ,a.WorkPoint ,''
  2605. FROM ICSInventoryLot a
  2606. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2607. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2608. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2609. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2610. ";
  2611. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, TransCode, TransSequence);
  2612. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2613. {
  2614. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2615. }
  2616. #region 获取分批后的条码(lotstr)
  2617. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  2618. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  2619. sql = string.Format(sql, LotNo, WorkPoint);
  2620. dt = DBHelper.SQlReturnData(sql, cmd);
  2621. if (dt.Rows.Count == 0)
  2622. {
  2623. lotstr = LotNo + "-" + 1;
  2624. }
  2625. else
  2626. {
  2627. lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  2628. }
  2629. NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  2630. #endregion
  2631. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  2632. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  2633. Quantity,Amount,ExtensionID,Type,PrintTimes,
  2634. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  2635. WorkPoint,EATTRIBUTE1)
  2636. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  2637. '{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes,
  2638. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  2639. a.WorkPoint ,'{1}'
  2640. From ICSInventoryLot a
  2641. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  2642. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  2643. cmd.CommandText = sql;
  2644. result = cmd.ExecuteNonQuery();
  2645. if (result <= 0)
  2646. {
  2647. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  2648. }
  2649. #endregion
  2650. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2651. select NEWID(),'{0}','{4}','{5}',InvCode,'{2}',InDate,LockQuantity
  2652. ,MUSER,MUSERName,GETDATE(),'{3}',''
  2653. from ICSWareHouseLotInfo
  2654. where LotNO='{1}' AND WorkPoint='{3}'";
  2655. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint,WarehouseCode,LocationCode);
  2656. cmd.CommandText = sql;
  2657. result = cmd.ExecuteNonQuery();
  2658. if (result <= 0)
  2659. {
  2660. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  2661. }
  2662. //插入条码单据表
  2663. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  2664. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  2665. FROM ICSInventoryLot a
  2666. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2667. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2668. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  2669. sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
  2670. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2671. {
  2672. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  2673. }
  2674. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2675. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2676. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2677. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2678. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  2679. SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
  2680. c.WarehouseCode,c.LocationCode,'{11}','{12}','{6}',
  2681. '','0','{7}','{8}','0','',
  2682. '','','',f.F_Account ,f.F_RealName ,
  2683. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  2684. FROM ICSInventoryLot a
  2685. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2686. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2687. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2688. ";
  2689. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr, WarehouseCode, LocationCode);
  2690. cmd.CommandText = sql;
  2691. result = cmd.ExecuteNonQuery();
  2692. if (result <= 0)
  2693. {
  2694. throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
  2695. }
  2696. ///添加日志
  2697. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2698. BEGIN
  2699. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2700. RETURN
  2701. END
  2702. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2703. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2704. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2705. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2706. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  2707. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  2708. c.WarehouseCode,c.LocationCode,'','',c.Quantity,
  2709. '','0','{7}','32','0','',
  2710. '','','',f.F_Account ,f.F_RealName ,
  2711. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  2712. FROM ICSInventoryLot a
  2713. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2714. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2715. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2716. ";
  2717. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  2718. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2719. {
  2720. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2721. }
  2722. if (PrintEnable.Equals("True"))
  2723. {
  2724. sql = @"select A.LotNO AS OLDLotNo , C.Quantity AS OLDLotQty, A.eattribute1 as LotNo, B.Quantity AS LotQty ,b.InvCode,d.InvStd,d.InvName,b.MTime,A.TransCode
  2725. from ICSWareHouseLotInfolog A
  2726. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  2727. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  2728. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  2729. where A.lotno ='{0}' and a.workpoint='{1}' and a.BusinessCode='{2}'
  2730. ";
  2731. sql = string.Format(sql, lotstr, WorkPoint, BusinessCode);
  2732. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  2733. lstDt = dtLotno;
  2734. }
  2735. }
  2736. else
  2737. {
  2738. ///添加日志
  2739. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2740. BEGIN
  2741. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2742. RETURN
  2743. END
  2744. IF EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE WarehouseCode='{9}' AND LocationCode='{10}' AND WorkPoint='{1}' AND LotNo = '{0}')
  2745. BEGIN
  2746. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo355")) + @"',16,1);
  2747. RETURN
  2748. END
  2749. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2750. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2751. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2752. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2753. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  2754. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  2755. c.WarehouseCode,c.LocationCode,'{9}','{10}',{6},
  2756. '','0','{7}','{8}','0','',
  2757. '','','',f.F_Account ,f.F_RealName ,
  2758. SYSDATETIME() ,a.WorkPoint ,'','{11}'
  2759. FROM ICSInventoryLot a
  2760. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2761. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2762. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2763. ";
  2764. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode, MergeID);
  2765. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2766. {
  2767. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2768. }
  2769. ///更新库存
  2770. sql = @"UPDATE ICSWareHouseLotInfo SET WareHouseCode='{2}',LocationCode='{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  2771. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  2772. BEGIN
  2773. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  2774. RETURN
  2775. END";
  2776. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode);
  2777. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2778. {
  2779. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  2780. }
  2781. }
  2782. DateTime now = DateTime.Now;
  2783. sql = @"select 1 from ICSContainerLot
  2784. where LotNo='{0}' and WorkPoint='{1}'
  2785. ";
  2786. sql = string.Format(sql, LotNo, WorkPoint);
  2787. log.Debug("查询容器条码关联表是否存在");
  2788. DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
  2789. if (dttte.Rows.Count > 0)
  2790. {
  2791. ///删除条码关联表数据
  2792. sql = @"DELETE FROM ICSContainerLot
  2793. where LotNo='{0}' and WorkPoint='{1}'
  2794. ";
  2795. sql = string.Format(sql, LotNo, WorkPoint);
  2796. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2797. {
  2798. throw new Exception(language.GetNameByCode("容器条码关联表数据删除失败"));
  2799. }
  2800. }
  2801. }
  2802. catch (Exception)
  2803. {
  2804. throw;
  2805. }
  2806. return lstDt;
  2807. }
  2808. /// <summary>
  2809. /// 移库
  2810. /// </summary>
  2811. /// <param name="LocationCode"></param>
  2812. /// <param name="LotNo"></param>
  2813. /// <param name="Quantity"></param>
  2814. /// <param name="User"></param>
  2815. /// <param name="WorkPoint"></param>
  2816. /// <param name="TransType"></param>
  2817. /// <param name="BusinessCode"></param>
  2818. /// <param name="cmd"></param>
  2819. public static void WareHouseLotInfoLibrary(string Identification, string TransCode, string TransSequence, string WarehouseCode, string LocationCode,
  2820. string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  2821. {
  2822. try
  2823. {
  2824. string sql = @"SELECT WarehouseCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  2825. sql = string.Format(sql, LotNo,WorkPoint);
  2826. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2827. if (dt == null || dt.Rows.Count <= 0)
  2828. {
  2829. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
  2830. }
  2831. string whcode = dt.Rows[0]["WarehouseCode"].ToString();
  2832. ///添加日志
  2833. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2834. BEGIN
  2835. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2836. RETURN
  2837. END
  2838. IF('" + whcode + @"' != '{8}')
  2839. BEGIN
  2840. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo394"), "{8}", whcode) + @"', 16, 1);
  2841. RETURN
  2842. END
  2843. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2844. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2845. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2846. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2847. MTIME,WorkPoint,EATTRIBUTE1 )
  2848. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  2849. c.WarehouseCode,c.LocationCode,'{8}','{9}',c.Quantity,
  2850. '','0','{6}','{7}','0','',
  2851. '','','',f.F_Account ,f.F_RealName ,
  2852. SYSDATETIME() ,a.WorkPoint ,''
  2853. FROM ICSInventoryLot a
  2854. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2855. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2856. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2857. ";
  2858. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, BusinessCode, WarehouseCode, LocationCode);
  2859. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2860. {
  2861. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2862. }
  2863. ///添加库存
  2864. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity>0)
  2865. BEGIN
  2866. RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
  2867. RETURN
  2868. END
  2869. IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.WarehouseCode='{2}')
  2870. BEGIN
  2871. RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
  2872. RETURN
  2873. END
  2874. UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  2875. ";
  2876. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode);
  2877. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2878. {
  2879. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
  2880. }
  2881. DateTime now = DateTime.Now;
  2882. sql = @"select 1 from ICSContainerLot
  2883. where LotNo='{0}' and WorkPoint='{1}'
  2884. ";
  2885. sql = string.Format(sql, LotNo, WorkPoint);
  2886. log.Debug("查询容器条码关联表是否存在");
  2887. DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
  2888. if (dttte.Rows.Count > 0)
  2889. {
  2890. ///删除条码关联表数据
  2891. sql = @"DELETE FROM ICSContainerLot
  2892. where LotNo='{0}' and WorkPoint='{1}'
  2893. ";
  2894. sql = string.Format(sql, LotNo, WorkPoint);
  2895. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2896. {
  2897. throw new Exception(language.GetNameByCode("容器条码关联表数据删除失败"));
  2898. }
  2899. }
  2900. }
  2901. catch (Exception)
  2902. {
  2903. throw;
  2904. }
  2905. }
  2906. /// <summary>
  2907. /// 两步调入
  2908. /// </summary>
  2909. /// <param name="LocationCode"></param>
  2910. /// <param name="LotNo"></param>
  2911. /// <param name="Quantity"></param>
  2912. /// <param name="User"></param>
  2913. /// <param name="WorkPoint"></param>
  2914. /// <param name="TransType"></param>
  2915. /// <param name="BusinessCode"></param>
  2916. /// <param name="cmd"></param>
  2917. public static void WareHouseLotInfoTwoStepTransferDocIn(string Identification, string TransCode, string TransSequence, string WarehouseCode,
  2918. string LocationCode, string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  2919. {
  2920. try
  2921. {
  2922. ///添加日志
  2923. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2924. BEGIN
  2925. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2926. RETURN
  2927. END
  2928. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2929. ToWarehouseCode,ToLocationCode,Quantity,
  2930. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2931. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2932. MTIME,WorkPoint,EATTRIBUTE1)
  2933. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  2934. '{9}','{10}','{6}',
  2935. '','0','{7}','{8}','0','',
  2936. '','','',f.F_Account ,f.F_RealName ,
  2937. SYSDATETIME() ,a.WorkPoint ,''
  2938. FROM ICSInventoryLot a
  2939. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2940. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2941. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2942. ";
  2943. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode);
  2944. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2945. {
  2946. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2947. }
  2948. ///添加库存
  2949. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  2950. BEGIN
  2951. RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
  2952. RETURN
  2953. END
  2954. UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}',Quantity=Quantity+'{4}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  2955. ";
  2956. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode, Quantity);
  2957. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2958. {
  2959. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
  2960. }
  2961. }
  2962. catch (Exception)
  2963. {
  2964. throw;
  2965. }
  2966. }
  2967. /// <summary>
  2968. /// 合并日志
  2969. /// </summary>
  2970. /// <param name="Identification"></param>
  2971. /// <param name="LotNo"></param>
  2972. /// <param name="User"></param>
  2973. /// <param name="WorkPoint"></param>
  2974. /// <param name="TransType"></param>
  2975. /// <param name="BusinessCode"></param>
  2976. /// <param name="cmd"></param>
  2977. public static DataTable WareHouseLotInfoLogMerge(string Identification, string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, string newLotno, SqlCommand cmd, Dictionary<string, string> language)
  2978. {
  2979. String LotEnable = "";
  2980. String PrintEnable = "";
  2981. DataTable dtLotno = new DataTable();
  2982. DataTable lstDt = new DataTable();
  2983. try
  2984. {
  2985. //检验是否分批
  2986. string sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  2987. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  2988. where a.LotNo='{0}' and a.WorkPoint='{1}'
  2989. ";
  2990. sql = string.Format(sql, LotNo, WorkPoint);
  2991. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2992. if (dt.Rows.Count == 0)
  2993. {
  2994. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  2995. }
  2996. else
  2997. {
  2998. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  2999. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  3000. }
  3001. ///添加日志
  3002. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  3003. BEGIN
  3004. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3005. RETURN
  3006. END
  3007. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  3008. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  3009. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  3010. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  3011. MTIME,WorkPoint,EATTRIBUTE1)
  3012. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  3013. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  3014. '','0','{4}','{5}','0','',
  3015. '','','',f.F_Account ,f.F_RealName ,
  3016. SYSDATETIME() ,a.WorkPoint ,''
  3017. FROM ICSInventoryLot a
  3018. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3019. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  3020. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3021. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  3022. ";
  3023. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  3024. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3025. {
  3026. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  3027. }
  3028. if (PrintEnable.Equals("True"))
  3029. {
  3030. sql = @"select A.LotNO , B.Quantity AS OLDLotQty, C.Quantity AS LotQty ,b.InvCode,d.INVSTD,d.INVNAME,b.MTIME,A.TransCode
  3031. from ICSWareHouseLotInfolog A
  3032. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  3033. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  3034. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  3035. where a.BusinessCode='34'
  3036. and A.lotno = '{0}' and a.workpoint='{1}'
  3037. ";
  3038. sql = string.Format(sql, LotNo, WorkPoint, BusinessCode, newLotno);
  3039. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  3040. lstDt = dtLotno;
  3041. }
  3042. }
  3043. catch (Exception)
  3044. {
  3045. throw;
  3046. }
  3047. return lstDt;
  3048. }
  3049. /// <summary>
  3050. /// 拆分、合并日志
  3051. /// </summary>
  3052. /// <param name="Identification"></param>
  3053. /// <param name="LotNo"></param>
  3054. /// <param name="User"></param>
  3055. /// <param name="WorkPoint"></param>
  3056. /// <param name="TransType"></param>
  3057. /// <param name="BusinessCode"></param>
  3058. /// <param name="cmd"></param>
  3059. public static DataTable WareHouseLotInfoLog(string Identification, string LotNo, string User, string WorkPoint, string TransType, string BusinessCode,string newLotno, SqlCommand cmd, Dictionary<string, string> language)
  3060. {
  3061. String LotEnable = "";
  3062. String PrintEnable = "";
  3063. DataTable dtLotno = new DataTable();
  3064. DataTable lstDt = new DataTable();
  3065. try{
  3066. //检验是否分批
  3067. string sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  3068. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  3069. where a.LotNo='{0}' and a.WorkPoint='{1}'
  3070. ";
  3071. sql = string.Format(sql, LotNo, WorkPoint);
  3072. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  3073. if (dt.Rows.Count == 0)
  3074. {
  3075. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  3076. }
  3077. else
  3078. {
  3079. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  3080. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  3081. }
  3082. ///添加日志
  3083. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  3084. BEGIN
  3085. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3086. RETURN
  3087. END
  3088. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  3089. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  3090. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  3091. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  3092. MTIME,WorkPoint,EATTRIBUTE1)
  3093. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  3094. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  3095. '','0','{4}','{5}','0','',
  3096. '','','',f.F_Account ,f.F_RealName ,
  3097. SYSDATETIME() ,a.WorkPoint ,''
  3098. FROM ICSInventoryLot a
  3099. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3100. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  3101. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3102. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  3103. ";
  3104. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  3105. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3106. {
  3107. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  3108. }
  3109. if (PrintEnable.Equals("True"))
  3110. {
  3111. sql = @"select A.LotNO , C.Quantity AS OLDLotQty, B.Quantity AS LotQty ,b.InvCode,d.INVSTD,d.INVNAME,b.MTIME,A.TransCode,c.LocationCode,f.BatchCode
  3112. from ICSWareHouseLotInfolog A
  3113. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  3114. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  3115. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  3116. left JOIN ICSExtension f on b.ExtensionID=f.id and b.WorkPoint=f.WorkPoint
  3117. where a.BusinessCode='32'
  3118. and A.lotno = '{3}' and a.workpoint='{1}'
  3119. ";
  3120. sql = string.Format(sql, LotNo, WorkPoint, BusinessCode,newLotno);
  3121. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  3122. lstDt = dtLotno;
  3123. }
  3124. }
  3125. catch (Exception)
  3126. {
  3127. throw;
  3128. }
  3129. return lstDt;
  3130. }
  3131. /// <summary>
  3132. /// 合并
  3133. /// </summary>
  3134. /// <param name="Identification"></param>
  3135. /// <param name="LotNo"></param>
  3136. /// <param name="User"></param>
  3137. /// <param name="WorkPoint"></param>
  3138. /// <param name="TransType"></param>
  3139. /// <param name="BusinessCode"></param>
  3140. /// <param name="cmd"></param>
  3141. public static void WareHouseLotInfoMerge(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
  3142. string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  3143. {
  3144. try
  3145. {
  3146. ///更新目标条码库存
  3147. string sql = @"IF NOT EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  3148. INNER JOIN ICSInventoryLot b ON b.LotNo='{3}' AND a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  3149. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  3150. BEGIN
  3151. RAISERROR('" + language.GetNameByCode("WMSAPIInfo170") + @"',16,1);
  3152. RETURN
  3153. END
  3154. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  3155. BEGIN
  3156. RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
  3157. RETURN
  3158. END
  3159. IF EXISTS(
  3160. SELECT * FROM ICSWareHouseLotInfo a
  3161. INNER JOIN ICSInventoryLot c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  3162. INNER JOIN ICSInventory d on c.invcode=d.invcode and c.WorkPoint=d.WorkPoint
  3163. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and d.BatchEnable='1'
  3164. )
  3165. BEGIN
  3166. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a
  3167. INNER JOIN ICSWareHouseLotInfo b ON b.LotNo='{3}' AND a.WarehouseCode=b.WarehouseCode AND a.WorkPoint=b.WorkPoint
  3168. INNER JOIN ICSInventoryLot c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  3169. INNER JOIN ICSInventoryLot d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint
  3170. INNER JOIN ICSExtension e on c.ExtensionID=e.ID and c.WorkPoint=e.WorkPoint
  3171. INNER JOIN ICSExtension f on d.ExtensionID=f.id and d.WorkPoint=f.WorkPoint
  3172. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and e.ID=f.ID)
  3173. BEGIN
  3174. RAISERROR('/',16,1);
  3175. RETURN
  3176. END
  3177. END
  3178. IF NOT EXISTS(
  3179. SELECT * FROM ICSWareHouseLotInfo a
  3180. INNER JOIN ICSInventoryLot c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  3181. INNER JOIN ICSInventory d on c.invcode=d.invcode and c.WorkPoint=d.WorkPoint
  3182. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and d.BatchEnable='1'
  3183. )
  3184. BEGIN
  3185. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a
  3186. INNER JOIN ICSWareHouseLotInfo b ON b.LotNo='{3}' AND a.WarehouseCode=b.WarehouseCode AND a.WorkPoint=b.WorkPoint
  3187. INNER JOIN ICSInventoryLot c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  3188. INNER JOIN ICSInventoryLot d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint
  3189. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  3190. BEGIN
  3191. RAISERROR('/',16,1);
  3192. RETURN
  3193. END
  3194. END
  3195. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  3196. UPDATE ICSInventoryLot SET Amount=(ISNULL(Amount,0)+(select Amount from
  3197. ICSInventoryLot where LotNo='{3}' AND WorkPoint='{1}')) WHERE LotNo='{0}' AND WorkPoint='{1}'
  3198. ";
  3199. sql = string.Format(sql, LotNo, WorkPoint, Quantity, CurrentLotNo);
  3200. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3201. {
  3202. throw new Exception(language.GetNameByCode("WMSAPIInfo169"));//"目标条码库存更新失败!");
  3203. }
  3204. ///更新原条码库存
  3205. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  3206. UPDATE ICSInventoryLot SET Amount=(ISNULL(Amount,0)-(select Amount from
  3207. ICSInventoryLot where LotNo='{0}' AND WorkPoint='{1}')) WHERE LotNo='{0}' AND WorkPoint='{1}'
  3208. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  3209. BEGIN
  3210. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  3211. RETURN
  3212. END";
  3213. sql = string.Format(sql, CurrentLotNo, WorkPoint, Quantity);
  3214. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3215. {
  3216. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  3217. }
  3218. ///添加日志
  3219. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  3220. BEGIN
  3221. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3222. RETURN
  3223. END
  3224. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  3225. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  3226. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  3227. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  3228. MTIME,WorkPoint,EATTRIBUTE1)
  3229. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  3230. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  3231. '','0','{4}','{5}','0','',
  3232. '','','',f.F_Account ,f.F_RealName ,
  3233. SYSDATETIME() ,a.WorkPoint ,''
  3234. FROM ICSInventoryLot a
  3235. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3236. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  3237. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3238. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  3239. ";
  3240. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  3241. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3242. {
  3243. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  3244. }
  3245. }
  3246. catch (Exception)
  3247. {
  3248. throw;
  3249. }
  3250. }
  3251. /// <summary>
  3252. /// 拆分
  3253. /// </summary>
  3254. /// <param name="Identification"></param>
  3255. /// <param name="LotNo"></param>
  3256. /// <param name="User"></param>
  3257. /// <param name="WorkPoint"></param>
  3258. /// <param name="TransType"></param>
  3259. /// <param name="BusinessCode"></param>
  3260. /// <param name="cmd"></param>
  3261. public static void WareHouseLotInfoSplit(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
  3262. string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  3263. {
  3264. try
  3265. {
  3266. ///更新库存
  3267. string sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  3268. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  3269. BEGIN
  3270. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  3271. RETURN
  3272. END";
  3273. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  3274. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3275. {
  3276. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  3277. }
  3278. #region 添加库存
  3279. //插入条码表
  3280. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  3281. BEGIN
  3282. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3283. RETURN
  3284. END
  3285. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a WHERE a.LotNo='{4}' AND a.WorkPoint='{1}')
  3286. BEGIN
  3287. RAISERROR('" + language.GetNameByCode("WMSAPIInfo172") + @"',16,1);
  3288. RETURN
  3289. END
  3290. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,Amount,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  3291. SELECT NEWID(),'{4}' ,a.InvCode,a.ProductDate,a.ExpirationDate ,'{3}',a.Amount/a.Quantity*{3},a.ExtensionID,'101',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,a.LotNo
  3292. FROM ICSInventoryLot a
  3293. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3294. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  3295. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, CurrentLotNo);
  3296. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3297. {
  3298. throw new Exception(language.GetNameByCode("WMSAPIInfo173"));//"条码表写入失败!");
  3299. }
  3300. //插入条码单据表
  3301. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  3302. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  3303. FROM ICSInventoryLot a
  3304. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3305. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3306. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  3307. sql = string.Format(sql, LotNo, WorkPoint, User, CurrentLotNo);
  3308. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3309. {
  3310. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  3311. }
  3312. ///添加库存
  3313. sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  3314. BEGIN
  3315. RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
  3316. RETURN
  3317. END
  3318. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  3319. SELECT NEWID(),a.LotNo ,d.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  3320. FROM ICSInventoryLot a
  3321. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3322. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
  3323. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3324. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  3325. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Quantity);
  3326. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3327. {
  3328. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  3329. }
  3330. ///添加日志
  3331. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  3332. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  3333. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  3334. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  3335. MTIME,WorkPoint,EATTRIBUTE1)
  3336. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  3337. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  3338. '','0','{4}','{5}','0','',
  3339. '','','',f.F_Account ,f.F_RealName ,
  3340. SYSDATETIME() ,a.WorkPoint ,''
  3341. FROM ICSInventoryLot a
  3342. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3343. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  3344. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3345. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  3346. ";
  3347. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  3348. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3349. {
  3350. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  3351. }
  3352. #endregion
  3353. }
  3354. catch (Exception)
  3355. {
  3356. throw;
  3357. }
  3358. }
  3359. /// <summary>
  3360. /// 拆分(奥美)
  3361. /// </summary>
  3362. /// <param name="Identification"></param>
  3363. /// <param name="LotNo"></param>
  3364. /// <param name="User"></param>
  3365. /// <param name="WorkPoint"></param>
  3366. /// <param name="TransType"></param>
  3367. /// <param name="BusinessCode"></param>
  3368. /// <param name="cmd"></param>
  3369. public static void AMWareHouseLotInfoSplit(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
  3370. string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  3371. {
  3372. try
  3373. {
  3374. string amount = "";
  3375. //string sqql = @"select a.Amount FROM ICSInventoryLot a
  3376. // WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  3377. //sqql = string.Format(sqql, LotNo, WorkPoint);
  3378. //DataTable dtaa = DBHelper.SQlReturnData(sqql, cmd);
  3379. //amount = dtaa.Rows[0]["Amount"].ToString();
  3380. string cheksql = @"select d.EATTRIBUTE1 FROM ICSInventoryLot a
  3381. INNER JOIN ICSWareHouseLotInfo b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3382. INNER JOIN ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  3383. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and d.AmountEnable='1'";
  3384. cheksql = string.Format(cheksql, LotNo, WorkPoint);
  3385. DataTable dta = DBHelper.SQlReturnData(cheksql, cmd);
  3386. if (dta.Rows.Count > 0)
  3387. {
  3388. Quantity = (decimal.Parse(Quantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  3389. }
  3390. ///更新库存
  3391. string sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  3392. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  3393. BEGIN
  3394. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  3395. RETURN
  3396. END";
  3397. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  3398. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3399. {
  3400. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  3401. }
  3402. #region 添加库存
  3403. //插入条码表
  3404. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  3405. BEGIN
  3406. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3407. RETURN
  3408. END
  3409. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a WHERE a.LotNo='{4}' AND a.WorkPoint='{1}')
  3410. BEGIN
  3411. RAISERROR('" + language.GetNameByCode("WMSAPIInfo172") + @"',16,1);
  3412. RETURN
  3413. END
  3414. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,Amount,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  3415. SELECT NEWID(),'{4}' ,a.InvCode,a.ProductDate,a.ExpirationDate ,'{3}',a.Amount/a.Quantity*{3},a.ExtensionID,'101',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,a.LotNo
  3416. FROM ICSInventoryLot a
  3417. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3418. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  3419. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, CurrentLotNo);
  3420. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3421. {
  3422. throw new Exception(language.GetNameByCode("WMSAPIInfo173"));//"条码表写入失败!");
  3423. }
  3424. //插入条码单据表
  3425. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  3426. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  3427. FROM ICSInventoryLot a
  3428. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3429. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3430. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  3431. sql = string.Format(sql, LotNo, WorkPoint, User, CurrentLotNo);
  3432. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3433. {
  3434. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  3435. }
  3436. ///添加库存
  3437. sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  3438. BEGIN
  3439. RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
  3440. RETURN
  3441. END
  3442. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  3443. SELECT NEWID(),a.LotNo ,d.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  3444. FROM ICSInventoryLot a
  3445. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3446. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
  3447. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3448. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  3449. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Quantity);
  3450. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3451. {
  3452. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  3453. }
  3454. ///添加日志
  3455. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  3456. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  3457. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  3458. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  3459. MTIME,WorkPoint,EATTRIBUTE1)
  3460. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  3461. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  3462. '','0','{4}','{5}','0','',
  3463. '','','',f.F_Account ,f.F_RealName ,
  3464. SYSDATETIME() ,a.WorkPoint ,''
  3465. FROM ICSInventoryLot a
  3466. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3467. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  3468. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3469. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  3470. ";
  3471. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  3472. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3473. {
  3474. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  3475. }
  3476. #endregion
  3477. }
  3478. catch (Exception)
  3479. {
  3480. throw;
  3481. }
  3482. }
  3483. /// <summary>
  3484. /// 回写ERP ID
  3485. /// </summary>
  3486. /// <param name="TransType"></param>
  3487. /// <param name="SourceDetailID"></param>
  3488. /// <param name="Identification"></param>
  3489. /// <param name="ID"></param>
  3490. /// <param name="DetailID"></param>
  3491. /// <param name="Code"></param>
  3492. /// <param name="Sequence"></param>
  3493. /// <param name="cmd"></param>
  3494. public static void WareHouseLotInfoLogUpdate(string TransType, string SourceDetailID, string Identification, string ID, string DetailID, string Code, string Sequence, string col, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  3495. {
  3496. string ERPupdate = string.Empty;
  3497. string NewERPupdate = string.Empty;
  3498. try
  3499. {
  3500. //采购入库
  3501. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  3502. {
  3503. ERPupdate = @"SELECT a.id
  3504. INTO #NewTempERP
  3505. FROM ICSWareHouseLotInfoLog a
  3506. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3507. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3508. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3509. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3510. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3511. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3512. WHERE c.PODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3513. and (ISNULL(a.towarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3514. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3515. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3516. where ID in (select id from #NewTempERP)
  3517. DROP TABLE #NewTempERP";
  3518. }
  3519. //审核的到货单
  3520. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  3521. {
  3522. ERPupdate = @"SELECT a.id
  3523. INTO #NewTempERP
  3524. FROM ICSWareHouseLotInfoLog a
  3525. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3526. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3527. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3528. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3529. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3530. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3531. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3532. and (ISNULL(a.towarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3533. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3534. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3535. where ID in (select id from #NewTempERP)
  3536. DROP TABLE #NewTempERP
  3537. ";
  3538. }
  3539. //采购拒收
  3540. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  3541. {
  3542. ERPupdate = @"SELECT a.id
  3543. INTO #NewTempERP
  3544. FROM ICSWareHouseLotInfoLog a
  3545. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3546. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3547. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3548. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3549. where ID in (select id from #NewTempERP)
  3550. DROP TABLE #NewTempERP
  3551. ";
  3552. }
  3553. //审核的委外到货单
  3554. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  3555. {
  3556. ERPupdate = @"SELECT a.id
  3557. INTO #NewTempERP
  3558. FROM ICSWareHouseLotInfoLog a
  3559. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3560. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3561. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3562. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3563. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3564. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3565. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3566. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3567. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3568. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3569. where ID in (select id from #NewTempERP)
  3570. DROP TABLE #NewTempERP
  3571. ";
  3572. }
  3573. //委外拒收
  3574. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  3575. {
  3576. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3577. FROM ICSWareHouseLotInfoLog a
  3578. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3579. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3580. ";
  3581. }
  3582. //采购退货
  3583. else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  3584. {
  3585. ERPupdate = @"SELECT a.id
  3586. INTO #NewTempERP
  3587. FROM ICSWareHouseLotInfoLog a
  3588. INNER JOIN ICSDeliveryNotice c ON a.TransCode=c.DNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3589. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3590. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3591. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3592. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3593. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DNType='2' AND a.BusinessCode ='{7}'
  3594. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3595. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3596. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3597. where ID in (select id from #NewTempERP)
  3598. DROP TABLE #NewTempERP
  3599. ";
  3600. }
  3601. //委外发料
  3602. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  3603. {
  3604. ERPupdate = @"SELECT a.id
  3605. INTO #NewTempERP
  3606. FROM ICSWareHouseLotInfoLog a
  3607. INNER JOIN ICSOutsourcingOrder y ON a.TransCode=y.OOCode AND a.WorkPoint=y.WorkPoint
  3608. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  3609. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3610. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3611. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3612. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3613. WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3614. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3615. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3616. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3617. where ID in (select id from #NewTempERP)
  3618. DROP TABLE #NewTempERP
  3619. ";
  3620. }
  3621. //委外退料
  3622. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  3623. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  3624. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  3625. {
  3626. ERPupdate = @"--根据退料单退料
  3627. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3628. FROM ICSWareHouseLotInfoLog a
  3629. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3630. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  3631. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  3632. Left JOIN ICSOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  3633. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3634. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3635. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3636. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3637. WHERE ISNULL(m.ApplyDetailID,ISNULL(m.PickID, c.SourceDetailID))='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3638. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3639. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3640. --退-
  3641. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3642. FROM ICSWareHouseLotInfoLog a
  3643. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  3644. INNER JOIN ICSOutsourcingOrder y ON b.TransCode=y.OOCode AND b.WorkPoint=y.WorkPoint
  3645. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  3646. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3647. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3648. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3649. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3650. WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  3651. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3652. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3653. --退-
  3654. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3655. FROM ICSWareHouseLotInfoLog a
  3656. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  3657. INNER JOIN ICSOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  3658. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3659. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3660. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3661. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3662. WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  3663. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3664. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3665. --退-
  3666. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3667. FROM ICSWareHouseLotInfoLog a
  3668. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  3669. INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  3670. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  3671. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  3672. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  3673. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3674. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3675. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3676. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3677. WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  3678. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3679. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3680. ";
  3681. }
  3682. //委外入库
  3683. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  3684. {
  3685. ERPupdate = @"SELECT a.id
  3686. INTO #NewTempERP
  3687. FROM ICSWareHouseLotInfoLog a
  3688. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3689. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3690. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3691. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3692. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3693. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3694. WHERE c.OODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3695. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3696. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3697. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3698. where ID in (select id from #NewTempERP)
  3699. DROP TABLE #NewTempERP";
  3700. }
  3701. //委外退货
  3702. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  3703. {
  3704. ERPupdate = @"SELECT a.id
  3705. INTO #NewTempERP
  3706. FROM ICSWareHouseLotInfoLog a
  3707. INNER JOIN ICSODeliveryNotice c ON a.TransCode=c.ODNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3708. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3709. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3710. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3711. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3712. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.ODNType='2' AND a.BusinessCode ='{7}'
  3713. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3714. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3715. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3716. where ID in (select id from #NewTempERP)
  3717. DROP TABLE #NewTempERP
  3718. ";
  3719. }
  3720. //生产发料
  3721. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  3722. {
  3723. //ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3724. // FROM ICSWareHouseLotInfoLog a
  3725. // INNER JOIN ICSMO y ON a.TransCode=y.MOCode AND a.WorkPoint=y.WorkPoint
  3726. // INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  3727. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3728. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3729. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3730. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3731. // WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3732. // and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3733. // ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3734. // ";
  3735. ERPupdate = @"SELECT a.id
  3736. INTO #NewTempERP
  3737. FROM ICSWareHouseLotInfoLog a
  3738. INNER JOIN ICSMO y ON a.TransCode=y.MOCode AND a.WorkPoint=y.WorkPoint
  3739. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  3740. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3741. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3742. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3743. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3744. WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3745. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3746. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3747. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3748. where ID in (select id from #NewTempERP)
  3749. DROP TABLE #NewTempERP";
  3750. }
  3751. //生产退料
  3752. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  3753. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  3754. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  3755. {
  3756. ERPupdate = @"--根据退料单退料
  3757. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3758. FROM ICSWareHouseLotInfoLog a
  3759. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3760. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  3761. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  3762. left JOIN ICSMOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  3763. WHERE ISNULL(m.ApplyDetailID, ISNULL(m.PickID, c.SourceDetailID))='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3764. --退-
  3765. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3766. FROM ICSWareHouseLotInfoLog a
  3767. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  3768. INNER JOIN ICSMO y ON b.TransCode=y.MOCode AND b.WorkPoint=y.WorkPoint
  3769. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  3770. WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  3771. --退-
  3772. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3773. FROM ICSWareHouseLotInfoLog a
  3774. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  3775. INNER JOIN ICSMOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  3776. WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  3777. --退-
  3778. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3779. FROM ICSWareHouseLotInfoLog a
  3780. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  3781. INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  3782. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  3783. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  3784. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  3785. WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  3786. ";
  3787. }
  3788. //生产入库
  3789. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  3790. {
  3791. //ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3792. // FROM ICSWareHouseLotInfoLog a
  3793. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3794. // INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3795. // INNER JOIN ICSExtension docext ON docext.ID=c.ExtensionID AND docext.WorkPoint=c.WorkPoint
  3796. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3797. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3798. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3799. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3800. // WHERE c.MODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3801. // and (ISNULL(a.fromwarehousecode, '')
  3802. // + CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END
  3803. // + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END
  3804. // + CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END
  3805. // + CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END
  3806. // + CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END
  3807. // + CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END
  3808. // + CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END
  3809. // + CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END
  3810. // + CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END
  3811. // + CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END
  3812. // + CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END
  3813. // + CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END
  3814. // + CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END
  3815. // + CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END)='{6}'
  3816. //";
  3817. ERPupdate = @"SELECT a.id
  3818. INTO #NewTempERP
  3819. FROM ICSWareHouseLotInfoLog a
  3820. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3821. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3822. INNER JOIN ICSExtension docext ON docext.ID=c.ExtensionID AND docext.WorkPoint=c.WorkPoint
  3823. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3824. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3825. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3826. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3827. WHERE c.MODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3828. and (ISNULL(a.fromwarehousecode, '')
  3829. + CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END
  3830. + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END
  3831. + CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END
  3832. + CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END
  3833. + CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END
  3834. + CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END
  3835. + CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END
  3836. + CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END
  3837. + CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END
  3838. + CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END
  3839. + CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END
  3840. + CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END
  3841. + CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END
  3842. + CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END)='{6}'
  3843. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3844. where ID in (select id from #NewTempERP)
  3845. DROP TABLE #NewTempERP
  3846. ";
  3847. }
  3848. //开立的生产入库单
  3849. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  3850. {
  3851. ERPupdate = @"SELECT a.id
  3852. INTO #NewTempERP
  3853. FROM ICSWareHouseLotInfoLog a
  3854. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3855. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3856. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND a.BusinessCode ='{7}'
  3857. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3858. where ID in (select id from #NewTempERP)
  3859. DROP TABLE #NewTempERP
  3860. ";
  3861. }
  3862. //销售出库
  3863. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  3864. {
  3865. ERPupdate = @"SELECT a.id
  3866. INTO #NewTempERP
  3867. FROM ICSWareHouseLotInfoLog a
  3868. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3869. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3870. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3871. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3872. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3873. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND a.BusinessCode ='{7}'
  3874. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3875. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3876. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3877. where ID in (select id from #NewTempERP)
  3878. DROP TABLE #NewTempERP
  3879. ";
  3880. }
  3881. //销售退货
  3882. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  3883. {
  3884. ERPupdate = @"SELECT a.id
  3885. INTO #NewTempERP
  3886. FROM ICSWareHouseLotInfoLog a
  3887. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3888. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3889. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3890. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3891. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3892. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND a.BusinessCode ='{7}'
  3893. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3894. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3895. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3896. where ID in (select id from #NewTempERP)
  3897. DROP TABLE #NewTempERP";
  3898. }
  3899. //返工工单
  3900. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  3901. {
  3902. ERPupdate = @"SELECT a.id
  3903. INTO #NewTempERP
  3904. FROM ICSWareHouseLotInfoLog a
  3905. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3906. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  3907. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  3908. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3909. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3910. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3911. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3912. WHERE d.PickID='{3}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3913. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3914. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3915. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3916. where ID in (select id from #NewTempERP)
  3917. DROP TABLE #NewTempERP
  3918. ";
  3919. }
  3920. //一步调拨
  3921. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  3922. {
  3923. ERPupdate = @"SELECT a.id
  3924. INTO #NewTempERP
  3925. FROM ICSWareHouseLotInfoLog a
  3926. INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3927. WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND a.BusinessCode ='{7}'
  3928. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3929. where ID in (select id from #NewTempERP)
  3930. DROP TABLE #NewTempERP
  3931. ";
  3932. }
  3933. //调拨
  3934. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  3935. {
  3936. ERPupdate = @"SELECT a.id
  3937. INTO #NewTempERP
  3938. FROM ICSWareHouseLotInfoLog a
  3939. INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3940. WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND a.BusinessCode ='{7}'
  3941. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3942. where ID in (select id from #NewTempERP)
  3943. DROP TABLE #NewTempERP
  3944. ";
  3945. }
  3946. //无源头调拨
  3947. else if (TransType == TransTypeEnum.StepNoTransferDocIn.GetDescription())
  3948. {
  3949. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3950. FROM ICSWareHouseLotInfoLog a
  3951. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3952. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3953. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3954. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3955. WHERE a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode='70'
  3956. and (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3957. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3958. ";
  3959. }
  3960. //两步调出
  3961. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  3962. {
  3963. ERPupdate = @"SELECT a.id
  3964. INTO #NewTempERP
  3965. FROM ICSWareHouseLotInfoLog a
  3966. INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3967. INNER JOIN ICSTransfer d ON c.TransferDetailID=d.TransferDetailID AND c.WorkPoint=d.WorkPoint
  3968. WHERE c.OutID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3969. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3970. where ID in (select id from #NewTempERP)
  3971. DROP TABLE #NewTempERP
  3972. ";
  3973. }
  3974. //两步调入
  3975. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  3976. {
  3977. ERPupdate = @"SELECT a.id
  3978. INTO #NewTempERP
  3979. FROM ICSWareHouseLotInfoLog a
  3980. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  3981. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  3982. WHERE b.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3983. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3984. where ID in (select id from #NewTempERP)
  3985. DROP TABLE #NewTempERP
  3986. ";
  3987. }
  3988. //销售退货-原条码
  3989. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  3990. {
  3991. ERPupdate = @"SELECT a.id
  3992. INTO #NewTempERP
  3993. FROM ICSWareHouseLotInfoLog a
  3994. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3995. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3996. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3997. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3998. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3999. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND a.BusinessCode ='{7}'
  4000. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4001. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4002. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4003. where ID in (select id from #NewTempERP)
  4004. DROP TABLE #NewTempERP";
  4005. }
  4006. //其他出库
  4007. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  4008. {
  4009. ERPupdate = @"SELECT a.id
  4010. INTO #NewTempERP
  4011. FROM ICSWareHouseLotInfoLog a
  4012. INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4013. WHERE c.OutID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  4014. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4015. where ID in (select id from #NewTempERP)
  4016. DROP TABLE #NewTempERP
  4017. ";
  4018. }
  4019. //其他入库
  4020. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  4021. {
  4022. ERPupdate = @"SELECT a.id
  4023. INTO #NewTempERP
  4024. FROM ICSWareHouseLotInfoLog a
  4025. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  4026. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  4027. WHERE c.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4028. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4029. where ID in (select id from #NewTempERP)
  4030. DROP TABLE #NewTempERP
  4031. ";
  4032. }
  4033. //拆卸单
  4034. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  4035. {
  4036. ERPupdate = @"UPDATE d set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4037. FROM ICSWareHouseLotInfoLog a
  4038. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  4039. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  4040. INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
  4041. WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND d.ERPUpload='0' AND a.BusinessCode ='{7}'
  4042. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4043. FROM ICSWareHouseLotInfoLog a
  4044. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  4045. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  4046. WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DABDOCType='2' AND a.BusinessCode ='{7}'
  4047. ";
  4048. }
  4049. //领料申请单
  4050. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  4051. {
  4052. //ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4053. // FROM ICSWareHouseLotInfoLog a
  4054. // INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4055. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4056. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4057. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4058. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4059. // WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4060. // and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4061. // ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4062. // ";
  4063. ERPupdate = @"SELECT a.id
  4064. INTO #NewTempERP
  4065. FROM ICSWareHouseLotInfoLog a
  4066. INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4067. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4068. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4069. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4070. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4071. WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4072. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4073. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4074. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4075. where ID in (select id from #NewTempERP)
  4076. DROP TABLE #NewTempERP
  4077. ";
  4078. }
  4079. //补料申请单
  4080. else if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
  4081. {
  4082. //ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4083. // FROM ICSWareHouseLotInfoLog a
  4084. // INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4085. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4086. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4087. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4088. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4089. // WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4090. // and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4091. // ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4092. // ";
  4093. ERPupdate = @"SELECT a.id
  4094. INTO #NewTempERP
  4095. FROM ICSWareHouseLotInfoLog a
  4096. INNER JOIN ICSMOReplenishment c ON a.TransCode=c.ReplenishmentCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4097. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4098. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4099. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4100. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4101. WHERE c.ReplenishmentDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4102. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4103. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4104. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4105. where ID in (select id from #NewTempERP)
  4106. DROP TABLE #NewTempERP
  4107. ";
  4108. }
  4109. //委外领料申请单
  4110. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  4111. {
  4112. //ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4113. // FROM ICSWareHouseLotInfoLog a
  4114. // INNER JOIN ICSOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4115. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4116. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4117. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4118. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4119. // WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4120. // and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4121. // ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4122. // ";
  4123. ERPupdate = @"SELECT a.id
  4124. INTO #NewTempERP
  4125. FROM ICSWareHouseLotInfoLog a
  4126. INNER JOIN ICSOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4127. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4128. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4129. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4130. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4131. WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4132. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4133. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4134. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4135. where ID in (select id from #NewTempERP)
  4136. DROP TABLE #NewTempERP
  4137. ";
  4138. }
  4139. //开立材料出库
  4140. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  4141. {
  4142. ERPupdate = @"SELECT a.id
  4143. INTO #NewTempERP
  4144. FROM ICSWareHouseLotInfoLog a
  4145. INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4146. WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4147. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4148. where ID in (select id from #NewTempERP)
  4149. DROP TABLE #NewTempERP
  4150. ";
  4151. }
  4152. //开立委外材料出库
  4153. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  4154. {
  4155. ERPupdate = @"SELECT a.id
  4156. INTO #NewTempERP
  4157. FROM ICSWareHouseLotInfoLog a
  4158. INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4159. WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4160. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4161. where ID in (select id from #NewTempERP)
  4162. DROP TABLE #NewTempERP
  4163. ";
  4164. }
  4165. //开立红字入库单
  4166. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  4167. {
  4168. ERPupdate = @"SELECT a.id
  4169. INTO #NewTempERP
  4170. FROM ICSWareHouseLotInfoLog a
  4171. INNER JOIN ICSPurchaseReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4172. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND a.BusinessCode ='{7}'
  4173. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4174. where ID in (select id from #NewTempERP)
  4175. DROP TABLE #NewTempERP
  4176. ";
  4177. }
  4178. //开立委外红字入库单
  4179. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  4180. {
  4181. ERPupdate = @"SELECT a.id
  4182. INTO #NewTempERP
  4183. FROM ICSWareHouseLotInfoLog a
  4184. INNER JOIN ICSOutsourcingReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4185. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND a.BusinessCode ='{7}'
  4186. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4187. where ID in (select id from #NewTempERP)
  4188. DROP TABLE #NewTempERP
  4189. ";
  4190. }
  4191. //借用
  4192. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  4193. {
  4194. ERPupdate = @"SELECT a.id
  4195. INTO #NewTempERP
  4196. FROM ICSWareHouseLotInfoLog a
  4197. INNER JOIN ICSBrrow c ON a.TransCode=c.BrrowCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4198. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4199. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4200. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4201. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4202. WHERE c.BrrowDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4203. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4204. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4205. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4206. where ID in (select id from #NewTempERP)
  4207. DROP TABLE #NewTempERP";
  4208. }
  4209. //归还
  4210. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  4211. {
  4212. ERPupdate = @"SELECT a.id
  4213. INTO #NewTempERP
  4214. FROM ICSWareHouseLotInfoLog a
  4215. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  4216. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  4217. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4218. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4219. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4220. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4221. WHERE c.ReturnDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4222. and (ISNULL(a.tohwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4223. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4224. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4225. where ID in (select id from #NewTempERP)
  4226. DROP TABLE #NewTempERP";
  4227. }
  4228. ERPupdate = string.Format(ERPupdate, SourceDetailID, Identification, ID, DetailID, Code, Sequence, col, BusinessCode);
  4229. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  4230. {
  4231. throw new Exception(TransType + language.GetNameByCode("WMSAPIInfo175"));//"回写日志失败!");
  4232. }
  4233. }
  4234. catch (Exception ex)
  4235. {
  4236. log.Debug(ex.ToString());
  4237. log.Debug(TransType + Environment.NewLine + ERPupdate);
  4238. throw;
  4239. }
  4240. }
  4241. /// <summary>
  4242. /// 倒冲时子件已领数量回写
  4243. /// </summary>
  4244. public static void DetailQTYUpdate()
  4245. {
  4246. }
  4247. /// <summary>
  4248. /// 生成条码
  4249. /// </summary>
  4250. /// <param name="LotNo"></param>
  4251. /// <param name="Quantity"></param>
  4252. /// <param name="TransCode"></param>
  4253. /// <param name="TransSequence"></param>
  4254. /// <param name="WorkPoint"></param>
  4255. /// <param name="Identification"></param>
  4256. /// <param name="User"></param>
  4257. /// <param name="InvCode"></param>
  4258. /// <param name="BusinessCode"></param>
  4259. /// <param name="ProjectCode"></param>
  4260. /// <param name="BatchCode"></param>
  4261. /// <param name="Version"></param>
  4262. /// <param name="Brand"></param>
  4263. /// <param name="cFree1"></param>
  4264. /// <param name="cFree2"></param>
  4265. /// <param name="cFree3"></param>
  4266. /// <param name="cFree4"></param>
  4267. /// <param name="cFree5"></param>
  4268. /// <param name="cFree6"></param>
  4269. /// <param name="cFree7"></param>
  4270. /// <param name="cFree8"></param>
  4271. /// <param name="cFree9"></param>
  4272. /// <param name="cFree10"></param>
  4273. /// <param name="cmd"></param>
  4274. /// <param name="language"></param>
  4275. public static void CreateLotNo(string LotNo, string Quantity, string TransCode, string TransSequence, string WorkPoint, string Identification, string User, string InvCode, string BusinessCode,
  4276. string ProjectCode, string BatchCode, string Version, string Brand, string cFree1, string cFree2, string cFree3, string cFree4, string cFree5,string cFree6, string cFree7, string cFree8, string cFree9, string cFree10, SqlCommand cmd, Dictionary<string, string> language,string LocationCode,string OLDLotNo)
  4277. {
  4278. try
  4279. {
  4280. String EffectiveEnable = "";
  4281. String Colspan = "";
  4282. String IDD = "";
  4283. int EffectiveDays = 0;
  4284. String Time = "";
  4285. int EffectiveDayss = 0;
  4286. DateTime dtt;
  4287. DateTime now = DateTime.Now;
  4288. string sql = string.Empty;
  4289. //string sql = @"select EffectiveEnable,EffectiveDays from ICSInventory a
  4290. // Left Join ICSMO b ON a.InvCode=b.InvCode and a.WorkPoint = b.WorkPoint
  4291. // where b.MoCode='{0}' and b.WorkPoint='{1}'";
  4292. //sql = string.Format(sql, TransCode, WorkPoint);
  4293. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  4294. //if (dt.Rows.Count == 0)
  4295. //{
  4296. // throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  4297. //}
  4298. //else
  4299. //{
  4300. // EffectiveEnable = dt.Rows[0]["EffectiveEnable"].ToString();
  4301. //EffectiveDays = Convert.ToInt32(dt.Rows[0]["EffectiveDays"]);
  4302. //}
  4303. //EffectiveDayss = Convert.ToInt32(EffectiveDays);
  4304. //if (!EffectiveEnable.Equals("False"))
  4305. //{
  4306. int year = now.Year;
  4307. int month = now.Month;
  4308. int day = now.Day;
  4309. int n = DateTime.DaysInMonth(year, month);
  4310. int k = day + EffectiveDays;
  4311. if (k > n)
  4312. {
  4313. day = EffectiveDays - (n - day);
  4314. month = month + 1;
  4315. if (month > 12)
  4316. {
  4317. month = 1;
  4318. year = year + 1;
  4319. }
  4320. }
  4321. else
  4322. {
  4323. day = day + EffectiveDays;
  4324. }
  4325. Time = year + "-" + month + "-" + day;
  4326. //}
  4327. //else
  4328. //{
  4329. // Time = "2999-12-31 00:00:00.000";
  4330. //}
  4331. dtt = Convert.ToDateTime(Time);
  4332. //检验自由项
  4333. Colspan = ProjectCode + "~" + BatchCode + "~" + Version
  4334. + "~" + Brand + "~" + cFree1
  4335. + "~" + cFree2 + "~" + cFree3 + "~" + cFree4
  4336. + "~" + cFree5 + "~" + cFree6 + "~" + cFree7
  4337. + "~" + cFree8 + "~" + cFree9 + "~" + cFree10;
  4338. sql = @"select ID,Colspan from ICSExtension a
  4339. where Colspan='{0}' and WorkPoint='{1}'";
  4340. sql = string.Format(sql, Colspan, WorkPoint);
  4341. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  4342. if (dttt.Rows.Count == 0)
  4343. {
  4344. IDD = Guid.NewGuid().ToString();
  4345. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  4346. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  4347. sql = string.Format(sql, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, User, WorkPoint, IDD);
  4348. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4349. {
  4350. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  4351. }
  4352. }
  4353. else
  4354. {
  4355. IDD = dttt.Rows[0]["ID"].ToString();
  4356. }
  4357. //存入条码表
  4358. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  4359. BEGIN
  4360. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  4361. RETURN
  4362. END
  4363. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  4364. Quantity,Amount,ExtensionID,Type,PrintTimes,
  4365. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  4366. WorkPoint,EATTRIBUTE1)
  4367. SELECT TOP 1 NEWID(),'{0}','{8}',GETDATE(),'{6}',
  4368. '{1}','0','{7}','16',null,
  4369. null,null,'{2}' ,f.F_RealName ,GETDATE(),
  4370. '{4}' ,''
  4371. FROM Sys_SRM_User f
  4372. where f.F_Account='{2}' and f.F_Location='{4}'
  4373. ";
  4374. sql = string.Format(sql, LotNo, Quantity, User, TransCode, WorkPoint, TransSequence, dtt, IDD,InvCode);
  4375. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4376. {
  4377. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  4378. }
  4379. ///存入条码关联表
  4380. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{3}')
  4381. BEGIN
  4382. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  4383. RETURN
  4384. END
  4385. INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,
  4386. WorkPoint,EATTRIBUTE1)
  4387. SELECT '{4}','{0}','{1}',f.F_Account ,f.F_RealName,GETDATE(),
  4388. a.WorkPoint,''
  4389. FROM ICSInventoryLot a
  4390. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  4391. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  4392. WHERE a.LotNo='{5}' AND a.WorkPoint='{3}'
  4393. ";
  4394. sql = string.Format(sql, TransCode, TransSequence, User, WorkPoint, LotNo, OLDLotNo);
  4395. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4396. {
  4397. throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
  4398. }
  4399. //存入库存表
  4400. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  4401. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'0',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  4402. FROM ICSInventoryLot a
  4403. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  4404. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  4405. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  4406. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  4407. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  4408. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  4409. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode);
  4410. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4411. {
  4412. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  4413. }
  4414. }
  4415. catch (Exception)
  4416. {
  4417. throw;
  4418. }
  4419. }
  4420. }
  4421. }