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

2356 lines
158 KiB

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