|
|
using NFine.Code;using NFine.Domain.Entity.SystemManage;using System.Collections.Generic;using System.Data;using System.Data.Common;using NFine.Repository;using System.Text;using System;using System.Configuration;using NFine.Data;using System.IO;using Newtonsoft.Json;using NFine.Domain._02_ViewModel;using NFine.Data.Extensions;using Newtonsoft.Json.Linq;
namespace NFine.Application.SRM{ public class WatchPanelApp : RepositoryFactory<ModuleEntity> { //到货明细
public DataTable GetList1(string queryJson, ref Pagination jqgridparam) { var queryParam = queryJson.ToJObject(); OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString; List<DbParameter> parameter = new List<DbParameter>(); string SqlText = @"
select * from ( SELECT *,
收货数量 -已检数量 待检数量, CASE WHEN 收货数量 -已检数量> 0 THEN '待检验' WHEN 已检待入> 0 THEN '待入库' ELSE '完成' END 状态 FROM ( SELECT cc.receiptNo 到货单号,dd.orderno 订单号,dd.itemcode 料号,dd.planqty 收货数量,inv.invname 物料名称, isnull(( SELECT SUM (lotqty) FROM icsitemlot lot with (nolock) WHERE lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine AND isnull(IQCStatus,'') !='' AND cc.workpoint=lot.workpoint),0) 已检数量, isnull(( SELECT SUM (lotqty) FROM icsitemlot lot with (nolock) WHERE lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine AND isnull(IQCStatus,'') !='' AND cc.workpoint=lot.workpoint AND NOT EXISTS ( SELECT 1 FROM ICSWareHouseLotInfo info WHERE info.lotno=lot.lotno AND info.workpoint=lot.workpoint)),0) 已检待入 FROM ICSINVReceipt cc with (nolock) LEFT JOIN ICSINVReceiptDetail dd with (nolock) ON cc.ReceiptNO=dd.ReceiptNO AND dd.workpoint=cc.workpoint LEFT JOIN ICSINVENTORY inv with (nolock) ON inv.invcode=dd.itemcode AND dd.workpoint=inv.workpoint WHERE cc.mtime >=DATEADD(week, -1,getdate()) and cc.workpoint='" + workpoint + @"' ) ff ) gg ";
DataTable dt = Repository().FindTablePageBySql_Other(SqlText, "MESconnstr", parameter.ToArray(), ref jqgridparam);
return dt;
}
//来料不合格明细
public DataTable GetList2(string queryJson, ref Pagination jqgridparam) { var queryParam = queryJson.ToJObject(); string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString; OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); List<DbParameter> parameter = new List<DbParameter>(); string SqlText = @"
select * from ( SELECT cc.receiptNo 到货单,dd.orderno 采购订单号,dd.itemcode 料号, inv.invname 物料名称, sum(lot.lotqty) 不合格数量 ,kk.CKITEMDESC 不良原因 FROM ICSINVReceipt cc with (nolock) LEFT JOIN ICSINVReceiptDetail dd with (nolock) ON cc.ReceiptNO=dd.ReceiptNO AND dd.workpoint=cc.workpoint LEFT JOIN ICSINVENTORY inv with (nolock) ON inv.invcode=dd.itemcode AND dd.workpoint=inv.workpoint left join icsitemlot lot with (nolock) on lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine AND cc.workpoint=lot.workpoint left join (select * from (select ROW_NUMBER()over(partition by LOTNO order by mtime desc,id ) rowId,lotno ,errdata , CASE WHEN NG='' THEN CKITEMDESC ELSE NG END CKITEMDESC from ICSIQCErrList ck with (nolock) where workpoint='" + workpoint + @"' and errdata='不合格' ) as AuctionRecords where rowId=1) kk on kk.lotno=lot.lotno WHERE 1=1 and cc.mtime >=DATEADD(MONTH, -1,getdate()) -- and kk.errdata='不合格' and isnull(lot.iqcstatus,'') ='不合格' and cc.workpoint='" + workpoint + @"' group by cc.receiptNo ,dd.orderno ,dd.itemcode , inv.invname ,kk.CKITEMDESC ) jj ";
DataTable dt = Repository().FindTablePageBySql_Other(SqlText, "MESconnstr", parameter.ToArray(), ref jqgridparam);
return dt;
}
//配料信息表
public DataTable GetList3(string queryJson, ref Pagination jqgridparam) { string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString; var queryParam = queryJson.ToJObject(); string type = queryParam["type"].ToString(); OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); List<DbParameter> parameter = new List<DbParameter>(); string SqlText = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJRdTrans'))
drop table #Temp_TJRdTrans if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJRdTransLog')) drop table #Temp_TJRdTransLog if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJResult')) drop table #Temp_TJResult select tt.rdcode 出库单号,tt.invcode 产品编号, tt.rdstatus 业务类型, tt.depname 需求部门,tt.fromstoragecode 所属仓库, tt.mocode 生产工单号,'' 项目号,tt.rduser 制单人,tt.mtime 制单日期 , CASE WHEN isnull(tt.actqty,0) !=0 then '完成' else '待提交' end 状态, tt.rdNO,case when PLANQTY<0 then '物料退料' else '材料出库' end LogType into #Temp_TJRdTrans from ICSRdTransTer tt with (nolock) left join icsmo mo with (nolock) on mo.mocode=tt.mocode and mo.moseq=tt.moseq and mo.workpoint=tt.workpoint where tt.rdtype='材料出库单' AND TT.MTIME >DATEADD(MONTH, -1, GETDATE()) AND TT.WORKPOINT='" + workpoint + @"' and CASE WHEN isnull(tt.actqty,0) !=0 then '已完成' else '未完成' end ='" + type + @"'
SELECT * into #Temp_TJRdTransLog FROM ( 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
from ICSWareHouseLotInfoLog LOG with (nolock) WHERE EXISTS(SELECT 1 FROM #Temp_TJRdTrans TT WHERE tt.rdNO =LOG.TransLine AND TT.出库单号=LOG.TransNO AND LOG.BUSINESSCODE=tt.LogType and 状态='完成' ) AND LOG.WORKPOINT='" + workpoint + @"' ) FF WHERE RN=1
select distinct 出库单号,需求部门,生产工单号,制单人, CONVERT(varchar(19), 制单日期, 21) 制单日期,CONVERT(varchar(19), 完成日期, 21) 完成日期,状态 into #Temp_TJResult from ( SELECT tt.*,log.MUSERNAME 审核人,log.mtime 完成日期 FROM #Temp_TJRdTrans tt LEFT JOIN #Temp_TJRdTransLog log on tt.rdNO =LOG.TransLine AND TT.出库单号=LOG.TransNO
) gg ";
DataTable dt = Repository().FindTablePageBySql_OtherTemp(SqlText, " #Temp_TJResult ", @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJRdTrans'))
drop table #Temp_TJRdTrans if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJRdTransLog')) drop table #Temp_TJRdTransLog if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_TJResult')) drop table #Temp_TJResult ",
"MESconnstr", parameter.ToArray(), ref jqgridparam);
return dt;
}
//待入库明细
public DataTable GetList4(string queryJson, ref Pagination jqgridparam) { string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString; var queryParam = queryJson.ToJObject(); OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent(); List<DbParameter> parameter = new List<DbParameter>(); string SqlText = @"
select * from ( SELECT cc.receiptNo 到货单,dd.orderno 采购订单号,dd.itemcode 料号, inv.invname 物料名称, sum(lot.lotqty) 待入库数量 ,(select top 1 bincode from ICSWareHouseLotInfo info where info.lotno=lot.lotno and info.workpoint=cc.workpoint) 库位,lot.lotno 条码 FROM ICSINVReceipt cc with (nolock) LEFT JOIN ICSINVReceiptDetail dd with (nolock) ON cc.ReceiptNO=dd.ReceiptNO AND dd.workpoint=cc.workpoint LEFT JOIN ICSINVENTORY inv with (nolock) ON inv.invcode=dd.itemcode AND dd.workpoint=inv.workpoint left join icsitemlot lot with (nolock) on lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine AND cc.workpoint=lot.workpoint left join ICSWareHouseLotInfolog kk with (nolock) on kk.lotno=lot.lotno and kk.workpoint=cc.workpoint and kk.transtype='收' WHERE 1=1 and kk.lotno is null and lot.IQCStatus= '合格' and cc.mtime >=DATEADD(month, -1,getdate()) and cc.workpoint='" + workpoint + @"' group by cc.receiptNo ,dd.orderno ,dd.itemcode , inv.invname ,lot.lotno ,kk.tostackcode,cc.workpoint ) jj ";
DataTable dt = Repository().FindTablePageBySql_Other(SqlText, "MESconnstr", parameter.ToArray(), ref jqgridparam);
return dt;
}
//生产进度汇总表
public DataTable GetList_WIPJinDu(string queryJson, string filters, ref Pagination jqgridparam) { try { List<DbParameter> parameter = new List<DbParameter>();
#region 过滤条件
string SQLWhere = "";
if (!queryJson.Contains("[]")) { JObject jobject = JObject.Parse(queryJson); JArray array = JArray.Parse(jobject["value"].ToString()); SQLWhere += " and A.SEGCODE in (";
foreach(JObject j in array) { SQLWhere += "'" + j["value"].ToString()+"',"; } SQLWhere= SQLWhere.TrimEnd(','); SQLWhere += ")"; }
#endregion
string SqlText = GetCaiJiSQL(SQLWhere);
DataTable dt = SqlHelper.GetDataTableBySql(SqlText); return dt;
} catch (Exception ex) { WriteLogFile(ex.ToString(), "看板异常"); } return null; }
public DataTable GetList_WIPJinDu(string value) { try { WriteLogFile("参数:"+ value, "看板异常"); List<DbParameter> parameter = new List<DbParameter>();
#region 过滤条件
string SQLWhere = ""; if (!string.IsNullOrEmpty(value)) { SQLWhere += " and A.SEGCODE in ('" + value .Replace(",","','")+ "')"; }
#endregion
string SqlText = GetCaiJiSQL(SQLWhere);
DataTable dt = SqlHelper.GetDataTableBySql(SqlText);
return dt;
} catch (Exception ex) { WriteLogFile(ex.ToString(), "看板异常"); } return null; }
private string GetCaiJiSQL(string SQLWhere) { string SqlText = @"
if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOSelect')) drop table #TempMOSelect if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCaiJi')) drop table #TempCaiJi if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_MINDaJian')) drop table #Temp_MINDaJian select distinct lot.lotno,mo.mocode as 生产订单号, mo.moseq 生产订单行号, a.StartPlanDate as 工单日期,c.INVPARSETYPE as 产品代码, mo.ITEMCODE as 产品编码,mo.moplanqty as 计划量,lot.lotqty,a.mtime 换线时间,A.SEGCODE AS 线体 into #TempMOSelect from icsmo2user A with (nolock) inner JOIN ICSMO mo with (nolock) ON A.MOCODE=mo.MOCODE AND A.MOSEQ=mo.MOSEQ left join ICSITEMLot lot with (nolock) on mo.mocode=lot.transno and mo.moseq=lot.transline LEFT JOIN ICSINVENTORY C with (nolock) ON C.INVCODE=mo.ITEMCODE where mo.itemcode like '30%' and a.rcard='非批次' and a.StartPlanDate >= dateadd(day,-30,getdate()) " + SQLWhere + @"
select hh.lotno,hh.AB面,min(hh.mtime) mtime,tt.lotqty lotqty,生产订单号,生产订单行号 into #TempCaiJi from( select Rcard lotno,case when plane='BOTTOM' then 'B' else 'A' end AB面,min(mtime) mtime from ICSSZAOIDATA where Rcard is not null and Rcard!='' and Rcard in (select lotno from #TempMOSelect) group by Rcard,case when plane='BOTTOM' then 'B' else 'A' end union all select snno lotno,case when type='1' then 'A' else 'B' end AB面,min(data4) mtime from ICSAIODATA dd where snno is not null and snno!='' and snno in (select lotno from #TempMOSelect tt) group by snno ,case when type='1' then 'A' else 'B' end ) hh left join #TempMOSelect tt on hh.lotno=tt.lotno group by hh.lotno,hh.AB面,tt.lotqty,生产订单号,生产订单行号
select min(hh.mtime) mtime ,生产订单号 into #Temp_MINDaJian from ICSSMTFEEDINGINFO hh inner join #TempCaiJi tt on hh.mocode=tt.生产订单号 group by 生产订单号
select * , case when 计划量 is not null and 计划量!=0 then cast(Convert(decimal(18,2),产出量*1.0000/计划量*100) as nvarchar) +'%' else '0%' end 完成率 from ( select gg.线体,gg.生产订单号 ,gg.AB面,gg.工单日期 ,gg.产品编码 ,gg.产品代码 ,gg.换线时间 ,cc2.mtime 打件时间, (select min(mtime) from #TempCaiJi cc where cc.生产订单号=gg.生产订单号 and cc.生产订单行号=gg.生产订单行号 and cc.AB面=gg.AB面 ) 首检时间, gg.计划量, (select sum(lotqty) from #TempCaiJi cc where cc.生产订单号=gg.生产订单号 and cc.生产订单行号=gg.生产订单行号 and cc.AB面=gg.AB面 ) 产出量
from ( select cc.AB面,mm.生产订单号, mm.生产订单行号, mm.工单日期,mm.产品代码, mm. 产品编码,mm.计划量,min(换线时间) 换线时间,mm.线体 from #TempCaiJi cc left join #TempMOSelect mm with (nolock) on cc.lotno=mm.lotno group by cc.AB面,mm.生产订单号, mm.生产订单行号, mm.工单日期,mm.产品代码, mm. 产品编码,mm.计划量,mm.线体 ) gg left join #Temp_MINDaJian cc2 on cc2.生产订单号=gg.生产订单号 ) jj order by 2,1,3 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOSelect')) drop table #TempMOSelect if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCaiJi')) drop table #TempCaiJi if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Temp_MINDaJian')) drop table #Temp_MINDaJian
";
return SqlText; }
//项目阶段
public DataTable GetProjectJD() { List<DbParameter> parameter = new List<DbParameter>(); string sql = @" select distinct REPLACE(PROJECTSTAGE, '生产确认表', '待装配') NAME from EXP_PROJECTPRODUCTIONSCHEDULE
where OQC is null and not (PROJECTID>='2117101' and PROJECTID<='2117116') and REPLACE(PROJECTSTAGE, '生产确认表', '待装配') is not null";
DataTable dt = OracleHelper.GetTable(sql, "Oracleconnstr", parameter.ToArray()); return dt; //DataTable tblDatas = new DataTable("Datas");
//tblDatas.Columns.Add("NAME", Type.GetType("System.String"));
//for (int i = 0; i < 5; i++)
//{
// DataRow newRow;
// newRow = tblDatas.NewRow();
// newRow["NAME"] = i.ToString();
// tblDatas.Rows.Add(newRow);
//}
//return tblDatas;
}
//设备类型
public DataTable GetEQPType() { List<DbParameter> parameter = new List<DbParameter>(); string sql = @" select distinct DEVICETYPE NAME from EXP_PROJECTPRODUCTIONSCHEDULE
where OQC is null and not (PROJECTID>='2117101' and PROJECTID<='2117116') and DEVICETYPE is not null ";
DataTable dt = OracleHelper.GetTable(sql, "Oracleconnstr", parameter.ToArray()); return dt; }
//状态
public DataTable GetStatus() { List<DbParameter> parameter = new List<DbParameter>(); string sql = @" select distinct case when PROJECTSTAGE ='FAT完成' then '完成' when PROJECTSTAGE ='FQC' then '完成'
when BEGINDATE like '%-%-%' and TO_DATE(BEGINDATE,'YYYY-MM-DD')-sysdate < 7 and NVL(RTRIM(PROJECTSCHEDULE,'%'),0) <80 then '紧急' else STATUS end NAME from EXP_PROJECTPRODUCTIONSCHEDULE where OQC is null and not (PROJECTID>='2117101' and PROJECTID<='2117116') and case when PROJECTSTAGE ='FAT完成' then '完成' when PROJECTSTAGE ='FQC' then '完成' 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 ";
DataTable dt = OracleHelper.GetTable(sql, "Oracleconnstr", parameter.ToArray()); return dt; }
//生产进度-层析柱Qty
public DataTable GetWIPQty1() { try { List<DbParameter> parameter = new List<DbParameter>(); string SqlText = @"
SELECT sum(case when REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ) like '%开始%' or REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ) not like '%完成%' then to_number ( QUANTITY ) else 0 end ) WIPQTY, sum(case when REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ) not like '%开始%' and REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ) like '%完成%' then to_number ( QUANTITY ) else 0 end ) COMQTY, sum(to_number ( QUANTITY ) ) ZQTY, REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ), '完成', '' ), '开始', '' ) PROJECTStr FROM EXP_PROJECTPRODUCTIONSCHEDULE WHERE 1 = 1 and not (PROJECTID>='2117101' and PROJECTID<='2117116') and DEVICETYPE in ('EAC系列') and OQC is null GROUP BY REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ), '完成', '' ), '开始', '' ) HAVING sum(to_number ( QUANTITY ) )>0 ";
DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
return dt; } catch (Exception ex) { WriteLogFile(ex.ToString(), "看板异常"); } return null; }
//生产进度-设备Qty
public DataTable GetWIPQty5() { try { List<DbParameter> parameter = new List<DbParameter>(); string SqlText = @" SELECT
sum(case when REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ) like '%开始%' or REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ) not like '%完成%' then to_number ( QUANTITY ) else 0 end ) WIPQTY, sum(case when REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ) not like '%开始%' and REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ) like '%完成%' then to_number ( QUANTITY ) else 0 end ) COMQTY, sum(to_number ( QUANTITY ) ) ZQTY, REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ), '完成', '' ), '开始', '' ) PROJECTStr FROM EXP_PROJECTPRODUCTIONSCHEDULE WHERE 1 = 1 AND NOT ( PROJECTID >= '2117101' AND PROJECTID <= '2117116' ) AND DEVICETYPE NOT IN ( 'SAC系列','EAC系列' ) AND OQC IS NULL GROUP BY REPLACE( REPLACE( REPLACE( PROJECTSTAGE, '生产确认表', '待装配' ), '完成', '' ), '开始', '' ) HAVING sum(to_number ( QUANTITY ) )>0 ";
DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
return dt; } catch (Exception ex) { WriteLogFile(ex.ToString(), "看板异常"); } return null; }
//生产进度 柱状图 (在制数 完成数 )
public DataTable GetWIPQty2() {
try { //生产确认表 有值中: 电装开始 有值 就是已开工,电装开始 无值 就是待开工
List<DbParameter> parameter = new List<DbParameter>(); string SqlText = @" SELECT
SUM(CASE WHEN PRODUCTIONCONFIRM IS NOT NULL AND ELECTRICASSEMBLYSTART IS NOT NULL THEN to_number(QUANTITY) ELSE 0 END) YKGQty, SUM(CASE WHEN PRODUCTIONCONFIRM IS NOT NULL AND ELECTRICASSEMBLYSTART IS NULL THEN to_number(QUANTITY) ELSE 0 END) DKGQty
from EXP_PROJECTPRODUCTIONSCHEDULE WHERE 1=1 AND PRODUCTIONCONFIRM IS NOT NULL and not (PROJECTID>='2117101' and PROJECTID<='2117116') and OQC is null ";
DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
return dt; } catch (Exception ex) { WriteLogFile(ex.ToString(), "看板异常"); } return null; }
//设备类型在制数
public DataTable GetWIPQty3() {
try { //生产确认表 有值 FQC 无值
List<DbParameter> parameter = new List<DbParameter>(); string SqlText = @" SELECT
SUM( to_number(QUANTITY) ) Qty,nvl(DEVICETYPE,'空设备类型') EQPTypeName from EXP_PROJECTPRODUCTIONSCHEDULE WHERE 1=1 AND PRODUCTIONCONFIRM IS NOT NULL and not (PROJECTID>='2117101' and PROJECTID<='2117116') AND OQC IS NULL GROUP BY DEVICETYPE ";
DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
return dt; } catch (Exception ex) { WriteLogFile(ex.ToString(), "看板异常"); } return null; }
//待开工项目(Qty)
public DataTable GetWIPQty4() {
try { //生产确认表 有值 电装开始 无值
List<DbParameter> parameter = new List<DbParameter>(); string SqlText = @"
SELECT SUM ( to_number ( QUANTITY ) ) Qty, SUBSTR ( BEGINDATE, 0, 4+instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) ) MonthStr FROM EXP_PROJECTPRODUCTIONSCHEDULE WHERE 1 = 1 AND( (ELECTRICASSEMBLYSTART IS NULL AND PRODUCTIONCONFIRM IS NOT NULL and OQC IS NULL ) or PROJECTSTAGE='生产确认表' ) AND BEGINDATE IS NOT NULL and not (PROJECTID>='2117101' and PROJECTID<='2117116') GROUP BY SUBSTR ( BEGINDATE, 0, 4+instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) ), SUBSTR ( BEGINDATE, 0, 4 ), to_number ( SUBSTR ( BEGINDATE, 6, instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) - 1 ) ) ORDER BY SUBSTR ( BEGINDATE, 0, 4 ), to_number ( SUBSTR ( BEGINDATE, 6, instr ( SUBSTR ( BEGINDATE, 6, 3 ), '-' ) - 1 ) ) ";
DataTable dt = OracleHelper.GetTable(SqlText, "Oracleconnstr", parameter.ToArray());
return dt; } catch (Exception ex) { WriteLogFile(ex.ToString(), "看板异常"); } return null; }
//收货进度
public DataTable GetRCVJingDu() { string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString; List<DbParameter> parameter = new List<DbParameter>(); string SqlText = @"
if exists(select* from tempdb..sysobjects where id= object_id('tempdb..#TEMP_ItemCK')) drop table #TEMP_ItemCK
select sum(lotqty) Qty,cktype INTO #TEMP_ItemCK from( select lot.lotno, lot.lotqty, lot.IQCStatus, lot.step, case when lot.step= '优先' and lot.IQCStatus= '' then '优先待检' when isnull(lot.step,'')!='优先' and lot.IQCStatus='' then '待检' when lot.IQCStatus= '合格' then '已检待入' else '' end CKType from ICSINVReceipt cc with (nolock) left join ICSINVReceiptDetail dd with (nolock) on cc.ReceiptNO= dd.ReceiptNO and dd.workpoint= cc.workpoint left join ICSITEMLot lot with (nolock) on lot.mcode= dd.itemcode and lot.TransNO= dd.ReceiptNO and lot.TransLine= dd.ReceiptLine and dd.workpoint= lot.workpoint
where not exists(select 1 from ICSWareHouseLotInfoLog log with (nolock) where log.lotno= lot.lotno) and lot.lotno is not null and cc.workpoint ='" + workpoint + @"' and cc.mtime >=DATEADD(week, -1,getdate()) ) gg where cktype!='' group by cktype
select * from ( SELECT QTY,CKTYPE,cast(CONVERT(DECIMAL(18,2),QTY/(SELECT SUM(QTY) FROM #TEMP_ItemCK )*100) as NVARCHAR) +'%' Qtypercent from #TEMP_ItemCK union all SELECT 0,'优先待检', '0%' Qtypercent where not EXISTS(select 1 from #TEMP_ItemCK where cktype='优先待检') union all SELECT 0,'已检待入', '0%' Qtypercent where not EXISTS(select 1 from #TEMP_ItemCK where cktype='已检待入') union all SELECT 0,'待检', '0%' Qtypercent where not EXISTS(select 1 from #TEMP_ItemCK where cktype='待检') ) ff order by case CKTYPE when '已检待入' then 0 when '优先待检' then 1 when '待检' then 2 else 3 end ";
DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
return dt; }
//到货数量(item)
public DataTable GetRCVQty(string type) { string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString; List<DbParameter> parameter = new List<DbParameter>();
string SqlText = ""; switch (type) { case "日": SqlText = @"
IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) DROP TABLE #TEMP_Itemrr_tt IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) DROP TABLE #TEMP_Itemrr_tt2 SELECT CONVERT( VARCHAR ( 100 ), DATEADD( DAY, number *- 1, getdate( ) ), 23 ) AS 日期 INTO #TEMP_Itemrr_tt2 FROM master.dbo.spt_values WHERE type = 'p' AND number <= 6 AND number >= 0 SELECT SUM( planqty ) QTY, CONVERT ( VARCHAR ( 100 ), mtime, 23 ) 日期 INTO #TEMP_Itemrr_tt FROM ICSINVReceiptDetail WHERE mtime >= CONVERT ( VARCHAR ( 10 ), DATEADD( DAY, - 6, getdate( ) ), 23 ) + ' 00:00:00' AND workpoint = '" + workpoint + @"' GROUP BY CONVERT ( VARCHAR ( 100 ), mtime, 23 ) SELECT substring( aa.日期,6,5) 日期, isnull( bb.qty, 0 ) QTY FROM #TEMP_Itemrr_tt2 aa LEFT JOIN #TEMP_Itemrr_tt bb ON aa.日期 = bb.日期 ORDER BY 1 IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) DROP TABLE #TEMP_Itemrr_tt
IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) DROP TABLE #TEMP_Itemrr_tt2 ";
break; case "周": SqlText = @"
IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) DROP TABLE #TEMP_Itemrr_tt IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) DROP TABLE #TEMP_Itemrr_tt2
SELECT DATEPART(wk,CONVERT( VARCHAR ( 10 ), DATEADD( week, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS 日期 , CONVERT( VARCHAR ( 4 ), DATEADD( week, -1*NUMBER, getdate( ) ),23) 年 INTO #TEMP_Itemrr_tt2 FROM master.dbo.spt_values WHERE type = 'p' AND number <= 7 AND number >= 0 SELECT SUM( planqty ) QTY, DATEPART(wk, mtime) 日期,CONVERT( VARCHAR ( 4 ),mtime,23) 年 INTO #TEMP_Itemrr_tt FROM ICSINVReceiptDetail with (nolock) WHERE mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( week, -7, getdate( ) ),23)+' 00:00:00' AND workpoint = '" + workpoint + @"' GROUP BY DATEPART(wk, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(wk, mtime)
SELECT aa.日期, isnull( bb.qty, 0 ) QTY FROM #TEMP_Itemrr_tt2 aa LEFT JOIN #TEMP_Itemrr_tt bb ON aa.日期 = bb.日期 AND aa.年 = bb.年 ORDER BY aa.年, aa.日期 IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) DROP TABLE #TEMP_Itemrr_tt
IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) DROP TABLE #TEMP_Itemrr_tt2 "; break;
case "月": SqlText = @"
IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) DROP TABLE #TEMP_Itemrr_tt IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) DROP TABLE #TEMP_Itemrr_tt2
SELECT DATEPART(month,CONVERT( VARCHAR ( 10 ), DATEADD( month, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS 日期 , CONVERT( VARCHAR ( 4 ), DATEADD( month, -1*NUMBER, getdate( ) ),23) 年 INTO #TEMP_Itemrr_tt2 FROM master.dbo.spt_values WHERE type = 'p' AND number <= 11 AND number >= 0 SELECT SUM( planqty ) QTY, DATEPART(month, mtime) 日期,CONVERT( VARCHAR ( 4 ),mtime,23) 年 INTO #TEMP_Itemrr_tt FROM ICSINVReceiptDetail with (nolock) WHERE mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( month, -11, getdate( ) ),23)+' 00:00:00' AND workpoint = '" + workpoint + @"' GROUP BY DATEPART(month, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(month, mtime)
SELECT aa.日期, isnull( bb.qty, 0 ) QTY FROM #TEMP_Itemrr_tt2 aa LEFT JOIN #TEMP_Itemrr_tt bb ON aa.日期 = bb.日期 AND aa.年 = bb.年 ORDER BY aa.年, aa.日期 IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) DROP TABLE #TEMP_Itemrr_tt
IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) DROP TABLE #TEMP_Itemrr_tt2 "; break;
case "年": SqlText = @"
SELECT SUM( planqty ) QTY, CONVERT( VARCHAR ( 4 ),mtime,23) 日期 FROM ICSINVReceiptDetail with (nolock) WHERE workpoint = '" + workpoint + @"' GROUP BY CONVERT( VARCHAR ( 4 ),mtime,23) ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23)
"; break;
}
DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
return dt; }
//入库数量(item)
public DataTable GetWareInQty(string type) { string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString; List<DbParameter> parameter = new List<DbParameter>();
string SqlText = ""; switch (type) { case "日": SqlText = @"
IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) DROP TABLE #TEMP_Itemrr_tt IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) DROP TABLE #TEMP_Itemrr_tt2 SELECT CONVERT( VARCHAR ( 100 ), DATEADD( DAY, number *- 1, getdate( ) ), 23 ) AS 日期 INTO #TEMP_Itemrr_tt2 FROM master.dbo.spt_values WHERE type = 'p' AND number <= 6 AND number >= 0 SELECT SUM( TRANSQTY ) QTY, CONVERT ( VARCHAR ( 100 ), MTIME, 23 ) 日期 INTO #TEMP_Itemrr_tt FROM ICSWareHouseLotInfoLOG log with (nolock) WHERE MTIME >= CONVERT ( VARCHAR ( 10 ), DATEADD( DAY, - 6, getdate( ) ), 23 ) + ' 00:00:00' AND workpoint = '" + workpoint + @"' and log.transtype in ('收','退') GROUP BY CONVERT ( VARCHAR ( 100 ), MTIME, 23 ) SELECT substring( aa.日期,6,5) 日期, isnull( bb.qty, 0 ) QTY FROM #TEMP_Itemrr_tt2 aa LEFT JOIN #TEMP_Itemrr_tt bb ON aa.日期 = bb.日期 ORDER BY 1 IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) DROP TABLE #TEMP_Itemrr_tt
IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) DROP TABLE #TEMP_Itemrr_tt2 ";
break; case "周": SqlText = @"
IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) DROP TABLE #TEMP_Itemrr_tt IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) DROP TABLE #TEMP_Itemrr_tt2
SELECT DATEPART(wk,CONVERT( VARCHAR ( 10 ), DATEADD( week, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS 日期 , CONVERT( VARCHAR ( 4 ), DATEADD( week, -1*NUMBER, getdate( ) ),23) 年 INTO #TEMP_Itemrr_tt2 FROM master.dbo.spt_values WHERE type = 'p' AND number <= 7 AND number >= 0 SELECT SUM( transqty ) QTY, DATEPART(wk, mtime) 日期,CONVERT( VARCHAR ( 4 ),mtime,23) 年 INTO #TEMP_Itemrr_tt FROM ICSWareHouseLotInfolog log with (nolock) WHERE mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( week, -7, getdate( ) ),23)+' 00:00:00' AND workpoint = '" + workpoint + @"' and log.transtype in ('收','退') GROUP BY DATEPART(wk, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(wk, mtime)
SELECT aa.日期, isnull( bb.qty, 0 ) QTY FROM #TEMP_Itemrr_tt2 aa LEFT JOIN #TEMP_Itemrr_tt bb ON aa.日期 = bb.日期 AND aa.年 = bb.年 ORDER BY aa.年, aa.日期 IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) DROP TABLE #TEMP_Itemrr_tt
IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) DROP TABLE #TEMP_Itemrr_tt2 "; break;
case "月": SqlText = @"
IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) DROP TABLE #TEMP_Itemrr_tt IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) DROP TABLE #TEMP_Itemrr_tt2
SELECT DATEPART(month,CONVERT( VARCHAR ( 10 ), DATEADD( month, -1*NUMBER, getdate( ) ),23)+' 00:00:00') AS 日期 , CONVERT( VARCHAR ( 4 ), DATEADD( month, -1*NUMBER, getdate( ) ),23) 年 INTO #TEMP_Itemrr_tt2 FROM master.dbo.spt_values WHERE type = 'p' AND number <= 11 AND number >= 0 SELECT SUM( transqty ) QTY, DATEPART(month, mtime) 日期,CONVERT( VARCHAR ( 4 ),mtime,23) 年 INTO #TEMP_Itemrr_tt FROM ICSWareHouseLotInfolog log with (nolock) WHERE mtime >= CONVERT( VARCHAR ( 10 ), DATEADD( month, -11, getdate( ) ),23)+' 00:00:00' AND workpoint = '" + workpoint + @"' and log.transtype in ('收','退') GROUP BY DATEPART(month, mtime) ,CONVERT( VARCHAR ( 4 ),mtime,23) ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23),DATEPART(month, mtime)
SELECT aa.日期, isnull( bb.qty, 0 ) QTY FROM #TEMP_Itemrr_tt2 aa LEFT JOIN #TEMP_Itemrr_tt bb ON aa.日期 = bb.日期 AND aa.年 = bb.年 ORDER BY aa.年, aa.日期 IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt' ) ) DROP TABLE #TEMP_Itemrr_tt
IF EXISTS ( SELECT * FROM tempdb..sysobjects WHERE id = object_id( 'tempdb..#TEMP_Itemrr_tt2' ) ) DROP TABLE #TEMP_Itemrr_tt2 "; break;
case "年": SqlText = @"
SELECT SUM( transqty ) QTY, CONVERT( VARCHAR ( 4 ),mtime,23) 日期 FROM ICSWareHouseLotInfolog log with (nolock) WHERE workpoint = '" + workpoint + @"' and log.transtype in ('收','退') GROUP BY CONVERT( VARCHAR ( 4 ),mtime,23) ORDER BY CONVERT( VARCHAR ( 4 ),mtime,23)
"; break;
}
DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
return dt; }
//配料进度
public DataTable GetPeiLiaoJingDu() { string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString; List<DbParameter> parameter = new List<DbParameter>(); string SqlText = @"
select UnDoQty, DoneQty, case when DoneQty + UnDoQty=0 then '0%' else cast(Convert(decimal(18, 2), DoneQty / (DoneQty + UnDoQty) * 100) as NVARCHAR) + '%' end DoneQtyPer, case when DoneQty + UnDoQty=0 then '0%' else cast(Convert(decimal(18, 2), UnDoQty / (DoneQty + UnDoQty) * 100) as NVARCHAR) + '%' end UnDoQtyPer from( select isnull(sum(case when isnull(actqty, 0) = 0 then planqty else 0 end),0) UnDoQty, isnull(sum(case when isnull(actqty, 0) = 0 then 0 else actqty end),0) DoneQty from ICSRdTransTer with (nolock) where RdType = '材料出库单' and planqty > 0 and workpoint ='" + workpoint + @"' and mtime >=DATEADD(MONTH, -1,getdate()) ) gg ";
DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null); DataTable retdd = new DataTable(); retdd.Columns.Add("cktype", Type.GetType("System.String")); retdd.Columns.Add("Qty", Type.GetType("System.Decimal")); retdd.Columns.Add("Qtypercent", Type.GetType("System.String"));
if (dt != null && dt.Rows.Count > 0) { DataRow newRow = retdd.NewRow(); newRow["cktype"] = "待配料"; newRow["Qty"] = Convert.ToDecimal(dt.Rows[0]["UnDoQty"].ToString()); newRow["Qtypercent"] = dt.Rows[0]["UnDoQtyPer"].ToString(); retdd.Rows.Add(newRow);
DataRow newRow2 = retdd.NewRow(); newRow2["cktype"] = "已配料"; newRow2["Qty"] = Convert.ToDecimal(dt.Rows[0]["DoneQty"].ToString()); newRow2["Qtypercent"] = dt.Rows[0]["DoneQtyPer"].ToString(); retdd.Rows.Add(newRow2); } else { DataRow newRow = retdd.NewRow(); newRow["cktype"] = "待配料"; newRow["Qty"] = 0; newRow["Qtypercent"] = "0%"; retdd.Rows.Add(newRow);
DataRow newRow2 = retdd.NewRow(); newRow2["cktype"] = "已配料"; newRow2["Qty"] = 0; newRow2["Qtypercent"] = "0%"; retdd.Rows.Add(newRow2); }
return retdd; }
public DataTable GetSScode(string cookie) { string sql = @"
select distinct a.sscode as name,a.sscode as value,'' as selected from ICSSS as a,ICSSEG as b,ICSSHIFTTYPE as c where a.SEGID = b.ID and a.SHIFTTYPEID = c.ID and b.WorkPoint = a.WorkPoint and c.WorkPoint = a.WorkPoint order by 1 ";
DataTable table= Repository().GetDataTableBySql_Other(sql, "MESconnstr", null); foreach (DataRow row in table.Rows) { if (!string.IsNullOrEmpty(cookie)) { JObject jobject = JObject.Parse(cookie); JArray array = JArray.Parse(jobject["value"].ToString()); foreach (JObject j in array) { if (j["value"].ToString() == row["value"].ToString()) row["selected"] = "true"; }
}
} table.AcceptChanges(); return table; }
public static void WriteLogFile(string input, string txtName) { try { string logAdress = "C:\\看板日志" + "\\"; if (!System.IO.Directory.Exists(logAdress)) { System.IO.Directory.CreateDirectory(logAdress);//不存在就创建目录
}
string adress = logAdress + txtName; if (!System.IO.Directory.Exists(adress)) { System.IO.Directory.CreateDirectory(adress);//不存在就创建目录
}
// string logAdress = ConfigurationManager.AppSettings["logAdress"].ToString();
/**/ ///指定日志文件的目录
string fname = adress + "\\" + "log" + DateTime.Now.ToString("yy-MM-dd") + ".txt"; /**/ ///定义文件信息对象
FileInfo finfo = new FileInfo(fname);
if (!finfo.Exists) { FileStream fs; fs = File.Create(fname); fs.Close(); finfo = new FileInfo(fname); }
/**/ ///判断文件是否存在以及是否大于2K
if (finfo.Length > 1024 * 1024 * 10) { /**/ ///文件超过10MB则重命名
File.Move(logAdress + "\\Log\\" + txtName + ".txt", Directory.GetCurrentDirectory() + DateTime.Now.TimeOfDay + "\\Log\\" + txtName + ".txt"); /**/ ///删除该文件
//finfo.Delete();
} //finfo.AppendText();
/**/ ///创建只写文件流
using (FileStream fs = finfo.OpenWrite()) { /**/ ///根据上面创建的文件流创建写数据流
StreamWriter w = new StreamWriter(fs);
/**/ ///设置写数据流的起始位置为文件流的末尾
///设置写数据流的起始位置为文件流的末尾
w.BaseStream.Seek(0, SeekOrigin.End);
w.WriteLine("*****************Start*****************"); w.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); /**/ ///写入当前系统时间并换行
/**/ ///写入日志内容并换行
w.WriteLine(input);
/**/ ///写入------------------------------------“并换行
w.WriteLine("------------------END------------------------");
/**/ ///清空缓冲区内容,并把缓冲区内容写入基础流
w.Flush();
/**/ ///关闭写数据流
w.Close(); } } catch (Exception ex) { }
}
public string ConvertDataTableToJson(DataTable dt) { StringBuilder sbs = new StringBuilder(); if (dt.Rows.Count > 0)//如果有记录
{ sbs.Append("{'" + dt.TableName + "':["); string str = ""; foreach (DataRow dr in dt.Rows)//开始拼
{ string result = ""; foreach (DataColumn dc in dt.Columns) { result += string.Format(",'{0}':'{1}'", dc.ColumnName, dr[dc.ColumnName]); } result = result.Substring(1); result = ",{" + result + "}"; str += result; } str = str.Substring(1); sbs.Append(str); sbs.Append("]}"); } else//如果没有记录
{ sbs.Append(""); } return sbs.ToString(); }
#region 执行大看板
public DataTable GetZhiXing_MO(string ItemNumber) { string SqlText = ""; SqlText = @"
if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCCDD')) drop table #TempCCDD SELECT DISTINCT C.molotcode as 销售车号,C.ITEMCODE 物料编码,dd.INVNAME 物料名称 ,C.MOCODE 工单号,LL.OPSEQ,a.OPCODE 工序代码,ppp.opname 工序名称,us.UserName 报工人,CASE WHEN A.ACTIONRESULT='COLLECT_BEGIN' then '----生产中----' WHEN A.ACTIONRESULT='COLLECT_END' then '----已结束----' end as 工序结束状态,SUM(DATEDIFF(MINUTE, B.BeginDateTime, B.EndDateTime)) as '报工时长',isnull(SUM(DATEDIFF(MINUTE, B.BeginDateTime, B.EndDateTime))-ISNULL(xx.[暂停时长],0),'') AS 有效时间,xx.[暂停时长], isnull(CONVERT(VARCHAR,B.BeginDateTime,120),'') 开工时间, isnull(CONVERT(VARCHAR,B.EndDateTime,120),'') 完工时间,isnull(CONVERT(VARCHAR,xx.开始时间 ,120),'') as 暂停开始时间,isnull(CONVERT(VARCHAR,xx.结束时间,120),'') as 暂停结束时间,xx.[暂停原因],xx.[暂停备注]into #TempCCDDFROM ICSLOTONWIP A LEFT JOIN ICSLOTONWIPDetail B ON A.LOTNO=B.LOTNO AND A.OPCODE=B.OPCODELEFT JOIN ICSOP ppp on a.OPCODE=ppp.OPCODELEFT JOIN ICSLOTSIMULATION nn on nn.LOTNO=A.LOTNOLEFT JOIN Sys_User us on us.UserCode=B.UserCodeBeginLEFT JOIN ICSMO C ON A.MOCODE=C.MOCODE AND A.MOSEQ=C.MOSEQLEFT JOIN ICSMO2ROUTE gg ON c.MOCODE=gg.MOCODE and gg.EATTRIBUTE1=C.MOSEQLEFT JOIN ICSINVENTORY dd on C.ITEMCODE=dd.INVCODELEFT JOIN ICSITEMROUTE2OPLot LL ON LL.LotNo=A.LOTNO AND A.OPCODE=LL.OPCODELEFT JOIN ICSMO2User UU ON UU.LOTNO=A.LOTNO AND UU.OPCODE=A.OPCODE AND B.ECCode=UU.CREWCODELEFT JOIN (SELECT DISTINCT C.molotcode as 销售车号,C.ITEMCODE 物料编码,dd.INVNAME 物料名称 ,gg.ROUTECODE 工艺路线 ,A.LOTNO 跟踪单号, c.MOCODE 工单号,c.MOSEQ 工单行号, A.OPCODE 工序,us.UserName as 报工人,pp.BeginTime 开始时间,pp.EndTime 结束时间,SUM(DATEDIFF(MINUTE, PP.BeginTime, PP.EndTime)) as '暂停时长' ,vv.EnumText 暂停原因,pp.Memo 暂停备注 from ICSLOTONWIP A INNER JOIN ICSLOTPAUSE pp on A.Lotno=pp.lotno and A.opcode=pp.opcode
LEFT JOIN Sys_User us on us.UserCode=PP.UsercodeLEFT JOIN ICSMO C ON A.MOCODE=C.MOCODE AND A.MOSEQ=C.MOSEQLEFT JOIN ICSMO2ROUTE gg ON c.MOCODE=gg.MOCODE and gg.EATTRIBUTE1=C.MOSEQLEFT JOIN ICSINVENTORY dd on C.ITEMCODE=dd.INVCODE LEFT JOIN ICSITEMROUTE2OPLot LL ON LL.LotNo=A.LOTNO AND A.OPCODE=LL.OPCODELEFT JOIN ICSMO2User UU ON UU.LOTNO=A.LOTNO AND UU.OPCODE=A.OPCODE AND pp.EATTRIBUTE1=UU.CREWCODELEFT JOIN Sys_EnumValues vv on vv.EnumValue=pp.RESCODE --AND vv.EnumKey='00022' where pp.MODELCODE='标准报工' and vv.EnumKey='00022' --AND a.LOTNO=''-- and A.ACTIONRESULT = 'COLLECT_END'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 ,pp.Memo) xx on xx.[工单号]=c.MOCODE AND xx.[工单行号]=c.MOSEQ AND A.OPCODE=xx.[工序] AND xx.[报工人]=us.UserName AND xx.开始时间 >B.BeginDateTime --AND xx.结束时间 < B.EndDateTimeAND ISNULL(xx.结束时间, '2024-02-21 17:37:02') < ISNULL(B.EndDateTime, '2025-02-21 17:37:02')where 1=1 AND b.Type='标准报工' and a.WorkPoint='6000' and B.BeginDateTime>=DATEADD(mm, -3, getdate())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.[暂停原因],xx.[暂停备注],A.ACTIONRESULT,LL.OPSEQ
ORDER BY C.molotcode, C.ITEMCODE ,LL.OPSEQ,us.UserName asc
SELECT *,case when 暂停开始时间 is not null and 暂停结束时间 is null then '暂停中' else '' end 暂停状态 FROM #TempCCDDWHERE CONVERT(varchar(10), 开工时间, 21) =(SELECT MAX(CONVERT(varchar(10), 开工时间, 21)) FROM #TempCCDD)ORDER BY 销售车号,物料编码,报工人 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempCCDD')) drop table #TempCCDD ";
DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
return dt; } #endregion
#region 振翔生产进度区域一
public DataTable GetAreal1() { string where1 = ""; string SqlText = ""; SqlText = @" select * from(
select isnull(mpproduct,0) as 月度生产,isnull(mpsaleout,0) 月度发车 from ICSZXBoardPlan where moth = CONVERT(CHAR(10),DATEADD(month,0,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) )a left join ( select isnull(realsaleout,0) 上月度发车 from ICSZXBoardSaleout where id = '1') b on 1=1";
DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null); return dt; } #endregion
#region 振翔生产进度
public DataTable GetProductProgress(string ItemNumber) { string where1 = "";
string SqlText = ""; SqlText = @" --socode销售车辆号 monum工单总行 wipnum报告结束数量 wipbnum报告的数量含开工中
select tmo.socode,tmo.monum,isnull(wip.wipnum ,0) as wipnum , isnull(wipb.num ,0) as wipbnum into #tempNum from ( select tso.socode ,count(*) as monum from icsso tso left join icsmo tmo on tso.socode = tmo.molotcode group by tso.socode ) tmo left join ( select tso.socode ,count(*) as wipnum from icsso tso left join (select mocode,molotcode from icsmo group by mocode,molotcode) tmo on tso.socode = tmo.molotcode LEFT JOIN ICSLOTSIMULATION wip on tmo.mocode = wip.mocode where wip.iscom='1' group by tso.socode ) wip on tmo.socode = wip.socode left join ( select tso.socode ,count(*) as num from icsso tso left join (select mocode,molotcode from icsmo group by mocode,molotcode) tmo on tso.socode = tmo.molotcode LEFT JOIN ICSLOTONWIP wip on tmo.mocode = wip.mocode where wip.actionresult!='' group by tso.socode ) wipb on tmo.socode = wipb.socode
select row_number() over (order by a.客户交货期,a.销售车辆号)as 序号, a.* from ( select distinct tso.socode 销售车辆号,tso.plandate as 客户交货期, isnull(convert(char(4),cus.fname),'') 用户单位, inv.invname as 产品名称, concat(cast(cast(tnum.wipnum * 1.0 / tnum.monum as decimal(18,3))* 100 as decimal(18,1)),'%') 进度, (case when tnum.wipnum/tnum.monum =1 then '已完工' when tnum.wipbnum >0 then '开工中' else '未开工' end ) 生产状态 from icsso tso left join ICSCustomer cus on tso.cusid = cus.FCUSTID left join icsmo tmo on tso.socode = tmo.molotcode left join #tempNum tnum on tnum.socode = tso.socode left join ICSINVENTORY inv on inv.invstd LIKE '%'+'.'+tmo.molotcode where tso.status = 'C' and tmo.id in(select moid from ICSMO2ROUTE)) a if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempNum')) drop table #tempNum ";
DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
return dt; } #endregion
#region 振翔月进度
#endregion
#region 振翔看板产量
public DataTable GetOutput() {
string SqlText = "";
SqlText = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempNum'))
drop table #tempNum if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempData')) drop table #tempData --用销售订单中的销售车辆号查询出工单开工行数,与报工表中的数据做对比 相等的为完工数量 select tmo.socode,tmo.monum,isnull(wip.wipnum ,0) as wipnum ,wip.EndTime into #tempNum from ( select tso.socode ,count(*) as monum from icsso tso left join icsmo tmo on tso.socode = tmo.molotcode group by tso.socode ) tmo left join ( select tso.socode ,count(*) as wipnum,min(wip.EndTime) EndTime from icsso tso left join (select mocode,molotcode from icsmo group by mocode,molotcode) tmo on tso.socode = tmo.molotcode LEFT JOIN ICSLOTSIMULATION wip on tmo.mocode = wip.mocode where wip.iscom='1' group by tso.socode ) wip on tmo.socode = wip.socode
select * into #tempData from( select isnull(mpproduct,0) as 上月度生产 from ICSZXBoardPlan where moth = CONVERT(CHAR(10),DATEADD(month,-1,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) )a --此部分为上月数据 left join ( select isnull(mpproduct,0) as 前月度生产 from ICSZXBoardPlan where moth = CONVERT(CHAR(10),DATEADD(month,-2,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) ) b on 1=1 --此部分为前月数据 left join ( select count(*) 上月完成 from #tempNum t where t.wipnum = t.monum and t.EndTime between CONVERT(CHAR(10),DATEADD(month,-1,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) and CONVERT(CHAR(10),DATEADD(month,0,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120)) c on 1=1 left join ( select count(*) 前月完成 from #tempNum t where t.wipnum = t.monum and t.EndTime between CONVERT(CHAR(10),DATEADD(month,-2,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) and CONVERT(CHAR(10),DATEADD(month,-1,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120)) d on 1=1
select isnull(上月度生产,'0') 上月度生产 , isnull(上月完成,'0') 上月完成, isnull(前月度生产,'0') 前月度生产 , isnull(前月完成,'0') 前月完成, --case when isnull(上月度生产,0) = 0 then 0 else --convert(decimal(10,2),isnull(上月度生产,0))*1.0/isnull(convert(decimal(10,2),case when 上月完成 = 0 then 1 else 上月完成 end),1) end 上月比, --case when isnull(前月度生产,0) = 0 then 0 else --convert(decimal(10,2),isnull(前月度生产,0))*1.0/isnull(convert(decimal(10,2),case when 前月完成 = 0 then 1 else 前月完成 end),1) end 前月比, case when isnull(上月完成,0) = 0 then 0 else convert(decimal(10,2),isnull(上月完成,0))*1.0/isnull(convert(decimal(10,2),case when 上月度生产 = 0 then 1 else 上月度生产 end),1) end 上月比, case when isnull(前月完成,0) = 0 then 0 else convert(decimal(10,2),isnull(前月完成,0))*1.0/isnull(convert(decimal(10,2),case when 前月度生产 = 0 then 1 else 前月度生产 end),1) end 前月比, month(DATEADD(month,-1,DATEADD(dd,-DAY(GETDATE())+1,GETDATE()))) 上月, month(DATEADD(month,-2,DATEADD(dd,-DAY(GETDATE())+1,GETDATE()))) 前月 from #tempData if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempNum')) drop table #tempNum if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempData')) drop table #tempData ";
DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
return dt; } #endregion
#region 振翔看板月产出
public DataTable monthOutput() {
string SqlText = ""; //SqlText = @"
// if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempMO'))
// drop table #tempMO
// if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempM'))
// drop table #tempM
// --获取当前月份前十一个月的最大工单行数据
// select mocode,max(MOSEQ) as moseq
// into #tempMO
// from icsmo
// where MTIME between CONVERT(CHAR(10),DATEADD(month,-11,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111)
// and CONVERT(CHAR(10),DATEADD(month,0,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111)
// group by mocode
// --查询出当前年月向前十二月数据
// select *
// into #tempM
// from
// (select
// CONVERT(CHAR(7),DATEADD(month,-11,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
// union select
// CONVERT(CHAR(7),DATEADD(month,-10,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
// union select
// CONVERT(CHAR(7),DATEADD(month,-9,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
// union select
// CONVERT(CHAR(7),DATEADD(month,-8,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
// union select
// CONVERT(CHAR(7),DATEADD(month,-7,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
// union select
// CONVERT(CHAR(7),DATEADD(month,-6,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
// union select
// CONVERT(CHAR(7),DATEADD(month,-5,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
// union select
// CONVERT(CHAR(7),DATEADD(month,-4,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
// union select
// CONVERT(CHAR(7),DATEADD(month,-3,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
// union select
// CONVERT(CHAR(7),DATEADD(month,-2,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
// union select
// CONVERT(CHAR(7),DATEADD(month,-1,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont
// union select
// CONVERT(CHAR(7),DATEADD(month,0,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont) TempM
// --获取前十二月数据
// select Mont,isnull(num,0) as num from #tempM tm
// left join (
// select convert(varchar(7),EndTime ,111) endtime, count(*) num
// from ICSLOTONWIP wip
// left join #tempMO mo on mo.moseq = wip.MOSEQ and mo.MOCODE = wip.MOCODE
// where wip.ACTIONRESULT = 'COLLECT_END'
// group by convert(varchar(7),EndTime ,111)) wip on tm.Mont= wip.endtime
// if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempMO'))
// drop table #tempMO
// if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempM'))
// drop table #tempM
// ";
SqlText = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempNum'))
drop table #tempNum
--用销售订单中的销售车辆号查询出工单开工行数,与报工表中的数据做对比 相等的为完工数量 select tmo.socode,tmo.monum,isnull(wip.wipnum ,0) as wipnum ,wip.EndTime into #tempNum from ( select tso.socode ,count(*) as monum from icsso tso left join icsmo tmo on tso.socode = tmo.molotcode group by tso.socode ) tmo left join ( select tso.socode ,count(*) as wipnum,min(wip.EndTime) EndTime from icsso tso left join (select mocode,molotcode from icsmo group by mocode,molotcode) tmo on tso.socode = tmo.molotcode LEFT JOIN ICSLOTSIMULATION wip on tmo.mocode = wip.mocode where wip.iscom='1' group by tso.socode ) wip on tmo.socode = wip.socode
select count(*) num , CONVERT(CHAR(7),DATEADD(month,0,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont from #tempNum t where t.wipnum = t.monum and t.EndTime between CONVERT(CHAR(10),DATEADD(month,-1,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) and CONVERT(CHAR(10),DATEADD(month,0,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) union select count(*) num , CONVERT(CHAR(7),DATEADD(month,-1,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont from #tempNum t where t.wipnum = t.monum and t.EndTime between CONVERT(CHAR(10),DATEADD(month,-2,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) and CONVERT(CHAR(10),DATEADD(month,-1,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) union select count(*) num,CONVERT(CHAR(7),DATEADD(month,-2,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont from #tempNum t where t.wipnum = t.monum and t.EndTime between CONVERT(CHAR(10),DATEADD(month,-3,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) and CONVERT(CHAR(10),DATEADD(month,-2,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) union select count(*) num,CONVERT(CHAR(7),DATEADD(month,-3,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont from #tempNum t where t.wipnum = t.monum and t.EndTime between CONVERT(CHAR(10),DATEADD(month,-4,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) and CONVERT(CHAR(10),DATEADD(month,-3,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) union select count(*) num,CONVERT(CHAR(7),DATEADD(month,-4,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont from #tempNum t where t.wipnum = t.monum and t.EndTime between CONVERT(CHAR(10),DATEADD(month,-5,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) and CONVERT(CHAR(10),DATEADD(month,-4,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) union select count(*) num,CONVERT(CHAR(7),DATEADD(month,-5,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),111) Mont from #tempNum t where t.wipnum = t.monum and t.EndTime between CONVERT(CHAR(10),DATEADD(month,-6,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) and CONVERT(CHAR(10),DATEADD(month,-5,DATEADD(dd,-DAY(GETDATE())+1,GETDATE())),120) if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#tempNum')) drop table #tempNum ";
DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null); return dt; } #endregion
public DataTable GetZhiXing_OQC( ) {
string SqlText = "";
SqlText = @"
if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIPPCC')) drop table #TempIPPCC if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMonthcc')) drop table #TempMonthcc declare @begin datetime,@end datetime set @end=GETDATE() declare @months int set @months=6 select convert(varchar(7),DATEADD(month,number*-1+1,@end) ,120) AS 月份 into #TempMonthcc from master.dbo.spt_values where type='p' AND number<=@months and number>=1 order by 1 select count(1) Qty,result,月份 into #TempIPPCC from ( select distinct ccode, invcode ,result,convert(varchar(7),mtime,120) 月份
from ICSOQCLotNo where mtime>=DATEADD(month,DATEDIFF(month,0,DATEADD(mm, -5, GETDATE() )),0) and result in('合格','不合格') ) dd group by 月份,result
select isnull( case when isnull(gg.QtyAll,0) =0 then 0 else Convert(decimal(18,2), (isnull(gg.QtyAll,0)-isnull(FF.QtyNG,0))*1.00/gg.QtyAll*100) end ,0) PercentNum, cc.月份 FROM #TempMonthcc cc left join (select sum(qty) QtyAll,月份 from #TempIPPCC hh group by 月份 ) GG on cc.月份=gg.月份 left join (select isnull(sum(qty),0) QtyNG,月份 from #TempIPPCC hh where result='不合格' group by 月份 ) ff on cc.月份=ff.月份 ORDER BY cc.月份 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIPPCC')) drop table #TempIPPCC if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMonthcc')) drop table #TempMonthcc ";
DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
return dt; }
public DataTable GetZhiXing_RCVUnInWare() {
string SqlText = "";
SqlText = @"
select A.CCODE 到货单号, B.LOTNO,a.cInvCode as 物料编码,C.INVSTD 规格型号,C.INVNAME 物料名称,b.transno 采购订单号, A.iQuantity AS 数量,A.STNO 送货单号 ,CONVERT(varchar(100), a.MTime, 23) MTime , 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,'') 检验人 from ICSPOArrive a with(nolock) inner join icsitemlot b with(nolock) on a.LOTNO=b.LotNO LEFT JOIN ICSINVENTORY C with(nolock) ON C.INVCODE = A.cInvCode where EXISTS(select 1 from ICSOQCLotNo d with(nolock) where D.CCODE=a.cCode and d.InvCode=a.cInvCode and result='合格' ) and not EXISTS(select 1 from ICSWareHouseLotInfoLog ll with(nolock) where ll.lotno=a.lotno and ll.TransType='收') order by A.CCODE,a.cInvCode,B.LOTNO ";
DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
return dt; }
public DataTable GetOtherData() {
string SqlText = "";
SqlText = @"
if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Tcustttemp1')) drop table #Tcustttemp1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Tcusttfilter')) drop table #Tcusttfilter if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TcusttDJ')) drop table #TcusttDJ if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Tcustt_TOCKQty')) drop table #Tcustt_TOCKQty
--用途程表关联wip表拼出所有的检验数据 select a.ITEMCODE,a.ROUTECODE,a.OPCODE, a.OPType AS OPTIONALOP, a.OPControlSeq,b.LOTNO, isnull(b.ACTIONRESULT,'~') as ACTIONRESULT,b.MOCODE,b.MOSEQ,d.molotcode into #Tcustttemp1 from ICSITEMROUTE2OPLot a with(nolock) left join icslotonwip b with(nolock) on a.ITEMCODE = b.ITEMCODE and a.ROUTECODE = b.ROUTECODE and a.OPCODE = b.OPCODE inner join (SELECT distinct a.ITEMCODE,a.ROUTECODE from ICSITEMROUTE2OPLot a with(nolock) left join icslotonwip b with(nolock) on a.ITEMCODE = b.ITEMCODE and a.ROUTECODE = b.ROUTECODE and a.OPCODE = b.OPCODE WHERE b.ACTIONRESULT is not null ) c on a.ITEMCODE = c.ITEMCODE and a.ROUTECODE = c.ROUTECODE
left join icsmo d with(nolock) on d.MOCODE = b.MOCODE and b.SEQ = d.MOSEQ order by ITEMCODE,OPControlSeq --把wip表里有在开工的排除 select ITEMCODE,ROUTECODE,ACTIONRESULT into #Tcusttfilter from icslotonwip with(nolock) group by ITEMCODE,ROUTECODE,ACTIONRESULT HAVING COUNT(ITEMCODE) = 1 and COUNT(ROUTECODE)=1 --找出待检的工序 select ITEMCODE,a.ROUTECODE,OPCODE,c.MOCODE,c.MOSEQ,c.LOTNO into #TcusttDJ from #Tcustttemp1 a inner join (select min(OPControlSeq) OPControlSeq,ROUTECODE from #Tcustttemp1 where OPTIONALOP = '检验工序' and LOTNO is null--最小未检前一道结束的 and ROUTECODE in (select ROUTECODE from (select max(a.OPControlSeq) OPControlSeq,a.ROUTECODE from #Tcustttemp1 a inner join (select min(OPControlSeq) OPControlSeq,ROUTECODE from #Tcustttemp1 where OPTIONALOP = '检验工序' and LOTNO is null group by ROUTECODE) b on a.ROUTECODE = b.ROUTECODE and b.OPControlSeq >a.OPControlSeq and a.ACTIONRESULT = 'COLLECT_END' group by a.ROUTECODE) a ) GROUP BY ROUTECODE) b on a.ROUTECODE = b.ROUTECODE and a.OPControlSeq = b.OPControlSeq inner join ( select distinct mocode,MOSEQ,ROUTECODE,LOTNO from icslotonwip with(nolock) ) c on a.ROUTECODE =c.ROUTECODE where not EXISTS( select 1 from #Tcusttfilter f where f.ITEMCODE=a.ITEMCODE and f.ROUTECODE =a.ROUTECODE ) --将数据拼接成在检和待检两部分
--1、待检验数据 待检车辆 select count(1) Qty into #Tcustt_TOCKQty from ( select b.molotCode [销售车号] -- , dj.LOTNO [产品跟踪单], dj.OPCODE [工序代码] from #TcusttDJ dj inner join #Tcustttemp1 a on dj.ROUTECODE = a.ROUTECODE and a.OPCODE = dj.OPCODE and optionalop ='检验工序' inner join icsmo b with(nolock) on dj.MOCODE = b.MOCODE and dj.MOSEQ = b.MOSEQ inner join ICSMO2user d with(nolock) on b.mocode = d.mocode and b.moseq = d.moseq and d.opcode = dj.OPCODE union select c.molotCode [销售车号] --, d.LOTNO [产品跟踪单], d.OPCODE [工序代码] from (select * from ICSITEMROUTE2OP with(nolock) where optionalop ='检验工序' and routecode in( select DISTINCT routecode from ICSITEMROUTE2OP with(nolock) GROUP BY routecode HAVING count(*) = 1 )) a --查询只有一道工序的工艺路线 inner JOIN ICSMO2ROUTE b with(nolock) on a.routeid = b.routeid inner join ICSMO c with(nolock) on c.id = b.moid inner join ICSMO2user d with(nolock) on c.mocode = d.mocode and c.moseq = d.moseq inner join ICSITEMROUTE2OPLot lot with(nolock) on lot.itemcode = a.ITEMCODE and b.ROUTECODE = lot.ROUTECODE and lot.OPCODE = d.opcode 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') ) jj
--1、已检验数据 已检车辆 select count(1) Qty into #Tcustt_CKQty from ( SELECT distinct mm.molotcode 销售车号--,b.LOTNO,a.OPCODE from ICSQualityCKDATA a with(nolock) LEFT JOIN ICSQualityCKDATADetail b with(nolock) on a.LOTNO=b.LOTNO and a.ID=b.DATAID LEFT JOIN ICSLOTONWIP d with(nolock) on d.LotNo=a.LOTNO and d.opcode=a.OPCODE LEFT JOIN icsmo mm with(nolock) on mm.MOCODE =d.MOCODE and mm.MOSEQ=d.MOSEQ LEFT JOIN ICSITEMROUTE2OPLot ll with(nolock) on ll.OPCODE=a.OPCODE and ll.LotNo=a.LOTNO WHERE ll.OPType='检验工序' and b.MTIME>= CONVERT(varchar(7), dateadd(mm,-1,getdate()), 21) +'-01 00:00:00' and b.CKRESULT is not null ) jj select isnull((select Qty from #Tcustt_TOCKQty ),0) 待检车辆, isnull((select Qty from #Tcustt_CKQty ),0) 已检车辆, isnull((select count(1) from ICSZXCheck with(nolock) where checked='0'),0) 待整改, isnull((select count(1) from ICSZXCheck with(nolock) where checked='1' and month>= CONVERT(varchar(7), dateadd(mm,-1,getdate()), 21) +'-01' ),0) 已整改
if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Tcustttemp1')) drop table #Tcustttemp1 if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Tcusttfilter')) drop table #Tcusttfilter if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TcusttDJ')) drop table #TcusttDJ if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Tcustt_TOCKQty')) drop table #Tcustt_TOCKQty ";
DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
return dt; }
public DataTable GetCKData() {
string SqlText = "";
SqlText = @"
SELECT TOP 100 mm.molotcode 销售车号,yy.INVNAME 部件名称, b.MUSERName 人员, pp.CKGROUPDESC 项目, CONVERT(varchar(16), b.MTIME, 120) as 时间, b.Type 类型 , CASE when b.CKRESULT ='1' then '合格' when b.CKRESULT ='0' then '不合格' end as '结果' from ICSQualityCKDATA a with(nolock) LEFT JOIN ICSQualityCKDATADetail b with(nolock) on a.LOTNO=b.LOTNO and a.ID=b.DATAID LEFT JOIN ICSLOTONWIP d with(nolock) on d.LotNo=a.LOTNO and d.opcode=a.OPCODE 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 LEFT JOIN icsmo mm with(nolock) on mm.MOCODE =d.MOCODE and mm.MOSEQ=d.MOSEQ -- LEFT JOIN ICSMO2ROUTE tt on tt.mocode=mm.mocode and tt.EATTRIBUTE1=mm.MOSEQ LEFT JOIN ICSINVENTORY yy with(nolock) on yy.INVCODE=mm.ITEMCODE LEFT JOIN ICSITEMROUTE2OPLot ll with(nolock) on ll.OPCODE=a.OPCODE and ll.LotNo=a.LOTNO LEFT JOIN ICSOQCCKGROUP pp with(nolock) on pp.CKGROUP=qq.CKGROUPCode -- LEFT JOIN ICSECS sss on sss.ecscode=b.CKvalue -- LEFT JOIN ICSECS s1 on s1.ecscode=b.CKvalue2 -- LEFT JOIN ICSECS s2 on s2.ecscode=b.CKvalue3 -- LEFT JOIN ICSECS s3 on s3.ecscode=b.CKvalue4 -- LEFT JOIN ICSECS s4 on s4.ecscode=b.CKvalue5 -- LEFT JOIN ICSECS s5 on s5.ecscode=b.CKvalue6 WHERE ll.OPType='检验工序' and 1=1 ORDER BY b.MTIME desc ";
DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
return dt; }
public DataTable GetCKOKRate() {
string SqlText = "";
SqlText = @"
if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Tcustccff')) drop table #Tcustccff select convert(varchar(7),DATEADD(month,number*-1,getdate()) ,120) AS 月份,number into #Tcustccff from master.dbo.spt_values where type='p' AND number<=5 and number>=0 order by 1
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 from #Tcustccff ff left join ( SELECT distinct mm.molotcode 销售车号,b.LOTNO,a.OPCODE, CASE when b.CKRESULT ='1' then 1 when b.CKRESULT ='0' then 0 end as 合格, CONVERT(varchar(7), b.MTIME,21) 月份 from ICSQualityCKDATA a with(nolock) LEFT JOIN ICSQualityCKDATADetail b with(nolock) on a.LOTNO=b.LOTNO and a.ID=b.DATAID LEFT JOIN ICSLOTONWIP d with(nolock) on d.LotNo=a.LOTNO and d.opcode=a.OPCODE LEFT JOIN icsmo mm with(nolock) on mm.MOCODE =d.MOCODE and mm.MOSEQ=d.MOSEQ LEFT JOIN ICSITEMROUTE2OPLot ll with(nolock) on ll.OPCODE=a.OPCODE and ll.LotNo=a.LOTNO WHERE ll.OPType='检验工序' and b.MTIME>= CONVERT(varchar(7), dateadd(mm,-6,getdate()), 21) +'-01 00:00:00' and b.CKRESULT is not null ) jj on ff.月份=jj.月份 group by ff.月份,ff.number order by ff.number desc if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#Tcustccff')) drop table #Tcustccff ";
DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
return dt; }
public DataTable GetCKOKRateALL() {
string SqlText = "";
SqlText = @"
select Convert(decimal(18,0),isnull(case when isnull(count(1),0)=0 then 0 else sum(合格)*1.0000/count(1) end,0)) Qty from ( SELECT distinct mm.molotcode 销售车号,b.LOTNO,a.OPCODE, CASE when b.CKRESULT ='1' then 1 when b.CKRESULT ='0' then 0 end as 合格, CONVERT(varchar(7), b.MTIME,21) 月份 from ICSQualityCKDATA a with(nolock) LEFT JOIN ICSQualityCKDATADetail b with(nolock) on a.LOTNO=b.LOTNO and a.ID=b.DATAID LEFT JOIN ICSLOTONWIP d with(nolock) on d.LotNo=a.LOTNO and d.opcode=a.OPCODE LEFT JOIN icsmo mm with(nolock) on mm.MOCODE =d.MOCODE and mm.MOSEQ=d.MOSEQ LEFT JOIN ICSITEMROUTE2OPLot ll with(nolock) on ll.OPCODE=a.OPCODE and ll.LotNo=a.LOTNO WHERE ll.OPType='检验工序' and b.CKRESULT is not null ) jj ";
DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "MESconnstr", null);
return dt; }
}}
|