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

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