纽威

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