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.

5051 lines
326 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.Linq;
  9. using System.Net.Http;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace ICSSoft.DataProject
  13. {
  14. /// <summary>
  15. /// 使用中
  16. /// 更新库存表、日志表
  17. /// </summary>
  18. public class ICSWareHouseLotInfoService
  19. {
  20. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  21. /// <summary>
  22. /// 分批
  23. /// </summary>
  24. /// <param name="Identification"></param>
  25. /// <param name="TransCode"></param>
  26. /// <param name="TransSequence"></param>
  27. /// <param name="LotNo"></param>
  28. /// <param name="Quantity"></param>
  29. /// <param name="User"></param>
  30. /// <param name="WorkPoint"></param>
  31. /// <param name="TransType"></param>
  32. /// <param name="BusinessCode"></param>
  33. /// <param name="cmd"></param>
  34. public static void WareHouseLotInfoInBatches(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
  35. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID = "")
  36. {
  37. }
  38. /// <summary>
  39. /// 添加库存
  40. /// </summary>
  41. /// <param name="LocationCode"></param>
  42. /// <param name="LotNo"></param>
  43. /// <param name="Quantity"></param>
  44. /// <param name="User"></param>
  45. /// <param name="WorkPoint"></param>
  46. /// <param name="TransType"></param>
  47. /// <param name="BusinessCode"></param>
  48. /// <param name="cmd"></param>
  49. /// <param name="jointLotNo"></param>
  50. public static void WareHouseLotInfoUp(string Identification, string LocationCode, string LotNo, string Quantity, string User,
  51. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string LogID,string jointLotNo, string TransCode, string TransSequence)
  52. {
  53. try
  54. {
  55. #region 正常入库
  56. ///添加库存(原条码退回,更新库存;新条码直接入库)
  57. //stirng locationcode = "";
  58. string sql = string.Empty;
  59. string locationcode = "";
  60. if (BusinessCode != TransTypeEnum.SalesReturnBack.GetDescription<DBValue>())
  61. {
  62. if (string.IsNullOrWhiteSpace(LogID))
  63. {
  64. sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  65. BEGIN
  66. RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
  67. RETURN
  68. END ";
  69. }
  70. else
  71. {
  72. sql = @"SELECT LocationCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  73. sql = string.Format(sql, LotNo, WorkPoint);
  74. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  75. if (dt == null || dt.Rows.Count <= 0)
  76. {
  77. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
  78. }
  79. locationcode = dt.Rows[0]["LocationCode"].ToString();
  80. }
  81. }
  82. if (BusinessCode == TransTypeEnum.MOStockINByProductNoTrans.GetDescription<DBValue>())
  83. {
  84. sql += @" IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  85. BEGIN
  86. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  87. RETURN
  88. END
  89. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  90. BEGIN
  91. IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity=0)
  92. BEGIN
  93. UPDATE a SET a.Quantity=ISNULL(a.Quantity,0)+'{3}',WarehouseCode=e.WarehouseCode,LocationCode=d.LocationCode
  94. From ICSWareHouseLotInfo a
  95. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  96. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  97. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  98. END
  99. ELSE IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.LocationCode='{4}')
  100. BEGIN
  101. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
  102. WHERE LotNo='{0}' AND WorkPoint='{1}'
  103. END
  104. ELSE IF('" + locationcode + @"' != '{4}')
  105. BEGIN
  106. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo395"), "{4}", locationcode) + @"', 16, 1);
  107. RETURN
  108. END
  109. END
  110. ELSE
  111. BEGIN
  112. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  113. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  114. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  115. BEGIN
  116. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  117. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  118. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}' AND il.LocationCode='{4}')
  119. BEGIN
  120. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  121. RETURN
  122. END
  123. END
  124. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  125. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  126. FROM ICSInventoryLot a
  127. LEFT JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  128. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  129. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  130. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  131. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  132. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  133. END";
  134. }
  135. else
  136. {
  137. sql += @" IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  138. BEGIN
  139. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  140. RETURN
  141. END
  142. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  143. BEGIN
  144. IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity=0)
  145. BEGIN
  146. UPDATE a SET a.Quantity=ISNULL(a.Quantity,0)+'{3}',WarehouseCode=e.WarehouseCode,LocationCode=d.LocationCode
  147. From ICSWareHouseLotInfo a
  148. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  149. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  150. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  151. END
  152. ELSE IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.LocationCode='{4}')
  153. BEGIN
  154. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
  155. WHERE LotNo='{0}' AND WorkPoint='{1}'
  156. END
  157. ELSE IF('" + locationcode + @"' != '{4}')
  158. BEGIN
  159. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo395"), "{4}", locationcode) + @"', 16, 1);
  160. RETURN
  161. END
  162. END
  163. ELSE
  164. BEGIN
  165. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  166. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  167. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  168. BEGIN
  169. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  170. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  171. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}' AND il.LocationCode='{4}')
  172. BEGIN
  173. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  174. RETURN
  175. END
  176. END
  177. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  178. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  179. FROM ICSInventoryLot a
  180. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  181. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  182. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  183. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  184. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  185. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  186. END";
  187. }
  188. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode);
  189. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  190. {
  191. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  192. }
  193. if (BusinessCode == TransTypeEnum.MOStockINByProductNoTrans.GetDescription<DBValue>())
  194. {
  195. ///添加日志
  196. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  197. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  198. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  199. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  200. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  201. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  202. '','',c.WarehouseCode,c.LocationCode,'{6}',
  203. '','0','{4}','{5}','0','',
  204. '','','',f.F_Account ,f.F_RealName ,
  205. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  206. FROM ICSInventoryLot a
  207. LEFT JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  208. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  209. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  210. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  211. ";
  212. }
  213. else
  214. {
  215. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  216. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  217. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  218. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  219. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  220. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  221. '','',c.WarehouseCode,c.LocationCode,'{6}',
  222. '','0','{4}','{5}','0','',
  223. '','','',f.F_Account ,f.F_RealName ,
  224. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  225. FROM ICSInventoryLot a
  226. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  227. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  228. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  229. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  230. ";
  231. }
  232. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
  233. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  234. {
  235. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  236. }
  237. #endregion
  238. #region 管控方式是"料品"时
  239. ControlMode mode = ICSControlModeService.GetControlMode();
  240. if (mode.itemCode.Equals("ControlMode02"))
  241. {
  242. //查询是否存在料品管控的条码
  243. string sqlStrNew = @"SELECT a.ID,
  244. con.ContainerCode,
  245. con.ContainerName,
  246. a.LotNo,
  247. a.InvCode,
  248. inv.InvName,
  249. inv.InvStd,
  250. inv.InvUnit,-- {0}
  251. inv.AmountUnit,
  252. ext.ID AS ExtensionID,
  253. ext.ProjectCode,
  254. ext.Version,
  255. ext.BatchCode,
  256. ext.Brand,
  257. ext.cFree1,
  258. ext.cFree2,
  259. ext.cFree3,
  260. ext.cFree4,
  261. ext.cFree5,
  262. ext.cFree6,
  263. ext.cFree7,
  264. ext.cFree8,
  265. ext.cFree9,
  266. ext.cFree10,
  267. a.MUSER AS [ USER ],
  268. a.MTIME AS [ MTime ]
  269. FROM
  270. ICSInventoryLot a
  271. LEFT JOIN ICSContainerLot conlot ON a.LotNo = conlot.LotNo AND a.WorkPoint = conlot.WorkPoint
  272. LEFT JOIN ICSContainer con ON conlot.ContainerID = con.ID AND conlot.WorkPoint = con.WorkPoint
  273. INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint
  274. INNER JOIN ICSExtension ext ON a.ExtensionID = ext.ID AND a.WorkPoint = ext.WorkPoint
  275. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  276. sqlStrNew = string.Format(sqlStrNew, jointLotNo, WorkPoint);
  277. DataTable table = DBHelper.SQlReturnData(sqlStrNew, cmd);
  278. string json = JsonConvert.SerializeObject(table);
  279. List<LotNoMode> modelNew = JsonConvert.DeserializeObject<List<LotNoMode>>(json);
  280. //当不存在料品管控条码时,生成新条码
  281. if (!(modelNew.Count > 0))
  282. {
  283. //获取旧条码的信息
  284. string jsonStr = ICSControlModeService.QueryLotNo(LotNo, WorkPoint);
  285. List<LotNoMode> model = JsonConvert.DeserializeObject<List<LotNoMode>>(jsonStr);
  286. //在条码表中插入一条新数据,在条码表中插入一条新数据,并在库存表中添加新数据
  287. LotNoMode lotNoMode = model[0];
  288. CreateLotNo(jointLotNo, Quantity, "", "", WorkPoint, Identification, User, lotNoMode.InvCode, BusinessCode, lotNoMode.ProjectCode, lotNoMode.BatchCode,
  289. lotNoMode.Version, lotNoMode.Brand, lotNoMode.cFree1, lotNoMode.cFree2, lotNoMode.cFree3, lotNoMode.cFree4, lotNoMode.cFree5, lotNoMode.cFree6, lotNoMode.cFree7,
  290. lotNoMode.cFree8, lotNoMode.cFree9, lotNoMode.cFree10, cmd, language, LocationCode, LotNo);
  291. }
  292. try
  293. {
  294. //合并前日志
  295. WareHouseLotInfoLog(Identification, jointLotNo, User, WorkPoint, "2",
  296. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(),"", cmd, language);
  297. //更新目标条码库存
  298. WareHouseLotInfoMerge(Identification, jointLotNo, LotNo, Quantity, User, WorkPoint, "2",
  299. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  300. //合并后日志
  301. WareHouseLotInfoLog(Identification, jointLotNo, User, WorkPoint, "2",
  302. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), "",cmd, language);
  303. }
  304. catch (Exception)
  305. {
  306. throw;
  307. }
  308. }
  309. #endregion
  310. #region 成品(生产)入库,倒冲
  311. if (BusinessCode.Equals(TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>()))
  312. {
  313. #region sql
  314. sql = @"-- 1.创建临时表 初始单据数据 maintemp
  315. SELECT
  316. c.MOCode AS TransCode,
  317. a.MODetailID AS DetailID,
  318. a.InvCode,
  319. b.InvName,
  320. b.InvStd,
  321. a.ParentQuantity/c.Quantity*{2} AS Quantity,
  322. a.Amount,
  323. a.Sequence AS TransSequence,
  324. a.IssueQuantity,
  325. c.Sequence,
  326. inv.InvUnit,
  327. 0 AS LocationQty,
  328. inv.AmountUnit,
  329. a.ExtensionID,
  330. a.WorkPoint,
  331. ext.ProjectCode,
  332. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  333. ext.Version,
  334. ext.Brand,
  335. ext.cFree1,
  336. ext.cFree2,
  337. ext.cFree3,
  338. ext.cFree4,
  339. ext.cFree5,
  340. ext.cFree6,
  341. ext.cFree7,
  342. ext.cFree8,
  343. ext.cFree9,
  344. ext.cFree10
  345. INTO #maintemp
  346. FROM
  347. ICSMOPick a
  348. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  349. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  350. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  351. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  352. INNER JOIN (
  353. SELECT a.MOCode,a.Sequence,a.WorkPoint
  354. FROM ICSMO a
  355. INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.MOCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
  356. INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
  357. WHERE c.LotNo='{0}' AND c.WorkPoint='{1}'
  358. ) temp ON c.MOCode=temp.MOCode AND a.WorkPoint=temp.WorkPoint AND c.Sequence=temp.Sequence
  359. WHERE a.SupplyType='1'
  360. GROUP BY c.MOCode,a.ParentQuantity,a.Quantity,c.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,
  361. 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;
  362. select * into #resulttemp from #maintemp
  363. ALTER TABLE #resulttemp ADD LotNo VARCHAR(50)
  364. delete from #resulttemp
  365. -- 2.maintemp barcodetemp
  366. select a.lotno,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime into #barcodetemp from ICSWareHouseLotInfo a LEFT JOIN
  367. (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
  368. -- 3.maintemp ID barcodetemp
  369. BEGIN
  370. DECLARE @transSequence int;--
  371. DECLARE @qty int;--
  372. DECLARE @needqty int;--
  373. DECLARE @lotno VARCHAR(50);--
  374. DECLARE @DetailID VARCHAR(50);--ID
  375. DECLARE tempCursor CURSOR FOR (select transSequence,DetailID from #maintemp); --tempCursor
  376. OPEN tempCursor; --
  377. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID; --
  378. WHILE @@fetch_status=0
  379. BEGIN
  380. select @needqty=Quantity from #maintemp where transSequence = @transSequence AND DetailID = @DetailID
  381. PRINT @transSequence
  382. WHILE @needqty>0
  383. BEGIN
  384. select top 1 @qty = isnull(quantity,0),@lotno = isnull(lotno,'') from #barcodetemp a
  385. RIGHT JOIN (select invcode from #maintemp where transSequence = @transSequence AND DetailID = @DetailID) b on a.invcode=b.invcode ORDER BY mtime
  386. BEGIN
  387. IF(@needqty-@qty>=0 and ISNULL(@lotno, '')<>'')
  388. BEGIN
  389. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  390. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  391. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  392. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  393. ISNULL(Amount, 0), InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@qty,ISNULL(AmountUnit, ''),
  394. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  395. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  396. delete from #barcodetemp where lotno = @lotno
  397. SET @needqty=@needqty-@qty
  398. END
  399. ELSE IF(@needqty-@qty<0 and ISNULL(@lotno, '')<>'')
  400. BEGIN
  401. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  402. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  403. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  404. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  405. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@needqty,ISNULL(AmountUnit, ''),
  406. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  407. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  408. update #barcodetemp set quantity = @qty-@needqty where lotno = @lotno
  409. SET @needqty=@needqty-@qty
  410. END
  411. ELSE
  412. BEGIN
  413. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  414. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  415. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  416. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  417. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,0,ISNULL(AmountUnit, ''),
  418. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  419. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  420. SET @needqty=0
  421. END
  422. END
  423. END
  424. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID;
  425. END
  426. CLOSE tempCursor
  427. DEALLOCATE tempCursor
  428. END
  429. select TransCode,LotNo,LocationQty AS Quantity,InvCode,DetailID,Sequence,TransSequence from #resulttemp
  430. --select * from #resulttemp
  431. DROP table #maintemp
  432. DROP table #resulttemp
  433. DROP table #barcodetemp";
  434. #endregion
  435. sql = String.Format(sql,LotNo,WorkPoint, Quantity);
  436. DataTable table = DBHelper.SQlReturnData(sql,cmd);
  437. string json = JsonConvert.SerializeObject(table);
  438. List<DownItemModel> downItemModels = JsonConvert.DeserializeObject<List<DownItemModel>>(json);
  439. foreach (DownItemModel model in downItemModels)
  440. {
  441. if (model != null && model.LotNo == null || "" == model.LotNo)
  442. {
  443. throw new Exception(language.GetNameByCode("WMSAPIInfo201"));
  444. }
  445. WareHouseLotInfoDown(Identification,model.TransCode,model.Sequence + "~" + model.TransSequence,model.LotNo,model.Quantity,User,WorkPoint,"12",BusinessCode,cmd,language,"","");
  446. //回写已领数量
  447. sql = @"UPDATE ICSMOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + model.Quantity+") WHERE MODetailID='{0}' AND Sequence='{1}' AND WorkPoint='{2}'";
  448. sql = String.Format(sql,model.DetailID,model.TransSequence,WorkPoint);
  449. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  450. {
  451. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  452. }
  453. }
  454. }
  455. #endregion
  456. #region 委外入库,倒冲
  457. if (BusinessCode.Equals(TransTypeEnum.OutsourcingReceiveDoc.GetDescription<DBValue>()))
  458. {
  459. #region sql
  460. sql = @"-- 1.创建临时表 初始单据数据 maintemp
  461. SELECT
  462. c.OOCode AS TransCode,
  463. a.OODetailID AS DetailID,
  464. a.InvCode,
  465. b.InvName,
  466. b.InvStd,
  467. a.ParentQuantity/c.Quantity*{2} AS Quantity,
  468. a.Amount,
  469. a.Sequence AS TransSequence,
  470. a.IssueQuantity,
  471. c.Sequence,
  472. inv.InvUnit,
  473. 0 AS LocationQty,
  474. inv.AmountUnit,
  475. a.ExtensionID,
  476. a.WorkPoint,
  477. ext.ProjectCode,
  478. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  479. ext.Version,
  480. ext.Brand,
  481. ext.cFree1,
  482. ext.cFree2,
  483. ext.cFree3,
  484. ext.cFree4,
  485. ext.cFree5,
  486. ext.cFree6,
  487. ext.cFree7,
  488. ext.cFree8,
  489. ext.cFree9,
  490. ext.cFree10
  491. INTO #maintemp
  492. FROM
  493. ICSOOPick a
  494. inner join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  495. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  496. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  497. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  498. INNER JOIN (
  499. SELECT a.OOCode,a.Sequence,a.WorkPoint
  500. FROM ICSOutsourcingOrder a
  501. INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.OOCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
  502. INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
  503. WHERE c.LotNo='{0}' AND c.WorkPoint='{1}'
  504. ) temp ON c.OOCode=temp.OOCode AND a.WorkPoint=temp.WorkPoint AND c.Sequence=temp.Sequence
  505. WHERE a.SupplyType='1'
  506. GROUP BY c.OOCode,a.ParentQuantity,a.Quantity,c.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,
  507. 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;
  508. select * into #resulttemp from #maintemp
  509. ALTER TABLE #resulttemp ADD LotNo VARCHAR(50)
  510. delete from #resulttemp
  511. -- 2.maintemp barcodetemp
  512. select a.lotno,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime into #barcodetemp from ICSWareHouseLotInfo a LEFT JOIN
  513. (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
  514. -- 3.maintemp ID barcodetemp
  515. BEGIN
  516. DECLARE @transSequence int;--
  517. DECLARE @qty int;--
  518. DECLARE @needqty int;--
  519. DECLARE @lotno VARCHAR(50);--
  520. DECLARE @DetailID VARCHAR(50);--ID
  521. DECLARE tempCursor CURSOR FOR (select transSequence,DetailID from #maintemp); --tempCursor
  522. OPEN tempCursor; --
  523. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID; --
  524. WHILE @@fetch_status=0
  525. BEGIN
  526. select @needqty=Quantity from #maintemp where transSequence = @transSequence AND DetailID = @DetailID
  527. PRINT @transSequence
  528. WHILE @needqty>0
  529. BEGIN
  530. select top 1 @qty = isnull(quantity,0),@lotno = isnull(lotno,'') from #barcodetemp a
  531. RIGHT JOIN (select invcode from #maintemp where transSequence = @transSequence AND DetailID = @DetailID) b on a.invcode=b.invcode ORDER BY mtime
  532. BEGIN
  533. IF(@needqty-@qty>=0 and ISNULL(@lotno, '')<>'')
  534. BEGIN
  535. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  536. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  537. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  538. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  539. ISNULL(Amount, 0), InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@qty,ISNULL(AmountUnit, ''),
  540. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  541. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  542. delete from #barcodetemp where lotno = @lotno
  543. SET @needqty=@needqty-@qty
  544. END
  545. ELSE IF(@needqty-@qty<0 and ISNULL(@lotno, '')<>'')
  546. BEGIN
  547. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  548. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  549. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  550. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  551. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@needqty,ISNULL(AmountUnit, ''),
  552. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  553. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  554. update #barcodetemp set quantity = @qty-@needqty where lotno = @lotno
  555. SET @needqty=@needqty-@qty
  556. END
  557. ELSE
  558. BEGIN
  559. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  560. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  561. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  562. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  563. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,0,ISNULL(AmountUnit, ''),
  564. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  565. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  566. SET @needqty=0
  567. END
  568. END
  569. END
  570. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID;
  571. END
  572. CLOSE tempCursor
  573. DEALLOCATE tempCursor
  574. END
  575. select TransCode,LotNo,LocationQty AS Quantity,InvCode,DetailID,Sequence,TransSequence from #resulttemp
  576. --select * from #resulttemp
  577. DROP table #maintemp
  578. DROP table #resulttemp
  579. DROP table #barcodetemp";
  580. #endregion
  581. sql = String.Format(sql, LotNo, WorkPoint, Quantity);
  582. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  583. string json = JsonConvert.SerializeObject(table);
  584. List<DownItemModel> downItemModels = JsonConvert.DeserializeObject<List<DownItemModel>>(json);
  585. foreach (DownItemModel model in downItemModels)
  586. {
  587. if (model != null && model.LotNo == null || "" == model.LotNo)
  588. {
  589. throw new Exception(language.GetNameByCode("WMSAPIInfo201"));
  590. }
  591. WareHouseLotInfoDown(Identification, model.TransCode, model.Sequence + "~" + model.TransSequence, model.LotNo, model.Quantity, User, WorkPoint, "13", BusinessCode, cmd, language,"","");
  592. //回写已领数量
  593. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + model.Quantity+") WHERE OODetailID='{0}' AND Sequence='{1}' AND WorkPoint='{2}'";
  594. sql = String.Format(sql, model.DetailID, model.TransSequence, WorkPoint);
  595. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  596. {
  597. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  598. }
  599. }
  600. }
  601. #endregion
  602. }
  603. catch (Exception)
  604. {
  605. throw;
  606. }
  607. }
  608. /// <summary>
  609. /// 添加库存(奥美专用)
  610. /// </summary>
  611. /// <param name="LocationCode"></param>
  612. /// <param name="LotNo"></param>
  613. /// <param name="Quantity"></param>
  614. /// <param name="User"></param>
  615. /// <param name="WorkPoint"></param>
  616. /// <param name="TransType"></param>
  617. /// <param name="BusinessCode"></param>
  618. /// <param name="cmd"></param>
  619. /// <param name="jointLotNo"></param>
  620. public static void WareHouseLotInfoUpAM(string Identification, string LocationCode, string LotNo, string Quantity, string User,
  621. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string LogID, string jointLotNo,string TransCode,string TransSequence,string LotFlag,string WarehouseCode)
  622. {
  623. try
  624. {
  625. #region 正常入库
  626. ///添加库存(原条码退回,更新库存;新条码直接入库)
  627. //stirng locationcode = "";
  628. string sql = string.Empty;
  629. string outsql = string.Empty;
  630. string locationcode = "";
  631. string newlocationcode = "";
  632. string amount = "";
  633. decimal LotQTYYY = 0;
  634. decimal LotQTY = 0;
  635. string LotEnable = "";
  636. string chekEnable = "";
  637. string DisPrintEnable = "";
  638. string PrintEnable = "";
  639. string lotstr = "";
  640. int result = 0;
  641. DataTable dtLotno = new DataTable();
  642. DataTable lstDt = new DataTable();
  643. DataTable dttt = new DataTable();
  644. //string sqql = @"select a.Amount FROM ICSInventoryLot a
  645. // WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  646. //sqql = string.Format(sqql, LotNo, WorkPoint);
  647. //DataTable dtaa = DBHelper.SQlReturnData(sqql, cmd);
  648. //amount = dtaa.Rows[0]["Amount"].ToString();
  649. //string cheksql = @"select d.EATTRIBUTE1 FROM ICSInventoryLot a
  650. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  651. // INNER JOIN ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  652. // WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and d.AmountEnable='1'";
  653. //cheksql = string.Format(cheksql, LotNo, WorkPoint);
  654. //DataTable dta = DBHelper.SQlReturnData(cheksql, cmd);
  655. //if (dta.Rows.Count > 0)
  656. //{
  657. // Quantity = (decimal.Parse(Quantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  658. //}
  659. if (BusinessCode != TransTypeEnum.SalesReturnBack.GetDescription<DBValue>())
  660. {
  661. if (string.IsNullOrWhiteSpace(LogID))
  662. {
  663. sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  664. BEGIN
  665. RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
  666. RETURN
  667. END ";
  668. }
  669. else
  670. {
  671. sql = @"SELECT LocationCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  672. sql = string.Format(sql, LotNo, WorkPoint);
  673. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  674. if (dt == null || dt.Rows.Count <= 0)
  675. {
  676. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
  677. }
  678. locationcode = dt.Rows[0]["LocationCode"].ToString();
  679. }
  680. }
  681. if(BusinessCode == TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>())
  682. {
  683. sql = @"SELECT FromLocationCode FROM ICSWareHouseLotInfoLog a WHERE LotNo='{0}' AND WorkPoint='{1}' AND ID='{2}'";
  684. sql = string.Format(sql, LotNo, WorkPoint,LogID);
  685. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  686. if (dt == null || dt.Rows.Count <= 0)
  687. {
  688. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
  689. }
  690. newlocationcode = dt.Rows[0]["FromLocationCode"].ToString();
  691. sql += @" IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  692. BEGIN
  693. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  694. RETURN
  695. END
  696. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  697. BEGIN
  698. IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity=0)
  699. BEGIN
  700. UPDATE a SET a.Quantity=ISNULL(a.Quantity,0)+'{3}',WarehouseCode=e.WarehouseCode,LocationCode=d.LocationCode
  701. From ICSWareHouseLotInfo a
  702. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  703. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  704. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  705. END
  706. ELSE IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.LocationCode=(select a.FromLocationCode FROM ICSWareHouseLotInfoLog a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.id='{5}'
  707. AND a.FromLocationCode='" + locationcode + @"'))
  708. BEGIN
  709. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
  710. WHERE LotNo='{0}' AND WorkPoint='{1}'
  711. END
  712. ELSE
  713. BEGIN
  714. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo395"), "{4}", locationcode) + @"', 16, 1);
  715. RETURN
  716. END
  717. END
  718. ELSE
  719. BEGIN
  720. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  721. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  722. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  723. BEGIN
  724. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  725. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  726. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}' AND il.LocationCode='{4}')
  727. BEGIN
  728. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  729. RETURN
  730. END
  731. END
  732. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  733. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  734. FROM ICSInventoryLot a
  735. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  736. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  737. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  738. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  739. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  740. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  741. END";
  742. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, newlocationcode, LogID);
  743. }
  744. else if (BusinessCode == TransTypeEnum.MOStockINByProductNoTrans.GetDescription<DBValue>())
  745. {
  746. sql += @" IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  747. BEGIN
  748. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  749. RETURN
  750. END
  751. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  752. BEGIN
  753. IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity=0)
  754. BEGIN
  755. UPDATE a SET a.Quantity=ISNULL(a.Quantity,0)+'{3}',WarehouseCode=e.WarehouseCode,LocationCode=d.LocationCode
  756. From ICSWareHouseLotInfo a
  757. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  758. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  759. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  760. END
  761. ELSE IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.LocationCode='{4}')
  762. BEGIN
  763. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
  764. WHERE LotNo='{0}' AND WorkPoint='{1}'
  765. END
  766. ELSE IF('" + locationcode + @"' != '{4}')
  767. BEGIN
  768. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo395"), "{4}", locationcode) + @"', 16, 1);
  769. RETURN
  770. END
  771. END
  772. ELSE
  773. BEGIN
  774. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  775. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  776. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  777. BEGIN
  778. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  779. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  780. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}' AND il.LocationCode='{4}')
  781. BEGIN
  782. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  783. RETURN
  784. END
  785. END
  786. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  787. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  788. FROM ICSInventoryLot a
  789. LEFT JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  790. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  791. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  792. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  793. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  794. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  795. END";
  796. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode);
  797. }
  798. else if (BusinessCode == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription<DBValue>())
  799. {
  800. //入库分批
  801. sql = @"select Quantity from ICSWareHouseLotInfo
  802. where LotNO='{0}' AND WorkPoint='{1}'";
  803. sql = string.Format(sql, LotNo, WorkPoint);
  804. DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
  805. if (dtt.Rows.Count<0||dtt==null)
  806. {
  807. throw new Exception("请使用发料条码进行退料");//条码分批后条码表存入失败!
  808. }
  809. LotQTYYY = Convert.ToDecimal(dtt.Rows[0]["Quantity"]);
  810. log.Debug("数量:"+LotQTYYY);
  811. if (LotFlag == "1")
  812. {
  813. if (LotQTYYY > 0)
  814. {
  815. #region 获取分批后的条码(lotstr)
  816. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  817. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  818. sql = string.Format(sql, LotNo, WorkPoint);
  819. dttt = DBHelper.SQlReturnData(sql, cmd);
  820. if (dttt.Rows.Count == 0)
  821. {
  822. lotstr = LotNo + "-" + 1;
  823. }
  824. else
  825. {
  826. lotstr = LotNo + "-" + (Convert.ToInt32(dttt.Rows[0]["LotNO"].ToString().Split('-')[dttt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  827. }
  828. //NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  829. #endregion
  830. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  831. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  832. Quantity,Amount,ExtensionID,Type,PrintTimes,
  833. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  834. WorkPoint,EATTRIBUTE1)
  835. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  836. '{2}',a.Amount/a.Quantity*Quantity,a.ExtensionID,a.Type,a.PrintTimes,
  837. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  838. a.WorkPoint ,'{1}'
  839. From ICSInventoryLot a
  840. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  841. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  842. cmd.CommandText = sql;
  843. result = cmd.ExecuteNonQuery();
  844. if (result <= 0)
  845. {
  846. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  847. }
  848. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  849. select NEWID(),'{0}','{5}','{4}',InvCode,'{2}',InDate,LockQuantity
  850. ,MUSER,MUSERName,GETDATE(),'{3}',''
  851. from ICSWareHouseLotInfo
  852. where LotNO='{1}' AND WorkPoint='{3}'";
  853. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint, LocationCode, WarehouseCode);
  854. log.Debug("添加库存sql:"+sql);
  855. cmd.CommandText = sql;
  856. result = cmd.ExecuteNonQuery();
  857. if (result <= 0)
  858. {
  859. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  860. }
  861. //插入条码单据表
  862. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  863. SELECT '{3}','{4}','{5}',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  864. FROM ICSInventoryLot a
  865. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  866. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  867. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  868. sql = string.Format(sql, LotNo, WorkPoint, User, lotstr,TransCode,TransSequence);
  869. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  870. {
  871. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  872. }
  873. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  874. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  875. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  876. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  877. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  878. SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
  879. '','','{12}','{11}','{6}',
  880. '','0','{7}','{8}','0','',
  881. '','','',f.F_Account ,f.F_RealName ,
  882. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  883. FROM ICSInventoryLot a
  884. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  885. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  886. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  887. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  888. ";
  889. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, "", lotstr, LocationCode, WarehouseCode);
  890. //if (!DBHelper.ExecuteNonQuery(sql, cmd))
  891. //{
  892. // throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//"条码单据表写入失败!");
  893. //}
  894. #endregion
  895. }
  896. else if (LotQTYYY == 0)
  897. {
  898. sql += @" IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  899. BEGIN
  900. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  901. RETURN
  902. END
  903. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}', LocationCode='{4}',WarehouseCode='{5}'
  904. WHERE LotNo='{0}' AND WorkPoint='{1}'
  905. ";
  906. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode, WarehouseCode);
  907. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  908. {
  909. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  910. }
  911. ///添加日志
  912. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  913. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  914. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  915. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  916. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  917. SELECT NEWID(),'{3}','{10}','{11}',a.LotNo ,a.InvCode ,
  918. '','','{9}','{8}','{6}',
  919. '','0','{4}','{5}','0','',
  920. '','','',f.F_Account ,f.F_RealName ,
  921. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  922. FROM ICSInventoryLot a
  923. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  924. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  925. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  926. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  927. ";
  928. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID,LocationCode,WarehouseCode, TransCode, TransSequence);
  929. }
  930. }
  931. else
  932. {
  933. if (LotQTYYY > 0)
  934. {
  935. sql += @" IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  936. BEGIN
  937. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  938. RETURN
  939. END
  940. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
  941. WHERE LotNo='{0}' AND WorkPoint='{1}'
  942. ";
  943. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode);
  944. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  945. {
  946. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  947. }
  948. ///添加日志
  949. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  950. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  951. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  952. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  953. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  954. SELECT NEWID(),'{3}','{10}','{11}',a.LotNo ,a.InvCode ,
  955. '','','{9}','{8}','{6}',
  956. '','0','{4}','{5}','0','',
  957. '','','',f.F_Account ,f.F_RealName ,
  958. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  959. FROM ICSInventoryLot a
  960. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  961. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  962. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  963. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  964. ";
  965. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID, LocationCode, WarehouseCode, TransCode, TransSequence);
  966. }
  967. else if (LotQTYYY == 0)
  968. {
  969. sql += @" IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  970. BEGIN
  971. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  972. RETURN
  973. END
  974. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}', LocationCode='{4}',WarehouseCode='{5}'
  975. WHERE LotNo='{0}' AND WorkPoint='{1}'
  976. ";
  977. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode, WarehouseCode);
  978. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  979. {
  980. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  981. }
  982. ///添加日志
  983. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  984. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  985. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  986. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  987. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  988. SELECT NEWID(),'{3}','{10}','{11}',a.LotNo ,a.InvCode ,
  989. '','','{9}','{8}','{6}',
  990. '','0','{4}','{5}','0','',
  991. '','','',f.F_Account ,f.F_RealName ,
  992. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  993. FROM ICSInventoryLot a
  994. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  995. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  996. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  997. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  998. ";
  999. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID, LocationCode, WarehouseCode, TransCode, TransSequence);
  1000. }
  1001. }
  1002. }
  1003. else
  1004. {
  1005. sql += @" IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1006. BEGIN
  1007. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1008. RETURN
  1009. END
  1010. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1011. BEGIN
  1012. IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity=0)
  1013. BEGIN
  1014. UPDATE a SET a.Quantity=ISNULL(a.Quantity,0)+'{3}',WarehouseCode=e.WarehouseCode,LocationCode=d.LocationCode
  1015. From ICSWareHouseLotInfo a
  1016. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  1017. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  1018. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1019. END
  1020. ELSE IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.LocationCode='{4}')
  1021. BEGIN
  1022. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
  1023. WHERE LotNo='{0}' AND WorkPoint='{1}'
  1024. END
  1025. ELSE IF('" + locationcode + @"' != '{4}')
  1026. BEGIN
  1027. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo395"), "{4}", locationcode) + @"', 16, 1);
  1028. RETURN
  1029. END
  1030. END
  1031. ELSE
  1032. BEGIN
  1033. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  1034. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  1035. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  1036. BEGIN
  1037. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  1038. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  1039. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}' AND il.LocationCode='{4}')
  1040. BEGIN
  1041. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  1042. RETURN
  1043. END
  1044. END
  1045. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1046. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  1047. FROM ICSInventoryLot a
  1048. --INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1049. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1050. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  1051. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  1052. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1053. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1054. END";
  1055. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode);
  1056. }
  1057. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1058. {
  1059. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  1060. }
  1061. if (BusinessCode != TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription<DBValue>())
  1062. {
  1063. log.Debug("1111");
  1064. if (BusinessCode == TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>())
  1065. {
  1066. ///添加日志
  1067. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1068. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1069. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1070. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1071. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  1072. SELECT NEWID(),'{3}','{8}','{9}',a.LotNo ,a.InvCode ,
  1073. '','',c.WarehouseCode,c.LocationCode,'{6}',
  1074. '','0','{4}','{5}','0','',
  1075. '','','',f.F_Account ,f.F_RealName ,
  1076. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  1077. FROM ICSInventoryLot a
  1078. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1079. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1080. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1081. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1082. ";
  1083. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID, TransCode, TransSequence);
  1084. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1085. {
  1086. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1087. }
  1088. }
  1089. else if (BusinessCode == TransTypeEnum.MOStockINByProduct.GetDescription<DBValue>())
  1090. {
  1091. ///添加日志
  1092. sql = @"IF EXISTS(SELECT 1 FROM ICSInventoryLot lot WHERE lot.LotNo='{0}' AND lot.WorkPoint='{1}' AND lot.Type=19)
  1093. BEGIN
  1094. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1095. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1096. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1097. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1098. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  1099. SELECT NEWID(),'{3}','','',a.LotNo ,a.InvCode ,
  1100. '','',c.WarehouseCode,c.LocationCode,'{6}',
  1101. '','0','{4}','{5}','0','',
  1102. '','','',f.F_Account ,f.F_RealName ,
  1103. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  1104. FROM ICSInventoryLot a
  1105. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1106. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1107. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1108. END
  1109. ELSE
  1110. BEGIN
  1111. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1112. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1113. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1114. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1115. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  1116. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1117. '','',c.WarehouseCode,c.LocationCode,'{6}',
  1118. '','0','{4}','{5}','0','',
  1119. '','','',f.F_Account ,f.F_RealName ,
  1120. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  1121. FROM ICSInventoryLot a
  1122. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1123. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1124. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1125. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1126. END
  1127. ";
  1128. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
  1129. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1130. {
  1131. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1132. }
  1133. }
  1134. else if (BusinessCode == TransTypeEnum.MOStockINByProductNoTrans.GetDescription<DBValue>())
  1135. {
  1136. ///添加日志
  1137. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1138. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1139. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1140. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1141. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  1142. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1143. '','',c.WarehouseCode,c.LocationCode,'{6}',
  1144. '','0','{4}','{5}','0','',
  1145. '','','',f.F_Account ,f.F_RealName ,
  1146. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  1147. FROM ICSInventoryLot a
  1148. LEFT JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1149. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1150. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1151. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1152. ";
  1153. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
  1154. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1155. {
  1156. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1157. }
  1158. }
  1159. else if (BusinessCode == TransTypeEnum.OOStockINByProduct.GetDescription<DBValue>())
  1160. {
  1161. ///添加日志
  1162. sql = @"IF EXISTS(SELECT 1 FROM ICSInventoryLot lot WHERE lot.LotNo='{0}' AND lot.WorkPoint='{1}' AND lot.Type=19)
  1163. BEGIN
  1164. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1165. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1166. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1167. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1168. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  1169. SELECT NEWID(),'{3}','','',a.LotNo ,a.InvCode ,
  1170. '','',c.WarehouseCode,c.LocationCode,'{6}',
  1171. '','0','{4}','{5}','0','',
  1172. '','','',f.F_Account ,f.F_RealName ,
  1173. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  1174. FROM ICSInventoryLot a
  1175. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1176. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1177. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1178. END
  1179. ELSE
  1180. BEGIN
  1181. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1182. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1183. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1184. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1185. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  1186. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1187. '','',c.WarehouseCode,c.LocationCode,'{6}',
  1188. '','0','{4}','{5}','0','',
  1189. '','','',f.F_Account ,f.F_RealName ,
  1190. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  1191. FROM ICSInventoryLot a
  1192. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1193. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1194. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1195. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1196. END
  1197. ";
  1198. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
  1199. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1200. {
  1201. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1202. }
  1203. }
  1204. else
  1205. {
  1206. ///添加日志
  1207. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1208. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1209. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1210. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1211. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  1212. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1213. '','',c.WarehouseCode,c.LocationCode,'{6}',
  1214. '','0','{4}','{5}','0','',
  1215. '','','',f.F_Account ,f.F_RealName ,
  1216. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  1217. FROM ICSInventoryLot a
  1218. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1219. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1220. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1221. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1222. ";
  1223. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
  1224. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1225. {
  1226. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1227. }
  1228. }
  1229. }
  1230. #endregion
  1231. #region 管控方式是"料品"时
  1232. ControlMode mode = ICSControlModeService.GetControlMode();
  1233. if (mode.itemCode.Equals("ControlMode02"))
  1234. {
  1235. //查询是否存在料品管控的条码
  1236. string sqlStrNew = @"SELECT a.ID,
  1237. con.ContainerCode,
  1238. con.ContainerName,
  1239. a.LotNo,
  1240. a.InvCode,
  1241. inv.InvName,
  1242. inv.InvStd,
  1243. inv.InvUnit,-- {0}
  1244. inv.AmountUnit,
  1245. ext.ID AS ExtensionID,
  1246. ext.ProjectCode,
  1247. ext.Version,
  1248. ext.BatchCode,
  1249. ext.Brand,
  1250. ext.cFree1,
  1251. ext.cFree2,
  1252. ext.cFree3,
  1253. ext.cFree4,
  1254. ext.cFree5,
  1255. ext.cFree6,
  1256. ext.cFree7,
  1257. ext.cFree8,
  1258. ext.cFree9,
  1259. ext.cFree10,
  1260. a.MUSER AS [ USER ],
  1261. a.MTIME AS [ MTime ]
  1262. FROM
  1263. ICSInventoryLot a
  1264. LEFT JOIN ICSContainerLot conlot ON a.LotNo = conlot.LotNo AND a.WorkPoint = conlot.WorkPoint
  1265. LEFT JOIN ICSContainer con ON conlot.ContainerID = con.ID AND conlot.WorkPoint = con.WorkPoint
  1266. INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint
  1267. INNER JOIN ICSExtension ext ON a.ExtensionID = ext.ID AND a.WorkPoint = ext.WorkPoint
  1268. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1269. sqlStrNew = string.Format(sqlStrNew, jointLotNo, WorkPoint);
  1270. DataTable table = DBHelper.SQlReturnData(sqlStrNew, cmd);
  1271. string json = JsonConvert.SerializeObject(table);
  1272. List<LotNoMode> modelNew = JsonConvert.DeserializeObject<List<LotNoMode>>(json);
  1273. //当不存在料品管控条码时,生成新条码
  1274. if (!(modelNew.Count > 0))
  1275. {
  1276. //获取旧条码的信息
  1277. string jsonStr = ICSControlModeService.QueryLotNo(LotNo, WorkPoint);
  1278. List<LotNoMode> model = JsonConvert.DeserializeObject<List<LotNoMode>>(jsonStr);
  1279. //在条码表中插入一条新数据,在条码表中插入一条新数据,并在库存表中添加新数据
  1280. LotNoMode lotNoMode = model[0];
  1281. CreateLotNo(jointLotNo, Quantity, "", "", WorkPoint, Identification, User, lotNoMode.InvCode, BusinessCode, lotNoMode.ProjectCode, lotNoMode.BatchCode,
  1282. lotNoMode.Version, lotNoMode.Brand, lotNoMode.cFree1, lotNoMode.cFree2, lotNoMode.cFree3, lotNoMode.cFree4, lotNoMode.cFree5, lotNoMode.cFree6, lotNoMode.cFree7,
  1283. lotNoMode.cFree8, lotNoMode.cFree9, lotNoMode.cFree10, cmd, language, LocationCode, LotNo);
  1284. }
  1285. try
  1286. {
  1287. //合并前日志
  1288. WareHouseLotInfoLog(Identification, jointLotNo, User, WorkPoint, "2",
  1289. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(), "", cmd, language);
  1290. //更新目标条码库存
  1291. WareHouseLotInfoMerge(Identification, jointLotNo, LotNo, Quantity, User, WorkPoint, "2",
  1292. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  1293. //合并后日志
  1294. WareHouseLotInfoLog(Identification, jointLotNo, User, WorkPoint, "2",
  1295. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), "", cmd, language);
  1296. }
  1297. catch (Exception)
  1298. {
  1299. throw;
  1300. }
  1301. }
  1302. #endregion
  1303. #region 成品(生产)入库,倒冲
  1304. if (BusinessCode.Equals(TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>()))
  1305. {
  1306. #region sql
  1307. sql = @"-- 1.创建临时表 初始单据数据 maintemp
  1308. SELECT
  1309. c.MOCode AS TransCode,
  1310. a.MODetailID AS DetailID,
  1311. a.InvCode,
  1312. b.InvName,
  1313. b.InvStd,
  1314. a.ParentQuantity/c.Quantity*{2} AS Quantity,
  1315. a.Amount,
  1316. a.Sequence AS TransSequence,
  1317. a.IssueQuantity,
  1318. c.Sequence,
  1319. inv.InvUnit,
  1320. 0 AS LocationQty,
  1321. inv.AmountUnit,
  1322. a.ExtensionID,
  1323. a.WorkPoint,
  1324. ext.ProjectCode,
  1325. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  1326. ext.Version,
  1327. ext.Brand,
  1328. ext.cFree1,
  1329. ext.cFree2,
  1330. ext.cFree3,
  1331. ext.cFree4,
  1332. ext.cFree5,
  1333. ext.cFree6,
  1334. ext.cFree7,
  1335. ext.cFree8,
  1336. ext.cFree9,
  1337. ext.cFree10
  1338. INTO #maintemp
  1339. FROM
  1340. ICSMOPick a
  1341. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  1342. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1343. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1344. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1345. INNER JOIN (
  1346. SELECT a.MOCode,a.Sequence,a.WorkPoint
  1347. FROM ICSMO a
  1348. INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.MOCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
  1349. INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
  1350. WHERE c.LotNo='{0}' AND c.WorkPoint='{1}'
  1351. ) temp ON c.MOCode=temp.MOCode AND a.WorkPoint=temp.WorkPoint AND c.Sequence=temp.Sequence
  1352. WHERE a.SupplyType='1'
  1353. GROUP BY c.MOCode,a.ParentQuantity,a.Quantity,c.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,
  1354. 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;
  1355. select * into #resulttemp from #maintemp
  1356. ALTER TABLE #resulttemp ADD LotNo VARCHAR(50)
  1357. delete from #resulttemp
  1358. -- 2.maintemp barcodetemp
  1359. select a.lotno,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime into #barcodetemp from ICSWareHouseLotInfo a LEFT JOIN
  1360. (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
  1361. -- 3.maintemp ID barcodetemp
  1362. BEGIN
  1363. DECLARE @transSequence int;--
  1364. DECLARE @qty int;--
  1365. DECLARE @needqty int;--
  1366. DECLARE @lotno VARCHAR(50);--
  1367. DECLARE @DetailID VARCHAR(50);--ID
  1368. DECLARE tempCursor CURSOR FOR (select transSequence,DetailID from #maintemp); --tempCursor
  1369. OPEN tempCursor; --
  1370. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID; --
  1371. WHILE @@fetch_status=0
  1372. BEGIN
  1373. select @needqty=Quantity from #maintemp where transSequence = @transSequence AND DetailID = @DetailID
  1374. PRINT @transSequence
  1375. WHILE @needqty>0
  1376. BEGIN
  1377. select top 1 @qty = isnull(quantity,0),@lotno = isnull(lotno,'') from #barcodetemp a
  1378. RIGHT JOIN (select invcode from #maintemp where transSequence = @transSequence AND DetailID = @DetailID) b on a.invcode=b.invcode ORDER BY mtime
  1379. BEGIN
  1380. IF(@needqty-@qty>=0 and ISNULL(@lotno, '')<>'')
  1381. BEGIN
  1382. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  1383. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  1384. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  1385. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  1386. ISNULL(Amount, 0), InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@qty,ISNULL(AmountUnit, ''),
  1387. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  1388. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  1389. delete from #barcodetemp where lotno = @lotno
  1390. SET @needqty=@needqty-@qty
  1391. END
  1392. ELSE IF(@needqty-@qty<0 and ISNULL(@lotno, '')<>'')
  1393. BEGIN
  1394. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  1395. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  1396. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  1397. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  1398. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@needqty,ISNULL(AmountUnit, ''),
  1399. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  1400. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  1401. update #barcodetemp set quantity = @qty-@needqty where lotno = @lotno
  1402. SET @needqty=@needqty-@qty
  1403. END
  1404. ELSE
  1405. BEGIN
  1406. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  1407. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  1408. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  1409. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  1410. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,0,ISNULL(AmountUnit, ''),
  1411. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  1412. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  1413. SET @needqty=0
  1414. END
  1415. END
  1416. END
  1417. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID;
  1418. END
  1419. CLOSE tempCursor
  1420. DEALLOCATE tempCursor
  1421. END
  1422. select TransCode,LotNo,LocationQty AS Quantity,InvCode,DetailID,Sequence,TransSequence from #resulttemp
  1423. --select * from #resulttemp
  1424. DROP table #maintemp
  1425. DROP table #resulttemp
  1426. DROP table #barcodetemp";
  1427. #endregion
  1428. sql = String.Format(sql, LotNo, WorkPoint, Quantity);
  1429. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  1430. string json = JsonConvert.SerializeObject(table);
  1431. List<DownItemModel> downItemModels = JsonConvert.DeserializeObject<List<DownItemModel>>(json);
  1432. foreach (DownItemModel model in downItemModels)
  1433. {
  1434. if (model != null && model.LotNo == null || "" == model.LotNo)
  1435. {
  1436. throw new Exception(language.GetNameByCode("WMSAPIInfo201"));
  1437. }
  1438. WareHouseLotInfoDown(Identification, model.TransCode, model.Sequence + "~" + model.TransSequence, model.LotNo, model.Quantity, User, WorkPoint, "12", BusinessCode, cmd, language, "", "");
  1439. //回写已领数量
  1440. sql = @"UPDATE ICSMOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + model.Quantity + ") WHERE MODetailID='{0}' AND Sequence='{1}' AND WorkPoint='{2}'";
  1441. sql = String.Format(sql, model.DetailID, model.TransSequence, WorkPoint);
  1442. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1443. {
  1444. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1445. }
  1446. }
  1447. }
  1448. #endregion
  1449. #region 委外入库,倒冲
  1450. if (BusinessCode.Equals(TransTypeEnum.OutsourcingReceiveDoc.GetDescription<DBValue>()))
  1451. {
  1452. #region sql
  1453. sql = @"-- 1.创建临时表 初始单据数据 maintemp
  1454. SELECT
  1455. c.OOCode AS TransCode,
  1456. a.OODetailID AS DetailID,
  1457. a.InvCode,
  1458. b.InvName,
  1459. b.InvStd,
  1460. a.ParentQuantity/c.Quantity*{2} AS Quantity,
  1461. a.Amount,
  1462. a.Sequence AS TransSequence,
  1463. a.IssueQuantity,
  1464. c.Sequence,
  1465. inv.InvUnit,
  1466. 0 AS LocationQty,
  1467. inv.AmountUnit,
  1468. a.ExtensionID,
  1469. a.WorkPoint,
  1470. ext.ProjectCode,
  1471. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  1472. ext.Version,
  1473. ext.Brand,
  1474. ext.cFree1,
  1475. ext.cFree2,
  1476. ext.cFree3,
  1477. ext.cFree4,
  1478. ext.cFree5,
  1479. ext.cFree6,
  1480. ext.cFree7,
  1481. ext.cFree8,
  1482. ext.cFree9,
  1483. ext.cFree10
  1484. INTO #maintemp
  1485. FROM
  1486. ICSOOPick a
  1487. inner join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  1488. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1489. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1490. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1491. INNER JOIN (
  1492. SELECT a.OOCode,a.Sequence,a.WorkPoint
  1493. FROM ICSOutsourcingOrder a
  1494. INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.OOCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
  1495. INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
  1496. WHERE c.LotNo='{0}' AND c.WorkPoint='{1}'
  1497. ) temp ON c.OOCode=temp.OOCode AND a.WorkPoint=temp.WorkPoint AND c.Sequence=temp.Sequence
  1498. WHERE a.SupplyType='1'
  1499. GROUP BY c.OOCode,a.ParentQuantity,a.Quantity,c.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,
  1500. 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;
  1501. select * into #resulttemp from #maintemp
  1502. ALTER TABLE #resulttemp ADD LotNo VARCHAR(50)
  1503. delete from #resulttemp
  1504. -- 2.maintemp barcodetemp
  1505. select a.lotno,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime into #barcodetemp from ICSWareHouseLotInfo a LEFT JOIN
  1506. (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
  1507. -- 3.maintemp ID barcodetemp
  1508. BEGIN
  1509. DECLARE @transSequence int;--
  1510. DECLARE @qty int;--
  1511. DECLARE @needqty int;--
  1512. DECLARE @lotno VARCHAR(50);--
  1513. DECLARE @DetailID VARCHAR(50);--ID
  1514. DECLARE tempCursor CURSOR FOR (select transSequence,DetailID from #maintemp); --tempCursor
  1515. OPEN tempCursor; --
  1516. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID; --
  1517. WHILE @@fetch_status=0
  1518. BEGIN
  1519. select @needqty=Quantity from #maintemp where transSequence = @transSequence AND DetailID = @DetailID
  1520. PRINT @transSequence
  1521. WHILE @needqty>0
  1522. BEGIN
  1523. select top 1 @qty = isnull(quantity,0),@lotno = isnull(lotno,'') from #barcodetemp a
  1524. RIGHT JOIN (select invcode from #maintemp where transSequence = @transSequence AND DetailID = @DetailID) b on a.invcode=b.invcode ORDER BY mtime
  1525. BEGIN
  1526. IF(@needqty-@qty>=0 and ISNULL(@lotno, '')<>'')
  1527. BEGIN
  1528. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  1529. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  1530. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  1531. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  1532. ISNULL(Amount, 0), InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@qty,ISNULL(AmountUnit, ''),
  1533. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  1534. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  1535. delete from #barcodetemp where lotno = @lotno
  1536. SET @needqty=@needqty-@qty
  1537. END
  1538. ELSE IF(@needqty-@qty<0 and ISNULL(@lotno, '')<>'')
  1539. BEGIN
  1540. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  1541. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  1542. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  1543. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  1544. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@needqty,ISNULL(AmountUnit, ''),
  1545. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  1546. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  1547. update #barcodetemp set quantity = @qty-@needqty where lotno = @lotno
  1548. SET @needqty=@needqty-@qty
  1549. END
  1550. ELSE
  1551. BEGIN
  1552. insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
  1553. Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
  1554. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
  1555. SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
  1556. ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,0,ISNULL(AmountUnit, ''),
  1557. ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
  1558. where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
  1559. SET @needqty=0
  1560. END
  1561. END
  1562. END
  1563. FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID;
  1564. END
  1565. CLOSE tempCursor
  1566. DEALLOCATE tempCursor
  1567. END
  1568. select TransCode,LotNo,LocationQty AS Quantity,InvCode,DetailID,Sequence,TransSequence from #resulttemp
  1569. --select * from #resulttemp
  1570. DROP table #maintemp
  1571. DROP table #resulttemp
  1572. DROP table #barcodetemp";
  1573. #endregion
  1574. sql = String.Format(sql, LotNo, WorkPoint, Quantity);
  1575. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  1576. string json = JsonConvert.SerializeObject(table);
  1577. List<DownItemModel> downItemModels = JsonConvert.DeserializeObject<List<DownItemModel>>(json);
  1578. foreach (DownItemModel model in downItemModels)
  1579. {
  1580. if (model != null && model.LotNo == null || "" == model.LotNo)
  1581. {
  1582. throw new Exception(language.GetNameByCode("WMSAPIInfo201"));
  1583. }
  1584. WareHouseLotInfoDown(Identification, model.TransCode, model.Sequence + "~" + model.TransSequence, model.LotNo, model.Quantity, User, WorkPoint, "13", BusinessCode, cmd, language, "", "");
  1585. //回写已领数量
  1586. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + model.Quantity + ") WHERE OODetailID='{0}' AND Sequence='{1}' AND WorkPoint='{2}'";
  1587. sql = String.Format(sql, model.DetailID, model.TransSequence, WorkPoint);
  1588. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1589. {
  1590. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1591. }
  1592. }
  1593. }
  1594. #endregion
  1595. }
  1596. catch (Exception)
  1597. {
  1598. throw;
  1599. }
  1600. }
  1601. /// <summary>
  1602. /// 减少库存
  1603. /// </summary>
  1604. /// <param name="Identification"></param>
  1605. /// <param name="TransCode"></param>
  1606. /// <param name="TransSequence"></param>
  1607. /// <param name="LotNo"></param>
  1608. /// <param name="Quantity"></param>
  1609. /// <param name="User"></param>
  1610. /// <param name="WorkPoint"></param>
  1611. /// <param name="TransType"></param>
  1612. /// <param name="BusinessCode"></param>
  1613. /// <param name="cmd"></param>
  1614. public static DataTable WareHouseLotInfoDown(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
  1615. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string LogID, string MergeID = "")
  1616. {
  1617. decimal LotQTYYY = 0;
  1618. decimal LotQTY = 0;
  1619. string LotEnable = "";
  1620. string chekEnable = "";
  1621. string DisPrintEnable = "";
  1622. string PrintEnable = "";
  1623. string sql = "";
  1624. string lotstr = "";
  1625. int result = 0;
  1626. List<string> NewBarCodeList = new List<string>();
  1627. DataTable dtLotno = new DataTable();
  1628. DataTable lstDt = new DataTable();
  1629. DataTable ZLtable = new DataTable();
  1630. try
  1631. {
  1632. //检验是否分批
  1633. sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  1634. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  1635. where a.LotNo='{0}' and a.WorkPoint='{1}'
  1636. ";
  1637. sql = string.Format(sql, LotNo, WorkPoint);
  1638. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1639. if (dt.Rows.Count == 0)
  1640. {
  1641. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  1642. }
  1643. else
  1644. {
  1645. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  1646. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  1647. }
  1648. string cheksql = @"IF NOT EXISTS(select b.F_ItemCode as Code ,b.F_ItemName as Name,b.F_EnabledMark AS Enable ,b.F_IsDefault AS DisPrintEnable
  1649. from Sys_SRM_Items a
  1650. left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  1651. where a.F_EnCode='TransBatch' and b.F_ItemCode='{0}' )
  1652. BEGIN
  1653. RAISERROR('" + language.GetNameByCode("WMSAPIInfo470") + @"',16,1);
  1654. RETURN
  1655. END
  1656. select b.F_ItemCode as Code ,b.F_ItemName as Name,b.F_EnabledMark AS Enable ,b.F_IsDefault AS DisPrintEnable
  1657. from Sys_SRM_Items a
  1658. left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  1659. where a.F_EnCode='TransBatch' and b.F_ItemCode='{0}'
  1660. ";
  1661. cheksql = string.Format(cheksql, BusinessCode);
  1662. DataTable chekdt = DBHelper.SQlReturnData(cheksql, cmd);
  1663. if (chekdt.Rows.Count == 0)
  1664. {
  1665. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  1666. }
  1667. else
  1668. {
  1669. chekEnable = chekdt.Rows[0]["Enable"].ToString();
  1670. DisPrintEnable = chekdt.Rows[0]["DisPrintEnable"].ToString();
  1671. }
  1672. sql = @"select Quantity from ICSWareHouseLotInfo
  1673. where LotNO='{0}' AND WorkPoint='{1}'";
  1674. sql = string.Format(sql, LotNo, WorkPoint);
  1675. DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
  1676. LotQTYYY = Convert.ToDecimal(dtt.Rows[0]["Quantity"]);
  1677. LotQTY = Convert.ToDecimal(Quantity);
  1678. if (!LotEnable.Equals("False")&&!chekEnable.Equals("False") && LotQTYYY - LotQTY > 0)
  1679. {
  1680. ZLtable = ICSControlModeService.GetZL();
  1681. if (ZLtable == null)
  1682. {
  1683. throw new Exception(language.GetNameByCode("WMSAPIInfo471"));
  1684. }
  1685. for (int i = 0; i < ZLtable.Rows.Count; i++)
  1686. {
  1687. string zlName = ZLtable.Rows[i]["Name"].ToString();
  1688. string zlTransCode = ZLtable.Rows[i]["BusinessCode"].ToString();
  1689. string Enable = ZLtable.Rows[i]["Enable"].ToString();
  1690. if (zlTransCode.Equals(BusinessCode))
  1691. {
  1692. if (Enable.Equals("True"))
  1693. {
  1694. ///更新日志
  1695. sql = @"
  1696. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and transtype='15')
  1697. BEGIN
  1698. RAISERROR('" + language.GetNameByCode("WMSAPIInfo472") + @"',16,1);
  1699. RETURN
  1700. END
  1701. UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE2='1' WHERE LotNo='{0}' AND WorkPoint='{1}' and transtype='15'
  1702. ";
  1703. sql = string.Format(sql, LotNo, WorkPoint, LogID);
  1704. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1705. {
  1706. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"占料标识更新失败!");
  1707. }
  1708. ///更新库存
  1709. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}',LockQuantity=ISNULL(LockQuantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1710. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity-LockQuantity<0)
  1711. BEGIN
  1712. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1713. RETURN
  1714. END";
  1715. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1716. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1717. {
  1718. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1719. }
  1720. }
  1721. else
  1722. {
  1723. ///更新库存
  1724. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-ISNULL(LockQuantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1725. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity-LockQuantity<0)
  1726. BEGIN
  1727. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1728. RETURN
  1729. END";
  1730. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1731. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1732. {
  1733. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1734. }
  1735. }
  1736. }
  1737. }
  1738. ///分批前添加日志
  1739. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1740. BEGIN
  1741. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1742. RETURN
  1743. END
  1744. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1745. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1746. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1747. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1748. MTIME,WorkPoint,EATTRIBUTE1)
  1749. SELECT NEWID(),'{3}','{7}','{8}',a.LotNo ,a.InvCode ,
  1750. c.WarehouseCode,c.LocationCode,'','',c.Quantity+{6},
  1751. '','0','{4}','31','0','',
  1752. '','','',f.F_Account ,f.F_RealName ,
  1753. SYSDATETIME() ,a.WorkPoint ,''
  1754. FROM ICSInventoryLot a
  1755. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1756. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1757. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1758. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1759. ";
  1760. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, TransCode, TransSequence);
  1761. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1762. {
  1763. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1764. }
  1765. #region 获取分批后的条码(lotstr)
  1766. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  1767. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  1768. sql = string.Format(sql, LotNo, WorkPoint);
  1769. dt = DBHelper.SQlReturnData(sql, cmd);
  1770. if (dt.Rows.Count == 0)
  1771. {
  1772. lotstr = LotNo + "-" + 1;
  1773. }
  1774. else
  1775. {
  1776. lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  1777. }
  1778. NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  1779. #endregion
  1780. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  1781. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  1782. Quantity,Amount,ExtensionID,Type,PrintTimes,
  1783. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  1784. WorkPoint,EATTRIBUTE1)
  1785. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  1786. '{2}',a.Amount/a.Quantity*Quantity,a.ExtensionID,a.Type,a.PrintTimes,
  1787. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  1788. a.WorkPoint ,'{1}'
  1789. From ICSInventoryLot a
  1790. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  1791. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  1792. cmd.CommandText = sql;
  1793. result = cmd.ExecuteNonQuery();
  1794. if (result <= 0)
  1795. {
  1796. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  1797. }
  1798. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1799. select NEWID(),'{0}',WarehouseCode,LocationCode,InvCode,'0',InDate,LockQuantity
  1800. ,MUSER,MUSERName,GETDATE(),'{3}',''
  1801. from ICSWareHouseLotInfo
  1802. where LotNO='{1}' AND WorkPoint='{3}'";
  1803. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  1804. cmd.CommandText = sql;
  1805. result = cmd.ExecuteNonQuery();
  1806. if (result <= 0)
  1807. {
  1808. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  1809. }
  1810. //插入条码单据表
  1811. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1812. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  1813. FROM ICSInventoryLot a
  1814. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1815. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1816. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1817. sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
  1818. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1819. {
  1820. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  1821. }
  1822. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1823. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1824. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1825. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1826. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  1827. SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
  1828. c.WarehouseCode,c.LocationCode,'','','{6}',
  1829. '','0','{7}','{8}','0','',
  1830. '','','',f.F_Account ,f.F_RealName ,
  1831. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  1832. FROM ICSInventoryLot a
  1833. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1834. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1835. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1836. ";
  1837. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr);
  1838. cmd.CommandText = sql;
  1839. result = cmd.ExecuteNonQuery();
  1840. if (result <= 0)
  1841. {
  1842. throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
  1843. }
  1844. if (PrintEnable.Equals("True")&& DisPrintEnable.Equals("True"))
  1845. {
  1846. 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
  1847. from ICSWareHouseLotInfolog A
  1848. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  1849. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  1850. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  1851. where A.lotno ='{0}' and a.workpoint='{1}' and a.BusinessCode='{2}'
  1852. ";
  1853. sql = string.Format(sql, lotstr, WorkPoint,BusinessCode);
  1854. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  1855. lstDt=dtLotno;
  1856. }
  1857. ///添加日志
  1858. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1859. BEGIN
  1860. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1861. RETURN
  1862. END
  1863. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1864. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1865. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1866. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1867. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  1868. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1869. c.WarehouseCode,c.LocationCode,'','',c.Quantity,
  1870. '','0','{7}','32','0','',
  1871. '','','',f.F_Account ,f.F_RealName ,
  1872. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  1873. FROM ICSInventoryLot a
  1874. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1875. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1876. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1877. ";
  1878. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  1879. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1880. {
  1881. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1882. }
  1883. #endregion
  1884. }
  1885. else
  1886. {
  1887. NewBarCodeList.Add(LotNo);
  1888. ///添加日志
  1889. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1890. BEGIN
  1891. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1892. RETURN
  1893. END
  1894. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1895. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1896. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1897. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1898. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  1899. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1900. c.WarehouseCode,c.LocationCode,'','','{6}',
  1901. '','0','{7}','{8}','0','',
  1902. '','','',f.F_Account ,f.F_RealName ,
  1903. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  1904. FROM ICSInventoryLot a
  1905. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1906. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1907. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1908. ";
  1909. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  1910. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1911. {
  1912. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1913. }
  1914. ZLtable = ICSControlModeService.GetZL();
  1915. if (ZLtable == null)
  1916. {
  1917. throw new Exception(language.GetNameByCode("WMSAPIInfo471"));
  1918. }
  1919. for (int i = 0; i < ZLtable.Rows.Count; i++)
  1920. {
  1921. string zlTransCode = ZLtable.Rows[i]["BusinessCode"].ToString();
  1922. string Enable = ZLtable.Rows[i]["Enable"].ToString();
  1923. if (zlTransCode.Equals(BusinessCode))
  1924. {
  1925. if (Enable.Equals("True"))
  1926. {
  1927. ///更新日志
  1928. sql = @"
  1929. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and transtype='15')
  1930. BEGIN
  1931. RAISERROR('" + language.GetNameByCode("WMSAPIInfo472") + @"',16,1);
  1932. RETURN
  1933. END
  1934. UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE2='1' WHERE LotNo='{0}' AND WorkPoint='{1}' and transtype='15'
  1935. ";
  1936. sql = string.Format(sql, LotNo, WorkPoint, LogID);
  1937. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1938. {
  1939. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"占料标识更新失败!");
  1940. }
  1941. ///更新库存
  1942. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}',LockQuantity=ISNULL(LockQuantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1943. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity-LockQuantity<0)
  1944. BEGIN
  1945. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1946. RETURN
  1947. END";
  1948. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1949. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1950. {
  1951. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1952. }
  1953. }
  1954. else
  1955. {
  1956. ///更新库存
  1957. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1958. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity-LockQuantity<0)
  1959. BEGIN
  1960. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1961. RETURN
  1962. END";
  1963. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1964. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1965. {
  1966. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1967. }
  1968. }
  1969. }
  1970. }
  1971. /////更新库存
  1972. //sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1973. // IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  1974. // BEGIN
  1975. // RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1976. // RETURN
  1977. // END";
  1978. //sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1979. //if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1980. //{
  1981. // throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1982. //}
  1983. }
  1984. }
  1985. catch (Exception)
  1986. {
  1987. throw;
  1988. }
  1989. return lstDt;
  1990. }
  1991. /// <summary>
  1992. /// 减少库存(奥美专用)
  1993. /// </summary>
  1994. /// <param name="Identification"></param>
  1995. /// <param name="TransCode"></param>
  1996. /// <param name="TransSequence"></param>
  1997. /// <param name="LotNo"></param>
  1998. /// <param name="Quantity"></param>
  1999. /// <param name="User"></param>
  2000. /// <param name="WorkPoint"></param>
  2001. /// <param name="TransType"></param>
  2002. /// <param name="BusinessCode"></param>
  2003. /// <param name="cmd"></param>
  2004. public static DataTable AMWareHouseLotInfoDown(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
  2005. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string LogID, string MergeID = "")
  2006. {
  2007. decimal LotQTYYY = 0;
  2008. decimal LotQTY = 0;
  2009. string LotEnable = "";
  2010. string chekEnable = "";
  2011. string DisPrintEnable = "";
  2012. string PrintEnable = "";
  2013. string sql = "";
  2014. string lotstr = "";
  2015. int result = 0;
  2016. List<string> NewBarCodeList = new List<string>();
  2017. DataTable dtLotno = new DataTable();
  2018. DataTable lstDt = new DataTable();
  2019. DataTable ZLtable = new DataTable();
  2020. try
  2021. {
  2022. string amount = "";
  2023. //string sqql = @"select a.Amount FROM ICSInventoryLot a
  2024. // WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  2025. //sqql = string.Format(sqql, LotNo, WorkPoint);
  2026. //DataTable dtaa = DBHelper.SQlReturnData(sqql, cmd);
  2027. //amount = dtaa.Rows[0]["Amount"].ToString();
  2028. //string chekksql = @"select c.EATTRIBUTE1 FROM ICSMOPick a
  2029. // INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  2030. // INNER JOIN ICSInventory c on a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  2031. // WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}' and c.AmountEnable='1'";
  2032. //chekksql = string.Format(chekksql, TransCode, WorkPoint, Quantity, TransSequence);
  2033. //DataTable dta = DBHelper.SQlReturnData(chekksql, cmd);
  2034. //if (dta.Rows.Count > 0)
  2035. //{
  2036. // Quantity = (decimal.Parse(Quantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  2037. //}
  2038. //检验是否分批
  2039. sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  2040. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  2041. where a.LotNo='{0}' and a.WorkPoint='{1}'
  2042. ";
  2043. sql = string.Format(sql, LotNo, WorkPoint);
  2044. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2045. if (dt.Rows.Count == 0)
  2046. {
  2047. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  2048. }
  2049. else
  2050. {
  2051. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  2052. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  2053. }
  2054. string cheksql = @"IF NOT EXISTS(select b.F_ItemCode as Code ,b.F_ItemName as Name,b.F_EnabledMark AS Enable ,b.F_IsDefault AS DisPrintEnable
  2055. from Sys_SRM_Items a
  2056. left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  2057. where a.F_EnCode='TransBatch' and b.F_ItemCode='{0}' )
  2058. BEGIN
  2059. RAISERROR('" + language.GetNameByCode("WMSAPIInfo470") + @"',16,1);
  2060. RETURN
  2061. END
  2062. select b.F_ItemCode as Code ,b.F_ItemName as Name,b.F_EnabledMark AS Enable ,b.F_IsDefault AS DisPrintEnable
  2063. from Sys_SRM_Items a
  2064. left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  2065. where a.F_EnCode='TransBatch' and b.F_ItemCode='{0}'
  2066. ";
  2067. cheksql = string.Format(cheksql, BusinessCode);
  2068. DataTable chekdt = DBHelper.SQlReturnData(cheksql, cmd);
  2069. if (chekdt.Rows.Count == 0)
  2070. {
  2071. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  2072. }
  2073. else
  2074. {
  2075. chekEnable = chekdt.Rows[0]["Enable"].ToString();
  2076. DisPrintEnable = chekdt.Rows[0]["DisPrintEnable"].ToString();
  2077. }
  2078. sql = @"select Quantity from ICSWareHouseLotInfo
  2079. where LotNO='{0}' AND WorkPoint='{1}'";
  2080. sql = string.Format(sql, LotNo, WorkPoint);
  2081. DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
  2082. LotQTYYY = Convert.ToDecimal(dtt.Rows[0]["Quantity"]);
  2083. LotQTY = Convert.ToDecimal(Quantity);
  2084. if (!LotEnable.Equals("False") && !chekEnable.Equals("False") && LotQTYYY - LotQTY > 0)
  2085. {
  2086. ZLtable = ICSControlModeService.GetZL();
  2087. if (ZLtable == null)
  2088. {
  2089. throw new Exception(language.GetNameByCode("WMSAPIInfo471"));
  2090. }
  2091. for (int i = 0; i < ZLtable.Rows.Count; i++)
  2092. {
  2093. string zlName = ZLtable.Rows[i]["Name"].ToString();
  2094. string zlTransCode = ZLtable.Rows[i]["BusinessCode"].ToString();
  2095. string Enable = ZLtable.Rows[i]["Enable"].ToString();
  2096. if (zlTransCode.Equals(BusinessCode))
  2097. {
  2098. if (Enable.Equals("True"))
  2099. {
  2100. ///更新日志
  2101. sql = @"
  2102. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and transtype='15')
  2103. BEGIN
  2104. RAISERROR('" + language.GetNameByCode("WMSAPIInfo472") + @"',16,1);
  2105. RETURN
  2106. END
  2107. UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE2='1' WHERE LotNo='{0}' AND WorkPoint='{1}' and transtype='15'
  2108. ";
  2109. sql = string.Format(sql, LotNo, WorkPoint, LogID);
  2110. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2111. {
  2112. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"占料标识更新失败!");
  2113. }
  2114. ///更新库存
  2115. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}',LockQuantity=ISNULL(LockQuantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  2116. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity-LockQuantity<0)
  2117. BEGIN
  2118. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  2119. RETURN
  2120. END";
  2121. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2122. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2123. {
  2124. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  2125. }
  2126. }
  2127. else
  2128. {
  2129. ///更新库存
  2130. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-ISNULL(LockQuantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  2131. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity-LockQuantity<0)
  2132. BEGIN
  2133. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  2134. RETURN
  2135. END";
  2136. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2137. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2138. {
  2139. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  2140. }
  2141. }
  2142. }
  2143. }
  2144. ///分批前添加日志
  2145. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2146. BEGIN
  2147. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2148. RETURN
  2149. END
  2150. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2151. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2152. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2153. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2154. MTIME,WorkPoint,EATTRIBUTE1)
  2155. SELECT NEWID(),'{3}','{7}','{8}',a.LotNo ,a.InvCode ,
  2156. c.WarehouseCode,c.LocationCode,'','',c.Quantity+{6},
  2157. '','0','{4}','31','0','',
  2158. '','','',f.F_Account ,f.F_RealName ,
  2159. SYSDATETIME() ,a.WorkPoint ,''
  2160. FROM ICSInventoryLot a
  2161. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2162. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2163. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2164. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2165. ";
  2166. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, TransCode, TransSequence);
  2167. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2168. {
  2169. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2170. }
  2171. #region 获取分批后的条码(lotstr)
  2172. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  2173. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  2174. sql = string.Format(sql, LotNo, WorkPoint);
  2175. dt = DBHelper.SQlReturnData(sql, cmd);
  2176. if (dt.Rows.Count == 0)
  2177. {
  2178. lotstr = LotNo + "-" + 1;
  2179. }
  2180. else
  2181. {
  2182. lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  2183. }
  2184. NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  2185. #endregion
  2186. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  2187. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  2188. Quantity,Amount,ExtensionID,Type,PrintTimes,
  2189. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  2190. WorkPoint,EATTRIBUTE1)
  2191. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  2192. '{2}',a.Amount/a.Quantity*Quantity,a.ExtensionID,a.Type,a.PrintTimes,
  2193. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  2194. a.WorkPoint ,'{1}'
  2195. From ICSInventoryLot a
  2196. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  2197. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  2198. cmd.CommandText = sql;
  2199. result = cmd.ExecuteNonQuery();
  2200. if (result <= 0)
  2201. {
  2202. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  2203. }
  2204. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2205. select NEWID(),'{0}',WarehouseCode,LocationCode,InvCode,'0',InDate,LockQuantity
  2206. ,MUSER,MUSERName,GETDATE(),'{3}',''
  2207. from ICSWareHouseLotInfo
  2208. where LotNO='{1}' AND WorkPoint='{3}'";
  2209. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  2210. cmd.CommandText = sql;
  2211. result = cmd.ExecuteNonQuery();
  2212. if (result <= 0)
  2213. {
  2214. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  2215. }
  2216. //插入条码单据表
  2217. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  2218. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  2219. FROM ICSInventoryLot a
  2220. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2221. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2222. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  2223. sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
  2224. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2225. {
  2226. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  2227. }
  2228. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2229. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2230. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2231. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2232. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  2233. SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
  2234. c.WarehouseCode,c.LocationCode,'','','{6}',
  2235. '','0','{7}','{8}','0','',
  2236. '','','',f.F_Account ,f.F_RealName ,
  2237. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  2238. FROM ICSInventoryLot a
  2239. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2240. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2241. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2242. ";
  2243. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr);
  2244. cmd.CommandText = sql;
  2245. result = cmd.ExecuteNonQuery();
  2246. if (result <= 0)
  2247. {
  2248. throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
  2249. }
  2250. if (PrintEnable.Equals("True") && DisPrintEnable.Equals("True"))
  2251. {
  2252. 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
  2253. from ICSWareHouseLotInfolog A
  2254. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  2255. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  2256. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  2257. where A.lotno ='{0}' and a.workpoint='{1}' and a.BusinessCode='{2}'
  2258. ";
  2259. sql = string.Format(sql, lotstr, WorkPoint, BusinessCode);
  2260. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  2261. lstDt = dtLotno;
  2262. }
  2263. ///添加日志
  2264. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2265. BEGIN
  2266. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2267. RETURN
  2268. END
  2269. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2270. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2271. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2272. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2273. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  2274. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  2275. c.WarehouseCode,c.LocationCode,'','',c.Quantity,
  2276. '','0','{7}','32','0','',
  2277. '','','',f.F_Account ,f.F_RealName ,
  2278. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  2279. FROM ICSInventoryLot a
  2280. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2281. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2282. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2283. ";
  2284. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  2285. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2286. {
  2287. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2288. }
  2289. #endregion
  2290. }
  2291. else
  2292. {
  2293. NewBarCodeList.Add(LotNo);
  2294. ///添加日志
  2295. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2296. BEGIN
  2297. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2298. RETURN
  2299. END
  2300. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2301. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2302. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2303. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2304. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  2305. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  2306. c.WarehouseCode,c.LocationCode,'','','{6}',
  2307. '','0','{7}','{8}','0','',
  2308. '','','',f.F_Account ,f.F_RealName ,
  2309. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  2310. FROM ICSInventoryLot a
  2311. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2312. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2313. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2314. ";
  2315. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  2316. log.Debug("出库增加日志:" + sql);
  2317. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2318. {
  2319. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2320. }
  2321. ZLtable = ICSControlModeService.GetZL();
  2322. if (ZLtable == null)
  2323. {
  2324. throw new Exception(language.GetNameByCode("WMSAPIInfo471"));
  2325. }
  2326. for (int i = 0; i < ZLtable.Rows.Count; i++)
  2327. {
  2328. string zlTransCode = ZLtable.Rows[i]["BusinessCode"].ToString();
  2329. string Enable = ZLtable.Rows[i]["Enable"].ToString();
  2330. if (zlTransCode.Equals(BusinessCode))
  2331. {
  2332. if (Enable.Equals("True"))
  2333. {
  2334. ///更新日志
  2335. sql = @"
  2336. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and transtype='15')
  2337. BEGIN
  2338. RAISERROR('" + language.GetNameByCode("WMSAPIInfo472") + @"',16,1);
  2339. RETURN
  2340. END
  2341. UPDATE ICSWareHouseLotInfoLog SET EATTRIBUTE2='1' WHERE LotNo='{0}' AND WorkPoint='{1}' and transtype='15'
  2342. ";
  2343. sql = string.Format(sql, LotNo, WorkPoint, LogID);
  2344. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2345. {
  2346. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"占料标识更新失败!");
  2347. }
  2348. ///更新库存
  2349. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}',LockQuantity=ISNULL(LockQuantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  2350. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity-LockQuantity<0)
  2351. BEGIN
  2352. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  2353. RETURN
  2354. END";
  2355. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2356. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2357. {
  2358. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  2359. }
  2360. }
  2361. else
  2362. {
  2363. ///更新库存
  2364. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  2365. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity-LockQuantity<0)
  2366. BEGIN
  2367. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  2368. RETURN
  2369. END";
  2370. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2371. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2372. {
  2373. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  2374. }
  2375. }
  2376. }
  2377. }
  2378. /////更新库存
  2379. //sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  2380. // IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  2381. // BEGIN
  2382. // RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  2383. // RETURN
  2384. // END";
  2385. //sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2386. //if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2387. //{
  2388. // throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  2389. //}
  2390. }
  2391. }
  2392. catch (Exception)
  2393. {
  2394. throw;
  2395. }
  2396. return lstDt;
  2397. }
  2398. /// <summary>
  2399. /// 无源头调拨
  2400. /// </summary>
  2401. /// <param name="LocationCode"></param>
  2402. /// <param name="LotNo"></param>
  2403. /// <param name="Quantity"></param>
  2404. /// <param name="User"></param>
  2405. /// <param name="WorkPoint"></param>
  2406. /// <param name="TransType"></param>
  2407. /// <param name="BusinessCode"></param>
  2408. /// <param name="cmd"></param>
  2409. public static DataTable WareHouseLotInfoNoTransfer(string Identification, string WarehouseCode, string LocationCode,
  2410. string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID)
  2411. {
  2412. decimal LotQTYYY = 0;
  2413. decimal LotQTY = 0;
  2414. String LotEnable = "";
  2415. String PrintEnable = "";
  2416. String ToWareHouseCode = "";
  2417. String ToLocationCode = "";
  2418. string lotstr = "";
  2419. int result = 0;
  2420. DataTable dtLotno = new DataTable();
  2421. DataTable lstDt = new DataTable();
  2422. List<string> NewBarCodeList = new List<string>();
  2423. try
  2424. {
  2425. //检验是否分批
  2426. string sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  2427. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  2428. where a.LotNo='{0}' and a.WorkPoint='{1}'
  2429. ";
  2430. sql = string.Format(sql, LotNo, WorkPoint);
  2431. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2432. if (dt.Rows.Count == 0)
  2433. {
  2434. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  2435. }
  2436. else
  2437. {
  2438. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  2439. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  2440. }
  2441. sql = @"select Quantity from ICSWareHouseLotInfo
  2442. where LotNO='{0}' AND WorkPoint='{1}'";
  2443. sql = string.Format(sql, LotNo, WorkPoint);
  2444. DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
  2445. LotQTYYY = Convert.ToDecimal(dtt.Rows[0]["Quantity"]);
  2446. LotQTY = Convert.ToDecimal(Quantity);
  2447. if (!LotEnable.Equals("False") && LotQTYYY - LotQTY > 0)
  2448. {
  2449. ///更新库存
  2450. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  2451. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  2452. BEGIN
  2453. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  2454. RETURN
  2455. END";
  2456. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2457. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2458. {
  2459. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  2460. }
  2461. ///分批前添加日志
  2462. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2463. BEGIN
  2464. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2465. RETURN
  2466. END
  2467. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2468. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2469. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2470. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2471. MTIME,WorkPoint,EATTRIBUTE1)
  2472. SELECT NEWID(),'{3}','','',a.LotNo ,a.InvCode ,
  2473. c.WarehouseCode,c.LocationCode,'','',c.Quantity+{6},
  2474. '','0','{4}','31','0','',
  2475. '','','',f.F_Account ,f.F_RealName ,
  2476. SYSDATETIME() ,a.WorkPoint ,''
  2477. FROM ICSInventoryLot a
  2478. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2479. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2480. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2481. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2482. ";
  2483. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity);
  2484. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2485. {
  2486. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2487. }
  2488. #region 获取分批后的条码(lotstr)
  2489. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  2490. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  2491. sql = string.Format(sql, LotNo, WorkPoint);
  2492. dt = DBHelper.SQlReturnData(sql, cmd);
  2493. if (dt.Rows.Count == 0)
  2494. {
  2495. lotstr = LotNo + "-" + 1;
  2496. }
  2497. else
  2498. {
  2499. lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  2500. }
  2501. NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  2502. #endregion
  2503. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  2504. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  2505. Quantity,Amount,ExtensionID,Type,PrintTimes,
  2506. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  2507. WorkPoint,EATTRIBUTE1)
  2508. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  2509. '{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes,
  2510. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  2511. a.WorkPoint ,'{1}'
  2512. From ICSInventoryLot a
  2513. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  2514. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  2515. cmd.CommandText = sql;
  2516. result = cmd.ExecuteNonQuery();
  2517. if (result <= 0)
  2518. {
  2519. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  2520. }
  2521. #endregion
  2522. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2523. select NEWID(),'{0}','{4}','{5}',InvCode,'{2}',InDate,LockQuantity
  2524. ,MUSER,MUSERName,GETDATE(),'{3}',''
  2525. from ICSWareHouseLotInfo
  2526. where LotNO='{1}' AND WorkPoint='{3}'";
  2527. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint, WarehouseCode, LocationCode);
  2528. cmd.CommandText = sql;
  2529. result = cmd.ExecuteNonQuery();
  2530. if (result <= 0)
  2531. {
  2532. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  2533. }
  2534. //插入条码单据表
  2535. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  2536. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  2537. FROM ICSInventoryLot a
  2538. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2539. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2540. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  2541. sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
  2542. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2543. {
  2544. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  2545. }
  2546. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2547. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2548. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2549. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2550. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  2551. SELECT NEWID(),'{3}','','','{8}' ,a.InvCode ,
  2552. c.WarehouseCode,c.LocationCode,'{9}','{10}','{4}',
  2553. '','0','{5}','{6}','0','',
  2554. '','','',f.F_Account ,f.F_RealName ,
  2555. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  2556. FROM ICSInventoryLot a
  2557. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2558. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2559. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2560. ";
  2561. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, Quantity, TransType, BusinessCode, MergeID, lotstr, WarehouseCode, LocationCode);
  2562. cmd.CommandText = sql;
  2563. result = cmd.ExecuteNonQuery();
  2564. if (result <= 0)
  2565. {
  2566. throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
  2567. }
  2568. ///添加日志
  2569. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2570. BEGIN
  2571. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2572. RETURN
  2573. END
  2574. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2575. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2576. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2577. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2578. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  2579. SELECT NEWID(),'{3}','','',a.LotNo ,a.InvCode ,
  2580. c.WarehouseCode,c.LocationCode,'','',c.Quantity,
  2581. '','0','{5}','32','0','',
  2582. '','','',f.F_Account ,f.F_RealName ,
  2583. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  2584. FROM ICSInventoryLot a
  2585. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2586. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2587. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2588. ";
  2589. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, Quantity, TransType, BusinessCode, MergeID);
  2590. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2591. {
  2592. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2593. }
  2594. if (PrintEnable.Equals("True"))
  2595. {
  2596. 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
  2597. from ICSWareHouseLotInfolog A
  2598. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  2599. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  2600. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  2601. where a.BusinessCode ='105'
  2602. and A.lotno like'{0}%' and a.workpoint='{1}'
  2603. ";
  2604. sql = string.Format(sql, LotNo, WorkPoint);
  2605. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  2606. lstDt = dtLotno;
  2607. }
  2608. }
  2609. else
  2610. {
  2611. ///添加日志
  2612. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2613. BEGIN
  2614. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2615. RETURN
  2616. END
  2617. IF EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE WarehouseCode='{7}' AND LocationCode='{8}' AND WorkPoint='{1}' AND LotNo = '{0}')
  2618. BEGIN
  2619. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo355")) + @"',16,1);
  2620. RETURN
  2621. END
  2622. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2623. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2624. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2625. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2626. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  2627. SELECT NEWID(),'{3}','','',a.LotNo ,a.InvCode ,
  2628. c.WarehouseCode,c.LocationCode,'{7}','{8}',{4},
  2629. '','0','{5}','{6}','0','',
  2630. '','','',f.F_Account ,f.F_RealName ,
  2631. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  2632. FROM ICSInventoryLot a
  2633. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2634. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2635. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2636. ";
  2637. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode, MergeID);
  2638. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2639. {
  2640. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2641. }
  2642. ///更新库存
  2643. sql = @"UPDATE ICSWareHouseLotInfo SET WareHouseCode='{2}',LocationCode='{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  2644. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  2645. BEGIN
  2646. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  2647. RETURN
  2648. END";
  2649. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode);
  2650. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2651. {
  2652. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  2653. }
  2654. }
  2655. }
  2656. catch (Exception)
  2657. {
  2658. throw;
  2659. }
  2660. return lstDt;
  2661. }
  2662. /// <summary>
  2663. /// 修改库存
  2664. /// </summary>
  2665. /// <param name="Identification"></param>
  2666. /// <param name="TransCode"></param>
  2667. /// <param name="TransSequence"></param>
  2668. /// <param name="LotNo"></param>
  2669. /// <param name="Quantity"></param>
  2670. /// <param name="User"></param>
  2671. /// <param name="WorkPoint"></param>
  2672. /// <param name="TransType"></param>
  2673. /// <param name="cmd"></param>
  2674. public static void WareHouseLotInfoUpdate(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
  2675. string WorkPoint, string TransType,string CheckKind, SqlCommand cmd, Dictionary<string, string> language)
  2676. {
  2677. try
  2678. {
  2679. ///添加日志
  2680. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2681. BEGIN
  2682. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2683. RETURN
  2684. END
  2685. IF EXISTS(SELECT id FROM ICSInventoryLot WHERE LotNo='{0}' AND Quantity<'{9}')
  2686. BEGIN
  2687. RAISERROR(' {0} !',16,1);
  2688. RETURN
  2689. END
  2690. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2691. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2692. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2693. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2694. MTIME,WorkPoint,EATTRIBUTE1)
  2695. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  2696. a.WarehouseCode,a.LocationCode,'','',a.Quantity,
  2697. '{8}','0','{6}','{7}','0','',
  2698. '','','',f.F_Account ,f.F_RealName ,
  2699. SYSDATETIME() ,a.WorkPoint ,''
  2700. FROM ICSWareHouseLotInfo a
  2701. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2702. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2703. ";
  2704. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, TransTypeEnum.LOTCheckBefore.GetDescription<DBValue>(), CheckKind, Quantity);
  2705. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2706. {
  2707. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2708. }
  2709. ///更新库存
  2710. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity='{2}',LockQuantity=LockQuantity-{2} WHERE LotNo='{0}' AND WorkPoint='{1}'";
  2711. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2712. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2713. {
  2714. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  2715. }
  2716. ///更新库存
  2717. sql = @"UPDATE ICSCheck SET Status='2' WHERE CHeckCode='{0}' AND WorkPoint='{1}'";
  2718. sql = string.Format(sql, TransCode, WorkPoint);
  2719. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2720. {
  2721. throw new Exception("盘点状态更新失败!");//"库存更新失败!");
  2722. }
  2723. ///添加日志
  2724. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2725. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2726. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2727. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2728. MTIME,WorkPoint,EATTRIBUTE1)
  2729. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  2730. a.WarehouseCode,a.LocationCode,'','',a.Quantity,
  2731. '{8}','0','{6}','{7}','0','',
  2732. '','','',f.F_Account ,f.F_RealName ,
  2733. SYSDATETIME() ,a.WorkPoint ,''
  2734. FROM ICSWareHouseLotInfo a
  2735. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2736. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2737. ";
  2738. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, TransTypeEnum.LOTCheckAfter.GetDescription<DBValue>(), CheckKind);
  2739. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2740. {
  2741. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2742. }
  2743. }
  2744. catch (Exception)
  2745. {
  2746. throw;
  2747. }
  2748. }
  2749. /// <summary>
  2750. /// 调拨
  2751. /// </summary>
  2752. /// <param name="LocationCode"></param>
  2753. /// <param name="LotNo"></param>
  2754. /// <param name="Quantity"></param>
  2755. /// <param name="User"></param>
  2756. /// <param name="WorkPoint"></param>
  2757. /// <param name="TransType"></param>
  2758. /// <param name="BusinessCode"></param>
  2759. /// <param name="cmd"></param>
  2760. public static DataTable WareHouseLotInfoTransfer(string Identification, string TransCode, string TransSequence, string WarehouseCode, string LocationCode,
  2761. string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID)
  2762. {
  2763. decimal LotQTYYY = 0;
  2764. decimal LotQTY = 0;
  2765. String LotEnable = "";
  2766. String PrintEnable = "";
  2767. string lotstr = "";
  2768. int result = 0;
  2769. DataTable dtLotno = new DataTable();
  2770. DataTable lstDt = new DataTable();
  2771. List<string> NewBarCodeList = new List<string>();
  2772. try
  2773. {
  2774. //检验是否分批
  2775. string sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  2776. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  2777. where a.LotNo='{0}' and a.WorkPoint='{1}'
  2778. ";
  2779. sql = string.Format(sql, LotNo, WorkPoint);
  2780. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2781. if (dt.Rows.Count == 0)
  2782. {
  2783. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  2784. }
  2785. else
  2786. {
  2787. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  2788. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  2789. }
  2790. sql = @"select Quantity from ICSWareHouseLotInfo
  2791. where LotNO='{0}' AND WorkPoint='{1}'";
  2792. sql = string.Format(sql, LotNo, WorkPoint);
  2793. DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
  2794. LotQTYYY = Convert.ToDecimal(dtt.Rows[0]["Quantity"]);
  2795. LotQTY = Convert.ToDecimal(Quantity);
  2796. if (!LotEnable.Equals("False") && LotQTYYY - LotQTY > 0)//增加数量判断
  2797. {
  2798. ///更新库存
  2799. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  2800. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  2801. BEGIN
  2802. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  2803. RETURN
  2804. END";
  2805. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2806. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2807. {
  2808. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  2809. }
  2810. ///分批前添加日志
  2811. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2812. BEGIN
  2813. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2814. RETURN
  2815. END
  2816. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2817. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2818. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2819. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2820. MTIME,WorkPoint,EATTRIBUTE1)
  2821. SELECT NEWID(),'{3}','{7}','{8}',a.LotNo ,a.InvCode ,
  2822. c.WarehouseCode,c.LocationCode,'','',c.Quantity+{6},
  2823. '','0','{4}','31','0','',
  2824. '','','',f.F_Account ,f.F_RealName ,
  2825. SYSDATETIME() ,a.WorkPoint ,''
  2826. FROM ICSInventoryLot a
  2827. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2828. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2829. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2830. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2831. ";
  2832. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, TransCode, TransSequence);
  2833. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2834. {
  2835. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2836. }
  2837. #region 获取分批后的条码(lotstr)
  2838. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  2839. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  2840. sql = string.Format(sql, LotNo, WorkPoint);
  2841. dt = DBHelper.SQlReturnData(sql, cmd);
  2842. if (dt.Rows.Count == 0)
  2843. {
  2844. lotstr = LotNo + "-" + 1;
  2845. }
  2846. else
  2847. {
  2848. lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  2849. }
  2850. NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  2851. #endregion
  2852. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  2853. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  2854. Quantity,Amount,ExtensionID,Type,PrintTimes,
  2855. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  2856. WorkPoint,EATTRIBUTE1)
  2857. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  2858. '{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes,
  2859. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  2860. a.WorkPoint ,'{1}'
  2861. From ICSInventoryLot a
  2862. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  2863. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  2864. cmd.CommandText = sql;
  2865. result = cmd.ExecuteNonQuery();
  2866. if (result <= 0)
  2867. {
  2868. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  2869. }
  2870. #endregion
  2871. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2872. select NEWID(),'{0}','{4}','{5}',InvCode,'{2}',InDate,LockQuantity
  2873. ,MUSER,MUSERName,GETDATE(),'{3}',''
  2874. from ICSWareHouseLotInfo
  2875. where LotNO='{1}' AND WorkPoint='{3}'";
  2876. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint,WarehouseCode,LocationCode);
  2877. cmd.CommandText = sql;
  2878. result = cmd.ExecuteNonQuery();
  2879. if (result <= 0)
  2880. {
  2881. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  2882. }
  2883. //插入条码单据表
  2884. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  2885. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  2886. FROM ICSInventoryLot a
  2887. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2888. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2889. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  2890. sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
  2891. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2892. {
  2893. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  2894. }
  2895. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2896. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2897. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2898. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2899. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  2900. SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
  2901. c.WarehouseCode,c.LocationCode,'{11}','{12}','{6}',
  2902. '','0','{7}','{8}','0','',
  2903. '','','',f.F_Account ,f.F_RealName ,
  2904. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  2905. FROM ICSInventoryLot a
  2906. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2907. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2908. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2909. ";
  2910. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr, WarehouseCode, LocationCode);
  2911. cmd.CommandText = sql;
  2912. result = cmd.ExecuteNonQuery();
  2913. if (result <= 0)
  2914. {
  2915. throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
  2916. }
  2917. ///添加日志
  2918. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2919. BEGIN
  2920. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2921. RETURN
  2922. END
  2923. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2924. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2925. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2926. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2927. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  2928. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  2929. c.WarehouseCode,c.LocationCode,'','',c.Quantity,
  2930. '','0','{7}','32','0','',
  2931. '','','',f.F_Account ,f.F_RealName ,
  2932. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  2933. FROM ICSInventoryLot a
  2934. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2935. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2936. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2937. ";
  2938. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  2939. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2940. {
  2941. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2942. }
  2943. if (PrintEnable.Equals("True"))
  2944. {
  2945. 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
  2946. from ICSWareHouseLotInfolog A
  2947. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  2948. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  2949. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  2950. where A.lotno ='{0}' and a.workpoint='{1}' and a.BusinessCode='{2}'
  2951. ";
  2952. sql = string.Format(sql, lotstr, WorkPoint, BusinessCode);
  2953. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  2954. lstDt = dtLotno;
  2955. }
  2956. }
  2957. else
  2958. {
  2959. ///添加日志
  2960. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2961. BEGIN
  2962. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2963. RETURN
  2964. END
  2965. IF EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE WarehouseCode='{9}' AND LocationCode='{10}' AND WorkPoint='{1}' AND LotNo = '{0}')
  2966. BEGIN
  2967. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo355")) + @"',16,1);
  2968. RETURN
  2969. END
  2970. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  2971. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  2972. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  2973. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  2974. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  2975. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  2976. c.WarehouseCode,c.LocationCode,'{9}','{10}',{6},
  2977. '','0','{7}','{8}','0','',
  2978. '','','',f.F_Account ,f.F_RealName ,
  2979. SYSDATETIME() ,a.WorkPoint ,'','{11}'
  2980. FROM ICSInventoryLot a
  2981. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  2982. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2983. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2984. ";
  2985. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode, MergeID);
  2986. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2987. {
  2988. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  2989. }
  2990. ///更新库存
  2991. sql = @"UPDATE ICSWareHouseLotInfo SET WareHouseCode='{2}',LocationCode='{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  2992. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  2993. BEGIN
  2994. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  2995. RETURN
  2996. END";
  2997. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode);
  2998. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2999. {
  3000. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  3001. }
  3002. }
  3003. DateTime now = DateTime.Now;
  3004. sql = @"select 1 from ICSContainerLot
  3005. where LotNo='{0}' and WorkPoint='{1}'
  3006. ";
  3007. sql = string.Format(sql, LotNo, WorkPoint);
  3008. log.Debug("查询容器条码关联表是否存在");
  3009. DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
  3010. if (dttte.Rows.Count > 0)
  3011. {
  3012. ///删除条码关联表数据
  3013. sql = @"DELETE FROM ICSContainerLot
  3014. where LotNo='{0}' and WorkPoint='{1}'
  3015. ";
  3016. sql = string.Format(sql, LotNo, WorkPoint);
  3017. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3018. {
  3019. throw new Exception(language.GetNameByCode("容器条码关联表数据删除失败"));
  3020. }
  3021. }
  3022. }
  3023. catch (Exception)
  3024. {
  3025. throw;
  3026. }
  3027. return lstDt;
  3028. }
  3029. /// <summary>
  3030. /// 移库
  3031. /// </summary>
  3032. /// <param name="LocationCode"></param>
  3033. /// <param name="LotNo"></param>
  3034. /// <param name="Quantity"></param>
  3035. /// <param name="User"></param>
  3036. /// <param name="WorkPoint"></param>
  3037. /// <param name="TransType"></param>
  3038. /// <param name="BusinessCode"></param>
  3039. /// <param name="cmd"></param>
  3040. public static void WareHouseLotInfoLibrary(string Identification, string TransCode, string TransSequence, string WarehouseCode, string LocationCode,
  3041. string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  3042. {
  3043. try
  3044. {
  3045. string sql = @"SELECT WarehouseCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  3046. sql = string.Format(sql, LotNo,WorkPoint);
  3047. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  3048. if (dt == null || dt.Rows.Count <= 0)
  3049. {
  3050. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
  3051. }
  3052. string whcode = dt.Rows[0]["WarehouseCode"].ToString();
  3053. ///添加日志
  3054. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  3055. BEGIN
  3056. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3057. RETURN
  3058. END
  3059. IF('" + whcode + @"' != '{8}')
  3060. BEGIN
  3061. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo394"), "{8}", whcode) + @"', 16, 1);
  3062. RETURN
  3063. END
  3064. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  3065. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  3066. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  3067. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  3068. MTIME,WorkPoint,EATTRIBUTE1 )
  3069. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  3070. c.WarehouseCode,c.LocationCode,'{8}','{9}',c.Quantity,
  3071. '','0','{6}','{7}','0','',
  3072. '','','',f.F_Account ,f.F_RealName ,
  3073. SYSDATETIME() ,a.WorkPoint ,''
  3074. FROM ICSInventoryLot a
  3075. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  3076. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3077. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  3078. ";
  3079. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, BusinessCode, WarehouseCode, LocationCode);
  3080. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3081. {
  3082. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  3083. }
  3084. ///添加库存
  3085. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity>0)
  3086. BEGIN
  3087. RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
  3088. RETURN
  3089. END
  3090. IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.WarehouseCode='{2}')
  3091. BEGIN
  3092. RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
  3093. RETURN
  3094. END
  3095. UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  3096. ";
  3097. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode);
  3098. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3099. {
  3100. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
  3101. }
  3102. DateTime now = DateTime.Now;
  3103. sql = @"select 1 from ICSContainerLot
  3104. where LotNo='{0}' and WorkPoint='{1}'
  3105. ";
  3106. sql = string.Format(sql, LotNo, WorkPoint);
  3107. log.Debug("查询容器条码关联表是否存在");
  3108. DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
  3109. if (dttte.Rows.Count > 0)
  3110. {
  3111. ///删除条码关联表数据
  3112. sql = @"DELETE FROM ICSContainerLot
  3113. where LotNo='{0}' and WorkPoint='{1}'
  3114. ";
  3115. sql = string.Format(sql, LotNo, WorkPoint);
  3116. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3117. {
  3118. throw new Exception(language.GetNameByCode("容器条码关联表数据删除失败"));
  3119. }
  3120. }
  3121. }
  3122. catch (Exception)
  3123. {
  3124. throw;
  3125. }
  3126. }
  3127. /// <summary>
  3128. /// 两步调入
  3129. /// </summary>
  3130. /// <param name="LocationCode"></param>
  3131. /// <param name="LotNo"></param>
  3132. /// <param name="Quantity"></param>
  3133. /// <param name="User"></param>
  3134. /// <param name="WorkPoint"></param>
  3135. /// <param name="TransType"></param>
  3136. /// <param name="BusinessCode"></param>
  3137. /// <param name="cmd"></param>
  3138. public static void WareHouseLotInfoTwoStepTransferDocIn(string Identification, string TransCode, string TransSequence, string WarehouseCode,
  3139. string LocationCode, string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  3140. {
  3141. try
  3142. {
  3143. ///添加日志
  3144. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  3145. BEGIN
  3146. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3147. RETURN
  3148. END
  3149. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  3150. ToWarehouseCode,ToLocationCode,Quantity,
  3151. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  3152. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  3153. MTIME,WorkPoint,EATTRIBUTE1)
  3154. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  3155. '{9}','{10}','{6}',
  3156. '','0','{7}','{8}','0','',
  3157. '','','',f.F_Account ,f.F_RealName ,
  3158. SYSDATETIME() ,a.WorkPoint ,''
  3159. FROM ICSInventoryLot a
  3160. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  3161. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3162. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  3163. ";
  3164. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode);
  3165. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3166. {
  3167. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  3168. }
  3169. ///添加库存
  3170. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  3171. BEGIN
  3172. RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
  3173. RETURN
  3174. END
  3175. UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}',Quantity=Quantity+'{4}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  3176. ";
  3177. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode, Quantity);
  3178. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3179. {
  3180. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
  3181. }
  3182. }
  3183. catch (Exception)
  3184. {
  3185. throw;
  3186. }
  3187. }
  3188. /// <summary>
  3189. /// 合并日志
  3190. /// </summary>
  3191. /// <param name="Identification"></param>
  3192. /// <param name="LotNo"></param>
  3193. /// <param name="User"></param>
  3194. /// <param name="WorkPoint"></param>
  3195. /// <param name="TransType"></param>
  3196. /// <param name="BusinessCode"></param>
  3197. /// <param name="cmd"></param>
  3198. public static DataTable WareHouseLotInfoLogMerge(string Identification, string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, string newLotno, SqlCommand cmd, Dictionary<string, string> language)
  3199. {
  3200. String LotEnable = "";
  3201. String PrintEnable = "";
  3202. DataTable dtLotno = new DataTable();
  3203. DataTable lstDt = new DataTable();
  3204. try
  3205. {
  3206. //检验是否分批
  3207. string sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  3208. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  3209. where a.LotNo='{0}' and a.WorkPoint='{1}'
  3210. ";
  3211. sql = string.Format(sql, LotNo, WorkPoint);
  3212. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  3213. if (dt.Rows.Count == 0)
  3214. {
  3215. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  3216. }
  3217. else
  3218. {
  3219. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  3220. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  3221. }
  3222. ///添加日志
  3223. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  3224. BEGIN
  3225. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3226. RETURN
  3227. END
  3228. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  3229. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  3230. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  3231. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  3232. MTIME,WorkPoint,EATTRIBUTE1)
  3233. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  3234. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  3235. '','0','{4}','{5}','0','',
  3236. '','','',f.F_Account ,f.F_RealName ,
  3237. SYSDATETIME() ,a.WorkPoint ,''
  3238. FROM ICSInventoryLot a
  3239. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3240. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  3241. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3242. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  3243. ";
  3244. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  3245. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3246. {
  3247. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  3248. }
  3249. if (PrintEnable.Equals("True"))
  3250. {
  3251. sql = @"select A.LotNO , B.Quantity AS OLDLotQty, C.Quantity AS LotQty ,b.InvCode,d.INVSTD,d.INVNAME,b.MTIME,A.TransCode
  3252. from ICSWareHouseLotInfolog A
  3253. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  3254. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  3255. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  3256. where a.BusinessCode='34'
  3257. and A.lotno = '{0}' and a.workpoint='{1}'
  3258. ";
  3259. sql = string.Format(sql, LotNo, WorkPoint, BusinessCode, newLotno);
  3260. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  3261. lstDt = dtLotno;
  3262. }
  3263. }
  3264. catch (Exception)
  3265. {
  3266. throw;
  3267. }
  3268. return lstDt;
  3269. }
  3270. /// <summary>
  3271. /// 拆分、合并日志
  3272. /// </summary>
  3273. /// <param name="Identification"></param>
  3274. /// <param name="LotNo"></param>
  3275. /// <param name="User"></param>
  3276. /// <param name="WorkPoint"></param>
  3277. /// <param name="TransType"></param>
  3278. /// <param name="BusinessCode"></param>
  3279. /// <param name="cmd"></param>
  3280. public static DataTable WareHouseLotInfoLog(string Identification, string LotNo, string User, string WorkPoint, string TransType, string BusinessCode,string newLotno, SqlCommand cmd, Dictionary<string, string> language)
  3281. {
  3282. String LotEnable = "";
  3283. String PrintEnable = "";
  3284. DataTable dtLotno = new DataTable();
  3285. DataTable lstDt = new DataTable();
  3286. try{
  3287. //检验是否分批
  3288. string sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  3289. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  3290. where a.LotNo='{0}' and a.WorkPoint='{1}'
  3291. ";
  3292. sql = string.Format(sql, LotNo, WorkPoint);
  3293. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  3294. if (dt.Rows.Count == 0)
  3295. {
  3296. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  3297. }
  3298. else
  3299. {
  3300. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  3301. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  3302. }
  3303. ///添加日志
  3304. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  3305. BEGIN
  3306. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3307. RETURN
  3308. END
  3309. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  3310. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  3311. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  3312. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  3313. MTIME,WorkPoint,EATTRIBUTE1)
  3314. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  3315. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  3316. '','0','{4}','{5}','0','',
  3317. '','','',f.F_Account ,f.F_RealName ,
  3318. SYSDATETIME() ,a.WorkPoint ,''
  3319. FROM ICSInventoryLot a
  3320. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3321. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  3322. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3323. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  3324. ";
  3325. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  3326. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3327. {
  3328. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  3329. }
  3330. if (PrintEnable.Equals("True"))
  3331. {
  3332. sql = @"select A.LotNO , C.Quantity AS OLDLotQty, B.Quantity AS LotQty ,b.InvCode,d.INVSTD,d.INVNAME,b.MTIME,A.TransCode,c.LocationCode,f.BatchCode
  3333. from ICSWareHouseLotInfolog A
  3334. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  3335. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  3336. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  3337. left JOIN ICSExtension f on b.ExtensionID=f.id and b.WorkPoint=f.WorkPoint
  3338. where a.BusinessCode='32'
  3339. and A.lotno = '{3}' and a.workpoint='{1}'
  3340. ";
  3341. sql = string.Format(sql, LotNo, WorkPoint, BusinessCode,newLotno);
  3342. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  3343. lstDt = dtLotno;
  3344. }
  3345. }
  3346. catch (Exception)
  3347. {
  3348. throw;
  3349. }
  3350. return lstDt;
  3351. }
  3352. /// <summary>
  3353. /// 合并
  3354. /// </summary>
  3355. /// <param name="Identification"></param>
  3356. /// <param name="LotNo"></param>
  3357. /// <param name="User"></param>
  3358. /// <param name="WorkPoint"></param>
  3359. /// <param name="TransType"></param>
  3360. /// <param name="BusinessCode"></param>
  3361. /// <param name="cmd"></param>
  3362. public static void WareHouseLotInfoMerge(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
  3363. string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  3364. {
  3365. try
  3366. {
  3367. ///更新目标条码库存
  3368. string sql = @"IF NOT EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  3369. INNER JOIN ICSInventoryLot b ON b.LotNo='{3}' AND a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  3370. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  3371. BEGIN
  3372. RAISERROR('" + language.GetNameByCode("WMSAPIInfo170") + @"',16,1);
  3373. RETURN
  3374. END
  3375. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  3376. BEGIN
  3377. RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
  3378. RETURN
  3379. END
  3380. IF EXISTS(
  3381. SELECT * FROM ICSWareHouseLotInfo a
  3382. INNER JOIN ICSInventoryLot c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  3383. INNER JOIN ICSInventory d on c.invcode=d.invcode and c.WorkPoint=d.WorkPoint
  3384. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and d.BatchEnable='1'
  3385. )
  3386. BEGIN
  3387. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a
  3388. INNER JOIN ICSWareHouseLotInfo b ON b.LotNo='{3}' AND a.WarehouseCode=b.WarehouseCode AND a.WorkPoint=b.WorkPoint
  3389. INNER JOIN ICSInventoryLot c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  3390. INNER JOIN ICSInventoryLot d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint
  3391. INNER JOIN ICSExtension e on c.ExtensionID=e.ID and c.WorkPoint=e.WorkPoint
  3392. INNER JOIN ICSExtension f on d.ExtensionID=f.id and d.WorkPoint=f.WorkPoint
  3393. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and e.ID=f.ID)
  3394. BEGIN
  3395. RAISERROR('/',16,1);
  3396. RETURN
  3397. END
  3398. END
  3399. IF NOT EXISTS(
  3400. SELECT * FROM ICSWareHouseLotInfo a
  3401. INNER JOIN ICSInventoryLot c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  3402. INNER JOIN ICSInventory d on c.invcode=d.invcode and c.WorkPoint=d.WorkPoint
  3403. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and d.BatchEnable='1'
  3404. )
  3405. BEGIN
  3406. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a
  3407. INNER JOIN ICSWareHouseLotInfo b ON b.LotNo='{3}' AND a.WarehouseCode=b.WarehouseCode AND a.WorkPoint=b.WorkPoint
  3408. INNER JOIN ICSInventoryLot c on a.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  3409. INNER JOIN ICSInventoryLot d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint
  3410. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  3411. BEGIN
  3412. RAISERROR('/',16,1);
  3413. RETURN
  3414. END
  3415. END
  3416. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  3417. ";
  3418. //UPDATE ICSInventoryLot SET Amount=(ISNULL(Amount,0)+(select Amount from
  3419. //ICSInventoryLot where LotNo='{3}' AND WorkPoint='{1}')) WHERE LotNo='{0}' AND WorkPoint='{1}'
  3420. sql = string.Format(sql, LotNo, WorkPoint, Quantity, CurrentLotNo);
  3421. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3422. {
  3423. throw new Exception(language.GetNameByCode("WMSAPIInfo169"));//"目标条码库存更新失败!");
  3424. }
  3425. ///更新原条码库存
  3426. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  3427. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  3428. BEGIN
  3429. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  3430. RETURN
  3431. END";
  3432. //UPDATE ICSInventoryLot SET Amount=(ISNULL(Amount,0)-(select Amount from
  3433. //ICSInventoryLot where LotNo='{0}' AND WorkPoint='{1}')) WHERE LotNo='{0}' AND WorkPoint='{1}'
  3434. sql = string.Format(sql, CurrentLotNo, WorkPoint, Quantity);
  3435. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3436. {
  3437. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  3438. }
  3439. ///添加日志
  3440. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  3441. BEGIN
  3442. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3443. RETURN
  3444. END
  3445. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  3446. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  3447. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  3448. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  3449. MTIME,WorkPoint,EATTRIBUTE1)
  3450. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  3451. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  3452. '','0','{4}','{5}','0','',
  3453. '','','',f.F_Account ,f.F_RealName ,
  3454. SYSDATETIME() ,a.WorkPoint ,''
  3455. FROM ICSInventoryLot a
  3456. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3457. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  3458. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3459. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  3460. ";
  3461. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  3462. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3463. {
  3464. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  3465. }
  3466. }
  3467. catch (Exception)
  3468. {
  3469. throw;
  3470. }
  3471. }
  3472. /// <summary>
  3473. /// 拆分
  3474. /// </summary>
  3475. /// <param name="Identification"></param>
  3476. /// <param name="LotNo"></param>
  3477. /// <param name="User"></param>
  3478. /// <param name="WorkPoint"></param>
  3479. /// <param name="TransType"></param>
  3480. /// <param name="BusinessCode"></param>
  3481. /// <param name="cmd"></param>
  3482. public static void WareHouseLotInfoSplit(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
  3483. string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  3484. {
  3485. try
  3486. {
  3487. ///更新库存
  3488. string sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  3489. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  3490. BEGIN
  3491. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  3492. RETURN
  3493. END";
  3494. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  3495. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3496. {
  3497. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  3498. }
  3499. #region 添加库存
  3500. //插入条码表
  3501. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  3502. BEGIN
  3503. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3504. RETURN
  3505. END
  3506. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a WHERE a.LotNo='{4}' AND a.WorkPoint='{1}')
  3507. BEGIN
  3508. RAISERROR('" + language.GetNameByCode("WMSAPIInfo172") + @"',16,1);
  3509. RETURN
  3510. END
  3511. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,Amount,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  3512. SELECT NEWID(),'{4}' ,a.InvCode,a.ProductDate,a.ExpirationDate ,'{3}',a.Amount/a.Quantity*{3},a.ExtensionID,'101',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,a.LotNo
  3513. FROM ICSInventoryLot a
  3514. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3515. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  3516. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, CurrentLotNo);
  3517. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3518. {
  3519. throw new Exception(language.GetNameByCode("WMSAPIInfo173"));//"条码表写入失败!");
  3520. }
  3521. //插入条码单据表
  3522. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  3523. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  3524. FROM ICSInventoryLot a
  3525. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3526. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3527. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  3528. sql = string.Format(sql, LotNo, WorkPoint, User, CurrentLotNo);
  3529. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3530. {
  3531. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  3532. }
  3533. ///添加库存
  3534. sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  3535. BEGIN
  3536. RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
  3537. RETURN
  3538. END
  3539. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  3540. SELECT NEWID(),a.LotNo ,d.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  3541. FROM ICSInventoryLot a
  3542. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3543. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
  3544. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3545. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  3546. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Quantity);
  3547. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3548. {
  3549. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  3550. }
  3551. ///添加日志
  3552. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  3553. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  3554. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  3555. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  3556. MTIME,WorkPoint,EATTRIBUTE1)
  3557. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  3558. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  3559. '','0','{4}','{5}','0','',
  3560. '','','',f.F_Account ,f.F_RealName ,
  3561. SYSDATETIME() ,a.WorkPoint ,''
  3562. FROM ICSInventoryLot a
  3563. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3564. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  3565. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3566. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  3567. ";
  3568. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  3569. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3570. {
  3571. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  3572. }
  3573. #endregion
  3574. }
  3575. catch (Exception)
  3576. {
  3577. throw;
  3578. }
  3579. }
  3580. /// <summary>
  3581. /// 拆分(奥美)
  3582. /// </summary>
  3583. /// <param name="Identification"></param>
  3584. /// <param name="LotNo"></param>
  3585. /// <param name="User"></param>
  3586. /// <param name="WorkPoint"></param>
  3587. /// <param name="TransType"></param>
  3588. /// <param name="BusinessCode"></param>
  3589. /// <param name="cmd"></param>
  3590. public static void AMWareHouseLotInfoSplit(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
  3591. string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  3592. {
  3593. try
  3594. {
  3595. string amount = "";
  3596. //string sqql = @"select a.Amount FROM ICSInventoryLot a
  3597. // WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  3598. //sqql = string.Format(sqql, LotNo, WorkPoint);
  3599. //DataTable dtaa = DBHelper.SQlReturnData(sqql, cmd);
  3600. //amount = dtaa.Rows[0]["Amount"].ToString();
  3601. string cheksql = @"select d.EATTRIBUTE1 FROM ICSInventoryLot a
  3602. INNER JOIN ICSWareHouseLotInfo b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3603. INNER JOIN ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  3604. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and d.AmountEnable='1'";
  3605. cheksql = string.Format(cheksql, LotNo, WorkPoint);
  3606. DataTable dta = DBHelper.SQlReturnData(cheksql, cmd);
  3607. if (dta.Rows.Count > 0)
  3608. {
  3609. Quantity = (decimal.Parse(Quantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  3610. }
  3611. ///更新库存
  3612. string sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  3613. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  3614. BEGIN
  3615. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  3616. RETURN
  3617. END";
  3618. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  3619. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3620. {
  3621. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  3622. }
  3623. #region 添加库存
  3624. //插入条码表
  3625. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  3626. BEGIN
  3627. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3628. RETURN
  3629. END
  3630. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a WHERE a.LotNo='{4}' AND a.WorkPoint='{1}')
  3631. BEGIN
  3632. RAISERROR('" + language.GetNameByCode("WMSAPIInfo172") + @"',16,1);
  3633. RETURN
  3634. END
  3635. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,Amount,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  3636. SELECT NEWID(),'{4}' ,a.InvCode,a.ProductDate,a.ExpirationDate ,'{3}',a.Amount/a.Quantity*{3},a.ExtensionID,'101',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,a.LotNo
  3637. FROM ICSInventoryLot a
  3638. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3639. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  3640. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, CurrentLotNo);
  3641. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3642. {
  3643. throw new Exception(language.GetNameByCode("WMSAPIInfo173"));//"条码表写入失败!");
  3644. }
  3645. //插入条码单据表
  3646. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  3647. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  3648. FROM ICSInventoryLot a
  3649. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3650. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3651. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  3652. sql = string.Format(sql, LotNo, WorkPoint, User, CurrentLotNo);
  3653. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3654. {
  3655. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  3656. }
  3657. ///添加库存
  3658. sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  3659. BEGIN
  3660. RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
  3661. RETURN
  3662. END
  3663. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  3664. SELECT NEWID(),a.LotNo ,d.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  3665. FROM ICSInventoryLot a
  3666. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3667. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
  3668. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3669. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  3670. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Quantity);
  3671. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3672. {
  3673. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  3674. }
  3675. ///添加日志
  3676. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  3677. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  3678. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  3679. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  3680. MTIME,WorkPoint,EATTRIBUTE1)
  3681. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  3682. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  3683. '','0','{4}','{5}','0','',
  3684. '','','',f.F_Account ,f.F_RealName ,
  3685. SYSDATETIME() ,a.WorkPoint ,''
  3686. FROM ICSInventoryLot a
  3687. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3688. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  3689. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3690. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  3691. ";
  3692. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  3693. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3694. {
  3695. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  3696. }
  3697. #endregion
  3698. }
  3699. catch (Exception)
  3700. {
  3701. throw;
  3702. }
  3703. }
  3704. /// <summary>
  3705. /// 回写ERP ID
  3706. /// </summary>
  3707. /// <param name="TransType"></param>
  3708. /// <param name="SourceDetailID"></param>
  3709. /// <param name="Identification"></param>
  3710. /// <param name="ID"></param>
  3711. /// <param name="DetailID"></param>
  3712. /// <param name="Code"></param>
  3713. /// <param name="Sequence"></param>
  3714. /// <param name="cmd"></param>
  3715. public static void WareHouseLotInfoLogUpdate(string TransType, string SourceDetailID, string Identification, string ID, string DetailID, string Code, string Sequence, string col, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  3716. {
  3717. string ERPupdate = string.Empty;
  3718. string NewERPupdate = string.Empty;
  3719. try
  3720. {
  3721. //采购入库
  3722. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  3723. {
  3724. ERPupdate = @"SELECT a.id
  3725. INTO #NewTempERP
  3726. FROM ICSWareHouseLotInfoLog a
  3727. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3728. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3729. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3730. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3731. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3732. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3733. WHERE c.PODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3734. and (ISNULL(a.towarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3735. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3736. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3737. where ID in (select id from #NewTempERP)
  3738. DROP TABLE #NewTempERP";
  3739. }
  3740. //审核的到货单
  3741. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  3742. {
  3743. ERPupdate = @"SELECT a.id
  3744. INTO #NewTempERP
  3745. FROM ICSWareHouseLotInfoLog a
  3746. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3747. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3748. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3749. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3750. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3751. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3752. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3753. and (ISNULL(a.towarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3754. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3755. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3756. where ID in (select id from #NewTempERP)
  3757. DROP TABLE #NewTempERP
  3758. ";
  3759. }
  3760. //采购拒收
  3761. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  3762. {
  3763. ERPupdate = @"SELECT a.id
  3764. INTO #NewTempERP
  3765. FROM ICSWareHouseLotInfoLog a
  3766. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3767. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3768. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3769. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3770. where ID in (select id from #NewTempERP)
  3771. DROP TABLE #NewTempERP
  3772. ";
  3773. }
  3774. //审核的委外到货单
  3775. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  3776. {
  3777. ERPupdate = @"SELECT a.id
  3778. INTO #NewTempERP
  3779. FROM ICSWareHouseLotInfoLog a
  3780. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3781. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3782. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3783. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3784. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3785. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3786. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3787. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3788. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3789. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3790. where ID in (select id from #NewTempERP)
  3791. DROP TABLE #NewTempERP
  3792. ";
  3793. }
  3794. //委外拒收
  3795. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  3796. {
  3797. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3798. FROM ICSWareHouseLotInfoLog a
  3799. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3800. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3801. ";
  3802. }
  3803. //采购退货
  3804. else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  3805. {
  3806. ERPupdate = @"SELECT a.id
  3807. INTO #NewTempERP
  3808. FROM ICSWareHouseLotInfoLog a
  3809. INNER JOIN ICSDeliveryNotice c ON a.TransCode=c.DNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3810. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3811. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3812. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3813. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3814. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DNType='2' AND a.BusinessCode ='{7}'
  3815. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3816. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3817. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3818. where ID in (select id from #NewTempERP)
  3819. DROP TABLE #NewTempERP
  3820. ";
  3821. }
  3822. //委外发料
  3823. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  3824. {
  3825. ERPupdate = @"SELECT a.id
  3826. INTO #NewTempERP
  3827. FROM ICSWareHouseLotInfoLog a
  3828. INNER JOIN ICSOutsourcingOrder y ON a.TransCode=y.OOCode AND a.WorkPoint=y.WorkPoint
  3829. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  3830. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3831. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3832. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3833. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3834. WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3835. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3836. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3837. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3838. where ID in (select id from #NewTempERP)
  3839. DROP TABLE #NewTempERP
  3840. ";
  3841. }
  3842. //委外退料
  3843. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  3844. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  3845. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  3846. {
  3847. ERPupdate = @"--根据退料单退料
  3848. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3849. FROM ICSWareHouseLotInfoLog a
  3850. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3851. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  3852. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  3853. Left JOIN ICSOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  3854. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3855. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3856. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3857. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3858. WHERE ISNULL(m.ApplyDetailID,ISNULL(m.PickID, c.SourceDetailID))='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3859. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3860. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3861. --退-
  3862. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3863. FROM ICSWareHouseLotInfoLog a
  3864. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  3865. INNER JOIN ICSOutsourcingOrder y ON b.TransCode=y.OOCode AND b.WorkPoint=y.WorkPoint
  3866. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  3867. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3868. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3869. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3870. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3871. WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  3872. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3873. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3874. --退-
  3875. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3876. FROM ICSWareHouseLotInfoLog a
  3877. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  3878. INNER JOIN ICSOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  3879. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3880. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3881. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3882. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3883. WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  3884. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3885. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3886. --退-
  3887. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3888. FROM ICSWareHouseLotInfoLog a
  3889. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  3890. INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  3891. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  3892. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  3893. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  3894. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3895. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3896. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3897. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3898. WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  3899. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3900. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3901. ";
  3902. }
  3903. //委外入库
  3904. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  3905. {
  3906. ERPupdate = @"SELECT a.id
  3907. INTO #NewTempERP
  3908. FROM ICSWareHouseLotInfoLog a
  3909. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3910. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3911. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3912. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3913. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3914. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3915. WHERE c.OODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3916. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3917. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3918. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3919. where ID in (select id from #NewTempERP)
  3920. DROP TABLE #NewTempERP";
  3921. }
  3922. //委外退货
  3923. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  3924. {
  3925. ERPupdate = @"SELECT a.id
  3926. INTO #NewTempERP
  3927. FROM ICSWareHouseLotInfoLog a
  3928. INNER JOIN ICSODeliveryNotice c ON a.TransCode=c.ODNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  3929. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3930. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3931. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3932. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3933. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.ODNType='2' AND a.BusinessCode ='{7}'
  3934. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3935. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3936. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3937. where ID in (select id from #NewTempERP)
  3938. DROP TABLE #NewTempERP
  3939. ";
  3940. }
  3941. //生产发料
  3942. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  3943. {
  3944. //ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3945. // FROM ICSWareHouseLotInfoLog a
  3946. // INNER JOIN ICSMO y ON a.TransCode=y.MOCode AND a.WorkPoint=y.WorkPoint
  3947. // INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  3948. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3949. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3950. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3951. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3952. // WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3953. // and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3954. // ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3955. // ";
  3956. ERPupdate = @"SELECT a.id
  3957. INTO #NewTempERP
  3958. FROM ICSWareHouseLotInfoLog a
  3959. INNER JOIN ICSMO y ON a.TransCode=y.MOCode AND a.WorkPoint=y.WorkPoint
  3960. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  3961. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3962. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3963. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3964. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3965. WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3966. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  3967. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  3968. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3969. where ID in (select id from #NewTempERP)
  3970. DROP TABLE #NewTempERP";
  3971. }
  3972. //生产退料
  3973. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  3974. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  3975. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  3976. {
  3977. ERPupdate = @"--根据退料单退料
  3978. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3979. FROM ICSWareHouseLotInfoLog a
  3980. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3981. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  3982. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  3983. left JOIN ICSMOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  3984. WHERE ISNULL(m.ApplyDetailID, ISNULL(m.PickID, c.SourceDetailID))='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  3985. --退-
  3986. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3987. FROM ICSWareHouseLotInfoLog a
  3988. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  3989. INNER JOIN ICSMO y ON b.TransCode=y.MOCode AND b.WorkPoint=y.WorkPoint
  3990. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  3991. WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  3992. --退-
  3993. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  3994. FROM ICSWareHouseLotInfoLog a
  3995. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  3996. INNER JOIN ICSMOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  3997. WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  3998. --退-
  3999. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4000. FROM ICSWareHouseLotInfoLog a
  4001. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  4002. INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  4003. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  4004. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  4005. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  4006. WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  4007. ";
  4008. }
  4009. //生产入库
  4010. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  4011. {
  4012. //ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4013. // FROM ICSWareHouseLotInfoLog a
  4014. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  4015. // INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4016. // INNER JOIN ICSExtension docext ON docext.ID=c.ExtensionID AND docext.WorkPoint=c.WorkPoint
  4017. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4018. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4019. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4020. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4021. // WHERE c.MODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4022. // and (ISNULL(a.fromwarehousecode, '')
  4023. // + CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END
  4024. // + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END
  4025. // + CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END
  4026. // + CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END
  4027. // + CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END
  4028. // + CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END
  4029. // + CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END
  4030. // + CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END
  4031. // + CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END
  4032. // + CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END
  4033. // + CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END
  4034. // + CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END
  4035. // + CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END
  4036. // + CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END)='{6}'
  4037. //";
  4038. ERPupdate = @"SELECT a.id
  4039. INTO #NewTempERP
  4040. FROM ICSWareHouseLotInfoLog a
  4041. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  4042. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4043. INNER JOIN ICSExtension docext ON docext.ID=c.ExtensionID AND docext.WorkPoint=c.WorkPoint
  4044. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4045. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4046. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4047. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4048. WHERE c.MODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4049. and (ISNULL(a.fromwarehousecode, '')
  4050. + CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END
  4051. + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END
  4052. + CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END
  4053. + CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END
  4054. + CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END
  4055. + CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END
  4056. + CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END
  4057. + CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END
  4058. + CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END
  4059. + CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END
  4060. + CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END
  4061. + CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END
  4062. + CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END
  4063. + CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END)='{6}'
  4064. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4065. where ID in (select id from #NewTempERP)
  4066. DROP TABLE #NewTempERP
  4067. ";
  4068. }
  4069. //开立的生产入库单
  4070. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  4071. {
  4072. ERPupdate = @"SELECT a.id
  4073. INTO #NewTempERP
  4074. FROM ICSWareHouseLotInfoLog a
  4075. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  4076. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4077. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND a.BusinessCode ='{7}'
  4078. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4079. where ID in (select id from #NewTempERP)
  4080. DROP TABLE #NewTempERP
  4081. ";
  4082. }
  4083. //销售出库
  4084. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  4085. {
  4086. ERPupdate = @"SELECT a.id
  4087. INTO #NewTempERP
  4088. FROM ICSWareHouseLotInfoLog a
  4089. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4090. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4091. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4092. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4093. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4094. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND a.BusinessCode ='{7}'
  4095. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4096. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4097. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4098. where ID in (select id from #NewTempERP)
  4099. DROP TABLE #NewTempERP
  4100. ";
  4101. }
  4102. //销售退货
  4103. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  4104. {
  4105. ERPupdate = @"SELECT a.id
  4106. INTO #NewTempERP
  4107. FROM ICSWareHouseLotInfoLog a
  4108. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4109. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4110. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4111. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4112. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4113. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND a.BusinessCode ='{7}'
  4114. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4115. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4116. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4117. where ID in (select id from #NewTempERP)
  4118. DROP TABLE #NewTempERP";
  4119. }
  4120. //返工工单
  4121. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  4122. {
  4123. ERPupdate = @"SELECT a.id
  4124. INTO #NewTempERP
  4125. FROM ICSWareHouseLotInfoLog a
  4126. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  4127. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  4128. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  4129. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4130. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4131. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4132. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4133. WHERE d.PickID='{3}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4134. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4135. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4136. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4137. where ID in (select id from #NewTempERP)
  4138. DROP TABLE #NewTempERP
  4139. ";
  4140. }
  4141. //一步调拨
  4142. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  4143. {
  4144. ERPupdate = @"SELECT a.id
  4145. INTO #NewTempERP
  4146. FROM ICSWareHouseLotInfoLog a
  4147. INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4148. WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND a.BusinessCode ='{7}'
  4149. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4150. where ID in (select id from #NewTempERP)
  4151. DROP TABLE #NewTempERP
  4152. ";
  4153. }
  4154. //调拨
  4155. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  4156. {
  4157. ERPupdate = @"SELECT a.id
  4158. INTO #NewTempERP
  4159. FROM ICSWareHouseLotInfoLog a
  4160. INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4161. WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND a.BusinessCode ='{7}'
  4162. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4163. where ID in (select id from #NewTempERP)
  4164. DROP TABLE #NewTempERP
  4165. ";
  4166. }
  4167. //无源头调拨
  4168. else if (TransType == TransTypeEnum.StepNoTransferDocIn.GetDescription())
  4169. {
  4170. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4171. FROM ICSWareHouseLotInfoLog a
  4172. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4173. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4174. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4175. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4176. WHERE a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode='70'
  4177. and (ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4178. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4179. ";
  4180. }
  4181. //两步调出
  4182. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  4183. {
  4184. ERPupdate = @"SELECT a.id
  4185. INTO #NewTempERP
  4186. FROM ICSWareHouseLotInfoLog a
  4187. INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4188. INNER JOIN ICSTransfer d ON c.TransferDetailID=d.TransferDetailID AND c.WorkPoint=d.WorkPoint
  4189. WHERE c.OutID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4190. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4191. where ID in (select id from #NewTempERP)
  4192. DROP TABLE #NewTempERP
  4193. ";
  4194. }
  4195. //两步调入
  4196. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  4197. {
  4198. ERPupdate = @"SELECT a.id
  4199. INTO #NewTempERP
  4200. FROM ICSWareHouseLotInfoLog a
  4201. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  4202. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  4203. WHERE b.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4204. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4205. where ID in (select id from #NewTempERP)
  4206. DROP TABLE #NewTempERP
  4207. ";
  4208. }
  4209. //销售退货-原条码
  4210. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  4211. {
  4212. ERPupdate = @"SELECT a.id
  4213. INTO #NewTempERP
  4214. FROM ICSWareHouseLotInfoLog a
  4215. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4216. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4217. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4218. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4219. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4220. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND a.BusinessCode ='{7}'
  4221. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4222. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4223. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4224. where ID in (select id from #NewTempERP)
  4225. DROP TABLE #NewTempERP";
  4226. }
  4227. //其他出库
  4228. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  4229. {
  4230. ERPupdate = @"SELECT a.id
  4231. INTO #NewTempERP
  4232. FROM ICSWareHouseLotInfoLog a
  4233. INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4234. WHERE c.OutID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  4235. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4236. where ID in (select id from #NewTempERP)
  4237. DROP TABLE #NewTempERP
  4238. ";
  4239. }
  4240. //其他入库
  4241. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  4242. {
  4243. ERPupdate = @"SELECT a.id
  4244. INTO #NewTempERP
  4245. FROM ICSWareHouseLotInfoLog a
  4246. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  4247. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  4248. WHERE c.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4249. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4250. where ID in (select id from #NewTempERP)
  4251. DROP TABLE #NewTempERP
  4252. ";
  4253. }
  4254. //拆卸单
  4255. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  4256. {
  4257. ERPupdate = @"UPDATE d set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4258. FROM ICSWareHouseLotInfoLog a
  4259. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  4260. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  4261. INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
  4262. WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND d.ERPUpload='0' AND a.BusinessCode ='{7}'
  4263. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4264. FROM ICSWareHouseLotInfoLog a
  4265. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  4266. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  4267. WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DABDOCType='2' AND a.BusinessCode ='{7}'
  4268. ";
  4269. }
  4270. //领料申请单
  4271. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  4272. {
  4273. //ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4274. // FROM ICSWareHouseLotInfoLog a
  4275. // INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4276. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4277. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4278. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4279. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4280. // WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4281. // and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4282. // ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4283. // ";
  4284. ERPupdate = @"SELECT a.id
  4285. INTO #NewTempERP
  4286. FROM ICSWareHouseLotInfoLog a
  4287. INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4288. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4289. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4290. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4291. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4292. WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4293. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4294. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4295. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4296. where ID in (select id from #NewTempERP)
  4297. DROP TABLE #NewTempERP
  4298. ";
  4299. }
  4300. //补料申请单
  4301. else if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
  4302. {
  4303. //ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4304. // FROM ICSWareHouseLotInfoLog a
  4305. // INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4306. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4307. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4308. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4309. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4310. // WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4311. // and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4312. // ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4313. // ";
  4314. ERPupdate = @"SELECT a.id
  4315. INTO #NewTempERP
  4316. FROM ICSWareHouseLotInfoLog a
  4317. INNER JOIN ICSMOReplenishment c ON a.TransCode=c.ReplenishmentCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4318. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4319. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4320. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4321. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4322. WHERE c.ReplenishmentDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4323. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4324. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4325. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4326. where ID in (select id from #NewTempERP)
  4327. DROP TABLE #NewTempERP
  4328. ";
  4329. }
  4330. //委外领料申请单
  4331. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  4332. {
  4333. //ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4334. // FROM ICSWareHouseLotInfoLog a
  4335. // INNER JOIN ICSOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4336. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4337. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4338. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4339. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4340. // WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4341. // and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4342. // ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4343. // ";
  4344. ERPupdate = @"SELECT a.id
  4345. INTO #NewTempERP
  4346. FROM ICSWareHouseLotInfoLog a
  4347. INNER JOIN ICSOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4348. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4349. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4350. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4351. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4352. WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4353. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4354. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4355. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4356. where ID in (select id from #NewTempERP)
  4357. DROP TABLE #NewTempERP
  4358. ";
  4359. }
  4360. //开立材料出库
  4361. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  4362. {
  4363. ERPupdate = @"SELECT a.id
  4364. INTO #NewTempERP
  4365. FROM ICSWareHouseLotInfoLog a
  4366. INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4367. WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4368. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4369. where ID in (select id from #NewTempERP)
  4370. DROP TABLE #NewTempERP
  4371. ";
  4372. }
  4373. //开立委外材料出库
  4374. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  4375. {
  4376. ERPupdate = @"SELECT a.id
  4377. INTO #NewTempERP
  4378. FROM ICSWareHouseLotInfoLog a
  4379. INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4380. WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4381. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4382. where ID in (select id from #NewTempERP)
  4383. DROP TABLE #NewTempERP
  4384. ";
  4385. }
  4386. //开立红字入库单
  4387. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  4388. {
  4389. ERPupdate = @"SELECT a.id
  4390. INTO #NewTempERP
  4391. FROM ICSWareHouseLotInfoLog a
  4392. INNER JOIN ICSPurchaseReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4393. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND a.BusinessCode ='{7}'
  4394. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4395. where ID in (select id from #NewTempERP)
  4396. DROP TABLE #NewTempERP
  4397. ";
  4398. }
  4399. //开立委外红字入库单
  4400. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  4401. {
  4402. ERPupdate = @"SELECT a.id
  4403. INTO #NewTempERP
  4404. FROM ICSWareHouseLotInfoLog a
  4405. INNER JOIN ICSOutsourcingReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4406. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND a.BusinessCode ='{7}'
  4407. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4408. where ID in (select id from #NewTempERP)
  4409. DROP TABLE #NewTempERP
  4410. ";
  4411. }
  4412. //借用
  4413. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  4414. {
  4415. ERPupdate = @"SELECT a.id
  4416. INTO #NewTempERP
  4417. FROM ICSWareHouseLotInfoLog a
  4418. INNER JOIN ICSBrrow c ON a.TransCode=c.BrrowCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  4419. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4420. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4421. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4422. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4423. WHERE c.BrrowDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4424. and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4425. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4426. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4427. where ID in (select id from #NewTempERP)
  4428. DROP TABLE #NewTempERP";
  4429. }
  4430. //归还
  4431. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  4432. {
  4433. ERPupdate = @"SELECT a.id
  4434. INTO #NewTempERP
  4435. FROM ICSWareHouseLotInfoLog a
  4436. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  4437. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  4438. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  4439. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4440. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4441. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  4442. WHERE c.ReturnDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  4443. and (ISNULL(a.tohwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
  4444. ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
  4445. UPDATE ICSWareHouseLotInfoLog set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  4446. where ID in (select id from #NewTempERP)
  4447. DROP TABLE #NewTempERP";
  4448. }
  4449. ERPupdate = string.Format(ERPupdate, SourceDetailID, Identification, ID, DetailID, Code, Sequence, col, BusinessCode);
  4450. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  4451. {
  4452. throw new Exception(TransType + language.GetNameByCode("WMSAPIInfo175"));//"回写日志失败!");
  4453. }
  4454. }
  4455. catch (Exception ex)
  4456. {
  4457. log.Debug(ex.ToString());
  4458. log.Debug(TransType + Environment.NewLine + ERPupdate);
  4459. throw;
  4460. }
  4461. }
  4462. /// <summary>
  4463. /// 倒冲时子件已领数量回写
  4464. /// </summary>
  4465. public static void DetailQTYUpdate()
  4466. {
  4467. }
  4468. /// <summary>
  4469. /// 生成条码
  4470. /// </summary>
  4471. /// <param name="LotNo"></param>
  4472. /// <param name="Quantity"></param>
  4473. /// <param name="TransCode"></param>
  4474. /// <param name="TransSequence"></param>
  4475. /// <param name="WorkPoint"></param>
  4476. /// <param name="Identification"></param>
  4477. /// <param name="User"></param>
  4478. /// <param name="InvCode"></param>
  4479. /// <param name="BusinessCode"></param>
  4480. /// <param name="ProjectCode"></param>
  4481. /// <param name="BatchCode"></param>
  4482. /// <param name="Version"></param>
  4483. /// <param name="Brand"></param>
  4484. /// <param name="cFree1"></param>
  4485. /// <param name="cFree2"></param>
  4486. /// <param name="cFree3"></param>
  4487. /// <param name="cFree4"></param>
  4488. /// <param name="cFree5"></param>
  4489. /// <param name="cFree6"></param>
  4490. /// <param name="cFree7"></param>
  4491. /// <param name="cFree8"></param>
  4492. /// <param name="cFree9"></param>
  4493. /// <param name="cFree10"></param>
  4494. /// <param name="cmd"></param>
  4495. /// <param name="language"></param>
  4496. public static void CreateLotNo(string LotNo, string Quantity, string TransCode, string TransSequence, string WorkPoint, string Identification, string User, string InvCode, string BusinessCode,
  4497. string ProjectCode, string BatchCode, string Version, string Brand, string cFree1, string cFree2, string cFree3, string cFree4, string cFree5,string cFree6, string cFree7, string cFree8, string cFree9, string cFree10, SqlCommand cmd, Dictionary<string, string> language,string LocationCode,string OLDLotNo)
  4498. {
  4499. try
  4500. {
  4501. String EffectiveEnable = "";
  4502. String Colspan = "";
  4503. String IDD = "";
  4504. int EffectiveDays = 0;
  4505. String Time = "";
  4506. int EffectiveDayss = 0;
  4507. DateTime dtt;
  4508. DateTime now = DateTime.Now;
  4509. string sql = string.Empty;
  4510. //string sql = @"select EffectiveEnable,EffectiveDays from ICSInventory a
  4511. // Left Join ICSMO b ON a.InvCode=b.InvCode and a.WorkPoint = b.WorkPoint
  4512. // where b.MoCode='{0}' and b.WorkPoint='{1}'";
  4513. //sql = string.Format(sql, TransCode, WorkPoint);
  4514. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  4515. //if (dt.Rows.Count == 0)
  4516. //{
  4517. // throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  4518. //}
  4519. //else
  4520. //{
  4521. // EffectiveEnable = dt.Rows[0]["EffectiveEnable"].ToString();
  4522. //EffectiveDays = Convert.ToInt32(dt.Rows[0]["EffectiveDays"]);
  4523. //}
  4524. //EffectiveDayss = Convert.ToInt32(EffectiveDays);
  4525. //if (!EffectiveEnable.Equals("False"))
  4526. //{
  4527. int year = now.Year;
  4528. int month = now.Month;
  4529. int day = now.Day;
  4530. int n = DateTime.DaysInMonth(year, month);
  4531. int k = day + EffectiveDays;
  4532. if (k > n)
  4533. {
  4534. day = EffectiveDays - (n - day);
  4535. month = month + 1;
  4536. if (month > 12)
  4537. {
  4538. month = 1;
  4539. year = year + 1;
  4540. }
  4541. }
  4542. else
  4543. {
  4544. day = day + EffectiveDays;
  4545. }
  4546. Time = year + "-" + month + "-" + day;
  4547. //}
  4548. //else
  4549. //{
  4550. // Time = "2999-12-31 00:00:00.000";
  4551. //}
  4552. dtt = Convert.ToDateTime(Time);
  4553. //检验自由项
  4554. Colspan = ProjectCode + "~" + BatchCode + "~" + Version
  4555. + "~" + Brand + "~" + cFree1
  4556. + "~" + cFree2 + "~" + cFree3 + "~" + cFree4
  4557. + "~" + cFree5 + "~" + cFree6 + "~" + cFree7
  4558. + "~" + cFree8 + "~" + cFree9 + "~" + cFree10;
  4559. sql = @"select ID,Colspan from ICSExtension a
  4560. where Colspan='{0}' and WorkPoint='{1}'";
  4561. sql = string.Format(sql, Colspan, WorkPoint);
  4562. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  4563. if (dttt.Rows.Count == 0)
  4564. {
  4565. IDD = Guid.NewGuid().ToString();
  4566. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  4567. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  4568. sql = string.Format(sql, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, User, WorkPoint, IDD);
  4569. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4570. {
  4571. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  4572. }
  4573. }
  4574. else
  4575. {
  4576. IDD = dttt.Rows[0]["ID"].ToString();
  4577. }
  4578. //存入条码表
  4579. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  4580. BEGIN
  4581. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  4582. RETURN
  4583. END
  4584. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  4585. Quantity,Amount,ExtensionID,Type,PrintTimes,
  4586. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  4587. WorkPoint,EATTRIBUTE1)
  4588. SELECT TOP 1 NEWID(),'{0}','{8}',GETDATE(),'{6}',
  4589. '{1}','0','{7}','16',null,
  4590. null,null,'{2}' ,f.F_RealName ,GETDATE(),
  4591. '{4}' ,''
  4592. FROM Sys_SRM_User f
  4593. where f.F_Account='{2}' and f.F_Location='{4}'
  4594. ";
  4595. sql = string.Format(sql, LotNo, Quantity, User, TransCode, WorkPoint, TransSequence, dtt, IDD,InvCode);
  4596. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4597. {
  4598. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  4599. }
  4600. ///存入条码关联表
  4601. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{3}')
  4602. BEGIN
  4603. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  4604. RETURN
  4605. END
  4606. INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,
  4607. WorkPoint,EATTRIBUTE1)
  4608. SELECT '{4}','{0}','{1}',f.F_Account ,f.F_RealName,GETDATE(),
  4609. a.WorkPoint,''
  4610. FROM ICSInventoryLot a
  4611. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  4612. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  4613. WHERE a.LotNo='{5}' AND a.WorkPoint='{3}'
  4614. ";
  4615. sql = string.Format(sql, TransCode, TransSequence, User, WorkPoint, LotNo, OLDLotNo);
  4616. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4617. {
  4618. throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
  4619. }
  4620. //存入库存表
  4621. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  4622. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'0',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  4623. FROM ICSInventoryLot a
  4624. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  4625. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  4626. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  4627. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  4628. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  4629. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  4630. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode);
  4631. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4632. {
  4633. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  4634. }
  4635. }
  4636. catch (Exception)
  4637. {
  4638. throw;
  4639. }
  4640. }
  4641. }
  4642. }