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

5406 lines
308 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
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 = @"
  1429. IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo = '{2}' AND a.WorkPoint = '{3}')
  1430. BEGIN
  1431. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"', 16, 1);
  1432. RETURN
  1433. END
  1434. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  1435. BEGIN
  1436. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  1437. RETURN
  1438. END
  1439. IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
  1440. INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  1441. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint
  1442. LEFT JOIN ICSInventoryLotDetail c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1443. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND (b.InvIQC='1'AND ins.LotNo IS NULL) AND c.TransCode NOT LIKE 'RD%')
  1444. BEGIN
  1445. RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"',16,1);
  1446. RETURN
  1447. END
  1448. " + sql;
  1449. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  1450. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  1451. '' AS WHCode,
  1452. '' AS WHName,
  1453. '' AS LocationCode,
  1454. '' AS LocationName,
  1455. ext.BatchCode AS BatchCode,";
  1456. tableName = @"ICSInventoryLot a
  1457. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1458. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  1459. }
  1460. else
  1461. {
  1462. sql = @"
  1463. WITH ICSBomALL AS
  1464. (
  1465. SELECT
  1466. ContainerCode AS TContainerCode,
  1467. ContainerCode AS PContainerCode,
  1468. ContainerCode AS ContainerCode,
  1469. ID,
  1470. ContainerID,
  1471. 0 AS [Level],
  1472. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  1473. CAST('00001' AS nvarchar(MAX)) AS Sort
  1474. FROM ICSContainer
  1475. WHERE ContainerCode='{2}'
  1476. UNION ALL
  1477. SELECT
  1478. b.TContainerCode,
  1479. b.ContainerCode AS PContainerCode,
  1480. a.ContainerCode,
  1481. a.ID,
  1482. a.ContainerID,
  1483. b.[Level]+1 AS [Level],
  1484. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  1485. 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
  1486. FROM
  1487. ICSContainer a
  1488. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  1489. )
  1490. " + sql;
  1491. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  1492. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  1493. '' AS WHCode,
  1494. '' AS WHName,
  1495. '' AS LocationCode,
  1496. '' AS LocationName,
  1497. ext.BatchCode AS BatchCode,";
  1498. tableName = @"ICSInventoryLot a
  1499. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1500. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  1501. }
  1502. }
  1503. if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName))
  1504. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
  1505. sql = string.Format(sql, columns, tableName, JsonData.Code, JsonData.WorkPoint);
  1506. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  1507. if (table == null || table.Rows.Count <= 0)
  1508. throw new Exception(language.GetNameByCode("WMSAPIInfo008"));//"未查询到条码数据!"
  1509. #region 出库检验是否符合源头单据
  1510. string msg = string.Empty;
  1511. bool isLimit = false;
  1512. string sqlCheckSign = @"select F_EnabledMark from Sys_SRM_Items where F_EnCode = 'OutWithLocationCode' and F_EnabledMark = '1'";
  1513. DataTable flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  1514. if (isOut) // && TransType != TransTypeEnum.LOTSplit.GetDescription()
  1515. {//&& TransType != TransTypeEnum.TransferLibrary.GetDescription()
  1516. string Lot = "";
  1517. string workP = "";
  1518. if (TransType == TransTypeEnum.TransferLibrary.GetDescription())
  1519. {
  1520. foreach (DataRow drLot in table.Rows)
  1521. {
  1522. Lot = drLot["LotNo"].ToString();
  1523. sql = @"SELECT WarehouseCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  1524. sql = string.Format(sql, Lot, JsonData.WorkPoint);
  1525. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1526. if (dt == null || dt.Rows.Count <= 0)
  1527. {
  1528. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), Lot));
  1529. }
  1530. string whcode = dt.Rows[0]["WarehouseCode"].ToString();
  1531. if (!JsonData.WHCode.Equals(whcode))
  1532. {
  1533. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo395"), JsonData.WHCode, whcode));
  1534. }
  1535. }
  1536. }
  1537. else
  1538. {
  1539. if (string.IsNullOrEmpty(JsonData.TransCode))
  1540. {
  1541. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  1542. }
  1543. WMSSourceDocumentModel model = new WMSSourceDocumentModel();
  1544. model.TransCode = JsonData.TransCode;
  1545. model.TransType = JsonData.TransType;
  1546. model.WorkPoint = JsonData.WorkPoint;
  1547. DataTable TransData = TransInformationGet(model);
  1548. DataView dataView = TransData.DefaultView;
  1549. foreach (DataRow drLot in table.Rows)
  1550. {
  1551. Lot = drLot["LotNo"].ToString();
  1552. //盘点不需要对比以下属性
  1553. if (TransType == TransTypeEnum.Check.GetDescription())
  1554. continue;
  1555. string rowFilter = "InvCode='" + drLot["InvCode"] + "'";
  1556. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo041"), Lot, drLot["InvCode"]));
  1557. rowFilter += " AND (LEN(ISNULL(WHCode,''))<=0 OR (LEN(ISNULL(WHCode,''))>0 AND WHCode='" + drLot["WHCode"] + "'))";
  1558. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["WHCode"]));
  1559. rowFilter += " AND (LEN(ISNULL(ProjectCode,''))<=0 OR (LEN(ISNULL(ProjectCode,''))>0 AND ProjectCode='" + drLot["ProjectCode"] + "'))";
  1560. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo043"), Lot, drLot["ProjectCode"]));
  1561. rowFilter += "AND (LEN(ISNULL(BatchCode,''))<=0 OR (LEN(ISNULL(BatchCode,''))>0 AND BatchCode='" + drLot["BatchCode"] + "'))";
  1562. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo044"), Lot, drLot["BatchCode"]));
  1563. rowFilter += "AND (LEN(ISNULL(Version,''))<=0 OR (LEN(ISNULL(Version,''))>0 AND Version='" + drLot["Version"] + "'))";
  1564. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo045"), Lot, drLot["Version"]));
  1565. rowFilter += "AND (LEN(ISNULL(Brand,''))<=0 OR (LEN(ISNULL(Brand,''))>0 AND Brand='" + drLot["Brand"] + "'))";
  1566. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo046"), Lot, drLot["Brand"]));
  1567. rowFilter += "AND (LEN(ISNULL(cFree1,''))<=0 OR (LEN(ISNULL(cFree1,''))>0 AND cFree1='" + drLot["cFree1"] + "'))";
  1568. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo047"), Lot, drLot["cFree1"]));
  1569. rowFilter += "AND (LEN(ISNULL(cFree2,''))<=0 OR (LEN(ISNULL(cFree2,''))>0 AND cFree2='" + drLot["cFree2"] + "'))";
  1570. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo048"), Lot, drLot["cFree2"]));
  1571. rowFilter += "AND (LEN(ISNULL(cFree3,''))<=0 OR (LEN(ISNULL(cFree3,''))>0 AND cFree3='" + drLot["cFree3"] + "'))";
  1572. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo049"), Lot, drLot["cFree3"]));
  1573. rowFilter += "AND (LEN(ISNULL(cFree4,''))<=0 OR (LEN(ISNULL(cFree4,''))>0 AND cFree4='" + drLot["cFree4"] + "'))";
  1574. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo050"), Lot, drLot["cFree4"]));
  1575. rowFilter += "AND (LEN(ISNULL(cFree5,''))<=0 OR (LEN(ISNULL(cFree5,''))>0 AND cFree5='" + drLot["cFree5"] + "'))";
  1576. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo051"), Lot, drLot["cFree5"]));
  1577. rowFilter += "AND (LEN(ISNULL(cFree6,''))<=0 OR (LEN(ISNULL(cFree6,''))>0 AND cFree6='" + drLot["cFree6"] + "'))";
  1578. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo052"), Lot, drLot["cFree6"]));
  1579. rowFilter += "AND (LEN(ISNULL(cFree7,''))<=0 OR (LEN(ISNULL(cFree7,''))>0 AND cFree7='" + drLot["cFree7"] + "'))";
  1580. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo053"), Lot, drLot["cFree7"]));
  1581. rowFilter += "AND (LEN(ISNULL(cFree8,''))<=0 OR (LEN(ISNULL(cFree8,''))>0 AND cFree8='" + drLot["cFree8"] + "'))";
  1582. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo054"), Lot, drLot["cFree8"]));
  1583. rowFilter += "AND (LEN(ISNULL(cFree9,''))<=0 OR (LEN(ISNULL(cFree9,''))>0 AND cFree9='" + drLot["cFree9"] + "'))";
  1584. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo055"), Lot, drLot["cFree9"]));
  1585. rowFilter += "AND (LEN(ISNULL(cFree10,''))<=0 OR (LEN(ISNULL(cFree10,''))>0 AND cFree10='" + drLot["cFree10"] + "'))";
  1586. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo056"), Lot, drLot["cFree10"]));
  1587. if (flag != null && flag.Rows.Count > 0)
  1588. {
  1589. rowFilter += " AND LocationCode='" + drLot["LocationCode"] + "'";
  1590. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["LocationCode"]));
  1591. }
  1592. //保质期管理
  1593. var resultEffective = Effective(Lot, JsonData.WorkPoint, cmd, language);
  1594. //0 - 已经是最早的批次
  1595. //1 - 不管控
  1596. //2 - 提醒
  1597. //3 - 限制
  1598. if (resultEffective == "2")
  1599. {
  1600. msg += string.Format(language.GetNameByCode("WMSAPIInfo181"), Lot) + Environment.NewLine;
  1601. }
  1602. else if (resultEffective == "3")
  1603. {
  1604. msg += string.Format(language.GetNameByCode("WMSAPIInfo182"), Lot) + Environment.NewLine;
  1605. isLimit = true;
  1606. }
  1607. //先进先出判断
  1608. var result = CanOut(Lot, JsonData.WorkPoint, JsonData.ScanLotCode, cmd, language);
  1609. //0 - 已经是最早的批次
  1610. //1 - 不管控
  1611. //2 - 提醒
  1612. //3 - 限制
  1613. if (result == "2")
  1614. {
  1615. msg += string.Format(language.GetNameByCode("WMSAPIInfo178"), Lot) + Environment.NewLine;
  1616. }
  1617. else if (result == "3")
  1618. {
  1619. msg += string.Format(language.GetNameByCode("WMSAPIInfo179"), Lot) + Environment.NewLine;
  1620. isLimit = true;
  1621. }
  1622. }
  1623. }
  1624. }
  1625. #endregion
  1626. //return table;
  1627. Result res = new Result();
  1628. res.Success = true;
  1629. res.Message = msg;// "接口调用成功!";
  1630. if (!isLimit)
  1631. res.Data = table;
  1632. return res;
  1633. //出库时
  1634. //Message无值、Data有值,可直接处理
  1635. //Message有值、Data有值,弹出提醒框(可点击确定、取消,确定后继续出库,取消后不处理这批条码),显示Message信息
  1636. //Message有值、Data无值,弹出警告框(只能点击确定,且不处理这批条码),显示Message信息
  1637. }
  1638. catch (Exception ex)
  1639. {
  1640. log.Error(ex.Message);
  1641. throw new Exception(ex.Message);
  1642. }
  1643. finally
  1644. {
  1645. if (conn.State == ConnectionState.Open)
  1646. {
  1647. conn.Close();
  1648. }
  1649. conn.Dispose();
  1650. }
  1651. }
  1652. }
  1653. /// <summary>
  1654. /// 校验条码对应的物料、自由项等信息是否与源头单据匹配
  1655. /// </summary>
  1656. private static void CheckTrans(DataView dataView, string rowFilter, string message)
  1657. {
  1658. dataView.RowFilter = rowFilter;
  1659. if (dataView == null || dataView.Count <= 0)
  1660. throw new Exception(message);
  1661. }
  1662. #endregion
  1663. /// <summary>
  1664. /// 上架
  1665. /// </summary>BusinessCode,TransType 两个类型
  1666. /// <param name="JsonData"></param>
  1667. /// <returns></returns>
  1668. public static DataTable LOTStockCreate(List<LOTStockUpCreateIModel> JsonData)
  1669. {
  1670. var language = LanguageHelper.GetName("WMSAPIInfo");
  1671. if (JsonData.Count <= 0)
  1672. {
  1673. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  1674. }
  1675. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  1676. {
  1677. conn.Open();
  1678. SqlTransaction sqlTran = conn.BeginTransaction();
  1679. SqlCommand cmd = new SqlCommand();
  1680. cmd.Transaction = sqlTran;
  1681. cmd.Connection = conn;
  1682. try
  1683. {
  1684. string TransType = string.Empty;
  1685. string Identification = Guid.NewGuid().ToString();
  1686. foreach (var item in JsonData)
  1687. {
  1688. TransType = item.TransType;
  1689. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  1690. {
  1691. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  1692. }
  1693. string WHTransType = "2";
  1694. string BusinessCode = string.Empty;
  1695. foreach (var itemInfo in item.detail)
  1696. {
  1697. #region 两步调入
  1698. if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  1699. {
  1700. //更新源头单据数量
  1701. ICSWareHouseService.TwoStepTransferDocIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1702. //入库
  1703. ICSWareHouseLotInfoService.WareHouseLotInfoTwoStepTransferDocIn(Identification, itemInfo.TransCode, itemInfo.TransSequence,
  1704. itemInfo.WarehouseCode, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity, item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocIn.GetDescription<DBValue>(), cmd, language);
  1705. }
  1706. #endregion
  1707. #region 销售退货-原条码
  1708. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  1709. {
  1710. //更新源头单据数量
  1711. ICSSalesService.SalesReturnBackIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1712. //入库
  1713. BusinessCode = TransTypeEnum.SalesReturnBack.GetDescription<DBValue>();
  1714. //入库
  1715. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  1716. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode);
  1717. //更新日志表源头单据信息
  1718. string sql = @"UPDATE ICSWareHouseLotInfoLog SET TransCode='{3}',TransSequence='{4}'
  1719. WHERE LotNo='{0}' AND WorkPoint='{1}' AND Identification='{2}' AND TransCode='' AND TransSequence=''";
  1720. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, Identification, itemInfo.TransCode, itemInfo.TransSequence);
  1721. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1722. {
  1723. throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
  1724. }
  1725. }
  1726. #endregion
  1727. else
  1728. {
  1729. #region 采购入库
  1730. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  1731. {
  1732. //更新源头单据数量
  1733. ICSPurchaseService.PurchaseReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1734. BusinessCode = TransTypeEnum.PurchaseReceiveDoc.GetDescription<DBValue>();
  1735. }
  1736. #endregion
  1737. #region 审核的到货单
  1738. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  1739. {
  1740. //更新源头单据数量
  1741. ICSPurchaseService.DeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1742. BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription<DBValue>();
  1743. }
  1744. #endregion
  1745. #region 采购拒收
  1746. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  1747. {
  1748. //更新源头单据数量
  1749. ICSPurchaseService.PurchaseRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1750. BusinessCode = TransTypeEnum.PurchaseRejectDoc.GetDescription<DBValue>();
  1751. }
  1752. #endregion
  1753. #region 审核的委外到货单
  1754. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  1755. {
  1756. //更新源头单据数量
  1757. ICSOutsourcingService.ODeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1758. BusinessCode = TransTypeEnum.ODeliveryNotice.GetDescription<DBValue>();
  1759. }
  1760. #endregion
  1761. #region 委外拒收
  1762. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  1763. {
  1764. //更新源头单据数量
  1765. ICSOutsourcingService.OutsourcingRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1766. BusinessCode = TransTypeEnum.OutsourcingRejectDoc.GetDescription<DBValue>();
  1767. }
  1768. #endregion
  1769. #region 委外退料
  1770. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  1771. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  1772. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1773. {
  1774. //更新源头单据数量
  1775. ICSOutsourcingService.OutsourcingIssueDoNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1776. BusinessCode = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription<DBValue>();
  1777. }
  1778. #endregion
  1779. #region 返工工单
  1780. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  1781. {
  1782. //更新源头单据数量
  1783. ICSManufactureService.ReWorkReceiveMo(itemInfo.LotNo, itemInfo.Quantity, itemInfo.WarehouseCode, itemInfo.LocationCode, item.WorkPoint, item.User, TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>(), cmd, language);
  1784. BusinessCode = TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>();
  1785. }
  1786. #endregion
  1787. #region 委外入库
  1788. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  1789. {
  1790. //更新源头单据数量
  1791. ICSOutsourcingService.OutsourcingReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1792. BusinessCode = TransTypeEnum.OutsourcingReceiveDoc.GetDescription<DBValue>();
  1793. }
  1794. #endregion
  1795. #region 生产退料
  1796. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  1797. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  1798. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1799. {
  1800. //更新源头单据数量
  1801. ICSManufactureService.MOIssueDocNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1802. BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>();
  1803. }
  1804. #endregion
  1805. #region 生产入库
  1806. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  1807. {
  1808. //更新源头单据数量
  1809. ICSManufactureService.ManufactureReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1810. BusinessCode = TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>();
  1811. }
  1812. #endregion
  1813. #region 开立的生产入库单
  1814. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  1815. {
  1816. //更新源头单据数量
  1817. ICSManufactureService.ManufactureReceive(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1818. BusinessCode = TransTypeEnum.ManufactureReceive.GetDescription<DBValue>();
  1819. }
  1820. #endregion
  1821. #region 销售退货
  1822. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  1823. {
  1824. //更新源头单据数量
  1825. ICSSalesService.SalesShipmentDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1826. BusinessCode = TransTypeEnum.SalesShipmentDocNegative.GetDescription<DBValue>();
  1827. }
  1828. #endregion
  1829. #region 其他入库
  1830. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  1831. {
  1832. //更新源头单据数量
  1833. ICSWareHouseService.OtherInDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1834. BusinessCode = TransTypeEnum.OtherInDoc.GetDescription<DBValue>();
  1835. }
  1836. #endregion
  1837. #region 拆卸单
  1838. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  1839. {
  1840. ICSWareHouseService.DisassemblyDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1841. WHTransType = "11";
  1842. BusinessCode = TransTypeEnum.DisassemblyDoc.GetDescription<DBValue>();
  1843. }
  1844. #endregion
  1845. #region 归还
  1846. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  1847. {
  1848. //更新源头单据数量
  1849. ICSWareHouseService.ReturnDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1850. BusinessCode = TransTypeEnum.ReturnDoc.GetDescription<DBValue>();
  1851. }
  1852. #endregion
  1853. else
  1854. {
  1855. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  1856. }
  1857. //入库
  1858. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  1859. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language,itemInfo.LogID,itemInfo.InvCode + itemInfo.WarehouseCode);
  1860. }
  1861. }
  1862. #region 拆卸单
  1863. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  1864. {
  1865. //更新套件锁定数量
  1866. ICSWareHouseService.DisassemblyDoc(Identification, cmd, language);
  1867. }
  1868. #endregion}
  1869. }
  1870. //上传ERP
  1871. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  1872. {
  1873. //采购入库
  1874. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  1875. ICSPurchaseService.PurchaseReceiveDocERP(TransType, Identification, cmd, language);
  1876. //审核的到货单
  1877. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  1878. ICSPurchaseService.DeliveryNoticeInERP(TransType, Identification, cmd, language);
  1879. //采购拒收
  1880. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  1881. ICSPurchaseService.PurchaseRejectDocInERP(TransType, Identification, cmd, language);
  1882. //审核的委外到货单
  1883. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  1884. ICSOutsourcingService.ODeliveryNoticeInERP(TransType, Identification, cmd, language);
  1885. //委外拒收
  1886. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  1887. ICSOutsourcingService.OutsourcingRejectDocInERP(TransType, Identification, cmd, language);
  1888. //委外退料
  1889. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  1890. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  1891. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1892. ICSOutsourcingService.OutsourcingIssueDoNegativeERP(TransType, Identification, cmd, language);
  1893. //委外入库
  1894. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  1895. ICSOutsourcingService.OutsourcingReceiveDocERP(TransType, Identification, cmd, language);
  1896. //生产退料
  1897. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  1898. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  1899. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1900. ICSManufactureService.MOIssueDocNegativeERP(TransType, Identification, cmd, language);
  1901. //生产入库
  1902. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  1903. ICSManufactureService.ManufactureReceiveDocERP(TransType, Identification, cmd, language);
  1904. //开立的生产入库单
  1905. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  1906. ICSManufactureService.ManufactureReceiveERP(TransType, Identification, cmd, language);
  1907. //返工工单
  1908. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  1909. ICSManufactureService.ReWorkReceiveMoERP(TransType, Identification, cmd, language);
  1910. //销售退货
  1911. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  1912. ICSSalesService.SalesShipmentDocNegativeERP(TransType, Identification, cmd, language);
  1913. //两步调入
  1914. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  1915. ICSWareHouseService.TwoStepTransferDocInERP(TransType, Identification, cmd, language);
  1916. //销售退货-原条码
  1917. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  1918. ICSSalesService.SalesReturnBackInERP(TransType, Identification, cmd, language);
  1919. //其他入库
  1920. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  1921. ICSWareHouseService.OtherInDocERP(TransType, Identification, cmd, language);
  1922. //拆卸单
  1923. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  1924. ICSWareHouseService.DisassemblyDocERP(TransType, Identification, cmd, language);
  1925. //归还
  1926. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  1927. ICSWareHouseService.ReturnDocERP(TransType, Identification, cmd, language);
  1928. }
  1929. DataTable table = GetData(Identification, 1, cmd);
  1930. cmd.Transaction.Commit();
  1931. return table;
  1932. }
  1933. catch (Exception ex)
  1934. {
  1935. if (cmd.Transaction != null)
  1936. cmd.Transaction.Rollback();
  1937. log.Error(ex.Message);
  1938. throw new Exception(ex.Message);
  1939. }
  1940. finally
  1941. {
  1942. if (conn.State == ConnectionState.Open)
  1943. {
  1944. conn.Close();
  1945. }
  1946. conn.Dispose();
  1947. }
  1948. }
  1949. }
  1950. /// <summary>
  1951. /// 下架
  1952. /// </summary>
  1953. /// <param name="JsonData"></param>
  1954. /// <returns></returns>
  1955. public static DataTable LOTStockDownCreate(List<LOTStockModel> JsonData)
  1956. {
  1957. String PrintEnable = "";
  1958. var language = LanguageHelper.GetName("WMSAPIInfo");
  1959. if (JsonData.Count <= 0)
  1960. {
  1961. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  1962. }
  1963. List<LOTStockModelList> model = new List<LOTStockModelList>();
  1964. DataTable printTable = new DataTable();
  1965. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  1966. {
  1967. conn.Open();
  1968. SqlTransaction sqlTran = conn.BeginTransaction();
  1969. SqlCommand cmd = new SqlCommand();
  1970. cmd.Transaction = sqlTran;
  1971. cmd.Connection = conn;
  1972. try
  1973. {
  1974. string TransType = string.Empty;
  1975. string Identification = Guid.NewGuid().ToString();
  1976. foreach (var item in JsonData)
  1977. {
  1978. TransType = item.TransType;
  1979. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  1980. {
  1981. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  1982. }
  1983. else if (string.IsNullOrEmpty(item.TransCode))
  1984. {
  1985. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  1986. }
  1987. string[] trans = item.TransCode.Split('~');
  1988. string MergeID = "";
  1989. if (trans.Length == 2)
  1990. {
  1991. MergeID = trans[0];
  1992. item.TransCode = trans[1];
  1993. }
  1994. #region 采购退货
  1995. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  1996. {
  1997. //更新源头单据数量
  1998. ICSPurchaseService.PurchaseReceiveDoctNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  1999. foreach (var itemInfo in item.detail)
  2000. {
  2001. //出库
  2002. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2003. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>(), cmd, language);
  2004. }
  2005. }
  2006. #endregion
  2007. #region 委外发料
  2008. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  2009. {
  2010. //更新源头单据数量
  2011. ICSOutsourcingService.OutsourcingIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2012. foreach (var itemInfo in item.detail)
  2013. {
  2014. //出库
  2015. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2016. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2017. }
  2018. }
  2019. #endregion
  2020. #region 委外退货
  2021. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  2022. {
  2023. //更新源头单据数量
  2024. ICSOutsourcingService.OutsourcingReturnBack(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2025. foreach (var itemInfo in item.detail)
  2026. {
  2027. //出库
  2028. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2029. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>(), cmd, language);
  2030. }
  2031. }
  2032. #endregion
  2033. #region 生产发料
  2034. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  2035. {
  2036. //更新源头单据数量
  2037. ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2038. foreach (var itemInfo in item.detail)
  2039. {
  2040. //出库
  2041. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2042. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssueDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2043. }
  2044. }
  2045. #endregion
  2046. #region 销售出库
  2047. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  2048. {
  2049. //更新源头单据数量
  2050. ICSSalesService.SalesShipmentDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2051. foreach (var itemInfo in item.detail)
  2052. {
  2053. //出库
  2054. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2055. item.User, item.WorkPoint, "3", TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2056. }
  2057. }
  2058. #endregion
  2059. #region 两步调出
  2060. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  2061. {
  2062. //更新源头单据数量
  2063. ICSWareHouseService.TwoStepTransferDocOut(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2064. foreach (var itemInfo in item.detail)
  2065. {
  2066. //出库
  2067. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2068. item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocOut.GetDescription<DBValue>(), cmd, language, MergeID);
  2069. }
  2070. }
  2071. #endregion
  2072. #region 其他出库
  2073. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  2074. {
  2075. //更新源头单据数量
  2076. ICSWareHouseService.OtherOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2077. foreach (var itemInfo in item.detail)
  2078. {
  2079. //出库
  2080. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2081. item.User, item.WorkPoint, "3", TransTypeEnum.OtherOutDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2082. }
  2083. }
  2084. #endregion
  2085. #region 领料申请单发料
  2086. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  2087. {
  2088. //更新源头单据数量
  2089. ICSManufactureService.MOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2090. foreach (var itemInfo in item.detail)
  2091. {
  2092. //出库
  2093. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2094. item.User, item.WorkPoint, "3", TransTypeEnum.MOApply.GetDescription<DBValue>(), cmd, language, MergeID);
  2095. }
  2096. }
  2097. #endregion
  2098. #region 委外领料申请单发料
  2099. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  2100. {
  2101. //更新源头单据数量
  2102. ICSOutsourcingService.OOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2103. foreach (var itemInfo in item.detail)
  2104. {
  2105. //出库
  2106. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2107. item.User, item.WorkPoint, "3", TransTypeEnum.OOApply.GetDescription<DBValue>(), cmd, language,MergeID);
  2108. }
  2109. }
  2110. #endregion
  2111. #region 开立材料出库
  2112. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  2113. {
  2114. //更新源头单据数量
  2115. ICSManufactureService.MOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2116. foreach (var itemInfo in item.detail)
  2117. {
  2118. //出库
  2119. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2120. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssue.GetDescription<DBValue>(), cmd, language, MergeID);
  2121. }
  2122. }
  2123. #endregion
  2124. #region 开立委外材料出库
  2125. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  2126. {
  2127. //更新源头单据数量
  2128. ICSOutsourcingService.OOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2129. foreach (var itemInfo in item.detail)
  2130. {
  2131. //出库
  2132. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2133. item.User, item.WorkPoint, "3", TransTypeEnum.OOIssue.GetDescription<DBValue>(), cmd, language, MergeID);
  2134. }
  2135. }
  2136. #endregion
  2137. #region 开立红字入库单
  2138. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  2139. {
  2140. //更新源头单据数量
  2141. ICSPurchaseService.PurchaseReceive(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2142. foreach (var itemInfo in item.detail)
  2143. {
  2144. //出库
  2145. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2146. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceive.GetDescription<DBValue>(), cmd, language);
  2147. }
  2148. }
  2149. #endregion
  2150. #region 开立委外红字入库单
  2151. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  2152. {
  2153. //更新源头单据数量
  2154. ICSOutsourcingService.OutsourcingReceiveDocNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2155. foreach (var itemInfo in item.detail)
  2156. {
  2157. //出库
  2158. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2159. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription<DBValue>(), cmd, language);
  2160. }
  2161. }
  2162. #endregion
  2163. #region 借用
  2164. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  2165. {
  2166. //更新源头单据数量
  2167. ICSWareHouseService.BrrowDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2168. foreach (var itemInfo in item.detail)
  2169. {
  2170. //出库
  2171. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2172. item.User, item.WorkPoint, "3", TransTypeEnum.BrrowDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2173. }
  2174. }
  2175. #endregion
  2176. else
  2177. {
  2178. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  2179. }
  2180. }
  2181. //上传ERP
  2182. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  2183. {
  2184. //采购退货
  2185. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  2186. ICSPurchaseService.PurchaseReceiveDoctNegativeERP(TransType, Identification, cmd, language);
  2187. //委外发料
  2188. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  2189. ICSOutsourcingService.OutsourcingIssueDocERP(TransType, Identification, cmd, language);
  2190. //委外退货
  2191. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  2192. ICSOutsourcingService.OutsourcingReturnBackERP(TransType, Identification, cmd, language);
  2193. //生产发料
  2194. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  2195. ICSManufactureService.MOIssueDocERP(TransType, Identification, cmd, language);
  2196. //销售出库
  2197. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  2198. ICSSalesService.SalesShipmentDocERP(TransType, Identification, cmd, language);
  2199. //两步调出
  2200. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  2201. ICSWareHouseService.TwoStepTransferDocOutERP(TransType, Identification, cmd, language);
  2202. //其他出库
  2203. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  2204. ICSWareHouseService.OtherOutDocERP(TransType, Identification, cmd, language);
  2205. //领料申请单发料
  2206. if (TransType == TransTypeEnum.MOApply.GetDescription())
  2207. ICSManufactureService.MOApplyERP(TransType, Identification, cmd, language);
  2208. //委外领料申请单发料
  2209. if (TransType == TransTypeEnum.OOApply.GetDescription())
  2210. ICSOutsourcingService.OOApplyERP(TransType, Identification, cmd, language);
  2211. //开立材料出库
  2212. if (TransType == TransTypeEnum.MOIssue.GetDescription())
  2213. ICSManufactureService.MOIssueERP(TransType, Identification, cmd, language);
  2214. //开立委外材料出库
  2215. if (TransType == TransTypeEnum.OOIssue.GetDescription())
  2216. ICSOutsourcingService.OOIssueERP(TransType, Identification, cmd, language);
  2217. //开立红字入库单
  2218. if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  2219. ICSPurchaseService.PurchaseReceiveERP(TransType, Identification, cmd, language);
  2220. //开立委外红字入库单
  2221. if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  2222. ICSOutsourcingService.OutsourcingReceiveDocNegativeERP(TransType, Identification, cmd, language);
  2223. //借用
  2224. if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  2225. ICSWareHouseService.BrrowDocERP(TransType, Identification, cmd, language);
  2226. }
  2227. if (!printTable.Equals("{}"))
  2228. {
  2229. cmd.Transaction.Commit();
  2230. return printTable;
  2231. }
  2232. else
  2233. {
  2234. DataTable table = GetData(Identification, 2, cmd);
  2235. cmd.Transaction.Commit();
  2236. return table;
  2237. }
  2238. }
  2239. catch (Exception ex)
  2240. {
  2241. if (cmd.Transaction != null)
  2242. cmd.Transaction.Rollback();
  2243. log.Error(ex.Message);
  2244. throw new Exception(ex.Message);
  2245. }
  2246. finally
  2247. {
  2248. if (conn.State == ConnectionState.Open)
  2249. {
  2250. conn.Close();
  2251. }
  2252. conn.Dispose();
  2253. }
  2254. }
  2255. }
  2256. #region 采购
  2257. /// <summary>
  2258. /// 采购到货
  2259. /// </summary>
  2260. /// <param name="JsonData"></param>
  2261. /// <returns></returns>
  2262. public static DataTable DeliveryNoticeCreate(List<ICSDeliveryNotice> JsonData)
  2263. {
  2264. var language = LanguageHelper.GetName("WMSAPIInfo");
  2265. if (JsonData.Count <= 0)
  2266. {
  2267. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2268. }
  2269. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2270. {
  2271. conn.Open();
  2272. SqlTransaction sqlTran = conn.BeginTransaction();
  2273. SqlCommand cmd = new SqlCommand();
  2274. cmd.Transaction = sqlTran;
  2275. cmd.Connection = conn;
  2276. try
  2277. {
  2278. string asncodes = string.Empty;
  2279. string sql = string.Empty;
  2280. foreach (var item in JsonData)
  2281. {
  2282. if (string.IsNullOrEmpty(item.ASNCode))
  2283. {
  2284. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!"
  2285. }
  2286. //获取单号
  2287. sql = @"IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.ASNCode='{0}' AND DNType = '1' AND a.WorkPoint='{1}')
  2288. BEGIN
  2289. RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  2290. RETURN
  2291. END
  2292. DECLARE @Status VARCHAR(10)
  2293. SELECT @Status=Status FROM ICSASN WHERE ASNCode='{0}' and WorkPoint='{1}'
  2294. IF (@Status IS NULL)
  2295. BEGIN
  2296. RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  2297. RETURN
  2298. END
  2299. ELSE IF (@Status!='2')
  2300. BEGIN
  2301. RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  2302. RETURN
  2303. END
  2304. DECLARE @MaxNO INT,@date varchar(20)='DN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  2305. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  2306. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  2307. IF @MaxNO IS NULL
  2308. BEGIN
  2309. SELECT @date+'00001' AS Code
  2310. END
  2311. ELSE
  2312. BEGIN
  2313. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  2314. END ";
  2315. sql = string.Format(sql, item.ASNCode, item.WorkPoint);
  2316. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2317. //修改送货单到货数量
  2318. foreach (var itemInfo in item.detail)
  2319. {
  2320. sql = @"UPDATE ICSASNDetail SET DNQuantity=ISNULL(DNQuantity, 0)+'{2}'
  2321. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  2322. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  2323. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2324. {
  2325. throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"送货单子表信息更新失败!");
  2326. }
  2327. }
  2328. //创建到货单信息
  2329. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  2330. BEGIN
  2331. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  2332. RETURN
  2333. END
  2334. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  2335. DNType,InvCode,Quantity,Amount,RCVQuantity,
  2336. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  2337. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  2338. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  2339. SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
  2340. '1',b.InvCode,SUM(a.DNQuantity),'0','0',
  2341. d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
  2342. d.POID,d.PODetailID,newid(),newid(),b.ExtensionID,
  2343. e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.ASNCode
  2344. FROM ICSASNDetail a
  2345. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2346. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  2347. INNER JOIN ICSPurchaseOrder d ON c.TransCode=d.POCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  2348. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  2349. WHERE a.ASNCode='{3}' AND a.WorkPoint='{2}'
  2350. 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";
  2351. sql = string.Format(sql, Code, item.User, item.WorkPoint, item.ASNCode);
  2352. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2353. {
  2354. throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
  2355. }
  2356. ICSPurchaseService.DeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
  2357. asncodes += "'" + item.ASNCode + item.WorkPoint + "',";
  2358. }
  2359. if (string.IsNullOrWhiteSpace(asncodes))
  2360. {
  2361. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
  2362. }
  2363. #region 查询返回数据
  2364. sql = @"SELECT
  2365. n.POCode,
  2366. n.Sequence AS POSequence,
  2367. a.ASNCode,
  2368. a.DNCode,
  2369. a.Sequence,
  2370. a.VenCode,
  2371. a.DepCode,
  2372. a.InvCode,
  2373. inv.InvName,
  2374. inv.InvStd,
  2375. a.Quantity,
  2376. inv.InvUnit,
  2377. a.Amount,
  2378. inv.AmountUnit,
  2379. a.RCVQuantity,
  2380. a.UnitPrice,
  2381. a.Currency,
  2382. a.POID,
  2383. a.PODetailID,
  2384. a.DNID,
  2385. a.DNDetailID,
  2386. ext.ProjectCode,
  2387. ext.BatchCode,
  2388. ext.Version,
  2389. ext.Brand,
  2390. ext.cFree1,
  2391. ext.cFree2,
  2392. ext.cFree3,
  2393. ext.cFree4,
  2394. ext.cFree5,
  2395. ext.cFree6,
  2396. ext.cFree7,
  2397. ext.cFree8,
  2398. ext.cFree9,
  2399. ext.cFree10,
  2400. a.MUSER AS [User],
  2401. a.MTIME AS [MTime]
  2402. FROM ICSDeliveryNotice a
  2403. INNER JOIN ICSPurchaseOrder n ON a.POID =n.POID AND a.PODetailID=n.PODetailID AND a.WorkPoint=n.WorkPoint
  2404. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2405. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2406. WHERE a.ASNCode+a.WorkPoint IN ({0})";
  2407. sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
  2408. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2409. #endregion
  2410. cmd.Transaction.Commit();
  2411. return data;
  2412. }
  2413. catch (Exception ex)
  2414. {
  2415. if (cmd.Transaction != null)
  2416. cmd.Transaction.Rollback();
  2417. log.Error(ex.Message);
  2418. throw new Exception(ex.Message);
  2419. }
  2420. finally
  2421. {
  2422. if (conn.State == ConnectionState.Open)
  2423. {
  2424. conn.Close();
  2425. }
  2426. conn.Dispose();
  2427. }
  2428. }
  2429. }
  2430. /// <summary>
  2431. /// 采购拒收
  2432. /// </summary>
  2433. /// <param name="JsonData"></param>
  2434. /// <returns></returns>
  2435. public static DataTable PurchaseRejectDocCreate(List<ICSDeliveryNotice> JsonData)
  2436. {
  2437. var language = LanguageHelper.GetName("WMSAPIInfo");
  2438. if (JsonData.Count <= 0)
  2439. {
  2440. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2441. }
  2442. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2443. {
  2444. conn.Open();
  2445. SqlTransaction sqlTran = conn.BeginTransaction();
  2446. SqlCommand cmd = new SqlCommand();
  2447. cmd.Transaction = sqlTran;
  2448. cmd.Connection = conn;
  2449. try
  2450. {
  2451. string lots = string.Empty;
  2452. string sql = string.Empty;
  2453. foreach (var item in JsonData)
  2454. {
  2455. if (string.IsNullOrEmpty(item.DNCode))
  2456. {
  2457. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  2458. }
  2459. //获取单号
  2460. sql = @"DECLARE @Status VARCHAR(10)
  2461. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' and DNType='1' and WorkPoint='{1}'
  2462. IF (@Status IS NULL)
  2463. BEGIN
  2464. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  2465. RETURN
  2466. END
  2467. ELSE IF (@Status!='2')
  2468. BEGIN
  2469. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  2470. RETURN
  2471. END
  2472. DECLARE @MaxNO INT,@date varchar(20)='RJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  2473. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  2474. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  2475. IF @MaxNO IS NULL
  2476. BEGIN
  2477. SELECT @date+'00001' AS Code
  2478. END
  2479. ELSE
  2480. BEGIN
  2481. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  2482. END ";
  2483. sql = string.Format(sql, item.DNCode, item.WorkPoint);
  2484. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2485. //修改送货单到货数量
  2486. foreach (var itemInfo in item.detail)
  2487. {
  2488. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  2489. BEGIN
  2490. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  2491. RETURN
  2492. END
  2493. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND DNType = '3' AND a.WorkPoint='{2}')
  2494. BEGIN
  2495. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  2496. RETURN
  2497. END
  2498. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  2499. DNType,InvCode,Quantity,Amount,RCVQuantity,
  2500. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  2501. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  2502. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  2503. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  2504. '3',d.InvCode,'{7}', '{8}', 0,
  2505. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  2506. a.DNID,a.DNDetailID, '0', '0', a.ExtensionID,
  2507. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, b.LOTNO,''
  2508. FROM ICSDeliveryNotice a
  2509. INNER JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  2510. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  2511. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  2512. INNER JOIN ICSPurchaseOrder n ON m.TransCode =n.POCode AND m.TransSequence=n.Sequence AND a.PODetailID=n.PODetailID AND m.WorkPoint=n.WorkPoint
  2513. INNER JOIN ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
  2514. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  2515. WHERE a.DNCode='{0}' and b.LOTNO='{1}' AND a.WorkPoint='{2}'";
  2516. 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);
  2517. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2518. {
  2519. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  2520. }
  2521. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  2522. }
  2523. ICSPurchaseService.PurchaseRejectDocInNewERP(item.DNCode, Code, item.WorkPoint, cmd, language);
  2524. }
  2525. if (string.IsNullOrWhiteSpace(lots))
  2526. {
  2527. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  2528. }
  2529. #region 查询返回数据
  2530. sql = @"SELECT
  2531. n.DNCode,
  2532. n.Sequence,
  2533. a.DNCode AS RJTCode,
  2534. a.Sequence AS RJTSequence,
  2535. a.VenCode,
  2536. a.DepCode,
  2537. a.InvCode,
  2538. inv.InvName,
  2539. inv.InvStd,
  2540. a.Quantity,
  2541. inv.InvUnit,
  2542. a.Amount,
  2543. inv.AmountUnit,
  2544. a.RCVQuantity,
  2545. a.UnitPrice,
  2546. a.Currency,
  2547. a.POID,
  2548. a.PODetailID,
  2549. a.DNID,
  2550. a.DNDetailID,
  2551. ext.ProjectCode,
  2552. ext.BatchCode,
  2553. ext.Version,
  2554. ext.Brand,
  2555. ext.cFree1,
  2556. ext.cFree2,
  2557. ext.cFree3,
  2558. ext.cFree4,
  2559. ext.cFree5,
  2560. ext.cFree6,
  2561. ext.cFree7,
  2562. ext.cFree8,
  2563. ext.cFree9,
  2564. ext.cFree10,
  2565. a.MUSER AS [User],
  2566. a.MTIME AS [MTime]
  2567. FROM ICSDeliveryNotice a
  2568. INNER JOIN ICSDeliveryNotice n ON a.POID =n.DNID AND a.PODetailID=n.DNDetailID AND a.WorkPoint=n.WorkPoint
  2569. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2570. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2571. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  2572. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  2573. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2574. #endregion
  2575. cmd.Transaction.Commit();
  2576. return data;
  2577. }
  2578. catch (Exception ex)
  2579. {
  2580. if (cmd.Transaction != null)
  2581. cmd.Transaction.Rollback();
  2582. log.Error(ex.Message);
  2583. throw new Exception(ex.Message);
  2584. }
  2585. finally
  2586. {
  2587. if (conn.State == ConnectionState.Open)
  2588. {
  2589. conn.Close();
  2590. }
  2591. conn.Dispose();
  2592. }
  2593. }
  2594. }
  2595. #endregion
  2596. #region 委外
  2597. /// <summary>
  2598. /// 委外退料 新建
  2599. /// </summary>
  2600. /// <param name="JsonData"></param>
  2601. /// <returns></returns>
  2602. public static DataTable OutsourcingIssueDoNegativeApplyCreate(List<ICSOApplyNeg> JsonData)
  2603. {
  2604. var language = LanguageHelper.GetName("WMSAPIInfo");
  2605. if (JsonData.Count <= 0)
  2606. {
  2607. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2608. }
  2609. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2610. {
  2611. conn.Open();
  2612. SqlTransaction sqlTran = conn.BeginTransaction();
  2613. SqlCommand cmd = new SqlCommand();
  2614. cmd.Transaction = sqlTran;
  2615. cmd.Connection = conn;
  2616. try
  2617. {
  2618. string codes = string.Empty;
  2619. string sql = string.Empty;
  2620. foreach (var item in JsonData)
  2621. {
  2622. //获取单号
  2623. sql = @"DECLARE @MaxNO INT,@date varchar(20)='OOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  2624. SELECT @MaxNO=SUBSTRING(MAX(OApplyNegCode),LEN(@date)+1,LEN(MAX(OApplyNegCode))-LEN(@date))+1 FROM ICSOApplyNeg
  2625. WHERE SUBSTRING(OApplyNegCode, 1, LEN(@date))=@date
  2626. IF @MaxNO IS NULL
  2627. BEGIN
  2628. SELECT @date+'00001' AS Code
  2629. END
  2630. ELSE
  2631. BEGIN
  2632. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  2633. END ";
  2634. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2635. //创建主表
  2636. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  2637. BEGIN
  2638. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2639. RETURN
  2640. END
  2641. INSERT INTO ICSOApplyNeg(ID,OApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2642. 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}','')";
  2643. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  2644. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2645. {
  2646. throw new Exception(language.GetNameByCode("WMSAPIInfo014"));//"委外退料单信息创建失败!");
  2647. }
  2648. foreach (var itemInfo in item.detail)
  2649. {
  2650. //创建子表
  2651. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  2652. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  2653. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  2654. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  2655. '{4}','{5}',0,'{6}','{7}',
  2656. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  2657. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  2658. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2659. {
  2660. throw new Exception(language.GetNameByCode("WMSAPIInfo015"));//"委外退料单子表信息创建失败!");
  2661. }
  2662. }
  2663. //校验退料数量是否超出领料数量
  2664. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  2665. DBHelper.ExecuteNonQuery(sql, cmd);
  2666. codes += "'" + Code + item.WorkPoint + "',";
  2667. }
  2668. if (string.IsNullOrWhiteSpace(codes))
  2669. {
  2670. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  2671. }
  2672. #region 查询返回数据
  2673. sql = @"SELECT a.OApplyNegCode,
  2674. c.WHCode,
  2675. c.Memo,
  2676. d.Name AS Status,
  2677. a.Sequence,
  2678. a.InvCode,
  2679. inv.InvName,
  2680. inv.InvStd,
  2681. a.Quantity,
  2682. inv.InvUnit,
  2683. a.Amount,
  2684. inv.AmountUnit,
  2685. a.IssueNegQuantity,
  2686. ext.ProjectCode,
  2687. ext.BatchCode,
  2688. ext.Version,
  2689. ext.Brand,
  2690. ext.cFree1,
  2691. ext.cFree2,
  2692. ext.cFree3,
  2693. ext.cFree4,
  2694. ext.cFree5,
  2695. ext.cFree6,
  2696. ext.cFree7,
  2697. ext.cFree8,
  2698. ext.cFree9,
  2699. ext.cFree10,
  2700. a.MUSER AS [User],
  2701. a.MTIME AS [MTime]
  2702. FROM ICSOApplyNegDetail a
  2703. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2704. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  2705. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2706. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2707. WHERE a.OApplyNegCode+a.WorkPoint IN ({0})";
  2708. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  2709. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2710. #endregion
  2711. cmd.Transaction.Commit();
  2712. return data;
  2713. }
  2714. catch (Exception ex)
  2715. {
  2716. if (cmd.Transaction != null)
  2717. cmd.Transaction.Rollback();
  2718. log.Error(ex.Message);
  2719. throw new Exception(ex.Message);
  2720. }
  2721. finally
  2722. {
  2723. if (conn.State == ConnectionState.Open)
  2724. {
  2725. conn.Close();
  2726. }
  2727. conn.Dispose();
  2728. }
  2729. }
  2730. }
  2731. private static string CheckOutsourcingIssueDoc(string Type, string Code, string WorkPoint, Dictionary<string, string> language)
  2732. {
  2733. string sql = string.Empty;
  2734. if (Type == "1")
  2735. {
  2736. sql = @"DECLARE @PickID VARCHAR(10)
  2737. SELECT @PickID=b.PickID
  2738. FROM ICSOApplyNegDetail a
  2739. INNER JOIN ICSOOPick b ON a.SourceDetailID=b.PickID AND a.WorkPoint=b.WorkPoint
  2740. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2741. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  2742. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  2743. FROM ICSOApplyNegDetail a
  2744. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2745. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  2746. GROUP BY b.PickID
  2747. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  2748. IF (@PickID IS NOT NULL)
  2749. BEGIN
  2750. DECLARE @InvCode VARCHAR(100)
  2751. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOOPick WHERE PickID=@PickID AND WorkPoint='{1}'
  2752. RAISERROR(@InvCode,16,1);
  2753. RETURN
  2754. END ";
  2755. }
  2756. else if (Type == "2")
  2757. {
  2758. sql = @"DECLARE @ApplyDetailID VARCHAR(10)
  2759. SELECT @ApplyDetailID=b.ApplyDetailID
  2760. FROM ICSOApplyNegDetail a
  2761. INNER JOIN ICSOApply b ON a.SourceDetailID=b.ApplyDetailID AND a.WorkPoint=b.WorkPoint
  2762. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2763. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  2764. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  2765. FROM ICSOApplyNegDetail a
  2766. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2767. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  2768. GROUP BY b.ApplyDetailID
  2769. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  2770. IF (@ApplyDetailID IS NOT NULL)
  2771. BEGIN
  2772. DECLARE @InvCode VARCHAR(100)
  2773. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOApply WHERE ApplyDetailID=@ApplyDetailID AND WorkPoint='{1}'
  2774. RAISERROR(@InvCode,16,1);
  2775. RETURN
  2776. END ";
  2777. }
  2778. else if (Type == "3")
  2779. {
  2780. sql = @"DECLARE @IssueDetailID VARCHAR(10)
  2781. SELECT @IssueDetailID=b.IssueDetailID
  2782. FROM ICSOApplyNegDetail a
  2783. INNER JOIN ICSOIssue b ON a.SourceDetailID=b.IssueDetailID AND a.WorkPoint=b.WorkPoint
  2784. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2785. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  2786. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  2787. FROM ICSOApplyNegDetail a
  2788. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2789. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  2790. GROUP BY b.IssueDetailID
  2791. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  2792. IF (@IssueDetailID IS NOT NULL)
  2793. BEGIN
  2794. DECLARE @InvCode VARCHAR(100)
  2795. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOIssue WHERE IssueDetailID=@IssueDetailID AND WorkPoint='{1}'
  2796. RAISERROR(@InvCode,16,1);
  2797. RETURN
  2798. END ";
  2799. }
  2800. else
  2801. {
  2802. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  2803. }
  2804. sql = string.Format(sql, Code, WorkPoint, Type);
  2805. return sql;
  2806. }
  2807. /// <summary>
  2808. /// 委外退料 修改
  2809. /// </summary>
  2810. /// <param name="JsonData"></param>
  2811. /// <returns></returns>
  2812. public static DataTable OutsourcingIssueDoNegativeApplyUpdate(List<ICSOApplyNeg> JsonData)
  2813. {
  2814. var language = LanguageHelper.GetName("WMSAPIInfo");
  2815. if (JsonData.Count <= 0)
  2816. {
  2817. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2818. }
  2819. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2820. {
  2821. conn.Open();
  2822. SqlTransaction sqlTran = conn.BeginTransaction();
  2823. SqlCommand cmd = new SqlCommand();
  2824. cmd.Transaction = sqlTran;
  2825. cmd.Connection = conn;
  2826. try
  2827. {
  2828. string sql = string.Empty;
  2829. string Code = string.Empty;
  2830. string ids = string.Empty;
  2831. foreach (var item in JsonData)
  2832. {
  2833. //主表修改
  2834. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  2835. BEGIN
  2836. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  2837. RETURN
  2838. END
  2839. DECLARE @Status VARCHAR(10)
  2840. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  2841. IF (@Status IS NULL)
  2842. BEGIN
  2843. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  2844. RETURN
  2845. END
  2846. ELSE IF (@Status!='1')
  2847. BEGIN
  2848. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  2849. RETURN
  2850. END
  2851. 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}' ";
  2852. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.id, item.WorkPoint);
  2853. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2854. {
  2855. throw new Exception(language.GetNameByCode("WMSAPIInfo016"));//"委外退料单信息修改失败!");
  2856. }
  2857. var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  2858. if (detail > 0)
  2859. {
  2860. sql = @"SELECT OApplyNegCode FROM ICSOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  2861. sql = string.Format(sql, item.id, item.WorkPoint);
  2862. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2863. }
  2864. foreach (var itemInfo in item.detail)
  2865. {
  2866. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  2867. {
  2868. //创建子表
  2869. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  2870. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  2871. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  2872. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  2873. '{4}','{5}',0,'{6}','{7}',
  2874. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  2875. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  2876. }
  2877. else
  2878. {
  2879. //子表修改
  2880. 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}'";
  2881. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  2882. }
  2883. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2884. {
  2885. throw new Exception(language.GetNameByCode("WMSAPIInfo017"));//"委外退料单子表信息修改失败!");
  2886. }
  2887. }
  2888. //校验退料数量是否超出领料数量
  2889. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  2890. DBHelper.ExecuteNonQuery(sql, cmd);
  2891. ids += "'" + item.id + "',";
  2892. }
  2893. if (string.IsNullOrWhiteSpace(ids))
  2894. {
  2895. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  2896. }
  2897. #region 查询返回数据
  2898. sql = @"SELECT a.OApplyNegCode,
  2899. c.WHCode,
  2900. c.Memo,
  2901. d.Name AS Status,
  2902. a.Sequence,
  2903. a.InvCode,
  2904. inv.InvName,
  2905. inv.InvStd,
  2906. a.Quantity,
  2907. inv.InvUnit,
  2908. a.Amount,
  2909. inv.AmountUnit,
  2910. a.IssueNegQuantity,
  2911. ext.ProjectCode,
  2912. ext.BatchCode,
  2913. ext.Version,
  2914. ext.Brand,
  2915. ext.cFree1,
  2916. ext.cFree2,
  2917. ext.cFree3,
  2918. ext.cFree4,
  2919. ext.cFree5,
  2920. ext.cFree6,
  2921. ext.cFree7,
  2922. ext.cFree8,
  2923. ext.cFree9,
  2924. ext.cFree10,
  2925. a.MUSER AS [User],
  2926. a.MTIME AS [MTime]
  2927. FROM ICSOApplyNegDetail a
  2928. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2929. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  2930. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2931. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2932. WHERE c.ID IN ({0})";
  2933. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  2934. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2935. #endregion
  2936. cmd.Transaction.Commit();
  2937. return data;
  2938. }
  2939. catch (Exception ex)
  2940. {
  2941. if (cmd.Transaction != null)
  2942. cmd.Transaction.Rollback();
  2943. log.Error(ex.Message);
  2944. throw new Exception(ex.Message);
  2945. }
  2946. finally
  2947. {
  2948. if (conn.State == ConnectionState.Open)
  2949. {
  2950. conn.Close();
  2951. }
  2952. conn.Dispose();
  2953. }
  2954. }
  2955. }
  2956. /// <summary>
  2957. /// 委外退料审核
  2958. /// </summary>
  2959. /// <param name="JsonData"></param>
  2960. /// <returns></returns>
  2961. public static DataTable OutsourcingIssueDoNegativeApplyApprove(List<ICSUser> JsonData)
  2962. {
  2963. var language = LanguageHelper.GetName("WMSAPIInfo");
  2964. if (JsonData.Count <= 0)
  2965. {
  2966. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2967. }
  2968. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2969. {
  2970. conn.Open();
  2971. SqlTransaction sqlTran = conn.BeginTransaction();
  2972. SqlCommand cmd = new SqlCommand();
  2973. cmd.Transaction = sqlTran;
  2974. cmd.Connection = conn;
  2975. try
  2976. {
  2977. string sql = string.Empty;
  2978. string ids = string.Empty;
  2979. foreach (var item in JsonData)
  2980. {
  2981. if (string.IsNullOrEmpty(item.ID))
  2982. {
  2983. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  2984. }
  2985. if (string.IsNullOrEmpty(item.User))
  2986. {
  2987. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  2988. }
  2989. if (item.MTime <= new DateTime(2000, 1, 1))
  2990. {
  2991. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  2992. }
  2993. //获取单号
  2994. sql = @"DECLARE @Status VARCHAR(10)
  2995. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{0}'
  2996. IF (@Status IS NULL)
  2997. BEGIN
  2998. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  2999. RETURN
  3000. END
  3001. ELSE IF (@Status!='1')
  3002. BEGIN
  3003. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  3004. RETURN
  3005. END
  3006. update ICSOApplyNeg set Status='2',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  3007. sql = string.Format(sql, item.ID, item.User, item.MTime);
  3008. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3009. {
  3010. throw new Exception(language.GetNameByCode("WMSAPIInfo021"));//"委外退料申请单审核失败!");
  3011. }
  3012. ids += "'" + item.ID + "',";
  3013. }
  3014. if (string.IsNullOrWhiteSpace(ids))
  3015. {
  3016. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  3017. }
  3018. #region 查询返回数据
  3019. sql = @"SELECT a.OApplyNegCode,
  3020. c.WHCode,
  3021. c.Memo,
  3022. d.Name AS Status,
  3023. a.Sequence,
  3024. a.InvCode,
  3025. inv.InvName,
  3026. inv.InvStd,
  3027. a.Quantity,
  3028. inv.InvUnit,
  3029. a.Amount,
  3030. inv.AmountUnit,
  3031. a.IssueNegQuantity,
  3032. ext.ProjectCode,
  3033. ext.BatchCode,
  3034. ext.Version,
  3035. ext.Brand,
  3036. ext.cFree1,
  3037. ext.cFree2,
  3038. ext.cFree3,
  3039. ext.cFree4,
  3040. ext.cFree5,
  3041. ext.cFree6,
  3042. ext.cFree7,
  3043. ext.cFree8,
  3044. ext.cFree9,
  3045. ext.cFree10,
  3046. a.MUSER AS [User],
  3047. a.MTIME AS [MTime]
  3048. FROM ICSOApplyNegDetail a
  3049. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3050. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3051. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3052. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3053. WHERE c.ID IN ({0})";
  3054. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  3055. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3056. #endregion
  3057. cmd.Transaction.Commit();
  3058. return data;
  3059. }
  3060. catch (Exception ex)
  3061. {
  3062. if (cmd.Transaction != null)
  3063. cmd.Transaction.Rollback();
  3064. log.Error(ex.Message);
  3065. throw new Exception(ex.Message);
  3066. }
  3067. finally
  3068. {
  3069. if (conn.State == ConnectionState.Open)
  3070. {
  3071. conn.Close();
  3072. }
  3073. conn.Dispose();
  3074. }
  3075. }
  3076. }
  3077. /// <summary>
  3078. /// 委外到货
  3079. /// </summary>
  3080. /// <param name="JsonData"></param>
  3081. /// <returns></returns>
  3082. public static DataTable OutsourcingDeliveryNoticeCreate(List<ICSDeliveryNotice> JsonData)
  3083. {
  3084. var language = LanguageHelper.GetName("WMSAPIInfo");
  3085. if (JsonData.Count <= 0)
  3086. {
  3087. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3088. }
  3089. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3090. {
  3091. conn.Open();
  3092. SqlTransaction sqlTran = conn.BeginTransaction();
  3093. SqlCommand cmd = new SqlCommand();
  3094. cmd.Transaction = sqlTran;
  3095. cmd.Connection = conn;
  3096. try
  3097. {
  3098. string asncodes = string.Empty;
  3099. string sql = string.Empty;
  3100. foreach (var item in JsonData)
  3101. {
  3102. if (string.IsNullOrEmpty(item.OASNCode))
  3103. {
  3104. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!");
  3105. }
  3106. //获取单号
  3107. sql = @"IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.OASNCode='{0}' AND ODNType = '1' AND a.WorkPoint='{1}')
  3108. BEGIN
  3109. RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  3110. RETURN
  3111. END
  3112. DECLARE @Status VARCHAR(10)
  3113. SELECT @Status=Status FROM ICSOASN WHERE OASNCode='{0}' and WorkPoint='{1}'
  3114. IF (@Status IS NULL)
  3115. BEGIN
  3116. RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  3117. RETURN
  3118. END
  3119. ELSE IF (@Status!='2')
  3120. BEGIN
  3121. RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  3122. RETURN
  3123. END
  3124. DECLARE @MaxNO INT,@date varchar(20)='ODN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3125. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  3126. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  3127. IF @MaxNO IS NULL
  3128. BEGIN
  3129. SELECT @date+'00001' AS Code
  3130. END
  3131. ELSE
  3132. BEGIN
  3133. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3134. END ";
  3135. sql = string.Format(sql, item.OASNCode, item.WorkPoint);
  3136. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3137. //修改送货单到货数量
  3138. foreach (var itemInfo in item.detail)
  3139. {
  3140. sql = @"UPDATE ICSOASNDetail SET ODNQuantity=ISNULL(ODNQuantity, 0)+'{2}'
  3141. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  3142. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  3143. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3144. {
  3145. throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"委外送货单子表信息更新失败!");
  3146. }
  3147. }
  3148. //创建到货单信息
  3149. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  3150. BEGIN
  3151. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  3152. RETURN
  3153. END
  3154. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  3155. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  3156. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  3157. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  3158. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  3159. SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
  3160. '1',b.InvCode,SUM(a.ODNQuantity),'0','0',
  3161. d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
  3162. d.OOID,d.OODetailID,newid(),newid(),b.ExtensionID,
  3163. e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.OASNCode
  3164. FROM ICSOASNDetail a
  3165. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3166. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  3167. INNER JOIN ICSOutsourcingOrder d ON c.TransCode=d.OOCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  3168. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  3169. WHERE a.OASNCode='{3}' AND a.WorkPoint='{2}'
  3170. 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";
  3171. sql = string.Format(sql, Code, item.User, item.WorkPoint, item.OASNCode);
  3172. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3173. {
  3174. throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
  3175. }
  3176. ICSOutsourcingService.OutsourcingDeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
  3177. asncodes += "'" + item.OASNCode + item.WorkPoint + "',";
  3178. }
  3179. if (string.IsNullOrWhiteSpace(asncodes))
  3180. {
  3181. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
  3182. }
  3183. #region 查询返回数据
  3184. sql = @"SELECT
  3185. n.OOCode,
  3186. n.Sequence AS OOSequence,
  3187. a.OASNCode,
  3188. a.ODNCode,
  3189. a.Sequence,
  3190. a.VenCode,
  3191. a.DepCode,
  3192. a.InvCode,
  3193. inv.InvName,
  3194. inv.InvStd,
  3195. a.Quantity,
  3196. inv.InvUnit,
  3197. a.Amount,
  3198. inv.AmountUnit,
  3199. a.RCVQuantity,
  3200. a.UnitPrice,
  3201. a.Currency,
  3202. a.OOID,
  3203. a.OODetailID,
  3204. a.ODNID,
  3205. a.ODNDetailID,
  3206. ext.ProjectCode,
  3207. ext.BatchCode,
  3208. ext.Version,
  3209. ext.Brand,
  3210. ext.cFree1,
  3211. ext.cFree2,
  3212. ext.cFree3,
  3213. ext.cFree4,
  3214. ext.cFree5,
  3215. ext.cFree6,
  3216. ext.cFree7,
  3217. ext.cFree8,
  3218. ext.cFree9,
  3219. ext.cFree10,
  3220. a.MUSER AS [User],
  3221. a.MTIME AS [MTime]
  3222. FROM ICSODeliveryNotice a
  3223. INNER JOIN ICSOutsourcingOrder n ON a.OOID =n.OOID AND a.OODetailID=n.OODetailID AND a.WorkPoint=n.WorkPoint
  3224. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3225. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3226. WHERE a.OASNCode+a.WorkPoint IN ({0})";
  3227. sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
  3228. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3229. #endregion
  3230. cmd.Transaction.Commit();
  3231. return data;
  3232. }
  3233. catch (Exception ex)
  3234. {
  3235. if (cmd.Transaction != null)
  3236. cmd.Transaction.Rollback();
  3237. log.Error(ex.Message);
  3238. throw new Exception(ex.Message);
  3239. }
  3240. finally
  3241. {
  3242. if (conn.State == ConnectionState.Open)
  3243. {
  3244. conn.Close();
  3245. }
  3246. conn.Dispose();
  3247. }
  3248. }
  3249. }
  3250. /// <summary>
  3251. /// 委外拒收
  3252. /// </summary>
  3253. /// <param name="JsonData"></param>
  3254. /// <returns></returns>
  3255. public static DataTable OutsourcingRejectDocCreate(List<ICSDeliveryNotice> JsonData)
  3256. {
  3257. var language = LanguageHelper.GetName("WMSAPIInfo");
  3258. if (JsonData.Count <= 0)
  3259. {
  3260. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3261. }
  3262. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3263. {
  3264. conn.Open();
  3265. SqlTransaction sqlTran = conn.BeginTransaction();
  3266. SqlCommand cmd = new SqlCommand();
  3267. cmd.Transaction = sqlTran;
  3268. cmd.Connection = conn;
  3269. try
  3270. {
  3271. string lots = string.Empty;
  3272. string sql = string.Empty;
  3273. foreach (var item in JsonData)
  3274. {
  3275. if (string.IsNullOrEmpty(item.ODNCode))
  3276. {
  3277. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  3278. }
  3279. //获取单号
  3280. sql = @"DECLARE @Status VARCHAR(10)
  3281. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' and ODNType='1' and WorkPoint='{1}'
  3282. IF (@Status IS NULL)
  3283. BEGIN
  3284. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  3285. RETURN
  3286. END
  3287. ELSE IF (@Status!='2')
  3288. BEGIN
  3289. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  3290. RETURN
  3291. END
  3292. DECLARE @MaxNO INT,@date varchar(20)='ORJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3293. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  3294. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  3295. IF @MaxNO IS NULL
  3296. BEGIN
  3297. SELECT @date+'00001' AS Code
  3298. END
  3299. ELSE
  3300. BEGIN
  3301. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3302. END ";
  3303. sql = string.Format(sql, item.ODNCode, item.WorkPoint);
  3304. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3305. //修改送货单到货数量
  3306. foreach (var itemInfo in item.detail)
  3307. {
  3308. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  3309. BEGIN
  3310. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  3311. RETURN
  3312. END
  3313. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND ODNType = '3' AND a.WorkPoint='{2}')
  3314. BEGIN
  3315. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  3316. RETURN
  3317. END
  3318. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  3319. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  3320. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  3321. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  3322. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  3323. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  3324. '3',d.InvCode,'{7}', '{8}', 0,
  3325. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  3326. a.ODNID,a.ODNDetailID, '0', '0', a.ExtensionID,
  3327. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, b.LOTNO,''
  3328. FROM ICSODeliveryNotice a
  3329. INNER JOIN ICSOASNDetail b ON a.OASNCode=b.OASNCode AND a.WorkPoint=b.WorkPoint
  3330. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  3331. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  3332. INNER JOIN ICSOutsourcingOrder n ON m.TransCode =n.OOCode AND m.TransSequence=n.Sequence AND a.OODetailID=n.OODetailID AND m.WorkPoint=n.WorkPoint
  3333. INNER JOIN ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
  3334. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  3335. WHERE a.ODNCode='{0}' and b.LOTNO='{1}' AND a.WorkPoint='{2}'";
  3336. 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);
  3337. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3338. {
  3339. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  3340. }
  3341. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  3342. }
  3343. ICSOutsourcingService.OutsourcingRejectDocInNewERP(item.ODNCode, Code, item.WorkPoint, cmd, language);
  3344. }
  3345. if (string.IsNullOrWhiteSpace(lots))
  3346. {
  3347. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  3348. }
  3349. #region 查询返回数据
  3350. sql = @"SELECT
  3351. n.ODNCode,
  3352. n.Sequence,
  3353. a.ODNCode AS RJTCode,
  3354. a.Sequence AS RJTSequence,
  3355. a.VenCode,
  3356. a.DepCode,
  3357. a.InvCode,
  3358. inv.InvName,
  3359. inv.InvStd,
  3360. a.Quantity,
  3361. inv.InvUnit,
  3362. a.Amount,
  3363. inv.AmountUnit,
  3364. a.RCVQuantity,
  3365. a.UnitPrice,
  3366. a.Currency,
  3367. a.OOID,
  3368. a.OODetailID,
  3369. a.ODNID,
  3370. a.ODNDetailID,
  3371. ext.ProjectCode,
  3372. ext.BatchCode,
  3373. ext.Version,
  3374. ext.Brand,
  3375. ext.cFree1,
  3376. ext.cFree2,
  3377. ext.cFree3,
  3378. ext.cFree4,
  3379. ext.cFree5,
  3380. ext.cFree6,
  3381. ext.cFree7,
  3382. ext.cFree8,
  3383. ext.cFree9,
  3384. ext.cFree10,
  3385. a.MUSER AS [User],
  3386. a.MTIME AS [MTime]
  3387. FROM ICSODeliveryNotice a
  3388. INNER JOIN ICSODeliveryNotice n ON a.OOID =n.ODNID AND a.OODetailID=n.ODNDetailID AND a.WorkPoint=n.WorkPoint
  3389. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3390. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3391. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  3392. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  3393. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3394. #endregion
  3395. cmd.Transaction.Commit();
  3396. return data;
  3397. }
  3398. catch (Exception ex)
  3399. {
  3400. if (cmd.Transaction != null)
  3401. cmd.Transaction.Rollback();
  3402. log.Error(ex.Message);
  3403. throw new Exception(ex.Message);
  3404. }
  3405. finally
  3406. {
  3407. if (conn.State == ConnectionState.Open)
  3408. {
  3409. conn.Close();
  3410. }
  3411. conn.Dispose();
  3412. }
  3413. }
  3414. }
  3415. #endregion
  3416. #region 生产
  3417. /// <summary>
  3418. /// 生产退料 新建
  3419. /// </summary>
  3420. /// <param name="JsonData"></param>
  3421. /// <returns></returns>
  3422. public static DataTable MOIssueDocNegativeApplyCreate(List<ICSMOApplyNeg> JsonData)
  3423. {
  3424. var language = LanguageHelper.GetName("WMSAPIInfo");
  3425. if (JsonData.Count <= 0)
  3426. {
  3427. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3428. }
  3429. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3430. {
  3431. conn.Open();
  3432. SqlTransaction sqlTran = conn.BeginTransaction();
  3433. SqlCommand cmd = new SqlCommand();
  3434. cmd.Transaction = sqlTran;
  3435. cmd.Connection = conn;
  3436. try
  3437. {
  3438. string codes = string.Empty;
  3439. string sql = string.Empty;
  3440. foreach (var item in JsonData)
  3441. {
  3442. //获取单号
  3443. sql = @"DECLARE @MaxNO INT,@date varchar(20)='MOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3444. SELECT @MaxNO=SUBSTRING(MAX(ApplyNegCode),LEN(@date)+1,LEN(MAX(ApplyNegCode))-LEN(@date))+1 FROM ICSMOApplyNeg
  3445. WHERE SUBSTRING(ApplyNegCode, 1, LEN(@date))=@date
  3446. IF @MaxNO IS NULL
  3447. BEGIN
  3448. SELECT @date+'00001' AS Code
  3449. END
  3450. ELSE
  3451. BEGIN
  3452. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3453. END ";
  3454. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3455. //创建主表
  3456. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  3457. BEGIN
  3458. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3459. RETURN
  3460. END
  3461. INSERT INTO ICSMOApplyNeg(ID,ApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  3462. 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}','')";
  3463. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  3464. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3465. {
  3466. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产退料单信息创建失败!");
  3467. }
  3468. foreach (var itemInfo in item.detail)
  3469. {
  3470. //创建子表
  3471. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,
  3472. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  3473. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  3474. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  3475. '{4}','{5}',0,'{6}','{7}',
  3476. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  3477. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  3478. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3479. {
  3480. throw new Exception(language.GetNameByCode("WMSAPIInfo023"));//"生产退料单子表信息创建失败!");
  3481. }
  3482. }
  3483. //校验退料数量是否超出领料数量
  3484. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  3485. DBHelper.ExecuteNonQuery(sql, cmd);
  3486. codes += "'" + Code + item.WorkPoint + "',";
  3487. }
  3488. if (string.IsNullOrWhiteSpace(codes))
  3489. {
  3490. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  3491. }
  3492. #region 查询返回数据
  3493. sql = @"SELECT a.ApplyNegCode,
  3494. c.WHCode,
  3495. c.Memo,
  3496. d.Name AS Status,
  3497. a.Sequence,
  3498. a.InvCode,
  3499. inv.InvName,
  3500. inv.InvStd,
  3501. a.Quantity,
  3502. inv.InvUnit,
  3503. a.Amount,
  3504. inv.AmountUnit,
  3505. a.IssueNegQuantity,
  3506. ext.ProjectCode,
  3507. ext.BatchCode,
  3508. ext.Version,
  3509. ext.Brand,
  3510. ext.cFree1,
  3511. ext.cFree2,
  3512. ext.cFree3,
  3513. ext.cFree4,
  3514. ext.cFree5,
  3515. ext.cFree6,
  3516. ext.cFree7,
  3517. ext.cFree8,
  3518. ext.cFree9,
  3519. ext.cFree10,
  3520. a.MUSER AS [User],
  3521. a.MTIME AS [MTime]
  3522. FROM ICSMOApplyNegDetail a
  3523. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3524. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3525. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3526. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3527. WHERE a.ApplyNegCode+a.WorkPoint IN ({0})";
  3528. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  3529. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3530. #endregion
  3531. cmd.Transaction.Commit();
  3532. return data;
  3533. }
  3534. catch (Exception ex)
  3535. {
  3536. if (cmd.Transaction != null)
  3537. cmd.Transaction.Rollback();
  3538. log.Error(ex.Message);
  3539. throw new Exception(ex.Message);
  3540. }
  3541. finally
  3542. {
  3543. if (conn.State == ConnectionState.Open)
  3544. {
  3545. conn.Close();
  3546. }
  3547. conn.Dispose();
  3548. }
  3549. }
  3550. }
  3551. private static string CheckMOIssueDoc(string Type, string ID, string WorkPoint, Dictionary<string, string> language)
  3552. {
  3553. string sql = string.Empty;
  3554. if (Type == "1")
  3555. {
  3556. sql = @"DECLARE @PickID VARCHAR(10)
  3557. SELECT @PickID=b.PickID
  3558. FROM ICSMOApplyNegDetail a
  3559. INNER JOIN ICSMOPick b ON a.SourceDetailID=b.PickID AND a.WorkPoint=b.WorkPoint
  3560. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3561. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3562. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3563. FROM ICSMOApplyNegDetail a
  3564. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3565. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3566. GROUP BY b.PickID
  3567. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3568. IF (@PickID IS NOT NULL)
  3569. BEGIN
  3570. DECLARE @InvCode VARCHAR(100)
  3571. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOPick WHERE PickID=@PickID AND WorkPoint='{1}'
  3572. RAISERROR(@InvCode,16,1);
  3573. RETURN
  3574. END ";
  3575. }
  3576. else if (Type == "2")
  3577. {
  3578. sql = @"DECLARE @ApplyDetailID VARCHAR(10)
  3579. SELECT @ApplyDetailID=b.ApplyDetailID
  3580. FROM ICSMOApplyNegDetail a
  3581. INNER JOIN ICSMOApply b ON a.SourceDetailID=b.ApplyDetailID AND a.WorkPoint=b.WorkPoint
  3582. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3583. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3584. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3585. FROM ICSMOApplyNegDetail a
  3586. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3587. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3588. GROUP BY b.ApplyDetailID
  3589. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3590. IF (@ApplyDetailID IS NOT NULL)
  3591. BEGIN
  3592. DECLARE @InvCode VARCHAR(100)
  3593. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOApply WHERE ApplyDetailID=@ApplyDetailID AND WorkPoint='{1}'
  3594. RAISERROR(@InvCode,16,1);
  3595. RETURN
  3596. END ";
  3597. }
  3598. else if (Type == "3")
  3599. {
  3600. sql = @"DECLARE @IssueDetailID VARCHAR(10)
  3601. SELECT @IssueDetailID=b.IssueDetailID
  3602. FROM ICSMOApplyNegDetail a
  3603. INNER JOIN ICSMOIssue b ON a.SourceDetailID=b.IssueDetailID AND a.WorkPoint=b.WorkPoint
  3604. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3605. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3606. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3607. FROM ICSMOApplyNegDetail a
  3608. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3609. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3610. GROUP BY b.IssueDetailID
  3611. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3612. IF (@IssueDetailID IS NOT NULL)
  3613. BEGIN
  3614. DECLARE @InvCode VARCHAR(100)
  3615. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOIssue WHERE IssueDetailID=@IssueDetailID AND WorkPoint='{1}'
  3616. RAISERROR(@InvCode,16,1);
  3617. RETURN
  3618. END ";
  3619. }
  3620. else
  3621. {
  3622. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  3623. }
  3624. sql = string.Format(sql, ID, WorkPoint, Type);
  3625. return sql;
  3626. }
  3627. /// <summary>
  3628. /// 生产退料 修改
  3629. /// </summary>
  3630. /// <param name="JsonData"></param>
  3631. /// <returns></returns>
  3632. public static DataTable MOIssueDocNegativeApplyUpdate(List<ICSMOApplyNeg> JsonData)
  3633. {
  3634. var language = LanguageHelper.GetName("WMSAPIInfo");
  3635. if (JsonData.Count <= 0)
  3636. {
  3637. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3638. }
  3639. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3640. {
  3641. conn.Open();
  3642. SqlTransaction sqlTran = conn.BeginTransaction();
  3643. SqlCommand cmd = new SqlCommand();
  3644. cmd.Transaction = sqlTran;
  3645. cmd.Connection = conn;
  3646. try
  3647. {
  3648. string sql = string.Empty;
  3649. string Code = string.Empty;
  3650. string ids = string.Empty;
  3651. foreach (var item in JsonData)
  3652. {
  3653. //主表修改
  3654. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  3655. BEGIN
  3656. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  3657. RETURN
  3658. END
  3659. DECLARE @Status VARCHAR(10)
  3660. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  3661. IF (@Status IS NULL)
  3662. BEGIN
  3663. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  3664. RETURN
  3665. END
  3666. ELSE IF (@Status!='1')
  3667. BEGIN
  3668. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  3669. RETURN
  3670. END
  3671. 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}' ";
  3672. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.ID, item.WorkPoint);
  3673. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3674. {
  3675. throw new Exception(language.GetNameByCode("WMSAPIInfo024"));//"生产退料单信息修改失败!");
  3676. }
  3677. var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  3678. if (detail > 0)
  3679. {
  3680. sql = @"SELECT ApplyNegCode FROM ICSMOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  3681. sql = string.Format(sql, item.ID, item.WorkPoint);
  3682. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3683. }
  3684. foreach (var itemInfo in item.detail)
  3685. {
  3686. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  3687. {
  3688. //创建子表
  3689. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  3690. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  3691. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  3692. '{4}','{5}',0,'{6}','{7}',
  3693. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  3694. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  3695. }
  3696. else
  3697. {
  3698. //子表修改
  3699. 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}'";
  3700. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  3701. }
  3702. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3703. {
  3704. throw new Exception(language.GetNameByCode("WMSAPIInfo025"));//"生产退料单子表信息修改失败!");
  3705. }
  3706. }
  3707. //校验退料数量是否超出领料数量
  3708. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  3709. DBHelper.ExecuteNonQuery(sql, cmd);
  3710. ids += "'" + item.ID + "',";
  3711. }
  3712. if (string.IsNullOrWhiteSpace(ids))
  3713. {
  3714. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  3715. }
  3716. #region 查询返回数据
  3717. sql = @"SELECT a.ApplyNegCode,
  3718. c.WHCode,
  3719. c.Memo,
  3720. d.Name AS Status,
  3721. a.Sequence,
  3722. a.InvCode,
  3723. inv.InvName,
  3724. inv.InvStd,
  3725. a.Quantity,
  3726. inv.InvUnit,
  3727. a.Amount,
  3728. inv.AmountUnit,
  3729. a.IssueNegQuantity,
  3730. ext.ProjectCode,
  3731. ext.BatchCode,
  3732. ext.Version,
  3733. ext.Brand,
  3734. ext.cFree1,
  3735. ext.cFree2,
  3736. ext.cFree3,
  3737. ext.cFree4,
  3738. ext.cFree5,
  3739. ext.cFree6,
  3740. ext.cFree7,
  3741. ext.cFree8,
  3742. ext.cFree9,
  3743. ext.cFree10,
  3744. a.MUSER AS [User],
  3745. a.MTIME AS [MTime]
  3746. FROM ICSMOApplyNegDetail a
  3747. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3748. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3749. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3750. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3751. WHERE c.ID IN ({0})";
  3752. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  3753. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3754. #endregion
  3755. cmd.Transaction.Commit();
  3756. return data;
  3757. }
  3758. catch (Exception ex)
  3759. {
  3760. if (cmd.Transaction != null)
  3761. cmd.Transaction.Rollback();
  3762. log.Error(ex.Message);
  3763. throw new Exception(ex.Message);
  3764. }
  3765. finally
  3766. {
  3767. if (conn.State == ConnectionState.Open)
  3768. {
  3769. conn.Close();
  3770. }
  3771. conn.Dispose();
  3772. }
  3773. }
  3774. }
  3775. /// <summary>
  3776. /// 生产退料审核
  3777. /// </summary>
  3778. /// <param name="JsonData"></param>
  3779. /// <returns></returns>
  3780. public static DataTable MOIssueDocNegativeApplyApprove(List<ICSUser> JsonData)
  3781. {
  3782. var language = LanguageHelper.GetName("WMSAPIInfo");
  3783. if (JsonData.Count <= 0)
  3784. {
  3785. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3786. }
  3787. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3788. {
  3789. conn.Open();
  3790. SqlTransaction sqlTran = conn.BeginTransaction();
  3791. SqlCommand cmd = new SqlCommand();
  3792. cmd.Transaction = sqlTran;
  3793. cmd.Connection = conn;
  3794. try
  3795. {
  3796. string sql = string.Empty;
  3797. string ids = string.Empty;
  3798. foreach (var item in JsonData)
  3799. {
  3800. if (string.IsNullOrEmpty(item.ID))
  3801. {
  3802. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  3803. }
  3804. if (string.IsNullOrEmpty(item.User))
  3805. {
  3806. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  3807. }
  3808. if (item.MTime <= new DateTime(2000, 1, 1))
  3809. {
  3810. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  3811. }
  3812. //获取单号
  3813. sql = @"DECLARE @Status VARCHAR(10)
  3814. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{0}'
  3815. IF (@Status IS NULL)
  3816. BEGIN
  3817. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  3818. RETURN
  3819. END
  3820. ELSE IF (@Status!='1')
  3821. BEGIN
  3822. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  3823. RETURN
  3824. END
  3825. update ICSMOApplyNeg set Status='2',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  3826. sql = string.Format(sql, item.ID, item.User, item.MTime);
  3827. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3828. {
  3829. throw new Exception(language.GetNameByCode("WMSAPIInfo026"));//"生产退料申请单审核失败!");
  3830. }
  3831. ids += "'" + item.ID + "',";
  3832. }
  3833. if (string.IsNullOrWhiteSpace(ids))
  3834. {
  3835. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  3836. }
  3837. #region 查询返回数据
  3838. sql = @"SELECT a.ApplyNegCode,
  3839. c.WHCode,
  3840. c.Memo,
  3841. d.Name AS Status,
  3842. a.Sequence,
  3843. a.InvCode,
  3844. inv.InvName,
  3845. inv.InvStd,
  3846. a.Quantity,
  3847. inv.InvUnit,
  3848. a.Amount,
  3849. inv.AmountUnit,
  3850. a.IssueNegQuantity,
  3851. ext.ProjectCode,
  3852. ext.BatchCode,
  3853. ext.Version,
  3854. ext.Brand,
  3855. ext.cFree1,
  3856. ext.cFree2,
  3857. ext.cFree3,
  3858. ext.cFree4,
  3859. ext.cFree5,
  3860. ext.cFree6,
  3861. ext.cFree7,
  3862. ext.cFree8,
  3863. ext.cFree9,
  3864. ext.cFree10,
  3865. a.MUSER AS [User],
  3866. a.MTIME AS [MTime]
  3867. FROM ICSMOApplyNegDetail a
  3868. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3869. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3870. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3871. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3872. WHERE c.ID IN ({0})";
  3873. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  3874. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3875. #endregion
  3876. cmd.Transaction.Commit();
  3877. return data;
  3878. }
  3879. catch (Exception ex)
  3880. {
  3881. if (cmd.Transaction != null)
  3882. cmd.Transaction.Rollback();
  3883. log.Error(ex.Message);
  3884. throw new Exception(ex.Message);
  3885. }
  3886. finally
  3887. {
  3888. if (conn.State == ConnectionState.Open)
  3889. {
  3890. conn.Close();
  3891. }
  3892. conn.Dispose();
  3893. }
  3894. }
  3895. }
  3896. #endregion
  3897. #region 一步调拨
  3898. /// <summary>
  3899. /// 一步调拨
  3900. /// </summary>
  3901. /// <param name="JsonData"></param>
  3902. /// <returns></returns>
  3903. public static DataTable OneStepTransferDocIn(List<TransferDoc> JsonData)
  3904. {
  3905. var language = LanguageHelper.GetName("WMSAPIInfo");
  3906. if (JsonData.Count <= 0)
  3907. {
  3908. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3909. }
  3910. DataTable printTable = new DataTable();
  3911. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3912. {
  3913. conn.Open();
  3914. SqlTransaction sqlTran = conn.BeginTransaction();
  3915. SqlCommand cmd = new SqlCommand();
  3916. cmd.Transaction = sqlTran;
  3917. cmd.Connection = conn;
  3918. try
  3919. {
  3920. string sql = string.Empty;
  3921. string Identification = Guid.NewGuid().ToString();
  3922. foreach (var item in JsonData)
  3923. {
  3924. if (string.IsNullOrEmpty(item.TransCode))
  3925. {
  3926. throw new Exception(language.GetNameByCode("WMSAPIInfo027"));//"调拨单号不能为空!");
  3927. }
  3928. string[] trans = item.TransCode.Split('~');
  3929. string MergeID = "";
  3930. if (trans.Length == 2)
  3931. {
  3932. MergeID = trans[0];
  3933. item.TransCode = trans[1];
  3934. }
  3935. //验证信息
  3936. sql = @"DECLARE @Status VARCHAR(10)
  3937. SELECT @Status=Status FROM ICSTransfer WHERE TransferNO='{0}' and WorkPoint='{1}' AND Type = '1'
  3938. IF (@Status IS NULL)
  3939. BEGIN
  3940. RAISERROR('" + language.GetNameByCode("WMSAPIInfo067") + @"',16,1);
  3941. RETURN
  3942. END
  3943. ELSE IF (@Status!='1')
  3944. BEGIN
  3945. RAISERROR('" + language.GetNameByCode("WMSAPIInfo068") + @"',16,1);
  3946. RETURN
  3947. END";
  3948. sql = string.Format(sql, item.TransCode, item.WorkPoint);
  3949. DBHelper.ExecuteNonQuery(sql, cmd);
  3950. foreach (var itemInfo in item.Detail)
  3951. {
  3952. //验证仓库库位信息
  3953. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  3954. BEGIN
  3955. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  3956. RETURN
  3957. END
  3958. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  3959. BEGIN
  3960. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  3961. RETURN
  3962. END
  3963. IF NOT EXISTS(SELECT a.ID
  3964. FROM ICSWareHouse a
  3965. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  3966. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  3967. BEGIN
  3968. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  3969. RETURN
  3970. END";
  3971. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  3972. DBHelper.ExecuteNonQuery(sql, cmd);
  3973. //更新源头单据信息
  3974. ICSWareHouseService.OneStepTransferDocIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity, cmd, language);
  3975. //更新条码信息
  3976. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  3977. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "6", TransTypeEnum.OneStepTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  3978. }
  3979. }
  3980. ICSWareHouseService.OneStepTransferDocInERP(TransTypeEnum.OneStepTransferDocIn.GetDescription(), Identification, cmd, language);
  3981. if (!printTable.Equals("{}"))
  3982. {
  3983. cmd.Transaction.Commit();
  3984. return printTable;
  3985. }
  3986. else
  3987. {
  3988. DataTable table = GetData(Identification, 3, cmd);
  3989. cmd.Transaction.Commit();
  3990. return table;
  3991. }
  3992. }
  3993. catch (Exception ex)
  3994. {
  3995. if (cmd.Transaction != null)
  3996. cmd.Transaction.Rollback();
  3997. log.Error(ex.Message);
  3998. throw new Exception(ex.Message);
  3999. }
  4000. finally
  4001. {
  4002. if (conn.State == ConnectionState.Open)
  4003. {
  4004. conn.Close();
  4005. }
  4006. conn.Dispose();
  4007. }
  4008. }
  4009. }
  4010. #endregion
  4011. #region 调拨
  4012. /// <summary>
  4013. /// 调拨
  4014. /// </summary>
  4015. /// <param name="JsonData"></param>
  4016. /// <returns></returns>
  4017. public static DataTable TransferDocCreate(List<TransferDoc> JsonData)
  4018. {
  4019. var language = LanguageHelper.GetName("WMSAPIInfo");
  4020. if (JsonData.Count <= 0)
  4021. {
  4022. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4023. }
  4024. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4025. {
  4026. conn.Open();
  4027. SqlTransaction sqlTran = conn.BeginTransaction();
  4028. SqlCommand cmd = new SqlCommand();
  4029. cmd.Transaction = sqlTran;
  4030. cmd.Connection = conn;
  4031. try
  4032. {
  4033. string sql = string.Empty;
  4034. string Identification = Guid.NewGuid().ToString();
  4035. foreach (var item in JsonData)
  4036. {
  4037. string MergeID = "";
  4038. foreach (var itemInfo in item.Detail)
  4039. {
  4040. //验证仓库库位信息
  4041. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  4042. BEGIN
  4043. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  4044. RETURN
  4045. END
  4046. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  4047. BEGIN
  4048. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  4049. RETURN
  4050. END
  4051. IF NOT EXISTS(SELECT a.ID
  4052. FROM ICSWareHouse a
  4053. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  4054. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  4055. BEGIN
  4056. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  4057. RETURN
  4058. END";
  4059. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  4060. DBHelper.ExecuteNonQuery(sql, cmd);
  4061. //更新条码信息
  4062. ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  4063. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "6", TransTypeEnum.StepTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  4064. }
  4065. }
  4066. ICSWareHouseService.StepTransferDocInERP(TransTypeEnum.StepTransferDocIn.GetDescription(), Identification, cmd, language);
  4067. DataTable table = GetData(Identification, 3, cmd);
  4068. cmd.Transaction.Commit();
  4069. return table;
  4070. }
  4071. catch (Exception ex)
  4072. {
  4073. if (cmd.Transaction != null)
  4074. cmd.Transaction.Rollback();
  4075. log.Error(ex.Message);
  4076. throw new Exception(ex.Message);
  4077. }
  4078. finally
  4079. {
  4080. if (conn.State == ConnectionState.Open)
  4081. {
  4082. conn.Close();
  4083. }
  4084. conn.Dispose();
  4085. }
  4086. }
  4087. }
  4088. #endregion
  4089. #region 移库
  4090. /// <summary>
  4091. /// 移库
  4092. /// </summary>
  4093. /// <param name="JsonData"></param>
  4094. /// <returns></returns>
  4095. public static DataTable LibraryUpdate(List<ICSLibraryModel> JsonData)
  4096. {
  4097. var language = LanguageHelper.GetName("WMSAPIInfo");
  4098. if (JsonData.Count <= 0)
  4099. {
  4100. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4101. }
  4102. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4103. {
  4104. conn.Open();
  4105. SqlTransaction sqlTran = conn.BeginTransaction();
  4106. SqlCommand cmd = new SqlCommand();
  4107. cmd.Transaction = sqlTran;
  4108. cmd.Connection = conn;
  4109. try
  4110. {
  4111. string sql = string.Empty;
  4112. string Identification = Guid.NewGuid().ToString();
  4113. foreach (var item in JsonData)
  4114. {
  4115. if (string.IsNullOrEmpty(item.LotNo))
  4116. {
  4117. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  4118. }
  4119. //验证仓库库位信息
  4120. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  4121. BEGIN
  4122. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  4123. RETURN
  4124. END
  4125. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  4126. BEGIN
  4127. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo072"), "{2}") + @"',16,1);
  4128. RETURN
  4129. END
  4130. IF NOT EXISTS(SELECT a.ID
  4131. FROM ICSWareHouse a
  4132. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  4133. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  4134. BEGIN
  4135. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  4136. RETURN
  4137. END";
  4138. sql = string.Format(sql, item.WarehouseCode, item.WorkPoint, item.LocationCode);
  4139. DBHelper.ExecuteNonQuery(sql, cmd);
  4140. //更新条码信息
  4141. ICSWareHouseLotInfoService.WareHouseLotInfoLibrary(Identification, item.TransCode, item.TransSequence, item.WarehouseCode, item.LocationCode, item.LotNo,
  4142. item.User, item.WorkPoint, "7", "29", cmd, language);
  4143. }
  4144. DataTable table = GetData(Identification, 3, cmd);
  4145. cmd.Transaction.Commit();
  4146. return table;
  4147. }
  4148. catch (Exception ex)
  4149. {
  4150. if (cmd.Transaction != null)
  4151. cmd.Transaction.Rollback();
  4152. log.Error(ex.Message);
  4153. throw new Exception(ex.Message);
  4154. }
  4155. finally
  4156. {
  4157. if (conn.State == ConnectionState.Open)
  4158. {
  4159. conn.Close();
  4160. }
  4161. conn.Dispose();
  4162. }
  4163. }
  4164. }
  4165. #endregion
  4166. #region 合并
  4167. /// <summary>
  4168. /// 合并
  4169. /// </summary>
  4170. /// <param name="JsonData"></param>
  4171. /// <returns></returns>
  4172. public static DataTable LOTMergeCreate(List<LOTCreateIModel> JsonData)
  4173. {
  4174. var language = LanguageHelper.GetName("WMSAPIInfo");
  4175. if (JsonData.Count <= 0)
  4176. {
  4177. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4178. }
  4179. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4180. {
  4181. conn.Open();
  4182. SqlTransaction sqlTran = conn.BeginTransaction();
  4183. SqlCommand cmd = new SqlCommand();
  4184. cmd.Transaction = sqlTran;
  4185. cmd.Connection = conn;
  4186. try
  4187. {
  4188. string Identification = Guid.NewGuid().ToString();
  4189. foreach (var item in JsonData)
  4190. {
  4191. if (string.IsNullOrEmpty(item.LotNo))
  4192. {
  4193. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  4194. }
  4195. else if (item.detail.Count <= 0)
  4196. {
  4197. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  4198. }
  4199. //合并前日志
  4200. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "5",
  4201. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(), cmd, language);
  4202. foreach (var info in item.detail)
  4203. {
  4204. //合并前日志
  4205. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, info.CurrentLotNo, item.User, item.WorkPoint, "5",
  4206. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(), cmd, language);
  4207. //更新条码信息
  4208. ICSWareHouseLotInfoService.WareHouseLotInfoMerge(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "5",
  4209. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  4210. }
  4211. //合并后日志
  4212. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "5",
  4213. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  4214. }
  4215. DataTable table = GetData(Identification, 1, cmd);
  4216. cmd.Transaction.Commit();
  4217. return table;
  4218. }
  4219. catch (Exception ex)
  4220. {
  4221. if (cmd.Transaction != null)
  4222. cmd.Transaction.Rollback();
  4223. log.Error(ex.Message);
  4224. throw new Exception(ex.Message);
  4225. }
  4226. finally
  4227. {
  4228. if (conn.State == ConnectionState.Open)
  4229. {
  4230. conn.Close();
  4231. }
  4232. conn.Dispose();
  4233. }
  4234. }
  4235. }
  4236. #endregion
  4237. #region 拆分
  4238. /// <summary>
  4239. /// 拆分
  4240. /// </summary>
  4241. /// <param name="JsonData"></param>
  4242. /// <returns></returns>
  4243. public static DataTable LOTSplitCreate(List<LOTCreateIModel> JsonData)
  4244. {
  4245. var language = LanguageHelper.GetName("WMSAPIInfo");
  4246. if (JsonData.Count <= 0)
  4247. {
  4248. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4249. }
  4250. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4251. {
  4252. conn.Open();
  4253. SqlTransaction sqlTran = conn.BeginTransaction();
  4254. SqlCommand cmd = new SqlCommand();
  4255. cmd.Transaction = sqlTran;
  4256. cmd.Connection = conn;
  4257. try
  4258. {
  4259. string Identification = Guid.NewGuid().ToString();
  4260. foreach (var item in JsonData)
  4261. {
  4262. if (string.IsNullOrEmpty(item.LotNo))
  4263. {
  4264. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  4265. }
  4266. else if (item.detail.Count <= 0)
  4267. {
  4268. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  4269. }
  4270. //拆分前日志
  4271. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  4272. TransTypeEnum.LOTSplitBefore.GetDescription<DBValue>(), cmd, language);
  4273. foreach (var info in item.detail)
  4274. {
  4275. //更新条码信息
  4276. ICSWareHouseLotInfoService.WareHouseLotInfoSplit(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "4",
  4277. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), cmd, language);
  4278. }
  4279. //拆分后日志
  4280. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  4281. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), cmd, language);
  4282. }
  4283. DataTable table = GetData(Identification, 1, cmd);
  4284. cmd.Transaction.Commit();
  4285. return table;
  4286. }
  4287. catch (Exception ex)
  4288. {
  4289. if (cmd.Transaction != null)
  4290. cmd.Transaction.Rollback();
  4291. log.Error(ex.Message);
  4292. throw new Exception(ex.Message);
  4293. }
  4294. finally
  4295. {
  4296. if (conn.State == ConnectionState.Open)
  4297. {
  4298. conn.Close();
  4299. }
  4300. conn.Dispose();
  4301. }
  4302. }
  4303. }
  4304. #endregion
  4305. /// <summary>
  4306. /// 获取出入库记录信息
  4307. /// </summary>
  4308. /// <param name="Identification"></param>
  4309. /// <param name="type">1:入库,2:出库,3:调拨</param>
  4310. /// <param name="cmd"></param>
  4311. /// <returns></returns>
  4312. private static DataTable GetData(string Identification, int type, SqlCommand cmd)
  4313. {
  4314. #region SLQ
  4315. string sql = @"SELECT log.ID,
  4316. log.TransCode,
  4317. log.TransSequence,
  4318. log.LotNo,
  4319. log.InvCode,
  4320. inv.InvName,
  4321. inv.InvStd,
  4322. log.Quantity,
  4323. inv.InvUnit,
  4324. log.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  4325. inv.AmountUnit,
  4326. {1}
  4327. ext.ProjectCode,
  4328. 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,
  4329. ext.Version,
  4330. ext.Brand,
  4331. ext.cFree1,
  4332. ext.cFree2,
  4333. ext.cFree3,
  4334. ext.cFree4,
  4335. ext.cFree5,
  4336. ext.cFree6,
  4337. ext.cFree7,
  4338. ext.cFree8,
  4339. ext.cFree9,
  4340. ext.cFree10,
  4341. type.Name AS TransType,
  4342. log.MUSER AS [User],
  4343. log.MTIME AS [MTime]
  4344. FROM ICSWareHouseLotInfoLog log
  4345. LEFT JOIN ICSType type ON type.TableCode='ICSWareHouseLotInfoLog' AND type.ColumnCode='BusinessCode' AND log.BusinessCode=type.Code AND log.WorkPoint=type.WorkPoint
  4346. INNER JOIN ICSInventoryLot lot ON log.LotNo=lot.LotNo AND log.WorkPoint=lot.WorkPoint
  4347. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4348. INNER JOIN ICSInventory inv ON log.InvCode=inv.InvCode AND log.WorkPoint=inv.WorkPoint
  4349. {2}
  4350. LEFT JOIN ICSInventoryBatchEnable invBat ON log.InvCode=invBat.InvCode AND log.FromWarehouseCode=invBat.WHCode AND log.WorkPoint=invBat.WorkPoint
  4351. WHERE log.Identification='{0}'";
  4352. #endregion
  4353. string columns = @"log.ToWarehouseCode AS WHCode,
  4354. log.ToLocationCode AS LocationCode,
  4355. wh.WarehouseName AS WHName,
  4356. loc.LocationName AS LocationName,";
  4357. string tables = @"INNER JOIN ICSWarehouse wh ON log.ToWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  4358. INNER JOIN ICSLocation loc ON log.ToLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint";
  4359. if (type == 2)//出库
  4360. {
  4361. columns = @"log.FromWarehouseCode AS WHCode,
  4362. log.FromLocationCode AS LocationCode,
  4363. wh.WarehouseName AS WHName,
  4364. loc.LocationName AS LocationName,";
  4365. tables = @"INNER JOIN ICSWarehouse wh ON log.FromWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  4366. INNER JOIN ICSLocation loc ON log.FromLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint";
  4367. }
  4368. else if (type == 3)//调拨
  4369. {
  4370. columns = @"log.FromWarehouseCode AS FromWHCode,
  4371. log.FromLocationCode,
  4372. wh.WarehouseName AS FromWHName,
  4373. loc.LocationName AS FromLocationName,
  4374. log.ToWarehouseCode AS ToWHCode,
  4375. log.ToLocationCode,
  4376. whto.WarehouseName AS ToWHName,
  4377. locto.LocationName AS ToLocationName,";
  4378. tables = @"INNER JOIN ICSWarehouse wh ON log.FromWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  4379. INNER JOIN ICSLocation loc ON log.FromLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint
  4380. INNER JOIN ICSWarehouse whto ON log.ToWarehouseCode=whto.WarehouseCode AND log.WorkPoint=whto.WorkPoint
  4381. INNER JOIN ICSLocation locto ON log.ToLocationCode=locto.LocationCode AND log.WorkPoint=locto.WorkPoint";
  4382. }
  4383. sql = string.Format(sql, Identification, columns, tables);
  4384. return DBHelper.SQlReturnData(sql, cmd);
  4385. }
  4386. /// <summary>
  4387. /// 先进先出批次管控
  4388. /// </summary>
  4389. /// <param name="LotNo"></param>
  4390. /// <param name="WorkPoitCode"></param>
  4391. /// <param name="cmd"></param>
  4392. /// <returns></returns>
  4393. public static string CanOut(string LotNo, string WorkPoitCode, string ScanLotCode, SqlCommand cmd, Dictionary<string, string> language)
  4394. {
  4395. try
  4396. {
  4397. //根据Sys_SRM_Items.F_Description备注列维护的提前天数,比如维护的是1,最早条码是2022.5.16,现在扫描2022.5.17的条码也能出库,扫描2022.5.18的条码不能直接出,需要校验以下逻辑
  4398. string sql = @"DECLARE @CountNO INT,@Days INT
  4399. SELECT @Days=F_Description FROM Sys_SRM_Items WHERE F_EnCode='FIFO'
  4400. SET @CountNO=(
  4401. SELECT COUNT(a.LotNO) FROM ICSWareHouseLotInfo a
  4402. INNER JOIN ICSInventoryLot b ON a.LotNO=b.LotNO AND a.WorkPoint=b.WorkPoint
  4403. WHERE a.WorkPoint='{1}' AND ISNULL(a.Quantity,0)>0 AND 1=1
  4404. AND CONVERT(varchar(100), a.InDate, 23)<
  4405. (SELECT DATEADD(DAY, -@Days, CONVERT(varchar(100), x.InDate, 23)) FROM ICSWareHouseLotInfo x
  4406. INNER JOIN ICSInventoryLot y ON x.LotNO=y.LotNO AND x.WorkPoint=y.WorkPoint
  4407. WHERE x.LotNO='{0}' AND x.WorkPoint='{1}' AND y.INVCode=b.INVCode AND y.ExtensionID=b.ExtensionID)
  4408. )
  4409. IF @CountNO>0
  4410. BEGIN
  4411. SELECT TOP 1 CASE a.F_ItemCode WHEN 'FIFO01' THEN '1' WHEN 'FIFO02' THEN '2' ELSE '3' END AS Type
  4412. FROM Sys_SRM_ItemsDetail a
  4413. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  4414. WHERE b.F_EnCode='FIFO' AND a.F_EnabledMark='1'
  4415. ORDER BY a.F_SortCode DESC
  4416. END
  4417. ELSE
  4418. BEGIN
  4419. SELECT @CountNO
  4420. END";
  4421. //0 - 已经是最早的批次
  4422. //1 - 不管控
  4423. //2 - 提醒
  4424. //3 - 限制
  4425. sql = string.Format(sql, LotNo, WorkPoitCode);
  4426. if (!string.IsNullOrWhiteSpace(ScanLotCode))
  4427. {
  4428. sql = sql.Replace("1=1", "a.LotNO NOT IN (" + ScanLotCode + ")");
  4429. }
  4430. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  4431. if (string.IsNullOrWhiteSpace(res))
  4432. {
  4433. throw new Exception(language.GetNameByCode("WMSAPIInfo183"));//"查询管控信息失败!");
  4434. }
  4435. else
  4436. return res;
  4437. }
  4438. catch (Exception ex)
  4439. {
  4440. throw new Exception(ex.Message);
  4441. }
  4442. }
  4443. /// <summary>
  4444. /// 保质期管控
  4445. /// </summary>
  4446. /// <param name="LotNo"></param>
  4447. /// <param name="WorkPoitCode"></param>
  4448. /// <param name="cmd"></param>
  4449. /// <returns></returns>
  4450. public static string Effective(string LotNo, string WorkPoitCode, SqlCommand cmd, Dictionary<string, string> language)
  4451. {
  4452. try
  4453. {
  4454. string sql = @"DECLARE @CountNO INT,@Days INT,@CurrentDays INT
  4455. SELECT @CountNO=EffectiveEnable,@Days=EffectiveDays,@CurrentDays=DATEDIFF(DAY, GETDATE(), b.ExpirationDate) FROM ICSInventory a
  4456. INNER JOIN ICSInventoryLot b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  4457. INNER JOIN ICSWareHouseLotInfo c ON b.LotNO=c.LotNO AND b.WorkPoint=c.WorkPoint
  4458. WHERE b.LotNO='{0}' AND b.WorkPoint='{1}'
  4459. IF @CountNO='1' AND @CurrentDays<0
  4460. BEGIN
  4461. SELECT TOP 1 CASE a.F_ItemCode WHEN 'Effective01' THEN '1' WHEN 'Effective02' THEN '2' ELSE '3' END AS Type
  4462. FROM Sys_SRM_ItemsDetail a
  4463. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  4464. WHERE b.F_EnCode='Effective' AND a.F_EnabledMark='1'
  4465. ORDER BY a.F_SortCode DESC
  4466. END
  4467. ELSE
  4468. BEGIN
  4469. SELECT @CountNO
  4470. END";
  4471. //0 - 已经是最早的批次
  4472. //1 - 不管控
  4473. //2 - 提醒
  4474. //3 - 限制
  4475. sql = string.Format(sql, LotNo, WorkPoitCode);
  4476. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  4477. if (string.IsNullOrWhiteSpace(res))
  4478. {
  4479. throw new Exception(language.GetNameByCode("WMSAPIInfo183"));//"查询管控信息失败!");
  4480. }
  4481. else
  4482. return res;
  4483. }
  4484. catch (Exception ex)
  4485. {
  4486. throw new Exception(ex.Message);
  4487. }
  4488. }
  4489. #region 包装
  4490. /// <summary>
  4491. /// 查询包装信息
  4492. /// </summary>
  4493. /// <param name="JsonData"></param>
  4494. /// <returns></returns>
  4495. public static object ContainerGet(ICSContainer JsonData)
  4496. {
  4497. var language = LanguageHelper.GetName("WMSAPIInfo");
  4498. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4499. {
  4500. conn.Open();
  4501. SqlTransaction sqlTran = conn.BeginTransaction();
  4502. SqlCommand cmd = new SqlCommand();
  4503. cmd.Transaction = sqlTran;
  4504. cmd.Connection = conn;
  4505. try
  4506. {
  4507. string sql = string.Empty;
  4508. //目标包装
  4509. if (JsonData.ToContainerCode != null)
  4510. {
  4511. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  4512. BEGIN
  4513. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  4514. RETURN
  4515. END
  4516. SELECT ContainerCode,ContainerName FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}'";
  4517. sql = string.Format(sql, JsonData.ToContainerCode, JsonData.WorkPoint);
  4518. }
  4519. ///原包装
  4520. else if (JsonData.FromContainerCode != null)
  4521. {
  4522. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  4523. BEGIN
  4524. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  4525. RETURN
  4526. END
  4527. IF NOT EXISTS(SELECT a.ID FROM ICSContainer a
  4528. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  4529. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}')
  4530. BEGIN
  4531. RAISERROR('" + language.GetNameByCode("WMSAPIInfo073") + @"',16,1);
  4532. RETURN
  4533. END
  4534. SELECT ContainerCode,ContainerName FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}'";
  4535. sql = string.Format(sql, JsonData.FromContainerCode, JsonData.WorkPoint);
  4536. }
  4537. else
  4538. {
  4539. throw new Exception(language.GetNameByCode("WMSAPIInfo029"));//"请传入包装条码!");
  4540. }
  4541. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  4542. cmd.Transaction.Commit();
  4543. return table;
  4544. }
  4545. catch (Exception ex)
  4546. {
  4547. if (cmd.Transaction != null)
  4548. cmd.Transaction.Rollback();
  4549. log.Error(ex.Message);
  4550. throw new Exception(ex.Message);
  4551. }
  4552. finally
  4553. {
  4554. if (conn.State == ConnectionState.Open)
  4555. {
  4556. conn.Close();
  4557. }
  4558. conn.Dispose();
  4559. }
  4560. }
  4561. }
  4562. /// <summary>
  4563. /// 修改包装信息
  4564. /// </summary>
  4565. /// <param name="JsonData"></param>
  4566. /// <returns></returns>
  4567. public static DataTable ContainerUpdate(List<ICSContainer> JsonData)
  4568. {
  4569. var language = LanguageHelper.GetName("WMSAPIInfo");
  4570. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4571. {
  4572. conn.Open();
  4573. SqlTransaction sqlTran = conn.BeginTransaction();
  4574. SqlCommand cmd = new SqlCommand();
  4575. cmd.Transaction = sqlTran;
  4576. cmd.Connection = conn;
  4577. try
  4578. {
  4579. string sql = string.Empty;
  4580. string codes = string.Empty;
  4581. foreach (ICSContainer container in JsonData)
  4582. {
  4583. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  4584. BEGIN
  4585. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  4586. RETURN
  4587. END
  4588. IF NOT EXISTS(SELECT a.ID FROM ICSContainer a
  4589. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  4590. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}')
  4591. BEGIN
  4592. RAISERROR('" + language.GetNameByCode("WMSAPIInfo073") + @"',16,1);
  4593. RETURN
  4594. END
  4595. IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{2}' and WorkPoint='{1}')
  4596. BEGIN
  4597. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo072"), "{2}") + @"',16,1);
  4598. RETURN
  4599. END
  4600. UPDATE b SET ContainerID=c.ID
  4601. FROM ICSContainer a
  4602. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  4603. INNER JOIN ICSContainer c ON c.ContainerCODE ='{2}' and a.WorkPoint=c.WorkPoint
  4604. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}'";
  4605. sql = string.Format(sql, container.FromContainerCode, container.WorkPoint, container.ToContainerCode);
  4606. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4607. {
  4608. throw new Exception(language.GetNameByCode("WMSAPIInfo030"));//"包装更新失败!");
  4609. }
  4610. codes += "'" + container.ToContainerCode + container.WorkPoint + "',";
  4611. }
  4612. sql = @"SELECT a.ContainerCode, a.ContainerName,b.LotNo FROM ICSContainer a
  4613. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  4614. WHERE a.ContainerCODE+a.WorkPoint IN({0})";
  4615. sql = string.Format(sql, codes.Substring(0,codes.Length - 1));
  4616. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  4617. cmd.Transaction.Commit();
  4618. return table;
  4619. }
  4620. catch (Exception ex)
  4621. {
  4622. if (cmd.Transaction != null)
  4623. cmd.Transaction.Rollback();
  4624. log.Error(ex.Message);
  4625. throw new Exception(ex.Message);
  4626. }
  4627. finally
  4628. {
  4629. if (conn.State == ConnectionState.Open)
  4630. {
  4631. conn.Close();
  4632. }
  4633. conn.Dispose();
  4634. }
  4635. }
  4636. }
  4637. #endregion
  4638. #region 盘点
  4639. /// <summary>
  4640. /// 创建盘点单
  4641. /// </summary>
  4642. /// <param name="JsonData"></param>
  4643. /// <returns></returns>
  4644. public static DataTable CheckCreate(List<ICSCheck> JsonData)
  4645. {
  4646. var language = LanguageHelper.GetName("WMSAPIInfo");
  4647. if (JsonData.Count <= 0)
  4648. {
  4649. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4650. }
  4651. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4652. {
  4653. conn.Open();
  4654. SqlTransaction sqlTran = conn.BeginTransaction();
  4655. SqlCommand cmd = new SqlCommand();
  4656. cmd.Transaction = sqlTran;
  4657. cmd.Connection = conn;
  4658. try
  4659. {
  4660. string Code = string.Empty;
  4661. string sql = string.Empty;
  4662. foreach (var item in JsonData)
  4663. {
  4664. if (string.IsNullOrEmpty(item.User))
  4665. {
  4666. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"操作人不能为空!");
  4667. }
  4668. if (string.IsNullOrEmpty(item.WorkPoint))
  4669. {
  4670. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  4671. }
  4672. //获取单号
  4673. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
  4674. BEGIN
  4675. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  4676. RETURN
  4677. END
  4678. DECLARE @MaxNO INT,@date varchar(20)='CHK'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  4679. SELECT @MaxNO=SUBSTRING(MAX(CheckCode),LEN(@date)+1,LEN(MAX(CheckCode))-LEN(@date))+1 FROM ICSCheck
  4680. WHERE SUBSTRING(CheckCode, 1, LEN(@date))=@date
  4681. IF @MaxNO IS NULL
  4682. BEGIN
  4683. SELECT @date+'00001' AS Code
  4684. END
  4685. ELSE
  4686. BEGIN
  4687. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  4688. END ";
  4689. sql = string.Format(sql, item.User, item.WorkPoint);
  4690. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  4691. //创建盘点单
  4692. foreach (var itemInfo in item.detail)
  4693. {
  4694. int len = itemInfo.SelectLevel.Length;
  4695. sql = @"IF NOT EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE SUBSTRING(LocationCode,1,{4}) = '{1}')
  4696. BEGIN
  4697. RAISERROR('" + language.GetNameByCode("WMSAPIInfo460") + @"',16,1);
  4698. RETURN
  4699. END
  4700. INSERT INTO ICSCheck (ID,CheckCode,SelectLevel,Status,Quantity,Amount,MUSER,MUSERName,MTIME,WorkPoint)
  4701. SELECT NEWID(),'{0}','{1}','2',SUM(a.Quantity),0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location
  4702. FROM ICSWareHouseLotInfo a
  4703. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  4704. WHERE SUBSTRING(a.LocationCode,1,{4}) = '{1}'
  4705. GROUP BY b.F_Account,b.F_RealName,b.F_Location";
  4706. sql = string.Format(sql, Code, itemInfo.SelectLevel, item.User, item.WorkPoint, len);
  4707. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4708. {
  4709. throw new Exception(language.GetNameByCode("WMSAPIInfo031"));//"盘点单创建失败!");
  4710. }
  4711. }
  4712. }
  4713. if (string.IsNullOrWhiteSpace(Code))
  4714. {
  4715. throw new Exception(language.GetNameByCode("WMSAPIInfo032"));//"盘点单单号不能为空!");
  4716. }
  4717. #region 查询返回数据
  4718. sql = @"SELECT a.ID,a.CheckCode,a.SelectLevel,
  4719. a.Quantity,
  4720. a.Amount,
  4721. a.MUSER AS [User],
  4722. a.MTIME AS [MTime]
  4723. FROM ICSCheck a
  4724. WHERE a.CheckCode='{0}'";
  4725. sql = string.Format(sql, Code);
  4726. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4727. #endregion
  4728. cmd.Transaction.Commit();
  4729. return data;
  4730. }
  4731. catch (Exception ex)
  4732. {
  4733. if (cmd.Transaction != null)
  4734. cmd.Transaction.Rollback();
  4735. log.Error(ex.Message);
  4736. throw new Exception(ex.Message);
  4737. }
  4738. finally
  4739. {
  4740. if (conn.State == ConnectionState.Open)
  4741. {
  4742. conn.Close();
  4743. }
  4744. conn.Dispose();
  4745. }
  4746. }
  4747. }
  4748. /// <summary>
  4749. /// 盘点扫描
  4750. /// </summary>
  4751. /// <param name="JsonData"></param>
  4752. /// <returns></returns>
  4753. public static DataTable LOTCheckCreate(List<ICSCheck> JsonData)
  4754. {
  4755. var language = LanguageHelper.GetName("WMSAPIInfo");
  4756. if (JsonData.Count <= 0)
  4757. {
  4758. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4759. }
  4760. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4761. {
  4762. conn.Open();
  4763. SqlTransaction sqlTran = conn.BeginTransaction();
  4764. SqlCommand cmd = new SqlCommand();
  4765. cmd.Transaction = sqlTran;
  4766. cmd.Connection = conn;
  4767. try
  4768. {
  4769. string lots = string.Empty;
  4770. string sql = string.Empty;
  4771. int result = 0;
  4772. string Identification = Guid.NewGuid().ToString();
  4773. foreach (var item in JsonData)
  4774. {
  4775. if (string.IsNullOrEmpty(item.User))
  4776. {
  4777. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"操作人不能为空!");
  4778. }
  4779. if (string.IsNullOrEmpty(item.WorkPoint))
  4780. {
  4781. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  4782. }
  4783. if (string.IsNullOrEmpty(item.CheckCode))
  4784. {
  4785. throw new Exception(language.GetNameByCode("WMSAPIInfo032"));//"盘点单号不能为空!");
  4786. }
  4787. //校验
  4788. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
  4789. BEGIN
  4790. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  4791. RETURN
  4792. END
  4793. IF NOT EXISTS(SELECT ID FROM ICSCheck WHERE CheckCode='{2}' AND WorkPoint='{1}')
  4794. BEGIN
  4795. RAISERROR('" + language.GetNameByCode("WMSAPIInfo075") + @"',16,1);
  4796. RETURN
  4797. END";
  4798. sql = string.Format(sql, item.User, item.WorkPoint, item.CheckCode);
  4799. DBHelper.ExecuteNonQuery(sql, cmd);
  4800. //创建盘点单
  4801. foreach (var itemInfo in item.detail)
  4802. {
  4803. sql = @"IF NOT EXISTS(SELECT LotNo FROM ICSWareHouseLotInfo WHERE LotNo='{1}' AND WorkPoint='{3}')
  4804. BEGIN
  4805. RAISERROR('" + language.GetNameByCode("WMSAPIInfo076") + @"',16,1);
  4806. RETURN
  4807. END
  4808. IF EXISTS(SELECT LotNo FROM ICSCheckDetail a
  4809. LEFT JOIN ICSCheck b ON a.CheckID=b.ID AND a.WorkPoint=b.WorkPoint
  4810. WHERE b.CheckCode='{0}' AND a.LotNo='{1}' AND a.WorkPoint='{3}')
  4811. BEGIN
  4812. IF ('{5}'='')
  4813. BEGIN
  4814. UPDATE a SET PrimaryQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE()
  4815. FROM ICSCheckDetail a
  4816. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  4817. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  4818. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  4819. END
  4820. ELSE IF ('{5}'='')
  4821. BEGIN
  4822. UPDATE a SET CheckQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE()
  4823. FROM ICSCheckDetail a
  4824. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  4825. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  4826. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  4827. END
  4828. ELSE
  4829. BEGIN
  4830. UPDATE a SET ReplayQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE()
  4831. FROM ICSCheckDetail a
  4832. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  4833. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  4834. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  4835. END
  4836. END
  4837. ELSE
  4838. BEGIN
  4839. IF ('{5}'='')
  4840. BEGIN
  4841. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint)
  4842. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','{4}','0','0','0','0','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  4843. FROM ICSWareHouseLotInfo a
  4844. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  4845. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  4846. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  4847. END
  4848. ELSE IF ('{5}'='')
  4849. BEGIN
  4850. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint)
  4851. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','0','0','0','0','{4}','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  4852. FROM ICSWareHouseLotInfo a
  4853. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  4854. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  4855. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  4856. END
  4857. ELSE
  4858. BEGIN
  4859. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint)
  4860. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','0','0','{4}','0','0','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  4861. FROM ICSWareHouseLotInfo a
  4862. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  4863. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  4864. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  4865. END
  4866. END";
  4867. sql = string.Format(sql, item.CheckCode, itemInfo.LotNo, item.User, item.WorkPoint, itemInfo.ActualQuantity, item.CheckKind);
  4868. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4869. {
  4870. throw new Exception(language.GetNameByCode("WMSAPIInfo033"));//"盘点扫描创建失败!");
  4871. }
  4872. #region 更新ICSCheckDetail表
  4873. //string strSql = @"UPDATE ICSCheckDetail Set";
  4874. //if (item.CheckKind == "初盘")
  4875. // strSql += @" PrimaryQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  4876. //else if (item.CheckKind == "复盘")
  4877. // strSql += @" ReplayQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  4878. //else
  4879. // strSql += @" CheckQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  4880. //strSql += @" where ToCheckNO='" + item.CheckCode + "' AND WorkPoint='" + item.WorkPoint + "'";
  4881. //cmd.CommandText = strSql;
  4882. //result = cmd.ExecuteNonQuery();
  4883. //if (result <= 0)
  4884. //{
  4885. // throw new Exception(language.GetNameByCode("WMSAPIInfo296"));//"盘点子表数量增加失败!");
  4886. //}
  4887. #endregion
  4888. #region 更新库存
  4889. if (item.UpdateWHLI)
  4890. {
  4891. ICSWareHouseLotInfoService.WareHouseLotInfoUpdate(Identification, item.CheckCode, "", itemInfo.LotNo, itemInfo.ActualQuantity, item.User, item.WorkPoint, TransTypeEnum.Check.GetDescription<DBValue>(), item.CheckKind, cmd, language);
  4892. }
  4893. #endregion
  4894. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  4895. }
  4896. if (string.IsNullOrWhiteSpace(lots))
  4897. {
  4898. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  4899. }
  4900. //sql = @"UPDATE a SET ActualQuantity=b.ActualQuantity
  4901. // FROM ICSCheck a
  4902. // 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
  4903. // WHERE a.CheckCode='{0}' and a.WorkPoint='{1}'";
  4904. //sql = string.Format(sql, item.CheckCode, item.WorkPoint, lots.Substring(0, lots.Length - 1));
  4905. //if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4906. //{
  4907. // throw new Exception(language.GetNameByCode("WMSAPIInfo034"));//"盘点扫描更新盘点单失败!");
  4908. //}
  4909. }
  4910. #region 查询返回数据
  4911. sql = @"SELECT x.ID,x.CheckID,y.WarehouseCode AS WHCode,x.LotNo,
  4912. y.InvCode,
  4913. inv.InvName,
  4914. inv.InvStd,
  4915. x.Quantity,x.PrimaryQuantity,x.PrimaryAmount,x.ReplayQuantity,x.ReplayAmount,x.CheckQuantity,x.CheckAmount,
  4916. inv.InvUnit,
  4917. x.MUSER AS [User],
  4918. x.MTIME AS [MTime]
  4919. FROM ICSCheckDetail x
  4920. INNER JOIN ICSWareHouseLotInfo y ON x.LotNo=y.LotNo AND x.WorkPoint=y.WorkPoint
  4921. INNER JOIN ICSInventory inv ON y.InvCode=inv.InvCode AND y.WorkPoint=inv.WorkPoint
  4922. WHERE x.LotNo+x.WorkPoint IN ({0})";
  4923. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  4924. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4925. #endregion
  4926. cmd.Transaction.Commit();
  4927. return data;
  4928. }
  4929. catch (Exception ex)
  4930. {
  4931. if (cmd.Transaction != null)
  4932. cmd.Transaction.Rollback();
  4933. log.Error(ex.Message);
  4934. throw new Exception(ex.Message);
  4935. }
  4936. finally
  4937. {
  4938. if (conn.State == ConnectionState.Open)
  4939. {
  4940. conn.Close();
  4941. }
  4942. conn.Dispose();
  4943. }
  4944. }
  4945. }
  4946. #endregion
  4947. #region 多语言
  4948. /// <summary>
  4949. /// 多语言查询
  4950. /// </summary>
  4951. /// <param name="JsonData"></param>
  4952. /// <returns></returns>
  4953. public static DataTable PromptInformationGet(WMSBarCoreModel JsonData)
  4954. {
  4955. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4956. {
  4957. conn.Open();
  4958. SqlCommand cmd = new SqlCommand();
  4959. cmd.Connection = conn;
  4960. try
  4961. {
  4962. string DefiniteLanguage = ICSDefiniteLanguageService.GetLanguage();
  4963. string sql = @"select " + DefiniteLanguage + " AS Name,Code from Sys_Language where 1=1";
  4964. if (!string.IsNullOrWhiteSpace(JsonData.Code))
  4965. {
  4966. sql += " and Code LIKE '%{0}%'";
  4967. }
  4968. sql = string.Format(sql, JsonData.Code);
  4969. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4970. return data;
  4971. }
  4972. catch (Exception ex)
  4973. {
  4974. log.Error(ex.Message);
  4975. throw new Exception(ex.Message);
  4976. }
  4977. finally
  4978. {
  4979. if (conn.State == ConnectionState.Open)
  4980. {
  4981. conn.Close();
  4982. }
  4983. conn.Dispose();
  4984. }
  4985. }
  4986. }
  4987. #endregion
  4988. #region 仓库/库位
  4989. /// <summary>
  4990. /// 仓库/库位
  4991. /// </summary>
  4992. /// <param name="JsonData"></param>
  4993. /// <returns></returns>
  4994. public static DataTable LocationGet(ICSLocation JsonData)
  4995. {
  4996. var language = LanguageHelper.GetName("WMSAPIInfo");
  4997. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4998. {
  4999. conn.Open();
  5000. SqlTransaction sqlTran = conn.BeginTransaction();
  5001. SqlCommand cmd = new SqlCommand();
  5002. cmd.Transaction = sqlTran;
  5003. cmd.Connection = conn;
  5004. try
  5005. {
  5006. string sql = @"IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a where LocationCode='{0}' AND a.WorkPoint='{1}')
  5007. BEGIN
  5008. RAISERROR('" + language.GetNameByCode("WMSAPIInfo070") + @"',16,1);
  5009. RETURN
  5010. END
  5011. 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}')
  5012. BEGIN
  5013. RAISERROR('" + language.GetNameByCode("WMSAPIInfo077") + @"',16,1);
  5014. RETURN
  5015. END
  5016. 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')
  5017. BEGIN
  5018. RAISERROR('" + language.GetNameByCode("WMSAPIInfo078") + @"',16,1);
  5019. RETURN
  5020. END
  5021. SELECT
  5022. LocationCode,
  5023. LocationName ,
  5024. WarehouseCode,
  5025. WarehouseName
  5026. FROM ICSLocation a
  5027. INNER JOIN ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where LocationCode='{0}' AND a.WorkPoint='{1}' and b.Enable='1'";
  5028. sql = string.Format(sql, JsonData.LocationCode, JsonData.WorkPoint);
  5029. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  5030. cmd.Transaction.Commit();
  5031. return data;
  5032. }
  5033. catch (Exception ex)
  5034. {
  5035. if (cmd.Transaction != null)
  5036. cmd.Transaction.Rollback();
  5037. log.Error(ex.Message);
  5038. throw new Exception(ex.Message);
  5039. }
  5040. finally
  5041. {
  5042. if (conn.State == ConnectionState.Open)
  5043. {
  5044. conn.Close();
  5045. }
  5046. conn.Dispose();
  5047. }
  5048. }
  5049. }
  5050. #endregion
  5051. #region 登陆
  5052. public static object CheckLogin(Sys_SRM_User userModel)
  5053. {
  5054. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5055. {
  5056. conn.Open();
  5057. SqlCommand cmd = new SqlCommand();
  5058. cmd.Connection = conn;
  5059. try
  5060. {
  5061. string sql = @"select F_Account from Sys_SRM_User where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";//已经启用的账号
  5062. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  5063. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  5064. if (dt != null && dt.Rows.Count > 0)//查询的数据不为空
  5065. {
  5066. sql = @" select a.[F_Id] as UserId
  5067. ,[F_Account] as userCode
  5068. ,[F_RealName] as UserName
  5069. ,[F_NickName]
  5070. ,b.F_UserPassword
  5071. ,b.F_UserSecretkey
  5072. ,[F_HeadIcon]
  5073. ,[F_Gender]
  5074. ,[F_Birthday]
  5075. ,[F_MobilePhone]
  5076. ,[F_Email]
  5077. ,[F_WeChat]
  5078. ,[F_ManagerId]
  5079. ,[F_SecurityLevel]
  5080. ,[F_Signature]
  5081. ,[F_OrganizeId]
  5082. ,[F_DepartmentId]
  5083. ,[F_RoleId]
  5084. ,[F_DutyId]
  5085. ,[F_IsAdministrator]
  5086. ,[F_SortCode]
  5087. ,[F_DeleteMark]
  5088. ,[F_EnabledMark]
  5089. ,[F_Description]
  5090. ,[F_CreatorTime]
  5091. ,[F_CreatorUserId]
  5092. ,[F_LastModifyTime]
  5093. ,[F_LastModifyUserId]
  5094. ,[F_DeleteTime]
  5095. ,[F_DeleteUserId]
  5096. ,[F_Location] as WorkPoint
  5097. ,[F_VenCode]
  5098. from Sys_SRM_User a
  5099. left join Sys_SRM_UserLogOn b on b.F_UserId=a.F_Id
  5100. where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";
  5101. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  5102. dt = DBHelper.SQlReturnData(sql, cmd);
  5103. IList<UserLogOnEntity> users = DBHelper.ModelConvertHelper<UserLogOnEntity>.ConvertToModel(dt);
  5104. // string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  5105. foreach (var item in users)
  5106. {
  5107. //string UserPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower()),16).ToLower();
  5108. string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  5109. if (dbPassword == item.F_UserPassword)
  5110. {
  5111. string json = JsonConvert.SerializeObject(dt);
  5112. List<Sys_SRM_User> userLogOnEntity = JsonConvert.DeserializeObject<List<Sys_SRM_User>>(json);
  5113. return userLogOnEntity;
  5114. }
  5115. else
  5116. {
  5117. throw new Exception(LanguageHelper.GetNameSingle("WMSAPI004"));//"密码不正确,请重新输入");
  5118. }
  5119. }
  5120. }
  5121. else
  5122. {
  5123. throw new Exception(LanguageHelper.GetNameSingle("WMSAPI005"));//"用户名不存在,请重新输入!");
  5124. }
  5125. return null;
  5126. }
  5127. catch (Exception ex)
  5128. {
  5129. log.Error(ex.Message);
  5130. throw new Exception(ex.Message);
  5131. }
  5132. finally
  5133. {
  5134. if (conn.State == ConnectionState.Open)
  5135. {
  5136. conn.Close();
  5137. }
  5138. conn.Dispose();
  5139. }
  5140. }
  5141. }
  5142. #endregion
  5143. }
  5144. }