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.

4706 lines
304 KiB

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