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

1399 lines
72 KiB

2 years ago
11 months ago
2 years ago
2 years ago
2 years ago
11 months ago
2 years ago
11 months ago
2 years ago
11 months ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
2 years ago
11 months ago
2 years ago
  1. using NFine.Code;
  2. using NFine.Domain.Entity.SystemManage;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.Common;
  6. using NFine.Repository;
  7. using System.Text;
  8. using System;
  9. using System.Configuration;
  10. using NFine.Data;
  11. using System.IO;
  12. using System.Linq;
  13. using Newtonsoft.Json;
  14. namespace NFine.Application.WMS
  15. {
  16. public class WatchPanelApp : RepositoryFactory<ModuleEntity>
  17. {
  18. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  19. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  20. private static string U9IP = ConfigurationManager.ConnectionStrings["U9connstr"].ConnectionString;
  21. private static string StratTimecfg = ConfigurationManager.ConnectionStrings["StratTime"].ConnectionString;
  22. private static string EndTimecfg = ConfigurationManager.ConnectionStrings["EndTime"].ConnectionString;
  23. private static string advDays = ConfigurationManager.ConnectionStrings["advDays"].ConnectionString;
  24. private static string workPoint = ConfigurationManager.ConnectionStrings["WorkPoint"].ConnectionString;
  25. string StratTime = DateTime.Parse(DateTime.Now.AddDays(-1).ToString()).ToString("yyyy-MM-dd") + ' ' + StratTimecfg;
  26. string EndTime = DateTime.Parse(DateTime.Now.ToString()).ToString("yyyy-MM-dd") + ' ' + EndTimecfg;
  27. //private string ERPName = U9IP.Substring(U9IP.IndexOf("Server=") + 7, 9) + "." + U9IP.Substring(U9IP.IndexOf("Catalog=") + 8, 7);
  28. //string dsaq = ConfigurationManager.ConnectionStrings["advDays"].ConnectionString;
  29. private static string conbegin = "Data Source=";
  30. private static int end = U9IP.IndexOf(";Uid=");
  31. private static string ERPName = "[" + U9IP.Substring(conbegin.Length, end - conbegin.Length).Replace(";Database=", "].");
  32. private static string ERPName1 = ERPName.Split('.')[ERPName.Split('.').Length - 1];
  33. string EndTime2 = "";
  34. //到货明细
  35. public DataTable GetList1(string queryJson, ref Pagination jqgridparam)
  36. {
  37. var queryParam = queryJson.ToJObject();
  38. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  39. List<DbParameter> parameter = new List<DbParameter>();
  40. string SqlText = @"
  41. select * from (
  42. SELECT *,
  43. - ,
  44. CASE WHEN -> 0 THEN '' WHEN > 0 THEN '' ELSE '' END
  45. FROM (
  46. SELECT dd.orderno ,dd.itemcode ,dd.planqty ,inv.invname ,
  47. isnull((
  48. SELECT SUM (lotqty)
  49. FROM icsitemlot lot
  50. WHERE lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine
  51. AND isnull(IQCStatus,'') !='' AND cc.workpoint=lot.workpoint),0) ,
  52. isnull((
  53. SELECT SUM (lotqty)
  54. FROM icsitemlot lot
  55. WHERE lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine
  56. AND isnull(IQCStatus,'') !='' AND cc.workpoint=lot.workpoint
  57. AND NOT EXISTS (
  58. SELECT 1 FROM ICSWareHouseLotInfo info
  59. WHERE info.lotno=lot.lotno AND info.workpoint=lot.workpoint)),0)
  60. FROM ICSINVReceipt cc
  61. LEFT JOIN ICSINVReceiptDetail dd ON cc.ReceiptNO=dd.ReceiptNO AND dd.workpoint=cc.workpoint
  62. LEFT JOIN ICSINVENTORY inv ON inv.invcode=dd.itemcode AND dd.workpoint=inv.workpoint
  63. WHERE cc.mtime >=DATEADD(week, -1,getdate())
  64. and cc.workpoint='" + workpoint + @"'
  65. ) ff ) gg
  66. ";
  67. DataTable dt = Repository().FindTablePageBySql_Other(SqlText, "WMSconnstr", parameter.ToArray(), ref jqgridparam);
  68. return dt;
  69. }
  70. //来料不合格明细
  71. public DataTable GetList2(string queryJson, ref Pagination jqgridparam)
  72. {
  73. var queryParam = queryJson.ToJObject();
  74. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  75. List<DbParameter> parameter = new List<DbParameter>();
  76. string SqlText = @"
  77. select * from (
  78. SELECT cc.receiptNo ,dd.orderno ,dd.itemcode , inv.invname ,
  79. sum(lot.lotqty) ,kk.CKITEMDESC
  80. FROM ICSINVReceipt cc
  81. LEFT JOIN ICSINVReceiptDetail dd ON cc.ReceiptNO=dd.ReceiptNO AND dd.workpoint=cc.workpoint
  82. LEFT JOIN ICSINVENTORY inv ON inv.invcode=dd.itemcode AND dd.workpoint=inv.workpoint
  83. left join icsitemlot lot on lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine
  84. AND cc.workpoint=lot.workpoint
  85. left join (select * from (select ROW_NUMBER()over(partition by LOTNO order by mtime desc,id ) rowId,lotno ,errdata ,CKITEMDESC
  86. from ICSIQCErrList ck where workpoint='" + workpoint + @"' ) as AuctionRecords
  87. where rowId=1) kk on kk.lotno=lot.lotno
  88. WHERE 1=1
  89. and cc.mtime >=DATEADD(MONTH, -1,getdate())
  90. and kk.errdata=''
  91. and cc.workpoint='" + workpoint + @"'
  92. group by cc.receiptNo ,dd.orderno ,dd.itemcode , inv.invname ,kk.CKITEMDESC ) jj
  93. ";
  94. DataTable dt = Repository().FindTablePageBySql_Other(SqlText, "WMSconnstr", parameter.ToArray(), ref jqgridparam);
  95. return dt;
  96. }
  97. public DataTable GetWIPDATA()
  98. {
  99. List<DbParameter> parameter = new List<DbParameter>();
  100. string SqlText = @"
  101. select distinct mo.mocode ,mo.moseq ,mo.itemcode ,inv.invname ,
  102. mo.moplanqty ,sim.MUSERName ,sim.opcode
  103. ,row_number() over (partition by mo.mocode ,mo.moseq , sim.MUSERName ,sim.opcode order by sim.mtime desc,sim.id desc) rn
  104. from icsmo mo
  105. left join ICSITEMLot lot on lot.transno =mo.mocode and lot.TransLine=mo.moseq and lot.workpoint =mo.workpoint
  106. left join ICSLOTSIMULATION sim on mo.WorkPoint=sim.WorkPoint and sim.lotno=lot.lotno
  107. left join ICSINVENTORY inv on inv.invcode=mo.itemcode and inv.workpoint=mo.workpoint
  108. where sim.mtime>CAST(CAST(GETDATE() as date) as varchar(10)) + ' 00:00:00'
  109. and mo.WorkPoint='" + workpoint + @"'
  110. ";
  111. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  112. //测试
  113. for (int i = 0; i < 20; i++)
  114. {
  115. DataRow newRow;
  116. newRow = dt.NewRow();
  117. newRow["生产订单号"] = "MO-0001" + i.ToString();
  118. newRow["行号"] = "22";
  119. dt.Rows.Add(newRow);
  120. }
  121. return dt;
  122. }
  123. //车间人员信息
  124. public DataTable GetWIPUser()
  125. {
  126. List<DbParameter> parameter = new List<DbParameter>();
  127. string SqlText = @"
  128. select distinct mo.mocode ,mo.moseq ,mo.itemcode ,inv.invname ,
  129. mo.moplanqty ,sim.MUSERName ,sim.opcode
  130. ,row_number() over (partition by mo.mocode ,mo.moseq , sim.MUSERName ,sim.opcode order by sim.mtime desc,sim.id desc) rn
  131. from icsmo mo
  132. left join ICSITEMLot lot on lot.transno =mo.mocode and lot.TransLine=mo.moseq and lot.workpoint =mo.workpoint
  133. left join ICSLOTSIMULATION sim on mo.WorkPoint=sim.WorkPoint and sim.lotno=lot.lotno
  134. left join ICSINVENTORY inv on inv.invcode=mo.itemcode and inv.workpoint=mo.workpoint
  135. where sim.mtime>CAST(CAST(GETDATE() as date) as varchar(10)) + ' 00:00:00'
  136. and mo.WorkPoint='" + workpoint + @"'
  137. ";
  138. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  139. //测试
  140. for (int i = 0; i < 20; i++)
  141. {
  142. DataRow newRow;
  143. newRow = dt.NewRow();
  144. newRow["生产订单号"] = "MO-0001" + i.ToString();
  145. newRow["行号"] = "22";
  146. dt.Rows.Add(newRow);
  147. }
  148. return dt;
  149. }
  150. //收料信息
  151. public DataTable GetWIPRCV()
  152. {
  153. List<DbParameter> parameter = new List<DbParameter>();
  154. string SqlText = @"
  155. select B.CreatedOn ,A.DescFlexField_PrivateDescSeg1 ,A.DocNO ,B.DocLineNo
  156. ,ISNULL(B.QCBillNo,'') AS ,CASE WHEN A.Status='0' THEN '' WHEN A.Status='2' THEN '' WHEN A.Status='3' THEN '' ELSE '' END AS
  157. ,A.Supplier_ShortName ,A.DescFlexField_PubDescSeg13 ,B.ItemInfo_ItemCode
  158. ,B.ItemInfo_ItemName ,C.INVSTD ,C.INVUOM ,B.ArriveQtyTU ,B.QualifiedQtyTU
  159. ,case when B.Status='5' then B.QualifiedQtyTU When B.Status='5' AND ISNULL(B.QCBillNo,'')='' then B.QualifiedQtyTU ELSE 0 end as U9已上架数量
  160. ,ISNULL(F.QTY,0) AS WMS已上架数量,B.ArriveQtyTU-ISNULL(F.QTY,0) AS WMS未上架数量,E.Name
  161. from
  162. {0}.DBO.PM_Receivement A
  163. LEFT JOIN (SELECT a.ID,b.CreatedOn,b.DocLineNo,b.QCBillNo,b.ItemInfo_ItemCode,b.ItemInfo_ItemName,b.ItemInfo_ItemID,b.WhMan
  164. ,sum(b.ArriveQtyTU) ArriveQtyTU,SUM(b.QualifiedQtyTU) QualifiedQtyTU,b.Status
  165. from {0}.DBO.PM_Receivement a LEFT JOIN {0}.DBO.PM_RcvLine b on b.Receivement=a.ID
  166. where (SplitFlag=0 OR SplitFlag=2)
  167. GROUP BY a.ID,b.CreatedOn,b.DocLineNo,b.QCBillNo,b.ItemInfo_ItemCode,b.ItemInfo_ItemName,b.ItemInfo_ItemID,b.WhMan,b.Status ) B
  168. ON B.ID=A.ID
  169. LEFT JOIN ICSINVENTORY C on C.ID=B.ItemInfo_ItemID
  170. LEFT JOIN {0}.DBO.CBO_Operators_trl E on E.ID=B.WhMan
  171. LEFT JOIN (SELECT ASN.STNO,ASN.ITEMCODE,SUM(ISNULL(WHLOT.LotQty,0)) AS QTY FROM ICSASNDETAIL ASN
  172. LEFT JOIN ICSITEMLot LOT ON LOT.LotNO=ASN.LOTNO AND LOT.WorkPoint=ASN.WorkPoint
  173. LEFT JOIN ICSWareHouseLotInfo WHLOT ON WHLOT.LotNO=LOT.LotNO AND WHLOT.WorkPoint=LOT.WorkPoint
  174. GROUP BY ASN.STNO,ASN.ITEMCODE) F ON F.STNO=A.DescFlexField_PrivateDescSeg1 AND F.ITEMCODE=B.ItemInfo_ItemCode
  175. where 1=1 and B.CreatedOn>CAST(CAST(GETDATE() as date) as varchar(10)) + ' 00:00:00'
  176. order by B.CreatedOn";
  177. SqlText = string.Format(SqlText, ERPName, workpoint);
  178. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  179. return dt;
  180. }
  181. //收料图表
  182. public DataTable GetWIPRCVChart()
  183. {
  184. List<DbParameter> parameter = new List<DbParameter>();
  185. string SqlText = @"
  186. SELECT top 1 (SELECT COUNT(ID) FROM {0}.DBO.PM_RcvLine
  187. where (SplitFlag=0 OR SplitFlag=2)
  188. and CreatedOn>CAST(CAST(GETDATE() as date) as varchar(10)) + ' 00:00:00' and status<>'5') as U9dk,
  189. (SELECT COUNT(ID) FROM {0}.DBO.PM_RcvLine
  190. where (SplitFlag=0 OR SplitFlag=2)
  191. and CreatedOn>CAST(CAST(GETDATE() as date) as varchar(10)) + ' 00:00:00' and status='5') as U9gb
  192. from {0}.DBO.PM_RcvLine";
  193. SqlText = string.Format(SqlText, ERPName, workpoint);
  194. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  195. return dt;
  196. }
  197. //发料信息
  198. public DataTable GetMaterialPick()
  199. {
  200. List<DbParameter> parameter = new List<DbParameter>();
  201. string SqlText = $@" SELECT
  202. a.ApplyCode,
  203. A.Sequence,
  204. --a.SAPSequence,
  205. a.InvCode,
  206. c.LotNo,
  207. c.Quantity,
  208. e.StartLocation,
  209. e.EndLocation
  210. -- e.TaskCode
  211. FROM
  212. ICSMOApply a
  213. -- INNER JOIN ICSContainerReceiptsNumber b ON a.ApplyCode= b.TransCode
  214. INNER JOIN ICSWareHouseLotInfoLog c ON a.ApplyCode= c.TransCode
  215. AND
  216. c.TransType= '15'
  217. AND a.Sequence= c.TransSequence
  218. INNER JOIN ( SELECT DISTINCT e.StartLocation,e.EndLocation FROM
  219. ICSForkLiftTaskLog e WHERE e.EndLocation is not null AND e.EndLocation!=''AND (e.EATTRIBUTE1 IS NULL OR e.EATTRIBUTE1!='') ) e ON c.FromLocationCode= e.StartLocation
  220. WHERE
  221. a.WorkPoint in({workPoint})";
  222. //if (!string.IsNullOrWhiteSpace(StratTime))
  223. //{
  224. // SqlText += " and a.CreatedOn>'" + StratTime + "'";
  225. //}
  226. //if (!string.IsNullOrWhiteSpace(EndTime))
  227. //{
  228. // SqlText += " and a.CreatedOn<'" + EndTime + "'";
  229. //}
  230. //if (!string.IsNullOrWhiteSpace(advDays))
  231. //{
  232. // SqlText += @" and a.MTIME>CAST(CAST(DATEADD(day, -" + advDays + @", GETDATE()) as date) as varchar(10)) + ' 00:00:00'
  233. // and a.MTIME<=CAST(CAST(GETDATE() as date) as varchar(10)) + ' 23:59:59'";
  234. //}
  235. //if (string.IsNullOrWhiteSpace(StratTime) && string.IsNullOrWhiteSpace(EndTime) && string.IsNullOrWhiteSpace(advDays))
  236. //{
  237. // SqlText += @" and a.MTIME>CAST(CAST(GETDATE() as date) as varchar(10)) + ' 00:00:00'
  238. // and a.MTIME<=CAST(CAST(GETDATE() as date) as varchar(10)) + ' 23:59:59'";
  239. //}
  240. SqlText += @"order by a.MTIME ";
  241. //SqlText = string.Format(SqlText, ERPName, workpoint);
  242. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  243. return dt;
  244. }
  245. //发料图表
  246. public DataTable GetMaterialPickChart()
  247. {
  248. List<DbParameter> parameter = new List<DbParameter>();
  249. string SqlText = @" SELECT top 1
  250. (SELECT COUNT(*) from {0}.DBO.MO_MO a
  251. where a.CreatedOn>CAST(CAST(DATEADD(day, -{2}, GETDATE()) as date) as varchar(10)) + ' 00:00:00')-
  252. (SELECT COUNT(*) from {0}.DBO.MO_MO a
  253. LEFT JOIN (SELECT DISTINCT COUNT(VouchRow) ,MOCode from ICSMaterialPick GROUP BY MOCode) b on a.DocNo=b.MOCode
  254. LEFT JOIN (SELECT DISTINCT COUNT(VouchRow) ,MOCode from ICSMaterialPick where Quantity<=HasQuantity GROUP BY MOCode) c on a.DocNo=c.MOCode
  255. where a.CreatedOn>CAST(CAST(DATEADD(day, -{2}, GETDATE()) as date) as varchar(10)) + ' 00:00:00' and b.=c.)
  256. as ,
  257. (SELECT COUNT(*) from {0}.DBO.MO_MO a
  258. LEFT JOIN (SELECT DISTINCT COUNT(VouchRow) ,MOCode from ICSMaterialPick GROUP BY MOCode) b on a.DocNo=b.MOCode
  259. LEFT JOIN (SELECT DISTINCT COUNT(VouchRow) ,MOCode from ICSMaterialPick where Quantity<=HasQuantity GROUP BY MOCode) c on a.DocNo=c.MOCode
  260. where a.CreatedOn>CAST(CAST(DATEADD(day, -{2}, GETDATE()) as date) as varchar(10)) + ' 00:00:00' and b.=c.) as
  261. from {0}.DBO.MO_MO";
  262. SqlText = string.Format(SqlText, ERPName, workpoint, advDays);
  263. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  264. return dt;
  265. }
  266. //查询月度每日下单行数与每日完成出库行数
  267. public DataTable GetGridJson_MonthDaliyComplete()
  268. {
  269. string sql = @"
  270. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp1'))
  271. drop table #temp1
  272. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp1OO'))
  273. drop table #temp1OO
  274. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp2'))
  275. drop table #temp2
  276. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp2OO'))
  277. drop table #temp2OO
  278. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp111'))
  279. drop table #temp111
  280. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp111OO'))
  281. drop table #temp111OO
  282. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp222'))
  283. drop table #temp222
  284. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp222OO'))
  285. drop table #temp222OO
  286. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempPX3'))
  287. drop table #TempPX3
  288. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempPX3OO'))
  289. drop table #TempPX3OO
  290. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempSCLL'))
  291. drop table #tempSCLL
  292. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempSCLLOO'))
  293. drop table #tempSCLLOO
  294. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempAll'))
  295. drop table #tempAll
  296. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempRK'))
  297. drop table #tempRK
  298. select ApplyCode,count(*) Count,WorkPoint into #temp1 from ICSMOApply WITH (NOLOCK)
  299. where CONVERT(VARCHAR(10), CreateDateTime, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -20, GETDATE()), 23)
  300. and CONVERT(VARCHAR(10), CreateDateTime, 23)<=CONVERT(VARCHAR(10), GETDATE(), 23)
  301. group by ApplyCode,WorkPoint
  302. select ApplyCode,sum(Quantity) Qty,WorkPoint into #temp2 from ICSMOApply WITH (NOLOCK)
  303. where CONVERT(VARCHAR(10), CreateDateTime, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -20, GETDATE()), 23)
  304. and CONVERT(VARCHAR(10), CreateDateTime, 23)<=CONVERT(VARCHAR(10), GETDATE(), 23)
  305. group by ApplyCode,WorkPoint
  306. select a.ApplyCode,a.WorkPoint,a.Count,b.Qty into #temp111 from #temp1 a
  307. left join #temp2 b on a.ApplyCode = b.ApplyCode
  308. and a.WorkPoint = b.WorkPoint
  309. select TransCode,WorkPoint, CONVERT(VARCHAR(10), MTIME, 23) MTIME,Quantity,id into #temp222 from ICSWareHouseLotInfoLog WITH (NOLOCK)
  310. where CONVERT(VARCHAR(10), MTIME, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  311. and CONVERT(VARCHAR(10), MTIME, 23)<=CONVERT(VARCHAR(10), GETDATE(), 23)
  312. and BusinessCode =14
  313. select aa.ApplyCode '',aa.WorkPoint '',aa.Count '',aa.Qty '',bb.MTIME '',bb.Quantity '', bb.id,
  314. row_number() over (partition by aa.ApplyCode order by bb.MTIME ,bb.id) rn
  315. into #TempPX3
  316. from #temp111 aa
  317. inner join #temp222 bb on aa.ApplyCode=bb.TransCode and aa.WorkPoint = bb.WorkPoint
  318. ---
  319. -- select *,case when > and <= then else 0 end
  320. -- from(
  321. -- select TT.*,
  322. -- ISNULL( (select sum() from #TempPX3 TT2
  323. -- WHERE TT2.RN<=TT.RN AND TT2.=TT. and TT2.=TT.),0)
  324. -- , ISNULL( (select sum() from #TempPX3 TT2
  325. -- WHERE TT2.RN<TT.RN AND TT2.=TT. AND TT2.=TT.),0)
  326. --
  327. -- from #TempPX3 TT
  328. -- ) gg
  329. ---
  330. select CONVERT(varchar(10), , 21) , sum(case when > and <= then else 0 end) into #tempSCLL
  331. from(
  332. select TT.*,
  333. ISNULL( (select sum() from #TempPX3 TT2
  334. WHERE TT2.RN<=TT.RN AND TT2.=TT. and TT2.=TT.),0)
  335. , ISNULL( (select sum() from #TempPX3 TT2
  336. WHERE TT2.RN<TT.RN AND TT2.=TT. and TT2.=TT.),0)
  337. from #TempPX3 TT
  338. ) gg
  339. group by CONVERT(varchar(10), , 21)
  340. select ApplyCode,count(*) Count,WorkPoint into #temp1OO from ICSOApply WITH (NOLOCK)
  341. where CONVERT(VARCHAR(10), CreateDateTime, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -20, GETDATE()), 23)
  342. and CONVERT(VARCHAR(10), CreateDateTime, 23)<=CONVERT(VARCHAR(10), GETDATE(), 23)
  343. group by ApplyCode,WorkPoint
  344. select ApplyCode,sum(Quantity) Qty,WorkPoint into #temp2OO from ICSOApply WITH (NOLOCK)
  345. where CONVERT(VARCHAR(10), CreateDateTime, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -20, GETDATE()), 23)
  346. and CONVERT(VARCHAR(10), CreateDateTime, 23)<=CONVERT(VARCHAR(10), GETDATE(), 23)
  347. group by ApplyCode,WorkPoint
  348. select a.ApplyCode,a.WorkPoint,a.Count,b.Qty into #temp111OO from #temp1OO a
  349. left join #temp2OO b on a.ApplyCode = b.ApplyCode
  350. and a.WorkPoint = b.WorkPoint
  351. select TransCode,WorkPoint, CONVERT(VARCHAR(10), MTIME, 23) MTIME,Quantity,id into #temp222OO from ICSWareHouseLotInfoLog WITH (NOLOCK)
  352. where CONVERT(VARCHAR(10), MTIME, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  353. and CONVERT(VARCHAR(10), MTIME, 23)<=CONVERT(VARCHAR(10), GETDATE(), 23)
  354. and BusinessCode =6
  355. select aa.ApplyCode '',aa.WorkPoint '',aa.Count '',aa.Qty '',bb.MTIME '',bb.Quantity '', bb.id,
  356. row_number() over (partition by aa.ApplyCode order by bb.MTIME ,bb.id) rn
  357. into #TempPX3OO
  358. from #temp111OO aa
  359. inner join #temp222OO bb on aa.ApplyCode=bb.TransCode and aa.WorkPoint = bb.WorkPoint
  360. --
  361. -- select *,case when > and <= then else 0 end
  362. -- from(
  363. -- select TT.*,
  364. -- ISNULL( (select sum() from #TempPX3 TT2
  365. -- WHERE TT2.RN<=TT.RN AND TT2.=TT. and TT2.=TT.),0)
  366. -- , ISNULL( (select sum() from #TempPX3 TT2
  367. -- WHERE TT2.RN<TT.RN AND TT2.=TT. AND TT2.=TT.),0)
  368. --
  369. -- from #TempPX3 TT
  370. -- ) gg
  371. ---
  372. select CONVERT(varchar(10), , 21) , sum(case when > and <= then else 0 end) into #tempSCLLOO
  373. from(
  374. select TT.*,
  375. ISNULL( (select sum() from #TempPX3OO TT2
  376. WHERE TT2.RN<=TT.RN AND TT2.=TT. and TT2.=TT.),0)
  377. , ISNULL( (select sum() from #TempPX3OO TT2
  378. WHERE TT2.RN<TT.RN AND TT2.=TT. and TT2.=TT.),0)
  379. from #TempPX3OO TT
  380. ) gg
  381. group by CONVERT(varchar(10), , 21)
  382. select a.,a. + isnull(b.,0) into #tempRK from #tempSCLL a
  383. left join #tempSCLLOO b on a. = b.
  384. select a.MTIME,sum(FLQty) FLQty into #tempAll from(
  385. SELECT CONVERT(VARCHAR(10), CreateDateTime, 23) MTIME,count(*) FLQty from ICSMOApply WITH (NOLOCK)
  386. where CONVERT(VARCHAR(10), CreateDateTime, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  387. and CONVERT(VARCHAR(10), CreateDateTime, 23)<=CONVERT(VARCHAR(10), GETDATE(), 23)
  388. group by CONVERT(VARCHAR(10), CreateDateTime, 23)
  389. union
  390. SELECT CONVERT(VARCHAR(10), CreateDateTime, 23) MTIME,count(*) FLQty from ICSOApply WITH (NOLOCK)
  391. where CONVERT(VARCHAR(10), CreateDateTime, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  392. and CONVERT(VARCHAR(10), CreateDateTime, 23)<=CONVERT(VARCHAR(10), GETDATE(), 23)
  393. group by CONVERT(VARCHAR(10), CreateDateTime, 23)) a GROUP BY a.MTIME
  394. select a.MTIME,a.FLQty,b. RkQty from #tempAll a
  395. left join #tempRK b on a.MTIME = b. order by a.MTIME";
  396. DataTable dt = Repository().GetDataTableBySql_Other(sql, "WMSconnstr", null);
  397. return dt;
  398. }
  399. //查询月度每日合格数数与每日完成入库数
  400. public DataTable GetGridJson_MonthDaliyRcv()
  401. {
  402. string SqlText = @"
  403. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp1'))
  404. drop table #temp1
  405. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp1OO'))
  406. drop table #temp1OO
  407. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp2'))
  408. drop table #temp2
  409. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp2OO'))
  410. drop table #temp2OO
  411. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp111'))
  412. drop table #temp111
  413. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp111OO'))
  414. drop table #temp111OO
  415. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp222'))
  416. drop table #temp222
  417. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp222OO'))
  418. drop table #temp222OO
  419. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempPX3'))
  420. drop table #TempPX3
  421. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempPX3OO'))
  422. drop table #TempPX3OO
  423. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempSCLL'))
  424. drop table #tempSCLL
  425. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempSCLLOO'))
  426. drop table #tempSCLLOO
  427. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempAll'))
  428. drop table #tempAll
  429. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempRK'))
  430. drop table #tempRK
  431. select DNCode,count(*) Count,WorkPoint into #temp1 from ICSDeliveryNotice WITH (NOLOCK)
  432. where CONVERT(VARCHAR(10), CreateDateTime, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -20, GETDATE()), 23)
  433. and CONVERT(VARCHAR(10), CreateDateTime, 23)<=CONVERT(VARCHAR(10), GETDATE(), 23)
  434. group by DNCode,WorkPoint
  435. select DNCode,sum(Quantity) Qty,WorkPoint into #temp2 from ICSDeliveryNotice WITH (NOLOCK)
  436. where CONVERT(VARCHAR(10), CreateDateTime, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -20, GETDATE()), 23)
  437. and CONVERT(VARCHAR(10), CreateDateTime, 23)<=CONVERT(VARCHAR(10), GETDATE(), 23)
  438. group by DNCode,WorkPoint
  439. select a.DNCode,a.WorkPoint,a.Count,b.Qty into #temp111 from #temp1 a
  440. left join #temp2 b on a.DNCode = b.DNCode
  441. and a.WorkPoint = b.WorkPoint
  442. select TransCode,WorkPoint, CONVERT(VARCHAR(10), MTIME, 23) MTIME,Quantity,id into #temp222 from ICSWareHouseLotInfoLog WITH (NOLOCK)
  443. where CONVERT(VARCHAR(10), MTIME, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  444. and CONVERT(VARCHAR(10), MTIME, 23)<=CONVERT(VARCHAR(10), GETDATE(), 23)
  445. and BusinessCode =2
  446. select aa.DNCode '',aa.WorkPoint '',aa.Count '',aa.Qty '',bb.MTIME '',bb.Quantity '', bb.id,
  447. row_number() over (partition by aa.DNCode order by bb.MTIME ,bb.id) rn
  448. into #TempPX3
  449. from #temp111 aa
  450. inner join #temp222 bb on aa.DNCode=bb.TransCode and aa.WorkPoint = bb.WorkPoint
  451. ---
  452. -- select *,case when > and <= then else 0 end
  453. -- from(
  454. -- select TT.*,
  455. -- ISNULL( (select sum() from #TempPX3 TT2
  456. -- WHERE TT2.RN<=TT.RN AND TT2.=TT. and TT2.=TT.),0)
  457. -- , ISNULL( (select sum() from #TempPX3 TT2
  458. -- WHERE TT2.RN<TT.RN AND TT2.=TT. AND TT2.=TT.),0)
  459. --
  460. -- from #TempPX3 TT
  461. -- ) gg
  462. ---
  463. select CONVERT(varchar(10), , 21) , sum(case when > and <= then else 0 end) into #tempSCLL
  464. from(
  465. select TT.*,
  466. ISNULL( (select sum() from #TempPX3 TT2
  467. WHERE TT2.RN<=TT.RN AND TT2.=TT. and TT2.=TT.),0)
  468. , ISNULL( (select sum() from #TempPX3 TT2
  469. WHERE TT2.RN<TT.RN AND TT2.=TT. and TT2.=TT.),0)
  470. from #TempPX3 TT
  471. ) gg
  472. group by CONVERT(varchar(10), , 21)
  473. select RCVCode,count(*) Count,WorkPoint into #temp1OO from ICSManufactureReceive WITH (NOLOCK)
  474. where CONVERT(VARCHAR(10), CreateDateTime, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -20, GETDATE()), 23)
  475. and CONVERT(VARCHAR(10), CreateDateTime, 23)<=CONVERT(VARCHAR(10), GETDATE(), 23)
  476. and STATUS =1
  477. group by RCVCode,WorkPoint
  478. select RCVCode,sum(Quantity) Qty,WorkPoint into #temp2OO from ICSManufactureReceive WITH (NOLOCK)
  479. where CONVERT(VARCHAR(10), CreateDateTime, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -20, GETDATE()), 23)
  480. and CONVERT(VARCHAR(10), CreateDateTime, 23)<=CONVERT(VARCHAR(10), GETDATE(), 23)
  481. and STATUS =1
  482. group by RCVCode,WorkPoint
  483. select a.RCVCode,a.WorkPoint,a.Count,b.Qty into #temp111OO from #temp1OO a
  484. left join #temp2OO b on a.RCVCode = b.RCVCode
  485. and a.WorkPoint = b.WorkPoint
  486. select TransCode,WorkPoint, CONVERT(VARCHAR(10), MTIME, 23) MTIME,Quantity,id into #temp222OO from ICSWareHouseLotInfoLog WITH (NOLOCK)
  487. where CONVERT(VARCHAR(10), MTIME, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  488. and CONVERT(VARCHAR(10), MTIME, 23)<=CONVERT(VARCHAR(10), GETDATE(), 23)
  489. and BusinessCode =18
  490. select aa.RCVCode '',aa.WorkPoint '',aa.Count '',aa.Qty '',bb.MTIME '',bb.Quantity '', bb.id,
  491. row_number() over (partition by aa.RCVCode order by bb.MTIME ,bb.id) rn
  492. into #TempPX3OO
  493. from #temp111OO aa
  494. inner join #temp222OO bb on aa.RCVCode=bb.TransCode and aa.WorkPoint = bb.WorkPoint
  495. --
  496. -- select *,case when > and <= then else 0 end
  497. -- from(
  498. -- select TT.*,
  499. -- ISNULL( (select sum() from #TempPX3 TT2
  500. -- WHERE TT2.RN<=TT.RN AND TT2.=TT. and TT2.=TT.),0)
  501. -- , ISNULL( (select sum() from #TempPX3 TT2
  502. -- WHERE TT2.RN<TT.RN AND TT2.=TT. AND TT2.=TT.),0)
  503. --
  504. -- from #TempPX3 TT
  505. -- ) gg
  506. ---
  507. select CONVERT(varchar(10), , 21) , sum(case when > and <= then else 0 end) into #tempSCLLOO
  508. from(
  509. select TT.*,
  510. ISNULL( (select sum() from #TempPX3OO TT2
  511. WHERE TT2.RN<=TT.RN AND TT2.=TT. and TT2.=TT.),0)
  512. , ISNULL( (select sum() from #TempPX3OO TT2
  513. WHERE TT2.RN<TT.RN AND TT2.=TT. and TT2.=TT.),0)
  514. from #TempPX3OO TT
  515. ) gg
  516. group by CONVERT(varchar(10), , 21)
  517. select a.,a. + isnull(b.,0) into #tempRK from #tempSCLL a
  518. left join #tempSCLLOO b on a. = b.
  519. select xx.Mtime,sum(LLQty) FLQty into #tempAll from(
  520. SELECT CONVERT(VARCHAR(10), CreateDateTime, 23) MTIME,count(*) LLQty from ICSDeliveryNotice WITH (NOLOCK)
  521. where CONVERT(VARCHAR(10), CreateDateTime, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  522. and CONVERT(VARCHAR(10), CreateDateTime, 23)<=CONVERT(VARCHAR(10), GETDATE(), 23)
  523. group by CONVERT(VARCHAR(10), CreateDateTime, 23)
  524. union all
  525. SELECT CONVERT(VARCHAR(10), CreateDateTime, 23) MTIME,count(*) LLQty from ICSManufactureReceive WITH (NOLOCK)
  526. where CONVERT(VARCHAR(10), CreateDateTime, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  527. and CONVERT(VARCHAR(10), CreateDateTime, 23)<=CONVERT(VARCHAR(10), GETDATE(), 23)
  528. and status =1
  529. group by CONVERT(VARCHAR(10), CreateDateTime, 23)) xx group by xx.Mtime
  530. select a.MTIME,a.FLQty,b. RkQty from #tempAll a
  531. left join #tempRK b on a.MTIME = b. order by a.MTIME";
  532. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  533. return dt;
  534. }
  535. //查询配、发料及时率
  536. public DataTable GetGridJson_MonthLLPer()
  537. {
  538. string SqlText = @"
  539. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp1'))
  540. drop table #temp1
  541. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp2'))
  542. drop table #temp2
  543. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempPX3'))
  544. drop table #TempPX3
  545. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempSCLL'))
  546. drop table #tempSCLL
  547. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempALL'))
  548. drop table #tempALL
  549. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempX'))
  550. drop table #tempX
  551. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp111'))
  552. drop table #temp111
  553. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempWc'))
  554. drop table #tempWc
  555. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp1JS'))
  556. drop table #temp1JS
  557. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp2JS'))
  558. drop table #temp2JS
  559. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempPX3JS'))
  560. drop table #TempPX3JS
  561. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempSCLLJS'))
  562. drop table #tempSCLLJS
  563. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempALLJS'))
  564. drop table #tempALLJS
  565. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempXJS'))
  566. drop table #tempXJS
  567. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#temp111JS'))
  568. drop table #temp111JS
  569. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempALLDataJS'))
  570. drop table #tempALLDataJS
  571. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempLastJS'))
  572. drop table #tempLastJS
  573. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempJs'))
  574. drop table #tempJs
  575. select ApplyCode,count(*) Count,WorkPoint into #temp1 from ICSMOApply WITH (NOLOCK)
  576. where NeedDate >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  577. and NeedDate<=CONVERT(VARCHAR(10), GETDATE(), 23)
  578. and EATTRIBUTE ='01'
  579. group by ApplyCode,WorkPoint
  580. select ApplyCode,sum(Quantity) Qty,WorkPoint into #tempX from ICSMOApply WITH (NOLOCK)
  581. where NeedDate >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  582. and NeedDate<=CONVERT(VARCHAR(10), GETDATE(), 23)
  583. and EATTRIBUTE ='01'
  584. group by ApplyCode,WorkPoint
  585. select a.ApplyCode,a.WorkPoint,a.Count,b.Qty into #temp111 from #temp1 a
  586. left join #tempX b on a.ApplyCode = b.ApplyCode
  587. and a.WorkPoint = b.WorkPoint
  588. select TransCode,WorkPoint, CONVERT(VARCHAR(10), MTIME, 23) MTIME,Quantity,id into #temp2 from ICSWareHouseLotInfoLog WITH (NOLOCK)
  589. where CONVERT(VARCHAR(10), MTIME, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -30, GETDATE()), 23)
  590. and CONVERT(VARCHAR(10), MTIME, 23)<=CONVERT(VARCHAR(10), GETDATE(), 23)
  591. and BusinessCode =14
  592. select aa.ApplyCode '',aa.WorkPoint '',aa.Count '',aa.Qty '',bb.MTIME '',bb.Quantity '', bb.id,
  593. row_number() over (partition by aa.ApplyCode order by bb.MTIME ,bb.id) rn
  594. into #TempPX3
  595. from #temp111 aa
  596. inner join #temp2 bb on aa.ApplyCode=bb.TransCode and aa.WorkPoint = bb.WorkPoint
  597. ---
  598. select ,sum(case when > and <= then else 0 end) into #tempSCLL
  599. from(
  600. select TT.*,
  601. ISNULL( (select sum() from #TempPX3 TT2
  602. WHERE TT2.RN<=TT.RN AND TT2.=TT. and TT2.=TT.),0)
  603. , ISNULL( (select sum() from #TempPX3 TT2
  604. WHERE TT2.RN<TT.RN AND TT2.=TT. and TT2.=TT.),0)
  605. from #TempPX3 TT
  606. ) gg
  607. group by
  608. SELECT NeedDate,count(*) Qty into #tempALL from ICSMOApply WITH (NOLOCK)
  609. where NeedDate >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  610. and NeedDate<=CONVERT(VARCHAR(10), GETDATE(), 23)
  611. and EATTRIBUTE ='01'
  612. group by NeedDate
  613. select a.NeedDate,ISNULL(Convert(decimal(18,2),Round(Convert(decimal(18,6),isnull(b.,0))/Convert(decimal(18,6),isnull(a.Qty,0)),2)*100),100) Per into #tempWc from #tempALL a
  614. left join #tempSCLL b on a.NeedDate = b. order by a.NeedDate;
  615. select ApplyCode,count(*) Count into #temp1JS from ICSMOApply WITH (NOLOCK)
  616. where NeedDate >=CONVERT(VARCHAR(10), DATEADD(day, -20, GETDATE()), 23)
  617. and NeedDate<=CONVERT(VARCHAR(10), GETDATE(), 23)
  618. and EATTRIBUTE ='01'
  619. group by ApplyCode
  620. select ApplyCode,sum(Quantity) Qty into #tempXJS from ICSMOApply WITH (NOLOCK)
  621. where NeedDate >=CONVERT(VARCHAR(10), DATEADD(day, -20, GETDATE()), 23)
  622. and NeedDate<=CONVERT(VARCHAR(10), GETDATE(), 23)
  623. and EATTRIBUTE ='01'
  624. group by ApplyCode
  625. select a.ApplyCode,a.Count,b.Qty into #temp111JS from #temp1JS a
  626. left join #tempXJS b on a.ApplyCode = b.ApplyCode
  627. select TransCode, CONVERT(VARCHAR(10), MTIME, 23) MTIME,Quantity,id into #temp2JS from ICSWareHouseLotInfoLog WITH (NOLOCK)
  628. where CONVERT(VARCHAR(10), MTIME, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -30, GETDATE()), 23)
  629. and CONVERT(VARCHAR(10), MTIME, 23)<=CONVERT(VARCHAR(10), GETDATE(), 23)
  630. and BusinessCode =14
  631. select aa.ApplyCode '',aa.Count '',aa.Qty '',bb.MTIME '',bb.Quantity '', bb.id,
  632. row_number() over (partition by aa.ApplyCode order by bb.MTIME ,bb.id) rn
  633. into #TempPX3JS
  634. from #temp111JS aa
  635. inner join #temp2JS bb on aa.ApplyCode=bb.TransCode
  636. ---
  637. select ,, sum(case when > and <= then else 0 end) into #tempSCLLJS
  638. from(
  639. select TT.*,
  640. ISNULL( (select sum() from #TempPX3JS TT2
  641. WHERE TT2.RN<=TT.RN AND TT2.=TT.),0)
  642. , ISNULL( (select sum() from #TempPX3JS TT2
  643. WHERE TT2.RN<TT.RN AND TT2.=TT.),0)
  644. from #TempPX3JS TT
  645. ) gg
  646. group by ,
  647. --SELECT sum() FROM #tempSCLL where ='2024-01-15' GROUP BY
  648. select distinct b.NeedDate ,a.,case when a. <= b.NeedDate then else 0 end into #tempALLDataJS
  649. from #tempSCLLJS a
  650. left join ICSMOApply b on a. = b.ApplyCode
  651. --GROUP BY b.NeedDate,a.
  652. select sum() ,NeedDate into #tempLastJS from #tempALLDataJS GROUP BY NeedDate
  653. SELECT NeedDate ,count(*) Qty into #tempALLJS
  654. from ICSMOApply WITH (NOLOCK)
  655. where NeedDate >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  656. and NeedDate<=CONVERT(VARCHAR(10), GETDATE(), 23)
  657. and EATTRIBUTE ='01'
  658. group by NeedDate
  659. select a.NeedDate,ISNULL(Convert(decimal(18,2),Round(Convert(decimal(18,6),isnull(b.,0))/Convert(decimal(18,6),isnull(a.Qty,0)),2)*100),100) Per into #tempJs from #tempALLJS a
  660. left join #tempLastJS b on a.NeedDate = b.NeedDate order by a.NeedDate
  661. select a.NeedDate,a.Per 'WcPer',b.Per 'JsPer' from #tempWc a left join #tempJs b on a.NeedDate = b.NeedDate
  662. ";
  663. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  664. return dt;
  665. }
  666. //查询一期库存状态
  667. public DataTable GetGridJson_WareStatusOne()
  668. {
  669. List<DbParameter> parameter = new List<DbParameter>();
  670. string SqlText = @"select a.LocationCode,isnull(b.Qty,0) Qty from ICSLocation a left join (
  671. select LocationCode,isnull(max(Quantity),0) Qty
  672. from ICSWareHouseLotInfo GROUP BY LocationCode) b on a.LocationCode = b.LocationCode
  673. where SUBSTRING(SUBSTRING(a.LocationCode,CHARINDEX('-',a.LocationCode)+1,len(a.LocationCode)),1,1) = '0'";
  674. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  675. return dt;
  676. }
  677. //查询二期库存状态
  678. public DataTable GetGridJson_WareStatusTwo()
  679. {
  680. List<DbParameter> parameter = new List<DbParameter>();
  681. string SqlText = @"select a.LocationCode,isnull(b.Qty,0) Qty from ICSLocation a left join (
  682. select LocationCode,isnull(max(Quantity),0) Qty
  683. from ICSWareHouseLotInfo GROUP BY LocationCode) b on a.LocationCode = b.LocationCode
  684. where SUBSTRING(SUBSTRING(a.LocationCode,CHARINDEX('-',a.LocationCode)+1,len(a.LocationCode)),1,1) = '2'";
  685. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  686. return dt;
  687. }
  688. //查询三期库存状态
  689. public DataTable GetGridJson_WareStatusThree()
  690. {
  691. List<DbParameter> parameter = new List<DbParameter>();
  692. string SqlText = @"select a.LocationCode,isnull(b.Qty,0) Qty from ICSLocation a left join (
  693. select LocationCode,isnull(max(Quantity),0) Qty
  694. from ICSWareHouseLotInfo GROUP BY LocationCode) b on a.LocationCode = b.LocationCode
  695. where SUBSTRING(SUBSTRING(a.LocationCode,CHARINDEX('-',a.LocationCode)+1,len(a.LocationCode)),1,1) = '3'";
  696. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  697. return dt;
  698. }
  699. //查询物料配料进度
  700. public DataTable GetGridJson_ApplyStatus()
  701. {
  702. #region 注释
  703. // //范围内的所有生产领料单号
  704. // string SqlText = @"select distinct a.DispatcherName,a.ReceiverName,a.ApplyCode,a.Urgency,
  705. //a.MTIME,isnull(b.MUSER,'') MUSER,isnull(c.F_RealName,'') MUSERName,a.NeedDate+' '+a.NeedTime NeedTime,a.WorkPoint
  706. //from ICSMOApply a
  707. //left join ICSWareHouseLotInfoLog b on a.ApplyCode = b.TransCode and a.WorkPoint = b.WorkPoint
  708. //left join Sys_SRM_User c on b.MUSER = c.F_Account
  709. //where a.EATTRIBUTE ='01'
  710. //and CONVERT(VARCHAR(10), a.MTIME, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  711. //and CONVERT(VARCHAR(10), a.MTIME, 23) <= CONVERT(VARCHAR(10), GETDATE(), 23) ";
  712. // DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  713. // //是否配料
  714. // SqlText = @"select distinct a.ApplyCode,a.WorkPoint from ICSMOApply a
  715. // left join ICSWareHouseLotInfoLog b on a.ApplyCode = b.TransCode and a.WorkPoint = b.WorkPoint
  716. // where b.TransType ='15' and a.EATTRIBUTE ='01'
  717. //and CONVERT(VARCHAR(10), a.MTIME, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  718. //and CONVERT(VARCHAR(10), a.MTIME, 23) <= CONVERT(VARCHAR(10), GETDATE(), 23) ";
  719. // DataTable dtPL = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  720. // //是否配料完成
  721. // SqlText = @"select distinct a.ApplyCode,a.WorkPoint from (
  722. //select sum(Quantity) Quantity,sum(IssueQuantity) IssueQuantity,ApplyCode,WorkPoint
  723. //from ICSMOApply
  724. //where EATTRIBUTE ='01'
  725. //and CONVERT(VARCHAR(10), MTIME, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  726. //and CONVERT(VARCHAR(10), MTIME, 23) <= CONVERT(VARCHAR(10), GETDATE(), 23)
  727. //group by ApplyCode,WorkPoint) a where a.Quantity = a.IssueQuantity";
  728. // DataTable dtPLCom = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  729. // //运输中
  730. // SqlText = @"select distinct a.ApplyCode,a.WorkPoint FROM ICSMOApply a
  731. //left join ICSWareHouseLotInfoLog b on a.ApplyCode = b.TransCode and a.WorkPoint = b.WorkPoint
  732. //left join ICSContainerLot c on b.LotNo = c.lotNo and b.WorkPoint = c.WorkPoint
  733. //left join ICSContainer d on c.ContainerID = d.ID
  734. //left join ICSAGVTaskLog e on d.ContainerCode = e.ContainerCode and d.WorkPoint = e.WorkPoint
  735. //where (e.EATTRIBUTE2 = '未完成')
  736. //and CONVERT(VARCHAR(10), a.MTIME, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  737. //and CONVERT(VARCHAR(10), a.MTIME, 23) <= CONVERT(VARCHAR(10), GETDATE(), 23)";
  738. // DataTable dtYsing = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  739. // //运输完成
  740. // SqlText = @"select distinct a.ApplyCode,a.WorkPoint FROM ICSMOApply a
  741. //left join ICSWareHouseLotInfoLog b on a.ApplyCode = b.TransCode and a.WorkPoint = b.WorkPoint
  742. //left join ICSContainerLot c on b.LotNo = c.lotNo and b.WorkPoint = c.WorkPoint
  743. //left join ICSContainer d on c.ContainerID = d.ID
  744. //left join ICSAGVTaskLog e on d.ContainerCode = e.ContainerCode and d.WorkPoint = e.WorkPoint
  745. //where e.EATTRIBUTE2 = '已完成'
  746. //and CONVERT(VARCHAR(10), a.MTIME, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  747. //and CONVERT(VARCHAR(10), a.MTIME, 23) <= CONVERT(VARCHAR(10), GETDATE(), 23)";
  748. // DataTable dtYsed = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  749. // //收料完成
  750. // // SqlText = @"select distinct ApplyCode,WorkPoint from ICSMOApply where isnull(MUSERName,'') <> 'JOB'
  751. // //and CONVERT(VARCHAR(10), MTIME, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  752. // //and CONVERT(VARCHAR(10), MTIME, 23) <= CONVERT(VARCHAR(10), GETDATE(), 23)";
  753. // // DataTable dtSlCom = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  754. // dt.Columns.Add("Status", typeof(string));
  755. #endregion
  756. string sql = @"if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempPL'))
  757. drop table #tempPL
  758. --
  759. select distinct a.ApplyCode,a.WorkPoint into #tempPL from (
  760. select sum(Quantity) Quantity,sum(IssueQuantity) IssueQuantity,ApplyCode,WorkPoint
  761. from ICSMOApply
  762. where EATTRIBUTE ='01'
  763. and CONVERT(VARCHAR(10), MTIME, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  764. and CONVERT(VARCHAR(10), MTIME, 23) <= CONVERT(VARCHAR(10), GETDATE(), 23)
  765. group by ApplyCode,WorkPoint) a where a.Quantity = a.IssueQuantity
  766. select distinct a.DispatcherName,a.ReceiverName,a.ApplyCode,a.Urgency,
  767. max(a.MTIME) MTIME,isnull(b.MUSER,'') MUSER,isnull(c.F_RealName,'') MUSERName,a.NeedDate+' '+a.NeedTime NeedTime,h.LocationCode,
  768. case when b.TransType ='15' then '' else
  769. (case when d.ApplyCode is not null then '' else
  770. (case when g.EATTRIBUTE2 ='' then '' else
  771. (case when g.EATTRIBUTE2 ='' then '' else '' end) end) end) end as 'Status'
  772. from ICSMOApply a
  773. left join ICSWareHouseLotInfoLog b on a.ApplyCode = b.TransCode and a.WorkPoint = b.WorkPoint
  774. left join Sys_SRM_User c on b.MUSER = c.F_Account
  775. left join #tempPL d on a.ApplyCode = d.ApplyCode and a.WorkPoint = d.WorkPoint
  776. left join ICSContainerLot e on b.LotNo = e.lotNo and b.WorkPoint = e.WorkPoint
  777. left join ICSContainer f on e.ContainerID = f.ID
  778. left join ICSAGVTaskLog g on f.ContainerCode = g.ContainerCode and f.WorkPoint = g.WorkPoint
  779. left join ICSInventoryDetail h on a.InvCode = h.InvCode and a.WHCode = h.WHCode
  780. where a.EATTRIBUTE ='01' and isnull(a.MUSERName,'') = 'JOB'
  781. and CONVERT(VARCHAR(10), a.MTIME, 23) >=CONVERT(VARCHAR(10), DATEADD(day, -15, GETDATE()), 23)
  782. and CONVERT(VARCHAR(10), a.MTIME, 23) <= CONVERT(VARCHAR(10), GETDATE(), 23)
  783. group by a.DispatcherName,a.ReceiverName,a.ApplyCode,a.Urgency,b.MUSER,
  784. c.F_RealName,a.NeedDate,a.NeedTime,b.TransType,d.ApplyCode,g.EATTRIBUTE2,h.LocationCode";
  785. DataTable dt = Repository().GetDataTableBySql_Other(sql, "WMSconnstr", null);
  786. List<DataRow> DrList = dt.Select("1=1").OrderByDescending(x => x["Urgency"].ToString()).ThenBy(x => x["NeedTime"]).ToList();
  787. DataTable dtNew = new DataTable();
  788. if (DrList.Count > 0)
  789. {
  790. dtNew = DrList[0].Table.Clone();
  791. foreach (DataRow item in DrList)
  792. {
  793. dtNew.ImportRow(item);
  794. }
  795. }
  796. return dtNew;
  797. }
  798. //查询物料账龄分布(调接口)
  799. public DataTable GetGridJson_ItemAge()
  800. {
  801. DataTable dt = new DataTable();
  802. GetItemAge.ZWMS_SK_KB_WXQKCZLClient client = new GetItemAge.ZWMS_SK_KB_WXQKCZLClient();
  803. List<GetItemAge.ZgcnyStrc> list = new List<GetItemAge.ZgcnyStrc>();
  804. List<GetItemAge.ZwxqkczlStrc> listX = new List<GetItemAge.ZwxqkczlStrc>();
  805. client.ClientCredentials.UserName.UserName = "NWBG";
  806. client.ClientCredentials.UserName.Password = "nwbg321";
  807. list.Add(new GetItemAge.ZgcnyStrc { Mandt = "900", Werks = "1701", Kmonth = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString().PadLeft(2, '0') });
  808. list.Add(new GetItemAge.ZgcnyStrc { Mandt = "900", Werks = "1701", Kmonth = DateTime.Now.AddMonths(-1).Year.ToString() + DateTime.Now.AddMonths(-1).Month.ToString().PadLeft(2, '0') });
  809. list.Add(new GetItemAge.ZgcnyStrc { Mandt = "900", Werks = "1701", Kmonth = DateTime.Now.AddMonths(-2).Year.ToString() + DateTime.Now.AddMonths(-2).Month.ToString().PadLeft(2, '0') });
  810. list.Add(new GetItemAge.ZgcnyStrc { Mandt = "900", Werks = "1701", Kmonth = DateTime.Now.AddMonths(-3).Year.ToString() + DateTime.Now.AddMonths(-3).Month.ToString().PadLeft(2, '0') });
  811. list.Add(new GetItemAge.ZgcnyStrc { Mandt = "900", Werks = "1701", Kmonth = DateTime.Now.AddMonths(-4).Year.ToString() + DateTime.Now.AddMonths(-4).Month.ToString().PadLeft(2, '0') });
  812. list.Add(new GetItemAge.ZgcnyStrc { Mandt = "900", Werks = "1701", Kmonth = DateTime.Now.AddMonths(-5).Year.ToString() + DateTime.Now.AddMonths(-5).Month.ToString().PadLeft(2, '0') });
  813. dt.Columns.Add("YearRound", typeof(string));
  814. dt.Columns.Add("Qty1", typeof(decimal));
  815. dt.Columns.Add("Qty2", typeof(decimal));
  816. dt.Columns.Add("Qty3", typeof(decimal));
  817. dt.Columns.Add("Qty4", typeof(decimal));
  818. dt.Columns.Add("Qty5", typeof(decimal));
  819. dt.Columns.Add("Qty6", typeof(decimal));
  820. GetItemAge.ZwmsSkKbWxqkczlResponse res = client.ZwmsSkKbWxqkczl(new GetItemAge.ZwmsSkKbWxqkczl
  821. {
  822. Zflag = "Y",
  823. ItGcny = list.ToArray(),
  824. ItWxqkczl = listX.ToArray()
  825. });
  826. List<GetItemAge.ZwxqkczlStrc> list1 = res.ItWxqkczl.ToList().Where(x => x.Kmonth == DateTime.Now.AddMonths(-5).Year.ToString() + DateTime.Now.AddMonths(-5).Month.ToString().PadLeft(2, '0')).ToList();
  827. List<GetItemAge.ZwxqkczlStrc> list2 = res.ItWxqkczl.ToList().Where(x => x.Kmonth == DateTime.Now.AddMonths(-4).Year.ToString() + DateTime.Now.AddMonths(-4).Month.ToString().PadLeft(2, '0')).ToList();
  828. List<GetItemAge.ZwxqkczlStrc> list3 = res.ItWxqkczl.ToList().Where(x => x.Kmonth == DateTime.Now.AddMonths(-3).Year.ToString() + DateTime.Now.AddMonths(-3).Month.ToString().PadLeft(2, '0')).ToList();
  829. List<GetItemAge.ZwxqkczlStrc> list4 = res.ItWxqkczl.ToList().Where(x => x.Kmonth == DateTime.Now.AddMonths(-2).Year.ToString() + DateTime.Now.AddMonths(-2).Month.ToString().PadLeft(2, '0')).ToList();
  830. List<GetItemAge.ZwxqkczlStrc> list5 = res.ItWxqkczl.ToList().Where(x => x.Kmonth == DateTime.Now.AddMonths(-1).Year.ToString() + DateTime.Now.AddMonths(-1).Month.ToString().PadLeft(2, '0')).ToList();
  831. List<GetItemAge.ZwxqkczlStrc> list6 = res.ItWxqkczl.ToList().Where(x => x.Kmonth == DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString().PadLeft(2, '0')).ToList();
  832. dt.Rows.Add("1年以下", list1.Count == 0 ? 0 : list1.Where(x => x.Zaging == "1年以下").ToList()[0].Zstock,
  833. list2.Count == 0 ? 0 : list2.Where(x => x.Zaging == "1年以下").ToList()[0].Zstock,
  834. list3.Count == 0 ? 0 : list3.Where(x => x.Zaging == "1年以下").ToList()[0].Zstock,
  835. list4.Count == 0 ? 0 : list4.Where(x => x.Zaging == "1年以下").ToList()[0].Zstock,
  836. list5.Count == 0 ? 0 : list5.Where(x => x.Zaging == "1年以下").ToList()[0].Zstock,
  837. list6.Count == 0 ? 0 : list6.Where(x => x.Zaging == "1年以下").ToList()[0].Zstock);
  838. dt.Rows.Add("1-2年", list1.Count == 0 ? 0 : list1.Where(x => x.Zaging == "1-2年").ToList()[0].Zstock,
  839. list2.Count == 0 ? 0 : list2.Where(x => x.Zaging == "1-2年").ToList()[0].Zstock,
  840. list3.Count == 0 ? 0 : list3.Where(x => x.Zaging == "1-2年").ToList()[0].Zstock,
  841. list4.Count == 0 ? 0 : list4.Where(x => x.Zaging == "1-2年").ToList()[0].Zstock,
  842. list5.Count == 0 ? 0 : list5.Where(x => x.Zaging == "1-2年").ToList()[0].Zstock,
  843. list6.Count == 0 ? 0 : list6.Where(x => x.Zaging == "1-2年").ToList()[0].Zstock);
  844. dt.Rows.Add("2-3年", list1.Count == 0 ? 0 : list1.Where(x => x.Zaging == "2-3年").ToList()[0].Zstock,
  845. list2.Count == 0 ? 0 : list2.Where(x => x.Zaging == "2-3年").ToList()[0].Zstock,
  846. list3.Count == 0 ? 0 : list3.Where(x => x.Zaging == "2-3年").ToList()[0].Zstock,
  847. list4.Count == 0 ? 0 : list4.Where(x => x.Zaging == "2-3年").ToList()[0].Zstock,
  848. list5.Count == 0 ? 0 : list5.Where(x => x.Zaging == "2-3年").ToList()[0].Zstock,
  849. list6.Count == 0 ? 0 : list6.Where(x => x.Zaging == "2-3年").ToList()[0].Zstock);
  850. dt.Rows.Add("3-4年", list1.Count == 0 ? 0 : list1.Where(x => x.Zaging == "3-4年").ToList()[0].Zstock,
  851. list2.Count == 0 ? 0 : list2.Where(x => x.Zaging == "3-4年").ToList()[0].Zstock,
  852. list3.Count == 0 ? 0 : list3.Where(x => x.Zaging == "3-4年").ToList()[0].Zstock,
  853. list4.Count == 0 ? 0 : list4.Where(x => x.Zaging == "3-4年").ToList()[0].Zstock,
  854. list5.Count == 0 ? 0 : list5.Where(x => x.Zaging == "3-4年").ToList()[0].Zstock,
  855. list6.Count == 0 ? 0 : list6.Where(x => x.Zaging == "3-4年").ToList()[0].Zstock);
  856. dt.Rows.Add("4-5年", list1.Count == 0 ? 0 : list1.Where(x => x.Zaging == "4-5年").ToList()[0].Zstock,
  857. list2.Count == 0 ? 0 : list2.Where(x => x.Zaging == "4-5年").ToList()[0].Zstock,
  858. list3.Count == 0 ? 0 : list3.Where(x => x.Zaging == "4-5年").ToList()[0].Zstock,
  859. list4.Count == 0 ? 0 : list4.Where(x => x.Zaging == "4-5年").ToList()[0].Zstock,
  860. list5.Count == 0 ? 0 : list5.Where(x => x.Zaging == "4-5年").ToList()[0].Zstock,
  861. list6.Count == 0 ? 0 : list6.Where(x => x.Zaging == "4-5年").ToList()[0].Zstock);
  862. dt.Rows.Add("5-6年", list1.Count == 0 ? 0 : list1.Where(x => x.Zaging == "5-6年").ToList()[0].Zstock,
  863. list2.Count == 0 ? 0 : list2.Where(x => x.Zaging == "5-6年").ToList()[0].Zstock,
  864. list3.Count == 0 ? 0 : list3.Where(x => x.Zaging == "5-6年").ToList()[0].Zstock,
  865. list4.Count == 0 ? 0 : list4.Where(x => x.Zaging == "5-6年").ToList()[0].Zstock,
  866. list5.Count == 0 ? 0 : list5.Where(x => x.Zaging == "5-6年").ToList()[0].Zstock,
  867. list6.Count == 0 ? 0 : list6.Where(x => x.Zaging == "5-6年").ToList()[0].Zstock);
  868. dt.Rows.Add("6-7年", list1.Count == 0 ? 0 : list1.Where(x => x.Zaging == "6-7年").ToList()[0].Zstock,
  869. list2.Count == 0 ? 0 : list2.Where(x => x.Zaging == "6-7年").ToList()[0].Zstock,
  870. list3.Count == 0 ? 0 : list3.Where(x => x.Zaging == "6-7年").ToList()[0].Zstock,
  871. list4.Count == 0 ? 0 : list4.Where(x => x.Zaging == "6-7年").ToList()[0].Zstock,
  872. list5.Count == 0 ? 0 : list5.Where(x => x.Zaging == "6-7年").ToList()[0].Zstock,
  873. list6.Count == 0 ? 0 : list6.Where(x => x.Zaging == "6-7年").ToList()[0].Zstock);
  874. dt.Rows.Add("7-8年", list1.Count == 0 ? 0 : list1.Where(x => x.Zaging == "7-8年").ToList()[0].Zstock,
  875. list2.Count == 0 ? 0 : list2.Where(x => x.Zaging == "7-8年").ToList()[0].Zstock,
  876. list3.Count == 0 ? 0 : list3.Where(x => x.Zaging == "7-8年").ToList()[0].Zstock,
  877. list4.Count == 0 ? 0 : list4.Where(x => x.Zaging == "7-8年").ToList()[0].Zstock,
  878. list5.Count == 0 ? 0 : list5.Where(x => x.Zaging == "7-8年").ToList()[0].Zstock,
  879. list6.Count == 0 ? 0 : list6.Where(x => x.Zaging == "7-8年").ToList()[0].Zstock);
  880. dt.Rows.Add("8-9年", list1.Count == 0 ? 0 : list1.Where(x => x.Zaging == "8-9年").ToList()[0].Zstock,
  881. list2.Count == 0 ? 0 : list2.Where(x => x.Zaging == "8-9年").ToList()[0].Zstock,
  882. list3.Count == 0 ? 0 : list3.Where(x => x.Zaging == "8-9年").ToList()[0].Zstock,
  883. list4.Count == 0 ? 0 : list4.Where(x => x.Zaging == "8-9年").ToList()[0].Zstock,
  884. list5.Count == 0 ? 0 : list5.Where(x => x.Zaging == "8-9年").ToList()[0].Zstock,
  885. list6.Count == 0 ? 0 : list6.Where(x => x.Zaging == "8-9年").ToList()[0].Zstock);
  886. dt.Rows.Add("9-10年", list1.Count == 0 ? 0 : list1.Where(x => x.Zaging == "9-10年").ToList()[0].Zstock,
  887. list2.Count == 0 ? 0 : list2.Where(x => x.Zaging == "9-10年").ToList()[0].Zstock,
  888. list3.Count == 0 ? 0 : list3.Where(x => x.Zaging == "9-10年").ToList()[0].Zstock,
  889. list4.Count == 0 ? 0 : list4.Where(x => x.Zaging == "9-10年").ToList()[0].Zstock,
  890. list5.Count == 0 ? 0 : list5.Where(x => x.Zaging == "9-10年").ToList()[0].Zstock,
  891. list6.Count == 0 ? 0 : list6.Where(x => x.Zaging == "9-10年").ToList()[0].Zstock);
  892. dt.Rows.Add("10年以上", list1.Count == 0 ? 0 : list1.Where(x => x.Zaging == "10年以上").ToList()[0].Zstock,
  893. list2.Count == 0 ? 0 : list2.Where(x => x.Zaging == "10年以上").ToList()[0].Zstock,
  894. list3.Count == 0 ? 0 : list3.Where(x => x.Zaging == "10年以上").ToList()[0].Zstock,
  895. list4.Count == 0 ? 0 : list4.Where(x => x.Zaging == "10年以上").ToList()[0].Zstock,
  896. list5.Count == 0 ? 0 : list5.Where(x => x.Zaging == "10年以上").ToList()[0].Zstock,
  897. list6.Count == 0 ? 0 : list6.Where(x => x.Zaging == "10年以上").ToList()[0].Zstock);
  898. return dt;
  899. }
  900. //查询物料账龄分布(不调接口)
  901. public DataTable GetGridJson_ItemAgeNew()
  902. {
  903. string SqlText = @" DECLARE @LastTime1 nvarchar(40)=FORMAT(DATEADD(MONTH, -5, GETDATE()),'yyyy') + FORMAT(DATEADD(MONTH, -5, GETDATE()),'MM')
  904. DECLARE @LastTime2 nvarchar(40)=FORMAT(DATEADD(MONTH, -4, GETDATE()),'yyyy') + FORMAT(DATEADD(MONTH, -4, GETDATE()),'MM')
  905. DECLARE @LastTime3 nvarchar(40)=FORMAT(DATEADD(MONTH, -3, GETDATE()),'yyyy') + FORMAT(DATEADD(MONTH, -3, GETDATE()),'MM')
  906. DECLARE @LastTime4 nvarchar(40)=FORMAT(DATEADD(MONTH, -2, GETDATE()),'yyyy') + FORMAT(DATEADD(MONTH, -2, GETDATE()),'MM')
  907. DECLARE @LastTime5 nvarchar(40)=FORMAT(DATEADD(MONTH, -1, GETDATE()),'yyyy') + FORMAT(DATEADD(MONTH, -1, GETDATE()),'MM')
  908. DECLARE @LastTime6 nvarchar(40)=FORMAT(GETDATE(),'yyyy') + FORMAT(GETDATE(),'MM')
  909. SELECT a.AgeType YearRound
  910. ,b1.Quantity Qty1,b2.Quantity Qty2,b3.Quantity Qty3,b4.Quantity Qty4,b5.Quantity Qty5,b6.Quantity Qty6
  911. FROM (
  912. SELECT DISTINCT AgeType ,EATTRIBUTE1 FROM ICSInventoryAge) a
  913. LEFT JOIN (SELECT AgeType , Quantity
  914. FROM ICSInventoryAge WHERE MonthDate=@LastTime1 ) b1 ON a.AgeType=b1.AgeType
  915. LEFT JOIN (SELECT AgeType , Quantity
  916. FROM ICSInventoryAge WHERE MonthDate=@LastTime2 ) b2 ON a.AgeType=b2.AgeType
  917. LEFT JOIN (SELECT AgeType , Quantity
  918. FROM ICSInventoryAge WHERE MonthDate=@LastTime3 ) b3 ON a.AgeType=b3.AgeType
  919. LEFT JOIN (SELECT AgeType , Quantity
  920. FROM ICSInventoryAge WHERE MonthDate=@LastTime4 ) b4 ON a.AgeType=b4.AgeType
  921. LEFT JOIN (SELECT AgeType , Quantity
  922. FROM ICSInventoryAge WHERE MonthDate=@LastTime5 ) b5 ON a.AgeType=b5.AgeType
  923. LEFT JOIN (SELECT AgeType , Quantity
  924. FROM ICSInventoryAge WHERE MonthDate=@LastTime6 ) b6 ON a.AgeType=b6.AgeType
  925. ORDER BY a.EATTRIBUTE1";
  926. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  927. return dt;
  928. }
  929. //查询193/199/zmm188处理进度
  930. public List<DataTable> GetGridJson_StoreStatus()
  931. {
  932. List<DataTable> dtList = new List<DataTable>();
  933. DataTable dt = new DataTable();
  934. dt.Columns.Add("Month", typeof(string));
  935. dt.Columns.Add("QtyHangCount", typeof(decimal));
  936. dt.Columns.Add("QtyCount", typeof(decimal));
  937. DataTable dt1 = new DataTable();
  938. dt1.Columns.Add("Month", typeof(string));
  939. dt1.Columns.Add("QtyHangCount", typeof(decimal));
  940. dt1.Columns.Add("QtyCount", typeof(decimal));
  941. DataTable dt2 = new DataTable();
  942. dt2.Columns.Add("Month", typeof(string));
  943. dt2.Columns.Add("QtyHangCount", typeof(decimal));
  944. dt2.Columns.Add("QtyCount", typeof(decimal));
  945. GetStoreStatus.ZWMS_WS_HGPJDClient client = new GetStoreStatus.ZWMS_WS_HGPJDClient();
  946. client.ClientCredentials.UserName.UserName = "NWBG";
  947. client.ClientCredentials.UserName.Password = "nwbg321";
  948. List<GetStoreStatus.ZhgpJd> list = new List<GetStoreStatus.ZhgpJd>();
  949. GetStoreStatus.ZwmsWsHgpjdResponse res = client.ZwmsWsHgpjd(new GetStoreStatus.ZwmsWsHgpjd
  950. {
  951. THgjd = list.ToArray()
  952. });
  953. log.Info(JsonConvert.SerializeObject(res));
  954. #region 193库位
  955. List<GetStoreStatus.ZhgpJd> list193 = res.THgjd.ToList().Where(x => x.Lgort == "193").OrderBy(x => x.Spmon).ToList();//193库位
  956. foreach (GetStoreStatus.ZhgpJd item in list193)
  957. {
  958. dt.Rows.Add(item.Spmon, item.Zbhgh, item.Zbhgs);
  959. }
  960. dtList.Add(dt);
  961. log.Info("193:" + JsonConvert.SerializeObject(dt));
  962. #endregion
  963. #region 199库位
  964. List<GetStoreStatus.ZhgpJd> list199 = res.THgjd.ToList().Where(x => x.Lgort == "199").OrderBy(x => x.Spmon).ToList();//199库位
  965. foreach (GetStoreStatus.ZhgpJd item in list199)
  966. {
  967. dt1.Rows.Add(item.Spmon, item.Zbhgh, item.Zbhgs);
  968. }
  969. dtList.Add(dt1);
  970. log.Info("199:" + JsonConvert.SerializeObject(dt1));
  971. #endregion
  972. #region 188库位
  973. List<GetStoreStatus.ZhgpJd> list188 = res.THgjd.ToList().Where(x => x.Tcode == "ZMM188").OrderBy(x => x.Spmon).ToList();//188库位
  974. foreach (GetStoreStatus.ZhgpJd item in list188)
  975. {
  976. dt2.Rows.Add(item.Spmon, item.Zbhgh, item.Zbhgs);
  977. }
  978. dtList.Add(dt2);
  979. log.Info("ZMM188:" + JsonConvert.SerializeObject(dt2));
  980. #endregion
  981. log.Info( JsonConvert.SerializeObject(dtList));
  982. return dtList;
  983. }
  984. //查询库存物料周转天数
  985. public DataTable GetGridJson_ItemZzDays()
  986. {
  987. DataTable dt = new DataTable();
  988. GetItemZzDays.ZWMS_SK_KCWLZZTSClient client = new GetItemZzDays.ZWMS_SK_KCWLZZTSClient();
  989. client.ClientCredentials.UserName.UserName = "NWBG";
  990. client.ClientCredentials.UserName.Password = "nwbg321";
  991. dt.Columns.Add("Week", typeof(string));
  992. dt.Columns.Add("Days", typeof(string));
  993. GetItemZzDays.ZwmsSkKcwlzztsResponse res = client.ZwmsSkKcwlzzts(new GetItemZzDays.ZwmsSkKcwlzzts { T_906t1 = new GetItemZzDays.Zmm906t1[] { } });
  994. List<GetItemZzDays.Zmm906t1> list = res.T_906t1.ToList().OrderBy(x => x.Zcycle).ToList();
  995. foreach (GetItemZzDays.Zmm906t1 item in list)
  996. {
  997. dt.Rows.Add(item.Zcycle, item.Zaging);
  998. }
  999. return dt;
  1000. }
  1001. //发货信息
  1002. public DataTable GetSo()
  1003. {
  1004. List<DbParameter> parameter = new List<DbParameter>();
  1005. string SqlText = @"
  1006. SELECT DISTINCT a1.CreatedOn ,A1.BusinessDate ,A1.DocNo ,A2.DocLineNo ,A5.Code ,A6.NameCombineName ,
  1007. A5.SPECS ,A10.Name ,ISNULL(A2.ShipQtyInvAmount, 0) ,ISNULL(so.HasQuantity, 0) ,ISNULL(A2.ShipQtyInvAmount,0)-isnull(so.HasQuantity, 0) WMS未发数量
  1008. from {0}.DBO.SM_Ship A1
  1009. LEFT JOIN {0}.dbo.SM_ShipLine A2 ON A2.Ship=A1.ID
  1010. LEFT JOIN {0}.dbo.SM_ShipLine_Trl A3 ON A2.ID=A3.ID AND A3.SysMLFlag='zh-CN'
  1011. LEFT JOIN {0}.dbo.CBO_ItemMaster A5 ON A2.ItemInfo_ItemID=A5.ID
  1012. LEFT JOIN {0}.dbo.CBO_ItemMaster_Trl A6 ON A6.ID = A5.ID AND A6.SysMLFlag='zh-CN'
  1013. LEFT JOIN {0}.dbo.CBO_Wh A7 ON A2.WH=A7.ID
  1014. LEFT JOIN {0}.dbo.CBO_Wh_Trl A8 ON A8.ID = A7.ID AND A8.SysMLFlag='zh-CN'
  1015. LEFT JOIN {0}.dbo.Base_UOM A9 ON A2.PriceUOM=A9.ID
  1016. LEFT JOIN {0}.dbo.Base_UOM_Trl A10 ON A10.ID = A9.ID AND A10.SysMLFlag='zh-CN'
  1017. LEFT JOIN ICSSODispatch so on A1.DocNo=so.DispatchCode AND A2.DocLineNo=so.DispatchRow
  1018. where 1=1 AND ISNULL(A2.WH,'')!=''";
  1019. if (!string.IsNullOrWhiteSpace(StratTime))
  1020. {
  1021. SqlText += " and a1.CreatedOn>'" + StratTime + "'";
  1022. }
  1023. if (!string.IsNullOrWhiteSpace(EndTime))
  1024. {
  1025. SqlText += " and a1.CreatedOn<'" + EndTime + "'";
  1026. }
  1027. if (string.IsNullOrWhiteSpace(StratTime) && string.IsNullOrWhiteSpace(EndTime) && !string.IsNullOrWhiteSpace(advDays))
  1028. {
  1029. SqlText += " and a1.CreatedOn>CAST(CAST(DATEADD(day, -" + advDays + ", GETDATE()) as date) as varchar(10)) + ' 00:00:00'";
  1030. }
  1031. if (string.IsNullOrWhiteSpace(StratTime) && string.IsNullOrWhiteSpace(EndTime) && string.IsNullOrWhiteSpace(advDays))
  1032. {
  1033. SqlText += " and a1.CreatedOn>CAST(CAST(GETDATE() as date) as varchar(10)) + ' 00:00:00'";
  1034. }
  1035. SqlText += @"order by a1.CreatedOn ";
  1036. SqlText = string.Format(SqlText, ERPName, workpoint);
  1037. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  1038. return dt;
  1039. }
  1040. //工单欠料信息
  1041. public DataTable GetOwe()
  1042. {
  1043. List<DbParameter> parameter = new List<DbParameter>();
  1044. string SqlText = @" SELECT a.DocNo U9工单,a.startDate 开工日期,BItem.Code 母件料号,BItem.Name 母件名称,BItem.SPECS 母件规格,A.ProductQty 工单数量,
  1045. UOM.Name ,cBItem.Code ,cBItem.Name ,cBItem.SPECS ,--b.id,c.id,d.MO,
  1046. b.ActualReqQty,c.IssuedQty,d.qty,
  1047. ISNULL(b.ActualReqQty, 0)-ISNULL(c.IssuedQty, 0)+ISNULL(d.qty, 0) as
  1048. from {0}.DBO.MO_MO a
  1049. LEFT JOIN {0}.DBO.CBO_ItemMaster BItem on BItem.ID=a.ItemMaster
  1050. LEFT JOIN {0}.DBO.Base_UOM_Trl UOM ON UOM.ID = BItem.InventoryUOM
  1051. LEFT JOIN {0}.DBO.MO_MoPickList b on a.ID=B.MO
  1052. LEFT JOIN {0}.DBO.CBO_ItemMaster cBItem on b.ItemMaster=cBItem.ID
  1053. LEFT JOIN {0}.DBO.MO_IssueDocLine c on a.ID=c.MO and b.ItemMaster=c.Item
  1054. LEFT JOIN (SELECT b.MO,b.IssuedQty as qty,b.Item from {0}.DBO.mo_IssueDoc a
  1055. INNER JOIN {0}.DBO.MO_IssueDocLine b on a.ID=b.IssueDoc
  1056. INNER JOIN {0}.DBO.MO_IssueDocLine c on b.SourceIssueDocLine=c.ID
  1057. where a.IssueType='1' ) d on a.ID=d.MO and b.ItemMaster=d.Item
  1058. where a.DocState<>3 ";
  1059. //if (!string.IsNullOrWhiteSpace(StratTime))
  1060. //{
  1061. // SqlText += " and a.CreatedOn>'" + StratTime + "'";
  1062. //}
  1063. //if (!string.IsNullOrWhiteSpace(EndTime))
  1064. //{
  1065. // SqlText += " and a.CreatedOn<'" + EndTime + "'";
  1066. //}
  1067. if (!string.IsNullOrWhiteSpace(advDays))
  1068. {
  1069. SqlText += @" and a.startDate>CAST(CAST(DATEADD(day, -" + advDays + @", GETDATE()) as date) as varchar(10)) + ' 00:00:00'
  1070. and a.startDate<=CAST(CAST(GETDATE() as date) as varchar(10)) + ' 23:59:59'";
  1071. }
  1072. if (string.IsNullOrWhiteSpace(StratTime) && string.IsNullOrWhiteSpace(EndTime) && string.IsNullOrWhiteSpace(advDays))
  1073. {
  1074. SqlText += @" and a.startDate>CAST(CAST(GETDATE() as date) as varchar(10)) + ' 00:00:00'
  1075. and a.startDate<=CAST(CAST(GETDATE() as date) as varchar(10)) + ' 23:59:59'";
  1076. }
  1077. SqlText += @"order by a.startDate ";
  1078. SqlText = string.Format(SqlText, ERPName, workpoint);
  1079. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  1080. return dt;
  1081. }
  1082. public static void WriteLogFile(string input, string txtName)
  1083. {
  1084. try
  1085. {
  1086. string logAdress = "C:\\看板日志" + "\\";
  1087. if (!System.IO.Directory.Exists(logAdress))
  1088. {
  1089. System.IO.Directory.CreateDirectory(logAdress);//不存在就创建目录
  1090. }
  1091. string adress = logAdress + txtName;
  1092. if (!System.IO.Directory.Exists(adress))
  1093. {
  1094. System.IO.Directory.CreateDirectory(adress);//不存在就创建目录
  1095. }
  1096. // string logAdress = ConfigurationManager.AppSettings["logAdress"].ToString();
  1097. /**/
  1098. ///指定日志文件的目录
  1099. string fname = adress + "\\" + "log" + DateTime.Now.ToString("yy-MM-dd") + ".txt";
  1100. /**/
  1101. ///定义文件信息对象
  1102. FileInfo finfo = new FileInfo(fname);
  1103. if (!finfo.Exists)
  1104. {
  1105. FileStream fs;
  1106. fs = File.Create(fname);
  1107. fs.Close();
  1108. finfo = new FileInfo(fname);
  1109. }
  1110. /**/
  1111. ///判断文件是否存在以及是否大于2K
  1112. if (finfo.Length > 1024 * 1024 * 10)
  1113. {
  1114. /**/
  1115. ///文件超过10MB则重命名
  1116. File.Move(logAdress + "\\Log\\" + txtName + ".txt", Directory.GetCurrentDirectory() + DateTime.Now.TimeOfDay + "\\Log\\" + txtName + ".txt");
  1117. /**/
  1118. ///删除该文件
  1119. //finfo.Delete();
  1120. }
  1121. //finfo.AppendText();
  1122. /**/
  1123. ///创建只写文件流
  1124. using (FileStream fs = finfo.OpenWrite())
  1125. {
  1126. /**/
  1127. ///根据上面创建的文件流创建写数据流
  1128. StreamWriter w = new StreamWriter(fs);
  1129. /**/
  1130. ///设置写数据流的起始位置为文件流的末尾
  1131. ///设置写数据流的起始位置为文件流的末尾
  1132. w.BaseStream.Seek(0, SeekOrigin.End);
  1133. w.WriteLine("*****************Start*****************");
  1134. w.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  1135. /**/
  1136. ///写入当前系统时间并换行
  1137. /**/
  1138. ///写入日志内容并换行
  1139. w.WriteLine(input);
  1140. /**/
  1141. ///写入------------------------------------“并换行
  1142. w.WriteLine("------------------END------------------------");
  1143. /**/
  1144. ///清空缓冲区内容,并把缓冲区内容写入基础流
  1145. w.Flush();
  1146. /**/
  1147. ///关闭写数据流
  1148. w.Close();
  1149. }
  1150. }
  1151. catch (Exception ex)
  1152. { }
  1153. }
  1154. }
  1155. }