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

1305 lines
59 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
  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. CASE WHEN -> 0 THEN '' WHEN > 0 THEN '' ELSE '' END
  31. FROM (
  32. SELECT cc.receiptNo ,dd.orderno ,dd.itemcode ,dd.planqty ,inv.invname ,
  33. isnull((
  34. SELECT SUM (lotqty)
  35. FROM icsitemlot lot with (nolock)
  36. WHERE lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine
  37. AND isnull(IQCStatus,'') !='' AND cc.workpoint=lot.workpoint),0) ,
  38. isnull((
  39. SELECT SUM (lotqty)
  40. FROM icsitemlot lot with (nolock)
  41. WHERE lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine
  42. AND isnull(IQCStatus,'') !='' AND cc.workpoint=lot.workpoint
  43. AND NOT EXISTS (
  44. SELECT 1 FROM ICSWareHouseLotInfo info
  45. WHERE info.lotno=lot.lotno AND info.workpoint=lot.workpoint)),0)
  46. FROM ICSINVReceipt cc with (nolock)
  47. LEFT JOIN ICSINVReceiptDetail dd with (nolock) ON cc.ReceiptNO=dd.ReceiptNO AND dd.workpoint=cc.workpoint
  48. LEFT JOIN ICSINVENTORY inv with (nolock) ON inv.invcode=dd.itemcode AND dd.workpoint=inv.workpoint
  49. WHERE cc.mtime >=DATEADD(week, -1,getdate())
  50. and cc.workpoint='" + workpoint + @"'
  51. ) ff ) gg
  52. ";
  53. DataTable dt = Repository().FindTablePageBySql_Other(SqlText, "MESconnstr", parameter.ToArray(), ref jqgridparam);
  54. return dt;
  55. }
  56. //来料不合格明细
  57. public DataTable GetList2(string queryJson, ref Pagination jqgridparam)
  58. {
  59. var queryParam = queryJson.ToJObject();
  60. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  61. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  62. List<DbParameter> parameter = new List<DbParameter>();
  63. string SqlText = @"
  64. select * from (
  65. SELECT cc.receiptNo ,dd.orderno ,dd.itemcode , inv.invname ,
  66. sum(lot.lotqty) ,kk.CKITEMDESC
  67. FROM ICSINVReceipt cc with (nolock)
  68. LEFT JOIN ICSINVReceiptDetail dd with (nolock) ON cc.ReceiptNO=dd.ReceiptNO AND dd.workpoint=cc.workpoint
  69. LEFT JOIN ICSINVENTORY inv with (nolock) ON inv.invcode=dd.itemcode AND dd.workpoint=inv.workpoint
  70. left join icsitemlot lot with (nolock) on lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine
  71. AND cc.workpoint=lot.workpoint
  72. left join (select * from (select ROW_NUMBER()over(partition by LOTNO order by mtime desc,id ) rowId,lotno ,errdata ,
  73. CASE WHEN NG='' THEN CKITEMDESC ELSE NG END CKITEMDESC
  74. from ICSIQCErrList ck with (nolock) where workpoint='" + workpoint + @"' and errdata='' ) as AuctionRecords
  75. where rowId=1) kk on kk.lotno=lot.lotno
  76. WHERE 1=1
  77. and cc.mtime >=DATEADD(MONTH, -1,getdate())
  78. -- and kk.errdata=''
  79. and isnull(lot.iqcstatus,'') =''
  80. and cc.workpoint='" + workpoint + @"'
  81. group by cc.receiptNo ,dd.orderno ,dd.itemcode , inv.invname ,kk.CKITEMDESC ) jj
  82. ";
  83. DataTable dt = Repository().FindTablePageBySql_Other(SqlText, "MESconnstr", parameter.ToArray(), ref jqgridparam);
  84. return dt;
  85. }
  86. //配料信息表
  87. public DataTable GetList3(string queryJson, ref Pagination jqgridparam)
  88. {
  89. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  90. var queryParam = queryJson.ToJObject();
  91. string type = queryParam["type"].ToString();
  92. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  93. List<DbParameter> parameter = new List<DbParameter>();
  94. string SqlText = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJRdTrans'))
  95. drop table #Temp_TJRdTrans
  96. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJRdTransLog'))
  97. drop table #Temp_TJRdTransLog
  98. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJResult'))
  99. drop table #Temp_TJResult
  100. select tt.rdcode ,tt.invcode , tt.rdstatus , tt.depname ,tt.fromstoragecode ,
  101. tt.mocode ,'' ,tt.rduser ,tt.mtime , CASE WHEN isnull(tt.actqty,0) !=0 then '' else '' end ,
  102. tt.rdNO,case when PLANQTY<0 then '退' else '' end LogType
  103. into #Temp_TJRdTrans
  104. from ICSRdTransTer tt with (nolock)
  105. left join icsmo mo with (nolock) on mo.mocode=tt.mocode and mo.moseq=tt.moseq and mo.workpoint=tt.workpoint
  106. where tt.rdtype=''
  107. AND TT.MTIME >DATEADD(MONTH, -1, GETDATE())
  108. AND TT.WORKPOINT='" + workpoint + @"'
  109. and CASE WHEN isnull(tt.actqty,0) !=0 then '' else '' end ='" + type + @"'
  110. SELECT * into #Temp_TJRdTransLog FROM (
  111. select LOG.MUSERNAME,LOG.TransNO,LOG.TransLine,LOG.MTIME ,row_number() over (partition by LOG.BUSINESSCODE,LOG.TransNO,LOG.TransLine order by LOG.LOTNO desc,ID) rn
  112. from ICSWareHouseLotInfoLog LOG with (nolock)
  113. WHERE EXISTS(SELECT 1 FROM #Temp_TJRdTrans TT
  114. WHERE tt.rdNO =LOG.TransLine
  115. AND TT.=LOG.TransNO AND LOG.BUSINESSCODE=tt.LogType and ='' )
  116. AND LOG.WORKPOINT='" + workpoint + @"'
  117. ) FF
  118. WHERE RN=1
  119. select distinct ,,,,
  120. CONVERT(varchar(19), , 21) ,CONVERT(varchar(19), , 21) , into #Temp_TJResult
  121. from (
  122. SELECT tt.*,log.MUSERNAME ,log.mtime
  123. FROM #Temp_TJRdTrans tt
  124. LEFT JOIN #Temp_TJRdTransLog log on tt.rdNO =LOG.TransLine AND TT.=LOG.TransNO ) gg ";
  125. DataTable dt = Repository().FindTablePageBySql_OtherTemp(SqlText, " #Temp_TJResult ",
  126. @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJRdTrans'))
  127. drop table #Temp_TJRdTrans
  128. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJRdTransLog'))
  129. drop table #Temp_TJRdTransLog
  130. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJResult'))
  131. drop table #Temp_TJResult ",
  132. "MESconnstr", parameter.ToArray(), ref jqgridparam);
  133. return dt;
  134. }
  135. //待入库明细
  136. public DataTable GetList4(string queryJson, ref Pagination jqgridparam)
  137. {
  138. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  139. var queryParam = queryJson.ToJObject();
  140. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  141. List<DbParameter> parameter = new List<DbParameter>();
  142. string SqlText = @"
  143. select * from (
  144. SELECT cc.receiptNo ,dd.orderno ,dd.itemcode , inv.invname ,
  145. sum(lot.lotqty) ,(select top 1 bincode from ICSWareHouseLotInfo info where info.lotno=lot.lotno
  146. and info.workpoint=cc.workpoint) ,lot.lotno
  147. FROM ICSINVReceipt cc with (nolock)
  148. LEFT JOIN ICSINVReceiptDetail dd with (nolock) ON cc.ReceiptNO=dd.ReceiptNO AND dd.workpoint=cc.workpoint
  149. LEFT JOIN ICSINVENTORY inv with (nolock) ON inv.invcode=dd.itemcode AND dd.workpoint=inv.workpoint
  150. left join icsitemlot lot with (nolock) on lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine AND cc.workpoint=lot.workpoint
  151. left join ICSWareHouseLotInfolog kk with (nolock) on kk.lotno=lot.lotno and kk.workpoint=cc.workpoint and kk.transtype='收'
  152. WHERE 1=1
  153. and kk.lotno is null
  154. and lot.IQCStatus= ''
  155. and cc.mtime >=DATEADD(month, -1,getdate())
  156. and cc.workpoint='" + workpoint + @"'
  157. group by cc.receiptNo ,dd.orderno ,dd.itemcode , inv.invname ,lot.lotno ,kk.tostackcode,cc.workpoint
  158. ) jj
  159. ";
  160. DataTable dt = Repository().FindTablePageBySql_Other(SqlText, "MESconnstr", parameter.ToArray(), ref jqgridparam);
  161. return dt;
  162. }
  163. //生产进度汇总表
  164. public DataTable GetList_WIPJinDu(string queryJson, string filters, ref Pagination jqgridparam)
  165. {
  166. try
  167. {
  168. List<DbParameter> parameter = new List<DbParameter>();
  169. #region 过滤条件
  170. string SQLWhere = "";
  171. if (!queryJson.Contains("[]"))
  172. {
  173. JObject jobject = JObject.Parse(queryJson);
  174. JArray array = JArray.Parse(jobject["value"].ToString());
  175. SQLWhere += " and A.SEGCODE in (";
  176. foreach(JObject j in array) {
  177. SQLWhere += "'" + j["value"].ToString()+"',";
  178. }
  179. SQLWhere= SQLWhere.TrimEnd(',');
  180. SQLWhere += ")";
  181. }
  182. #endregion
  183. string SqlText = GetCaiJiSQL(SQLWhere);
  184. DataTable dt = SqlHelper.GetDataTableBySql(SqlText);
  185. return dt;
  186. }
  187. catch (Exception ex)
  188. {
  189. WriteLogFile(ex.ToString(), "看板异常");
  190. }
  191. return null;
  192. }
  193. public DataTable GetList_WIPJinDu(string value)
  194. {
  195. try
  196. {
  197. WriteLogFile("参数:"+ value, "看板异常");
  198. List<DbParameter> parameter = new List<DbParameter>();
  199. #region 过滤条件
  200. string SQLWhere = "";
  201. if (!string.IsNullOrEmpty(value))
  202. {
  203. SQLWhere += " and A.SEGCODE in ('" + value .Replace(",","','")+ "')";
  204. }
  205. #endregion
  206. string SqlText = GetCaiJiSQL(SQLWhere);
  207. DataTable dt = SqlHelper.GetDataTableBySql(SqlText);
  208. return dt;
  209. }
  210. catch (Exception ex)
  211. {
  212. WriteLogFile(ex.ToString(), "看板异常");
  213. }
  214. return null;
  215. }
  216. private string GetCaiJiSQL(string SQLWhere)
  217. {
  218. string SqlText = @"
  219. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOSelect'))
  220. drop table #TempMOSelect
  221. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCaiJi'))
  222. drop table #TempCaiJi
  223. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_MINDaJian'))
  224. drop table #Temp_MINDaJian
  225. select distinct lot.lotno,mo.mocode as , mo.moseq ,
  226. a.StartPlanDate as ,c.INVPARSETYPE as ,
  227. mo.ITEMCODE as ,mo.moplanqty as ,lot.lotqty,a.mtime 线,A.SEGCODE AS 线
  228. into #TempMOSelect
  229. from icsmo2user A with (nolock)
  230. inner JOIN ICSMO mo with (nolock) ON A.MOCODE=mo.MOCODE AND A.MOSEQ=mo.MOSEQ
  231. left join ICSITEMLot lot with (nolock) on mo.mocode=lot.transno and mo.moseq=lot.transline
  232. LEFT JOIN ICSINVENTORY C with (nolock) ON C.INVCODE=mo.ITEMCODE
  233. where mo.itemcode like '30%' and a.rcard=''
  234. and a.StartPlanDate >= dateadd(day,-30,getdate())
  235. " + SQLWhere + @"
  236. select hh.lotno,hh.AB面,min(hh.mtime) mtime,tt.lotqty lotqty,,
  237. into #TempCaiJi
  238. from(
  239. select Rcard lotno,case when plane='BOTTOM' then 'B' else 'A' end AB面,min(mtime) mtime
  240. from ICSSZAOIDATA
  241. where Rcard is not null and Rcard!=''
  242. and Rcard in (select lotno from #TempMOSelect)
  243. group by Rcard,case when plane='BOTTOM' then 'B' else 'A' end
  244. union all
  245. select snno lotno,case when type='1' then 'A' else 'B' end AB面,min(data4) mtime
  246. from ICSAIODATA dd
  247. where snno is not null and snno!=''
  248. and snno in (select lotno from #TempMOSelect tt)
  249. group by snno ,case when type='1' then 'A' else 'B' end
  250. ) hh
  251. left join #TempMOSelect tt on hh.lotno=tt.lotno
  252. group by hh.lotno,hh.AB面,tt.lotqty,,
  253. select min(hh.mtime) mtime ,
  254. into #Temp_MINDaJian
  255. from ICSSMTFEEDINGINFO hh
  256. inner join #TempCaiJi tt on hh.mocode=tt.
  257. group by
  258. select * ,
  259. case when is not null and !=0 then cast(Convert(decimal(18,2),*1.0000/*100) as nvarchar) +'%'
  260. else '0%' end
  261. from (
  262. select gg.线,gg. ,gg.AB面,gg. ,gg. ,gg. ,gg.线 ,cc2.mtime ,
  263. (select min(mtime) from #TempCaiJi cc
  264. where cc.=gg. and cc.=gg. and cc.AB面=gg.AB面 ) ,
  265. gg.,
  266. (select sum(lotqty) from #TempCaiJi cc
  267. where cc.=gg. and cc.=gg. and cc.AB面=gg.AB面 )
  268. from (
  269. select cc.AB面,mm., mm.,
  270. mm.,mm.,
  271. mm. ,mm.,min(线) 线,mm.线
  272. from #TempCaiJi cc
  273. left join #TempMOSelect mm with (nolock) on cc.lotno=mm.lotno
  274. group by cc.AB面,mm., mm.,
  275. mm.,mm.,
  276. mm. ,mm.,mm.线
  277. ) gg
  278. left join #Temp_MINDaJian cc2 on cc2.=gg.
  279. ) jj
  280. order by 2,1,3
  281. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOSelect'))
  282. drop table #TempMOSelect
  283. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCaiJi'))
  284. drop table #TempCaiJi
  285. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_MINDaJian'))
  286. drop table #Temp_MINDaJian
  287. ";
  288. return SqlText;
  289. }
  290. //项目阶段
  291. public DataTable GetProjectJD()
  292. {
  293. List<DbParameter> parameter = new List<DbParameter>();
  294. string sql = @" select distinct REPLACE(PROJECTSTAGE, '生产确认表', '待装配') NAME from EXP_PROJECTPRODUCTIONSCHEDULE
  295. where OQC is null and not (PROJECTID>='2117101' and PROJECTID<='2117116') and REPLACE(PROJECTSTAGE, '', '') is not null";
  296. DataTable dt = OracleHelper.GetTable(sql, "Oracleconnstr", parameter.ToArray());
  297. return dt;
  298. //DataTable tblDatas = new DataTable("Datas");
  299. //tblDatas.Columns.Add("NAME", Type.GetType("System.String"));
  300. //for (int i = 0; i < 5; i++)
  301. //{
  302. // DataRow newRow;
  303. // newRow = tblDatas.NewRow();
  304. // newRow["NAME"] = i.ToString();
  305. // tblDatas.Rows.Add(newRow);
  306. //}
  307. //return tblDatas;
  308. }
  309. //设备类型
  310. public DataTable GetEQPType()
  311. {
  312. List<DbParameter> parameter = new List<DbParameter>();
  313. string sql = @" select distinct DEVICETYPE NAME from EXP_PROJECTPRODUCTIONSCHEDULE
  314. where OQC is null and not (PROJECTID>='2117101' and PROJECTID<='2117116') and DEVICETYPE is not null ";
  315. DataTable dt = OracleHelper.GetTable(sql, "Oracleconnstr", parameter.ToArray());
  316. return dt;
  317. }
  318. //状态
  319. public DataTable GetStatus()
  320. {
  321. List<DbParameter> parameter = new List<DbParameter>();
  322. string sql = @" select distinct case when PROJECTSTAGE ='FAT完成' then '完成' when PROJECTSTAGE ='FQC' then '完成'
  323. when BEGINDATE like '%-%-%' and TO_DATE(BEGINDATE,'YYYY-MM-DD')-sysdate < 7 and NVL(RTRIM(PROJECTSCHEDULE,'%'),0) <80 then '' else STATUS end NAME
  324. from EXP_PROJECTPRODUCTIONSCHEDULE
  325. where OQC is null and not (PROJECTID>='2117101' and PROJECTID<='2117116')
  326. and case when PROJECTSTAGE ='FAT完成' then '' when PROJECTSTAGE ='FQC' then ''
  327. 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 ";
  328. DataTable dt = OracleHelper.GetTable(sql, "Oracleconnstr", parameter.ToArray());
  329. return dt;
  330. }
  331. //生产进度-层析柱Qty
  332. public DataTable GetWIPQty1()
  333. {
  334. try
  335. {
  336. List<DbParameter> parameter = new List<DbParameter>();
  337. string SqlText = @"
  338. SELECT
  339. sum(case when REPLACE( PROJECTSTAGE, '', '' ) like '%%' or
  340. REPLACE( PROJECTSTAGE, '', '' ) not like '%%'
  341. then to_number ( QUANTITY ) else 0 end ) WIPQTY,
  342. sum(case when REPLACE( PROJECTSTAGE, '', '' ) not like '%%' and
  343. REPLACE( PROJECTSTAGE, '', '' ) like '%%'
  344. then to_number ( QUANTITY ) else 0 end ) COMQTY,
  345. sum(to_number ( QUANTITY ) ) ZQTY,
  346. REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '', '' ), '', '' ), '', '' ) PROJECTStr
  347. FROM
  348. EXP_PROJECTPRODUCTIONSCHEDULE
  349. WHERE
  350. 1 = 1
  351. and not (PROJECTID>='2117101' and PROJECTID<='2117116')
  352. and DEVICETYPE in ('EAC系列')
  353. and OQC is null
  354. GROUP BY REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '', '' ), '', '' ), '', '' )
  355. HAVING sum(to_number ( QUANTITY ) )>0 ";
  356. DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
  357. return dt;
  358. }
  359. catch (Exception ex)
  360. {
  361. WriteLogFile(ex.ToString(), "看板异常");
  362. }
  363. return null;
  364. }
  365. //生产进度-设备Qty
  366. public DataTable GetWIPQty5()
  367. {
  368. try
  369. {
  370. List<DbParameter> parameter = new List<DbParameter>();
  371. string SqlText = @" SELECT
  372. sum(case when REPLACE( PROJECTSTAGE, '', '' ) like '%%' or
  373. REPLACE( PROJECTSTAGE, '', '' ) not like '%%'
  374. then to_number ( QUANTITY ) else 0 end ) WIPQTY,
  375. sum(case when REPLACE( PROJECTSTAGE, '', '' ) not like '%%' and
  376. REPLACE( PROJECTSTAGE, '', '' ) like '%%'
  377. then to_number ( QUANTITY ) else 0 end ) COMQTY,
  378. sum(to_number ( QUANTITY ) ) ZQTY,
  379. REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '', '' ), '', '' ), '', '' ) PROJECTStr
  380. FROM
  381. EXP_PROJECTPRODUCTIONSCHEDULE
  382. WHERE
  383. 1 = 1
  384. AND NOT ( PROJECTID >= '2117101' AND PROJECTID <= '2117116' )
  385. AND DEVICETYPE NOT IN ( 'SAC系列','EAC系列' )
  386. AND OQC IS NULL
  387. GROUP BY REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '', '' ), '', '' ), '', '' )
  388. HAVING sum(to_number ( QUANTITY ) )>0 ";
  389. DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
  390. return dt;
  391. }
  392. catch (Exception ex)
  393. {
  394. WriteLogFile(ex.ToString(), "看板异常");
  395. }
  396. return null;
  397. }
  398. //生产进度 柱状图 (在制数 完成数 )
  399. public DataTable GetWIPQty2()
  400. {
  401. try
  402. {
  403. //生产确认表 有值中: 电装开始 有值 就是已开工,电装开始 无值 就是待开工
  404. List<DbParameter> parameter = new List<DbParameter>();
  405. string SqlText = @" SELECT
  406. SUM(CASE WHEN PRODUCTIONCONFIRM IS NOT NULL AND ELECTRICASSEMBLYSTART IS NOT NULL
  407. THEN to_number(QUANTITY) ELSE 0 END) YKGQty,
  408. SUM(CASE WHEN PRODUCTIONCONFIRM IS NOT NULL AND ELECTRICASSEMBLYSTART IS NULL
  409. THEN to_number(QUANTITY) ELSE 0 END) DKGQty
  410. from EXP_PROJECTPRODUCTIONSCHEDULE
  411. WHERE 1=1 AND PRODUCTIONCONFIRM IS NOT NULL
  412. and not (PROJECTID>='2117101' and PROJECTID<='2117116')
  413. and OQC is null ";
  414. DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
  415. return dt;
  416. }
  417. catch (Exception ex)
  418. {
  419. WriteLogFile(ex.ToString(), "看板异常");
  420. }
  421. return null;
  422. }
  423. //设备类型在制数
  424. public DataTable GetWIPQty3()
  425. {
  426. try
  427. {
  428. //生产确认表 有值 FQC 无值
  429. List<DbParameter> parameter = new List<DbParameter>();
  430. string SqlText = @" SELECT
  431. SUM( to_number(QUANTITY) ) Qty,nvl(DEVICETYPE,'') EQPTypeName
  432. from EXP_PROJECTPRODUCTIONSCHEDULE
  433. WHERE 1=1 AND PRODUCTIONCONFIRM IS NOT NULL
  434. and not (PROJECTID>='2117101' and PROJECTID<='2117116')
  435. AND OQC IS NULL
  436. GROUP BY DEVICETYPE ";
  437. DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
  438. return dt;
  439. }
  440. catch (Exception ex)
  441. {
  442. WriteLogFile(ex.ToString(), "看板异常");
  443. }
  444. return null;
  445. }
  446. //待开工项目(Qty)
  447. public DataTable GetWIPQty4()
  448. {
  449. try
  450. {
  451. //生产确认表 有值 电装开始 无值
  452. List<DbParameter> parameter = new List<DbParameter>();
  453. string SqlText = @"
  454. SELECT SUM ( to_number ( QUANTITY ) ) Qty,
  455. SUBSTR ( BEGINDATE, 0, 4+instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) ) MonthStr
  456. FROM
  457. EXP_PROJECTPRODUCTIONSCHEDULE
  458. WHERE
  459. 1 = 1
  460. AND( (ELECTRICASSEMBLYSTART IS NULL
  461. AND PRODUCTIONCONFIRM IS NOT NULL
  462. and OQC IS NULL
  463. ) or PROJECTSTAGE='' )
  464. AND BEGINDATE IS NOT NULL
  465. and not (PROJECTID>='2117101' and PROJECTID<='2117116')
  466. GROUP BY
  467. SUBSTR ( BEGINDATE, 0, 4+instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) ),
  468. SUBSTR ( BEGINDATE, 0, 4 ),
  469. to_number ( SUBSTR ( BEGINDATE, 6, instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) - 1 ) )
  470. ORDER BY
  471. SUBSTR ( BEGINDATE, 0, 4 ),
  472. to_number ( SUBSTR ( BEGINDATE, 6, instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) - 1 ) )
  473. ";
  474. DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
  475. return dt;
  476. }
  477. catch (Exception ex)
  478. {
  479. WriteLogFile(ex.ToString(), "看板异常");
  480. }
  481. return null;
  482. }
  483. //收货进度
  484. public DataTable GetRCVJingDu()
  485. {
  486. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  487. List<DbParameter> parameter = new List<DbParameter>();
  488. string SqlText = @"
  489. if exists(select* from tempdb..sysobjects where id= object_id('tempdb..#TEMP_ItemCK'))
  490. drop table #TEMP_ItemCK
  491. select sum(lotqty) Qty,cktype
  492. INTO #TEMP_ItemCK
  493. from(
  494. select lot.lotno, lot.lotqty, lot.IQCStatus, lot.step,
  495. case when lot.step= '' and lot.IQCStatus= '' then ''
  496. when isnull(lot.step,'')!='' and lot.IQCStatus='' then ''
  497. when lot.IQCStatus= '' then '' else '' end CKType
  498. from ICSINVReceipt cc with (nolock)
  499. left join ICSINVReceiptDetail dd with (nolock) on cc.ReceiptNO= dd.ReceiptNO and dd.workpoint= cc.workpoint
  500. left join ICSITEMLot lot with (nolock) on lot.mcode= dd.itemcode and lot.TransNO= dd.ReceiptNO
  501. and lot.TransLine= dd.ReceiptLine and dd.workpoint= lot.workpoint
  502. where not exists(select 1 from ICSWareHouseLotInfoLog log with (nolock) where log.lotno= lot.lotno)
  503. and lot.lotno is not null
  504. and cc.workpoint ='" + workpoint + @"'
  505. and cc.mtime >=DATEADD(week, -1,getdate())
  506. ) gg
  507. where cktype!=''
  508. group by cktype
  509. select * from (
  510. SELECT QTY,CKTYPE,cast(CONVERT(DECIMAL(18,2),QTY/(SELECT SUM(QTY) FROM #TEMP_ItemCK )*100) as NVARCHAR) +'%' Qtypercent
  511. from #TEMP_ItemCK
  512. union all
  513. SELECT 0,'', '0%' Qtypercent
  514. where not EXISTS(select 1 from #TEMP_ItemCK where cktype='')
  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. ) ff
  522. order by case CKTYPE when '' then 0 when '' then 1 when '' then 2 else 3 end
  523. ";
  524. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  525. return dt;
  526. }
  527. //到货数量(item)
  528. public DataTable GetRCVQty(string type)
  529. {
  530. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  531. List<DbParameter> parameter = new List<DbParameter>();
  532. string SqlText = "";
  533. switch (type)
  534. {
  535. case "日":
  536. SqlText = @"
  537. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  538. DROP TABLE #TEMP_Itemrr_tt
  539. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  540. DROP TABLE #TEMP_Itemrr_tt2
  541. SELECT CONVERT( VARCHAR ( 100 ), DATEADD( DAY, number *- 1, getdate( ) ), 23 ) AS
  542. INTO #TEMP_Itemrr_tt2
  543. FROM master.dbo.spt_values
  544. WHERE type = 'p'
  545. AND number <= 6 AND number >= 0
  546. SELECT SUM( planqty ) QTY,
  547. CONVERT ( VARCHAR ( 100 ), mtime, 23 )
  548. INTO #TEMP_Itemrr_tt
  549. FROM
  550. ICSINVReceiptDetail
  551. WHERE
  552. mtime >= CONVERT ( VARCHAR ( 10 ), DATEADD( DAY, - 6, getdate( ) ), 23 ) + ' 00:00:00'
  553. AND workpoint = '" + workpoint + @"'
  554. GROUP BY
  555. CONVERT ( VARCHAR ( 100 ), mtime, 23 )
  556. SELECT substring( aa.,6,5) ,
  557. isnull( bb.qty, 0 ) QTY
  558. FROM
  559. #TEMP_Itemrr_tt2 aa
  560. LEFT JOIN #TEMP_Itemrr_tt bb ON aa. = bb.
  561. ORDER BY 1
  562. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  563. DROP TABLE #TEMP_Itemrr_tt
  564. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  565. DROP TABLE #TEMP_Itemrr_tt2 ";
  566. break;
  567. case "周":
  568. SqlText = @"
  569. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  570. DROP TABLE #TEMP_Itemrr_tt
  571. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  572. DROP TABLE #TEMP_Itemrr_tt2
  573. SELECT DATEPART(wk,CONVERT( VARCHAR ( 10 ), DATEADD( week, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS ,
  574. CONVERT( VARCHAR ( 4 ), DATEADD( week, -1*NUMBER, getdate( ) ),23)
  575. INTO #TEMP_Itemrr_tt2
  576. FROM master.dbo.spt_values
  577. WHERE
  578. type = 'p'
  579. AND number <= 7 AND number >= 0
  580. SELECT SUM( planqty ) QTY,
  581. DATEPART(wk, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) INTO #TEMP_Itemrr_tt
  582. FROM
  583. ICSINVReceiptDetail with (nolock)
  584. WHERE
  585. mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( week, -7, getdate( ) ),23)+' 00:00:00'
  586. AND workpoint = '" + workpoint + @"'
  587. GROUP BY DATEPART(wk, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23)
  588. ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(wk, mtime)
  589. SELECT
  590. aa.,
  591. isnull( bb.qty, 0 ) QTY
  592. FROM
  593. #TEMP_Itemrr_tt2 aa
  594. LEFT JOIN #TEMP_Itemrr_tt bb ON aa. = bb. AND aa. = bb.
  595. ORDER BY aa., aa.
  596. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  597. DROP TABLE #TEMP_Itemrr_tt
  598. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  599. DROP TABLE #TEMP_Itemrr_tt2
  600. "; break;
  601. case "月":
  602. SqlText = @"
  603. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  604. DROP TABLE #TEMP_Itemrr_tt
  605. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  606. DROP TABLE #TEMP_Itemrr_tt2
  607. SELECT DATEPART(month,CONVERT( VARCHAR ( 10 ), DATEADD( month, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS ,
  608. CONVERT( VARCHAR ( 4 ), DATEADD( month, -1*NUMBER, getdate( ) ),23)
  609. INTO #TEMP_Itemrr_tt2
  610. FROM master.dbo.spt_values
  611. WHERE
  612. type = 'p'
  613. AND number <= 11 AND number >= 0
  614. SELECT SUM( planqty ) QTY,
  615. DATEPART(month, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) INTO #TEMP_Itemrr_tt
  616. FROM
  617. ICSINVReceiptDetail with (nolock)
  618. WHERE
  619. mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( month, -11, getdate( ) ),23)+' 00:00:00'
  620. AND workpoint = '" + workpoint + @"'
  621. GROUP BY DATEPART(month, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23)
  622. ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(month, mtime)
  623. SELECT
  624. aa.,
  625. isnull( bb.qty, 0 ) QTY
  626. FROM
  627. #TEMP_Itemrr_tt2 aa
  628. LEFT JOIN #TEMP_Itemrr_tt bb ON aa. = bb. AND aa. = bb.
  629. ORDER BY aa., aa.
  630. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  631. DROP TABLE #TEMP_Itemrr_tt
  632. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  633. DROP TABLE #TEMP_Itemrr_tt2
  634. "; break;
  635. case "年": SqlText = @"
  636. SELECT SUM( planqty ) QTY,
  637. CONVERT( VARCHAR ( 4 ),mtime,23)
  638. FROM
  639. ICSINVReceiptDetail with (nolock)
  640. WHERE workpoint = '" + workpoint + @"'
  641. GROUP BY CONVERT( VARCHAR ( 4 ),mtime,23)
  642. ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23)
  643. "; break;
  644. }
  645. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  646. return dt;
  647. }
  648. //入库数量(item)
  649. public DataTable GetWareInQty(string type)
  650. {
  651. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  652. List<DbParameter> parameter = new List<DbParameter>();
  653. string SqlText = "";
  654. switch (type)
  655. {
  656. case "日":
  657. SqlText = @"
  658. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  659. DROP TABLE #TEMP_Itemrr_tt
  660. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  661. DROP TABLE #TEMP_Itemrr_tt2
  662. SELECT CONVERT( VARCHAR ( 100 ), DATEADD( DAY, number *- 1, getdate( ) ), 23 ) AS
  663. INTO #TEMP_Itemrr_tt2
  664. FROM master.dbo.spt_values
  665. WHERE type = 'p'
  666. AND number <= 6 AND number >= 0
  667. SELECT SUM( TRANSQTY ) QTY,
  668. CONVERT ( VARCHAR ( 100 ), MTIME, 23 )
  669. INTO #TEMP_Itemrr_tt
  670. FROM
  671. ICSWareHouseLotInfoLOG log with (nolock)
  672. WHERE
  673. MTIME >= CONVERT ( VARCHAR ( 10 ), DATEADD( DAY, - 6, getdate( ) ), 23 ) + ' 00:00:00'
  674. AND workpoint = '" + workpoint + @"' and log.transtype in ('收','退')
  675. GROUP BY
  676. CONVERT ( VARCHAR ( 100 ), MTIME, 23 )
  677. SELECT substring( aa.,6,5) ,
  678. isnull( bb.qty, 0 ) QTY
  679. FROM
  680. #TEMP_Itemrr_tt2 aa
  681. LEFT JOIN #TEMP_Itemrr_tt bb ON aa. = bb.
  682. ORDER BY 1
  683. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  684. DROP TABLE #TEMP_Itemrr_tt
  685. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  686. DROP TABLE #TEMP_Itemrr_tt2 ";
  687. break;
  688. case "周":
  689. SqlText = @"
  690. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  691. DROP TABLE #TEMP_Itemrr_tt
  692. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  693. DROP TABLE #TEMP_Itemrr_tt2
  694. SELECT DATEPART(wk,CONVERT( VARCHAR ( 10 ), DATEADD( week, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS ,
  695. CONVERT( VARCHAR ( 4 ), DATEADD( week, -1*NUMBER, getdate( ) ),23)
  696. INTO #TEMP_Itemrr_tt2
  697. FROM master.dbo.spt_values
  698. WHERE
  699. type = 'p'
  700. AND number <= 7 AND number >= 0
  701. SELECT SUM( transqty ) QTY,
  702. DATEPART(wk, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) INTO #TEMP_Itemrr_tt
  703. FROM
  704. ICSWareHouseLotInfolog log with (nolock)
  705. WHERE
  706. mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( week, -7, getdate( ) ),23)+' 00:00:00'
  707. AND workpoint = '" + workpoint + @"' and log.transtype in ('收','退')
  708. GROUP BY DATEPART(wk, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23)
  709. ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(wk, mtime)
  710. SELECT
  711. aa.,
  712. isnull( bb.qty, 0 ) QTY
  713. FROM
  714. #TEMP_Itemrr_tt2 aa
  715. LEFT JOIN #TEMP_Itemrr_tt bb ON aa. = bb. AND aa. = bb.
  716. ORDER BY aa., aa.
  717. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  718. DROP TABLE #TEMP_Itemrr_tt
  719. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  720. DROP TABLE #TEMP_Itemrr_tt2
  721. "; break;
  722. case "月":
  723. SqlText = @"
  724. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  725. DROP TABLE #TEMP_Itemrr_tt
  726. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  727. DROP TABLE #TEMP_Itemrr_tt2
  728. SELECT DATEPART(month,CONVERT( VARCHAR ( 10 ), DATEADD( month, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS ,
  729. CONVERT( VARCHAR ( 4 ), DATEADD( month, -1*NUMBER, getdate( ) ),23)
  730. INTO #TEMP_Itemrr_tt2
  731. FROM master.dbo.spt_values
  732. WHERE
  733. type = 'p'
  734. AND number <= 11 AND number >= 0
  735. SELECT SUM( transqty ) QTY,
  736. DATEPART(month, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) INTO #TEMP_Itemrr_tt
  737. FROM
  738. ICSWareHouseLotInfolog log with (nolock)
  739. WHERE
  740. mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( month, -11, getdate( ) ),23)+' 00:00:00'
  741. AND workpoint = '" + workpoint + @"' and log.transtype in ('收','退')
  742. GROUP BY DATEPART(month, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23)
  743. ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(month, mtime)
  744. SELECT
  745. aa.,
  746. isnull( bb.qty, 0 ) QTY
  747. FROM
  748. #TEMP_Itemrr_tt2 aa
  749. LEFT JOIN #TEMP_Itemrr_tt bb ON aa. = bb. AND aa. = bb.
  750. ORDER BY aa., aa.
  751. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  752. DROP TABLE #TEMP_Itemrr_tt
  753. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  754. DROP TABLE #TEMP_Itemrr_tt2
  755. "; break;
  756. case "年": SqlText = @"
  757. SELECT SUM( transqty ) QTY,
  758. CONVERT( VARCHAR ( 4 ),mtime,23)
  759. FROM
  760. ICSWareHouseLotInfolog log with (nolock)
  761. WHERE workpoint = '" + workpoint + @"' and log.transtype in ('收','退')
  762. GROUP BY CONVERT( VARCHAR ( 4 ),mtime,23)
  763. ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23)
  764. "; break;
  765. }
  766. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  767. return dt;
  768. }
  769. //配料进度
  770. public DataTable GetPeiLiaoJingDu()
  771. {
  772. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  773. List<DbParameter> parameter = new List<DbParameter>();
  774. string SqlText = @"
  775. select UnDoQty, DoneQty,
  776. case when DoneQty + UnDoQty=0 then '0%' else cast(Convert(decimal(18, 2), DoneQty / (DoneQty + UnDoQty) * 100) as NVARCHAR) + '%' end DoneQtyPer,
  777. case when DoneQty + UnDoQty=0 then '0%' else cast(Convert(decimal(18, 2), UnDoQty / (DoneQty + UnDoQty) * 100) as NVARCHAR) + '%' end UnDoQtyPer
  778. from(
  779. select isnull(sum(case when isnull(actqty, 0) = 0 then planqty else 0 end),0) UnDoQty,
  780. isnull(sum(case when isnull(actqty, 0) = 0 then 0 else actqty end),0) DoneQty
  781. from ICSRdTransTer with (nolock)
  782. where RdType = ''
  783. and planqty > 0 and workpoint ='" + workpoint + @"'
  784. and mtime >=DATEADD(MONTH, -1,getdate())
  785. ) gg
  786. ";
  787. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  788. DataTable retdd = new DataTable();
  789. retdd.Columns.Add("cktype", Type.GetType("System.String"));
  790. retdd.Columns.Add("Qty", Type.GetType("System.Decimal"));
  791. retdd.Columns.Add("Qtypercent", Type.GetType("System.String"));
  792. if (dt != null && dt.Rows.Count > 0)
  793. {
  794. DataRow newRow = retdd.NewRow();
  795. newRow["cktype"] = "待配料";
  796. newRow["Qty"] = Convert.ToDecimal(dt.Rows[0]["UnDoQty"].ToString());
  797. newRow["Qtypercent"] = dt.Rows[0]["UnDoQtyPer"].ToString();
  798. retdd.Rows.Add(newRow);
  799. DataRow newRow2 = retdd.NewRow();
  800. newRow2["cktype"] = "已配料";
  801. newRow2["Qty"] = Convert.ToDecimal(dt.Rows[0]["DoneQty"].ToString());
  802. newRow2["Qtypercent"] = dt.Rows[0]["DoneQtyPer"].ToString();
  803. retdd.Rows.Add(newRow2);
  804. }
  805. else
  806. {
  807. DataRow newRow = retdd.NewRow();
  808. newRow["cktype"] = "待配料";
  809. newRow["Qty"] = 0;
  810. newRow["Qtypercent"] = "0%";
  811. retdd.Rows.Add(newRow);
  812. DataRow newRow2 = retdd.NewRow();
  813. newRow2["cktype"] = "已配料";
  814. newRow2["Qty"] = 0;
  815. newRow2["Qtypercent"] = "0%";
  816. retdd.Rows.Add(newRow2);
  817. }
  818. return retdd;
  819. }
  820. public DataTable GetSScode(string cookie) {
  821. string sql = @"
  822. select distinct a.sscode as name,a.sscode as value,'' as selected
  823. from ICSSS as a,ICSSEG as b,ICSSHIFTTYPE as c
  824. where a.SEGID = b.ID and a.SHIFTTYPEID = c.ID and
  825. b.WorkPoint = a.WorkPoint and c.WorkPoint = a.WorkPoint
  826. order by 1 ";
  827. DataTable table= Repository().GetDataTableBySql_Other(sql, "MESconnstr", null);
  828. foreach (DataRow row in table.Rows)
  829. {
  830. if (!string.IsNullOrEmpty(cookie))
  831. {
  832. JObject jobject = JObject.Parse(cookie);
  833. JArray array = JArray.Parse(jobject["value"].ToString());
  834. foreach (JObject j in array) {
  835. if (j["value"].ToString() == row["value"].ToString())
  836. row["selected"] = "true";
  837. }
  838. }
  839. }
  840. table.AcceptChanges();
  841. return table;
  842. }
  843. public static void WriteLogFile(string input, string txtName)
  844. {
  845. try
  846. {
  847. string logAdress = "C:\\看板日志" + "\\";
  848. if (!System.IO.Directory.Exists(logAdress))
  849. {
  850. System.IO.Directory.CreateDirectory(logAdress);//不存在就创建目录
  851. }
  852. string adress = logAdress + txtName;
  853. if (!System.IO.Directory.Exists(adress))
  854. {
  855. System.IO.Directory.CreateDirectory(adress);//不存在就创建目录
  856. }
  857. // string logAdress = ConfigurationManager.AppSettings["logAdress"].ToString();
  858. /**/
  859. ///指定日志文件的目录
  860. string fname = adress + "\\" + "log" + DateTime.Now.ToString("yy-MM-dd") + ".txt";
  861. /**/
  862. ///定义文件信息对象
  863. FileInfo finfo = new FileInfo(fname);
  864. if (!finfo.Exists)
  865. {
  866. FileStream fs;
  867. fs = File.Create(fname);
  868. fs.Close();
  869. finfo = new FileInfo(fname);
  870. }
  871. /**/
  872. ///判断文件是否存在以及是否大于2K
  873. if (finfo.Length > 1024 * 1024 * 10)
  874. {
  875. /**/
  876. ///文件超过10MB则重命名
  877. File.Move(logAdress + "\\Log\\" + txtName + ".txt", Directory.GetCurrentDirectory() + DateTime.Now.TimeOfDay + "\\Log\\" + txtName + ".txt");
  878. /**/
  879. ///删除该文件
  880. //finfo.Delete();
  881. }
  882. //finfo.AppendText();
  883. /**/
  884. ///创建只写文件流
  885. using (FileStream fs = finfo.OpenWrite())
  886. {
  887. /**/
  888. ///根据上面创建的文件流创建写数据流
  889. StreamWriter w = new StreamWriter(fs);
  890. /**/
  891. ///设置写数据流的起始位置为文件流的末尾
  892. ///设置写数据流的起始位置为文件流的末尾
  893. w.BaseStream.Seek(0, SeekOrigin.End);
  894. w.WriteLine("*****************Start*****************");
  895. w.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  896. /**/
  897. ///写入当前系统时间并换行
  898. /**/
  899. ///写入日志内容并换行
  900. w.WriteLine(input);
  901. /**/
  902. ///写入------------------------------------“并换行
  903. w.WriteLine("------------------END------------------------");
  904. /**/
  905. ///清空缓冲区内容,并把缓冲区内容写入基础流
  906. w.Flush();
  907. /**/
  908. ///关闭写数据流
  909. w.Close();
  910. }
  911. }
  912. catch (Exception ex)
  913. { }
  914. }
  915. public string ConvertDataTableToJson(DataTable dt)
  916. {
  917. StringBuilder sbs = new StringBuilder();
  918. if (dt.Rows.Count > 0)//如果有记录
  919. {
  920. sbs.Append("{'" + dt.TableName + "':[");
  921. string str = "";
  922. foreach (DataRow dr in dt.Rows)//开始拼
  923. {
  924. string result = "";
  925. foreach (DataColumn dc in dt.Columns)
  926. {
  927. result += string.Format(",'{0}':'{1}'",
  928. dc.ColumnName, dr[dc.ColumnName]);
  929. }
  930. result = result.Substring(1);
  931. result = ",{" + result + "}";
  932. str += result;
  933. }
  934. str = str.Substring(1);
  935. sbs.Append(str);
  936. sbs.Append("]}");
  937. }
  938. else//如果没有记录
  939. {
  940. sbs.Append("");
  941. }
  942. return sbs.ToString();
  943. }
  944. #region 执行大看板
  945. public DataTable GetZhiXing_MO(string ItemNumber)
  946. {
  947. string SqlText = "";
  948. SqlText = @"
  949. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCCDD'))
  950. drop table #TempCCDD
  951. SELECT DISTINCT C.molotcode as ,C.ITEMCODE ,dd.INVNAME ,C.MOCODE ,LL.OPSEQ,
  952. a.OPCODE ,ppp.opname ,us.UserName ,
  953. CASE WHEN A.ACTIONRESULT='COLLECT_BEGIN' then '--------' WHEN A.ACTIONRESULT='COLLECT_END' then '--------' end as ,
  954. SUM(DATEDIFF(MINUTE, B.BeginDateTime, B.EndDateTime)) as '',
  955. SUM(DATEDIFF(MINUTE, B.BeginDateTime, B.EndDateTime))-ISNULL(xx.[],0) AS ,
  956. xx.[],
  957. CONVERT(VARCHAR,B.BeginDateTime,120) ,
  958. CONVERT(VARCHAR,B.EndDateTime,120) ,
  959. CONVERT(VARCHAR,xx. ,120) as ,
  960. CONVERT(VARCHAR,xx.,120) as ,
  961. xx.[],
  962. xx.[]
  963. into #TempCCDD
  964. FROM ICSLOTONWIP A
  965. LEFT JOIN ICSLOTONWIPDetail B ON A.LOTNO=B.LOTNO AND A.OPCODE=B.OPCODE
  966. LEFT JOIN ICSOP ppp on a.OPCODE=ppp.OPCODE
  967. LEFT JOIN ICSLOTSIMULATION nn on nn.LOTNO=A.LOTNO
  968. LEFT JOIN Sys_User us on us.UserCode=B.UserCodeBegin
  969. LEFT JOIN ICSMO C ON A.MOCODE=C.MOCODE AND A.MOSEQ=C.MOSEQ
  970. LEFT JOIN ICSMO2ROUTE gg ON c.MOCODE=gg.MOCODE and gg.EATTRIBUTE1=C.MOSEQ
  971. LEFT JOIN ICSINVENTORY dd on C.ITEMCODE=dd.INVCODE
  972. LEFT JOIN ICSITEMROUTE2OPLot LL ON LL.LotNo=A.LOTNO AND A.OPCODE=LL.OPCODE
  973. LEFT JOIN ICSMO2User UU ON UU.LOTNO=A.LOTNO AND UU.OPCODE=A.OPCODE AND B.ECCode=UU.CREWCODE
  974. LEFT JOIN (SELECT DISTINCT C.molotcode as ,C.ITEMCODE ,dd.INVNAME ,gg.ROUTECODE 线 ,A.LOTNO ,
  975. c.MOCODE ,c.MOSEQ , A.OPCODE ,us.UserName as ,
  976. pp.BeginTime ,
  977. pp.EndTime ,
  978. SUM(DATEDIFF(MINUTE, PP.BeginTime, PP.EndTime)) as '' ,
  979. vv.EnumText ,
  980. pp.Memo
  981. from ICSLOTONWIP A INNER JOIN ICSLOTPAUSE pp on A.Lotno=pp.lotno and A.opcode=pp.opcode
  982. LEFT JOIN Sys_User us on us.UserCode=PP.Usercode
  983. LEFT JOIN ICSMO C ON A.MOCODE=C.MOCODE AND A.MOSEQ=C.MOSEQ
  984. LEFT JOIN ICSMO2ROUTE gg ON c.MOCODE=gg.MOCODE and gg.EATTRIBUTE1=C.MOSEQ
  985. LEFT JOIN ICSINVENTORY dd on C.ITEMCODE=dd.INVCODE
  986. LEFT JOIN ICSITEMROUTE2OPLot LL ON LL.LotNo=A.LOTNO AND A.OPCODE=LL.OPCODE
  987. LEFT JOIN ICSMO2User UU ON UU.LOTNO=A.LOTNO AND UU.OPCODE=A.OPCODE AND pp.EATTRIBUTE1=UU.CREWCODE
  988. LEFT JOIN Sys_EnumValues vv on vv.EnumValue=pp.RESCODE --AND vv.EnumKey='00022'
  989. where pp.MODELCODE='' and vv.EnumKey='00022' --AND a.LOTNO=''-- and A.ACTIONRESULT = 'COLLECT_END'
  990. GROUP BY C.molotcode,C.ITEMCODE ,dd.INVNAME ,gg.ROUTECODE, A.LOTNO,c.MOCODE ,c.MOSEQ , A.OPCODE ,us.UserName,pp.BeginTime,pp.EndTime,vv.EnumText ,
  991. pp.Memo)
  992. xx on xx.[]=c.MOCODE AND xx.[]=c.MOSEQ AND A.OPCODE=xx.[] AND xx.[]=us.UserName AND xx. >B.BeginDateTime AND xx. < B.EndDateTime
  993. where 1=1 AND b.Type='' and a.WorkPoint='6000' and B.BeginDateTime>=DATEADD(mm, -3, getdate())
  994. GROUP BY C.molotcode,C.ITEMCODE ,dd.INVNAME ,gg.ROUTECODE, A.LOTNO,c.MOCODE ,c.MOSEQ , A.OPCODE ,us.UserName,xx.[],nn.ISCOM,b.MTIME,B.BeginDateTime, B.EndDateTime,xx.[],xx.[],ppp.opname,xx.[],
  995. xx.[],A.ACTIONRESULT,LL.OPSEQ
  996. ORDER BY C.molotcode, C.ITEMCODE ,LL.OPSEQ,us.UserName asc
  997. SELECT *,case when is not null and is null then '' else '' end FROM #TempCCDD
  998. WHERE CONVERT(varchar(10), , 21) =(SELECT MAX(CONVERT(varchar(10), , 21)) FROM #TempCCDD)
  999. ORDER BY ,,
  1000. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCCDD'))
  1001. drop table #TempCCDD
  1002. ";
  1003. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  1004. return dt;
  1005. }
  1006. #endregion
  1007. #region 振翔生产进度
  1008. public DataTable GetProductProgress(string ItemNumber)
  1009. {
  1010. string where1 = "";
  1011. string SqlText = "";
  1012. SqlText = @" ";
  1013. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  1014. return dt;
  1015. }
  1016. public DataTable GetZhiXing_OQC( )
  1017. {
  1018. string SqlText = "";
  1019. SqlText = @"
  1020. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIPPCC'))
  1021. drop table #TempIPPCC
  1022. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMonthcc'))
  1023. drop table #TempMonthcc
  1024. declare @begin datetime,@end datetime
  1025. set @end=GETDATE()
  1026. declare @months int
  1027. set @months=6
  1028. select convert(varchar(7),DATEADD(month,number*-1+1,@end) ,120) AS
  1029. into #TempMonthcc
  1030. from master.dbo.spt_values
  1031. where type='p'
  1032. AND number<=@months
  1033. and number>=1
  1034. order by 1
  1035. select count(1) Qty,result,
  1036. into #TempIPPCC
  1037. from (
  1038. select distinct ccode, invcode ,result,convert(varchar(7),mtime,120)
  1039. from ICSOQCLotNo
  1040. where mtime>=DATEADD(month,DATEDIFF(month,0,DATEADD(mm, -5, GETDATE() )),0)
  1041. and result in('','')
  1042. ) dd
  1043. group by ,result
  1044. select isnull( case when isnull(gg.QtyAll,0) =0 then 0 else
  1045. Convert(decimal(18,2), (isnull(gg.QtyAll,0)-isnull(FF.QtyNG,0))*1.00/gg.QtyAll*100) end
  1046. ,0) PercentNum,
  1047. cc.
  1048. FROM #TempMonthcc cc
  1049. left join (select sum(qty) QtyAll, from #TempIPPCC hh group by ) GG on cc.=gg.
  1050. left join (select isnull(sum(qty),0) QtyNG, from #TempIPPCC hh where result='' group by ) ff on cc.=ff.
  1051. ORDER BY cc.
  1052. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIPPCC'))
  1053. drop table #TempIPPCC
  1054. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMonthcc'))
  1055. drop table #TempMonthcc
  1056. ";
  1057. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  1058. return dt;
  1059. }
  1060. public DataTable GetZhiXing_RCVUnInWare()
  1061. {
  1062. string SqlText = "";
  1063. SqlText = @"
  1064. select A.CCODE , B.LOTNO,a.cInvCode as ,C.INVSTD ,C.INVNAME ,b.transno ,
  1065. A.iQuantity AS ,A.STNO ,CONVERT(varchar(100), a.MTime, 23) MTime ,
  1066. 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,'')
  1067. from ICSPOArrive a with(nolock)
  1068. inner join icsitemlot b with(nolock) on a.LOTNO=b.LotNO
  1069. LEFT JOIN ICSINVENTORY C with(nolock) ON C.INVCODE = A.cInvCode
  1070. where EXISTS(select 1 from ICSOQCLotNo d with(nolock) where D.CCODE=a.cCode and d.InvCode=a.cInvCode and result='' )
  1071. and not EXISTS(select 1 from ICSWareHouseLotInfoLog ll with(nolock) where ll.lotno=a.lotno and ll.TransType='收')
  1072. order by A.CCODE,a.cInvCode,B.LOTNO ";
  1073. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  1074. return dt;
  1075. }
  1076. #endregion
  1077. }
  1078. }