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

2219 lines
138 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
  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 = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  936. BEGIN
  937. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  938. RETURN
  939. END
  940. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  941. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  942. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  943. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  944. MTIME,WorkPoint,EATTRIBUTE1)
  945. SELECT NEWID(),'{3}','{7}','{8}',a.LotNo ,a.InvCode ,
  946. c.WarehouseCode,c.LocationCode,'','',c.Quantity+{6},
  947. '','0','{4}','31','0','',
  948. '','','',f.F_Account ,f.F_RealName ,
  949. SYSDATETIME() ,a.WorkPoint ,''
  950. FROM ICSInventoryLot a
  951. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  952. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  953. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  954. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  955. ";
  956. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, TransCode, TransSequence);
  957. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  958. {
  959. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  960. }
  961. #region 获取分批后的条码(lotstr)
  962. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  963. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  964. sql = string.Format(sql, LotNo, WorkPoint);
  965. dt = DBHelper.SQlReturnData(sql, cmd);
  966. if (dt.Rows.Count == 0)
  967. {
  968. lotstr = LotNo + "-" + 1;
  969. }
  970. else
  971. {
  972. lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  973. }
  974. NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  975. #endregion
  976. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  977. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  978. Quantity,Amount,ExtensionID,Type,PrintTimes,
  979. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  980. WorkPoint,EATTRIBUTE1)
  981. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  982. '{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes,
  983. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  984. a.WorkPoint ,'{1}'
  985. From ICSInventoryLot a
  986. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  987. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  988. cmd.CommandText = sql;
  989. result = cmd.ExecuteNonQuery();
  990. if (result <= 0)
  991. {
  992. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  993. }
  994. #endregion
  995. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  996. select NEWID(),'{0}',WarehouseCode,LocationCode,InvCode,'0',InDate,LockQuantity
  997. ,MUSER,MUSERName,GETDATE(),'{3}',''
  998. from ICSWareHouseLotInfo
  999. where LotNO='{1}' AND WorkPoint='{3}'";
  1000. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  1001. cmd.CommandText = sql;
  1002. result = cmd.ExecuteNonQuery();
  1003. if (result <= 0)
  1004. {
  1005. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  1006. }
  1007. //插入条码单据表
  1008. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1009. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  1010. FROM ICSInventoryLot a
  1011. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1012. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1013. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1014. sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
  1015. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1016. {
  1017. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  1018. }
  1019. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1020. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1021. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1022. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1023. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  1024. SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
  1025. c.WarehouseCode,c.LocationCode,'','','{6}',
  1026. '','0','{7}','{8}','0','',
  1027. '','','',f.F_Account ,f.F_RealName ,
  1028. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  1029. FROM ICSInventoryLot a
  1030. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1031. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1032. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1033. ";
  1034. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr);
  1035. cmd.CommandText = sql;
  1036. result = cmd.ExecuteNonQuery();
  1037. if (result <= 0)
  1038. {
  1039. throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
  1040. }
  1041. ///添加日志
  1042. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1043. BEGIN
  1044. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1045. RETURN
  1046. END
  1047. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1048. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1049. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1050. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1051. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  1052. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1053. c.WarehouseCode,c.LocationCode,'','',c.Quantity,
  1054. '','0','{7}','32','0','',
  1055. '','','',f.F_Account ,f.F_RealName ,
  1056. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  1057. FROM ICSInventoryLot a
  1058. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1059. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1060. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1061. ";
  1062. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  1063. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1064. {
  1065. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1066. }
  1067. if (PrintEnable.Equals("True"))
  1068. {
  1069. 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
  1070. from ICSWareHouseLotInfolog A
  1071. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  1072. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  1073. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  1074. where a.BusinessCode ='105'
  1075. and A.lotno like'{0}%' and a.workpoint='{1}'
  1076. ";
  1077. sql = string.Format(sql, LotNo, WorkPoint);
  1078. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  1079. lstDt = dtLotno;
  1080. }
  1081. }
  1082. else
  1083. {
  1084. ///添加日志
  1085. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1086. BEGIN
  1087. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1088. RETURN
  1089. END
  1090. IF EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE WarehouseCode='{9}' AND LocationCode='{10}' AND WorkPoint='{1}' AND LotNo = '{0}')
  1091. BEGIN
  1092. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo355")) + @"',16,1);
  1093. RETURN
  1094. END
  1095. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1096. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1097. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1098. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1099. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  1100. SELECT NEWID(),'{3}','','',a.LotNo ,a.InvCode ,
  1101. c.WarehouseCode,c.LocationCode,'{9}','{10}',{6},
  1102. '','0','{7}','{8}','0','',
  1103. '','','',f.F_Account ,f.F_RealName ,
  1104. SYSDATETIME() ,a.WorkPoint ,'','{11}'
  1105. FROM ICSInventoryLot a
  1106. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1107. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1108. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1109. ";
  1110. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode, MergeID);
  1111. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1112. {
  1113. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1114. }
  1115. }
  1116. }
  1117. catch (Exception)
  1118. {
  1119. throw;
  1120. }
  1121. return lstDt;
  1122. }
  1123. /// <summary>
  1124. /// 移库
  1125. /// </summary>
  1126. /// <param name="LocationCode"></param>
  1127. /// <param name="LotNo"></param>
  1128. /// <param name="Quantity"></param>
  1129. /// <param name="User"></param>
  1130. /// <param name="WorkPoint"></param>
  1131. /// <param name="TransType"></param>
  1132. /// <param name="BusinessCode"></param>
  1133. /// <param name="cmd"></param>
  1134. public static void WareHouseLotInfoLibrary(string Identification, string TransCode, string TransSequence, string WarehouseCode, string LocationCode,
  1135. string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1136. {
  1137. try
  1138. {
  1139. string sql = @"SELECT WarehouseCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  1140. sql = string.Format(sql, LotNo,WorkPoint);
  1141. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1142. if (dt == null || dt.Rows.Count <= 0)
  1143. {
  1144. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
  1145. }
  1146. string whcode = dt.Rows[0]["WarehouseCode"].ToString();
  1147. ///添加日志
  1148. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1149. BEGIN
  1150. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1151. RETURN
  1152. END
  1153. IF('" + whcode + @"' != '{8}')
  1154. BEGIN
  1155. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo394"), "{8}", whcode) + @"', 16, 1);
  1156. RETURN
  1157. END
  1158. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1159. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1160. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1161. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1162. MTIME,WorkPoint,EATTRIBUTE1)
  1163. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1164. c.WarehouseCode,c.LocationCode,'{8}','{9}',c.Quantity,
  1165. '','0','{6}','{7}','0','',
  1166. '','','',f.F_Account ,f.F_RealName ,
  1167. SYSDATETIME() ,a.WorkPoint ,''
  1168. FROM ICSInventoryLot a
  1169. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1170. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1171. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1172. ";
  1173. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, BusinessCode, WarehouseCode, LocationCode);
  1174. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1175. {
  1176. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1177. }
  1178. ///添加库存
  1179. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity>0)
  1180. BEGIN
  1181. RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
  1182. RETURN
  1183. END
  1184. IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.WarehouseCode='{2}')
  1185. BEGIN
  1186. RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
  1187. RETURN
  1188. END
  1189. UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1190. ";
  1191. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode);
  1192. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1193. {
  1194. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
  1195. }
  1196. }
  1197. catch (Exception)
  1198. {
  1199. throw;
  1200. }
  1201. }
  1202. /// <summary>
  1203. /// 两步调入
  1204. /// </summary>
  1205. /// <param name="LocationCode"></param>
  1206. /// <param name="LotNo"></param>
  1207. /// <param name="Quantity"></param>
  1208. /// <param name="User"></param>
  1209. /// <param name="WorkPoint"></param>
  1210. /// <param name="TransType"></param>
  1211. /// <param name="BusinessCode"></param>
  1212. /// <param name="cmd"></param>
  1213. public static void WareHouseLotInfoTwoStepTransferDocIn(string Identification, string TransCode, string TransSequence, string WarehouseCode,
  1214. string LocationCode, string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1215. {
  1216. try
  1217. {
  1218. ///添加日志
  1219. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1220. BEGIN
  1221. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1222. RETURN
  1223. END
  1224. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1225. ToWarehouseCode,ToLocationCode,Quantity,
  1226. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1227. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1228. MTIME,WorkPoint,EATTRIBUTE1)
  1229. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1230. '{9}','{10}','{6}',
  1231. '','0','{7}','{8}','0','',
  1232. '','','',f.F_Account ,f.F_RealName ,
  1233. SYSDATETIME() ,a.WorkPoint ,''
  1234. FROM ICSInventoryLot a
  1235. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1236. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1237. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1238. ";
  1239. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode);
  1240. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1241. {
  1242. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1243. }
  1244. ///添加库存
  1245. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1246. BEGIN
  1247. RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
  1248. RETURN
  1249. END
  1250. UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}',Quantity=Quantity+'{4}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1251. ";
  1252. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode, Quantity);
  1253. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1254. {
  1255. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
  1256. }
  1257. }
  1258. catch (Exception)
  1259. {
  1260. throw;
  1261. }
  1262. }
  1263. /// <summary>
  1264. /// 拆分、合并日志
  1265. /// </summary>
  1266. /// <param name="Identification"></param>
  1267. /// <param name="LotNo"></param>
  1268. /// <param name="User"></param>
  1269. /// <param name="WorkPoint"></param>
  1270. /// <param name="TransType"></param>
  1271. /// <param name="BusinessCode"></param>
  1272. /// <param name="cmd"></param>
  1273. public static void WareHouseLotInfoLog(string Identification, string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1274. {
  1275. try
  1276. {
  1277. ///添加日志
  1278. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1279. BEGIN
  1280. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1281. RETURN
  1282. END
  1283. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1284. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1285. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1286. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1287. MTIME,WorkPoint,EATTRIBUTE1)
  1288. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1289. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  1290. '','0','{4}','{5}','0','',
  1291. '','','',f.F_Account ,f.F_RealName ,
  1292. SYSDATETIME() ,a.WorkPoint ,''
  1293. FROM ICSInventoryLot a
  1294. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1295. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1296. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1297. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1298. ";
  1299. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  1300. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1301. {
  1302. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1303. }
  1304. }
  1305. catch (Exception)
  1306. {
  1307. throw;
  1308. }
  1309. }
  1310. /// <summary>
  1311. /// 合并
  1312. /// </summary>
  1313. /// <param name="Identification"></param>
  1314. /// <param name="LotNo"></param>
  1315. /// <param name="User"></param>
  1316. /// <param name="WorkPoint"></param>
  1317. /// <param name="TransType"></param>
  1318. /// <param name="BusinessCode"></param>
  1319. /// <param name="cmd"></param>
  1320. public static void WareHouseLotInfoMerge(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
  1321. string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1322. {
  1323. try
  1324. {
  1325. ///更新目标条码库存
  1326. string sql = @"IF NOT EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1327. INNER JOIN ICSInventoryLot b ON b.LotNo='{3}' AND a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  1328. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1329. BEGIN
  1330. RAISERROR('" + language.GetNameByCode("WMSAPIInfo170") + @"',16,1);
  1331. RETURN
  1332. END
  1333. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1334. BEGIN
  1335. RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
  1336. RETURN
  1337. END
  1338. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1339. ";
  1340. sql = string.Format(sql, LotNo, WorkPoint, Quantity, CurrentLotNo);
  1341. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1342. {
  1343. throw new Exception(language.GetNameByCode("WMSAPIInfo169"));//"目标条码库存更新失败!");
  1344. }
  1345. ///更新原条码库存
  1346. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1347. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  1348. BEGIN
  1349. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1350. RETURN
  1351. END";
  1352. sql = string.Format(sql, CurrentLotNo, WorkPoint, Quantity);
  1353. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1354. {
  1355. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1356. }
  1357. ///添加日志
  1358. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1359. BEGIN
  1360. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1361. RETURN
  1362. END
  1363. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1364. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1365. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1366. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1367. MTIME,WorkPoint,EATTRIBUTE1)
  1368. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1369. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  1370. '','0','{4}','{5}','0','',
  1371. '','','',f.F_Account ,f.F_RealName ,
  1372. SYSDATETIME() ,a.WorkPoint ,''
  1373. FROM ICSInventoryLot a
  1374. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1375. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1376. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1377. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1378. ";
  1379. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  1380. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1381. {
  1382. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1383. }
  1384. }
  1385. catch (Exception)
  1386. {
  1387. throw;
  1388. }
  1389. }
  1390. /// <summary>
  1391. /// 拆分
  1392. /// </summary>
  1393. /// <param name="Identification"></param>
  1394. /// <param name="LotNo"></param>
  1395. /// <param name="User"></param>
  1396. /// <param name="WorkPoint"></param>
  1397. /// <param name="TransType"></param>
  1398. /// <param name="BusinessCode"></param>
  1399. /// <param name="cmd"></param>
  1400. public static void WareHouseLotInfoSplit(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
  1401. string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1402. {
  1403. try
  1404. {
  1405. ///更新库存
  1406. string sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1407. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  1408. BEGIN
  1409. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1410. RETURN
  1411. END";
  1412. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1413. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1414. {
  1415. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1416. }
  1417. #region 添加库存
  1418. //插入条码表
  1419. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1420. BEGIN
  1421. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1422. RETURN
  1423. END
  1424. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a WHERE a.LotNo='{4}' AND a.WorkPoint='{1}')
  1425. BEGIN
  1426. RAISERROR('" + language.GetNameByCode("WMSAPIInfo172") + @"',16,1);
  1427. RETURN
  1428. END
  1429. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1430. SELECT NEWID(),'{4}' ,a.InvCode,a.ProductDate,a.ExpirationDate ,'{3}',a.ExtensionID,'101',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,a.LotNo
  1431. FROM ICSInventoryLot a
  1432. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1433. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1434. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, CurrentLotNo);
  1435. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1436. {
  1437. throw new Exception(language.GetNameByCode("WMSAPIInfo173"));//"条码表写入失败!");
  1438. }
  1439. //插入条码单据表
  1440. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1441. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  1442. FROM ICSInventoryLot a
  1443. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1444. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1445. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1446. sql = string.Format(sql, LotNo, WorkPoint, User, CurrentLotNo);
  1447. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1448. {
  1449. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  1450. }
  1451. ///添加库存
  1452. sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1453. BEGIN
  1454. RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
  1455. RETURN
  1456. END
  1457. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  1458. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  1459. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
  1460. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  1461. BEGIN
  1462. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  1463. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  1464. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint AND il.LocationCode=d.LocationCode
  1465. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  1466. BEGIN
  1467. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  1468. RETURN
  1469. END
  1470. END
  1471. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1472. SELECT NEWID(),a.LotNo ,d.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  1473. FROM ICSInventoryLot a
  1474. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1475. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
  1476. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1477. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1478. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Quantity);
  1479. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1480. {
  1481. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  1482. }
  1483. ///添加日志
  1484. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1485. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1486. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1487. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1488. MTIME,WorkPoint,EATTRIBUTE1)
  1489. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1490. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  1491. '','0','{4}','{5}','0','',
  1492. '','','',f.F_Account ,f.F_RealName ,
  1493. SYSDATETIME() ,a.WorkPoint ,''
  1494. FROM ICSInventoryLot a
  1495. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1496. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1497. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1498. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1499. ";
  1500. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  1501. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1502. {
  1503. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1504. }
  1505. #endregion
  1506. }
  1507. catch (Exception)
  1508. {
  1509. throw;
  1510. }
  1511. }
  1512. /// <summary>
  1513. /// 回写ERP ID
  1514. /// </summary>
  1515. /// <param name="TransType"></param>
  1516. /// <param name="SourceDetailID"></param>
  1517. /// <param name="Identification"></param>
  1518. /// <param name="ID"></param>
  1519. /// <param name="DetailID"></param>
  1520. /// <param name="Code"></param>
  1521. /// <param name="Sequence"></param>
  1522. /// <param name="cmd"></param>
  1523. 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)
  1524. {
  1525. string ERPupdate = string.Empty;
  1526. try
  1527. {
  1528. //采购入库
  1529. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  1530. {
  1531. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1532. FROM ICSWareHouseLotInfoLog a
  1533. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1534. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1535. WHERE c.PODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1536. ";
  1537. }
  1538. //审核的到货单
  1539. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  1540. {
  1541. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1542. FROM ICSWareHouseLotInfoLog a
  1543. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1544. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1545. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1546. ";
  1547. }
  1548. //采购拒收
  1549. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  1550. {
  1551. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1552. FROM ICSWareHouseLotInfoLog a
  1553. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1554. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1555. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1556. ";
  1557. }
  1558. //审核的委外到货单
  1559. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  1560. {
  1561. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1562. FROM ICSWareHouseLotInfoLog a
  1563. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1564. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1565. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1566. ";
  1567. }
  1568. //委外拒收
  1569. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.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 ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1575. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1576. ";
  1577. }
  1578. //采购退货
  1579. else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  1580. {
  1581. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1582. FROM ICSWareHouseLotInfoLog a
  1583. INNER JOIN ICSDeliveryNotice c ON a.TransCode=c.DNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1584. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DNType='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1585. ";
  1586. }
  1587. //委外发料
  1588. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  1589. {
  1590. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1591. FROM ICSWareHouseLotInfoLog a
  1592. INNER JOIN ICSOutsourcingOrder y ON a.TransCode=y.OOCode AND a.WorkPoint=y.WorkPoint
  1593. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  1594. WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1595. ";
  1596. }
  1597. //委外退料
  1598. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  1599. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  1600. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1601. {
  1602. ERPupdate = @"--根据退料单退料
  1603. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1604. FROM ICSWareHouseLotInfoLog a
  1605. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1606. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1607. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  1608. Left JOIN ICSOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  1609. 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')
  1610. --退-
  1611. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1612. FROM ICSWareHouseLotInfoLog a
  1613. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1614. INNER JOIN ICSOutsourcingOrder y ON b.TransCode=y.OOCode AND b.WorkPoint=y.WorkPoint
  1615. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  1616. WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1617. --退-
  1618. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1619. FROM ICSWareHouseLotInfoLog a
  1620. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1621. INNER JOIN ICSOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  1622. WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1623. --退-
  1624. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1625. FROM ICSWareHouseLotInfoLog a
  1626. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1627. INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  1628. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1629. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  1630. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1631. WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1632. ";
  1633. }
  1634. //委外入库
  1635. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  1636. {
  1637. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1638. FROM ICSWareHouseLotInfoLog a
  1639. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1640. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1641. WHERE c.OODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1642. ";
  1643. }
  1644. //委外退货
  1645. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  1646. {
  1647. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1648. FROM ICSWareHouseLotInfoLog a
  1649. INNER JOIN ICSODeliveryNotice c ON a.TransCode=c.ODNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1650. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.ODNType='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1651. ";
  1652. }
  1653. //生产发料
  1654. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  1655. {
  1656. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1657. FROM ICSWareHouseLotInfoLog a
  1658. INNER JOIN ICSMO y ON a.TransCode=y.MOCode AND a.WorkPoint=y.WorkPoint
  1659. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  1660. WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1661. ";
  1662. }
  1663. //生产退料
  1664. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  1665. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  1666. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1667. {
  1668. ERPupdate = @"--根据退料单退料
  1669. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1670. FROM ICSWareHouseLotInfoLog a
  1671. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1672. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1673. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  1674. left JOIN ICSMOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  1675. 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')
  1676. --退-
  1677. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1678. FROM ICSWareHouseLotInfoLog a
  1679. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1680. INNER JOIN ICSMO y ON b.TransCode=y.MOCode AND b.WorkPoint=y.WorkPoint
  1681. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  1682. WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1683. --退-
  1684. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1685. FROM ICSWareHouseLotInfoLog a
  1686. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1687. INNER JOIN ICSMOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  1688. WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1689. --退-
  1690. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1691. FROM ICSWareHouseLotInfoLog a
  1692. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1693. INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  1694. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1695. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  1696. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1697. WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1698. ";
  1699. }
  1700. //生产入库
  1701. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  1702. {
  1703. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1704. FROM ICSWareHouseLotInfoLog a
  1705. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1706. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1707. WHERE c.MODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1708. ";
  1709. }
  1710. //开立的生产入库单
  1711. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  1712. {
  1713. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1714. FROM ICSWareHouseLotInfoLog a
  1715. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1716. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1717. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1718. ";
  1719. }
  1720. //销售出库
  1721. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  1722. {
  1723. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1724. FROM ICSWareHouseLotInfoLog a
  1725. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1726. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1727. ";
  1728. }
  1729. //销售退货
  1730. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  1731. {
  1732. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1733. FROM ICSWareHouseLotInfoLog a
  1734. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1735. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1736. ";
  1737. }
  1738. //返工工单
  1739. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  1740. {
  1741. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1742. FROM ICSWareHouseLotInfoLog a
  1743. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1744. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1745. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1746. WHERE d.PickID='{3}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1747. ";
  1748. }
  1749. //一步调拨
  1750. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  1751. {
  1752. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1753. FROM ICSWareHouseLotInfoLog a
  1754. INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1755. WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1756. ";
  1757. }
  1758. //调拨
  1759. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  1760. {
  1761. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1762. FROM ICSWareHouseLotInfoLog a
  1763. INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1764. WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1765. ";
  1766. }
  1767. //两步调出
  1768. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  1769. {
  1770. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1771. FROM ICSWareHouseLotInfoLog a
  1772. INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1773. INNER JOIN ICSTransfer d ON c.TransferDetailID=d.TransferDetailID AND c.WorkPoint=d.WorkPoint
  1774. WHERE c.OutID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1775. ";
  1776. }
  1777. //两步调入
  1778. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  1779. {
  1780. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1781. FROM ICSWareHouseLotInfoLog a
  1782. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1783. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  1784. WHERE b.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1785. ";
  1786. }
  1787. //销售退货-原条码
  1788. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  1789. {
  1790. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1791. FROM ICSWareHouseLotInfoLog a
  1792. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1793. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1794. ";
  1795. }
  1796. //其他出库
  1797. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  1798. {
  1799. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1800. FROM ICSWareHouseLotInfoLog a
  1801. INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1802. WHERE c.OutID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1803. ";
  1804. }
  1805. //其他入库
  1806. else if (TransType == TransTypeEnum.OtherInDoc.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 ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1812. WHERE c.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1813. ";
  1814. }
  1815. //拆卸单
  1816. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  1817. {
  1818. ERPupdate = @"UPDATE d set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1819. FROM ICSWareHouseLotInfoLog a
  1820. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1821. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1822. INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
  1823. WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND d.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1824. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1825. FROM ICSWareHouseLotInfoLog a
  1826. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1827. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1828. WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DABDOCType='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1829. ";
  1830. }
  1831. //领料申请单
  1832. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  1833. {
  1834. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1835. FROM ICSWareHouseLotInfoLog a
  1836. INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1837. WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1838. ";
  1839. }
  1840. //委外领料申请单
  1841. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  1842. {
  1843. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1844. FROM ICSWareHouseLotInfoLog a
  1845. INNER JOIN ICSOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1846. WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1847. ";
  1848. }
  1849. //开立材料出库
  1850. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  1851. {
  1852. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1853. FROM ICSWareHouseLotInfoLog a
  1854. INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1855. WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1856. ";
  1857. }
  1858. //开立委外材料出库
  1859. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  1860. {
  1861. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1862. FROM ICSWareHouseLotInfoLog a
  1863. INNER JOIN ICSOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1864. WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1865. ";
  1866. }
  1867. //开立红字入库单
  1868. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  1869. {
  1870. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1871. FROM ICSWareHouseLotInfoLog a
  1872. INNER JOIN ICSPurchaseReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1873. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1874. ";
  1875. }
  1876. //开立委外红字入库单
  1877. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  1878. {
  1879. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1880. FROM ICSWareHouseLotInfoLog a
  1881. INNER JOIN ICSOutsourcingReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1882. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1883. ";
  1884. }
  1885. //借用
  1886. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  1887. {
  1888. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1889. FROM ICSWareHouseLotInfoLog a
  1890. INNER JOIN ICSBrrow c ON a.TransCode=c.BrrowCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1891. WHERE c.BrrowDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1892. ";
  1893. }
  1894. //归还
  1895. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  1896. {
  1897. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1898. FROM ICSWareHouseLotInfoLog a
  1899. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1900. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1901. WHERE c.ReturnDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1902. ";
  1903. }
  1904. ERPupdate = string.Format(ERPupdate, SourceDetailID, Identification, ID, DetailID, Code, Sequence);
  1905. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  1906. {
  1907. throw new Exception(TransType + language.GetNameByCode("WMSAPIInfo175"));//"回写日志失败!");
  1908. }
  1909. }
  1910. catch (Exception ex)
  1911. {
  1912. log.Debug(ex.ToString());
  1913. log.Debug(TransType + Environment.NewLine + ERPupdate);
  1914. }
  1915. }
  1916. /// <summary>
  1917. /// 倒冲时子件已领数量回写
  1918. /// </summary>
  1919. public static void DetailQTYUpdate()
  1920. {
  1921. }
  1922. /// <summary>
  1923. /// 生成条码
  1924. /// </summary>
  1925. /// <param name="LotNo"></param>
  1926. /// <param name="Quantity"></param>
  1927. /// <param name="TransCode"></param>
  1928. /// <param name="TransSequence"></param>
  1929. /// <param name="WorkPoint"></param>
  1930. /// <param name="Identification"></param>
  1931. /// <param name="User"></param>
  1932. /// <param name="InvCode"></param>
  1933. /// <param name="BusinessCode"></param>
  1934. /// <param name="ProjectCode"></param>
  1935. /// <param name="BatchCode"></param>
  1936. /// <param name="Version"></param>
  1937. /// <param name="Brand"></param>
  1938. /// <param name="cFree1"></param>
  1939. /// <param name="cFree2"></param>
  1940. /// <param name="cFree3"></param>
  1941. /// <param name="cFree4"></param>
  1942. /// <param name="cFree5"></param>
  1943. /// <param name="cFree6"></param>
  1944. /// <param name="cFree7"></param>
  1945. /// <param name="cFree8"></param>
  1946. /// <param name="cFree9"></param>
  1947. /// <param name="cFree10"></param>
  1948. /// <param name="cmd"></param>
  1949. /// <param name="language"></param>
  1950. public static void CreateLotNo(string LotNo, string Quantity, string TransCode, string TransSequence, string WorkPoint, string Identification, string User, string InvCode, string BusinessCode,
  1951. 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)
  1952. {
  1953. try
  1954. {
  1955. String EffectiveEnable = "";
  1956. String Colspan = "";
  1957. String IDD = "";
  1958. int EffectiveDays = 0;
  1959. String Time = "";
  1960. int EffectiveDayss = 0;
  1961. DateTime dtt;
  1962. DateTime now = DateTime.Now;
  1963. string sql = string.Empty;
  1964. //string sql = @"select EffectiveEnable,EffectiveDays from ICSInventory a
  1965. // Left Join ICSMO b ON a.InvCode=b.InvCode and a.WorkPoint = b.WorkPoint
  1966. // where b.MoCode='{0}' and b.WorkPoint='{1}'";
  1967. //sql = string.Format(sql, TransCode, WorkPoint);
  1968. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1969. //if (dt.Rows.Count == 0)
  1970. //{
  1971. // throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  1972. //}
  1973. //else
  1974. //{
  1975. // EffectiveEnable = dt.Rows[0]["EffectiveEnable"].ToString();
  1976. // EffectiveDays = Convert.ToInt32(dt.Rows[0]["EffectiveDays"]);
  1977. //}
  1978. //EffectiveDayss = Convert.ToInt32(EffectiveDays);
  1979. //if (!EffectiveEnable.Equals("False"))
  1980. //{
  1981. int year = now.Year;
  1982. int month = now.Month;
  1983. int day = now.Day;
  1984. int n = DateTime.DaysInMonth(year, month);
  1985. int k = day + EffectiveDays;
  1986. if (k > n)
  1987. {
  1988. day = EffectiveDays - (n - day);
  1989. month = month + 1;
  1990. if (month > 12)
  1991. {
  1992. month = 1;
  1993. year = year + 1;
  1994. }
  1995. }
  1996. else
  1997. {
  1998. day = day + EffectiveDays;
  1999. }
  2000. Time = year + "-" + month + "-" + day;
  2001. //}
  2002. //else
  2003. //{
  2004. // Time = "2999-12-31 00:00:00.000";
  2005. //}
  2006. dtt = Convert.ToDateTime(Time);
  2007. //检验自由项
  2008. Colspan = ProjectCode + "~" + BatchCode + "~" + Version
  2009. + "~" + Brand + "~" + cFree1
  2010. + "~" + cFree2 + "~" + cFree3 + "~" + cFree4
  2011. + "~" + cFree5 + "~" + cFree6 + "~" + cFree7
  2012. + "~" + cFree8 + "~" + cFree9 + "~" + cFree10;
  2013. sql = @"select ID,Colspan from ICSExtension a
  2014. where Colspan='{0}' and WorkPoint='{1}'";
  2015. sql = string.Format(sql, Colspan, WorkPoint);
  2016. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  2017. if (dttt.Rows.Count == 0)
  2018. {
  2019. IDD = Guid.NewGuid().ToString();
  2020. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  2021. 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}'";
  2022. sql = string.Format(sql, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, User, WorkPoint, IDD);
  2023. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2024. {
  2025. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  2026. }
  2027. }
  2028. else
  2029. {
  2030. IDD = dttt.Rows[0]["ID"].ToString();
  2031. }
  2032. //存入条码表
  2033. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  2034. BEGIN
  2035. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2036. RETURN
  2037. END
  2038. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  2039. Quantity,Amount,ExtensionID,Type,PrintTimes,
  2040. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  2041. WorkPoint,EATTRIBUTE1)
  2042. SELECT TOP 1 NEWID(),'{0}','{8}',GETDATE(),'{6}',
  2043. 1,'0','{7}','16',null,
  2044. null,null,'{2}' ,f.F_RealName ,GETDATE(),
  2045. '{4}' ,''
  2046. FROM Sys_SRM_User f
  2047. where f.F_Account='{2}' and f.F_Location='{4}'
  2048. ";
  2049. sql = string.Format(sql, LotNo, Quantity, User, TransCode, WorkPoint, TransSequence, dtt, IDD,InvCode);
  2050. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2051. {
  2052. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  2053. }
  2054. ///存入条码关联表
  2055. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{3}')
  2056. BEGIN
  2057. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2058. RETURN
  2059. END
  2060. INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,
  2061. WorkPoint,EATTRIBUTE1)
  2062. SELECT a.LotNo,'{0}','{1}',f.F_Account ,f.F_RealName,GETDATE(),
  2063. a.WorkPoint,''
  2064. FROM ICSInventoryLot a
  2065. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2066. WHERE a.LotNo='{4}' AND a.WorkPoint='{3}'
  2067. ";
  2068. sql = string.Format(sql, TransCode, TransSequence, User, WorkPoint, LotNo);
  2069. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2070. {
  2071. throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
  2072. }
  2073. //存入库存表
  2074. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2075. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  2076. FROM ICSInventoryLot a
  2077. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2078. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2079. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  2080. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  2081. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2082. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  2083. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode);
  2084. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2085. {
  2086. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  2087. }
  2088. }
  2089. catch (Exception)
  2090. {
  2091. throw;
  2092. }
  2093. }
  2094. }
  2095. }