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

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