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

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