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

2778 lines
178 KiB

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