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

1861 lines
113 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
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.Linq;
  9. using System.Net.Http;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace ICSSoft.DataProject
  13. {
  14. /// <summary>
  15. /// 使用中
  16. /// 更新库存表、日志表
  17. /// </summary>
  18. public class ICSWareHouseLotInfoService
  19. {
  20. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  21. /// <summary>
  22. /// 分批
  23. /// </summary>
  24. /// <param name="Identification"></param>
  25. /// <param name="TransCode"></param>
  26. /// <param name="TransSequence"></param>
  27. /// <param name="LotNo"></param>
  28. /// <param name="Quantity"></param>
  29. /// <param name="User"></param>
  30. /// <param name="WorkPoint"></param>
  31. /// <param name="TransType"></param>
  32. /// <param name="BusinessCode"></param>
  33. /// <param name="cmd"></param>
  34. public static void WareHouseLotInfoInBatches(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
  35. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID = "")
  36. {
  37. }
  38. /// <summary>
  39. /// 添加库存
  40. /// </summary>
  41. /// <param name="LocationCode"></param>
  42. /// <param name="LotNo"></param>
  43. /// <param name="Quantity"></param>
  44. /// <param name="User"></param>
  45. /// <param name="WorkPoint"></param>
  46. /// <param name="TransType"></param>
  47. /// <param name="BusinessCode"></param>
  48. /// <param name="cmd"></param>
  49. /// <param name="jointLotNo"></param>
  50. public static void WareHouseLotInfoUp(string Identification, string LocationCode, string LotNo, string Quantity, string User,
  51. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string LogID,string jointLotNo)
  52. {
  53. try
  54. {
  55. ///添加库存(原条码退回,更新库存;新条码直接入库)
  56. string sql = string.Empty;
  57. string locationcode = "";
  58. if (BusinessCode != TransTypeEnum.SalesReturnBack.GetDescription<DBValue>())
  59. {
  60. if (string.IsNullOrWhiteSpace(LogID))
  61. {
  62. sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  63. BEGIN
  64. RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
  65. RETURN
  66. END ";
  67. }
  68. else
  69. {
  70. sql = @"SELECT LocationCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  71. sql = string.Format(sql, LotNo, WorkPoint);
  72. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  73. if (dt == null || dt.Rows.Count <= 0)
  74. {
  75. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
  76. }
  77. locationcode = dt.Rows[0]["LocationCode"].ToString();
  78. }
  79. }
  80. sql += @" IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  81. BEGIN
  82. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  83. RETURN
  84. END
  85. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  86. BEGIN
  87. IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity=0)
  88. BEGIN
  89. UPDATE a SET a.Quantity=ISNULL(a.Quantity,0)+'{3}',WarehouseCode=e.WarehouseCode,LocationCode=d.LocationCode
  90. From ICSWareHouseLotInfo a
  91. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  92. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  93. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  94. END
  95. ELSE IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.LocationCode='{4}')
  96. BEGIN
  97. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
  98. WHERE LotNo='{0}' AND WorkPoint='{1}'
  99. END
  100. ELSE IF('" + locationcode + @"' != '{4}')
  101. BEGIN
  102. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo395"), "{4}", locationcode) + @"', 16, 1);
  103. RETURN
  104. END
  105. END
  106. ELSE
  107. BEGIN
  108. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  109. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  110. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  111. BEGIN
  112. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  113. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  114. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}' AND il.LocationCode='{4}')
  115. BEGIN
  116. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  117. RETURN
  118. END
  119. END
  120. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  121. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  122. FROM ICSInventoryLot a
  123. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  124. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  125. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  126. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  127. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  128. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  129. END";
  130. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode);
  131. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  132. {
  133. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  134. }
  135. ///添加日志
  136. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  137. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  138. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  139. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  140. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  141. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  142. '','',c.WarehouseCode,c.LocationCode,'{6}',
  143. '','0','{4}','{5}','0','',
  144. '','','',f.F_Account ,f.F_RealName ,
  145. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  146. FROM ICSInventoryLot a
  147. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  148. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  149. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  150. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  151. ";
  152. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
  153. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  154. {
  155. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  156. }
  157. ControlMode mode = ICSControlModeService.GetControlMode();
  158. //管控方式是"料品"时
  159. if (mode.itemCode.Equals("ControlMode02"))
  160. {
  161. //在条码表中插入一条数据
  162. LotNoMode lotNoMode = ICSControlModeService.QueryLotNo(LotNo, WorkPoint);
  163. CreateLotNo(jointLotNo, Quantity, "", "", WorkPoint, Identification, User, lotNoMode.InvCode, BusinessCode, lotNoMode.ProjectCode,"",lotNoMode.Version,lotNoMode.Brand,
  164. lotNoMode.cFree1, lotNoMode.cFree2, lotNoMode.cFree3, lotNoMode.cFree4, lotNoMode.cFree5, lotNoMode.cFree6, lotNoMode.cFree7, lotNoMode.cFree8, lotNoMode.cFree9,
  165. lotNoMode.cFree10,cmd,language);
  166. sql = string.Empty;
  167. ///将物料编码作为物料条码添加库存(原条码退回,更新库存;新条码直接入库)
  168. if (BusinessCode != TransTypeEnum.SalesReturnBack.GetDescription<DBValue>()
  169. && string.IsNullOrWhiteSpace(LogID))
  170. {
  171. sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  172. BEGIN
  173. RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
  174. RETURN
  175. END ";
  176. }
  177. sql += @" IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  178. BEGIN
  179. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  180. RETURN
  181. END
  182. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  183. BEGIN
  184. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  185. END
  186. ELSE
  187. BEGIN
  188. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  189. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  190. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  191. BEGIN
  192. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  193. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  194. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}' AND il.LocationCode='{4}')
  195. BEGIN
  196. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  197. RETURN
  198. END
  199. END
  200. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  201. SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  202. FROM ICSInventoryLot a
  203. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  204. --INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  205. INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
  206. INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
  207. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  208. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  209. END";
  210. sql = string.Format(sql, jointLotNo, WorkPoint, User, Quantity, LocationCode);
  211. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  212. {
  213. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  214. }
  215. ///添加日志
  216. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  217. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  218. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  219. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  220. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  221. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  222. '','',c.WarehouseCode,c.LocationCode,'{6}',
  223. '','0','{4}','{5}','0','',
  224. '','','',f.F_Account ,f.F_RealName ,
  225. SYSDATETIME() ,a.WorkPoint ,'','{7}'
  226. FROM ICSInventoryLot a
  227. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  228. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  229. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  230. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  231. ";
  232. sql = string.Format(sql, jointLotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
  233. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  234. {
  235. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  236. }
  237. }
  238. }
  239. catch (Exception)
  240. {
  241. throw;
  242. }
  243. }
  244. /// <summary>
  245. /// 减少库存
  246. /// </summary>
  247. /// <param name="Identification"></param>
  248. /// <param name="TransCode"></param>
  249. /// <param name="TransSequence"></param>
  250. /// <param name="LotNo"></param>
  251. /// <param name="Quantity"></param>
  252. /// <param name="User"></param>
  253. /// <param name="WorkPoint"></param>
  254. /// <param name="TransType"></param>
  255. /// <param name="BusinessCode"></param>
  256. /// <param name="cmd"></param>
  257. public static DataTable WareHouseLotInfoDown(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
  258. string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID = "")
  259. {
  260. String LotEnable = "";
  261. String PrintEnable = "";
  262. string lotstr = "";
  263. int result = 0;
  264. List<string> NewBarCodeList = new List<string>();
  265. DataTable dtLotno = new DataTable();
  266. DataTable lstDt = new DataTable();
  267. try
  268. {
  269. ///更新库存
  270. string sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  271. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  272. BEGIN
  273. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  274. RETURN
  275. END";
  276. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  277. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  278. {
  279. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  280. }
  281. //检验是否分批
  282. sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  283. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  284. where a.LotNo='{0}' and a.WorkPoint='{1}'
  285. ";
  286. sql = string.Format(sql, LotNo, WorkPoint);
  287. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  288. if (dt.Rows.Count == 0)
  289. {
  290. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  291. }
  292. else
  293. {
  294. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  295. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  296. }
  297. if (LotEnable.Equals("True"))
  298. {
  299. ///分批前添加日志
  300. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  301. BEGIN
  302. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  303. RETURN
  304. END
  305. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  306. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  307. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  308. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  309. MTIME,WorkPoint,EATTRIBUTE1)
  310. SELECT NEWID(),'{3}','{7}','{8}',a.LotNo ,a.InvCode ,
  311. c.WarehouseCode,c.LocationCode,'','',c.Quantity+{6},
  312. '','0','{4}','31','0','',
  313. '','','',f.F_Account ,f.F_RealName ,
  314. SYSDATETIME() ,a.WorkPoint ,''
  315. FROM ICSInventoryLot a
  316. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  317. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  318. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  319. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  320. ";
  321. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, TransCode, TransSequence);
  322. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  323. {
  324. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  325. }
  326. #region 获取分批后的条码(lotstr)
  327. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  328. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  329. sql = string.Format(sql, LotNo, WorkPoint);
  330. dt = DBHelper.SQlReturnData(sql, cmd);
  331. if (dt.Rows.Count == 0)
  332. {
  333. lotstr = LotNo + "-" + 1;
  334. }
  335. else
  336. {
  337. lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  338. }
  339. NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  340. #endregion
  341. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  342. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  343. Quantity,Amount,ExtensionID,Type,PrintTimes,
  344. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  345. WorkPoint,EATTRIBUTE1)
  346. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  347. '{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes,
  348. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  349. a.WorkPoint ,'{1}'
  350. From ICSInventoryLot a
  351. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  352. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  353. cmd.CommandText = sql;
  354. result = cmd.ExecuteNonQuery();
  355. if (result <= 0)
  356. {
  357. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  358. }
  359. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  360. select NEWID(),'{0}',WarehouseCode,LocationCode,InvCode,'0',InDate,LockQuantity
  361. ,MUSER,MUSERName,GETDATE(),'{3}',''
  362. from ICSWareHouseLotInfo
  363. where LotNO='{1}' AND WorkPoint='{3}'";
  364. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  365. cmd.CommandText = sql;
  366. result = cmd.ExecuteNonQuery();
  367. if (result <= 0)
  368. {
  369. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  370. }
  371. //插入条码单据表
  372. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  373. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  374. FROM ICSInventoryLot a
  375. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  376. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  377. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  378. sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
  379. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  380. {
  381. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  382. }
  383. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  384. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  385. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  386. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  387. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  388. SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
  389. c.WarehouseCode,c.LocationCode,'','','{6}',
  390. '','0','{7}','{8}','0','',
  391. '','','',f.F_Account ,f.F_RealName ,
  392. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  393. FROM ICSInventoryLot a
  394. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  395. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  396. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  397. ";
  398. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr);
  399. cmd.CommandText = sql;
  400. result = cmd.ExecuteNonQuery();
  401. if (result <= 0)
  402. {
  403. throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
  404. }
  405. if (PrintEnable.Equals("True"))
  406. {
  407. 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
  408. from ICSWareHouseLotInfolog A
  409. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  410. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  411. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  412. where A.lotno like'{0}%' and a.workpoint='{1}'
  413. ";
  414. sql = string.Format(sql, LotNo, WorkPoint);
  415. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  416. lstDt=dtLotno;
  417. }
  418. ///添加日志
  419. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  420. BEGIN
  421. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  422. RETURN
  423. END
  424. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  425. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  426. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  427. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  428. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  429. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  430. c.WarehouseCode,c.LocationCode,'','',c.Quantity,
  431. '','0','{7}','32','0','',
  432. '','','',f.F_Account ,f.F_RealName ,
  433. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  434. FROM ICSInventoryLot a
  435. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  436. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  437. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  438. ";
  439. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  440. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  441. {
  442. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  443. }
  444. #endregion
  445. }
  446. else
  447. {
  448. NewBarCodeList.Add(LotNo);
  449. ///添加日志
  450. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  451. BEGIN
  452. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  453. RETURN
  454. END
  455. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  456. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  457. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  458. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  459. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  460. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  461. c.WarehouseCode,c.LocationCode,'','','{6}',
  462. '','0','{7}','{8}','0','',
  463. '','','',f.F_Account ,f.F_RealName ,
  464. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  465. FROM ICSInventoryLot a
  466. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  467. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  468. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  469. ";
  470. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
  471. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  472. {
  473. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  474. }
  475. }
  476. }
  477. catch (Exception)
  478. {
  479. throw;
  480. }
  481. return lstDt;
  482. }
  483. /// <summary>
  484. /// 修改库存
  485. /// </summary>
  486. /// <param name="Identification"></param>
  487. /// <param name="TransCode"></param>
  488. /// <param name="TransSequence"></param>
  489. /// <param name="LotNo"></param>
  490. /// <param name="Quantity"></param>
  491. /// <param name="User"></param>
  492. /// <param name="WorkPoint"></param>
  493. /// <param name="TransType"></param>
  494. /// <param name="cmd"></param>
  495. public static void WareHouseLotInfoUpdate(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
  496. string WorkPoint, string TransType,string CheckKind, SqlCommand cmd, Dictionary<string, string> language)
  497. {
  498. try
  499. {
  500. ///添加日志
  501. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  502. BEGIN
  503. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  504. RETURN
  505. END
  506. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  507. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  508. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  509. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  510. MTIME,WorkPoint,EATTRIBUTE1)
  511. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  512. a.WarehouseCode,a.LocationCode,'','',a.Quantity,
  513. '{8}','0','{6}','{7}','0','',
  514. '','','',f.F_Account ,f.F_RealName ,
  515. SYSDATETIME() ,a.WorkPoint ,''
  516. FROM ICSWareHouseLotInfo a
  517. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  518. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  519. ";
  520. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, TransTypeEnum.LOTCheckBefore.GetDescription<DBValue>(), CheckKind);
  521. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  522. {
  523. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  524. }
  525. ///更新库存
  526. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity='{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'";
  527. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  528. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  529. {
  530. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  531. }
  532. ///添加日志
  533. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  534. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  535. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  536. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  537. MTIME,WorkPoint,EATTRIBUTE1)
  538. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  539. a.WarehouseCode,a.LocationCode,'','',a.Quantity,
  540. '','0','{6}','{7}','0','',
  541. '','','',f.F_Account ,f.F_RealName ,
  542. SYSDATETIME() ,a.WorkPoint ,''
  543. FROM ICSWareHouseLotInfo a
  544. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  545. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  546. ";
  547. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, TransTypeEnum.LOTCheckAfter.GetDescription<DBValue>());
  548. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  549. {
  550. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  551. }
  552. }
  553. catch (Exception)
  554. {
  555. throw;
  556. }
  557. }
  558. /// <summary>
  559. /// 调拨
  560. /// </summary>
  561. /// <param name="LocationCode"></param>
  562. /// <param name="LotNo"></param>
  563. /// <param name="Quantity"></param>
  564. /// <param name="User"></param>
  565. /// <param name="WorkPoint"></param>
  566. /// <param name="TransType"></param>
  567. /// <param name="BusinessCode"></param>
  568. /// <param name="cmd"></param>
  569. public static DataTable WareHouseLotInfoTransfer(string Identification, string TransCode, string TransSequence, string WarehouseCode, string LocationCode,
  570. string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language, string MergeID)
  571. {
  572. String LotEnable = "";
  573. String PrintEnable = "";
  574. string lotstr = "";
  575. int result = 0;
  576. DataTable dtLotno = new DataTable();
  577. DataTable lstDt = new DataTable();
  578. List<string> NewBarCodeList = new List<string>();
  579. try
  580. {
  581. ///分批前添加日志
  582. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  583. BEGIN
  584. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  585. RETURN
  586. END
  587. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  588. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  589. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  590. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  591. MTIME,WorkPoint,EATTRIBUTE1)
  592. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  593. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  594. '','0','{4}','31','0','',
  595. '','','',f.F_Account ,f.F_RealName ,
  596. SYSDATETIME() ,a.WorkPoint ,''
  597. FROM ICSInventoryLot a
  598. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  599. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  600. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  601. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  602. ";
  603. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  604. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  605. {
  606. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  607. }
  608. //检验是否分批
  609. sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
  610. LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  611. where a.LotNo='{0}' and a.WorkPoint='{1}'
  612. ";
  613. sql = string.Format(sql, LotNo, WorkPoint);
  614. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  615. if (dt.Rows.Count == 0)
  616. {
  617. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  618. }
  619. else
  620. {
  621. LotEnable = dt.Rows[0]["LotEnable"].ToString();
  622. PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
  623. }
  624. if (!LotEnable.Equals("False"))
  625. {
  626. #region 获取分批后的条码(lotstr)
  627. sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
  628. ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
  629. sql = string.Format(sql, LotNo, WorkPoint);
  630. dt = DBHelper.SQlReturnData(sql, cmd);
  631. if (dt.Rows.Count == 0)
  632. {
  633. lotstr = LotNo + "-" + 1;
  634. }
  635. else
  636. {
  637. lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
  638. }
  639. NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
  640. #endregion
  641. #region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
  642. sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  643. Quantity,Amount,ExtensionID,Type,PrintTimes,
  644. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  645. WorkPoint,EATTRIBUTE1)
  646. SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
  647. '{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes,
  648. a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
  649. a.WorkPoint ,'{1}'
  650. From ICSInventoryLot a
  651. where a.LotNo='{1}' and a.WorkPoint='{3}'";
  652. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  653. cmd.CommandText = sql;
  654. result = cmd.ExecuteNonQuery();
  655. if (result <= 0)
  656. {
  657. throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
  658. }
  659. #endregion
  660. sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  661. select NEWID(),'{0}',WarehouseCode,LocationCode,InvCode,'{2}',InDate,LockQuantity
  662. ,MUSER,MUSERName,GETDATE(),'{3}',''
  663. from ICSWareHouseLotInfo
  664. where LotNO='{1}' AND WorkPoint='{3}'";
  665. sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
  666. cmd.CommandText = sql;
  667. result = cmd.ExecuteNonQuery();
  668. if (result <= 0)
  669. {
  670. throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
  671. }
  672. //插入条码单据表
  673. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  674. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  675. FROM ICSInventoryLot a
  676. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  677. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  678. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  679. sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
  680. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  681. {
  682. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  683. }
  684. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  685. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  686. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  687. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  688. MTIME,WorkPoint,EATTRIBUTE1,LogID)
  689. SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
  690. c.WarehouseCode,c.LocationCode,'','','{6}',
  691. '','0','{7}','105','0','',
  692. '','','',f.F_Account ,f.F_RealName ,
  693. SYSDATETIME() ,a.WorkPoint ,'','{9}'
  694. FROM ICSInventoryLot a
  695. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  696. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  697. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  698. ";
  699. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr);
  700. cmd.CommandText = sql;
  701. result = cmd.ExecuteNonQuery();
  702. if (result <= 0)
  703. {
  704. throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
  705. }
  706. ///添加日志
  707. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  708. BEGIN
  709. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  710. RETURN
  711. END
  712. IF EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE WarehouseCode='{9}' AND LocationCode='{10}' AND WorkPoint='{1}' AND LotNo = '{0}')
  713. BEGIN
  714. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo355")) + @"',16,1);
  715. RETURN
  716. END
  717. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  718. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  719. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  720. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  721. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  722. SELECT NEWID(),'{3}','','',a.LotNo ,a.InvCode ,
  723. c.WarehouseCode,c.LocationCode,'{9}','{10}',{6},
  724. '','0','{7}','32','0','',
  725. '','','',f.F_Account ,f.F_RealName ,
  726. SYSDATETIME() ,a.WorkPoint ,'','{11}'
  727. FROM ICSInventoryLot a
  728. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  729. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  730. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  731. ";
  732. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode, MergeID);
  733. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  734. {
  735. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  736. }
  737. if (PrintEnable.Equals("True"))
  738. {
  739. 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
  740. from ICSWareHouseLotInfolog A
  741. left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
  742. left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
  743. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  744. where a.BusinessCode ='105'
  745. and A.lotno like'{0}%' and a.workpoint='{1}'
  746. ";
  747. sql = string.Format(sql, LotNo, WorkPoint);
  748. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  749. lstDt = dtLotno;
  750. }
  751. }
  752. else
  753. {
  754. ///添加日志
  755. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  756. BEGIN
  757. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  758. RETURN
  759. END
  760. IF EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE WarehouseCode='{9}' AND LocationCode='{10}' AND WorkPoint='{1}' AND LotNo = '{0}')
  761. BEGIN
  762. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo355")) + @"',16,1);
  763. RETURN
  764. END
  765. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  766. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  767. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  768. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  769. MTIME,WorkPoint,EATTRIBUTE1,MergeID)
  770. SELECT NEWID(),'{3}','','',a.LotNo ,a.InvCode ,
  771. c.WarehouseCode,c.LocationCode,'{9}','{10}',{6},
  772. '','0','{7}','{8}','0','',
  773. '','','',f.F_Account ,f.F_RealName ,
  774. SYSDATETIME() ,a.WorkPoint ,'','{11}'
  775. FROM ICSInventoryLot a
  776. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  777. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  778. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  779. ";
  780. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode, MergeID);
  781. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  782. {
  783. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  784. }
  785. }
  786. ///添加库存
  787. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity>0)
  788. BEGIN
  789. RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
  790. RETURN
  791. END
  792. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}' AND a.Quantity<{4})
  793. BEGIN
  794. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  795. RETURN
  796. END
  797. UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  798. ";
  799. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode, Quantity);
  800. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  801. {
  802. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
  803. }
  804. }
  805. catch (Exception)
  806. {
  807. throw;
  808. }
  809. return lstDt;
  810. }
  811. /// <summary>
  812. /// 移库
  813. /// </summary>
  814. /// <param name="LocationCode"></param>
  815. /// <param name="LotNo"></param>
  816. /// <param name="Quantity"></param>
  817. /// <param name="User"></param>
  818. /// <param name="WorkPoint"></param>
  819. /// <param name="TransType"></param>
  820. /// <param name="BusinessCode"></param>
  821. /// <param name="cmd"></param>
  822. public static void WareHouseLotInfoLibrary(string Identification, string TransCode, string TransSequence, string WarehouseCode, string LocationCode,
  823. string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  824. {
  825. try
  826. {
  827. string sql = @"SELECT WarehouseCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  828. sql = string.Format(sql, LotNo,WorkPoint);
  829. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  830. if (dt == null || dt.Rows.Count <= 0)
  831. {
  832. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
  833. }
  834. string whcode = dt.Rows[0]["WarehouseCode"].ToString();
  835. ///添加日志
  836. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  837. BEGIN
  838. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  839. RETURN
  840. END
  841. IF('" + whcode + @"' != '{8}')
  842. BEGIN
  843. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo394"), "{8}", whcode) + @"', 16, 1);
  844. RETURN
  845. END
  846. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  847. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  848. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  849. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  850. MTIME,WorkPoint,EATTRIBUTE1)
  851. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  852. c.WarehouseCode,c.LocationCode,'{8}','{9}',c.Quantity,
  853. '','0','{6}','{7}','0','',
  854. '','','',f.F_Account ,f.F_RealName ,
  855. SYSDATETIME() ,a.WorkPoint ,''
  856. FROM ICSInventoryLot a
  857. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  858. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  859. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  860. ";
  861. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, BusinessCode, WarehouseCode, LocationCode);
  862. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  863. {
  864. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  865. }
  866. ///添加库存
  867. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity>0)
  868. BEGIN
  869. RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
  870. RETURN
  871. END
  872. IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.WarehouseCode='{2}')
  873. BEGIN
  874. RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
  875. RETURN
  876. END
  877. UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  878. ";
  879. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode);
  880. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  881. {
  882. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
  883. }
  884. }
  885. catch (Exception)
  886. {
  887. throw;
  888. }
  889. }
  890. /// <summary>
  891. /// 两步调入
  892. /// </summary>
  893. /// <param name="LocationCode"></param>
  894. /// <param name="LotNo"></param>
  895. /// <param name="Quantity"></param>
  896. /// <param name="User"></param>
  897. /// <param name="WorkPoint"></param>
  898. /// <param name="TransType"></param>
  899. /// <param name="BusinessCode"></param>
  900. /// <param name="cmd"></param>
  901. public static void WareHouseLotInfoTwoStepTransferDocIn(string Identification, string TransCode, string TransSequence, string WarehouseCode,
  902. string LocationCode, string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  903. {
  904. try
  905. {
  906. ///添加日志
  907. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  908. BEGIN
  909. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  910. RETURN
  911. END
  912. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  913. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  914. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  915. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  916. MTIME,WorkPoint,EATTRIBUTE1)
  917. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  918. c.WarehouseCode,c.LocationCode,'{9}','{10}','{6}',
  919. '','0','{7}','{8}','0','',
  920. '','','',f.F_Account ,f.F_RealName ,
  921. SYSDATETIME() ,a.WorkPoint ,''
  922. FROM ICSInventoryLot a
  923. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  924. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  925. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  926. ";
  927. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode);
  928. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  929. {
  930. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  931. }
  932. ///添加库存
  933. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  934. BEGIN
  935. RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
  936. RETURN
  937. END
  938. UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}',Quantity='{4}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  939. ";
  940. sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode, Quantity);
  941. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  942. {
  943. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
  944. }
  945. }
  946. catch (Exception)
  947. {
  948. throw;
  949. }
  950. }
  951. /// <summary>
  952. /// 拆分、合并日志
  953. /// </summary>
  954. /// <param name="Identification"></param>
  955. /// <param name="LotNo"></param>
  956. /// <param name="User"></param>
  957. /// <param name="WorkPoint"></param>
  958. /// <param name="TransType"></param>
  959. /// <param name="BusinessCode"></param>
  960. /// <param name="cmd"></param>
  961. public static void WareHouseLotInfoLog(string Identification, string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  962. {
  963. try
  964. {
  965. ///添加日志
  966. string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  967. BEGIN
  968. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  969. RETURN
  970. END
  971. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  972. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  973. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  974. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  975. MTIME,WorkPoint,EATTRIBUTE1)
  976. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  977. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  978. '','0','{4}','{5}','0','',
  979. '','','',f.F_Account ,f.F_RealName ,
  980. SYSDATETIME() ,a.WorkPoint ,''
  981. FROM ICSInventoryLot a
  982. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  983. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  984. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  985. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  986. ";
  987. sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  988. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  989. {
  990. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  991. }
  992. }
  993. catch (Exception)
  994. {
  995. throw;
  996. }
  997. }
  998. /// <summary>
  999. /// 合并
  1000. /// </summary>
  1001. /// <param name="Identification"></param>
  1002. /// <param name="LotNo"></param>
  1003. /// <param name="User"></param>
  1004. /// <param name="WorkPoint"></param>
  1005. /// <param name="TransType"></param>
  1006. /// <param name="BusinessCode"></param>
  1007. /// <param name="cmd"></param>
  1008. public static void WareHouseLotInfoMerge(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
  1009. string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1010. {
  1011. try
  1012. {
  1013. ///更新目标条码库存
  1014. string sql = @"IF NOT EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1015. INNER JOIN ICSInventoryLot b ON b.LotNo='{3}' AND a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  1016. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1017. BEGIN
  1018. RAISERROR('" + language.GetNameByCode("WMSAPIInfo170") + @"',16,1);
  1019. RETURN
  1020. END
  1021. IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1022. BEGIN
  1023. RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
  1024. RETURN
  1025. END
  1026. UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1027. ";
  1028. sql = string.Format(sql, LotNo, WorkPoint, Quantity, CurrentLotNo);
  1029. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1030. {
  1031. throw new Exception(language.GetNameByCode("WMSAPIInfo169"));//"目标条码库存更新失败!");
  1032. }
  1033. ///更新原条码库存
  1034. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1035. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  1036. BEGIN
  1037. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1038. RETURN
  1039. END";
  1040. sql = string.Format(sql, CurrentLotNo, WorkPoint, Quantity);
  1041. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1042. {
  1043. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1044. }
  1045. ///添加日志
  1046. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1047. BEGIN
  1048. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1049. RETURN
  1050. END
  1051. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1052. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1053. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1054. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1055. MTIME,WorkPoint,EATTRIBUTE1)
  1056. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1057. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  1058. '','0','{4}','{5}','0','',
  1059. '','','',f.F_Account ,f.F_RealName ,
  1060. SYSDATETIME() ,a.WorkPoint ,''
  1061. FROM ICSInventoryLot a
  1062. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1063. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1064. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1065. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1066. ";
  1067. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  1068. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1069. {
  1070. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1071. }
  1072. }
  1073. catch (Exception)
  1074. {
  1075. throw;
  1076. }
  1077. }
  1078. /// <summary>
  1079. /// 拆分
  1080. /// </summary>
  1081. /// <param name="Identification"></param>
  1082. /// <param name="LotNo"></param>
  1083. /// <param name="User"></param>
  1084. /// <param name="WorkPoint"></param>
  1085. /// <param name="TransType"></param>
  1086. /// <param name="BusinessCode"></param>
  1087. /// <param name="cmd"></param>
  1088. public static void WareHouseLotInfoSplit(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
  1089. string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1090. {
  1091. try
  1092. {
  1093. ///更新库存
  1094. string sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
  1095. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
  1096. BEGIN
  1097. RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
  1098. RETURN
  1099. END";
  1100. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1101. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1102. {
  1103. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  1104. }
  1105. #region 添加库存
  1106. //插入条码表
  1107. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1108. BEGIN
  1109. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1110. RETURN
  1111. END
  1112. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a WHERE a.LotNo='{4}' AND a.WorkPoint='{1}')
  1113. BEGIN
  1114. RAISERROR('" + language.GetNameByCode("WMSAPIInfo172") + @"',16,1);
  1115. RETURN
  1116. END
  1117. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1118. SELECT NEWID(),'{4}' ,a.InvCode,a.ProductDate,a.ExpirationDate ,'{3}',a.ExtensionID,'101',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,a.LotNo
  1119. FROM ICSInventoryLot a
  1120. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1121. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1122. sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, CurrentLotNo);
  1123. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1124. {
  1125. throw new Exception(language.GetNameByCode("WMSAPIInfo173"));//"条码表写入失败!");
  1126. }
  1127. //插入条码单据表
  1128. sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  1129. SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
  1130. FROM ICSInventoryLot a
  1131. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1132. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1133. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1134. sql = string.Format(sql, LotNo, WorkPoint, User, CurrentLotNo);
  1135. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1136. {
  1137. throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
  1138. }
  1139. ///添加库存
  1140. sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
  1141. BEGIN
  1142. RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
  1143. RETURN
  1144. END
  1145. IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  1146. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  1147. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
  1148. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  1149. BEGIN
  1150. IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
  1151. INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
  1152. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint AND il.LocationCode=d.LocationCode
  1153. WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
  1154. BEGIN
  1155. RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
  1156. RETURN
  1157. END
  1158. END
  1159. INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  1160. SELECT NEWID(),a.LotNo ,d.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
  1161. FROM ICSInventoryLot a
  1162. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1163. INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
  1164. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1165. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
  1166. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Quantity);
  1167. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1168. {
  1169. throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
  1170. }
  1171. ///添加日志
  1172. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  1173. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  1174. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  1175. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  1176. MTIME,WorkPoint,EATTRIBUTE1)
  1177. SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
  1178. '','',c.WarehouseCode,c.LocationCode,c.Quantity,
  1179. '','0','{4}','{5}','0','',
  1180. '','','',f.F_Account ,f.F_RealName ,
  1181. SYSDATETIME() ,a.WorkPoint ,''
  1182. FROM ICSInventoryLot a
  1183. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1184. INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1185. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1186. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1187. ";
  1188. sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
  1189. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1190. {
  1191. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  1192. }
  1193. #endregion
  1194. }
  1195. catch (Exception)
  1196. {
  1197. throw;
  1198. }
  1199. }
  1200. /// <summary>
  1201. /// 回写ERP ID
  1202. /// </summary>
  1203. /// <param name="TransType"></param>
  1204. /// <param name="SourceDetailID"></param>
  1205. /// <param name="Identification"></param>
  1206. /// <param name="ID"></param>
  1207. /// <param name="DetailID"></param>
  1208. /// <param name="Code"></param>
  1209. /// <param name="Sequence"></param>
  1210. /// <param name="cmd"></param>
  1211. public static void WareHouseLotInfoLogUpdate(string TransType, string SourceDetailID, string Identification, string ID, string DetailID, string Code, string Sequence, SqlCommand cmd, Dictionary<string, string> language)
  1212. {
  1213. string ERPupdate = string.Empty;
  1214. try
  1215. {
  1216. //采购入库
  1217. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  1218. {
  1219. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1220. FROM ICSWareHouseLotInfoLog a
  1221. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1222. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1223. WHERE c.PODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1224. ";
  1225. }
  1226. //审核的到货单
  1227. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  1228. {
  1229. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1230. FROM ICSWareHouseLotInfoLog a
  1231. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1232. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1233. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1234. ";
  1235. }
  1236. //采购拒收
  1237. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  1238. {
  1239. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1240. FROM ICSWareHouseLotInfoLog a
  1241. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1242. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1243. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1244. ";
  1245. }
  1246. //审核的委外到货单
  1247. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  1248. {
  1249. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1250. FROM ICSWareHouseLotInfoLog a
  1251. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1252. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1253. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1254. ";
  1255. }
  1256. //委外拒收
  1257. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  1258. {
  1259. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1260. FROM ICSWareHouseLotInfoLog a
  1261. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1262. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1263. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1264. ";
  1265. }
  1266. //采购退货
  1267. else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  1268. {
  1269. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1270. FROM ICSWareHouseLotInfoLog a
  1271. INNER JOIN ICSDeliveryNotice c ON a.TransCode=c.DNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1272. WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DNType='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1273. ";
  1274. }
  1275. //委外发料
  1276. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  1277. {
  1278. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1279. FROM ICSWareHouseLotInfoLog a
  1280. INNER JOIN ICSOutsourcingOrder y ON a.TransCode=y.OOCode AND a.WorkPoint=y.WorkPoint
  1281. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  1282. WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1283. ";
  1284. }
  1285. //委外退料
  1286. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  1287. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  1288. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1289. {
  1290. ERPupdate = @"--根据退料单退料
  1291. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1292. FROM ICSWareHouseLotInfoLog a
  1293. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1294. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1295. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  1296. Left JOIN ICSOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  1297. 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')
  1298. --退-
  1299. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1300. FROM ICSWareHouseLotInfoLog a
  1301. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1302. INNER JOIN ICSOutsourcingOrder y ON b.TransCode=y.OOCode AND b.WorkPoint=y.WorkPoint
  1303. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  1304. WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1305. --退-
  1306. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1307. FROM ICSWareHouseLotInfoLog a
  1308. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1309. INNER JOIN ICSOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  1310. WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1311. --退-
  1312. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1313. FROM ICSWareHouseLotInfoLog a
  1314. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1315. INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  1316. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1317. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  1318. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1319. WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1320. ";
  1321. }
  1322. //委外入库
  1323. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  1324. {
  1325. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1326. FROM ICSWareHouseLotInfoLog a
  1327. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1328. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1329. WHERE c.OODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1330. ";
  1331. }
  1332. //委外退货
  1333. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  1334. {
  1335. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1336. FROM ICSWareHouseLotInfoLog a
  1337. INNER JOIN ICSODeliveryNotice c ON a.TransCode=c.ODNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1338. WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.ODNType='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1339. ";
  1340. }
  1341. //生产发料
  1342. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  1343. {
  1344. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1345. FROM ICSWareHouseLotInfoLog a
  1346. INNER JOIN ICSMO y ON a.TransCode=y.MOCode AND a.WorkPoint=y.WorkPoint
  1347. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  1348. WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1349. ";
  1350. }
  1351. //生产退料
  1352. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  1353. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  1354. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1355. {
  1356. ERPupdate = @"--根据退料单退料
  1357. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1358. FROM ICSWareHouseLotInfoLog a
  1359. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1360. INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1361. INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
  1362. left JOIN ICSMOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  1363. 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')
  1364. --退-
  1365. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1366. FROM ICSWareHouseLotInfoLog a
  1367. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1368. INNER JOIN ICSMO y ON b.TransCode=y.MOCode AND b.WorkPoint=y.WorkPoint
  1369. INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  1370. WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1371. --退-
  1372. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1373. FROM ICSWareHouseLotInfoLog a
  1374. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1375. INNER JOIN ICSMOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  1376. WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1377. --退-
  1378. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1379. FROM ICSWareHouseLotInfoLog a
  1380. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  1381. INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  1382. LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  1383. LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
  1384. LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  1385. WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1386. ";
  1387. }
  1388. //生产入库
  1389. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  1390. {
  1391. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1392. FROM ICSWareHouseLotInfoLog a
  1393. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1394. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1395. WHERE c.MODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1396. ";
  1397. }
  1398. //开立的生产入库单
  1399. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  1400. {
  1401. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1402. FROM ICSWareHouseLotInfoLog a
  1403. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1404. INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1405. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1406. ";
  1407. }
  1408. //销售出库
  1409. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  1410. {
  1411. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1412. FROM ICSWareHouseLotInfoLog a
  1413. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1414. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1415. ";
  1416. }
  1417. //销售退货
  1418. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  1419. {
  1420. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1421. FROM ICSWareHouseLotInfoLog a
  1422. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1423. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1424. ";
  1425. }
  1426. //返工工单
  1427. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  1428. {
  1429. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1430. FROM ICSWareHouseLotInfoLog a
  1431. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1432. INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
  1433. INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
  1434. WHERE d.PickID='{3}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1435. ";
  1436. }
  1437. //一步调拨
  1438. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  1439. {
  1440. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1441. FROM ICSWareHouseLotInfoLog a
  1442. INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1443. WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1444. ";
  1445. }
  1446. //调拨
  1447. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  1448. {
  1449. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1450. FROM ICSWareHouseLotInfoLog a
  1451. INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1452. WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1453. ";
  1454. }
  1455. //两步调出
  1456. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  1457. {
  1458. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1459. FROM ICSWareHouseLotInfoLog a
  1460. INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1461. INNER JOIN ICSTransfer d ON c.TransferDetailID=d.TransferDetailID AND c.WorkPoint=d.WorkPoint
  1462. WHERE c.OutID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1463. ";
  1464. }
  1465. //两步调入
  1466. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  1467. {
  1468. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1469. FROM ICSWareHouseLotInfoLog a
  1470. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1471. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  1472. WHERE b.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1473. ";
  1474. }
  1475. //销售退货-原条码
  1476. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  1477. {
  1478. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1479. FROM ICSWareHouseLotInfoLog a
  1480. INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1481. WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1482. ";
  1483. }
  1484. //其他出库
  1485. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  1486. {
  1487. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1488. FROM ICSWareHouseLotInfoLog a
  1489. INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1490. WHERE c.OutID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1491. ";
  1492. }
  1493. //其他入库
  1494. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  1495. {
  1496. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1497. FROM ICSWareHouseLotInfoLog a
  1498. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1499. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1500. WHERE c.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1501. ";
  1502. }
  1503. //拆卸单
  1504. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  1505. {
  1506. ERPupdate = @"UPDATE d set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1507. FROM ICSWareHouseLotInfoLog a
  1508. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1509. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1510. INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
  1511. WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND d.ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1512. UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1513. FROM ICSWareHouseLotInfoLog a
  1514. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1515. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1516. WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DABDOCType='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1517. ";
  1518. }
  1519. //领料申请单
  1520. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  1521. {
  1522. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1523. FROM ICSWareHouseLotInfoLog a
  1524. INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1525. WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1526. ";
  1527. }
  1528. //委外领料申请单
  1529. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  1530. {
  1531. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1532. FROM ICSWareHouseLotInfoLog a
  1533. INNER JOIN ICSOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1534. WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1535. ";
  1536. }
  1537. //开立材料出库
  1538. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  1539. {
  1540. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1541. FROM ICSWareHouseLotInfoLog a
  1542. INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1543. WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1544. ";
  1545. }
  1546. //开立委外材料出库
  1547. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  1548. {
  1549. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1550. FROM ICSWareHouseLotInfoLog a
  1551. INNER JOIN ICSOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1552. WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1553. ";
  1554. }
  1555. //开立红字入库单
  1556. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  1557. {
  1558. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1559. FROM ICSWareHouseLotInfoLog a
  1560. INNER JOIN ICSPurchaseReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1561. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1562. ";
  1563. }
  1564. //开立委外红字入库单
  1565. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  1566. {
  1567. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1568. FROM ICSWareHouseLotInfoLog a
  1569. INNER JOIN ICSOutsourcingReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1570. WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1571. ";
  1572. }
  1573. //借用
  1574. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  1575. {
  1576. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1577. FROM ICSWareHouseLotInfoLog a
  1578. INNER JOIN ICSBrrow c ON a.TransCode=c.BrrowCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1579. WHERE c.BrrowDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1580. ";
  1581. }
  1582. //归还
  1583. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  1584. {
  1585. ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1586. FROM ICSWareHouseLotInfoLog a
  1587. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1588. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1589. WHERE c.ReturnDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND (a.BusinessCode <> '31' and a.BusinessCode <> '32')
  1590. ";
  1591. }
  1592. ERPupdate = string.Format(ERPupdate, SourceDetailID, Identification, ID, DetailID, Code, Sequence);
  1593. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  1594. {
  1595. throw new Exception(TransType + language.GetNameByCode("WMSAPIInfo175"));//"回写日志失败!");
  1596. }
  1597. }
  1598. catch (Exception ex)
  1599. {
  1600. log.Debug(ex.ToString());
  1601. log.Debug(TransType + Environment.NewLine + ERPupdate);
  1602. }
  1603. }
  1604. /// <summary>
  1605. /// 生成条码
  1606. /// </summary>
  1607. /// <param name="LotNo"></param>
  1608. /// <param name="Quantity"></param>
  1609. /// <param name="TransCode"></param>
  1610. /// <param name="TransSequence"></param>
  1611. /// <param name="WorkPoint"></param>
  1612. /// <param name="Identification"></param>
  1613. /// <param name="User"></param>
  1614. /// <param name="InvCode"></param>
  1615. /// <param name="BusinessCode"></param>
  1616. /// <param name="ProjectCode"></param>
  1617. /// <param name="BatchCode"></param>
  1618. /// <param name="Version"></param>
  1619. /// <param name="Brand"></param>
  1620. /// <param name="cFree1"></param>
  1621. /// <param name="cFree2"></param>
  1622. /// <param name="cFree3"></param>
  1623. /// <param name="cFree4"></param>
  1624. /// <param name="cFree5"></param>
  1625. /// <param name="cFree6"></param>
  1626. /// <param name="cFree7"></param>
  1627. /// <param name="cFree8"></param>
  1628. /// <param name="cFree9"></param>
  1629. /// <param name="cFree10"></param>
  1630. /// <param name="cmd"></param>
  1631. /// <param name="language"></param>
  1632. public static void CreateLotNo(string LotNo, string Quantity, string TransCode, string TransSequence, string WorkPoint, string Identification, string User, string InvCode, string BusinessCode,
  1633. 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)
  1634. {
  1635. try
  1636. {
  1637. String EffectiveEnable = "";
  1638. String Colspan = "";
  1639. String IDD = "";
  1640. int EffectiveDays = 0;
  1641. String Time = "";
  1642. int EffectiveDayss = 0;
  1643. DateTime dtt;
  1644. DateTime now = DateTime.Now;
  1645. string sql = string.Empty;
  1646. //string sql = @"select EffectiveEnable,EffectiveDays from ICSInventory a
  1647. // Left Join ICSMO b ON a.InvCode=b.InvCode and a.WorkPoint = b.WorkPoint
  1648. // where b.MoCode='{0}' and b.WorkPoint='{1}'";
  1649. //sql = string.Format(sql, TransCode, WorkPoint);
  1650. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1651. //if (dt.Rows.Count == 0)
  1652. //{
  1653. // throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  1654. //}
  1655. //else
  1656. //{
  1657. // EffectiveEnable = dt.Rows[0]["EffectiveEnable"].ToString();
  1658. // EffectiveDays = Convert.ToInt32(dt.Rows[0]["EffectiveDays"]);
  1659. //}
  1660. //EffectiveDayss = Convert.ToInt32(EffectiveDays);
  1661. //if (!EffectiveEnable.Equals("False"))
  1662. //{
  1663. int year = now.Year;
  1664. int month = now.Month;
  1665. int day = now.Day;
  1666. int n = DateTime.DaysInMonth(year, month);
  1667. int k = day + EffectiveDays;
  1668. if (k > n)
  1669. {
  1670. day = EffectiveDays - (n - day);
  1671. month = month + 1;
  1672. if (month > 12)
  1673. {
  1674. month = 1;
  1675. year = year + 1;
  1676. }
  1677. }
  1678. else
  1679. {
  1680. day = day + EffectiveDays;
  1681. }
  1682. Time = year + "-" + month + "-" + day;
  1683. //}
  1684. //else
  1685. //{
  1686. // Time = "2999-12-31 00:00:00.000";
  1687. //}
  1688. dtt = Convert.ToDateTime(Time);
  1689. //检验自由项
  1690. Colspan = ProjectCode + "~" + BatchCode + "~" + Version
  1691. + "~" + Brand + "~" + cFree1
  1692. + "~" + cFree2 + "~" + cFree3 + "~" + cFree4
  1693. + "~" + cFree5 + "~" + cFree6 + "~" + cFree7
  1694. + "~" + cFree8 + "~" + cFree9 + "~" + cFree10;
  1695. sql = @"select ID,Colspan from ICSExtension a
  1696. where Colspan='{0}' and WorkPoint='{1}'";
  1697. sql = string.Format(sql, Colspan, WorkPoint);
  1698. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  1699. if (dttt.Rows.Count == 0)
  1700. {
  1701. IDD = Guid.NewGuid().ToString();
  1702. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  1703. 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}'";
  1704. sql = string.Format(sql, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, User, WorkPoint, IDD);
  1705. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1706. {
  1707. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  1708. }
  1709. }
  1710. else
  1711. {
  1712. IDD = dttt.Rows[0]["ID"].ToString();
  1713. }
  1714. //存入条码表
  1715. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  1716. BEGIN
  1717. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1718. RETURN
  1719. END
  1720. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  1721. Quantity,Amount,ExtensionID,Type,PrintTimes,
  1722. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  1723. WorkPoint,EATTRIBUTE1)
  1724. SELECT TOP 1 NEWID(),'{0}','{8}',GETDATE(),'{6}',
  1725. 1,'0','{7}','90',null,
  1726. null,null,'{2}' ,f.F_RealName ,GETDATE(),
  1727. '{4}' ,''
  1728. FROM Sys_SRM_User f
  1729. where f.F_Account='{2}' and f.F_Location='{4}'
  1730. ";
  1731. sql = string.Format(sql, LotNo, Quantity, User, TransCode, WorkPoint, TransSequence, dtt, IDD,InvCode);
  1732. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1733. {
  1734. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  1735. }
  1736. ///存入条码关联表
  1737. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{3}')
  1738. BEGIN
  1739. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1740. RETURN
  1741. END
  1742. INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,
  1743. WorkPoint,EATTRIBUTE1)
  1744. SELECT a.LotNo,'{0}','{1}',f.F_Account ,f.F_RealName,GETDATE(),
  1745. a.WorkPoint,''
  1746. FROM ICSInventoryLot a
  1747. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1748. WHERE a.LotNo='{4}' AND a.WorkPoint='{3}'
  1749. ";
  1750. sql = string.Format(sql, TransCode, TransSequence, User, WorkPoint, LotNo);
  1751. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1752. {
  1753. throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
  1754. }
  1755. }
  1756. catch (Exception)
  1757. {
  1758. throw;
  1759. }
  1760. }
  1761. }
  1762. }