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

2110 lines
132 KiB

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