宁虹看板
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.

1142 lines
52 KiB

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
  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
  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
  47. LEFT JOIN ICSINVReceiptDetail dd ON cc.ReceiptNO=dd.ReceiptNO AND dd.workpoint=cc.workpoint
  48. LEFT JOIN ICSINVENTORY inv 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
  68. LEFT JOIN ICSINVReceiptDetail dd ON cc.ReceiptNO=dd.ReceiptNO AND dd.workpoint=cc.workpoint
  69. LEFT JOIN ICSINVENTORY inv ON inv.invcode=dd.itemcode AND dd.workpoint=inv.workpoint
  70. left join icsitemlot lot 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 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
  105. left join icsmo mo 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
  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
  148. LEFT JOIN ICSINVReceiptDetail dd ON cc.ReceiptNO=dd.ReceiptNO AND dd.workpoint=cc.workpoint
  149. LEFT JOIN ICSINVENTORY inv ON inv.invcode=dd.itemcode AND dd.workpoint=inv.workpoint
  150. left join icsitemlot lot on lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine AND cc.workpoint=lot.workpoint
  151. left join ICSWareHouseLotInfolog kk 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 = @" SELECT A.SEGCODE AS 线体,a.MOCODE as 生产订单号,a.MOSEQ as 工单行,a.StartPlanDate as 工单日期,INVPARSETYPE as 产品代码,
  184. a.INVSTD as ,a.ITEMCODE as ,a.pgqty as ,isnull(B.ENDQTY,0) as ,
  185. case
  186. when convert(decimal,isnull(B.ENDQTY,0))=0 or convert(decimal,isnull(a.pgqty,0))=0 then '0.00'
  187. else convert(nvarchar(20), CONVERT(DECIMAL(18,2), convert(decimal,isnull(B.ENDQTY,0))/ convert(decimal,isnull(a.pgqty,0)))*100) end as ,'' AS
  188. FROM (select sum(convert(decimal,ISNULL(A.EATTRIBUTE1,0))) as pgqty,SEGCODE,A.MOCODE,A.MOSEQ,B.ITEMCODE,C.INVNAME,C.INVSTD,a.StartPlanDate,C.INVPARSETYPE,B.EATTRIBUTE3
  189. from icsmo2user A
  190. inner JOIN ICSMO B ON A.MOCODE=B.MOCODE AND A.MOSEQ=B.MOSEQ
  191. LEFT JOIN ICSINVENTORY C ON C.INVCODE=B.ITEMCODE
  192. GROUP BY SEGCODE,A.MOCODE,A.MOSEQ,B.ITEMCODE,C.INVNAME,C.INVSTD,a.StartPlanDate,INVPARSETYPE,EATTRIBUTE3)A
  193. LEFT JOIN ( SELECT COUNT(*) AS ENDQTY,A.SSCODE,A.MOCODE,A.MOSEQ,SSDESC FROM ( select B.SSCODE,A.MOCODE,A.MOSEQ,C.SSDESC from icssimulation a
  194. INNER join ICSONWIP B ON A.RCARD=B.RCARD AND A.RCARDSEQ=B.RCARDSEQ
  195. LEFT JOIN ICSSS C ON C.SSCODE=B.SSCODE
  196. where a.EATTRIBUTE1='GOOD' and iscom='1')A
  197. GROUP BY A.SSCODE,A.MOCODE,A.MOSEQ,A.SSDESC)B ON (A.SEGCODE=B.SSCODE or a.SEGCODE=b.SSDESC) AND A.MOCODE=B.MOCODE AND A.MOSEQ=B.MOSEQ
  198. where A.eattribute3='SMT' " + SQLWhere+ @"
  199. ORDER BY a.StartPlanDate desc
  200. ";
  201. DataTable dt = SqlHelper.GetDataTableBySql(SqlText);
  202. // WriteLogFile(SqlText, "看板异常");
  203. dt.Columns.Add("ID", Type.GetType("System.String"));
  204. int i = 1;
  205. foreach (DataRow dr in dt.Rows)
  206. {
  207. dr["ID"] = "ID" + i.ToString();
  208. i++;
  209. }
  210. return dt;
  211. }
  212. catch (Exception ex)
  213. {
  214. WriteLogFile(ex.ToString(), "看板异常");
  215. }
  216. return null;
  217. }
  218. //项目阶段
  219. public DataTable GetProjectJD()
  220. {
  221. List<DbParameter> parameter = new List<DbParameter>();
  222. string sql = @" select distinct REPLACE(PROJECTSTAGE, '生产确认表', '待装配') NAME from EXP_PROJECTPRODUCTIONSCHEDULE
  223. where OQC is null and not (PROJECTID>='2117101' and PROJECTID<='2117116') and REPLACE(PROJECTSTAGE, '', '') is not null";
  224. DataTable dt = OracleHelper.GetTable(sql, "Oracleconnstr", parameter.ToArray());
  225. return dt;
  226. //DataTable tblDatas = new DataTable("Datas");
  227. //tblDatas.Columns.Add("NAME", Type.GetType("System.String"));
  228. //for (int i = 0; i < 5; i++)
  229. //{
  230. // DataRow newRow;
  231. // newRow = tblDatas.NewRow();
  232. // newRow["NAME"] = i.ToString();
  233. // tblDatas.Rows.Add(newRow);
  234. //}
  235. //return tblDatas;
  236. }
  237. //设备类型
  238. public DataTable GetEQPType()
  239. {
  240. List<DbParameter> parameter = new List<DbParameter>();
  241. string sql = @" select distinct DEVICETYPE NAME from EXP_PROJECTPRODUCTIONSCHEDULE
  242. where OQC is null and not (PROJECTID>='2117101' and PROJECTID<='2117116') and DEVICETYPE is not null ";
  243. DataTable dt = OracleHelper.GetTable(sql, "Oracleconnstr", parameter.ToArray());
  244. return dt;
  245. }
  246. //状态
  247. public DataTable GetStatus()
  248. {
  249. List<DbParameter> parameter = new List<DbParameter>();
  250. string sql = @" select distinct case when PROJECTSTAGE ='FAT完成' then '完成' when PROJECTSTAGE ='FQC' then '完成'
  251. when BEGINDATE like '%-%-%' and TO_DATE(BEGINDATE,'YYYY-MM-DD')-sysdate < 7 and NVL(RTRIM(PROJECTSCHEDULE,'%'),0) <80 then '' else STATUS end NAME
  252. from EXP_PROJECTPRODUCTIONSCHEDULE
  253. where OQC is null and not (PROJECTID>='2117101' and PROJECTID<='2117116')
  254. and case when PROJECTSTAGE ='FAT完成' then '' when PROJECTSTAGE ='FQC' then ''
  255. 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 ";
  256. DataTable dt = OracleHelper.GetTable(sql, "Oracleconnstr", parameter.ToArray());
  257. return dt;
  258. }
  259. //生产进度-层析柱Qty
  260. public DataTable GetWIPQty1()
  261. {
  262. try
  263. {
  264. List<DbParameter> parameter = new List<DbParameter>();
  265. string SqlText = @"
  266. SELECT
  267. sum(case when REPLACE( PROJECTSTAGE, '', '' ) like '%%' or
  268. REPLACE( PROJECTSTAGE, '', '' ) not like '%%'
  269. then to_number ( QUANTITY ) else 0 end ) WIPQTY,
  270. sum(case when REPLACE( PROJECTSTAGE, '', '' ) not like '%%' and
  271. REPLACE( PROJECTSTAGE, '', '' ) like '%%'
  272. then to_number ( QUANTITY ) else 0 end ) COMQTY,
  273. sum(to_number ( QUANTITY ) ) ZQTY,
  274. REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '', '' ), '', '' ), '', '' ) PROJECTStr
  275. FROM
  276. EXP_PROJECTPRODUCTIONSCHEDULE
  277. WHERE
  278. 1 = 1
  279. and not (PROJECTID>='2117101' and PROJECTID<='2117116')
  280. and DEVICETYPE in ('EAC系列')
  281. and OQC is null
  282. GROUP BY REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '', '' ), '', '' ), '', '' )
  283. HAVING sum(to_number ( QUANTITY ) )>0 ";
  284. DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
  285. return dt;
  286. }
  287. catch (Exception ex)
  288. {
  289. WriteLogFile(ex.ToString(), "看板异常");
  290. }
  291. return null;
  292. }
  293. //生产进度-设备Qty
  294. public DataTable GetWIPQty5()
  295. {
  296. try
  297. {
  298. List<DbParameter> parameter = new List<DbParameter>();
  299. string SqlText = @" SELECT
  300. sum(case when REPLACE( PROJECTSTAGE, '', '' ) like '%%' or
  301. REPLACE( PROJECTSTAGE, '', '' ) not like '%%'
  302. then to_number ( QUANTITY ) else 0 end ) WIPQTY,
  303. sum(case when REPLACE( PROJECTSTAGE, '', '' ) not like '%%' and
  304. REPLACE( PROJECTSTAGE, '', '' ) like '%%'
  305. then to_number ( QUANTITY ) else 0 end ) COMQTY,
  306. sum(to_number ( QUANTITY ) ) ZQTY,
  307. REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '', '' ), '', '' ), '', '' ) PROJECTStr
  308. FROM
  309. EXP_PROJECTPRODUCTIONSCHEDULE
  310. WHERE
  311. 1 = 1
  312. AND NOT ( PROJECTID >= '2117101' AND PROJECTID <= '2117116' )
  313. AND DEVICETYPE NOT IN ( 'SAC系列','EAC系列' )
  314. AND OQC IS NULL
  315. GROUP BY REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '', '' ), '', '' ), '', '' )
  316. HAVING sum(to_number ( QUANTITY ) )>0 ";
  317. DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
  318. return dt;
  319. }
  320. catch (Exception ex)
  321. {
  322. WriteLogFile(ex.ToString(), "看板异常");
  323. }
  324. return null;
  325. }
  326. //生产进度 柱状图 (在制数 完成数 )
  327. public DataTable GetWIPQty2()
  328. {
  329. try
  330. {
  331. //生产确认表 有值中: 电装开始 有值 就是已开工,电装开始 无值 就是待开工
  332. List<DbParameter> parameter = new List<DbParameter>();
  333. string SqlText = @" SELECT
  334. SUM(CASE WHEN PRODUCTIONCONFIRM IS NOT NULL AND ELECTRICASSEMBLYSTART IS NOT NULL
  335. THEN to_number(QUANTITY) ELSE 0 END) YKGQty,
  336. SUM(CASE WHEN PRODUCTIONCONFIRM IS NOT NULL AND ELECTRICASSEMBLYSTART IS NULL
  337. THEN to_number(QUANTITY) ELSE 0 END) DKGQty
  338. from EXP_PROJECTPRODUCTIONSCHEDULE
  339. WHERE 1=1 AND PRODUCTIONCONFIRM IS NOT NULL
  340. and not (PROJECTID>='2117101' and PROJECTID<='2117116')
  341. and OQC is null ";
  342. DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
  343. return dt;
  344. }
  345. catch (Exception ex)
  346. {
  347. WriteLogFile(ex.ToString(), "看板异常");
  348. }
  349. return null;
  350. }
  351. //设备类型在制数
  352. public DataTable GetWIPQty3()
  353. {
  354. try
  355. {
  356. //生产确认表 有值 FQC 无值
  357. List<DbParameter> parameter = new List<DbParameter>();
  358. string SqlText = @" SELECT
  359. SUM( to_number(QUANTITY) ) Qty,nvl(DEVICETYPE,'') EQPTypeName
  360. from EXP_PROJECTPRODUCTIONSCHEDULE
  361. WHERE 1=1 AND PRODUCTIONCONFIRM IS NOT NULL
  362. and not (PROJECTID>='2117101' and PROJECTID<='2117116')
  363. AND OQC IS NULL
  364. GROUP BY DEVICETYPE ";
  365. DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
  366. return dt;
  367. }
  368. catch (Exception ex)
  369. {
  370. WriteLogFile(ex.ToString(), "看板异常");
  371. }
  372. return null;
  373. }
  374. //待开工项目(Qty)
  375. public DataTable GetWIPQty4()
  376. {
  377. try
  378. {
  379. //生产确认表 有值 电装开始 无值
  380. List<DbParameter> parameter = new List<DbParameter>();
  381. string SqlText = @"
  382. SELECT SUM ( to_number ( QUANTITY ) ) Qty,
  383. SUBSTR ( BEGINDATE, 0, 4+instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) ) MonthStr
  384. FROM
  385. EXP_PROJECTPRODUCTIONSCHEDULE
  386. WHERE
  387. 1 = 1
  388. AND( (ELECTRICASSEMBLYSTART IS NULL
  389. AND PRODUCTIONCONFIRM IS NOT NULL
  390. and OQC IS NULL
  391. ) or PROJECTSTAGE='' )
  392. AND BEGINDATE IS NOT NULL
  393. and not (PROJECTID>='2117101' and PROJECTID<='2117116')
  394. GROUP BY
  395. SUBSTR ( BEGINDATE, 0, 4+instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) ),
  396. SUBSTR ( BEGINDATE, 0, 4 ),
  397. to_number ( SUBSTR ( BEGINDATE, 6, instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) - 1 ) )
  398. ORDER BY
  399. SUBSTR ( BEGINDATE, 0, 4 ),
  400. to_number ( SUBSTR ( BEGINDATE, 6, instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) - 1 ) )
  401. ";
  402. DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
  403. return dt;
  404. }
  405. catch (Exception ex)
  406. {
  407. WriteLogFile(ex.ToString(), "看板异常");
  408. }
  409. return null;
  410. }
  411. //收货进度
  412. public DataTable GetRCVJingDu()
  413. {
  414. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  415. List<DbParameter> parameter = new List<DbParameter>();
  416. string SqlText = @"
  417. if exists(select* from tempdb..sysobjects where id= object_id('tempdb..#TEMP_ItemCK'))
  418. drop table #TEMP_ItemCK
  419. select sum(lotqty) Qty,cktype
  420. INTO #TEMP_ItemCK
  421. from(
  422. select lot.lotno, lot.lotqty, lot.IQCStatus, lot.step,
  423. case when lot.step= '' and lot.IQCStatus= '' then ''
  424. when isnull(lot.step,'')!='' and lot.IQCStatus='' then ''
  425. when lot.IQCStatus= '' then '' else '' end CKType
  426. from ICSINVReceipt cc
  427. left join ICSINVReceiptDetail dd on cc.ReceiptNO= dd.ReceiptNO and dd.workpoint= cc.workpoint
  428. left join ICSITEMLot lot on lot.mcode= dd.itemcode and lot.TransNO= dd.ReceiptNO
  429. and lot.TransLine= dd.ReceiptLine and dd.workpoint= lot.workpoint
  430. where not exists(select 1 from ICSWareHouseLotInfoLog log where log.lotno= lot.lotno)
  431. and lot.lotno is not null
  432. and cc.workpoint ='" + workpoint + @"'
  433. and cc.mtime >=DATEADD(week, -1,getdate())
  434. ) gg
  435. where cktype!=''
  436. group by cktype
  437. select * from (
  438. SELECT QTY,CKTYPE,cast(CONVERT(DECIMAL(18,2),QTY/(SELECT SUM(QTY) FROM #TEMP_ItemCK )*100) as NVARCHAR) +'%' Qtypercent
  439. from #TEMP_ItemCK
  440. union all
  441. SELECT 0,'', '0%' Qtypercent
  442. where not EXISTS(select 1 from #TEMP_ItemCK where cktype='')
  443. union all
  444. SELECT 0,'', '0%' Qtypercent
  445. where not EXISTS(select 1 from #TEMP_ItemCK where cktype='')
  446. union all
  447. SELECT 0,'', '0%' Qtypercent
  448. where not EXISTS(select 1 from #TEMP_ItemCK where cktype='')
  449. ) ff
  450. order by case CKTYPE when '' then 0 when '' then 1 when '' then 2 else 3 end
  451. ";
  452. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  453. return dt;
  454. }
  455. //到货数量(item)
  456. public DataTable GetRCVQty(string type)
  457. {
  458. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  459. List<DbParameter> parameter = new List<DbParameter>();
  460. string SqlText = "";
  461. switch (type)
  462. {
  463. case "日":
  464. SqlText = @"
  465. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  466. DROP TABLE #TEMP_Itemrr_tt
  467. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  468. DROP TABLE #TEMP_Itemrr_tt2
  469. SELECT CONVERT( VARCHAR ( 100 ), DATEADD( DAY, number *- 1, getdate( ) ), 23 ) AS
  470. INTO #TEMP_Itemrr_tt2
  471. FROM master.dbo.spt_values
  472. WHERE type = 'p'
  473. AND number <= 6 AND number >= 0
  474. SELECT SUM( planqty ) QTY,
  475. CONVERT ( VARCHAR ( 100 ), mtime, 23 )
  476. INTO #TEMP_Itemrr_tt
  477. FROM
  478. ICSINVReceiptDetail
  479. WHERE
  480. mtime >= CONVERT ( VARCHAR ( 10 ), DATEADD( DAY, - 6, getdate( ) ), 23 ) + ' 00:00:00'
  481. AND workpoint = '" + workpoint + @"'
  482. GROUP BY
  483. CONVERT ( VARCHAR ( 100 ), mtime, 23 )
  484. SELECT substring( aa.,6,5) ,
  485. isnull( bb.qty, 0 ) QTY
  486. FROM
  487. #TEMP_Itemrr_tt2 aa
  488. LEFT JOIN #TEMP_Itemrr_tt bb ON aa. = bb.
  489. ORDER BY 1
  490. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  491. DROP TABLE #TEMP_Itemrr_tt
  492. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  493. DROP TABLE #TEMP_Itemrr_tt2 ";
  494. break;
  495. case "周":
  496. SqlText = @"
  497. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  498. DROP TABLE #TEMP_Itemrr_tt
  499. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  500. DROP TABLE #TEMP_Itemrr_tt2
  501. SELECT DATEPART(wk,CONVERT( VARCHAR ( 10 ), DATEADD( week, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS ,
  502. CONVERT( VARCHAR ( 4 ), DATEADD( week, -1*NUMBER, getdate( ) ),23)
  503. INTO #TEMP_Itemrr_tt2
  504. FROM master.dbo.spt_values
  505. WHERE
  506. type = 'p'
  507. AND number <= 7 AND number >= 0
  508. SELECT SUM( planqty ) QTY,
  509. DATEPART(wk, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) INTO #TEMP_Itemrr_tt
  510. FROM
  511. ICSINVReceiptDetail
  512. WHERE
  513. mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( week, -7, getdate( ) ),23)+' 00:00:00'
  514. AND workpoint = '" + workpoint + @"'
  515. GROUP BY DATEPART(wk, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23)
  516. ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(wk, mtime)
  517. SELECT
  518. aa.,
  519. isnull( bb.qty, 0 ) QTY
  520. FROM
  521. #TEMP_Itemrr_tt2 aa
  522. LEFT JOIN #TEMP_Itemrr_tt bb ON aa. = bb. AND aa. = bb.
  523. ORDER BY aa., aa.
  524. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  525. DROP TABLE #TEMP_Itemrr_tt
  526. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  527. DROP TABLE #TEMP_Itemrr_tt2
  528. "; break;
  529. case "月":
  530. SqlText = @"
  531. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  532. DROP TABLE #TEMP_Itemrr_tt
  533. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  534. DROP TABLE #TEMP_Itemrr_tt2
  535. SELECT DATEPART(month,CONVERT( VARCHAR ( 10 ), DATEADD( month, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS ,
  536. CONVERT( VARCHAR ( 4 ), DATEADD( month, -1*NUMBER, getdate( ) ),23)
  537. INTO #TEMP_Itemrr_tt2
  538. FROM master.dbo.spt_values
  539. WHERE
  540. type = 'p'
  541. AND number <= 11 AND number >= 0
  542. SELECT SUM( planqty ) QTY,
  543. DATEPART(month, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) INTO #TEMP_Itemrr_tt
  544. FROM
  545. ICSINVReceiptDetail
  546. WHERE
  547. mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( month, -11, getdate( ) ),23)+' 00:00:00'
  548. AND workpoint = '" + workpoint + @"'
  549. GROUP BY DATEPART(month, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23)
  550. ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(month, mtime)
  551. SELECT
  552. aa.,
  553. isnull( bb.qty, 0 ) QTY
  554. FROM
  555. #TEMP_Itemrr_tt2 aa
  556. LEFT JOIN #TEMP_Itemrr_tt bb ON aa. = bb. AND aa. = bb.
  557. ORDER BY aa., aa.
  558. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  559. DROP TABLE #TEMP_Itemrr_tt
  560. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  561. DROP TABLE #TEMP_Itemrr_tt2
  562. "; break;
  563. case "年": SqlText = @"
  564. SELECT SUM( planqty ) QTY,
  565. CONVERT( VARCHAR ( 4 ),mtime,23)
  566. FROM
  567. ICSINVReceiptDetail
  568. WHERE workpoint = '" + workpoint + @"'
  569. GROUP BY CONVERT( VARCHAR ( 4 ),mtime,23)
  570. ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23)
  571. "; break;
  572. }
  573. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  574. return dt;
  575. }
  576. //入库数量(item)
  577. public DataTable GetWareInQty(string type)
  578. {
  579. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  580. List<DbParameter> parameter = new List<DbParameter>();
  581. string SqlText = "";
  582. switch (type)
  583. {
  584. case "日":
  585. SqlText = @"
  586. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  587. DROP TABLE #TEMP_Itemrr_tt
  588. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  589. DROP TABLE #TEMP_Itemrr_tt2
  590. SELECT CONVERT( VARCHAR ( 100 ), DATEADD( DAY, number *- 1, getdate( ) ), 23 ) AS
  591. INTO #TEMP_Itemrr_tt2
  592. FROM master.dbo.spt_values
  593. WHERE type = 'p'
  594. AND number <= 6 AND number >= 0
  595. SELECT SUM( TRANSQTY ) QTY,
  596. CONVERT ( VARCHAR ( 100 ), MTIME, 23 )
  597. INTO #TEMP_Itemrr_tt
  598. FROM
  599. ICSWareHouseLotInfoLOG log
  600. WHERE
  601. MTIME >= CONVERT ( VARCHAR ( 10 ), DATEADD( DAY, - 6, getdate( ) ), 23 ) + ' 00:00:00'
  602. AND workpoint = '" + workpoint + @"' and log.transtype in ('收','退')
  603. GROUP BY
  604. CONVERT ( VARCHAR ( 100 ), MTIME, 23 )
  605. SELECT substring( aa.,6,5) ,
  606. isnull( bb.qty, 0 ) QTY
  607. FROM
  608. #TEMP_Itemrr_tt2 aa
  609. LEFT JOIN #TEMP_Itemrr_tt bb ON aa. = bb.
  610. ORDER BY 1
  611. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  612. DROP TABLE #TEMP_Itemrr_tt
  613. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  614. DROP TABLE #TEMP_Itemrr_tt2 ";
  615. break;
  616. case "周":
  617. SqlText = @"
  618. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  619. DROP TABLE #TEMP_Itemrr_tt
  620. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  621. DROP TABLE #TEMP_Itemrr_tt2
  622. SELECT DATEPART(wk,CONVERT( VARCHAR ( 10 ), DATEADD( week, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS ,
  623. CONVERT( VARCHAR ( 4 ), DATEADD( week, -1*NUMBER, getdate( ) ),23)
  624. INTO #TEMP_Itemrr_tt2
  625. FROM master.dbo.spt_values
  626. WHERE
  627. type = 'p'
  628. AND number <= 7 AND number >= 0
  629. SELECT SUM( transqty ) QTY,
  630. DATEPART(wk, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) INTO #TEMP_Itemrr_tt
  631. FROM
  632. ICSWareHouseLotInfolog log
  633. WHERE
  634. mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( week, -7, getdate( ) ),23)+' 00:00:00'
  635. AND workpoint = '" + workpoint + @"' and log.transtype in ('收','退')
  636. GROUP BY DATEPART(wk, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23)
  637. ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(wk, mtime)
  638. SELECT
  639. aa.,
  640. isnull( bb.qty, 0 ) QTY
  641. FROM
  642. #TEMP_Itemrr_tt2 aa
  643. LEFT JOIN #TEMP_Itemrr_tt bb ON aa. = bb. AND aa. = bb.
  644. ORDER BY aa., aa.
  645. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  646. DROP TABLE #TEMP_Itemrr_tt
  647. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  648. DROP TABLE #TEMP_Itemrr_tt2
  649. "; break;
  650. case "月":
  651. SqlText = @"
  652. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  653. DROP TABLE #TEMP_Itemrr_tt
  654. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  655. DROP TABLE #TEMP_Itemrr_tt2
  656. SELECT DATEPART(month,CONVERT( VARCHAR ( 10 ), DATEADD( month, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS ,
  657. CONVERT( VARCHAR ( 4 ), DATEADD( month, -1*NUMBER, getdate( ) ),23)
  658. INTO #TEMP_Itemrr_tt2
  659. FROM master.dbo.spt_values
  660. WHERE
  661. type = 'p'
  662. AND number <= 11 AND number >= 0
  663. SELECT SUM( transqty ) QTY,
  664. DATEPART(month, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) INTO #TEMP_Itemrr_tt
  665. FROM
  666. ICSWareHouseLotInfolog log
  667. WHERE
  668. mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( month, -11, getdate( ) ),23)+' 00:00:00'
  669. AND workpoint = '" + workpoint + @"' and log.transtype in ('收','退')
  670. GROUP BY DATEPART(month, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23)
  671. ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(month, mtime)
  672. SELECT
  673. aa.,
  674. isnull( bb.qty, 0 ) QTY
  675. FROM
  676. #TEMP_Itemrr_tt2 aa
  677. LEFT JOIN #TEMP_Itemrr_tt bb ON aa. = bb. AND aa. = bb.
  678. ORDER BY aa., aa.
  679. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) )
  680. DROP TABLE #TEMP_Itemrr_tt
  681. IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) )
  682. DROP TABLE #TEMP_Itemrr_tt2
  683. "; break;
  684. case "年": SqlText = @"
  685. SELECT SUM( transqty ) QTY,
  686. CONVERT( VARCHAR ( 4 ),mtime,23)
  687. FROM
  688. ICSWareHouseLotInfolog log
  689. WHERE workpoint = '" + workpoint + @"' and log.transtype in ('收','退')
  690. GROUP BY CONVERT( VARCHAR ( 4 ),mtime,23)
  691. ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23)
  692. "; break;
  693. }
  694. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  695. return dt;
  696. }
  697. //配料进度
  698. public DataTable GetPeiLiaoJingDu()
  699. {
  700. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  701. List<DbParameter> parameter = new List<DbParameter>();
  702. string SqlText = @"
  703. select UnDoQty, DoneQty,
  704. case when DoneQty + UnDoQty=0 then '0%' else cast(Convert(decimal(18, 2), DoneQty / (DoneQty + UnDoQty) * 100) as NVARCHAR) + '%' end DoneQtyPer,
  705. case when DoneQty + UnDoQty=0 then '0%' else cast(Convert(decimal(18, 2), UnDoQty / (DoneQty + UnDoQty) * 100) as NVARCHAR) + '%' end UnDoQtyPer
  706. from(
  707. select isnull(sum(case when isnull(actqty, 0) = 0 then planqty else 0 end),0) UnDoQty,
  708. isnull(sum(case when isnull(actqty, 0) = 0 then 0 else actqty end),0) DoneQty
  709. from ICSRdTransTer
  710. where RdType = ''
  711. and planqty > 0 and workpoint ='" + workpoint + @"'
  712. and mtime >=DATEADD(MONTH, -1,getdate())
  713. ) gg
  714. ";
  715. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  716. DataTable retdd = new DataTable();
  717. retdd.Columns.Add("cktype", Type.GetType("System.String"));
  718. retdd.Columns.Add("Qty", Type.GetType("System.Decimal"));
  719. retdd.Columns.Add("Qtypercent", Type.GetType("System.String"));
  720. if (dt != null && dt.Rows.Count > 0)
  721. {
  722. DataRow newRow = retdd.NewRow();
  723. newRow["cktype"] = "待配料";
  724. newRow["Qty"] = Convert.ToDecimal(dt.Rows[0]["UnDoQty"].ToString());
  725. newRow["Qtypercent"] = dt.Rows[0]["UnDoQtyPer"].ToString();
  726. retdd.Rows.Add(newRow);
  727. DataRow newRow2 = retdd.NewRow();
  728. newRow2["cktype"] = "已配料";
  729. newRow2["Qty"] = Convert.ToDecimal(dt.Rows[0]["DoneQty"].ToString());
  730. newRow2["Qtypercent"] = dt.Rows[0]["DoneQtyPer"].ToString();
  731. retdd.Rows.Add(newRow2);
  732. }
  733. else
  734. {
  735. DataRow newRow = retdd.NewRow();
  736. newRow["cktype"] = "待配料";
  737. newRow["Qty"] = 0;
  738. newRow["Qtypercent"] = "0%";
  739. retdd.Rows.Add(newRow);
  740. DataRow newRow2 = retdd.NewRow();
  741. newRow2["cktype"] = "已配料";
  742. newRow2["Qty"] = 0;
  743. newRow2["Qtypercent"] = "0%";
  744. retdd.Rows.Add(newRow2);
  745. }
  746. return retdd;
  747. }
  748. public DataTable GetSScode(string cookie) {
  749. string sql = "select distinct sscode as name,ssdesc as value,'' as selected from ICSSS";
  750. DataTable table= Repository().GetDataTableBySql_Other(sql, "MESconnstr", null);
  751. foreach (DataRow row in table.Rows)
  752. {
  753. if (!string.IsNullOrEmpty(cookie))
  754. {
  755. JObject jobject = JObject.Parse(cookie);
  756. JArray array = JArray.Parse(jobject["value"].ToString());
  757. foreach (JObject j in array) {
  758. if (j["value"].ToString() == row["value"].ToString())
  759. row["selected"] = "true";
  760. }
  761. }
  762. }
  763. table.AcceptChanges();
  764. return table;
  765. }
  766. public static void WriteLogFile(string input, string txtName)
  767. {
  768. try
  769. {
  770. string logAdress = "C:\\看板日志" + "\\";
  771. if (!System.IO.Directory.Exists(logAdress))
  772. {
  773. System.IO.Directory.CreateDirectory(logAdress);//不存在就创建目录
  774. }
  775. string adress = logAdress + txtName;
  776. if (!System.IO.Directory.Exists(adress))
  777. {
  778. System.IO.Directory.CreateDirectory(adress);//不存在就创建目录
  779. }
  780. // string logAdress = ConfigurationManager.AppSettings["logAdress"].ToString();
  781. /**/
  782. ///指定日志文件的目录
  783. string fname = adress + "\\" + "log" + DateTime.Now.ToString("yy-MM-dd") + ".txt";
  784. /**/
  785. ///定义文件信息对象
  786. FileInfo finfo = new FileInfo(fname);
  787. if (!finfo.Exists)
  788. {
  789. FileStream fs;
  790. fs = File.Create(fname);
  791. fs.Close();
  792. finfo = new FileInfo(fname);
  793. }
  794. /**/
  795. ///判断文件是否存在以及是否大于2K
  796. if (finfo.Length > 1024 * 1024 * 10)
  797. {
  798. /**/
  799. ///文件超过10MB则重命名
  800. File.Move(logAdress + "\\Log\\" + txtName + ".txt", Directory.GetCurrentDirectory() + DateTime.Now.TimeOfDay + "\\Log\\" + txtName + ".txt");
  801. /**/
  802. ///删除该文件
  803. //finfo.Delete();
  804. }
  805. //finfo.AppendText();
  806. /**/
  807. ///创建只写文件流
  808. using (FileStream fs = finfo.OpenWrite())
  809. {
  810. /**/
  811. ///根据上面创建的文件流创建写数据流
  812. StreamWriter w = new StreamWriter(fs);
  813. /**/
  814. ///设置写数据流的起始位置为文件流的末尾
  815. ///设置写数据流的起始位置为文件流的末尾
  816. w.BaseStream.Seek(0, SeekOrigin.End);
  817. w.WriteLine("*****************Start*****************");
  818. w.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  819. /**/
  820. ///写入当前系统时间并换行
  821. /**/
  822. ///写入日志内容并换行
  823. w.WriteLine(input);
  824. /**/
  825. ///写入------------------------------------“并换行
  826. w.WriteLine("------------------END------------------------");
  827. /**/
  828. ///清空缓冲区内容,并把缓冲区内容写入基础流
  829. w.Flush();
  830. /**/
  831. ///关闭写数据流
  832. w.Close();
  833. }
  834. }
  835. catch (Exception ex)
  836. { }
  837. }
  838. public string ConvertDataTableToJson(DataTable dt)
  839. {
  840. StringBuilder sbs = new StringBuilder();
  841. if (dt.Rows.Count > 0)//如果有记录
  842. {
  843. sbs.Append("{'" + dt.TableName + "':[");
  844. string str = "";
  845. foreach (DataRow dr in dt.Rows)//开始拼
  846. {
  847. string result = "";
  848. foreach (DataColumn dc in dt.Columns)
  849. {
  850. result += string.Format(",'{0}':'{1}'",
  851. dc.ColumnName, dr[dc.ColumnName]);
  852. }
  853. result = result.Substring(1);
  854. result = ",{" + result + "}";
  855. str += result;
  856. }
  857. str = str.Substring(1);
  858. sbs.Append(str);
  859. sbs.Append("]}");
  860. }
  861. else//如果没有记录
  862. {
  863. sbs.Append("");
  864. }
  865. return sbs.ToString();
  866. }
  867. #region 执行大看板
  868. public DataTable GetZhiXing_MO(string ItemNumber)
  869. {
  870. string SqlText = "";
  871. SqlText = @"
  872. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOComQty'))
  873. drop table #TempMOComQty
  874. select dd.mocode,sum(dd.rcardqty) Qty
  875. into #TempMOComQty
  876. from ICSMO2RCARD dd
  877. where exists(select 1 from ICSAIODATA ii where ii.snno=dd.rcard )
  878. group by dd.mocode
  879. select mo.mocode ,inv.invname , Convert(decimal(18,1),mo.moplanqty) ,Convert(decimal(18,1),isnull(QQ.qty,0)) ,
  880. CONVERT(varchar(10), mo.MOPLANENDDATE , 21) ,
  881. cast(Convert(decimal(18,2),isnull(QQ.qty,0)*1.00/mo.moplanqty*100) as NVARCHAR)+'%'
  882. from icsmo mo
  883. left join #TempMOComQty QQ on mo.mocode=qq.mocode
  884. left join ICSINVENTORY inv on inv.invcode=mo.itemcode
  885. where isnull(QQ.qty,0)<mo.moplanqty
  886. and qq.mocode is not null
  887. and MO.itemcode like '" + ItemNumber + @"%'
  888. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOComQty'))
  889. drop table #TempMOComQty ";
  890. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  891. return dt;
  892. }
  893. public DataTable GetZhiXing_OQC( )
  894. {
  895. string SqlText = "";
  896. SqlText = @"
  897. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIPPCC'))
  898. drop table #TempIPPCC
  899. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMonthcc'))
  900. drop table #TempMonthcc
  901. declare @begin datetime,@end datetime
  902. set @end=GETDATE()
  903. declare @months int
  904. set @months=6
  905. select convert(varchar(7),DATEADD(month,number*-1+1,@end) ,120) AS
  906. into #TempMonthcc
  907. from master.dbo.spt_values
  908. where type='p'
  909. AND number<=@months
  910. and number>=1
  911. order by 1
  912. select count(1) Qty,result,
  913. into #TempIPPCC
  914. from (
  915. select distinct ccode, invcode ,result,convert(varchar(7),mtime,120)
  916. from ICSOQCLotNo
  917. where mtime>=DATEADD(month,DATEDIFF(month,0,DATEADD(mm, -5, GETDATE() )),0)
  918. and result in('','')
  919. ) dd
  920. group by ,result
  921. select isnull( case when isnull(gg.QtyAll,0) =0 then 0 else
  922. Convert(decimal(18,2), (isnull(gg.QtyAll,0)-isnull(FF.QtyNG,0))*1.00/gg.QtyAll*100) end
  923. ,0) PercentNum,
  924. cc.
  925. FROM #TempMonthcc cc
  926. left join (select sum(qty) QtyAll, from #TempIPPCC hh group by ) GG on cc.=gg.
  927. left join (select isnull(sum(qty),0) QtyNG, from #TempIPPCC hh where result='' group by ) ff on cc.=ff.
  928. ORDER BY cc.
  929. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIPPCC'))
  930. drop table #TempIPPCC
  931. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMonthcc'))
  932. drop table #TempMonthcc
  933. ";
  934. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  935. return dt;
  936. }
  937. public DataTable GetZhiXing_RCVUnInWare()
  938. {
  939. string SqlText = "";
  940. SqlText = @"
  941. select A.CCODE , B.LOTNO,a.cInvCode as ,C.INVSTD ,C.INVNAME ,b.transno ,
  942. A.iQuantity AS ,A.STNO ,CONVERT(varchar(100), a.MTime, 23) MTime ,
  943. 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,'')
  944. from ICSPOArrive a with(nolock)
  945. inner join icsitemlot b with(nolock) on a.LOTNO=b.LotNO
  946. LEFT JOIN ICSINVENTORY C with(nolock) ON C.INVCODE = A.cInvCode
  947. where EXISTS(select 1 from ICSOQCLotNo d with(nolock) where D.CCODE=a.cCode and d.InvCode=a.cInvCode and result='' )
  948. and not EXISTS(select 1 from ICSWareHouseLotInfoLog ll with(nolock) where ll.lotno=a.lotno and ll.TransType='收')
  949. order by A.CCODE,a.cInvCode,B.LOTNO ";
  950. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
  951. return dt;
  952. }
  953. #endregion
  954. }
  955. }