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

995 lines
43 KiB

3 years ago
  1. using NFine.Data.Extensions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using NFine.Code;
  9. using NFine.Repository;
  10. using System.Data.Common;
  11. using NFine.Domain._03_Entity.SRM;
  12. using ICS.Application.Entity;
  13. using Newtonsoft.Json;
  14. using System.Configuration;
  15. using System.Data.SqlClient;
  16. using ICS.Data;
  17. namespace NFine.Application.WMS
  18. {
  19. public class PickMaterialApp : RepositoryFactory<ICSVendor>
  20. {
  21. public static DataTable Invmes = new DataTable();
  22. //工单备料(工单子件)
  23. public DataTable GetGridJson(string queryJson, ref Pagination jqgridparam)
  24. {
  25. DataTable dt = new DataTable();
  26. var queryParam = queryJson.ToJObject();
  27. List<DbParameter> parameter = new List<DbParameter>();
  28. string sql = "";
  29. #region [SQL]
  30. sql = @"select a.ID,b.MOCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,c.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  31. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  32. from ICSMOPick a
  33. left join ICSMO b on a.MODetailID=b.MODetailID and a.WorkPoint=b.WorkPoint
  34. left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
  35. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  36. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  37. sql += " WHERE 1=1 and e.ID is null";
  38. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  39. #endregion
  40. if (!string.IsNullOrWhiteSpace(queryJson))
  41. {
  42. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  43. {
  44. sql += " and b.MOCode like '%" + queryParam["POCode"].ToString() + "%' ";
  45. }
  46. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  47. {
  48. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  49. }
  50. }
  51. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  52. {
  53. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  54. }
  55. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  56. //{
  57. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  58. //}
  59. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  60. }
  61. //工单领料(发料申请)
  62. public DataTable GetGridJson2(string queryJson, ref Pagination jqgridparam)
  63. {
  64. DataTable dt = new DataTable();
  65. var queryParam = queryJson.ToJObject();
  66. List<DbParameter> parameter = new List<DbParameter>();
  67. string sql = "";
  68. #region [SQL]
  69. sql = @"
  70. select a.ID,a.ApplyCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName ,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  71. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  72. from ICSMOApply a
  73. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  74. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  75. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  76. sql += " WHERE 1=1 and e.ID is null";
  77. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  78. #endregion
  79. if (!string.IsNullOrWhiteSpace(queryJson))
  80. {
  81. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  82. {
  83. sql += " and a.ApplyCode like '%" + queryParam["POCode"].ToString() + "%' ";
  84. }
  85. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  86. {
  87. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  88. }
  89. }
  90. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  91. {
  92. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  93. }
  94. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  95. //{
  96. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  97. //}
  98. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  99. }
  100. //工单材料出库(材料出库)
  101. public DataTable GetGridJson3(string queryJson, ref Pagination jqgridparam)
  102. {
  103. DataTable dt = new DataTable();
  104. var queryParam = queryJson.ToJObject();
  105. List<DbParameter> parameter = new List<DbParameter>();
  106. string sql = "";
  107. #region [SQL]
  108. sql = @"select a.ID,a.IssueCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode ,b.WarehouseName ,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  109. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  110. from ICSMOIssue a
  111. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  112. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  113. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint ";
  114. sql += " WHERE 1=1 and e.ID is null";
  115. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  116. #endregion
  117. if (!string.IsNullOrWhiteSpace(queryJson))
  118. {
  119. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  120. {
  121. sql += " and a.IssueCode like '%" + queryParam["POCode"].ToString() + "%' ";
  122. }
  123. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  124. {
  125. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  126. }
  127. }
  128. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  129. {
  130. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  131. }
  132. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  133. //{
  134. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  135. //}
  136. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  137. }
  138. //委外备料(委外备料)
  139. public DataTable GetGridJson4(string queryJson, ref Pagination jqgridparam)
  140. {
  141. DataTable dt = new DataTable();
  142. var queryParam = queryJson.ToJObject();
  143. List<DbParameter> parameter = new List<DbParameter>();
  144. string sql = "";
  145. #region [SQL]
  146. sql = @"select a.ID,b.OOCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,c.WarehouseName ,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  147. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  148. from ICSOOPick a
  149. left join ICSOutsourcingOrder b on a.OODetailID=b.OODetailID and a.WorkPoint=b.WorkPoint
  150. left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
  151. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  152. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  153. sql += " WHERE 1=1 and e.ID is null";
  154. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  155. #endregion
  156. if (!string.IsNullOrWhiteSpace(queryJson))
  157. {
  158. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  159. {
  160. sql += " and a.OOCode like '%" + queryParam["POCode"].ToString() + "%' ";
  161. }
  162. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  163. {
  164. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  165. }
  166. }
  167. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  168. {
  169. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  170. }
  171. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  172. //{
  173. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  174. //}
  175. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  176. }
  177. //委外领料(委外发料申请)
  178. public DataTable GetGridJson5(string queryJson, ref Pagination jqgridparam)
  179. {
  180. DataTable dt = new DataTable();
  181. var queryParam = queryJson.ToJObject();
  182. List<DbParameter> parameter = new List<DbParameter>();
  183. string sql = "";
  184. #region [SQL]
  185. sql = @"select a.ID,a.ApplyCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  186. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  187. from ICSOApply a
  188. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  189. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  190. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  191. sql += " WHERE 1=1 and e.ID is null";
  192. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  193. #endregion
  194. if (!string.IsNullOrWhiteSpace(queryJson))
  195. {
  196. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  197. {
  198. sql += " and a.ApplyCode like '%" + queryParam["POCode"].ToString() + "%' ";
  199. }
  200. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  201. {
  202. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  203. }
  204. }
  205. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  206. {
  207. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  208. }
  209. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  210. //{
  211. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  212. //}
  213. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  214. }
  215. //委外材料出库(委外发料申请)
  216. public DataTable GetGridJson6(string queryJson, ref Pagination jqgridparam)
  217. {
  218. DataTable dt = new DataTable();
  219. var queryParam = queryJson.ToJObject();
  220. List<DbParameter> parameter = new List<DbParameter>();
  221. string sql = "";
  222. #region [SQL]
  223. sql = @"select a.ID,a.IssueCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseCode,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  224. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  225. from ICSOIssue a
  226. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  227. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  228. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  229. sql += " WHERE 1=1 and e.ID is null";
  230. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  231. #endregion
  232. if (!string.IsNullOrWhiteSpace(queryJson))
  233. {
  234. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  235. {
  236. sql += " and a.IssueCode like '%" + queryParam["POCode"].ToString() + "%' ";
  237. }
  238. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  239. {
  240. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  241. }
  242. }
  243. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  244. {
  245. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  246. }
  247. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  248. //{
  249. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  250. //}
  251. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  252. }
  253. //销售发货(销售发货)
  254. public DataTable GetGridJson7(string queryJson, ref Pagination jqgridparam)
  255. {
  256. DataTable dt = new DataTable();
  257. var queryParam = queryJson.ToJObject();
  258. List<DbParameter> parameter = new List<DbParameter>();
  259. string sql = "";
  260. #region [SQL]
  261. sql = @"select a.ID,a.SDNCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  262. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  263. from ICSSDN a
  264. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  265. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  266. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  267. sql += " WHERE 1=1 and a.Type='1' and e.ID is null";
  268. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  269. #endregion
  270. if (!string.IsNullOrWhiteSpace(queryJson))
  271. {
  272. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  273. {
  274. sql += " and a.SDNCode like '%" + queryParam["POCode"].ToString() + "%' ";
  275. }
  276. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  277. {
  278. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  279. }
  280. }
  281. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  282. {
  283. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  284. }
  285. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  286. //{
  287. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  288. //}
  289. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  290. }
  291. //其它出库(其它出库)
  292. public DataTable GetGridJson8(string queryJson, ref Pagination jqgridparam)
  293. {
  294. DataTable dt = new DataTable();
  295. var queryParam = queryJson.ToJObject();
  296. List<DbParameter> parameter = new List<DbParameter>();
  297. string sql = "";
  298. #region [SQL]
  299. sql = @"select a.ID,a.OutCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  300. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  301. from ICSOtherOut a
  302. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  303. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  304. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  305. sql += " WHERE 1=1 and e.ID is null ";
  306. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  307. #endregion
  308. if (!string.IsNullOrWhiteSpace(queryJson))
  309. {
  310. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  311. {
  312. sql += " and a.OutCode like '%" + queryParam["POCode"].ToString() + "%' ";
  313. }
  314. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  315. {
  316. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  317. }
  318. }
  319. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  320. {
  321. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  322. }
  323. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  324. //{
  325. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  326. //}
  327. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  328. }
  329. //借用(借用)
  330. public DataTable GetGridJson9(string queryJson, ref Pagination jqgridparam)
  331. {
  332. DataTable dt = new DataTable();
  333. var queryParam = queryJson.ToJObject();
  334. List<DbParameter> parameter = new List<DbParameter>();
  335. string sql = "";
  336. #region [SQL]
  337. sql = @"
  338. select a.ID,a.BrrowCode as Code,a.Sequence,a.MTIME,a.MUSERName,a.MUSER,a.WHCode,b.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  339. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  340. from ICSBrrow a
  341. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  342. left join ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
  343. left join ICSMOPickMerge e on a.ID=e.SourceID and a.WorkPoint=e.WorkPoint";
  344. sql += " WHERE 1=1 and e.ID is null ";
  345. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  346. #endregion
  347. if (!string.IsNullOrWhiteSpace(queryJson))
  348. {
  349. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  350. {
  351. sql += " and a.BrrowCode like '%" + queryParam["POCode"].ToString() + "%' ";
  352. }
  353. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  354. {
  355. sql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  356. }
  357. }
  358. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  359. {
  360. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  361. }
  362. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  363. //{
  364. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  365. //}
  366. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  367. }
  368. public DataTable GetICSMOPickMergeTemp(string ID,string Type)
  369. {
  370. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  371. #region sql
  372. string sql = @"SELECT row_number() over (order by c.Code) AS rowNo,
  373. c.Code,
  374. c.InvCode,
  375. c.InvName,
  376. c.InvStd,
  377. FLOOR(c.iQuantity) AS iQuantity,
  378. d.WarehouseCode,
  379. d.LocationCode,
  380. d.LotNO,
  381. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  382. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  383. FLOOR(f.QTYTotal) QTYTotal INTO #temp
  384. FROM
  385. ({0}) c
  386. LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='6000' AND d.Quantity>0
  387. LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='6000' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
  388. ORDER BY c.InvCode,d.MTIME,d.LotNO
  389. DECLARE @ItemCode VARCHAR(50),
  390. @QTY DECIMAL(18,3),
  391. @ItemCodeCurrent VARCHAR(50),
  392. @QTYCurrent DECIMAL(18,3),
  393. @iQuantityCurrent DECIMAL(18,3),
  394. @CanDelete BIT,
  395. @Row INT,
  396. @rowCurrent INT
  397. SET @Row = @@rowcount
  398. SET @rowCurrent=1
  399. SET @CanDelete=0
  400. SET @ItemCode=''
  401. WHILE @rowCurrent<=@Row
  402. BEGIN
  403. SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  404. PRINT(@rowCurrent)
  405. IF @ItemCode<>@ItemCodeCurrent
  406. BEGIN
  407. SET @ItemCode=@ItemCodeCurrent
  408. SET @QTY=0
  409. SET @CanDelete=0
  410. END
  411. IF @CanDelete=1
  412. BEGIN
  413. DELETE FROM #temp WHERE rowNo=@rowCurrent
  414. SET @rowCurrent += 1
  415. CONTINUE
  416. END
  417. SET @QTY += @QTYCurrent
  418. IF @QTY>=@iQuantityCurrent
  419. BEGIN
  420. SET @CanDelete=1
  421. END
  422. SET @rowCurrent += 1
  423. END
  424. SELECT * FROM #temp
  425. DROP TABLE #temp
  426. ";
  427. #endregion
  428. string sqls = "";
  429. if (Type=="1")
  430. {
  431. #region 工单备料sql
  432. sqls = @" SELECT
  433. c.MOCode as Code,
  434. a.Sequence,
  435. a.InvCode,
  436. b.InvName,
  437. b.InvStd,
  438. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  439. a.WhCode
  440. FROM
  441. ICSMOPick a
  442. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  443. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  444. WHERE c.MOCode+a.Sequence in ({0}) AND a.WorkPoint = '{1}'
  445. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence";
  446. #endregion
  447. }
  448. if (Type == "2")
  449. {
  450. #region 工单领料SQL
  451. sqls = @" select
  452. a.ApplyCode as Code,
  453. a.InvCode,
  454. a.Sequence,
  455. b.InvName,
  456. b.InvStd,
  457. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  458. a.WhCode
  459. FROM
  460. ICSMOApply a
  461. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  462. WHERE a.ApplyCode+a.Sequence in ({0}) AND a.WorkPoint = '{1}'
  463. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence";
  464. #endregion
  465. }
  466. if (Type=="3")
  467. {
  468. #region 工单材料出库SQL
  469. sqls = @" select
  470. a.IssueCode as Code,
  471. a.InvCode,
  472. a.Sequence,
  473. b.InvName,
  474. b.InvStd,
  475. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  476. a.WhCode
  477. FROM
  478. ICSMOIssue a
  479. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  480. WHERE a.IssueCode+a.Sequence in ({0}) AND a.WorkPoint = '{1}'
  481. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence";
  482. #endregion
  483. }
  484. if (Type=="4")
  485. {
  486. #region 委外备料SQL
  487. sqls = @" select
  488. c.OOCode as Code,
  489. a.InvCode,
  490. a.Sequence,
  491. b.InvName,
  492. b.InvStd,
  493. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  494. a.WhCode
  495. FROM
  496. ICSOOPick a
  497. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  498. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  499. WHERE c.OOCode+a.Sequence in ({0}) AND a.WorkPoint = '{1}'
  500. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence";
  501. #endregion
  502. }
  503. if (Type=="5")
  504. {
  505. #region 委外领料SQL
  506. sqls = @" select
  507. a.ApplyCode as Code,
  508. a.InvCode,
  509. a.Sequence,
  510. b.InvName,
  511. b.InvStd,
  512. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  513. a.WhCode
  514. FROM
  515. ICSOApply a
  516. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  517. WHERE a.ApplyCode+a.Sequence in ({0}) AND a.WorkPoint = '{1}'
  518. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence";
  519. #endregion
  520. }
  521. if (Type=="6")
  522. {
  523. #region 委外材料出库SQL
  524. sqls = @" select
  525. a.IssueCode as Code,
  526. a.InvCode,
  527. a.Sequence,
  528. b.InvName,
  529. b.InvStd,
  530. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  531. a.WhCode
  532. FROM
  533. ICSOIssue a
  534. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  535. WHERE a.IssueCode+a.Sequence in ({0}) AND a.WorkPoint = '{1}'
  536. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence";
  537. #endregion
  538. }
  539. if (Type=="7")
  540. {
  541. #region 销售发货SQL
  542. sqls = @" select
  543. a.SDNCode as Code,
  544. a.InvCode,
  545. a.Sequence,
  546. b.InvName,
  547. b.InvStd,
  548. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  549. a.WhCode
  550. FROM
  551. ICSSDN a
  552. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  553. WHERE a.SDNCode+a.Sequence in ({0}) AND a.WorkPoint = '{1}'
  554. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence";
  555. #endregion
  556. }
  557. if (Type=="8")
  558. {
  559. #region 其它出库SQL
  560. sqls = @" select
  561. a.OutCode as Code,
  562. a.InvCode,
  563. a.Sequence,
  564. b.InvName,
  565. b.InvStd,
  566. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  567. a.WhCode
  568. FROM
  569. ICSOtherOut a
  570. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  571. WHERE a.OutCode+a.Sequence in ({0}) AND a.WorkPoint = '{1}'
  572. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence";
  573. #endregion
  574. }
  575. if (Type == "9")
  576. {
  577. #region 借用SQL
  578. sqls = @"select
  579. a.BrrowCode as Code,
  580. a.InvCode,
  581. a.Sequence,
  582. b.InvName,
  583. b.InvStd,
  584. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  585. a.WhCode
  586. FROM
  587. ICSBrrow a
  588. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  589. WHERE a.BrrowCode+a.Sequence in ({0}) AND a.WorkPoint = '{1}'
  590. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence";
  591. #endregion
  592. }
  593. sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID)?"''":ID.TrimEnd(','),WorkPoint);
  594. sql = string.Format(sql, sqls);
  595. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  596. DataTable dtCloned = table.Clone();
  597. foreach (DataColumn col in dtCloned.Columns)
  598. {
  599. col.DataType = typeof(string);
  600. }
  601. foreach (DataRow row in table.Rows)
  602. {
  603. DataRow newrow = dtCloned.NewRow();
  604. foreach (DataColumn column in dtCloned.Columns)
  605. {
  606. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  607. }
  608. dtCloned.Rows.Add(newrow);
  609. }
  610. if (Invmes.Rows.Count > 0)
  611. {
  612. dtCloned.Merge(Invmes, false);
  613. }
  614. return dtCloned;
  615. }
  616. public DataTable GetICSMOPickMergeTemp2(string ID, string Type)
  617. {
  618. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  619. #region sql
  620. string sql = @"SELECT row_number() over (order by c.Code) AS rowNo,
  621. c.MergeID,
  622. c.Code,
  623. c.InvCode,
  624. c.InvName,
  625. c.InvStd,
  626. FLOOR(c.iQuantity) AS iQuantity,
  627. d.WarehouseCode,
  628. d.LocationCode,
  629. d.LotNO,
  630. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  631. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  632. FLOOR(f.QTYTotal) QTYTotal INTO #temp
  633. FROM
  634. ({0}) c
  635. LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='6000' AND d.Quantity>0
  636. LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='6000' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
  637. ORDER BY c.InvCode,d.MTIME,d.LotNO
  638. DECLARE @ItemCode VARCHAR(50),
  639. @QTY DECIMAL(18,3),
  640. @ItemCodeCurrent VARCHAR(50),
  641. @QTYCurrent DECIMAL(18,3),
  642. @iQuantityCurrent DECIMAL(18,3),
  643. @CanDelete BIT,
  644. @Row INT,
  645. @rowCurrent INT
  646. SET @Row = @@rowcount
  647. SET @rowCurrent=1
  648. SET @CanDelete=0
  649. SET @ItemCode=''
  650. WHILE @rowCurrent<=@Row
  651. BEGIN
  652. SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  653. PRINT(@rowCurrent)
  654. IF @ItemCode<>@ItemCodeCurrent
  655. BEGIN
  656. SET @ItemCode=@ItemCodeCurrent
  657. SET @QTY=0
  658. SET @CanDelete=0
  659. END
  660. IF @CanDelete=1
  661. BEGIN
  662. DELETE FROM #temp WHERE rowNo=@rowCurrent
  663. SET @rowCurrent += 1
  664. CONTINUE
  665. END
  666. SET @QTY += @QTYCurrent
  667. IF @QTY>=@iQuantityCurrent
  668. BEGIN
  669. SET @CanDelete=1
  670. END
  671. SET @rowCurrent += 1
  672. END
  673. SELECT * FROM #temp
  674. DROP TABLE #temp
  675. ";
  676. #endregion
  677. string sqls = "";
  678. if (Type == "1")
  679. {
  680. #region 工单备料sql
  681. sqls = @" select
  682. x.MergeID,
  683. c.MOCode as Code,
  684. a.Sequence,
  685. a.InvCode,
  686. b.InvName,
  687. b.InvStd,
  688. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  689. a.WhCode
  690. FROM
  691. ICSMOPick a
  692. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  693. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  694. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  695. WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}'
  696. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence,x.MergeID";
  697. #endregion
  698. }
  699. if (Type == "2")
  700. {
  701. #region 工单领料SQL
  702. sqls = @" select
  703. x.MergeID,
  704. a.ApplyCode as Code,
  705. a.InvCode,
  706. a.Sequence,
  707. b.InvName,
  708. b.InvStd,
  709. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  710. a.WhCode
  711. FROM
  712. ICSMOApply a
  713. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  714. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  715. WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}'
  716. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence,x.MergeID";
  717. #endregion
  718. }
  719. if (Type == "3")
  720. {
  721. #region 工单材料出库SQL
  722. sqls = @" select
  723. x.MergeID,
  724. a.IssueCode as Code,
  725. a.InvCode,
  726. a.Sequence,
  727. b.InvName,
  728. b.InvStd,
  729. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  730. a.WhCode
  731. FROM
  732. ICSMOIssue a
  733. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  734. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  735. WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}'
  736. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence,x.MergeID";
  737. #endregion
  738. }
  739. if (Type == "4")
  740. {
  741. #region 委外备料SQL
  742. sqls = @" select
  743. x.MergeID,
  744. c.OOCode as Code,
  745. a.InvCode,
  746. a.Sequence,
  747. b.InvName,
  748. b.InvStd,
  749. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  750. a.WhCode
  751. FROM
  752. ICSOOPick a
  753. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  754. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  755. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  756. WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}'
  757. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence, x.MergeID";
  758. #endregion
  759. }
  760. if (Type == "5")
  761. {
  762. #region 委外领料SQL
  763. sqls = @" select
  764. x.MergeID,
  765. a.ApplyCode as Code,
  766. a.InvCode,
  767. a.Sequence,
  768. b.InvName,
  769. b.InvStd,
  770. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  771. a.WhCode
  772. FROM
  773. ICSOApply a
  774. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  775. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  776. WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}'
  777. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence,x.MergeID";
  778. #endregion
  779. }
  780. if (Type == "6")
  781. {
  782. #region 委外材料出库SQL
  783. sqls = @" select
  784. x.MergeID,
  785. a.IssueCode as Code,
  786. a.InvCode,
  787. a.Sequence,
  788. b.InvName,
  789. b.InvStd,
  790. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  791. a.WhCode
  792. FROM
  793. ICSOIssue a
  794. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  795. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  796. WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}'
  797. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence,x.MergeID";
  798. #endregion
  799. }
  800. if (Type == "7")
  801. {
  802. #region 销售发货SQL
  803. sqls = @" select
  804. x.MergeID,
  805. a.SDNCode as Code,
  806. a.InvCode,
  807. a.Sequence,
  808. b.InvName,
  809. b.InvStd,
  810. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  811. a.WhCode
  812. FROM
  813. ICSSDN a
  814. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  815. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  816. WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}'
  817. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence,x.MergeID";
  818. #endregion
  819. }
  820. if (Type == "8")
  821. {
  822. #region 其它出库SQL
  823. sqls = @" select
  824. x.MergeID,
  825. a.OutCode as Code,
  826. a.InvCode,
  827. a.Sequence,
  828. b.InvName,
  829. b.InvStd,
  830. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  831. a.WhCode
  832. FROM
  833. ICSOtherOut a
  834. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  835. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  836. WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}'
  837. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence,x.MergeID";
  838. #endregion
  839. }
  840. if (Type == "9")
  841. {
  842. #region 借用SQL
  843. sqls = @" select
  844. x.MergeID,
  845. a.BrrowCode as Code,
  846. a.InvCode,
  847. a.Sequence,
  848. b.InvName,
  849. b.InvStd,
  850. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  851. a.WhCode
  852. FROM
  853. ICSBrrow a
  854. inner join ICSMOPickMerge x on a.ID=x.SourceID and a.WorkPoint=x.WorkPoint
  855. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  856. WHERE x.SourceID in ({0}) AND a.WorkPoint = '{1}'
  857. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.Sequence,x.MergeID";
  858. #endregion
  859. }
  860. sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(','), WorkPoint);
  861. sql = string.Format(sql, sqls);
  862. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  863. DataTable dtCloned = table.Clone();
  864. foreach (DataColumn col in dtCloned.Columns)
  865. {
  866. col.DataType = typeof(string);
  867. }
  868. foreach (DataRow row in table.Rows)
  869. {
  870. DataRow newrow = dtCloned.NewRow();
  871. foreach (DataColumn column in dtCloned.Columns)
  872. {
  873. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  874. }
  875. dtCloned.Rows.Add(newrow);
  876. }
  877. if (Invmes.Rows.Count > 0)
  878. {
  879. dtCloned.Merge(Invmes, false);
  880. }
  881. return dtCloned;
  882. }
  883. public string MergeMaterial(string keyValue,string Type)
  884. {
  885. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  886. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  887. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  888. string msg = "";
  889. string sql = string.Empty;
  890. keyValue = keyValue.TrimEnd(',');
  891. string[] str = keyValue.Split(',');
  892. DateTime time = DateTime.Now;
  893. string Tday = time.ToString("yyyyMMdd");
  894. string sqls = string.Format(@"SELECT MAX(A.SourceID) AS SourceID FROM ICSMOPickMerge A WHERE A.SourceID LIKE '{0}%' AND LEN(a.SourceID) = 13", Tday);
  895. DataSet ds = SqlHelper.GetDataSetBySql(sqls);
  896. string MergeID = "";
  897. Int64 Merge_ID = 0;
  898. DataTable dts = ds.Tables[0];
  899. if (dts != null && dts.Rows.Count > 0)
  900. {
  901. string lot = dts.Rows[0]["SourceID"].ToString();
  902. if (!string.IsNullOrWhiteSpace(lot))
  903. Merge_ID = Convert.ToInt64(lot.Substring(lot.Length - 5));
  904. }
  905. foreach (var item in str)
  906. {
  907. MergeID = Tday + (Merge_ID + 1).ToString().PadLeft(5, '0');
  908. sql += @"INSERT INTO dbo.ICSMOPickMerge
  909. ( ID ,MergeID ,SourceID ,Type,MUSER, MUSERName,MTIME,WorkPoint)
  910. Values(NEWID(),'{0}','{1}','{2}','{3}','{4}',GETDATE(),'{5}')
  911. ";
  912. sql = string.Format(sql, MergeID, item, Type, MUSER, MUSERNAME, WorkPoint);
  913. }
  914. try
  915. {
  916. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  917. {
  918. }
  919. else
  920. {
  921. msg = "新增失败";
  922. }
  923. }
  924. catch (Exception ex)
  925. {
  926. throw new Exception(ex.Message);
  927. }
  928. return msg;
  929. }
  930. public string CheckQty(string objArr)
  931. {
  932. objArr= objArr.TrimEnd(',');
  933. string sql = @"select * from ICSMOPickMerge where SourceID in ({0})";
  934. sql = string.Format(sql, objArr);
  935. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  936. if (dt != null&&dt.Rows.Count>0)
  937. {
  938. return "1";
  939. }
  940. return "0";
  941. }
  942. }
  943. }