纽威
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.

2135 lines
133 KiB

3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years 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)
  52. {
  53. try
  54. {
  55. #region 正常入库
  56. ///添加库存(原条码退回,更新库存;新条码直接入库)
  57. string sql = string.Empty;
  58. string locationcode = "";
  59. if (BusinessCode != TransTypeEnum.SalesReturnBack.GetDescription<DBValue>())
  60. {
  61. if (string.IsNullOrWhiteSpace(LogID))
  62. {
  63. sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  64. BEGIN
  65. RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
  66. RETURN
  67. END ";
  68. }
  69. else
  70. {
  71. sql = @"SELECT LocationCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  72. sql = string.Format(sql, LotNo, WorkPoint);
  73. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  74. if (dt == null || dt.Rows.Count <= 0)
  75. {
  76. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
  77. }
  78. locationcode = dt.Rows[0]["LocationCode"].ToString();
  79. }
  80. }
  81. sql += @" IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  82. BEGIN
  83. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  84. RETURN
  85. END
  86. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  87. BEGIN
  88. IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity=0)
  89. BEGIN
  90. UPDATE a SET a.Quantity=ISNULL(a.Quantity,0)+'{3}',WarehouseCode=e.WarehouseCode,LocationCode=d.LocationCode
  91. From ICSWareHouseLotInfo a
  92. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  93. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  94. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  95. END
  96. ELSE IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.LocationCode='{4}')
  97. BEGIN
  98. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
  99. WHERE LotNo='{0}' AND WorkPoint='{1}'
  100. END
  101. ELSE IF('" + locationcode + @"' != '{4}')
  102. BEGIN
  103. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo395"), "{4}", locationcode) + @"', 16, 1);
  104. RETURN
  105. END
  106. END
  107. ELSE
  108. BEGIN
  109. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  110. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  111. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  112. BEGIN
  113. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  114. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  115. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}' AND il.LocationCode='{4}')
  116. BEGIN
  117. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  118. RETURN
  119. END
  120. END
  121. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  122. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  123. FROM ICSInventoryLot a
  124. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  125. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  126. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  127. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  128. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  129. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  130. END";
  131. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode);
  132. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  133. {
  134. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  135. }
  136. ///添加日志
  137. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  138. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  139. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  140. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  141. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  142. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  143. '','',c.WarehouseCode,c.LocationCode,'{6}',
  144. '','0','{4}','{5}','0','',
  145. '','','',f.F_Account ,f.F_RealName ,
  146. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  147. FROM ICSInventoryLot a
  148. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  149. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  150. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  151. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  152. ";
  153. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
  154. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  155. {
  156. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  157. }
  158. #endregion
  159. #region 生产入库,倒冲
  160. if (BusinessCode.Equals(TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>()))
  161. {
  162. #region sql
  163. sql = @"-- 1.创建临时表 初始单据数据 maintemp
  164. SELECT
  165. c.MOCode AS TransCode,
  166. a.MODetailID AS DetailID,
  167. a.InvCode,
  168. b.InvName,
  169. b.InvStd,
  170. a.Quantity,
  171. a.Amount,
  172. a.Sequence AS TransSequence,
  173. a.IssueQuantity,
  174. c.Sequence,
  175. inv.InvUnit,
  176. 0 AS LocationQty,
  177. inv.AmountUnit,
  178. a.ExtensionID,
  179. a.WorkPoint,
  180. ext.ProjectCode,
  181. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  182. ext.Version,
  183. ext.Brand,
  184. ext.cFree1,
  185. ext.cFree2,
  186. ext.cFree3,
  187. ext.cFree4,
  188. ext.cFree5,
  189. ext.cFree6,
  190. ext.cFree7,
  191. ext.cFree8,
  192. ext.cFree9,
  193. ext.cFree10
  194. INTO #maintemp
  195. FROM
  196. ICSMOPick a
  197. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  198. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  199. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  200. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  201. INNER JOIN (
  202. SELECT a.MOCode,a.Sequence,a.WorkPoint
  203. FROM ICSMO a
  204. INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.MOCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
  205. INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
  206. WHERE c.LotNo='{0}' AND c.WorkPoint='{1}'
  207. ) temp ON c.MOCode=temp.MOCode AND a.WorkPoint=temp.WorkPoint AND c.Sequence=temp.Sequence
  208. WHERE a.SupplyType='1'
  209. GROUP BY c.MOCode,a.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,
  210. 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;
  211. select * into #resulttemp from #maintemp
  212. ALTER TABLE #resulttemp ADD LotNo VARCHAR(50)
  213. delete from #resulttemp
  214. -- 2.maintemp barcodetemp
  215. select a.lotno,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime into #barcodetemp from ICSWareHouseLotInfo a LEFT JOIN
  216. (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
  217. -- 3.maintemp ID barcodetemp
  218. BEGIN
  219. DECLARE @transSequence int;--
  220. DECLARE @qty int;--
  221. DECLARE @needqty int;--
  222. DECLARE @lotno VARCHAR(50);--
  223. DECLARE @DetailID VARCHAR(50);--ID
  224. DECLARE tempCursor CURSOR FOR (select transSequence,DetailID from #maintemp); --tempCursor
  225. OPEN tempCursor; --
  226. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID; --
  227. WHILE @@fetch_status=0
  228. BEGIN
  229. select @needqty=Quantity from #maintemp where transSequence = @transSequence AND DetailID = @DetailID
  230. PRINT @transSequence
  231. WHILE @needqty>0
  232. BEGIN
  233. select top 1 @qty = isnull(quantity,0),@lotno = isnull(lotno,'') from #barcodetemp a
  234. RIGHT JOIN (select invcode from #maintemp where transSequence = @transSequence AND DetailID = @DetailID) b on a.invcode=b.invcode ORDER BY mtime
  235. BEGIN
  236. IF(@needqty-@qty>=0 and ISNULL(@lotno, '')<>'')
  237. BEGIN
  238. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  239. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  240. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  241. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  242. ISNULL(Amount, 0), InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@qty,ISNULL(AmountUnit, ''),
  243. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  244. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  245. delete from #barcodetemp where lotno = @lotno
  246. SET @needqty=@needqty-@qty
  247. END
  248. ELSE IF(@needqty-@qty<0 and ISNULL(@lotno, '')<>'')
  249. BEGIN
  250. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  251. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  252. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  253. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  254. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@needqty,ISNULL(AmountUnit, ''),
  255. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  256. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  257. update #barcodetemp set quantity = @qty-@needqty where lotno = @lotno
  258. SET @needqty=@needqty-@qty
  259. END
  260. ELSE
  261. BEGIN
  262. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  263. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  264. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  265. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  266. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,0,ISNULL(AmountUnit, ''),
  267. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  268. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  269. SET @needqty=0
  270. END
  271. END
  272. END
  273. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID;
  274. END
  275. CLOSE tempCursor
  276. DEALLOCATE tempCursor
  277. END
  278. select TransCode,LotNo,LocationQty AS Quantity,InvCode,DetailID,Sequence,TransSequence from #resulttemp
  279. --select * from #resulttemp
  280. DROP table #maintemp
  281. DROP table #resulttemp
  282. DROP table #barcodetemp";
  283. #endregion
  284. sql = String.Format(sql,LotNo,WorkPoint);
  285. DataTable table = DBHelper.SQlReturnData(sql,cmd);
  286. string json = JsonConvert.SerializeObject(table);
  287. List<DownItemModel> downItemModels = JsonConvert.DeserializeObject<List<DownItemModel>>(json);
  288. foreach (DownItemModel model in downItemModels)
  289. {
  290. WareHouseLotInfoDown(Identification,model.TransCode,model.Sequence + "~" + model.TransSequence,model.LotNo,model.Quantity,User,WorkPoint,"12",BusinessCode,cmd,language);
  291. //回写已领数量
  292. sql = @"UPDATE ICSMOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + model.Quantity+") WHERE MODetailID='{0}' AND Sequence='{1}' AND WorkPoint='{2}'";
  293. sql = String.Format(sql,model.DetailID,model.TransSequence,WorkPoint);
  294. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  295. {
  296. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  297. }
  298. }
  299. }
  300. #endregion
  301. #region 委外入库,倒冲
  302. if (BusinessCode.Equals(TransTypeEnum.OutsourcingReceiveDoc.GetDescription<DBValue>()))
  303. {
  304. #region sql
  305. sql = @"-- 1.创建临时表 初始单据数据 maintemp
  306. SELECT
  307. c.OOCode AS TransCode,
  308. a.OODetailID AS DetailID,
  309. a.InvCode,
  310. b.InvName,
  311. b.InvStd,
  312. a.Quantity,
  313. a.Amount,
  314. a.Sequence AS TransSequence,
  315. a.IssueQuantity,
  316. c.Sequence,
  317. inv.InvUnit,
  318. 0 AS LocationQty,
  319. inv.AmountUnit,
  320. a.ExtensionID,
  321. a.WorkPoint,
  322. ext.ProjectCode,
  323. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  324. ext.Version,
  325. ext.Brand,
  326. ext.cFree1,
  327. ext.cFree2,
  328. ext.cFree3,
  329. ext.cFree4,
  330. ext.cFree5,
  331. ext.cFree6,
  332. ext.cFree7,
  333. ext.cFree8,
  334. ext.cFree9,
  335. ext.cFree10
  336. INTO #maintemp
  337. FROM
  338. ICSOOPick a
  339. inner join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  340. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  341. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  342. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  343. INNER JOIN (
  344. SELECT a.OOCode,a.Sequence,a.WorkPoint
  345. FROM ICSOutsourcingOrder a
  346. INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.OOCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
  347. INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
  348. WHERE c.LotNo='{0}' AND c.WorkPoint='{1}'
  349. ) temp ON c.OOCode=temp.OOCode AND a.WorkPoint=temp.WorkPoint AND c.Sequence=temp.Sequence
  350. WHERE a.SupplyType='1'
  351. GROUP BY c.OOCode,a.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,
  352. 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;
  353. select * into #resulttemp from #maintemp
  354. ALTER TABLE #resulttemp ADD LotNo VARCHAR(50)
  355. delete from #resulttemp
  356. -- 2.maintemp barcodetemp
  357. select a.lotno,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime into #barcodetemp from ICSWareHouseLotInfo a LEFT JOIN
  358. (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
  359. -- 3.maintemp ID barcodetemp
  360. BEGIN
  361. DECLARE @transSequence int;--
  362. DECLARE @qty int;--
  363. DECLARE @needqty int;--
  364. DECLARE @lotno VARCHAR(50);--
  365. DECLARE @DetailID VARCHAR(50);--ID
  366. DECLARE tempCursor CURSOR FOR (select transSequence,DetailID from #maintemp); --tempCursor
  367. OPEN tempCursor; --
  368. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID; --
  369. WHILE @@fetch_status=0
  370. BEGIN
  371. select @needqty=Quantity from #maintemp where transSequence = @transSequence AND DetailID = @DetailID
  372. PRINT @transSequence
  373. WHILE @needqty>0
  374. BEGIN
  375. select top 1 @qty = isnull(quantity,0),@lotno = isnull(lotno,'') from #barcodetemp a
  376. RIGHT JOIN (select invcode from #maintemp where transSequence = @transSequence AND DetailID = @DetailID) b on a.invcode=b.invcode ORDER BY mtime
  377. BEGIN
  378. IF(@needqty-@qty>=0 and ISNULL(@lotno, '')<>'')
  379. BEGIN
  380. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  381. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  382. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  383. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  384. ISNULL(Amount, 0), InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@qty,ISNULL(AmountUnit, ''),
  385. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  386. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  387. delete from #barcodetemp where lotno = @lotno
  388. SET @needqty=@needqty-@qty
  389. END
  390. ELSE IF(@needqty-@qty<0 and ISNULL(@lotno, '')<>'')
  391. BEGIN
  392. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  393. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  394. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  395. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  396. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@needqty,ISNULL(AmountUnit, ''),
  397. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  398. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  399. update #barcodetemp set quantity = @qty-@needqty where lotno = @lotno
  400. SET @needqty=@needqty-@qty
  401. END
  402. ELSE
  403. BEGIN
  404. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  405. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  406. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  407. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  408. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,0,ISNULL(AmountUnit, ''),
  409. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  410. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  411. SET @needqty=0
  412. END
  413. END
  414. END
  415. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID;
  416. END
  417. CLOSE tempCursor
  418. DEALLOCATE tempCursor
  419. END
  420. select TransCode,LotNo,LocationQty AS Quantity,InvCode,DetailID,Sequence,TransSequence from #resulttemp
  421. --select * from #resulttemp
  422. DROP table #maintemp
  423. DROP table #resulttemp
  424. DROP table #barcodetemp";
  425. #endregion
  426. sql = String.Format(sql, LotNo, WorkPoint);
  427. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  428. string json = JsonConvert.SerializeObject(table);
  429. List<DownItemModel> downItemModels = JsonConvert.DeserializeObject<List<DownItemModel>>(json);
  430. foreach (DownItemModel model in downItemModels)
  431. {
  432. WareHouseLotInfoDown(Identification, model.TransCode, model.Sequence + "~" + model.TransSequence, model.LotNo, model.Quantity, User, WorkPoint, "12", BusinessCode, cmd, language);
  433. //回写已领数量
  434. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + model.Quantity+") WHERE OODetailID='{0}' AND Sequence='{1}' AND WorkPoint='{2}'";
  435. sql = String.Format(sql, model.DetailID, model.TransSequence, WorkPoint);
  436. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  437. {
  438. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  439. }
  440. }
  441. }
  442. #endregion
  443. #region 管控方式是"料品"时
  444. ControlMode mode = ICSControlModeService.GetControlMode();
  445. if (mode.itemCode.Equals("ControlMode02"))
  446. {
  447. //查询是否存在料品管控的条码
  448. string jsonStrNew = ICSControlModeService.QueryLotNo(jointLotNo, WorkPoint);
  449. List<LotNoMode> modelNew = JsonConvert.DeserializeObject<List<LotNoMode>>(jsonStrNew);
  450. //当不存在料品管控条码时,生成新条码
  451. if (!(modelNew.Count > 0))
  452. {
  453. //获取旧条码的信息
  454. string jsonStr = ICSControlModeService.QueryLotNo(LotNo, WorkPoint);
  455. List<LotNoMode> model = JsonConvert.DeserializeObject<List<LotNoMode>>(jsonStr);
  456. //在条码表中插入一条新数据,在条码表中插入一条新数据,并在库存表中添加新数据
  457. LotNoMode lotNoMode = model[0];
  458. CreateLotNo(jointLotNo, Quantity, "", "", WorkPoint, Identification, User, lotNoMode.InvCode, BusinessCode, lotNoMode.ProjectCode,lotNoMode.BatchCode,
  459. lotNoMode.Version,lotNoMode.Brand,lotNoMode.cFree1, lotNoMode.cFree2, lotNoMode.cFree3, lotNoMode.cFree4, lotNoMode.cFree5, lotNoMode.cFree6, lotNoMode.cFree7,
  460. lotNoMode.cFree8, lotNoMode.cFree9, lotNoMode.cFree10,cmd,language,LocationCode);
  461. ///添加日志
  462. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  463. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  464. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  465. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  466. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  467. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  468. '','',c.WarehouseCode,c.LocationCode,'{6}',
  469. '','0','{4}','{5}','0','',
  470. '','','',f.F_Account ,f.F_RealName ,
  471. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  472. FROM ICSInventoryLot a
  473. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  474. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  475. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  476. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  477. ";
  478. sql = string.Format(sql, jointLotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
  479. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  480. {
  481. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  482. }
  483. }
  484. //当存在料品管控条码时,执行合批
  485. else
  486. {
  487. LotNoMode lotNoMode = modelNew[0];
  488. WareHouseLotInfoMerge(Identification,jointLotNo, LotNo, Quantity,User,WorkPoint,TransType,BusinessCode,cmd,language);
  489. }
  490. }
  491. #endregion
  492. }
  493. catch (Exception)
  494. {
  495. throw;
  496. }
  497. }
  498. /// <summary>
  499. /// 减少库存
  500. /// </summary>
  501. /// <param name="Identification"></param>
  502. /// <param name="TransCode"></param>
  503. /// <param name="TransSequence"></param>
  504. /// <param name="LotNo"></param>
  505. /// <param name="Quantity"></param>
  506. /// <param name="User"></param>
  507. /// <param name="WorkPoint"></param>
  508. /// <param name="TransType"></param>
  509. /// <param name="BusinessCode"></param>
  510. /// <param name="cmd"></param>
  511. public static DataTable WareHouseLotInfoDown(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
  512. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID = "")
  513. {
  514. String LotEnable = "";
  515. String PrintEnable = "";
  516. string lotstr = "";
  517. int result = 0;
  518. List<string> NewBarCodeList = new List<string>();
  519. DataTable dtLotno = new DataTable();
  520. DataTable lstDt = new DataTable();
  521. try
  522. {
  523. ///更新库存
  524. string sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  525. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  526. BEGIN
  527. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  528. RETURN
  529. END";
  530. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  531. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  532. {
  533. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  534. }
  535. //检验是否分批
  536. sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  537. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  538. where a.LotNo='{0}' and a.WorkPoint='{1}'
  539. ";
  540. sql = string.Format(sql, LotNo, WorkPoint);
  541. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  542. if (dt.Rows.Count == 0)
  543. {
  544. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  545. }
  546. else
  547. {
  548. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  549. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  550. }
  551. if (LotEnable.Equals("True"))
  552. {
  553. ///分批前添加日志
  554. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  555. BEGIN
  556. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  557. RETURN
  558. END
  559. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  560. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  561. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  562. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  563. MTIME,WorkPoint,EATTRIBUTE1)
  564. SELECT NEWID(),'{3}','{7}','{8}',a.LotNo ,a.InvCode ,
  565. c.WarehouseCode,c.LocationCode,'','',c.Quantity+{6},
  566. '','0','{4}','31','0','',
  567. '','','',f.F_Account ,f.F_RealName ,
  568. SYSDATETIME() ,a.WorkPoint ,''
  569. FROM ICSInventoryLot a
  570. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  571. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  572. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  573. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  574. ";
  575. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, TransCode, TransSequence);
  576. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  577. {
  578. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  579. }
  580. #region 获取分批后的条码(lotstr)
  581. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  582. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  583. sql = string.Format(sql, LotNo, WorkPoint);
  584. dt = DBHelper.SQlReturnData(sql, cmd);
  585. if (dt.Rows.Count == 0)
  586. {
  587. lotstr = LotNo + "-" + 1;
  588. }
  589. else
  590. {
  591. lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  592. }
  593. NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  594. #endregion
  595. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  596. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  597. Quantity,Amount,ExtensionID,Type,PrintTimes,
  598. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  599. WorkPoint,EATTRIBUTE1)
  600. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  601. '{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes,
  602. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  603. a.WorkPoint ,'{1}'
  604. From ICSInventoryLot a
  605. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  606. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  607. cmd.CommandText = sql;
  608. result = cmd.ExecuteNonQuery();
  609. if (result <= 0)
  610. {
  611. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  612. }
  613. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  614. select NEWID(),'{0}',WarehouseCode,LocationCode,InvCode,'0',InDate,LockQuantity
  615. ,MUSER,MUSERName,GETDATE(),'{3}',''
  616. from ICSWareHouseLotInfo
  617. where LotNO='{1}' AND WorkPoint='{3}'";
  618. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  619. cmd.CommandText = sql;
  620. result = cmd.ExecuteNonQuery();
  621. if (result <= 0)
  622. {
  623. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  624. }
  625. //插入条码单据表
  626. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  627. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  628. FROM ICSInventoryLot a
  629. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  630. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  631. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  632. sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
  633. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  634. {
  635. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  636. }
  637. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  638. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  639. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  640. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  641. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  642. SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
  643. c.WarehouseCode,c.LocationCode,'','','{6}',
  644. '','0','{7}','{8}','0','',
  645. '','','',f.F_Account ,f.F_RealName ,
  646. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  647. FROM ICSInventoryLot a
  648. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  649. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  650. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  651. ";
  652. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr);
  653. cmd.CommandText = sql;
  654. result = cmd.ExecuteNonQuery();
  655. if (result <= 0)
  656. {
  657. throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
  658. }
  659. if (PrintEnable.Equals("True"))
  660. {
  661. 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
  662. from ICSWareHouseLotInfolog A
  663. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  664. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  665. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  666. where A.lotno like'{0}%' and a.workpoint='{1}'
  667. ";
  668. sql = string.Format(sql, LotNo, WorkPoint);
  669. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  670. lstDt=dtLotno;
  671. }
  672. ///添加日志
  673. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  674. BEGIN
  675. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  676. RETURN
  677. END
  678. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  679. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  680. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  681. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  682. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  683. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  684. c.WarehouseCode,c.LocationCode,'','',c.Quantity,
  685. '','0','{7}','32','0','',
  686. '','','',f.F_Account ,f.F_RealName ,
  687. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  688. FROM ICSInventoryLot a
  689. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  690. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  691. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  692. ";
  693. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  694. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  695. {
  696. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  697. }
  698. #endregion
  699. }
  700. else
  701. {
  702. NewBarCodeList.Add(LotNo);
  703. ///添加日志
  704. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  705. BEGIN
  706. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  707. RETURN
  708. END
  709. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  710. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  711. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  712. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  713. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  714. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  715. c.WarehouseCode,c.LocationCode,'','','{6}',
  716. '','0','{7}','{8}','0','',
  717. '','','',f.F_Account ,f.F_RealName ,
  718. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  719. FROM ICSInventoryLot a
  720. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  721. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  722. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  723. ";
  724. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  725. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  726. {
  727. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  728. }
  729. }
  730. }
  731. catch (Exception)
  732. {
  733. throw;
  734. }
  735. return lstDt;
  736. }
  737. /// <summary>
  738. /// 修改库存
  739. /// </summary>
  740. /// <param name="Identification"></param>
  741. /// <param name="TransCode"></param>
  742. /// <param name="TransSequence"></param>
  743. /// <param name="LotNo"></param>
  744. /// <param name="Quantity"></param>
  745. /// <param name="User"></param>
  746. /// <param name="WorkPoint"></param>
  747. /// <param name="TransType"></param>
  748. /// <param name="cmd"></param>
  749. public static void WareHouseLotInfoUpdate(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
  750. string WorkPoint, string TransType,string CheckKind, SqlCommand cmd, Dictionary<string, string> language)
  751. {
  752. try
  753. {
  754. ///添加日志
  755. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  756. BEGIN
  757. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  758. RETURN
  759. END
  760. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  761. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  762. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  763. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  764. MTIME,WorkPoint,EATTRIBUTE1)
  765. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  766. a.WarehouseCode,a.LocationCode,'','',a.Quantity,
  767. '{8}','0','{6}','{7}','0','',
  768. '','','',f.F_Account ,f.F_RealName ,
  769. SYSDATETIME() ,a.WorkPoint ,''
  770. FROM ICSWareHouseLotInfo a
  771. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  772. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  773. ";
  774. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, TransTypeEnum.LOTCheckBefore.GetDescription<DBValue>(), CheckKind);
  775. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  776. {
  777. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  778. }
  779. ///更新库存
  780. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity='{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'";
  781. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  782. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  783. {
  784. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  785. }
  786. ///添加日志
  787. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  788. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  789. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  790. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  791. MTIME,WorkPoint,EATTRIBUTE1)
  792. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  793. a.WarehouseCode,a.LocationCode,'','',a.Quantity,
  794. '{8}','0','{6}','{7}','0','',
  795. '','','',f.F_Account ,f.F_RealName ,
  796. SYSDATETIME() ,a.WorkPoint ,''
  797. FROM ICSWareHouseLotInfo a
  798. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  799. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  800. ";
  801. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, TransTypeEnum.LOTCheckAfter.GetDescription<DBValue>(), CheckKind);
  802. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  803. {
  804. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  805. }
  806. }
  807. catch (Exception)
  808. {
  809. throw;
  810. }
  811. }
  812. /// <summary>
  813. /// 调拨
  814. /// </summary>
  815. /// <param name="LocationCode"></param>
  816. /// <param name="LotNo"></param>
  817. /// <param name="Quantity"></param>
  818. /// <param name="User"></param>
  819. /// <param name="WorkPoint"></param>
  820. /// <param name="TransType"></param>
  821. /// <param name="BusinessCode"></param>
  822. /// <param name="cmd"></param>
  823. public static DataTable WareHouseLotInfoTransfer(string Identification, string TransCode, string TransSequence, string WarehouseCode, string LocationCode,
  824. string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID)
  825. {
  826. String LotEnable = "";
  827. String PrintEnable = "";
  828. string lotstr = "";
  829. int result = 0;
  830. DataTable dtLotno = new DataTable();
  831. DataTable lstDt = new DataTable();
  832. List<string> NewBarCodeList = new List<string>();
  833. try
  834. {
  835. //检验是否分批
  836. string sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  837. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  838. where a.LotNo='{0}' and a.WorkPoint='{1}'
  839. ";
  840. sql = string.Format(sql, LotNo, WorkPoint);
  841. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  842. if (dt.Rows.Count == 0)
  843. {
  844. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  845. }
  846. else
  847. {
  848. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  849. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  850. }
  851. if (!LotEnable.Equals("False"))
  852. {
  853. ///分批前添加日志
  854. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  855. BEGIN
  856. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  857. RETURN
  858. END
  859. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  860. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  861. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  862. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  863. MTIME,WorkPoint,EATTRIBUTE1)
  864. SELECT NEWID(),'{3}','{7}','{8}',a.LotNo ,a.InvCode ,
  865. c.WarehouseCode,c.LocationCode,'','',c.Quantity+{6},
  866. '','0','{4}','31','0','',
  867. '','','',f.F_Account ,f.F_RealName ,
  868. SYSDATETIME() ,a.WorkPoint ,''
  869. FROM ICSInventoryLot a
  870. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  871. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  872. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  873. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  874. ";
  875. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, TransCode, TransSequence);
  876. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  877. {
  878. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  879. }
  880. #region 获取分批后的条码(lotstr)
  881. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  882. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  883. sql = string.Format(sql, LotNo, WorkPoint);
  884. dt = DBHelper.SQlReturnData(sql, cmd);
  885. if (dt.Rows.Count == 0)
  886. {
  887. lotstr = LotNo + "-" + 1;
  888. }
  889. else
  890. {
  891. lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  892. }
  893. NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  894. #endregion
  895. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  896. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  897. Quantity,Amount,ExtensionID,Type,PrintTimes,
  898. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  899. WorkPoint,EATTRIBUTE1)
  900. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  901. '{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes,
  902. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  903. a.WorkPoint ,'{1}'
  904. From ICSInventoryLot a
  905. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  906. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  907. cmd.CommandText = sql;
  908. result = cmd.ExecuteNonQuery();
  909. if (result <= 0)
  910. {
  911. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  912. }
  913. #endregion
  914. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  915. select NEWID(),'{0}',WarehouseCode,LocationCode,InvCode,'0',InDate,LockQuantity
  916. ,MUSER,MUSERName,GETDATE(),'{3}',''
  917. from ICSWareHouseLotInfo
  918. where LotNO='{1}' AND WorkPoint='{3}'";
  919. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  920. cmd.CommandText = sql;
  921. result = cmd.ExecuteNonQuery();
  922. if (result <= 0)
  923. {
  924. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  925. }
  926. //插入条码单据表
  927. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  928. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  929. FROM ICSInventoryLot a
  930. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  931. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  932. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  933. sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
  934. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  935. {
  936. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  937. }
  938. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  939. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  940. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  941. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  942. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  943. SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
  944. c.WarehouseCode,c.LocationCode,'','','{6}',
  945. '','0','{7}','{8}','0','',
  946. '','','',f.F_Account ,f.F_RealName ,
  947. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  948. FROM ICSInventoryLot a
  949. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  950. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  951. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  952. ";
  953. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr);
  954. cmd.CommandText = sql;
  955. result = cmd.ExecuteNonQuery();
  956. if (result <= 0)
  957. {
  958. throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
  959. }
  960. ///添加日志
  961. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  962. BEGIN
  963. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  964. RETURN
  965. END
  966. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  967. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  968. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  969. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  970. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  971. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  972. c.WarehouseCode,c.LocationCode,'','',c.Quantity,
  973. '','0','{7}','32','0','',
  974. '','','',f.F_Account ,f.F_RealName ,
  975. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  976. FROM ICSInventoryLot a
  977. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  978. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  979. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  980. ";
  981. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  982. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  983. {
  984. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  985. }
  986. if (PrintEnable.Equals("True"))
  987. {
  988. 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
  989. from ICSWareHouseLotInfolog A
  990. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  991. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  992. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  993. where a.BusinessCode ='105'
  994. and A.lotno like'{0}%' and a.workpoint='{1}'
  995. ";
  996. sql = string.Format(sql, LotNo, WorkPoint);
  997. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  998. lstDt = dtLotno;
  999. }
  1000. }
  1001. else
  1002. {
  1003. ///添加日志
  1004. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1005. BEGIN
  1006. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1007. RETURN
  1008. END
  1009. IF EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE WarehouseCode='{9}' AND LocationCode='{10}' AND WorkPoint='{1}' AND LotNo = '{0}')
  1010. BEGIN
  1011. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo355")) + @"',16,1);
  1012. RETURN
  1013. END
  1014. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1015. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1016. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1017. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1018. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  1019. SELECT NEWID(),'{3}','','',a.LotNo ,a.InvCode ,
  1020. c.WarehouseCode,c.LocationCode,'{9}','{10}',{6},
  1021. '','0','{7}','{8}','0','',
  1022. '','','',f.F_Account ,f.F_RealName ,
  1023. SYSDATETIME() ,a.WorkPoint ,'','{11}'
  1024. FROM ICSInventoryLot a
  1025. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1026. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1027. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1028. ";
  1029. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode, MergeID);
  1030. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1031. {
  1032. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1033. }
  1034. }
  1035. }
  1036. catch (Exception)
  1037. {
  1038. throw;
  1039. }
  1040. return lstDt;
  1041. }
  1042. /// <summary>
  1043. /// 移库
  1044. /// </summary>
  1045. /// <param name="LocationCode"></param>
  1046. /// <param name="LotNo"></param>
  1047. /// <param name="Quantity"></param>
  1048. /// <param name="User"></param>
  1049. /// <param name="WorkPoint"></param>
  1050. /// <param name="TransType"></param>
  1051. /// <param name="BusinessCode"></param>
  1052. /// <param name="cmd"></param>
  1053. public static void WareHouseLotInfoLibrary(string Identification, string TransCode, string TransSequence, string WarehouseCode, string LocationCode,
  1054. string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1055. {
  1056. try
  1057. {
  1058. string sql = @"SELECT WarehouseCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  1059. sql = string.Format(sql, LotNo,WorkPoint);
  1060. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1061. if (dt == null || dt.Rows.Count <= 0)
  1062. {
  1063. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
  1064. }
  1065. string whcode = dt.Rows[0]["WarehouseCode"].ToString();
  1066. ///添加日志
  1067. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1068. BEGIN
  1069. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1070. RETURN
  1071. END
  1072. IF('" + whcode + @"' != '{8}')
  1073. BEGIN
  1074. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo394"), "{8}", whcode) + @"', 16, 1);
  1075. RETURN
  1076. END
  1077. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1078. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1079. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1080. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1081. MTIME,WorkPoint,EATTRIBUTE1)
  1082. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1083. c.WarehouseCode,c.LocationCode,'{8}','{9}',c.Quantity,
  1084. '','0','{6}','{7}','0','',
  1085. '','','',f.F_Account ,f.F_RealName ,
  1086. SYSDATETIME() ,a.WorkPoint ,''
  1087. FROM ICSInventoryLot a
  1088. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1089. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1090. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1091. ";
  1092. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, BusinessCode, WarehouseCode, LocationCode);
  1093. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1094. {
  1095. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1096. }
  1097. ///添加库存
  1098. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity>0)
  1099. BEGIN
  1100. RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
  1101. RETURN
  1102. END
  1103. IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.WarehouseCode='{2}')
  1104. BEGIN
  1105. RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
  1106. RETURN
  1107. END
  1108. UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1109. ";
  1110. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode);
  1111. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1112. {
  1113. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
  1114. }
  1115. }
  1116. catch (Exception)
  1117. {
  1118. throw;
  1119. }
  1120. }
  1121. /// <summary>
  1122. /// 两步调入
  1123. /// </summary>
  1124. /// <param name="LocationCode"></param>
  1125. /// <param name="LotNo"></param>
  1126. /// <param name="Quantity"></param>
  1127. /// <param name="User"></param>
  1128. /// <param name="WorkPoint"></param>
  1129. /// <param name="TransType"></param>
  1130. /// <param name="BusinessCode"></param>
  1131. /// <param name="cmd"></param>
  1132. public static void WareHouseLotInfoTwoStepTransferDocIn(string Identification, string TransCode, string TransSequence, string WarehouseCode,
  1133. string LocationCode, string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1134. {
  1135. try
  1136. {
  1137. ///添加日志
  1138. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1139. BEGIN
  1140. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1141. RETURN
  1142. END
  1143. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1144. ToWarehouseCode,ToLocationCode,Quantity,
  1145. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1146. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1147. MTIME,WorkPoint,EATTRIBUTE1)
  1148. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1149. '{9}','{10}','{6}',
  1150. '','0','{7}','{8}','0','',
  1151. '','','',f.F_Account ,f.F_RealName ,
  1152. SYSDATETIME() ,a.WorkPoint ,''
  1153. FROM ICSInventoryLot a
  1154. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1155. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1156. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1157. ";
  1158. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode);
  1159. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1160. {
  1161. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1162. }
  1163. ///添加库存
  1164. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1165. BEGIN
  1166. RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
  1167. RETURN
  1168. END
  1169. UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}',Quantity=Quantity+'{4}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1170. ";
  1171. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode, Quantity);
  1172. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1173. {
  1174. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
  1175. }
  1176. }
  1177. catch (Exception)
  1178. {
  1179. throw;
  1180. }
  1181. }
  1182. /// <summary>
  1183. /// 拆分、合并日志
  1184. /// </summary>
  1185. /// <param name="Identification"></param>
  1186. /// <param name="LotNo"></param>
  1187. /// <param name="User"></param>
  1188. /// <param name="WorkPoint"></param>
  1189. /// <param name="TransType"></param>
  1190. /// <param name="BusinessCode"></param>
  1191. /// <param name="cmd"></param>
  1192. public static void WareHouseLotInfoLog(string Identification, string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1193. {
  1194. try
  1195. {
  1196. ///添加日志
  1197. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1198. BEGIN
  1199. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1200. RETURN
  1201. END
  1202. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1203. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1204. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1205. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1206. MTIME,WorkPoint,EATTRIBUTE1)
  1207. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1208. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  1209. '','0','{4}','{5}','0','',
  1210. '','','',f.F_Account ,f.F_RealName ,
  1211. SYSDATETIME() ,a.WorkPoint ,''
  1212. FROM ICSInventoryLot a
  1213. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1214. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1215. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1216. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1217. ";
  1218. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  1219. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1220. {
  1221. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1222. }
  1223. }
  1224. catch (Exception)
  1225. {
  1226. throw;
  1227. }
  1228. }
  1229. /// <summary>
  1230. /// 合并
  1231. /// </summary>
  1232. /// <param name="Identification"></param>
  1233. /// <param name="LotNo"></param>
  1234. /// <param name="User"></param>
  1235. /// <param name="WorkPoint"></param>
  1236. /// <param name="TransType"></param>
  1237. /// <param name="BusinessCode"></param>
  1238. /// <param name="cmd"></param>
  1239. public static void WareHouseLotInfoMerge(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
  1240. string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1241. {
  1242. try
  1243. {
  1244. ///更新目标条码库存
  1245. string sql = @"IF NOT EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1246. INNER JOIN ICSInventoryLot b ON b.LotNo='{3}' AND a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  1247. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1248. BEGIN
  1249. RAISERROR('" + language.GetNameByCode("WMSAPIInfo170") + @"',16,1);
  1250. RETURN
  1251. END
  1252. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1253. BEGIN
  1254. RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
  1255. RETURN
  1256. END
  1257. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1258. ";
  1259. sql = string.Format(sql, LotNo, WorkPoint, Quantity, CurrentLotNo);
  1260. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1261. {
  1262. throw new Exception(language.GetNameByCode("WMSAPIInfo169"));//"目标条码库存更新失败!");
  1263. }
  1264. ///更新原条码库存
  1265. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1266. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  1267. BEGIN
  1268. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1269. RETURN
  1270. END";
  1271. sql = string.Format(sql, CurrentLotNo, WorkPoint, Quantity);
  1272. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1273. {
  1274. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1275. }
  1276. ///添加日志
  1277. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1278. BEGIN
  1279. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1280. RETURN
  1281. END
  1282. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1283. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1284. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1285. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1286. MTIME,WorkPoint,EATTRIBUTE1)
  1287. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1288. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  1289. '','0','{4}','{5}','0','',
  1290. '','','',f.F_Account ,f.F_RealName ,
  1291. SYSDATETIME() ,a.WorkPoint ,''
  1292. FROM ICSInventoryLot a
  1293. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1294. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1295. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1296. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1297. ";
  1298. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  1299. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1300. {
  1301. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1302. }
  1303. }
  1304. catch (Exception)
  1305. {
  1306. throw;
  1307. }
  1308. }
  1309. /// <summary>
  1310. /// 拆分
  1311. /// </summary>
  1312. /// <param name="Identification"></param>
  1313. /// <param name="LotNo"></param>
  1314. /// <param name="User"></param>
  1315. /// <param name="WorkPoint"></param>
  1316. /// <param name="TransType"></param>
  1317. /// <param name="BusinessCode"></param>
  1318. /// <param name="cmd"></param>
  1319. public static void WareHouseLotInfoSplit(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
  1320. string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1321. {
  1322. try
  1323. {
  1324. ///更新库存
  1325. string sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1326. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  1327. BEGIN
  1328. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1329. RETURN
  1330. END";
  1331. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1332. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1333. {
  1334. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1335. }
  1336. #region 添加库存
  1337. //插入条码表
  1338. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1339. BEGIN
  1340. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1341. RETURN
  1342. END
  1343. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a WHERE a.LotNo='{4}' AND a.WorkPoint='{1}')
  1344. BEGIN
  1345. RAISERROR('" + language.GetNameByCode("WMSAPIInfo172") + @"',16,1);
  1346. RETURN
  1347. END
  1348. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1349. SELECT NEWID(),'{4}' ,a.InvCode,a.ProductDate,a.ExpirationDate ,'{3}',a.ExtensionID,'101',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,a.LotNo
  1350. FROM ICSInventoryLot a
  1351. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1352. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1353. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, CurrentLotNo);
  1354. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1355. {
  1356. throw new Exception(language.GetNameByCode("WMSAPIInfo173"));//"条码表写入失败!");
  1357. }
  1358. //插入条码单据表
  1359. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1360. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  1361. FROM ICSInventoryLot a
  1362. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1363. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1364. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1365. sql = string.Format(sql, LotNo, WorkPoint, User, CurrentLotNo);
  1366. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1367. {
  1368. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  1369. }
  1370. ///添加库存
  1371. sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1372. BEGIN
  1373. RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
  1374. RETURN
  1375. END
  1376. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  1377. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  1378. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
  1379. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  1380. BEGIN
  1381. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  1382. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  1383. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint AND il.LocationCode=d.LocationCode
  1384. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  1385. BEGIN
  1386. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  1387. RETURN
  1388. END
  1389. END
  1390. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1391. SELECT NEWID(),a.LotNo ,d.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  1392. FROM ICSInventoryLot a
  1393. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1394. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
  1395. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1396. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1397. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Quantity);
  1398. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1399. {
  1400. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  1401. }
  1402. ///添加日志
  1403. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1404. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1405. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1406. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1407. MTIME,WorkPoint,EATTRIBUTE1)
  1408. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1409. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  1410. '','0','{4}','{5}','0','',
  1411. '','','',f.F_Account ,f.F_RealName ,
  1412. SYSDATETIME() ,a.WorkPoint ,''
  1413. FROM ICSInventoryLot a
  1414. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1415. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1416. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1417. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1418. ";
  1419. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  1420. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1421. {
  1422. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1423. }
  1424. #endregion
  1425. }
  1426. catch (Exception)
  1427. {
  1428. throw;
  1429. }
  1430. }
  1431. /// <summary>
  1432. /// 回写ERP ID
  1433. /// </summary>
  1434. /// <param name="TransType"></param>
  1435. /// <param name="SourceDetailID"></param>
  1436. /// <param name="Identification"></param>
  1437. /// <param name="ID"></param>
  1438. /// <param name="DetailID"></param>
  1439. /// <param name="Code"></param>
  1440. /// <param name="Sequence"></param>
  1441. /// <param name="cmd"></param>
  1442. public static void WareHouseLotInfoLogUpdate(string TransType, string SourceDetailID, string Identification, string ID, string DetailID, string Code, string Sequence, SqlCommand cmd, Dictionary<string, string> language)
  1443. {
  1444. string ERPupdate = string.Empty;
  1445. try
  1446. {
  1447. //采购入库
  1448. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  1449. {
  1450. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1451. FROM ICSWareHouseLotInfoLog a
  1452. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1453. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1454. WHERE c.PODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1455. ";
  1456. }
  1457. //审核的到货单
  1458. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  1459. {
  1460. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1461. FROM ICSWareHouseLotInfoLog a
  1462. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1463. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1464. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1465. ";
  1466. }
  1467. //采购拒收
  1468. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  1469. {
  1470. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1471. FROM ICSWareHouseLotInfoLog a
  1472. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1473. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1474. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1475. ";
  1476. }
  1477. //审核的委外到货单
  1478. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  1479. {
  1480. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1481. FROM ICSWareHouseLotInfoLog a
  1482. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1483. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1484. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1485. ";
  1486. }
  1487. //委外拒收
  1488. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  1489. {
  1490. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1491. FROM ICSWareHouseLotInfoLog a
  1492. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1493. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1494. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1495. ";
  1496. }
  1497. //采购退货
  1498. else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  1499. {
  1500. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1501. FROM ICSWareHouseLotInfoLog a
  1502. INNER JOIN ICSDeliveryNotice c ON a.TransCode=c.DNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1503. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DNType='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1504. ";
  1505. }
  1506. //委外发料
  1507. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  1508. {
  1509. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1510. FROM ICSWareHouseLotInfoLog a
  1511. INNER JOIN ICSOutsourcingOrder y ON a.TransCode=y.OOCode AND a.WorkPoint=y.WorkPoint
  1512. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  1513. WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1514. ";
  1515. }
  1516. //委外退料
  1517. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  1518. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  1519. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1520. {
  1521. ERPupdate = @"--根据退料单退料
  1522. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1523. FROM ICSWareHouseLotInfoLog a
  1524. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1525. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1526. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  1527. Left JOIN ICSOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  1528. WHERE ISNULL(m.ApplyDetailID,ISNULL(m.PickID, c.SourceDetailID))='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1529. --退-
  1530. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1531. FROM ICSWareHouseLotInfoLog a
  1532. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1533. INNER JOIN ICSOutsourcingOrder y ON b.TransCode=y.OOCode AND b.WorkPoint=y.WorkPoint
  1534. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  1535. WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1536. --退-
  1537. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1538. FROM ICSWareHouseLotInfoLog a
  1539. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1540. INNER JOIN ICSOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  1541. WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1542. --退-
  1543. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1544. FROM ICSWareHouseLotInfoLog a
  1545. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1546. INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  1547. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1548. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  1549. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1550. WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1551. ";
  1552. }
  1553. //委外入库
  1554. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  1555. {
  1556. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1557. FROM ICSWareHouseLotInfoLog a
  1558. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1559. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1560. WHERE c.OODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1561. ";
  1562. }
  1563. //委外退货
  1564. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  1565. {
  1566. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1567. FROM ICSWareHouseLotInfoLog a
  1568. INNER JOIN ICSODeliveryNotice c ON a.TransCode=c.ODNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1569. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.ODNType='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1570. ";
  1571. }
  1572. //生产发料
  1573. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  1574. {
  1575. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1576. FROM ICSWareHouseLotInfoLog a
  1577. INNER JOIN ICSMO y ON a.TransCode=y.MOCode AND a.WorkPoint=y.WorkPoint
  1578. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  1579. WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1580. ";
  1581. }
  1582. //生产退料
  1583. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  1584. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  1585. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1586. {
  1587. ERPupdate = @"--根据退料单退料
  1588. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1589. FROM ICSWareHouseLotInfoLog a
  1590. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1591. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1592. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  1593. left JOIN ICSMOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  1594. WHERE ISNULL(m.ApplyDetailID, ISNULL(m.PickID, c.SourceDetailID))='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1595. --退-
  1596. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1597. FROM ICSWareHouseLotInfoLog a
  1598. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1599. INNER JOIN ICSMO y ON b.TransCode=y.MOCode AND b.WorkPoint=y.WorkPoint
  1600. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  1601. WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1602. --退-
  1603. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1604. FROM ICSWareHouseLotInfoLog a
  1605. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1606. INNER JOIN ICSMOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  1607. WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1608. --退-
  1609. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1610. FROM ICSWareHouseLotInfoLog a
  1611. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1612. INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  1613. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1614. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  1615. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1616. WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1617. ";
  1618. }
  1619. //生产入库
  1620. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  1621. {
  1622. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1623. FROM ICSWareHouseLotInfoLog a
  1624. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1625. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1626. WHERE c.MODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1627. ";
  1628. }
  1629. //开立的生产入库单
  1630. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  1631. {
  1632. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1633. FROM ICSWareHouseLotInfoLog a
  1634. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1635. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1636. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1637. ";
  1638. }
  1639. //销售出库
  1640. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  1641. {
  1642. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1643. FROM ICSWareHouseLotInfoLog a
  1644. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1645. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1646. ";
  1647. }
  1648. //销售退货
  1649. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  1650. {
  1651. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1652. FROM ICSWareHouseLotInfoLog a
  1653. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1654. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1655. ";
  1656. }
  1657. //返工工单
  1658. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  1659. {
  1660. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1661. FROM ICSWareHouseLotInfoLog a
  1662. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1663. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1664. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1665. WHERE d.PickID='{3}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1666. ";
  1667. }
  1668. //一步调拨
  1669. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  1670. {
  1671. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1672. FROM ICSWareHouseLotInfoLog a
  1673. INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1674. WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1675. ";
  1676. }
  1677. //调拨
  1678. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  1679. {
  1680. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1681. FROM ICSWareHouseLotInfoLog a
  1682. INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1683. WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1684. ";
  1685. }
  1686. //两步调出
  1687. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  1688. {
  1689. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1690. FROM ICSWareHouseLotInfoLog a
  1691. INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1692. INNER JOIN ICSTransfer d ON c.TransferDetailID=d.TransferDetailID AND c.WorkPoint=d.WorkPoint
  1693. WHERE c.OutID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1694. ";
  1695. }
  1696. //两步调入
  1697. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  1698. {
  1699. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1700. FROM ICSWareHouseLotInfoLog a
  1701. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1702. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  1703. WHERE b.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1704. ";
  1705. }
  1706. //销售退货-原条码
  1707. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  1708. {
  1709. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1710. FROM ICSWareHouseLotInfoLog a
  1711. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1712. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1713. ";
  1714. }
  1715. //其他出库
  1716. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  1717. {
  1718. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1719. FROM ICSWareHouseLotInfoLog a
  1720. INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1721. WHERE c.OutID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1722. ";
  1723. }
  1724. //其他入库
  1725. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  1726. {
  1727. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1728. FROM ICSWareHouseLotInfoLog a
  1729. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1730. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1731. WHERE c.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1732. ";
  1733. }
  1734. //拆卸单
  1735. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  1736. {
  1737. ERPupdate = @"UPDATE d set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1738. FROM ICSWareHouseLotInfoLog a
  1739. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1740. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1741. INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
  1742. WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND d.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1743. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1744. FROM ICSWareHouseLotInfoLog a
  1745. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1746. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1747. WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DABDOCType='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1748. ";
  1749. }
  1750. //领料申请单
  1751. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  1752. {
  1753. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1754. FROM ICSWareHouseLotInfoLog a
  1755. INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1756. WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1757. ";
  1758. }
  1759. //委外领料申请单
  1760. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  1761. {
  1762. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1763. FROM ICSWareHouseLotInfoLog a
  1764. INNER JOIN ICSOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1765. WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1766. ";
  1767. }
  1768. //开立材料出库
  1769. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  1770. {
  1771. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1772. FROM ICSWareHouseLotInfoLog a
  1773. INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1774. WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1775. ";
  1776. }
  1777. //开立委外材料出库
  1778. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  1779. {
  1780. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1781. FROM ICSWareHouseLotInfoLog a
  1782. INNER JOIN ICSOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1783. WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1784. ";
  1785. }
  1786. //开立红字入库单
  1787. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  1788. {
  1789. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1790. FROM ICSWareHouseLotInfoLog a
  1791. INNER JOIN ICSPurchaseReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1792. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1793. ";
  1794. }
  1795. //开立委外红字入库单
  1796. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  1797. {
  1798. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1799. FROM ICSWareHouseLotInfoLog a
  1800. INNER JOIN ICSOutsourcingReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1801. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1802. ";
  1803. }
  1804. //借用
  1805. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  1806. {
  1807. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1808. FROM ICSWareHouseLotInfoLog a
  1809. INNER JOIN ICSBrrow c ON a.TransCode=c.BrrowCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1810. WHERE c.BrrowDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1811. ";
  1812. }
  1813. //归还
  1814. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  1815. {
  1816. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1817. FROM ICSWareHouseLotInfoLog a
  1818. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1819. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1820. WHERE c.ReturnDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1821. ";
  1822. }
  1823. ERPupdate = string.Format(ERPupdate, SourceDetailID, Identification, ID, DetailID, Code, Sequence);
  1824. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  1825. {
  1826. throw new Exception(TransType + language.GetNameByCode("WMSAPIInfo175"));//"回写日志失败!");
  1827. }
  1828. }
  1829. catch (Exception ex)
  1830. {
  1831. log.Debug(ex.ToString());
  1832. log.Debug(TransType + Environment.NewLine + ERPupdate);
  1833. }
  1834. }
  1835. /// <summary>
  1836. /// 倒冲时子件已领数量回写
  1837. /// </summary>
  1838. public static void DetailQTYUpdate()
  1839. {
  1840. }
  1841. /// <summary>
  1842. /// 生成条码
  1843. /// </summary>
  1844. /// <param name="LotNo"></param>
  1845. /// <param name="Quantity"></param>
  1846. /// <param name="TransCode"></param>
  1847. /// <param name="TransSequence"></param>
  1848. /// <param name="WorkPoint"></param>
  1849. /// <param name="Identification"></param>
  1850. /// <param name="User"></param>
  1851. /// <param name="InvCode"></param>
  1852. /// <param name="BusinessCode"></param>
  1853. /// <param name="ProjectCode"></param>
  1854. /// <param name="BatchCode"></param>
  1855. /// <param name="Version"></param>
  1856. /// <param name="Brand"></param>
  1857. /// <param name="cFree1"></param>
  1858. /// <param name="cFree2"></param>
  1859. /// <param name="cFree3"></param>
  1860. /// <param name="cFree4"></param>
  1861. /// <param name="cFree5"></param>
  1862. /// <param name="cFree6"></param>
  1863. /// <param name="cFree7"></param>
  1864. /// <param name="cFree8"></param>
  1865. /// <param name="cFree9"></param>
  1866. /// <param name="cFree10"></param>
  1867. /// <param name="cmd"></param>
  1868. /// <param name="language"></param>
  1869. public static void CreateLotNo(string LotNo, string Quantity, string TransCode, string TransSequence, string WorkPoint, string Identification, string User, string InvCode, string BusinessCode,
  1870. 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)
  1871. {
  1872. try
  1873. {
  1874. String EffectiveEnable = "";
  1875. String Colspan = "";
  1876. String IDD = "";
  1877. int EffectiveDays = 0;
  1878. String Time = "";
  1879. int EffectiveDayss = 0;
  1880. DateTime dtt;
  1881. DateTime now = DateTime.Now;
  1882. string sql = string.Empty;
  1883. //string sql = @"select EffectiveEnable,EffectiveDays from ICSInventory a
  1884. // Left Join ICSMO b ON a.InvCode=b.InvCode and a.WorkPoint = b.WorkPoint
  1885. // where b.MoCode='{0}' and b.WorkPoint='{1}'";
  1886. //sql = string.Format(sql, TransCode, WorkPoint);
  1887. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1888. //if (dt.Rows.Count == 0)
  1889. //{
  1890. // throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  1891. //}
  1892. //else
  1893. //{
  1894. // EffectiveEnable = dt.Rows[0]["EffectiveEnable"].ToString();
  1895. // EffectiveDays = Convert.ToInt32(dt.Rows[0]["EffectiveDays"]);
  1896. //}
  1897. //EffectiveDayss = Convert.ToInt32(EffectiveDays);
  1898. //if (!EffectiveEnable.Equals("False"))
  1899. //{
  1900. int year = now.Year;
  1901. int month = now.Month;
  1902. int day = now.Day;
  1903. int n = DateTime.DaysInMonth(year, month);
  1904. int k = day + EffectiveDays;
  1905. if (k > n)
  1906. {
  1907. day = EffectiveDays - (n - day);
  1908. month = month + 1;
  1909. if (month > 12)
  1910. {
  1911. month = 1;
  1912. year = year + 1;
  1913. }
  1914. }
  1915. else
  1916. {
  1917. day = day + EffectiveDays;
  1918. }
  1919. Time = year + "-" + month + "-" + day;
  1920. //}
  1921. //else
  1922. //{
  1923. // Time = "2999-12-31 00:00:00.000";
  1924. //}
  1925. dtt = Convert.ToDateTime(Time);
  1926. //检验自由项
  1927. Colspan = ProjectCode + "~" + BatchCode + "~" + Version
  1928. + "~" + Brand + "~" + cFree1
  1929. + "~" + cFree2 + "~" + cFree3 + "~" + cFree4
  1930. + "~" + cFree5 + "~" + cFree6 + "~" + cFree7
  1931. + "~" + cFree8 + "~" + cFree9 + "~" + cFree10;
  1932. sql = @"select ID,Colspan from ICSExtension a
  1933. where Colspan='{0}' and WorkPoint='{1}'";
  1934. sql = string.Format(sql, Colspan, WorkPoint);
  1935. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  1936. if (dttt.Rows.Count == 0)
  1937. {
  1938. IDD = Guid.NewGuid().ToString();
  1939. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  1940. 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}'";
  1941. sql = string.Format(sql, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, User, WorkPoint, IDD);
  1942. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1943. {
  1944. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  1945. }
  1946. }
  1947. else
  1948. {
  1949. IDD = dttt.Rows[0]["ID"].ToString();
  1950. }
  1951. //存入条码表
  1952. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  1953. BEGIN
  1954. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1955. RETURN
  1956. END
  1957. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  1958. Quantity,Amount,ExtensionID,Type,PrintTimes,
  1959. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  1960. WorkPoint,EATTRIBUTE1)
  1961. SELECT TOP 1 NEWID(),'{0}','{8}',GETDATE(),'{6}',
  1962. 1,'0','{7}','16',null,
  1963. null,null,'{2}' ,f.F_RealName ,GETDATE(),
  1964. '{4}' ,''
  1965. FROM Sys_SRM_User f
  1966. where f.F_Account='{2}' and f.F_Location='{4}'
  1967. ";
  1968. sql = string.Format(sql, LotNo, Quantity, User, TransCode, WorkPoint, TransSequence, dtt, IDD,InvCode);
  1969. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1970. {
  1971. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  1972. }
  1973. ///存入条码关联表
  1974. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{3}')
  1975. BEGIN
  1976. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1977. RETURN
  1978. END
  1979. INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,
  1980. WorkPoint,EATTRIBUTE1)
  1981. SELECT a.LotNo,'{0}','{1}',f.F_Account ,f.F_RealName,GETDATE(),
  1982. a.WorkPoint,''
  1983. FROM ICSInventoryLot a
  1984. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1985. WHERE a.LotNo='{4}' AND a.WorkPoint='{3}'
  1986. ";
  1987. sql = string.Format(sql, TransCode, TransSequence, User, WorkPoint, LotNo);
  1988. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1989. {
  1990. throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
  1991. }
  1992. //存入库存表
  1993. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1994. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  1995. FROM ICSInventoryLot a
  1996. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1997. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1998. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  1999. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  2000. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2001. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  2002. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode);
  2003. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2004. {
  2005. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  2006. }
  2007. }
  2008. catch (Exception)
  2009. {
  2010. throw;
  2011. }
  2012. }
  2013. }
  2014. }