金豪看板
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.

1846 lines
88 KiB

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
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
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
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
  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 Newtonsoft.Json;
  13. using NFine.Domain._02_ViewModel;
  14. using NFine.Data.Extensions;
  15. using Newtonsoft.Json.Linq;
  16. namespace NFine.Application.SRM
  17. {
  18. public class WatchPanelApp : RepositoryFactory<ModuleEntity>
  19. {
  20. //到货明细
  21. public DataTable GetList1(string queryJson, ref Pagination jqgridparam)
  22. {
  23. var queryParam = queryJson.ToJObject();
  24. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  25. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  26. List<DbParameter> parameter = new List<DbParameter>();
  27. string SqlText = @"
  28. select * from (
  29. SELECT *,
  30. - ,
  31. CASE WHEN -> 0 THEN '' WHEN > 0 THEN '' ELSE '' END
  32. FROM (
  33. SELECT cc.receiptNo ,dd.orderno ,dd.itemcode ,dd.planqty ,inv.invname ,
  34. isnull((
  35. SELECT SUM (lotqty)
  36. FROM icsitemlot lot with (nolock)
  37. WHERE lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine
  38. AND isnull(IQCStatus,'') !='' AND cc.workpoint=lot.workpoint),0) ,
  39. isnull((
  40. SELECT SUM (lotqty)
  41. FROM icsitemlot lot with (nolock)
  42. WHERE lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine
  43. AND isnull(IQCStatus,'') !='' AND cc.workpoint=lot.workpoint
  44. AND NOT EXISTS (
  45. SELECT 1 FROM ICSWareHouseLotInfo info
  46. WHERE info.lotno=lot.lotno AND info.workpoint=lot.workpoint)),0)
  47. FROM ICSINVReceipt cc with (nolock)
  48. LEFT JOIN ICSINVReceiptDetail dd with (nolock) ON cc.ReceiptNO=dd.ReceiptNO AND dd.workpoint=cc.workpoint
  49. LEFT JOIN ICSINVENTORY inv with (nolock) ON inv.invcode=dd.itemcode AND dd.workpoint=inv.workpoint
  50. WHERE cc.mtime >=DATEADD(week, -1,getdate())
  51. and cc.workpoint='" + workpoint + @"'
  52. ) ff ) gg
  53. ";
  54. DataTable dt = Repository().FindTablePageBySql_Other(SqlText, "MESconnstr", parameter.ToArray(), ref jqgridparam);
  55. return dt;
  56. }
  57. //来料不合格明细
  58. public DataTable GetList2(string queryJson, ref Pagination jqgridparam)
  59. {
  60. var queryParam = queryJson.ToJObject();
  61. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  62. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  63. List<DbParameter> parameter = new List<DbParameter>();
  64. string SqlText = @"
  65. select * from (
  66. SELECT cc.receiptNo ,dd.orderno ,dd.itemcode , inv.invname ,
  67. sum(lot.lotqty) ,kk.CKITEMDESC
  68. FROM ICSINVReceipt cc with (nolock)
  69. LEFT JOIN ICSINVReceiptDetail dd with (nolock) ON cc.ReceiptNO=dd.ReceiptNO AND dd.workpoint=cc.workpoint
  70. LEFT JOIN ICSINVENTORY inv with (nolock) ON inv.invcode=dd.itemcode AND dd.workpoint=inv.workpoint
  71. left join icsitemlot lot with (nolock) on lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine
  72. AND cc.workpoint=lot.workpoint
  73. left join (select * from (select ROW_NUMBER()over(partition by LOTNO order by mtime desc,id ) rowId,lotno ,errdata ,
  74. CASE WHEN NG='' THEN CKITEMDESC ELSE NG END CKITEMDESC
  75. from ICSIQCErrList ck with (nolock) where workpoint='" + workpoint + @"' and errdata='' ) as AuctionRecords
  76. where rowId=1) kk on kk.lotno=lot.lotno
  77. WHERE 1=1
  78. and cc.mtime >=DATEADD(MONTH, -1,getdate())
  79. -- and kk.errdata=''
  80. and isnull(lot.iqcstatus,'') =''
  81. and cc.workpoint='" + workpoint + @"'
  82. group by cc.receiptNo ,dd.orderno ,dd.itemcode , inv.invname ,kk.CKITEMDESC ) jj
  83. ";
  84. DataTable dt = Repository().FindTablePageBySql_Other(SqlText, "MESconnstr", parameter.ToArray(), ref jqgridparam);
  85. return dt;
  86. }
  87. //配料信息表
  88. public DataTable GetList3(string queryJson, ref Pagination jqgridparam)
  89. {
  90. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  91. var queryParam = queryJson.ToJObject();
  92. string type = queryParam["type"].ToString();
  93. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  94. List<DbParameter> parameter = new List<DbParameter>();
  95. string SqlText = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJRdTrans'))
  96. drop table #Temp_TJRdTrans
  97. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJRdTransLog'))
  98. drop table #Temp_TJRdTransLog
  99. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJResult'))
  100. drop table #Temp_TJResult
  101. select tt.rdcode ,tt.invcode , tt.rdstatus , tt.depname ,tt.fromstoragecode ,
  102. tt.mocode ,'' ,tt.rduser ,tt.mtime , CASE WHEN isnull(tt.actqty,0) !=0 then '' else '' end ,
  103. tt.rdNO,case when PLANQTY<0 then '退' else '' end LogType
  104. into #Temp_TJRdTrans
  105. from ICSRdTransTer tt with (nolock)
  106. left join icsmo mo with (nolock) on mo.mocode=tt.mocode and mo.moseq=tt.moseq and mo.workpoint=tt.workpoint
  107. where tt.rdtype=''
  108. AND TT.MTIME >DATEADD(MONTH, -1, GETDATE())
  109. AND TT.WORKPOINT='" + workpoint + @"'
  110. and CASE WHEN isnull(tt.actqty,0) !=0 then '' else '' end ='" + type + @"'
  111. SELECT * into #Temp_TJRdTransLog FROM (
  112. select LOG.MUSERNAME,LOG.TransNO,LOG.TransLine,LOG.MTIME
  113. ,row_number() over (partition by LOG.BUSINESSCODE,LOG.TransNO,LOG.TransLine order by LOG.LOTNO desc,ID) rn
  114. from ICSWareHouseLotInfoLog LOG with (nolock)
  115. WHERE EXISTS(SELECT 1 FROM #Temp_TJRdTrans TT
  116. WHERE tt.rdNO =LOG.TransLine
  117. AND TT.=LOG.TransNO AND LOG.BUSINESSCODE=tt.LogType and ='' )
  118. AND LOG.WORKPOINT='" + workpoint + @"'
  119. ) FF
  120. WHERE RN=1
  121. select distinct ,,,,
  122. CONVERT(varchar(19), , 21) ,CONVERT(varchar(19), , 21) , into #Temp_TJResult
  123. from (
  124. SELECT tt.*,log.MUSERNAME ,log.mtime
  125. FROM #Temp_TJRdTrans tt
  126. LEFT JOIN #Temp_TJRdTransLog log on tt.rdNO =LOG.TransLine AND TT.=LOG.TransNO
  127. ) gg ";
  128. DataTable dt = Repository().FindTablePageBySql_OtherTemp(SqlText, " #Temp_TJResult ",
  129. @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJRdTrans'))
  130. drop table #Temp_TJRdTrans
  131. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJRdTransLog'))
  132. drop table #Temp_TJRdTransLog
  133. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJResult'))
  134. drop table #Temp_TJResult ",
  135. "MESconnstr", parameter.ToArray(), ref jqgridparam);
  136. return dt;
  137. }
  138. //待入库明细
  139. public DataTable GetList4(string queryJson, ref Pagination jqgridparam)
  140. {
  141. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  142. var queryParam = queryJson.ToJObject();
  143. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  144. List<DbParameter> parameter = new List<DbParameter>();
  145. string SqlText = @"
  146. select * from (
  147. SELECT cc.receiptNo ,dd.orderno ,dd.itemcode , inv.invname ,
  148. sum(lot.lotqty) ,(select top 1 bincode from ICSWareHouseLotInfo info where info.lotno=lot.lotno
  149. and info.workpoint=cc.workpoint) ,lot.lotno
  150. FROM ICSINVReceipt cc with (nolock)
  151. LEFT JOIN ICSINVReceiptDetail dd with (nolock) ON cc.ReceiptNO=dd.ReceiptNO AND dd.workpoint=cc.workpoint
  152. LEFT JOIN ICSINVENTORY inv with (nolock) ON inv.invcode=dd.itemcode AND dd.workpoint=inv.workpoint
  153. left join icsitemlot lot with (nolock) on lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine AND cc.workpoint=lot.workpoint
  154. left join ICSWareHouseLotInfolog kk with (nolock) on kk.lotno=lot.lotno and kk.workpoint=cc.workpoint and kk.transtype='收'
  155. WHERE 1=1
  156. and kk.lotno is null
  157. and lot.IQCStatus= ''
  158. and cc.mtime >=DATEADD(month, -1,getdate())
  159. and cc.workpoint='" + workpoint + @"'
  160. group by cc.receiptNo ,dd.orderno ,dd.itemcode , inv.invname ,lot.lotno ,kk.tostackcode,cc.workpoint
  161. ) jj
  162. ";
  163. DataTable dt = Repository().FindTablePageBySql_Other(SqlText, "MESconnstr", parameter.ToArray(), ref jqgridparam);
  164. return dt;
  165. }
  166. //生产进度汇总表
  167. public DataTable GetList_WIPJinDu(string queryJson, string filters, ref Pagination jqgridparam)
  168. {
  169. try
  170. {
  171. List<DbParameter> parameter = new List<DbParameter>();
  172. #region 过滤条件
  173. string SQLWhere = "";
  174. if (!queryJson.Contains("[]"))
  175. {
  176. JObject jobject = JObject.Parse(queryJson);
  177. JArray array = JArray.Parse(jobject["value"].ToString());
  178. SQLWhere += " and A.SEGCODE in (";
  179. foreach(JObject j in array) {
  180. SQLWhere += "'" + j["value"].ToString()+"',";
  181. }
  182. SQLWhere= SQLWhere.TrimEnd(',');
  183. SQLWhere += ")";
  184. }
  185. #endregion
  186. string SqlText = GetCaiJiSQL(SQLWhere);
  187. DataTable dt = SqlHelper.GetDataTableBySql(SqlText);
  188. return dt;
  189. }
  190. catch (Exception ex)
  191. {
  192. WriteLogFile(ex.ToString(), "看板异常");
  193. }
  194. return null;
  195. }
  196. public DataTable GetList_WIPJinDu(string value)
  197. {
  198. try
  199. {
  200. WriteLogFile("参数:"+ value, "看板异常");
  201. List<DbParameter> parameter = new List<DbParameter>();
  202. #region 过滤条件
  203. string SQLWhere = "";
  204. if (!string.IsNullOrEmpty(value))
  205. {
  206. SQLWhere += " and A.SEGCODE in ('" + value .Replace(",","','")+ "')";
  207. }
  208. #endregion
  209. string SqlText = GetCaiJiSQL(SQLWhere);
  210. DataTable dt = SqlHelper.GetDataTableBySql(SqlText);
  211. return dt;
  212. }
  213. catch (Exception ex)
  214. {
  215. WriteLogFile(ex.ToString(), "看板异常");
  216. }
  217. return null;
  218. }
  219. private string GetCaiJiSQL(string SQLWhere)
  220. {
  221. string SqlText = @"
  222. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOSelect'))
  223. drop table #TempMOSelect
  224. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCaiJi'))
  225. drop table #TempCaiJi
  226. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_MINDaJian'))
  227. drop table #Temp_MINDaJian
  228. select distinct lot.lotno,mo.mocode as , mo.moseq ,
  229. a.StartPlanDate as ,c.INVPARSETYPE as ,
  230. mo.ITEMCODE as ,mo.moplanqty as ,lot.lotqty,a.mtime 线,A.SEGCODE AS 线
  231. into #TempMOSelect
  232. from icsmo2user A with (nolock)
  233. inner JOIN ICSMO mo with (nolock) ON A.MOCODE=mo.MOCODE AND A.MOSEQ=mo.MOSEQ
  234. left join ICSITEMLot lot with (nolock) on mo.mocode=lot.transno and mo.moseq=lot.transline
  235. LEFT JOIN ICSINVENTORY C with (nolock) ON C.INVCODE=mo.ITEMCODE
  236. where mo.itemcode like '30%' and a.rcard=''
  237. and a.StartPlanDate >= dateadd(day,-30,getdate())
  238. " + SQLWhere + @"
  239. select hh.lotno,hh.AB面,min(hh.mtime) mtime,tt.lotqty lotqty,,
  240. into #TempCaiJi
  241. from(
  242. select Rcard lotno,case when plane='BOTTOM' then 'B' else 'A' end AB面,min(mtime) mtime
  243. from ICSSZAOIDATA
  244. where Rcard is not null and Rcard!=''
  245. and Rcard in (select lotno from #TempMOSelect)
  246. group by Rcard,case when plane='BOTTOM' then 'B' else 'A' end
  247. union all
  248. select snno lotno,case when type='1' then 'A' else 'B' end AB面,min(data4) mtime
  249. from ICSAIODATA dd
  250. where snno is not null and snno!=''
  251. and snno in (select lotno from #TempMOSelect tt)
  252. group by snno ,case when type='1' then 'A' else 'B' end
  253. ) hh
  254. left join #TempMOSelect tt on hh.lotno=tt.lotno
  255. group by hh.lotno,hh.AB面,tt.lotqty,,
  256. select min(hh.mtime) mtime ,
  257. into #Temp_MINDaJian
  258. from ICSSMTFEEDINGINFO hh
  259. inner join #TempCaiJi tt on hh.mocode=tt.
  260. group by
  261. select * ,
  262. case when is not null and !=0 then cast(Convert(decimal(18,2),*1.0000/*100) as nvarchar) +'%'
  263. else '0%' end
  264. from (
  265. select gg.线,gg. ,gg.AB面,gg. ,gg. ,gg. ,gg.线 ,cc2.mtime ,
  266. (select min(mtime) from #TempCaiJi cc
  267. where cc.=gg. and cc.=gg. and cc.AB面=gg.AB面 ) ,
  268. gg.,
  269. (select sum(lotqty) from #TempCaiJi cc
  270. where cc.=gg. and cc.=gg. and cc.AB面=gg.AB面 )
  271. from (
  272. select cc.AB面,mm., mm.,
  273. mm.,mm.,
  274. mm. ,mm.,min(线) 线,mm.线
  275. from #TempCaiJi cc
  276. left join #TempMOSelect mm with (nolock) on cc.lotno=mm.lotno
  277. group by cc.AB面,mm., mm.,
  278. mm.,mm.,
  279. mm. ,mm.,mm.线
  280. ) gg
  281. left join #Temp_MINDaJian cc2 on cc2.=gg.
  282. ) jj
  283. order by 2,1,3
  284. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOSelect'))
  285. drop table #TempMOSelect
  286. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCaiJi'))
  287. drop table #TempCaiJi
  288. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_MINDaJian'))
  289. drop table #Temp_MINDaJian
  290. ";
  291. return SqlText;
  292. }
  293. //项目阶段
  294. public DataTable GetProjectJD()
  295. {
  296. List<DbParameter> parameter = new List<DbParameter>();
  297. string sql = @" select distinct REPLACE(PROJECTSTAGE, '生产确认表', '待装配') NAME from EXP_PROJECTPRODUCTIONSCHEDULE
  298. where OQC is null and not (PROJECTID>='2117101' and PROJECTID<='2117116') and REPLACE(PROJECTSTAGE, '', '') is not null";
  299. DataTable dt = OracleHelper.GetTable(sql, "Oracleconnstr", parameter.ToArray());
  300. return dt;
  301. //DataTable tblDatas = new DataTable("Datas");
  302. //tblDatas.Columns.Add("NAME", Type.GetType("System.String"));
  303. //for (int i = 0; i < 5; i++)
  304. //{
  305. // DataRow newRow;
  306. // newRow = tblDatas.NewRow();
  307. // newRow["NAME"] = i.ToString();
  308. // tblDatas.Rows.Add(newRow);
  309. //}
  310. //return tblDatas;
  311. }
  312. //设备类型
  313. public DataTable GetEQPType()
  314. {
  315. List<DbParameter> parameter = new List<DbParameter>();
  316. string sql = @" select distinct DEVICETYPE NAME from EXP_PROJECTPRODUCTIONSCHEDULE
  317. where OQC is null and not (PROJECTID>='2117101' and PROJECTID<='2117116') and DEVICETYPE is not null ";
  318. DataTable dt = OracleHelper.GetTable(sql, "Oracleconnstr", parameter.ToArray());
  319. return dt;
  320. }
  321. //状态
  322. public DataTable GetStatus()
  323. {
  324. List<DbParameter> parameter = new List<DbParameter>();
  325. string sql = @" select distinct case when PROJECTSTAGE ='FAT完成' then '完成' when PROJECTSTAGE ='FQC' then '完成'
  326. when BEGINDATE like '%-%-%' and TO_DATE(BEGINDATE,'YYYY-MM-DD')-sysdate < 7 and NVL(RTRIM(PROJECTSCHEDULE,'%'),0) <80 then '' else STATUS end NAME
  327. from EXP_PROJECTPRODUCTIONSCHEDULE
  328. where OQC is null and not (PROJECTID>='2117101' and PROJECTID<='2117116')
  329. and case when PROJECTSTAGE ='FAT完成' then '' when PROJECTSTAGE ='FQC' then ''
  330. when BEGINDATE like '%-%-%' and TO_DATE(BEGINDATE,'YYYY-MM-DD')-sysdate < 7 and NVL(RTRIM(PROJECTSCHEDULE,'%'),0) <80 then '' else STATUS end is not null ";
  331. DataTable dt = OracleHelper.GetTable(sql, "Oracleconnstr", parameter.ToArray());
  332. return dt;
  333. }
  334. //生产进度-层析柱Qty
  335. public DataTable GetWIPQty1()
  336. {
  337. try
  338. {
  339. List<DbParameter> parameter = new List<DbParameter>();
  340. string SqlText = @"
  341. SELECT
  342. sum(case when REPLACE( PROJECTSTAGE, '', '' ) like '%%' or
  343. REPLACE( PROJECTSTAGE, '', '' ) not like '%%'
  344. then to_number ( QUANTITY ) else 0 end ) WIPQTY,
  345. sum(case when REPLACE( PROJECTSTAGE, '', '' ) not like '%%' and
  346. REPLACE( PROJECTSTAGE, '', '' ) like '%%'
  347. then to_number ( QUANTITY ) else 0 end ) COMQTY,
  348. sum(to_number ( QUANTITY ) ) ZQTY,
  349. REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '', '' ), '', '' ), '', '' ) PROJECTStr
  350. FROM
  351. EXP_PROJECTPRODUCTIONSCHEDULE
  352. WHERE
  353. 1 = 1
  354. and not (PROJECTID>='2117101' and PROJECTID<='2117116')
  355. and DEVICETYPE in ('EAC系列')
  356. and OQC is null
  357. GROUP BY REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '', '' ), '', '' ), '', '' )
  358. HAVING sum(to_number ( QUANTITY ) )>0 ";
  359. DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
  360. return dt;
  361. }
  362. catch (Exception ex)
  363. {
  364. WriteLogFile(ex.ToString(), "看板异常");
  365. }
  366. return null;
  367. }
  368. //生产进度-设备Qty
  369. public DataTable GetWIPQty5()
  370. {
  371. try
  372. {
  373. List<DbParameter> parameter = new List<DbParameter>();
  374. string SqlText = @" SELECT
  375. sum(case when REPLACE( PROJECTSTAGE, '', '' ) like '%%' or
  376. REPLACE( PROJECTSTAGE, '', '' ) not like '%%'
  377. then to_number ( QUANTITY ) else 0 end ) WIPQTY,
  378. sum(case when REPLACE( PROJECTSTAGE, '', '' ) not like '%%' and
  379. REPLACE( PROJECTSTAGE, '', '' ) like '%%'
  380. then to_number ( QUANTITY ) else 0 end ) COMQTY,
  381. sum(to_number ( QUANTITY ) ) ZQTY,
  382. REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '', '' ), '', '' ), '', '' ) PROJECTStr
  383. FROM
  384. EXP_PROJECTPRODUCTIONSCHEDULE
  385. WHERE
  386. 1 = 1
  387. AND NOT ( PROJECTID >= '2117101' AND PROJECTID <= '2117116' )
  388. AND DEVICETYPE NOT IN ( 'SAC系列','EAC系列' )
  389. AND OQC IS NULL
  390. GROUP BY REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '', '' ), '', '' ), '', '' )
  391. HAVING sum(to_number ( QUANTITY ) )>0 ";
  392. DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
  393. return dt;
  394. }
  395. catch (Exception ex)
  396. {
  397. WriteLogFile(ex.ToString(), "看板异常");
  398. }
  399. return null;
  400. }
  401. //生产进度 柱状图 (在制数 完成数 )
  402. public DataTable GetWIPQty2()
  403. {
  404. try
  405. {
  406. //生产确认表 有值中: 电装开始 有值 就是已开工,电装开始 无值 就是待开工
  407. List<DbParameter> parameter = new List<DbParameter>();
  408. string SqlText = @" SELECT
  409. SUM(CASE WHEN PRODUCTIONCONFIRM IS NOT NULL AND ELECTRICASSEMBLYSTART IS NOT NULL
  410. THEN to_number(QUANTITY) ELSE 0 END) YKGQty,
  411. SUM(CASE WHEN PRODUCTIONCONFIRM IS NOT NULL AND ELECTRICASSEMBLYSTART IS NULL
  412. THEN to_number(QUANTITY) ELSE 0 END) DKGQty
  413. from EXP_PROJECTPRODUCTIONSCHEDULE
  414. WHERE 1=1 AND PRODUCTIONCONFIRM IS NOT NULL
  415. and not (PROJECTID>='2117101' and PROJECTID<='2117116')
  416. and OQC is null ";
  417. DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
  418. return dt;
  419. }
  420. catch (Exception ex)
  421. {
  422. WriteLogFile(ex.ToString(), "看板异常");
  423. }
  424. return null;
  425. }
  426. //设备类型在制数
  427. public DataTable GetWIPQty3()
  428. {
  429. try
  430. {
  431. //生产确认表 有值 FQC 无值
  432. List<DbParameter> parameter = new List<DbParameter>();
  433. string SqlText = @" SELECT
  434. SUM( to_number(QUANTITY) ) Qty,nvl(DEVICETYPE,'') EQPTypeName
  435. from EXP_PROJECTPRODUCTIONSCHEDULE
  436. WHERE 1=1 AND PRODUCTIONCONFIRM IS NOT NULL
  437. and not (PROJECTID>='2117101' and PROJECTID<='2117116')
  438. AND OQC IS NULL
  439. GROUP BY DEVICETYPE ";
  440. DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
  441. return dt;
  442. }
  443. catch (Exception ex)
  444. {
  445. WriteLogFile(ex.ToString(), "看板异常");
  446. }
  447. return null;
  448. }
  449. //待开工项目(Qty)
  450. public DataTable GetWIPQty4()
  451. {
  452. try
  453. {
  454. //生产确认表 有值 电装开始 无值
  455. List<DbParameter> parameter = new List<DbParameter>();
  456. string SqlText = @"
  457. SELECT SUM ( to_number ( QUANTITY ) ) Qty,
  458. SUBSTR ( BEGINDATE, 0, 4+instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) ) MonthStr
  459. FROM
  460. EXP_PROJECTPRODUCTIONSCHEDULE
  461. WHERE
  462. 1 = 1
  463. AND( (ELECTRICASSEMBLYSTART IS NULL
  464. AND PRODUCTIONCONFIRM IS NOT NULL
  465. and OQC IS NULL
  466. ) or PROJECTSTAGE='' )
  467. AND BEGINDATE IS NOT NULL
  468. and not (PROJECTID>='2117101' and PROJECTID<='2117116')
  469. GROUP BY
  470. SUBSTR ( BEGINDATE, 0, 4+instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) ),
  471. SUBSTR ( BEGINDATE, 0, 4 ),
  472. to_number ( SUBSTR ( BEGINDATE, 6, instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) - 1 ) )
  473. ORDER BY
  474. SUBSTR ( BEGINDATE, 0, 4 ),
  475. to_number ( SUBSTR ( BEGINDATE, 6, instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) - 1 ) )
  476. ";
  477. DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
  478. return dt;
  479. }
  480. catch (Exception ex)
  481. {
  482. WriteLogFile(ex.ToString(), "看板异常");
  483. }
  484. return null;
  485. }
  486. //收货进度
  487. public DataTable GetRCVJingDu()
  488. {
  489. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  490. List<DbParameter> parameter = new List<DbParameter>();
  491. string SqlText = @"
  492. if exists(select* from tempdb..sysobjects where id= object_id('tempdb..#TEMP_ItemCK'))
  493. drop table #TEMP_ItemCK
  494. select sum(lotqty) Qty,cktype
  495. INTO #TEMP_ItemCK
  496. from(
  497. select lot.lotno, lot.lotqty, lot.IQCStatus, lot.step,
  498. case when lot.step= '' and lot.IQCStatus= '' then ''
  499. when isnull(lot.step,'')!='' and lot.IQCStatus='' then ''
  500. when lot.IQCStatus= '' then '' else '' end CKType
  501. from ICSINVReceipt cc with (nolock)
  502. left join ICSINVReceiptDetail dd with (nolock) on cc.ReceiptNO= dd.ReceiptNO and dd.workpoint= cc.workpoint
  503. left join ICSITEMLot lot with (nolock) on lot.mcode= dd.itemcode and lot.TransNO= dd.ReceiptNO
  504. and lot.TransLine= dd.ReceiptLine and dd.workpoint= lot.workpoint
  505. where not exists(select 1 from ICSWareHouseLotInfoLog log with (nolock) where log.lotno= lot.lotno)
  506. and lot.lotno is not null
  507. and cc.workpoint ='" + workpoint + @"'
  508. and cc.mtime >=DATEADD(week, -1,getdate())
  509. ) gg
  510. where cktype!=''
  511. group by cktype
  512. select * from (
  513. SELECT QTY,CKTYPE,cast(CONVERT(DECIMAL(18,2),QTY/(SELECT SUM(QTY) FROM #TEMP_ItemCK )*100) as NVARCHAR) +'%' Qtypercent
  514. from #TEMP_ItemCK
  515. union all
  516. SELECT 0,'', '0%' Qtypercent
  517. where not EXISTS(select 1 from #TEMP_ItemCK where cktype='')
  518. union all
  519. SELECT 0,'', '0%' Qtypercent
  520. where not EXISTS(select 1 from #TEMP_ItemCK where cktype='')
  521. union all
  522. SELECT 0,'', '0%' Qtypercent
  523. where not EXISTS(select 1 from #TEMP_ItemCK where cktype='')
  524. ) ff
  525. order by case CKTYPE when '' then 0 when '' then 1 when '' then 2 else 3 end
  526. ";
  527. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  528. return dt;
  529. }
  530. //到货数量(item)
  531. public DataTable GetRCVQty(string type)
  532. {
  533. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  534. List<DbParameter> parameter = new List<DbParameter>();
  535. string SqlText = "";
  536. switch (type)
  537. {
  538. case "日":
  539. SqlText = @"
  540. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  541. DROP TABLE #TEMP_Itemrr_tt
  542. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  543. DROP TABLE #TEMP_Itemrr_tt2
  544. SELECT CONVERT( VARCHAR ( 100 ), DATEADD( DAY, number *- 1, getdate( ) ), 23 ) AS
  545. INTO #TEMP_Itemrr_tt2
  546. FROM master.dbo.spt_values
  547. WHERE type = 'p'
  548. AND number <= 6 AND number >= 0
  549. SELECT SUM( planqty ) QTY,
  550. CONVERT ( VARCHAR ( 100 ), mtime, 23 )
  551. INTO #TEMP_Itemrr_tt
  552. FROM
  553. ICSINVReceiptDetail
  554. WHERE
  555. mtime >= CONVERT ( VARCHAR ( 10 ), DATEADD( DAY, - 6, getdate( ) ), 23 ) + ' 00:00:00'
  556. AND workpoint = '" + workpoint + @"'
  557. GROUP BY
  558. CONVERT ( VARCHAR ( 100 ), mtime, 23 )
  559. SELECT substring( aa.,6,5) ,
  560. isnull( bb.qty, 0 ) QTY
  561. FROM
  562. #TEMP_Itemrr_tt2 aa
  563. LEFT JOIN #TEMP_Itemrr_tt bb ON aa. = bb.
  564. ORDER BY 1
  565. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  566. DROP TABLE #TEMP_Itemrr_tt
  567. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  568. DROP TABLE #TEMP_Itemrr_tt2 ";
  569. break;
  570. case "周":
  571. SqlText = @"
  572. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  573. DROP TABLE #TEMP_Itemrr_tt
  574. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  575. DROP TABLE #TEMP_Itemrr_tt2
  576. SELECT DATEPART(wk,CONVERT( VARCHAR ( 10 ), DATEADD( week, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS ,
  577. CONVERT( VARCHAR ( 4 ), DATEADD( week, -1*NUMBER, getdate( ) ),23)
  578. INTO #TEMP_Itemrr_tt2
  579. FROM master.dbo.spt_values
  580. WHERE
  581. type = 'p'
  582. AND number <= 7 AND number >= 0
  583. SELECT SUM( planqty ) QTY,
  584. DATEPART(wk, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) INTO #TEMP_Itemrr_tt
  585. FROM
  586. ICSINVReceiptDetail with (nolock)
  587. WHERE
  588. mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( week, -7, getdate( ) ),23)+' 00:00:00'
  589. AND workpoint = '" + workpoint + @"'
  590. GROUP BY DATEPART(wk, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23)
  591. ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(wk, mtime)
  592. SELECT
  593. aa.,
  594. isnull( bb.qty, 0 ) QTY
  595. FROM
  596. #TEMP_Itemrr_tt2 aa
  597. LEFT JOIN #TEMP_Itemrr_tt bb ON aa. = bb. AND aa. = bb.
  598. ORDER BY aa., aa.
  599. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  600. DROP TABLE #TEMP_Itemrr_tt
  601. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  602. DROP TABLE #TEMP_Itemrr_tt2
  603. "; break;
  604. case "月":
  605. SqlText = @"
  606. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  607. DROP TABLE #TEMP_Itemrr_tt
  608. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  609. DROP TABLE #TEMP_Itemrr_tt2
  610. SELECT DATEPART(month,CONVERT( VARCHAR ( 10 ), DATEADD( month, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS ,
  611. CONVERT( VARCHAR ( 4 ), DATEADD( month, -1*NUMBER, getdate( ) ),23)
  612. INTO #TEMP_Itemrr_tt2
  613. FROM master.dbo.spt_values
  614. WHERE
  615. type = 'p'
  616. AND number <= 11 AND number >= 0
  617. SELECT SUM( planqty ) QTY,
  618. DATEPART(month, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) INTO #TEMP_Itemrr_tt
  619. FROM
  620. ICSINVReceiptDetail with (nolock)
  621. WHERE
  622. mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( month, -11, getdate( ) ),23)+' 00:00:00'
  623. AND workpoint = '" + workpoint + @"'
  624. GROUP BY DATEPART(month, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23)
  625. ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(month, mtime)
  626. SELECT
  627. aa.,
  628. isnull( bb.qty, 0 ) QTY
  629. FROM
  630. #TEMP_Itemrr_tt2 aa
  631. LEFT JOIN #TEMP_Itemrr_tt bb ON aa. = bb. AND aa. = bb.
  632. ORDER BY aa., aa.
  633. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  634. DROP TABLE #TEMP_Itemrr_tt
  635. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  636. DROP TABLE #TEMP_Itemrr_tt2
  637. "; break;
  638. case "年": SqlText = @"
  639. SELECT SUM( planqty ) QTY,
  640. CONVERT( VARCHAR ( 4 ),mtime,23)
  641. FROM
  642. ICSINVReceiptDetail with (nolock)
  643. WHERE workpoint = '" + workpoint + @"'
  644. GROUP BY CONVERT( VARCHAR ( 4 ),mtime,23)
  645. ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23)
  646. "; break;
  647. }
  648. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  649. return dt;
  650. }
  651. //入库数量(item)
  652. public DataTable GetWareInQty(string type)
  653. {
  654. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  655. List<DbParameter> parameter = new List<DbParameter>();
  656. string SqlText = "";
  657. switch (type)
  658. {
  659. case "日":
  660. SqlText = @"
  661. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  662. DROP TABLE #TEMP_Itemrr_tt
  663. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  664. DROP TABLE #TEMP_Itemrr_tt2
  665. SELECT CONVERT( VARCHAR ( 100 ), DATEADD( DAY, number *- 1, getdate( ) ), 23 ) AS
  666. INTO #TEMP_Itemrr_tt2
  667. FROM master.dbo.spt_values
  668. WHERE type = 'p'
  669. AND number <= 6 AND number >= 0
  670. SELECT SUM( TRANSQTY ) QTY,
  671. CONVERT ( VARCHAR ( 100 ), MTIME, 23 )
  672. INTO #TEMP_Itemrr_tt
  673. FROM
  674. ICSWareHouseLotInfoLOG log with (nolock)
  675. WHERE
  676. MTIME >= CONVERT ( VARCHAR ( 10 ), DATEADD( DAY, - 6, getdate( ) ), 23 ) + ' 00:00:00'
  677. AND workpoint = '" + workpoint + @"' and log.transtype in ('收','退')
  678. GROUP BY
  679. CONVERT ( VARCHAR ( 100 ), MTIME, 23 )
  680. SELECT substring( aa.,6,5) ,
  681. isnull( bb.qty, 0 ) QTY
  682. FROM
  683. #TEMP_Itemrr_tt2 aa
  684. LEFT JOIN #TEMP_Itemrr_tt bb ON aa. = bb.
  685. ORDER BY 1
  686. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  687. DROP TABLE #TEMP_Itemrr_tt
  688. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  689. DROP TABLE #TEMP_Itemrr_tt2 ";
  690. break;
  691. case "周":
  692. SqlText = @"
  693. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  694. DROP TABLE #TEMP_Itemrr_tt
  695. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  696. DROP TABLE #TEMP_Itemrr_tt2
  697. SELECT DATEPART(wk,CONVERT( VARCHAR ( 10 ), DATEADD( week, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS ,
  698. CONVERT( VARCHAR ( 4 ), DATEADD( week, -1*NUMBER, getdate( ) ),23)
  699. INTO #TEMP_Itemrr_tt2
  700. FROM master.dbo.spt_values
  701. WHERE
  702. type = 'p'
  703. AND number <= 7 AND number >= 0
  704. SELECT SUM( transqty ) QTY,
  705. DATEPART(wk, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) INTO #TEMP_Itemrr_tt
  706. FROM
  707. ICSWareHouseLotInfolog log with (nolock)
  708. WHERE
  709. mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( week, -7, getdate( ) ),23)+' 00:00:00'
  710. AND workpoint = '" + workpoint + @"' and log.transtype in ('收','退')
  711. GROUP BY DATEPART(wk, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23)
  712. ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(wk, mtime)
  713. SELECT
  714. aa.,
  715. isnull( bb.qty, 0 ) QTY
  716. FROM
  717. #TEMP_Itemrr_tt2 aa
  718. LEFT JOIN #TEMP_Itemrr_tt bb ON aa. = bb. AND aa. = bb.
  719. ORDER BY aa., aa.
  720. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  721. DROP TABLE #TEMP_Itemrr_tt
  722. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  723. DROP TABLE #TEMP_Itemrr_tt2
  724. "; break;
  725. case "月":
  726. SqlText = @"
  727. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  728. DROP TABLE #TEMP_Itemrr_tt
  729. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  730. DROP TABLE #TEMP_Itemrr_tt2
  731. SELECT DATEPART(month,CONVERT( VARCHAR ( 10 ), DATEADD( month, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS ,
  732. CONVERT( VARCHAR ( 4 ), DATEADD( month, -1*NUMBER, getdate( ) ),23)
  733. INTO #TEMP_Itemrr_tt2
  734. FROM master.dbo.spt_values
  735. WHERE
  736. type = 'p'
  737. AND number <= 11 AND number >= 0
  738. SELECT SUM( transqty ) QTY,
  739. DATEPART(month, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) INTO #TEMP_Itemrr_tt
  740. FROM
  741. ICSWareHouseLotInfolog log with (nolock)
  742. WHERE
  743. mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( month, -11, getdate( ) ),23)+' 00:00:00'
  744. AND workpoint = '" + workpoint + @"' and log.transtype in ('收','退')
  745. GROUP BY DATEPART(month, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23)
  746. ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(month, mtime)
  747. SELECT
  748. aa.,
  749. isnull( bb.qty, 0 ) QTY
  750. FROM
  751. #TEMP_Itemrr_tt2 aa
  752. LEFT JOIN #TEMP_Itemrr_tt bb ON aa. = bb. AND aa. = bb.
  753. ORDER BY aa., aa.
  754. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  755. DROP TABLE #TEMP_Itemrr_tt
  756. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  757. DROP TABLE #TEMP_Itemrr_tt2
  758. "; break;
  759. case "年": SqlText = @"
  760. SELECT SUM( transqty ) QTY,
  761. CONVERT( VARCHAR ( 4 ),mtime,23)
  762. FROM
  763. ICSWareHouseLotInfolog log with (nolock)
  764. WHERE workpoint = '" + workpoint + @"' and log.transtype in ('收','退')
  765. GROUP BY CONVERT( VARCHAR ( 4 ),mtime,23)
  766. ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23)
  767. "; break;
  768. }
  769. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  770. return dt;
  771. }
  772. //配料进度
  773. public DataTable GetPeiLiaoJingDu()
  774. {
  775. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  776. List<DbParameter> parameter = new List<DbParameter>();
  777. string SqlText = @"
  778. select UnDoQty, DoneQty,
  779. case when DoneQty + UnDoQty=0 then '0%' else cast(Convert(decimal(18, 2), DoneQty / (DoneQty + UnDoQty) * 100) as NVARCHAR) + '%' end DoneQtyPer,
  780. case when DoneQty + UnDoQty=0 then '0%' else cast(Convert(decimal(18, 2), UnDoQty / (DoneQty + UnDoQty) * 100) as NVARCHAR) + '%' end UnDoQtyPer
  781. from(
  782. select isnull(sum(case when isnull(actqty, 0) = 0 then planqty else 0 end),0) UnDoQty,
  783. isnull(sum(case when isnull(actqty, 0) = 0 then 0 else actqty end),0) DoneQty
  784. from ICSRdTransTer with (nolock)
  785. where RdType = ''
  786. and planqty > 0 and workpoint ='" + workpoint + @"'
  787. and mtime >=DATEADD(MONTH, -1,getdate())
  788. ) gg
  789. ";
  790. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  791. DataTable retdd = new DataTable();
  792. retdd.Columns.Add("cktype", Type.GetType("System.String"));
  793. retdd.Columns.Add("Qty", Type.GetType("System.Decimal"));
  794. retdd.Columns.Add("Qtypercent", Type.GetType("System.String"));
  795. if (dt != null && dt.Rows.Count > 0)
  796. {
  797. DataRow newRow = retdd.NewRow();
  798. newRow["cktype"] = "待配料";
  799. newRow["Qty"] = Convert.ToDecimal(dt.Rows[0]["UnDoQty"].ToString());
  800. newRow["Qtypercent"] = dt.Rows[0]["UnDoQtyPer"].ToString();
  801. retdd.Rows.Add(newRow);
  802. DataRow newRow2 = retdd.NewRow();
  803. newRow2["cktype"] = "已配料";
  804. newRow2["Qty"] = Convert.ToDecimal(dt.Rows[0]["DoneQty"].ToString());
  805. newRow2["Qtypercent"] = dt.Rows[0]["DoneQtyPer"].ToString();
  806. retdd.Rows.Add(newRow2);
  807. }
  808. else
  809. {
  810. DataRow newRow = retdd.NewRow();
  811. newRow["cktype"] = "待配料";
  812. newRow["Qty"] = 0;
  813. newRow["Qtypercent"] = "0%";
  814. retdd.Rows.Add(newRow);
  815. DataRow newRow2 = retdd.NewRow();
  816. newRow2["cktype"] = "已配料";
  817. newRow2["Qty"] = 0;
  818. newRow2["Qtypercent"] = "0%";
  819. retdd.Rows.Add(newRow2);
  820. }
  821. return retdd;
  822. }
  823. public DataTable GetSScode(string cookie) {
  824. string sql = @"
  825. select distinct a.sscode as name,a.sscode as value,'' as selected
  826. from ICSSS as a,ICSSEG as b,ICSSHIFTTYPE as c
  827. where a.SEGID = b.ID and a.SHIFTTYPEID = c.ID and
  828. b.WorkPoint = a.WorkPoint and c.WorkPoint = a.WorkPoint
  829. order by 1 ";
  830. DataTable table= Repository().GetDataTableBySql_Other(sql, "MESconnstr", null);
  831. foreach (DataRow row in table.Rows)
  832. {
  833. if (!string.IsNullOrEmpty(cookie))
  834. {
  835. JObject jobject = JObject.Parse(cookie);
  836. JArray array = JArray.Parse(jobject["value"].ToString());
  837. foreach (JObject j in array) {
  838. if (j["value"].ToString() == row["value"].ToString())
  839. row["selected"] = "true";
  840. }
  841. }
  842. }
  843. table.AcceptChanges();
  844. return table;
  845. }
  846. public static void WriteLogFile(string input, string txtName)
  847. {
  848. try
  849. {
  850. string logAdress = "C:\\看板日志" + "\\";
  851. if (!System.IO.Directory.Exists(logAdress))
  852. {
  853. System.IO.Directory.CreateDirectory(logAdress);//不存在就创建目录
  854. }
  855. string adress = logAdress + txtName;
  856. if (!System.IO.Directory.Exists(adress))
  857. {
  858. System.IO.Directory.CreateDirectory(adress);//不存在就创建目录
  859. }
  860. // string logAdress = ConfigurationManager.AppSettings["logAdress"].ToString();
  861. /**/
  862. ///指定日志文件的目录
  863. string fname = adress + "\\" + "log" + DateTime.Now.ToString("yy-MM-dd") + ".txt";
  864. /**/
  865. ///定义文件信息对象
  866. FileInfo finfo = new FileInfo(fname);
  867. if (!finfo.Exists)
  868. {
  869. FileStream fs;
  870. fs = File.Create(fname);
  871. fs.Close();
  872. finfo = new FileInfo(fname);
  873. }
  874. /**/
  875. ///判断文件是否存在以及是否大于2K
  876. if (finfo.Length > 1024 * 1024 * 10)
  877. {
  878. /**/
  879. ///文件超过10MB则重命名
  880. File.Move(logAdress + "\\Log\\" + txtName + ".txt", Directory.GetCurrentDirectory() + DateTime.Now.TimeOfDay + "\\Log\\" + txtName + ".txt");
  881. /**/
  882. ///删除该文件
  883. //finfo.Delete();
  884. }
  885. //finfo.AppendText();
  886. /**/
  887. ///创建只写文件流
  888. using (FileStream fs = finfo.OpenWrite())
  889. {
  890. /**/
  891. ///根据上面创建的文件流创建写数据流
  892. StreamWriter w = new StreamWriter(fs);
  893. /**/
  894. ///设置写数据流的起始位置为文件流的末尾
  895. ///设置写数据流的起始位置为文件流的末尾
  896. w.BaseStream.Seek(0, SeekOrigin.End);
  897. w.WriteLine("*****************Start*****************");
  898. w.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  899. /**/
  900. ///写入当前系统时间并换行
  901. /**/
  902. ///写入日志内容并换行
  903. w.WriteLine(input);
  904. /**/
  905. ///写入------------------------------------“并换行
  906. w.WriteLine("------------------END------------------------");
  907. /**/
  908. ///清空缓冲区内容,并把缓冲区内容写入基础流
  909. w.Flush();
  910. /**/
  911. ///关闭写数据流
  912. w.Close();
  913. }
  914. }
  915. catch (Exception ex)
  916. { }
  917. }
  918. public string ConvertDataTableToJson(DataTable dt)
  919. {
  920. StringBuilder sbs = new StringBuilder();
  921. if (dt.Rows.Count > 0)//如果有记录
  922. {
  923. sbs.Append("{'" + dt.TableName + "':[");
  924. string str = "";
  925. foreach (DataRow dr in dt.Rows)//开始拼
  926. {
  927. string result = "";
  928. foreach (DataColumn dc in dt.Columns)
  929. {
  930. result += string.Format(",'{0}':'{1}'",
  931. dc.ColumnName, dr[dc.ColumnName]);
  932. }
  933. result = result.Substring(1);
  934. result = ",{" + result + "}";
  935. str += result;
  936. }
  937. str = str.Substring(1);
  938. sbs.Append(str);
  939. sbs.Append("]}");
  940. }
  941. else//如果没有记录
  942. {
  943. sbs.Append("");
  944. }
  945. return sbs.ToString();
  946. }
  947. #region 执行大看板
  948. public DataTable GetZhiXing_MO(string ItemNumber)
  949. {
  950. string SqlText = "";
  951. SqlText = @"
  952. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCCDD_Tt'))
  953. drop table #TempCCDD_Tt
  954. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCCDD'))
  955. drop table #TempCCDD
  956. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempFFF'))
  957. drop table #TempFFF
  958. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempXXXXX'))
  959. drop table #TempXXXXX
  960. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempZTPP'))
  961. drop table #TempZTPP
  962. SELECT C.molotcode as ,C.ITEMCODE ,dd.INVNAME ,C.MOCODE ,
  963. a.OPCODE ,ppp.opname ,us.UserName ,B.UserCodeBegin,
  964. CASE WHEN A.ACTIONRESULT='COLLECT_BEGIN' then '--------' WHEN A.ACTIONRESULT='COLLECT_END' then '--------' end as ,
  965. ISNULL(DATEDIFF(MINUTE, B.BeginDateTime, B.EndDateTime) ,0) as '',
  966. isnull(CONVERT(VARCHAR,B.BeginDateTime,120),'') ,
  967. isnull(CONVERT(VARCHAR,B.EndDateTime,120),'') ,A.ID,B.ID DetailID,B.BeginDateTime,B.EndDateTime
  968. into #TempCCDD_Tt
  969. FROM ICSLOTONWIP A with(nolock)
  970. LEFT JOIN ICSLOTONWIPDetail B with(nolock) ON A.LOTNO=B.LOTNO AND A.OPCODE=B.OPCODE
  971. LEFT JOIN ICSOP ppp with(nolock) on a.OPCODE=ppp.OPCODE
  972. LEFT JOIN Sys_User us with(nolock) on us.UserCode=B.UserCodeBegin
  973. LEFT JOIN ICSMO C with(nolock) ON A.MOCODE=C.MOCODE AND A.MOSEQ=C.MOSEQ
  974. LEFT JOIN ICSINVENTORY dd with(nolock) on C.ITEMCODE=dd.INVCODE
  975. where 1=1 AND b.Type='' and a.WorkPoint='6000' and B.BeginDateTime>=DATEADD(mm, -1, getdate())
  976. ORDER BY C.molotcode, C.ITEMCODE , us.UserName asc
  977. SELECT A.id,
  978. PP.Usercode ,
  979. pp.BeginTime ,
  980. pp.EndTime ,
  981. isnull(vv.EnumText,'') ,
  982. DATEDIFF(MINUTE, PP.BeginTime, PP.EndTime)
  983. into #TempFFF
  984. from ICSLOTONWIP A with(nolock)
  985. INNER JOIN ICSLOTPAUSE pp with(nolock) on A.Lotno=pp.lotno and A.opcode=pp.opcode
  986. LEFT JOIN Sys_EnumValues vv with(nolock) on vv.EnumValue=pp.RESCODE
  987. where pp.MODELCODE='' and vv.EnumKey='00022'
  988. and pp.BeginTime >=DATEADD(mm, -1, getdate())
  989. SELECT DD.DetailID,XX.,xx.,xx. ,xx.
  990. into #TempXXXXX
  991. FROM #TempCCDD_Tt DD
  992. LEFT JOIN #TempFFF XX ON DD.ID=XX.ID AND xx.[Usercode]=DD.UserCodeBegin AND xx. >DD.BeginDateTime
  993. AND ISNULL(xx., '2024-02-21 17:37:02') < ISNULL(DD.EndDateTime, '2025-02-21 17:37:02')
  994. SELECT DetailID,SUM() ,MIN() ,MAX() ,
  995. STUFF((select',' + from (SELECT DISTINCT
  996. FROM #TempXXXXX SS WHERE SS.DetailID=HH.DetailID ) DD for xml path('')),1,1,'')
  997. INTO #TempZTPP
  998. FROM #TempXXXXX HH
  999. GROUP BY DetailID
  1000. SELECT , , , , , , , ,
  1001. ISNULL(DATEDIFF(MINUTE, DD.BeginDateTime, DD.EndDateTime) ,0) as '',
  1002. ISNULL( DATEDIFF(MINUTE, dd.BeginDateTime, dd.EndDateTime) -ISNULL(xx.[],0) ,0) AS ,
  1003. ISNULL(xx.[],0) ,
  1004. DD.,
  1005. DD.,
  1006. ISNULL(xx. ,'') ,
  1007. ISNULL(xx.,'') ,
  1008. isnull(xx.[],'') ,
  1009. case when is not null and is null then '' else '' end
  1010. FROM #TempCCDD_Tt DD
  1011. LEFT JOIN #TempZTPP xx on XX.DetailID=DD.DetailID
  1012. WHERE CONVERT(varchar(10), dd., 21) =(SELECT MAX(CONVERT(varchar(10), , 21)) FROM #TempCCDD_Tt)
  1013. ORDER BY , , asc
  1014. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCCDD_Tt'))
  1015. drop table #TempCCDD_Tt
  1016. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCCDD'))
  1017. drop table #TempCCDD
  1018. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempFFF'))
  1019. drop table #TempFFF
  1020. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempXXXXX'))
  1021. drop table #TempXXXXX
  1022. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempZTPP'))
  1023. drop table #TempZTPP
  1024. ";
  1025. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  1026. return dt;
  1027. }
  1028. #endregion
  1029. #region 振翔生产进度区域一
  1030. public DataTable GetAreal1()
  1031. {
  1032. string where1 = "";
  1033. string SqlText = "";
  1034. SqlText = @" select * from(
  1035. select isnull(mpproduct,0) as ,isnull(mpsaleout,0) from ICSZXBoardPlan
  1036. where moth = CONVERT(CHAR(10),DATEADD(month,0,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) )a
  1037. left join (
  1038. select isnull(realsaleout,0) from ICSZXBoardSaleout
  1039. where id = '1') b on 1=1
  1040. left join ( select isnull(realsaleout,0) from ICSZXBoardSaleout
  1041. where id = '2') f on 1=1 ";
  1042. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  1043. return dt;
  1044. }
  1045. #endregion
  1046. #region 振翔生产进度
  1047. public DataTable GetProductProgress(string ItemNumber)
  1048. {
  1049. string where1 = "";
  1050. string SqlText = "";
  1051. SqlText = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempSSCC'))
  1052. drop table #TempSSCC
  1053. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempNum'))
  1054. drop table #tempNum
  1055. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOCCOM'))
  1056. drop table #TempMOCCOM
  1057. select distinct tso.socode ,convert(varchar(10),tso.plandate,120) as ,
  1058. isnull(convert(char(4),cus.fname),'') , ISNULL(inv.invname,'') as
  1059. into #TempSSCC
  1060. from
  1061. icsso tso with(nolock)
  1062. left join ICSCustomer cus with(nolock) on tso.cusid = cus.FCUSTID
  1063. left join icsmo tmo with(nolock) on tso.socode = tmo.molotcode
  1064. left join ICSINVENTORY inv with(nolock) on inv.invcode=tmo.molotcode
  1065. where tso.status = 'C' and tmo.id in(select moid from ICSMO2ROUTE with(nolock) )
  1066. select count(id) wipnum,molotcode
  1067. into #TempMOCCOM
  1068. FROM (SELECT id,molotcode
  1069. from (
  1070. select tmo.id, molotcode,tmo.moplanqty, wip.LOTQTY
  1071. from icsmo tmo with(nolock)
  1072. INNER join ICSLOTSIMULATION wip with(nolock) ON tmo.mocode = wip.mocode and wip.iscom='1'
  1073. and tmo.moseq=wip.moseq
  1074. where tmo.molotcode in (select distinct from #TempSSCC)
  1075. ) jj
  1076. group by id,molotcode
  1077. having(max(moplanqty)<=sum(LOTQTY))
  1078. ) HH
  1079. GROUP BY molotcode
  1080. select tso. ,isnull(( select count(*)
  1081. from icsmo tmo with(nolock) where tso. = tmo.molotcode),0) monum ,
  1082. isnull(CCOM.wipnum,0) wipnum ,
  1083. case when exists(select 1 from icsmo tmo where tso. = tmo.molotcode
  1084. and exists(select 1 from ICSLOTONWIP wip with(nolock) where tmo.mocode = wip.mocode and wip.actionresult!='') ) then 1 else 0 end wipbnum into #tempNum
  1085. from ( select distinct from #TempSSCC) tso
  1086. LEFT JOIN #TempMOCCOM CCOM ON CCOM.molotcode=TSO.
  1087. select row_number() over (order by a.,a.)as , a.*
  1088. from (
  1089. select tso., , ,
  1090. ,
  1091. CASE WHEN ISNULL(tnum.monum,0) =0 THEN '0%' ELSE
  1092. concat(cast(cast(tnum.wipnum * 1.0 / tnum.monum as decimal(18,3))* 100 as decimal(18,0)),'%') END ,
  1093. CASE WHEN ISNULL(tnum.monum,0) =0 THEN '' ELSE (case when tnum.wipnum/tnum.monum =1 then '' when tnum.wipbnum >0 then '' else '' end ) END
  1094. from #TempSSCC tso
  1095. left join #tempNum tnum on tnum. = tso.
  1096. ) a
  1097. ";
  1098. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  1099. return dt;
  1100. }
  1101. #endregion
  1102. #region 振翔月进度
  1103. #endregion
  1104. #region 振翔看板产量
  1105. public DataTable GetOutput()
  1106. {
  1107. string SqlText = "";
  1108. SqlText = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempNum'))
  1109. drop table #tempNum
  1110. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempData'))
  1111. drop table #tempData
  1112. --
  1113. select tmo.socode,tmo.monum,isnull(wip.wipnum ,0) as wipnum ,wip.EndTime
  1114. into #tempNum
  1115. from
  1116. (
  1117. select tso.socode ,count(*) as monum from
  1118. icsso tso
  1119. left join icsmo tmo on tso.socode = tmo.molotcode
  1120. group by tso.socode
  1121. ) tmo
  1122. left join (
  1123. select tso.socode ,count(*) as wipnum,min(wip.EndTime) EndTime from
  1124. icsso tso
  1125. left join (select mocode,molotcode from icsmo group by mocode,molotcode) tmo on tso.socode = tmo.molotcode
  1126. LEFT JOIN ICSLOTSIMULATION wip on tmo.mocode = wip.mocode
  1127. where wip.iscom='1'
  1128. group by tso.socode
  1129. ) wip on tmo.socode = wip.socode
  1130. select * into #tempData from(
  1131. select isnull(mpproduct,0) as from ICSZXBoardPlan
  1132. where moth = CONVERT(CHAR(10),DATEADD(month,-1,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) )a --
  1133. left join (
  1134. select isnull(mpproduct,0) as from ICSZXBoardPlan
  1135. where moth = CONVERT(CHAR(10),DATEADD(month,0,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) ) b on 1=1 --
  1136. left join (
  1137. select count(*) from #tempNum t where t.wipnum = t.monum and t.EndTime between
  1138. CONVERT(CHAR(10),DATEADD(month,-1,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120)
  1139. and CONVERT(CHAR(10),DATEADD(month,0,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120)) c on 1=1
  1140. left join (
  1141. select count(*) from #tempNum t where t.wipnum = t.monum and t.EndTime between
  1142. CONVERT(CHAR(10),DATEADD(month,0,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120)
  1143. and CONVERT(CHAR(10),DATEADD(month,-1,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120)) d on 1=1
  1144. left join (
  1145. select count(*) from #tempNum t where t.wipnum = t.monum and t.EndTime >=
  1146. CONVERT(CHAR(10),DATEADD(month,-MONTH(GETDATE())+1,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120)) e on 1=1
  1147. select isnull(,'0') , isnull(,'0') ,
  1148. isnull(,'0') , isnull(,'0') ,isnull(,'0') ,
  1149. --case when isnull(,0) = 0 then 0 else
  1150. --convert(decimal(10,2),isnull(,0))*1.0/isnull(convert(decimal(10,2),case when = 0 then 1 else end),1) end ,
  1151. --case when isnull(,0) = 0 then 0 else
  1152. --convert(decimal(10,2),isnull(,0))*1.0/isnull(convert(decimal(10,2),case when = 0 then 1 else end),1) end ,
  1153. case when isnull(,0) = 0 then 0 else
  1154. convert(decimal(10,2),isnull(,0))*1.0/isnull(convert(decimal(10,2),case when = 0 then 1 else end),1) end ,
  1155. case when isnull(,0) = 0 then 0 else
  1156. convert(decimal(10,2),isnull(,0))*1.0/isnull(convert(decimal(10,2),case when = 0 then 1 else end),1) end ,
  1157. month(DATEADD(month,-1,DATEADD(dd,-DAY(GETDATE())+1,GETDATE()))) ,
  1158. month(DATEADD(month,0,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())))
  1159. from #tempData
  1160. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempNum'))
  1161. drop table #tempNum
  1162. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempData'))
  1163. drop table #tempData
  1164. ";
  1165. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  1166. return dt;
  1167. }
  1168. #endregion
  1169. #region 振翔看板月产出
  1170. public DataTable monthOutput()
  1171. {
  1172. string SqlText = "";
  1173. //SqlText = @"
  1174. // if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempMO'))
  1175. // drop table #tempMO
  1176. // if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempM'))
  1177. // drop table #tempM
  1178. // --获取当前月份前十一个月的最大工单行数据
  1179. // select mocode,max(MOSEQ) as moseq
  1180. // into #tempMO
  1181. // from icsmo
  1182. // where MTIME between CONVERT(CHAR(10),DATEADD(month,-11,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111)
  1183. // and CONVERT(CHAR(10),DATEADD(month,0,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111)
  1184. // group by mocode
  1185. // --查询出当前年月向前十二月数据
  1186. // select *
  1187. // into #tempM
  1188. // from
  1189. // (select
  1190. // CONVERT(CHAR(7),DATEADD(month,-11,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
  1191. // union select
  1192. // CONVERT(CHAR(7),DATEADD(month,-10,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
  1193. // union select
  1194. // CONVERT(CHAR(7),DATEADD(month,-9,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
  1195. // union select
  1196. // CONVERT(CHAR(7),DATEADD(month,-8,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
  1197. // union select
  1198. // CONVERT(CHAR(7),DATEADD(month,-7,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
  1199. // union select
  1200. // CONVERT(CHAR(7),DATEADD(month,-6,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
  1201. // union select
  1202. // CONVERT(CHAR(7),DATEADD(month,-5,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
  1203. // union select
  1204. // CONVERT(CHAR(7),DATEADD(month,-4,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
  1205. // union select
  1206. // CONVERT(CHAR(7),DATEADD(month,-3,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
  1207. // union select
  1208. // CONVERT(CHAR(7),DATEADD(month,-2,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
  1209. // union select
  1210. // CONVERT(CHAR(7),DATEADD(month,-1,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
  1211. // union select
  1212. // CONVERT(CHAR(7),DATEADD(month,0,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont) TempM
  1213. // --获取前十二月数据
  1214. // select Mont,isnull(num,0) as num from #tempM tm
  1215. // left join (
  1216. // select convert(varchar(7),EndTime ,111) endtime, count(*) num
  1217. // from ICSLOTONWIP wip
  1218. // left join #tempMO mo on mo.moseq = wip.MOSEQ and mo.MOCODE = wip.MOCODE
  1219. // where wip.ACTIONRESULT = 'COLLECT_END'
  1220. // group by convert(varchar(7),EndTime ,111)) wip on tm.Mont= wip.endtime
  1221. // if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempMO'))
  1222. // drop table #tempMO
  1223. // if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempM'))
  1224. // drop table #tempM
  1225. // ";
  1226. SqlText = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempNum'))
  1227. drop table #tempNum
  1228. --
  1229. select tmo.socode,tmo.monum,isnull(wip.wipnum ,0) as wipnum ,wip.EndTime
  1230. into #tempNum
  1231. from
  1232. (
  1233. select tso.socode ,count(*) as monum from
  1234. icsso tso
  1235. left join icsmo tmo on tso.socode = tmo.molotcode
  1236. group by tso.socode
  1237. ) tmo
  1238. left join (
  1239. select tso.socode ,count(*) as wipnum,min(wip.EndTime) EndTime from
  1240. icsso tso
  1241. left join (select mocode,molotcode from icsmo group by mocode,molotcode) tmo on tso.socode = tmo.molotcode
  1242. LEFT JOIN ICSLOTSIMULATION wip on tmo.mocode = wip.mocode
  1243. where wip.iscom='1'
  1244. group by tso.socode
  1245. ) wip on tmo.socode = wip.socode
  1246. select count(*) num , CONVERT(CHAR(7),DATEADD(month,0,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont from #tempNum t
  1247. where t.wipnum = t.monum and t.EndTime between
  1248. CONVERT(CHAR(10),DATEADD(month,-1,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120)
  1249. and CONVERT(CHAR(10),DATEADD(month,0,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120)
  1250. union
  1251. select count(*) num , CONVERT(CHAR(7),DATEADD(month,-1,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont from #tempNum t
  1252. where t.wipnum = t.monum and t.EndTime between
  1253. CONVERT(CHAR(10),DATEADD(month,-2,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120)
  1254. and CONVERT(CHAR(10),DATEADD(month,-1,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120)
  1255. union
  1256. select count(*) num,CONVERT(CHAR(7),DATEADD(month,-2,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont from #tempNum t
  1257. where t.wipnum = t.monum and t.EndTime between
  1258. CONVERT(CHAR(10),DATEADD(month,-3,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120)
  1259. and CONVERT(CHAR(10),DATEADD(month,-2,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120)
  1260. union
  1261. select count(*) num,CONVERT(CHAR(7),DATEADD(month,-3,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont from #tempNum t
  1262. where t.wipnum = t.monum and t.EndTime between
  1263. CONVERT(CHAR(10),DATEADD(month,-4,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120)
  1264. and CONVERT(CHAR(10),DATEADD(month,-3,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120)
  1265. union
  1266. select count(*) num,CONVERT(CHAR(7),DATEADD(month,-4,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont from #tempNum t
  1267. where t.wipnum = t.monum and t.EndTime between
  1268. CONVERT(CHAR(10),DATEADD(month,-5,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120)
  1269. and CONVERT(CHAR(10),DATEADD(month,-4,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120)
  1270. union
  1271. select count(*) num,CONVERT(CHAR(7),DATEADD(month,-5,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont from #tempNum t
  1272. where t.wipnum = t.monum and t.EndTime between
  1273. CONVERT(CHAR(10),DATEADD(month,-6,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120)
  1274. and CONVERT(CHAR(10),DATEADD(month,-5,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120)
  1275. order by Mont
  1276. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempNum'))
  1277. drop table #tempNum
  1278. ";
  1279. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  1280. return dt;
  1281. }
  1282. #endregion
  1283. public DataTable GetZhiXing_OQC( )
  1284. {
  1285. string SqlText = "";
  1286. SqlText = @"
  1287. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIPPCC'))
  1288. drop table #TempIPPCC
  1289. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMonthcc'))
  1290. drop table #TempMonthcc
  1291. declare @begin datetime,@end datetime
  1292. set @end=GETDATE()
  1293. declare @months int
  1294. set @months=6
  1295. select convert(varchar(7),DATEADD(month,number*-1+1,@end) ,120) AS
  1296. into #TempMonthcc
  1297. from master.dbo.spt_values
  1298. where type='p'
  1299. AND number<=@months
  1300. and number>=1
  1301. order by 1
  1302. select count(1) Qty,result,
  1303. into #TempIPPCC
  1304. from (
  1305. select distinct ccode, invcode ,result,convert(varchar(7),mtime,120)
  1306. from ICSOQCLotNo
  1307. where mtime>=DATEADD(month,DATEDIFF(month,0,DATEADD(mm, -5, GETDATE() )),0)
  1308. and result in('','')
  1309. ) dd
  1310. group by ,result
  1311. select isnull( case when isnull(gg.QtyAll,0) =0 then 0 else
  1312. Convert(decimal(18,2), (isnull(gg.QtyAll,0)-isnull(FF.QtyNG,0))*1.00/gg.QtyAll*100) end
  1313. ,0) PercentNum,
  1314. cc.
  1315. FROM #TempMonthcc cc
  1316. left join (select sum(qty) QtyAll, from #TempIPPCC hh group by ) GG on cc.=gg.
  1317. left join (select isnull(sum(qty),0) QtyNG, from #TempIPPCC hh where result='' group by ) ff on cc.=ff.
  1318. ORDER BY cc.
  1319. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIPPCC'))
  1320. drop table #TempIPPCC
  1321. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMonthcc'))
  1322. drop table #TempMonthcc
  1323. ";
  1324. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  1325. return dt;
  1326. }
  1327. public DataTable GetZhiXing_RCVUnInWare()
  1328. {
  1329. string SqlText = "";
  1330. SqlText = @"
  1331. select A.CCODE , B.LOTNO,a.cInvCode as ,C.INVSTD ,C.INVNAME ,b.transno ,
  1332. A.iQuantity AS ,A.STNO ,CONVERT(varchar(100), a.MTime, 23) MTime ,
  1333. STUFF((select',' + MUSERName from (SELECT DISTINCT MUSERName FROM ICSOQCLotNo d where D.CCODE=a.cCode and d.InvCode=a.cInvCode ) DD for xml path('')),1,1,'')
  1334. from ICSPOArrive a with(nolock)
  1335. inner join icsitemlot b with(nolock) on a.LOTNO=b.LotNO
  1336. LEFT JOIN ICSINVENTORY C with(nolock) ON C.INVCODE = A.cInvCode
  1337. where EXISTS(select 1 from ICSOQCLotNo d with(nolock) where D.CCODE=a.cCode and d.InvCode=a.cInvCode and result='' )
  1338. and not EXISTS(select 1 from ICSWareHouseLotInfoLog ll with(nolock) where ll.lotno=a.lotno and ll.TransType='收')
  1339. order by A.CCODE,a.cInvCode,B.LOTNO ";
  1340. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  1341. return dt;
  1342. }
  1343. public DataTable GetOtherData()
  1344. {
  1345. string SqlText = "";
  1346. SqlText = @"
  1347. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Tcustttemp1'))
  1348. drop table #Tcustttemp1
  1349. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Tcusttfilter'))
  1350. drop table #Tcusttfilter
  1351. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TcusttDJ'))
  1352. drop table #TcusttDJ
  1353. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Tcustt_TOCKQty'))
  1354. drop table #Tcustt_TOCKQty
  1355. --wip表拼出所有的检验数据
  1356. select a.ITEMCODE,a.ROUTECODE,a.OPCODE, a.OPType AS OPTIONALOP, a.OPControlSeq,b.LOTNO,
  1357. isnull(b.ACTIONRESULT,'~') as ACTIONRESULT,b.MOCODE,b.MOSEQ,d.molotcode into #Tcustttemp1
  1358. from ICSITEMROUTE2OPLot a with(nolock)
  1359. left join icslotonwip b with(nolock) on a.ITEMCODE = b.ITEMCODE and a.ROUTECODE = b.ROUTECODE and a.OPCODE = b.OPCODE
  1360. inner join (SELECT distinct a.ITEMCODE,a.ROUTECODE
  1361. from ICSITEMROUTE2OPLot a with(nolock)
  1362. left join icslotonwip b with(nolock) on a.ITEMCODE = b.ITEMCODE and a.ROUTECODE = b.ROUTECODE and a.OPCODE = b.OPCODE
  1363. WHERE b.ACTIONRESULT is not null
  1364. ) c on a.ITEMCODE = c.ITEMCODE and a.ROUTECODE = c.ROUTECODE
  1365. left join icsmo d with(nolock) on d.MOCODE = b.MOCODE and b.SEQ = d.MOSEQ
  1366. order by ITEMCODE,OPControlSeq
  1367. --wip表里有在开工的排除
  1368. select ITEMCODE,ROUTECODE,ACTIONRESULT into #Tcusttfilter from icslotonwip with(nolock)
  1369. group by ITEMCODE,ROUTECODE,ACTIONRESULT HAVING COUNT(ITEMCODE) = 1 and COUNT(ROUTECODE)=1
  1370. --
  1371. select ITEMCODE,a.ROUTECODE,OPCODE,c.MOCODE,c.MOSEQ,c.LOTNO into #TcusttDJ from #Tcustttemp1 a
  1372. inner join
  1373. (select min(OPControlSeq) OPControlSeq,ROUTECODE from #Tcustttemp1 where OPTIONALOP = '' and LOTNO is null--
  1374. and ROUTECODE in
  1375. (select ROUTECODE from (select max(a.OPControlSeq) OPControlSeq,a.ROUTECODE from #Tcustttemp1 a
  1376. inner join (select min(OPControlSeq) OPControlSeq,ROUTECODE from #Tcustttemp1 where OPTIONALOP = '' and LOTNO is null group by ROUTECODE) b
  1377. on a.ROUTECODE = b.ROUTECODE and b.OPControlSeq >a.OPControlSeq and a.ACTIONRESULT = 'COLLECT_END' group by a.ROUTECODE) a )
  1378. GROUP BY ROUTECODE) b
  1379. on a.ROUTECODE = b.ROUTECODE and a.OPControlSeq = b.OPControlSeq
  1380. inner join ( select distinct mocode,MOSEQ,ROUTECODE,LOTNO from icslotonwip with(nolock) ) c
  1381. on a.ROUTECODE =c.ROUTECODE
  1382. where
  1383. not EXISTS( select 1 from #Tcusttfilter f
  1384. where f.ITEMCODE=a.ITEMCODE and f.ROUTECODE =a.ROUTECODE )
  1385. --
  1386. --1
  1387. select count(1) Qty into #Tcustt_TOCKQty
  1388. from (
  1389. select b.molotCode [] -- , dj.LOTNO [], dj.OPCODE []
  1390. from #TcusttDJ dj
  1391. inner join #Tcustttemp1 a on dj.ROUTECODE = a.ROUTECODE and a.OPCODE = dj.OPCODE and optionalop =''
  1392. inner join icsmo b with(nolock) on dj.MOCODE = b.MOCODE and dj.MOSEQ = b.MOSEQ
  1393. inner join ICSMO2user d with(nolock) on b.mocode = d.mocode and b.moseq = d.moseq and d.opcode = dj.OPCODE
  1394. union
  1395. select c.molotCode [] --, d.LOTNO [], d.OPCODE []
  1396. from
  1397. (select * from ICSITEMROUTE2OP with(nolock) where optionalop ='' and routecode in(
  1398. select DISTINCT routecode from ICSITEMROUTE2OP with(nolock) GROUP BY routecode HAVING count(*) = 1 )) a --线
  1399. inner JOIN ICSMO2ROUTE b with(nolock) on a.routeid = b.routeid
  1400. inner join ICSMO c with(nolock) on c.id = b.moid
  1401. inner join ICSMO2user d with(nolock) on c.mocode = d.mocode and c.moseq = d.moseq
  1402. inner join ICSITEMROUTE2OPLot lot with(nolock) on lot.itemcode = a.ITEMCODE and b.ROUTECODE = lot.ROUTECODE and lot.OPCODE = d.opcode
  1403. where not exists (select 1 from ICSLOTONWIP wip with(nolock) where wip.lotno = d.LOTNO and wip.opcode =d.OPCODE and wip.actionresult ='COLLECT_END')
  1404. ) jj
  1405. --1
  1406. select count(1) Qty into #Tcustt_CKQty
  1407. from (
  1408. SELECT distinct mm.molotcode --,b.LOTNO,a.OPCODE
  1409. from ICSQualityCKDATA a with(nolock)
  1410. LEFT JOIN ICSQualityCKDATADetail b with(nolock) on a.LOTNO=b.LOTNO and a.ID=b.DATAID
  1411. LEFT JOIN ICSLOTONWIP d with(nolock) on d.LotNo=a.LOTNO and d.opcode=a.OPCODE
  1412. LEFT JOIN icsmo mm with(nolock) on mm.MOCODE =d.MOCODE and mm.MOSEQ=d.MOSEQ
  1413. LEFT JOIN ICSITEMROUTE2OPLot ll with(nolock) on ll.OPCODE=a.OPCODE and ll.LotNo=a.LOTNO
  1414. WHERE ll.OPType='' and b.MTIME>= CONVERT(varchar(7), dateadd(mm,-1,getdate()), 21) +'-01 00:00:00'
  1415. and b.CKRESULT is not null
  1416. ) jj
  1417. select isnull((select Qty from #Tcustt_TOCKQty ),0) ,
  1418. isnull((select Qty from #Tcustt_CKQty ),0) ,
  1419. isnull((select count(1) from ICSZXCheck with(nolock) where checked='0'),0) ,
  1420. isnull((select count(1) from ICSZXCheck with(nolock) where checked='1' and month>= CONVERT(varchar(7), dateadd(mm,-1,getdate()), 21) +'-01' ),0)
  1421. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Tcustttemp1'))
  1422. drop table #Tcustttemp1
  1423. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Tcusttfilter'))
  1424. drop table #Tcusttfilter
  1425. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TcusttDJ'))
  1426. drop table #TcusttDJ
  1427. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Tcustt_TOCKQty'))
  1428. drop table #Tcustt_TOCKQty
  1429. ";
  1430. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  1431. return dt;
  1432. }
  1433. public DataTable GetCKData()
  1434. {
  1435. string SqlText = "";
  1436. SqlText = @"
  1437. SELECT TOP 100 mm.molotcode ,yy.INVNAME ,
  1438. b.MUSERName ,
  1439. pp.CKGROUPDESC ,
  1440. CONVERT(varchar(16), b.MTIME, 120) as ,
  1441. b.Type ,
  1442. CASE when b.CKRESULT ='1' then '' when b.CKRESULT ='0' then '' end as ''
  1443. from ICSQualityCKDATA a with(nolock)
  1444. LEFT JOIN ICSQualityCKDATADetail b with(nolock) on a.LOTNO=b.LOTNO and a.ID=b.DATAID
  1445. LEFT JOIN ICSLOTONWIP d with(nolock) on d.LotNo=a.LOTNO and d.opcode=a.OPCODE
  1446. LEFT JOIN ICSOQCCKLIST qq with(nolock) on qq.invcode= d.itemcode and qq.opcode=d.opcode and qq.ckgroupattr=b.Type and b.CKitemid=qq.id
  1447. LEFT JOIN icsmo mm with(nolock) on mm.MOCODE =d.MOCODE and mm.MOSEQ=d.MOSEQ
  1448. -- LEFT JOIN ICSMO2ROUTE tt on tt.mocode=mm.mocode and tt.EATTRIBUTE1=mm.MOSEQ
  1449. LEFT JOIN ICSINVENTORY yy with(nolock) on yy.INVCODE=mm.ITEMCODE
  1450. LEFT JOIN ICSITEMROUTE2OPLot ll with(nolock) on ll.OPCODE=a.OPCODE and ll.LotNo=a.LOTNO
  1451. LEFT JOIN ICSOQCCKGROUP pp with(nolock) on pp.CKGROUP=qq.CKGROUPCode
  1452. -- LEFT JOIN ICSECS sss on sss.ecscode=b.CKvalue
  1453. -- LEFT JOIN ICSECS s1 on s1.ecscode=b.CKvalue2
  1454. -- LEFT JOIN ICSECS s2 on s2.ecscode=b.CKvalue3
  1455. -- LEFT JOIN ICSECS s3 on s3.ecscode=b.CKvalue4
  1456. -- LEFT JOIN ICSECS s4 on s4.ecscode=b.CKvalue5
  1457. -- LEFT JOIN ICSECS s5 on s5.ecscode=b.CKvalue6
  1458. WHERE ll.OPType='' and 1=1
  1459. ORDER BY b.MTIME desc
  1460. ";
  1461. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  1462. return dt;
  1463. }
  1464. public DataTable GetCKOKRate()
  1465. {
  1466. string SqlText = "";
  1467. SqlText = @"
  1468. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Tcustccff'))
  1469. drop table #Tcustccff
  1470. select convert(varchar(7),DATEADD(month,number*-1,getdate()) ,120) AS ,number
  1471. into #Tcustccff
  1472. from master.dbo.spt_values
  1473. where type='p'
  1474. AND number<=5
  1475. and number>=0
  1476. order by 1
  1477. select ff., Convert(decimal(18,0),isnull(case when isnull(count(1),0)=0 then 0 else sum()*100.0000/count(1) end,0)) Qty
  1478. from #Tcustccff ff
  1479. left join (
  1480. SELECT distinct mm.molotcode ,b.LOTNO,a.OPCODE,
  1481. CASE when b.CKRESULT ='1' then 1 when b.CKRESULT ='0' then 0 end as ,
  1482. CONVERT(varchar(7), b.MTIME,21)
  1483. from ICSQualityCKDATA a with(nolock)
  1484. LEFT JOIN ICSQualityCKDATADetail b with(nolock) on a.LOTNO=b.LOTNO and a.ID=b.DATAID
  1485. LEFT JOIN ICSLOTONWIP d with(nolock) on d.LotNo=a.LOTNO and d.opcode=a.OPCODE
  1486. LEFT JOIN icsmo mm with(nolock) on mm.MOCODE =d.MOCODE and mm.MOSEQ=d.MOSEQ
  1487. LEFT JOIN ICSITEMROUTE2OPLot ll with(nolock) on ll.OPCODE=a.OPCODE and ll.LotNo=a.LOTNO
  1488. WHERE ll.OPType='' and b.MTIME>= CONVERT(varchar(7), dateadd(mm,-6,getdate()), 21) +'-01 00:00:00'
  1489. and b.CKRESULT is not null
  1490. ) jj on ff.=jj.
  1491. group by ff.,ff.number
  1492. order by ff.number desc
  1493. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Tcustccff'))
  1494. drop table #Tcustccff
  1495. ";
  1496. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  1497. return dt;
  1498. }
  1499. public DataTable GetCKOKRateALL()
  1500. {
  1501. string SqlText = "";
  1502. SqlText = @"
  1503. select Convert(decimal(18,0),isnull(case when isnull(count(1),0)=0 then 0 else sum()*1.0000/count(1) end,0)) Qty
  1504. from (
  1505. SELECT distinct mm.molotcode ,b.LOTNO,a.OPCODE,
  1506. CASE when b.CKRESULT ='1' then 1 when b.CKRESULT ='0' then 0 end as ,
  1507. CONVERT(varchar(7), b.MTIME,21)
  1508. from ICSQualityCKDATA a with(nolock)
  1509. LEFT JOIN ICSQualityCKDATADetail b with(nolock) on a.LOTNO=b.LOTNO and a.ID=b.DATAID
  1510. LEFT JOIN ICSLOTONWIP d with(nolock) on d.LotNo=a.LOTNO and d.opcode=a.OPCODE
  1511. LEFT JOIN icsmo mm with(nolock) on mm.MOCODE =d.MOCODE and mm.MOSEQ=d.MOSEQ
  1512. LEFT JOIN ICSITEMROUTE2OPLot ll with(nolock) on ll.OPCODE=a.OPCODE and ll.LotNo=a.LOTNO
  1513. WHERE ll.OPType=''
  1514. and b.CKRESULT is not null
  1515. ) jj
  1516. ";
  1517. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  1518. return dt;
  1519. }
  1520. }
  1521. }