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.

620 lines
30 KiB

3 weeks 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. using Newtonsoft.Json.Linq;
  18. namespace NFine.Application.WMS
  19. {
  20. public class YLICSMoPickApp : RepositoryFactory<ICSVendor>
  21. {
  22. public static DataTable Invmes = new DataTable();
  23. //工单备料(工单子件)
  24. public DataTable GetGridJson(string queryJson, ref Pagination jqgridparam)
  25. {
  26. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  27. DataTable dt = new DataTable();
  28. var queryParam = queryJson.ToJObject();
  29. List<DbParameter> parameter = new List<DbParameter>();
  30. string sql = "";
  31. #region [SQL]
  32. // sql = @"select a.ID,b.MOCode as Code,a.Sequence as ZSequence,b.Sequence as MSequence,b.Sequence + '-' + a.Sequence AS Sequence,a.EATTRIBUTE2,
  33. //a.MTIME,a.MUSERName,a.MUSER,a.WHCode,c.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  34. // case when e.SourceID is null then '未合并' else '已合并' end as IsNew,a.Quantity
  35. // ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  36. // ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  37. // from ICSMOPick a
  38. // left
  39. // join ICSMO b on a.MODetailID = b.MODetailID and a.WorkPoint = b.WorkPoint and b.MOStatus<>'3'
  40. // left join Sys_SRM_Items g on g.F_EnCode='Reduction'
  41. // left join ICSWarehouse c on a.WHCode = c.WarehouseCode and a.WorkPoint = c.WorkPoint
  42. // inner join ICSInventory d on a.InvCode = d.InvCode and a.WorkPoint = d.WorkPoint
  43. // left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  44. // left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  45. // where a.EATTRIBUTE1 <> '1'
  46. // and SUBSTRING(a.InvCode, 1, CONVERT(int,g.F_Description)) NOT IN (select b.F_ItemCode from Sys_SRM_Items a left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  47. //where a.F_EnCode='Reduction')";
  48. sql = @"select a.ID,b.MOCode as Code,a.Sequence as ZSequence,b.Sequence as MSequence,b.Sequence + '-' + a.Sequence AS Sequence,a.EATTRIBUTE2,
  49. a.MTIME,a.MUSERName,a.MUSER,a.WHCode,c.WarehouseName,a.InvCode,d.InvName,d.InvDesc,d.InvStd,d.InvUnit,
  50. case when e.SourceID is null then '' else '' end as IsNew,a.Quantity
  51. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  52. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.IssueQuantity as IssueQuantity
  53. from ICSMOPick a
  54. left
  55. join ICSMO b on a.MODetailID = b.MODetailID and a.WorkPoint = b.WorkPoint and b.MOStatus<>'3'
  56. left join Sys_SRM_Items g on g.F_EnCode='Reduction'
  57. left join ICSWarehouse c on a.WHCode = c.WarehouseCode and a.WorkPoint = c.WorkPoint
  58. inner join ICSInventory d on a.InvCode = d.InvCode and a.WorkPoint = d.WorkPoint
  59. left join ICSMOPickMerge e on a.ID = e.SourceID and a.WorkPoint = e.WorkPoint
  60. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  61. where a.EATTRIBUTE1 <> '1'
  62. ";
  63. sql = string.Format(sql, WorkPoint);
  64. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  65. #endregion
  66. if (!string.IsNullOrWhiteSpace(queryJson))
  67. {
  68. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  69. {
  70. sql += " and b.MOCode = '" + queryParam["POCode"].ToString() + "' ";
  71. }
  72. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  73. {
  74. string[] values = queryParam["InvCode"].ToString().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  75. string InvCode = "'" + string.Join("','", values) + "'";
  76. sql += " and a.InvCode in (" + InvCode + ") ";
  77. }
  78. if (!string.IsNullOrWhiteSpace(queryParam["Mechanism"].ToString()))
  79. {
  80. sql += " and a.EATTRIBUTE2 = '" + queryParam["Mechanism"].ToString() + "' ";
  81. }
  82. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  83. {
  84. sql += " and convert(nvarchar(20),b.CreateDateTime,23) >= '" + queryParam["TimeFrom"].ToString() + "' ";
  85. }
  86. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  87. {
  88. sql += " and convert(nvarchar(20),b.CreateDateTime,23) <= '" + queryParam["TimeArrive"].ToString() + "' ";
  89. }
  90. }
  91. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  92. }
  93. public DataTable GetICSMOPickMergeTemp(string ID, string Type)
  94. {
  95. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  96. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  97. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  98. if (ID!="")
  99. {
  100. //ID = ID.Replace("'", "''");
  101. ID = ID.TrimEnd(',');
  102. // ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
  103. }
  104. //string Code = SqlHelper.GetItemsDetailEnabledMark("MtimeControl");
  105. string sql = @" --查询单据信息
  106. SELECT ROW_NUMBER() OVER (ORDER BY mo.MOCode,a.EATTRIBUTE2,mo.Sequence+'~'+a.Sequence) AS rowNo,
  107. mo.MOCode AS Code,
  108. mo.Sequence+'~'+a.Sequence AS Sequence,
  109. a.WhCode AS WarehouseCode,
  110. ISNULL(a.Quantity, 0) - ISNULL(a.IssueQuantity, 0) AS iQuantity,
  111. a.InvCode,
  112. b.InvName,
  113. b.InvStd,
  114. b.InvUnit,
  115. a.ExtensionID,
  116. ISNULL(c.ProjectCode, '') AS ProjectCode,
  117. ISNULL(c.BatchCode, '') AS BatchCode,
  118. ISNULL(c.Version, '') AS Version,
  119. ISNULL(c.Brand, '') AS Brand,
  120. ISNULL(c.cFree1, '') AS cFree1,
  121. ISNULL(c.cFree2, '') AS cFree2,
  122. ISNULL(c.cFree3, '') AS cFree3,
  123. ISNULL(c.cFree4, '') AS cFree4,
  124. ISNULL(c.cFree5, '') AS cFree5,
  125. ISNULL(c.cFree6, '') AS cFree6,
  126. ISNULL(c.cFree7, '') AS cFree7,
  127. ISNULL(c.cFree8, '') AS cFree8,
  128. ISNULL(c.cFree9, '') AS cFree9,
  129. ISNULL(c.cFree10, '') AS cFree10,
  130. CAST(NULL AS nvarchar(100)) AS LocationCode,
  131. CAST(NULL AS nvarchar(100)) AS LotNO,
  132. CAST(NULL AS DECIMAL(18,6)) AS QTY,
  133. CAST(NULL AS DECIMAL(18,6)) AS QTYTotal,
  134. CAST(NULL AS DECIMAL(18,6)) AS ReserveQuantity,
  135. CAST(NULL AS datetime2) AS MTIME,
  136. b.EATTRIBUTE2 AS U8InvCode,a.EATTRIBUTE2, getdate() as NowMTIME
  137. INTO #TempVouchs
  138. FROM ICSMOPick a
  139. INNER JOIN ICSMO mo ON a.MODetailID=mo.MODetailID AND a.WorkPoint=mo.WorkPoint AND mo.MOStatus<>'3'
  140. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint = b.WorkPoint
  141. LEFT JOIN ICSExtension c ON a.ExtensionID = c.ID AND a.WorkPoint = c.WorkPoint
  142. WHERE a.WorkPoint = '{1}' AND mo.MOCode+mo.Sequence+'-'+a.Sequence IN ({0}) AND ISNULL(a.Quantity, 0) > ISNULL(a.IssueQuantity, 0) AND a.EATTRIBUTE1<>'1'
  143. DECLARE @VouchsTotal INT=@@rowcount, --
  144. @VouchsRowCurrent INT=1 --
  145. --
  146. SELECT
  147. a.WarehouseCode,
  148. a.Quantity - a.LockQuantity AS LotQuantity,
  149. a.INVCode,
  150. b.LotNo,
  151. a.InDate AS MTIME,
  152. a.inDate,
  153. a.LocationCode,
  154. b.ExtensionID,
  155. b.ProductDate,
  156. b.ExpirationDate,
  157. ISNULL(c.ProjectCode, '') AS ProjectCode,
  158. ISNULL(c.BatchCode, '') AS BatchCode,
  159. ISNULL(c.Version, '') AS Version,
  160. ISNULL(c.Brand, '') AS Brand,
  161. ISNULL(c.cFree1, '') AS cFree1,
  162. ISNULL(c.cFree2, '') AS cFree2,
  163. ISNULL(c.cFree3, '') AS cFree3,
  164. ISNULL(c.cFree4, '') AS cFree4,
  165. ISNULL(c.cFree5, '') AS cFree5,
  166. ISNULL(c.cFree6, '') AS cFree6,
  167. ISNULL(c.cFree7, '') AS cFree7,
  168. ISNULL(c.cFree8, '') AS cFree8,
  169. ISNULL(c.cFree9, '') AS cFree9,
  170. ISNULL(c.cFree10, '') AS cFree10
  171. INTO #TempWH
  172. FROM ICSWareHouseLotInfo a
  173. INNER JOIN ICSInventoryLot b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
  174. INNER JOIN ICSExtension c ON b.ExtensionID = c.ID AND b.WorkPoint = c.WorkPoint
  175. WHERE a.WorkPoint = '{1}'
  176. AND a.Inspect='0' --
  177. AND a.Freeze='0' --
  178. AND a.Quantity > a.LockQuantity --
  179. AND a.InvCode IN (SELECT InvCode FROM #TempVouchs)
  180. --
  181. SELECT a.InvCode,a.Quantity AS QTYTotal,b.Quantity AS ReserveQuantity,a.Quantity-ISNULL(b.Quantity, 0) AS CanOutQuantity
  182. INTO #TempWHTotal
  183. FROM (SELECT InvCode,Sum(LotQuantity) AS Quantity FROM #TempWH GROUP BY InvCode) a
  184. LEFT JOIN ICSReserve b ON a.InvCode=b.InvCode AND b.Enable='1' AND b.WorkPoint='{1}' AND (GETDATE() BETWEEN b.BeginTime AND b.EndTime)
  185. -- SELECT * FROM #TempWH
  186. -- SELECT * FROM #TempWHTotal
  187. --
  188. SELECT TOP 0 Code,Sequence,InvCode,InvName,InvStd,InvUnit,FORMAT(iQuantity, '0.########') iQuantity,WarehouseCode,ExtensionID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,LocationCode,LotNO
  189. ,FORMAT(QTY, '0.########') QTY,FORMAT(QTYTotal, '0.########') QTYTotal,FORMAT(ReserveQuantity, '0.########') ReserveQuantity,MTIME,U8InvCode ,EATTRIBUTE2,NowMTIME
  190. INTO #TempResult FROM #TempVouchs
  191. --
  192. ALTER TABLE #TempResult ADD [rowNo] INT IDENTITY(1,1);
  193. --
  194. WHILE @VouchsRowCurrent<=@VouchsTotal
  195. BEGIN
  196. SELECT ROW_NUMBER() OVER (ORDER BY a.rowNo,b.MTIME,b.LotNO) AS rowNo,a.Code,a.Sequence,a.InvCode,a.InvName,a.InvStd,a.InvUnit,a.iQuantity,a.WarehouseCode,a.ExtensionID,a.ProjectCode,a.BatchCode,a.Version,a.Brand,a.cFree1,a.cFree2,a.cFree3,a.cFree4,a.cFree5,a.cFree6,a.cFree7,a.cFree8,a.cFree9,a.cFree10,
  197. b.LocationCode,b.LotNO,b.LotQuantity,c.QTYTotal,c.ReserveQuantity,b.MTIME,a.iQuantity AS NeedQuantity,c.CanOutQuantity,a.U8InvCode,a.EATTRIBUTE2,a.NowMTIME
  198. INTO #TempWHVouchs
  199. FROM #TempVouchs a
  200. LEFT JOIN #TempWH b ON a.InvCode=b.INVCode
  201. AND (LEN(a.WarehouseCode)<=0 OR (LEN(a.WarehouseCode)>0 AND a.WarehouseCode=b.WarehouseCode))
  202. AND (LEN(a.ProjectCode)<=0 OR (LEN(a.ProjectCode)>0 AND a.ProjectCode=b.ProjectCode))
  203. AND (LEN(a.BatchCode)<=0 OR (LEN(a.BatchCode)>0 AND a.BatchCode=b.BatchCode))
  204. AND (LEN(a.Version)<=0 OR (LEN(a.Version)>0 AND a.Version=b.Version))
  205. AND (LEN(a.Brand)<=0 OR (LEN(a.Brand)>0 AND a.Brand=b.Brand))
  206. AND (LEN(a.cFree1)<=0 OR (LEN(a.cFree1)>0 AND a.cFree1=b.cFree1))
  207. AND (LEN(a.cFree2)<=0 OR (LEN(a.cFree2)>0 AND a.cFree2=b.cFree2))
  208. AND (LEN(a.cFree3)<=0 OR (LEN(a.cFree3)>0 AND a.cFree3=b.cFree3))
  209. AND (LEN(a.cFree4)<=0 OR (LEN(a.cFree4)>0 AND a.cFree4=b.cFree4))
  210. AND (LEN(a.cFree5)<=0 OR (LEN(a.cFree5)>0 AND a.cFree5=b.cFree5))
  211. AND (LEN(a.cFree6)<=0 OR (LEN(a.cFree6)>0 AND a.cFree6=b.cFree6))
  212. AND (LEN(a.cFree7)<=0 OR (LEN(a.cFree7)>0 AND a.cFree7=b.cFree7))
  213. AND (LEN(a.cFree8)<=0 OR (LEN(a.cFree8)>0 AND a.cFree8=b.cFree8))
  214. AND (LEN(a.cFree9)<=0 OR (LEN(a.cFree9)>0 AND a.cFree9=b.cFree9))
  215. AND (LEN(a.cFree10)<=0 OR (LEN(a.cFree10)>0 AND a.cFree10=b.cFree10))
  216. LEFT JOIN #TempWHTotal c ON a.InvCode=c.INVCode
  217. WHERE rowNo=@VouchsRowCurrent
  218. DECLARE @WHTotal INT=@@rowcount, --
  219. @WHRowCurrent INT=1 --
  220. --
  221. IF EXISTS(SELECT rowNo FROM #TempWHTotal a LEFT JOIN #TempVouchs b ON a.InvCode=b.InvCode WHERE rowNo=@VouchsRowCurrent AND a.CanOutQuantity<=ISNULL(b.iQuantity, 0))
  222. BEGIN
  223. --
  224. UPDATE #TempWHVouchs SET NeedQuantity=CanOutQuantity
  225. --
  226. UPDATE a SET CanOutQuantity=0 FROM #TempWHTotal a INNER JOIN #TempVouchs b ON a.InvCode=b.InvCode WHERE rowNo=@VouchsRowCurrent
  227. --0
  228. DELETE FROM #TempWH WHERE InvCode=(SELECT InvCode FROM #TempVouchs WHERE rowNo=@VouchsRowCurrent)
  229. END
  230. --
  231. ELSE
  232. BEGIN
  233. --
  234. UPDATE a SET CanOutQuantity=a.CanOutQuantity-b.iQuantity FROM #TempWHTotal a INNER JOIN #TempVouchs b ON a.InvCode=b.InvCode WHERE rowNo=@VouchsRowCurrent
  235. END
  236. WHILE @WHRowCurrent<=@WHTotal
  237. BEGIN
  238. --,
  239. IF EXISTS(SELECT rowNo FROM #TempWHVouchs WHERE rowNo=@WHRowCurrent AND NeedQuantity<=LotQuantity)
  240. BEGIN
  241. INSERT INTO #TempResult
  242. SELECT a.Code,a.Sequence,a.InvCode,a.InvName,a.InvStd,a.InvUnit, FORMAT(a.iQuantity, '0.########') iQuantity,a.WarehouseCode,a.ExtensionID,a.ProjectCode,a.BatchCode,a.Version,a.Brand,a.cFree1,a.cFree2,a.cFree3,a.cFree4,a.cFree5,a.cFree6,a.cFree7,a.cFree8,a.cFree9,a.cFree10,
  243. a.LocationCode,a.LotNO,FORMAT(a.NeedQuantity, '0.########') NeedQuantity,FORMAT(a.QTYTotal, '0.########') QTYTotal,FORMAT(a.ReserveQuantity, '0.########') ReserveQuantity,a.MTIME,a.U8InvCode,a.EATTRIBUTE2,a.NowMTIME
  244. FROM #TempWHVouchs a
  245. WHERE rowNo=@WHRowCurrent
  246. --
  247. IF EXISTS(SELECT rowNo FROM #TempWHVouchs WHERE rowNo=@WHRowCurrent AND NeedQuantity=LotQuantity)
  248. BEGIN
  249. --使
  250. DELETE FROM #TempWH WHERE LotNO=(SELECT LotNO FROM #TempWHVouchs WHERE rowNo=@WHRowCurrent)
  251. END
  252. ELSE
  253. BEGIN
  254. --使
  255. UPDATE a SET LotQuantity=b.LotQuantity-b.NeedQuantity FROM #TempWH a INNER JOIN #TempWHVouchs b ON a.LotNO=b.LotNO WHERE rowNo=@WHRowCurrent
  256. END
  257. --
  258. BREAK
  259. END
  260. --
  261. ELSE
  262. BEGIN
  263. INSERT INTO #TempResult
  264. SELECT a.Code,a.Sequence,a.InvCode,a.InvName,a.InvStd,a.InvUnit,FORMAT(a.iQuantity, '0.########') iQuantity,a.WarehouseCode,a.ExtensionID,a.ProjectCode,a.BatchCode,a.Version,a.Brand,a.cFree1,a.cFree2,a.cFree3,a.cFree4,a.cFree5,a.cFree6,a.cFree7,a.cFree8,a.cFree9,a.cFree10,
  265. a.LocationCode,a.LotNO,FORMAT(a.LotQuantity, '0.########') LotQuantity,FORMAT(a.QTYTotal, '0.########') QTYTotal,FORMAT(a.ReserveQuantity, '0.########') ReserveQuantity,a.MTIME,a.U8InvCode,a.EATTRIBUTE2,a.NowMTIME
  266. FROM #TempWHVouchs a
  267. WHERE rowNo=@WHRowCurrent
  268. --
  269. UPDATE #TempWHVouchs SET NeedQuantity=NeedQuantity-(SELECT LotQuantity FROM #TempWHVouchs WHERE rowNo=@WHRowCurrent)
  270. --使
  271. DELETE FROM #TempWH WHERE LotNO=(SELECT LotNO FROM #TempWHVouchs WHERE rowNo=@WHRowCurrent)
  272. END
  273. --1
  274. SET @WHRowCurrent=@WHRowCurrent+1
  275. END
  276. --1
  277. SET @VouchsRowCurrent=@VouchsRowCurrent+1
  278. DROP TABLE #TempWHVouchs
  279. END
  280. -- SELECT * FROM #TempWH
  281. -- SELECT * FROM #TempWHTotal
  282. -- SELECT * FROM #TempVouchs
  283. SELECT * FROM #TempResult where isnull(LotNO,'')<>'' ORDER BY rowNo
  284. --
  285. DROP TABLE #TempVouchs
  286. DROP TABLE #TempWH
  287. DROP TABLE #TempWHTotal
  288. DROP TABLE #TempResult";
  289. sql = string.Format(sql, ID,WorkPoint);
  290. // sql = string.Format(sql, ID, Type, WorkPoint);
  291. var dataset = Repository().FindDataSetBySql(sql);
  292. if (dataset.Tables[0].Rows.Count == 0)
  293. return null;
  294. DataTable table = dataset.Tables[0];
  295. try
  296. {
  297. DataRow[] dss = table.Select("LotNO=''");
  298. foreach (var item in dss)
  299. {
  300. DataRow[] dsss = table.Select("Code='" + item["Code"].ToString() + "' and Sequence='" + item["Sequence"].ToString() + "' and LotNO <> '' ");
  301. if (dsss != null && dsss.Length > 0)
  302. {
  303. table.Rows.Remove(item);
  304. }
  305. }
  306. var result = ConvertCellToString(table);
  307. if (Invmes.Rows.Count > 0)
  308. {
  309. result.Merge(Invmes, false);
  310. }
  311. return result;
  312. }
  313. catch (Exception ex)
  314. {
  315. throw new Exception(ex.Message);
  316. }
  317. }
  318. // public DataTable GetICSMOPickMergeTemp(string ID, string Type)
  319. // {
  320. // string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  321. // string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  322. // string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  323. // ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
  324. // string sqls = "";
  325. // string wheresql = "";
  326. // #region 各单据sql
  327. // if (Type == "1")
  328. // {
  329. // #region 工单备料sql
  330. // sqls = @" SELECT
  331. // c.MOCode as Code,
  332. //c.Sequence+'-'+a.Sequence as Sequence,
  333. // a.InvCode,
  334. // b.InvName,
  335. // b.InvStd,
  336. // SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  337. // a.WhCode,
  338. // b.InvUnit,
  339. // a.ExtensionID,
  340. //a.EATTRIBUTE2,
  341. // f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  342. //,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  343. // FROM
  344. // ICSMOPick a
  345. // inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint and c.MOStatus<>'3'
  346. // LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  347. // LEFT JOIN ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  348. // WHERE c.MOCode+c.Sequence+'-'+a.Sequence in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0) and a.EATTRIBUTE1<>'1'
  349. //GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.EATTRIBUTE2,c.Sequence+'-'+a.Sequence,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  350. //,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10";
  351. // #endregion
  352. // }
  353. // #endregion
  354. // sqls = string.Format(sqls, ID, WorkPoint);
  355. // string sql = $@"SELECT row_number() over ( order by c.EATTRIBUTE2,c.InvCode,d.LocationCode) AS rowNo,
  356. // c.Code,
  357. //c.Sequence,
  358. // c.InvCode,
  359. // c.InvName,
  360. // c.InvStd,
  361. // c.InvUnit,
  362. // c.iQuantity AS iQuantity,
  363. // c.WHCode AS WarehouseCode,
  364. // d.LotNO,
  365. // ISNULL(d.Quantity, 0) AS QTY,
  366. // ISNULL(d.Quantity, 0) AS QTYLeft,
  367. // CONVERT(decimal(18,6),0) AS SendQTY,
  368. // d.LocationCode AS LocationCode,
  369. // CONVERT(varchar(100),d.MTIME, 23) MTIME,
  370. // f.QTYTotal QTYTotal,c.ExtensionID,
  371. // c.EATTRIBUTE2,
  372. // getdate() as NowMTIME
  373. // FROM
  374. // ({sqls}) c
  375. // left join (select d.WarehouseCode,d.Quantity-d.LockQuantity as Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID ,
  376. // f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  377. //,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  378. // from ICSWareHouseLotInfo d ,ICSInventoryLot m
  379. // LEFT JOIN ICSExtension f on m.ExtensionID=f.ID and m.WorkPoint=f.WorkPoint
  380. // where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  381. // and d.WorkPoint='{WorkPoint}' AND d.Quantity-d.LockQuantity>0 AND d.Quantity>0
  382. // ) d
  383. // on c.InvCode=d.INVCode
  384. // AND (LEN(ISNULL(c.WHCode,''))<=0 OR (LEN(ISNULL(c.WHCode,''))>0 AND c.WHCode=d.WarehouseCode))
  385. // AND (LEN(ISNULL(c.ProjectCode,''))<=0 OR (LEN(ISNULL(c.ProjectCode,''))>0 AND c.ProjectCode=d.ProjectCode))
  386. // AND (LEN(ISNULL(c.BatchCode,''))<=0 OR (LEN(ISNULL(c.BatchCode,''))>0 AND c.BatchCode=d.BatchCode))
  387. // AND (LEN(ISNULL(c.Version,''))<=0 OR (LEN(ISNULL(c.Version,''))>0 AND c.Version=d.Version))
  388. // AND (LEN(ISNULL(c.Brand,''))<=0 OR (LEN(ISNULL(c.Brand,''))>0 AND c.Brand=d.Brand))
  389. // AND (LEN(ISNULL(c.cFree1,''))<=0 OR (LEN(ISNULL(c.cFree1,''))>0 AND c.cFree1=d.cFree1))
  390. // AND (LEN(ISNULL(c.cFree2,''))<=0 OR (LEN(ISNULL(c.cFree2,''))>0 AND c.cFree2=d.cFree2))
  391. // AND (LEN(ISNULL(c.cFree3,''))<=0 OR (LEN(ISNULL(c.cFree3,''))>0 AND c.cFree3=d.cFree3))
  392. // AND (LEN(ISNULL(c.cFree4,''))<=0 OR (LEN(ISNULL(c.cFree4,''))>0 AND c.cFree4=d.cFree4))
  393. // AND (LEN(ISNULL(c.cFree5,''))<=0 OR (LEN(ISNULL(c.cFree5,''))>0 AND c.cFree5=d.cFree5))
  394. // AND (LEN(ISNULL(c.cFree6,''))<=0 OR (LEN(ISNULL(c.cFree6,''))>0 AND c.cFree6=d.cFree6))
  395. // AND (LEN(ISNULL(c.cFree7,''))<=0 OR (LEN(ISNULL(c.cFree7,''))>0 AND c.cFree7=d.cFree7))
  396. // AND (LEN(ISNULL(c.cFree8,''))<=0 OR (LEN(ISNULL(c.cFree8,''))>0 AND c.cFree8=d.cFree8))
  397. // AND (LEN(ISNULL(c.cFree9,''))<=0 OR (LEN(ISNULL(c.cFree9,''))>0 AND c.cFree9=d.cFree9))
  398. // AND (LEN(ISNULL(c.cFree10,''))<=0 OR (LEN(ISNULL(c.cFree10,''))>0 AND c.cFree10=d.cFree10))
  399. // LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity-LockQuantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{WorkPoint}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
  400. // order by cast( row_number() over ( order by c.EATTRIBUTE2,c.InvCode,d.LocationCode) as int), c.EATTRIBUTE2,c.InvCode,d.LocationCode ";
  401. // // sql = string.Format(sql, sqls)1;
  402. // var dataset = Repository().FindDataSetBySql(sql);
  403. // if (dataset.Tables[0].Rows.Count == 0)
  404. // return null;
  405. // DataTable table = dataset.Tables[0];
  406. // decimal qtyCount = 0;
  407. // bool remove = false;
  408. // List<int> removeList = new List<int>();
  409. // for (int i = 0; i < table.Rows.Count; i++)
  410. // {
  411. // if (i != 0
  412. // && (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString())
  413. // || !table.Rows[i]["Sequence"].ToString().Equals(table.Rows[i - 1]["Sequence"].ToString())
  414. // || !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString())
  415. // || !table.Rows[i]["ExtensionID"].ToString().Equals(table.Rows[i - 1]["ExtensionID"].ToString()))
  416. // )
  417. // {
  418. // qtyCount = 0;
  419. // remove = false;
  420. // }
  421. // if (table.Rows[i]["QTYLeft"].ToString().ToDecimal() == 0 && table.Rows[i]["LotNO"].ToString() != "")
  422. // {
  423. // table.Rows[i]["LotNO"] = "";
  424. // string a = "0.000000";
  425. // table.Rows[i]["QTY"] = Convert.ToDecimal(a);
  426. // //removeList.Add(i);
  427. // continue;
  428. // }
  429. // if (remove && table.Rows[i]["LotNO"].ToString() != "")
  430. // {
  431. // removeList.Add(i);
  432. // }
  433. // else
  434. // {
  435. // var lotQty = table.Rows[i]["QTYLeft"].ToString().ToDecimal();
  436. // var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
  437. // qtyCount += lotQty;
  438. // foreach (DataRow dr in table.Rows)
  439. // {
  440. // if (dr["LotNO"].ToString() == table.Rows[i]["LotNO"].ToString())
  441. // {
  442. // if (qtyCount > orderQty)
  443. // {
  444. // dr["QTYLeft"] = Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty);
  445. // }
  446. // else
  447. // {
  448. // dr["QTYLeft"] = 0;
  449. // }
  450. // }
  451. // }
  452. // if (qtyCount >= orderQty)
  453. // {
  454. // table.Rows[i]["SendQTY"] = Convert.ToDecimal(lotQty) - (Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty));
  455. // remove = true;
  456. // }
  457. // else
  458. // {
  459. // table.Rows[i]["SendQTY"] = lotQty;
  460. // }
  461. // }
  462. // }
  463. // if (removeList.Count > 0)
  464. // {
  465. // removeList.Reverse();
  466. // foreach (var item in removeList)
  467. // {
  468. // table.Rows.RemoveAt(item);
  469. // }
  470. // }
  471. // try
  472. // {
  473. // DataRow [] dss= table.Select("LotNO=''");
  474. // foreach (var item in dss)
  475. // {
  476. // DataRow[] dsss = table.Select("Code='"+ item["Code"].ToString()+ "' and Sequence='"+ item["Sequence"].ToString() + "' and LotNO <> '' ");
  477. // if (dsss!=null && dsss.Length>0)
  478. // {
  479. // table.Rows.Remove(item);
  480. // }
  481. // }
  482. // for (int i = 0; i < table.Rows.Count; i++)
  483. // {
  484. // table.Rows[i]["rowNo"] = i+1;
  485. // }
  486. // var result = ConvertCellToString(table);
  487. // if (Invmes.Rows.Count > 0)
  488. // {
  489. // result.Merge(Invmes, false);
  490. // }
  491. // return result;
  492. // }
  493. // catch (Exception ex)
  494. // {
  495. // throw new Exception(ex.Message);
  496. // }
  497. // }
  498. public DataTable ConvertCellToString(DataTable data)
  499. {
  500. DataTable dtCloned = data.Clone();
  501. foreach (DataColumn col in dtCloned.Columns)
  502. {
  503. col.DataType = typeof(string);
  504. }
  505. foreach (DataRow row in data.Rows)
  506. {
  507. DataRow newrow = dtCloned.NewRow();
  508. foreach (DataColumn column in dtCloned.Columns)
  509. {
  510. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  511. }
  512. dtCloned.Rows.Add(newrow);
  513. }
  514. return dtCloned;
  515. }
  516. public string CheckQty(string objArr)
  517. {
  518. objArr = objArr.TrimEnd(',');
  519. string sql = @"select * from ICSMOPickMerge a
  520. left join ICSMOPick b on a.SourceID=b.ID and a.WorkPoint=b.WorkPoint
  521. left join ICSMO c on b.MODetailID=c.MODetailID and b.WorkPoint=c.WorkPoint and c.MOStatus<>'3'
  522. where MOCode in ({0})";
  523. sql = string.Format(sql, objArr);
  524. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  525. if (dt != null && dt.Rows.Count > 0)
  526. {
  527. return "1";
  528. }
  529. return "0";
  530. }
  531. public object SeachPickingListType(string Type)
  532. {
  533. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  534. string sql = @" select b.F_EnabledMark as flag from Sys_SRM_Items a left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  535. where a.F_EnCode='PL00001' and b.F_ItemCode='{0}' order by cast(b.F_SortCode as int) asc";
  536. sql = string.Format(sql, Type);
  537. object flag = SqlHelper.ExecuteScalar(sql);
  538. return flag;
  539. }
  540. }
  541. }