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

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