纽威

3972 lines
251 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
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
3 years ago
3 years ago
3 years ago
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
2 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
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
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
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 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
2 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
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
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
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
2 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
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
3 years ago
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
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
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
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
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, string createDate)
  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}','{5}','0',f.F_Account ,f.F_RealName ,'{5}' ,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, createDate);
  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 TransCode, string TransLine, string INVCode, 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. string LotNo = "";
  518. #region 根据传入的料号和数量自动生成条码
  519. if (BusinessCode == "2")
  520. {
  521. string ExtensionID = "";
  522. string Pre = "DN" + TransCode + TransLine;
  523. string PRODUCTDATE = DateTime.Now.ToString();
  524. string lotsql = @"SELECT TOP 1 ISNULL(ExtensionID,'') AS ExtensionID FROM ICSDeliveryNotice WHERE DNCode='{0}' AND WorkPoint='{1}'";
  525. lotsql = string.Format(lotsql, TransCode, WorkPoint);
  526. DataTable lotdt = DBHelper.SQlReturnData(lotsql, cmd);
  527. if (lotdt.Rows.Count != 0)
  528. {
  529. ExtensionID = lotdt.Rows[0]["ExtensionID"].ToString();
  530. }
  531. lotsql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  532. lotsql = string.Format(lotsql, WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  533. LotNo = DBHelper.SQlReturnData(lotsql, cmd).Rows[0][0].ToString();
  534. lotsql = string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  535. Values('{0}','{1}','{2}','{3}','{3}',getdate(),'{4}' )",
  536. LotNo, TransCode, TransLine, User, WorkPoint);
  537. lotsql += string.Format(@"insert into ICSInventoryLot
  538. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  539. select
  540. newid(),'{0}',InvCode,'{1}','2999-12-31 00:00:00.000','{2}','{7}','7','{3}','{3}', getdate(),'{4}',0
  541. from ICSDeliveryNotice where DNCode='{5}' and Sequence='{6}' and WorkPoint='{4}'",
  542. LotNo, PRODUCTDATE, Quantity, User, WorkPoint, TransCode, TransLine, ExtensionID);
  543. if (!DBHelper.ExecuteNonQuery(lotsql, cmd))
  544. {
  545. throw new Exception(language.GetNameByCode("WMSAPIInfo215"));
  546. }
  547. }
  548. else if (BusinessCode == "18")
  549. {
  550. string ExtensionID = "";
  551. string Pre = "KCP" + TransCode + TransLine;
  552. string PRODUCTDATE = DateTime.Now.ToString();
  553. string lotsql = @"SELECT TOP 1 ISNULL(ExtensionID,'') AS ExtensionID FROM ICSManufactureReceive WHERE RCVCode='{0}' AND WorkPoint='{1}'";
  554. lotsql = string.Format(lotsql, TransCode, WorkPoint);
  555. DataTable lotdt = DBHelper.SQlReturnData(lotsql, cmd);
  556. if (lotdt.Rows.Count != 0)
  557. {
  558. ExtensionID = lotdt.Rows[0]["ExtensionID"].ToString();
  559. }
  560. lotsql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  561. lotsql = string.Format(lotsql, WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  562. LotNo = DBHelper.SQlReturnData(lotsql, cmd).Rows[0][0].ToString();
  563. lotsql = string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  564. Values('{0}','{1}','{2}','{3}','{3}',getdate(),'{4}' )",
  565. LotNo, TransCode, TransLine, User, WorkPoint);
  566. lotsql += string.Format(@"insert into ICSInventoryLot
  567. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  568. select
  569. newid(),'{0}',InvCode,'{1}','2999-12-31 00:00:00.000','{2}','{7}','9','{3}','{3}', getdate(),'{4}',0
  570. from ICSManufactureReceive where RCVCode='{5}' and Sequence='{6}' and WorkPoint='{4}'",
  571. LotNo, PRODUCTDATE, Quantity, User, WorkPoint, TransCode, TransLine, ExtensionID);
  572. if (!DBHelper.ExecuteNonQuery(lotsql, cmd))
  573. {
  574. throw new Exception(language.GetNameByCode("WMSAPIInfo215"));
  575. }
  576. }
  577. else if (BusinessCode == "16")
  578. {
  579. string ExtensionID = "";
  580. string Pre = "MA" + TransCode + TransLine;
  581. string PRODUCTDATE = DateTime.Now.ToString();
  582. string lotsql = @"SELECT TOP 1 ISNULL(ExtensionID,'') AS ExtensionID FROM ICSMOApplyNegDetail WHERE ApplyNegCode='{0}' AND WorkPoint='{1}'";
  583. lotsql = string.Format(lotsql, TransCode, WorkPoint);
  584. DataTable lotdt = DBHelper.SQlReturnData(lotsql, cmd);
  585. if (lotdt.Rows.Count != 0)
  586. {
  587. ExtensionID = lotdt.Rows[0]["ExtensionID"].ToString();
  588. }
  589. lotsql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  590. lotsql = string.Format(lotsql, WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
  591. LotNo = DBHelper.SQlReturnData(lotsql, cmd).Rows[0][0].ToString();
  592. lotsql = string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  593. Values('{0}','{1}','{2}','{3}','{3}',getdate(),'{4}' )",
  594. LotNo, TransCode, TransLine, User, WorkPoint);
  595. lotsql += string.Format(@"insert into ICSInventoryLot
  596. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  597. select
  598. newid(),'{0}',InvCode,'{1}','2999-12-31 00:00:00.000','{2}','{7}','12','{3}','{3}', getdate(),'{4}',0
  599. from ICSMOApplyNegDetail where ApplyNegCode='{5}' and Sequence='{6}' and WorkPoint='{4}'",
  600. LotNo, PRODUCTDATE, Quantity, User, WorkPoint, TransCode, TransLine, ExtensionID);
  601. if (!DBHelper.ExecuteNonQuery(lotsql, cmd))
  602. {
  603. throw new Exception(language.GetNameByCode("WMSAPIInfo215"));
  604. }
  605. }
  606. #endregion
  607. #region 正常入库
  608. #region 根据传入的货柜机器号找到对应的入库库位和仓库(一个机器号可能对应多个库位,需要根据料号找到对应区域确认唯一的入库库位)
  609. string chksql = @"select F_Define2 AS BinCode,C.WarehouseCode AS WHCode from Sys_SRM_ItemsDetail A
  610. LEFT JOIN ICSLocation B ON B.LocationCode=A.F_Define2 AND B.WorkPoint=A.F_Define4
  611. LEFT JOIN ICSWarehouse C ON C.ID=B.WHID AND C.WorkPoint=B.WorkPoint
  612. where F_Define1='{0}' AND F_ItemName='HG_Location' AND F_Define4='{1}'";
  613. chksql = string.Format(chksql, HGCode, WorkPoint);
  614. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  615. if (chkdt.Rows.Count == 0)
  616. {
  617. throw new Exception("传入货柜机器号:" + HGCode + "没有维护对应的WMS入库库位!");
  618. }
  619. else
  620. {
  621. #region 根据料号和仓库找到对应的区域
  622. string locationsql = @"";
  623. if (BusinessCode == "2")
  624. {
  625. locationsql = @"select B.LocationCode from ICSDeliveryNotice A
  626. INNER JOIN ICSInventoryDetail B ON B.INVCode=A.InvCode AND B.WHCode=A.WHCode
  627. AND B.WorkPoint=A.WorkPoint
  628. WHERE A.DNCode='{0}' AND A.WorkPoint='{1}'";
  629. }
  630. else if (BusinessCode == "18")
  631. {
  632. locationsql = @"select B.LocationCode from ICSManufactureReceive A
  633. INNER JOIN ICSInventoryDetail B ON B.INVCode=A.InvCode AND B.WHCode=A.WHCode AND B.WorkPoint=A.WorkPoint
  634. WHERE A.RCVCode='{0}' AND A.WorkPoint='{1}'";
  635. }
  636. else if (BusinessCode == "16")
  637. {
  638. locationsql = @"select B.LocationCode from ICSMOApplyNeg A
  639. INNER JOIN ICSMOApplyNegDetail C ON C.ApplyNegCode=A.ApplyNegCode AND C.WorkPoint=A.WorkPoint
  640. INNER JOIN ICSInventoryDetail B ON B.INVCode=C.InvCode AND B.WHCode=C.WHCode AND B.WorkPoint=C.WorkPoint
  641. WHERE A.ApplyNegCode='{0}' AND A.WorkPoint='{1}'";
  642. }
  643. locationsql = string.Format(locationsql, TransCode, WorkPoint);
  644. DataTable locationdt = DBHelper.SQlReturnData(locationsql, cmd);
  645. if (locationdt.Rows.Count == 0)
  646. {
  647. throw new Exception("单据:" + TransCode + "对应仓库及物料没有维护对应的区域,无法入库!");
  648. }
  649. else
  650. {
  651. foreach (DataRow dr in chkdt.Rows)
  652. {
  653. if (dr["BinCode"].ToString().Split('-')[1].ToString() == locationdt.Rows[0]["LocationCode"].ToString())
  654. {
  655. LocationCode = dr["BinCode"].ToString();
  656. WHCode = dr["WHCode"].ToString();
  657. }
  658. }
  659. }
  660. #endregion
  661. }
  662. #endregion
  663. if (LocationCode == "")
  664. {
  665. throw new Exception("传入机器号:" + HGCode + "对应的库位所在区域与单据:" + TransCode + "对应仓库及物料的所在区域不符,无法入库!");
  666. }
  667. string sql = string.Empty;
  668. sql = @" INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  669. SELECT NEWID(),a.LotNo ,'{4}','{5}',a.InvCode ,'{3}',SYSDATETIME(),'0','{2}','{2}',SYSDATETIME() ,a.WorkPoint ,''
  670. FROM ICSInventoryLot a
  671. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  672. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  673. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, WHCode, LocationCode);
  674. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  675. {
  676. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  677. }
  678. ///添加日志
  679. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  680. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  681. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  682. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  683. MTIME,WorkPoint,EATTRIBUTE1)
  684. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  685. '','',c.WarehouseCode,c.LocationCode,'{6}',
  686. '','0','{4}','{5}','0','',
  687. '','','','{2}','{2}',
  688. SYSDATETIME() ,a.WorkPoint ,''
  689. FROM ICSInventoryLot a
  690. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  691. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  692. --INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  693. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  694. ";
  695. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity);
  696. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  697. {
  698. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  699. }
  700. #endregion
  701. }
  702. catch (Exception)
  703. {
  704. throw;
  705. }
  706. }
  707. /// <summary>
  708. /// 减少库存
  709. /// </summary>
  710. /// <param name="Identification"></param>
  711. /// <param name="TransCode"></param>
  712. /// <param name="TransSequence"></param>
  713. /// <param name="LotNo"></param>
  714. /// <param name="Quantity"></param>
  715. /// <param name="User"></param>
  716. /// <param name="WorkPoint"></param>
  717. /// <param name="TransType"></param>
  718. /// <param name="BusinessCode"></param>
  719. /// <param name="cmd"></param>
  720. public static DataTable WareHouseLotInfoDown(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
  721. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID = "")
  722. {
  723. String LotEnable = "";
  724. String PrintEnable = "";
  725. string lotstr = "";
  726. int result = 0;
  727. List<string> NewBarCodeList = new List<string>();
  728. DataTable dtLotno = new DataTable();
  729. DataTable lstDt = new DataTable();
  730. try
  731. {
  732. ///更新库存
  733. string sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  734. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  735. BEGIN
  736. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  737. RETURN
  738. END";
  739. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  740. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  741. {
  742. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  743. }
  744. //出库后取消占料
  745. sql = @"update b set b.LockQuantity = convert(decimal(18, 6), b.LockQuantity) - convert(decimal(18, 6), c.Quantity)
  746. from dbo.ICSWareHouseLotInfo b
  747. inner join (select sum(Quantity) as Quantity, LotNo from ICSWareHouseLotInfolog where
  748. LotNo='{0}' AND TransCode ='{1}' AND TransSequence='{2}'
  749. and TransType = '15' and WorkPoint = '{3}' group by LotNo) c
  750. on c.LotNo = b.LotNo
  751. DELETE FROM ICSWareHouseLotInfoLog
  752. WHERE LotNo='{0}' AND TransCode='{1}' AND TransSequence='{2}' AND WorkPoint='{3}' AND TransType='15'";
  753. sql = string.Format(sql, LotNo, TransCode, TransSequence, WorkPoint);
  754. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  755. {
  756. //throw new Exception("占料信息解除失败!");//"库存更新失败!");
  757. }
  758. //检验是否分批
  759. sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  760. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  761. where a.LotNo='{0}' and a.WorkPoint='{1}'
  762. ";
  763. sql = string.Format(sql, LotNo, WorkPoint);
  764. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  765. if (dt.Rows.Count == 0)
  766. {
  767. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  768. }
  769. else
  770. {
  771. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  772. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  773. }
  774. if (LotEnable.Equals("True"))
  775. {
  776. ///分批前添加日志
  777. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  778. BEGIN
  779. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  780. RETURN
  781. END
  782. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  783. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  784. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  785. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  786. MTIME,WorkPoint,EATTRIBUTE1)
  787. SELECT NEWID(),'{3}','{7}','{8}',a.LotNo ,a.InvCode ,
  788. c.WarehouseCode,c.LocationCode,'','',c.Quantity+{6},
  789. '','0','{4}','31','0','',
  790. '','','',f.F_Account ,f.F_RealName ,
  791. SYSDATETIME() ,a.WorkPoint ,''
  792. FROM ICSInventoryLot a
  793. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  794. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  795. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  796. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  797. ";
  798. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, TransCode, TransSequence);
  799. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  800. {
  801. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  802. }
  803. #region 获取分批后的条码(lotstr)
  804. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  805. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  806. sql = string.Format(sql, LotNo, WorkPoint);
  807. dt = DBHelper.SQlReturnData(sql, cmd);
  808. if (dt.Rows.Count == 0)
  809. {
  810. lotstr = LotNo + "-" + 1;
  811. }
  812. else
  813. {
  814. lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  815. }
  816. NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  817. #endregion
  818. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  819. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  820. Quantity,Amount,ExtensionID,Type,PrintTimes,
  821. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  822. WorkPoint,EATTRIBUTE1)
  823. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  824. '{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes,
  825. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  826. a.WorkPoint ,'{1}'
  827. From ICSInventoryLot a
  828. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  829. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  830. cmd.CommandText = sql;
  831. result = cmd.ExecuteNonQuery();
  832. if (result <= 0)
  833. {
  834. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  835. }
  836. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  837. select NEWID(),'{0}',WarehouseCode,LocationCode,InvCode,'0',InDate,0
  838. ,MUSER,MUSERName,GETDATE(),'{3}',''
  839. from ICSWareHouseLotInfo
  840. where LotNO='{1}' AND WorkPoint='{3}'";
  841. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  842. cmd.CommandText = sql;
  843. result = cmd.ExecuteNonQuery();
  844. if (result <= 0)
  845. {
  846. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  847. }
  848. //插入条码单据表
  849. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  850. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  851. FROM ICSInventoryLot a
  852. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  853. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  854. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  855. sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
  856. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  857. {
  858. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  859. }
  860. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  861. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  862. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  863. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  864. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  865. SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
  866. c.WarehouseCode,c.LocationCode,'','','{6}',
  867. '','0','{7}','{8}','0','',
  868. '','','',f.F_Account ,f.F_RealName ,
  869. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  870. FROM ICSInventoryLot a
  871. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  872. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  873. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  874. ";
  875. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr);
  876. cmd.CommandText = sql;
  877. result = cmd.ExecuteNonQuery();
  878. if (result <= 0)
  879. {
  880. throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
  881. }
  882. if (PrintEnable.Equals("True"))
  883. {
  884. 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
  885. from ICSWareHouseLotInfolog A
  886. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  887. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  888. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  889. where A.lotno like'{0}%' and a.workpoint='{1}'
  890. ";
  891. sql = string.Format(sql, LotNo, WorkPoint);
  892. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  893. lstDt = dtLotno;
  894. }
  895. ///添加日志
  896. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  897. BEGIN
  898. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  899. RETURN
  900. END
  901. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  902. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  903. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  904. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  905. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  906. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  907. c.WarehouseCode,c.LocationCode,'','',c.Quantity,
  908. '','0','{7}','32','0','',
  909. '','','',f.F_Account ,f.F_RealName ,
  910. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  911. FROM ICSInventoryLot a
  912. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  913. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  914. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  915. ";
  916. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  917. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  918. {
  919. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  920. }
  921. #endregion
  922. }
  923. else
  924. {
  925. NewBarCodeList.Add(LotNo);
  926. ///添加日志
  927. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  928. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  929. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  930. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  931. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  932. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  933. c.WarehouseCode,c.LocationCode,'','','{6}',
  934. '','0','{7}','{8}','0','',
  935. '','','','{2}','{2}',
  936. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  937. FROM ICSInventoryLot a
  938. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  939. --INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  940. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  941. ";
  942. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  943. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  944. {
  945. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  946. }
  947. }
  948. }
  949. catch (Exception)
  950. {
  951. throw;
  952. }
  953. return lstDt;
  954. }
  955. /// <summary>
  956. /// 减少库存(货柜)
  957. /// </summary>
  958. /// <param name="Identification"></param>
  959. /// <param name="TransCode"></param>
  960. /// <param name="TransSequence"></param>
  961. /// <param name="LotNo"></param>
  962. /// <param name="Quantity"></param>
  963. /// <param name="User"></param>
  964. /// <param name="WorkPoint"></param>
  965. /// <param name="TransType"></param>
  966. /// <param name="BusinessCode"></param>
  967. /// <param name="cmd"></param>
  968. public static DataTable WareHouseLotInfoDownHG(string Identification, string TransCode, string User,
  969. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID = "")
  970. {
  971. String LotEnable = "";
  972. String PrintEnable = "";
  973. string lotstr = "";
  974. int result = 0;
  975. DataTable dtLotno = new DataTable();
  976. DataTable lstDt = new DataTable();
  977. try
  978. {
  979. #region 根据占料获取库存条码
  980. string sql = @"select TransSequence,LotNo,Quantity,InvCode from ICSWareHouseLotInfoLog
  981. where TransCode='{0}' and TransType='15' and WorkPoint='{1}'";
  982. sql = string.Format(sql, TransCode, WorkPoint);
  983. DataTable lotdt = DBHelper.SQlReturnData(sql, cmd);
  984. if (lotdt.Rows.Count == 0)
  985. {
  986. throw new Exception("未查询到单据占料信息,无法出库!");
  987. }
  988. #endregion
  989. foreach (DataRow dr in lotdt.Rows)
  990. {
  991. ///更新库存
  992. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  993. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  994. BEGIN
  995. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  996. RETURN
  997. END";
  998. sql = string.Format(sql, dr["LotNo"].ToString(), WorkPoint, Convert.ToDecimal(dr["Quantity"]));
  999. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1000. {
  1001. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1002. }
  1003. //出库后取消占料
  1004. sql = @"update b set b.LockQuantity = convert(decimal(18, 6), b.LockQuantity) - convert(decimal(18, 6), c.Quantity)
  1005. from dbo.ICSWareHouseLotInfo b
  1006. inner join (select sum(Quantity) as Quantity, LotNo from ICSWareHouseLotInfolog where
  1007. LotNo='{0}' AND TransCode ='{1}' AND TransSequence='{2}'
  1008. and TransType = '15' and WorkPoint = '{3}' group by LotNo) c
  1009. on c.LotNo = b.LotNo
  1010. DELETE FROM ICSWareHouseLotInfoLog
  1011. WHERE LotNo='{0}' AND TransCode='{1}' AND TransSequence='{2}' AND WorkPoint='{3}' AND TransType='15'";
  1012. sql = string.Format(sql, dr["LotNo"].ToString(), TransCode, dr["TransSequence"].ToString(), WorkPoint);
  1013. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1014. {
  1015. //throw new Exception("占料信息解除失败!");//"库存更新失败!");
  1016. }
  1017. ///添加日志
  1018. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1019. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1020. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1021. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1022. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  1023. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1024. c.WarehouseCode,c.LocationCode,'','','{6}',
  1025. '','0','{7}','{8}','0','',
  1026. '','','','{2}','{2}',
  1027. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  1028. FROM ICSInventoryLot a
  1029. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1030. --INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1031. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1032. ";
  1033. sql = string.Format(sql, dr["LotNo"].ToString(), WorkPoint, User, Identification, TransCode, dr["TransSequence"].ToString()
  1034. , Convert.ToDecimal(dr["Quantity"]), TransType, BusinessCode, MergeID);
  1035. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1036. {
  1037. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1038. }
  1039. }
  1040. }
  1041. catch (Exception)
  1042. {
  1043. throw;
  1044. }
  1045. return lstDt;
  1046. }
  1047. /// <summary>
  1048. /// 出库单据增加验证,整单全部出库之后删除所有跟单据关联的占料信息,解锁占料数量
  1049. /// </summary>
  1050. /// <param name="TransCode"></param>
  1051. /// <param name="WorkPoint"></param>
  1052. /// <param name="cmd"></param>
  1053. /// <param name="language"></param>
  1054. public static void MaterialOccpyCancel(string TransType, string TransCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1055. {
  1056. try
  1057. {
  1058. //验证单据是否整单出库完成,若已完成,则删除所有相关占料信息并解除占料数量
  1059. bool DocComplete = false;
  1060. string sql = "";
  1061. if (TransType == "采购退货-采购退货单")
  1062. {
  1063. sql = @"select SUM(Quantity) as NeedQTY,SUM(RCVQuantity) AS HasQTY from ICSDeliveryNotice
  1064. where DNCode='{0}' and WorkPoint='{1}'";
  1065. }
  1066. else if (TransType == "生产发料-领料申请单")
  1067. {
  1068. sql = @"select SUM(Quantity) as NeedQTY,SUM(IssueQuantity) AS HasQTY from ICSMOApply
  1069. where ApplyCode='{0}' and WorkPoint='{1}'";
  1070. }
  1071. else if (TransType == "委外发料-委外领料申请单")
  1072. {
  1073. sql = @"select SUM(Quantity) as NeedQTY,SUM(IssueQuantity) AS HasQTY from ICSOApply
  1074. where ApplyCode='{0}' and WorkPoint='{1}'";
  1075. }
  1076. else if (TransType == "销售发货-销售发货单")
  1077. {
  1078. sql = @"select SUM(Quantity) as NeedQTY,SUM(SDNQuantity) AS HasQTY from ICSSDN
  1079. where SDNCode='{0}' and WorkPoint='{1}'";
  1080. }
  1081. else if (TransType == "杂发")
  1082. {
  1083. sql = @"select SUM(Quantity) as NeedQTY,SUM(OutQuantity) AS HasQTY from ICSOtherOut
  1084. where OutCode='{0}' and WorkPoint='{1}'";
  1085. }
  1086. sql = string.Format(sql, TransCode, WorkPoint);
  1087. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1088. if (dt.Rows.Count != 0)
  1089. {
  1090. if (Convert.ToDecimal(dt.Rows[0]["NeedQTY"]) == Convert.ToDecimal(dt.Rows[0]["HasQTY"]))
  1091. {
  1092. DocComplete = true;
  1093. }
  1094. }
  1095. if (DocComplete == true)
  1096. {
  1097. sql = @"select LotNo,Quantity from ICSWareHouseLotInfoLog
  1098. where TransCode='{0}' AND WorkPoint='{1}' and TransType=15";
  1099. sql = string.Format(sql, TransCode, WorkPoint);
  1100. dt = DBHelper.SQlReturnData(sql, cmd);
  1101. foreach (DataRow dr in dt.Rows)
  1102. {
  1103. sql += @" update ICSWareHouseLotInfo set LockQuantity=CONVERT(decimal(18,6),LockQuantity)-{0}
  1104. where LotNo='{1}' AND WorkPoint='{2}' ";
  1105. sql = string.Format(sql, dr["Quantity"].ToString(), dr["LotNo"].ToString(), WorkPoint);
  1106. }
  1107. DBHelper.ExecuteNonQuery(sql, cmd);
  1108. sql = @"DELETE FROM ICSWareHouseLotInfoLog
  1109. WHERE TransType=15 AND TransCode='{0}' AND WorkPoint='{1}'";
  1110. sql = string.Format(sql, TransCode, WorkPoint);
  1111. DBHelper.ExecuteNonQuery(sql, cmd);
  1112. }
  1113. }
  1114. catch (Exception)
  1115. {
  1116. throw;
  1117. }
  1118. }
  1119. /// <summary>
  1120. /// 减少库存(无条码领料)
  1121. /// </summary>
  1122. /// <param name="Identification"></param>
  1123. /// <param name="TransCode"></param>
  1124. /// <param name="TransSequence"></param>
  1125. /// <param name="LotNo"></param>
  1126. /// <param name="Quantity"></param>
  1127. /// <param name="User"></param>
  1128. /// <param name="WorkPoint"></param>
  1129. /// <param name="TransType"></param>
  1130. /// <param name="BusinessCode"></param>
  1131. /// <param name="cmd"></param>
  1132. public static DataTable WareHouseLotInfoDownWithOutLot(string Identification, string TransCode, string User,
  1133. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID = "")
  1134. {
  1135. String LotEnable = "";
  1136. String PrintEnable = "";
  1137. string lotstr = "";
  1138. int result = 0;
  1139. List<string> NewBarCodeList = new List<string>();
  1140. DataTable dtLotno = new DataTable();
  1141. DataTable lstDt = new DataTable();
  1142. try
  1143. {
  1144. #region 根据单据获得占料信息
  1145. string docsql = @"select TransSequence,LotNo,Quantity,InvCode from ICSWareHouseLotInfoLog
  1146. where TransCode='{0}' and TransType='15' and WorkPoint='{1}'";
  1147. docsql = string.Format(docsql, TransCode, WorkPoint);
  1148. DataTable docdt = DBHelper.SQlReturnData(docsql, cmd);
  1149. #endregion
  1150. foreach (DataRow dr in docdt.Rows)
  1151. {
  1152. string INVCode = dr["InvCode"].ToString();
  1153. decimal lotQuantity = Convert.ToDecimal(dr["Quantity"]);
  1154. string DocLineNO = dr["TransSequence"].ToString();
  1155. string LotNO = dr["LotNo"].ToString();
  1156. ///更新库存
  1157. string sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1158. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  1159. BEGIN
  1160. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1161. RETURN
  1162. END";
  1163. sql = string.Format(sql, LotNO, WorkPoint, lotQuantity);
  1164. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1165. {
  1166. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1167. }
  1168. ///添加日志
  1169. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1170. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1171. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1172. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1173. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  1174. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1175. c.WarehouseCode,c.LocationCode,'','','{6}',
  1176. '','0','{7}','{8}','0','',
  1177. '','','','{2}','{2}',
  1178. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  1179. FROM ICSInventoryLot a
  1180. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1181. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1182. sql = string.Format(sql, LotNO, WorkPoint, User, Identification, TransCode, DocLineNO, lotQuantity, TransType, BusinessCode, MergeID);
  1183. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1184. {
  1185. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1186. }
  1187. }
  1188. //出库后取消占料
  1189. string cancelsql = @"update b set b.LockQuantity = convert(decimal(18, 6), b.LockQuantity) - convert(decimal(18, 6), c.Quantity)
  1190. from dbo.ICSWareHouseLotInfo b
  1191. inner join (select sum(Quantity) as Quantity, LotNo from ICSWareHouseLotInfolog where TransCode ='{0}'
  1192. and TransType = '15' and WorkPoint = '{1}' group by LotNo) c
  1193. on c.LotNo = b.LotNo
  1194. DELETE FROM ICSWareHouseLotInfoLog
  1195. WHERE TransCode='{0}' AND WorkPoint='{1}' AND TransType='15'";
  1196. cancelsql = string.Format(cancelsql, TransCode, WorkPoint);
  1197. if (!DBHelper.ExecuteNonQuery(cancelsql, cmd))
  1198. {
  1199. //throw new Exception("占料信息解除失败!");//"库存更新失败!");
  1200. }
  1201. }
  1202. catch (Exception)
  1203. {
  1204. throw;
  1205. }
  1206. return lstDt;
  1207. }
  1208. /// <summary>
  1209. /// 修改库存
  1210. /// </summary>
  1211. /// <param name="Identification"></param>
  1212. /// <param name="TransCode"></param>
  1213. /// <param name="TransSequence"></param>
  1214. /// <param name="LotNo"></param>
  1215. /// <param name="Quantity"></param>
  1216. /// <param name="User"></param>
  1217. /// <param name="WorkPoint"></param>
  1218. /// <param name="TransType"></param>
  1219. /// <param name="cmd"></param>
  1220. public static void WareHouseLotInfoUpdate(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
  1221. string WorkPoint, string TransType, string CheckKind, SqlCommand cmd, Dictionary<string, string> language)
  1222. {
  1223. try
  1224. {
  1225. ///添加日志
  1226. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1227. BEGIN
  1228. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1229. RETURN
  1230. END
  1231. IF EXISTS(SELECT LotNo FROM ICSWareHouseLotInfoLog WHERE LotNo='{0}' AND WorkPoint='{1}' AND TransType=15)
  1232. BEGIN
  1233. RAISERROR(':{0}!',16,1);
  1234. RETURN
  1235. END
  1236. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1237. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1238. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1239. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1240. MTIME,WorkPoint,EATTRIBUTE1)
  1241. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1242. a.WarehouseCode,a.LocationCode,'','',a.Quantity,
  1243. '{8}','0','{6}','{7}','0','',
  1244. '','','',f.F_Account ,f.F_RealName ,
  1245. SYSDATETIME() ,a.WorkPoint ,''
  1246. FROM ICSWareHouseLotInfo a
  1247. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1248. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1249. ";
  1250. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, TransTypeEnum.LOTCheckBefore.GetDescription<DBValue>(), CheckKind);
  1251. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1252. {
  1253. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1254. }
  1255. ///更新库存
  1256. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity='{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'";
  1257. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1258. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1259. {
  1260. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1261. }
  1262. ///添加日志
  1263. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1264. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1265. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1266. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1267. MTIME,WorkPoint,EATTRIBUTE1)
  1268. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1269. a.WarehouseCode,a.LocationCode,'','',a.Quantity,
  1270. '{8}','0','{6}','{7}','0','',
  1271. '','','',f.F_Account ,f.F_RealName ,
  1272. SYSDATETIME() ,a.WorkPoint ,''
  1273. FROM ICSWareHouseLotInfo a
  1274. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1275. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1276. ";
  1277. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, TransTypeEnum.LOTCheckAfter.GetDescription<DBValue>(), CheckKind);
  1278. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1279. {
  1280. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1281. }
  1282. }
  1283. catch (Exception)
  1284. {
  1285. throw;
  1286. }
  1287. }
  1288. /// <summary>
  1289. /// 调拨
  1290. /// </summary>
  1291. /// <param name="LocationCode"></param>
  1292. /// <param name="LotNo"></param>
  1293. /// <param name="Quantity"></param>
  1294. /// <param name="User"></param>
  1295. /// <param name="WorkPoint"></param>
  1296. /// <param name="TransType"></param>
  1297. /// <param name="BusinessCode"></param>
  1298. /// <param name="cmd"></param>
  1299. public static DataTable WareHouseLotInfoTransfer(string Identification, string TransCode, string TransSequence, string WarehouseCode, string LocationCode,
  1300. string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID)
  1301. {
  1302. bool? LotEnable = null;
  1303. String PrintEnable = "";
  1304. string lotstr = "";
  1305. int result = 0;
  1306. DataTable dtLotno = new DataTable();
  1307. DataTable lstDt = new DataTable();
  1308. List<string> NewBarCodeList = new List<string>();
  1309. try
  1310. {
  1311. var tranferWorkpoint = string.Empty;
  1312. var checksql = $@"SELECT
  1313. top 1 a.EATTRIBUTE1
  1314. FROM
  1315. ICSTransfer a
  1316. WHERE
  1317. TransferNO = '{TransCode}'
  1318. AND Sequence = '{TransSequence}'
  1319. AND WorkPoint = '{WorkPoint}'
  1320. AND Type = '{TransType}'";
  1321. var workPoint = DBHelper.ExecuteScalar(checksql, cmd).ToString();
  1322. if (workPoint == null || workPoint == "")
  1323. {
  1324. tranferWorkpoint = WorkPoint;
  1325. }
  1326. else
  1327. {
  1328. tranferWorkpoint = workPoint.ToString();
  1329. }
  1330. #region 先删除条码的占料信息
  1331. string sql = @" update b set b.LockQuantity = convert(decimal(18, 6), b.LockQuantity) - convert(decimal(18, 6), c.Quantity)
  1332. from dbo.ICSWareHouseLotInfo b
  1333. inner join (select sum(Quantity) as Quantity, LotNo from ICSWareHouseLotInfolog where
  1334. LotNo='{0}' AND TransCode ='{1}' AND TransSequence='{2}'
  1335. and TransType = '15' and WorkPoint = '{3}' group by LotNo) c
  1336. on c.LotNo = b.LotNo
  1337. delete from ICSWareHouseLotInfoLog
  1338. where LotNo='{0}' and TransCode='{1}' and TransSequence='{2}' and WorkPoint='{3}' and TransType=15";
  1339. sql = string.Format(sql, LotNo, TransCode, TransSequence, WorkPoint);
  1340. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1341. {
  1342. //throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1343. }
  1344. #endregion
  1345. ///分批前添加日志
  1346. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1347. BEGIN
  1348. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1349. RETURN
  1350. END
  1351. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1352. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1353. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1354. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1355. MTIME,WorkPoint,EATTRIBUTE1)
  1356. SELECT NEWID(),'{3}','{7}','{8}',a.LotNo ,a.InvCode ,
  1357. c.WarehouseCode,c.LocationCode,'','',c.Quantity,
  1358. '','0','{4}','31','0','',
  1359. '','','',f.F_Account ,f.F_RealName ,
  1360. SYSDATETIME() ,'{1}' ,'{9}'
  1361. FROM ICSInventoryLot a
  1362. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1363. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1364. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1365. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1366. ";
  1367. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, TransCode, TransSequence, tranferWorkpoint);
  1368. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1369. {
  1370. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1371. }
  1372. ///更新库存
  1373. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}',--LocationCode = '{3}',
  1374. WorkPoint ='{4}' WHERE LotNo='{0}' AND WorkPoint='{1}';
  1375. UPDATE ICSInventoryLot SET WorkPoint='{4}' WHERE LotNo='{0}' AND WorkPoint='{1}';
  1376. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  1377. BEGIN
  1378. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1379. RETURN
  1380. END";
  1381. sql = string.Format(sql, LotNo, WorkPoint, Quantity, LocationCode, tranferWorkpoint);
  1382. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1383. {
  1384. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1385. }
  1386. #region 获取分批后的条码(lotstr)
  1387. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  1388. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  1389. sql = string.Format(sql, LotNo, tranferWorkpoint);
  1390. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1391. if (dt.Rows.Count == 0)
  1392. {
  1393. lotstr = LotNo + "-" + 1;
  1394. }
  1395. else
  1396. {
  1397. lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  1398. }
  1399. NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  1400. #endregion
  1401. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  1402. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  1403. Quantity,Amount,ExtensionID,Type,PrintTimes,
  1404. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  1405. WorkPoint,EATTRIBUTE1)
  1406. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  1407. '{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes,
  1408. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  1409. '{3}' ,'{1}'
  1410. From ICSInventoryLot a
  1411. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  1412. sql = string.Format(sql, lotstr, LotNo, Quantity, tranferWorkpoint);
  1413. cmd.CommandText = sql;
  1414. result = cmd.ExecuteNonQuery();
  1415. if (result <= 0)
  1416. {
  1417. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  1418. }
  1419. #endregion
  1420. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1421. select NEWID(),'{0}','{4}','{5}',InvCode,'{2}',InDate,0
  1422. ,MUSER,MUSERName,GETDATE(),'{3}',''
  1423. from ICSWareHouseLotInfo
  1424. where LotNO='{1}' AND WorkPoint='{3}'";
  1425. sql = string.Format(sql, lotstr, LotNo, Quantity, tranferWorkpoint, WarehouseCode, LocationCode);
  1426. cmd.CommandText = sql;
  1427. result = cmd.ExecuteNonQuery();
  1428. if (result <= 0)
  1429. {
  1430. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  1431. }
  1432. //插入条码单据表
  1433. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1434. SELECT '{0}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,'{1}'
  1435. FROM ICSInventoryLot a
  1436. INNER JOIN ICSInventoryLotDetail b ON b.LotNo='{3}' AND a.WorkPoint=b.WorkPoint
  1437. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1438. WHERE a.LotNo='{3}' AND a.WorkPoint='{1}'";
  1439. sql = string.Format(sql, lotstr, tranferWorkpoint, User, LotNo);
  1440. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1441. {
  1442. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  1443. }
  1444. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1445. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1446. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1447. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1448. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  1449. SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
  1450. c.WarehouseCode,c.LocationCode,'{11}','{12}','{6}',
  1451. '','0','{7}','{8}','0','',
  1452. '','','',f.F_Account ,f.F_RealName ,
  1453. SYSDATETIME() ,'{1}' ,'{13}','{9}'
  1454. FROM ICSInventoryLot a
  1455. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1456. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1457. WHERE a.LotNo='{0}' AND a.WorkPoint='{13}'
  1458. ";
  1459. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr, WarehouseCode, LocationCode, tranferWorkpoint);
  1460. cmd.CommandText = sql;
  1461. result = cmd.ExecuteNonQuery();
  1462. if (result <= 0)
  1463. {
  1464. throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
  1465. }
  1466. ///添加日志
  1467. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1468. BEGIN
  1469. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1470. RETURN
  1471. END
  1472. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1473. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1474. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1475. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1476. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  1477. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1478. c.WarehouseCode,c.LocationCode,'','',c.Quantity,
  1479. '','0','{7}','32','0','',
  1480. '','','',f.F_Account ,f.F_RealName ,
  1481. SYSDATETIME() ,'{1}' ,'{10}','{9}'
  1482. FROM ICSInventoryLot a
  1483. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1484. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1485. WHERE a.LotNo='{0}' AND a.WorkPoint='{10}'
  1486. ";
  1487. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, tranferWorkpoint);
  1488. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1489. {
  1490. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1491. }
  1492. if (PrintEnable.Equals("True"))
  1493. {
  1494. sql = @"select A.LotNO , C.Quantity AS OLDLotQty, B.Quantity AS LotQty ,b.InvCode,d.INVSTD,d.INVNAME,b.MTIME,A.TransCode
  1495. from ICSWareHouseLotInfolog A
  1496. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  1497. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  1498. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  1499. where (a.BusinessCode ='{2}' or a.BusinessCode='32')
  1500. and A.lotno like '{0}%' and a.workpoint='{1}'
  1501. and a.TransCode='{3}' and a.TransSequence='{4}'
  1502. ";
  1503. sql = string.Format(sql, LotNo, WorkPoint, BusinessCode, TransCode, TransSequence);
  1504. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  1505. lstDt = dtLotno;
  1506. }
  1507. #region 整单验证,如果单据全部完成,整单删除占料信息
  1508. bool DocComplete = false;
  1509. sql = @"select SUM(Quantity) as NeedQTY,SUM(TransferQuantity) AS HasQTY from ICSTransfer
  1510. where TransferNO='{0}' and WorkPoint='{1}'";
  1511. sql = string.Format(sql, TransCode, WorkPoint);
  1512. DataTable chkdt = DBHelper.SQlReturnData(sql, cmd);
  1513. if (dt.Rows.Count != 0)
  1514. {
  1515. if (Convert.ToDecimal(chkdt.Rows[0]["NeedQTY"]) == Convert.ToDecimal(chkdt.Rows[0]["HasQTY"]))
  1516. {
  1517. DocComplete = true;
  1518. }
  1519. }
  1520. if (DocComplete == true)
  1521. {
  1522. sql = @"select LotNo,Quantity from ICSWareHouseLotInfoLog
  1523. where TransCode='{0}' AND WorkPoint='{1}' and TransType=15";
  1524. sql = string.Format(sql, TransCode, WorkPoint);
  1525. dt = DBHelper.SQlReturnData(sql, cmd);
  1526. foreach (DataRow dr in dt.Rows)
  1527. {
  1528. sql += @" update ICSWareHouseLotInfo set LockQuantity=CONVERT(decimal(18,6),LockQuantity)-{0}
  1529. where LotNo='{1}' AND WorkPoint='{2}' ";
  1530. sql = string.Format(sql, dr["Quantity"].ToString(), dr["LotNo"].ToString(), WorkPoint);
  1531. }
  1532. DBHelper.ExecuteNonQuery(sql, cmd);
  1533. sql = @"DELETE FROM ICSWareHouseLotInfoLog
  1534. WHERE TransType=15 AND TransCode='{0}' AND WorkPoint='{1}'";
  1535. sql = string.Format(sql, TransCode, WorkPoint);
  1536. DBHelper.ExecuteNonQuery(sql, cmd);
  1537. }
  1538. #endregion
  1539. }
  1540. catch (Exception)
  1541. {
  1542. throw;
  1543. }
  1544. return lstDt;
  1545. }
  1546. /// <summary>
  1547. /// 移库
  1548. /// </summary>
  1549. /// <param name="LocationCode"></param>
  1550. /// <param name="LotNo"></param>
  1551. /// <param name="Quantity"></param>
  1552. /// <param name="User"></param>
  1553. /// <param name="WorkPoint"></param>
  1554. /// <param name="TransType"></param>
  1555. /// <param name="BusinessCode"></param>
  1556. /// <param name="cmd"></param>
  1557. public static void WareHouseLotInfoLibrary(string Identification, string TransCode, string TransSequence, string WarehouseCode, string LocationCode,
  1558. string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1559. {
  1560. try
  1561. {
  1562. string sql = @"SELECT WarehouseCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  1563. sql = string.Format(sql, LotNo, WorkPoint);
  1564. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1565. if (dt == null || dt.Rows.Count <= 0)
  1566. {
  1567. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
  1568. }
  1569. string whcode = dt.Rows[0]["WarehouseCode"].ToString();
  1570. ///添加日志
  1571. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1572. BEGIN
  1573. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1574. RETURN
  1575. END
  1576. IF('" + whcode + @"' != '{8}')
  1577. BEGIN
  1578. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo394"), "{8}", whcode) + @"', 16, 1);
  1579. RETURN
  1580. END
  1581. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1582. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1583. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1584. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1585. MTIME,WorkPoint,EATTRIBUTE1)
  1586. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1587. c.WarehouseCode,c.LocationCode,'{8}','{9}',c.Quantity,
  1588. '','0','{6}','{7}','0','',
  1589. '','','',f.F_Account ,f.F_RealName ,
  1590. SYSDATETIME() ,a.WorkPoint ,''
  1591. FROM ICSInventoryLot a
  1592. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1593. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1594. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1595. ";
  1596. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, BusinessCode, WarehouseCode, LocationCode);
  1597. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1598. {
  1599. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1600. }
  1601. ///添加库存
  1602. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity>0)
  1603. BEGIN
  1604. RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
  1605. RETURN
  1606. END
  1607. IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.WarehouseCode='{2}')
  1608. BEGIN
  1609. RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
  1610. RETURN
  1611. END
  1612. UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1613. ";
  1614. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode);
  1615. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1616. {
  1617. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
  1618. }
  1619. }
  1620. catch (Exception)
  1621. {
  1622. throw;
  1623. }
  1624. }
  1625. /// <summary>
  1626. /// 两步调入
  1627. /// </summary>
  1628. /// <param name="LocationCode"></param>
  1629. /// <param name="LotNo"></param>
  1630. /// <param name="Quantity"></param>
  1631. /// <param name="User"></param>
  1632. /// <param name="WorkPoint"></param>
  1633. /// <param name="TransType"></param>
  1634. /// <param name="BusinessCode"></param>
  1635. /// <param name="cmd"></param>
  1636. public static void WareHouseLotInfoTwoStepTransferDocIn(string Identification, string TransCode, string TransSequence, string WarehouseCode,
  1637. string LocationCode, string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1638. {
  1639. try
  1640. {
  1641. ///添加日志
  1642. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1643. BEGIN
  1644. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1645. RETURN
  1646. END
  1647. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1648. ToWarehouseCode,ToLocationCode,Quantity,
  1649. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1650. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1651. MTIME,WorkPoint,EATTRIBUTE1)
  1652. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  1653. '{9}','{10}','{6}',
  1654. '','0','{7}','{8}','0','',
  1655. '','','',f.F_Account ,f.F_RealName ,
  1656. SYSDATETIME() ,a.WorkPoint ,''
  1657. FROM ICSInventoryLot a
  1658. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1659. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1660. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1661. ";
  1662. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode);
  1663. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1664. {
  1665. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1666. }
  1667. ///添加库存
  1668. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1669. BEGIN
  1670. RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
  1671. RETURN
  1672. END
  1673. UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}',Quantity=Quantity+'{4}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1674. ";
  1675. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode, Quantity);
  1676. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1677. {
  1678. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
  1679. }
  1680. }
  1681. catch (Exception)
  1682. {
  1683. throw;
  1684. }
  1685. }
  1686. /// <summary>
  1687. /// 拆分、合并日志
  1688. /// </summary>
  1689. /// <param name="Identification"></param>
  1690. /// <param name="LotNo"></param>
  1691. /// <param name="User"></param>
  1692. /// <param name="WorkPoint"></param>
  1693. /// <param name="TransType"></param>
  1694. /// <param name="BusinessCode"></param>
  1695. /// <param name="cmd"></param>
  1696. public static DataTable WareHouseLotInfoLog(string Identification, string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1697. {
  1698. String LotEnable = "";
  1699. String PrintEnable = "";
  1700. DataTable dtLotno = new DataTable();
  1701. DataTable lstDt = new DataTable();
  1702. try
  1703. {
  1704. //检验是否分批
  1705. string sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  1706. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  1707. where a.LotNo='{0}' and a.WorkPoint='{1}'
  1708. ";
  1709. sql = string.Format(sql, LotNo, WorkPoint);
  1710. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1711. if (dt.Rows.Count == 0)
  1712. {
  1713. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  1714. }
  1715. else
  1716. {
  1717. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  1718. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  1719. }
  1720. ///添加日志
  1721. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1722. BEGIN
  1723. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1724. RETURN
  1725. END
  1726. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1727. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1728. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1729. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1730. MTIME,WorkPoint,EATTRIBUTE1)
  1731. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1732. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  1733. '','0','{4}','{5}','0','',
  1734. '','','',f.F_Account ,f.F_RealName ,
  1735. SYSDATETIME() ,a.WorkPoint ,''
  1736. FROM ICSInventoryLot a
  1737. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1738. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1739. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1740. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1741. ";
  1742. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  1743. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1744. {
  1745. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1746. }
  1747. if (PrintEnable.Equals("True"))
  1748. {
  1749. sql = @"select A.LotNO , C.Quantity AS OLDLotQty, B.Quantity AS LotQty ,b.InvCode,d.INVSTD,d.INVNAME,b.MTIME,A.TransCode
  1750. from ICSWareHouseLotInfolog A
  1751. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  1752. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  1753. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  1754. where a.BusinessCode='32'
  1755. and A.lotno like '{0}%' and a.workpoint='{1}'
  1756. ";
  1757. sql = string.Format(sql, LotNo, WorkPoint, BusinessCode);
  1758. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  1759. lstDt = dtLotno;
  1760. }
  1761. }
  1762. catch (Exception)
  1763. {
  1764. throw;
  1765. }
  1766. return lstDt;
  1767. }
  1768. /// <summary>
  1769. /// 合并
  1770. /// </summary>
  1771. /// <param name="Identification"></param>
  1772. /// <param name="LotNo"></param>
  1773. /// <param name="User"></param>
  1774. /// <param name="WorkPoint"></param>
  1775. /// <param name="TransType"></param>
  1776. /// <param name="BusinessCode"></param>
  1777. /// <param name="cmd"></param>
  1778. public static void WareHouseLotInfoMerge(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
  1779. string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1780. {
  1781. try
  1782. {
  1783. ///更新目标条码库存
  1784. string sql = @"IF NOT EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1785. INNER JOIN ICSInventoryLot b ON b.LotNo='{3}' AND a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  1786. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1787. BEGIN
  1788. RAISERROR('" + language.GetNameByCode("WMSAPIInfo170") + @"',16,1);
  1789. RETURN
  1790. END
  1791. IF NOT EXISTS (SELECT a.LotNo FROM ICSInventoryLot a,ICSInventoryLot b WHERE
  1792. a.LotNo= '{0}' AND b.LotNo= '{3}'
  1793. AND a.WorkPoint= '{1}' AND a.ExtensionID= b.ExtensionID )
  1794. BEGIN
  1795. RAISERROR ('" + language.GetNameByCode("WMSAPIInfo467") + @"',16,1 );
  1796. RETURN
  1797. END
  1798. IF NOT EXISTS (SELECT a.LotNo FROM ICSWareHouseLotInfo a,ICSWareHouseLotInfo b WHERE
  1799. a.LotNo= '{0}' AND b.LotNo= '{3}'
  1800. AND a.WorkPoint= '{1}' AND a.WarehouseCode= b.WarehouseCode )
  1801. BEGIN
  1802. RAISERROR ( '" + language.GetNameByCode("WMSAPIInfo468") + @"', 16, 1 );
  1803. RETURN
  1804. END
  1805. IF NOT EXISTS (SELECT a.LotNo FROM ICSWareHouseLotInfo a,ICSWareHouseLotInfo b WHERE
  1806. a.LotNo= '{0}' AND b.LotNo= '{3}'
  1807. AND a.WorkPoint= '{1}' AND a.LocationCode= b.LocationCode )
  1808. BEGIN
  1809. RAISERROR ( '" + language.GetNameByCode("WMSAPIInfo469") + @"', 16, 1 );
  1810. RETURN
  1811. END
  1812. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1813. BEGIN
  1814. RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
  1815. RETURN
  1816. END
  1817. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1818. ";
  1819. sql = string.Format(sql, LotNo, WorkPoint, Quantity, CurrentLotNo);
  1820. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1821. {
  1822. throw new Exception(language.GetNameByCode("WMSAPIInfo169"));//"目标条码库存更新失败!");
  1823. }
  1824. ///更新原条码库存
  1825. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1826. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  1827. BEGIN
  1828. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1829. RETURN
  1830. END";
  1831. sql = string.Format(sql, CurrentLotNo, WorkPoint, Quantity);
  1832. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1833. {
  1834. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1835. }
  1836. ///添加日志
  1837. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1838. BEGIN
  1839. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1840. RETURN
  1841. END
  1842. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1843. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1844. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1845. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1846. MTIME,WorkPoint,EATTRIBUTE1)
  1847. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1848. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  1849. '','0','{4}','{5}','0','',
  1850. '','','',f.F_Account ,f.F_RealName ,
  1851. SYSDATETIME() ,a.WorkPoint ,''
  1852. FROM ICSInventoryLot a
  1853. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1854. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1855. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1856. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1857. ";
  1858. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  1859. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1860. {
  1861. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1862. }
  1863. }
  1864. catch (Exception)
  1865. {
  1866. throw;
  1867. }
  1868. }
  1869. /// <summary>
  1870. /// 拆分
  1871. /// </summary>
  1872. /// <param name="Identification"></param>
  1873. /// <param name="LotNo"></param>
  1874. /// <param name="User"></param>
  1875. /// <param name="WorkPoint"></param>
  1876. /// <param name="TransType"></param>
  1877. /// <param name="BusinessCode"></param>
  1878. /// <param name="cmd"></param>
  1879. public static void WareHouseLotInfoSplit(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
  1880. string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1881. {
  1882. try
  1883. {
  1884. ///更新库存
  1885. string sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1886. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  1887. BEGIN
  1888. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1889. RETURN
  1890. END";
  1891. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1892. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1893. {
  1894. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1895. }
  1896. #region 添加库存
  1897. //插入条码表
  1898. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1899. BEGIN
  1900. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1901. RETURN
  1902. END
  1903. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a WHERE a.LotNo='{4}' AND a.WorkPoint='{1}')
  1904. BEGIN
  1905. RAISERROR('" + language.GetNameByCode("WMSAPIInfo172") + @"',16,1);
  1906. RETURN
  1907. END
  1908. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1909. SELECT NEWID(),'{4}' ,a.InvCode,a.ProductDate,a.ExpirationDate ,'{3}',a.ExtensionID,'101',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,a.LotNo
  1910. FROM ICSInventoryLot a
  1911. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1912. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1913. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, CurrentLotNo);
  1914. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1915. {
  1916. throw new Exception(language.GetNameByCode("WMSAPIInfo173"));//"条码表写入失败!");
  1917. }
  1918. //插入条码单据表
  1919. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1920. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  1921. FROM ICSInventoryLot a
  1922. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1923. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1924. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1925. sql = string.Format(sql, LotNo, WorkPoint, User, CurrentLotNo);
  1926. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1927. {
  1928. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  1929. }
  1930. ///添加库存
  1931. sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1932. BEGIN
  1933. RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
  1934. RETURN
  1935. END
  1936. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  1937. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  1938. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
  1939. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  1940. BEGIN
  1941. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  1942. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  1943. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint AND il.LocationCode=d.LocationCode
  1944. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  1945. BEGIN
  1946. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  1947. RETURN
  1948. END
  1949. END
  1950. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1951. SELECT NEWID(),a.LotNo ,d.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  1952. FROM ICSInventoryLot a
  1953. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1954. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
  1955. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1956. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1957. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Quantity);
  1958. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1959. {
  1960. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  1961. }
  1962. ///添加日志
  1963. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1964. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1965. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1966. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1967. MTIME,WorkPoint,EATTRIBUTE1)
  1968. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1969. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  1970. '','0','{4}','{5}','0','',
  1971. '','','',f.F_Account ,f.F_RealName ,
  1972. SYSDATETIME() ,a.WorkPoint ,''
  1973. FROM ICSInventoryLot a
  1974. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1975. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1976. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1977. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1978. ";
  1979. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  1980. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1981. {
  1982. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1983. }
  1984. #endregion
  1985. }
  1986. catch (Exception)
  1987. {
  1988. throw;
  1989. }
  1990. }
  1991. /// <summary>
  1992. /// 回写ERP ID
  1993. /// </summary>
  1994. /// <param name="TransType"></param>
  1995. /// <param name="SourceDetailID"></param>
  1996. /// <param name="Identification"></param>
  1997. /// <param name="ID"></param>
  1998. /// <param name="DetailID"></param>
  1999. /// <param name="Code"></param>
  2000. /// <param name="Sequence"></param>
  2001. /// <param name="cmd"></param>
  2002. 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)
  2003. {
  2004. string ERPupdate = string.Empty;
  2005. try
  2006. {
  2007. //采购入库
  2008. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  2009. {
  2010. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2011. FROM ICSWareHouseLotInfoLog a
  2012. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2013. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2014. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2015. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2016. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2017. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2018. WHERE c.PODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2019. 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, '') +
  2020. 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}'
  2021. ";
  2022. }
  2023. //审核的到货单
  2024. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  2025. {
  2026. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2027. FROM ICSWareHouseLotInfoLog a
  2028. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2029. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2030. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2031. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2032. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2033. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2034. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2035. 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, '') +
  2036. 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}'
  2037. ";
  2038. }
  2039. //采购拒收
  2040. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  2041. {
  2042. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2043. FROM ICSWareHouseLotInfoLog a
  2044. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2045. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2046. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2047. ";
  2048. }
  2049. //审核的委外到货单
  2050. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  2051. {
  2052. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2053. FROM ICSWareHouseLotInfoLog a
  2054. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2055. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2056. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2057. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2058. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2059. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2060. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2061. 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, '') +
  2062. 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}'
  2063. ";
  2064. }
  2065. //委外拒收
  2066. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  2067. {
  2068. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2069. FROM ICSWareHouseLotInfoLog a
  2070. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2071. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2072. ";
  2073. }
  2074. //采购退货
  2075. else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  2076. {
  2077. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2078. FROM ICSWareHouseLotInfoLog a
  2079. INNER JOIN ICSDeliveryNotice c ON a.TransCode=c.DNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2080. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2081. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2082. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2083. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2084. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DNType='2' AND a.BusinessCode ='{7}'
  2085. 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, '') +
  2086. 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}'
  2087. ";
  2088. }
  2089. //委外发料
  2090. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  2091. {
  2092. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2093. FROM ICSWareHouseLotInfoLog a
  2094. INNER JOIN ICSOutsourcingOrder y ON a.TransCode=y.OOCode AND a.WorkPoint=y.WorkPoint
  2095. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  2096. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2097. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2098. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2099. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2100. WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2101. 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, '') +
  2102. 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}'
  2103. ";
  2104. }
  2105. //委外退料
  2106. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  2107. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  2108. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  2109. {
  2110. ERPupdate = @"--根据退料单退料
  2111. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2112. FROM ICSWareHouseLotInfoLog a
  2113. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2114. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2115. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  2116. Left JOIN ICSOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  2117. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2118. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2119. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2120. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2121. WHERE ISNULL(m.ApplyDetailID,ISNULL(m.PickID, c.SourceDetailID))='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2122. 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, '') +
  2123. 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}'
  2124. --退-
  2125. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2126. FROM ICSWareHouseLotInfoLog a
  2127. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  2128. INNER JOIN ICSOutsourcingOrder y ON b.TransCode=y.OOCode AND b.WorkPoint=y.WorkPoint
  2129. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  2130. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2131. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2132. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2133. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2134. WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  2135. 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, '') +
  2136. 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}'
  2137. --退-
  2138. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2139. FROM ICSWareHouseLotInfoLog a
  2140. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  2141. INNER JOIN ICSOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  2142. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2143. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2144. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2145. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2146. WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  2147. 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, '') +
  2148. 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}'
  2149. --退-
  2150. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2151. FROM ICSWareHouseLotInfoLog a
  2152. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  2153. INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  2154. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  2155. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  2156. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  2157. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2158. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2159. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2160. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2161. WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  2162. 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, '') +
  2163. 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}'
  2164. ";
  2165. }
  2166. //委外入库
  2167. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  2168. {
  2169. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2170. FROM ICSWareHouseLotInfoLog a
  2171. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2172. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2173. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2174. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2175. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2176. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2177. WHERE c.OODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2178. 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, '') +
  2179. 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}'
  2180. ";
  2181. }
  2182. //委外退货
  2183. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  2184. {
  2185. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2186. FROM ICSWareHouseLotInfoLog a
  2187. INNER JOIN ICSODeliveryNotice c ON a.TransCode=c.ODNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2188. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2189. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2190. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2191. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2192. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.ODNType='2' AND a.BusinessCode ='{7}'
  2193. 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, '') +
  2194. 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}'
  2195. ";
  2196. }
  2197. //生产发料
  2198. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  2199. {
  2200. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2201. FROM ICSWareHouseLotInfoLog a
  2202. INNER JOIN ICSMO y ON a.TransCode=y.MOCode AND a.WorkPoint=y.WorkPoint
  2203. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  2204. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2205. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2206. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2207. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2208. WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2209. 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, '') +
  2210. 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}'
  2211. ";
  2212. }
  2213. //生产退料
  2214. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  2215. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  2216. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  2217. {
  2218. ERPupdate = @"--根据退料单退料
  2219. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2220. FROM ICSWareHouseLotInfoLog a
  2221. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2222. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2223. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  2224. left JOIN ICSMOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  2225. WHERE ISNULL(m.ApplyDetailID, ISNULL(m.PickID, c.SourceDetailID))='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2226. --退-
  2227. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2228. FROM ICSWareHouseLotInfoLog a
  2229. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  2230. INNER JOIN ICSMO y ON b.TransCode=y.MOCode AND b.WorkPoint=y.WorkPoint
  2231. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  2232. WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  2233. --退-
  2234. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2235. FROM ICSWareHouseLotInfoLog a
  2236. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  2237. INNER JOIN ICSMOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  2238. WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  2239. --退-
  2240. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2241. FROM ICSWareHouseLotInfoLog a
  2242. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  2243. INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  2244. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  2245. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  2246. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  2247. WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  2248. ";
  2249. }
  2250. //生产入库
  2251. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  2252. {
  2253. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2254. FROM ICSWareHouseLotInfoLog a
  2255. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2256. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2257. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2258. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2259. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2260. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2261. WHERE c.MODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2262. 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, '') +
  2263. 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}'
  2264. ";
  2265. }
  2266. //开立的生产入库单
  2267. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  2268. {
  2269. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2270. FROM ICSWareHouseLotInfoLog a
  2271. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2272. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2273. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND a.BusinessCode ='{7}'
  2274. ";
  2275. }
  2276. //销售出库
  2277. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  2278. {
  2279. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2280. FROM ICSWareHouseLotInfoLog a
  2281. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2282. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2283. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2284. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2285. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2286. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND a.BusinessCode ='{7}'
  2287. 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, '') +
  2288. 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}'
  2289. ";
  2290. }
  2291. //销售退货
  2292. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  2293. {
  2294. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2295. FROM ICSWareHouseLotInfoLog a
  2296. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2297. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2298. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2299. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2300. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2301. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND a.BusinessCode ='{7}'
  2302. 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, '') +
  2303. 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}'
  2304. ";
  2305. }
  2306. //返工工单
  2307. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  2308. {
  2309. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2310. FROM ICSWareHouseLotInfoLog a
  2311. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2312. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  2313. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  2314. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2315. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2316. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2317. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2318. WHERE d.PickID='{3}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2319. 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, '') +
  2320. 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}'
  2321. ";
  2322. }
  2323. //一步调拨
  2324. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  2325. {
  2326. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2327. FROM ICSWareHouseLotInfoLog a
  2328. INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2329. WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND a.BusinessCode ='{7}'
  2330. ";
  2331. }
  2332. //调拨
  2333. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  2334. {
  2335. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2336. FROM ICSWareHouseLotInfoLog a
  2337. INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2338. WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND a.BusinessCode ='{7}'
  2339. ";
  2340. }
  2341. //两步调出
  2342. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  2343. {
  2344. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2345. FROM ICSWareHouseLotInfoLog a
  2346. INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2347. INNER JOIN ICSTransfer d ON c.TransferDetailID=d.TransferDetailID AND c.WorkPoint=d.WorkPoint
  2348. WHERE c.OutID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2349. ";
  2350. }
  2351. //两步调入
  2352. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  2353. {
  2354. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2355. FROM ICSWareHouseLotInfoLog a
  2356. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2357. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  2358. WHERE b.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2359. ";
  2360. }
  2361. //销售退货-原条码
  2362. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  2363. {
  2364. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2365. FROM ICSWareHouseLotInfoLog a
  2366. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2367. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2368. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2369. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2370. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2371. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND a.BusinessCode ='{7}'
  2372. 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, '') +
  2373. 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}'
  2374. ";
  2375. }
  2376. //其他出库
  2377. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  2378. {
  2379. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2380. FROM ICSWareHouseLotInfoLog a
  2381. INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2382. WHERE c.OutID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
  2383. ";
  2384. }
  2385. //其他入库
  2386. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  2387. {
  2388. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2389. FROM ICSWareHouseLotInfoLog a
  2390. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2391. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2392. WHERE c.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2393. ";
  2394. }
  2395. //拆卸单
  2396. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  2397. {
  2398. ERPupdate = @"UPDATE d set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2399. FROM ICSWareHouseLotInfoLog a
  2400. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2401. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2402. INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
  2403. WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND d.ERPUpload='0' AND a.BusinessCode ='{7}'
  2404. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2405. FROM ICSWareHouseLotInfoLog a
  2406. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2407. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2408. WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DABDOCType='2' AND a.BusinessCode ='{7}'
  2409. ";
  2410. }
  2411. //领料申请单
  2412. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  2413. {
  2414. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2415. FROM ICSWareHouseLotInfoLog a
  2416. INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2417. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2418. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2419. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2420. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2421. WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2422. 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, '') +
  2423. 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}'
  2424. ";
  2425. }
  2426. //委外领料申请单
  2427. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  2428. {
  2429. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2430. FROM ICSWareHouseLotInfoLog a
  2431. INNER JOIN ICSOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2432. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2433. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2434. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2435. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2436. WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2437. 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, '') +
  2438. 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}'
  2439. ";
  2440. }
  2441. //开立材料出库
  2442. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  2443. {
  2444. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2445. FROM ICSWareHouseLotInfoLog a
  2446. INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2447. WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2448. ";
  2449. }
  2450. //开立委外材料出库
  2451. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  2452. {
  2453. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2454. FROM ICSWareHouseLotInfoLog a
  2455. INNER JOIN ICSOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2456. WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2457. ";
  2458. }
  2459. //开立红字入库单
  2460. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  2461. {
  2462. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2463. FROM ICSWareHouseLotInfoLog a
  2464. INNER JOIN ICSPurchaseReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2465. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND a.BusinessCode ='{7}'
  2466. ";
  2467. }
  2468. //开立委外红字入库单
  2469. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  2470. {
  2471. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2472. FROM ICSWareHouseLotInfoLog a
  2473. INNER JOIN ICSOutsourcingReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2474. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND a.BusinessCode ='{7}'
  2475. ";
  2476. }
  2477. //借用
  2478. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  2479. {
  2480. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2481. FROM ICSWareHouseLotInfoLog a
  2482. INNER JOIN ICSBrrow c ON a.TransCode=c.BrrowCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2483. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2484. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2485. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2486. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2487. WHERE c.BrrowDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2488. 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, '') +
  2489. 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}'
  2490. ";
  2491. }
  2492. //归还
  2493. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  2494. {
  2495. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  2496. FROM ICSWareHouseLotInfoLog a
  2497. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2498. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2499. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2500. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2501. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2502. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2503. WHERE c.ReturnDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
  2504. 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, '') +
  2505. 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}'
  2506. ";
  2507. }
  2508. ERPupdate = string.Format(ERPupdate, SourceDetailID, Identification, ID, DetailID, Code, Sequence, col, BusinessCode);
  2509. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  2510. {
  2511. throw new Exception(TransType + language.GetNameByCode("WMSAPIInfo175"));//"回写日志失败!");
  2512. }
  2513. }
  2514. catch (Exception ex)
  2515. {
  2516. log.Debug(ex.ToString());
  2517. log.Debug(TransType + Environment.NewLine + ERPupdate);
  2518. throw;
  2519. }
  2520. }
  2521. /// <summary>
  2522. /// 倒冲时子件已领数量回写
  2523. /// </summary>
  2524. public static void DetailQTYUpdate()
  2525. {
  2526. }
  2527. /// <summary>
  2528. /// 生成条码
  2529. /// </summary>
  2530. /// <param name="LotNo"></param>
  2531. /// <param name="Quantity"></param>
  2532. /// <param name="TransCode"></param>
  2533. /// <param name="TransSequence"></param>
  2534. /// <param name="WorkPoint"></param>
  2535. /// <param name="Identification"></param>
  2536. /// <param name="User"></param>
  2537. /// <param name="InvCode"></param>
  2538. /// <param name="BusinessCode"></param>
  2539. /// <param name="ProjectCode"></param>
  2540. /// <param name="BatchCode"></param>
  2541. /// <param name="Version"></param>
  2542. /// <param name="Brand"></param>
  2543. /// <param name="cFree1"></param>
  2544. /// <param name="cFree2"></param>
  2545. /// <param name="cFree3"></param>
  2546. /// <param name="cFree4"></param>
  2547. /// <param name="cFree5"></param>
  2548. /// <param name="cFree6"></param>
  2549. /// <param name="cFree7"></param>
  2550. /// <param name="cFree8"></param>
  2551. /// <param name="cFree9"></param>
  2552. /// <param name="cFree10"></param>
  2553. /// <param name="cmd"></param>
  2554. /// <param name="language"></param>
  2555. public static void CreateLotNo(string LotNo, string Quantity, string TransCode, string TransSequence, string WorkPoint, string Identification, string User, string InvCode, string BusinessCode,
  2556. 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)
  2557. {
  2558. try
  2559. {
  2560. String EffectiveEnable = "";
  2561. String Colspan = "";
  2562. String IDD = "";
  2563. int EffectiveDays = 0;
  2564. String Time = "";
  2565. int EffectiveDayss = 0;
  2566. DateTime dtt;
  2567. DateTime now = DateTime.Now;
  2568. string sql = string.Empty;
  2569. //string sql = @"select EffectiveEnable,EffectiveDays from ICSInventory a
  2570. // Left Join ICSMO b ON a.InvCode=b.InvCode and a.WorkPoint = b.WorkPoint
  2571. // where b.MoCode='{0}' and b.WorkPoint='{1}'";
  2572. //sql = string.Format(sql, TransCode, WorkPoint);
  2573. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2574. //if (dt.Rows.Count == 0)
  2575. //{
  2576. // throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  2577. //}
  2578. //else
  2579. //{
  2580. // EffectiveEnable = dt.Rows[0]["EffectiveEnable"].ToString();
  2581. //EffectiveDays = Convert.ToInt32(dt.Rows[0]["EffectiveDays"]);
  2582. //}
  2583. //EffectiveDayss = Convert.ToInt32(EffectiveDays);
  2584. //if (!EffectiveEnable.Equals("False"))
  2585. //{
  2586. int year = now.Year;
  2587. int month = now.Month;
  2588. int day = now.Day;
  2589. int n = DateTime.DaysInMonth(year, month);
  2590. int k = day + EffectiveDays;
  2591. if (k > n)
  2592. {
  2593. day = EffectiveDays - (n - day);
  2594. month = month + 1;
  2595. if (month > 12)
  2596. {
  2597. month = 1;
  2598. year = year + 1;
  2599. }
  2600. }
  2601. else
  2602. {
  2603. day = day + EffectiveDays;
  2604. }
  2605. Time = year + "-" + month + "-" + day;
  2606. //}
  2607. //else
  2608. //{
  2609. // Time = "2999-12-31 00:00:00.000";
  2610. //}
  2611. dtt = Convert.ToDateTime(Time);
  2612. //检验自由项
  2613. Colspan = ProjectCode + "~" + BatchCode + "~" + Version
  2614. + "~" + Brand + "~" + cFree1
  2615. + "~" + cFree2 + "~" + cFree3 + "~" + cFree4
  2616. + "~" + cFree5 + "~" + cFree6 + "~" + cFree7
  2617. + "~" + cFree8 + "~" + cFree9 + "~" + cFree10;
  2618. sql = @"select ID,Colspan from ICSExtension a
  2619. where Colspan='{0}' and WorkPoint='{1}'";
  2620. sql = string.Format(sql, Colspan, WorkPoint);
  2621. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  2622. if (dttt.Rows.Count == 0)
  2623. {
  2624. IDD = Guid.NewGuid().ToString();
  2625. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  2626. 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}'";
  2627. sql = string.Format(sql, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, User, WorkPoint, IDD);
  2628. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2629. {
  2630. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  2631. }
  2632. }
  2633. else
  2634. {
  2635. IDD = dttt.Rows[0]["ID"].ToString();
  2636. }
  2637. //存入条码表
  2638. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  2639. BEGIN
  2640. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2641. RETURN
  2642. END
  2643. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  2644. Quantity,Amount,ExtensionID,Type,PrintTimes,
  2645. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  2646. WorkPoint,EATTRIBUTE1)
  2647. SELECT TOP 1 NEWID(),'{0}','{8}',GETDATE(),'{6}',
  2648. '{1}','0','{7}','16',null,
  2649. null,null,'{2}' ,f.F_RealName ,GETDATE(),
  2650. '{4}' ,''
  2651. FROM Sys_SRM_User f
  2652. where f.F_Account='{2}' and f.F_Location='{4}'
  2653. ";
  2654. sql = string.Format(sql, LotNo, Quantity, User, TransCode, WorkPoint, TransSequence, dtt, IDD, InvCode);
  2655. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2656. {
  2657. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  2658. }
  2659. ///存入条码关联表
  2660. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{3}')
  2661. BEGIN
  2662. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2663. RETURN
  2664. END
  2665. INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,
  2666. WorkPoint,EATTRIBUTE1)
  2667. SELECT '{4}','{0}','{1}',f.F_Account ,f.F_RealName,GETDATE(),
  2668. a.WorkPoint,''
  2669. FROM ICSInventoryLot a
  2670. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2671. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2672. WHERE a.LotNo='{5}' AND a.WorkPoint='{3}'
  2673. ";
  2674. sql = string.Format(sql, TransCode, TransSequence, User, WorkPoint, LotNo, OLDLotNo);
  2675. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2676. {
  2677. throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
  2678. }
  2679. //存入库存表
  2680. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2681. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'0',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  2682. FROM ICSInventoryLot a
  2683. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2684. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2685. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  2686. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  2687. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2688. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  2689. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode);
  2690. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2691. {
  2692. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  2693. }
  2694. }
  2695. catch (Exception)
  2696. {
  2697. throw;
  2698. }
  2699. }
  2700. /// <summary>
  2701. /// 料架条码绑定
  2702. /// </summary>
  2703. /// <param name="LotNo"></param>
  2704. /// <param name="ContainerCode"></param>
  2705. /// <param name="User"></param>
  2706. /// <param name="WorkPoint"></param>
  2707. /// <param name="cmd"></param>
  2708. /// <param name="language"></param>
  2709. public static void ContainerBind(string LotNo, string ContainerCode, string ContainerType, string LocationCode, string RecomendBinCode, string User, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2710. {
  2711. try
  2712. {
  2713. ///添加日志
  2714. if (ContainerType != "窄巷道叉车(木托盘)")
  2715. {
  2716. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  2717. BEGIN
  2718. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  2719. RETURN
  2720. END
  2721. IF NOT EXISTS(SELECT ID FROM ICSInventoryLot WHERE LotNO='{0}')
  2722. BEGIN
  2723. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{0}") + @"',16,1);
  2724. RETURN
  2725. END
  2726. IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCode='{1}' AND WorkPoint='{2}')
  2727. BEGIN
  2728. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo473"), "{2}", "{1}") + @"',16,1);
  2729. RETURN
  2730. END
  2731. IF NOT EXISTS (SELECT * FROM ICSContainerLot WHERE ContainerID=
  2732. (SELECT ID FROM ICSContainer WHERE ContainerCode='{1}' AND WorkPoint='{2}') AND LotNo='{0}')
  2733. BEGIN
  2734. -- update ICSContainer set EATTRIBUTE1='' where ContainerCode='{1}' AND WorkPoint='{2}'
  2735. INSERT INTO ICSContainerLot
  2736. (ID,ContainerID,LotNo,MUSER,MUSERName,WorkPoint,MTIME,EATTRIBUTE1)
  2737. SELECT NEWID(),ID,'{0}','{3}'
  2738. ,(SELECT F_RealName FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}'),'{2}',GETDATE(),'' FROM ICSContainer
  2739. WHERE ContainerCode='{1}' AND WorkPoint='{2}'
  2740. END
  2741. -- ELSE
  2742. -- BEGIN
  2743. -- update ICSContainer set LocationCode='{4}',EATTRIBUTE1='' where ContainerCode='{1}' AND WorkPoint='{2}'
  2744. -- UPDATE ICSContainerLot SET LotNo='{0}' WHERE ContainerID=
  2745. -- (SELECT ID FROM ICSContainer WHERE ContainerCode='{1}' AND WorkPoint='{2}')
  2746. -- END
  2747. ";
  2748. sql = string.Format(sql, LotNo, ContainerCode, WorkPoint, User, LocationCode);
  2749. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2750. {
  2751. throw new Exception("容器:" + ContainerCode + "与条码:" + LotNo + "绑定失败!");
  2752. }
  2753. }
  2754. else
  2755. {
  2756. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  2757. BEGIN
  2758. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  2759. RETURN
  2760. END
  2761. IF NOT EXISTS (SELECT * FROM ICSContainerLot WHERE ContainerID=
  2762. (SELECT ID FROM ICSContainer WHERE ContainerCode='{1}' AND WorkPoint='{2}'))
  2763. BEGIN
  2764. INSERT INTO ICSContainerLot
  2765. (ID,ContainerID,LotNo,MUSER,MUSERName,WorkPoint,MTIME,EATTRIBUTE1)
  2766. SELECT NEWID(),ID,'{0}','{3}'
  2767. ,(SELECT F_RealName FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}'),'{2}',GETDATE(),'{4}' FROM ICSContainer
  2768. WHERE ContainerCode='{1}' AND WorkPoint='{2}'
  2769. END
  2770. ELSE
  2771. BEGIN
  2772. UPDATE ICSContainerLot SET LotNo='{0}' WHERE ContainerID=
  2773. (SELECT ID FROM ICSContainer WHERE ContainerCode='{1}' AND WorkPoint='{2}')
  2774. END
  2775. ";
  2776. sql = string.Format(sql, LotNo, ContainerCode, WorkPoint, User, LocationCode);
  2777. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2778. {
  2779. throw new Exception("容器:" + ContainerCode + "与条码:" + LotNo + "绑定失败!");
  2780. }
  2781. //if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadForkLift"]))
  2782. //{
  2783. // string ForkLiftUrl = System.Configuration.ConfigurationManager.AppSettings["ForkLiftUrl"];
  2784. // string Year = DateTime.Now.Year.ToString();
  2785. // string Month = DateTime.Now.Month.ToString().PadLeft(2, '0');
  2786. // string Day = DateTime.Now.Day.ToString().PadLeft(2, '0');
  2787. // string Hour = DateTime.Now.Hour.ToString().PadLeft(2, '0');
  2788. // string Minute = DateTime.Now.Minute.ToString().PadLeft(2, '0');
  2789. // string Second = DateTime.Now.Second.ToString().PadLeft(2, '0');
  2790. // string InspectJosn = "{";
  2791. // InspectJosn += "\"ID\":\"" + Year + Month + Day + Hour + Minute + Second + "\",";
  2792. // InspectJosn += "\"PalletID\": \"" + ContainerCode + "\",";
  2793. // InspectJosn += "\"LaneCode\": \"\",";
  2794. // InspectJosn += "\"TaskType\": \"PTWY\",";
  2795. // InspectJosn += "\"SourceBin\": \"\",";
  2796. // InspectJosn += "\"DestBin\": \"" + RecomendBinCode + "\"";
  2797. // InspectJosn += "}";
  2798. // RestHelper rest = new RestHelper(ForkLiftUrl, HttpVerb.POST);
  2799. // rest.PostData = InspectJosn;
  2800. // string strResult = rest.MakeRequest();
  2801. // //string resultstr = HTTPHelper.Post(ERPUrl.AGVBineURL, InspectJosn);
  2802. // ForkLiftResult result = JsonConvert.DeserializeObject<ForkLiftResult>(strResult);
  2803. // if (result.Ret == 1)
  2804. // {
  2805. // sql = @"update ICSContainer set LocationCode='{2}',EATTRIBUTE1='已搬运' where ContainerCode='{0}' AND WorkPoint='{1}'";
  2806. // sql = string.Format(sql, ContainerCode, WorkPoint, LocationCode);
  2807. // if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2808. // {
  2809. // throw new Exception(language.GetNameByCode("WMSAPIInfo207"));//料架状态更新失败
  2810. // }
  2811. // }
  2812. // else
  2813. // {
  2814. // throw new Exception(result.RetMsg);
  2815. // }
  2816. //}
  2817. }
  2818. //else
  2819. //{
  2820. // if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  2821. // {
  2822. // string Year = DateTime.Now.Year.ToString();
  2823. // string Month = DateTime.Now.Month.ToString().PadLeft(2, '0');
  2824. // string Day = DateTime.Now.Day.ToString().PadLeft(2, '0');
  2825. // string Hour = DateTime.Now.Hour.ToString().PadLeft(2, '0');
  2826. // string Minute = DateTime.Now.Minute.ToString().PadLeft(2, '0');
  2827. // string Second = DateTime.Now.Second.ToString().PadLeft(2, '0');
  2828. // // {
  2829. // // "reqCode":"20230420150602",
  2830. // // "podCode":"200051",
  2831. // // "positionCode":"105670AA130750",
  2832. // // "indBind":"1"
  2833. // //}
  2834. // string InspectJosn = "{";
  2835. // InspectJosn += "\"reqCode\":\"" + Year + Month + Day + Hour + Minute + Second + "\",";
  2836. // InspectJosn += "\"podCode\": \"" + ContainerCode + "\",";
  2837. // InspectJosn += "\"positionCode\": \"" + LocationCode + "\",";
  2838. // InspectJosn += "\"indBind\": \"1\",";
  2839. // InspectJosn += "\"PodDir\": \"0\"";
  2840. // InspectJosn += "}";
  2841. // if (InspectJosn != "")
  2842. // {
  2843. // RestHelper rest = new RestHelper(ERPUrl.AGVBineURL, HttpVerb.POST);
  2844. // rest.PostData = InspectJosn;
  2845. // string strResult = rest.MakeRequest();
  2846. // //string resultstr = HTTPHelper.Post(ERPUrl.AGVBineURL, InspectJosn);
  2847. // AGVPodBindOutputModel result = JsonConvert.DeserializeObject<AGVPodBindOutputModel>(strResult);
  2848. // if (result.code == 0)
  2849. // {
  2850. // sql = @"update ICSContainer set LocationCode='{2}',EATTRIBUTE1='已绑定' where ContainerCode='{0}' AND WorkPoint='{1}'";
  2851. // sql = string.Format(sql, ContainerCode, WorkPoint, LocationCode);
  2852. // if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2853. // {
  2854. // throw new Exception(language.GetNameByCode("WMSAPIInfo207"));//料架状态更新失败
  2855. // }
  2856. // }
  2857. // else
  2858. // {
  2859. // throw new Exception(result.message);
  2860. // }
  2861. // }
  2862. // }
  2863. //}
  2864. }
  2865. catch (Exception)
  2866. {
  2867. throw;
  2868. }
  2869. }
  2870. /// <summary>
  2871. /// 料架条码解绑
  2872. /// </summary>
  2873. /// <param name="ContainerCode"></param>
  2874. /// <param name="WorkPoint"></param>
  2875. /// <param name="cmd"></param>
  2876. /// <param name="language"></param>
  2877. public static void ContainerUnBind(string ContainerCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2878. {
  2879. try
  2880. {
  2881. string datasql = @"select LocationCode from ICSContainer
  2882. where ContainerCode='{0}' and WorkPoint='{1}'";
  2883. datasql = string.Format(datasql, ContainerCode, WorkPoint);
  2884. DataTable datadt = DBHelper.SQlReturnData(datasql, cmd);
  2885. if (datadt.Rows.Count == 0)
  2886. {
  2887. throw new Exception(language.GetNameByCode("WMSAPIInfo207"));
  2888. }
  2889. else
  2890. {
  2891. string LocationCode = datadt.Rows[0]["LocationCode"].ToString();
  2892. string sql = @"delete from ICSContainerLot
  2893. WHERE ContainerID=
  2894. (SELECT ID FROM ICSContainer WHERE ContainerCode='{0}' AND WorkPoint='{1}')";
  2895. sql = string.Format(sql, ContainerCode, WorkPoint);
  2896. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2897. {
  2898. throw new Exception("料架:" + ContainerCode + "解绑失败!");
  2899. }
  2900. //else
  2901. //{
  2902. // if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  2903. // {
  2904. // AGVPodBindInputModel Info = new AGVPodBindInputModel();
  2905. // Info.reqCode = "5";
  2906. // Info.podCode = ContainerCode;
  2907. // Info.positionCode = LocationCode;
  2908. // Info.indBind = "0";
  2909. // string poststr = JsonConvert.SerializeObject(Info);
  2910. // string resultstr = HTTPHelper.HttpPost("AGV料架解绑", ERPUrl.AGVBineURL, poststr);
  2911. // AGVPodBindOutputModel result = JsonConvert.DeserializeObject<AGVPodBindOutputModel>(resultstr.ToString());
  2912. // if (result.code != 0)
  2913. // {
  2914. // throw new Exception(result.message);
  2915. // }
  2916. // else
  2917. // {
  2918. // sql = @"Update ICSContainer set EATTRIBUTE1='',LocationCode=''
  2919. // WHERE ContainerCode='{0}' AND WorkPoint='{1}'";
  2920. // sql = string.Format(sql, ContainerCode, WorkPoint);
  2921. // if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2922. // {
  2923. // throw new Exception(language.GetNameByCode("WMSAPIInfo207"));//料架状态更新失败
  2924. // }
  2925. // }
  2926. // }
  2927. //}
  2928. }
  2929. }
  2930. catch (Exception)
  2931. {
  2932. throw;
  2933. }
  2934. }
  2935. /// <summary>
  2936. /// 呼叫AGV开始搬运任务
  2937. /// </summary>
  2938. /// <param name="ContainerCode"></param>
  2939. /// <param name="LocationCode"></param>
  2940. /// <param name="User"></param>
  2941. /// <param name="WorkPoint"></param>
  2942. /// <param name="cmd"></param>
  2943. /// <param name="language"></param>
  2944. public static void CallAGVStartTask(string ContainerCode, string TransType, string LocationCode, string User, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2945. {
  2946. try
  2947. {
  2948. string sql = @"select ContainerCode from ICSContainer
  2949. where LocationCode='{0}' and WorkPoint='{1}'";
  2950. sql = string.Format(sql, ContainerCode, WorkPoint);
  2951. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2952. if (dt.Rows.Count == 0)
  2953. {
  2954. throw new Exception(language.GetNameByCode("WMSAPIInfo209"));//位置编码未绑定料架
  2955. }
  2956. else
  2957. {
  2958. ContainerCode = dt.Rows[0]["ContainerCode"].ToString();
  2959. }
  2960. if (TransType == "开始任务")
  2961. {
  2962. sql = @"update ICSContainer set EATTRIBUTE1='已搬运' where ContainerCode='{0}' AND WorkPoint='{1}'";
  2963. }
  2964. else
  2965. {
  2966. sql = @"update ICSContainer set EATTRIBUTE1='已绑定' where ContainerCode='{0}' AND WorkPoint='{1}'";
  2967. }
  2968. sql = string.Format(sql, ContainerCode, WorkPoint, LocationCode);
  2969. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2970. {
  2971. throw new Exception(language.GetNameByCode("WMSAPIInfo207"));//料架状态更新失败
  2972. }
  2973. //if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  2974. //{
  2975. // string Year = DateTime.Now.Year.ToString();
  2976. // string Month = DateTime.Now.Month.ToString().PadLeft(2, '0');
  2977. // string Day = DateTime.Now.Day.ToString().PadLeft(2, '0');
  2978. // string Hour = DateTime.Now.Hour.ToString().PadLeft(2, '0');
  2979. // string Minute = DateTime.Now.Minute.ToString().PadLeft(2, '0');
  2980. // string Second = DateTime.Now.Second.ToString().PadLeft(2, '0');
  2981. // AGVStartTaskModel Info = new AGVStartTaskModel();
  2982. // List<AGVStartTaskLineModel> LineList = new List<AGVStartTaskLineModel>();
  2983. // AGVStartTaskLineModel LineInfo = new AGVStartTaskLineModel();
  2984. // Info.reqCode = Year + Month + Day + Hour + Minute + Second;
  2985. // Info.podCode = ContainerCode;
  2986. // Info.taskTyp = "F01";
  2987. // LineInfo.positionCode = LocationCode;
  2988. // LineInfo.type = "00";
  2989. // LineList.Add(LineInfo);
  2990. // LineInfo = new AGVStartTaskLineModel();
  2991. // LineInfo.positionCode = "1";//目标位置编码待提供
  2992. // LineInfo.type = "04";
  2993. // LineList.Add(LineInfo);
  2994. // Info.positionCodePath = LineList;
  2995. // string poststr = JsonConvert.SerializeObject(Info);
  2996. // string resultstr = HTTPHelper.HttpPost("AGV开始任务", ERPUrl.AGVTaskStart, poststr);
  2997. // AGVStartTaskResultModel result = JsonConvert.DeserializeObject<AGVStartTaskResultModel>(resultstr.ToString());
  2998. // if (result.code == 0)
  2999. // {
  3000. // }
  3001. // else
  3002. // {
  3003. // throw new Exception(result.message);
  3004. // }
  3005. //}
  3006. }
  3007. catch (Exception)
  3008. {
  3009. throw;
  3010. }
  3011. }
  3012. /// <summary>
  3013. /// 获取AGV搬运的目标位置
  3014. /// </summary>
  3015. /// <param name="LocationCode"></param>
  3016. /// <param name="User"></param>
  3017. /// <param name="WorkPoint"></param>
  3018. /// <param name="cmd"></param>
  3019. /// <param name="language"></param>
  3020. public static string GetAGVTaskPosition(string ContainerCode, bool isOverLoad, string User, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  3021. {
  3022. try
  3023. {
  3024. string sql = @" select TOP 1 B.LotNo from ICSContainer A
  3025. INNER JOIN ICSContainerLot B ON B.ContainerID=A.ID AND B.WorkPoint=A.WorkPoint
  3026. Where A.ContainerCode='{0}' AND A.WorkPoint='{1}'
  3027. ORDER BY B.MTIME DESC";
  3028. sql = string.Format(sql, ContainerCode, WorkPoint);
  3029. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  3030. if (dt.Rows.Count == 0)
  3031. {
  3032. return "Empty";
  3033. }
  3034. else
  3035. {
  3036. sql = @"SELECT A.WHCode,C.LocationCode FROM ICSDeliveryNotice A
  3037. INNER JOIN ICSInventoryLotDetail B ON B.TransCode=A.DNCode AND B.TransSequence=A.Sequence AND B.WorkPoint=A.WorkPoint
  3038. INNER JOIN ICSInventoryDetail C ON C.INVCode=A.InvCode AND C.WHCode=A.WHCode AND C.WorkPoint=A.WorkPoint
  3039. WHERE B.LotNo='{0}' AND B.WorkPoint='{1}'";
  3040. sql = string.Format(sql, dt.Rows[0]["LotNo"].ToString(), WorkPoint);
  3041. dt = DBHelper.SQlReturnData(sql, cmd);
  3042. string InWHCode = dt.Rows[0]["WHCode"].ToString();
  3043. string InLocationCode = dt.Rows[0]["LocationCode"].ToString();
  3044. #region 根据入库仓库和区域获取按库位编码排序后可以入库的下一个库位
  3045. if (isOverLoad == false)
  3046. {
  3047. #region 正常入库
  3048. #region 获取已被超托入库占用的库位
  3049. string LocationIsTaken = "";
  3050. sql = @"SELECT A.EATTRIBUTE1 FROM ICSLocation A
  3051. LEFT JOIN ICSWareHouseLotInfo B ON B.LocationCode=A.LocationCode AND B.WorkPoint=A.WorkPoint
  3052. WHERE (ISNULL(A.EATTRIBUTE1,'')!='' AND A.LocationCode like ('{0}'+'-'+'{1}%') AND ISNULL(B.Quantity,0)>0)
  3053. OR (ISNULL(A.EATTRIBUTE1,'')!='' AND A.LocationCode like ('{0}'+'-'+'{1}%') AND ISNULL(A.Isoccupy,'')!='')";
  3054. sql = string.Format(sql, InWHCode, InLocationCode);
  3055. dt = DBHelper.SQlReturnData(sql, cmd);
  3056. foreach (DataRow dr in dt.Rows)
  3057. {
  3058. if (LocationIsTaken == "")
  3059. {
  3060. LocationIsTaken += "'" + dr["EATTRIBUTE1"].ToString().Split(',')[0] + "','" + dr["EATTRIBUTE1"].ToString().Split(',')[1] + "'";
  3061. }
  3062. else
  3063. {
  3064. LocationIsTaken += ",'" + dr["EATTRIBUTE1"].ToString().Split(',')[0] + "','" + dr["EATTRIBUTE1"].ToString().Split(',')[1] + "'";
  3065. }
  3066. }
  3067. #endregion
  3068. sql = @"select TOP 1 A.LocationCode,A.StockInArea from ICSLocation A
  3069. LEFT JOIN ICSWareHouseLotInfo B ON B.LocationCode=A.LocationCode AND B.WorkPoint=A.WorkPoint AND ISNULL(B.Quantity,0)>0
  3070. where B.LocationCode IS NULL AND A.LocationCode like ('{0}'+'-'+'{1}%') AND ISNULL(A.EATTRIBUTE1,'')=''
  3071. AND A.LocationCode NOT IN ({2}) AND ISNULL(A.Isoccupy,'')=''
  3072. ORDER BY A.LocationCode";
  3073. if (LocationIsTaken == "")
  3074. {
  3075. sql = string.Format(sql, InWHCode, InLocationCode, "''");
  3076. }
  3077. else
  3078. {
  3079. sql = string.Format(sql, InWHCode, InLocationCode, LocationIsTaken);
  3080. }
  3081. dt = DBHelper.SQlReturnData(sql, cmd);
  3082. if (dt.Rows.Count == 0)
  3083. {
  3084. throw new Exception("仓库:" + InWHCode + ",区域:" + InLocationCode + "无可用库位,无法入库!");
  3085. }
  3086. else
  3087. {
  3088. #region 更新库位表Isoccupy字段以作占用
  3089. string occupysql = @"Update ICSLocation set Isoccupy='{2}'
  3090. where LocationCode='{0}' AND WorkPoint='{1}'";
  3091. occupysql = string.Format(occupysql, dt.Rows[0]["LocationCode"].ToString(), WorkPoint, ContainerCode);
  3092. DBHelper.ExecuteNonQuery(occupysql, cmd);
  3093. #endregion
  3094. return dt.Rows[0]["StockInArea"].ToString();
  3095. }
  3096. #endregion
  3097. }
  3098. else
  3099. {
  3100. #region 超托入库
  3101. #region 获取已被正常入库占用的库位
  3102. string LocationIsTaken = "";
  3103. sql = @"SELECT A.LocationCode,A.WorkPoint INTO #tempLocation FROM ICSLocation A
  3104. LEFT JOIN ICSWareHouseLotInfo B ON B.LocationCode=A.LocationCode AND B.WorkPoint=A.WorkPoint
  3105. WHERE ISNULL(A.EATTRIBUTE1,'') = '' AND A.LocationCode like ('{0}'+'-'+'{1}%') AND ISNULL(B.Quantity,0)>0
  3106. OR (ISNULL(A.EATTRIBUTE1,'') = '' AND A.LocationCode like ('{0}'+'-'+'{1}%') AND ISNULL(A.Isoccupy,'')!='')
  3107. SELECT * INTO #tempOverLoad FROM ICSLocationOverLoad WHERE LocationCode like ('{0}'+'-'+'{1}%')
  3108. select Distinct A.OverLoadLocationCode from #tempOverLoad A
  3109. INNER JOIN #tempLocation B ON B.LocationCode=A.LocationCode AND B.WorkPoint=A.WorkPoint
  3110. drop table #tempLocation
  3111. drop table #tempOverLoad";
  3112. sql = string.Format(sql, InWHCode, InLocationCode);
  3113. dt = DBHelper.SQlReturnData(sql, cmd);
  3114. foreach (DataRow dr in dt.Rows)
  3115. {
  3116. if (LocationIsTaken == "")
  3117. {
  3118. LocationIsTaken += "'" + dr["OverLoadLocationCode"].ToString() + "'";
  3119. }
  3120. else
  3121. {
  3122. LocationIsTaken += ",'" + dr["OverLoadLocationCode"].ToString() + "'";
  3123. }
  3124. }
  3125. #endregion
  3126. sql = @"select TOP 1 A.LocationCode,A.StockInArea from ICSLocation A
  3127. LEFT JOIN ICSWareHouseLotInfo B ON B.LocationCode=A.LocationCode AND B.WorkPoint=A.WorkPoint AND ISNULL(B.Quantity,0)>0
  3128. where B.LocationCode IS NULL AND A.LocationCode like ('{0}'+'-'+'{1}%') AND ISNULL(A.EATTRIBUTE1,'')!=''
  3129. AND A.EATTRIBUTE1 NOT IN ({2}) AND ISNULL(A.Isoccupy,'')=''
  3130. ORDER BY A.LocationCode";
  3131. sql = string.Format(sql, InWHCode, InLocationCode, LocationIsTaken);
  3132. dt = DBHelper.SQlReturnData(sql, cmd);
  3133. if (dt.Rows.Count == 0)
  3134. {
  3135. throw new Exception("仓库:" + InWHCode + ",区域:" + InLocationCode + "无可用库位,无法入库!");
  3136. }
  3137. else
  3138. {
  3139. #region 更新库位表Isoccupy字段以作占用
  3140. string occupysql = @"Update ICSLocation set Isoccupy='{2}'
  3141. where LocationCode='{0}' AND WorkPoint='{1}'";
  3142. occupysql = string.Format(occupysql, dt.Rows[0]["LocationCode"].ToString(), WorkPoint, ContainerCode);
  3143. DBHelper.ExecuteNonQuery(occupysql, cmd);
  3144. #endregion
  3145. return dt.Rows[0]["StockInArea"].ToString();
  3146. }
  3147. #endregion
  3148. }
  3149. #endregion
  3150. }
  3151. }
  3152. catch (Exception)
  3153. {
  3154. throw;
  3155. }
  3156. }
  3157. /// <summary>
  3158. /// 保存AGV任务ID
  3159. /// </summary>
  3160. /// <param name="LocationCode"></param>
  3161. /// <param name="User"></param>
  3162. /// <param name="WorkPoint"></param>
  3163. /// <param name="cmd"></param>
  3164. /// <param name="language"></param>
  3165. public static void ActionSaveAGVTaskCode(string data, string TaskCode, string ContainerCode, string Location, bool IsOverLoad, string TransType, string User, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  3166. {
  3167. try
  3168. {
  3169. string sql = @" IF EXISTS(SELECT * FROM ICSAGVTaskLog WHERE TaskCode='{0}' AND WorkPoint='{5}')
  3170. BEGIN
  3171. RAISERROR('',16,1);
  3172. RETURN
  3173. END
  3174. Insert into ICSAGVTaskLog
  3175. (ID,TaskCode,ContainerCode,LocationCode,IsOverLoad,UserCode,MTIME,WorkPoint,EATTRIBUTE1)
  3176. select '{7}','{0}','{1}','{2}','{3}','{4}',GETDATE(),'{5}','{6}'";
  3177. if (IsOverLoad == true)
  3178. {
  3179. sql = string.Format(sql, TaskCode, ContainerCode, Location, "是", User, WorkPoint, TransType,data);
  3180. }
  3181. else
  3182. {
  3183. sql = string.Format(sql, TaskCode, ContainerCode, Location, "否", User, WorkPoint, TransType, data);
  3184. }
  3185. DBHelper.ExecuteNonQuery(sql, cmd);
  3186. }
  3187. catch (Exception ex)
  3188. {
  3189. throw new Exception(ex.Message);
  3190. }
  3191. }
  3192. /// <summary>
  3193. /// AGV搬运完成回调
  3194. /// </summary>
  3195. /// <param name="LocationCode"></param>
  3196. /// <param name="User"></param>
  3197. /// <param name="WorkPoint"></param>
  3198. /// <param name="cmd"></param>
  3199. /// <param name="language"></param>
  3200. public static void ActionAGVTaskEnd(string reqCode, string currentPositionCode, string taskCode, string action, string podCode, SqlCommand cmd, Dictionary<string, string> language)
  3201. {
  3202. try
  3203. {
  3204. #region 根据任务ID查询是否需要超托入库
  3205. string ContainerCode = "";
  3206. string InLocationCode = "";
  3207. string sql = @"select ContainerCode,LocationCode,IsOverLoad from ICSAGVTaskLog
  3208. where ID='{0}'";
  3209. sql = string.Format(sql, reqCode);
  3210. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  3211. if (dt.Rows.Count == 0)
  3212. {
  3213. throw new Exception("未查询到对应的任务ID:" + reqCode + "!");
  3214. }
  3215. else
  3216. {
  3217. ContainerCode = dt.Rows[0]["ContainerCode"].ToString();
  3218. #region 根据料架查询事先占用的库位直接传给叉车
  3219. sql = @"select LocationCode from ICSLocation
  3220. where Isoccupy='{0}'";
  3221. sql = string.Format(sql, ContainerCode);
  3222. dt = DBHelper.SQlReturnData(sql, cmd);
  3223. if (dt.Rows.Count == 0)
  3224. {
  3225. throw new Exception("未查询到料架:" + ContainerCode + ",对应的入库库位!");
  3226. }
  3227. else
  3228. {
  3229. InLocationCode = dt.Rows[0]["LocationCode"].ToString();
  3230. #region 叉车接口调用
  3231. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadForkLift"]))
  3232. {
  3233. string ForkLiftUrl = System.Configuration.ConfigurationManager.AppSettings["ForkLiftUrl"];
  3234. string Year = DateTime.Now.Year.ToString();
  3235. string Month = DateTime.Now.Month.ToString().PadLeft(2, '0');
  3236. string Day = DateTime.Now.Day.ToString().PadLeft(2, '0');
  3237. string Pre = "CC" + Year + Month + Day;
  3238. string serialsql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  3239. serialsql = string.Format(serialsql, "1701", "ICSForkLiftTaskLog", "TaskCode", Pre, 4);
  3240. string TaskCode = DBHelper.SQlReturnData(serialsql, cmd).Rows[0][0].ToString();
  3241. string SerialNum = DateTime.Now.Hour.ToString().PadLeft(2, '0');
  3242. string InspectJosn = "{";
  3243. InspectJosn += "\"TaskID\":\"" + TaskCode + "\",";//任务编号
  3244. InspectJosn += "\"PalletID\": \"" + ContainerCode + "\",";//料架号
  3245. //InspectJosn += "\"LaneCode\": \"\",";
  3246. InspectJosn += "\"TaskType\": \"PTWY\",";//任务类型
  3247. InspectJosn += "\"SourceBin\": \"" + currentPositionCode + "\",";//起始点位
  3248. InspectJosn += "\"DestBin\": \"" + InLocationCode + "\"";//目标点位
  3249. InspectJosn += "}";
  3250. RestHelper rest = new RestHelper(ForkLiftUrl, HttpVerb.POST);
  3251. rest.PostData = InspectJosn;
  3252. string strResult = rest.MakeRequest();
  3253. //string resultstr = HTTPHelper.Post(ERPUrl.AGVBineURL, InspectJosn);
  3254. ForkLiftResult result = JsonConvert.DeserializeObject<ForkLiftResult>(strResult);
  3255. if (result.Ret == 1)
  3256. {
  3257. #region 记录叉车的任务编号及相关信息
  3258. sql = @"INSERT INTO ICSForkLiftTaskLog
  3259. (ID,TaskCode,ContainerCode,TaskType,StartLocation,EndLocation,MTIME,WorkPoint)
  3260. select NEWID(),'{0}','{1}','PTWY','{2}','{3}',GETDATE(),'1701'
  3261. Update ICSAGVCallBackLog set Result='',Message=''
  3262. where ReqCode='{4}'";
  3263. sql = string.Format(sql, TaskCode, ContainerCode, currentPositionCode, dt.Rows[0]["LocationCode"].ToString(), reqCode);
  3264. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3265. {
  3266. //throw new Exception("任务编码:" + TaskCode + ",日志记录失败");//料架状态更新失败
  3267. }
  3268. #endregion
  3269. }
  3270. else
  3271. {
  3272. throw new Exception(result.RetMsg);
  3273. }
  3274. }
  3275. #endregion
  3276. }
  3277. #endregion
  3278. }
  3279. #endregion
  3280. }
  3281. catch (Exception ex)
  3282. {
  3283. throw new Exception(ex.Message);
  3284. }
  3285. }
  3286. /// <summary>
  3287. /// 叉车搬运完成回调
  3288. /// </summary>
  3289. /// <param name="TaskID"></param>
  3290. /// <param name="cmd"></param>
  3291. /// <param name="language"></param>
  3292. public static void ActionForkLiftTaskEnd(string TaskID, string TaskType, string DestBin, SqlCommand cmd, Dictionary<string, string> language)
  3293. {
  3294. try
  3295. {
  3296. if (TaskType == "PTWY")
  3297. {
  3298. #region 入库
  3299. #region 获取任务ID相关的料架条码及目标库位信息
  3300. string ContainerCode = "";
  3301. string StartLocation = "";
  3302. string EndLocation = "";
  3303. string sql = @"select ContainerCode,StartLocation,EndLocation from ICSForkLiftTaskLog
  3304. where TaskCode='{0}'";
  3305. sql = string.Format(sql, TaskID);
  3306. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  3307. if (dt.Rows.Count == 0)
  3308. {
  3309. throw new Exception("任务ID:" + TaskID + ",未查询到相关任务记录,无法入库!");
  3310. }
  3311. else
  3312. {
  3313. ContainerCode = dt.Rows[0]["ContainerCode"].ToString();
  3314. StartLocation = dt.Rows[0]["StartLocation"].ToString();
  3315. EndLocation = dt.Rows[0]["EndLocation"].ToString();
  3316. }
  3317. #endregion
  3318. #region 根据条码获取入库单据信息
  3319. string chksql = @"select COUNT(B.LotNo) AS LotCount from ICSContainer A
  3320. INNER JOIN ICSContainerLot B ON B.ContainerID=A.ID AND B.WorkPoint=A.WorkPoint
  3321. WHERE ContainerCode='{0}'";
  3322. chksql = string.Format(chksql, ContainerCode);
  3323. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  3324. sql = @"select E.DNCode AS TransNO,E.Sequence AS TransLine,C.LotNo,C.Quantity,'采购入库' AS DocType
  3325. ,A.WorkPoint,C.InvCode from ICSContainer A
  3326. INNER JOIN ICSContainerLot B ON B.ContainerID=A.ID AND B.WorkPoint=A.WorkPoint
  3327. INNER JOIN ICSInventoryLot C ON C.LotNo=B.LotNo AND C.WorkPoint=B.WorkPoint
  3328. INNER JOIN ICSInventoryLotDetail D ON D.LotNo=C.LotNo AND D.WorkPoint=C.WorkPoint
  3329. INNER JOIN ICSDeliveryNotice E ON E.DNCode=D.TransCode AND E.Sequence=D.TransSequence AND E.WorkPoint=D.WorkPoint
  3330. where A.ContainerCode='{0}'
  3331. UNION ALL
  3332. select E.ApplyNegCode AS TransNO,E.Sequence AS TransLine,C.LotNo,C.Quantity,'退' AS DocType
  3333. ,A.WorkPoint,C.InvCode from ICSContainer A
  3334. INNER JOIN ICSContainerLot B ON B.ContainerID=A.ID AND B.WorkPoint=A.WorkPoint
  3335. INNER JOIN ICSInventoryLot C ON C.LotNo=B.LotNo AND C.WorkPoint=B.WorkPoint
  3336. INNER JOIN ICSInventoryLotDetail D ON D.LotNo=C.LotNo AND D.WorkPoint=C.WorkPoint
  3337. INNER JOIN ICSMOApplyNegDetail E ON E.ApplyNegCode=D.TransCode AND E.Sequence=D.TransSequence AND E.WorkPoint=D.WorkPoint
  3338. where A.ContainerCode='{0}'";
  3339. sql = string.Format(sql, ContainerCode);
  3340. dt = DBHelper.SQlReturnData(sql, cmd);
  3341. if (Convert.ToInt32(chkdt.Rows[0]["LotCount"]) != dt.Rows.Count)
  3342. {
  3343. throw new Exception("料架:" + ContainerCode + ",绑定条码的数量与实际查到的条码单据关联数据不符,请确认条码信息!");
  3344. }
  3345. #endregion
  3346. else
  3347. {
  3348. #region WMS入库
  3349. string Identification = Guid.NewGuid().ToString();
  3350. string BusinessCode = string.Empty;
  3351. foreach (DataRow dr in dt.Rows)
  3352. {
  3353. if (dr["DocType"].ToString() == "采购入库")
  3354. {
  3355. #region 采购入库
  3356. ICSPurchaseService.DeliveryNoticeIn(dr["LotNo"].ToString(), dr["Quantity"].ToString(), dr["WorkPoint"].ToString(), cmd, language);
  3357. BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription<DBValue>();
  3358. #endregion
  3359. }
  3360. else
  3361. {
  3362. #region 生产退料入库
  3363. ICSManufactureService.MOIssueDocNegative(TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  3364. , "", dr["LotNo"].ToString(), dr["Quantity"].ToString(), dr["WorkPoint"].ToString(), cmd, language);
  3365. BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>();
  3366. #endregion
  3367. }
  3368. WareHouseLotInfoUp(Identification, EndLocation, dr["LotNo"].ToString(), dr["Quantity"].ToString(),
  3369. "ForkLift", dr["WorkPoint"].ToString(), "2", BusinessCode
  3370. , cmd, language, "", dr["InvCode"].ToString() + EndLocation.Split('-')[0].ToString()
  3371. , DateTime.Now.ToString());
  3372. }
  3373. #endregion
  3374. #region 入库完成后解除料架对库位的占用
  3375. string occupysql = @"Update ICSLocation set Isoccupy=''
  3376. where LocationCode='{0}'";
  3377. occupysql = string.Format(occupysql, EndLocation);
  3378. DBHelper.ExecuteNonQuery(sql, cmd);
  3379. #endregion
  3380. }
  3381. #region 判断单据是否全部完成入库,并过账SAP
  3382. string docsql = @"select DISTINCT E.DNCode AS TransNO,'采购入库' AS DocType,A.WorkPoint from ICSContainer A
  3383. INNER JOIN ICSContainerLot B ON B.ContainerID=A.ContainerID AND B.WorkPoint=A.WorkPoint
  3384. INNER JOIN ICSInventoryLot C ON C.LotNo=B.LotNo AND C.WorkPoint=B.WorkPoint
  3385. INNER JOIN ICSInventoryLotDetail D ON D.LotNo=C.LotNo AND D.WorkPoint=C.WorkPoint
  3386. INNER JOIN ICSDeliveryNotice E ON E.DNCode=D.TransCode AND E.Sequence=D.TransSequence AND E.WorkPoint=D.WorkPoint
  3387. where A.ContainerCode='{0}'
  3388. UNION ALL
  3389. select DISTINCT E.ApplyNegCode AS TransNO,'退' AS DocType,A.WorkPoint from ICSContainer A
  3390. INNER JOIN ICSContainerLot B ON B.ContainerID=A.ContainerID AND B.WorkPoint=A.WorkPoint
  3391. INNER JOIN ICSInventoryLot C ON C.LotNo=B.LotNo AND C.WorkPoint=B.WorkPoint
  3392. INNER JOIN ICSInventoryLotDetail D ON D.LotNo=C.LotNo AND D.WorkPoint=C.WorkPoint
  3393. INNER JOIN ICSMOApplyNegDetail E ON E.ApplyNegCode=D.TransCode AND E.Sequence=D.TransSequence AND E.WorkPoint=D.WorkPoint
  3394. where A.ContainerCode='{0}'";
  3395. docsql = string.Format(docsql, ContainerCode);
  3396. DataTable docdt = DBHelper.SQlReturnData(sql, cmd);
  3397. foreach (DataRow dr in docdt.Rows)
  3398. {
  3399. if (dr["DocType"].ToString() == "采购入库")
  3400. {
  3401. #region 检验合格单过账SAP(检验合格单为两层结构 一行对应一个序列号)
  3402. chksql = @"select SUM(Quantity) AS Quantity,SUM(RCVQuantity) AS RCVQuantity from ICSDeliveryNotice
  3403. where DNCode='{0}' and WorkPoint='{1}'
  3404. GROUP BY DNCode,WorkPoint";
  3405. chksql = string.Format(chksql, dr["TransNO"].ToString(), dr["WorkPoint"].ToString());
  3406. chkdt = DBHelper.SQlReturnData(chksql, cmd);
  3407. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) != Convert.ToDecimal(chkdt.Rows[0]["RCVQuantity"]))
  3408. {
  3409. continue;
  3410. }
  3411. sql = @"select A.DNCode,
  3412. CASE WHEN SUM(Convert(decimal(18,6),A.SAPSequence)) IS NULL THEN SUM(A.RCVQuantity)
  3413. ELSE SUM(Convert(decimal(18,6),A.SAPSequence)) END AS RCVQuantity,B.BatchCode from ICSDeliveryNotice A
  3414. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  3415. WHERE DNCode='{0}' AND A.WorkPoint='{1}'
  3416. GROUP BY A.DNCode,B.BatchCode";
  3417. sql = string.Format(sql, dr["TransNO"].ToString(), dr["WorkPoint"].ToString());
  3418. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  3419. if (Sapdt.Rows.Count == 0)
  3420. {
  3421. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo205"), dr["TransNO"].ToString()));//单据查询失败
  3422. }
  3423. SAPCallBackJYHGDCS.ZWMS_SK_WS_RUKU Client = new SAPCallBackJYHGDCS.ZWMS_SK_WS_RUKU();
  3424. SAPCallBackJYHGDCS.ZWMS_SK_WS_RUKU1 Info = new SAPCallBackJYHGDCS.ZWMS_SK_WS_RUKU1();
  3425. Info.NEWID = Guid.NewGuid().ToString();
  3426. Info.PRUEFLOS = Sapdt.Rows[0]["DNCode"].ToString();
  3427. Info.L_LME = System.Decimal.Round(Convert.ToDecimal(Sapdt.Rows[0]["RCVQuantity"].ToString()), 3);
  3428. Info.SERNP = Sapdt.Rows[0]["BatchCode"].ToString();
  3429. Info.Z_GERNR = new SAPCallBackJYHGDCS.ZWEBS_GERNR[0];
  3430. SAPCallBackJYHGDCS.ZWMS_SK_WS_RUKUResponse result = new SAPCallBackJYHGDCS.ZWMS_SK_WS_RUKUResponse();
  3431. result = Client.CallZWMS_SK_WS_RUKU(Info);
  3432. if (result.Z_NULL == "N")
  3433. {
  3434. string logsql = @"insert into ICSWMSCallSAPErrorLog
  3435. (ID,DocType,DocNO,WorkPoint,MTIME,WorkType,EATTRIBUTE1)
  3436. Select NEWID(),'{0}','{1}','{2}',GETDATE(),'','{3}'";
  3437. logsql = string.Format(logsql, "采购入库", dr["TransNO"].ToString(), dr["WorkPoint"].ToString()
  3438. , result.L_MESSAGE);
  3439. DBHelper.ExecuteNonQuery(logsql, cmd);
  3440. }
  3441. #endregion
  3442. }
  3443. else
  3444. {
  3445. #region SAP(三层结构)
  3446. string ErrorMessage = "";
  3447. chksql = @"select SUM(B.Quantity) AS Quantity,SUM(B.IssueNegQuantity) AS IssueQuantity from ICSMOApplyNeg A
  3448. LEFT JOIN ICSMOApplyNegDetail B ON B.ApplyNegCode=A.ApplyNegCode AND B.WorkPoint=A.WorkPoint
  3449. where A.ApplyNegCode='{0}' and A.WorkPoint='{1}'
  3450. GROUP BY A.ApplyNegCode,A.WorkPoint";
  3451. chksql = string.Format(chksql, dr["TransNO"].ToString(), dr["WorkPoint"].ToString());
  3452. chkdt = DBHelper.SQlReturnData(chksql, cmd);
  3453. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) == Convert.ToDecimal(chkdt.Rows[0]["IssueQuantity"]))
  3454. {
  3455. SAPCallBackDocVPNCS.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPNCS.ZWMS_SK_WS_PZ();
  3456. SAPCallBackDocVPNCS.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPNCS.ZWMS_SK_WS_PZ1();
  3457. Info.NEWID = Guid.NewGuid().ToString();
  3458. Info.DANJU = dr["TransNO"].ToString();
  3459. Info.STATE = "0";
  3460. List<SAPCallBackDocVPNCS.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPNCS.ZWMS_PZ>();
  3461. List<SAPCallBackDocVPNCS.ZWEBS_GERNR> ItemLineList = new List<SAPCallBackDocVPNCS.ZWEBS_GERNR>();
  3462. Info.Z_FLAG = new SAPCallBackDocVPNCS.ZWEB_RETURN[1];
  3463. sql = @" select A.ApplyNegCode,B.SAPSequence,B.InvCode,B.Sequence,B.Quantity,B.IssueNegQuantity
  3464. ,ISNULL(C.BatchCode,'') AS BatchCode from ICSMOApplyNeg A
  3465. LEFT JOIN ICSMOApplyNegDetail B ON B.ApplyNegCode=A.ApplyNegCode AND B.WorkPoint=A.WorkPoint
  3466. LEFT JOIN ICSExtension C ON C.ID=B.ExtensionID AND C.WorkPoint=B.WorkPoint
  3467. WHERE A.ApplyNegCode='{0}' AND A.WorkPoint='{1}'";
  3468. sql = string.Format(sql, dr["TransNO"].ToString(), dr["WorkPoint"].ToString());
  3469. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  3470. foreach (DataRow drs in Sapdt.Rows)
  3471. {
  3472. if (Convert.ToDecimal(drs["Quantity"].ToString()) == Convert.ToDecimal(drs["IssueNegQuantity"].ToString()))
  3473. {
  3474. SAPCallBackDocVPNCS.ZWMS_PZ Item = new SAPCallBackDocVPNCS.ZWMS_PZ();
  3475. SAPCallBackDocVPNCS.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPNCS.ZWEBS_GERNR();
  3476. Item.DANJU = drs["ApplyNegCode"].ToString();
  3477. Item.POSNR = drs["SAPSequence"].ToString();
  3478. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(drs["Quantity"].ToString()), 3);
  3479. ItemList.Add(Item);
  3480. if (drs["BatchCode"].ToString() != "")
  3481. {
  3482. ItemLine.DANJU = drs["ApplyNegCode"].ToString();
  3483. ItemLine.POSNR = drs["SAPSequence"].ToString();
  3484. ItemLine.MATNR = drs["InvCode"].ToString();
  3485. ItemLine.GERNR = drs["BatchCode"].ToString();
  3486. ItemLineList.Add(ItemLine);
  3487. }
  3488. }
  3489. }
  3490. if (ItemList.Count > 0)
  3491. {
  3492. Info.Z_ITEM = ItemList.ToArray();
  3493. if (ItemLineList.Count > 0)
  3494. {
  3495. Info.Z_GERNR = ItemLineList.ToArray();
  3496. }
  3497. else
  3498. {
  3499. Info.Z_GERNR = new SAPCallBackDocVPNCS.ZWEBS_GERNR[1];
  3500. }
  3501. SAPCallBackDocVPNCS.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPNCS.ZWMS_SK_WS_PZResponse();
  3502. result = Client.CallZWMS_SK_WS_PZ(Info);
  3503. if (result.Z_NULL == "N")
  3504. {
  3505. foreach (SAPCallBackDocVPNCS.ZWEB_RETURN resultItem in result.Z_FLAG)
  3506. {
  3507. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  3508. }
  3509. string logsql = @"insert into ICSWMSCallSAPErrorLog
  3510. (ID,DocType,DocNO,WorkPoint,MTIME,WorkType,EATTRIBUTE1)
  3511. Select NEWID(),'{0}','{1}','{2}',GETDATE(),'','{3}'";
  3512. logsql = string.Format(logsql, "生产退料", dr["TransNO"].ToString(), dr["WorkPoint"].ToString()
  3513. , ErrorMessage);
  3514. DBHelper.ExecuteNonQuery(logsql, cmd);
  3515. }
  3516. }
  3517. }
  3518. #endregion
  3519. }
  3520. }
  3521. #endregion
  3522. #region 呼叫AGV将料架搬运至空料架区
  3523. string areasql = @" select F_Define1 from Sys_SRM_ItemsDetail
  3524. where F_ItemName='EmptyPodArea'";
  3525. DataTable areadt = DBHelper.SQlReturnData(areasql, cmd);
  3526. string Year = DateTime.Now.Year.ToString();
  3527. string Month = DateTime.Now.Month.ToString().PadLeft(2, '0');
  3528. string Day = DateTime.Now.Day.ToString().PadLeft(2, '0');
  3529. string Hour = DateTime.Now.Hour.ToString().PadLeft(2, '0');
  3530. string Minute = DateTime.Now.Minute.ToString().PadLeft(2, '0');
  3531. string Second = DateTime.Now.Second.ToString().PadLeft(2, '0');
  3532. ServiceCallAgvTask.CallAgvTaskTaskData AGVInfo = new ServiceCallAgvTask.CallAgvTaskTaskData();
  3533. List<ServiceCallAgvTask.CallAgvTaskpositionCodePath> AGVLineList = new List<ServiceCallAgvTask.CallAgvTaskpositionCodePath>();
  3534. ServiceCallAgvTask.CallAgvTaskpositionCodePath AGVLineInfo = new ServiceCallAgvTask.CallAgvTaskpositionCodePath();
  3535. AGVInfo.reqCode = Year + Month + Day + Hour + Minute + Second;
  3536. AGVInfo.podCode = ContainerCode;
  3537. AGVInfo.taskTyp = "F02";
  3538. AGVLineInfo.positionCode = StartLocation;
  3539. AGVLineInfo.type = "00";
  3540. AGVLineList.Add(AGVLineInfo);
  3541. AGVLineInfo = new ServiceCallAgvTask.CallAgvTaskpositionCodePath();
  3542. AGVLineInfo.positionCode = areadt.Rows[0]["F_Define1"].ToString();//空料架区位置编码待提供
  3543. AGVLineInfo.type = "04";
  3544. AGVLineList.Add(AGVLineInfo);
  3545. AGVInfo.positionCodePath = AGVLineList.ToArray();
  3546. ServiceCallAgvTask.CallAgvTaskOperationResult agvresult = new ServiceCallAgvTask.CallAgvTaskOperationResult();
  3547. ServiceCallAgvTask.StartAgvTaskClient client = new ServiceCallAgvTask.StartAgvTaskClient();
  3548. agvresult = client.StartCallAgvTask(AGVInfo);
  3549. if (agvresult.code != 0)
  3550. {
  3551. throw new Exception(agvresult.message);
  3552. }
  3553. #endregion
  3554. #endregion
  3555. }
  3556. else if (TaskType == "PICK")
  3557. {
  3558. #region 出库(仅记录叉车搬运到的出库点位,用于后面的回库)
  3559. string sql = @" Update ICSForkLiftTaskLog SET EndLocation='{0}'
  3560. where TaskCode='{1}'";
  3561. sql = string.Format(sql, DestBin, TaskID);
  3562. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3563. {
  3564. //throw new Exception("任务编码:" + TaskCode + ",日志记录失败");//料架状态更新失败
  3565. }
  3566. #endregion
  3567. }
  3568. }
  3569. catch (Exception ex)
  3570. {
  3571. throw new Exception(ex.Message);
  3572. }
  3573. }
  3574. /// <summary>
  3575. /// 料架单据绑定
  3576. /// </summary>
  3577. /// <param name="LotNo"></param>
  3578. /// <param name="ContainerCode"></param>
  3579. /// <param name="User"></param>
  3580. /// <param name="WorkPoint"></param>
  3581. /// <param name="cmd"></param>
  3582. /// <param name="language"></param>
  3583. public static void ContainerTransCodeBind(List<string> tranCodes, string containerCode, string User, SqlCommand cmd, Dictionary<string, string> language)
  3584. {
  3585. try
  3586. {
  3587. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' )
  3588. BEGIN
  3589. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  3590. RETURN
  3591. END
  3592. IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCode='{0}' )
  3593. BEGIN
  3594. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo473"), "", "{0}") + @"',16,1);
  3595. RETURN
  3596. END;
  3597. SELECT top 1 Desks FROM ICSMOApply WHERE ApplyCode='{2}'
  3598. ";
  3599. sql = string.Format(sql, containerCode, User, tranCodes.FirstOrDefault());
  3600. var table = DBHelper.SQlReturnData(sql, cmd);
  3601. if (table.Rows.Count <= 0)
  3602. {
  3603. throw new Exception("单据对应的工位不存在,操作失败");
  3604. }
  3605. foreach (string tranCode in tranCodes)
  3606. {
  3607. string sqlCheck = @"IF NOT EXISTS( SELECT ID FROM ICSMOApply WHERE ApplyCode='{0}' AND Desks='{1}')
  3608. BEGIN
  3609. RAISERROR('" + language.GetNameByCode("WMSAPIInfo477") + @"',16,1);
  3610. RETURN
  3611. END;
  3612. IF EXISTS(select ID from ICSContainerReceiptsNumber where TransCode='{0}' AND EATTRIBUTE5='')
  3613. BEGIN
  3614. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo479"), "{0}", "{2}") + @"',16,1);
  3615. RETURN
  3616. END;
  3617. INSERT INTO ICSContainerReceiptsNumber SELECT NEWID(),'{0}','{2}',F_Account,F_RealName,GETDATE(),NULL,NULL,NULL,NULL,'' FROM Sys_SRM_User WHERE F_Account='{3}' ";
  3618. sqlCheck = string.Format(sqlCheck, tranCode, table.Rows[0]["Desks"].ToString(), containerCode, User);
  3619. if (!DBHelper.ExecuteNonQuery(sqlCheck, cmd))
  3620. {
  3621. throw new Exception("单据新增失败");
  3622. }
  3623. }
  3624. }
  3625. catch (Exception ex)
  3626. {
  3627. throw ex;
  3628. }
  3629. }
  3630. /// <summary>
  3631. /// 根据条码获取仓库和区域信息
  3632. /// </summary>
  3633. /// <param name="LotNo"></param>
  3634. /// <param name="cmd"></param>
  3635. public static DataTable GetWHCodeArea(string LotNo, SqlCommand cmd)
  3636. {
  3637. try
  3638. {
  3639. string check = $@"SELECT C.WHCode,C.LocationCode FROM ICSInventoryLotDetail A
  3640. INNER JOIN ICSDeliveryNotice B ON B.DNCode=A.TransCode AND B.Sequence=A.TransSequence AND B.WorkPoint=A.WorkPoint
  3641. INNER JOIN ICSInventoryDetail C ON C.INVCode=B.InvCode AND C.WHCode=B.WHCode AND C.WorkPoint=B.WorkPoint
  3642. WHERE A.LotNo='{LotNo}'
  3643. UNION ALL
  3644. SELECT C.WHCode,C.LocationCode FROM ICSInventoryLotDetail A
  3645. INNER JOIN ICSMOApplyNegDetail B ON B.ApplyNegCode=A.TransCode AND B.Sequence=A.TransSequence AND B.WorkPoint=A.WorkPoint
  3646. INNER JOIN ICSInventoryDetail C ON C.INVCode=B.InvCode AND C.WHCode=B.WHCode AND C.WorkPoint=B.WorkPoint
  3647. WHERE A.LotNo='{LotNo}'";
  3648. var table = DBHelper.SQlReturnData(check, cmd);
  3649. return table;
  3650. }
  3651. catch (Exception ex)
  3652. {
  3653. throw ex;
  3654. }
  3655. }
  3656. /// <summary>
  3657. /// 叉车回库调用叉车搬运接口
  3658. /// </summary>
  3659. /// <param name="TaskID"></param>
  3660. /// <param name="cmd"></param>
  3661. /// <param name="language"></param>
  3662. public static void ActionMaterialBack(string GUID, string OutPosition, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  3663. {
  3664. try
  3665. {
  3666. #region 回库
  3667. #region 根据出库点位获取回库库位
  3668. string sql = @"select TaskCode,StartLocation from ICSForkLiftTaskLog
  3669. where EndLocation='{0}' AND WorkPoint='{1}' AND ISNULL(EATTRIBUTE1,'')=''";
  3670. sql = string.Format(sql, OutPosition, WorkPoint);
  3671. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  3672. if (dt.Rows.Count == 0)
  3673. {
  3674. throw new Exception("出库点位未查询到相关的未回库记录,无法回库!");
  3675. }
  3676. else
  3677. {
  3678. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadForkLift"]))
  3679. {
  3680. string ForkLiftUrl = System.Configuration.ConfigurationManager.AppSettings["ForkLiftUrl"];
  3681. string Year = DateTime.Now.Year.ToString();
  3682. string Month = DateTime.Now.Month.ToString().PadLeft(2, '0');
  3683. string Day = DateTime.Now.Day.ToString().PadLeft(2, '0');
  3684. string Pre = "CC" + Year + Month + Day;
  3685. string serialsql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  3686. serialsql = string.Format(serialsql, "1701", "ICSForkLiftTaskLog", "TaskCode", Pre, 4);
  3687. string TaskCode = DBHelper.SQlReturnData(serialsql, cmd).Rows[0][0].ToString();
  3688. string SerialNum = DateTime.Now.Hour.ToString().PadLeft(2, '0');
  3689. string InspectJosn = "{";
  3690. InspectJosn += "\"TaskID\":\"" + TaskCode + "\",";//任务编号
  3691. //InspectJosn += "\"PalletID\": \"" + ContainerCode + "\",";//料架号
  3692. //InspectJosn += "\"LaneCode\": \"\",";
  3693. InspectJosn += "\"TaskType\": \"RETN\",";//任务类型
  3694. InspectJosn += "\"SourceBin\": \"" + OutPosition + "\",";//起始点位
  3695. InspectJosn += "\"DestBin\": \"" + dt.Rows[0]["StartLocation"].ToString() + "\"";//目标点位
  3696. InspectJosn += "}";
  3697. RestHelper rest = new RestHelper(ForkLiftUrl, HttpVerb.POST);
  3698. rest.PostData = InspectJosn;
  3699. string strResult = rest.MakeRequest();
  3700. string resultstr = HTTPHelper.Post(ERPUrl.ForkLiftTaskStart, InspectJosn);
  3701. ForkLiftResult result = JsonConvert.DeserializeObject<ForkLiftResult>(strResult);
  3702. if (result.Ret == 1)
  3703. {
  3704. #region 记录叉车的任务编号及相关信息
  3705. sql = @"INSERT INTO ICSForkLiftTaskLog
  3706. (ID,TaskCode,ContainerCode,TaskType,StartLocation,EndLocation,MTIME,WorkPoint)
  3707. select NEWID(),'{0}','','RETN','{1}','{2}',GETDATE(),'1701'
  3708. update ICSForkLiftTaskLog SET EATTRIBUTE1=''
  3709. where TaskCode='{4}'
  3710. Update ICSForkLiftMaterialBackLog set Result='',Message=''
  3711. where ID='{3}'";
  3712. sql = string.Format(sql, TaskCode, OutPosition, dt.Rows[0]["StartLocation"].ToString(), GUID, dt.Rows[0]["TaskCode"].ToString());
  3713. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3714. {
  3715. //throw new Exception("任务编码:" + TaskCode + ",日志记录失败");//料架状态更新失败
  3716. }
  3717. #endregion
  3718. }
  3719. else
  3720. {
  3721. throw new Exception(result.RetMsg);
  3722. }
  3723. }
  3724. }
  3725. #endregion
  3726. #endregion
  3727. }
  3728. catch (Exception ex)
  3729. {
  3730. throw new Exception(ex.Message);
  3731. }
  3732. }
  3733. #region 临时接口(用于单独过账SAP接口 不经过WMS)
  3734. public static void CallBackSAPJYHGDTemp(SqlCommand cmd, Dictionary<string, string> language)
  3735. {
  3736. try
  3737. {
  3738. #region SAP(检验合格单为两层结构 一行对应一个序列号)
  3739. string IsSuccess = "";
  3740. string ErrorMessage = "";
  3741. string sql = @" select DISTINCT A.TransCode,B.RCVQuantity,C.BatchCode,B.SAPSequence from ICSWareHouseLotInfoLog A
  3742. INNER JOIN ICSDeliveryNotice B ON B.DNCode=A.TransCode AND B.WorkPoint=A.WorkPoint
  3743. INNER JOIN ICSExtension C ON C.ID=B.ExtensionID AND C.WorkPoint=B.WorkPoint
  3744. WHERE A.TransCode='010002726704'
  3745. ORDER BY A.TransCode";
  3746. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  3747. if (Sapdt.Rows.Count == 0)
  3748. {
  3749. return;
  3750. }
  3751. foreach (DataRow dr in Sapdt.Rows)
  3752. {
  3753. string GUID = Guid.NewGuid().ToString();
  3754. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU Client = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU();
  3755. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU1 Info = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU1();
  3756. Info.NEWID = GUID;
  3757. Info.PRUEFLOS = dr["TransCode"].ToString();
  3758. Info.L_LME = System.Decimal.Round(Convert.ToDecimal(dr["SAPSequence"].ToString()), 3);
  3759. Info.SERNP = Sapdt.Rows[0]["BatchCode"].ToString();
  3760. Info.Z_GERNR = new SAPCallBackJYHGDVPN.ZWEBS_GERNR[0];
  3761. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKUResponse result = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKUResponse();
  3762. result = Client.CallZWMS_SK_WS_RUKU(Info);
  3763. if (result.Z_NULL == "N")
  3764. {
  3765. IsSuccess = "N";
  3766. ErrorMessage += result.L_MESSAGE;
  3767. }
  3768. }
  3769. #endregion
  3770. }
  3771. catch (Exception)
  3772. {
  3773. throw;
  3774. }
  3775. }
  3776. #endregion
  3777. }
  3778. }