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

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