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.

2100 lines
118 KiB

1 year ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using System.Linq;
  10. using System.Net.Http;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace ICSSoft.DataProject
  14. {
  15. /// <summary>
  16. /// 使用中
  17. /// 库内作业模块
  18. /// </summary>
  19. public class ICSWareHouseService
  20. {
  21. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  22. #region 一步调拨
  23. /// <summary>
  24. /// 一步调拨
  25. /// </summary>
  26. /// <param name="TransCode"></param>
  27. /// <param name="TransSequence"></param>
  28. /// <param name="Quantity"></param>
  29. /// <param name="WorkPoint"></param>
  30. /// <param name="cmd"></param>
  31. public static void OneStepTransferDocIn(string TransCode,string TransSequence, string WorkPoint,string Quantity, SqlCommand cmd, Dictionary<string, string> language)
  32. {
  33. try
  34. {
  35. string sql = @"UPDATE ICSTransfer SET TransferQuantity=ISNULL(TransferQuantity,0)+'{2}'
  36. WHERE TransferNO='{0}' AND Sequence='{3}' AND WorkPoint='{1}' AND Type='1'
  37. IF EXISTS(SELECT a.ID FROM ICSTransfer a
  38. WHERE a.TransferNO='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='1' AND a.TransferQuantity<a.TransferQuantity)
  39. BEGIN
  40. RAISERROR('" + language.GetNameByCode("WMSAPIInfo144") + @"',16,1);
  41. RETURN
  42. END";
  43. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  44. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  45. {
  46. throw new Exception(language.GetNameByCode("WMSAPIInfo145"));//"调拨单信息更新失败!");
  47. }
  48. }
  49. catch (Exception)
  50. {
  51. throw;
  52. }
  53. }
  54. /// <summary>
  55. /// 无源头调拨接口
  56. /// </summary>
  57. /// <param name="TransType"></param>
  58. /// <param name="Identification"></param>
  59. /// <param name="cmd"></param>
  60. public static void OneStepNoTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  61. {
  62. try
  63. {
  64. #region 生成调拨单
  65. string sql = @"SELECT a.FromWarehouseCode+a.ToWarehouseCode+a.MUSER AS Costre,'' AS FromDepCode,'' AS ToDepCode,a.FromWarehouseCode AS FromWHCode,a.ToWarehouseCode AS ToWHCode,'' AS TACode,CASE WHEN a.MUSER='2301' or a.MUSER='2305' THEN '039' ELSE a.MUSER END AS MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,a.ToWarehouseCode,a.InvCode) AS Sequence,
  66. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(lot.Amount) ELSE '0' END AS Amount,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,'' AS TAetailID
  67. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  68. ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  69. INTO #TempERP
  70. FROM ICSWareHouseLotInfoLog a
  71. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  72. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  73. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  74. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  75. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  76. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  77. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  78. WHERE a.Identification='{0}' AND ERPUpload='0' and a.BusinessCode='70'
  79. GROUP BY lot.Amount,inv.AmountEnable,a.FromWarehouseCode,a.ToWarehouseCode,a.MUSER,a.InvCode,con.Enable,conStock.Enable
  80. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  81. ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, '')
  82. SELECT DISTINCT Costre,WorkPoint,FromDepCode,ToDepCode,FromWHCode,ToWHCode,TACode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock,'TransIn002'as DocType,SYSDATETIME() as DocDate FROM #TempERP
  83. SELECT Costre,Sequence,InvCode,Quantity,Amount,TAetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,FromWHCode as OutWhCode,ToWHCode as INWhCode
  84. FROM #TempERP
  85. DROP TABLE #TempERP";
  86. sql = string.Format(sql, Identification);
  87. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  88. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  89. string resultStr = "";
  90. if (DBHelper.IsU9())
  91. {
  92. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9OneStepNoTransferDocInURL, Inputstr);
  93. }
  94. else
  95. {
  96. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepNoTransferDocInURL, Inputstr);
  97. }
  98. Result result = new Result();
  99. result = JsonConvert.DeserializeObject<Result>(resultStr);
  100. if (result.Success)
  101. {
  102. try
  103. {
  104. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  105. foreach (var item in res)
  106. {
  107. JObject jo = (JObject)item;
  108. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  109. foreach (var detail in resdetail)
  110. {
  111. JObject det = (JObject)detail;
  112. string allcol = det["ProjectCode"].ToString() + det["BatchCode"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  113. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  114. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, "", Identification, jo["ID"].ToString(),
  115. det["DetailID"].ToString(), jo["TransCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  116. }
  117. }
  118. //foreach (DataRow dr in ds.Tables)
  119. //{
  120. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, "", Identification, "", "", "", "", "", cmd, language);
  121. //}
  122. }
  123. catch (Exception ex)
  124. {
  125. log.Debug(ex.ToString());
  126. log.Debug(resultStr);
  127. }
  128. }
  129. else
  130. {
  131. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  132. }
  133. #endregion
  134. }
  135. catch (Exception)
  136. {
  137. throw;
  138. }
  139. }
  140. #region 一步调拨(调拨申请单)
  141. /// <summary>
  142. /// 一步调拨(调拨申请单)
  143. /// </summary>
  144. /// <param name="TransCode"></param>
  145. /// <param name="TransSequence"></param>
  146. /// <param name="Quantity"></param>
  147. /// <param name="WorkPoint"></param>
  148. /// <param name="cmd"></param>
  149. public static void OneStepTransferApplicationIn(string TransCode, string TransSequence, string WorkPoint, string Quantity, SqlCommand cmd, Dictionary<string, string> language)
  150. {
  151. try
  152. {
  153. string sql = @"UPDATE ICSTransferApplication SET TransferQuantity=ISNULL(TransferQuantity,0)+'{2}'
  154. WHERE TransferNO='{0}' AND Sequence='{3}' AND WorkPoint='{1}' AND Type='1'
  155. IF EXISTS(SELECT a.ID FROM ICSTransferApplication a
  156. WHERE a.TransferNO='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='1' AND a.TransferQuantity<a.TransferQuantity)
  157. BEGIN
  158. RAISERROR('" + language.GetNameByCode("WMSAPIInfo144") + @"',16,1);
  159. RETURN
  160. END";
  161. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  162. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  163. {
  164. throw new Exception(language.GetNameByCode("WMSAPIInfo145"));//"调拨单信息更新失败!");
  165. }
  166. }
  167. catch (Exception)
  168. {
  169. throw;
  170. }
  171. }
  172. /// <summary>
  173. /// 一步调拨接口
  174. /// </summary>
  175. /// <param name="TransType"></param>
  176. /// <param name="Identification"></param>
  177. /// <param name="cmd"></param>
  178. public static void OneStepTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  179. {
  180. try
  181. {
  182. #region ERP开立状态单据审核
  183. //检验调拨单是否一次性发完
  184. string sql = @"IF EXISTS(SELECT b.ID FROM ICSTransfer b
  185. WHERE b.TransferNO+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  186. AND b.Type = '1' AND b.Quantity!=b.TransferQuantity)
  187. BEGIN
  188. RAISERROR('" + language.GetNameByCode("WMSAPIInfo097") + @"',16,1);
  189. RETURN
  190. END
  191. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  192. FROM ICSWareHouseLotInfoLog a
  193. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  194. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  195. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  196. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1'
  197. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  198. sql = string.Format(sql, Identification);
  199. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  200. string Inputstr =JsonConvert.SerializeObject(dt);
  201. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  202. Result result = new Result();
  203. result = JsonConvert.DeserializeObject<Result>(resultStr);
  204. if (result.Success)
  205. {
  206. try
  207. {
  208. foreach (DataRow dr in dt.Rows)
  209. {
  210. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "","", cmd, language, BusinessCode);
  211. }
  212. }
  213. catch (Exception ex)
  214. {
  215. log.Debug(ex.ToString());
  216. log.Debug(resultStr);
  217. }
  218. }
  219. else
  220. {
  221. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  222. }
  223. #endregion
  224. }
  225. catch (Exception)
  226. {
  227. throw;
  228. }
  229. }
  230. #endregion
  231. #region 调拨
  232. /// <summary>
  233. /// 调拨接口
  234. /// </summary>
  235. /// <param name="TransType"></param>
  236. /// <param name="Identification"></param>
  237. /// <param name="cmd"></param>
  238. public static void StepTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  239. {
  240. try
  241. {
  242. #region ERP开立状态单据审核
  243. //检验调拨单是否一次性发完
  244. string sql = @"SELECT a.ToWarehouseCode+a.MUSER+a.FromWarehouseCode AS Costre,a.ToWarehouseCode AS ToWHCode,a.FromWarehouseCode AS FromWHCode,a.MUSER,'' AS FromDepCode,'' AS ToDepCode,NULL AS TACode,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode) AS Sequence,NULL AS TADetailID,
  245. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  246. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  247. ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  248. INTO #TempERP
  249. FROM ICSWareHouseLotInfoLog a
  250. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  251. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  252. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  253. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  254. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  255. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  256. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  257. WHERE a.Identification='{0}' AND ERPUpload='0'
  258. GROUP BY a.ToWarehouseCode,a.MUSER,a.InvCode,conStock.Enable,con.Enable,a.FromWarehouseCode
  259. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  260. ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, '')
  261. SELECT DISTINCT Costre,ToWHCode,FromWHCode,FromDepCode ,ToDepCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint,TACode,UpdateStock FROM #TempERP
  262. SELECT Costre,Sequence,InvCode,Quantity,Amount,TADetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  263. FROM #TempERP
  264. DROP TABLE #TempERP";
  265. sql = string.Format(sql, Identification);
  266. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  267. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  268. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.StepTransferDocInURL, Inputstr);
  269. Result result = new Result();
  270. result = JsonConvert.DeserializeObject<Result>(resultStr);
  271. if (result.Success)
  272. {
  273. try
  274. {
  275. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  276. foreach (var item in res)
  277. {
  278. JObject jo = (JObject)item;
  279. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  280. foreach (var detail in resdetail)
  281. {
  282. JObject det = (JObject)detail;
  283. string allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  284. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  285. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(),allcol, cmd, language, BusinessCode);
  286. }
  287. }
  288. }
  289. catch (Exception ex)
  290. {
  291. log.Debug(ex.ToString());
  292. log.Debug(resultStr);
  293. }
  294. }
  295. else
  296. {
  297. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  298. }
  299. #endregion
  300. }
  301. catch (Exception)
  302. {
  303. throw;
  304. }
  305. }
  306. #endregion
  307. #region 调拨申请单接口
  308. /// <summary>
  309. /// 调拨申请单接口
  310. /// </summary>
  311. /// <param name="TransType"></param>
  312. /// <param name="Identification"></param>
  313. /// <param name="cmd"></param>
  314. public static void StepTransferApplicationERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  315. {
  316. try
  317. {
  318. #region ERP开立状态单据审核
  319. //检验调拨单是否一次性发完
  320. string sql = @"SELECT c.TransferDetailID as TADetailID,a.ToWarehouseCode+a.MUSER+a.FromWarehouseCode AS Costre,a.ToWarehouseCode AS ToWHCode,a.FromWarehouseCode AS FromWHCode,a.MUSER,'' AS FromDepCode,'' AS ToDepCode,a.TransCode AS TACode,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode) AS Sequence,
  321. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  322. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  323. ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  324. INTO #TempERP
  325. FROM ICSWareHouseLotInfoLog a
  326. INNER JOIN ICSTransferApplication c ON a.TransCode=c.TransferNO and a.TransSequence=c.Sequence and a.WorkPoint=c.WorkPoint
  327. --INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  328. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  329. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  330. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  331. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  332. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  333. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  334. WHERE a.Identification='{0}' AND ERPUpload='0'
  335. GROUP BY a.ToWarehouseCode,a.MUSER,c.TransferDetailID,a.InvCode,conStock.Enable,con.Enable,a.FromWarehouseCode
  336. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  337. ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, ''),a.TransCode
  338. SELECT DISTINCT Costre,ToWHCode,FromWHCode,FromDepCode ,ToDepCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint,TACode,UpdateStock FROM #TempERP
  339. SELECT Costre,Sequence,InvCode,Quantity,Amount,TADetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  340. FROM #TempERP
  341. DROP TABLE #TempERP";
  342. sql = string.Format(sql, Identification);
  343. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  344. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  345. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.StepTransferApplicationURL, Inputstr);
  346. Result result = new Result();
  347. result = JsonConvert.DeserializeObject<Result>(resultStr);
  348. if (result.Success)
  349. {
  350. try
  351. {
  352. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  353. foreach (var item in res)
  354. {
  355. JObject jo = (JObject)item;
  356. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  357. foreach (var detail in resdetail)
  358. {
  359. JObject det = (JObject)detail;
  360. string allcol = "" + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  361. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  362. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  363. }
  364. }
  365. }
  366. catch (Exception ex)
  367. {
  368. log.Debug(ex.ToString());
  369. log.Debug(resultStr);
  370. }
  371. }
  372. else
  373. {
  374. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  375. }
  376. #endregion
  377. }
  378. catch (Exception)
  379. {
  380. throw;
  381. }
  382. }
  383. #endregion
  384. #region 两步调出
  385. /// <summary>
  386. /// 两步调出
  387. /// </summary>
  388. /// <param name="TransCode"></param>
  389. /// <param name="TransSequence"></param>
  390. /// <param name="Quantity"></param>
  391. /// <param name="WorkPoint"></param>
  392. /// <param name="cmd"></param>
  393. public static void TwoStepTransferDocOut(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  394. {
  395. try
  396. {
  397. string sql = @"DECLARE @Status VARCHAR(10)
  398. SELECT @Status=a.Status FROM ICSOtherOut a
  399. INNER JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID AND a.WorkPoint=b.WorkPoint
  400. WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  401. IF (@Status IS NULL)
  402. BEGIN
  403. RAISERROR('" + language.GetNameByCode("WMSAPIInfo146") + @"',16,1);
  404. RETURN
  405. END
  406. ELSE IF (@Status!='1')
  407. BEGIN
  408. RAISERROR('" + language.GetNameByCode("WMSAPIInfo147") + @"',16,1);
  409. RETURN
  410. END
  411. UPDATE a SET OutQuantity=ISNULL(OutQuantity,0)+'{2}'
  412. FROM ICSOtherOut a
  413. INNER JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID AND a.WorkPoint=b.WorkPoint
  414. WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  415. IF EXISTS(SELECT a.ID FROM ICSOtherOut a
  416. INNER JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID AND a.WorkPoint=b.WorkPoint
  417. WHERE a.OutCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.OutQuantity)
  418. BEGIN
  419. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  420. RETURN
  421. END";
  422. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  423. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  424. {
  425. throw new Exception(language.GetNameByCode("WMSAPIInfo148"));//"两步调出单更新失败!");
  426. }
  427. }
  428. catch (Exception)
  429. {
  430. throw;
  431. }
  432. }
  433. /// <summary>
  434. /// 两步调出接口
  435. /// </summary>
  436. /// <param name="TransType"></param>
  437. /// <param name="Identification"></param>
  438. /// <param name="cmd"></param>
  439. public static void TwoStepTransferDocOutERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  440. {
  441. try
  442. {
  443. #region ERP开立状态单据审核
  444. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  445. INTO #NewTempERP
  446. from ICSWareHouseLotInfoLog
  447. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '22'
  448. IF EXISTS(SELECT b.ID FROM ICSOtherOut b
  449. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  450. WHERE b.OutCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  451. AND b.Quantity!=b.OutQuantity)
  452. BEGIN
  453. RAISERROR('" + language.GetNameByCode("WMSAPIInfo098") + @"',16,1);
  454. RETURN
  455. END
  456. SELECT b.OutID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  457. FROM #NewTempERP a
  458. INNER JOIN ICSOtherOut b ON a.TransCode=b.OutCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  459. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  460. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  461. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  462. GROUP BY b.OutID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  463. DROP TABLE #NewTempERP";
  464. sql = string.Format(sql, Identification);
  465. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  466. string Inputstr = JsonConvert.SerializeObject(dt);
  467. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.TwoStepTransferDocOutURL, Inputstr);
  468. Result result = new Result();
  469. result = JsonConvert.DeserializeObject<Result>(resultStr);
  470. if (result.Success)
  471. {
  472. try
  473. {
  474. foreach (DataRow dr in dt.Rows)
  475. {
  476. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  477. }
  478. }
  479. catch (Exception ex)
  480. {
  481. log.Debug(ex.ToString());
  482. log.Debug(resultStr);
  483. }
  484. }
  485. else
  486. {
  487. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  488. }
  489. #endregion
  490. }
  491. catch (Exception)
  492. {
  493. throw;
  494. }
  495. }
  496. #endregion
  497. #region 两步调入
  498. /// <summary>
  499. /// 两步调入
  500. /// </summary>
  501. /// <param name="TransCode"></param>
  502. /// <param name="TransSequence"></param>
  503. /// <param name="Quantity"></param>
  504. /// <param name="WorkPoint"></param>
  505. /// <param name="cmd"></param>
  506. public static void TwoStepTransferDocIn(string TransCode, string TransSequence, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  507. {
  508. //需要关联其他入库单
  509. try
  510. {
  511. string sql = @"DECLARE @Status VARCHAR(10)
  512. SELECT @Status=Otin.Status FROM ICSOtherIn Otin
  513. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  514. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  515. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  516. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  517. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Otin.InCode='{2}' AND Otin.Sequence='{3}'
  518. IF (@Status IS NULL)
  519. BEGIN
  520. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  521. RETURN
  522. END
  523. ELSE IF (@Status!='1')
  524. BEGIN
  525. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  526. RETURN
  527. END
  528. UPDATE Otin SET InQuantity=ISNULL(InQuantity,0)+'{4}'
  529. FROM ICSOtherIn Otin
  530. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  531. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  532. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  533. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  534. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Otin.InCode='{2}' AND Otin.Sequence='{3}'
  535. IF EXISTS(SELECT a.LotNo FROM ICSOtherIn Otin
  536. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  537. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  538. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  539. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  540. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Otin.InCode='{2}' AND Otin.Sequence='{3}' AND Otin.Quantity<Otin.InQuantity)
  541. BEGIN
  542. RAISERROR('" + language.GetNameByCode("WMSAPIInfo149") + @"',16,1);
  543. END";
  544. sql = string.Format(sql, LotNo, WorkPoint,TransCode,TransSequence, Quantity);
  545. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  546. {
  547. throw new Exception(language.GetNameByCode("WMSAPIInfo150"));//"两步调入单更新失败!");
  548. }
  549. }
  550. catch (Exception)
  551. {
  552. throw;
  553. }
  554. }
  555. /// <summary>
  556. /// 两步调入接口
  557. /// </summary>
  558. /// <param name="TransType"></param>
  559. /// <param name="Identification"></param>
  560. /// <param name="cmd"></param>
  561. public static void TwoStepTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  562. {
  563. try
  564. {
  565. #region ERP开立状态单据审核
  566. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  567. INTO #NewTempERP
  568. from ICSWareHouseLotInfoLog
  569. WHERE Identification='{0}' AND ERPUpload='0'
  570. IF EXISTS(SELECT b.ID FROM ICSOtherIn b
  571. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  572. WHERE b.InCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  573. AND b.Quantity!=b.InQuantity)
  574. BEGIN
  575. RAISERROR('" + language.GetNameByCode("WMSAPIInfo099") + @"',16,1);
  576. RETURN
  577. END
  578. SELECT b.InID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  579. FROM #NewTempERP a
  580. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  581. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  582. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  583. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  584. GROUP BY b.InID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  585. DROP TABLE #NewTempERP";
  586. sql = string.Format(sql, Identification);
  587. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  588. string Inputstr = JsonConvert.SerializeObject(dt);
  589. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.TwoStepTransferDocInURL, Inputstr);
  590. Result result = new Result();
  591. result = JsonConvert.DeserializeObject<Result>(resultStr);
  592. if (result.Success)
  593. {
  594. try
  595. {
  596. foreach (DataRow dr in dt.Rows)
  597. {
  598. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "","", cmd, language, BusinessCode);
  599. }
  600. }
  601. catch (Exception ex)
  602. {
  603. log.Debug(ex.ToString());
  604. log.Debug(resultStr);
  605. }
  606. }
  607. else
  608. {
  609. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  610. }
  611. #endregion
  612. }
  613. catch (Exception)
  614. {
  615. throw;
  616. }
  617. }
  618. #endregion
  619. #region 其他出库
  620. /// <summary>
  621. /// 其他出库
  622. /// </summary>
  623. /// <param name="TransCode"></param>
  624. /// <param name="TransSequence"></param>
  625. /// <param name="Quantity"></param>
  626. /// <param name="WorkPoint"></param>
  627. /// <param name="cmd"></param>
  628. public static void OtherOutDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  629. {
  630. try
  631. {
  632. string sql = @"DECLARE @Status VARCHAR(10)
  633. SELECT @Status=a.Status FROM ICSOtherOut a
  634. WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  635. IF (@Status IS NULL)
  636. BEGIN
  637. RAISERROR('" + language.GetNameByCode("WMSAPIInfo151") + @"',16,1);
  638. RETURN
  639. END
  640. ELSE IF (@Status!='1')
  641. BEGIN
  642. RAISERROR('" + language.GetNameByCode("WMSAPIInfo152") + @"',16,1);
  643. RETURN
  644. END
  645. UPDATE a SET OutQuantity=ISNULL(OutQuantity,0)+'{2}'
  646. FROM ICSOtherOut a
  647. WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  648. IF EXISTS(SELECT a.ID FROM ICSOtherOut a
  649. WHERE a.OutCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.OutQuantity)
  650. BEGIN
  651. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  652. RETURN
  653. END";
  654. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  655. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  656. {
  657. throw new Exception(language.GetNameByCode("WMSAPIInfo153"));//"其他出库单更新失败!");
  658. }
  659. }
  660. catch (Exception)
  661. {
  662. throw;
  663. }
  664. }
  665. /// <summary>
  666. /// 其他出库接口
  667. /// </summary>
  668. /// <param name="TransType"></param>
  669. /// <param name="Identification"></param>
  670. /// <param name="cmd"></param>
  671. public static void OtherOutDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  672. {
  673. try
  674. {
  675. #region ERP开立状态单据审核
  676. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  677. INTO #NewTempERP
  678. from ICSWareHouseLotInfoLog
  679. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '24'
  680. IF EXISTS(SELECT b.ID FROM ICSOtherOut b
  681. WHERE b.OutCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  682. AND b.Quantity!=b.OutQuantity)
  683. BEGIN
  684. RAISERROR('" + language.GetNameByCode("WMSAPIInfo100") + @"',16,1);
  685. RETURN
  686. END
  687. SELECT b.OutID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  688. FROM #NewTempERP a
  689. INNER JOIN ICSOtherOut b ON a.TransCode=b.OutCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  690. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  691. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  692. GROUP BY b.OutID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  693. DROP TABLE #NewTempERP";
  694. sql = string.Format(sql, Identification);
  695. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  696. string Inputstr = JsonConvert.SerializeObject(dt);
  697. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OtherOutDocURL, Inputstr);
  698. Result result = new Result();
  699. result = JsonConvert.DeserializeObject<Result>(resultStr);
  700. if (result.Success)
  701. {
  702. try
  703. {
  704. foreach (DataRow dr in dt.Rows)
  705. {
  706. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "","", cmd, language, BusinessCode);
  707. }
  708. }
  709. catch (Exception ex)
  710. {
  711. log.Debug(ex.ToString());
  712. log.Debug(resultStr);
  713. }
  714. }
  715. else
  716. {
  717. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  718. }
  719. #endregion
  720. }
  721. catch (Exception)
  722. {
  723. throw;
  724. }
  725. }
  726. /// <summary>
  727. /// 创建U9杂发单接口
  728. /// </summary>
  729. /// <param name="TransType"></param>
  730. /// <param name="Identification"></param>
  731. /// <param name="cmd"></param>
  732. public static void CreateOtherOutDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  733. {
  734. try
  735. {
  736. #region U9创建单据并审核
  737. string sql = @"select LotNo,WorkPoint,InvCode,FromWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  738. INTO #NewTempERP
  739. from ICSWareHouseLotInfoLog
  740. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='24'
  741. SELECT a.FromWarehouseCode+b.OutCode+a.MUSER AS Costre,a.FromWarehouseCode AS WarehouseCode,b.OutCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.OutCode,a.InvCode) AS Sequence,
  742. b.EATTRIBUTE2 as DocType,b.EATTRIBUTE4 as ClientCode,b.EATTRIBUTE7 as Project,b.EATTRIBUTE1 as Dep,
  743. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  744. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  745. ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  746. INTO #TempERP
  747. FROM #NewTempERP a
  748. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  749. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  750. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  751. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  752. INNER JOIN ICSOtherOut b ON a.TransCode=b.OutCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  753. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  754. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock009' AND a.WorkPoint=conStock.WorkPoint
  755. GROUP BY inv.AmountEnable,a.FromWarehouseCode,b.OutCode,a.MUSER,a.InvCode,con.Enable,conStock.Enable,b.EATTRIBUTE4,b.EATTRIBUTE2,b.EATTRIBUTE7 ,b.EATTRIBUTE1
  756. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  757. ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, '')
  758. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,DocType,ClientCode,OutCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  759. SELECT WarehouseCode AS WHCode,Costre,Sequence,InvCode,Quantity,Amount,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,Project,Dep FROM #TempERP
  760. DROP TABLE #TempERP
  761. DROP TABLE #NewTempERP";
  762. sql = string.Format(sql, Identification, BusinessCode);
  763. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  764. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  765. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateOtherOutDocURL, Inputstr);
  766. //sql = string.Format(sql, Identification);
  767. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  768. //string Inputstr = JsonConvert.SerializeObject(dt);
  769. //string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateOtherOutDocURL, Inputstr);
  770. Result result = new Result();
  771. result = JsonConvert.DeserializeObject<Result>(resultStr);
  772. if (result.Success)
  773. {
  774. try
  775. {
  776. //foreach (DataRow dr in dt.Rows)
  777. //{
  778. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  779. //}
  780. }
  781. catch (Exception ex)
  782. {
  783. log.Debug(ex.ToString());
  784. log.Debug(resultStr);
  785. }
  786. }
  787. else
  788. {
  789. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  790. }
  791. #endregion
  792. }
  793. catch (Exception)
  794. {
  795. throw;
  796. }
  797. }
  798. #endregion
  799. #region 其他入库
  800. /// <summary>
  801. /// 其他入库
  802. /// </summary>
  803. /// <param name="TransCode"></param>
  804. /// <param name="TransSequence"></param>
  805. /// <param name="Quantity"></param>
  806. /// <param name="WorkPoint"></param>
  807. /// <param name="cmd"></param>
  808. public static void OtherInDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  809. {
  810. try
  811. {
  812. string sql = @"DECLARE @Status VARCHAR(10)
  813. SELECT @Status=c.Status FROM ICSInventoryLot a
  814. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  815. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  816. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  817. IF (@Status IS NULL)
  818. BEGIN
  819. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  820. RETURN
  821. END
  822. ELSE IF (@Status!='1')
  823. BEGIN
  824. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  825. RETURN
  826. END
  827. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  828. FROM ICSInventoryLot a
  829. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  830. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  831. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  832. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  833. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  834. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  835. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.InQuantity)
  836. BEGIN
  837. RAISERROR('" + language.GetNameByCode("WMSAPIInfo154") + @"',16,1);
  838. END";
  839. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  840. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  841. {
  842. throw new Exception(language.GetNameByCode("WMSAPIInfo155"));//"其他入库单更新失败!");
  843. }
  844. }
  845. catch (Exception)
  846. {
  847. throw;
  848. }
  849. }
  850. /// <summary>
  851. /// 其他入库接口
  852. /// </summary>
  853. /// <param name="TransType"></param>
  854. /// <param name="Identification"></param>
  855. /// <param name="cmd"></param>
  856. public static void OtherInDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  857. {
  858. try
  859. {
  860. #region ERP开立状态单据审核
  861. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  862. INTO #NewTempERP
  863. from ICSWareHouseLotInfoLog
  864. WHERE Identification='{0}' AND ERPUpload='0'
  865. IF EXISTS(SELECT b.ID FROM ICSOtherIn b
  866. WHERE b.InCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  867. AND b.Quantity!=b.InQuantity)
  868. BEGIN
  869. RAISERROR('" + language.GetNameByCode("WMSAPIInfo101") + @"',16,1);
  870. RETURN
  871. END
  872. SELECT b.InID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  873. FROM #NewTempERP a
  874. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  875. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  876. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  877. GROUP BY b.InID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  878. DROP TABLE #NewTempERP";
  879. sql = string.Format(sql, Identification);
  880. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  881. string Inputstr = JsonConvert.SerializeObject(dt);
  882. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OtherInDocURL, Inputstr);
  883. Result result = new Result();
  884. result = JsonConvert.DeserializeObject<Result>(resultStr);
  885. if (result.Success)
  886. {
  887. try
  888. {
  889. foreach (DataRow dr in dt.Rows)
  890. {
  891. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "","", cmd, language, BusinessCode);
  892. }
  893. }
  894. catch (Exception ex)
  895. {
  896. log.Debug(ex.ToString());
  897. log.Debug(resultStr);
  898. }
  899. }
  900. else
  901. {
  902. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  903. }
  904. #endregion
  905. }
  906. catch (Exception)
  907. {
  908. throw;
  909. }
  910. }
  911. /// <summary>
  912. /// 创建U9杂收单接口
  913. /// </summary>
  914. /// <param name="TransType"></param>
  915. /// <param name="Identification"></param>
  916. /// <param name="cmd"></param>
  917. public static void CreateOtherInDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  918. {
  919. try
  920. {
  921. #region ERP开立状态单据审核
  922. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  923. INTO #NewTempERP
  924. from ICSWareHouseLotInfoLog
  925. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='25'
  926. SELECT a.ToWarehouseCode+b.InCode+a.MUSER AS Costre,a.ToWarehouseCode AS WarehouseCode,b.InCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode,b.InCode,a.InvCode) AS Sequence,
  927. b.EATTRIBUTE2 as DocType,b.EATTRIBUTE4 as ClientCode,
  928. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  929. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  930. ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  931. ,b.EATTRIBUTE7 as Project,b.EATTRIBUTE1 as Dep
  932. INTO #TempERP
  933. FROM #NewTempERP a
  934. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  935. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  936. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  937. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  938. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  939. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  940. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock009' AND a.WorkPoint=conStock.WorkPoint
  941. GROUP BY inv.AmountEnable,a.ToWarehouseCode,b.InCode,a.MUSER,a.InvCode,con.Enable,conStock.Enable,b.EATTRIBUTE4,b.EATTRIBUTE2
  942. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  943. ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, ''),b.EATTRIBUTE7,b.EATTRIBUTE1
  944. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,DocType,ClientCode,InCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  945. SELECT WarehouseCode AS WHCode,Costre,Sequence,InvCode,Quantity,Amount,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,Project,Dep FROM #TempERP
  946. DROP TABLE #TempERP
  947. DROP TABLE #NewTempERP";
  948. sql = string.Format(sql, Identification, BusinessCode);
  949. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  950. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  951. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateOtherInDocURL, Inputstr);
  952. //sql = string.Format(sql, Identification);
  953. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  954. //string Inputstr = JsonConvert.SerializeObject(dt);
  955. //string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateOtherInDocURL, Inputstr);
  956. Result result = new Result();
  957. result = JsonConvert.DeserializeObject<Result>(resultStr);
  958. if (result.Success)
  959. {
  960. try
  961. {
  962. //foreach (DataRow dr in dt.Rows)
  963. //{
  964. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  965. //}
  966. }
  967. catch (Exception ex)
  968. {
  969. log.Debug(ex.ToString());
  970. log.Debug(resultStr);
  971. }
  972. }
  973. else
  974. {
  975. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  976. }
  977. #endregion
  978. }
  979. catch (Exception)
  980. {
  981. throw;
  982. }
  983. }
  984. #endregion
  985. #region 拆卸单
  986. /// <summary>
  987. /// 拆卸单
  988. /// </summary>
  989. /// <param name="TransCode"></param>
  990. /// <param name="TransSequence"></param>
  991. /// <param name="Quantity"></param>
  992. /// <param name="WorkPoint"></param>
  993. /// <param name="cmd"></param>
  994. public static void DisassemblyDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  995. {
  996. try
  997. {
  998. string sql = @"DECLARE @Status VARCHAR(10)
  999. SELECT @Status=c.Status FROM ICSInventoryLot a
  1000. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1001. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1002. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DABDOCType='2'
  1003. IF (@Status IS NULL)
  1004. BEGIN
  1005. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1006. RETURN
  1007. END
  1008. ELSE IF (@Status!='1')
  1009. BEGIN
  1010. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  1011. RETURN
  1012. END
  1013. UPDATE c SET DABDOCQuantity=ISNULL(DABDOCQuantity,0)+'{2}'
  1014. FROM ICSInventoryLot a
  1015. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1016. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1017. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1018. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1019. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1020. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1021. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.DABDOCQuantity)
  1022. BEGIN
  1023. RAISERROR('" + language.GetNameByCode("WMSAPIInfo156") + @"',16,1);
  1024. END";
  1025. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1026. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1027. {
  1028. throw new Exception(language.GetNameByCode("WMSAPIInfo157"));//"拆卸单更新失败!");
  1029. }
  1030. }
  1031. catch (Exception)
  1032. {
  1033. throw;
  1034. }
  1035. }
  1036. /// <summary>
  1037. /// 拆卸单更新套件锁定数量
  1038. /// </summary>
  1039. /// <param name="Identification"></param>
  1040. /// <param name="cmd"></param>
  1041. public static void DisassemblyDoc(string Identification, SqlCommand cmd, Dictionary<string, string> language)
  1042. {
  1043. try
  1044. {
  1045. string sql = @"UPDATE ICSDisassemblyDoc SET DABDOCQuantity=Quantity
  1046. WHERE DABDOCCode+Sequence+WorkPoint IN(SELECT DISTINCT d.TransCode+d.TransSequence+d.WorkPoint
  1047. FROM ICSWareHouseLotInfoLog a
  1048. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1049. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1050. INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
  1051. WHERE a.Identification='{0}' AND d.ERPUpload='0' AND d.Lock='1')
  1052. UPDATE ICSWareHouseLotInfo SET Quantity=Quantity-LockQuantity,LockQuantity=0
  1053. WHERE LotNo+WorkPoint IN(SELECT DISTINCT d.LotNo+d.WorkPoint
  1054. FROM ICSWareHouseLotInfoLog a
  1055. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1056. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1057. INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
  1058. WHERE a.Identification='{0}' AND d.ERPUpload='0' AND d.Lock='1')";
  1059. sql = string.Format(sql, Identification);
  1060. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1061. {
  1062. throw new Exception(language.GetNameByCode("WMSAPIInfo158"));//"拆卸单套件更新失败!");
  1063. }
  1064. }
  1065. catch (Exception)
  1066. {
  1067. throw;
  1068. }
  1069. }
  1070. /// <summary>
  1071. /// 拆卸单接口
  1072. /// </summary>
  1073. /// <param name="TransType"></param>
  1074. /// <param name="Identification"></param>
  1075. /// <param name="cmd"></param>
  1076. public static void DisassemblyDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1077. {
  1078. try
  1079. {
  1080. #region ERP开立状态单据审核
  1081. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1082. INTO #NewTempERP
  1083. from ICSWareHouseLotInfoLog
  1084. WHERE Identification='{0}' AND ERPUpload='0'
  1085. IF EXISTS(SELECT b.ID FROM ICSDisassemblyDoc b
  1086. WHERE b.DABDOCCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  1087. AND b.Quantity!=b.DABDOCQuantity)
  1088. BEGIN
  1089. RAISERROR('" + language.GetNameByCode("WMSAPIInfo102") + @"',16,1);
  1090. RETURN
  1091. END
  1092. SELECT b.DABDOCID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1093. FROM #NewTempERP a
  1094. INNER JOIN ICSDisassemblyDoc b ON a.TransCode=b.DABDOCCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1095. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  1096. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  1097. GROUP BY b.DABDOCID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1098. DROP TABLE #NewTempERP";
  1099. sql = string.Format(sql, Identification);
  1100. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1101. string Inputstr = JsonConvert.SerializeObject(dt);
  1102. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DisassemblyDocURL, Inputstr);
  1103. Result result = new Result();
  1104. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1105. if (result.Success)
  1106. {
  1107. try
  1108. {
  1109. foreach (DataRow dr in dt.Rows)
  1110. {
  1111. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "","", cmd, language, BusinessCode);
  1112. }
  1113. }
  1114. catch (Exception ex)
  1115. {
  1116. log.Debug(ex.ToString());
  1117. log.Debug(resultStr);
  1118. }
  1119. }
  1120. else
  1121. {
  1122. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  1123. }
  1124. #endregion
  1125. }
  1126. catch (Exception)
  1127. {
  1128. throw;
  1129. }
  1130. }
  1131. #endregion
  1132. #region 借用
  1133. /// <summary>
  1134. /// 借用
  1135. /// </summary>
  1136. /// <param name="TransCode"></param>
  1137. /// <param name="TransSequence"></param>
  1138. /// <param name="Quantity"></param>
  1139. /// <param name="WorkPoint"></param>
  1140. /// <param name="cmd"></param>
  1141. public static void BrrowDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1142. {
  1143. try
  1144. {
  1145. string sql = @"DECLARE @Status VARCHAR(10)
  1146. SELECT @Status=a.Status FROM ICSBrrow a
  1147. WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  1148. IF (@Status IS NULL)
  1149. BEGIN
  1150. RAISERROR('" + language.GetNameByCode("WMSAPIInfo159") + @"',16,1);
  1151. RETURN
  1152. END
  1153. ELSE IF (@Status!='2')
  1154. BEGIN
  1155. RAISERROR('" + language.GetNameByCode("WMSAPIInfo160") + @"',16,1);
  1156. RETURN
  1157. END
  1158. UPDATE a SET BrrowQuantity=ISNULL(BrrowQuantity,0)+'{2}'
  1159. FROM ICSBrrow a
  1160. WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  1161. IF EXISTS(SELECT a.ID FROM ICSBrrow a
  1162. WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.BrrowQuantity)
  1163. BEGIN
  1164. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  1165. RETURN
  1166. END";
  1167. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  1168. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1169. {
  1170. throw new Exception(language.GetNameByCode("WMSAPIInfo161"));//"借用单更新失败!");
  1171. }
  1172. }
  1173. catch (Exception)
  1174. {
  1175. throw;
  1176. }
  1177. }
  1178. /// <summary>
  1179. /// 借用接口
  1180. /// </summary>
  1181. /// <param name="TransType"></param>
  1182. /// <param name="Identification"></param>
  1183. /// <param name="cmd"></param>
  1184. public static void BrrowDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1185. {
  1186. try
  1187. {
  1188. #region ERP
  1189. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  1190. INTO #NewTempERP
  1191. from ICSWareHouseLotInfoLog
  1192. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '26'
  1193. SELECT a.FromWarehouseCode+b.BrrowCode+a.MUSER AS Costre,a.FromWarehouseCode AS WarehouseCode,b.BrrowCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.BrrowCode,b.BrrowDetailID,a.InvCode) AS Sequence,
  1194. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(b.Amount/b.Quantity)) ELSE '0' END AS Amount,b.BrrowDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1195. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  1196. ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  1197. INTO #TempERP
  1198. FROM #NewTempERP a
  1199. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1200. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1201. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1202. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1203. INNER JOIN ICSBrrow b ON a.TransCode=b.BrrowCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1204. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1205. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock008' AND a.WorkPoint=conStock.WorkPoint
  1206. GROUP BY inv.AmountEnable,a.FromWarehouseCode,b.BrrowCode,a.MUSER,a.InvCode,b.BrrowDetailID,con.Enable,conStock.Enable
  1207. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  1208. ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, '')
  1209. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,BrrowCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  1210. SELECT Costre,Sequence,InvCode,Quantity,Amount,BrrowDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  1211. DROP TABLE #TempERP
  1212. DROP TABLE #NewTempERP";
  1213. sql = string.Format(sql, Identification);
  1214. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1215. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1216. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.BrrowDocURL, Inputstr);
  1217. Result result = new Result();
  1218. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1219. if (result.Success)
  1220. {
  1221. try
  1222. {
  1223. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1224. foreach (var item in res)
  1225. {
  1226. JObject jo = (JObject)item;
  1227. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1228. foreach (var detail in resdetail)
  1229. {
  1230. JObject det = (JObject)detail;
  1231. string allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  1232. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1233. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1234. det["DetailID"].ToString(), jo["OtherOutCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1235. }
  1236. }
  1237. }
  1238. catch (Exception ex)
  1239. {
  1240. log.Debug(ex.ToString());
  1241. log.Debug(resultStr);
  1242. }
  1243. }
  1244. else
  1245. {
  1246. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1247. }
  1248. #endregion
  1249. }
  1250. catch (Exception)
  1251. {
  1252. throw;
  1253. }
  1254. }
  1255. #endregion
  1256. #region 归还
  1257. /// <summary>
  1258. /// 归还
  1259. /// </summary>
  1260. /// <param name="TransCode"></param>
  1261. /// <param name="TransSequence"></param>
  1262. /// <param name="Quantity"></param>
  1263. /// <param name="WorkPoint"></param>
  1264. /// <param name="cmd"></param>
  1265. public static void ReturnDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1266. {
  1267. try
  1268. {
  1269. string sql = @"DECLARE @Status VARCHAR(10)
  1270. SELECT @Status=c.Status FROM ICSInventoryLot a
  1271. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1272. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1273. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1274. IF (@Status IS NULL)
  1275. BEGIN
  1276. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1277. RETURN
  1278. END
  1279. ELSE IF (@Status!='2')
  1280. BEGIN
  1281. RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
  1282. RETURN
  1283. END
  1284. UPDATE c SET ReturnQuantity=ISNULL(ReturnQuantity,0)+'{2}'
  1285. FROM ICSInventoryLot a
  1286. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1287. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1288. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1289. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1290. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1291. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1292. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.ReturnQuantity)
  1293. BEGIN
  1294. RAISERROR('" + language.GetNameByCode("WMSAPIInfo162") + @"',16,1);
  1295. END";
  1296. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1297. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1298. {
  1299. throw new Exception(language.GetNameByCode("WMSAPIInfo163"));//"归还单更新失败!");
  1300. }
  1301. }
  1302. catch (Exception)
  1303. {
  1304. throw;
  1305. }
  1306. }
  1307. /// <summary>
  1308. /// 归还接口
  1309. /// </summary>
  1310. /// <param name="TransType"></param>
  1311. /// <param name="Identification"></param>
  1312. /// <param name="cmd"></param>
  1313. public static void ReturnDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1314. {
  1315. try
  1316. {
  1317. #region ERP
  1318. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1319. INTO #NewTempERP
  1320. from ICSWareHouseLotInfoLog
  1321. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1322. SELECT a.ToWarehouseCode+b.ReturnCode+a.MUSER AS Costre,a.ToWarehouseCode AS WarehouseCode,b.ReturnCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode,b.ReturnCode,b.ReturnDetailID,a.InvCode) AS Sequence,
  1323. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,b.ReturnDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1324. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  1325. ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  1326. INTO #TempERP
  1327. FROM #NewTempERP a
  1328. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1329. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1330. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1331. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1332. INNER JOIN ICSReturn b ON a.TransCode=b.ReturnCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1333. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1334. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock009' AND a.WorkPoint=conStock.WorkPoint
  1335. GROUP BY inv.AmountEnable,a.ToWarehouseCode,b.ReturnCode,a.MUSER,a.InvCode,b.ReturnDetailID,con.Enable,conStock.Enable
  1336. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  1337. ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, '')
  1338. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,ReturnCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  1339. SELECT Costre,Sequence,InvCode,Quantity,Amount,ReturnDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  1340. DROP TABLE #TempERP
  1341. DROP TABLE #NewTempERP";
  1342. sql = string.Format(sql, Identification,BusinessCode);
  1343. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1344. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1345. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ReturnDocURL, Inputstr);
  1346. Result result = new Result();
  1347. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1348. if (result.Success)
  1349. {
  1350. try
  1351. {
  1352. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1353. foreach (var item in res)
  1354. {
  1355. JObject jo = (JObject)item;
  1356. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1357. foreach (var detail in resdetail)
  1358. {
  1359. JObject det = (JObject)detail;
  1360. string allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  1361. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1362. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1363. det["DetailID"].ToString(), jo["OtherInCode"].ToString(), det["Sequence"].ToString(),"", cmd,language, BusinessCode);
  1364. }
  1365. }
  1366. }
  1367. catch (Exception ex)
  1368. {
  1369. log.Debug(ex.ToString());
  1370. log.Debug(resultStr);
  1371. }
  1372. }
  1373. else
  1374. {
  1375. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1376. }
  1377. #endregion
  1378. }
  1379. catch (Exception)
  1380. {
  1381. throw;
  1382. }
  1383. }
  1384. #endregion
  1385. #endregion
  1386. // #region 工单关联
  1387. // /// <summary>
  1388. // /// 工单关联
  1389. // /// </summary>
  1390. // /// <param name="TransCode"></param>
  1391. // /// <param name="TransSequence"></param>
  1392. // /// <param name="Quantity"></param>
  1393. // /// <param name="WorkPoint"></param>
  1394. // /// <param name="cmd"></param>
  1395. // public static void ICSMOReceive(string LotNo, string Quantity, string TransCode, string TransSequence, string WorkPoint, string Identification, string User, string SRMLotGroup,
  1396. // string ProjectCode, string BatchCode, string Version, string Brand, string cFree1, string cFree2, string cFree3, string cFree4, string cFree5,
  1397. // string cFree6, string cFree7, string cFree8, string cFree9, string cFree10, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1398. // {
  1399. // try
  1400. // {
  1401. // decimal LOTQTY = 0;
  1402. // decimal MOQTY = 0;
  1403. // String EffectiveEnable = "";
  1404. // String Colspan = "";
  1405. // String IDD = "";
  1406. // int EffectiveDays = 0;
  1407. // String Time = "";
  1408. // int EffectiveDayss = 0;
  1409. // DateTime dtt;
  1410. // DateTime now = DateTime.Now;
  1411. // string sql = @"select * from ICSInventoryLotDetail
  1412. // where LotNo='{0}' and WorkPoint='{1}'
  1413. // ";
  1414. // sql = string.Format(sql, LotNo, WorkPoint);
  1415. // DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
  1416. // if (dttte.Rows.Count > 0)
  1417. // {
  1418. // sql = @"IF NOT EXISTS(select * from ICSMO b
  1419. // where b.MOCODE='{2}' and b.WorkPoint='{1}' and b.EATTRIBUTE1='1')
  1420. // BEGIN
  1421. // select * from ICSInventoryLotDetail a
  1422. // left join ICSMO b ON a.transcode=b.mocode and a.WorkPoint=b.WorkPoint
  1423. // where a.LotNo='{0}' and a.WorkPoint='{1}' and a.TransCode = ''
  1424. // END
  1425. // ELSE
  1426. // BEGIN
  1427. // select * from ICSInventoryLotDetail
  1428. // where LotNo='{0}' and WorkPoint='{1}'
  1429. // END";
  1430. // sql = string.Format(sql, LotNo, WorkPoint, TransCode);
  1431. // DataTable tt = DBHelper.SQlReturnData(sql, cmd);
  1432. // if (tt.Rows.Count > 0)
  1433. // {
  1434. // ///修改条码关联表
  1435. // sql = @"update ICSInventoryLotDetail set TransCode='{0}',TransSequence='{1}'
  1436. // where lotno='{3}' and WorkPoint='{2}'
  1437. // ";
  1438. // sql = string.Format(sql, TransCode, TransSequence, WorkPoint, LotNo);
  1439. // if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1440. // {
  1441. // throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
  1442. // }
  1443. // ///修改条码表
  1444. // sql = @"update ICSInventoryLot set InvCode=(select a.InvCode from ICSMO a where a.MOCode='{0}' and a.Sequence='{1}')
  1445. // where lotno='{3}' and WorkPoint='{2}'
  1446. // ";
  1447. // sql = string.Format(sql, TransCode, TransSequence, WorkPoint, LotNo);
  1448. // if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1449. // {
  1450. // throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
  1451. // }
  1452. // }
  1453. // else
  1454. // {
  1455. // throw new Exception(language.GetNameByCode("WMSAPIInfo374"));
  1456. // }
  1457. // }
  1458. // else
  1459. // {
  1460. // sql = @"select EffectiveEnable,EffectiveDays from ICSInventory a
  1461. // Left Join ICSMO b ON a.InvCode=b.InvCode and a.WorkPoint = b.WorkPoint
  1462. // where b.MoCode='{0}' and b.WorkPoint='{1}'";
  1463. // sql = string.Format(sql, TransCode, WorkPoint);
  1464. // DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1465. // if (dt.Rows.Count == 0)
  1466. // {
  1467. // throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  1468. // }
  1469. // else
  1470. // {
  1471. // EffectiveEnable = dt.Rows[0]["EffectiveEnable"].ToString();
  1472. // EffectiveDays = Convert.ToInt32(dt.Rows[0]["EffectiveDays"]);
  1473. // }
  1474. // //EffectiveDayss = Convert.ToInt32(EffectiveDays);
  1475. // if (!EffectiveEnable.Equals("False"))
  1476. // {
  1477. // Time = DBHelper.ReTime(now, EffectiveDays);
  1478. // }
  1479. // else
  1480. // {
  1481. // Time = "2999-12-31 00:00:00.000";
  1482. // }
  1483. // dtt = Convert.ToDateTime(Time);
  1484. // sql = @"DECLARE @aa VARCHAR(10)
  1485. //DECLARE @bb VARCHAR(10)
  1486. // SELECT @aa=a.EATTRIBUTE1 FROM ICSMO a
  1487. // WHERE a.MOCode='{0}' and a.WorkPoint='{1}'
  1488. // print @aa
  1489. // IF(@aa='1')
  1490. // BEGIN
  1491. // select Count(c.lotno) AS LOTQTY,a.Quantity+ISNULL((select SUM(b.Quantity) from ICSMO a
  1492. // left join ICSMOPick b on a.MODetailID=b.MODetailID and a.WorkPoint=b.WorkPoint
  1493. // where a.MOCode='{0}' and a.EATTRIBUTE1='1' and b.EATTRIBUTE1='1' and a.WorkPoint='{1}'),0) AS MOQTY
  1494. // from ICSMO a
  1495. // left join ICSInventoryLotDetail bb on a.MOCode=bb.TransCode and a.WorkPoint=bb.WorkPoint
  1496. // left join ICSInventoryLot c on bb.LotNo=c.LotNo and c.WorkPoint=bb.WorkPoint
  1497. // where a.MOCode='{0}' and a.WorkPoint='{1}'
  1498. // group by a.Quantity
  1499. // END
  1500. // ELSE
  1501. // BEGIN
  1502. // select Count(bb.lotno) AS LOTQTY,a.Quantity AS MOQTY
  1503. // from ICSMO a
  1504. // left join ICSInventoryLotDetail bb on a.MOCode=bb.TransCode and a.Sequence=bb.transSequence and a.WorkPoint=bb.WorkPoint
  1505. // left join ICSInventoryLot c on bb.LotNo=c.LotNo and c.WorkPoint=bb.WorkPoint
  1506. // where a.MOCode='{0}' and a.WorkPoint='{1}'
  1507. // group by a.Quantity
  1508. // END
  1509. // ";
  1510. // sql = string.Format(sql, TransCode, WorkPoint);
  1511. // DataTable dtttt = DBHelper.SQlReturnData(sql, cmd);
  1512. // LOTQTY = Convert.ToDecimal(dtttt.Rows[0]["LOTQTY"]);
  1513. // MOQTY = Convert.ToDecimal(dtttt.Rows[0]["MOQTY"]);
  1514. // sql = @"select * from ICSInventoryLot
  1515. // where LotNo='{0}' and WorkPoint='{1}'
  1516. // ";
  1517. // sql = string.Format(sql, LotNo, WorkPoint);
  1518. // DataTable dttaa = DBHelper.SQlReturnData(sql, cmd);
  1519. // if (LOTQTY < MOQTY)
  1520. // {
  1521. // //检验自由项
  1522. // Colspan = ProjectCode + "~" + BatchCode + "~" + Version
  1523. // + "~" + Brand + "~" + cFree1
  1524. // + "~" + cFree2 + "~" + cFree3 + "~" + cFree4
  1525. // + "~" + cFree5 + "~" + cFree6 + "~" + cFree7
  1526. // + "~" + cFree8 + "~" + cFree9 + "~" + cFree10;
  1527. // sql = @"select ID,Colspan from ICSExtension a
  1528. // where Colspan='{0}' and WorkPoint='{1}'";
  1529. // sql = string.Format(sql, Colspan, WorkPoint);
  1530. // DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  1531. // if (dttt.Rows.Count == 0)
  1532. // {
  1533. // IDD = Guid.NewGuid().ToString();
  1534. // sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  1535. // 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}'";
  1536. // sql = string.Format(sql, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, User, WorkPoint, IDD);
  1537. // if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1538. // {
  1539. // throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  1540. // }
  1541. // }
  1542. // else
  1543. // {
  1544. // IDD = dttt.Rows[0]["ID"].ToString();
  1545. // }
  1546. // if (dttaa.Rows.Count == 0)
  1547. // {
  1548. // //存入条码表
  1549. // sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  1550. // BEGIN
  1551. // RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1552. // RETURN
  1553. // END
  1554. // INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  1555. // Quantity,Amount,ExtensionID,Type,PrintTimes,
  1556. // LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  1557. // WorkPoint,EATTRIBUTE1)
  1558. // SELECT TOP 1 NEWID(),'{0}',a.InvCode,GETDATE(),'{6}',
  1559. // 1,'0','{7}','90',null,
  1560. // null,null,'{2}' ,f.F_RealName ,GETDATE(),
  1561. // '{4}' ,''
  1562. // FROM ICSMO a
  1563. // INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1564. // INNER JOIN ICSExtension b ON a.ExtensionID=b.ID AND a.WorkPoint=b.WorkPoint
  1565. // INNER JOIN ICSInventory c ON a.InvCode=c.InvCode AND a.WorkPoint=c.WorkPoint
  1566. // where a.MOCode='{3}' and a.Sequence='{5}' and a.WorkPoint='{4}'
  1567. // ";
  1568. // sql = string.Format(sql, LotNo, Quantity, User, TransCode, WorkPoint, TransSequence, dtt, IDD);
  1569. // if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1570. // {
  1571. // throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  1572. // }
  1573. // }
  1574. // ///存入条码关联表
  1575. // sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{3}')
  1576. // BEGIN
  1577. // RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  1578. // RETURN
  1579. // END
  1580. // INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,
  1581. // WorkPoint,EATTRIBUTE1)
  1582. // SELECT a.LotNo,'{0}','{1}',f.F_Account ,f.F_RealName,GETDATE(),
  1583. // a.WorkPoint,''
  1584. // FROM ICSInventoryLot a
  1585. // INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  1586. // WHERE a.LotNo='{4}' AND a.WorkPoint='{3}'
  1587. // ";
  1588. // sql = string.Format(sql, TransCode, TransSequence, User, WorkPoint, LotNo);
  1589. // if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1590. // {
  1591. // throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
  1592. // }
  1593. // }
  1594. // else
  1595. // {
  1596. // throw new Exception(language.GetNameByCode("WMSAPIInfo373"));//條碼綁定工單失敗!數量已滿!
  1597. // }
  1598. // }
  1599. // }
  1600. // catch (Exception)
  1601. // {
  1602. // throw;
  1603. // }
  1604. // }
  1605. // public static void ICSMOReceiveUntie(string LotNo, string WorkPoint, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1606. // {
  1607. // try
  1608. // {
  1609. // DateTime now = DateTime.Now;
  1610. // string sql = @"select * from ICSInventoryLotDetail
  1611. // where LotNo='{0}' and WorkPoint='{1}'
  1612. // ";
  1613. // sql = string.Format(sql, LotNo, WorkPoint);
  1614. // DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
  1615. // if (dttte.Rows.Count > 0)
  1616. // {
  1617. // ///删除条码关联表数据
  1618. // sql = @"DELETE FROM [dbo].[ICSInventoryLotDetail] WHERE LotNo='{0}' AND WorkPoint='{1}'
  1619. // ";
  1620. // sql = string.Format(sql, LotNo, WorkPoint);
  1621. // if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1622. // {
  1623. // throw new Exception(language.GetNameByCode("WMSAPIInfo464"));
  1624. // }
  1625. // sql = @"DELETE FROM [dbo].[ICSInventoryLot] WHERE LotNo = '{0}' AND WorkPoint = '{1}'
  1626. // ";
  1627. // sql = string.Format(sql, LotNo, WorkPoint);
  1628. // if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1629. // {
  1630. // throw new Exception(language.GetNameByCode("WMSAPIInfo464"));
  1631. // }
  1632. // }
  1633. // else
  1634. // {
  1635. // throw new Exception(language.GetNameByCode("WMSAPIInfo465"));
  1636. // }
  1637. // }
  1638. // catch (Exception)
  1639. // {
  1640. // throw;
  1641. // }
  1642. // }
  1643. // #endregion
  1644. #region 容器条码绑定
  1645. public static bool ICSContainerLot(string LotNo, string containerCode, string WorkPoint, string Identification, string User,
  1646. string ProjectCode, string BatchCode, string Version, string Brand, string cFree1, string cFree2, string cFree3, string cFree4, string cFree5,
  1647. string cFree6, string cFree7, string cFree8, string cFree9, string cFree10, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  1648. {
  1649. try
  1650. {
  1651. Boolean flag = false;
  1652. decimal LOTQTY = 0;
  1653. decimal MOQTY = 0;
  1654. String EffectiveEnable = "";
  1655. String Colspan = "";
  1656. String IDD = "";
  1657. int EffectiveDays = 0;
  1658. String Time = "";
  1659. int EffectiveDayss = 0;
  1660. DateTime dtt;
  1661. DateTime now = DateTime.Now;
  1662. string sql = @"select * FROM ICSContainerLot WHERE LotNo='{0}' AND WorkPoint='{1}'
  1663. ";
  1664. sql = string.Format(sql, LotNo, WorkPoint);
  1665. DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
  1666. if (dttte.Rows.Count > 0)
  1667. {
  1668. ///修改容器关联表
  1669. sql = @"UPDATE ICSContainerLot SET ContainerID=(SELECT ID FROM ICSContainer WHERE ContainerCode='{0}' AND WorkPoint='{1}' )
  1670. where lotno='{2}' and WorkPoint='{1}'
  1671. ";
  1672. sql = string.Format(sql, containerCode, WorkPoint, LotNo);
  1673. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1674. {
  1675. throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
  1676. }
  1677. flag = true;
  1678. }
  1679. else
  1680. {
  1681. sql = @"select 1 from ICSInventoryLot
  1682. where LotNo='{0}' and WorkPoint='{1}'
  1683. ";
  1684. sql = string.Format(sql, LotNo, WorkPoint);
  1685. DataTable dttaa = DBHelper.SQlReturnData(sql, cmd);
  1686. if(dttaa.Rows.Count > 0)
  1687. {
  1688. //检验自由项
  1689. Colspan = ProjectCode + "~" + BatchCode + "~" + Version
  1690. + "~" + Brand + "~" + cFree1
  1691. + "~" + cFree2 + "~" + cFree3 + "~" + cFree4
  1692. + "~" + cFree5 + "~" + cFree6 + "~" + cFree7
  1693. + "~" + cFree8 + "~" + cFree9 + "~" + cFree10;
  1694. sql = @"select ID,Colspan from ICSExtension a
  1695. where Colspan='{0}' and WorkPoint='{1}'";
  1696. sql = string.Format(sql, Colspan, WorkPoint);
  1697. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  1698. if (dttt.Rows.Count == 0)
  1699. {
  1700. IDD = Guid.NewGuid().ToString();
  1701. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  1702. 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}'";
  1703. sql = string.Format(sql, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, User, WorkPoint, IDD);
  1704. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1705. {
  1706. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  1707. }
  1708. }
  1709. else
  1710. {
  1711. IDD = dttt.Rows[0]["ID"].ToString();
  1712. }
  1713. Time = "2999-12-31 00:00:00.000";
  1714. dtt = Convert.ToDateTime(Time);
  1715. ///存入容器关联表
  1716. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  1717. BEGIN
  1718. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  1719. RETURN
  1720. END
  1721. INSERT INTO ICSContainerLot(ID,ContainerID,LotNo,MUSER,MUSERName,WorkPoint,MTIME)
  1722. SELECT NEWID(),a.ID,'{3}','{1}',f.F_RealName,'{2}',GETDATE()
  1723. FROM ICSContainer a
  1724. INNER JOIN Sys_SRM_User f ON f.F_Account='{1}' AND a.WorkPoint=f.F_Location
  1725. WHERE a.ContainerCode='{0}' AND WorkPoint='{2}'
  1726. ";
  1727. sql = string.Format(sql, containerCode, User, WorkPoint, LotNo);
  1728. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1729. {
  1730. throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
  1731. }
  1732. ///记录日志
  1733. sql = @"INSERT INTO ICSContainerLog(ID,ContainerID,ContainerOrLotNo,Type,MUSER,MUSERName,WorkPoint,MTIME)
  1734. VALUES(NEWID(), (SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{0}'), '{1}', 2, '{2}', (SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{2}'), '{3}', GETDATE())";
  1735. sql = string.Format(sql, containerCode, LotNo, User, WorkPoint);
  1736. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1737. {
  1738. throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
  1739. }
  1740. flag = true;
  1741. }
  1742. }
  1743. return flag;
  1744. }
  1745. catch(Exception ex)
  1746. {
  1747. log.Error(ex.Message);
  1748. //return false;
  1749. throw;
  1750. }
  1751. }
  1752. /// <summary>
  1753. /// 容器条码解绑
  1754. /// </summary>
  1755. /// <param name="LotNo"></param>
  1756. /// <param name="WorkPoint"></param>
  1757. /// <param name="User"></param>
  1758. /// <param name="cmd"></param>
  1759. /// <param name="language"></param>
  1760. public static bool ICSContainerLotUntie(string ContainerCode, string LotNo, string WorkPoint, string User, string Type, SqlCommand cmd, Dictionary<string, string> language)
  1761. {
  1762. try
  1763. {
  1764. DateTime now = DateTime.Now;
  1765. string sql = @"select 1 from ICSContainerLot
  1766. where ContainerID=(SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{2}') AND LotNo='{0}' and WorkPoint='{1}'
  1767. ";
  1768. sql = string.Format(sql, LotNo, WorkPoint, ContainerCode);
  1769. log.Debug("查询容器条码关联表是否存在");
  1770. DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
  1771. if (dttte.Rows.Count > 0)
  1772. {
  1773. ///删除条码关联表数据
  1774. sql = @"DELETE FROM ICSContainerLot
  1775. where ContainerID=(SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{2}') AND LotNo='{0}' and WorkPoint='{1}'
  1776. ";
  1777. sql = string.Format(sql, LotNo, WorkPoint,ContainerCode);
  1778. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1779. {
  1780. throw new Exception(language.GetNameByCode("容器条码关联表数据删除失败"));
  1781. }
  1782. ///记录日志
  1783. sql = @"INSERT INTO ICSContainerLog(ID,ContainerID,ContainerOrLotNo,Type,MUSER,MUSERName,WorkPoint,MTIME)
  1784. VALUES(NEWID(), (SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{0}'), '{1}', '{4}', '{2}', (SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{2}'), '{3}', GETDATE())";
  1785. sql = string.Format(sql, ContainerCode, LotNo, User, WorkPoint, Type);
  1786. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1787. {
  1788. throw new Exception(language.GetNameByCode("条码解绑容器记录日志表失败"));
  1789. }
  1790. return true;
  1791. }
  1792. else
  1793. {
  1794. throw new Exception(language.GetNameByCode("容器条码关联表不存在容器" + ContainerCode + "与条码" + LotNo + "的绑定关系"));
  1795. }
  1796. }
  1797. catch (Exception)
  1798. {
  1799. throw;
  1800. }
  1801. }
  1802. /// <summary>
  1803. /// 容器绑定父容器
  1804. /// </summary>
  1805. /// <param name="superiorContainerCode"></param>
  1806. /// <param name="containerCode"></param>
  1807. /// <param name="WorkPoint"></param>
  1808. /// <param name="User"></param>
  1809. /// <param name="Type"></param>
  1810. /// <param name="cmd"></param>
  1811. /// <param name="language"></param>
  1812. /// <returns></returns>
  1813. public static bool ICSContainerCon(string superiorContainerCode, string containerCode, string WorkPoint, string User, string MTIME, string Type, SqlCommand cmd, Dictionary<string, string> language)
  1814. {
  1815. try
  1816. {
  1817. Boolean flag = false;
  1818. DateTime now = DateTime.Now;
  1819. string superiorContainerID = "";
  1820. string sql = @"SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{0}' AND WorkPoint='{1}'";
  1821. sql = string.Format(sql, superiorContainerCode, WorkPoint);
  1822. DataTable dataTable = DBHelper.SQlReturnData(sql, cmd);
  1823. if(dataTable.Rows.Count == 0)
  1824. {
  1825. throw new Exception("父容器不存在");
  1826. }
  1827. else
  1828. {
  1829. //绑定父容器
  1830. superiorContainerID = dataTable.Rows[0]["ID"].ToString();
  1831. sql = @"UPDATE ICSContainer SET ContainerID='{0}',MUSER='{1}',MUSERName=(SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}'),MTIME='{2}' WHERE ContainerCode='{3}' AND WorkPoint='{4}'";
  1832. sql = string.Format(sql, superiorContainerID, User, MTIME, containerCode, WorkPoint);
  1833. if(!DBHelper.ExecuteNonQuery(sql, cmd))
  1834. {
  1835. throw new Exception("绑定父容器失败");
  1836. }
  1837. //添加日志
  1838. sql = @"INSERT INTO ICSContainerLog(ID,ContainerID,ContainerOrLotNo,Type,MUSER,MUSERName,WorkPoint,MTIME)
  1839. VALUES(NEWID(), (SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{0}'), '{1}', '{4}', '{2}', (SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{2}'), '{3}', GETDATE())";
  1840. sql = string.Format(sql, superiorContainerCode, containerCode, User, WorkPoint, Type);
  1841. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1842. {
  1843. throw new Exception("日志记录失败");
  1844. }
  1845. flag = true;
  1846. }
  1847. return flag;
  1848. }
  1849. catch (Exception ex)
  1850. {
  1851. log.Error(ex.Message);
  1852. //return false;
  1853. throw;
  1854. }
  1855. }
  1856. /// <summary>
  1857. /// 容器解绑父容器
  1858. /// </summary>
  1859. /// <param name="ContainerCode"></param>
  1860. /// <param name="WorkPoint"></param>
  1861. /// <param name="User"></param>
  1862. /// <param name="Type"></param>
  1863. /// <param name="MTIME"></param>
  1864. /// <param name="cmd"></param>
  1865. /// <param name="language"></param>
  1866. /// <returns></returns>
  1867. public static bool ICSContainerConUntie(string ContainerCode, string WorkPoint, string User, string Type, SqlCommand cmd, Dictionary<string, string> language)
  1868. {
  1869. try
  1870. {
  1871. //容器表父容器ID清空
  1872. string sql = string.Format(@"UPDATE ICSContainer SET ContainerID='',MUSER='{2}',
  1873. MUSERName=(SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  1874. ,MTIME=GETDATE()
  1875. WHERE ContainerCode='{0}' AND WorkPoint='{1}'",
  1876. ContainerCode,WorkPoint,User);
  1877. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1878. {
  1879. throw new Exception("容器解绑父容器失败");
  1880. }
  1881. //添加日志
  1882. sql = @"INSERT INTO ICSContainerLog(ID,ContainerID,ContainerOrLotNo,Type,MUSER,MUSERName,WorkPoint,MTIME)
  1883. VALUES(NEWID(), '', '{0}', '{3}', '{1}', (SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{1}'), '{2}', GETDATE())";
  1884. sql = string.Format(sql, ContainerCode, User, WorkPoint, Type);
  1885. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1886. {
  1887. throw new Exception("日志记录失败");
  1888. }
  1889. return true;
  1890. }
  1891. catch (Exception)
  1892. {
  1893. throw;
  1894. }
  1895. }
  1896. #endregion
  1897. #region 车次条码清单
  1898. public static bool ICSCartScheduleCreate(string LotNo ,string Quantity, string CartNo, string User, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1899. {
  1900. try
  1901. {
  1902. bool flag = false;
  1903. string sql = @"INSERT INTO dbo.ICSCartLotNoCheckList (id,CartNo,LotNo,MUSER,MUSERName,MTIME,WorkPoint,Quantity)
  1904. VALUES(NEWID(),'{0}','{1}','{2}','{2}',CONVERT(VARCHAR,GETDATE(),120),'{3}','{4}')";
  1905. sql = string.Format(sql, CartNo,LotNo,User,WorkPoint,"" == Quantity ? null : Quantity);
  1906. log.Debug("生成车次条码清单:" + sql);
  1907. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1908. {
  1909. throw new Exception("生成车次条码清单失败!");
  1910. }
  1911. flag = true;
  1912. return flag;
  1913. }
  1914. catch (Exception ex)
  1915. {
  1916. log.Error(ex.Message);
  1917. //return false;
  1918. throw;
  1919. }
  1920. }
  1921. #endregion
  1922. }
  1923. }