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

2412 lines
163 KiB

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