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

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