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

6190 lines
353 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using NFine.Code;
  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 ICSSubmitService
  20. {
  21. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  22. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ConnStr"];
  23. #region 源头单据信息
  24. /// <summary>
  25. /// 源头单据信息
  26. /// </summary>
  27. /// <param name="JsonData"></param>
  28. /// <returns></returns>
  29. public static DataTable TransInformationGet(WMSSourceDocumentModel JsonData)
  30. {
  31. var language = LanguageHelper.GetName("WMSAPIInfo");
  32. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  33. {
  34. conn.Open();
  35. SqlCommand cmd = new SqlCommand();
  36. cmd.Connection = conn;
  37. try
  38. {
  39. if (string.IsNullOrEmpty(JsonData.TransCode))
  40. {
  41. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  42. }
  43. else if (string.IsNullOrEmpty(JsonData.TransType))
  44. {
  45. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  46. }
  47. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  48. {
  49. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  50. }
  51. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  52. {
  53. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  54. }
  55. string TransType = JsonData.TransType;
  56. #region SLQ
  57. string sqlCheck = @"IF NOT EXISTS(SELECT a.ID FROM {1} WHERE {2})
  58. BEGIN
  59. RAISERROR('" + language.GetNameByCode("WMSAPIInfo035") + @"',16,1);
  60. RETURN
  61. END
  62. ";
  63. string sql = @"SELECT a.ID,
  64. {0}
  65. convert(varchar(100),'') AS LocationCode,
  66. convert(varchar(100),'') AS LotNo,
  67. convert(varchar(10),'') AS ToWarehouseCode,
  68. 0 AS LocationQty,
  69. 0 AS isMatched,
  70. a.InvCode,
  71. inv.InvName,
  72. inv.InvStd,
  73. a.Quantity,
  74. inv.InvUnit,
  75. a.Amount,
  76. a.WHCode,
  77. inv.AmountUnit,
  78. wh.WarehouseName AS WHName,
  79. ISNULL(ext.ProjectCode, '') AS ProjectCode,
  80. a.ExtensionID,
  81. 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,
  82. ISNULL(ext.Version, '') AS Version,
  83. ISNULL(ext.Brand, '') AS Brand,
  84. ISNULL(ext.cFree1, '') AS cFree1,
  85. ISNULL(ext.cFree2, '') AS cFree2,
  86. ISNULL(ext.cFree3, '') AS cFree3,
  87. ISNULL(ext.cFree4, '') AS cFree4,
  88. ISNULL(ext.cFree5, '') AS cFree5,
  89. ISNULL(ext.cFree6, '') AS cFree6,
  90. ISNULL(ext.cFree7, '') AS cFree7,
  91. ISNULL(ext.cFree8, '') AS cFree8,
  92. ISNULL(ext.cFree9, '') AS cFree9,
  93. ISNULL(ext.cFree10, '') AS cFree10,
  94. a.MUSER AS [User],
  95. a.MTIME AS [MTime]
  96. FROM {1}
  97. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  98. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  99. LEFT JOIN ICSWarehouse wh ON a.WHCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  100. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  101. WHERE {2} ";
  102. #endregion
  103. bool isDeliveryNotice = false; //送货、到货、含委外
  104. string columns = string.Empty; //查询源头单据表的特殊列名
  105. string tableName = string.Empty; //查询源头单据表名
  106. string where = string.Empty; //查询源头单据的过滤条件
  107. bool isMerge = false; //合并发料
  108. string columnsMerge = string.Empty; //合并发料查询源头单据表的特殊列名
  109. string tableNameMerge = string.Empty; //合并发料查询源头单据表名
  110. #region 出库
  111. #region 采购退货
  112. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  113. {
  114. isDeliveryNotice = true;
  115. columns = @"a.DNCode AS TransCode,
  116. a.DNDetailID AS DetailID,
  117. a.DNType AS Type,
  118. a.Sequence AS TransSequence,
  119. a.RCVQuantity AS IssueQuantity,
  120. a.Quantity,
  121. a.Amount,
  122. a.MUSER AS [User],
  123. a.MTIME AS [MTime],";
  124. tableName = @"ICSDeliveryNotice a ";
  125. where = @" a.DNCode='{0}' AND a.WorkPoint='{1}' AND a.DNType='2' ";
  126. }
  127. #endregion
  128. #region 委外发料(合并发料)
  129. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  130. {
  131. isMerge = true;
  132. columnsMerge = @"mer.MergeID+'~'+b.OOCode AS TransCode,
  133. a.PickID AS DetailID,
  134. a.SupplyType AS Type,
  135. b.Sequence+'~'+a.Sequence AS TransSequence,
  136. a.IssueQuantity AS IssueQuantity,";
  137. tableNameMerge = @"ICSOOPick a
  138. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
  139. INNER JOIN ICSMOPickMerge mer ON a.PickID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  140. columns = @"b.OOCode AS TransCode,
  141. a.PickID AS DetailID,
  142. a.SupplyType AS Type,
  143. b.Sequence+'~'+a.Sequence AS TransSequence,
  144. a.IssueQuantity AS IssueQuantity,";
  145. tableName = @"ICSOOPick a
  146. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint ";
  147. where = @" b.OOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' ";
  148. }
  149. #endregion
  150. #region 委外退货
  151. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  152. {
  153. isDeliveryNotice = true;
  154. columns = @"a.ODNCode AS TransCode,
  155. a.ODNDetailID AS DetailID,
  156. a.ODNType AS Type,
  157. a.Sequence AS TransSequence,
  158. a.RCVQuantity AS IssueQuantity,
  159. a.Quantity,
  160. a.Amount,
  161. a.MUSER AS [User],
  162. a.MTIME AS [MTime],";
  163. tableName = @"ICSODeliveryNotice a ";
  164. where = @" a.ODNCode='{0}' AND a.WorkPoint='{1}' AND a.ODNType='2' ";
  165. }
  166. #endregion
  167. #region 生产发料(合并发料)
  168. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  169. {
  170. isMerge = true;
  171. columnsMerge = @"mer.MergeID+'~'+b.MOCode AS TransCode,
  172. a.PickID AS DetailID,
  173. a.SupplyType AS Type,
  174. b.Sequence+'~'+a.Sequence AS TransSequence,
  175. a.IssueQuantity AS IssueQuantity,";
  176. tableNameMerge = @"ICSMOPick a
  177. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  178. INNER JOIN ICSMOPickMerge mer ON a.PickID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  179. columns = @"b.MOCode AS TransCode,
  180. a.PickID AS DetailID,
  181. a.SupplyType AS Type,
  182. b.Sequence+'~'+a.Sequence AS TransSequence,
  183. a.IssueQuantity AS IssueQuantity,";
  184. tableName = @"ICSMOPick a
  185. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint ";
  186. where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' ";
  187. }
  188. #endregion
  189. #region 销售出库(合并发料)
  190. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  191. {
  192. isMerge = true;
  193. columnsMerge = @"mer.MergeID+'~'+a.SDNCode AS TransCode,
  194. a.SDNDetailID AS DetailID,
  195. a.Type,
  196. a.Sequence AS TransSequence,
  197. a.SDNQuantity AS IssueQuantity,";
  198. tableNameMerge = @"ICSSDN a
  199. INNER JOIN ICSMOPickMerge mer ON a.SDNDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  200. columns = @"a.SDNCode AS TransCode,
  201. a.SDNDetailID AS DetailID,
  202. a.Type,
  203. a.Sequence AS TransSequence,
  204. a.SDNQuantity AS IssueQuantity,";
  205. tableName = @"ICSSDN a ";
  206. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' ";
  207. }
  208. #endregion
  209. #region 盘点
  210. else if (TransType == TransTypeEnum.Check.GetDescription())
  211. {
  212. #region SLQ
  213. sql = @"SELECT a.ID,
  214. {0}
  215. a.Quantity,
  216. a.SelectLevel AS LocationCode,
  217. a.Amount,
  218. a.MUSER AS [User],
  219. a.MTIME AS [MTime]
  220. FROM {1}
  221. WHERE {2} ";
  222. #endregion
  223. columns = @"a.CheckCode AS TransCode,
  224. a.ID,
  225. '' AS Type,";
  226. tableName = @"ICSCheck a ";
  227. where = @" a.CheckCode='{0}' AND a.WorkPoint='{1}' ";
  228. }
  229. #endregion
  230. #region 一步调拨(合并发料)
  231. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  232. {
  233. isMerge = true;
  234. columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
  235. a.TransferDetailID AS DetailID,
  236. '' AS Type,
  237. a.Sequence AS TransSequence,
  238. a.TransferQuantity AS IssueQuantity,
  239. a.ToWarehouseCode,";
  240. tableNameMerge = @"ICSTransfer a
  241. INNER JOIN ICSMOPickMerge mer ON a.TransferDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  242. #region SLQ
  243. sql = @"SELECT a.ID,
  244. {0}
  245. convert(varchar(100),'') AS LocationCode,
  246. convert(varchar(100),'') AS LotNo,
  247. 0 AS LocationQty,
  248. 0 AS isMatched,
  249. a.InvCode,
  250. inv.InvName,
  251. inv.InvStd,
  252. a.Quantity,
  253. inv.InvUnit,
  254. a.Amount,
  255. a.FromWarehouseCode AS WHCode,
  256. inv.AmountUnit,
  257. wh.WarehouseName AS WHName,
  258. a.ExtensionID,
  259. ext.ProjectCode,
  260. 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,
  261. ext.Version,
  262. ext.Brand,
  263. ext.cFree1,
  264. ext.cFree2,
  265. ext.cFree3,
  266. ext.cFree4,
  267. ext.cFree5,
  268. ext.cFree6,
  269. ext.cFree7,
  270. ext.cFree8,
  271. ext.cFree9,
  272. ext.cFree10,
  273. a.MUSER AS [User],
  274. a.MTIME AS [MTime]
  275. FROM {1}
  276. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  277. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  278. LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  279. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  280. WHERE {2} ";
  281. #endregion
  282. columns = @"a.TransferNO AS TransCode,
  283. a.TransferDetailID AS DetailID,
  284. '' AS Type,
  285. a.Sequence AS TransSequence,
  286. a.TransferQuantity AS IssueQuantity,
  287. a.ToWarehouseCode,";
  288. tableName = @"ICSTransfer a ";
  289. where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' ";
  290. }
  291. #endregion
  292. #region 调拨申请单(领料)
  293. else if (TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription())
  294. {
  295. isMerge = true;
  296. columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
  297. a.TransferDetailID AS DetailID,
  298. '' AS Type,
  299. a.Sequence AS TransSequence,
  300. a.TransferQuantity AS IssueQuantity,
  301. a.ToWarehouseCode,";
  302. tableNameMerge = @"ICSTransferApplication a
  303. INNER JOIN ICSMOPickMerge mer ON a.TransferDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  304. #region SLQ
  305. sql = @"SELECT a.ID,
  306. {0}
  307. convert(varchar(100),'') AS LocationCode,
  308. convert(varchar(100),'') AS LotNo,
  309. 0 AS LocationQty,
  310. 0 AS isMatched,
  311. a.InvCode,
  312. inv.InvName,
  313. inv.InvStd,
  314. a.Quantity,
  315. inv.InvUnit,
  316. a.Amount,
  317. a.FromWarehouseCode AS WHCode,
  318. inv.AmountUnit,
  319. wh.WarehouseName AS WHName,
  320. a.ExtensionID,
  321. ext.ProjectCode,
  322. 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,
  323. ext.Version,
  324. ext.Brand,
  325. ext.cFree1,
  326. ext.cFree2,
  327. ext.cFree3,
  328. ext.cFree4,
  329. ext.cFree5,
  330. ext.cFree6,
  331. ext.cFree7,
  332. ext.cFree8,
  333. ext.cFree9,
  334. ext.cFree10,
  335. a.MUSER AS [User],
  336. a.MTIME AS [MTime]
  337. FROM {1}
  338. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  339. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  340. LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  341. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  342. WHERE {2} ";
  343. #endregion
  344. columns = @"a.TransferNO AS TransCode,
  345. a.TransferDetailID AS DetailID,
  346. '' AS Type,
  347. a.Sequence AS TransSequence,
  348. a.TransferQuantity AS IssueQuantity,
  349. a.ToWarehouseCode,";
  350. tableName = @"ICSTransferApplication a ";
  351. where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' ";
  352. }
  353. #endregion
  354. #region 调拨(合并发料)
  355. else if (TransType == TransTypeEnum.StepTransferDocIn.GetDescription())
  356. {
  357. }
  358. #endregion
  359. #region 两步调出(合并发料)
  360. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  361. {
  362. isMerge = true;
  363. columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
  364. a.OutDetailID AS DetailID,
  365. '' AS Type,
  366. a.Sequence AS TransSequence,
  367. a.OutQuantity AS IssueQuantity,";
  368. tableNameMerge = @"ICSOtherOut a
  369. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  370. INNER JOIN ICSMOPickMerge mer ON a.OutDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  371. columns = @"a.OutCode AS TransCode,
  372. a.OutDetailID AS DetailID,
  373. '' AS Type,
  374. a.Sequence AS TransSequence,
  375. a.OutQuantity AS IssueQuantity,";
  376. tableName = @"ICSOtherOut a
  377. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
  378. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' ";
  379. }
  380. #endregion
  381. #region 其他出库(合并发料)
  382. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  383. {
  384. isMerge = true;
  385. columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
  386. a.OutDetailID AS DetailID,
  387. '' AS Type,
  388. a.Sequence AS TransSequence,
  389. a.OutQuantity AS IssueQuantity,";
  390. tableNameMerge = @"ICSOtherOut a
  391. INNER JOIN ICSMOPickMerge mer ON a.OutDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  392. columns = @"a.OutCode AS TransCode,
  393. a.OutDetailID AS DetailID,
  394. '' AS Type,
  395. a.Sequence AS TransSequence,
  396. a.OutQuantity AS IssueQuantity,";
  397. tableName = @"ICSOtherOut a ";
  398. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' ";
  399. }
  400. #endregion
  401. #region 领料申请单发料(合并发料)
  402. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  403. {
  404. isMerge = true;
  405. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  406. a.ApplyDetailID AS DetailID,
  407. a.Type,
  408. a.Sequence AS TransSequence,
  409. a.IssueQuantity AS IssueQuantity,";
  410. tableNameMerge = @"ICSMOApply a
  411. INNER JOIN ICSMOPickMerge mer ON a.ApplyDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  412. columns = @"a.ApplyCode AS TransCode,
  413. a.ApplyDetailID AS DetailID,
  414. a.Type,
  415. a.Sequence AS TransSequence,
  416. a.IssueQuantity AS IssueQuantity,";
  417. tableName = @"ICSMOApply a ";
  418. where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' ";
  419. }
  420. #endregion
  421. #region 委外领料申请单发料(合并发料)
  422. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  423. {
  424. isMerge = true;
  425. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  426. a.ApplyDetailID AS DetailID,
  427. a.Type,
  428. a.Sequence AS TransSequence,
  429. a.IssueQuantity AS IssueQuantity,";
  430. tableNameMerge = @"ICSOApply a
  431. INNER JOIN ICSMOPickMerge mer ON a.ApplyDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  432. columns = @"a.ApplyCode AS TransCode,
  433. a.ApplyDetailID AS DetailID,
  434. a.Type,
  435. a.Sequence AS TransSequence,
  436. a.IssueQuantity AS IssueQuantity,";
  437. tableName = @"ICSOApply a ";
  438. where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' ";
  439. }
  440. #endregion
  441. #region 开立材料出库(合并发料)
  442. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  443. {
  444. isMerge = true;
  445. columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
  446. a.IssueDetailID AS DetailID,
  447. a.Type,
  448. a.Sequence AS TransSequence,
  449. a.IssueQuantity AS IssueQuantity,";
  450. tableNameMerge = @"ICSMOIssue a
  451. INNER JOIN ICSMOPickMerge mer ON a.IssueDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  452. columns = @"a.IssueCode AS TransCode,
  453. a.IssueDetailID AS DetailID,
  454. a.Type,
  455. a.Sequence AS TransSequence,
  456. a.IssueQuantity AS IssueQuantity,";
  457. tableName = @"ICSMOIssue a ";
  458. where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' ";
  459. }
  460. #endregion
  461. #region 开立委外材料出库(合并发料)
  462. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  463. {
  464. isMerge = true;
  465. columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
  466. a.IssueDetailID AS DetailID,
  467. a.Type,
  468. a.Sequence AS TransSequence,
  469. a.IssueQuantity AS IssueQuantity,";
  470. tableNameMerge = @"ICSOIssue a
  471. INNER JOIN ICSMOPickMerge mer ON a.IssueDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  472. columns = @"a.IssueCode AS TransCode,
  473. a.IssueDetailID AS DetailID,
  474. a.Type,
  475. a.Sequence AS TransSequence,
  476. a.IssueQuantity AS IssueQuantity,";
  477. tableName = @"ICSOIssue a ";
  478. where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' ";
  479. }
  480. #endregion
  481. #region 开立红字入库单
  482. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  483. {
  484. columns = @"a.RCVCode AS TransCode,
  485. a.RCVDetailID AS DetailID,
  486. a.Type,
  487. a.Sequence AS TransSequence,
  488. a.RCVQuantity AS IssueQuantity,";
  489. tableName = @"ICSPurchaseReceive a ";
  490. where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' ";
  491. }
  492. #endregion
  493. #region 开立委外红字入库单
  494. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  495. {
  496. columns = @"a.RCVCode AS TransCode,
  497. a.RCVDetailID AS DetailID,
  498. a.Type,
  499. a.Sequence AS TransSequence,
  500. a.RCVQuantity AS IssueQuantity,";
  501. tableName = @"ICSOutsourcingReceive a ";
  502. where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' ";
  503. }
  504. #endregion
  505. #region 借用(合并发料)
  506. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  507. {
  508. isMerge = true;
  509. columnsMerge = @"mer.MergeID+'~'+a.BrrowCode AS TransCode,
  510. a.BrrowDetailID AS DetailID,
  511. '' AS Type,
  512. a.Sequence AS TransSequence,
  513. a.BrrowQuantity AS IssueQuantity,";
  514. tableNameMerge = @"ICSBrrow a
  515. INNER JOIN ICSMOPickMerge mer ON a.BrrowDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  516. columns = @"a.BrrowCode AS TransCode,
  517. a.BrrowDetailID AS DetailID,
  518. '' AS Type,
  519. a.Sequence AS TransSequence,
  520. a.BrrowQuantity AS IssueQuantity,";
  521. tableName = @"ICSBrrow a ";
  522. where = @" a.BrrowCode='{0}' AND a.WorkPoint='{1}' ";
  523. }
  524. #endregion
  525. #region 送货单
  526. else if (TransType == TransTypeEnum.ASN.GetDescription())
  527. {
  528. isDeliveryNotice = true;
  529. columns = @"asn.ASNCode AS TransCode,
  530. asn.ID AS DetailID,
  531. asn.LotNo,
  532. '' AS Type,
  533. asn.Sequence AS TransSequence,
  534. asn.DNQuantity AS IssueQuantity,
  535. asn.Quantity,
  536. asn.Quantity*(a.Amount/a.Quantity) AS Amount,
  537. asn.MUSER AS [User],
  538. asn.MTIME AS [MTime],";
  539. tableName = @"ICSInventoryLot a
  540. INNER JOIN ICSASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint ";
  541. where = @" asn.ASNCode='{0}' AND a.WorkPoint='{1}' ";
  542. }
  543. #endregion
  544. #region 委外送货单
  545. else if (TransType == TransTypeEnum.OASN.GetDescription())
  546. {
  547. isDeliveryNotice = true;
  548. columns = @"asn.OASNCode AS TransCode,
  549. asn.ID AS DetailID,
  550. asn.LotNo,
  551. '' AS Type,
  552. asn.Sequence AS TransSequence,
  553. asn.ODNQuantity AS IssueQuantity,
  554. asn.Quantity,
  555. asn.Quantity*(a.Amount/a.Quantity) AS Amount,
  556. asn.MUSER AS [User],
  557. asn.MTIME AS [MTime],";
  558. tableName = @"ICSInventoryLot a
  559. INNER JOIN ICSOASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint ";
  560. where = @" asn.OASNCode='{0}' AND a.WorkPoint='{1}' ";
  561. }
  562. #endregion
  563. #endregion
  564. #region 入库
  565. #region 采购入库
  566. else if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  567. {
  568. }
  569. #endregion
  570. #region 审核的到货单
  571. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  572. {
  573. }
  574. #endregion
  575. #region 采购拒收
  576. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  577. {
  578. }
  579. #endregion
  580. #region 审核的委外到货单
  581. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  582. {
  583. }
  584. #endregion
  585. #region 委外拒收
  586. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  587. {
  588. }
  589. #endregion
  590. #region 委外退料
  591. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  592. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  593. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  594. {
  595. }
  596. #endregion
  597. #region 委外入库
  598. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  599. {
  600. }
  601. #endregion
  602. #region 生产退料
  603. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  604. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  605. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  606. {
  607. }
  608. #endregion
  609. #region 生产入库
  610. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  611. {
  612. }
  613. #endregion
  614. #region 开立的生产入库单
  615. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  616. {
  617. }
  618. #endregion
  619. #region 返工工单
  620. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  621. {
  622. }
  623. #endregion
  624. #region 销售退货
  625. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  626. {
  627. }
  628. #endregion
  629. #region 两步调入
  630. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  631. {
  632. columns = @"a.InCode AS TransCode,
  633. a.InDetailID AS DetailID,
  634. '' AS Type,
  635. a.Sequence AS TransSequence,
  636. a.InQuantity AS IssueQuantity,";
  637. tableName = @"ICSOtherIn a
  638. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
  639. where = @" a.InCode='{0}' AND a.WorkPoint='{1}' ";
  640. }
  641. #endregion
  642. #region 销售退货-原条码
  643. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  644. {
  645. columns = @"a.SDNCode AS TransCode,
  646. a.SDNDetailID AS DetailID,
  647. a.Type,
  648. a.Sequence AS TransSequence,
  649. a.SDNQuantity AS IssueQuantity,";
  650. tableName = @"ICSSDN a ";
  651. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' ";
  652. }
  653. #endregion
  654. #region 其他入库
  655. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  656. {
  657. }
  658. #endregion
  659. #region 拆卸单
  660. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  661. {
  662. columns = @"a.DABDOCCode AS TransCode,
  663. a.DABDOCDetailID AS DetailID,
  664. a.DABDOCType AS Type,
  665. a.Sequence AS TransSequence,
  666. a.DABDOCQuantity AS IssueQuantity,";
  667. tableName = @"ICSDisassemblyDoc a";
  668. where = @" a.DABDOCCode='{0}' AND a.WorkPoint='{1}' AND a.DABDOCType='2' ";
  669. }
  670. #endregion
  671. #region 归还
  672. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  673. {
  674. }
  675. #endregion
  676. #endregion
  677. if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName) || string.IsNullOrWhiteSpace(where))
  678. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
  679. #region 判断是否启用匹配库位
  680. string sqlCheckSign = @"select F_EnabledMark from Sys_SRM_Items where F_EnCode = 'OutWithLocationCode'and F_EnabledMark = '1'";
  681. DataTable flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  682. if (flag != null && flag.Rows.Count > 0)
  683. //if (true)
  684. {
  685. sql = @"select * into #maintemp from (" + sql + @")a
  686. select * into #resulttemp from #maintemp
  687. truncate table #resulttemp
  688. select a.lotno,a.locationcode,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime,a.warehousecode,isnull(ext.ProjectCode,'')as ProjectCode, isnull(ext.Version,'')as Version,
  689. isnull(ext.Brand,'')as Brand,
  690. isnull(ext.cFree1,'')as cFree1,
  691. isnull(ext.cFree2,'') cFree2,
  692. isnull(ext.cFree3,'') cFree3,
  693. isnull(ext.cFree4,'') cFree4,
  694. isnull(ext.cFree5,'') cFree5,
  695. isnull(ext.cFree6,'') cFree6,
  696. isnull(ext.cFree7,'') cFree7,
  697. isnull(ext.cFree8,'') cFree8,
  698. isnull(ext.cFree9,'') cFree9,
  699. isnull(ext.cFree10,'') cFree10,ISNULL(ext.BatchCode, '') BatchCode into #barcodetemp
  700. from ICSWareHouseLotInfo a INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  701. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  702. LEFT JOIN
  703. (select invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE from #maintemp
  704. group by invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE) b on a.invcode = b.invcode
  705. where (a.warehousecode = b.whcode or ISNULL(b.whcode,'')='') and a.Quantity-a.lockQuantity>0 and
  706. isnull(ext.ProjectCode,'') = b.ProjectCode and isnull(ext.Version,'')=b.Version and
  707. isnull(ext.Brand,'') =b.Brand and
  708. isnull(ext.cFree1,'')=b.cFree1 and
  709. isnull(ext.cFree2,'')=b.cFree2 and
  710. isnull(ext.cFree3,'')=b.cFree3 and
  711. isnull(ext.cFree4,'')=b.cFree4 and
  712. isnull(ext.cFree5,'')=b.cFree5 and
  713. isnull(ext.cFree6,'')=b.cFree6 and
  714. isnull(ext.cFree7,'')=b.cFree7 and
  715. isnull(ext.cFree8,'')=b.cFree8 and
  716. isnull(ext.cFree9,'')=b.cFree9 and
  717. isnull(ext.cFree10,'')=b.cFree10 and
  718. ((isnull(b.BatchCode,'')<>'' and b.BatchCode =ext.BatchCode) or isnull(b.BatchCode,'') ='')
  719. BEGIN
  720. DECLARE @transSequence VARCHAR(50);--
  721. DECLARE @qty decimal(18, 4);--
  722. DECLARE @needqty decimal(18, 4);--
  723. DECLARE @lotno VARCHAR(50);--
  724. DECLARE @locationcode VARCHAR(50);--
  725. DECLARE @WHCode VARCHAR(50);--
  726. DECLARE @invcode VARCHAR(50);--
  727. DECLARE @issueQuantity decimal(18, 4);
  728. DECLARE tempCursor CURSOR FOR (select transSequence from #maintemp); --tempCursor
  729. OPEN tempCursor; --
  730. FETCH NEXT FROM tempCursor INTO @transSequence; --
  731. WHILE @@fetch_status=0
  732. BEGIN
  733. select @needqty=Quantity,@issueQuantity=issueQuantity from #maintemp where transSequence = @transSequence
  734. PRINT @transSequence
  735. WHILE @needqty>0
  736. BEGIN
  737. select top 1 @qty = isnull(a.quantity,0), @locationcode = isnull(a.locationcode,''),@lotno = isnull(a.lotno,''),@WHCode = isnull(a.warehousecode,''),@invcode = b.invcode from #barcodetemp a
  738. right JOIN(select invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE from #maintemp where transSequence=@transSequence)b on a.invcode = b.invcode
  739. and ((isnull(b.ProjectCode,'')<>'' and b.ProjectCode = a.ProjectCode) or isnull(b.ProjectCode,'') ='') and
  740. ((isnull(b.Version,'')<>'' and b.Version = a.Version) or isnull(b.Version,'') ='') and
  741. ((isnull(b.Brand,'')<>'' and b.Brand = a.Brand )or isnull(b.Brand,'') ='') and
  742. ((isnull(b.cFree1,'')<>'' and b.cFree1 =a.cFree1) or isnull(b.cFree1,'') ='') and
  743. ((isnull(b.cFree2,'')<>'' and b.cFree2 =a.cFree2 )or isnull(b.cFree2,'') ='') and
  744. ((isnull(b.cFree3,'')<>'' and b.cFree3 =a.cFree3 )or isnull(b.cFree3,'') ='') and
  745. ((isnull(b.cFree4,'')<>'' and b.cFree4 =a.cFree4 )or isnull(b.cFree4,'') ='') and
  746. ((isnull(b.cFree5,'')<>'' and b.cFree5 =a.cFree5) or isnull(b.cFree5,'') ='') and
  747. ((isnull(b.cFree6,'')<>'' and b.cFree6 =a.cFree6 )or isnull(b.cFree6,'') ='') and
  748. ((isnull(b.cFree7,'')<>'' and b.cFree7 =a.cFree7) or isnull(b.cFree7,'') ='') and
  749. ((isnull(b.cFree8,'')<>'' and b.cFree8 =a.cFree8) or isnull(b.cFree8,'') ='') and
  750. ((isnull(b.cFree9,'')<>'' and b.cFree9 =a.cFree9) or isnull(b.cFree9,'') ='') and
  751. ((isnull(b.cFree10,'')<>'' and b.cFree10 =a.cFree10) or isnull(b.cFree10,'') ='') and
  752. ((isnull(b.BatchCode,'')<>'' and b.BatchCode =a.BatchCode) or isnull(b.BatchCode,'') ='')ORDER BY mtime,locationcode
  753. IF(@needqty-@issueQuantity-@qty>=0 and ISNULL(@lotno, '')<>'')
  754. BEGIN
  755. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  756. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotNo,
  757. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  758. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  759. ISNULL(Amount, 0),[User],[MTime],InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),@qty,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  760. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  761. delete from #barcodetemp where lotno = @lotno
  762. SET @needqty=@needqty-@qty
  763. END
  764. ELSE if(@needqty-@issueQuantity-@qty<0 and ISNULL(@lotno, '')<>''and @needqty-@issueQuantity>0)
  765. BEGIN
  766. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  767. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
  768. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  769. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  770. ISNULL(Amount, 0),[User],[MTime],InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),case WHEN ISNULL(@qty, 0)=0 THEN 0 else @needqty-@issueQuantity end ,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  771. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  772. update #barcodetemp set quantity = @qty-@needqty+-@issueQuantity where lotno = @lotno
  773. SET @needqty=@needqty-@issueQuantity-@qty
  774. END
  775. ELSE
  776. BEGIN
  777. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  778. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
  779. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  780. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  781. ISNULL(Amount, 0),[User],[MTime],InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),0 ,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  782. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  783. SET @needqty=0
  784. END
  785. END
  786. FETCH NEXT FROM tempCursor INTO @transSequence;
  787. END
  788. CLOSE tempCursor
  789. DEALLOCATE tempCursor
  790. END
  791. select id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  792. [User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,sum(LocationQty)as LocationQty,isMatched,AmountUnit,--lotno,
  793. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #resulttemp GROUP BY id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  794. [User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,isMatched,AmountUnit,--lotno,
  795. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ORDER BY locationcode ASC ,InvCode ASC
  796. DROP table #maintemp
  797. DROP table #resulttemp
  798. DROP table #barcodetemp";
  799. }
  800. #endregion
  801. if (isDeliveryNotice)//送货、到货、含委外
  802. {
  803. #region SLQ
  804. sql = sqlCheck + @"SELECT a.ID,
  805. {0}
  806. a.InvCode,
  807. inv.InvName,
  808. inv.InvStd,
  809. inv.InvUnit,
  810. '' AS WHCode,
  811. inv.AmountUnit,
  812. '' AS WHName,
  813. a.ExtensionID,
  814. ext.ProjectCode,
  815. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  816. ext.Version,
  817. ext.Brand,
  818. ext.cFree1,
  819. ext.cFree2,
  820. ext.cFree3,
  821. ext.cFree4,
  822. ext.cFree5,
  823. ext.cFree6,
  824. ext.cFree7,
  825. ext.cFree8,
  826. ext.cFree9,
  827. ext.cFree10
  828. FROM {1}
  829. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  830. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  831. WHERE {2} ";
  832. #endregion
  833. }
  834. else if(isMerge)//合并发料
  835. {
  836. #region SLQ
  837. string sqlMerge = "SELECT ID FROM ICSMOPickMerge WHERE MergeID='"+ JsonData.TransCode + "' AND WorkPoint='"+ JsonData.WorkPoint + "'";
  838. DataTable sign = DBHelper.SQlReturnData(sqlMerge, cmd);
  839. if (sign != null && flag.Rows.Count > 0)
  840. {
  841. string whereMerge = string.Format("mer.MergeID='{0}' AND mer.WorkPoint='{1}'", JsonData.TransCode, JsonData.WorkPoint);
  842. sql = string.Format(sql, columnsMerge, tableNameMerge, whereMerge, JsonData.TransCode, JsonData.WorkPoint);
  843. }
  844. else
  845. {
  846. sql = @" BEGIN
  847. IF EXISTS(SELECT a.ID FROM {1} INNER JOIN ICSMOPickMerge c ON a.ID=c.SourceID AND a.WorkPoint=c.WorkPoint WHERE {2})
  848. BEGIN
  849. RAISERROR('" + language.GetNameByCode("WMSAPIInfo194") + @"',16,1);
  850. RETURN
  851. END
  852. " + sqlCheck + sql + @"
  853. END";
  854. }
  855. #endregion
  856. }
  857. else
  858. {
  859. sql = sqlCheck + sql;
  860. }
  861. where = string.Format(where, JsonData.TransCode, JsonData.WorkPoint);
  862. sql = string.Format(sql, columns, tableName, where, JsonData.TransCode);
  863. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  864. return table;
  865. }
  866. catch (Exception ex)
  867. {
  868. log.Error(ex.Message);
  869. throw new Exception(ex.Message);
  870. }
  871. finally
  872. {
  873. if (conn.State == ConnectionState.Open)
  874. {
  875. conn.Close();
  876. }
  877. conn.Dispose();
  878. }
  879. }
  880. }
  881. #endregion
  882. #region 条码信息
  883. /// <summary>
  884. /// 条码信息
  885. /// </summary>
  886. /// <param name="JsonData"></param>
  887. /// <returns></returns>
  888. public static Result BarCodeInformationGet(BarCodeModel JsonData)
  889. {
  890. var language = LanguageHelper.GetName("WMSAPIInfo");
  891. DataTable table = new DataTable();
  892. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  893. {
  894. conn.Open();
  895. SqlCommand cmd = new SqlCommand();
  896. cmd.Connection = conn;
  897. try
  898. {
  899. string ScanType = DBHelper.ScanTypeCheck(JsonData.Code, JsonData.WorkPoint, cmd);
  900. if (string.IsNullOrEmpty(JsonData.Code))
  901. {
  902. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  903. }
  904. else if (string.IsNullOrEmpty(JsonData.TransType))
  905. {
  906. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  907. }
  908. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  909. {
  910. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  911. }
  912. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  913. {
  914. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  915. }
  916. string TransType = JsonData.TransType;
  917. string sql = "";
  918. string LotTypesql = "";
  919. string Losql = "";
  920. string sqlNew = "";
  921. string LotType = "";
  922. #region SLQ
  923. if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
  924. {
  925. //Losql = @"SELECT a.ID,
  926. // con.ContainerCode,
  927. // con.ContainerName,
  928. // a.LotNo,
  929. // a.InvCode,
  930. // inv.InvName,
  931. // inv.InvStd,
  932. // inv.InvUnit,
  933. // inv.LotEnable,
  934. // {0}
  935. // inv.AmountUnit,
  936. // ext.ID AS ExtensionID,
  937. // ext.ProjectCode,
  938. // ext.Version,
  939. // ext.Brand,
  940. // ext.cFree1,
  941. // ext.cFree2,
  942. // ext.cFree3,
  943. // ext.cFree4,
  944. // ext.cFree5,
  945. // ext.cFree6,
  946. // ext.cFree7,
  947. // ext.cFree8,
  948. // ext.cFree9,
  949. // ext.cFree10,
  950. // a.MUSER AS [User],
  951. // a.MTIME AS [MTime]
  952. // FROM {1}
  953. // LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  954. // LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  955. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  956. // WHERE a.Quantity>0 and a.WorkPoint='{3}'";
  957. Losql = @"DECLARE @aa VARCHAR(MAX)
  958. DECLARE @bb VARCHAR(MAX)
  959. DECLARE @cc VARCHAR(MAX)
  960. DECLARE @b VARCHAR(MAX)
  961. set @b =
  962. 'SELECT a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,
  963. inv.InvName,
  964. inv.InvStd,
  965. inv.InvUnit,
  966. inv.LotEnable,
  967. s.WarehouseCode,sum(a.Quantity) as Qty,s.sumQty,
  968. inv.AmountUnit,
  969. ext.ID AS ExtensionID,
  970. ext.ProjectCode,
  971. ext.Version,
  972. ext.Brand,
  973. ext.cFree1,
  974. ext.cFree2,
  975. ext.cFree3,
  976. ext.cFree4,
  977. ext.cFree5,
  978. ext.cFree6,
  979. ext.cFree7,
  980. ext.cFree8,
  981. ext.cFree9,
  982. ext.cFree10,
  983. a.MUSER AS [User],
  984. a.MTIME AS [MTime]
  985. FROM ICSWareHouseLotInfo a
  986. LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
  987. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  988. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  989. LEFT JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode from ICSWareHouseLotInfo group by WarehouseCode,INVCode)s ON a.INVCode=s.INVCode
  990. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  991. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  992. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  993. WHERE a.Quantity>0 and a.WorkPoint=''{3}'' and'
  994. select @aa=id from ICSWareHouseLotInfo where LotNo='{2}'
  995. IF @aa IS NOT NULL
  996. BEGIN
  997. set @b = @b+' lot.invcode IN(SELECT invcode FROM ICSWareHouseLotInfo where LotNo=''{2}'')
  998. group by a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.LotEnable,s.WarehouseCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,s.sumQty,inv.AmountUnit,
  999. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MTIME
  1000. '
  1001. END
  1002. select @bb=id from ICSLocation where LocationCode='{2}'
  1003. IF @bb IS not NULL
  1004. BEGIN
  1005. set @b = @b+' a.WarehouseCode=s.WarehouseCode and a.LocationCode=''{2}''
  1006. group by a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.LotEnable,s.WarehouseCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,s.sumQty,inv.AmountUnit,
  1007. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MTIME'
  1008. END
  1009. select @cc=id from ICSInventory where invcode='{2}'
  1010. IF @cc IS not NULL
  1011. BEGIN
  1012. set @b = @b+' a.WarehouseCode=s.WarehouseCode and inv.invcode=''{2}''
  1013. group by a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.LotEnable,s.WarehouseCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,s.sumQty,inv.AmountUnit,
  1014. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MTIME'
  1015. END
  1016. exec(@b)
  1017. ";
  1018. }
  1019. else
  1020. {
  1021. if (ScanType == "LOTNO")
  1022. {
  1023. sql = @"SELECT a.ID,
  1024. con.ContainerCode,
  1025. con.ContainerName,
  1026. a.LotNo,
  1027. a.InvCode,
  1028. inv.InvName,
  1029. inv.InvStd,
  1030. inv.InvUnit,
  1031. inv.LotEnable,
  1032. {0}
  1033. inv.AmountUnit,
  1034. ext.ID AS ExtensionID,
  1035. ext.ProjectCode,
  1036. ext.Version,
  1037. ext.Brand,
  1038. ext.cFree1,
  1039. ext.cFree2,
  1040. ext.cFree3,
  1041. ext.cFree4,
  1042. ext.cFree5,
  1043. ext.cFree6,
  1044. ext.cFree7,
  1045. ext.cFree8,
  1046. ext.cFree9,
  1047. ext.cFree10,
  1048. a.MUSER AS [User],
  1049. a.MTIME AS [MTime]
  1050. FROM {1}
  1051. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  1052. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  1053. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1054. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' ";
  1055. }
  1056. else
  1057. {
  1058. sql = @"SELECT a.ID,
  1059. con.ContainerCode,
  1060. con.ContainerName,
  1061. a.LotNo,
  1062. a.InvCode,
  1063. inv.InvName,
  1064. inv.InvStd,
  1065. inv.InvUnit,
  1066. {0}
  1067. inv.AmountUnit,
  1068. ext.ID AS ExtensionID,
  1069. ext.ProjectCode,
  1070. ext.Version,
  1071. ext.Brand,
  1072. ext.cFree1,
  1073. ext.cFree2,
  1074. ext.cFree3,
  1075. ext.cFree4,
  1076. ext.cFree5,
  1077. ext.cFree6,
  1078. ext.cFree7,
  1079. ext.cFree8,
  1080. ext.cFree9,
  1081. ext.cFree10,
  1082. a.MUSER AS [User],
  1083. a.MTIME AS [MTime]
  1084. FROM {1}
  1085. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  1086. LEFT JOIN ICSBomALL bom ON bom.ID=conlot.ContainerID
  1087. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  1088. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1089. WHERE bom.ContainerCode='{2}' AND a.WorkPoint='{3}' ";
  1090. }
  1091. }
  1092. #endregion
  1093. bool isOut = false; //出库标记
  1094. string columns = string.Empty; //查询源头单据表的特殊列名
  1095. string columnsWHNAME = string.Empty;
  1096. string columnsWHCODE = string.Empty;
  1097. string tableName = string.Empty; //查询源头单据表名
  1098. string where = string.Empty; //排序
  1099. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription() //采购退货
  1100. || TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription() //委外发料
  1101. || TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription() //委外退货
  1102. || TransType == TransTypeEnum.MOIssueDoc.GetDescription() //生产发料
  1103. || TransType == TransTypeEnum.SalesShipmentDoc.GetDescription() //销售出库
  1104. || TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription() //一步调拨
  1105. || TransType == TransTypeEnum.StepTransferDocIn.GetDescription() //调拨
  1106. || TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription() //两步调出
  1107. || TransType == TransTypeEnum.OtherOutDoc.GetDescription() //其他出库
  1108. || TransType == TransTypeEnum.Check.GetDescription() //盘点
  1109. || TransType == TransTypeEnum.MOApply.GetDescription() //领料申请单
  1110. || TransType == TransTypeEnum.OOApply.GetDescription() //委外领料申请单
  1111. || TransType == TransTypeEnum.MOIssue.GetDescription() //开立材料出库单
  1112. || TransType == TransTypeEnum.OOIssue.GetDescription() //开立委外材料出库单
  1113. || TransType == TransTypeEnum.PurchaseReceive.GetDescription() //开立红字入库单
  1114. || TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription()//开立委外红字入库单
  1115. || TransType == TransTypeEnum.BrrowDoc.GetDescription() //借用
  1116. || TransType == TransTypeEnum.TransferLibrary.GetDescription() //移库
  1117. //|| TransType == TransTypeEnum.DisassemblyDoc.GetDescription() //拆卸单(散件生成条码入库)
  1118. )
  1119. {
  1120. isOut = true;
  1121. }
  1122. //库位查询
  1123. if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
  1124. {
  1125. // Losql = @"" + Losql + "group by a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.LotEnable,s.WarehouseCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,s.sumQty,inv.AmountUnit,ext.ID,ext.ProjectCode,ext.Version,ext.Brand, " +
  1126. // "ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MTIME";
  1127. // columns = @"s.WarehouseCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,sum(a.Quantity) as Qty,s.sumQty,";
  1128. // tableName = @"ICSWareHouseLotInfo a
  1129. //LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
  1130. //INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1131. //INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1132. //LEFT JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode from ICSWareHouseLotInfo group by WarehouseCode,INVCode)s
  1133. //ON a.INVCode=s.INVCode ";
  1134. }
  1135. else
  1136. {
  1137. //两步调入条码
  1138. if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  1139. {
  1140. if (string.IsNullOrEmpty(JsonData.TransCode))
  1141. {
  1142. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  1143. }
  1144. if (ScanType == "LOTNO")
  1145. {
  1146. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSOtherIn Otin
  1147. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  1148. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  1149. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  1150. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1151. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND Otin.InCode = '" + JsonData.TransCode + @"')
  1152. BEGIN
  1153. RAISERROR('" + language.GetNameByCode("WMSAPIInfo036") + @"',16,1);
  1154. RETURN
  1155. END
  1156. " + sql + "AND Otin.InCode = '" + JsonData.TransCode + @"'
  1157. GROUP BY a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  1158. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  1159. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
  1160. columns = @"SUM(log.Quantity) AS Quantity,
  1161. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  1162. a.WarehouseCode AS WHCode,
  1163. wh.WarehouseName AS WHName,
  1164. a.LocationCode,
  1165. loc.LocationName,
  1166. 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,";
  1167. tableName = @"ICSOtherIn Otin
  1168. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  1169. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  1170. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  1171. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1172. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1173. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1174. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1175. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1176. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1177. }
  1178. else
  1179. {
  1180. sql = @"WITH ICSBomALL AS
  1181. (
  1182. SELECT
  1183. ContainerCode AS TContainerCode,
  1184. ContainerCode AS PContainerCode,
  1185. ContainerCode AS ContainerCode,
  1186. ID,
  1187. ContainerID,
  1188. 0 AS [Level],
  1189. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  1190. CAST('00001' AS nvarchar(MAX)) AS Sort
  1191. FROM ICSContainer
  1192. WHERE ContainerCode='{2}'
  1193. UNION ALL
  1194. SELECT
  1195. b.TContainerCode,
  1196. b.ContainerCode AS PContainerCode,
  1197. a.ContainerCode,
  1198. a.ID,
  1199. a.ContainerID,
  1200. b.[Level]+1 AS [Level],
  1201. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  1202. CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
  1203. FROM
  1204. ICSContainer a
  1205. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  1206. )
  1207. " + sql + "AND Otin.InCode = '" + JsonData.TransCode + @"'
  1208. GROUP BY a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  1209. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  1210. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
  1211. columns = @"SUM(log.Quantity) AS Quantity,
  1212. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  1213. a.WarehouseCode AS WHCode,
  1214. wh.WarehouseName AS WHName,
  1215. a.LocationCode,
  1216. loc.LocationName,
  1217. 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,";
  1218. tableName = @"ICSOtherIn Otin
  1219. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  1220. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  1221. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  1222. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1223. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1224. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1225. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1226. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1227. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1228. }
  1229. }
  1230. //销售退货-原条码(可支持一个条码多次发货,汇总数量,目前加了限制:785-793行)
  1231. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  1232. {
  1233. if (string.IsNullOrEmpty(JsonData.TransCode))
  1234. {
  1235. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  1236. }
  1237. if (ScanType == "LOTNO")
  1238. {
  1239. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSSDN sdn
  1240. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  1241. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1242. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND sdn.Type='1')
  1243. BEGIN
  1244. RAISERROR('" + language.GetNameByCode("WMSAPIInfo037") + @"',16,1);
  1245. RETURN
  1246. END
  1247. IF EXISTS(SELECT log.LotNo FROM ICSSDN sdn
  1248. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  1249. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1250. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND sdn.Type='1' AND log.BusinessCode='19'
  1251. GROUP BY log.LotNo HAVING COUNT(log.LotNo)>=2)
  1252. BEGIN
  1253. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo191"), "{2}") + @"',16,1);
  1254. RETURN
  1255. END
  1256. " + sql + @"AND sdn.Type='1'
  1257. GROUP BY a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  1258. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  1259. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
  1260. columns = @"SUM(log.Quantity) AS Quantity,
  1261. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  1262. a.WarehouseCode AS WHCode,
  1263. wh.WarehouseName AS WHName,
  1264. a.LocationCode,
  1265. loc.LocationName,
  1266. 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,";
  1267. tableName = @"ICSSDN sdn
  1268. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  1269. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1270. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1271. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1272. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1273. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1274. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1275. }
  1276. else
  1277. {
  1278. sql = @"WITH ICSBomALL AS
  1279. (
  1280. SELECT
  1281. ContainerCode AS TContainerCode,
  1282. ContainerCode AS PContainerCode,
  1283. ContainerCode AS ContainerCode,
  1284. ID,
  1285. ContainerID,
  1286. 0 AS [Level],
  1287. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  1288. CAST('00001' AS nvarchar(MAX)) AS Sort
  1289. FROM ICSContainer
  1290. WHERE ContainerCode='{2}'
  1291. UNION ALL
  1292. SELECT
  1293. b.TContainerCode,
  1294. b.ContainerCode AS PContainerCode,
  1295. a.ContainerCode,
  1296. a.ID,
  1297. a.ContainerID,
  1298. b.[Level]+1 AS [Level],
  1299. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  1300. CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
  1301. FROM
  1302. ICSContainer a
  1303. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  1304. )
  1305. " + sql + @"AND sdn.Type='1'
  1306. GROUP BY a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  1307. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  1308. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
  1309. columns = @"SUM(log.Quantity) AS Quantity,
  1310. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  1311. a.WarehouseCode AS WHCode,
  1312. wh.WarehouseName AS WHName,
  1313. a.LocationCode,
  1314. loc.LocationName,
  1315. 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,";
  1316. tableName = @"ICSSDN sdn
  1317. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  1318. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1319. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1320. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1321. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1322. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1323. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1324. }
  1325. }
  1326. //生产(委外)退料-原条码+新条码
  1327. //先校验日志里面是否有原条码(同一种类型的条码只能发一次料才能原条码退,不然更新源头单据数量有问题,根据LogID判断是否原条码退回),如果没有查询新条码
  1328. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  1329. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  1330. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription()
  1331. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  1332. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  1333. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1334. {
  1335. string type = "13";
  1336. string msglanguage = "WMSAPIInfo185";
  1337. if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  1338. {
  1339. type = "14";
  1340. msglanguage = "WMSAPIInfo186";
  1341. }
  1342. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1343. {
  1344. type = "15";
  1345. msglanguage = "WMSAPIInfo187";
  1346. }
  1347. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  1348. {
  1349. type = "5";
  1350. msglanguage = "WMSAPIInfo188";
  1351. }
  1352. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  1353. {
  1354. type = "6";
  1355. msglanguage = "WMSAPIInfo189";
  1356. }
  1357. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1358. {
  1359. type = "7";
  1360. msglanguage = "WMSAPIInfo190";
  1361. }
  1362. #region 新条码
  1363. if (ScanType == "LOTNO")
  1364. {
  1365. sqlNew = @"IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  1366. BEGIN
  1367. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  1368. RETURN
  1369. END
  1370. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  1371. BEGIN
  1372. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  1373. RETURN
  1374. END
  1375. IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
  1376. INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  1377. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint
  1378. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND (b.InvIQC='1'AND ins.LotNo IS NULL))
  1379. BEGIN
  1380. RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"',16,1);
  1381. RETURN
  1382. END
  1383. " + sql;
  1384. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  1385. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  1386. '' AS WHCode,
  1387. '' AS WHName,
  1388. '' AS LocationCode,
  1389. '' AS LocationName,
  1390. ext.BatchCode AS BatchCode,";
  1391. tableName = @"ICSInventoryLot a
  1392. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1393. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  1394. }
  1395. else
  1396. {
  1397. sqlNew = @"WITH ICSBomALL AS
  1398. (
  1399. SELECT
  1400. ContainerCode AS TContainerCode,
  1401. ContainerCode AS PContainerCode,
  1402. ContainerCode AS ContainerCode,
  1403. ID,
  1404. ContainerID,
  1405. 0 AS [Level],
  1406. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  1407. CAST('00001' AS nvarchar(MAX)) AS Sort
  1408. FROM ICSContainer
  1409. WHERE ContainerCode='{2}'
  1410. UNION ALL
  1411. SELECT
  1412. b.TContainerCode,
  1413. b.ContainerCode AS PContainerCode,
  1414. a.ContainerCode,
  1415. a.ID,
  1416. a.ContainerID,
  1417. b.[Level]+1 AS [Level],
  1418. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  1419. CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
  1420. FROM
  1421. ICSContainer a
  1422. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  1423. )
  1424. " + sql;
  1425. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  1426. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  1427. '' AS WHCode,
  1428. '' AS WHName,
  1429. '' AS LocationCode,
  1430. '' AS LocationName,
  1431. ext.BatchCode AS BatchCode,";
  1432. tableName = @"ICSInventoryLot a
  1433. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1434. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  1435. }
  1436. sqlNew = string.Format(sqlNew, columns, tableName, JsonData.Code, JsonData.WorkPoint);
  1437. #endregion
  1438. #region 原条码
  1439. if (ScanType == "LOTNO")
  1440. {
  1441. sql = sql + @" AND log.BusinessCode IN('" + type + @"') GROUP BY log.ID,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  1442. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN(invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')= '1') OR ISNULL(invBat.BatchEnable, '0')= '1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  1443. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME
  1444. ";
  1445. sql = @"IF EXISTS(" + sql + @")
  1446. BEGIN
  1447. " + sql + @"
  1448. END
  1449. ELSE
  1450. BEGIN
  1451. " + sqlNew + @"
  1452. END";
  1453. sql = @"IF EXISTS(SELECT log.LotNo FROM ICSWareHouseLotInfoLog log
  1454. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1455. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND log.BusinessCode='" + type + @"'
  1456. GROUP BY log.LotNo HAVING COUNT(log.LotNo)>=2)
  1457. BEGIN
  1458. RAISERROR('" + string.Format(language.GetNameByCode(msglanguage), "{2}") + @"',16,1);
  1459. RETURN
  1460. END
  1461. " + sql;
  1462. columns = @"SUM(log.Quantity) AS Quantity,
  1463. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  1464. a.WarehouseCode AS WHCode,
  1465. wh.WarehouseName AS WHName,
  1466. a.LocationCode,
  1467. loc.LocationName,
  1468. log.ID AS LogID,
  1469. 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,";
  1470. tableName = @"ICSWareHouseLotInfoLog log
  1471. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1472. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1473. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1474. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1475. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1476. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1477. }
  1478. else
  1479. {
  1480. sql = sql + @" AND log.BusinessCode IN('" + type + @"') GROUP BY log.ID,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  1481. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN(invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')= '1') OR ISNULL(invBat.BatchEnable, '0')= '1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  1482. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME
  1483. ";
  1484. sql = @"IF EXISTS(" + sql + @")
  1485. BEGIN
  1486. " + sql + @"
  1487. END
  1488. ELSE
  1489. BEGIN
  1490. " + sqlNew + @"
  1491. END";
  1492. sql = @"WITH ICSBomALL AS
  1493. (
  1494. SELECT
  1495. ContainerCode AS TContainerCode,
  1496. ContainerCode AS PContainerCode,
  1497. ContainerCode AS ContainerCode,
  1498. ID,
  1499. ContainerID,
  1500. 0 AS [Level],
  1501. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  1502. CAST('00001' AS nvarchar(MAX)) AS Sort
  1503. FROM ICSContainer
  1504. WHERE ContainerCode='{2}'
  1505. UNION ALL
  1506. SELECT
  1507. b.TContainerCode,
  1508. b.ContainerCode AS PContainerCode,
  1509. a.ContainerCode,
  1510. a.ID,
  1511. a.ContainerID,
  1512. b.[Level]+1 AS [Level],
  1513. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  1514. CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
  1515. FROM
  1516. ICSContainer a
  1517. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  1518. )
  1519. " + sql;
  1520. columns = @"SUM(log.Quantity) AS Quantity,
  1521. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  1522. a.WarehouseCode AS WHCode,
  1523. wh.WarehouseName AS WHName,
  1524. a.LocationCode,
  1525. loc.LocationName,
  1526. log.ID AS LogID,
  1527. 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,";
  1528. tableName = @"ICSWareHouseLotInfoLog log
  1529. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1530. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1531. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1532. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1533. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1534. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1535. }
  1536. #endregion
  1537. }
  1538. //分批
  1539. else if (TransType == TransTypeEnum.LOTSplit.GetDescription() || TransType == TransTypeEnum.LOTMerge.GetDescription())
  1540. {
  1541. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0)
  1542. BEGIN
  1543. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  1544. RETURN
  1545. END
  1546. " + sql;
  1547. columns = @"a.Quantity,
  1548. a.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  1549. a.WarehouseCode AS WHCode,
  1550. wh.WarehouseName AS WHName,
  1551. a.LocationCode,
  1552. loc.LocationName,
  1553. 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,
  1554. ISNULL(split.SplitLotNo, a.LotNo+'-1') AS SplitLotNo,";
  1555. tableName = @"ICSWareHouseLotInfo a
  1556. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1557. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1558. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1559. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1560. LEFT JOIN (SELECT EATTRIBUTE1 AS LotNo,WorkPoint,EATTRIBUTE1+'-'+CAST((MAX(CAST(SUBSTRING(LotNo, CHARINDEX('-', LotNo)+1, LEN(LotNo)-CHARINDEX('-', LotNo)) AS INT))+1) AS VARCHAR) AS SplitLotNo FROM ICSInventoryLot GROUP BY EATTRIBUTE1,WorkPoint) split ON a.LotNo=split.LotNo AND a.WorkPoint=split.WorkPoint
  1561. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1562. }
  1563. //出库条码
  1564. else if (isOut)
  1565. {
  1566. if (ScanType == "LOTNO")
  1567. {
  1568. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0)
  1569. BEGIN
  1570. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  1571. RETURN
  1572. END
  1573. " + sql;
  1574. columns = @"a.Quantity,
  1575. a.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  1576. a.WarehouseCode AS WHCode,
  1577. wh.WarehouseName AS WHName,
  1578. inv.LotEnable,
  1579. a.LocationCode,
  1580. loc.LocationName,
  1581. 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,";
  1582. tableName = @"ICSWareHouseLotInfo a
  1583. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1584. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1585. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1586. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1587. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1588. }
  1589. else
  1590. {
  1591. sql = @"
  1592. WITH ICSBomALL AS
  1593. (
  1594. SELECT
  1595. ContainerCode AS TContainerCode,
  1596. ContainerCode AS PContainerCode,
  1597. ContainerCode AS ContainerCode,
  1598. ID,
  1599. ContainerID,
  1600. 0 AS [Level],
  1601. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  1602. CAST('00001' AS nvarchar(MAX)) AS Sort
  1603. FROM ICSContainer
  1604. WHERE ContainerCode='{2}'
  1605. UNION ALL
  1606. SELECT
  1607. b.TContainerCode,
  1608. b.ContainerCode AS PContainerCode,
  1609. a.ContainerCode,
  1610. a.ID,
  1611. a.ContainerID,
  1612. b.[Level]+1 AS [Level],
  1613. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  1614. CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
  1615. FROM
  1616. ICSContainer a
  1617. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  1618. )
  1619. " + sql;
  1620. columns = @"a.Quantity,
  1621. a.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  1622. a.WarehouseCode AS WHCode,
  1623. wh.WarehouseName AS WHName,
  1624. a.LocationCode,
  1625. loc.LocationName,
  1626. 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,";
  1627. tableName = @"ICSWareHouseLotInfo a
  1628. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1629. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1630. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1631. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1632. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1633. ";
  1634. }
  1635. }
  1636. //入库条码
  1637. else
  1638. {
  1639. if (ScanType == "LOTNO")
  1640. {
  1641. sql = @"
  1642. IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo = '{2}' AND a.WorkPoint = '{3}')
  1643. BEGIN
  1644. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"', 16, 1);
  1645. RETURN
  1646. END
  1647. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  1648. BEGIN
  1649. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  1650. RETURN
  1651. END
  1652. IF EXISTS(SELECT a.ID,c.TransCode FROM ICSInventoryLot a
  1653. INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  1654. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint
  1655. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND (b.InvIQC='1' AND ins.LotNo IS NULL))
  1656. BEGIN
  1657. RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"',16,1);
  1658. RETURN
  1659. END
  1660. " + sql;
  1661. ControlMode mode = ICSControlModeService.GetSuLocation();
  1662. //获取条码类型
  1663. LotTypesql = @"IF NOT EXISTS(SELECT Type FROM ICSInventoryLot WHERE LotNo='{0}' AND WorkPoint='{1}')
  1664. BEGIN
  1665. RAISERROR('" + language.GetNameByCode("WMSAPIInfo461") + @"',16,1);
  1666. RETURN
  1667. END
  1668. SELECT Type FROM ICSInventoryLot WHERE LotNo='{0}' AND WorkPoint='{1}'";
  1669. LotTypesql = string.Format(LotTypesql, JsonData.Code, JsonData.WorkPoint);
  1670. DataTable dt = DBHelper.SQlReturnData(LotTypesql, cmd);
  1671. LotType = dt.Rows[0]["Type"].ToString();
  1672. if (mode.itemCode.Equals("LocationRemind01"))
  1673. {
  1674. columnsWHNAME = @"
  1675. (SELECT Top 1 locat.LocationName from ICSWareHouseLotInfoLog log
  1676. LEFT JOIN ICSLocation locat on locat.LocationCode=log.ToLocationCode and log.WorkPoint=locat.WorkPoint where log.TransType='2' and a.InvCode=log.InvCode AND a.WorkPoint=log.WorkPoint
  1677. ORDER BY log.Mtime desc) AS LocationName,";
  1678. }
  1679. else if (mode.itemCode.Equals("LocationRemind02"))
  1680. {
  1681. columnsWHNAME = @"
  1682. STUFF(
  1683. (SELECT DISTINCT ',' + LocationName
  1684. from ICSLocation wh
  1685. LEFT JOIN ICSWareHouseLotInfo lotinfo on wh.LocationCode=lotinfo.LocationCode and wh.WorkPoint=lotinfo.WorkPoint
  1686. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and lotinfo.Quantity>0
  1687. FOR xml path('')
  1688. ),1,1,''
  1689. ) AS LocationName,";
  1690. }
  1691. else
  1692. {
  1693. columnsWHNAME = @"
  1694. STUFF(
  1695. (SELECT DISTINCT ',' + LocationName
  1696. from ICSLocation wh
  1697. LEFT JOIN ICSWareHouseLotInfoLog lotinfo on wh.LocationCode=lotinfo.ToLocationCode and wh.WorkPoint=lotinfo.WorkPoint
  1698. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and (lotinfo.TransType='2' OR lotinfo.TransType='3')
  1699. FOR xml path('')
  1700. ),1,1,''
  1701. ) AS LocationName,";
  1702. }
  1703. #region 根据条码类型找到单据仓库信息
  1704. if (LotType.Equals("1"))
  1705. {//生产退料
  1706. columnsWHCODE = @"(SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  1707. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1') AS WHCode";
  1708. }else if (LotType.Equals("2"))
  1709. {//委外退料
  1710. columnsWHCODE = @"(SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  1711. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1') AS WHCode";
  1712. }else if (LotType.Equals("3"))
  1713. {//工单
  1714. columnsWHCODE = @"(SELECT a.WHCode FROM ICSMO a WHERE a.MOCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AS WHCode";
  1715. }
  1716. else if (LotType.Equals("4"))
  1717. {//销售退货
  1718. columnsWHCODE = @"(SELECT a.WHCode FROM ICSSDN a WHERE a.SDNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AS WHCode";
  1719. }
  1720. else if (LotType.Equals("5"))
  1721. {//其他入库
  1722. columnsWHCODE = @"(SELECT a.WHCode FROM ICSOtherIn a WHERE a.InCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AS WHCode";
  1723. }
  1724. else if (LotType.Equals("6"))
  1725. {//归还单
  1726. columnsWHCODE = @"(SELECT a.WHCode FROM ICSReturn a WHERE a.ReturnCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AS WHCode";
  1727. }
  1728. else if (LotType.Equals("7"))
  1729. {//采购到货单
  1730. columnsWHCODE = @"(SELECT a.WHCode FROM ICSDeliveryNotice a WHERE a.DNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint AND a.DNType='1') AS WHCode";
  1731. }
  1732. else if (LotType.Equals("8"))
  1733. {//委外到货单
  1734. columnsWHCODE = @"(SELECT a.WHCode FROM ICSODeliveryNotice a WHERE a.ODNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint and a.ODNType='1') AS WHCode";
  1735. }
  1736. else if (LotType.Equals("9"))
  1737. {//成品入库单
  1738. columnsWHCODE = @"(SELECT a.WHCode FROM ICSManufactureReceive a WHERE a.RCVCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AS WHCode";
  1739. }
  1740. else if (LotType.Equals("10"))
  1741. {//拒收单
  1742. columnsWHCODE = @"(SELECT a.WHCode FROM ICSDeliveryNotice a WHERE a.DNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint AND a.DNType='3') AS WHCode";
  1743. }
  1744. else if (LotType.Equals("11"))
  1745. {//委外拒收单
  1746. columnsWHCODE = @"(SELECT a.WHCode FROM ICSODeliveryNotice a WHERE a.ODNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint and a.ODNType='3') AS WHCode";
  1747. }
  1748. else if (LotType.Equals("12"))
  1749. {//领料申请退料
  1750. columnsWHCODE = @"(SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  1751. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2') AS WHCode";
  1752. }
  1753. else if (LotType.Equals("13"))
  1754. {//材料出库退料
  1755. columnsWHCODE = @"(SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  1756. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3') AS WHCode";
  1757. }
  1758. else if (LotType.Equals("14"))
  1759. {//委外领料申请退料
  1760. columnsWHCODE = @"(SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  1761. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2') AS WHCode";
  1762. }
  1763. else if (LotType.Equals("15"))
  1764. {//委外材料出库退料
  1765. columnsWHCODE = @"(SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  1766. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3') AS WHCode";
  1767. }
  1768. else if (LotType.Equals("16"))
  1769. {//返工工单
  1770. columnsWHCODE = @"(SELECT pick.WHCode FROM ICSMOPick pick LEFT JOIN ICSMO moo ON pick.MODetailID=moo.MODetailID AND pick.WorkPoint=moo.WorkPoint
  1771. WHERE moo.MOCode=lotdd.TransCode AND pick.Sequence=lotdd.TransSequence AND pick.WorkPoint=lotdd.WorkPoint) AS WHCode ";
  1772. }
  1773. #endregion
  1774. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  1775. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  1776. {0},'' AS WHName,
  1777. '' AS LocationCode,
  1778. {1}
  1779. ext.BatchCode AS BatchCode,";
  1780. tableName = @"ICSInventoryLot a
  1781. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1782. LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
  1783. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  1784. columns = string.Format(columns, columnsWHCODE, columnsWHNAME);
  1785. }
  1786. else
  1787. {
  1788. sql = @"
  1789. WITH ICSBomALL AS
  1790. (
  1791. SELECT
  1792. ContainerCode AS TContainerCode,
  1793. ContainerCode AS PContainerCode,
  1794. ContainerCode AS ContainerCode,
  1795. ID,
  1796. ContainerID,
  1797. 0 AS [Level],
  1798. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  1799. CAST('00001' AS nvarchar(MAX)) AS Sort
  1800. FROM ICSContainer
  1801. WHERE ContainerCode='{2}'
  1802. UNION ALL
  1803. SELECT
  1804. b.TContainerCode,
  1805. b.ContainerCode AS PContainerCode,
  1806. a.ContainerCode,
  1807. a.ID,
  1808. a.ContainerID,
  1809. b.[Level]+1 AS [Level],
  1810. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  1811. CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
  1812. FROM
  1813. ICSContainer a
  1814. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  1815. )
  1816. " + sql;
  1817. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  1818. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  1819. '' AS WHCode,
  1820. '' AS WHName,
  1821. '' AS LocationCode,
  1822. '' AS LocationName,
  1823. ext.BatchCode AS BatchCode,";
  1824. tableName = @"ICSInventoryLot a
  1825. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1826. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  1827. }
  1828. }
  1829. }
  1830. if (TransType != TransTypeEnum.LocationSeatch.GetDescription())
  1831. {
  1832. if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName))
  1833. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
  1834. }
  1835. if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
  1836. {
  1837. Losql = string.Format(Losql, columns, tableName, JsonData.Code, JsonData.WorkPoint);
  1838. table = DBHelper.SQlReturnData(Losql, cmd);
  1839. }
  1840. else
  1841. {
  1842. sql = string.Format(sql, columns, tableName, JsonData.Code, JsonData.WorkPoint);
  1843. log.Info("条码sql:" + sql);
  1844. table = DBHelper.SQlReturnData(sql, cmd);
  1845. }
  1846. if (table == null || table.Rows.Count <= 0)
  1847. throw new Exception(language.GetNameByCode("WMSAPIInfo008"));//"未查询到条码数据!"
  1848. #region 出库检验是否符合源头单据
  1849. string msg = string.Empty;
  1850. bool isLimit = false;
  1851. string sqlCheckSign = @"select F_EnabledMark from Sys_SRM_Items where F_EnCode = 'OutWithLocationCode' and F_EnabledMark = '1'";
  1852. DataTable flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  1853. if (isOut) // && TransType != TransTypeEnum.LOTSplit.GetDescription()
  1854. {//&& TransType != TransTypeEnum.TransferLibrary.GetDescription()
  1855. string Lot = "";
  1856. string workP = "";
  1857. if (TransType == TransTypeEnum.TransferLibrary.GetDescription())
  1858. {
  1859. foreach (DataRow drLot in table.Rows)
  1860. {
  1861. Lot = drLot["LotNo"].ToString();
  1862. sql = @"SELECT WarehouseCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  1863. sql = string.Format(sql, Lot, JsonData.WorkPoint);
  1864. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1865. if (dt == null || dt.Rows.Count <= 0)
  1866. {
  1867. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), Lot));
  1868. }
  1869. string whcode = dt.Rows[0]["WarehouseCode"].ToString();
  1870. if (!JsonData.WHCode.Equals(whcode))
  1871. {
  1872. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo395"), JsonData.WHCode, whcode));
  1873. }
  1874. }
  1875. }
  1876. else if(TransType != TransTypeEnum.LocationSeatch.GetDescription())
  1877. {
  1878. if (string.IsNullOrEmpty(JsonData.TransCode))
  1879. {
  1880. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  1881. }
  1882. WMSSourceDocumentModel model = new WMSSourceDocumentModel();
  1883. model.TransCode = JsonData.TransCode;
  1884. model.TransType = JsonData.TransType;
  1885. model.WorkPoint = JsonData.WorkPoint;
  1886. DataTable TransData = TransInformationGet(model);
  1887. DataView dataView = TransData.DefaultView;
  1888. foreach (DataRow drLot in table.Rows)
  1889. {
  1890. Lot = drLot["LotNo"].ToString();
  1891. //盘点不需要对比以下属性
  1892. if (TransType == TransTypeEnum.Check.GetDescription())
  1893. continue;
  1894. string rowFilter = "InvCode='" + drLot["InvCode"] + "'";
  1895. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo041"), Lot, drLot["InvCode"]));
  1896. rowFilter += " AND (LEN(ISNULL(WHCode,''))<=0 OR (LEN(ISNULL(WHCode,''))>0 AND WHCode='" + drLot["WHCode"] + "'))";
  1897. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["WHCode"]));
  1898. rowFilter += " AND (LEN(ISNULL(ProjectCode,''))<=0 OR (LEN(ISNULL(ProjectCode,''))>0 AND ProjectCode='" + drLot["ProjectCode"] + "'))";
  1899. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo043"), Lot, drLot["ProjectCode"]));
  1900. rowFilter += "AND (LEN(ISNULL(BatchCode,''))<=0 OR (LEN(ISNULL(BatchCode,''))>0 AND BatchCode='" + drLot["BatchCode"] + "'))";
  1901. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo044"), Lot, drLot["BatchCode"]));
  1902. rowFilter += "AND (LEN(ISNULL(Version,''))<=0 OR (LEN(ISNULL(Version,''))>0 AND Version='" + drLot["Version"] + "'))";
  1903. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo045"), Lot, drLot["Version"]));
  1904. rowFilter += "AND (LEN(ISNULL(Brand,''))<=0 OR (LEN(ISNULL(Brand,''))>0 AND Brand='" + drLot["Brand"] + "'))";
  1905. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo046"), Lot, drLot["Brand"]));
  1906. rowFilter += "AND (LEN(ISNULL(cFree1,''))<=0 OR (LEN(ISNULL(cFree1,''))>0 AND cFree1='" + drLot["cFree1"] + "'))";
  1907. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo047"), Lot, drLot["cFree1"]));
  1908. rowFilter += "AND (LEN(ISNULL(cFree2,''))<=0 OR (LEN(ISNULL(cFree2,''))>0 AND cFree2='" + drLot["cFree2"] + "'))";
  1909. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo048"), Lot, drLot["cFree2"]));
  1910. rowFilter += "AND (LEN(ISNULL(cFree3,''))<=0 OR (LEN(ISNULL(cFree3,''))>0 AND cFree3='" + drLot["cFree3"] + "'))";
  1911. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo049"), Lot, drLot["cFree3"]));
  1912. rowFilter += "AND (LEN(ISNULL(cFree4,''))<=0 OR (LEN(ISNULL(cFree4,''))>0 AND cFree4='" + drLot["cFree4"] + "'))";
  1913. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo050"), Lot, drLot["cFree4"]));
  1914. rowFilter += "AND (LEN(ISNULL(cFree5,''))<=0 OR (LEN(ISNULL(cFree5,''))>0 AND cFree5='" + drLot["cFree5"] + "'))";
  1915. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo051"), Lot, drLot["cFree5"]));
  1916. rowFilter += "AND (LEN(ISNULL(cFree6,''))<=0 OR (LEN(ISNULL(cFree6,''))>0 AND cFree6='" + drLot["cFree6"] + "'))";
  1917. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo052"), Lot, drLot["cFree6"]));
  1918. rowFilter += "AND (LEN(ISNULL(cFree7,''))<=0 OR (LEN(ISNULL(cFree7,''))>0 AND cFree7='" + drLot["cFree7"] + "'))";
  1919. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo053"), Lot, drLot["cFree7"]));
  1920. rowFilter += "AND (LEN(ISNULL(cFree8,''))<=0 OR (LEN(ISNULL(cFree8,''))>0 AND cFree8='" + drLot["cFree8"] + "'))";
  1921. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo054"), Lot, drLot["cFree8"]));
  1922. rowFilter += "AND (LEN(ISNULL(cFree9,''))<=0 OR (LEN(ISNULL(cFree9,''))>0 AND cFree9='" + drLot["cFree9"] + "'))";
  1923. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo055"), Lot, drLot["cFree9"]));
  1924. rowFilter += "AND (LEN(ISNULL(cFree10,''))<=0 OR (LEN(ISNULL(cFree10,''))>0 AND cFree10='" + drLot["cFree10"] + "'))";
  1925. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo056"), Lot, drLot["cFree10"]));
  1926. if (flag != null && flag.Rows.Count > 0)
  1927. {
  1928. rowFilter += " AND LocationCode='" + drLot["LocationCode"] + "'";
  1929. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["LocationCode"]));
  1930. }
  1931. //保质期管理
  1932. var resultEffective = Effective(Lot, JsonData.WorkPoint, cmd, language);
  1933. //0 - 已经是最早的批次
  1934. //1 - 不管控
  1935. //2 - 提醒
  1936. //3 - 限制
  1937. if (resultEffective == "2")
  1938. {
  1939. msg += string.Format(language.GetNameByCode("WMSAPIInfo181"), Lot) + Environment.NewLine;
  1940. }
  1941. else if (resultEffective == "3")
  1942. {
  1943. msg += string.Format(language.GetNameByCode("WMSAPIInfo182"), Lot) + Environment.NewLine;
  1944. isLimit = true;
  1945. }
  1946. //先进先出判断
  1947. var result = CanOut(Lot, JsonData.WorkPoint, JsonData.ScanLotCode, cmd, language);
  1948. //0 - 已经是最早的批次
  1949. //1 - 不管控
  1950. //2 - 提醒
  1951. //3 - 限制
  1952. if (result == "2")
  1953. {
  1954. msg += string.Format(language.GetNameByCode("WMSAPIInfo178"), Lot) + Environment.NewLine;
  1955. }
  1956. else if (result == "3")
  1957. {
  1958. msg += string.Format(language.GetNameByCode("WMSAPIInfo179"), Lot) + Environment.NewLine;
  1959. isLimit = true;
  1960. }
  1961. }
  1962. }
  1963. }
  1964. #endregion
  1965. //return table;
  1966. Result res = new Result();
  1967. res.Success = true;
  1968. res.Message = msg;// "接口调用成功!";
  1969. if (!isLimit)
  1970. res.Data = table;
  1971. return res;
  1972. //出库时
  1973. //Message无值、Data有值,可直接处理
  1974. //Message有值、Data有值,弹出提醒框(可点击确定、取消,确定后继续出库,取消后不处理这批条码),显示Message信息
  1975. //Message有值、Data无值,弹出警告框(只能点击确定,且不处理这批条码),显示Message信息
  1976. }
  1977. catch (Exception ex)
  1978. {
  1979. log.Error(ex.Message);
  1980. throw new Exception(ex.Message);
  1981. }
  1982. finally
  1983. {
  1984. if (conn.State == ConnectionState.Open)
  1985. {
  1986. conn.Close();
  1987. }
  1988. conn.Dispose();
  1989. }
  1990. }
  1991. }
  1992. /// <summary>
  1993. /// 校验条码对应的物料、自由项等信息是否与源头单据匹配
  1994. /// </summary>
  1995. private static void CheckTrans(DataView dataView, string rowFilter, string message)
  1996. {
  1997. dataView.RowFilter = rowFilter;
  1998. if (dataView == null || dataView.Count <= 0)
  1999. throw new Exception(message);
  2000. }
  2001. #endregion
  2002. /// <summary>
  2003. /// 上架
  2004. /// </summary>BusinessCode,TransType 两个类型
  2005. /// <param name="JsonData"></param>
  2006. /// <returns></returns>
  2007. public static DataTable LOTStockCreate(List<LOTStockUpCreateIModel> JsonData)
  2008. {
  2009. var language = LanguageHelper.GetName("WMSAPIInfo");
  2010. if (JsonData.Count <= 0)
  2011. {
  2012. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2013. }
  2014. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2015. {
  2016. conn.Open();
  2017. SqlTransaction sqlTran = conn.BeginTransaction();
  2018. SqlCommand cmd = new SqlCommand();
  2019. cmd.Transaction = sqlTran;
  2020. cmd.Connection = conn;
  2021. string BusinessCode = string.Empty;
  2022. try
  2023. {
  2024. string TransType = string.Empty;
  2025. string Identification = Guid.NewGuid().ToString();
  2026. foreach (var item in JsonData)
  2027. {
  2028. TransType = item.TransType;
  2029. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  2030. {
  2031. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  2032. }
  2033. string WHTransType = "2";
  2034. foreach (var itemInfo in item.detail)
  2035. {
  2036. #region 两步调入
  2037. if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  2038. {
  2039. //更新源头单据数量
  2040. ICSWareHouseService.TwoStepTransferDocIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2041. //入库
  2042. ICSWareHouseLotInfoService.WareHouseLotInfoTwoStepTransferDocIn(Identification, itemInfo.TransCode, itemInfo.TransSequence,
  2043. itemInfo.WarehouseCode, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity, item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocIn.GetDescription<DBValue>(), cmd, language);
  2044. }
  2045. #endregion
  2046. #region 销售退货-原条码
  2047. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  2048. {
  2049. //更新源头单据数量
  2050. ICSSalesService.SalesReturnBackIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2051. //入库
  2052. BusinessCode = TransTypeEnum.SalesReturnBack.GetDescription<DBValue>();
  2053. //入库
  2054. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  2055. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode);
  2056. //更新日志表源头单据信息
  2057. string sql = @"UPDATE ICSWareHouseLotInfoLog SET TransCode='{3}',TransSequence='{4}'
  2058. WHERE LotNo='{0}' AND WorkPoint='{1}' AND Identification='{2}' AND TransCode='' AND TransSequence=''";
  2059. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, Identification, itemInfo.TransCode, itemInfo.TransSequence);
  2060. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2061. {
  2062. throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
  2063. }
  2064. }
  2065. #endregion
  2066. else
  2067. {
  2068. #region 采购入库
  2069. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  2070. {
  2071. //更新源头单据数量
  2072. ICSPurchaseService.PurchaseReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2073. BusinessCode = TransTypeEnum.PurchaseReceiveDoc.GetDescription<DBValue>();
  2074. }
  2075. #endregion
  2076. #region 审核的到货单
  2077. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  2078. {
  2079. //更新源头单据数量
  2080. ICSPurchaseService.DeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2081. BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription<DBValue>();
  2082. }
  2083. #endregion
  2084. #region 采购拒收
  2085. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  2086. {
  2087. //更新源头单据数量
  2088. ICSPurchaseService.PurchaseRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2089. BusinessCode = TransTypeEnum.PurchaseRejectDoc.GetDescription<DBValue>();
  2090. }
  2091. #endregion
  2092. #region 审核的委外到货单
  2093. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  2094. {
  2095. //更新源头单据数量
  2096. ICSOutsourcingService.ODeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2097. BusinessCode = TransTypeEnum.ODeliveryNotice.GetDescription<DBValue>();
  2098. }
  2099. #endregion
  2100. #region 委外拒收
  2101. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  2102. {
  2103. //更新源头单据数量
  2104. ICSOutsourcingService.OutsourcingRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2105. BusinessCode = TransTypeEnum.OutsourcingRejectDoc.GetDescription<DBValue>();
  2106. }
  2107. #endregion
  2108. #region 委外退料
  2109. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  2110. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  2111. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  2112. {
  2113. //更新源头单据数量
  2114. ICSOutsourcingService.OutsourcingIssueDoNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2115. BusinessCode = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription<DBValue>();
  2116. }
  2117. #endregion
  2118. #region 返工工单
  2119. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  2120. {
  2121. //更新源头单据数量
  2122. ICSManufactureService.ReWorkReceiveMo(itemInfo.LotNo, itemInfo.Quantity, itemInfo.WarehouseCode, itemInfo.LocationCode, item.WorkPoint, item.User, TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>(), cmd, language);
  2123. BusinessCode = TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>();
  2124. }
  2125. #endregion
  2126. #region 委外入库
  2127. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  2128. {
  2129. //更新源头单据数量
  2130. ICSOutsourcingService.OutsourcingReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2131. BusinessCode = TransTypeEnum.OutsourcingReceiveDoc.GetDescription<DBValue>();
  2132. }
  2133. #endregion
  2134. #region 生产退料
  2135. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  2136. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  2137. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  2138. {
  2139. //更新源头单据数量
  2140. ICSManufactureService.MOIssueDocNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2141. BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>();
  2142. }
  2143. #endregion
  2144. #region 生产入库
  2145. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  2146. {
  2147. //更新源头单据数量
  2148. ICSManufactureService.ManufactureReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2149. BusinessCode = TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>();
  2150. }
  2151. #endregion
  2152. #region 开立的生产入库单
  2153. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  2154. {
  2155. //更新源头单据数量
  2156. ICSManufactureService.ManufactureReceive(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2157. BusinessCode = TransTypeEnum.ManufactureReceive.GetDescription<DBValue>();
  2158. }
  2159. #endregion
  2160. #region 销售退货
  2161. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  2162. {
  2163. //更新源头单据数量
  2164. ICSSalesService.SalesShipmentDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2165. BusinessCode = TransTypeEnum.SalesShipmentDocNegative.GetDescription<DBValue>();
  2166. }
  2167. #endregion
  2168. #region 其他入库
  2169. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  2170. {
  2171. //更新源头单据数量
  2172. ICSWareHouseService.OtherInDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2173. BusinessCode = TransTypeEnum.OtherInDoc.GetDescription<DBValue>();
  2174. }
  2175. #endregion
  2176. #region 拆卸单
  2177. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  2178. {
  2179. ICSWareHouseService.DisassemblyDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2180. WHTransType = "11";
  2181. BusinessCode = TransTypeEnum.DisassemblyDoc.GetDescription<DBValue>();
  2182. }
  2183. #endregion
  2184. #region 归还
  2185. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  2186. {
  2187. //更新源头单据数量
  2188. ICSWareHouseService.ReturnDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2189. BusinessCode = TransTypeEnum.ReturnDoc.GetDescription<DBValue>();
  2190. }
  2191. #endregion
  2192. else
  2193. {
  2194. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  2195. }
  2196. //入库
  2197. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  2198. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language,itemInfo.LogID,itemInfo.InvCode + itemInfo.WarehouseCode);
  2199. }
  2200. }
  2201. #region 拆卸单
  2202. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  2203. {
  2204. //更新套件锁定数量
  2205. ICSWareHouseService.DisassemblyDoc(Identification, cmd, language);
  2206. }
  2207. #endregion}
  2208. }
  2209. //上传ERP
  2210. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  2211. {
  2212. //采购入库
  2213. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  2214. ICSPurchaseService.PurchaseReceiveDocERP(TransType, Identification, cmd, language, BusinessCode);
  2215. //审核的到货单
  2216. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  2217. ICSPurchaseService.DeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode);
  2218. //采购拒收
  2219. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  2220. ICSPurchaseService.PurchaseRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
  2221. //审核的委外到货单
  2222. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  2223. ICSOutsourcingService.ODeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode);
  2224. //委外拒收
  2225. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  2226. ICSOutsourcingService.OutsourcingRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
  2227. //委外退料
  2228. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  2229. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  2230. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  2231. ICSOutsourcingService.OutsourcingIssueDoNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  2232. //委外入库
  2233. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  2234. ICSOutsourcingService.OutsourcingReceiveDocERP(TransType, Identification, cmd, language, BusinessCode);
  2235. //生产退料
  2236. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  2237. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  2238. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  2239. ICSManufactureService.MOIssueDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  2240. //生产入库
  2241. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  2242. ICSManufactureService.ManufactureReceiveDocERP(TransType, Identification, cmd, language,BusinessCode);
  2243. //开立的生产入库单
  2244. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  2245. ICSManufactureService.ManufactureReceiveERP(TransType, Identification, cmd, language, BusinessCode);
  2246. //返工工单
  2247. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  2248. ICSManufactureService.ReWorkReceiveMoERP(TransType, Identification, cmd, language, BusinessCode);
  2249. //销售退货
  2250. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  2251. ICSSalesService.SalesShipmentDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  2252. //两步调入
  2253. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  2254. ICSWareHouseService.TwoStepTransferDocInERP(TransType, Identification, cmd, language, BusinessCode);
  2255. //销售退货-原条码
  2256. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  2257. ICSSalesService.SalesReturnBackInERP(TransType, Identification, cmd, language, BusinessCode);
  2258. //其他入库
  2259. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  2260. ICSWareHouseService.OtherInDocERP(TransType, Identification, cmd, language, BusinessCode);
  2261. //拆卸单
  2262. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  2263. ICSWareHouseService.DisassemblyDocERP(TransType, Identification, cmd, language, BusinessCode);
  2264. //归还
  2265. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  2266. ICSWareHouseService.ReturnDocERP(TransType, Identification, cmd, language, BusinessCode);
  2267. }
  2268. DataTable table = GetData(Identification, 1, cmd);
  2269. cmd.Transaction.Commit();
  2270. return table;
  2271. }
  2272. catch (Exception ex)
  2273. {
  2274. if (cmd.Transaction != null)
  2275. cmd.Transaction.Rollback();
  2276. log.Error(ex.Message);
  2277. throw new Exception(ex.Message);
  2278. }
  2279. finally
  2280. {
  2281. if (conn.State == ConnectionState.Open)
  2282. {
  2283. conn.Close();
  2284. }
  2285. conn.Dispose();
  2286. }
  2287. }
  2288. }
  2289. /// <summary>
  2290. /// 下架
  2291. /// </summary>
  2292. /// <param name="JsonData"></param>
  2293. /// <returns></returns>
  2294. public static DataTable LOTStockDownCreate(List<LOTStockModel> JsonData)
  2295. {
  2296. String PrintEnable = "";
  2297. var language = LanguageHelper.GetName("WMSAPIInfo");
  2298. if (JsonData.Count <= 0)
  2299. {
  2300. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2301. }
  2302. List<LOTStockModelList> model = new List<LOTStockModelList>();
  2303. DataTable printTable = new DataTable();
  2304. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2305. {
  2306. conn.Open();
  2307. SqlTransaction sqlTran = conn.BeginTransaction();
  2308. SqlCommand cmd = new SqlCommand();
  2309. cmd.Transaction = sqlTran;
  2310. cmd.Connection = conn;
  2311. string BusinessCode = string.Empty;
  2312. try
  2313. {
  2314. string TransType = string.Empty;
  2315. string Identification = Guid.NewGuid().ToString();
  2316. foreach (var item in JsonData)
  2317. {
  2318. TransType = item.TransType;
  2319. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  2320. {
  2321. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  2322. }
  2323. else if (string.IsNullOrEmpty(item.TransCode))
  2324. {
  2325. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  2326. }
  2327. string[] trans = item.TransCode.Split('~');
  2328. string MergeID = "";
  2329. if (trans.Length == 2)
  2330. {
  2331. MergeID = trans[0];
  2332. item.TransCode = trans[1];
  2333. }
  2334. #region 采购退货
  2335. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  2336. {
  2337. BusinessCode = TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>();
  2338. //更新源头单据数量
  2339. ICSPurchaseService.PurchaseReceiveDoctNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2340. foreach (var itemInfo in item.detail)
  2341. {
  2342. //出库
  2343. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2344. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>(), cmd, language);
  2345. }
  2346. }
  2347. #endregion
  2348. #region 委外发料
  2349. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  2350. {
  2351. BusinessCode = TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>();
  2352. //更新源头单据数量
  2353. ICSOutsourcingService.OutsourcingIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2354. foreach (var itemInfo in item.detail)
  2355. {
  2356. //出库
  2357. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2358. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2359. }
  2360. }
  2361. #endregion
  2362. #region 委外退货
  2363. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  2364. {
  2365. BusinessCode = TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>();
  2366. //更新源头单据数量
  2367. ICSOutsourcingService.OutsourcingReturnBack(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2368. foreach (var itemInfo in item.detail)
  2369. {
  2370. //出库
  2371. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2372. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>(), cmd, language);
  2373. }
  2374. }
  2375. #endregion
  2376. #region 生产发料
  2377. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  2378. {
  2379. BusinessCode = TransTypeEnum.MOIssueDoc.GetDescription<DBValue>();
  2380. //更新源头单据数量
  2381. ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2382. foreach (var itemInfo in item.detail)
  2383. {
  2384. //出库
  2385. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2386. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssueDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2387. }
  2388. }
  2389. #endregion
  2390. #region 销售出库
  2391. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  2392. {
  2393. BusinessCode = TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>();
  2394. //更新源头单据数量
  2395. ICSSalesService.SalesShipmentDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2396. foreach (var itemInfo in item.detail)
  2397. {
  2398. //出库
  2399. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2400. item.User, item.WorkPoint, "3", TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2401. }
  2402. }
  2403. #endregion
  2404. #region 两步调出
  2405. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  2406. {
  2407. BusinessCode = TransTypeEnum.TwoStepTransferDocOut.GetDescription<DBValue>();
  2408. //更新源头单据数量
  2409. ICSWareHouseService.TwoStepTransferDocOut(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2410. foreach (var itemInfo in item.detail)
  2411. {
  2412. //出库
  2413. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2414. item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocOut.GetDescription<DBValue>(), cmd, language, MergeID);
  2415. }
  2416. }
  2417. #endregion
  2418. #region 其他出库
  2419. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  2420. {
  2421. BusinessCode = TransTypeEnum.OtherOutDoc.GetDescription<DBValue>();
  2422. //更新源头单据数量
  2423. ICSWareHouseService.OtherOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2424. foreach (var itemInfo in item.detail)
  2425. {
  2426. //出库
  2427. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2428. item.User, item.WorkPoint, "3", TransTypeEnum.OtherOutDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2429. }
  2430. }
  2431. #endregion
  2432. #region 领料申请单发料
  2433. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  2434. {
  2435. BusinessCode = TransTypeEnum.MOApply.GetDescription<DBValue>();
  2436. //更新源头单据数量
  2437. ICSManufactureService.MOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2438. foreach (var itemInfo in item.detail)
  2439. {
  2440. //出库
  2441. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2442. item.User, item.WorkPoint, "3", TransTypeEnum.MOApply.GetDescription<DBValue>(), cmd, language, MergeID);
  2443. }
  2444. }
  2445. #endregion
  2446. #region 委外领料申请单发料
  2447. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  2448. {
  2449. BusinessCode = TransTypeEnum.OOApply.GetDescription<DBValue>();
  2450. //更新源头单据数量
  2451. ICSOutsourcingService.OOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2452. foreach (var itemInfo in item.detail)
  2453. {
  2454. //出库
  2455. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2456. item.User, item.WorkPoint, "3", TransTypeEnum.OOApply.GetDescription<DBValue>(), cmd, language,MergeID);
  2457. }
  2458. }
  2459. #endregion
  2460. #region 开立材料出库
  2461. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  2462. {
  2463. BusinessCode = TransTypeEnum.MOIssue.GetDescription<DBValue>();
  2464. //更新源头单据数量
  2465. ICSManufactureService.MOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2466. foreach (var itemInfo in item.detail)
  2467. {
  2468. //出库
  2469. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2470. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssue.GetDescription<DBValue>(), cmd, language, MergeID);
  2471. }
  2472. }
  2473. #endregion
  2474. #region 开立委外材料出库
  2475. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  2476. {
  2477. BusinessCode = TransTypeEnum.OOIssue.GetDescription<DBValue>();
  2478. //更新源头单据数量
  2479. ICSOutsourcingService.OOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2480. foreach (var itemInfo in item.detail)
  2481. {
  2482. //出库
  2483. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2484. item.User, item.WorkPoint, "3", TransTypeEnum.OOIssue.GetDescription<DBValue>(), cmd, language, MergeID);
  2485. }
  2486. }
  2487. #endregion
  2488. #region 开立红字入库单
  2489. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  2490. {
  2491. BusinessCode = TransTypeEnum.PurchaseReceive.GetDescription<DBValue>();
  2492. //更新源头单据数量
  2493. ICSPurchaseService.PurchaseReceive(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2494. foreach (var itemInfo in item.detail)
  2495. {
  2496. //出库
  2497. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2498. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceive.GetDescription<DBValue>(), cmd, language);
  2499. }
  2500. }
  2501. #endregion
  2502. #region 开立委外红字入库单
  2503. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  2504. {
  2505. BusinessCode = TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription<DBValue>();
  2506. //更新源头单据数量
  2507. ICSOutsourcingService.OutsourcingReceiveDocNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2508. foreach (var itemInfo in item.detail)
  2509. {
  2510. //出库
  2511. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2512. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription<DBValue>(), cmd, language);
  2513. }
  2514. }
  2515. #endregion
  2516. #region 借用
  2517. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  2518. {
  2519. BusinessCode = TransTypeEnum.BrrowDoc.GetDescription<DBValue>();
  2520. //更新源头单据数量
  2521. ICSWareHouseService.BrrowDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2522. foreach (var itemInfo in item.detail)
  2523. {
  2524. //出库
  2525. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2526. item.User, item.WorkPoint, "3", TransTypeEnum.BrrowDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2527. }
  2528. }
  2529. #endregion
  2530. else
  2531. {
  2532. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  2533. }
  2534. }
  2535. //上传ERP
  2536. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  2537. {
  2538. //采购退货
  2539. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  2540. ICSPurchaseService.PurchaseReceiveDoctNegativeERP(TransType, Identification, cmd, language,BusinessCode);
  2541. //委外发料
  2542. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  2543. ICSOutsourcingService.OutsourcingIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
  2544. //委外退货
  2545. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  2546. ICSOutsourcingService.OutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode);
  2547. //生产发料
  2548. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  2549. ICSManufactureService.MOIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
  2550. //销售出库
  2551. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  2552. ICSSalesService.SalesShipmentDocERP(TransType, Identification, cmd, language, BusinessCode);
  2553. //两步调出
  2554. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  2555. ICSWareHouseService.TwoStepTransferDocOutERP(TransType, Identification, cmd, language, BusinessCode);
  2556. //其他出库
  2557. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  2558. ICSWareHouseService.OtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
  2559. //领料申请单发料
  2560. if (TransType == TransTypeEnum.MOApply.GetDescription())
  2561. ICSManufactureService.MOApplyERP(TransType, Identification, cmd, language, BusinessCode);
  2562. //委外领料申请单发料
  2563. if (TransType == TransTypeEnum.OOApply.GetDescription())
  2564. ICSOutsourcingService.OOApplyERP(TransType, Identification, cmd, language, BusinessCode);
  2565. //开立材料出库
  2566. if (TransType == TransTypeEnum.MOIssue.GetDescription())
  2567. ICSManufactureService.MOIssueERP(TransType, Identification, cmd, language, BusinessCode);
  2568. //开立委外材料出库
  2569. if (TransType == TransTypeEnum.OOIssue.GetDescription())
  2570. ICSOutsourcingService.OOIssueERP(TransType, Identification, cmd, language, BusinessCode);
  2571. //开立红字入库单
  2572. if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  2573. ICSPurchaseService.PurchaseReceiveERP(TransType, Identification, cmd, language, BusinessCode);
  2574. //开立委外红字入库单
  2575. if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  2576. ICSOutsourcingService.OutsourcingReceiveDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  2577. //借用
  2578. if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  2579. ICSWareHouseService.BrrowDocERP(TransType, Identification, cmd, language, BusinessCode);
  2580. }
  2581. if (!printTable.Equals("{}"))
  2582. {
  2583. cmd.Transaction.Commit();
  2584. return printTable;
  2585. }
  2586. else
  2587. {
  2588. DataTable table = GetData(Identification, 2, cmd);
  2589. cmd.Transaction.Commit();
  2590. return table;
  2591. }
  2592. }
  2593. catch (Exception ex)
  2594. {
  2595. if (cmd.Transaction != null)
  2596. cmd.Transaction.Rollback();
  2597. log.Error(ex.Message);
  2598. throw new Exception(ex.Message);
  2599. }
  2600. finally
  2601. {
  2602. if (conn.State == ConnectionState.Open)
  2603. {
  2604. conn.Close();
  2605. }
  2606. conn.Dispose();
  2607. }
  2608. }
  2609. }
  2610. #region 采购
  2611. /// <summary>
  2612. /// 采购到货
  2613. /// </summary>
  2614. /// <param name="JsonData"></param>
  2615. /// <returns></returns>
  2616. public static DataTable DeliveryNoticeCreate(List<ICSDeliveryNotice> JsonData)
  2617. {
  2618. var language = LanguageHelper.GetName("WMSAPIInfo");
  2619. if (JsonData.Count <= 0)
  2620. {
  2621. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2622. }
  2623. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2624. {
  2625. conn.Open();
  2626. SqlTransaction sqlTran = conn.BeginTransaction();
  2627. SqlCommand cmd = new SqlCommand();
  2628. cmd.Transaction = sqlTran;
  2629. cmd.Connection = conn;
  2630. try
  2631. {
  2632. string asncodes = string.Empty;
  2633. string sql = string.Empty;
  2634. foreach (var item in JsonData)
  2635. {
  2636. if (string.IsNullOrEmpty(item.ASNCode))
  2637. {
  2638. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!"
  2639. }
  2640. //获取单号
  2641. sql = @"IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.ASNCode='{0}' AND DNType = '1' AND a.WorkPoint='{1}')
  2642. BEGIN
  2643. RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  2644. RETURN
  2645. END
  2646. DECLARE @Status VARCHAR(10)
  2647. SELECT @Status=Status FROM ICSASN WHERE ASNCode='{0}' and WorkPoint='{1}'
  2648. IF (@Status IS NULL)
  2649. BEGIN
  2650. RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  2651. RETURN
  2652. END
  2653. ELSE IF (@Status!='2')
  2654. BEGIN
  2655. RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  2656. RETURN
  2657. END
  2658. DECLARE @MaxNO INT,@date varchar(20)='DN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  2659. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  2660. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  2661. IF @MaxNO IS NULL
  2662. BEGIN
  2663. SELECT @date+'00001' AS Code
  2664. END
  2665. ELSE
  2666. BEGIN
  2667. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  2668. END ";
  2669. sql = string.Format(sql, item.ASNCode, item.WorkPoint);
  2670. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2671. //修改送货单到货数量
  2672. foreach (var itemInfo in item.detail)
  2673. {
  2674. sql = @"UPDATE ICSASNDetail SET DNQuantity=ISNULL(DNQuantity, 0)+'{2}'
  2675. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  2676. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  2677. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2678. {
  2679. throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"送货单子表信息更新失败!");
  2680. }
  2681. sql = @"UPDATE ICSInventoryLot SET Quantity='{2}'
  2682. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  2683. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  2684. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2685. {
  2686. throw new Exception(language.GetNameByCode("WMSAPIInfo462")); //"条码表信息更新失败!");
  2687. }
  2688. }
  2689. //创建到货单信息
  2690. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  2691. BEGIN
  2692. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  2693. RETURN
  2694. END
  2695. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  2696. DNType,InvCode,Quantity,Amount,RCVQuantity,
  2697. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  2698. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  2699. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  2700. SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
  2701. '1',b.InvCode,SUM(a.DNQuantity),'0','0',
  2702. d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
  2703. d.POID,d.PODetailID,newid(),newid(),b.ExtensionID,
  2704. e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.ASNCode
  2705. FROM ICSASNDetail a
  2706. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2707. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  2708. INNER JOIN ICSPurchaseOrder d ON c.TransCode=d.POCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  2709. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  2710. WHERE a.ASNCode='{3}' AND a.WorkPoint='{2}'
  2711. GROUP BY d.POID,d.PODetailID,d.VenCode,d.UnitPrice,d.Currency,d.DepCode,b.ExtensionID,b.InvCode,a.ASNCode,e.F_Account,e.F_RealName,a.WorkPoint";
  2712. sql = string.Format(sql, Code, item.User, item.WorkPoint, item.ASNCode);
  2713. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2714. {
  2715. throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
  2716. }
  2717. ICSPurchaseService.DeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
  2718. asncodes += "'" + item.ASNCode + item.WorkPoint + "',";
  2719. }
  2720. if (string.IsNullOrWhiteSpace(asncodes))
  2721. {
  2722. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
  2723. }
  2724. #region 查询返回数据
  2725. sql = @"SELECT
  2726. n.POCode,
  2727. n.Sequence AS POSequence,
  2728. a.ASNCode,
  2729. a.DNCode,
  2730. a.Sequence,
  2731. a.VenCode,
  2732. a.DepCode,
  2733. a.InvCode,
  2734. inv.InvName,
  2735. inv.InvStd,
  2736. a.Quantity,
  2737. inv.InvUnit,
  2738. a.Amount,
  2739. inv.AmountUnit,
  2740. a.RCVQuantity,
  2741. a.UnitPrice,
  2742. a.Currency,
  2743. a.POID,
  2744. a.PODetailID,
  2745. a.DNID,
  2746. a.DNDetailID,
  2747. ext.ProjectCode,
  2748. ext.BatchCode,
  2749. ext.Version,
  2750. ext.Brand,
  2751. ext.cFree1,
  2752. ext.cFree2,
  2753. ext.cFree3,
  2754. ext.cFree4,
  2755. ext.cFree5,
  2756. ext.cFree6,
  2757. ext.cFree7,
  2758. ext.cFree8,
  2759. ext.cFree9,
  2760. ext.cFree10,
  2761. a.MUSER AS [User],
  2762. a.MTIME AS [MTime]
  2763. FROM ICSDeliveryNotice a
  2764. INNER JOIN ICSPurchaseOrder n ON a.POID =n.POID AND a.PODetailID=n.PODetailID AND a.WorkPoint=n.WorkPoint
  2765. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2766. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2767. WHERE a.ASNCode+a.WorkPoint IN ({0})";
  2768. sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
  2769. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2770. #endregion
  2771. cmd.Transaction.Commit();
  2772. return data;
  2773. }
  2774. catch (Exception ex)
  2775. {
  2776. if (cmd.Transaction != null)
  2777. cmd.Transaction.Rollback();
  2778. log.Error(ex.Message);
  2779. throw new Exception(ex.Message);
  2780. }
  2781. finally
  2782. {
  2783. if (conn.State == ConnectionState.Open)
  2784. {
  2785. conn.Close();
  2786. }
  2787. conn.Dispose();
  2788. }
  2789. }
  2790. }
  2791. /// <summary>
  2792. /// 采购拒收
  2793. /// </summary>
  2794. /// <param name="JsonData"></param>
  2795. /// <returns></returns>
  2796. public static DataTable PurchaseRejectDocCreate(List<ICSDeliveryNotice> JsonData)
  2797. {
  2798. var language = LanguageHelper.GetName("WMSAPIInfo");
  2799. if (JsonData.Count <= 0)
  2800. {
  2801. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2802. }
  2803. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2804. {
  2805. conn.Open();
  2806. SqlTransaction sqlTran = conn.BeginTransaction();
  2807. SqlCommand cmd = new SqlCommand();
  2808. cmd.Transaction = sqlTran;
  2809. cmd.Connection = conn;
  2810. try
  2811. {
  2812. string lots = string.Empty;
  2813. string sql = string.Empty;
  2814. foreach (var item in JsonData)
  2815. {
  2816. if (string.IsNullOrEmpty(item.DNCode))
  2817. {
  2818. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  2819. }
  2820. //获取单号
  2821. sql = @"DECLARE @Status VARCHAR(10)
  2822. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' and DNType='1' and WorkPoint='{1}'
  2823. IF (@Status IS NULL)
  2824. BEGIN
  2825. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  2826. RETURN
  2827. END
  2828. ELSE IF (@Status!='2')
  2829. BEGIN
  2830. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  2831. RETURN
  2832. END
  2833. DECLARE @MaxNO INT,@date varchar(20)='RJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  2834. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  2835. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  2836. IF @MaxNO IS NULL
  2837. BEGIN
  2838. SELECT @date+'00001' AS Code
  2839. END
  2840. ELSE
  2841. BEGIN
  2842. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  2843. END ";
  2844. sql = string.Format(sql, item.DNCode, item.WorkPoint);
  2845. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2846. //修改送货单到货数量
  2847. foreach (var itemInfo in item.detail)
  2848. {
  2849. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  2850. BEGIN
  2851. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  2852. RETURN
  2853. END
  2854. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND DNType = '3' AND a.WorkPoint='{2}')
  2855. BEGIN
  2856. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  2857. RETURN
  2858. END
  2859. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  2860. DNType,InvCode,Quantity,Amount,RCVQuantity,
  2861. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  2862. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  2863. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  2864. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  2865. '3',d.InvCode,'{7}', '{8}', 0,
  2866. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  2867. a.DNID,a.DNDetailID, '0', '0', a.ExtensionID,
  2868. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, b.LOTNO,''
  2869. FROM ICSDeliveryNotice a
  2870. INNER JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  2871. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  2872. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  2873. INNER JOIN ICSPurchaseOrder n ON m.TransCode =n.POCode AND m.TransSequence=n.Sequence AND a.PODetailID=n.PODetailID AND m.WorkPoint=n.WorkPoint
  2874. INNER JOIN ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
  2875. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  2876. WHERE a.DNCode='{0}' and b.LOTNO='{1}' AND a.WorkPoint='{2}'";
  2877. sql = string.Format(sql, item.DNCode, itemInfo.LotNo, item.WorkPoint, item.User, Code, item.VenCode, item.DepCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.UnitPrice, itemInfo.Currency, itemInfo.Sequence);
  2878. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2879. {
  2880. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  2881. }
  2882. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  2883. }
  2884. ICSPurchaseService.PurchaseRejectDocInNewERP(item.DNCode, Code, item.WorkPoint, cmd, language);
  2885. }
  2886. if (string.IsNullOrWhiteSpace(lots))
  2887. {
  2888. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  2889. }
  2890. #region 查询返回数据
  2891. sql = @"SELECT
  2892. n.DNCode,
  2893. n.Sequence,
  2894. a.DNCode AS RJTCode,
  2895. a.Sequence AS RJTSequence,
  2896. a.VenCode,
  2897. a.DepCode,
  2898. a.InvCode,
  2899. inv.InvName,
  2900. inv.InvStd,
  2901. a.Quantity,
  2902. inv.InvUnit,
  2903. a.Amount,
  2904. inv.AmountUnit,
  2905. a.RCVQuantity,
  2906. a.UnitPrice,
  2907. a.Currency,
  2908. a.POID,
  2909. a.PODetailID,
  2910. a.DNID,
  2911. a.DNDetailID,
  2912. ext.ProjectCode,
  2913. ext.BatchCode,
  2914. ext.Version,
  2915. ext.Brand,
  2916. ext.cFree1,
  2917. ext.cFree2,
  2918. ext.cFree3,
  2919. ext.cFree4,
  2920. ext.cFree5,
  2921. ext.cFree6,
  2922. ext.cFree7,
  2923. ext.cFree8,
  2924. ext.cFree9,
  2925. ext.cFree10,
  2926. a.MUSER AS [User],
  2927. a.MTIME AS [MTime]
  2928. FROM ICSDeliveryNotice a
  2929. INNER JOIN ICSDeliveryNotice n ON a.POID =n.DNID AND a.PODetailID=n.DNDetailID AND a.WorkPoint=n.WorkPoint
  2930. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2931. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2932. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  2933. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  2934. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2935. #endregion
  2936. cmd.Transaction.Commit();
  2937. return data;
  2938. }
  2939. catch (Exception ex)
  2940. {
  2941. if (cmd.Transaction != null)
  2942. cmd.Transaction.Rollback();
  2943. log.Error(ex.Message);
  2944. throw new Exception(ex.Message);
  2945. }
  2946. finally
  2947. {
  2948. if (conn.State == ConnectionState.Open)
  2949. {
  2950. conn.Close();
  2951. }
  2952. conn.Dispose();
  2953. }
  2954. }
  2955. }
  2956. #endregion
  2957. #region 委外
  2958. /// <summary>
  2959. /// 委外退料 新建
  2960. /// </summary>
  2961. /// <param name="JsonData"></param>
  2962. /// <returns></returns>
  2963. public static DataTable OutsourcingIssueDoNegativeApplyCreate(List<ICSOApplyNeg> JsonData)
  2964. {
  2965. var language = LanguageHelper.GetName("WMSAPIInfo");
  2966. if (JsonData.Count <= 0)
  2967. {
  2968. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2969. }
  2970. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2971. {
  2972. conn.Open();
  2973. SqlTransaction sqlTran = conn.BeginTransaction();
  2974. SqlCommand cmd = new SqlCommand();
  2975. cmd.Transaction = sqlTran;
  2976. cmd.Connection = conn;
  2977. try
  2978. {
  2979. string codes = string.Empty;
  2980. string sql = string.Empty;
  2981. foreach (var item in JsonData)
  2982. {
  2983. //获取单号
  2984. sql = @"DECLARE @MaxNO INT,@date varchar(20)='OOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  2985. SELECT @MaxNO=SUBSTRING(MAX(OApplyNegCode),LEN(@date)+1,LEN(MAX(OApplyNegCode))-LEN(@date))+1 FROM ICSOApplyNeg
  2986. WHERE SUBSTRING(OApplyNegCode, 1, LEN(@date))=@date
  2987. IF @MaxNO IS NULL
  2988. BEGIN
  2989. SELECT @date+'00001' AS Code
  2990. END
  2991. ELSE
  2992. BEGIN
  2993. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  2994. END ";
  2995. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2996. //创建主表
  2997. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  2998. BEGIN
  2999. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3000. RETURN
  3001. END
  3002. INSERT INTO ICSOApplyNeg(ID,OApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  3003. VALUES (NEWID(),'{0}','{1}','1','{5}','','{2}','{3}','{2}',(select F_RealName from Sys_SRM_User where F_Account='{2}' and F_Location='{4}'),'{3}','{4}','')";
  3004. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  3005. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3006. {
  3007. throw new Exception(language.GetNameByCode("WMSAPIInfo014"));//"委外退料单信息创建失败!");
  3008. }
  3009. foreach (var itemInfo in item.detail)
  3010. {
  3011. //创建子表
  3012. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  3013. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  3014. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  3015. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  3016. '{4}','{5}',0,'{6}','{7}',
  3017. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  3018. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  3019. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3020. {
  3021. throw new Exception(language.GetNameByCode("WMSAPIInfo015"));//"委外退料单子表信息创建失败!");
  3022. }
  3023. }
  3024. //校验退料数量是否超出领料数量
  3025. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  3026. DBHelper.ExecuteNonQuery(sql, cmd);
  3027. codes += "'" + Code + item.WorkPoint + "',";
  3028. }
  3029. if (string.IsNullOrWhiteSpace(codes))
  3030. {
  3031. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  3032. }
  3033. #region 查询返回数据
  3034. sql = @"SELECT a.OApplyNegCode,
  3035. c.WHCode,
  3036. c.Memo,
  3037. d.Name AS Status,
  3038. a.Sequence,
  3039. a.InvCode,
  3040. inv.InvName,
  3041. inv.InvStd,
  3042. a.Quantity,
  3043. inv.InvUnit,
  3044. a.Amount,
  3045. inv.AmountUnit,
  3046. a.IssueNegQuantity,
  3047. ext.ProjectCode,
  3048. ext.BatchCode,
  3049. ext.Version,
  3050. ext.Brand,
  3051. ext.cFree1,
  3052. ext.cFree2,
  3053. ext.cFree3,
  3054. ext.cFree4,
  3055. ext.cFree5,
  3056. ext.cFree6,
  3057. ext.cFree7,
  3058. ext.cFree8,
  3059. ext.cFree9,
  3060. ext.cFree10,
  3061. a.MUSER AS [User],
  3062. a.MTIME AS [MTime]
  3063. FROM ICSOApplyNegDetail a
  3064. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3065. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3066. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3067. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3068. WHERE a.OApplyNegCode+a.WorkPoint IN ({0})";
  3069. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  3070. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3071. #endregion
  3072. cmd.Transaction.Commit();
  3073. return data;
  3074. }
  3075. catch (Exception ex)
  3076. {
  3077. if (cmd.Transaction != null)
  3078. cmd.Transaction.Rollback();
  3079. log.Error(ex.Message);
  3080. throw new Exception(ex.Message);
  3081. }
  3082. finally
  3083. {
  3084. if (conn.State == ConnectionState.Open)
  3085. {
  3086. conn.Close();
  3087. }
  3088. conn.Dispose();
  3089. }
  3090. }
  3091. }
  3092. private static string CheckOutsourcingIssueDoc(string Type, string Code, string WorkPoint, Dictionary<string, string> language)
  3093. {
  3094. string sql = string.Empty;
  3095. if (Type == "1")
  3096. {
  3097. sql = @"DECLARE @PickID VARCHAR(10)
  3098. SELECT @PickID=b.PickID
  3099. FROM ICSOApplyNegDetail a
  3100. INNER JOIN ICSOOPick b ON a.SourceDetailID=b.PickID AND a.WorkPoint=b.WorkPoint
  3101. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3102. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3103. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3104. FROM ICSOApplyNegDetail a
  3105. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3106. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3107. GROUP BY b.PickID
  3108. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3109. IF (@PickID IS NOT NULL)
  3110. BEGIN
  3111. DECLARE @InvCode VARCHAR(100)
  3112. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOOPick WHERE PickID=@PickID AND WorkPoint='{1}'
  3113. RAISERROR(@InvCode,16,1);
  3114. RETURN
  3115. END ";
  3116. }
  3117. else if (Type == "2")
  3118. {
  3119. sql = @"DECLARE @ApplyDetailID VARCHAR(10)
  3120. SELECT @ApplyDetailID=b.ApplyDetailID
  3121. FROM ICSOApplyNegDetail a
  3122. INNER JOIN ICSOApply b ON a.SourceDetailID=b.ApplyDetailID AND a.WorkPoint=b.WorkPoint
  3123. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3124. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3125. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3126. FROM ICSOApplyNegDetail a
  3127. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3128. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3129. GROUP BY b.ApplyDetailID
  3130. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3131. IF (@ApplyDetailID IS NOT NULL)
  3132. BEGIN
  3133. DECLARE @InvCode VARCHAR(100)
  3134. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOApply WHERE ApplyDetailID=@ApplyDetailID AND WorkPoint='{1}'
  3135. RAISERROR(@InvCode,16,1);
  3136. RETURN
  3137. END ";
  3138. }
  3139. else if (Type == "3")
  3140. {
  3141. sql = @"DECLARE @IssueDetailID VARCHAR(10)
  3142. SELECT @IssueDetailID=b.IssueDetailID
  3143. FROM ICSOApplyNegDetail a
  3144. INNER JOIN ICSOIssue b ON a.SourceDetailID=b.IssueDetailID AND a.WorkPoint=b.WorkPoint
  3145. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3146. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3147. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3148. FROM ICSOApplyNegDetail a
  3149. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3150. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3151. GROUP BY b.IssueDetailID
  3152. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3153. IF (@IssueDetailID IS NOT NULL)
  3154. BEGIN
  3155. DECLARE @InvCode VARCHAR(100)
  3156. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOIssue WHERE IssueDetailID=@IssueDetailID AND WorkPoint='{1}'
  3157. RAISERROR(@InvCode,16,1);
  3158. RETURN
  3159. END ";
  3160. }
  3161. else
  3162. {
  3163. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  3164. }
  3165. sql = string.Format(sql, Code, WorkPoint, Type);
  3166. return sql;
  3167. }
  3168. /// <summary>
  3169. /// 委外退料 修改
  3170. /// </summary>
  3171. /// <param name="JsonData"></param>
  3172. /// <returns></returns>
  3173. public static DataTable OutsourcingIssueDoNegativeApplyUpdate(List<ICSOApplyNeg> JsonData)
  3174. {
  3175. var language = LanguageHelper.GetName("WMSAPIInfo");
  3176. if (JsonData.Count <= 0)
  3177. {
  3178. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3179. }
  3180. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3181. {
  3182. conn.Open();
  3183. SqlTransaction sqlTran = conn.BeginTransaction();
  3184. SqlCommand cmd = new SqlCommand();
  3185. cmd.Transaction = sqlTran;
  3186. cmd.Connection = conn;
  3187. try
  3188. {
  3189. string sql = string.Empty;
  3190. string Code = string.Empty;
  3191. string ids = string.Empty;
  3192. foreach (var item in JsonData)
  3193. {
  3194. //主表修改
  3195. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  3196. BEGIN
  3197. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  3198. RETURN
  3199. END
  3200. DECLARE @Status VARCHAR(10)
  3201. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  3202. IF (@Status IS NULL)
  3203. BEGIN
  3204. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  3205. RETURN
  3206. END
  3207. ELSE IF (@Status!='1')
  3208. BEGIN
  3209. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  3210. RETURN
  3211. END
  3212. update ICSOApplyNeg set WHCode='{0}',MUSER='{1}',MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{1}' and F_Location='{4}'),MTIME='{2}' where ID='{3}' and WorkPoint='{4}' ";
  3213. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.id, item.WorkPoint);
  3214. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3215. {
  3216. throw new Exception(language.GetNameByCode("WMSAPIInfo016"));//"委外退料单信息修改失败!");
  3217. }
  3218. var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  3219. if (detail > 0)
  3220. {
  3221. sql = @"SELECT OApplyNegCode FROM ICSOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  3222. sql = string.Format(sql, item.id, item.WorkPoint);
  3223. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3224. }
  3225. foreach (var itemInfo in item.detail)
  3226. {
  3227. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  3228. {
  3229. //创建子表
  3230. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  3231. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  3232. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  3233. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  3234. '{4}','{5}',0,'{6}','{7}',
  3235. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  3236. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  3237. }
  3238. else
  3239. {
  3240. //子表修改
  3241. sql = @"update ICSOApplyNegDetail set InvCode='{0}' ,Quantity='{1}',Amount='{2}',SourceDetailID='{3}',MUSER='{6}',MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{6}' and F_Location='{5}') where ID='{4}' and WorkPoint='{5}'";
  3242. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  3243. }
  3244. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3245. {
  3246. throw new Exception(language.GetNameByCode("WMSAPIInfo017"));//"委外退料单子表信息修改失败!");
  3247. }
  3248. }
  3249. //校验退料数量是否超出领料数量
  3250. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  3251. DBHelper.ExecuteNonQuery(sql, cmd);
  3252. ids += "'" + item.id + "',";
  3253. }
  3254. if (string.IsNullOrWhiteSpace(ids))
  3255. {
  3256. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  3257. }
  3258. #region 查询返回数据
  3259. sql = @"SELECT a.OApplyNegCode,
  3260. c.WHCode,
  3261. c.Memo,
  3262. d.Name AS Status,
  3263. a.Sequence,
  3264. a.InvCode,
  3265. inv.InvName,
  3266. inv.InvStd,
  3267. a.Quantity,
  3268. inv.InvUnit,
  3269. a.Amount,
  3270. inv.AmountUnit,
  3271. a.IssueNegQuantity,
  3272. ext.ProjectCode,
  3273. ext.BatchCode,
  3274. ext.Version,
  3275. ext.Brand,
  3276. ext.cFree1,
  3277. ext.cFree2,
  3278. ext.cFree3,
  3279. ext.cFree4,
  3280. ext.cFree5,
  3281. ext.cFree6,
  3282. ext.cFree7,
  3283. ext.cFree8,
  3284. ext.cFree9,
  3285. ext.cFree10,
  3286. a.MUSER AS [User],
  3287. a.MTIME AS [MTime]
  3288. FROM ICSOApplyNegDetail a
  3289. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3290. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3291. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3292. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3293. WHERE c.ID IN ({0})";
  3294. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  3295. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3296. #endregion
  3297. cmd.Transaction.Commit();
  3298. return data;
  3299. }
  3300. catch (Exception ex)
  3301. {
  3302. if (cmd.Transaction != null)
  3303. cmd.Transaction.Rollback();
  3304. log.Error(ex.Message);
  3305. throw new Exception(ex.Message);
  3306. }
  3307. finally
  3308. {
  3309. if (conn.State == ConnectionState.Open)
  3310. {
  3311. conn.Close();
  3312. }
  3313. conn.Dispose();
  3314. }
  3315. }
  3316. }
  3317. /// <summary>
  3318. /// 委外退料审核
  3319. /// </summary>
  3320. /// <param name="JsonData"></param>
  3321. /// <returns></returns>
  3322. public static DataTable OutsourcingIssueDoNegativeApplyApprove(List<ICSUser> JsonData)
  3323. {
  3324. var language = LanguageHelper.GetName("WMSAPIInfo");
  3325. if (JsonData.Count <= 0)
  3326. {
  3327. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3328. }
  3329. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3330. {
  3331. conn.Open();
  3332. SqlTransaction sqlTran = conn.BeginTransaction();
  3333. SqlCommand cmd = new SqlCommand();
  3334. cmd.Transaction = sqlTran;
  3335. cmd.Connection = conn;
  3336. try
  3337. {
  3338. string sql = string.Empty;
  3339. string ids = string.Empty;
  3340. foreach (var item in JsonData)
  3341. {
  3342. if (string.IsNullOrEmpty(item.ID))
  3343. {
  3344. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  3345. }
  3346. if (string.IsNullOrEmpty(item.User))
  3347. {
  3348. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  3349. }
  3350. if (item.MTime <= new DateTime(2000, 1, 1))
  3351. {
  3352. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  3353. }
  3354. //获取单号
  3355. sql = @"DECLARE @Status VARCHAR(10)
  3356. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{0}'
  3357. IF (@Status IS NULL)
  3358. BEGIN
  3359. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  3360. RETURN
  3361. END
  3362. ELSE IF (@Status!='1')
  3363. BEGIN
  3364. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  3365. RETURN
  3366. END
  3367. update ICSOApplyNeg set Status='2',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  3368. sql = string.Format(sql, item.ID, item.User, item.MTime);
  3369. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3370. {
  3371. throw new Exception(language.GetNameByCode("WMSAPIInfo021"));//"委外退料申请单审核失败!");
  3372. }
  3373. ids += "'" + item.ID + "',";
  3374. }
  3375. if (string.IsNullOrWhiteSpace(ids))
  3376. {
  3377. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  3378. }
  3379. #region 查询返回数据
  3380. sql = @"SELECT a.OApplyNegCode,
  3381. c.WHCode,
  3382. c.Memo,
  3383. d.Name AS Status,
  3384. a.Sequence,
  3385. a.InvCode,
  3386. inv.InvName,
  3387. inv.InvStd,
  3388. a.Quantity,
  3389. inv.InvUnit,
  3390. a.Amount,
  3391. inv.AmountUnit,
  3392. a.IssueNegQuantity,
  3393. ext.ProjectCode,
  3394. ext.BatchCode,
  3395. ext.Version,
  3396. ext.Brand,
  3397. ext.cFree1,
  3398. ext.cFree2,
  3399. ext.cFree3,
  3400. ext.cFree4,
  3401. ext.cFree5,
  3402. ext.cFree6,
  3403. ext.cFree7,
  3404. ext.cFree8,
  3405. ext.cFree9,
  3406. ext.cFree10,
  3407. a.MUSER AS [User],
  3408. a.MTIME AS [MTime]
  3409. FROM ICSOApplyNegDetail a
  3410. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3411. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3412. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3413. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3414. WHERE c.ID IN ({0})";
  3415. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  3416. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3417. #endregion
  3418. cmd.Transaction.Commit();
  3419. return data;
  3420. }
  3421. catch (Exception ex)
  3422. {
  3423. if (cmd.Transaction != null)
  3424. cmd.Transaction.Rollback();
  3425. log.Error(ex.Message);
  3426. throw new Exception(ex.Message);
  3427. }
  3428. finally
  3429. {
  3430. if (conn.State == ConnectionState.Open)
  3431. {
  3432. conn.Close();
  3433. }
  3434. conn.Dispose();
  3435. }
  3436. }
  3437. }
  3438. /// <summary>
  3439. /// 委外到货
  3440. /// </summary>
  3441. /// <param name="JsonData"></param>
  3442. /// <returns></returns>
  3443. public static DataTable OutsourcingDeliveryNoticeCreate(List<ICSDeliveryNotice> JsonData)
  3444. {
  3445. var language = LanguageHelper.GetName("WMSAPIInfo");
  3446. if (JsonData.Count <= 0)
  3447. {
  3448. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3449. }
  3450. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3451. {
  3452. conn.Open();
  3453. SqlTransaction sqlTran = conn.BeginTransaction();
  3454. SqlCommand cmd = new SqlCommand();
  3455. cmd.Transaction = sqlTran;
  3456. cmd.Connection = conn;
  3457. try
  3458. {
  3459. string asncodes = string.Empty;
  3460. string sql = string.Empty;
  3461. foreach (var item in JsonData)
  3462. {
  3463. if (string.IsNullOrEmpty(item.OASNCode))
  3464. {
  3465. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!");
  3466. }
  3467. //获取单号
  3468. sql = @"IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.OASNCode='{0}' AND ODNType = '1' AND a.WorkPoint='{1}')
  3469. BEGIN
  3470. RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  3471. RETURN
  3472. END
  3473. DECLARE @Status VARCHAR(10)
  3474. SELECT @Status=Status FROM ICSOASN WHERE OASNCode='{0}' and WorkPoint='{1}'
  3475. IF (@Status IS NULL)
  3476. BEGIN
  3477. RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  3478. RETURN
  3479. END
  3480. ELSE IF (@Status!='2')
  3481. BEGIN
  3482. RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  3483. RETURN
  3484. END
  3485. DECLARE @MaxNO INT,@date varchar(20)='ODN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3486. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  3487. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  3488. IF @MaxNO IS NULL
  3489. BEGIN
  3490. SELECT @date+'00001' AS Code
  3491. END
  3492. ELSE
  3493. BEGIN
  3494. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3495. END ";
  3496. sql = string.Format(sql, item.OASNCode, item.WorkPoint);
  3497. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3498. //修改送货单到货数量
  3499. foreach (var itemInfo in item.detail)
  3500. {
  3501. sql = @"UPDATE ICSOASNDetail SET ODNQuantity=ISNULL(ODNQuantity, 0)+'{2}'
  3502. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  3503. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  3504. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3505. {
  3506. throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"委外送货单子表信息更新失败!");
  3507. }
  3508. }
  3509. //创建到货单信息
  3510. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  3511. BEGIN
  3512. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  3513. RETURN
  3514. END
  3515. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  3516. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  3517. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  3518. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  3519. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  3520. SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
  3521. '1',b.InvCode,SUM(a.ODNQuantity),'0','0',
  3522. d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
  3523. d.OOID,d.OODetailID,newid(),newid(),b.ExtensionID,
  3524. e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.OASNCode
  3525. FROM ICSOASNDetail a
  3526. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3527. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  3528. INNER JOIN ICSOutsourcingOrder d ON c.TransCode=d.OOCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  3529. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  3530. WHERE a.OASNCode='{3}' AND a.WorkPoint='{2}'
  3531. GROUP BY d.OOID,d.OODetailID,d.VenCode,d.UnitPrice,d.Currency,d.DepCode,b.ExtensionID,b.InvCode,a.OASNCode,e.F_Account,e.F_RealName,a.WorkPoint";
  3532. sql = string.Format(sql, Code, item.User, item.WorkPoint, item.OASNCode);
  3533. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3534. {
  3535. throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
  3536. }
  3537. ICSOutsourcingService.OutsourcingDeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
  3538. asncodes += "'" + item.OASNCode + item.WorkPoint + "',";
  3539. }
  3540. if (string.IsNullOrWhiteSpace(asncodes))
  3541. {
  3542. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
  3543. }
  3544. #region 查询返回数据
  3545. sql = @"SELECT
  3546. n.OOCode,
  3547. n.Sequence AS OOSequence,
  3548. a.OASNCode,
  3549. a.ODNCode,
  3550. a.Sequence,
  3551. a.VenCode,
  3552. a.DepCode,
  3553. a.InvCode,
  3554. inv.InvName,
  3555. inv.InvStd,
  3556. a.Quantity,
  3557. inv.InvUnit,
  3558. a.Amount,
  3559. inv.AmountUnit,
  3560. a.RCVQuantity,
  3561. a.UnitPrice,
  3562. a.Currency,
  3563. a.OOID,
  3564. a.OODetailID,
  3565. a.ODNID,
  3566. a.ODNDetailID,
  3567. ext.ProjectCode,
  3568. ext.BatchCode,
  3569. ext.Version,
  3570. ext.Brand,
  3571. ext.cFree1,
  3572. ext.cFree2,
  3573. ext.cFree3,
  3574. ext.cFree4,
  3575. ext.cFree5,
  3576. ext.cFree6,
  3577. ext.cFree7,
  3578. ext.cFree8,
  3579. ext.cFree9,
  3580. ext.cFree10,
  3581. a.MUSER AS [User],
  3582. a.MTIME AS [MTime]
  3583. FROM ICSODeliveryNotice a
  3584. INNER JOIN ICSOutsourcingOrder n ON a.OOID =n.OOID AND a.OODetailID=n.OODetailID AND a.WorkPoint=n.WorkPoint
  3585. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3586. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3587. WHERE a.OASNCode+a.WorkPoint IN ({0})";
  3588. sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
  3589. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3590. #endregion
  3591. cmd.Transaction.Commit();
  3592. return data;
  3593. }
  3594. catch (Exception ex)
  3595. {
  3596. if (cmd.Transaction != null)
  3597. cmd.Transaction.Rollback();
  3598. log.Error(ex.Message);
  3599. throw new Exception(ex.Message);
  3600. }
  3601. finally
  3602. {
  3603. if (conn.State == ConnectionState.Open)
  3604. {
  3605. conn.Close();
  3606. }
  3607. conn.Dispose();
  3608. }
  3609. }
  3610. }
  3611. /// <summary>
  3612. /// 委外拒收
  3613. /// </summary>
  3614. /// <param name="JsonData"></param>
  3615. /// <returns></returns>
  3616. public static DataTable OutsourcingRejectDocCreate(List<ICSDeliveryNotice> JsonData)
  3617. {
  3618. var language = LanguageHelper.GetName("WMSAPIInfo");
  3619. if (JsonData.Count <= 0)
  3620. {
  3621. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3622. }
  3623. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3624. {
  3625. conn.Open();
  3626. SqlTransaction sqlTran = conn.BeginTransaction();
  3627. SqlCommand cmd = new SqlCommand();
  3628. cmd.Transaction = sqlTran;
  3629. cmd.Connection = conn;
  3630. try
  3631. {
  3632. string lots = string.Empty;
  3633. string sql = string.Empty;
  3634. foreach (var item in JsonData)
  3635. {
  3636. if (string.IsNullOrEmpty(item.ODNCode))
  3637. {
  3638. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  3639. }
  3640. //获取单号
  3641. sql = @"DECLARE @Status VARCHAR(10)
  3642. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' and ODNType='1' and WorkPoint='{1}'
  3643. IF (@Status IS NULL)
  3644. BEGIN
  3645. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  3646. RETURN
  3647. END
  3648. ELSE IF (@Status!='2')
  3649. BEGIN
  3650. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  3651. RETURN
  3652. END
  3653. DECLARE @MaxNO INT,@date varchar(20)='ORJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3654. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  3655. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  3656. IF @MaxNO IS NULL
  3657. BEGIN
  3658. SELECT @date+'00001' AS Code
  3659. END
  3660. ELSE
  3661. BEGIN
  3662. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3663. END ";
  3664. sql = string.Format(sql, item.ODNCode, item.WorkPoint);
  3665. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3666. //修改送货单到货数量
  3667. foreach (var itemInfo in item.detail)
  3668. {
  3669. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  3670. BEGIN
  3671. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  3672. RETURN
  3673. END
  3674. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND ODNType = '3' AND a.WorkPoint='{2}')
  3675. BEGIN
  3676. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  3677. RETURN
  3678. END
  3679. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  3680. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  3681. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  3682. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  3683. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  3684. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  3685. '3',d.InvCode,'{7}', '{8}', 0,
  3686. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  3687. a.ODNID,a.ODNDetailID, '0', '0', a.ExtensionID,
  3688. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, b.LOTNO,''
  3689. FROM ICSODeliveryNotice a
  3690. INNER JOIN ICSOASNDetail b ON a.OASNCode=b.OASNCode AND a.WorkPoint=b.WorkPoint
  3691. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  3692. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  3693. INNER JOIN ICSOutsourcingOrder n ON m.TransCode =n.OOCode AND m.TransSequence=n.Sequence AND a.OODetailID=n.OODetailID AND m.WorkPoint=n.WorkPoint
  3694. INNER JOIN ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
  3695. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  3696. WHERE a.ODNCode='{0}' and b.LOTNO='{1}' AND a.WorkPoint='{2}'";
  3697. sql = string.Format(sql, item.ODNCode, itemInfo.LotNo, item.WorkPoint, item.User, Code, item.VenCode, item.DepCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.UnitPrice, itemInfo.Currency, itemInfo.Sequence);
  3698. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3699. {
  3700. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  3701. }
  3702. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  3703. }
  3704. ICSOutsourcingService.OutsourcingRejectDocInNewERP(item.ODNCode, Code, item.WorkPoint, cmd, language);
  3705. }
  3706. if (string.IsNullOrWhiteSpace(lots))
  3707. {
  3708. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  3709. }
  3710. #region 查询返回数据
  3711. sql = @"SELECT
  3712. n.ODNCode,
  3713. n.Sequence,
  3714. a.ODNCode AS RJTCode,
  3715. a.Sequence AS RJTSequence,
  3716. a.VenCode,
  3717. a.DepCode,
  3718. a.InvCode,
  3719. inv.InvName,
  3720. inv.InvStd,
  3721. a.Quantity,
  3722. inv.InvUnit,
  3723. a.Amount,
  3724. inv.AmountUnit,
  3725. a.RCVQuantity,
  3726. a.UnitPrice,
  3727. a.Currency,
  3728. a.OOID,
  3729. a.OODetailID,
  3730. a.ODNID,
  3731. a.ODNDetailID,
  3732. ext.ProjectCode,
  3733. ext.BatchCode,
  3734. ext.Version,
  3735. ext.Brand,
  3736. ext.cFree1,
  3737. ext.cFree2,
  3738. ext.cFree3,
  3739. ext.cFree4,
  3740. ext.cFree5,
  3741. ext.cFree6,
  3742. ext.cFree7,
  3743. ext.cFree8,
  3744. ext.cFree9,
  3745. ext.cFree10,
  3746. a.MUSER AS [User],
  3747. a.MTIME AS [MTime]
  3748. FROM ICSODeliveryNotice a
  3749. INNER JOIN ICSODeliveryNotice n ON a.OOID =n.ODNID AND a.OODetailID=n.ODNDetailID AND a.WorkPoint=n.WorkPoint
  3750. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3751. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3752. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  3753. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  3754. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3755. #endregion
  3756. cmd.Transaction.Commit();
  3757. return data;
  3758. }
  3759. catch (Exception ex)
  3760. {
  3761. if (cmd.Transaction != null)
  3762. cmd.Transaction.Rollback();
  3763. log.Error(ex.Message);
  3764. throw new Exception(ex.Message);
  3765. }
  3766. finally
  3767. {
  3768. if (conn.State == ConnectionState.Open)
  3769. {
  3770. conn.Close();
  3771. }
  3772. conn.Dispose();
  3773. }
  3774. }
  3775. }
  3776. #endregion
  3777. #region 生产
  3778. /// <summary>
  3779. /// 生产退料 新建
  3780. /// </summary>
  3781. /// <param name="JsonData"></param>
  3782. /// <returns></returns>
  3783. public static DataTable MOIssueDocNegativeApplyCreate(List<ICSMOApplyNeg> JsonData)
  3784. {
  3785. var language = LanguageHelper.GetName("WMSAPIInfo");
  3786. if (JsonData.Count <= 0)
  3787. {
  3788. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3789. }
  3790. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3791. {
  3792. conn.Open();
  3793. SqlTransaction sqlTran = conn.BeginTransaction();
  3794. SqlCommand cmd = new SqlCommand();
  3795. cmd.Transaction = sqlTran;
  3796. cmd.Connection = conn;
  3797. try
  3798. {
  3799. string codes = string.Empty;
  3800. string sql = string.Empty;
  3801. foreach (var item in JsonData)
  3802. {
  3803. //获取单号
  3804. sql = @"DECLARE @MaxNO INT,@date varchar(20)='MOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3805. SELECT @MaxNO=SUBSTRING(MAX(ApplyNegCode),LEN(@date)+1,LEN(MAX(ApplyNegCode))-LEN(@date))+1 FROM ICSMOApplyNeg
  3806. WHERE SUBSTRING(ApplyNegCode, 1, LEN(@date))=@date
  3807. IF @MaxNO IS NULL
  3808. BEGIN
  3809. SELECT @date+'00001' AS Code
  3810. END
  3811. ELSE
  3812. BEGIN
  3813. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3814. END ";
  3815. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3816. //创建主表
  3817. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  3818. BEGIN
  3819. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3820. RETURN
  3821. END
  3822. INSERT INTO ICSMOApplyNeg(ID,ApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  3823. VALUES (NEWID(),'{0}','{1}','1','{5}','','{2}','{3}','{2}',(select F_RealName from Sys_SRM_User where F_Account='{2}' and F_Location='{4}'),'{3}','{4}','')";
  3824. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  3825. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3826. {
  3827. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产退料单信息创建失败!");
  3828. }
  3829. foreach (var itemInfo in item.detail)
  3830. {
  3831. //创建子表
  3832. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,
  3833. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  3834. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  3835. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  3836. '{4}','{5}',0,'{6}','{7}',
  3837. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  3838. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  3839. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3840. {
  3841. throw new Exception(language.GetNameByCode("WMSAPIInfo023"));//"生产退料单子表信息创建失败!");
  3842. }
  3843. }
  3844. //校验退料数量是否超出领料数量
  3845. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  3846. DBHelper.ExecuteNonQuery(sql, cmd);
  3847. codes += "'" + Code + item.WorkPoint + "',";
  3848. }
  3849. if (string.IsNullOrWhiteSpace(codes))
  3850. {
  3851. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  3852. }
  3853. #region 查询返回数据
  3854. sql = @"SELECT a.ApplyNegCode,
  3855. c.WHCode,
  3856. c.Memo,
  3857. d.Name AS Status,
  3858. a.Sequence,
  3859. a.InvCode,
  3860. inv.InvName,
  3861. inv.InvStd,
  3862. a.Quantity,
  3863. inv.InvUnit,
  3864. a.Amount,
  3865. inv.AmountUnit,
  3866. a.IssueNegQuantity,
  3867. ext.ProjectCode,
  3868. ext.BatchCode,
  3869. ext.Version,
  3870. ext.Brand,
  3871. ext.cFree1,
  3872. ext.cFree2,
  3873. ext.cFree3,
  3874. ext.cFree4,
  3875. ext.cFree5,
  3876. ext.cFree6,
  3877. ext.cFree7,
  3878. ext.cFree8,
  3879. ext.cFree9,
  3880. ext.cFree10,
  3881. a.MUSER AS [User],
  3882. a.MTIME AS [MTime]
  3883. FROM ICSMOApplyNegDetail a
  3884. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3885. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3886. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3887. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3888. WHERE a.ApplyNegCode+a.WorkPoint IN ({0})";
  3889. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  3890. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3891. #endregion
  3892. cmd.Transaction.Commit();
  3893. return data;
  3894. }
  3895. catch (Exception ex)
  3896. {
  3897. if (cmd.Transaction != null)
  3898. cmd.Transaction.Rollback();
  3899. log.Error(ex.Message);
  3900. throw new Exception(ex.Message);
  3901. }
  3902. finally
  3903. {
  3904. if (conn.State == ConnectionState.Open)
  3905. {
  3906. conn.Close();
  3907. }
  3908. conn.Dispose();
  3909. }
  3910. }
  3911. }
  3912. private static string CheckMOIssueDoc(string Type, string ID, string WorkPoint, Dictionary<string, string> language)
  3913. {
  3914. string sql = string.Empty;
  3915. if (Type == "1")
  3916. {
  3917. sql = @"DECLARE @PickID VARCHAR(10)
  3918. SELECT @PickID=b.PickID
  3919. FROM ICSMOApplyNegDetail a
  3920. INNER JOIN ICSMOPick b ON a.SourceDetailID=b.PickID AND a.WorkPoint=b.WorkPoint
  3921. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3922. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3923. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3924. FROM ICSMOApplyNegDetail a
  3925. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3926. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3927. GROUP BY b.PickID
  3928. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3929. IF (@PickID IS NOT NULL)
  3930. BEGIN
  3931. DECLARE @InvCode VARCHAR(100)
  3932. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOPick WHERE PickID=@PickID AND WorkPoint='{1}'
  3933. RAISERROR(@InvCode,16,1);
  3934. RETURN
  3935. END ";
  3936. }
  3937. else if (Type == "2")
  3938. {
  3939. sql = @"DECLARE @ApplyDetailID VARCHAR(10)
  3940. SELECT @ApplyDetailID=b.ApplyDetailID
  3941. FROM ICSMOApplyNegDetail a
  3942. INNER JOIN ICSMOApply b ON a.SourceDetailID=b.ApplyDetailID AND a.WorkPoint=b.WorkPoint
  3943. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3944. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3945. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3946. FROM ICSMOApplyNegDetail a
  3947. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3948. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3949. GROUP BY b.ApplyDetailID
  3950. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3951. IF (@ApplyDetailID IS NOT NULL)
  3952. BEGIN
  3953. DECLARE @InvCode VARCHAR(100)
  3954. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOApply WHERE ApplyDetailID=@ApplyDetailID AND WorkPoint='{1}'
  3955. RAISERROR(@InvCode,16,1);
  3956. RETURN
  3957. END ";
  3958. }
  3959. else if (Type == "3")
  3960. {
  3961. sql = @"DECLARE @IssueDetailID VARCHAR(10)
  3962. SELECT @IssueDetailID=b.IssueDetailID
  3963. FROM ICSMOApplyNegDetail a
  3964. INNER JOIN ICSMOIssue b ON a.SourceDetailID=b.IssueDetailID AND a.WorkPoint=b.WorkPoint
  3965. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3966. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3967. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3968. FROM ICSMOApplyNegDetail a
  3969. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3970. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3971. GROUP BY b.IssueDetailID
  3972. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3973. IF (@IssueDetailID IS NOT NULL)
  3974. BEGIN
  3975. DECLARE @InvCode VARCHAR(100)
  3976. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOIssue WHERE IssueDetailID=@IssueDetailID AND WorkPoint='{1}'
  3977. RAISERROR(@InvCode,16,1);
  3978. RETURN
  3979. END ";
  3980. }
  3981. else
  3982. {
  3983. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  3984. }
  3985. sql = string.Format(sql, ID, WorkPoint, Type);
  3986. return sql;
  3987. }
  3988. /// <summary>
  3989. /// 生产退料 修改
  3990. /// </summary>
  3991. /// <param name="JsonData"></param>
  3992. /// <returns></returns>
  3993. public static DataTable MOIssueDocNegativeApplyUpdate(List<ICSMOApplyNeg> JsonData)
  3994. {
  3995. var language = LanguageHelper.GetName("WMSAPIInfo");
  3996. if (JsonData.Count <= 0)
  3997. {
  3998. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3999. }
  4000. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4001. {
  4002. conn.Open();
  4003. SqlTransaction sqlTran = conn.BeginTransaction();
  4004. SqlCommand cmd = new SqlCommand();
  4005. cmd.Transaction = sqlTran;
  4006. cmd.Connection = conn;
  4007. try
  4008. {
  4009. string sql = string.Empty;
  4010. string Code = string.Empty;
  4011. string ids = string.Empty;
  4012. foreach (var item in JsonData)
  4013. {
  4014. //主表修改
  4015. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  4016. BEGIN
  4017. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  4018. RETURN
  4019. END
  4020. DECLARE @Status VARCHAR(10)
  4021. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  4022. IF (@Status IS NULL)
  4023. BEGIN
  4024. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  4025. RETURN
  4026. END
  4027. ELSE IF (@Status!='1')
  4028. BEGIN
  4029. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  4030. RETURN
  4031. END
  4032. update ICSMOApplyNeg set WHCode='{0}',MUSER='{1}',MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{1}' and F_Location='{4}'),MTIME='{2}' where ID='{3}' and WorkPoint='{4}' ";
  4033. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.ID, item.WorkPoint);
  4034. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4035. {
  4036. throw new Exception(language.GetNameByCode("WMSAPIInfo024"));//"生产退料单信息修改失败!");
  4037. }
  4038. var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  4039. if (detail > 0)
  4040. {
  4041. sql = @"SELECT ApplyNegCode FROM ICSMOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  4042. sql = string.Format(sql, item.ID, item.WorkPoint);
  4043. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  4044. }
  4045. foreach (var itemInfo in item.detail)
  4046. {
  4047. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  4048. {
  4049. //创建子表
  4050. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  4051. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  4052. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  4053. '{4}','{5}',0,'{6}','{7}',
  4054. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  4055. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  4056. }
  4057. else
  4058. {
  4059. //子表修改
  4060. sql = @"update ICSMOApplyNegDetail set InvCode='{0}' ,Quantity='{1}',Amount='{2}',SourceDetailID='{3}',MUSER='{6}',MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{6}' and F_Location='{5}') where ID='{4}' and WorkPoint='{5}'";
  4061. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  4062. }
  4063. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4064. {
  4065. throw new Exception(language.GetNameByCode("WMSAPIInfo025"));//"生产退料单子表信息修改失败!");
  4066. }
  4067. }
  4068. //校验退料数量是否超出领料数量
  4069. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  4070. DBHelper.ExecuteNonQuery(sql, cmd);
  4071. ids += "'" + item.ID + "',";
  4072. }
  4073. if (string.IsNullOrWhiteSpace(ids))
  4074. {
  4075. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  4076. }
  4077. #region 查询返回数据
  4078. sql = @"SELECT a.ApplyNegCode,
  4079. c.WHCode,
  4080. c.Memo,
  4081. d.Name AS Status,
  4082. a.Sequence,
  4083. a.InvCode,
  4084. inv.InvName,
  4085. inv.InvStd,
  4086. a.Quantity,
  4087. inv.InvUnit,
  4088. a.Amount,
  4089. inv.AmountUnit,
  4090. a.IssueNegQuantity,
  4091. ext.ProjectCode,
  4092. ext.BatchCode,
  4093. ext.Version,
  4094. ext.Brand,
  4095. ext.cFree1,
  4096. ext.cFree2,
  4097. ext.cFree3,
  4098. ext.cFree4,
  4099. ext.cFree5,
  4100. ext.cFree6,
  4101. ext.cFree7,
  4102. ext.cFree8,
  4103. ext.cFree9,
  4104. ext.cFree10,
  4105. a.MUSER AS [User],
  4106. a.MTIME AS [MTime]
  4107. FROM ICSMOApplyNegDetail a
  4108. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4109. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  4110. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  4111. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4112. WHERE c.ID IN ({0})";
  4113. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  4114. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4115. #endregion
  4116. cmd.Transaction.Commit();
  4117. return data;
  4118. }
  4119. catch (Exception ex)
  4120. {
  4121. if (cmd.Transaction != null)
  4122. cmd.Transaction.Rollback();
  4123. log.Error(ex.Message);
  4124. throw new Exception(ex.Message);
  4125. }
  4126. finally
  4127. {
  4128. if (conn.State == ConnectionState.Open)
  4129. {
  4130. conn.Close();
  4131. }
  4132. conn.Dispose();
  4133. }
  4134. }
  4135. }
  4136. /// <summary>
  4137. /// 生产退料审核
  4138. /// </summary>
  4139. /// <param name="JsonData"></param>
  4140. /// <returns></returns>
  4141. public static DataTable MOIssueDocNegativeApplyApprove(List<ICSUser> JsonData)
  4142. {
  4143. var language = LanguageHelper.GetName("WMSAPIInfo");
  4144. if (JsonData.Count <= 0)
  4145. {
  4146. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4147. }
  4148. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4149. {
  4150. conn.Open();
  4151. SqlTransaction sqlTran = conn.BeginTransaction();
  4152. SqlCommand cmd = new SqlCommand();
  4153. cmd.Transaction = sqlTran;
  4154. cmd.Connection = conn;
  4155. try
  4156. {
  4157. string sql = string.Empty;
  4158. string ids = string.Empty;
  4159. foreach (var item in JsonData)
  4160. {
  4161. if (string.IsNullOrEmpty(item.ID))
  4162. {
  4163. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  4164. }
  4165. if (string.IsNullOrEmpty(item.User))
  4166. {
  4167. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  4168. }
  4169. if (item.MTime <= new DateTime(2000, 1, 1))
  4170. {
  4171. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  4172. }
  4173. //获取单号
  4174. sql = @"DECLARE @Status VARCHAR(10)
  4175. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{0}'
  4176. IF (@Status IS NULL)
  4177. BEGIN
  4178. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  4179. RETURN
  4180. END
  4181. ELSE IF (@Status!='1')
  4182. BEGIN
  4183. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  4184. RETURN
  4185. END
  4186. update ICSMOApplyNeg set Status='2',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  4187. sql = string.Format(sql, item.ID, item.User, item.MTime);
  4188. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4189. {
  4190. throw new Exception(language.GetNameByCode("WMSAPIInfo026"));//"生产退料申请单审核失败!");
  4191. }
  4192. ids += "'" + item.ID + "',";
  4193. }
  4194. if (string.IsNullOrWhiteSpace(ids))
  4195. {
  4196. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  4197. }
  4198. #region 查询返回数据
  4199. sql = @"SELECT a.ApplyNegCode,
  4200. c.WHCode,
  4201. c.Memo,
  4202. d.Name AS Status,
  4203. a.Sequence,
  4204. a.InvCode,
  4205. inv.InvName,
  4206. inv.InvStd,
  4207. a.Quantity,
  4208. inv.InvUnit,
  4209. a.Amount,
  4210. inv.AmountUnit,
  4211. a.IssueNegQuantity,
  4212. ext.ProjectCode,
  4213. ext.BatchCode,
  4214. ext.Version,
  4215. ext.Brand,
  4216. ext.cFree1,
  4217. ext.cFree2,
  4218. ext.cFree3,
  4219. ext.cFree4,
  4220. ext.cFree5,
  4221. ext.cFree6,
  4222. ext.cFree7,
  4223. ext.cFree8,
  4224. ext.cFree9,
  4225. ext.cFree10,
  4226. a.MUSER AS [User],
  4227. a.MTIME AS [MTime]
  4228. FROM ICSMOApplyNegDetail a
  4229. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4230. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  4231. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  4232. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4233. WHERE c.ID IN ({0})";
  4234. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  4235. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4236. #endregion
  4237. cmd.Transaction.Commit();
  4238. return data;
  4239. }
  4240. catch (Exception ex)
  4241. {
  4242. if (cmd.Transaction != null)
  4243. cmd.Transaction.Rollback();
  4244. log.Error(ex.Message);
  4245. throw new Exception(ex.Message);
  4246. }
  4247. finally
  4248. {
  4249. if (conn.State == ConnectionState.Open)
  4250. {
  4251. conn.Close();
  4252. }
  4253. conn.Dispose();
  4254. }
  4255. }
  4256. }
  4257. #endregion
  4258. #region 一步调拨(调拨申请单)
  4259. /// <summary>
  4260. /// 一步调拨(调拨申请单)
  4261. /// </summary>
  4262. /// <param name="JsonData"></param>
  4263. /// <returns></returns>
  4264. public static DataTable OneStepTransferApplicationIn(List<TransferApplication> JsonData)
  4265. {
  4266. var language = LanguageHelper.GetName("WMSAPIInfo");
  4267. if (JsonData.Count <= 0)
  4268. {
  4269. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4270. }
  4271. DataTable printTable = new DataTable();
  4272. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4273. {
  4274. conn.Open();
  4275. SqlTransaction sqlTran = conn.BeginTransaction();
  4276. SqlCommand cmd = new SqlCommand();
  4277. cmd.Transaction = sqlTran;
  4278. cmd.Connection = conn;
  4279. string BusinessCode = string.Empty;
  4280. try
  4281. {
  4282. string sql = string.Empty;
  4283. string Identification = Guid.NewGuid().ToString();
  4284. foreach (var item in JsonData)
  4285. {
  4286. if (string.IsNullOrEmpty(item.TransCode))
  4287. {
  4288. throw new Exception(language.GetNameByCode("WMSAPIInfo027"));//"调拨申请单号不能为空!");
  4289. }
  4290. string[] trans = item.TransCode.Split('~');
  4291. string MergeID = "";
  4292. if (trans.Length == 2)
  4293. {
  4294. MergeID = trans[0];
  4295. item.TransCode = trans[1];
  4296. }
  4297. //验证信息
  4298. sql = @"DECLARE @Status VARCHAR(10)
  4299. SELECT @Status=Status FROM ICSTransferApplication WHERE TransferNO='{0}' and WorkPoint='{1}' AND Type = '1'
  4300. IF (@Status IS NULL)
  4301. BEGIN
  4302. RAISERROR('" + language.GetNameByCode("WMSAPIInfo067") + @"',16,1);
  4303. RETURN
  4304. END
  4305. ELSE IF (@Status!='1')
  4306. BEGIN
  4307. RAISERROR('" + language.GetNameByCode("WMSAPIInfo068") + @"',16,1);
  4308. RETURN
  4309. END";
  4310. sql = string.Format(sql, item.TransCode, item.WorkPoint);
  4311. DBHelper.ExecuteNonQuery(sql, cmd);
  4312. foreach (var itemInfo in item.Detail)
  4313. {
  4314. //验证仓库库位信息
  4315. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  4316. BEGIN
  4317. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  4318. RETURN
  4319. END
  4320. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  4321. BEGIN
  4322. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  4323. RETURN
  4324. END
  4325. IF NOT EXISTS(SELECT a.ID
  4326. FROM ICSWareHouse a
  4327. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  4328. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  4329. BEGIN
  4330. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  4331. RETURN
  4332. END";
  4333. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  4334. DBHelper.ExecuteNonQuery(sql, cmd);
  4335. BusinessCode = TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>();
  4336. //更新源头单据信息
  4337. ICSWareHouseService.OneStepTransferApplicationIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity, cmd, language);
  4338. //更新条码信息
  4339. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  4340. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "14", TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>(), cmd, language, MergeID);
  4341. }
  4342. }
  4343. ICSWareHouseService.OneStepTransferDocInERP(TransTypeEnum.OneStepTransferDocIn.GetDescription(), Identification, cmd, language, BusinessCode);
  4344. if (!printTable.Equals("{}"))
  4345. {
  4346. cmd.Transaction.Commit();
  4347. return printTable;
  4348. }
  4349. else
  4350. {
  4351. DataTable table = GetData(Identification, 3, cmd);
  4352. cmd.Transaction.Commit();
  4353. return table;
  4354. }
  4355. }
  4356. catch (Exception ex)
  4357. {
  4358. if (cmd.Transaction != null)
  4359. cmd.Transaction.Rollback();
  4360. log.Error(ex.Message);
  4361. throw new Exception(ex.Message);
  4362. }
  4363. finally
  4364. {
  4365. if (conn.State == ConnectionState.Open)
  4366. {
  4367. conn.Close();
  4368. }
  4369. conn.Dispose();
  4370. }
  4371. }
  4372. }
  4373. #endregion
  4374. #region 一步调拨
  4375. /// <summary>
  4376. /// 一步调拨
  4377. /// </summary>
  4378. /// <param name="JsonData"></param>
  4379. /// <returns></returns>
  4380. public static DataTable OneStepTransferDocIn(List<TransferDoc> JsonData)
  4381. {
  4382. var language = LanguageHelper.GetName("WMSAPIInfo");
  4383. if (JsonData.Count <= 0)
  4384. {
  4385. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4386. }
  4387. DataTable printTable = new DataTable();
  4388. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4389. {
  4390. conn.Open();
  4391. SqlTransaction sqlTran = conn.BeginTransaction();
  4392. SqlCommand cmd = new SqlCommand();
  4393. cmd.Transaction = sqlTran;
  4394. cmd.Connection = conn;
  4395. string BusinessCode = string.Empty;
  4396. try
  4397. {
  4398. string sql = string.Empty;
  4399. string Identification = Guid.NewGuid().ToString();
  4400. foreach (var item in JsonData)
  4401. {
  4402. if (string.IsNullOrEmpty(item.TransCode))
  4403. {
  4404. throw new Exception(language.GetNameByCode("WMSAPIInfo027"));//"调拨单号不能为空!");
  4405. }
  4406. string[] trans = item.TransCode.Split('~');
  4407. string MergeID = "";
  4408. if (trans.Length == 2)
  4409. {
  4410. MergeID = trans[0];
  4411. item.TransCode = trans[1];
  4412. }
  4413. //验证信息
  4414. sql = @"DECLARE @Status VARCHAR(10)
  4415. SELECT @Status=Status FROM ICSTransfer WHERE TransferNO='{0}' and WorkPoint='{1}' AND Type = '1'
  4416. IF (@Status IS NULL)
  4417. BEGIN
  4418. RAISERROR('" + language.GetNameByCode("WMSAPIInfo067") + @"',16,1);
  4419. RETURN
  4420. END
  4421. ELSE IF (@Status!='1')
  4422. BEGIN
  4423. RAISERROR('" + language.GetNameByCode("WMSAPIInfo068") + @"',16,1);
  4424. RETURN
  4425. END";
  4426. sql = string.Format(sql, item.TransCode, item.WorkPoint);
  4427. DBHelper.ExecuteNonQuery(sql, cmd);
  4428. foreach (var itemInfo in item.Detail)
  4429. {
  4430. //验证仓库库位信息
  4431. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  4432. BEGIN
  4433. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  4434. RETURN
  4435. END
  4436. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  4437. BEGIN
  4438. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  4439. RETURN
  4440. END
  4441. IF NOT EXISTS(SELECT a.ID
  4442. FROM ICSWareHouse a
  4443. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  4444. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  4445. BEGIN
  4446. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  4447. RETURN
  4448. END";
  4449. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  4450. DBHelper.ExecuteNonQuery(sql, cmd);
  4451. BusinessCode = TransTypeEnum.OneStepTransferDocIn.GetDescription<DBValue>();
  4452. //更新源头单据信息
  4453. ICSWareHouseService.OneStepTransferDocIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity, cmd, language);
  4454. //更新条码信息
  4455. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  4456. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "6", TransTypeEnum.OneStepTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  4457. }
  4458. }
  4459. ICSWareHouseService.OneStepTransferDocInERP(TransTypeEnum.OneStepTransferDocIn.GetDescription(), Identification, cmd, language, BusinessCode);
  4460. if (!printTable.Equals("{}"))
  4461. {
  4462. cmd.Transaction.Commit();
  4463. return printTable;
  4464. }
  4465. else
  4466. {
  4467. DataTable table = GetData(Identification, 3, cmd);
  4468. cmd.Transaction.Commit();
  4469. return table;
  4470. }
  4471. }
  4472. catch (Exception ex)
  4473. {
  4474. if (cmd.Transaction != null)
  4475. cmd.Transaction.Rollback();
  4476. log.Error(ex.Message);
  4477. throw new Exception(ex.Message);
  4478. }
  4479. finally
  4480. {
  4481. if (conn.State == ConnectionState.Open)
  4482. {
  4483. conn.Close();
  4484. }
  4485. conn.Dispose();
  4486. }
  4487. }
  4488. }
  4489. #endregion
  4490. #region 调拨
  4491. /// <summary>
  4492. /// 调拨
  4493. /// </summary>
  4494. /// <param name="JsonData"></param>
  4495. /// <returns></returns>
  4496. public static DataTable TransferDocCreate(List<TransferDoc> JsonData)
  4497. {
  4498. var language = LanguageHelper.GetName("WMSAPIInfo");
  4499. if (JsonData.Count <= 0)
  4500. {
  4501. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4502. }
  4503. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4504. {
  4505. conn.Open();
  4506. SqlTransaction sqlTran = conn.BeginTransaction();
  4507. SqlCommand cmd = new SqlCommand();
  4508. cmd.Transaction = sqlTran;
  4509. cmd.Connection = conn;
  4510. string BusinessCode = string.Empty;
  4511. try
  4512. {
  4513. string sql = string.Empty;
  4514. string Identification = Guid.NewGuid().ToString();
  4515. foreach (var item in JsonData)
  4516. {
  4517. string MergeID = "";
  4518. foreach (var itemInfo in item.Detail)
  4519. {
  4520. //验证仓库库位信息
  4521. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  4522. BEGIN
  4523. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  4524. RETURN
  4525. END
  4526. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  4527. BEGIN
  4528. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  4529. RETURN
  4530. END
  4531. IF NOT EXISTS(SELECT a.ID
  4532. FROM ICSWareHouse a
  4533. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  4534. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  4535. BEGIN
  4536. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  4537. RETURN
  4538. END";
  4539. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  4540. DBHelper.ExecuteNonQuery(sql, cmd);
  4541. BusinessCode = TransTypeEnum.StepTransferDocIn.GetDescription<DBValue>();
  4542. //更新条码信息
  4543. ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  4544. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "6", TransTypeEnum.StepTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  4545. }
  4546. }
  4547. ICSWareHouseService.StepTransferDocInERP(TransTypeEnum.StepTransferDocIn.GetDescription(), Identification, cmd, language, BusinessCode);
  4548. DataTable table = GetData(Identification, 3, cmd);
  4549. cmd.Transaction.Commit();
  4550. return table;
  4551. }
  4552. catch (Exception ex)
  4553. {
  4554. if (cmd.Transaction != null)
  4555. cmd.Transaction.Rollback();
  4556. log.Error(ex.Message);
  4557. throw new Exception(ex.Message);
  4558. }
  4559. finally
  4560. {
  4561. if (conn.State == ConnectionState.Open)
  4562. {
  4563. conn.Close();
  4564. }
  4565. conn.Dispose();
  4566. }
  4567. }
  4568. }
  4569. #endregion
  4570. #region 调拨申请单
  4571. /// <summary>
  4572. /// 调拨
  4573. /// </summary>
  4574. /// <param name="JsonData"></param>
  4575. /// <returns></returns>
  4576. public static DataTable TransferApplicationCreate(List<TransferApplication> JsonData)
  4577. {
  4578. var language = LanguageHelper.GetName("WMSAPIInfo");
  4579. if (JsonData.Count <= 0)
  4580. {
  4581. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4582. }
  4583. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4584. {
  4585. conn.Open();
  4586. SqlTransaction sqlTran = conn.BeginTransaction();
  4587. SqlCommand cmd = new SqlCommand();
  4588. cmd.Transaction = sqlTran;
  4589. cmd.Connection = conn;
  4590. string BusinessCode = string.Empty;
  4591. try
  4592. {
  4593. string sql = string.Empty;
  4594. string Identification = Guid.NewGuid().ToString();
  4595. foreach (var item in JsonData)
  4596. {
  4597. string MergeID = "";
  4598. foreach (var itemInfo in item.Detail)
  4599. {
  4600. //验证仓库库位信息
  4601. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  4602. BEGIN
  4603. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  4604. RETURN
  4605. END
  4606. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  4607. BEGIN
  4608. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  4609. RETURN
  4610. END
  4611. IF NOT EXISTS(SELECT a.ID
  4612. FROM ICSWareHouse a
  4613. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  4614. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  4615. BEGIN
  4616. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  4617. RETURN
  4618. END";
  4619. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  4620. DBHelper.ExecuteNonQuery(sql, cmd);
  4621. BusinessCode = TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>();
  4622. //更新条码信息
  4623. ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  4624. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "14", TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>(), cmd, language, MergeID);
  4625. }
  4626. }
  4627. ICSWareHouseService.StepTransferDocInERP(TransTypeEnum.StepTransferApplicationIn.GetDescription(), Identification, cmd, language, BusinessCode);
  4628. DataTable table = GetData(Identification, 3, cmd);
  4629. cmd.Transaction.Commit();
  4630. return table;
  4631. }
  4632. catch (Exception ex)
  4633. {
  4634. if (cmd.Transaction != null)
  4635. cmd.Transaction.Rollback();
  4636. log.Error(ex.Message);
  4637. throw new Exception(ex.Message);
  4638. }
  4639. finally
  4640. {
  4641. if (conn.State == ConnectionState.Open)
  4642. {
  4643. conn.Close();
  4644. }
  4645. conn.Dispose();
  4646. }
  4647. }
  4648. }
  4649. #endregion
  4650. #region 调拨申请单
  4651. /// <summary>
  4652. /// 调拨申请单
  4653. /// </summary>
  4654. /// <param name="JsonData"></param>
  4655. /// <returns></returns>
  4656. public static DataTable TransferApplicationInCreate(List<TransferApplication> JsonData)
  4657. {
  4658. var language = LanguageHelper.GetName("WMSAPIInfo");
  4659. if (JsonData.Count <= 0)
  4660. {
  4661. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4662. }
  4663. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4664. {
  4665. conn.Open();
  4666. SqlTransaction sqlTran = conn.BeginTransaction();
  4667. SqlCommand cmd = new SqlCommand();
  4668. cmd.Transaction = sqlTran;
  4669. cmd.Connection = conn;
  4670. string BusinessCode = string.Empty;
  4671. try
  4672. {
  4673. string sql = string.Empty;
  4674. string Identification = Guid.NewGuid().ToString();
  4675. foreach (var item in JsonData)
  4676. {
  4677. string MergeID = "";
  4678. foreach (var itemInfo in item.Detail)
  4679. {
  4680. //验证仓库库位信息
  4681. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  4682. BEGIN
  4683. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  4684. RETURN
  4685. END
  4686. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  4687. BEGIN
  4688. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  4689. RETURN
  4690. END
  4691. IF NOT EXISTS(SELECT a.ID
  4692. FROM ICSWareHouse a
  4693. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  4694. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  4695. BEGIN
  4696. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  4697. RETURN
  4698. END
  4699. IF EXISTS(SELECT ID
  4700. FROM ICSWareHouseLotInfo
  4701. WHERE WarehouseCode='{0}' AND WorkPoint='{1}' AND LotNo='{3}')
  4702. BEGIN
  4703. RAISERROR('" + language.GetNameByCode("WMSAPIInfo355") + @"',16,1);
  4704. RETURN
  4705. END";
  4706. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode, itemInfo.LotNo);
  4707. DBHelper.ExecuteNonQuery(sql, cmd);
  4708. BusinessCode = TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>();
  4709. //更新源头单据信息
  4710. ICSWareHouseService.OneStepTransferApplicationIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity, cmd, language);
  4711. //更新条码信息
  4712. ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  4713. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "14", TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>(), cmd, language, MergeID);
  4714. }
  4715. }
  4716. ICSWareHouseService.StepTransferApplicationERP(TransTypeEnum.StepTransferApplicationIn.GetDescription(), Identification, cmd, language, BusinessCode);
  4717. DataTable table = GetData(Identification, 3, cmd);
  4718. cmd.Transaction.Commit();
  4719. return table;
  4720. }
  4721. catch (Exception ex)
  4722. {
  4723. if (cmd.Transaction != null)
  4724. cmd.Transaction.Rollback();
  4725. log.Error(ex.Message);
  4726. throw new Exception(ex.Message);
  4727. }
  4728. finally
  4729. {
  4730. if (conn.State == ConnectionState.Open)
  4731. {
  4732. conn.Close();
  4733. }
  4734. conn.Dispose();
  4735. }
  4736. }
  4737. }
  4738. #endregion
  4739. #region 移库
  4740. /// <summary>
  4741. /// 移库
  4742. /// </summary>
  4743. /// <param name="JsonData"></param>
  4744. /// <returns></returns>
  4745. public static DataTable LibraryUpdate(List<ICSLibraryModel> JsonData)
  4746. {
  4747. var language = LanguageHelper.GetName("WMSAPIInfo");
  4748. if (JsonData.Count <= 0)
  4749. {
  4750. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4751. }
  4752. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4753. {
  4754. conn.Open();
  4755. SqlTransaction sqlTran = conn.BeginTransaction();
  4756. SqlCommand cmd = new SqlCommand();
  4757. cmd.Transaction = sqlTran;
  4758. cmd.Connection = conn;
  4759. try
  4760. {
  4761. string sql = string.Empty;
  4762. string Identification = Guid.NewGuid().ToString();
  4763. foreach (var item in JsonData)
  4764. {
  4765. if (string.IsNullOrEmpty(item.LotNo))
  4766. {
  4767. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  4768. }
  4769. //验证仓库库位信息
  4770. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  4771. BEGIN
  4772. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  4773. RETURN
  4774. END
  4775. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  4776. BEGIN
  4777. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo072"), "{2}") + @"',16,1);
  4778. RETURN
  4779. END
  4780. IF NOT EXISTS(SELECT a.ID
  4781. FROM ICSWareHouse a
  4782. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  4783. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  4784. BEGIN
  4785. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  4786. RETURN
  4787. END";
  4788. sql = string.Format(sql, item.WarehouseCode, item.WorkPoint, item.LocationCode);
  4789. DBHelper.ExecuteNonQuery(sql, cmd);
  4790. //更新条码信息
  4791. ICSWareHouseLotInfoService.WareHouseLotInfoLibrary(Identification, item.TransCode, item.TransSequence, item.WarehouseCode, item.LocationCode, item.LotNo,
  4792. item.User, item.WorkPoint, "7", "29", cmd, language);
  4793. }
  4794. DataTable table = GetData(Identification, 3, cmd);
  4795. cmd.Transaction.Commit();
  4796. return table;
  4797. }
  4798. catch (Exception ex)
  4799. {
  4800. if (cmd.Transaction != null)
  4801. cmd.Transaction.Rollback();
  4802. log.Error(ex.Message);
  4803. throw new Exception(ex.Message);
  4804. }
  4805. finally
  4806. {
  4807. if (conn.State == ConnectionState.Open)
  4808. {
  4809. conn.Close();
  4810. }
  4811. conn.Dispose();
  4812. }
  4813. }
  4814. }
  4815. #endregion
  4816. #region 合并
  4817. /// <summary>
  4818. /// 合并
  4819. /// </summary>
  4820. /// <param name="JsonData"></param>
  4821. /// <returns></returns>
  4822. public static DataTable LOTMergeCreate(List<LOTCreateIModel> JsonData)
  4823. {
  4824. var language = LanguageHelper.GetName("WMSAPIInfo");
  4825. if (JsonData.Count <= 0)
  4826. {
  4827. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4828. }
  4829. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4830. {
  4831. conn.Open();
  4832. SqlTransaction sqlTran = conn.BeginTransaction();
  4833. SqlCommand cmd = new SqlCommand();
  4834. cmd.Transaction = sqlTran;
  4835. cmd.Connection = conn;
  4836. try
  4837. {
  4838. string Identification = Guid.NewGuid().ToString();
  4839. foreach (var item in JsonData)
  4840. {
  4841. if (string.IsNullOrEmpty(item.LotNo))
  4842. {
  4843. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  4844. }
  4845. else if (item.detail.Count <= 0)
  4846. {
  4847. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  4848. }
  4849. //合并前日志
  4850. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "5",
  4851. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(), cmd, language);
  4852. foreach (var info in item.detail)
  4853. {
  4854. //合并前日志
  4855. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, info.CurrentLotNo, item.User, item.WorkPoint, "5",
  4856. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(), cmd, language);
  4857. //更新条码信息
  4858. ICSWareHouseLotInfoService.WareHouseLotInfoMerge(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "5",
  4859. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  4860. }
  4861. //合并后日志
  4862. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "5",
  4863. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  4864. }
  4865. DataTable table = GetData(Identification, 1, cmd);
  4866. cmd.Transaction.Commit();
  4867. return table;
  4868. }
  4869. catch (Exception ex)
  4870. {
  4871. if (cmd.Transaction != null)
  4872. cmd.Transaction.Rollback();
  4873. log.Error(ex.Message);
  4874. throw new Exception(ex.Message);
  4875. }
  4876. finally
  4877. {
  4878. if (conn.State == ConnectionState.Open)
  4879. {
  4880. conn.Close();
  4881. }
  4882. conn.Dispose();
  4883. }
  4884. }
  4885. }
  4886. #endregion
  4887. #region 拆分
  4888. /// <summary>
  4889. /// 拆分
  4890. /// </summary>
  4891. /// <param name="JsonData"></param>
  4892. /// <returns></returns>
  4893. public static DataTable LOTSplitCreate(List<LOTCreateIModel> JsonData)
  4894. {
  4895. var language = LanguageHelper.GetName("WMSAPIInfo");
  4896. if (JsonData.Count <= 0)
  4897. {
  4898. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4899. }
  4900. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4901. {
  4902. conn.Open();
  4903. SqlTransaction sqlTran = conn.BeginTransaction();
  4904. SqlCommand cmd = new SqlCommand();
  4905. cmd.Transaction = sqlTran;
  4906. cmd.Connection = conn;
  4907. try
  4908. {
  4909. string Identification = Guid.NewGuid().ToString();
  4910. foreach (var item in JsonData)
  4911. {
  4912. if (string.IsNullOrEmpty(item.LotNo))
  4913. {
  4914. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  4915. }
  4916. else if (item.detail.Count <= 0)
  4917. {
  4918. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  4919. }
  4920. //拆分前日志
  4921. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  4922. TransTypeEnum.LOTSplitBefore.GetDescription<DBValue>(), cmd, language);
  4923. foreach (var info in item.detail)
  4924. {
  4925. //更新条码信息
  4926. ICSWareHouseLotInfoService.WareHouseLotInfoSplit(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "4",
  4927. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), cmd, language);
  4928. }
  4929. //拆分后日志
  4930. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  4931. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), cmd, language);
  4932. }
  4933. DataTable table = GetData(Identification, 1, cmd);
  4934. cmd.Transaction.Commit();
  4935. return table;
  4936. }
  4937. catch (Exception ex)
  4938. {
  4939. if (cmd.Transaction != null)
  4940. cmd.Transaction.Rollback();
  4941. log.Error(ex.Message);
  4942. throw new Exception(ex.Message);
  4943. }
  4944. finally
  4945. {
  4946. if (conn.State == ConnectionState.Open)
  4947. {
  4948. conn.Close();
  4949. }
  4950. conn.Dispose();
  4951. }
  4952. }
  4953. }
  4954. #endregion
  4955. /// <summary>
  4956. /// 获取出入库记录信息
  4957. /// </summary>
  4958. /// <param name="Identification"></param>
  4959. /// <param name="type">1:入库,2:出库,3:调拨</param>
  4960. /// <param name="cmd"></param>
  4961. /// <returns></returns>
  4962. private static DataTable GetData(string Identification, int type, SqlCommand cmd)
  4963. {
  4964. #region SLQ
  4965. string sql = @"SELECT log.ID,
  4966. log.TransCode,
  4967. log.TransSequence,
  4968. log.LotNo,
  4969. log.InvCode,
  4970. inv.InvName,
  4971. inv.InvStd,
  4972. log.Quantity,
  4973. inv.InvUnit,
  4974. log.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  4975. inv.AmountUnit,
  4976. {1}
  4977. ext.ProjectCode,
  4978. 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,
  4979. ext.Version,
  4980. ext.Brand,
  4981. ext.cFree1,
  4982. ext.cFree2,
  4983. ext.cFree3,
  4984. ext.cFree4,
  4985. ext.cFree5,
  4986. ext.cFree6,
  4987. ext.cFree7,
  4988. ext.cFree8,
  4989. ext.cFree9,
  4990. ext.cFree10,
  4991. type.Name AS TransType,
  4992. log.MUSER AS [User],
  4993. log.MTIME AS [MTime]
  4994. FROM ICSWareHouseLotInfoLog log
  4995. LEFT JOIN ICSType type ON type.TableCode='ICSWareHouseLotInfoLog' AND type.ColumnCode='BusinessCode' AND log.BusinessCode=type.Code AND log.WorkPoint=type.WorkPoint
  4996. INNER JOIN ICSInventoryLot lot ON log.LotNo=lot.LotNo AND log.WorkPoint=lot.WorkPoint
  4997. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4998. INNER JOIN ICSInventory inv ON log.InvCode=inv.InvCode AND log.WorkPoint=inv.WorkPoint
  4999. {2}
  5000. LEFT JOIN ICSInventoryBatchEnable invBat ON log.InvCode=invBat.InvCode AND log.FromWarehouseCode=invBat.WHCode AND log.WorkPoint=invBat.WorkPoint
  5001. WHERE log.Identification='{0}'";
  5002. #endregion
  5003. string columns = @"log.ToWarehouseCode AS WHCode,
  5004. log.ToLocationCode AS LocationCode,
  5005. wh.WarehouseName AS WHName,
  5006. loc.LocationName AS LocationName,";
  5007. string tables = @"INNER JOIN ICSWarehouse wh ON log.ToWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  5008. INNER JOIN ICSLocation loc ON log.ToLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint";
  5009. if (type == 2)//出库
  5010. {
  5011. columns = @"log.FromWarehouseCode AS WHCode,
  5012. log.FromLocationCode AS LocationCode,
  5013. wh.WarehouseName AS WHName,
  5014. loc.LocationName AS LocationName,";
  5015. tables = @"INNER JOIN ICSWarehouse wh ON log.FromWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  5016. INNER JOIN ICSLocation loc ON log.FromLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint";
  5017. }
  5018. else if (type == 3)//调拨
  5019. {
  5020. columns = @"log.FromWarehouseCode AS FromWHCode,
  5021. log.FromLocationCode,
  5022. wh.WarehouseName AS FromWHName,
  5023. loc.LocationName AS FromLocationName,
  5024. log.ToWarehouseCode AS ToWHCode,
  5025. log.ToLocationCode,
  5026. whto.WarehouseName AS ToWHName,
  5027. locto.LocationName AS ToLocationName,";
  5028. tables = @"INNER JOIN ICSWarehouse wh ON log.FromWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  5029. INNER JOIN ICSLocation loc ON log.FromLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint
  5030. INNER JOIN ICSWarehouse whto ON log.ToWarehouseCode=whto.WarehouseCode AND log.WorkPoint=whto.WorkPoint
  5031. INNER JOIN ICSLocation locto ON log.ToLocationCode=locto.LocationCode AND log.WorkPoint=locto.WorkPoint";
  5032. }
  5033. sql = string.Format(sql, Identification, columns, tables);
  5034. return DBHelper.SQlReturnData(sql, cmd);
  5035. }
  5036. /// <summary>
  5037. /// 先进先出批次管控
  5038. /// </summary>
  5039. /// <param name="LotNo"></param>
  5040. /// <param name="WorkPoitCode"></param>
  5041. /// <param name="cmd"></param>
  5042. /// <returns></returns>
  5043. public static string CanOut(string LotNo, string WorkPoitCode, string ScanLotCode, SqlCommand cmd, Dictionary<string, string> language)
  5044. {
  5045. try
  5046. {
  5047. //根据Sys_SRM_Items.F_Description备注列维护的提前天数,比如维护的是1,最早条码是2022.5.16,现在扫描2022.5.17的条码也能出库,扫描2022.5.18的条码不能直接出,需要校验以下逻辑
  5048. string sql = @"DECLARE @CountNO INT,@Days INT
  5049. SELECT @Days=F_Description FROM Sys_SRM_Items WHERE F_EnCode='FIFO'
  5050. SET @CountNO=(
  5051. SELECT COUNT(a.LotNO) FROM ICSWareHouseLotInfo a
  5052. INNER JOIN ICSInventoryLot b ON a.LotNO=b.LotNO AND a.WorkPoint=b.WorkPoint
  5053. WHERE a.WorkPoint='{1}' AND ISNULL(a.Quantity,0)>0 AND 1=1
  5054. AND CONVERT(varchar(100), a.InDate, 23)<
  5055. (SELECT DATEADD(DAY, -@Days, CONVERT(varchar(100), x.InDate, 23)) FROM ICSWareHouseLotInfo x
  5056. INNER JOIN ICSInventoryLot y ON x.LotNO=y.LotNO AND x.WorkPoint=y.WorkPoint
  5057. WHERE x.LotNO='{0}' AND x.WorkPoint='{1}' AND y.INVCode=b.INVCode AND y.ExtensionID=b.ExtensionID)
  5058. )
  5059. IF @CountNO>0
  5060. BEGIN
  5061. SELECT TOP 1 CASE a.F_ItemCode WHEN 'FIFO01' THEN '1' WHEN 'FIFO02' THEN '2' ELSE '3' END AS Type
  5062. FROM Sys_SRM_ItemsDetail a
  5063. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  5064. WHERE b.F_EnCode='FIFO' AND a.F_EnabledMark='1'
  5065. ORDER BY a.F_SortCode DESC
  5066. END
  5067. ELSE
  5068. BEGIN
  5069. SELECT @CountNO
  5070. END";
  5071. //0 - 已经是最早的批次
  5072. //1 - 不管控
  5073. //2 - 提醒
  5074. //3 - 限制
  5075. sql = string.Format(sql, LotNo, WorkPoitCode);
  5076. if (!string.IsNullOrWhiteSpace(ScanLotCode))
  5077. {
  5078. sql = sql.Replace("1=1", "a.LotNO NOT IN (" + ScanLotCode + ")");
  5079. }
  5080. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  5081. if (string.IsNullOrWhiteSpace(res))
  5082. {
  5083. throw new Exception(language.GetNameByCode("WMSAPIInfo183"));//"查询管控信息失败!");
  5084. }
  5085. else
  5086. return res;
  5087. }
  5088. catch (Exception ex)
  5089. {
  5090. throw new Exception(ex.Message);
  5091. }
  5092. }
  5093. /// <summary>
  5094. /// 保质期管控
  5095. /// </summary>
  5096. /// <param name="LotNo"></param>
  5097. /// <param name="WorkPoitCode"></param>
  5098. /// <param name="cmd"></param>
  5099. /// <returns></returns>
  5100. public static string Effective(string LotNo, string WorkPoitCode, SqlCommand cmd, Dictionary<string, string> language)
  5101. {
  5102. try
  5103. {
  5104. string sql = @"DECLARE @CountNO INT,@Days INT,@CurrentDays INT
  5105. SELECT @CountNO=EffectiveEnable,@Days=EffectiveDays,@CurrentDays=DATEDIFF(DAY, GETDATE(), b.ExpirationDate) FROM ICSInventory a
  5106. INNER JOIN ICSInventoryLot b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  5107. INNER JOIN ICSWareHouseLotInfo c ON b.LotNO=c.LotNO AND b.WorkPoint=c.WorkPoint
  5108. WHERE b.LotNO='{0}' AND b.WorkPoint='{1}'
  5109. IF @CountNO='1' AND @CurrentDays<0
  5110. BEGIN
  5111. SELECT TOP 1 CASE a.F_ItemCode WHEN 'Effective01' THEN '1' WHEN 'Effective02' THEN '2' ELSE '3' END AS Type
  5112. FROM Sys_SRM_ItemsDetail a
  5113. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  5114. WHERE b.F_EnCode='Effective' AND a.F_EnabledMark='1'
  5115. ORDER BY a.F_SortCode DESC
  5116. END
  5117. ELSE
  5118. BEGIN
  5119. SELECT @CountNO
  5120. END";
  5121. //0 - 已经是最早的批次
  5122. //1 - 不管控
  5123. //2 - 提醒
  5124. //3 - 限制
  5125. sql = string.Format(sql, LotNo, WorkPoitCode);
  5126. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  5127. if (string.IsNullOrWhiteSpace(res))
  5128. {
  5129. throw new Exception(language.GetNameByCode("WMSAPIInfo183"));//"查询管控信息失败!");
  5130. }
  5131. else
  5132. return res;
  5133. }
  5134. catch (Exception ex)
  5135. {
  5136. throw new Exception(ex.Message);
  5137. }
  5138. }
  5139. #region 包装
  5140. /// <summary>
  5141. /// 查询包装信息
  5142. /// </summary>
  5143. /// <param name="JsonData"></param>
  5144. /// <returns></returns>
  5145. public static object ContainerGet(ICSContainer JsonData)
  5146. {
  5147. var language = LanguageHelper.GetName("WMSAPIInfo");
  5148. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5149. {
  5150. conn.Open();
  5151. SqlTransaction sqlTran = conn.BeginTransaction();
  5152. SqlCommand cmd = new SqlCommand();
  5153. cmd.Transaction = sqlTran;
  5154. cmd.Connection = conn;
  5155. try
  5156. {
  5157. string sql = string.Empty;
  5158. //目标包装
  5159. if (JsonData.ToContainerCode != null)
  5160. {
  5161. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  5162. BEGIN
  5163. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  5164. RETURN
  5165. END
  5166. SELECT ContainerCode,ContainerName FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}'";
  5167. sql = string.Format(sql, JsonData.ToContainerCode, JsonData.WorkPoint);
  5168. }
  5169. ///原包装
  5170. else if (JsonData.FromContainerCode != null)
  5171. {
  5172. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  5173. BEGIN
  5174. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  5175. RETURN
  5176. END
  5177. IF NOT EXISTS(SELECT a.ID FROM ICSContainer a
  5178. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  5179. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}')
  5180. BEGIN
  5181. RAISERROR('" + language.GetNameByCode("WMSAPIInfo073") + @"',16,1);
  5182. RETURN
  5183. END
  5184. SELECT ContainerCode,ContainerName FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}'";
  5185. sql = string.Format(sql, JsonData.FromContainerCode, JsonData.WorkPoint);
  5186. }
  5187. else
  5188. {
  5189. throw new Exception(language.GetNameByCode("WMSAPIInfo029"));//"请传入包装条码!");
  5190. }
  5191. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  5192. cmd.Transaction.Commit();
  5193. return table;
  5194. }
  5195. catch (Exception ex)
  5196. {
  5197. if (cmd.Transaction != null)
  5198. cmd.Transaction.Rollback();
  5199. log.Error(ex.Message);
  5200. throw new Exception(ex.Message);
  5201. }
  5202. finally
  5203. {
  5204. if (conn.State == ConnectionState.Open)
  5205. {
  5206. conn.Close();
  5207. }
  5208. conn.Dispose();
  5209. }
  5210. }
  5211. }
  5212. /// <summary>
  5213. /// 修改包装信息
  5214. /// </summary>
  5215. /// <param name="JsonData"></param>
  5216. /// <returns></returns>
  5217. public static DataTable ContainerUpdate(List<ICSContainer> JsonData)
  5218. {
  5219. var language = LanguageHelper.GetName("WMSAPIInfo");
  5220. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5221. {
  5222. conn.Open();
  5223. SqlTransaction sqlTran = conn.BeginTransaction();
  5224. SqlCommand cmd = new SqlCommand();
  5225. cmd.Transaction = sqlTran;
  5226. cmd.Connection = conn;
  5227. try
  5228. {
  5229. string sql = string.Empty;
  5230. string codes = string.Empty;
  5231. foreach (ICSContainer container in JsonData)
  5232. {
  5233. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  5234. BEGIN
  5235. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  5236. RETURN
  5237. END
  5238. IF NOT EXISTS(SELECT a.ID FROM ICSContainer a
  5239. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  5240. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}')
  5241. BEGIN
  5242. RAISERROR('" + language.GetNameByCode("WMSAPIInfo073") + @"',16,1);
  5243. RETURN
  5244. END
  5245. IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{2}' and WorkPoint='{1}')
  5246. BEGIN
  5247. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo072"), "{2}") + @"',16,1);
  5248. RETURN
  5249. END
  5250. UPDATE b SET ContainerID=c.ID
  5251. FROM ICSContainer a
  5252. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  5253. INNER JOIN ICSContainer c ON c.ContainerCODE ='{2}' and a.WorkPoint=c.WorkPoint
  5254. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}'";
  5255. sql = string.Format(sql, container.FromContainerCode, container.WorkPoint, container.ToContainerCode);
  5256. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5257. {
  5258. throw new Exception(language.GetNameByCode("WMSAPIInfo030"));//"包装更新失败!");
  5259. }
  5260. codes += "'" + container.ToContainerCode + container.WorkPoint + "',";
  5261. }
  5262. sql = @"SELECT a.ContainerCode, a.ContainerName,b.LotNo FROM ICSContainer a
  5263. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  5264. WHERE a.ContainerCODE+a.WorkPoint IN({0})";
  5265. sql = string.Format(sql, codes.Substring(0,codes.Length - 1));
  5266. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  5267. cmd.Transaction.Commit();
  5268. return table;
  5269. }
  5270. catch (Exception ex)
  5271. {
  5272. if (cmd.Transaction != null)
  5273. cmd.Transaction.Rollback();
  5274. log.Error(ex.Message);
  5275. throw new Exception(ex.Message);
  5276. }
  5277. finally
  5278. {
  5279. if (conn.State == ConnectionState.Open)
  5280. {
  5281. conn.Close();
  5282. }
  5283. conn.Dispose();
  5284. }
  5285. }
  5286. }
  5287. #endregion
  5288. #region 盘点
  5289. /// <summary>
  5290. /// 创建盘点单
  5291. /// </summary>
  5292. /// <param name="JsonData"></param>
  5293. /// <returns></returns>
  5294. public static DataTable CheckCreate(List<ICSCheck> JsonData)
  5295. {
  5296. var language = LanguageHelper.GetName("WMSAPIInfo");
  5297. if (JsonData.Count <= 0)
  5298. {
  5299. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5300. }
  5301. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5302. {
  5303. conn.Open();
  5304. SqlTransaction sqlTran = conn.BeginTransaction();
  5305. SqlCommand cmd = new SqlCommand();
  5306. cmd.Transaction = sqlTran;
  5307. cmd.Connection = conn;
  5308. try
  5309. {
  5310. string Code = string.Empty;
  5311. string sql = string.Empty;
  5312. foreach (var item in JsonData)
  5313. {
  5314. if (string.IsNullOrEmpty(item.User))
  5315. {
  5316. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"操作人不能为空!");
  5317. }
  5318. if (string.IsNullOrEmpty(item.WorkPoint))
  5319. {
  5320. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  5321. }
  5322. //获取单号
  5323. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
  5324. BEGIN
  5325. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  5326. RETURN
  5327. END
  5328. DECLARE @MaxNO INT,@date varchar(20)='CHK'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  5329. SELECT @MaxNO=SUBSTRING(MAX(CheckCode),LEN(@date)+1,LEN(MAX(CheckCode))-LEN(@date))+1 FROM ICSCheck
  5330. WHERE SUBSTRING(CheckCode, 1, LEN(@date))=@date
  5331. IF @MaxNO IS NULL
  5332. BEGIN
  5333. SELECT @date+'00001' AS Code
  5334. END
  5335. ELSE
  5336. BEGIN
  5337. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  5338. END ";
  5339. sql = string.Format(sql, item.User, item.WorkPoint);
  5340. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  5341. //创建盘点单
  5342. foreach (var itemInfo in item.detail)
  5343. {
  5344. int len = itemInfo.SelectLevel.Length;
  5345. sql = @"IF NOT EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE SUBSTRING(LocationCode,1,{4}) = '{1}')
  5346. BEGIN
  5347. RAISERROR('" + language.GetNameByCode("WMSAPIInfo460") + @"',16,1);
  5348. RETURN
  5349. END
  5350. INSERT INTO ICSCheck (ID,CheckCode,SelectLevel,Status,Quantity,Amount,MUSER,MUSERName,MTIME,WorkPoint)
  5351. SELECT NEWID(),'{0}','{1}','2',SUM(a.Quantity),0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location
  5352. FROM ICSWareHouseLotInfo a
  5353. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  5354. WHERE SUBSTRING(a.LocationCode,1,{4}) = '{1}'
  5355. GROUP BY b.F_Account,b.F_RealName,b.F_Location";
  5356. sql = string.Format(sql, Code, itemInfo.SelectLevel, item.User, item.WorkPoint, len);
  5357. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5358. {
  5359. throw new Exception(language.GetNameByCode("WMSAPIInfo031"));//"盘点单创建失败!");
  5360. }
  5361. }
  5362. }
  5363. if (string.IsNullOrWhiteSpace(Code))
  5364. {
  5365. throw new Exception(language.GetNameByCode("WMSAPIInfo032"));//"盘点单单号不能为空!");
  5366. }
  5367. #region 查询返回数据
  5368. sql = @"SELECT a.ID,a.CheckCode,a.SelectLevel,
  5369. a.Quantity,
  5370. a.Amount,
  5371. a.MUSER AS [User],
  5372. a.MTIME AS [MTime]
  5373. FROM ICSCheck a
  5374. WHERE a.CheckCode='{0}'";
  5375. sql = string.Format(sql, Code);
  5376. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  5377. #endregion
  5378. cmd.Transaction.Commit();
  5379. return data;
  5380. }
  5381. catch (Exception ex)
  5382. {
  5383. if (cmd.Transaction != null)
  5384. cmd.Transaction.Rollback();
  5385. log.Error(ex.Message);
  5386. throw new Exception(ex.Message);
  5387. }
  5388. finally
  5389. {
  5390. if (conn.State == ConnectionState.Open)
  5391. {
  5392. conn.Close();
  5393. }
  5394. conn.Dispose();
  5395. }
  5396. }
  5397. }
  5398. /// <summary>
  5399. /// 盘点扫描
  5400. /// </summary>
  5401. /// <param name="JsonData"></param>
  5402. /// <returns></returns>
  5403. public static DataTable LOTCheckCreate(List<ICSCheck> JsonData)
  5404. {
  5405. var language = LanguageHelper.GetName("WMSAPIInfo");
  5406. if (JsonData.Count <= 0)
  5407. {
  5408. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5409. }
  5410. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5411. {
  5412. conn.Open();
  5413. SqlTransaction sqlTran = conn.BeginTransaction();
  5414. SqlCommand cmd = new SqlCommand();
  5415. cmd.Transaction = sqlTran;
  5416. cmd.Connection = conn;
  5417. try
  5418. {
  5419. string lots = string.Empty;
  5420. string sql = string.Empty;
  5421. int result = 0;
  5422. string Identification = Guid.NewGuid().ToString();
  5423. foreach (var item in JsonData)
  5424. {
  5425. if (string.IsNullOrEmpty(item.User))
  5426. {
  5427. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"操作人不能为空!");
  5428. }
  5429. if (string.IsNullOrEmpty(item.WorkPoint))
  5430. {
  5431. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  5432. }
  5433. if (string.IsNullOrEmpty(item.CheckCode))
  5434. {
  5435. throw new Exception(language.GetNameByCode("WMSAPIInfo032"));//"盘点单号不能为空!");
  5436. }
  5437. //校验
  5438. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
  5439. BEGIN
  5440. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  5441. RETURN
  5442. END
  5443. IF NOT EXISTS(SELECT ID FROM ICSCheck WHERE CheckCode='{2}' AND WorkPoint='{1}')
  5444. BEGIN
  5445. RAISERROR('" + language.GetNameByCode("WMSAPIInfo075") + @"',16,1);
  5446. RETURN
  5447. END";
  5448. sql = string.Format(sql, item.User, item.WorkPoint, item.CheckCode);
  5449. DBHelper.ExecuteNonQuery(sql, cmd);
  5450. //创建盘点单
  5451. foreach (var itemInfo in item.detail)
  5452. {
  5453. sql = @"IF NOT EXISTS(SELECT LotNo FROM ICSWareHouseLotInfo WHERE LotNo='{1}' AND WorkPoint='{3}')
  5454. BEGIN
  5455. RAISERROR('" + language.GetNameByCode("WMSAPIInfo076") + @"',16,1);
  5456. RETURN
  5457. END
  5458. IF EXISTS(SELECT LotNo FROM ICSCheckDetail a
  5459. LEFT JOIN ICSCheck b ON a.CheckID=b.ID AND a.WorkPoint=b.WorkPoint
  5460. WHERE b.CheckCode='{0}' AND a.LotNo='{1}' AND a.WorkPoint='{3}')
  5461. BEGIN
  5462. IF ('{5}'='')
  5463. BEGIN
  5464. UPDATE a SET PrimaryQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE()
  5465. FROM ICSCheckDetail a
  5466. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  5467. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  5468. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  5469. END
  5470. ELSE IF ('{5}'='')
  5471. BEGIN
  5472. UPDATE a SET CheckQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE()
  5473. FROM ICSCheckDetail a
  5474. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  5475. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  5476. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  5477. END
  5478. ELSE
  5479. BEGIN
  5480. UPDATE a SET ReplayQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE()
  5481. FROM ICSCheckDetail a
  5482. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  5483. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  5484. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  5485. END
  5486. END
  5487. ELSE
  5488. BEGIN
  5489. IF ('{5}'='')
  5490. BEGIN
  5491. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint)
  5492. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','{4}','0','0','0','0','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  5493. FROM ICSWareHouseLotInfo a
  5494. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  5495. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  5496. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  5497. END
  5498. ELSE IF ('{5}'='')
  5499. BEGIN
  5500. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint)
  5501. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','0','0','0','0','{4}','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  5502. FROM ICSWareHouseLotInfo a
  5503. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  5504. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  5505. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  5506. END
  5507. ELSE
  5508. BEGIN
  5509. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint)
  5510. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','0','0','{4}','0','0','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  5511. FROM ICSWareHouseLotInfo a
  5512. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  5513. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  5514. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  5515. END
  5516. END";
  5517. sql = string.Format(sql, item.CheckCode, itemInfo.LotNo, item.User, item.WorkPoint, itemInfo.ActualQuantity, item.CheckKind);
  5518. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5519. {
  5520. throw new Exception(language.GetNameByCode("WMSAPIInfo033"));//"盘点扫描创建失败!");
  5521. }
  5522. #region 更新ICSCheckDetail表
  5523. //string strSql = @"UPDATE ICSCheckDetail Set";
  5524. //if (item.CheckKind == "初盘")
  5525. // strSql += @" PrimaryQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  5526. //else if (item.CheckKind == "复盘")
  5527. // strSql += @" ReplayQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  5528. //else
  5529. // strSql += @" CheckQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  5530. //strSql += @" where ToCheckNO='" + item.CheckCode + "' AND WorkPoint='" + item.WorkPoint + "'";
  5531. //cmd.CommandText = strSql;
  5532. //result = cmd.ExecuteNonQuery();
  5533. //if (result <= 0)
  5534. //{
  5535. // throw new Exception(language.GetNameByCode("WMSAPIInfo296"));//"盘点子表数量增加失败!");
  5536. //}
  5537. #endregion
  5538. #region 更新库存
  5539. if (item.UpdateWHLI)
  5540. {
  5541. ICSWareHouseLotInfoService.WareHouseLotInfoUpdate(Identification, item.CheckCode, "", itemInfo.LotNo, itemInfo.ActualQuantity, item.User, item.WorkPoint, TransTypeEnum.Check.GetDescription<DBValue>(), item.CheckKind, cmd, language);
  5542. }
  5543. #endregion
  5544. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  5545. }
  5546. if (string.IsNullOrWhiteSpace(lots))
  5547. {
  5548. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  5549. }
  5550. //sql = @"UPDATE a SET ActualQuantity=b.ActualQuantity
  5551. // FROM ICSCheck a
  5552. // INNER JOIN (SELECT x.CheckCode,x.WorkPoint,y.WarehouseCode,y.InvCode,SUM(ActualQuantity) AS ActualQuantity FROM ICSCheckDetail x INNER JOIN ICSWareHouseLotInfo y ON x.LotNo=y.LotNo AND x.WorkPoint=y.WorkPoint WHERE x.LotNo+x.WorkPoint IN ({2}) GROUP BY x.CheckCode,x.WorkPoint,y.WarehouseCode,y.InvCode) b ON a.CheckCode=b.CheckCode AND a.WorkPoint=b.WorkPoint AND a.WHCode=b.WarehouseCode AND a.InvCode=b.InvCode
  5553. // WHERE a.CheckCode='{0}' and a.WorkPoint='{1}'";
  5554. //sql = string.Format(sql, item.CheckCode, item.WorkPoint, lots.Substring(0, lots.Length - 1));
  5555. //if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5556. //{
  5557. // throw new Exception(language.GetNameByCode("WMSAPIInfo034"));//"盘点扫描更新盘点单失败!");
  5558. //}
  5559. }
  5560. #region 查询返回数据
  5561. sql = @"SELECT x.ID,x.CheckID,y.WarehouseCode AS WHCode,x.LotNo,
  5562. y.InvCode,
  5563. inv.InvName,
  5564. inv.InvStd,
  5565. x.Quantity,x.PrimaryQuantity,x.PrimaryAmount,x.ReplayQuantity,x.ReplayAmount,x.CheckQuantity,x.CheckAmount,
  5566. inv.InvUnit,
  5567. x.MUSER AS [User],
  5568. x.MTIME AS [MTime]
  5569. FROM ICSCheckDetail x
  5570. INNER JOIN ICSWareHouseLotInfo y ON x.LotNo=y.LotNo AND x.WorkPoint=y.WorkPoint
  5571. INNER JOIN ICSInventory inv ON y.InvCode=inv.InvCode AND y.WorkPoint=inv.WorkPoint
  5572. WHERE x.LotNo+x.WorkPoint IN ({0})";
  5573. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  5574. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  5575. #endregion
  5576. cmd.Transaction.Commit();
  5577. return data;
  5578. }
  5579. catch (Exception ex)
  5580. {
  5581. if (cmd.Transaction != null)
  5582. cmd.Transaction.Rollback();
  5583. log.Error(ex.Message);
  5584. throw new Exception(ex.Message);
  5585. }
  5586. finally
  5587. {
  5588. if (conn.State == ConnectionState.Open)
  5589. {
  5590. conn.Close();
  5591. }
  5592. conn.Dispose();
  5593. }
  5594. }
  5595. }
  5596. #endregion
  5597. #region 多语言
  5598. /// <summary>
  5599. /// 多语言查询
  5600. /// </summary>
  5601. /// <param name="JsonData"></param>
  5602. /// <returns></returns>
  5603. public static DataTable PromptInformationGet(WMSBarCoreModel JsonData)
  5604. {
  5605. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5606. {
  5607. conn.Open();
  5608. SqlCommand cmd = new SqlCommand();
  5609. cmd.Connection = conn;
  5610. try
  5611. {
  5612. string DefiniteLanguage = ICSDefiniteLanguageService.GetLanguage();
  5613. string sql = @"select " + DefiniteLanguage + " AS Name,Code from Sys_Language where 1=1";
  5614. if (!string.IsNullOrWhiteSpace(JsonData.Code))
  5615. {
  5616. sql += " and Code LIKE '%{0}%'";
  5617. }
  5618. sql = string.Format(sql, JsonData.Code);
  5619. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  5620. return data;
  5621. }
  5622. catch (Exception ex)
  5623. {
  5624. log.Error(ex.Message);
  5625. throw new Exception(ex.Message);
  5626. }
  5627. finally
  5628. {
  5629. if (conn.State == ConnectionState.Open)
  5630. {
  5631. conn.Close();
  5632. }
  5633. conn.Dispose();
  5634. }
  5635. }
  5636. }
  5637. #endregion
  5638. #region 仓库/库位
  5639. /// <summary>
  5640. /// 仓库/库位
  5641. /// </summary>
  5642. /// <param name="JsonData"></param>
  5643. /// <returns></returns>
  5644. public static DataTable LocationGet(ICSLocation JsonData)
  5645. {
  5646. var language = LanguageHelper.GetName("WMSAPIInfo");
  5647. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5648. {
  5649. conn.Open();
  5650. SqlTransaction sqlTran = conn.BeginTransaction();
  5651. SqlCommand cmd = new SqlCommand();
  5652. cmd.Transaction = sqlTran;
  5653. cmd.Connection = conn;
  5654. try
  5655. {
  5656. string sql = @"IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a where LocationCode='{0}' AND a.WorkPoint='{1}')
  5657. BEGIN
  5658. RAISERROR('" + language.GetNameByCode("WMSAPIInfo070") + @"',16,1);
  5659. RETURN
  5660. END
  5661. IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a INNER JOIN ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where LocationCode='{0}' AND a.WorkPoint='{1}')
  5662. BEGIN
  5663. RAISERROR('" + language.GetNameByCode("WMSAPIInfo077") + @"',16,1);
  5664. RETURN
  5665. END
  5666. IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a INNER JOIN ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where LocationCode='{0}' AND a.WorkPoint='{1}' and b.Enable='1')
  5667. BEGIN
  5668. RAISERROR('" + language.GetNameByCode("WMSAPIInfo078") + @"',16,1);
  5669. RETURN
  5670. END
  5671. SELECT
  5672. LocationCode,
  5673. LocationName ,
  5674. WarehouseCode,
  5675. WarehouseName
  5676. FROM ICSLocation a
  5677. INNER JOIN ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where LocationCode='{0}' AND a.WorkPoint='{1}' and b.Enable='1'";
  5678. sql = string.Format(sql, JsonData.LocationCode, JsonData.WorkPoint);
  5679. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  5680. cmd.Transaction.Commit();
  5681. return data;
  5682. }
  5683. catch (Exception ex)
  5684. {
  5685. if (cmd.Transaction != null)
  5686. cmd.Transaction.Rollback();
  5687. log.Error(ex.Message);
  5688. throw new Exception(ex.Message);
  5689. }
  5690. finally
  5691. {
  5692. if (conn.State == ConnectionState.Open)
  5693. {
  5694. conn.Close();
  5695. }
  5696. conn.Dispose();
  5697. }
  5698. }
  5699. }
  5700. #endregion
  5701. #region 登陆
  5702. public static object CheckLogin(Sys_SRM_User userModel)
  5703. {
  5704. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5705. {
  5706. conn.Open();
  5707. SqlCommand cmd = new SqlCommand();
  5708. cmd.Connection = conn;
  5709. try
  5710. {
  5711. string sql = @"select F_Account from Sys_SRM_User where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";//已经启用的账号
  5712. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  5713. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  5714. if (dt != null && dt.Rows.Count > 0)//查询的数据不为空
  5715. {
  5716. sql = @" select a.[F_Id] as UserId
  5717. ,[F_Account] as userCode
  5718. ,[F_RealName] as UserName
  5719. ,[F_NickName]
  5720. ,b.F_UserPassword
  5721. ,b.F_UserSecretkey
  5722. ,[F_HeadIcon]
  5723. ,[F_Gender]
  5724. ,[F_Birthday]
  5725. ,[F_MobilePhone]
  5726. ,[F_Email]
  5727. ,[F_WeChat]
  5728. ,[F_ManagerId]
  5729. ,[F_SecurityLevel]
  5730. ,[F_Signature]
  5731. ,[F_OrganizeId]
  5732. ,[F_DepartmentId]
  5733. ,[F_RoleId]
  5734. ,[F_DutyId]
  5735. ,[F_IsAdministrator]
  5736. ,[F_SortCode]
  5737. ,[F_DeleteMark]
  5738. ,[F_EnabledMark]
  5739. ,[F_Description]
  5740. ,[F_CreatorTime]
  5741. ,[F_CreatorUserId]
  5742. ,[F_LastModifyTime]
  5743. ,[F_LastModifyUserId]
  5744. ,[F_DeleteTime]
  5745. ,[F_DeleteUserId]
  5746. ,[F_Location] as WorkPoint
  5747. ,[F_VenCode]
  5748. from Sys_SRM_User a
  5749. left join Sys_SRM_UserLogOn b on b.F_UserId=a.F_Id
  5750. where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";
  5751. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  5752. dt = DBHelper.SQlReturnData(sql, cmd);
  5753. IList<UserLogOnEntity> users = DBHelper.ModelConvertHelper<UserLogOnEntity>.ConvertToModel(dt);
  5754. // string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  5755. foreach (var item in users)
  5756. {
  5757. //string UserPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower()),16).ToLower();
  5758. string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  5759. if (dbPassword == item.F_UserPassword)
  5760. {
  5761. string json = JsonConvert.SerializeObject(dt);
  5762. List<Sys_SRM_User> userLogOnEntity = JsonConvert.DeserializeObject<List<Sys_SRM_User>>(json);
  5763. return userLogOnEntity;
  5764. }
  5765. else
  5766. {
  5767. throw new Exception(LanguageHelper.GetNameSingle("WMSAPI004"));//"密码不正确,请重新输入");
  5768. }
  5769. }
  5770. }
  5771. else
  5772. {
  5773. throw new Exception(LanguageHelper.GetNameSingle("WMSAPI005"));//"用户名不存在,请重新输入!");
  5774. }
  5775. return null;
  5776. }
  5777. catch (Exception ex)
  5778. {
  5779. log.Error(ex.Message);
  5780. throw new Exception(ex.Message);
  5781. }
  5782. finally
  5783. {
  5784. if (conn.State == ConnectionState.Open)
  5785. {
  5786. conn.Close();
  5787. }
  5788. conn.Dispose();
  5789. }
  5790. }
  5791. }
  5792. #endregion
  5793. #region 获取调拨单
  5794. /// <summary>
  5795. /// 获取未发,未发完调拨单
  5796. /// </summary>
  5797. /// <param name="JsonData"></param>
  5798. /// <returns></returns>
  5799. public static DataTable TransCodemationGet(TransferDoc JsonData)
  5800. {
  5801. var language = LanguageHelper.GetName("WMSAPIInfo");
  5802. if (JsonData == null)
  5803. {
  5804. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5805. }
  5806. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5807. {
  5808. conn.Open();
  5809. SqlTransaction sqlTran = conn.BeginTransaction();
  5810. SqlCommand cmd = new SqlCommand();
  5811. cmd.Transaction = sqlTran;
  5812. cmd.Connection = conn;
  5813. try
  5814. {
  5815. string Workpoint = "";
  5816. Workpoint = JsonData.WorkPoint;
  5817. string sql = @"SELECT DISTINCT TransferNO as TransCode FROM ICSTransferApplication
  5818. WHERE WorkPoint='{0}' AND Quantity>ISNULL(TransferQuantity, 0) order by TransferNO desc";
  5819. sql = string.Format(sql, Workpoint);
  5820. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  5821. return table;
  5822. }
  5823. catch (Exception ex)
  5824. {
  5825. if (cmd.Transaction != null)
  5826. cmd.Transaction.Rollback();
  5827. log.Error(ex.Message);
  5828. throw new Exception(ex.Message);
  5829. }
  5830. finally
  5831. {
  5832. if (conn.State == ConnectionState.Open)
  5833. {
  5834. conn.Close();
  5835. }
  5836. conn.Dispose();
  5837. }
  5838. }
  5839. }
  5840. #endregion
  5841. }
  5842. }