纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2460 lines
163 KiB

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