爱思开
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.

2065 lines
136 KiB

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