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

2394 lines
162 KiB

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
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
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
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
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
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
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
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
  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 sqlStrNew = @"SELECT a.ID,
  449. con.ContainerCode,
  450. con.ContainerName,
  451. a.LotNo,
  452. a.InvCode,
  453. inv.InvName,
  454. inv.InvStd,
  455. inv.InvUnit,-- {0}
  456. inv.AmountUnit,
  457. ext.ID AS ExtensionID,
  458. ext.ProjectCode,
  459. ext.Version,
  460. ext.BatchCode,
  461. ext.Brand,
  462. ext.cFree1,
  463. ext.cFree2,
  464. ext.cFree3,
  465. ext.cFree4,
  466. ext.cFree5,
  467. ext.cFree6,
  468. ext.cFree7,
  469. ext.cFree8,
  470. ext.cFree9,
  471. ext.cFree10,
  472. a.MUSER AS [ USER ],
  473. a.MTIME AS [ MTime ]
  474. FROM
  475. ICSInventoryLot a
  476. LEFT JOIN ICSContainerLot conlot ON a.LotNo = conlot.LotNo AND a.WorkPoint = conlot.WorkPoint
  477. LEFT JOIN ICSContainer con ON conlot.ContainerID = con.ID AND conlot.WorkPoint = con.WorkPoint
  478. INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint
  479. INNER JOIN ICSExtension ext ON a.ExtensionID = ext.ID AND a.WorkPoint = ext.WorkPoint
  480. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  481. sqlStrNew = string.Format(sqlStrNew, jointLotNo, WorkPoint);
  482. DataTable table = DBHelper.SQlReturnData(sqlStrNew, cmd);
  483. string json = JsonConvert.SerializeObject(table);
  484. List<LotNoMode> modelNew = JsonConvert.DeserializeObject<List<LotNoMode>>(json);
  485. //当不存在料品管控条码时,生成新条码
  486. if (!(modelNew.Count > 0))
  487. {
  488. //获取旧条码的信息
  489. string jsonStr = ICSControlModeService.QueryLotNo(LotNo, WorkPoint);
  490. List<LotNoMode> model = JsonConvert.DeserializeObject<List<LotNoMode>>(jsonStr);
  491. //在条码表中插入一条新数据,在条码表中插入一条新数据,并在库存表中添加新数据
  492. LotNoMode lotNoMode = model[0];
  493. CreateLotNo(jointLotNo, Quantity, "", "", WorkPoint, Identification, User, lotNoMode.InvCode, BusinessCode, lotNoMode.ProjectCode,lotNoMode.BatchCode,
  494. lotNoMode.Version,lotNoMode.Brand,lotNoMode.cFree1, lotNoMode.cFree2, lotNoMode.cFree3, lotNoMode.cFree4, lotNoMode.cFree5, lotNoMode.cFree6, lotNoMode.cFree7,
  495. lotNoMode.cFree8, lotNoMode.cFree9, lotNoMode.cFree10,cmd,language,LocationCode);
  496. ///添加日志
  497. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  498. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  499. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  500. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  501. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  502. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  503. '','',c.WarehouseCode,c.LocationCode,'{6}',
  504. '','0','{4}','{5}','0','',
  505. '','','',f.F_Account ,f.F_RealName ,
  506. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  507. FROM ICSInventoryLot a
  508. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  509. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  510. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  511. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  512. ";
  513. sql = string.Format(sql, jointLotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
  514. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  515. {
  516. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  517. }
  518. }
  519. //当存在料品管控条码时,直接将数量叠加
  520. else
  521. {
  522. try
  523. {
  524. ///更新目标条码库存
  525. sql = @"
  526. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  527. BEGIN
  528. RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
  529. RETURN
  530. END
  531. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  532. ";
  533. sql = string.Format(sql, jointLotNo, WorkPoint, Quantity);
  534. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  535. {
  536. throw new Exception(language.GetNameByCode("WMSAPIInfo169"));//"目标条码库存更新失败!");
  537. }
  538. ///添加日志
  539. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  540. BEGIN
  541. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  542. RETURN
  543. END
  544. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  545. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  546. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  547. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  548. MTIME,WorkPoint,EATTRIBUTE1)
  549. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  550. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  551. '','0','{4}','{5}','0','',
  552. '','','',f.F_Account ,f.F_RealName ,
  553. SYSDATETIME() ,a.WorkPoint ,''
  554. FROM ICSInventoryLot a
  555. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  556. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  557. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  558. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  559. ";
  560. sql = string.Format(sql, jointLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  561. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  562. {
  563. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  564. }
  565. }
  566. catch (Exception)
  567. {
  568. throw;
  569. }
  570. }
  571. }
  572. #endregion
  573. }
  574. catch (Exception)
  575. {
  576. throw;
  577. }
  578. }
  579. /// <summary>
  580. /// 减少库存
  581. /// </summary>
  582. /// <param name="Identification"></param>
  583. /// <param name="TransCode"></param>
  584. /// <param name="TransSequence"></param>
  585. /// <param name="LotNo"></param>
  586. /// <param name="Quantity"></param>
  587. /// <param name="User"></param>
  588. /// <param name="WorkPoint"></param>
  589. /// <param name="TransType"></param>
  590. /// <param name="BusinessCode"></param>
  591. /// <param name="cmd"></param>
  592. public static DataTable WareHouseLotInfoDown(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
  593. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID = "")
  594. {
  595. String LotEnable = "";
  596. String PrintEnable = "";
  597. string lotstr = "";
  598. int result = 0;
  599. List<string> NewBarCodeList = new List<string>();
  600. DataTable dtLotno = new DataTable();
  601. DataTable lstDt = new DataTable();
  602. try
  603. {
  604. ///更新库存
  605. string sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  606. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  607. BEGIN
  608. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  609. RETURN
  610. END";
  611. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  612. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  613. {
  614. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  615. }
  616. //检验是否分批
  617. sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  618. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  619. where a.LotNo='{0}' and a.WorkPoint='{1}'
  620. ";
  621. sql = string.Format(sql, LotNo, WorkPoint);
  622. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  623. if (dt.Rows.Count == 0)
  624. {
  625. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  626. }
  627. else
  628. {
  629. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  630. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  631. }
  632. if (LotEnable.Equals("True"))
  633. {
  634. ///分批前添加日志
  635. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  636. BEGIN
  637. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  638. RETURN
  639. END
  640. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  641. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  642. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  643. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  644. MTIME,WorkPoint,EATTRIBUTE1)
  645. SELECT NEWID(),'{3}','{7}','{8}',a.LotNo ,a.InvCode ,
  646. c.WarehouseCode,c.LocationCode,'','',c.Quantity+{6},
  647. '','0','{4}','31','0','',
  648. '','','',f.F_Account ,f.F_RealName ,
  649. SYSDATETIME() ,a.WorkPoint ,''
  650. FROM ICSInventoryLot a
  651. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  652. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  653. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  654. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  655. ";
  656. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, TransCode, TransSequence);
  657. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  658. {
  659. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  660. }
  661. #region 获取分批后的条码(lotstr)
  662. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  663. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  664. sql = string.Format(sql, LotNo, WorkPoint);
  665. dt = DBHelper.SQlReturnData(sql, cmd);
  666. if (dt.Rows.Count == 0)
  667. {
  668. lotstr = LotNo + "-" + 1;
  669. }
  670. else
  671. {
  672. lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  673. }
  674. NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  675. #endregion
  676. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  677. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  678. Quantity,Amount,ExtensionID,Type,PrintTimes,
  679. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  680. WorkPoint,EATTRIBUTE1)
  681. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  682. '{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes,
  683. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  684. a.WorkPoint ,'{1}'
  685. From ICSInventoryLot a
  686. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  687. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  688. cmd.CommandText = sql;
  689. result = cmd.ExecuteNonQuery();
  690. if (result <= 0)
  691. {
  692. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  693. }
  694. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  695. select NEWID(),'{0}',WarehouseCode,LocationCode,InvCode,'0',InDate,LockQuantity
  696. ,MUSER,MUSERName,GETDATE(),'{3}',''
  697. from ICSWareHouseLotInfo
  698. where LotNO='{1}' AND WorkPoint='{3}'";
  699. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  700. cmd.CommandText = sql;
  701. result = cmd.ExecuteNonQuery();
  702. if (result <= 0)
  703. {
  704. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  705. }
  706. //插入条码单据表
  707. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  708. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  709. FROM ICSInventoryLot a
  710. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  711. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  712. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  713. sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
  714. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  715. {
  716. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  717. }
  718. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  719. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  720. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  721. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  722. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  723. SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
  724. c.WarehouseCode,c.LocationCode,'','','{6}',
  725. '','0','{7}','{8}','0','',
  726. '','','',f.F_Account ,f.F_RealName ,
  727. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  728. FROM ICSInventoryLot a
  729. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  730. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  731. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  732. ";
  733. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr);
  734. cmd.CommandText = sql;
  735. result = cmd.ExecuteNonQuery();
  736. if (result <= 0)
  737. {
  738. throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
  739. }
  740. if (PrintEnable.Equals("True"))
  741. {
  742. 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
  743. from ICSWareHouseLotInfolog A
  744. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  745. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  746. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  747. where A.lotno like'{0}%' and a.workpoint='{1}'
  748. ";
  749. sql = string.Format(sql, LotNo, WorkPoint);
  750. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  751. lstDt=dtLotno;
  752. }
  753. ///添加日志
  754. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  755. BEGIN
  756. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  757. RETURN
  758. END
  759. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  760. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  761. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  762. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  763. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  764. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  765. c.WarehouseCode,c.LocationCode,'','',c.Quantity,
  766. '','0','{7}','32','0','',
  767. '','','',f.F_Account ,f.F_RealName ,
  768. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  769. FROM ICSInventoryLot a
  770. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  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, Quantity, TransType, BusinessCode, MergeID);
  775. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  776. {
  777. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  778. }
  779. #endregion
  780. }
  781. else
  782. {
  783. NewBarCodeList.Add(LotNo);
  784. ///添加日志
  785. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  786. BEGIN
  787. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  788. RETURN
  789. END
  790. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  791. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  792. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  793. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  794. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  795. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  796. c.WarehouseCode,c.LocationCode,'','','{6}',
  797. '','0','{7}','{8}','0','',
  798. '','','',f.F_Account ,f.F_RealName ,
  799. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  800. FROM ICSInventoryLot a
  801. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  802. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  803. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  804. ";
  805. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  806. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  807. {
  808. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  809. }
  810. }
  811. }
  812. catch (Exception)
  813. {
  814. throw;
  815. }
  816. return lstDt;
  817. }
  818. /// <summary>
  819. /// 修改库存
  820. /// </summary>
  821. /// <param name="Identification"></param>
  822. /// <param name="TransCode"></param>
  823. /// <param name="TransSequence"></param>
  824. /// <param name="LotNo"></param>
  825. /// <param name="Quantity"></param>
  826. /// <param name="User"></param>
  827. /// <param name="WorkPoint"></param>
  828. /// <param name="TransType"></param>
  829. /// <param name="cmd"></param>
  830. public static void WareHouseLotInfoUpdate(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
  831. string WorkPoint, string TransType,string CheckKind, SqlCommand cmd, Dictionary<string, string> language)
  832. {
  833. try
  834. {
  835. ///添加日志
  836. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  837. BEGIN
  838. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  839. RETURN
  840. END
  841. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  842. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  843. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  844. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  845. MTIME,WorkPoint,EATTRIBUTE1)
  846. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  847. a.WarehouseCode,a.LocationCode,'','',a.Quantity,
  848. '{8}','0','{6}','{7}','0','',
  849. '','','',f.F_Account ,f.F_RealName ,
  850. SYSDATETIME() ,a.WorkPoint ,''
  851. FROM ICSWareHouseLotInfo a
  852. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  853. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  854. ";
  855. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, TransTypeEnum.LOTCheckBefore.GetDescription<DBValue>(), CheckKind);
  856. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  857. {
  858. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  859. }
  860. ///更新库存
  861. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity='{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'";
  862. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  863. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  864. {
  865. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  866. }
  867. ///添加日志
  868. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  869. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  870. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  871. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  872. MTIME,WorkPoint,EATTRIBUTE1)
  873. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  874. a.WarehouseCode,a.LocationCode,'','',a.Quantity,
  875. '{8}','0','{6}','{7}','0','',
  876. '','','',f.F_Account ,f.F_RealName ,
  877. SYSDATETIME() ,a.WorkPoint ,''
  878. FROM ICSWareHouseLotInfo a
  879. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  880. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  881. ";
  882. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, TransTypeEnum.LOTCheckAfter.GetDescription<DBValue>(), CheckKind);
  883. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  884. {
  885. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  886. }
  887. }
  888. catch (Exception)
  889. {
  890. throw;
  891. }
  892. }
  893. /// <summary>
  894. /// 调拨
  895. /// </summary>
  896. /// <param name="LocationCode"></param>
  897. /// <param name="LotNo"></param>
  898. /// <param name="Quantity"></param>
  899. /// <param name="User"></param>
  900. /// <param name="WorkPoint"></param>
  901. /// <param name="TransType"></param>
  902. /// <param name="BusinessCode"></param>
  903. /// <param name="cmd"></param>
  904. public static DataTable WareHouseLotInfoTransfer(string Identification, string TransCode, string TransSequence, string WarehouseCode, string LocationCode,
  905. string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID)
  906. {
  907. String LotEnable = "";
  908. String PrintEnable = "";
  909. string lotstr = "";
  910. int result = 0;
  911. DataTable dtLotno = new DataTable();
  912. DataTable lstDt = new DataTable();
  913. List<string> NewBarCodeList = new List<string>();
  914. try
  915. {
  916. //检验是否分批
  917. string sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  918. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  919. where a.LotNo='{0}' and a.WorkPoint='{1}'
  920. ";
  921. sql = string.Format(sql, LotNo, WorkPoint);
  922. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  923. if (dt.Rows.Count == 0)
  924. {
  925. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  926. }
  927. else
  928. {
  929. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  930. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  931. }
  932. if (!LotEnable.Equals("False"))
  933. {
  934. ///更新库存
  935. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  936. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  937. BEGIN
  938. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  939. RETURN
  940. END";
  941. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  942. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  943. {
  944. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  945. }
  946. ///分批前添加日志
  947. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  948. BEGIN
  949. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  950. RETURN
  951. END
  952. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  953. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  954. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  955. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  956. MTIME,WorkPoint,EATTRIBUTE1)
  957. SELECT NEWID(),'{3}','{7}','{8}',a.LotNo ,a.InvCode ,
  958. c.WarehouseCode,c.LocationCode,'','',c.Quantity+{6},
  959. '','0','{4}','31','0','',
  960. '','','',f.F_Account ,f.F_RealName ,
  961. SYSDATETIME() ,a.WorkPoint ,''
  962. FROM ICSInventoryLot a
  963. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  964. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  965. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  966. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  967. ";
  968. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, TransCode, TransSequence);
  969. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  970. {
  971. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  972. }
  973. #region 获取分批后的条码(lotstr)
  974. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  975. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  976. sql = string.Format(sql, LotNo, WorkPoint);
  977. dt = DBHelper.SQlReturnData(sql, cmd);
  978. if (dt.Rows.Count == 0)
  979. {
  980. lotstr = LotNo + "-" + 1;
  981. }
  982. else
  983. {
  984. lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  985. }
  986. NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  987. #endregion
  988. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  989. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  990. Quantity,Amount,ExtensionID,Type,PrintTimes,
  991. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  992. WorkPoint,EATTRIBUTE1)
  993. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  994. '{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes,
  995. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  996. a.WorkPoint ,'{1}'
  997. From ICSInventoryLot a
  998. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  999. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  1000. cmd.CommandText = sql;
  1001. result = cmd.ExecuteNonQuery();
  1002. if (result <= 0)
  1003. {
  1004. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  1005. }
  1006. #endregion
  1007. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1008. select NEWID(),'{0}',WarehouseCode,LocationCode,InvCode,'{2}',InDate,LockQuantity
  1009. ,MUSER,MUSERName,GETDATE(),'{3}',''
  1010. from ICSWareHouseLotInfo
  1011. where LotNO='{1}' AND WorkPoint='{3}'";
  1012. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  1013. cmd.CommandText = sql;
  1014. result = cmd.ExecuteNonQuery();
  1015. if (result <= 0)
  1016. {
  1017. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  1018. }
  1019. //插入条码单据表
  1020. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1021. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  1022. FROM ICSInventoryLot a
  1023. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1024. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1025. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1026. sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
  1027. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1028. {
  1029. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  1030. }
  1031. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1032. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1033. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1034. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1035. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  1036. SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
  1037. c.WarehouseCode,c.LocationCode,'{11}','{12}','{6}',
  1038. '','0','{7}','{8}','0','',
  1039. '','','',f.F_Account ,f.F_RealName ,
  1040. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  1041. FROM ICSInventoryLot a
  1042. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1043. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1044. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1045. ";
  1046. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr, WarehouseCode, LocationCode);
  1047. cmd.CommandText = sql;
  1048. result = cmd.ExecuteNonQuery();
  1049. if (result <= 0)
  1050. {
  1051. throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
  1052. }
  1053. ///添加日志
  1054. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1055. BEGIN
  1056. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1057. RETURN
  1058. END
  1059. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1060. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1061. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1062. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1063. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  1064. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1065. c.WarehouseCode,c.LocationCode,'','',c.Quantity,
  1066. '','0','{7}','32','0','',
  1067. '','','',f.F_Account ,f.F_RealName ,
  1068. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  1069. FROM ICSInventoryLot a
  1070. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1071. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1072. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1073. ";
  1074. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  1075. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1076. {
  1077. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1078. }
  1079. if (PrintEnable.Equals("True"))
  1080. {
  1081. 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
  1082. from ICSWareHouseLotInfolog A
  1083. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  1084. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  1085. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  1086. where a.BusinessCode ='105'
  1087. and A.lotno like'{0}%' and a.workpoint='{1}'
  1088. ";
  1089. sql = string.Format(sql, LotNo, WorkPoint);
  1090. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  1091. lstDt = dtLotno;
  1092. }
  1093. }
  1094. else
  1095. {
  1096. ///添加日志
  1097. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1098. BEGIN
  1099. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1100. RETURN
  1101. END
  1102. IF EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE WarehouseCode='{9}' AND LocationCode='{10}' AND WorkPoint='{1}' AND LotNo = '{0}')
  1103. BEGIN
  1104. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo355")) + @"',16,1);
  1105. RETURN
  1106. END
  1107. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1108. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1109. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1110. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1111. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  1112. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1113. c.WarehouseCode,c.LocationCode,'{9}','{10}',{6},
  1114. '','0','{7}','{8}','0','',
  1115. '','','',f.F_Account ,f.F_RealName ,
  1116. SYSDATETIME() ,a.WorkPoint ,'','{11}'
  1117. FROM ICSInventoryLot a
  1118. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1119. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1120. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1121. ";
  1122. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode, MergeID);
  1123. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1124. {
  1125. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1126. }
  1127. ///更新库存
  1128. sql = @"UPDATE ICSWareHouseLotInfo SET WareHouseCode='{2}',LocationCode='{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1129. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  1130. BEGIN
  1131. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1132. RETURN
  1133. END";
  1134. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode);
  1135. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1136. {
  1137. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1138. }
  1139. }
  1140. }
  1141. catch (Exception)
  1142. {
  1143. throw;
  1144. }
  1145. return lstDt;
  1146. }
  1147. /// <summary>
  1148. /// 移库
  1149. /// </summary>
  1150. /// <param name="LocationCode"></param>
  1151. /// <param name="LotNo"></param>
  1152. /// <param name="Quantity"></param>
  1153. /// <param name="User"></param>
  1154. /// <param name="WorkPoint"></param>
  1155. /// <param name="TransType"></param>
  1156. /// <param name="BusinessCode"></param>
  1157. /// <param name="cmd"></param>
  1158. public static void WareHouseLotInfoLibrary(string Identification, string TransCode, string TransSequence, string WarehouseCode, string LocationCode,
  1159. string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1160. {
  1161. try
  1162. {
  1163. string sql = @"SELECT WarehouseCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  1164. sql = string.Format(sql, LotNo,WorkPoint);
  1165. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1166. if (dt == null || dt.Rows.Count <= 0)
  1167. {
  1168. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
  1169. }
  1170. string whcode = dt.Rows[0]["WarehouseCode"].ToString();
  1171. ///添加日志
  1172. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1173. BEGIN
  1174. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1175. RETURN
  1176. END
  1177. IF('" + whcode + @"' != '{8}')
  1178. BEGIN
  1179. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo394"), "{8}", whcode) + @"', 16, 1);
  1180. RETURN
  1181. END
  1182. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1183. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1184. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1185. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1186. MTIME,WorkPoint,EATTRIBUTE1)
  1187. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1188. c.WarehouseCode,c.LocationCode,'{8}','{9}',c.Quantity,
  1189. '','0','{6}','{7}','0','',
  1190. '','','',f.F_Account ,f.F_RealName ,
  1191. SYSDATETIME() ,a.WorkPoint ,''
  1192. FROM ICSInventoryLot a
  1193. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1194. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1195. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1196. ";
  1197. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, BusinessCode, WarehouseCode, LocationCode);
  1198. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1199. {
  1200. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1201. }
  1202. ///添加库存
  1203. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity>0)
  1204. BEGIN
  1205. RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
  1206. RETURN
  1207. END
  1208. IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.WarehouseCode='{2}')
  1209. BEGIN
  1210. RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
  1211. RETURN
  1212. END
  1213. UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1214. ";
  1215. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode);
  1216. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1217. {
  1218. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
  1219. }
  1220. }
  1221. catch (Exception)
  1222. {
  1223. throw;
  1224. }
  1225. }
  1226. /// <summary>
  1227. /// 两步调入
  1228. /// </summary>
  1229. /// <param name="LocationCode"></param>
  1230. /// <param name="LotNo"></param>
  1231. /// <param name="Quantity"></param>
  1232. /// <param name="User"></param>
  1233. /// <param name="WorkPoint"></param>
  1234. /// <param name="TransType"></param>
  1235. /// <param name="BusinessCode"></param>
  1236. /// <param name="cmd"></param>
  1237. public static void WareHouseLotInfoTwoStepTransferDocIn(string Identification, string TransCode, string TransSequence, string WarehouseCode,
  1238. string LocationCode, string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1239. {
  1240. try
  1241. {
  1242. ///添加日志
  1243. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1244. BEGIN
  1245. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1246. RETURN
  1247. END
  1248. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1249. ToWarehouseCode,ToLocationCode,Quantity,
  1250. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1251. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1252. MTIME,WorkPoint,EATTRIBUTE1)
  1253. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1254. '{9}','{10}','{6}',
  1255. '','0','{7}','{8}','0','',
  1256. '','','',f.F_Account ,f.F_RealName ,
  1257. SYSDATETIME() ,a.WorkPoint ,''
  1258. FROM ICSInventoryLot a
  1259. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1260. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1261. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1262. ";
  1263. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode);
  1264. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1265. {
  1266. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1267. }
  1268. ///添加库存
  1269. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1270. BEGIN
  1271. RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
  1272. RETURN
  1273. END
  1274. UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}',Quantity=Quantity+'{4}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1275. ";
  1276. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode, Quantity);
  1277. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1278. {
  1279. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
  1280. }
  1281. }
  1282. catch (Exception)
  1283. {
  1284. throw;
  1285. }
  1286. }
  1287. /// <summary>
  1288. /// 拆分、合并日志
  1289. /// </summary>
  1290. /// <param name="Identification"></param>
  1291. /// <param name="LotNo"></param>
  1292. /// <param name="User"></param>
  1293. /// <param name="WorkPoint"></param>
  1294. /// <param name="TransType"></param>
  1295. /// <param name="BusinessCode"></param>
  1296. /// <param name="cmd"></param>
  1297. public static void WareHouseLotInfoLog(string Identification, string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1298. {
  1299. try
  1300. {
  1301. ///添加日志
  1302. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1303. BEGIN
  1304. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1305. RETURN
  1306. END
  1307. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1308. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1309. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1310. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1311. MTIME,WorkPoint,EATTRIBUTE1)
  1312. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1313. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  1314. '','0','{4}','{5}','0','',
  1315. '','','',f.F_Account ,f.F_RealName ,
  1316. SYSDATETIME() ,a.WorkPoint ,''
  1317. FROM ICSInventoryLot a
  1318. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1319. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1320. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1321. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1322. ";
  1323. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  1324. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1325. {
  1326. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1327. }
  1328. }
  1329. catch (Exception)
  1330. {
  1331. throw;
  1332. }
  1333. }
  1334. /// <summary>
  1335. /// 合并
  1336. /// </summary>
  1337. /// <param name="Identification"></param>
  1338. /// <param name="LotNo"></param>
  1339. /// <param name="User"></param>
  1340. /// <param name="WorkPoint"></param>
  1341. /// <param name="TransType"></param>
  1342. /// <param name="BusinessCode"></param>
  1343. /// <param name="cmd"></param>
  1344. public static void WareHouseLotInfoMerge(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
  1345. string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1346. {
  1347. try
  1348. {
  1349. ///更新目标条码库存
  1350. string sql = @"IF NOT EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1351. INNER JOIN ICSInventoryLot b ON b.LotNo='{3}' AND a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  1352. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1353. BEGIN
  1354. RAISERROR('" + language.GetNameByCode("WMSAPIInfo170") + @"',16,1);
  1355. RETURN
  1356. END
  1357. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1358. BEGIN
  1359. RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
  1360. RETURN
  1361. END
  1362. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1363. ";
  1364. sql = string.Format(sql, LotNo, WorkPoint, Quantity, CurrentLotNo);
  1365. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1366. {
  1367. throw new Exception(language.GetNameByCode("WMSAPIInfo169"));//"目标条码库存更新失败!");
  1368. }
  1369. ///更新原条码库存
  1370. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1371. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  1372. BEGIN
  1373. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1374. RETURN
  1375. END";
  1376. sql = string.Format(sql, CurrentLotNo, WorkPoint, Quantity);
  1377. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1378. {
  1379. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1380. }
  1381. ///添加日志
  1382. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1383. BEGIN
  1384. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1385. RETURN
  1386. END
  1387. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1388. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1389. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1390. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1391. MTIME,WorkPoint,EATTRIBUTE1)
  1392. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1393. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  1394. '','0','{4}','{5}','0','',
  1395. '','','',f.F_Account ,f.F_RealName ,
  1396. SYSDATETIME() ,a.WorkPoint ,''
  1397. FROM ICSInventoryLot a
  1398. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1399. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1400. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1401. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1402. ";
  1403. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  1404. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1405. {
  1406. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1407. }
  1408. }
  1409. catch (Exception)
  1410. {
  1411. throw;
  1412. }
  1413. }
  1414. /// <summary>
  1415. /// 拆分
  1416. /// </summary>
  1417. /// <param name="Identification"></param>
  1418. /// <param name="LotNo"></param>
  1419. /// <param name="User"></param>
  1420. /// <param name="WorkPoint"></param>
  1421. /// <param name="TransType"></param>
  1422. /// <param name="BusinessCode"></param>
  1423. /// <param name="cmd"></param>
  1424. public static void WareHouseLotInfoSplit(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
  1425. string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1426. {
  1427. try
  1428. {
  1429. ///更新库存
  1430. string sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1431. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  1432. BEGIN
  1433. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1434. RETURN
  1435. END";
  1436. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1437. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1438. {
  1439. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1440. }
  1441. #region 添加库存
  1442. //插入条码表
  1443. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1444. BEGIN
  1445. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1446. RETURN
  1447. END
  1448. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a WHERE a.LotNo='{4}' AND a.WorkPoint='{1}')
  1449. BEGIN
  1450. RAISERROR('" + language.GetNameByCode("WMSAPIInfo172") + @"',16,1);
  1451. RETURN
  1452. END
  1453. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1454. SELECT NEWID(),'{4}' ,a.InvCode,a.ProductDate,a.ExpirationDate ,'{3}',a.ExtensionID,'101',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,a.LotNo
  1455. FROM ICSInventoryLot a
  1456. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1457. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1458. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, CurrentLotNo);
  1459. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1460. {
  1461. throw new Exception(language.GetNameByCode("WMSAPIInfo173"));//"条码表写入失败!");
  1462. }
  1463. //插入条码单据表
  1464. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1465. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  1466. FROM ICSInventoryLot a
  1467. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1468. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1469. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1470. sql = string.Format(sql, LotNo, WorkPoint, User, CurrentLotNo);
  1471. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1472. {
  1473. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  1474. }
  1475. ///添加库存
  1476. sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1477. BEGIN
  1478. RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
  1479. RETURN
  1480. END
  1481. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  1482. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  1483. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
  1484. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  1485. BEGIN
  1486. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  1487. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  1488. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint AND il.LocationCode=d.LocationCode
  1489. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  1490. BEGIN
  1491. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  1492. RETURN
  1493. END
  1494. END
  1495. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1496. SELECT NEWID(),a.LotNo ,d.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  1497. FROM ICSInventoryLot a
  1498. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1499. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
  1500. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1501. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1502. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Quantity);
  1503. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1504. {
  1505. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  1506. }
  1507. ///添加日志
  1508. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1509. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1510. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1511. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1512. MTIME,WorkPoint,EATTRIBUTE1)
  1513. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1514. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  1515. '','0','{4}','{5}','0','',
  1516. '','','',f.F_Account ,f.F_RealName ,
  1517. SYSDATETIME() ,a.WorkPoint ,''
  1518. FROM ICSInventoryLot a
  1519. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1520. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1521. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1522. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1523. ";
  1524. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  1525. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1526. {
  1527. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1528. }
  1529. #endregion
  1530. }
  1531. catch (Exception)
  1532. {
  1533. throw;
  1534. }
  1535. }
  1536. /// <summary>
  1537. /// 回写ERP ID
  1538. /// </summary>
  1539. /// <param name="TransType"></param>
  1540. /// <param name="SourceDetailID"></param>
  1541. /// <param name="Identification"></param>
  1542. /// <param name="ID"></param>
  1543. /// <param name="DetailID"></param>
  1544. /// <param name="Code"></param>
  1545. /// <param name="Sequence"></param>
  1546. /// <param name="cmd"></param>
  1547. public static void WareHouseLotInfoLogUpdate(string TransType, string SourceDetailID, string Identification, string ID, string DetailID, string Code, string Sequence, string col, SqlCommand cmd, Dictionary<string, string> language)
  1548. {
  1549. string ERPupdate = string.Empty;
  1550. try
  1551. {
  1552. //采购入库
  1553. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  1554. {
  1555. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1556. FROM ICSWareHouseLotInfoLog a
  1557. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1558. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1559. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1560. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1561. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1562. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1563. WHERE c.PODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1564. and (ISNULL(a.towarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  1565. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  1566. ";
  1567. }
  1568. //审核的到货单
  1569. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  1570. {
  1571. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1572. FROM ICSWareHouseLotInfoLog a
  1573. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1574. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1575. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1576. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1577. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1578. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1579. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1580. and (ISNULL(a.towarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  1581. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  1582. ";
  1583. }
  1584. //采购拒收
  1585. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  1586. {
  1587. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1588. FROM ICSWareHouseLotInfoLog a
  1589. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1590. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1591. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1592. ";
  1593. }
  1594. //审核的委外到货单
  1595. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  1596. {
  1597. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1598. FROM ICSWareHouseLotInfoLog a
  1599. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1600. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1601. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1602. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1603. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1604. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1605. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1606. and (ISNULL(a.fromwarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  1607. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  1608. ";
  1609. }
  1610. //委外拒收
  1611. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  1612. {
  1613. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1614. FROM ICSWareHouseLotInfoLog a
  1615. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1616. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1617. ";
  1618. }
  1619. //采购退货
  1620. else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  1621. {
  1622. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1623. FROM ICSWareHouseLotInfoLog a
  1624. INNER JOIN ICSDeliveryNotice c ON a.TransCode=c.DNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1625. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1626. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1627. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1628. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1629. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DNType='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1630. and (ISNULL(a.fromwarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  1631. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  1632. ";
  1633. }
  1634. //委外发料
  1635. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  1636. {
  1637. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1638. FROM ICSWareHouseLotInfoLog a
  1639. INNER JOIN ICSOutsourcingOrder y ON a.TransCode=y.OOCode AND a.WorkPoint=y.WorkPoint
  1640. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  1641. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1642. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1643. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1644. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1645. WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1646. and (ISNULL(a.fromwarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  1647. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  1648. ";
  1649. }
  1650. //委外退料
  1651. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  1652. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  1653. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1654. {
  1655. ERPupdate = @"--根据退料单退料
  1656. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1657. FROM ICSWareHouseLotInfoLog a
  1658. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1659. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1660. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  1661. Left JOIN ICSOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  1662. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1663. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1664. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1665. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1666. 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')
  1667. and (ISNULL(a.fromwarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  1668. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  1669. --退-
  1670. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1671. FROM ICSWareHouseLotInfoLog a
  1672. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1673. INNER JOIN ICSOutsourcingOrder y ON b.TransCode=y.OOCode AND b.WorkPoint=y.WorkPoint
  1674. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  1675. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1676. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1677. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1678. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1679. WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1680. and (ISNULL(a.fromwarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  1681. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  1682. --退-
  1683. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1684. FROM ICSWareHouseLotInfoLog a
  1685. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1686. INNER JOIN ICSOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  1687. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1688. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1689. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1690. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1691. WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1692. and (ISNULL(a.fromwarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  1693. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  1694. --退-
  1695. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1696. FROM ICSWareHouseLotInfoLog a
  1697. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1698. INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  1699. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1700. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  1701. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1702. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1703. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1704. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1705. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1706. WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1707. and (ISNULL(a.fromwarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  1708. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  1709. ";
  1710. }
  1711. //委外入库
  1712. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  1713. {
  1714. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1715. FROM ICSWareHouseLotInfoLog a
  1716. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1717. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1718. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1719. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1720. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1721. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1722. WHERE c.OODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1723. and (ISNULL(a.fromwarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  1724. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  1725. ";
  1726. }
  1727. //委外退货
  1728. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  1729. {
  1730. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1731. FROM ICSWareHouseLotInfoLog a
  1732. INNER JOIN ICSODeliveryNotice c ON a.TransCode=c.ODNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1733. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1734. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1735. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1736. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1737. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.ODNType='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1738. and (ISNULL(a.fromwarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  1739. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  1740. ";
  1741. }
  1742. //生产发料
  1743. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  1744. {
  1745. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1746. FROM ICSWareHouseLotInfoLog a
  1747. INNER JOIN ICSMO y ON a.TransCode=y.MOCode AND a.WorkPoint=y.WorkPoint
  1748. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  1749. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1750. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1751. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1752. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1753. WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1754. and (ISNULL(a.fromwarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  1755. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  1756. ";
  1757. }
  1758. //生产退料
  1759. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  1760. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  1761. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1762. {
  1763. ERPupdate = @"--根据退料单退料
  1764. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1765. FROM ICSWareHouseLotInfoLog a
  1766. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1767. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1768. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  1769. left JOIN ICSMOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  1770. 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')
  1771. --退-
  1772. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1773. FROM ICSWareHouseLotInfoLog a
  1774. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1775. INNER JOIN ICSMO y ON b.TransCode=y.MOCode AND b.WorkPoint=y.WorkPoint
  1776. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  1777. WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1778. --退-
  1779. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1780. FROM ICSWareHouseLotInfoLog a
  1781. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1782. INNER JOIN ICSMOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  1783. WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1784. --退-
  1785. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1786. FROM ICSWareHouseLotInfoLog a
  1787. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1788. INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  1789. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1790. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  1791. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1792. WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1793. ";
  1794. }
  1795. //生产入库
  1796. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  1797. {
  1798. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1799. FROM ICSWareHouseLotInfoLog a
  1800. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1801. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1802. WHERE c.MODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1803. ";
  1804. }
  1805. //开立的生产入库单
  1806. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  1807. {
  1808. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1809. FROM ICSWareHouseLotInfoLog a
  1810. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1811. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1812. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1813. ";
  1814. }
  1815. //销售出库
  1816. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  1817. {
  1818. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1819. FROM ICSWareHouseLotInfoLog a
  1820. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1821. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1822. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1823. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1824. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1825. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1826. and (ISNULL(a.fromwarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  1827. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  1828. ";
  1829. }
  1830. //销售退货
  1831. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  1832. {
  1833. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1834. FROM ICSWareHouseLotInfoLog a
  1835. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1836. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1837. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1838. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1839. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1840. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1841. and (ISNULL(a.fromwarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  1842. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  1843. ";
  1844. }
  1845. //返工工单
  1846. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  1847. {
  1848. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1849. FROM ICSWareHouseLotInfoLog a
  1850. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1851. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1852. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1853. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1854. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1855. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1856. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1857. WHERE d.PickID='{3}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1858. and (ISNULL(a.fromwarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  1859. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  1860. ";
  1861. }
  1862. //一步调拨
  1863. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  1864. {
  1865. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1866. FROM ICSWareHouseLotInfoLog a
  1867. INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1868. WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1869. ";
  1870. }
  1871. //调拨
  1872. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  1873. {
  1874. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1875. FROM ICSWareHouseLotInfoLog a
  1876. INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1877. WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1878. ";
  1879. }
  1880. //两步调出
  1881. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  1882. {
  1883. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1884. FROM ICSWareHouseLotInfoLog a
  1885. INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1886. INNER JOIN ICSTransfer d ON c.TransferDetailID=d.TransferDetailID AND c.WorkPoint=d.WorkPoint
  1887. WHERE c.OutID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1888. ";
  1889. }
  1890. //两步调入
  1891. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  1892. {
  1893. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1894. FROM ICSWareHouseLotInfoLog a
  1895. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1896. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  1897. WHERE b.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1898. ";
  1899. }
  1900. //销售退货-原条码
  1901. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  1902. {
  1903. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1904. FROM ICSWareHouseLotInfoLog a
  1905. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1906. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1907. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1908. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1909. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1910. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1911. and (ISNULL(a.fromwarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  1912. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  1913. ";
  1914. }
  1915. //其他出库
  1916. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  1917. {
  1918. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1919. FROM ICSWareHouseLotInfoLog a
  1920. INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1921. WHERE c.OutID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1922. ";
  1923. }
  1924. //其他入库
  1925. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  1926. {
  1927. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1928. FROM ICSWareHouseLotInfoLog a
  1929. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1930. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1931. WHERE c.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1932. ";
  1933. }
  1934. //拆卸单
  1935. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  1936. {
  1937. ERPupdate = @"UPDATE d set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1938. FROM ICSWareHouseLotInfoLog a
  1939. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1940. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1941. INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
  1942. WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND d.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1943. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1944. FROM ICSWareHouseLotInfoLog a
  1945. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1946. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1947. WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DABDOCType='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1948. ";
  1949. }
  1950. //领料申请单
  1951. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  1952. {
  1953. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1954. FROM ICSWareHouseLotInfoLog a
  1955. INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1956. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1957. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1958. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1959. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1960. WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1961. and (ISNULL(a.fromwarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  1962. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  1963. ";
  1964. }
  1965. //委外领料申请单
  1966. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  1967. {
  1968. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1969. FROM ICSWareHouseLotInfoLog a
  1970. INNER JOIN ICSOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1971. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1972. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1973. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1974. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1975. WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1976. and (ISNULL(a.fromwarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  1977. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  1978. ";
  1979. }
  1980. //开立材料出库
  1981. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  1982. {
  1983. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1984. FROM ICSWareHouseLotInfoLog a
  1985. INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1986. WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1987. ";
  1988. }
  1989. //开立委外材料出库
  1990. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  1991. {
  1992. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1993. FROM ICSWareHouseLotInfoLog a
  1994. INNER JOIN ICSOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1995. WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1996. ";
  1997. }
  1998. //开立红字入库单
  1999. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  2000. {
  2001. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2002. FROM ICSWareHouseLotInfoLog a
  2003. INNER JOIN ICSPurchaseReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2004. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  2005. ";
  2006. }
  2007. //开立委外红字入库单
  2008. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  2009. {
  2010. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2011. FROM ICSWareHouseLotInfoLog a
  2012. INNER JOIN ICSOutsourcingReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2013. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  2014. ";
  2015. }
  2016. //借用
  2017. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  2018. {
  2019. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2020. FROM ICSWareHouseLotInfoLog a
  2021. INNER JOIN ICSBrrow c ON a.TransCode=c.BrrowCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2022. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2023. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2024. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2025. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2026. WHERE c.BrrowDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  2027. and (ISNULL(a.fromwarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  2028. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  2029. ";
  2030. }
  2031. //归还
  2032. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  2033. {
  2034. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2035. FROM ICSWareHouseLotInfoLog a
  2036. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2037. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2038. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2039. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2040. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2041. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2042. WHERE c.ReturnDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  2043. and (ISNULL(a.tohwarehousecode, '') + (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  2044. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  2045. ";
  2046. }
  2047. ERPupdate = string.Format(ERPupdate, SourceDetailID, Identification, ID, DetailID, Code, Sequence,col);
  2048. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  2049. {
  2050. throw new Exception(TransType + language.GetNameByCode("WMSAPIInfo175"));//"回写日志失败!");
  2051. }
  2052. }
  2053. catch (Exception ex)
  2054. {
  2055. log.Debug(ex.ToString());
  2056. log.Debug(TransType + Environment.NewLine + ERPupdate);
  2057. }
  2058. }
  2059. /// <summary>
  2060. /// 倒冲时子件已领数量回写
  2061. /// </summary>
  2062. public static void DetailQTYUpdate()
  2063. {
  2064. }
  2065. /// <summary>
  2066. /// 生成条码
  2067. /// </summary>
  2068. /// <param name="LotNo"></param>
  2069. /// <param name="Quantity"></param>
  2070. /// <param name="TransCode"></param>
  2071. /// <param name="TransSequence"></param>
  2072. /// <param name="WorkPoint"></param>
  2073. /// <param name="Identification"></param>
  2074. /// <param name="User"></param>
  2075. /// <param name="InvCode"></param>
  2076. /// <param name="BusinessCode"></param>
  2077. /// <param name="ProjectCode"></param>
  2078. /// <param name="BatchCode"></param>
  2079. /// <param name="Version"></param>
  2080. /// <param name="Brand"></param>
  2081. /// <param name="cFree1"></param>
  2082. /// <param name="cFree2"></param>
  2083. /// <param name="cFree3"></param>
  2084. /// <param name="cFree4"></param>
  2085. /// <param name="cFree5"></param>
  2086. /// <param name="cFree6"></param>
  2087. /// <param name="cFree7"></param>
  2088. /// <param name="cFree8"></param>
  2089. /// <param name="cFree9"></param>
  2090. /// <param name="cFree10"></param>
  2091. /// <param name="cmd"></param>
  2092. /// <param name="language"></param>
  2093. public static void CreateLotNo(string LotNo, string Quantity, string TransCode, string TransSequence, string WorkPoint, string Identification, string User, string InvCode, string BusinessCode,
  2094. 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)
  2095. {
  2096. try
  2097. {
  2098. String EffectiveEnable = "";
  2099. String Colspan = "";
  2100. String IDD = "";
  2101. int EffectiveDays = 0;
  2102. String Time = "";
  2103. int EffectiveDayss = 0;
  2104. DateTime dtt;
  2105. DateTime now = DateTime.Now;
  2106. string sql = string.Empty;
  2107. //string sql = @"select EffectiveEnable,EffectiveDays from ICSInventory a
  2108. // Left Join ICSMO b ON a.InvCode=b.InvCode and a.WorkPoint = b.WorkPoint
  2109. // where b.MoCode='{0}' and b.WorkPoint='{1}'";
  2110. //sql = string.Format(sql, TransCode, WorkPoint);
  2111. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2112. //if (dt.Rows.Count == 0)
  2113. //{
  2114. // throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  2115. //}
  2116. //else
  2117. //{
  2118. // EffectiveEnable = dt.Rows[0]["EffectiveEnable"].ToString();
  2119. // EffectiveDays = Convert.ToInt32(dt.Rows[0]["EffectiveDays"]);
  2120. //}
  2121. //EffectiveDayss = Convert.ToInt32(EffectiveDays);
  2122. //if (!EffectiveEnable.Equals("False"))
  2123. //{
  2124. int year = now.Year;
  2125. int month = now.Month;
  2126. int day = now.Day;
  2127. int n = DateTime.DaysInMonth(year, month);
  2128. int k = day + EffectiveDays;
  2129. if (k > n)
  2130. {
  2131. day = EffectiveDays - (n - day);
  2132. month = month + 1;
  2133. if (month > 12)
  2134. {
  2135. month = 1;
  2136. year = year + 1;
  2137. }
  2138. }
  2139. else
  2140. {
  2141. day = day + EffectiveDays;
  2142. }
  2143. Time = year + "-" + month + "-" + day;
  2144. //}
  2145. //else
  2146. //{
  2147. // Time = "2999-12-31 00:00:00.000";
  2148. //}
  2149. dtt = Convert.ToDateTime(Time);
  2150. //检验自由项
  2151. Colspan = ProjectCode + "~" + BatchCode + "~" + Version
  2152. + "~" + Brand + "~" + cFree1
  2153. + "~" + cFree2 + "~" + cFree3 + "~" + cFree4
  2154. + "~" + cFree5 + "~" + cFree6 + "~" + cFree7
  2155. + "~" + cFree8 + "~" + cFree9 + "~" + cFree10;
  2156. sql = @"select ID,Colspan from ICSExtension a
  2157. where Colspan='{0}' and WorkPoint='{1}'";
  2158. sql = string.Format(sql, Colspan, WorkPoint);
  2159. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  2160. if (dttt.Rows.Count == 0)
  2161. {
  2162. IDD = Guid.NewGuid().ToString();
  2163. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  2164. 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}'";
  2165. sql = string.Format(sql, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, User, WorkPoint, IDD);
  2166. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2167. {
  2168. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  2169. }
  2170. }
  2171. else
  2172. {
  2173. IDD = dttt.Rows[0]["ID"].ToString();
  2174. }
  2175. //存入条码表
  2176. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  2177. BEGIN
  2178. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2179. RETURN
  2180. END
  2181. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  2182. Quantity,Amount,ExtensionID,Type,PrintTimes,
  2183. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  2184. WorkPoint,EATTRIBUTE1)
  2185. SELECT TOP 1 NEWID(),'{0}','{8}',GETDATE(),'{6}',
  2186. 1,'0','{7}','16',null,
  2187. null,null,'{2}' ,f.F_RealName ,GETDATE(),
  2188. '{4}' ,''
  2189. FROM Sys_SRM_User f
  2190. where f.F_Account='{2}' and f.F_Location='{4}'
  2191. ";
  2192. sql = string.Format(sql, LotNo, Quantity, User, TransCode, WorkPoint, TransSequence, dtt, IDD,InvCode);
  2193. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2194. {
  2195. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  2196. }
  2197. ///存入条码关联表
  2198. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{3}')
  2199. BEGIN
  2200. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2201. RETURN
  2202. END
  2203. INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,
  2204. WorkPoint,EATTRIBUTE1)
  2205. SELECT a.LotNo,'{0}','{1}',f.F_Account ,f.F_RealName,GETDATE(),
  2206. a.WorkPoint,''
  2207. FROM ICSInventoryLot a
  2208. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2209. WHERE a.LotNo='{4}' AND a.WorkPoint='{3}'
  2210. ";
  2211. sql = string.Format(sql, TransCode, TransSequence, User, WorkPoint, LotNo);
  2212. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2213. {
  2214. throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
  2215. }
  2216. //存入库存表
  2217. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2218. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  2219. FROM ICSInventoryLot a
  2220. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2221. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2222. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  2223. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  2224. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2225. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  2226. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode);
  2227. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2228. {
  2229. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  2230. }
  2231. }
  2232. catch (Exception)
  2233. {
  2234. throw;
  2235. }
  2236. }
  2237. }
  2238. }