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.

5644 lines
362 KiB

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