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

5421 lines
309 KiB

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