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.
7173 lines
329 KiB
7173 lines
329 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using Dapper;
|
|
using Warehouse.DAL.Report;
|
|
|
|
namespace JHReport.DAL
|
|
{
|
|
public class ReportDal
|
|
{
|
|
static DbUtility dbhelp = new DbUtility(System.Configuration.ConfigurationManager.ConnectionStrings["mesConn"].ToString(), DbProviderType.SqlServer);
|
|
|
|
#region 晶科报表
|
|
|
|
public DataTable JKQueryInfo(string salesorder, string lot)
|
|
{
|
|
|
|
return dbhelp.ExecuteDataTable(JKSql(salesorder, lot), null);
|
|
}
|
|
|
|
public IEnumerable<dynamic> JKQueryInfoAPI(string salesorder, string lot)
|
|
{
|
|
IEnumerable<dynamic> res = null;
|
|
using (var conn = Dpperhelper.OpenSqlConnection())
|
|
{
|
|
res = conn.Query(JKSql(salesorder, lot));
|
|
}
|
|
return res;
|
|
}
|
|
|
|
private string JKSql(string salesorder, string lot)
|
|
{
|
|
string sql = @"SELECT
|
|
convert(varchar(100), iv.[wks_visit_date],120) AS TTIME,
|
|
ast.[serial_nbr] AS LOT_NUM,
|
|
wm.[sale_order] AS WORK_ORDER_NO,
|
|
iv.[wks_id] AS DEVICENUM,
|
|
iv.[surf_temp] AS AMBIENTTEMP,
|
|
iv.[Sun_Ref] AS INTENSITY, -- iv.[SunRef]
|
|
left(cast(iv.FF as DECIMAL(18,6) ) , charindex('.',cast(iv.ff as DECIMAL(18,6) )) + 2) AS FF,
|
|
left(cast(iv.eff as DECIMAL(18,6) ) , charindex('.',cast(iv.eff as DECIMAL(18,6) )) + 2) AS EFF,
|
|
left(cast(iv.pmax as DECIMAL(18,6) ) , charindex('.',cast(iv.pmax as DECIMAL(18,6) )) + 2) AS PM,
|
|
left(cast(iv.isc as DECIMAL(18,6) ) , charindex('.',cast(iv.isc as DECIMAL(18,6) )) + 2) AS ISC,
|
|
left(cast(iv.ipm as DECIMAL(18,6) ) , charindex('.',cast(iv.ipm as DECIMAL(18,6) )) + 2) AS IPM,
|
|
left(cast(iv.voc as DECIMAL(18,6) ) , charindex('.',cast(iv.voc as DECIMAL(18,6) )) + 2) AS VOC,
|
|
left(cast(iv.vpm as DECIMAL(18,6) ) , charindex('.',cast(iv.vpm as DECIMAL(18,6) )) + 2) AS VPM,
|
|
iv.[surf_temp] AS SENSORTEMP,
|
|
left(cast(iv.rs as DECIMAL(18,6) ) , charindex('.',cast(iv.rs as DECIMAL(18,6) )) + 2) AS RS,
|
|
left(cast(iv.rsh as DECIMAL(18,6) ) , charindex('.',cast(iv.rsh as DECIMAL(18,6) )) + 2) AS RSH,
|
|
iv.[temp] AS TEMP,
|
|
iv.[ivfile_path],
|
|
ms.[descriptions] AS SUPPLIER_NAME,
|
|
[cell_uop] AS 电池单片功率
|
|
,
|
|
iv.[pmax] / (
|
|
CAST ( REPLACE( cp.[cell_qty], 'W', '' ) AS FLOAT ) * CAST ( REPLACE( [cell_uop], 'W', '' ) AS FLOAT )) AS DEC_CTM --CTM=测试功率/(单片功率X电池片数量)
|
|
,
|
|
'' AS VC_CELLEFF,
|
|
'' AS RESULT,
|
|
'' AS TYPE,
|
|
'' AS IV_TEST_KEY,
|
|
'' AS PALLET_NO,
|
|
'' AS PRO_LEVEL,
|
|
'' AS CIR_NO,
|
|
'' AS SALE_ORDER_NO
|
|
FROM
|
|
[mes_main].[dbo].[assembly_status] ast
|
|
LEFT JOIN [mes_level2_iface].[dbo].[iv] iv ON ast.[serial_nbr] = iv.[serial_nbr]
|
|
LEFT JOIN [mes_main].[dbo].[pack_pallets] ppk ON ast.[pallet_nbr] = ppk.[pallet_nbr]
|
|
LEFT JOIN [mes_main].[dbo].[df_pallet_status] dps ON ppk.[pallet_status] = dps.[pallet_status]
|
|
LEFT JOIN [mes_main].[dbo].[df_shift_type] dst ON ppk.[shift_type] = dst.[shift_type]
|
|
LEFT JOIN [mes_main].[dbo].[config_power_group] cpp ON ppk.[power_grade_group_id] = cpp.[power_grade_group_id]
|
|
LEFT JOIN [mes_main].[dbo].[assembly_basis] ab ON ast.[serial_nbr] = ab.[serial_nbr]
|
|
LEFT JOIN [mes_main].[dbo].[config_mat_cell] cmc ON ab.[cell_part_nbr] = cmc.[part_nbr]
|
|
LEFT JOIN [mes_level4_iface].[dbo].[master_supplier] ms ON ab.[cell_supplier_code] = ms.[supplier_code]
|
|
LEFT JOIN [mes_main].[dbo].[config_products] cp ON ab.[product_code] = cp.[product_code]
|
|
LEFT JOIN [mes_main].[dbo].[wo_mfg] wm ON ast.[workorder] = wm.[workorder]
|
|
LEFT JOIN [mes_main].[dbo].[config_mat_eva] cmeva ON ab.[eva_part_nbr] = cmeva.[part_nbr]
|
|
LEFT JOIN [mes_main].[dbo].[config_mat_bks] cmbks ON ab.[cell_part_nbr] = cmbks.[part_nbr]
|
|
LEFT JOIN [mes_main].[dbo].[config_mat_glass] cmglass ON ab.glass_part_nbr= cmglass.part_nbr
|
|
LEFT JOIN [mes_main].[dbo].[config_mat_frame] cmframe ON ab.frame_part_nbr= cmframe.part_nbr
|
|
LEFT JOIN [mes_main].[dbo].[config_mat_jbox] cmjbox ON ab.jbox_part_nbr= cmjbox.part_nbr
|
|
WHERE 1=1 ";
|
|
sql += String.IsNullOrEmpty(lot) ? "" : " and iv.[serial_nbr] = '" + lot + "'";
|
|
sql += String.IsNullOrEmpty(salesorder) ? "" : " and wm.[sale_order] = '" + salesorder + "'";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
#region 测试数据明细
|
|
public DataTable TestDataDetailQueryInfo(string lot, string wo, string bt, string et, string workshop, string pallet_nb, string sale_order, string containerno, string check_nbr)
|
|
{
|
|
return dbhelp.ExecuteDataTable(TestDataDetailSql(lot, wo, bt, et, workshop, pallet_nb, sale_order, containerno, check_nbr), null);
|
|
}
|
|
|
|
|
|
|
|
|
|
internal IEnumerable<dynamic> TestDataDetailQueryInfo(string lot)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
//(旧版本)
|
|
private string TestDataDetail2Sql(string lot, string wo, string bt, string et, string workshop, string pallet_nbr, string sale_order, string containerno, string check_nbr)
|
|
{
|
|
string strwhere = "";
|
|
|
|
if (!string.IsNullOrEmpty(bt.ToString()))
|
|
{
|
|
strwhere += "and iv.wks_visit_date >= '" + Convert.ToString(bt) + "'";
|
|
strwhere += "and iv.wks_visit_date <= '" + Convert.ToString(et) + "'";
|
|
}
|
|
strwhere += String.IsNullOrEmpty(workshop.ToString()) ? "" : " and wm.area_code LIKE '" + Convert.ToString(workshop) + "%'";
|
|
strwhere += String.IsNullOrEmpty(wo.ToString()) ? "" : " AND wm.workorder = '" + Convert.ToString(wo) + "'";
|
|
strwhere += String.IsNullOrEmpty(lot.ToString()) ? "" : " AND iv.serial_nbr = '" + Convert.ToString(lot) + "'";
|
|
strwhere += String.IsNullOrEmpty(pallet_nbr.ToString()) ? "" : " AND bz.pallet_nbr = '" + Convert.ToString(pallet_nbr) + "'";
|
|
|
|
strwhere += String.IsNullOrEmpty(sale_order) ? "" : " AND wm.sale_order = '" + Convert.ToString(sale_order) + "'";
|
|
strwhere += String.IsNullOrEmpty(containerno) ? "" : " and pg.containerno = '" + Convert.ToString(containerno) + "'";
|
|
strwhere += String.IsNullOrEmpty(check_nbr) ? "" : " and BZ.check_nbr = '" + Convert.ToString(check_nbr) + "'";
|
|
|
|
string sql = @"select a.[product_code]/*组件类型*/
|
|
,a.power_grade/*功率档位*/
|
|
,convert(varchar(100),a.[wks_visit_date],120) as wks_visit_date/*测试时间*/
|
|
,a.[wks_id]/*机台号*/
|
|
,a.containerno/*柜号*/
|
|
,a.pallet_nbr/*托盘号*/
|
|
,a.[serial_nbr] /*组件序列号*/
|
|
,a.pmax
|
|
,a.[isc]
|
|
,a.voc
|
|
,a.[ipm]
|
|
,a.vpm
|
|
,a.[ff]
|
|
,a.current_grade/*电流档位*/
|
|
,a.[workorder] as workorder/*工单号*/
|
|
,a.cell_uop/*电池片功率*/
|
|
,a.cell_eff/*电池片效率*/
|
|
--,a.[ipm]
|
|
,a.[rs]
|
|
,a.[rsh]
|
|
,a.[eff]
|
|
,a.[env_temp]
|
|
,a.[surf_temp]
|
|
,a.[temp]
|
|
,a.[ivfile_path]
|
|
,a.[cell_part_nbr]/*电池料号*/
|
|
,a.[cell_lot_nbr]/*电池批号*/
|
|
,a.[cell_supplier_code]/*电池供应商*/
|
|
,a.[glass_part_nbr]/*玻璃料号*/
|
|
,a.[glass_supplier_code]/*玻璃供应商*/
|
|
,a.[glass_lot_nbr]/*电池批号*/
|
|
,a.[eva_part_nbr]/*EVA料号*/
|
|
,a.[eva_supplier_code]/*EVA供应商*/
|
|
,a.[eva_lot_nbr]/*EVA批号*/
|
|
,a.[bks_part_nbr]/*背板料号*/
|
|
,a.[bks_supplier_code]/*背板供应商*/
|
|
,a.[bks_lot_nbr]/*背板批号*/
|
|
,a.[frame_part_nbr]/*型材料号*/
|
|
,a.[frame_supplier_code]/*型材供应商*/
|
|
,a.[frame_lot_nbr]/*型材批号*/
|
|
,a.[jbox_part_nbr]/*接线盒料号*/
|
|
,a.[jbox_supplier_code]/*接线盒供应商*/
|
|
,a.[jbox_lot_nbr]/*接线盒批号*/
|
|
,a.[huiliu_part_nbr]
|
|
,a.[huiliu_supplier_code]
|
|
,a.[huiliu_lot_nbr]
|
|
,a.[hulian_part_nbr]
|
|
,a.[hulian_supplier_code]
|
|
,a.[hulian_lot_nbr]
|
|
,a.el_grade
|
|
,a.DPGL
|
|
,a.cell_qty
|
|
,a.EDGL
|
|
,cast(convert(DECIMAL(18,2),a.pmax/a.EDGL*100) as varchar)+'%' as CTM
|
|
from (select
|
|
ab.[product_code]/*组件类型*/
|
|
,sm.power_grade/*功率档位*/
|
|
,convert(varchar(100),iv.[wks_visit_date],120) as wks_visit_date/*测试时间*/
|
|
,iv.[wks_id]/*机台号*/
|
|
,pg.containerno/*柜号*/
|
|
,BZ.pallet_nbr/*托盘号*/
|
|
,iv.[serial_nbr] /*组件序列号*/
|
|
,iv.[voc]
|
|
,iv.[isc]
|
|
,iv.[vpm]
|
|
,iv.[ipm]
|
|
,iv.[pmax]
|
|
,iv.[ff]
|
|
,sm.current_grade/*电流档位*/
|
|
,ab.[workorder] as workorder/*工单号*/
|
|
,cmc.cell_uop/*电池片功率*/
|
|
,cmc.cell_eff/*电池片效率*/
|
|
--,iv.[ipm]
|
|
,iv.[rs]
|
|
,iv.[rsh]
|
|
,iv.[eff]
|
|
,iv.[env_temp]
|
|
,iv.[surf_temp]
|
|
,iv.[temp]
|
|
,iv.[ivfile_path]
|
|
,ab.[cell_part_nbr]/*电池料号*/
|
|
,ab.[cell_lot_nbr]/*电池批号*/
|
|
,ab.[cell_supplier_code]/*电池供应商*/
|
|
,ab.[glass_part_nbr]/*玻璃料号*/
|
|
,ab.[glass_supplier_code]/*玻璃供应商*/
|
|
,ab.[glass_lot_nbr]/*电池批号*/
|
|
,ab.[eva_part_nbr]/*EVA料号*/
|
|
,ab.[eva_supplier_code]/*EVA供应商*/
|
|
,ab.[eva_lot_nbr]/*EVA批号*/
|
|
,ab.[bks_part_nbr]/*背板料号*/
|
|
,ab.[bks_supplier_code]/*背板供应商*/
|
|
,ab.[bks_lot_nbr]/*背板批号*/
|
|
,ab.[frame_part_nbr]/*型材料号*/
|
|
,ab.[frame_supplier_code]/*型材供应商*/
|
|
,ab.[frame_lot_nbr]/*型材批号*/
|
|
,ab.[jbox_part_nbr]/*接线盒料号*/
|
|
,ab.[jbox_supplier_code]/*接线盒供应商*/
|
|
,ab.[jbox_lot_nbr]/*接线盒批号*/
|
|
,ab.[huiliu_part_nbr]
|
|
,ab.[huiliu_supplier_code]
|
|
,ab.[huiliu_lot_nbr]
|
|
,ab.[hulian_part_nbr]
|
|
,ab.[hulian_supplier_code]
|
|
,ab.[hulian_lot_nbr]
|
|
,sm.el_grade
|
|
,SUBSTRING(part.descriptions,dbo.fn_find('_',part.descriptions,5)+1,
|
|
case
|
|
when dbo.fn_find('_',part.descriptions,6)-dbo.fn_find('_',part.descriptions,5) >0 then dbo.fn_find('_',part.descriptions,6)-dbo.fn_find('_',part.descriptions,5)-2
|
|
else 0
|
|
end) as DPGL
|
|
,wm.cell_qty
|
|
,CONVERT(decimal(10,2),SUBSTRING(part.descriptions,dbo.fn_find('_',part.descriptions,5)+1,
|
|
case
|
|
when dbo.fn_find('_',part.descriptions,6)-dbo.fn_find('_',part.descriptions,5) >0 then dbo.fn_find('_',part.descriptions,6)-dbo.fn_find('_',part.descriptions,5)-2
|
|
else 0
|
|
end))*CONVERT(int,wm.cell_qty) as EDGL
|
|
from mes_level2_iface.dbo.iv iv
|
|
inner join [mes_main].[dbo].[assembly_status] sm on iv.serial_nbr = sm.serial_nbr
|
|
inner join [mes_main].[dbo].[wo_mfg] wm on sm.workorder = wm.workorder
|
|
left join [mes_main].[dbo].[assembly_basis] ab on ab.serial_nbr=sm.serial_nbr
|
|
left join [mes_main].[dbo].[config_mat_cell]cmc on ab.cell_part_nbr=cmc.[part_nbr]
|
|
left join [mes_main].[dbo].[pack_pallets] BZ on BZ.pallet_nbr = SM.pallet_nbr
|
|
left join [wh].[dbo].[tcontainerpallet] PG ON PG.palletno = bz.pallet_nbr
|
|
left join mes_level4_iface.dbo.master_part part on ab.cell_part_nbr = part.bom_part_nbr
|
|
where 1=1 " + strwhere + @"
|
|
)a
|
|
order by right(a.pallet_nbr,2)";
|
|
|
|
|
|
|
|
|
|
return sql;
|
|
}
|
|
|
|
|
|
//(山东客户版本)
|
|
private string TestDataDetailSql(string lot, string wo, string bt, string et, string workshop, string pallet_nbr, string sale_order, string containerno, string check_nbr)
|
|
{
|
|
string strwhere = "";
|
|
|
|
if (!string.IsNullOrEmpty(bt.ToString()))
|
|
{
|
|
strwhere += "and iv.wks_visit_date >= '" + Convert.ToString(bt) + "'";
|
|
strwhere += "and iv.wks_visit_date <= '" + Convert.ToString(et) + "'";
|
|
}
|
|
strwhere += String.IsNullOrEmpty(workshop) ? "" : " and wm.area_code LIKE '" + Convert.ToString(workshop) + "%'";
|
|
strwhere += String.IsNullOrEmpty(wo) ? "" : " AND wm.workorder = '" + Convert.ToString(wo) + "'";
|
|
strwhere += String.IsNullOrEmpty(lot) ? "" : " AND ast.serial_nbr in (" + Convert.ToString(lot) + ")";
|
|
strwhere += String.IsNullOrEmpty(pallet_nbr) ? "" : " AND ppk.pallet_nbr = '" + Convert.ToString(pallet_nbr) + "'";
|
|
////
|
|
strwhere += String.IsNullOrEmpty(sale_order) ? "" : " AND wm.sale_order = '" + Convert.ToString(sale_order) + "'";
|
|
strwhere += String.IsNullOrEmpty(containerno) ? "" : " and pg.containerno = '" + Convert.ToString(containerno) + "'";
|
|
strwhere += String.IsNullOrEmpty(check_nbr) ? "" : " and ppk.check_nbr = '" + Convert.ToString(check_nbr) + "'";
|
|
|
|
string sql = @"SELECT
|
|
wh.containerno as container_nbr/*柜号*/
|
|
,ast.[pallet_nbr]/*托盘编码*/
|
|
,ast.[pack_seq]/*包装顺序*/
|
|
,ast.[workorder]/*工单号*/
|
|
,wm.sale_order
|
|
,ast.[serial_nbr] /*组件序列号*/
|
|
--,CONVERT(varchar(100), ppk.[pack_date], 120) as pack_date/*封箱时间*/
|
|
,CONVERT(varchar(100),iv.wks_visit_date, 120) as wks_visit_date /*测试时间*/
|
|
,iv.wks_id/*测试机台*/
|
|
,ast.[power_grade]/*功率档位*/
|
|
,ast.current_grade/*电流档位*/
|
|
--,ast.[product_code]/*装配件号*/
|
|
,ast.[el_grade]/*EL等级*/
|
|
,ast.exterior_grade/*外观等级*/
|
|
,ast.[final_grade]/*最终等级*/
|
|
--,cpp.[descriptions]/*功率组*/
|
|
--,dst.[descriptions] shift_type/*班次*/
|
|
,iv.[voc] voc
|
|
,iv.[isc] isc
|
|
,iv.[pmax] pmax
|
|
,iv.[vpm] vpm
|
|
,iv.[ipm] ipm
|
|
,cast(substring(cast(iv.[ff]*100.00 as varchar(100)),1,charindex('.',iv.[ff]*100.00)+2) as float) as ff
|
|
,iv.[rs] rs
|
|
,iv.[rsh] rsh
|
|
,iv.[eff] eff
|
|
--,cast(iv.[eff] as numeric(18,2)) eff
|
|
,iv.[env_temp] env_temp
|
|
--,cast(iv.[surf_temp] as numeric(18,2)) surf_temp
|
|
--,cast(iv.[temp] as numeric(18,2)) temp
|
|
--,cast(iv.[ivfile_path] as numeric(18,2)) ivfile_path
|
|
,iv.[surf_temp] tmod
|
|
,ms.[descriptions] as cell_supplier/*电池片供应商*/
|
|
--,ppk.[check_nbr]
|
|
,case when cmc.attr_code = 'cell_uop' then cmc.attr_value end cell_uop/*单片功率*/
|
|
,case when color.attr_code = 'cell_color' then color.attr_value end cell_color/*电池颜色*/
|
|
,case when grade.attr_code = 'cell_grade' then grade.attr_value end cell_grade/*电池片等级*/
|
|
,case when type.attr_code = 'cell_type' then type.attr_value end cell_type/*电池片类型*/
|
|
,case when eff.attr_code = 'cell_eff' then eff.attr_value end cell_eff/*电池片效率档*/
|
|
--,cp.[cell_qty]
|
|
--,ppk.container_nbr as batch
|
|
,dps.[pallet_status_desc]/*托盘状态*/
|
|
,wm.cell_qty
|
|
,CONVERT(numeric(18,2),wm.cell_qty)* cast(
|
|
case when right(cmc.attr_value,1)='W' THEN left(cmc.attr_value,LEN(cmc.attr_value)-1)
|
|
else cmc.attr_value
|
|
end
|
|
as float) EDGL
|
|
,isnull(cast(cast(iv.[pmax]/NULLIF(cast(CONVERT(numeric(18,2),wm.cell_qty)* cast(
|
|
case when right(cmc.attr_value,1)='W' THEN left(cmc.attr_value,LEN(cmc.attr_value)-1)
|
|
else cmc.attr_value
|
|
end
|
|
as float) as FLOAT),0)*100 as numeric(18,2)) as varchar(50)),0)+'%' fff /*投入产出比*/
|
|
,case when cmc.attr_code = 'crys_type' then cmc.attr_value end crys_type/*电池片类型*/
|
|
,case when cmc.attr_code = 'cell_size' then cmc.attr_value end cell_size/*电池片效率档*/
|
|
--,CONVERT(int,wm.cell_qty)
|
|
,a.[wks_id] hj_wks_id
|
|
FROM[mes_main].[dbo].[assembly_status]
|
|
ast
|
|
left join[mes_level2_iface].[dbo].[iv]
|
|
iv
|
|
on ast.[serial_nbr]=iv.[serial_nbr]
|
|
left join[mes_main].[dbo].[pack_pallets]
|
|
ppk
|
|
on ast.[pallet_nbr]=ppk.[pallet_nbr]
|
|
left join[mes_main].[dbo].[df_pallet_status]
|
|
dps
|
|
on ppk.[pallet_status]=dps.[pallet_status]
|
|
left join[mes_main].[dbo].[df_shift_type]
|
|
dst
|
|
on ppk.[shift_type]=dst.[shift_type]
|
|
left join[mes_main].[dbo].[config_power_group]
|
|
cpp
|
|
on ppk.[power_grade_group_id]=cpp.[power_grade_group_id]
|
|
LEFT join mes_main.dbo.trace_componnet_lot
|
|
ab
|
|
on ab.serial_nbr = ast.serial_nbr and ab.part_type = 'CELL'
|
|
--left join[mes_main].[dbo].[assembly_basis]
|
|
-- ab
|
|
--on ast.[serial_nbr]=ab.[serial_nbr]
|
|
left join[mes_main].[dbo].[config_mat_attr]
|
|
cmc
|
|
on ab.part_nbr=cmc.[part_nbr] and cmc.attr_code = 'cell_uop'
|
|
left join[mes_main].[dbo].[config_mat_attr]
|
|
color
|
|
on ab.part_nbr=color.[part_nbr] and color.attr_code = 'cell_color'
|
|
left join[mes_main].[dbo].[config_mat_attr]
|
|
grade
|
|
on ab.part_nbr=grade.[part_nbr] and grade.attr_code = 'cell_grade'
|
|
left join[mes_main].[dbo].[config_mat_attr]
|
|
type
|
|
on ab.part_nbr=type.[part_nbr] and type.attr_code = 'cell_type'
|
|
left join[mes_main].[dbo].[config_mat_attr]
|
|
eff
|
|
on ab.part_nbr=eff.[part_nbr] and eff.attr_code = 'cell_eff'
|
|
left join[mes_level4_iface].[dbo].[master_supplier]
|
|
ms
|
|
on ab.supplier_code=ms.[supplier_code]
|
|
left join[mes_main].[dbo].[config_products]
|
|
cp
|
|
on ppk.[product_code]=cp.[product_code]
|
|
left join[mes_main].[dbo].[wo_mfg]
|
|
wm
|
|
on ast.[workorder]=wm.[workorder]
|
|
left join [wh].[dbo].[tcontainerpallet]
|
|
PG
|
|
ON PG.palletno = ppk.pallet_nbr
|
|
--left join[mes_main].[dbo].[config_mat_eva]
|
|
--cmeva
|
|
--on ab.[eva_part_nbr]=cmeva.[part_nbr]
|
|
--left join[mes_main].[dbo].[config_mat_bks]
|
|
--cmbks
|
|
--on ab.[cell_part_nbr]=cmbks.[part_nbr]
|
|
--left join[mes_main].[dbo].[config_mat_glass]
|
|
--cmglass
|
|
--on ab.glass_part_nbr=cmglass.part_nbr
|
|
--left join[mes_main].[dbo].[config_mat_frame]
|
|
--cmframe
|
|
--on ab.frame_part_nbr=cmframe.part_nbr
|
|
--left join[mes_main].[dbo].[config_mat_jbox]
|
|
--cmjbox
|
|
--on ab.jbox_part_nbr=cmjbox.part_nbr
|
|
left join wh.dbo.tcontainerpallet wh
|
|
on ast.pallet_nbr =wh.palletno
|
|
left join [mes_main].[dbo].[trace_workstation_visit] a
|
|
on ast.[serial_nbr]=a.[serial_nbr] and a.wks_id like '%HJJ%'
|
|
where 1=1 and iv.[pmax] is not null " + strwhere;
|
|
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
//就将正泰衰减数据
|
|
#region 测试数据明细(衰减数据)
|
|
public DataTable TestDataDetailQueryInfoFake(string lot, string wo, string bt, string et, string workshop, string pallet_nb, string sale_order, string containerno, string check_nbr)
|
|
{
|
|
return dbhelp.ExecuteDataTable(TestDataDetailFakeSql(lot, wo, bt, et, workshop, pallet_nb, sale_order, containerno, check_nbr), null);
|
|
}
|
|
|
|
//internal IEnumerable<dynamic> TestDataDetailQueryInfo(string lot)
|
|
//{
|
|
// throw new NotImplementedException();
|
|
//}
|
|
private string TestDataDetailFakeSql(string lot, string wo, string bt, string et, string workshop, string pallet_nbr, string sale_order, string containerno, string check_nbr)
|
|
{
|
|
string strwhere = "";
|
|
|
|
if (!string.IsNullOrEmpty(bt.ToString()))
|
|
{
|
|
strwhere += "and iv.wks_visit_date >= '" + Convert.ToString(bt) + "'";
|
|
strwhere += "and iv.wks_visit_date <= '" + Convert.ToString(et) + "'";
|
|
}
|
|
strwhere += String.IsNullOrEmpty(workshop.ToString()) ? "" : " and wm.area_code LIKE '" + Convert.ToString(workshop) + "%'";
|
|
strwhere += String.IsNullOrEmpty(wo.ToString()) ? "" : " AND wm.workorder = '" + Convert.ToString(wo) + "'";
|
|
strwhere += String.IsNullOrEmpty(lot.ToString()) ? "" : " AND iv.serial_nbr = '" + Convert.ToString(lot) + "'";
|
|
strwhere += String.IsNullOrEmpty(pallet_nbr.ToString()) ? "" : " AND bz.pallet_nbr = '" + Convert.ToString(pallet_nbr) + "'";
|
|
|
|
strwhere += String.IsNullOrEmpty(sale_order) ? "" : " AND wm.sale_order = '" + Convert.ToString(sale_order) + "'";
|
|
strwhere += String.IsNullOrEmpty(containerno) ? "" : " and pg.containerno = '" + Convert.ToString(containerno) + "'";
|
|
strwhere += String.IsNullOrEmpty(check_nbr) ? "" : " and BZ.check_nbr = '" + Convert.ToString(check_nbr) + "'";
|
|
|
|
string sql = @"select a.[product_code]/*组件类型*/
|
|
,a.power_grade/*功率档位*/
|
|
,convert(varchar(100),a.[wks_visit_date],120) as wks_visit_date/*测试时间*/
|
|
,a.[wks_id]/*机台号*/
|
|
,a.containerno/*柜号*/
|
|
,a.pallet_nbr/*托盘号*/
|
|
,a.[serial_nbr] /*组件序列号*/
|
|
,case
|
|
when a.[pmax] >= 405 and a.pmax < 410 then ROUND(a.pmax,2,1)
|
|
when a.pmax >= 410 and a.pmax < 415 then ROUND(a.pmax*0.9879,2,1)
|
|
when a.pmax >= 415 then ROUND(a.pmax*0.98,2,1)
|
|
end pmax
|
|
,round(a.[isc],2,1) isc
|
|
,case
|
|
when a.[pmax] >= 405 and a.pmax < 410 then ROUND(a.voc,2,1)
|
|
when a.pmax >= 410 and a.pmax < 415 then ROUND(a.voc*0.9879,2,1)
|
|
when a.pmax >= 415 then ROUND(a.voc*0.98,2,1)
|
|
end voc
|
|
,round(a.[ipm],2,1) ipm
|
|
,case
|
|
when a.[pmax] >= 405 and a.pmax < 410 then ROUND(a.vpm,2,1)
|
|
when a.pmax >= 410 and a.pmax < 415 then ROUND(a.vpm*0.9879,2,1)
|
|
when a.pmax >= 415 then ROUND(a.vpm*0.98,2,1)
|
|
end vpm
|
|
,a.[ff]
|
|
,a.current_grade/*电流档位*/
|
|
,a.[workorder] as workorder/*工单号*/
|
|
,a.cell_uop/*电池片功率*/
|
|
,a.cell_eff/*电池片效率*/
|
|
--,a.[ipm]
|
|
,a.[rs]
|
|
,a.[rsh]
|
|
,a.[eff]
|
|
,a.[env_temp]
|
|
,a.[surf_temp]
|
|
,a.[temp]
|
|
,a.[ivfile_path]
|
|
,a.[cell_part_nbr]/*电池料号*/
|
|
,a.[cell_lot_nbr]/*电池批号*/
|
|
,a.[cell_supplier_code]/*电池供应商*/
|
|
,a.[glass_part_nbr]/*玻璃料号*/
|
|
,a.[glass_supplier_code]/*玻璃供应商*/
|
|
,a.[glass_lot_nbr]/*电池批号*/
|
|
,a.[eva_part_nbr]/*EVA料号*/
|
|
,a.[eva_supplier_code]/*EVA供应商*/
|
|
,a.[eva_lot_nbr]/*EVA批号*/
|
|
,a.[bks_part_nbr]/*背板料号*/
|
|
,a.[bks_supplier_code]/*背板供应商*/
|
|
,a.[bks_lot_nbr]/*背板批号*/
|
|
,a.[frame_part_nbr]/*型材料号*/
|
|
,a.[frame_supplier_code]/*型材供应商*/
|
|
,a.[frame_lot_nbr]/*型材批号*/
|
|
,a.[jbox_part_nbr]/*接线盒料号*/
|
|
,a.[jbox_supplier_code]/*接线盒供应商*/
|
|
,a.[jbox_lot_nbr]/*接线盒批号*/
|
|
,a.[huiliu_part_nbr]
|
|
,a.[huiliu_supplier_code]
|
|
,a.[huiliu_lot_nbr]
|
|
,a.[hulian_part_nbr]
|
|
,a.[hulian_supplier_code]
|
|
,a.[hulian_lot_nbr]
|
|
,a.el_grade
|
|
,a.DPGL
|
|
,a.cell_qty
|
|
,a.EDGL
|
|
,cast(convert(DECIMAL(18,2),a.pmax/a.EDGL*100) as varchar)+'%' as CTM
|
|
from (select
|
|
ab.[product_code]/*组件类型*/
|
|
,sm.power_grade/*功率档位*/
|
|
,convert(varchar(100),iv.[wks_visit_date],120) as wks_visit_date/*测试时间*/
|
|
,iv.[wks_id]/*机台号*/
|
|
,pg.containerno/*柜号*/
|
|
,BZ.pallet_nbr/*托盘号*/
|
|
,iv.[serial_nbr] /*组件序列号*/
|
|
,iv.[voc]
|
|
,iv.[isc]
|
|
,iv.[vpm]
|
|
,iv.[ipm]
|
|
,iv.[pmax]
|
|
,iv.[ff]
|
|
,sm.current_grade/*电流档位*/
|
|
,ab.[workorder] as workorder/*工单号*/
|
|
,cmc.cell_uop/*电池片功率*/
|
|
,cmc.cell_eff/*电池片效率*/
|
|
--,iv.[ipm]
|
|
,iv.[rs]
|
|
,iv.[rsh]
|
|
,iv.[eff]
|
|
,iv.[env_temp]
|
|
,iv.[surf_temp]
|
|
,iv.[temp]
|
|
,iv.[ivfile_path]
|
|
,ab.[cell_part_nbr]/*电池料号*/
|
|
,ab.[cell_lot_nbr]/*电池批号*/
|
|
,ab.[cell_supplier_code]/*电池供应商*/
|
|
,ab.[glass_part_nbr]/*玻璃料号*/
|
|
,ab.[glass_supplier_code]/*玻璃供应商*/
|
|
,ab.[glass_lot_nbr]/*电池批号*/
|
|
,ab.[eva_part_nbr]/*EVA料号*/
|
|
,ab.[eva_supplier_code]/*EVA供应商*/
|
|
,ab.[eva_lot_nbr]/*EVA批号*/
|
|
,ab.[bks_part_nbr]/*背板料号*/
|
|
,ab.[bks_supplier_code]/*背板供应商*/
|
|
,ab.[bks_lot_nbr]/*背板批号*/
|
|
,ab.[frame_part_nbr]/*型材料号*/
|
|
,ab.[frame_supplier_code]/*型材供应商*/
|
|
,ab.[frame_lot_nbr]/*型材批号*/
|
|
,ab.[jbox_part_nbr]/*接线盒料号*/
|
|
,ab.[jbox_supplier_code]/*接线盒供应商*/
|
|
,ab.[jbox_lot_nbr]/*接线盒批号*/
|
|
,ab.[huiliu_part_nbr]
|
|
,ab.[huiliu_supplier_code]
|
|
,ab.[huiliu_lot_nbr]
|
|
,ab.[hulian_part_nbr]
|
|
,ab.[hulian_supplier_code]
|
|
,ab.[hulian_lot_nbr]
|
|
,sm.el_grade
|
|
,SUBSTRING(part.descriptions,dbo.fn_find('_',part.descriptions,5)+1,
|
|
case
|
|
when dbo.fn_find('_',part.descriptions,6)-dbo.fn_find('_',part.descriptions,5) >0 then dbo.fn_find('_',part.descriptions,6)-dbo.fn_find('_',part.descriptions,5)-2
|
|
else 0
|
|
end) as DPGL
|
|
,wm.cell_qty
|
|
,CONVERT(decimal(10,2),SUBSTRING(part.descriptions,dbo.fn_find('_',part.descriptions,5)+1,
|
|
case
|
|
when dbo.fn_find('_',part.descriptions,6)-dbo.fn_find('_',part.descriptions,5) >0 then dbo.fn_find('_',part.descriptions,6)-dbo.fn_find('_',part.descriptions,5)-2
|
|
else 0
|
|
end))*CONVERT(int,wm.cell_qty) as EDGL
|
|
from mes_level2_iface.dbo.iv iv
|
|
inner join [mes_main].[dbo].[assembly_status] sm on iv.serial_nbr = sm.serial_nbr
|
|
inner join [mes_main].[dbo].[wo_mfg] wm on sm.workorder = wm.workorder
|
|
left join [mes_main].[dbo].[assembly_basis] ab on ab.serial_nbr=sm.serial_nbr
|
|
left join [mes_main].[dbo].[config_mat_cell]cmc on ab.cell_part_nbr=cmc.[part_nbr]
|
|
left join [mes_main].[dbo].[pack_pallets] BZ on BZ.pallet_nbr = SM.pallet_nbr
|
|
left join [wh].[dbo].[tcontainerpallet] PG ON PG.palletno = bz.pallet_nbr
|
|
left join mes_level4_iface.dbo.master_part part on ab.cell_part_nbr = part.bom_part_nbr
|
|
where 1=1 " + strwhere + @"
|
|
)a
|
|
order by right(a.pallet_nbr,2)";
|
|
|
|
|
|
|
|
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
#region 多次测试明细
|
|
public DataTable MultipleTestDetailQueryInfo(string lot, string wo, string bt, string et, string workshop)
|
|
{
|
|
return dbhelp.ExecuteDataTable(MultipleTestDetailSql(lot, wo, bt, et, workshop), null);
|
|
}
|
|
|
|
internal IEnumerable<dynamic> MultipleTestDetailQueryInfo(string lot)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private string MultipleTestDetailSql(string lot, string wo, string bt, string et, string workshop)
|
|
{
|
|
string sql = @"select
|
|
CONVERT(varchar(100), iv.[wks_visit_date], 120) as wks_visit_date/*测试时间*/
|
|
,iv.[serial_nbr] /*组件序列号*/
|
|
,iv.[wks_id]/*机台号*/
|
|
,ab.[workorder] as workorder/*工单号*/
|
|
,cmc.cell_uop/*电池片功率*/
|
|
,cmc.cell_eff/*电池片效率*/
|
|
,iv.[pmax]
|
|
,iv.[isc]
|
|
,iv.[voc]
|
|
,iv.[ipm]
|
|
,iv.[vpm]
|
|
,iv.[ff]
|
|
,iv.[rs]
|
|
,iv.[rsh]
|
|
,iv.[eff]
|
|
,iv.[env_temp]
|
|
,iv.[surf_temp]
|
|
,iv.[temp]
|
|
,iv.[ivfile_path]
|
|
,ab.[product_code]/*组件类型*/
|
|
,ab.[cell_part_nbr]/*电池料号*/
|
|
,ab.[cell_lot_nbr]/*电池批号*/
|
|
,ab.[cell_supplier_code]/*电池供应商*/
|
|
,ab.[glass_part_nbr]/*玻璃料号*/
|
|
,ab.[glass_supplier_code]/*玻璃供应商*/
|
|
,ab.[glass_lot_nbr]/*电池批号*/
|
|
,ab.[eva_part_nbr]/*EVA料号*/
|
|
,ab.[eva_supplier_code]/*EVA供应商*/
|
|
,ab.[eva_lot_nbr]/*EVA批号*/
|
|
,ab.[bks_part_nbr]/*背板料号*/
|
|
,ab.[bks_supplier_code]/*背板供应商*/
|
|
,ab.[bks_lot_nbr]/*背板批号*/
|
|
,ab.[frame_part_nbr]/*型材料号*/
|
|
,ab.[frame_supplier_code]/*型材供应商*/
|
|
,ab.[frame_lot_nbr]/*型材批号*/
|
|
,ab.[jbox_part_nbr]/*接线盒料号*/
|
|
,ab.[jbox_supplier_code]/*接线盒供应商*/
|
|
,ab.[jbox_lot_nbr]/*接线盒批号*/
|
|
,ab.[huiliu_part_nbr]
|
|
,ab.[huiliu_supplier_code]
|
|
,ab.[huiliu_lot_nbr]
|
|
,ab.[hulian_part_nbr]
|
|
,ab.[hulian_supplier_code]
|
|
,ab.[hulian_lot_nbr]
|
|
,sm.el_grade
|
|
|
|
from mes_level2_iface.dbo.iv_hist iv
|
|
|
|
left join[mes_main].[dbo].[assembly_status] sm on iv.serial_nbr = sm.serial_nbr
|
|
left join mes_main.dbo.wo_mfg wm on sm.workorder = wm.workorder
|
|
|
|
left join [mes_main].[dbo].[assembly_basis] ab on ab.serial_nbr= sm.serial_nbr
|
|
|
|
left join [mes_main].[dbo].[config_mat_cell]cmc on ab.cell_part_nbr= cmc.[part_nbr]
|
|
|
|
where 1=1";
|
|
if (!string.IsNullOrEmpty(bt.ToString()))
|
|
{
|
|
sql += "and iv.wks_visit_date >= '" + Convert.ToString(bt) + "'";
|
|
sql += "and iv.wks_visit_date <= '" + Convert.ToString(et) + "'";
|
|
}
|
|
|
|
sql += String.IsNullOrEmpty(workshop.ToString()) ? "" : " and wm.area_code LIKE '" + Convert.ToString(workshop) + "%'";
|
|
sql += String.IsNullOrEmpty(wo.ToString()) ? "" : " AND wm.workorder = '" + Convert.ToString(wo) + "'";
|
|
sql += String.IsNullOrEmpty(lot.ToString()) ? "" : " AND iv.serial_nbr = '" + Convert.ToString(lot) + "'";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 质量报表
|
|
public DataTable QCQueryInfo(string bt, string et, string lot, string workshop, string workorder, string station)
|
|
{
|
|
return dbhelp.ExecuteDataTable(QCSql(bt, et, lot, workshop, workorder, station), null);
|
|
}
|
|
|
|
//private string QCSql(string bt, string et, string lot, string workshop, string status, string workorder);
|
|
//private string QCSql(string bt, string et, string lot, string workshop, string status, string workorder);
|
|
private string QCSql(string bt, string et, string lot, string workshop, string workorder, string station)
|
|
{
|
|
string strwhere = string.Empty;
|
|
string strwheres = string.Empty;
|
|
if (!string.IsNullOrEmpty(bt.ToString()))
|
|
{
|
|
strwhere += "and alls.create_date >= '" + Convert.ToString(bt) + "'";
|
|
strwhere += "and alls.create_date <= '" + Convert.ToString(et) + "'";
|
|
}
|
|
if (!string.IsNullOrEmpty(lot.ToString()))
|
|
{
|
|
strwhere += " and alls.[serial_nbr] = '" + Convert.ToString(lot) + "'";
|
|
}
|
|
if (!string.IsNullOrEmpty(workshop.ToString()))
|
|
{
|
|
strwhere += " and alls.[area_code] = '" + Convert.ToString(workshop) + "'";
|
|
}
|
|
//if (!string.IsNullOrEmpty(para.status.ToString()))
|
|
//{
|
|
// strwhere += " AND qcv.[visit_type] = '" + Convert.ToString(para.status) + "'";
|
|
//}
|
|
if (!string.IsNullOrEmpty(workorder.ToString()))
|
|
{
|
|
strwhere += " AND alls.schedule_nbr = '" + Convert.ToString(workorder) + "'";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(station.ToString()))
|
|
{
|
|
strwheres += " AND e.process_code = '" + Convert.ToString(station) + "'";
|
|
}
|
|
string sql = @"select distinct alls.serial_nbr,alls.sale_order,alls.schedule_nbr,alls.dqstatus,alls.final_grade
|
|
,code.process_code_desc,defecttype.defect_type_name,defectposition.defect_position
|
|
,remark.remark,accord.according_std
|
|
,hold.serial_status hstatus,hold.hperson,CONVERT(varchar(100), hold.htime, 120) as htime
|
|
,qcv.serial_status rstatus,qcv.operator rperson,CONVERT(varchar(100), pend.rtime, 120) as rtime
|
|
from ( select a.serial_nbr,b.sale_order,a.schedule_nbr,c.serial_status dqstatus,c.final_grade,a.create_date,b.area_code
|
|
FROM [mes_main].[dbo].[qc_visit] a
|
|
left join mes_main.dbo.wo_mfg b
|
|
on a.schedule_nbr = b.workorder
|
|
left join mes_main.dbo.assembly_status c
|
|
on a.serial_nbr = c.serial_nbr
|
|
left join [mes_main].[dbo].[config_workstation] e
|
|
on a.wks_id = e.wks_id
|
|
where 1=1 " + strwheres + @") alls
|
|
left join ( select aa.serial_nbr, process_code_desc = (stuff((select ',' + bb.process_code_desc from (select p.serial_nbr,p.process_code_desc from
|
|
mes_main.dbo.defects p
|
|
left join [mes_main].[dbo].[config_workstation] e
|
|
on p.wks_id = e.wks_id
|
|
where 1 = 1 " + strwheres + @"
|
|
group by p.serial_nbr,p.process_code_desc ) bb where bb.serial_nbr =
|
|
aa.serial_nbr for xml path('')),1,1,'')) from (select p.serial_nbr,p.process_code_desc from
|
|
mes_main.dbo.defects p
|
|
left join [mes_main].[dbo].[config_workstation] e
|
|
on p.wks_id = e.wks_id
|
|
where 1 = 1 " + strwheres + @"
|
|
group by p.serial_nbr,p.process_code_desc ) aa
|
|
where aa.serial_nbr != ''
|
|
group by aa.serial_nbr ) code
|
|
on alls.serial_nbr = code.serial_nbr
|
|
left join ( select aa.serial_nbr, defect_type_name = (stuff((select ',' + bb.defect_type_name from (select p.serial_nbr,d.defect_type_name from
|
|
mes_main.dbo.defects p
|
|
left join mes_main.dbo.config_defect_type d
|
|
on p.defect_type_id = d.defect_type_id
|
|
left join [mes_main].[dbo].[config_workstation] e
|
|
on p.wks_id = e.wks_id
|
|
where 1 = 1 " + strwheres + @"
|
|
group by p.serial_nbr,d.defect_type_name ) bb where bb.serial_nbr =
|
|
aa.serial_nbr for xml path('')),1,1,'')) from (select p.serial_nbr,d.defect_type_name from
|
|
mes_main.dbo.defects p
|
|
left join mes_main.dbo.config_defect_type d
|
|
on p.defect_type_id = d.defect_type_id
|
|
left join [mes_main].[dbo].[config_workstation] e
|
|
on p.wks_id = e.wks_id
|
|
where 1 = 1 " + strwheres + @"
|
|
group by p.serial_nbr,d.defect_type_name ) aa
|
|
where aa.serial_nbr != ''
|
|
group by aa.serial_nbr ) defecttype
|
|
on alls.serial_nbr = defecttype.serial_nbr
|
|
left join (select aa.serial_nbr, defect_position = (stuff((select ',' + bb.defect_position from (select p.serial_nbr,p.defect_position from
|
|
mes_main.dbo.defects p
|
|
left join [mes_main].[dbo].[config_workstation] e
|
|
on p.wks_id = e.wks_id
|
|
where 1 = 1 " + strwheres + @"
|
|
group by p.serial_nbr,p.defect_position ) bb where bb.serial_nbr =
|
|
aa.serial_nbr for xml path('')),1,1,'')) from (select p.serial_nbr,p.defect_position from
|
|
mes_main.dbo.defects p
|
|
left join [mes_main].[dbo].[config_workstation] e
|
|
on p.wks_id = e.wks_id
|
|
where 1 = 1 " + strwheres + @"
|
|
group by p.serial_nbr,p.defect_position ) aa
|
|
where aa.serial_nbr != ''
|
|
group by aa.serial_nbr ) defectposition
|
|
on alls.serial_nbr = defectposition.serial_nbr
|
|
left join (select aa.serial_nbr, remark = (stuff((select ',' + bb.remark from (select p.serial_nbr,p.remark from
|
|
mes_main.dbo.defects p
|
|
left join [mes_main].[dbo].[config_workstation] e
|
|
on p.wks_id = e.wks_id
|
|
where 1 = 1 " + strwheres + @"
|
|
group by p.serial_nbr,p.remark ) bb where bb.serial_nbr =
|
|
aa.serial_nbr for xml path('')),1,1,'')) from (select p.serial_nbr,p.remark from
|
|
mes_main.dbo.defects p
|
|
left join [mes_main].[dbo].[config_workstation] e
|
|
on p.wks_id = e.wks_id
|
|
where 1 = 1 " + strwheres + @"
|
|
group by p.serial_nbr,p.remark ) aa
|
|
where aa.serial_nbr != ''
|
|
group by aa.serial_nbr ) remark
|
|
on alls.serial_nbr = remark.serial_nbr
|
|
left join ( select aa.serial_nbr, according_std = (stuff((select ',' + bb.according_std from (select p.serial_nbr,p.according_std from
|
|
mes_main.dbo.defects p
|
|
left join [mes_main].[dbo].[config_workstation] e
|
|
on p.wks_id = e.wks_id
|
|
where 1 = 1 " + strwheres + @"
|
|
group by p.serial_nbr,p.according_std ) bb where bb.serial_nbr =
|
|
aa.serial_nbr for xml path('')),1,1,'')) from (select p.serial_nbr,p.according_std from
|
|
mes_main.dbo.defects p
|
|
left join [mes_main].[dbo].[config_workstation] e
|
|
on p.wks_id = e.wks_id
|
|
where 1 = 1 " + strwheres + @"
|
|
group by p.serial_nbr,p.according_std ) aa
|
|
where aa.serial_nbr != ''
|
|
group by aa.serial_nbr ) accord
|
|
on alls.serial_nbr = accord.serial_nbr
|
|
left join (select a.serial_nbr,a.create_date htime,a.serial_status,a.operator hperson
|
|
FROM [mes_main].[dbo].[qc_visit] a
|
|
left join [mes_main].[dbo].[config_workstation] e
|
|
on a.wks_id = e.wks_id
|
|
where a.visit_type = 'H' " + strwheres + @" ) hold
|
|
on alls.serial_nbr = hold.serial_nbr
|
|
left join ( select a.serial_nbr,max(a.create_date) rtime
|
|
FROM [mes_main].[dbo].[qc_visit] a
|
|
where a.wks_id = 'QC' and a.visit_type in ('PENDING','RL','RW','S')
|
|
group by a.serial_nbr) pend
|
|
on alls.serial_nbr = pend.serial_nbr
|
|
left join mes_main.dbo.qc_visit qcv
|
|
on pend.serial_nbr = qcv.serial_nbr and pend.rtime = qcv.create_date
|
|
where 1 = 1 " + strwhere;
|
|
//if (!string.IsNullOrEmpty(bt.ToString()))
|
|
//{
|
|
// sql += "and qcv.create_date >= '" + Convert.ToString(bt) + "'";
|
|
// sql += "and qcv.create_date <= '" + Convert.ToString(et) + "'";
|
|
//}
|
|
//sql += String.IsNullOrEmpty(lot.ToString()) ? "" : " and qcv.[serial_nbr] LIKE '" + Convert.ToString(lot) + "%'";
|
|
//sql += String.IsNullOrEmpty(workshop.ToString()) ? "" : " AND wo.[area_code] = '" + Convert.ToString(workshop) + "' ";
|
|
//sql += String.IsNullOrEmpty(status.ToString()) ? "" : " AND qcv.[visit_type] = '" + Convert.ToString(status) + "'";
|
|
//sql += String.IsNullOrEmpty(workorder.ToString()) ? "" : " AND qcv.schedule_nbr = '" + Convert.ToString(workorder) + "'";
|
|
return sql;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region 包装产量报表
|
|
public DataTable PackOutputQueryInfo(string workshop, string bt, string et, string lot, string container, string pallet, string check, string workorder)
|
|
{
|
|
return dbhelp.ExecuteDataTable(PackOutputSql(workshop, bt, et, lot, container, pallet, check, workorder), null);
|
|
}
|
|
//英利客户
|
|
public DataTable PackOutputDetailQueryInfo(string workshop, string bt, string et, string lot, string container, string pallet, string check, string workorder)
|
|
{
|
|
return dbhelp.ExecuteDataTable(PackOutputDetailSql(workshop, bt, et, lot, container, pallet, check, workorder), null);
|
|
}
|
|
|
|
//(旧版本)
|
|
private string PackOutput2Sql(string workshop, string bt, string et, string lot, string container, string pallet, string check, string workorder)
|
|
{
|
|
string sql = @"SELECT ast.[pallet_nbr]/*托盘编码*/
|
|
,wh.containerno as container_nbr/*柜号*/
|
|
,ast.[serial_nbr] /*组件序列号*/
|
|
,ast.[workorder]/*工单号*/
|
|
,wm.sale_order
|
|
,ast.[power_grade]/*功率档位*/
|
|
,ast.current_grade/*电流档位*/
|
|
,ast.[product_code]/*装配件号*/
|
|
,ast.exterior_grade
|
|
,ast.[el_grade]/*EL等级*/
|
|
,ast.[final_grade]/*外观等级*/
|
|
,iv.wks_id
|
|
,CONVERT(varchar(100), ppk.[pack_date], 120) as pack_date/*封箱时间*/
|
|
,cpp.[descriptions]/*功率组*/
|
|
,dps.[pallet_status_desc]/*是否入库*/
|
|
,dst.[descriptions] shift_type/*班次*/
|
|
, iv.[pmax]
|
|
,iv.[voc]
|
|
,iv.[isc]
|
|
,iv.[ff]
|
|
,iv.[vpm]
|
|
,iv.[ipm]
|
|
,iv.[rs]
|
|
,iv.[rsh]
|
|
,iv.[eff]
|
|
,iv.[env_temp]
|
|
,iv.[surf_temp]
|
|
,iv.[temp]
|
|
,iv.[ivfile_path]
|
|
,ast.[pack_seq]
|
|
,ppk.[check_nbr]
|
|
,ms.[descriptions] as cell_supplier/*电池片供应商*/
|
|
,cmc.cell_color_desc
|
|
,cmc.cell_type_desc
|
|
,'' /*电池片档位*/
|
|
,[cell_uop] /*电池片效率*/
|
|
,iv.[pmax]/(cast(REPLACE(cp.[cell_qty],'W','') as float)*cast(REPLACE([cell_uop],'W','') as float)) fff /*转换效率*/
|
|
--,cp.[cell_qty]
|
|
,ab.[eva_supplier_code]/*EVA供应商*/
|
|
,cmeva.[eva_thickness] /*EVA规格*/
|
|
,ab.[eva_lot_nbr]/*EVA批号*/
|
|
,ab.[bks_supplier_code]/*背板供应商*/
|
|
,cmbks.[bks_thickness] /*bks规格*/
|
|
,ab.[bks_lot_nbr]/*背板批号*/
|
|
,ab.[glass_supplier_code]/*玻璃供应商*/
|
|
,cmglass.glass_thickness_desc /*玻璃规格*/
|
|
,ab.[glass_lot_nbr]/*电池批号*/
|
|
,ab.[jbox_supplier_code]/*接线盒供应商*/
|
|
,cmjbox.jbox_model_desc/*型材规格*/
|
|
,ab.[jbox_lot_nbr]/*接线盒批号*/
|
|
,ab.[frame_supplier_code]/*型材供应商*/
|
|
,cmframe.frame_thickness_desc/*型材规格*/
|
|
,ab.[frame_lot_nbr]/*型材批号*/
|
|
,wm.[customer]
|
|
,ppk.[product_code_original]
|
|
--,ppk.container_nbr as batch
|
|
,CONVERT(varchar(100),iv.wks_visit_date, 120) as wks_visit_date /*测试时间*/
|
|
FROM[mes_main].[dbo].[assembly_status]
|
|
ast
|
|
left join[mes_level2_iface].[dbo].[iv]
|
|
iv
|
|
on ast.[serial_nbr]=iv.[serial_nbr]
|
|
left join[mes_main].[dbo].[pack_pallets]
|
|
ppk
|
|
on ast.[pallet_nbr]=ppk.[pallet_nbr]
|
|
left join[mes_main].[dbo].[df_pallet_status]
|
|
dps
|
|
on ppk.[pallet_status]=dps.[pallet_status]
|
|
left join[mes_main].[dbo].[df_shift_type]
|
|
dst
|
|
on ppk.[shift_type]=dst.[shift_type]
|
|
left join[mes_main].[dbo].[config_power_group]
|
|
cpp
|
|
on ppk.[power_grade_group_id]=cpp.[power_grade_group_id]
|
|
left join[mes_main].[dbo].[assembly_basis]
|
|
ab
|
|
on ast.[serial_nbr]=ab.[serial_nbr]
|
|
left join[mes_main].[dbo].[config_mat_cell]
|
|
cmc
|
|
on ab.[cell_part_nbr]=cmc.[part_nbr]
|
|
left join[mes_level4_iface].[dbo].[master_supplier]
|
|
ms
|
|
on ab.[cell_supplier_code]=ms.[supplier_code]
|
|
left join[mes_main].[dbo].[config_products]
|
|
cp
|
|
on ab.[product_code]=cp.[product_code]
|
|
left join[mes_main].[dbo].[wo_mfg]
|
|
wm
|
|
on ast.[workorder]=wm.[workorder]
|
|
left join[mes_main].[dbo].[config_mat_eva]
|
|
cmeva
|
|
on ab.[eva_part_nbr]=cmeva.[part_nbr]
|
|
left join[mes_main].[dbo].[config_mat_bks]
|
|
cmbks
|
|
on ab.[cell_part_nbr]=cmbks.[part_nbr]
|
|
left join[mes_main].[dbo].[config_mat_glass]
|
|
cmglass
|
|
on ab.glass_part_nbr=cmglass.part_nbr
|
|
left join[mes_main].[dbo].[config_mat_frame]
|
|
cmframe
|
|
on ab.frame_part_nbr=cmframe.part_nbr
|
|
left join[mes_main].[dbo].[config_mat_jbox]
|
|
cmjbox
|
|
on ab.jbox_part_nbr=cmjbox.part_nbr
|
|
left join wh.dbo.tcontainerpallet wh
|
|
on ast.pallet_nbr =wh.palletno
|
|
where 1=1 ast.pallet_nbr is not null";
|
|
//ppk.[pack_date]>='" + Convert.ToString(bt) + "' and ppk.[pack_date]<='" + Convert.ToString(et) + "' ";
|
|
//车间
|
|
sql += (String.IsNullOrEmpty(workshop) | (workorder == "''")) ? "" : " AND wm.area_code='" + Convert.ToString(workshop) + "'";
|
|
//报检单号
|
|
sql += (String.IsNullOrEmpty(bt) | (bt == "''")) ? "" : " AND ppk.[pack_date]>='" + Convert.ToString(bt) + "'";
|
|
//报检单号
|
|
sql += (String.IsNullOrEmpty(et) | (et == "''")) ? "" : " AND ppk.[pack_date]<='" + Convert.ToString(et) + "'";
|
|
//柜号
|
|
sql += String.IsNullOrEmpty(container) | (container == "''") ? "" : " and wh.containerno in ( " + Convert.ToString(container) + " )";
|
|
//托盘号
|
|
sql += (String.IsNullOrEmpty(pallet) | (pallet == "''")) ? "" : " and ast.[pallet_nbr] in ( " + Convert.ToString(pallet) + " ) ";
|
|
//组件序列号
|
|
sql += (String.IsNullOrEmpty(lot) | (lot == "''")) ? "" : " AND ast.[serial_nbr] in ( " + Convert.ToString(lot) + " )";
|
|
//报检单号
|
|
sql += (String.IsNullOrEmpty(check) | (check == "''")) ? "" : " AND ppk.[check_nbr]='" + Convert.ToString(check) + "'";
|
|
//报检单号
|
|
sql += (String.IsNullOrEmpty(workorder) | (workorder == "''")) ? "" : " AND wm.workorder='" + Convert.ToString(workorder) + "'";
|
|
return sql;
|
|
}
|
|
|
|
//(山东客户版本)
|
|
private string PackOutputSql(string workshop, string bt, string et, string lot, string container, string pallet, string check, string workorder)
|
|
{
|
|
string sql = @"SELECT
|
|
wh.containerno as container_nbr/*柜号*/
|
|
,ast.[pallet_nbr]/*托盘编码*/
|
|
,ast.[pack_seq]/*包装顺序*/
|
|
,ast.[workorder]/*工单号*/
|
|
,wm.sale_order
|
|
,ast.[serial_nbr] /*组件序列号*/
|
|
,CONVERT(varchar(100), ppk.[pack_date], 120) as pack_date/*封箱时间*/
|
|
,CONVERT(varchar(100),iv.wks_visit_date, 120) as wks_visit_date /*测试时间*/
|
|
,iv.wks_id/*测试机台*/
|
|
,ast.[power_grade]/*功率档位*/
|
|
,ast.current_grade/*电流档位*/
|
|
--,ast.[product_code]/*装配件号*/
|
|
,ast.exterior_grade/*外观等级*/
|
|
,ast.[el_grade]/*EL等级*/
|
|
,ast.[final_grade]/*最终等级*/
|
|
--,cpp.[descriptions]/*功率组*/
|
|
--,dst.[descriptions] shift_type/*班次*/
|
|
--, cast(iv.[pmax] as numeric(18,2)) pmax
|
|
,iv.[pmax]
|
|
,iv.[ff]
|
|
,iv.[voc]
|
|
,iv.[isc]
|
|
,iv.[vpm]
|
|
,iv.[ipm]
|
|
,iv.[rs]
|
|
,iv.[rsh]
|
|
,iv.[eff]
|
|
--,cast(iv.[eff] as numeric(18,2)) eff
|
|
,iv.[env_temp]
|
|
--,cast(iv.[surf_temp] as numeric(18,2)) surf_temp
|
|
--,cast(iv.[temp] as numeric(18,2)) temp
|
|
--,cast(iv.[ivfile_path] as numeric(18,2)) ivfile_path
|
|
,iv.[surf_temp] tmod
|
|
,ms.[descriptions] as cell_supplier/*电池片供应商*/
|
|
--,ppk.[check_nbr]
|
|
,case when cmc.attr_code = 'cell_uop' then cmc.attr_value end cell_uop/*单片功率*/
|
|
,case when color.attr_code = 'cell_color' then color.attr_value end cell_color/*电池颜色*/
|
|
,case when grade.attr_code = 'cell_grade' then grade.attr_value end cell_grade/*电池片等级*/
|
|
,case when type.attr_code = 'cell_type' then type.attr_value end cell_type/*电池片类型*/
|
|
,case when eff.attr_code = 'cell_eff' then eff.attr_value end cell_eff/*电池片效率档*/
|
|
--,iv.[pmax]/(cast(REPLACE(cp.[cell_qty],'W','') as float)*cast(REPLACE([cell_uop],'W','') as float)) fff /*转换效率*/
|
|
--,cp.[cell_qty]
|
|
--,ppk.container_nbr as batch
|
|
,dps.[pallet_status_desc]/*托盘状态*/
|
|
FROM[mes_main].[dbo].[assembly_status]
|
|
ast
|
|
left join[mes_level2_iface].[dbo].[iv]
|
|
iv
|
|
on ast.[serial_nbr]=iv.[serial_nbr]
|
|
left join[mes_main].[dbo].[pack_pallets]
|
|
ppk
|
|
on ast.[pallet_nbr]=ppk.[pallet_nbr]
|
|
left join[mes_main].[dbo].[df_pallet_status]
|
|
dps
|
|
on ppk.[pallet_status]=dps.[pallet_status]
|
|
left join[mes_main].[dbo].[df_shift_type]
|
|
dst
|
|
on ppk.[shift_type]=dst.[shift_type]
|
|
left join[mes_main].[dbo].[config_power_group]
|
|
cpp
|
|
on ppk.[power_grade_group_id]=cpp.[power_grade_group_id]
|
|
LEFT join mes_main.dbo.trace_componnet_lot
|
|
ab
|
|
on ab.serial_nbr = ast.serial_nbr and ab.part_type = 'CELL'
|
|
--left join[mes_main].[dbo].[assembly_basis]
|
|
-- ab
|
|
--on ast.[serial_nbr]=ab.[serial_nbr]
|
|
left join[mes_main].[dbo].[config_mat_attr]
|
|
cmc
|
|
on ab.part_nbr=cmc.[part_nbr] and cmc.attr_code = 'cell_uop'
|
|
left join[mes_main].[dbo].[config_mat_attr]
|
|
color
|
|
on ab.part_nbr=color.[part_nbr] and color.attr_code = 'cell_color'
|
|
left join[mes_main].[dbo].[config_mat_attr]
|
|
grade
|
|
on ab.part_nbr=grade.[part_nbr] and grade.attr_code = 'cell_grade'
|
|
left join[mes_main].[dbo].[config_mat_attr]
|
|
type
|
|
on ab.part_nbr=type.[part_nbr] and type.attr_code = 'cell_type'
|
|
left join[mes_main].[dbo].[config_mat_attr]
|
|
eff
|
|
on ab.part_nbr=eff.[part_nbr] and eff.attr_code = 'cell_eff'
|
|
left join[mes_level4_iface].[dbo].[master_supplier]
|
|
ms
|
|
on ab.supplier_code=ms.[supplier_code]
|
|
left join[mes_main].[dbo].[config_products]
|
|
cp
|
|
on ppk.[product_code]=cp.[product_code]
|
|
left join[mes_main].[dbo].[wo_mfg]
|
|
wm
|
|
on ast.[workorder]=wm.[workorder]
|
|
--left join[mes_main].[dbo].[config_mat_eva]
|
|
--cmeva
|
|
--on ab.[eva_part_nbr]=cmeva.[part_nbr]
|
|
--left join[mes_main].[dbo].[config_mat_bks]
|
|
--cmbks
|
|
--on ab.[cell_part_nbr]=cmbks.[part_nbr]
|
|
--left join[mes_main].[dbo].[config_mat_glass]
|
|
--cmglass
|
|
--on ab.glass_part_nbr=cmglass.part_nbr
|
|
--left join[mes_main].[dbo].[config_mat_frame]
|
|
--cmframe
|
|
--on ab.frame_part_nbr=cmframe.part_nbr
|
|
--left join[mes_main].[dbo].[config_mat_jbox]
|
|
--cmjbox
|
|
--on ab.jbox_part_nbr=cmjbox.part_nbr
|
|
left join wh.dbo.tcontainerpallet wh
|
|
on ast.pallet_nbr =wh.palletno
|
|
where 1=1 and ast.pallet_nbr is not null";
|
|
//ppk.[pack_date]>='" + Convert.ToString(bt) + "' and ppk.[pack_date]<='" + Convert.ToString(et) + "' ";
|
|
//报检单号
|
|
sql += (String.IsNullOrEmpty(workshop) | (workorder == "''")) ? "" : " AND wm.area_code='" + Convert.ToString(workshop) + "'";
|
|
sql += (String.IsNullOrEmpty(bt) | (bt == "''")) ? "" : " AND ppk.[pack_date]>='" + Convert.ToString(bt) + "'";
|
|
//报检单号
|
|
sql += (String.IsNullOrEmpty(et) | (et == "''")) ? "" : " AND ppk.[pack_date]<='" + Convert.ToString(et) + "'";
|
|
//柜号
|
|
sql += String.IsNullOrEmpty(container) | (container == "''") ? "" : " and wh.containerno in ( " + Convert.ToString(container) + " )";
|
|
//托盘号
|
|
sql += (String.IsNullOrEmpty(pallet) | (pallet == "''")) ? "" : " and ast.[pallet_nbr] in ( " + Convert.ToString(pallet) + " ) ";
|
|
//组件序列号
|
|
sql += (String.IsNullOrEmpty(lot) | (lot == "''")) ? "" : " AND ast.[serial_nbr] in ( " + Convert.ToString(lot) + " )";
|
|
//报检单号
|
|
sql += (String.IsNullOrEmpty(check) | (check == "''")) ? "" : " AND ppk.[check_nbr]='" + Convert.ToString(check) + "'";
|
|
sql += (String.IsNullOrEmpty(workorder) | (workorder == "''")) ? "" : " AND wm.workorder='" + Convert.ToString(workorder) + "'";
|
|
return sql;
|
|
}
|
|
|
|
//(英利客户版本)
|
|
private string PackOutputDetailSql(string workshop, string bt, string et, string lot, string container, string pallet, string check, string workorder)
|
|
{
|
|
string sql = @"SELECT
|
|
ast.[pallet_nbr]/*托盘编码*/
|
|
,ast.[serial_nbr] /*组件序列号*/
|
|
--,round(iv.[voc] ,2) voc
|
|
,iv.[voc]
|
|
--,round(iv.[isc] ,2) isc
|
|
,iv.[isc]
|
|
,iv.[pmax]
|
|
--,round(iv.[vpm] ,2) vpm
|
|
,iv.[vpm]
|
|
--,round(iv.[ipm] ,2) ipm
|
|
,iv.[ipm]
|
|
,cast(substring(cast(iv.[ff]*100.00 as varchar(10)),1,charindex('.',iv.[ff]*100.00)+2) as float) as ff
|
|
,CONVERT(varchar(100),iv.wks_visit_date, 120) as wks_visit_date /*测试时间*/
|
|
FROM[mes_main].[dbo].[assembly_status]
|
|
ast
|
|
left join[mes_level2_iface].[dbo].[iv]
|
|
iv
|
|
on ast.[serial_nbr]=iv.[serial_nbr]
|
|
left join[mes_main].[dbo].[pack_pallets]
|
|
ppk
|
|
on ast.[pallet_nbr]=ppk.[pallet_nbr]
|
|
left join[mes_main].[dbo].[df_pallet_status]
|
|
dps
|
|
on ppk.[pallet_status]=dps.[pallet_status]
|
|
left join[mes_main].[dbo].[df_shift_type]
|
|
dst
|
|
on ppk.[shift_type]=dst.[shift_type]
|
|
left join[mes_main].[dbo].[config_power_group]
|
|
cpp
|
|
on ppk.[power_grade_group_id]=cpp.[power_grade_group_id]
|
|
LEFT join mes_main.dbo.trace_componnet_lot
|
|
ab
|
|
on ab.serial_nbr = ast.serial_nbr and ab.part_type = 'CELL'
|
|
--left join[mes_main].[dbo].[assembly_basis]
|
|
-- ab
|
|
--on ast.[serial_nbr]=ab.[serial_nbr]
|
|
left join[mes_main].[dbo].[config_mat_attr]
|
|
cmc
|
|
on ab.part_nbr=cmc.[part_nbr] and cmc.attr_code = 'cell_uop'
|
|
left join[mes_main].[dbo].[config_mat_attr]
|
|
color
|
|
on ab.part_nbr=color.[part_nbr] and color.attr_code = 'cell_color'
|
|
left join[mes_main].[dbo].[config_mat_attr]
|
|
grade
|
|
on ab.part_nbr=grade.[part_nbr] and grade.attr_code = 'cell_grade'
|
|
left join[mes_main].[dbo].[config_mat_attr]
|
|
type
|
|
on ab.part_nbr=type.[part_nbr] and type.attr_code = 'cell_type'
|
|
left join[mes_main].[dbo].[config_mat_attr]
|
|
eff
|
|
on ab.part_nbr=eff.[part_nbr] and eff.attr_code = 'cell_eff'
|
|
left join[mes_level4_iface].[dbo].[master_supplier]
|
|
ms
|
|
on ab.supplier_code=ms.[supplier_code]
|
|
left join[mes_main].[dbo].[config_products]
|
|
cp
|
|
on ppk.[product_code]=cp.[product_code]
|
|
left join[mes_main].[dbo].[wo_mfg]
|
|
wm
|
|
on ast.[workorder]=wm.[workorder]
|
|
--left join[mes_main].[dbo].[config_mat_eva]
|
|
--cmeva
|
|
--on ab.[eva_part_nbr]=cmeva.[part_nbr]
|
|
--left join[mes_main].[dbo].[config_mat_bks]
|
|
--cmbks
|
|
--on ab.[cell_part_nbr]=cmbks.[part_nbr]
|
|
--left join[mes_main].[dbo].[config_mat_glass]
|
|
--cmglass
|
|
--on ab.glass_part_nbr=cmglass.part_nbr
|
|
--left join[mes_main].[dbo].[config_mat_frame]
|
|
--cmframe
|
|
--on ab.frame_part_nbr=cmframe.part_nbr
|
|
--left join[mes_main].[dbo].[config_mat_jbox]
|
|
--cmjbox
|
|
--on ab.jbox_part_nbr=cmjbox.part_nbr
|
|
left join wh.dbo.tcontainerpallet wh
|
|
on ast.pallet_nbr =wh.palletno
|
|
where 1=1 ";
|
|
//ppk.[pack_date]>='" + Convert.ToString(bt) + "' and ppk.[pack_date]<='" + Convert.ToString(et) + "' ";
|
|
//报检单号
|
|
sql += (String.IsNullOrEmpty(workshop) | (workorder == "''")) ? "" : " AND wm.area_code='" + Convert.ToString(workshop) + "'";
|
|
sql += (String.IsNullOrEmpty(bt) | (bt == "''")) ? "" : " AND ppk.[pack_date]>='" + Convert.ToString(bt) + "'";
|
|
//报检单号
|
|
sql += (String.IsNullOrEmpty(et) | (et == "''")) ? "" : " AND ppk.[pack_date]<='" + Convert.ToString(et) + "'";
|
|
//柜号
|
|
sql += String.IsNullOrEmpty(container) | (container == "''") ? "" : " and wh.containerno in ( " + Convert.ToString(container) + " )";
|
|
//托盘号
|
|
sql += (String.IsNullOrEmpty(pallet) | (pallet == "''")) ? "" : " and ast.[pallet_nbr] in ( " + Convert.ToString(pallet) + " ) ";
|
|
//组件序列号
|
|
sql += (String.IsNullOrEmpty(lot) | (lot == "''")) ? "" : " AND ast.[serial_nbr] in ( " + Convert.ToString(lot) + " )";
|
|
//报检单号
|
|
sql += (String.IsNullOrEmpty(check) | (check == "''")) ? "" : " AND ppk.[check_nbr]='" + Convert.ToString(check) + "'";
|
|
sql += (String.IsNullOrEmpty(workorder) | (workorder == "''")) ? "" : " AND wm.workorder='" + Convert.ToString(workorder) + "'";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 组件电子流转单
|
|
//装框线盒查询
|
|
private string FrameBoxSql(string lot)
|
|
{
|
|
string sql = @"select tcl.serial_nbr /*组件序列号*/
|
|
,twv.schedule_nbr/*工单号*/
|
|
, CONVERT(varchar(100),tcl.wks_visit_date , 120) as wks_visit_date/*过站时间*/
|
|
,dpt.[descriptions] part_type/*材料类型*/
|
|
,tcl.part_nbr/*材料料号*/
|
|
,ms.descriptions supplier_code/*材料供应商*/
|
|
,tcl.lot_nbr/*材料批次号*/
|
|
,DU.nickname operator/*材料供应商*/
|
|
,twv.wks_id/*机台号*/
|
|
,cw.process_code /*站点编号*/
|
|
,dp.descriptions/*站点名称*/
|
|
,dst.descriptions shift_type/*班次*/
|
|
,(select top 1 frame_spec_desc from [mes_main].[dbo].[config_mat_frame] where part_nbr = tcl.part_nbr ) spec
|
|
from trace_componnet_lot tcl/*记录材料*/
|
|
,trace_workstation_visit twv /*记录机台*/
|
|
,assembly_status ab
|
|
,wo_mfg wm
|
|
,[mes_level4_iface].[dbo].[df_part_type] dpt
|
|
,[mes_level4_iface].[dbo].[master_supplier] ms
|
|
,[mes_main].[dbo].[df_shift_type] dst
|
|
,[mes_auth].[dbo].[df_user] du
|
|
,[mes_main].[dbo].[config_workstation] cw
|
|
,[mes_main].[dbo].[df_processes] dp
|
|
where twv.serial_nbr=tcl.serial_nbr
|
|
and tcl.wks_id=twv.wks_id
|
|
and twv.serial_nbr=ab.serial_nbr
|
|
and ab.workorder=wm.workorder
|
|
and tcl.part_type=dpt.part_type
|
|
and tcl.supplier_code=ms.supplier_code
|
|
and twv.shift_type =dst.shift_type
|
|
and twv.operator=du.username
|
|
and twv.wks_id=cw.wks_id
|
|
and cw.process_code=dp.process_code
|
|
and tcl.serial_nbr='" + lot + "'" + " and dp.descriptions='装框' "; //and dpt.[descriptions]='线盒'
|
|
return sql;
|
|
|
|
}
|
|
public IEnumerable<dynamic> FrameBoxQueryInfo(string lot)
|
|
{
|
|
IEnumerable<dynamic> res = null;
|
|
using (var conn = Dpperhelper.OpenSqlConnection())
|
|
{
|
|
res = conn.Query(FrameBoxSql(lot));
|
|
}
|
|
return res;
|
|
}
|
|
|
|
//叠层eva
|
|
private string LaminationEVASql(string lot)
|
|
{
|
|
string sql = @"select tcl.serial_nbr /*组件序列号*/
|
|
,twv.schedule_nbr/*工单号*/
|
|
,tcl.wks_visit_date/*过站时间*/
|
|
,dpt.[descriptions] part_type/*材料类型*/
|
|
,tcl.part_nbr/*材料料号*/
|
|
,ms.descriptions supplier_code/*材料供应商*/
|
|
,tcl.lot_nbr/*材料批次号*/
|
|
,DU.nickname operator/*材料供应商*/
|
|
,twv.wks_id/*机台号*/
|
|
,cw.process_code /*站点编号*/
|
|
,dp.descriptions/*站点名称*/
|
|
,dst.descriptions shift_type/*班次*/
|
|
,a.eva_width
|
|
,a.eva_thickness
|
|
from trace_componnet_lot tcl/*记录材料*/
|
|
,trace_workstation_visit twv /*记录机台*/
|
|
,assembly_status ab
|
|
,wo_mfg wm
|
|
,[mes_level4_iface].[dbo].[df_part_type] dpt
|
|
,[mes_level4_iface].[dbo].[master_supplier] ms
|
|
,[mes_main].[dbo].[df_shift_type] dst
|
|
,[mes_auth].[dbo].[df_user] du
|
|
,[mes_main].[dbo].[config_workstation] cw
|
|
,[mes_main].[dbo].[df_processes] dp
|
|
,[mes_main].[dbo].[config_mat_eva] a
|
|
where twv.serial_nbr=tcl.serial_nbr
|
|
and tcl.wks_id=twv.wks_id
|
|
--and twv.serial_nbr='JYP171202X60000019'
|
|
and twv.serial_nbr=ab.serial_nbr
|
|
and ab.workorder=wm.workorder
|
|
and tcl.part_type=dpt.part_type
|
|
and tcl.supplier_code=ms.supplier_code
|
|
and twv.shift_type =dst.shift_type
|
|
and twv.operator=du.username
|
|
and twv.wks_id=cw.wks_id
|
|
and cw.process_code=dp.process_code
|
|
and tcl.part_nbr = a.part_nbr
|
|
and tcl.serial_nbr='" + lot + "' and dp.descriptions = '叠层' and dpt.[descriptions]='EVA'";
|
|
return sql;
|
|
}
|
|
public IEnumerable<dynamic> LaminationEVAQueryInfo(string lot)
|
|
{
|
|
IEnumerable<dynamic> res = null;
|
|
using (var conn = Dpperhelper.OpenSqlConnection())
|
|
{
|
|
res = conn.Query(LaminationEVASql(lot));
|
|
}
|
|
return res;
|
|
}
|
|
|
|
//叠层高透EVA
|
|
private string LaminationHighEVASql(string lot)
|
|
{
|
|
string sql = @"select tcl.serial_nbr /*组件序列号*/
|
|
,twv.schedule_nbr/*工单号*/
|
|
,tcl.wks_visit_date/*过站时间*/
|
|
,dpt.[descriptions] part_type/*材料类型*/
|
|
,tcl.part_nbr/*材料料号*/
|
|
,ms.descriptions supplier_code/*材料供应商*/
|
|
,tcl.lot_nbr/*材料批次号*/
|
|
,DU.nickname operator/*材料供应商*/
|
|
,twv.wks_id/*机台号*/
|
|
,cw.process_code /*站点编号*/
|
|
,dp.descriptions/*站点名称*/
|
|
,dst.descriptions shift_type/*班次*/
|
|
,a.eva_width
|
|
,a.eva_thickness
|
|
from trace_componnet_lot tcl/*记录材料*/
|
|
,trace_workstation_visit twv /*记录机台*/
|
|
,assembly_status ab
|
|
,wo_mfg wm
|
|
,[mes_level4_iface].[dbo].[df_part_type] dpt
|
|
,[mes_level4_iface].[dbo].[master_supplier] ms
|
|
,[mes_main].[dbo].[df_shift_type] dst
|
|
,[mes_auth].[dbo].[df_user] du
|
|
,[mes_main].[dbo].[config_workstation] cw
|
|
,[mes_main].[dbo].[df_processes] dp
|
|
,[mes_main].[dbo].[config_mat_eva] a
|
|
where twv.serial_nbr=tcl.serial_nbr
|
|
and tcl.wks_id=twv.wks_id
|
|
--and twv.serial_nbr='JYP171202X60000019'
|
|
and twv.serial_nbr=ab.serial_nbr
|
|
and ab.workorder=wm.workorder
|
|
and tcl.part_type=dpt.part_type
|
|
and tcl.supplier_code=ms.supplier_code
|
|
and twv.shift_type =dst.shift_type
|
|
and twv.operator=du.username
|
|
and twv.wks_id=cw.wks_id
|
|
and cw.process_code=dp.process_code
|
|
and tcl.part_nbr = a.part_nbr
|
|
and tcl.serial_nbr='" + lot + "' and dp.descriptions='叠层' and dpt.[descriptions]='高透EVA'";
|
|
return sql;
|
|
}
|
|
public IEnumerable<dynamic> LaminationHighEVAQueryInfo(string lot)
|
|
{
|
|
IEnumerable<dynamic> res = null;
|
|
using (var conn = Dpperhelper.OpenSqlConnection())
|
|
{
|
|
res = conn.Query(LaminationHighEVASql(lot));
|
|
}
|
|
return res;
|
|
}
|
|
|
|
//叠层玻璃
|
|
private string LaminationGlassSql(string lot)
|
|
{
|
|
string sql = @"select tcl.serial_nbr /*组件序列号*/
|
|
,twv.schedule_nbr/*工单号*/
|
|
,tcl.wks_visit_date/*过站时间*/
|
|
,dpt.[descriptions] part_type/*材料类型*/
|
|
,tcl.part_nbr/*材料料号*/
|
|
,ms.descriptions supplier_code/*材料供应商*/
|
|
,tcl.lot_nbr/*材料批次号*/
|
|
,DU.nickname operator/*材料供应商*/
|
|
,twv.wks_id/*机台号*/
|
|
,cw.process_code /*站点编号*/
|
|
,dp.descriptions/*站点名称*/
|
|
,dst.descriptions shift_type/*班次*/
|
|
,a.glass_width_desc
|
|
,a.glass_thickness_desc
|
|
,a.glass_length_desc
|
|
from trace_componnet_lot tcl/*记录材料*/
|
|
,trace_workstation_visit twv /*记录机台*/
|
|
,assembly_status ab
|
|
,wo_mfg wm
|
|
,[mes_level4_iface].[dbo].[df_part_type] dpt
|
|
,[mes_level4_iface].[dbo].[master_supplier] ms
|
|
,[mes_main].[dbo].[df_shift_type] dst
|
|
,[mes_auth].[dbo].[df_user] du
|
|
,[mes_main].[dbo].[config_workstation] cw
|
|
,[mes_main].[dbo].[df_processes] dp
|
|
,[mes_main].[dbo].[config_mat_glass] a
|
|
where twv.serial_nbr=tcl.serial_nbr
|
|
and tcl.wks_id=twv.wks_id
|
|
--and twv.serial_nbr='JYP171202X60000019'
|
|
and twv.serial_nbr=ab.serial_nbr
|
|
and ab.workorder=wm.workorder
|
|
and tcl.part_type=dpt.part_type
|
|
and tcl.supplier_code=ms.supplier_code
|
|
and twv.shift_type =dst.shift_type
|
|
and twv.operator=du.username
|
|
and twv.wks_id=cw.wks_id
|
|
and cw.process_code=dp.process_code
|
|
and a.part_nbr = tcl.part_nbr
|
|
and tcl.serial_nbr='" + lot + "' and dp.descriptions='叠层' and dpt.[descriptions]='玻璃'";
|
|
return sql;
|
|
}
|
|
public IEnumerable<dynamic> LaminationGlassQueryInfo(string lot)
|
|
{
|
|
IEnumerable<dynamic> res = null;
|
|
using (var conn = Dpperhelper.OpenSqlConnection())
|
|
{
|
|
res = conn.Query(LaminationGlassSql(lot));
|
|
}
|
|
return res;
|
|
}
|
|
//叠层背板
|
|
private string LaminationBackSql(string lot)
|
|
{
|
|
string sql = @"select tcl.serial_nbr /*组件序列号*/
|
|
,twv.schedule_nbr/*工单号*/
|
|
,tcl.wks_visit_date/*过站时间*/
|
|
,dpt.[descriptions] part_type/*材料类型*/
|
|
,tcl.part_nbr/*材料料号*/
|
|
,ms.descriptions supplier_code/*材料供应商*/
|
|
,tcl.lot_nbr/*材料批次号*/
|
|
,DU.nickname operator/*材料供应商*/
|
|
,twv.wks_id/*机台号*/
|
|
,cw.process_code /*站点编号*/
|
|
,dp.descriptions/*站点名称*/
|
|
,dst.descriptions shift_type/*班次*/
|
|
,a.bks_width
|
|
,a.bks_thickness
|
|
from trace_componnet_lot tcl/*记录材料*/
|
|
,trace_workstation_visit twv /*记录机台*/
|
|
,assembly_status ab
|
|
,wo_mfg wm
|
|
,[mes_level4_iface].[dbo].[df_part_type] dpt
|
|
,[mes_level4_iface].[dbo].[master_supplier] ms
|
|
,[mes_main].[dbo].[df_shift_type] dst
|
|
,[mes_auth].[dbo].[df_user] du
|
|
,[mes_main].[dbo].[config_workstation] cw
|
|
,[mes_main].[dbo].[df_processes] dp
|
|
,[mes_main].[dbo].[config_mat_bks] a
|
|
where twv.serial_nbr=tcl.serial_nbr
|
|
and tcl.wks_id=twv.wks_id
|
|
--and twv.serial_nbr='JYP171202X60000019'
|
|
and twv.serial_nbr=ab.serial_nbr
|
|
and ab.workorder=wm.workorder
|
|
and tcl.part_type=dpt.part_type
|
|
and tcl.supplier_code=ms.supplier_code
|
|
and twv.shift_type =dst.shift_type
|
|
and twv.operator=du.username
|
|
and twv.wks_id=cw.wks_id
|
|
and cw.process_code=dp.process_code
|
|
and tcl.part_nbr = a.part_nbr
|
|
and tcl.serial_nbr='" + lot + "' and dp.descriptions='叠层' and dpt.[descriptions]='背板'";
|
|
return sql;
|
|
}
|
|
public IEnumerable<dynamic> LaminationBackQueryInfo(string lot)
|
|
{
|
|
IEnumerable<dynamic> res = null;
|
|
using (var conn = Dpperhelper.OpenSqlConnection())
|
|
{
|
|
res = conn.Query(LaminationBackSql(lot));
|
|
}
|
|
return res;
|
|
}
|
|
|
|
//IV
|
|
private string IVSql(string lot)
|
|
{
|
|
string sql = @"SELECT [serial_nbr]
|
|
,[wks_id]
|
|
,[wks_visit_date]
|
|
,[pmax]
|
|
,[voc]
|
|
,[isc]
|
|
,[ff]
|
|
,[vpm]
|
|
,[ipm]
|
|
,[rs]
|
|
,[rsh]
|
|
,[eff]
|
|
,[env_temp]
|
|
,[surf_temp]
|
|
,[temp]
|
|
,[ivfile_path]
|
|
FROM [mes_level2_iface].[dbo].[iv] iv
|
|
where iv.serial_nbr='" + lot + "'";
|
|
return sql;
|
|
}
|
|
public IEnumerable<dynamic> IVQueryInfo(string lot)
|
|
{
|
|
IEnumerable<dynamic> res = null;
|
|
using (var conn = Dpperhelper.OpenSqlConnection())
|
|
{
|
|
res = conn.Query(IVSql(lot));
|
|
}
|
|
return res;
|
|
}
|
|
|
|
//包装
|
|
private string PackSql(string lot)
|
|
{
|
|
string sql = @"select AST.[serial_nbr]
|
|
,AST.[pallet_nbr]
|
|
,AST.[pack_date]
|
|
,PPT.wks_id
|
|
From [mes_main].[dbo].[assembly_status] ast
|
|
LEFT JOIN [mes_main].[dbo].[pack_pallets] PPT
|
|
ON AST.pallet_nbr=PPT.pallet_nbr
|
|
WHERE AST.[serial_nbr]='" + lot + "' ";
|
|
return sql;
|
|
}
|
|
public IEnumerable<dynamic> PackQueryInfo(string lot)
|
|
{
|
|
IEnumerable<dynamic> res = null;
|
|
using (var conn = Dpperhelper.OpenSqlConnection())
|
|
{
|
|
res = conn.Query(PackSql(lot));
|
|
}
|
|
return res;
|
|
}
|
|
|
|
//测试后EL
|
|
private string ELAfterTestSql(string lot)
|
|
{
|
|
string sql = @"SELECT [serial_nbr]
|
|
,[wks_id]
|
|
,[wks_visit_date]
|
|
,[el_grade]
|
|
,[process_code]
|
|
,[el_path]
|
|
FROM [mes_level2_iface].[dbo].[el] el
|
|
where [process_code]='HEL'
|
|
and el.serial_nbr='" + lot + "'";
|
|
return sql;
|
|
}
|
|
|
|
public IEnumerable<dynamic> ELAfterTest(string lot)
|
|
{
|
|
IEnumerable<dynamic> res = null;
|
|
using (var conn = Dpperhelper.OpenSqlConnection())
|
|
{
|
|
res = conn.Query(ELAfterTestSql(lot));
|
|
}
|
|
return res;
|
|
}
|
|
|
|
//层压前EL
|
|
//增加是否返修add by xue lei on 2018-7-31
|
|
private string ELBeforeLayupSql(string lot)
|
|
{
|
|
string sql = @"SELECT [serial_nbr]
|
|
,[wks_id]
|
|
,[wks_visit_date]
|
|
,[el_grade]
|
|
,[process_code]
|
|
,[el_path]
|
|
,case ( select count(*) from mes_main.dbo.qc_visit as a where a.visit_type='M' and wks_id = 'QC' and serial_nbr =el.serial_nbr )
|
|
when 0 then 'N'
|
|
else 'Y' end
|
|
isRepair
|
|
FROM [mes_level2_iface].[dbo].[el] el
|
|
where el.[process_code]='QEL'
|
|
and el.serial_nbr='" + lot + "'";
|
|
return sql;
|
|
}
|
|
|
|
public IEnumerable<dynamic> ELBeforeLayup(string lot)
|
|
{
|
|
IEnumerable<dynamic> res = null;
|
|
using (var conn = Dpperhelper.OpenSqlConnection())
|
|
{
|
|
res = conn.Query(ELBeforeLayupSql(lot));
|
|
}
|
|
return res;
|
|
}
|
|
|
|
//功率后EL
|
|
private string ELAfterIVSql(string lot)
|
|
{
|
|
string sql = @"SELECT [serial_nbr]
|
|
,[wks_id]
|
|
,[wks_visit_date]
|
|
,[el_grade]
|
|
,[process_code]
|
|
,[el_path]
|
|
FROM [mes_level2_iface].[dbo].[el] el
|
|
where el.[process_code]='HEL'
|
|
and el.serial_nbr='" + lot + "'";
|
|
return sql;
|
|
}
|
|
|
|
public IEnumerable<dynamic> ELAfterIV(string lot)
|
|
{
|
|
IEnumerable<dynamic> res = null;
|
|
using (var conn = Dpperhelper.OpenSqlConnection())
|
|
{
|
|
res = conn.Query(ELAfterIVSql(lot));
|
|
}
|
|
return res;
|
|
}
|
|
|
|
|
|
//清洗
|
|
private string CleanSql(string lot)
|
|
{
|
|
string sql = @"select
|
|
datediff(mi,
|
|
(select top 1 a.wks_visit_date from trace_workstation_visit a
|
|
inner join [mes_main].[dbo].[config_workstation] b on a.wks_id = b.wks_id
|
|
where b.process_code = 'M45' and a.serial_nbr = ab.serial_nbr order by a.wks_visit_date desc),twv.wks_visit_date) curingtime
|
|
,twv.wks_visit_date
|
|
,twv.wks_id/*机台号*/
|
|
,cw.process_code /*站点编号*/
|
|
,dp.descriptions/*站点名称*/
|
|
,dst.descriptions shift_type/*班次*/
|
|
,du.nickname
|
|
from
|
|
trace_workstation_visit twv /*记录机台*/
|
|
,assembly_status ab
|
|
,[mes_main].[dbo].[df_shift_type] dst
|
|
,[mes_auth].[dbo].[df_user] du
|
|
,[mes_main].[dbo].[config_workstation] cw
|
|
,[mes_main].[dbo].[df_processes] dp
|
|
where twv.serial_nbr=ab.serial_nbr
|
|
--and twv.serial_nbr='JYP171202X60000019'
|
|
and twv.serial_nbr=ab.serial_nbr
|
|
and twv.shift_type =dst.shift_type
|
|
and twv.operator=du.username
|
|
and twv.wks_id=cw.wks_id
|
|
and cw.process_code=dp.process_code
|
|
and ab.serial_nbr='" + lot + "' and dp.descriptions='清洗' order by twv.wks_visit_date desc";
|
|
return sql;
|
|
}
|
|
|
|
public IEnumerable<dynamic> CleanQueryInfo(string lot)
|
|
{
|
|
IEnumerable<dynamic> res = null;
|
|
using (var conn = Dpperhelper.OpenSqlConnection())
|
|
{
|
|
res = conn.Query(CleanSql(lot));
|
|
}
|
|
return res;
|
|
}
|
|
|
|
//层压后检验
|
|
private string QCAfterLayupSql(string lot)
|
|
{
|
|
string sql = @" select * ,(select nickname from [mes_auth].[dbo].[df_user] where username = a.operator) as username,
|
|
(select count(*) from mes_main.dbo.qc_visit where qc_visit.visit_type = 'H' and wks_id like '%CYHJ%' and serial_nbr = a.serial_nbr) as isHold
|
|
from[mes_main].[dbo].[trace_workstation_visit] as a where serial_nbr = '" + lot + "' and wks_id like '%CYHJ%' order by wks_visit_date desc; ";
|
|
return sql;
|
|
}
|
|
public IEnumerable<dynamic> QCAfterLayup(string lot)
|
|
{
|
|
IEnumerable<dynamic> res = null;
|
|
using (var conn = Dpperhelper.OpenSqlConnection())
|
|
{
|
|
res = conn.Query(QCAfterLayupSql(lot));
|
|
}
|
|
return res;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 工单达成情况
|
|
|
|
private string WOFinishStatusSql(string wo, string sales, string customer, string bt, string et)
|
|
{
|
|
string sql = @"exec mes_main.dbo.prWOFinishStatus ";
|
|
sql += string.IsNullOrEmpty(wo) ? " @wo=N''" : " @wo =N'" + wo + "'";
|
|
sql += string.IsNullOrEmpty(sales) ? " ,@sales=N''" : " ,@sales=N'" + sales + "'";
|
|
sql += string.IsNullOrEmpty(customer) ? " ,@customer=N''" : " ,@customer=N'" + customer + "'";
|
|
if (!string.IsNullOrEmpty(bt) && !string.IsNullOrEmpty(et))
|
|
{
|
|
sql += " ,@bt=N'" + bt + "',@et=N'" + et + "'";
|
|
}
|
|
else
|
|
{
|
|
sql += " ,@bt=N'',@et=N''";
|
|
}
|
|
return sql;
|
|
}
|
|
|
|
private string WOFinishStatusSql1(string wo, string sales, string customer, string bt, string et)
|
|
{
|
|
string sql = @"select CONVERT(varchar(100),a.create_date , 120) as create_date
|
|
,( select top 1 create_date from mes_main.dbo.assembly_status where workorder = a.workorder order by create_date ) firstlottime
|
|
,a.customer
|
|
,a.sale_order
|
|
,a.workorder
|
|
,( select top 1 serial_nbr from mes_main.dbo.assembly_status where workorder = a.workorder order by create_date ) firstlot
|
|
,a.product_code
|
|
,a.plan_qty
|
|
,(select count( a1.serial_nbr) from mes_main.dbo.[trace_workstation_visit] a1
|
|
inner join mes_main.dbo.config_workstation b on a1.wks_id = b.wks_id
|
|
inner join mes_main.dbo.assembly_status c on a1.serial_nbr = c.serial_nbr
|
|
where b.process_code = 'M15' and c.workorder = a.workorder) laminationqty
|
|
,a.cell_supplier_desc
|
|
,(select top 1 c.cell_uop from mes_main.dbo.trace_componnet_lot a2
|
|
inner join mes_main.dbo.config_workstation b on a2.wks_id = b.wks_id
|
|
inner join [mes_main].[dbo].[config_mat_cell] c on a2.part_nbr = c.part_nbr
|
|
inner join mes_main.dbo.assembly_status d on d.serial_nbr = a2.serial_nbr
|
|
where b.process_code = 'M10' and d.workorder = a.workorder ) cellgrade
|
|
,(select isnull(max( case report_grade when 'A' then ''+ CAST( gradeqty as nvarchar) end),'A:0')
|
|
+'|'+isnull(max(case report_grade when 'B' then ''+ CAST( gradeqty as nvarchar) end) ,'B:0')
|
|
+'|'+isnull(max(case report_grade when 'C' then '' + CAST( gradeqty as nvarchar) end) ,'C:0')
|
|
from
|
|
(
|
|
select a1.report_grade, count( a1.report_grade) gradeqty from mes_main.dbo.config_report_grade a1
|
|
inner join mes_main.dbo.assembly_status b on a1.exterior_grade = b.final_grade where b.serial_status = 'G' and b.workorder = a.workorder and a1.customer = a.customer
|
|
group by a1.report_grade
|
|
) t) gradeqty
|
|
,(select count(serial_nbr) from mes_main.dbo.assembly_status where serial_status ='S' and workorder = a.workorder) scrapqty
|
|
,(select cast(max(a3.pmax)as nvarchar)+'|'+cast(min(a3.pmax)as nvarchar)+'|'+ cast( avg(a3.pmax) as nvarchar) from mes_level2_iface.dbo.iv a3 inner join mes_main.dbo.assembly_status b on a3.serial_nbr = b.serial_nbr
|
|
where b.workorder = a.workorder) testpower
|
|
from mes_main.dbo.wo_mfg a where 1=1 ";
|
|
sql += string.IsNullOrEmpty(wo) ? "" : " and a.workorder = '" + wo + "'";
|
|
sql += string.IsNullOrEmpty(sales) ? "" : " and a.sale_order = '" + sales + "'";
|
|
sql += string.IsNullOrEmpty(customer) ? "" : " and a.customer = '" + customer + "'";
|
|
if (!string.IsNullOrEmpty(bt) && !string.IsNullOrEmpty(et))
|
|
{
|
|
sql += " and a.create_date between '" + bt + "' and '" + et + "' ";
|
|
}
|
|
return sql;
|
|
}
|
|
|
|
public IEnumerable<dynamic> WOFinishStatus(string wo, string sales, string customer, string bt, string et)
|
|
{
|
|
IEnumerable<dynamic> res = null;
|
|
using (var conn = Dpperhelper.OpenSqlConnection())
|
|
{
|
|
res = conn.Query(WOFinishStatusSql(wo, sales, customer, bt, et));
|
|
}
|
|
return res;
|
|
}
|
|
#endregion
|
|
|
|
#region 工单状态
|
|
//增加订单号查询条件 显示内容增加el等级 modify by xue lei on 2018-10-11
|
|
private string WOStatusSql(string wo, string sales)
|
|
{
|
|
string sql = @"select distinct a.serial_nbr,a.workorder,b.sale_order,convert(varchar(100), c.wks_visit_date,120) wks_visit_date
|
|
,e.descriptions process_code,a.exterior_grade,a.el_grade,a.final_grade,d.pmax from mes_main.dbo.assembly_status a
|
|
inner join mes_main.dbo.wo_mfg b on a.workorder = b.workorder
|
|
inner join mes_main.dbo.trace_workstation_visit c on a.serial_nbr = c.serial_nbr and c.wks_id like '%HJJ%'
|
|
left join [mes_level2_iface].[dbo].[iv] d on a.serial_nbr = d.serial_nbr
|
|
left join [mes_main].[dbo].[df_processes] e on a.process_code = e.process_code where 1=1";
|
|
sql += string.IsNullOrEmpty(wo) ? "" : " and a.workorder ='" + wo + "'";
|
|
sql += string.IsNullOrEmpty(sales) ? "" : " and b.sale_order = '" + sales + "'";
|
|
//where a.workorder = '" + wo+"'";
|
|
|
|
return sql;
|
|
}
|
|
//出货sql
|
|
private string ShipmentsReportSql(string StartDateTime, string EndDateTime, string WorkShop, string product_code, string power_grade, string containerno)
|
|
{
|
|
string sql = string.Empty;
|
|
string strWhere = string.Empty;
|
|
|
|
if (!string.IsNullOrEmpty(StartDateTime))
|
|
{
|
|
strWhere += " and g.shipmenttime >= '" + StartDateTime + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(EndDateTime))
|
|
{
|
|
strWhere += " and g.shipmenttime <= '" + EndDateTime + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(WorkShop))
|
|
{
|
|
strWhere += " and c.area_code = '" + WorkShop + "' ";
|
|
}
|
|
//if (!string.IsNullOrEmpty(station))
|
|
//{
|
|
// strWhere += "and JT.process_code = '" + station + "' ";
|
|
//}
|
|
if (!string.IsNullOrEmpty(product_code))
|
|
{
|
|
strWhere += " and a.product_code = '" + product_code + "' ";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(power_grade))
|
|
{
|
|
strWhere += " and a.power_grade = '" + power_grade + "' ";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(containerno) && containerno != "''" && containerno != "'Null'")
|
|
{
|
|
strWhere += " and e.containerno in( " + containerno + " ) ";
|
|
}
|
|
|
|
sql = @"
|
|
SELECT CONVERT(varchar(100), g.shipmenttime, 120) as outtime,h.sale_order as orderid,f.descriptions as area_code,
|
|
a.product_code,a.power_grade,e.containerno,
|
|
g.materialcompany,g.billlading,g.plateno,g.shipmentcarton,
|
|
CONVERT(varchar(100), a.pack_date, 120) as outtime,a.pallet_nbr,b.serial_nbr,d.voc,
|
|
d.isc,d.vpm,d.ipm,d.pmax,d.ff,a.current_grade
|
|
FROM mes_main.dbo.pack_pallets a
|
|
left join mes_main.dbo.assembly_status b
|
|
on a.pallet_nbr = b.pallet_nbr
|
|
left join mes_main.dbo.config_workstation c
|
|
on a.wks_id =c.wks_id
|
|
left join mes_level2_iface.dbo.iv d
|
|
on b.serial_nbr =d.serial_nbr
|
|
left join wh.dbo.tcontainerpallet e
|
|
on a.pallet_nbr =e.palletno
|
|
left join mes_main.dbo.df_areas f
|
|
on c.area_code =f.area_code
|
|
left join wh.dbo.tcontainer g
|
|
on e.containerno =g.containerno
|
|
LEFT JOIN mes_main.dbo.wo_mfg h
|
|
on h.workorder = b.workorder
|
|
where 1=1 " + strWhere + @"";
|
|
return sql;
|
|
}
|
|
|
|
//出货datatable
|
|
public DataTable ShipmentsReportDT(string StartDateTime, string EndDateTime, string WorkShop, string product_code, string power_grade, string containerno)
|
|
{
|
|
return dbhelp.ExecuteDataTable(ShipmentsReportSql(StartDateTime, EndDateTime, WorkShop, product_code, power_grade, containerno), null);
|
|
}
|
|
//生产在制统计sql
|
|
private string StationNbrAndGoingSql(string StartDateTime, string EndDateTime, string WorkShop, string Station, string WorkOrder, string SaleOrder,string WorkTime)
|
|
{
|
|
string sql = string.Empty;
|
|
string strWhere = string.Empty;
|
|
|
|
if (!string.IsNullOrEmpty(StartDateTime))
|
|
{
|
|
strWhere += " and a.wks_visit_date >= '" + StartDateTime + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(EndDateTime))
|
|
{
|
|
strWhere += " and a.wks_visit_date <= '" + EndDateTime + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(WorkShop))
|
|
{
|
|
strWhere += "and b.area_code = '" + WorkShop + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(Station))
|
|
{
|
|
strWhere += "and b.process_code = '" + Station + "' ";
|
|
}
|
|
|
|
//if (!string.IsNullOrEmpty(wks))
|
|
//{
|
|
// strWhere += " and a.wks_id = '" + wks + "' ";
|
|
//}
|
|
|
|
if (!string.IsNullOrEmpty(WorkOrder))
|
|
{
|
|
strWhere += " and f.workorder = '" + WorkOrder + "' ";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(SaleOrder))
|
|
{
|
|
strWhere += " and f.sale_order = '" + SaleOrder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(WorkTime))
|
|
{
|
|
strWhere += " and a.shift_type= '" + WorkTime + "' ";
|
|
}
|
|
|
|
sql = @"select FA.process_code,FA.descriptions,FA.workshop,FA.station_nbr,FB.going_nbr from
|
|
(
|
|
SELECT
|
|
e.descriptions as workshop,
|
|
e.area_code,
|
|
b.process_code ,
|
|
d.descriptions,
|
|
COUNT(distinct a.serial_nbr)as station_nbr
|
|
FROM (select distinct serial_nbr,wks_id,shift_type,max(wks_visit_date)as wks_visit_date
|
|
from mes_main.dbo.trace_workstation_visit
|
|
group by serial_nbr,wks_id,shift_type) a
|
|
LEFT join mes_main.dbo.config_workstation b
|
|
on a.wks_id = b.wks_id
|
|
LEFT JOIN mes_main.dbo.assembly_status c
|
|
on a.serial_nbr =c.serial_nbr
|
|
LEFT JOIN mes_main.dbo.df_processes d
|
|
on b.process_code = d.process_code
|
|
left join mes_main.dbo.df_areas e
|
|
on b.area_code= e.area_code
|
|
LEFT JOIN mes_main.DBO.wo_mfg f
|
|
ON f.workorder = c.workorder
|
|
where 1=1 " + strWhere + @"
|
|
group by b.process_code,b.area_code,d.descriptions,e.descriptions,e.area_code
|
|
--order by RIGHT(b.process_code,2)
|
|
)FA
|
|
LEFT JOIN
|
|
(
|
|
select COUNT(zzsl.serial_nbr) as going_nbr,zzsl.ZZZD,zzsl.area_code from
|
|
(
|
|
select a.serial_nbr,MAX(a.wks_visit_date) as wks_visit_date,max(g.process_code) AS ZZZD,b.area_code
|
|
from mes_main.dbo.trace_workstation_visit a
|
|
left join mes_main.dbo.assembly_status e
|
|
on a.serial_nbr = e.serial_nbr
|
|
left join mes_main.dbo.config_products c
|
|
on e.product_code = c.product_code
|
|
left join mes_main.dbo.config_workstation b
|
|
on a.wks_id = b.wks_id
|
|
left join mes_main.dbo.config_process d
|
|
on c.process_group_id = d.process_group_id
|
|
and e.process_code = d.process_code
|
|
left join mes_main.dbo.config_process g
|
|
on c.process_group_id = g.process_group_id
|
|
and g.process_idx-1 = d.process_idx
|
|
LEFT JOIN mes_main.DBO.wo_mfg f
|
|
ON f.workorder = e.workorder
|
|
where 1=1 " + strWhere + @"
|
|
group by a.serial_nbr,b.area_code
|
|
)zzsl
|
|
group by zzsl.ZZZD,zzsl.area_code
|
|
)FB
|
|
ON FA.process_code = FB.ZZZD and FA.area_code = FB.area_code
|
|
order by RIGHT(FA.process_code,2) ";
|
|
return sql;
|
|
}
|
|
|
|
//生产在制统计datatable
|
|
public DataTable StationNbrAndGoingDT(string StartDateTime, string EndDateTime, string WorkShop, string Station, string WorkOrder, string SaleOrder,string WorkTime)
|
|
{
|
|
return dbhelp.ExecuteDataTable(StationNbrAndGoingSql(StartDateTime, EndDateTime, WorkShop, Station, WorkOrder, SaleOrder,WorkTime), null);
|
|
}
|
|
//组件产能
|
|
|
|
//生产在制详细sql
|
|
private string StationDetailedSql(string StartDateTime, string EndDateTime, string WorkShop, string Station, string Workorder,string Machine, string Saleorder, string WorkTime)
|
|
{
|
|
string sql = string.Empty;
|
|
string strWhere = string.Empty;
|
|
|
|
if (!string.IsNullOrEmpty(StartDateTime))
|
|
{
|
|
strWhere += " and GZ.wks_visit_date >= '" + StartDateTime + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(EndDateTime))
|
|
{
|
|
strWhere += " and GZ.wks_visit_date <= '" + EndDateTime + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(WorkShop))
|
|
{
|
|
strWhere += "and JT.area_code = '" + WorkShop + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(Station))
|
|
{
|
|
strWhere += "and JT.process_code = '" + Station + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(Workorder))
|
|
{
|
|
strWhere += "and wo.workorder = '" + Workorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(Machine))
|
|
{
|
|
strWhere += "and JT.wks_id = '" + Machine + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(Saleorder))
|
|
{
|
|
strWhere += "and wo.saleorder = '" + Saleorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(WorkTime))
|
|
{
|
|
strWhere += "and GZ.shift_type = '" + WorkTime + "' ";
|
|
}
|
|
|
|
sql = @" select distinct GZ.serial_nbr,SM.workorder,GZ.wks_id,GZ.shift_type,JT.process_code,
|
|
CJ.descriptions,SM.el_grade,SM.final_grade,convert(varchar(100), MAX(GZ.wks_visit_date),120) as wks_visit_date,GZ.operator,
|
|
case when SM.process_code=JT.process_code then 'going'
|
|
when SM.process_code !=JT.process_code then 'OK' end AS ZT,
|
|
blms.MS
|
|
from mes_main.dbo.trace_workstation_visit GZ
|
|
left join mes_main.dbo.config_workstation JT
|
|
on GZ.wks_id =JT.wks_id
|
|
left join mes_main.dbo.df_areas CJ
|
|
on CJ.area_code =JT.area_code
|
|
left join mes_main.dbo.assembly_status SM
|
|
on GZ.serial_nbr = SM.serial_nbr
|
|
left join mes_main.dbo.wo_mfg wo
|
|
on SM.workorder = wo.workorder
|
|
left join
|
|
(select serial_nbr,MS =(select a.defect_type_name+';' from (select GZ.serial_nbr,BLMS.defect_type_name
|
|
from mes_main.dbo.trace_workstation_visit GZ
|
|
left join mes_main.dbo.defects BL
|
|
on BL.serial_nbr =GZ.serial_nbr
|
|
left join mes_main.dbo.config_defect_type BLMS
|
|
on BL.defect_type_id =BLMS.defect_type_id
|
|
group by GZ.serial_nbr,BLMS.defect_type_name) as a where serial_nbr =bl.serial_nbr
|
|
FOR XML PATH(''))
|
|
from (select GZ.serial_nbr, BLMS.defect_type_name
|
|
from mes_main.dbo.trace_workstation_visit GZ
|
|
left join mes_main.dbo.defects BL
|
|
on BL.serial_nbr =GZ.serial_nbr
|
|
left join mes_main.dbo.config_defect_type BLMS
|
|
on BL.defect_type_id =BLMS.defect_type_id
|
|
group by GZ.serial_nbr,BLMS.defect_type_name)as bl) blms
|
|
on GZ.serial_nbr=blms.serial_nbr
|
|
WHERE 1=1 " + strWhere + @"
|
|
GROUP BY GZ.serial_nbr,SM.workorder,GZ.wks_id,GZ.shift_type,CJ.descriptions,
|
|
SM.el_grade,SM.final_grade,GZ.operator,JT.process_code,SM.process_code,blms.MS
|
|
order by wks_visit_date
|
|
";
|
|
return sql;
|
|
}
|
|
|
|
//生产在制详细datatable
|
|
public DataTable StationDetailedDT(string StartDateTime, string EndDateTime, string WorkShop, string Station, string Workorder, string Machine,string Saleorder,string WorkTime)
|
|
{
|
|
return dbhelp.ExecuteDataTable(StationDetailedSql(StartDateTime, EndDateTime, WorkShop, Station, Workorder,Machine,Saleorder,WorkTime), null);
|
|
}
|
|
|
|
|
|
public DataTable WOStatusDT(string wo, string sales)
|
|
{
|
|
return dbhelp.ExecuteDataTable(WOStatusSql(wo, sales), null);
|
|
}
|
|
public IEnumerable<dynamic> WOStatus(string wo, string sales)
|
|
{
|
|
IEnumerable<dynamic> res = null;
|
|
using (var conn = Dpperhelper.OpenSqlConnection())
|
|
{
|
|
res = conn.Query(WOStatusSql(wo, sales));
|
|
}
|
|
return res;
|
|
}
|
|
#endregion
|
|
|
|
#region 包装删除记录
|
|
private string PackDelHistoryQueryInfoSql(string lot)
|
|
{
|
|
string sql = @"SELECT
|
|
[aiid]
|
|
,[pallet_nbr]/*托盘编码*/
|
|
,convert(varchar(100),del_time,120) as del_time /*删除时间*/
|
|
,[operator]/*删除人员*/
|
|
,[machine_name]/*计算机名称*/
|
|
,[wks_id]
|
|
FROM [mes_main].[dbo].[pallets_deleted_hist]
|
|
where [pallet_nbr]='" + Convert.ToString(lot) + "'";
|
|
|
|
return sql;
|
|
}
|
|
public DataTable PackDelHistoryQueryInfoDT(string lot)
|
|
{
|
|
return dbhelp.ExecuteDataTable(PackDelHistoryQueryInfoSql(lot), null);
|
|
}
|
|
public IEnumerable<dynamic> PackDelHistoryQueryInfo(string lot)
|
|
{
|
|
IEnumerable<dynamic> res = null;
|
|
using (var conn = Dpperhelper.OpenSqlConnection())
|
|
{
|
|
res = conn.Query(PackDelHistoryQueryInfoSql(lot));
|
|
}
|
|
return res;
|
|
}
|
|
#endregion
|
|
|
|
#region 工单各站点在制
|
|
private string WOprocessQueryInfoSql(string wo)
|
|
{
|
|
string sql = @"select FA.descriptions site,FB.going_nbr module,FA.workshop areas,FA.workorder wo from
|
|
(
|
|
SELECT
|
|
e.descriptions as workshop,
|
|
e.area_code,
|
|
b.process_code ,
|
|
d.descriptions,
|
|
f.workorder
|
|
FROM (select distinct serial_nbr,wks_id,shift_type,max(wks_visit_date)as wks_visit_date
|
|
from mes_main.dbo.trace_workstation_visit
|
|
group by serial_nbr,wks_id,shift_type) a
|
|
-- left join [mes_main].[dbo].[df_shift_type] time
|
|
-- on a.shift_type=time.shift_type
|
|
LEFT join mes_main.dbo.config_workstation b
|
|
on a.wks_id = b.wks_id
|
|
LEFT JOIN mes_main.dbo.assembly_status c
|
|
on a.serial_nbr =c.serial_nbr
|
|
LEFT JOIN mes_main.dbo.df_processes d
|
|
on b.process_code = d.process_code
|
|
left join mes_main.dbo.df_areas e
|
|
on b.area_code= e.area_code
|
|
LEFT JOIN mes_main.DBO.wo_mfg f
|
|
ON f.workorder = c.workorder
|
|
where 1=1 and f.workorder = '" + Convert.ToString(wo) + @"'
|
|
group by b.process_code,d.descriptions,e.descriptions,e.area_code,f.workorder
|
|
--order by RIGHT(b.process_code,2)
|
|
)FA
|
|
LEFT JOIN
|
|
(
|
|
select COUNT(zzsl.serial_nbr) as going_nbr,zzsl.ZZZD,zzsl.area_code from
|
|
(
|
|
select a.serial_nbr,MAX(a.wks_visit_date) as wks_visit_date,max(g.process_code) AS ZZZD,b.area_code
|
|
from (select serial_nbr,MAX(wks_visit_date) as wks_visit_date
|
|
from mes_main.dbo.trace_workstation_visit
|
|
group by serial_nbr) a
|
|
left join mes_main.dbo.trace_workstation_visit h
|
|
on a.serial_nbr = h.serial_nbr and a.wks_visit_date = h.wks_visit_date
|
|
--left join [mes_main].[dbo].[df_shift_type] time
|
|
-- on a.shift_type=time.shift_type
|
|
left join mes_main.dbo.assembly_status e
|
|
on a.serial_nbr = e.serial_nbr
|
|
left join mes_main.dbo.config_products c
|
|
on e.product_code = c.product_code
|
|
left join mes_main.dbo.config_workstation b
|
|
on h.wks_id = b.wks_id
|
|
left join mes_main.dbo.config_process d
|
|
on c.process_group_id = d.process_group_id
|
|
and e.process_code = d.process_code
|
|
left join mes_main.dbo.config_process g
|
|
on c.process_group_id = g.process_group_id
|
|
and g.process_idx-1 = d.process_idx
|
|
LEFT JOIN mes_main.DBO.wo_mfg f
|
|
ON f.workorder = e.workorder
|
|
where 1=1 and f.workorder = '" + Convert.ToString(wo) + @"'
|
|
group by a.serial_nbr,b.area_code
|
|
)zzsl
|
|
group by zzsl.ZZZD,zzsl.area_code
|
|
)FB
|
|
ON FA.process_code = FB.ZZZD and FA.area_code = FB.area_code
|
|
where FB.going_nbr is not null
|
|
order by RIGHT(FA.process_code,2)";
|
|
|
|
return sql;
|
|
}
|
|
public DataTable WOprocessQueryInfoDT(string wo)
|
|
{
|
|
return dbhelp.ExecuteDataTable(WOprocessQueryInfoSql(wo), null);
|
|
}
|
|
public IEnumerable<dynamic> WOprocessQueryInfo(string wo)
|
|
{
|
|
IEnumerable<dynamic> res = null;
|
|
using (var conn = Dpperhelper.OpenSqlConnection())
|
|
{
|
|
res = conn.Query(WOprocessQueryInfoSql(wo));
|
|
}
|
|
return res;
|
|
}
|
|
#endregion
|
|
|
|
#region 各站点产能
|
|
public DataTable SitecapacityQueryInfo(string bt, string et, string lot, string workshop, string status)
|
|
{
|
|
return dbhelp.ExecuteDataTable(SitecapacitySql(bt, et, lot, workshop, status), null);
|
|
}
|
|
|
|
private string SitecapacitySql(string bt, string et, string lot, string workshop, string status)
|
|
{
|
|
string sql = @"SELECT
|
|
CASE WHEN HOUR(create_time)>=0 AND HOUR(create_time)<2 THEN '00-02'
|
|
WHEN HOUR(create_time)>1 AND HOUR(create_time)<4 THEN '02-04'
|
|
WHEN HOUR(create_time)>3 AND HOUR(create_time)<6 THEN '04-06'
|
|
WHEN HOUR(create_time)>5 AND HOUR(create_time)<8 THEN '06-08'
|
|
WHEN HOUR(create_time)>7 AND HOUR(create_time)<10 THEN '08-10'
|
|
WHEN HOUR(create_time)>9 AND HOUR(create_time)<12 THEN '10-12'
|
|
WHEN HOUR(create_time)>11 AND HOUR(create_time)<14 THEN '12-14'
|
|
WHEN HOUR(create_time)>13 AND HOUR(create_time)<16 THEN '14-16'
|
|
WHEN HOUR(create_time)>15 AND HOUR(create_time)<18 THEN '16-18'
|
|
WHEN HOUR(create_time)>17 AND HOUR(create_time)<20 THEN '18-20'
|
|
WHEN HOUR(create_time)>19 AND HOUR(create_time)<22 THEN '20-22'
|
|
WHEN HOUR(create_time)>21 AND HOUR(create_time)<24 THEN '22-24'
|
|
END times,
|
|
COUNT( CASE WHEN worksite='M10' THEN 1 END) AS HJ,
|
|
COUNT( CASE WHEN worksite='M15' THEN 1 END) AS DC,
|
|
COUNT( CASE WHEN worksite='M30' THEN 1 END) AS CY,
|
|
COUNT( CASE WHEN worksite='M45' THEN 1 END) AS ZK,
|
|
COUNT( CASE WHEN worksite='M70' THEN 1 END) AS QJ,
|
|
COUNT( CASE WHEN worksite='M75' THEN 1 END) AS BZ
|
|
FROM js_mes.rt_worksite_common
|
|
where create_time>='" + bt + "' and create_time<='" + et + "' GROUP BY times;";
|
|
//sql += String.IsNullOrEmpty(lot) ? "" : " and qcv.[serial_nbr] LIKE '" + lot + "%'";
|
|
//sql += String.IsNullOrEmpty(workshop) ? "" : " AND wo.[area_code] = '" + workshop + "' ";
|
|
//sql += String.IsNullOrEmpty(status) ? "" : " AND qcv.[visit_type] = '" + status + "'";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 库存
|
|
public DataTable InventoryDT(string locationname, string name)
|
|
{
|
|
return dbhelp.ExecuteDataTable(InventorySql(locationname, name), null);
|
|
}
|
|
|
|
public string InventorySql(string locationname, string name)
|
|
{
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(locationname))
|
|
{
|
|
strWhere += " and a.locationname = '" + locationname + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(name))
|
|
{
|
|
strWhere += " and b.name = '" + name + "' ";
|
|
}
|
|
string sql = @"SELECT b.name,a.locationname,b.type,h.sale_order as orders,
|
|
max(e.powergrade) as powergrade,h.busbar_type_desc as sanshu,h.product_code as mpxh,h.pallet_qty as pall_qty,
|
|
COUNT(distinct(d.palletno)) as contqty_pall,count(g.schedule_nbr) as contqty_lot,(count(g.schedule_nbr)*max(e.powergrade))*0.000001 as countmw,
|
|
h.frame_type_desc as frame_type_desc,h.jbox_type_desc as jbox_type_desc,h.final_grade as gread,d.containerno
|
|
FROM [wh].[dbo].[tstoragelocation] a
|
|
left join wh.dbo.tstock b
|
|
on a.stockid =b.id
|
|
left join wh.dbo.tstockinlog c
|
|
on a.id =c.storagelocationid
|
|
left join wh.dbo.tcontainerpallet d
|
|
on c.palletno=d.palletno
|
|
left join wh.dbo.tlocationcondition e
|
|
on c.storagelocationconditionid =e.id
|
|
left join mes_main.dbo.pack_pallets f
|
|
on d.palletno=f.pallet_nbr
|
|
left join mes_main.dbo.assembly_status g
|
|
on g.pallet_nbr= c.palletno
|
|
left join(select a.containerno,a.palletno,b.pallet_qty,wo.product_code,wo.sale_order,
|
|
max(cell.busbar_type_desc) as busbar_type_desc,max(frame.frame_type_desc) as frame_type_desc
|
|
,MAX(jbox.jbox_type_desc) as jbox_type_desc,c.final_grade
|
|
from wh.dbo.tcontainerpallet a
|
|
left join mes_main.dbo.pack_pallets b
|
|
on a.palletno =b.pallet_nbr
|
|
left join mes_main.dbo.assembly_status c
|
|
on b.pallet_nbr = c.pallet_nbr and c.pack_seq = '1'
|
|
left join mes_main.dbo.trace_componnet_lot d
|
|
on c.serial_nbr =d.serial_nbr
|
|
left join mes_main.dbo.config_mat_cell cell
|
|
on d.part_nbr =cell.part_nbr and d.part_type='CELL'
|
|
left join mes_main.dbo.config_mat_frame frame
|
|
on d.part_nbr =frame.part_nbr
|
|
left join mes_main.dbo.config_mat_jbox jbox
|
|
on d.part_nbr =jbox.part_nbr
|
|
left join mes_main.dbo.wo_mfg wo
|
|
on c.workorder=wo.workorder
|
|
WHERE a.createtime in (select min(createtime) from wh.dbo.tcontainerpallet a group by a.containerno)
|
|
group by a.containerno,a.palletno,b.pallet_qty,wo.product_code,wo.sale_order,c.final_grade)h
|
|
on d.containerno = h.containerno
|
|
where c.status in('2','4')
|
|
--and d.containerno is not null
|
|
" + strWhere + @"
|
|
group by a.locationname,b.type,b.name,d.containerno,h.sale_order,
|
|
h.busbar_type_desc,h.jbox_type_desc,h.frame_type_desc,h.product_code,h.pallet_qty,h.final_grade";
|
|
//sql += String.IsNullOrEmpty(lot) ? "" : " and qcv.[serial_nbr] LIKE '" + lot + "%'";
|
|
//sql += String.IsNullOrEmpty(workshop) ? "" : " AND wo.[area_code] = '" + workshop + "' ";
|
|
//sql += String.IsNullOrEmpty(status) ? "" : " AND qcv.[visit_type] = '" + status + "'";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 库存JY
|
|
public DataTable InventoryJYDT(string locationname, string name)
|
|
{
|
|
return dbhelp.ExecuteDataTable(InventoryJYSql(locationname, name), null);
|
|
}
|
|
|
|
public string InventoryJYSql(string locationname, string name)
|
|
{
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(locationname))
|
|
{
|
|
strWhere += " and b.locationname = '" + locationname + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(name))
|
|
{
|
|
strWhere += " and c.name = '" + name + "' ";
|
|
}
|
|
string sql = @"
|
|
SELECT
|
|
c.name,b.locationname,e.sale_order,k.containerno,
|
|
case
|
|
when k.status ='complete' then '满柜'
|
|
else '半柜'
|
|
end isfulltank,
|
|
d.power_grade,cell.busbar_type_desc,e.product_code,
|
|
--f.pallet_qty,COUNT(distinct a.palletno)as pall_qty,
|
|
COUNT(d.serial_nbr) contqty,SUM(d.power_grade)*0.000001 as countmw
|
|
,frame.frame_type_desc,jbox.jbox_type_desc,d.final_grade,'' BJZT
|
|
FROM [wh].[dbo].[tstockinlog] a
|
|
left join [wh].[dbo].[tstoragelocation] b
|
|
on a.storagelocationid = b.id
|
|
left join wh.dbo.tstock c
|
|
on b.stockid =c.id
|
|
left join mes_main.dbo.assembly_status d
|
|
on d.pallet_nbr = a.palletno
|
|
left join mes_main.dbo.wo_mfg e
|
|
on e.workorder = d.workorder
|
|
left join mes_main.dbo.pack_pallets f
|
|
on a.palletno = f.pallet_nbr
|
|
left join mes_level2_iface.dbo.iv g
|
|
on g.serial_nbr = d.serial_nbr
|
|
|
|
left join wh.dbo.tcontainerpallet k
|
|
on a.palletno=k.palletno
|
|
|
|
left join mes_main.dbo.trace_componnet_lot h
|
|
on h.serial_nbr =d.serial_nbr and h.part_nbr='CELL'
|
|
left join mes_main.dbo.trace_componnet_lot I
|
|
on h.serial_nbr =d.serial_nbr and h.part_nbr='JBOX'
|
|
left join mes_main.dbo.trace_componnet_lot J
|
|
on h.serial_nbr =d.serial_nbr and h.part_nbr='BKSHEET'
|
|
left join mes_main.dbo.config_mat_cell cell
|
|
on h.part_nbr =cell.part_nbr
|
|
left join mes_main.dbo.config_mat_frame frame
|
|
on I.part_nbr =frame.part_nbr
|
|
left join mes_main.dbo.config_mat_jbox jbox
|
|
on J.part_nbr =jbox.part_nbr
|
|
where a.status in('2','4') " + strWhere + @"
|
|
group by c.name,b.locationname,d.power_grade,d.final_grade,e.sale_order,f.pallet_qty,e.product_code,k.containerno
|
|
,cell.busbar_type_desc,frame.frame_type_desc,jbox.jbox_type_desc,k.status";
|
|
//sql += String.IsNullOrEmpty(lot) ? "" : " and qcv.[serial_nbr] LIKE '" + lot + "%'";
|
|
//sql += String.IsNullOrEmpty(workshop) ? "" : " AND wo.[area_code] = '" + workshop + "' ";
|
|
//sql += String.IsNullOrEmpty(status) ? "" : " AND qcv.[visit_type] = '" + status + "'";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 库存详细JY
|
|
public DataTable InventoryDetailedJYDT(string locationname, string name)
|
|
{
|
|
return dbhelp.ExecuteDataTable(InventoryDetailedbJYSql(locationname, name), null);
|
|
}
|
|
|
|
public string InventoryDetailedbJYSql(string locationname, string name)
|
|
{
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(locationname))
|
|
{
|
|
strWhere += " and kw.locationname = '" + locationname + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(name))
|
|
{
|
|
strWhere += " and ck.name = '" + name + "' ";
|
|
}
|
|
string sql = @"
|
|
SELECT ast.[pallet_nbr]/*托盘编码*/
|
|
,wh.containerno as container_nbr/*柜号*/
|
|
,ast.[serial_nbr] /*组件序列号*/
|
|
,ast.[workorder]/*工单号*/
|
|
,ast.[power_grade]/*功率档位*/
|
|
,ast.current_grade/*电流档位*/
|
|
,ast.[product_code]/*装配件号*/
|
|
,ast.[el_grade]/*EL等级*/
|
|
,ast.[final_grade]/*外观等级*/
|
|
,CONVERT(varchar(100), ppk.[pack_date], 120) as pack_date/*封箱时间*/
|
|
,cpp.[descriptions]/*功率组*/
|
|
,dps.[pallet_status_desc]/*是否入库*/
|
|
,dst.[descriptions] shift_type/*班次*/
|
|
, iv.[pmax]
|
|
,iv.[voc]
|
|
,iv.[isc]
|
|
,iv.[ff]
|
|
,iv.[vpm]
|
|
,iv.[ipm]
|
|
,iv.[rs]
|
|
,iv.[rsh]
|
|
,iv.[eff]
|
|
,iv.[env_temp]
|
|
,iv.[surf_temp]
|
|
,iv.[temp]
|
|
,iv.[ivfile_path]
|
|
,ast.[pack_seq]
|
|
,ppk.[check_nbr]
|
|
,ms.[descriptions] as cell_supplier/*电池片供应商*/
|
|
,'' /*电池片档位*/
|
|
,[cell_uop] /*电池片效率*/
|
|
,iv.[pmax]/(cast(REPLACE(cp.[cell_qty],'W','') as float)*cast(REPLACE([cell_uop],'W','') as float)) fff /*转换效率*/
|
|
--,cp.[cell_qty]
|
|
,ab.[eva_supplier_code]/*EVA供应商*/
|
|
,cmeva.[eva_thickness] /*EVA规格*/
|
|
,ab.[eva_lot_nbr]/*EVA批号*/
|
|
,ab.[bks_supplier_code]/*背板供应商*/
|
|
,cmbks.[bks_thickness] /*bks规格*/
|
|
,ab.[bks_lot_nbr]/*背板批号*/
|
|
,ab.[glass_supplier_code]/*玻璃供应商*/
|
|
,cmglass.glass_thickness_desc /*玻璃规格*/
|
|
,ab.[glass_lot_nbr]/*电池批号*/
|
|
,ab.[jbox_supplier_code]/*接线盒供应商*/
|
|
,cmjbox.jbox_model_desc/*型材规格*/
|
|
,ab.[jbox_lot_nbr]/*接线盒批号*/
|
|
,ab.[frame_supplier_code]/*型材供应商*/
|
|
,cmframe.frame_thickness_desc/*型材规格*/
|
|
,ab.[frame_lot_nbr]/*型材批号*/
|
|
,wm.[customer]
|
|
,ppk.[product_code_original]
|
|
,ppk.container_nbr as batch
|
|
,CONVERT(varchar(100),iv.wks_visit_date, 120) as wks_visit_date/*测试时间*/
|
|
FROM[mes_main].[dbo].[assembly_status]
|
|
ast
|
|
left join[mes_level2_iface].[dbo].[iv]
|
|
iv
|
|
on ast.[serial_nbr]=iv.[serial_nbr]
|
|
left join[mes_main].[dbo].[pack_pallets]
|
|
ppk
|
|
on ast.[pallet_nbr]=ppk.[pallet_nbr]
|
|
left join[mes_main].[dbo].[df_pallet_status]
|
|
dps
|
|
on ppk.[pallet_status]=dps.[pallet_status]
|
|
left join[mes_main].[dbo].[df_shift_type]
|
|
dst
|
|
on ppk.[shift_type]=dst.[shift_type]
|
|
left join[mes_main].[dbo].[config_power_group]
|
|
cpp
|
|
on ppk.[power_grade_group_id]=cpp.[power_grade_group_id]
|
|
left join[mes_main].[dbo].[assembly_basis]
|
|
ab
|
|
on ast.[serial_nbr]=ab.[serial_nbr]
|
|
left join[mes_main].[dbo].[config_mat_cell]
|
|
cmc
|
|
on ab.[cell_part_nbr]=cmc.[part_nbr]
|
|
left join[mes_level4_iface].[dbo].[master_supplier]
|
|
ms
|
|
on ab.[cell_supplier_code]=ms.[supplier_code]
|
|
left join[mes_main].[dbo].[config_products]
|
|
cp
|
|
on ab.[product_code]=cp.[product_code]
|
|
left join[mes_main].[dbo].[wo_mfg]
|
|
wm
|
|
on ast.[workorder]=wm.[workorder]
|
|
left join[mes_main].[dbo].[config_mat_eva]
|
|
cmeva
|
|
on ab.[eva_part_nbr]=cmeva.[part_nbr]
|
|
left join[mes_main].[dbo].[config_mat_bks]
|
|
cmbks
|
|
on ab.[cell_part_nbr]=cmbks.[part_nbr]
|
|
left join[mes_main].[dbo].[config_mat_glass]
|
|
cmglass
|
|
on ab.glass_part_nbr=cmglass.part_nbr
|
|
left join[mes_main].[dbo].[config_mat_frame]
|
|
cmframe
|
|
on ab.frame_part_nbr=cmframe.part_nbr
|
|
left join[mes_main].[dbo].[config_mat_jbox]
|
|
cmjbox
|
|
on ab.jbox_part_nbr=cmjbox.part_nbr
|
|
left join wh.dbo.tcontainerpallet wh
|
|
on ast.pallet_nbr =wh.palletno
|
|
where 1=1 " + strWhere + "";
|
|
//sql += String.IsNullOrEmpty(lot) ? "" : " and qcv.[serial_nbr] LIKE '" + lot + "%'";
|
|
//sql += String.IsNullOrEmpty(workshop) ? "" : " AND wo.[area_code] = '" + workshop + "' ";
|
|
//sql += String.IsNullOrEmpty(status) ? "" : " AND qcv.[visit_type] = '" + status + "'";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 入库
|
|
public DataTable StorageDT(string bt, string et, string name, string locationname, string containerno, string palletno, string final_grade, string power_grade, string workorder, string saleorder, string area_code,string serial)
|
|
{
|
|
return dbhelp.ExecuteDataTable(StorageSql(bt, et, name, locationname, containerno, palletno, final_grade, power_grade, workorder, saleorder, area_code,serial), null);
|
|
}
|
|
|
|
public string StorageSql(string bt, string et, string name, string locationname, string containerno, string palletno, string final_grade, string power_grade, string workorder, string saleorder, string area_code,string serial)
|
|
{
|
|
// --and a.createtime>'' and a.createtime < '' and c.name = '' and b.locationname =''
|
|
//--and d.containerno in('') and a.palletno in('') and e.final_grade = '' and e.power_grade = ''
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and a.createtime >= '" + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and a.createtime <= '" + et + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(name))
|
|
{
|
|
strWhere += "and c.name = '" + name + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(locationname))
|
|
{
|
|
strWhere += " and b.locationname = '" + locationname + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(containerno) && containerno != "''" && containerno != "NULL")
|
|
{
|
|
strWhere += " and d.containerno in (" + containerno + ") ";
|
|
}
|
|
if (!string.IsNullOrEmpty(palletno) && palletno != "''" && palletno != "NULL")
|
|
{
|
|
strWhere += " and a.palletno in (" + palletno + ") ";
|
|
}
|
|
if (!string.IsNullOrEmpty(final_grade))
|
|
{
|
|
strWhere += " and e.final_grade = '" + final_grade + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(power_grade))
|
|
{
|
|
strWhere += " and e.power_grade = '" + power_grade + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and e.workorder = '" + workorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(saleorder))
|
|
{
|
|
strWhere += " and wo.sale_order = '" + saleorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(area_code))
|
|
{
|
|
strWhere += " and wo.area_code = '" + area_code + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(serial))
|
|
{
|
|
strWhere += " and e.serial_nbr = '" + serial + "' ";
|
|
}
|
|
string sql = @"SELECT ROW_NUMBER()OVER(ORDER BY a.createtime) as id,CONVERT(varchar(100),a.createtime, 23) as createtime,c.name,b.locationname,
|
|
wo.sale_order,wo.workorder,d.containerno,a.palletno,
|
|
e.serial_nbr,iv.voc,iv.isc,iv.vpm,iv.ipm,
|
|
iv.pmax,iv.ff,pack.current_grade,
|
|
wo.product_code,e.power_grade,
|
|
max(pro.busbar_type_desc) as busbar_type_desc,
|
|
--pack.pallet_qty,
|
|
max(e.final_grade) as final_grade,
|
|
max(pro.mod_spec_desc) as frame_type_desc
|
|
,max(jboox.jbox_type_desc) as jbox_type_desc,
|
|
case
|
|
when a.status= '-1' then '退库'
|
|
when a.status= '2' then '入库'
|
|
when a.status= '3' then '出货'
|
|
when a.status= '4' then '监装'
|
|
end as statuss,areas.descriptions
|
|
FROM [wh].[dbo].[tstockinlog] a
|
|
left join wh.dbo.tstoragelocation b
|
|
on a.storagelocationid = b.id
|
|
left join wh.dbo.tstock c
|
|
on b.stockid =c.id
|
|
left join wh.dbo.tcontainerpallet d
|
|
on a.palletno =d.palletno
|
|
left join mes_main.dbo.assembly_status e
|
|
on a.palletno = e.pallet_nbr
|
|
left join mes_main.dbo.trace_componnet_lot f
|
|
on e.serial_nbr = f.serial_nbr
|
|
left join mes_main.dbo.config_mat_jbox jboox
|
|
on f.part_nbr =jboox.part_nbr
|
|
--left join mes_main.dbo.config_mat_frame frame
|
|
--on f.part_nbr =frame.part_nbr
|
|
--left join mes_main.dbo.config_mat_cell cell
|
|
--on f.part_nbr =cell.part_nbr
|
|
left join mes_main.dbo.wo_mfg wo
|
|
on e.workorder =wo.workorder
|
|
left join mes_main.dbo.df_areas areas
|
|
on wo.area_code =areas.area_code
|
|
left join mes_main.dbo.pack_pallets pack
|
|
on a.palletno =pack.pallet_nbr
|
|
left join mes_main.dbo.config_products pro
|
|
on e.product_code =pro.product_code
|
|
left join mes_level2_iface.dbo.iv iv
|
|
on e.serial_nbr =iv.serial_nbr
|
|
where 1 = 1
|
|
--e.pack_seq ='1'
|
|
--and a.status != '3' and a.status != '-1'
|
|
" + strWhere + @"
|
|
group by a.createtime,c.name,b.locationname,d.containerno,a.palletno,
|
|
a.status,e.power_grade,wo.product_code,wo.sale_order,areas.descriptions
|
|
,pack.pallet_qty,wo.workorder,e.serial_nbr,iv.voc,iv.isc,iv.vpm,iv.ipm,
|
|
iv.pmax,iv.ff,pack.current_grade
|
|
ORDER BY a.createtime";
|
|
//sql += String.IsNullOrEmpty(lot) ? "" : " and qcv.[serial_nbr] LIKE '" + lot + "%'";
|
|
//sql += String.IsNullOrEmpty(workshop) ? "" : " AND wo.[area_code] = '" + workshop + "' ";
|
|
//sql += String.IsNullOrEmpty(status) ? "" : " AND qcv.[visit_type] = '" + status + "'";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
#region 收发存test
|
|
public DataTable receivedanddepositDT(string bt, string et, string name, string locationname, string sale_order)
|
|
{
|
|
return dbhelp.ExecuteDataTable(receivedanddepositSql(bt, et, name, locationname, sale_order), null);
|
|
}
|
|
|
|
public string receivedanddepositSql(string bt, string et, string name, string locationname, string sale_order)
|
|
{
|
|
// --and a.createtime>'' and a.createtime < '' and c.name = '' and b.locationname =''
|
|
//--and d.containerno in('') and a.palletno in('') and e.final_grade = '' and e.power_grade = ''
|
|
string strWhere = string.Empty;
|
|
string strWhereout = string.Empty;
|
|
string strWherereturn = string.Empty;
|
|
string strWheremovein = string.Empty;
|
|
string strWheremoveout = string.Empty;
|
|
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and c.createtime >= '" + bt + "' ";
|
|
strWhereout += " and m.shipmenttime > = '" + bt + "' ";
|
|
strWherereturn += " and returnlog.createtime >= '" + bt + "' ";
|
|
strWheremovein += "and movesin.createtime >= '" + bt + "' ";
|
|
strWheremoveout += " and movesout.createtime >= ' " + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and c.createtime <= '" + et + "' ";
|
|
strWhereout += " and m.shipmenttime <= '" + et + "' ";
|
|
strWherereturn += " and returnlog.createtime <= '" + et + "' ";
|
|
strWheremovein += " and movesin.createtime <= '" + et + "' ";
|
|
strWheremoveout += "and movesout.createtime <= '" + et + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(name))
|
|
{
|
|
strWhere += " and a.name = '" + name + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(locationname))
|
|
{
|
|
strWhere += " and b.locationname = '" + locationname + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(sale_order))
|
|
{
|
|
strWhere += " and n.sale_order = '" + sale_order + "' ";
|
|
}
|
|
|
|
string sql = @"
|
|
select a.name,b.locationname,n.sale_order as saleorder,j.containerno,max(d.product_code) as product_code,max(d.power_grade) as power_grade
|
|
,max(d.final_grade) as final_grade,max(e.mod_spec_desc) as mod_spec_desc,max(h.jbox_type_desc) as jbox_type_desc
|
|
,COUNT(c.palletno) as stockinnbr
|
|
,MAX(l.movein) as movein
|
|
,MAX(k.moveout) as moveout
|
|
,max(i.returnnbr) as returnnbr
|
|
,count(
|
|
case
|
|
when 1=1
|
|
and m.shipmenttime is not null
|
|
" + strWhereout + @"
|
|
then 1
|
|
end
|
|
) as shipnbr
|
|
from wh.dbo.tstock a
|
|
left join wh.dbo.tstoragelocation b
|
|
on a.id = b.stockid
|
|
join wh.dbo.tstockinlog c
|
|
on c.storagelocationid = b.id
|
|
left join mes_main.dbo.pack_pallets d
|
|
on c.palletno =d.pallet_nbr
|
|
left join mes_main.dbo.config_products e
|
|
on d.product_code =e.product_code
|
|
left join mes_main.dbo.assembly_status f
|
|
on d.pallet_nbr =f.pallet_nbr and f.pack_seq =d.pallet_qty
|
|
left join mes_main.dbo.trace_componnet_lot g
|
|
on f.serial_nbr =g.serial_nbr and g.part_type = 'JBOX'
|
|
left join mes_main.dbo.config_mat_jbox h
|
|
on h.part_nbr =g.part_nbr
|
|
left join (
|
|
SELECT returnlog.storagelocationid,COUNT(returnlog.pallet)as returnnbr
|
|
FROM wh.dbo.treturnstocklog returnlog
|
|
where 1=1 " + strWherereturn + @"
|
|
group by returnlog.storagelocationid) i
|
|
on b.id =i.storagelocationid
|
|
left join wh.dbo.tcontainerpallet j
|
|
on c.palletno =j.palletno
|
|
left join (
|
|
SELECT COUNT(movesout.pallet) as moveout,
|
|
movesout.oldstoragelocationid
|
|
FROM wh.dbo.tmovestocklog movesout
|
|
where 1=1 " + strWheremoveout + @"
|
|
group by movesout.oldstoragelocationid)k
|
|
on b.id=k.oldstoragelocationid
|
|
left join(
|
|
SELECT
|
|
COUNT(movesin.pallet) as movein,
|
|
movesin.newstoragelocationid
|
|
FROM wh.dbo.tmovestocklog movesin
|
|
where 1=1 " + strWheremovein + @"
|
|
group by movesin.newstoragelocationid)l
|
|
on b.id=l.newstoragelocationid
|
|
left join wh.dbo.tcontainer m
|
|
on j.containerno = m.containerno
|
|
left join mes_main.dbo.wo_mfg n
|
|
on n.workorder =f.workorder
|
|
where 1=1 " + strWhere + @"
|
|
group by a.name,b.locationname,j.containerno,n.sale_order ";
|
|
//sql += String.IsNullOrEmpty(lot) ? "" : " and qcv.[serial_nbr] LIKE '" + lot + "%'";
|
|
//sql += String.IsNullOrEmpty(workshop) ? "" : " AND wo.[area_code] = '" + workshop + "' ";
|
|
//sql += String.IsNullOrEmpty(status) ? "" : " AND qcv.[visit_type] = '" + status + "'";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
#region 材料追溯
|
|
public DataTable MaterialTraceabilityDT(string lot_nbr, string orig_batch_nbr, string serial_nbr, string bt, string et, string wks_desc, string area_code)
|
|
{
|
|
return dbhelp.ExecuteDataTable(MaterialTraceabilitySql(lot_nbr, orig_batch_nbr, serial_nbr, bt, et, wks_desc, area_code), null);
|
|
}
|
|
|
|
public string MaterialTraceabilitySql(string lot_nbr, string orig_batch_nbr, string serial_nbr, string bt, string et, string wks_desc, string area_code)
|
|
{
|
|
// --and a.createtime>'' and a.createtime < '' and c.name = '' and b.locationname =''
|
|
//--and d.containerno in('') and a.palletno in('') and e.final_grade = '' and e.power_grade = ''
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(lot_nbr))
|
|
{
|
|
strWhere += " and a.lot_nbr = '" + lot_nbr + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(orig_batch_nbr))
|
|
{
|
|
strWhere += " and a.orig_batch_nbr = '" + orig_batch_nbr + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(serial_nbr))
|
|
{
|
|
strWhere += " and b.serial_nbr = '" + serial_nbr + "' ";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and a.create_date >= '" + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and a.create_date <= '" + et + "' ";
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(wks_desc))
|
|
{
|
|
strWhere += " and g.wks_desc = '" + wks_desc + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(area_code))
|
|
{
|
|
strWhere += " and g.area_code = '" + area_code + "' ";
|
|
}
|
|
|
|
// string sql = @"
|
|
//SELECT ROW_NUMBER()OVER(ORDER BY a.lot_nbr) as id,
|
|
//case
|
|
//when b.part_type = 'CELL' then '电池片'
|
|
//when b.part_type = 'EVA' then 'EVA'
|
|
//when b.part_type = 'EVA2' then '高透EVA'
|
|
//when b.part_type = 'GLASS' then '玻璃'
|
|
//when b.part_type = 'GLASS2' then '玻璃2'
|
|
//when b.part_type = 'BKSHEET' then '背板'
|
|
//when b.part_type = 'LFRAME' then '长型材'
|
|
//when b.part_type = 'SFRAME' then '短型材'
|
|
//when b.part_type = 'JBOX' then '接线盒'
|
|
//end as part_type,
|
|
//a.lot_nbr,a.orig_batch_nbr,b.serial_nbr,g.wks_desc,c.final_grade,
|
|
//case
|
|
// when (c.pallet_nbr IS NULL) then f.descriptions
|
|
// when (c.pallet_nbr IS not null and d.containerno IS null and e.palletno IS null)then '包装'
|
|
// when (c.pallet_nbr IS not null and d.containerno IS not null and e.palletno IS null)then '拼柜'
|
|
// when (c.pallet_nbr IS not null and e.status = '2')then '入库'
|
|
// when (c.pallet_nbr IS not null and e.status > '2')then '出货'
|
|
//end as statu,
|
|
//case
|
|
// when (c.pallet_nbr IS not NULL) then c.pallet_nbr
|
|
// else '无'
|
|
//end as pallet_nbr,
|
|
//case
|
|
// when (d.containerno IS not NULL) then d.containerno
|
|
// else '无'
|
|
//end as containerno,
|
|
//case
|
|
// when e.palletno IS not null then '是'
|
|
// else '否'
|
|
//end as isstock,
|
|
//case
|
|
// when e.status > '2' then '是'
|
|
// else '否'
|
|
//end as isshimp
|
|
//,CONVERT(varchar(100),a.create_date, 120) as create_date
|
|
// FROM mes_main.dbo.pack_material_lot a
|
|
// left join mes_main.dbo.trace_componnet_lot b
|
|
// on a.lot_nbr =b.lot_nbr
|
|
// left join mes_main.dbo.assembly_status c
|
|
// on b.serial_nbr =c.serial_nbr
|
|
// left join wh.dbo.tcontainerpallet d
|
|
// on c.pallet_nbr =d.palletno
|
|
// left join wh.dbo.tstockinlog e
|
|
// on (c.pallet_nbr =e.palletno and e.status>=2)
|
|
// left join mes_main.dbo.df_processes f
|
|
// on c.process_code =f.process_code
|
|
// left join mes_main.dbo.config_workstation g
|
|
// on b.wks_id = g.wks_id
|
|
// where c.serial_nbr is not null
|
|
// " + strWhere ;
|
|
//sql += String.IsNullOrEmpty(lot) ? "" : " and qcv.[serial_nbr] LIKE '" + lot + "%'";
|
|
//sql += String.IsNullOrEmpty(workshop) ? "" : " AND wo.[area_code] = '" + workshop + "' ";
|
|
//sql += String.IsNullOrEmpty(status) ? "" : " AND qcv.[visit_type] = '" + status + "'";
|
|
string sql = @"SELECT ROW_NUMBER()OVER(ORDER BY a.lot_nbr) as id,
|
|
case
|
|
when b.part_type = 'CELL' then '电池片'
|
|
when b.part_type = 'HUILIU' then '汇流条'
|
|
when b.part_type = 'HULIAN' then '互联条'
|
|
when b.part_type = 'Solder' then '助焊剂'
|
|
when b.part_type = 'EVA' then 'EVA'
|
|
when b.part_type = 'EVA3' then '白膜EVA'
|
|
when b.part_type = 'EVA2' then '高透EVA'
|
|
when b.part_type = 'GLASS' then '玻璃'
|
|
when b.part_type = 'GLASS2' then '玻璃2'
|
|
when b.part_type = 'BKSHEET' then '背板'
|
|
when b.part_type = 'LFRAME' then '长型材'
|
|
when b.part_type = 'SFRAME' then '短型材'
|
|
when b.part_type = 'JBOX' then '接线盒'
|
|
when b.part_type = 'JBOXGLUE' then '接线盒胶'
|
|
when b.part_type = 'ABGLUE' then 'AB胶'
|
|
when b.part_type = 'FRAMEGLUE' then '型材胶'
|
|
when b.part_type = 'GLUE' then '胶'
|
|
end as part_type,
|
|
a.supplier_lot,a.lot_nbr,a.orig_batch_nbr,b.serial_nbr,g.wks_desc,c.final_grade,
|
|
case
|
|
when (c.pallet_nbr IS NULL) then f.descriptions
|
|
when (c.pallet_nbr IS not null and d.containerno IS null and e.palletno IS null)then '包装'
|
|
when (c.pallet_nbr IS not null and d.containerno IS not null and e.palletno IS null)then '拼柜'
|
|
when (c.pallet_nbr IS not null and e.status = '2')then '入库'
|
|
when (c.pallet_nbr IS not null and e.status > '2')then '出货'
|
|
end as statu,
|
|
case
|
|
when (c.pallet_nbr IS not NULL) then c.pallet_nbr
|
|
else '无'
|
|
end as pallet_nbr,
|
|
case
|
|
when (d.containerno IS not NULL) then d.containerno
|
|
else '无'
|
|
end as containerno,
|
|
case
|
|
when e.palletno IS not null then '是'
|
|
else '否'
|
|
end as isstock,
|
|
case
|
|
when e.status > '2' then '是'
|
|
else '否'
|
|
end as isshimp
|
|
,CONVERT(varchar(100),a.create_date, 120) as create_date
|
|
FROM mes_main.dbo.pack_material_lot a
|
|
left join mes_main.dbo.trace_componnet_lot b
|
|
on a.lot_nbr =b.lot_nbr
|
|
left join mes_main.dbo.assembly_status c
|
|
on b.serial_nbr =c.serial_nbr
|
|
left join wh.dbo.tcontainerpallet d
|
|
on c.pallet_nbr =d.palletno
|
|
left join wh.dbo.tstockinlog e
|
|
on (c.pallet_nbr =e.palletno and e.status>=2)
|
|
left join mes_main.dbo.df_processes f
|
|
on c.process_code =f.process_code
|
|
left join mes_main.dbo.config_workstation g
|
|
on b.wks_id = g.wks_id
|
|
where c.serial_nbr is not null" + strWhere;
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
#region 工单条码登记表(原始版本)
|
|
public DataTable WorkLot2DT(string bt, string et, string workshop, string sale_order, string workorder)
|
|
{
|
|
return dbhelp.ExecuteDataTable(WorkLot2Sql(bt, et, workshop, sale_order, workorder), null);
|
|
}
|
|
|
|
public string WorkLot2Sql(string bt, string et, string workshop, string sale_order, string workorder)
|
|
{
|
|
// --and a.createtime>'' and a.createtime < '' and c.name = '' and b.locationname =''
|
|
//--and d.containerno in('') and a.palletno in('') and e.final_grade = '' and e.power_grade = ''
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and b.create_date > = '" + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and b.create_date < = '" + et + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workshop))
|
|
{
|
|
strWhere += " and a.area_code = '" + workshop + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(sale_order))
|
|
{
|
|
strWhere += " and a.sale_order = '" + sale_order + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and a.workorder = '" + workorder + "' ";
|
|
}
|
|
|
|
string sql = @"select a.sale_order,a.workorder,CONVERT(varchar(100), b.create_date, 120) as create_date,CONVERT(varchar(100), a.create_date, 120) as wo_create_date ,a.plan_qty,
|
|
--a.sn_qty,
|
|
cast(right(max(b.serial_nbr),5) as int)-cast(right(min(b.serial_nbr),5) as int)+1 sn_qty,
|
|
(a.plan_qty-a.sn_qty)as noqty,a.OEMcustomer,a.product_code,
|
|
min(b.serial_nbr)+'--'+
|
|
max(b.serial_nbr) as qujian
|
|
from mes_main.dbo.wo_mfg a
|
|
left join mes_main.dbo.assembly_status b
|
|
on a.workorder =b.workorder
|
|
where 1=1 " + strWhere + @"
|
|
group by a.workorder,a.sale_order,a.create_date,a.plan_qty,a.sn_qty,b.create_date
|
|
,a.OEMcustomer,a.product_code";
|
|
//sql += String.IsNullOrEmpty(lot) ? "" : " and qcv.[serial_nbr] LIKE '" + lot + "%'";
|
|
//sql += String.IsNullOrEmpty(workshop) ? "" : " AND wo.[area_code] = '" + workshop + "' ";
|
|
//sql += String.IsNullOrEmpty(status) ? "" : " AND qcv.[visit_type] = '" + status + "'";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
#region 工单条码登记表(山东客户版本)
|
|
public DataTable WorkLotDT(string bt, string et, string workshop, string sale_order, string workorder)
|
|
{
|
|
return dbhelp.ExecuteDataTable(WorkLotSql(bt, et, workshop, sale_order, workorder), null);
|
|
}
|
|
|
|
public string WorkLotSql(string bt, string et, string workshop, string sale_order, string workorder)
|
|
{
|
|
// --and a.createtime>'' and a.createtime < '' and c.name = '' and b.locationname =''
|
|
//--and d.containerno in('') and a.palletno in('') and e.final_grade = '' and e.power_grade = ''
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and b.create_date > = '" + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and b.create_date < = '" + et + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workshop))
|
|
{
|
|
strWhere += " and a.area_code = '" + workshop + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(sale_order))
|
|
{
|
|
strWhere += " and a.sale_order = '" + sale_order + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and a.workorder = '" + workorder + "' ";
|
|
}
|
|
|
|
string sql = @"select c.descriptions,a.sale_order,a.workorder,a.plan_qty,a.sn_qty,min(b.serial_nbr) start_serial,max(b.serial_nbr) end_serial,a.OEMcustomer,
|
|
CONVERT(varchar(100), b.create_date, 120) as create_date,CONVERT(varchar(100), a.create_date, 120) as wo_create_date ,
|
|
--(a.plan_qty-a.sn_qty)as noqty,
|
|
a.product_code
|
|
--min(b.serial_nbr)+'--'+
|
|
--max(b.serial_nbr) as qujian
|
|
from mes_main.dbo.wo_mfg a
|
|
left join mes_main.dbo.assembly_status b
|
|
on a.workorder =b.workorder
|
|
left join mes_main.dbo.df_areas c
|
|
on a.area_code = c.area_code
|
|
where 1=1 " + strWhere + @"
|
|
group by c.descriptions,a.workorder,a.sale_order,a.create_date,a.plan_qty,a.sn_qty,b.create_date
|
|
,a.OEMcustomer,a.product_code";
|
|
//sql += String.IsNullOrEmpty(lot) ? "" : " and qcv.[serial_nbr] LIKE '" + lot + "%'";
|
|
//sql += String.IsNullOrEmpty(workshop) ? "" : " AND wo.[area_code] = '" + workshop + "' ";
|
|
//sql += String.IsNullOrEmpty(status) ? "" : " AND qcv.[visit_type] = '" + status + "'";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
#region 工单达成情况
|
|
public DataTable WOFinishStatusDT(string wo, string sales, string customer, string bt, string et)
|
|
{
|
|
return dbhelp.ExecuteDataTable(WOFinishStatusSql(wo, sales, customer, bt, et), null);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region CTM
|
|
public DataTable FinalTestRoomDataDT(string bt, string et, string workshop, string workorder)
|
|
{
|
|
return dbhelp.ExecuteDataTable(FinalTestRoomDataSql(bt, et, workshop, workorder), null);
|
|
}
|
|
|
|
public string FinalTestRoomDataSql(string bt, string et, string workshop, string workorder)
|
|
{
|
|
string strWhere = string.Empty;
|
|
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and a.wks_visit_date >= '" + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and a.wks_visit_date < '" + et + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workshop))
|
|
{
|
|
strWhere += " and c.area_code = '" + workshop + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and b.workorder = '" + workorder + "' ";
|
|
}
|
|
|
|
string sql = @"SELECT fianl.workorder,fianl.PY,fianl.EDGL,fianl.PJGL
|
|
,cast(convert(DECIMAL(18,2),fianl.PJGL/fianl.EDGL*100) as varchar)+'%' as CTM,fianl.ZJSL
|
|
,fianl.[0W]
|
|
,fianl.[5W]
|
|
,fianl.[10W]
|
|
,fianl.[15W]
|
|
,fianl.[20W]
|
|
,fianl.[25W]
|
|
,fianl.[30W]
|
|
,fianl.[35W]
|
|
,fianl.[40W]
|
|
,fianl.[45W]
|
|
,fianl.[50W]
|
|
,fianl.[55W]
|
|
,fianl.[60W]
|
|
,fianl.[65W]
|
|
,fianl.[70W]
|
|
,fianl.[75W]
|
|
,fianl.[80W]
|
|
,fianl.[85W]
|
|
,fianl.[90W]
|
|
,fianl.[95W]
|
|
,fianl.[100W]
|
|
,fianl.[105W]
|
|
,fianl.[110W]
|
|
,fianl.[115W]
|
|
,fianl.[120W]
|
|
,fianl.[125W]
|
|
,fianl.[130W]
|
|
,fianl.[135W]
|
|
,fianl.[140W]
|
|
,fianl.[145W]
|
|
,fianl.[150W]
|
|
,fianl.[155W]
|
|
,fianl.[160W]
|
|
,fianl.[165W]
|
|
,fianl.[170W]
|
|
,fianl.[175W]
|
|
,fianl.[180W]
|
|
,fianl.[185W]
|
|
,fianl.[190W]
|
|
,fianl.[195W]
|
|
,fianl.[200W]
|
|
,fianl.[205W]
|
|
,fianl.[210W]
|
|
,fianl.[215W]
|
|
,fianl.[220W]
|
|
,fianl.[225W]
|
|
,fianl.[230W]
|
|
,fianl.[235W]
|
|
,fianl.[240W]
|
|
,fianl.[245W]
|
|
,fianl.[250W]
|
|
,fianl.[255W]
|
|
,fianl.[260W]
|
|
,fianl.[265W]
|
|
,fianl.[270W]
|
|
,fianl.[275W]
|
|
,fianl.[280W]
|
|
,fianl.[285W]
|
|
,fianl.[290W]
|
|
,fianl.[295W]
|
|
,fianl.[300W]
|
|
,fianl.[305W]
|
|
,fianl.[310W]
|
|
,fianl.[315W]
|
|
,fianl.[320W]
|
|
,fianl.[325W]
|
|
,fianl.[330W]
|
|
,fianl.[335W]
|
|
,fianl.[340W]
|
|
,fianl.[345W]
|
|
,fianl.[350W]
|
|
,fianl.[355W]
|
|
,fianl.[360W]
|
|
,fianl.[365W]
|
|
,fianl.[370W]
|
|
,fianl.[375W]
|
|
,fianl.[380W]
|
|
,fianl.[385W]
|
|
,fianl.[390W]
|
|
,fianl.[395W]
|
|
,fianl.[400W]
|
|
,fianl.[405W]
|
|
,fianl.[410W]
|
|
,fianl.[415W]
|
|
,fianl.[420W]
|
|
,fianl.[425W]
|
|
,fianl.[430W]
|
|
,fianl.[435W]
|
|
,fianl.[440W]
|
|
,fianl.[445W]
|
|
,fianl.[450W]
|
|
,fianl.[455W]
|
|
,fianl.[460W]
|
|
,fianl.[465W]
|
|
,fianl.[470W]
|
|
,fianl.[475W]
|
|
,fianl.[480W]
|
|
,fianl.[485W]
|
|
,fianl.[490W]
|
|
,fianl.[495W]
|
|
,fianl.[500W]
|
|
,fianl.[505W]
|
|
,fianl.[510W]
|
|
,fianl.[515W]
|
|
,fianl.[520W]
|
|
,fianl.[525W]
|
|
,fianl.[530W]
|
|
,fianl.[535W]
|
|
,fianl.[540W]
|
|
,fianl.[545W]
|
|
,fianl.[550W]
|
|
,fianl.[555W]
|
|
,fianl.[560W]
|
|
,fianl.[565W]
|
|
,fianl.[570W]
|
|
,fianl.[575W]
|
|
,fianl.[580W]
|
|
,fianl.[585W]
|
|
,fianl.[590W]
|
|
,fianl.[595W]
|
|
,cast(convert(DECIMAL(18,2),fianl.[0W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO0W
|
|
,cast(convert(DECIMAL(18,2),fianl.[5W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO5W
|
|
,cast(convert(DECIMAL(18,2),fianl.[10W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO10W
|
|
,cast(convert(DECIMAL(18,2),fianl.[15W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO15W
|
|
,cast(convert(DECIMAL(18,2),fianl.[20W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO20W
|
|
,cast(convert(DECIMAL(18,2),fianl.[25W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO25W
|
|
,cast(convert(DECIMAL(18,2),fianl.[30W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO30W
|
|
,cast(convert(DECIMAL(18,2),fianl.[35W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO35W
|
|
,cast(convert(DECIMAL(18,2),fianl.[40W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO40W
|
|
,cast(convert(DECIMAL(18,2),fianl.[45W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO45W
|
|
,cast(convert(DECIMAL(18,2),fianl.[50W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO50W
|
|
,cast(convert(DECIMAL(18,2),fianl.[55W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO55W
|
|
,cast(convert(DECIMAL(18,2),fianl.[60W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO60W
|
|
,cast(convert(DECIMAL(18,2),fianl.[65W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO65W
|
|
,cast(convert(DECIMAL(18,2),fianl.[70W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO70W
|
|
,cast(convert(DECIMAL(18,2),fianl.[75W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO75W
|
|
,cast(convert(DECIMAL(18,2),fianl.[80W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO80W
|
|
,cast(convert(DECIMAL(18,2),fianl.[85W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO85W
|
|
,cast(convert(DECIMAL(18,2),fianl.[90W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO90W
|
|
,cast(convert(DECIMAL(18,2),fianl.[95W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO95W
|
|
,cast(convert(DECIMAL(18,2),fianl.[100W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO100W
|
|
,cast(convert(DECIMAL(18,2),fianl.[105W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO105W
|
|
,cast(convert(DECIMAL(18,2),fianl.[110W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO110W
|
|
,cast(convert(DECIMAL(18,2),fianl.[115W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO115W
|
|
,cast(convert(DECIMAL(18,2),fianl.[120W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO120W
|
|
,cast(convert(DECIMAL(18,2),fianl.[125W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO125W
|
|
,cast(convert(DECIMAL(18,2),fianl.[130W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO130W
|
|
,cast(convert(DECIMAL(18,2),fianl.[135W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO135W
|
|
,cast(convert(DECIMAL(18,2),fianl.[140W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO140W
|
|
,cast(convert(DECIMAL(18,2),fianl.[145W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO145W
|
|
,cast(convert(DECIMAL(18,2),fianl.[150W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO150W
|
|
,cast(convert(DECIMAL(18,2),fianl.[155W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO155W
|
|
,cast(convert(DECIMAL(18,2),fianl.[160W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO160W
|
|
,cast(convert(DECIMAL(18,2),fianl.[165W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO165W
|
|
,cast(convert(DECIMAL(18,2),fianl.[170W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO170W
|
|
,cast(convert(DECIMAL(18,2),fianl.[175W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO175W
|
|
,cast(convert(DECIMAL(18,2),fianl.[180W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO180W
|
|
,cast(convert(DECIMAL(18,2),fianl.[185W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO185W
|
|
,cast(convert(DECIMAL(18,2),fianl.[190W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO190W
|
|
,cast(convert(DECIMAL(18,2),fianl.[195W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO195W
|
|
,cast(convert(DECIMAL(18,2),fianl.[200W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO200W
|
|
,cast(convert(DECIMAL(18,2),fianl.[205W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO205W
|
|
,cast(convert(DECIMAL(18,2),fianl.[210W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO210W
|
|
,cast(convert(DECIMAL(18,2),fianl.[215W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO215W
|
|
,cast(convert(DECIMAL(18,2),fianl.[220W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO220W
|
|
,cast(convert(DECIMAL(18,2),fianl.[225W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO225W
|
|
,cast(convert(DECIMAL(18,2),fianl.[230W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO230W
|
|
,cast(convert(DECIMAL(18,2),fianl.[235W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO235W
|
|
,cast(convert(DECIMAL(18,2),fianl.[240W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO240W
|
|
,cast(convert(DECIMAL(18,2),fianl.[245W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO245W
|
|
,cast(convert(DECIMAL(18,2),fianl.[250W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO250W
|
|
,cast(convert(DECIMAL(18,2),fianl.[255W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO255W
|
|
,cast(convert(DECIMAL(18,2),fianl.[260W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO260W
|
|
,cast(convert(DECIMAL(18,2),fianl.[265W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO265W
|
|
,cast(convert(DECIMAL(18,2),fianl.[270W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO270W
|
|
,cast(convert(DECIMAL(18,2),fianl.[275W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO275W
|
|
,cast(convert(DECIMAL(18,2),fianl.[280W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO280W
|
|
,cast(convert(DECIMAL(18,2),fianl.[285W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO285W
|
|
,cast(convert(DECIMAL(18,2),fianl.[290W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO290W
|
|
,cast(convert(DECIMAL(18,2),fianl.[295W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO295W
|
|
,cast(convert(DECIMAL(18,2),fianl.[300W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO300W
|
|
,cast(convert(DECIMAL(18,2),fianl.[305W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO305W
|
|
,cast(convert(DECIMAL(18,2),fianl.[310W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO310W
|
|
,cast(convert(DECIMAL(18,2),fianl.[315W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO315W
|
|
,cast(convert(DECIMAL(18,2),fianl.[320W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO320W
|
|
,cast(convert(DECIMAL(18,2),fianl.[325W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO325W
|
|
,cast(convert(DECIMAL(18,2),fianl.[330W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO330W
|
|
,cast(convert(DECIMAL(18,2),fianl.[335W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO335W
|
|
,cast(convert(DECIMAL(18,2),fianl.[340W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO340W
|
|
,cast(convert(DECIMAL(18,2),fianl.[345W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO345W
|
|
,cast(convert(DECIMAL(18,2),fianl.[350W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO350W
|
|
,cast(convert(DECIMAL(18,2),fianl.[355W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO355W
|
|
,cast(convert(DECIMAL(18,2),fianl.[360W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO360W
|
|
,cast(convert(DECIMAL(18,2),fianl.[365W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO365W
|
|
,cast(convert(DECIMAL(18,2),fianl.[370W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO370W
|
|
,cast(convert(DECIMAL(18,2),fianl.[375W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO375W
|
|
,cast(convert(DECIMAL(18,2),fianl.[380W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO380W
|
|
,cast(convert(DECIMAL(18,2),fianl.[385W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO385W
|
|
,cast(convert(DECIMAL(18,2),fianl.[390W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO390W
|
|
,cast(convert(DECIMAL(18,2),fianl.[395W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO395W
|
|
,cast(convert(DECIMAL(18,2),fianl.[400W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO400W
|
|
,cast(convert(DECIMAL(18,2),fianl.[405W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO405W
|
|
,cast(convert(DECIMAL(18,2),fianl.[410W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO410W
|
|
,cast(convert(DECIMAL(18,2),fianl.[415W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO415W
|
|
,cast(convert(DECIMAL(18,2),fianl.[420W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO420W
|
|
,cast(convert(DECIMAL(18,2),fianl.[425W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO425W
|
|
,cast(convert(DECIMAL(18,2),fianl.[430W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO430W
|
|
,cast(convert(DECIMAL(18,2),fianl.[435W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO435W
|
|
,cast(convert(DECIMAL(18,2),fianl.[440W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO440W
|
|
,cast(convert(DECIMAL(18,2),fianl.[445W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO445W
|
|
,cast(convert(DECIMAL(18,2),fianl.[450W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO450W
|
|
,cast(convert(DECIMAL(18,2),fianl.[455W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO455W
|
|
,cast(convert(DECIMAL(18,2),fianl.[460W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO460W
|
|
,cast(convert(DECIMAL(18,2),fianl.[465W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO465W
|
|
,cast(convert(DECIMAL(18,2),fianl.[470W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO470W
|
|
,cast(convert(DECIMAL(18,2),fianl.[475W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO475W
|
|
,cast(convert(DECIMAL(18,2),fianl.[480W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO480W
|
|
,cast(convert(DECIMAL(18,2),fianl.[485W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO485W
|
|
,cast(convert(DECIMAL(18,2),fianl.[490W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO490W
|
|
,cast(convert(DECIMAL(18,2),fianl.[495W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO495W
|
|
,cast(convert(DECIMAL(18,2),fianl.[500W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO500W
|
|
,cast(convert(DECIMAL(18,2),fianl.[505W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO505W
|
|
,cast(convert(DECIMAL(18,2),fianl.[510W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO510W
|
|
,cast(convert(DECIMAL(18,2),fianl.[515W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO515W
|
|
,cast(convert(DECIMAL(18,2),fianl.[520W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO520W
|
|
,cast(convert(DECIMAL(18,2),fianl.[525W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO525W
|
|
,cast(convert(DECIMAL(18,2),fianl.[530W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO530W
|
|
,cast(convert(DECIMAL(18,2),fianl.[535W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO535W
|
|
,cast(convert(DECIMAL(18,2),fianl.[540W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO540W
|
|
,cast(convert(DECIMAL(18,2),fianl.[545W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO545W
|
|
,cast(convert(DECIMAL(18,2),fianl.[550W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO550W
|
|
,cast(convert(DECIMAL(18,2),fianl.[555W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO555W
|
|
,cast(convert(DECIMAL(18,2),fianl.[560W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO560W
|
|
,cast(convert(DECIMAL(18,2),fianl.[565W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO565W
|
|
,cast(convert(DECIMAL(18,2),fianl.[570W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO570W
|
|
,cast(convert(DECIMAL(18,2),fianl.[575W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO575W
|
|
,cast(convert(DECIMAL(18,2),fianl.[580W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO580W
|
|
,cast(convert(DECIMAL(18,2),fianl.[585W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO585W
|
|
,cast(convert(DECIMAL(18,2),fianl.[590W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO590W
|
|
,cast(convert(DECIMAL(18,2),fianl.[595W]*1.0/fianl.ZJSL*1.0*100) as varchar)+'%' as RATIO595W
|
|
FROM (SELECT SUBSTRING(g.descriptions,dbo.fn_find('_',g.descriptions,1)+1,
|
|
case
|
|
when dbo.fn_find('_',g.descriptions,2)-dbo.fn_find('_',g.descriptions,1) >0 then dbo.fn_find('_',g.descriptions,2)-dbo.fn_find('_',g.descriptions,1)-1
|
|
else 0
|
|
end)+' '+
|
|
SUBSTRING(g.descriptions,dbo.fn_find('_',g.descriptions,5)+1,
|
|
case
|
|
when dbo.fn_find('_',g.descriptions,6)-dbo.fn_find('_',g.descriptions,5) >0 then dbo.fn_find('_',g.descriptions,6)-dbo.fn_find('_',g.descriptions,5)-2
|
|
else 0
|
|
end) as PY,
|
|
CONVERT(decimal(10,2), SUBSTRING(g.descriptions,dbo.fn_find('_',g.descriptions,5)+1,
|
|
case
|
|
when dbo.fn_find('_',g.descriptions,6)-dbo.fn_find('_',g.descriptions,5) >0 then dbo.fn_find('_',g.descriptions,6)-dbo.fn_find('_',g.descriptions,5)-2
|
|
else 0
|
|
end))*CONVERT(int,c.cell_qty) as EDGL,
|
|
SUM(a.pmax)/count(a.serial_nbr) as PJGL,
|
|
count(a.serial_nbr) as ZJSL,
|
|
b.workorder,
|
|
count(case when a.pmax >=0 and a.pmax <5 then 1 end) as '0W',
|
|
count(case when a.pmax >=5 and a.pmax <10 then 1 end) as '5W',
|
|
count(case when a.pmax >=10 and a.pmax <15 then 1 end) as '10W',
|
|
count(case when a.pmax >=15 and a.pmax <20 then 1 end) as '15W',
|
|
count(case when a.pmax >=20 and a.pmax <25 then 1 end) as '20W',
|
|
count(case when a.pmax >=25 and a.pmax <30 then 1 end) as '25W',
|
|
count(case when a.pmax >=30 and a.pmax <35 then 1 end) as '30W',
|
|
count(case when a.pmax >=35 and a.pmax <40 then 1 end) as '35W',
|
|
count(case when a.pmax >=40 and a.pmax <45 then 1 end) as '40W',
|
|
count(case when a.pmax >=45 and a.pmax <50 then 1 end) as '45W',
|
|
count(case when a.pmax >=50 and a.pmax <55 then 1 end) as '50W',
|
|
count(case when a.pmax >=55 and a.pmax <60 then 1 end) as '55W',
|
|
count(case when a.pmax >=60 and a.pmax <65 then 1 end) as '60W',
|
|
count(case when a.pmax >=65 and a.pmax <70 then 1 end) as '65W',
|
|
count(case when a.pmax >=70 and a.pmax <75 then 1 end) as '70W',
|
|
count(case when a.pmax >=75 and a.pmax <80 then 1 end) as '75W',
|
|
count(case when a.pmax >=80 and a.pmax <85 then 1 end) as '80W',
|
|
count(case when a.pmax >=85 and a.pmax <90 then 1 end) as '85W',
|
|
count(case when a.pmax >=90 and a.pmax <95 then 1 end) as '90W',
|
|
count(case when a.pmax >=95 and a.pmax <100 then 1 end) as '95W',
|
|
count(case when a.pmax >=100 and a.pmax <105 then 1 end) as '100W',
|
|
count(case when a.pmax >=105 and a.pmax <110 then 1 end) as '105W',
|
|
count(case when a.pmax >=110 and a.pmax <115 then 1 end) as '110W',
|
|
count(case when a.pmax >=115 and a.pmax <120 then 1 end) as '115W',
|
|
count(case when a.pmax >=120 and a.pmax <125 then 1 end) as '120W',
|
|
count(case when a.pmax >=125 and a.pmax <130 then 1 end) as '125W',
|
|
count(case when a.pmax >=130 and a.pmax <135 then 1 end) as '130W',
|
|
count(case when a.pmax >=135 and a.pmax <140 then 1 end) as '135W',
|
|
count(case when a.pmax >=140 and a.pmax <145 then 1 end) as '140W',
|
|
count(case when a.pmax >=145 and a.pmax <150 then 1 end) as '145W',
|
|
count(case when a.pmax >=150 and a.pmax <155 then 1 end) as '150W',
|
|
count(case when a.pmax >=155 and a.pmax <160 then 1 end) as '155W',
|
|
count(case when a.pmax >=160 and a.pmax <165 then 1 end) as '160W',
|
|
count(case when a.pmax >=165 and a.pmax <170 then 1 end) as '165W',
|
|
count(case when a.pmax >=170 and a.pmax <175 then 1 end) as '170W',
|
|
count(case when a.pmax >=175 and a.pmax <180 then 1 end) as '175W',
|
|
count(case when a.pmax >=180 and a.pmax <185 then 1 end) as '180W',
|
|
count(case when a.pmax >=185 and a.pmax <190 then 1 end) as '185W',
|
|
count(case when a.pmax >=190 and a.pmax <195 then 1 end) as '190W',
|
|
count(case when a.pmax >=195 and a.pmax <200 then 1 end) as '195W',
|
|
count(case when a.pmax >=200 and a.pmax <205 then 1 end) as '200W',
|
|
count(case when a.pmax >=205 and a.pmax <210 then 1 end) as '205W',
|
|
count(case when a.pmax >=210 and a.pmax <215 then 1 end) as '210W',
|
|
count(case when a.pmax >=215 and a.pmax <220 then 1 end) as '215W',
|
|
count(case when a.pmax >=220 and a.pmax <225 then 1 end) as '220W',
|
|
count(case when a.pmax >=225 and a.pmax <230 then 1 end) as '225W',
|
|
count(case when a.pmax >=230 and a.pmax <235 then 1 end) as '230W',
|
|
count(case when a.pmax >=235 and a.pmax <240 then 1 end) as '235W',
|
|
count(case when a.pmax >=240 and a.pmax <245 then 1 end) as '240W',
|
|
count(case when a.pmax >=245 and a.pmax <250 then 1 end) as '245W',
|
|
count(case when a.pmax >=250 and a.pmax <255 then 1 end) as '250W',
|
|
count(case when a.pmax >=255 and a.pmax <260 then 1 end) as '255W',
|
|
count(case when a.pmax >=260 and a.pmax <265 then 1 end) as '260W',
|
|
count(case when a.pmax >=265 and a.pmax <270 then 1 end) as '265W',
|
|
count(case when a.pmax >=270 and a.pmax <275 then 1 end) as '270W',
|
|
count(case when a.pmax >=275 and a.pmax <280 then 1 end) as '275W',
|
|
count(case when a.pmax >=280 and a.pmax <285 then 1 end) as '280W',
|
|
count(case when a.pmax >=285 and a.pmax <290 then 1 end) as '285W',
|
|
count(case when a.pmax >=290 and a.pmax <295 then 1 end) as '290W',
|
|
count(case when a.pmax >=295 and a.pmax <300 then 1 end) as '295W',
|
|
count(case when a.pmax >=300 and a.pmax <305 then 1 end) as '300W',
|
|
count(case when a.pmax >=305 and a.pmax <310 then 1 end) as '305W',
|
|
count(case when a.pmax >=310 and a.pmax <315 then 1 end) as '310W',
|
|
count(case when a.pmax >=315 and a.pmax <320 then 1 end) as '315W',
|
|
count(case when a.pmax >=320 and a.pmax <325 then 1 end) as '320W',
|
|
count(case when a.pmax >=325 and a.pmax <330 then 1 end) as '325W',
|
|
count(case when a.pmax >=330 and a.pmax <335 then 1 end) as '330W',
|
|
count(case when a.pmax >=335 and a.pmax <340 then 1 end) as '335W',
|
|
count(case when a.pmax >=340 and a.pmax <345 then 1 end) as '340W',
|
|
count(case when a.pmax >=345 and a.pmax <350 then 1 end) as '345W',
|
|
count(case when a.pmax >=350 and a.pmax <355 then 1 end) as '350W',
|
|
count(case when a.pmax >=355 and a.pmax <360 then 1 end) as '355W',
|
|
count(case when a.pmax >=360 and a.pmax <365 then 1 end) as '360W',
|
|
count(case when a.pmax >=365 and a.pmax <370 then 1 end) as '365W',
|
|
count(case when a.pmax >=370 and a.pmax <375 then 1 end) as '370W',
|
|
count(case when a.pmax >=375 and a.pmax <380 then 1 end) as '375W',
|
|
count(case when a.pmax >=380 and a.pmax <385 then 1 end) as '380W',
|
|
count(case when a.pmax >=385 and a.pmax <390 then 1 end) as '385W',
|
|
count(case when a.pmax >=390 and a.pmax <395 then 1 end) as '390W',
|
|
count(case when a.pmax >=395 and a.pmax <400 then 1 end) as '395W',
|
|
count(case when a.pmax >=400 and a.pmax <405 then 1 end) as '400W',
|
|
count(case when a.pmax >=405 and a.pmax <410 then 1 end) as '405W',
|
|
count(case when a.pmax >=410 and a.pmax <415 then 1 end) as '410W',
|
|
count(case when a.pmax >=415 and a.pmax <420 then 1 end) as '415W',
|
|
count(case when a.pmax >=420 and a.pmax <425 then 1 end) as '420W',
|
|
count(case when a.pmax >=425 and a.pmax <430 then 1 end) as '425W',
|
|
count(case when a.pmax >=430 and a.pmax <435 then 1 end) as '430W',
|
|
count(case when a.pmax >=435 and a.pmax <440 then 1 end) as '435W',
|
|
count(case when a.pmax >=440 and a.pmax <445 then 1 end) as '440W',
|
|
count(case when a.pmax >=445 and a.pmax <450 then 1 end) as '445W',
|
|
count(case when a.pmax >=450 and a.pmax <455 then 1 end) as '450W',
|
|
count(case when a.pmax >=455 and a.pmax <460 then 1 end) as '455W',
|
|
count(case when a.pmax >=460 and a.pmax <465 then 1 end) as '460W',
|
|
count(case when a.pmax >=465 and a.pmax <470 then 1 end) as '465W',
|
|
count(case when a.pmax >=470 and a.pmax <475 then 1 end) as '470W',
|
|
count(case when a.pmax >=475 and a.pmax <480 then 1 end) as '475W',
|
|
count(case when a.pmax >=480 and a.pmax <485 then 1 end) as '480W',
|
|
count(case when a.pmax >=485 and a.pmax <490 then 1 end) as '485W',
|
|
count(case when a.pmax >=490 and a.pmax <495 then 1 end) as '490W',
|
|
count(case when a.pmax >=495 and a.pmax <500 then 1 end) as '495W',
|
|
count(case when a.pmax >=500 and a.pmax <505 then 1 end) as '500W',
|
|
count(case when a.pmax >=505 and a.pmax <510 then 1 end) as '505W',
|
|
count(case when a.pmax >=510 and a.pmax <515 then 1 end) as '510W',
|
|
count(case when a.pmax >=515 and a.pmax <520 then 1 end) as '515W',
|
|
count(case when a.pmax >=520 and a.pmax <525 then 1 end) as '520W',
|
|
count(case when a.pmax >=525 and a.pmax <530 then 1 end) as '525W',
|
|
count(case when a.pmax >=530 and a.pmax <535 then 1 end) as '530W',
|
|
count(case when a.pmax >=535 and a.pmax <540 then 1 end) as '535W',
|
|
count(case when a.pmax >=540 and a.pmax <545 then 1 end) as '540W',
|
|
count(case when a.pmax >=545 and a.pmax <550 then 1 end) as '545W',
|
|
count(case when a.pmax >=550 and a.pmax <555 then 1 end) as '550W',
|
|
count(case when a.pmax >=555 and a.pmax <560 then 1 end) as '555W',
|
|
count(case when a.pmax >=560 and a.pmax <565 then 1 end) as '560W',
|
|
count(case when a.pmax >=565 and a.pmax <570 then 1 end) as '565W',
|
|
count(case when a.pmax >=570 and a.pmax <575 then 1 end) as '570W',
|
|
count(case when a.pmax >=575 and a.pmax <580 then 1 end) as '575W',
|
|
count(case when a.pmax >=580 and a.pmax <585 then 1 end) as '580W',
|
|
count(case when a.pmax >=585 and a.pmax <590 then 1 end) as '585W',
|
|
count(case when a.pmax >=590 and a.pmax <595 then 1 end) as '590W',
|
|
count(case when a.pmax >=595 and a.pmax <600 then 1 end) as '595W'
|
|
--FLOOR(a.pmax/5)*5
|
|
FROM [mes_level2_iface].[dbo].[iv] a
|
|
left join mes_main.dbo.assembly_status b
|
|
on a.serial_nbr =b.serial_nbr
|
|
left join mes_main.dbo.wo_mfg c
|
|
on b.workorder =c.workorder
|
|
left join mes_main.dbo.trace_componnet_lot d
|
|
on a.serial_nbr =d.serial_nbr AND d.part_type = 'CELL'
|
|
left join mes_level4_iface.dbo.master_part g
|
|
on d.part_nbr =g.bom_part_nbr
|
|
where 1=1 " + strWhere + @"
|
|
group by g.descriptions,c.cell_qty,b.workorder) fianl
|
|
";
|
|
//sql += String.IsNullOrEmpty(lot) ? "" : " and qcv.[serial_nbr] LIKE '" + lot + "%'";
|
|
//sql += String.IsNullOrEmpty(workshop) ? "" : " AND wo.[area_code] = '" + workshop + "' ";
|
|
//sql += String.IsNullOrEmpty(status) ? "" : " AND qcv.[visit_type] = '" + status + "'";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
#region 发料报表
|
|
public DataTable StoreIssueDT(string bt, string et, string part_nbr, string workorder, string lot_nbr)
|
|
{
|
|
return dbhelp.ExecuteDataTable(StoreIssueSql(bt, et, part_nbr, workorder, lot_nbr), null);
|
|
}
|
|
|
|
public string StoreIssueSql(string bt, string et, string part_nbr, string workorder, string lot_nbr)
|
|
{
|
|
//and a.workorder = '' and a.part_nbr ='' and a.lot_nbr = ''
|
|
//and a.create_date >= '' and a.create_date <= ''
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and a.createtime >= '" + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and a.createtime <= '" + et + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(part_nbr))
|
|
{
|
|
strWhere += "a.part_nbr = '" + part_nbr + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and a.workorder = '" + workorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(lot_nbr))
|
|
{
|
|
strWhere += "a.lot_nbr = '" + lot_nbr + "' ";
|
|
}
|
|
string sql = @"select CONVERT(varchar(100),a.create_date, 120) as create_date,c.descriptions,a.workorder,b.customer,a.part_nbr
|
|
,'' as 'CHGG',a.lot_nbr,'' AS 'SQJC','' AS 'FCSL','' as 'DDFCSL','' AS 'XCJY'
|
|
FROM [mes_main].[dbo].[pack_material_lot] a
|
|
left join mes_main.dbo.wo_mfg b
|
|
on a.workorder =b.workorder
|
|
left join mes_main.dbo.df_areas c
|
|
on b.area_code = c.area_code
|
|
WHERE 1=1 " + strWhere + @"";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
#region 返修换片报表
|
|
public DataTable RepairDT(string bt, string et, string sale_order, string workorder)
|
|
{
|
|
return dbhelp.ExecuteDataTable(RepairSql(bt, et, sale_order, workorder), null);
|
|
}
|
|
|
|
public string RepairSql(string bt, string et, string sale_order, string workorder)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
string strWhere1 = string.Empty;
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and a.create_date >= '" + bt + "' ";
|
|
strWhere1 += " and a.operators_date >= '" + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and a.create_date <= '" + et + "' ";
|
|
strWhere1 += " and a.operators_date <= '" + et + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(sale_order))
|
|
{
|
|
strWhere += "and c.sale_order = '" + sale_order + "' ";
|
|
strWhere1 += "and c.sale_order = '" + sale_order + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and b.workorder = '" + workorder + "' ";
|
|
strWhere1 += " and b.workorder = '" + workorder + "' ";
|
|
}
|
|
string sql = @"(SELECT c.sale_order,b.workorder,a.serial_nbr,c.cell_qty,c.mod_color
|
|
,h.part_nbr as oldpart_nbr,h.supplier_code as oldsupplier_code,
|
|
SUBSTRING(j.descriptions,dbo.fn_find('_',j.descriptions,5)+1,
|
|
case
|
|
when dbo.fn_find('_',j.descriptions,6)-dbo.fn_find('_',j.descriptions,5) >0 then dbo.fn_find('_',j.descriptions,6)-dbo.fn_find('_',j.descriptions,5)-1
|
|
else 0
|
|
end) as oldcell_uop,
|
|
a.org_celllot
|
|
,i.part_nbr as newpart_nbr,i.supplier_code as newsupplier_code,
|
|
SUBSTRING(k.descriptions,dbo.fn_find('_',k.descriptions,5)+1,
|
|
case
|
|
when dbo.fn_find('_',k.descriptions,6)-dbo.fn_find('_',k.descriptions,5) >0 then dbo.fn_find('_',k.descriptions,6)-dbo.fn_find('_',k.descriptions,5)-1
|
|
else 0
|
|
end) as newcell_uop,
|
|
a.new_celllot
|
|
,a.wks_id,e.defect_group_desc,d.defect_type_name,f.defect_position,a.change_cell_qty,a.operator,g.nickname,a.remark
|
|
,CONVERT(varchar(100),b.create_date, 120) as create_date
|
|
,l.wks_id as hjj,m.wks_id as dct
|
|
FROM [mes_main].[dbo].[cellchangelog] a
|
|
left join mes_main.dbo.assembly_status b
|
|
on a.serial_nbr =b.serial_nbr
|
|
left join mes_main.dbo.wo_mfg c
|
|
on b.workorder =c.workorder
|
|
left join mes_main.dbo.config_defect_type d
|
|
on a.defect_type_id = d.defect_type_id
|
|
left join mes_main.dbo.config_defect_group e
|
|
on d.defect_group_id = e.defect_group_id
|
|
left join mes_main.dbo.defects f
|
|
on a.Defects_aiid = f.aiid
|
|
left join mes_auth.dbo.df_user g
|
|
on a.operator = g.username
|
|
left join mes_main.dbo.pack_material_lot h
|
|
on a.org_celllot = h.lot_nbr
|
|
left join mes_main.dbo.pack_material_lot i
|
|
on a.new_celllot = i.lot_nbr
|
|
left join mes_level4_iface.dbo.master_part j
|
|
on h.part_nbr =j.bom_part_nbr
|
|
left join mes_level4_iface.dbo.master_part k
|
|
on i.part_nbr =k.bom_part_nbr
|
|
left join mes_main.dbo.trace_workstation_visit l
|
|
on a.serial_nbr = l.serial_nbr and l.wks_id like'%HJJ%'
|
|
left join mes_main.dbo.trace_workstation_visit m
|
|
on a.serial_nbr = m.serial_nbr and m.wks_id like'%DCT%'
|
|
where 1=1 " + strWhere + @"
|
|
--and c.sale_order = '11'
|
|
--and b.workorder ='' and c.area_code ='' and a.create_date >='' and a.create_date <''
|
|
)
|
|
union all
|
|
(SELECT c.sale_order,b.workorder,'' as serial_nbr,'' as cell_qty
|
|
,'' as mod_color,a.part_nbr as oldpart_nbr,a.cell_supplier as oldsupplier_code,a.cell_power as oldcell_uop,a.lot_nbr as org_celllot
|
|
,'' as newpart_nbr, '' as newsupplier_code
|
|
,'' as newcell_uop,'' as new_celllot,'' as wks_id,'来料返' as defect_group_desc,d.defect_type_name as defect_type_name
|
|
,'' asdefect_position,a.defect_cell_qty as change_cell_qty,a.operators_name as operator,g.nickname as nickname,'' as remark,CONVERT(varchar(100),a.operators_date, 120) as create_date,'' as hjj,'' as dct
|
|
FROM [mes_main].[dbo].[defects_lot] a
|
|
left join mes_main.dbo.pack_material_lot b
|
|
on a.lot_nbr = b.lot_nbr
|
|
left join mes_main.dbo.wo_mfg c
|
|
on b.workorder = c.workorder
|
|
left join mes_main.dbo.config_defect_type d
|
|
on d.defect_type_id = a.defect_type_id
|
|
left join mes_auth.dbo.df_user g
|
|
on a.operators_name = g.username
|
|
where 1=1 " + strWhere1 + @"
|
|
--and c.sale_order = '11'
|
|
--and b.workorder ='' and c.area_code ='' and a.operators_date >='' and a.operators_date <''
|
|
)";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
#region 订单达成率
|
|
public DataTable BarCodeAndQualityRateDT(string sale_order, string workorder, string station)
|
|
{
|
|
return dbhelp.ExecuteDataTable(BarCodeAndQualityRateSql(sale_order, workorder, station), null);
|
|
}
|
|
|
|
public string BarCodeAndQualityRateSql(string sale_order, string workorder, string station)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(sale_order))
|
|
{
|
|
strWhere += "and b.sale_order = '" + sale_order + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and a.workorder = '" + workorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(station))
|
|
{
|
|
strWhere += " and e.descriptions = '" + station + "' ";
|
|
}
|
|
|
|
string sql = @"SELECT c.descriptions,b.sale_order,max(b.customer) as customer,b.workorder as workorder,sum(b.plan_qty)over(partition by b.sale_order) as plan_qty,
|
|
b.sn_qty as woplan,
|
|
count(a.serial_nbr) as qty,
|
|
CAST(CAST((count(case
|
|
when a.final_grade = 'Q0' AND a.serial_status != 'S' then 1
|
|
end)+count(case
|
|
when a.final_grade = 'A' AND a.serial_status != 'S' then 1
|
|
end))*1.0*100/count(a.serial_nbr) as decimal(10,2)) as varchar(50)) +'%' as QualityRate
|
|
" +
|
|
//,count(case
|
|
// when a.final_grade = 'A' AND a.serial_status != 'S' then 1
|
|
// end)A
|
|
// ,count(case
|
|
// when a.final_grade = 'A1' AND a.serial_status != 'S' then 1
|
|
// end)A1
|
|
// ,count(case
|
|
// when a.final_grade = 'A2' AND a.serial_status != 'S' then 1
|
|
// end)A2
|
|
@"
|
|
,count(case
|
|
when a.final_grade = 'Q0' AND a.serial_status != 'S' then 1
|
|
end)Q0
|
|
,count(case
|
|
when a.final_grade = 'Q1' AND a.serial_status != 'S' then 1
|
|
end)Q1
|
|
,count(case
|
|
when a.final_grade = 'Q2' AND a.serial_status != 'S' then 1
|
|
end)Q2
|
|
,count(case
|
|
when a.final_grade = 'Q3' AND a.serial_status != 'S' then 1
|
|
end)Q3
|
|
,count(case
|
|
when a.final_grade = 'B' AND a.serial_status != 'S' then 1
|
|
end)B
|
|
,count(case
|
|
when a.serial_status = 'S' then 1
|
|
end)bf
|
|
FROM mes_main.dbo.trace_workstation_visit wks
|
|
left join [mes_main].[dbo].[assembly_status] a
|
|
on wks.serial_nbr = a.serial_nbr
|
|
left join mes_main.dbo.wo_mfg b
|
|
on a.workorder =b.workorder
|
|
left join [mes_main].[dbo].[df_areas] c
|
|
on b.area_code =c.area_code
|
|
left join mes_main.dbo.config_workstation d
|
|
on wks.wks_id = d.wks_id
|
|
left join [mes_main].[dbo].[df_processes] e
|
|
on d.process_code =e.process_code
|
|
WHERE 1=1 " + strWhere + @"
|
|
group by c.descriptions,b.sale_order,b.workorder,b.plan_qty,b.sn_qty "
|
|
;
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
#region 工单结批率(原始版本)
|
|
public DataTable BatchRate2DT(string sale_order, string workorder, string workshop)
|
|
{
|
|
return dbhelp.ExecuteDataTable(BatchRate2Sql(sale_order, workorder, workshop), null);
|
|
}
|
|
|
|
public string BatchRate2Sql(string sale_order, string workorder, string workshop)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(sale_order))
|
|
{
|
|
strWhere += "and b.sale_order = '" + sale_order + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and a.workorder = '" + workorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workshop))
|
|
{
|
|
strWhere += " and b.area_code = '" + workshop + "' ";
|
|
}
|
|
string sql = @"SELECT c.descriptions,b.sale_order,b.OEMcustomer,a.workorder,b.plan_qty,
|
|
COUNT(a.serial_nbr) as qty
|
|
,COUNT(case
|
|
when (e.palletno IS not null OR e.palletno!='') and (a.process_code = 'N50' or a.process_code = 'P100') then 1
|
|
end) as rk
|
|
,count(case
|
|
when d.descriptions !='生码' and a.serial_status = 'S' then 1
|
|
end) as zjbf
|
|
,count(case
|
|
when d.descriptions ='生码' and a.serial_status = 'S' then 1
|
|
end) as smbf
|
|
,count(case
|
|
when d.descriptions ='生码' and a.serial_status != 'S' then 1
|
|
end) as sm
|
|
,count(case
|
|
when d.descriptions ='焊接' and a.serial_status != 'S' then 1
|
|
end) as hj
|
|
,count(case
|
|
when d.descriptions ='叠层' and a.serial_status != 'S' then 1
|
|
end) as dc
|
|
,count(case
|
|
when d.descriptions ='层压' and a.serial_status != 'S' then 1
|
|
end) as cy
|
|
,count(case
|
|
when d.process_code ='N40' and a.serial_status != 'S' then 1
|
|
end) as cyhjy
|
|
,count(case
|
|
when d.descriptions ='装框' and a.serial_status != 'S' then 1
|
|
end) as zk
|
|
,count(case
|
|
when d.descriptions ='清洗' and a.serial_status != 'S' and (a.pallet_nbr IS NULL OR a.pallet_nbr='') then 1
|
|
end) as qx
|
|
,count(case
|
|
when d.process_code ='N60' and a.serial_status != 'S' and (a.pallet_nbr IS NULL OR a.pallet_nbr='') then 1
|
|
end) as qj
|
|
,count(case
|
|
when ((a.pallet_nbr IS not null or a.process_code = 'P100') and a.serial_status != 'S' and e.palletno IS null) then 1
|
|
end) as bz
|
|
,CAST(CAST(COUNT(case
|
|
when (e.palletno IS not null OR e.palletno!='') then 1
|
|
end)*1.0*100/count(a.serial_nbr) as decimal(10,2)) as varchar(50)) +'%' as rkl
|
|
,
|
|
CONVERT(varchar(100),MIN(e.createtime), 120) as minT,
|
|
CONVERT(varchar(100),b.finish_time, 120) as finish_time,
|
|
CONVERT(varchar(100),MAX(e.createtime), 120) as maxT
|
|
FROM [mes_main].[dbo].[assembly_status] a
|
|
left join mes_main.dbo.wo_mfg b
|
|
on a.workorder =b.workorder
|
|
left join mes_main.dbo.df_areas c
|
|
on b.area_code =c.area_code
|
|
left join mes_main.dbo.df_processes d
|
|
on a.process_code =d.process_code
|
|
left join (SELECT a.palletno,MAX(a.status) as status
|
|
,max(a.createtime) as createtime
|
|
FROM [wh].[dbo].[tstockinlog] a
|
|
group by a.palletno) e
|
|
on a.pallet_nbr =e.palletno and e.status in('2','3','4')
|
|
where 1=1" + strWhere + @"
|
|
group by c.descriptions,b.sale_order,b.customer,a.workorder,b.plan_qty,b.create_date,b.finish_time,b.OEMcustomer";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
#region 工单结批率(山东版本)
|
|
public DataTable BatchRateDT(string sale_order, string workorder, string workshop)
|
|
{
|
|
return dbhelp.ExecuteDataTable(BatchRateSql(sale_order, workorder, workshop), null);
|
|
}
|
|
|
|
public string BatchRateSql(string sale_order, string workorder, string workshop)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
string strWhere0 = string.Empty;
|
|
if (!string.IsNullOrEmpty(sale_order))
|
|
{
|
|
strWhere += "and b.sale_order = '" + sale_order + "' ";
|
|
strWhere0 += "and d.sale_order = '" + sale_order + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and b.workorder = '" + workorder + "' ";
|
|
strWhere0 += " and d.workorder = '" + workorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workshop))
|
|
{
|
|
strWhere += " and b.area_code = '" + workshop + "' ";
|
|
strWhere0 += " and d.area_code = '" + workshop + "' ";
|
|
}
|
|
string sql = @"SELECT FIAN1.descriptions,FIAN1.sale_order,FIAN1.OEMcustomer,FIAN1.workorder,FIAN1.plan_qty,FIAN1.qty,
|
|
FIAN1.rk,FIAN1.zjbf,FIAN1.smbf,FIAN1.sm,FIAN1.hj,FIAN1.dc,FIAN1.cy,FIAN2.CYHJY,FIAN1.zk,FIAN1.qx,
|
|
FIAN1.QJ,FIAN1.bz,FIAN1.rkl,FIAN1.minT,FIAN1.finish_time,FIAN1.maxT
|
|
FROM (
|
|
SELECT c.descriptions,b.sale_order,b.OEMcustomer,a.workorder,b.plan_qty,
|
|
COUNT(a.serial_nbr) as qty
|
|
,COUNT(case
|
|
when (e.palletno IS not null OR e.palletno!='') and (a.pallet_nbr IS not null OR a.pallet_nbr !='') then 1
|
|
end) as rk
|
|
,count(case
|
|
when d.descriptions !='生码' and a.serial_status = 'S' then 1
|
|
end) as zjbf
|
|
,count(case
|
|
when d.descriptions ='生码' and a.serial_status = 'S' then 1
|
|
end) as smbf
|
|
,count(case
|
|
when d.descriptions ='生码' and a.serial_status != 'S' and (a.pallet_nbr IS NULL OR a.pallet_nbr='') then 1
|
|
end) as sm
|
|
,count(case
|
|
when d.descriptions ='焊接' and a.serial_status != 'S' and (a.pallet_nbr IS NULL OR a.pallet_nbr='') then 1
|
|
end) as hj
|
|
,count(case
|
|
when d.descriptions ='叠层' and a.serial_status != 'S' and (a.pallet_nbr IS NULL OR a.pallet_nbr='') then 1
|
|
end) as dc
|
|
,count(case
|
|
when d.descriptions ='层压' and a.serial_status != 'S' and (a.pallet_nbr IS NULL OR a.pallet_nbr='') then 1
|
|
end) as cy
|
|
,count(case
|
|
when d.process_code ='N40' and a.serial_status != 'S' and (a.pallet_nbr IS NULL OR a.pallet_nbr='') then 1
|
|
end) as cyhjy
|
|
,count(case
|
|
when d.descriptions ='装框' and a.serial_status != 'S'and (a.pallet_nbr IS NULL OR a.pallet_nbr='') then 1
|
|
end) as zk
|
|
,count(case
|
|
when d.descriptions ='清洗' and a.serial_status != 'S' and (a.pallet_nbr IS NULL OR a.pallet_nbr='') then 1
|
|
end) as qx
|
|
,count(case
|
|
when d.process_code ='N60' and a.serial_status != 'S' and (a.pallet_nbr IS NULL OR a.pallet_nbr='') then 1
|
|
end) as qj
|
|
,count(case
|
|
when ((a.pallet_nbr IS not null or a.process_code = 'P100') and a.serial_status != 'S' and e.palletno IS null) then 1
|
|
end) as bz
|
|
,CAST(CAST(COUNT(case
|
|
when (e.palletno IS not null OR e.palletno!='') then 1
|
|
end)*1.0*100/count(a.serial_nbr) as decimal(10,2)) as varchar(50)) +'%' as rkl
|
|
,
|
|
CONVERT(varchar(100),MIN(e.createtime), 120) as minT,
|
|
CONVERT(varchar(100),b.finish_time, 120) as finish_time,
|
|
CONVERT(varchar(100),MAX(e.createtime), 120) as maxT
|
|
FROM [mes_main].[dbo].[assembly_status] a
|
|
left join mes_main.dbo.wo_mfg b
|
|
on a.workorder =b.workorder
|
|
left join mes_main.dbo.df_areas c
|
|
on b.area_code =c.area_code
|
|
left join mes_main.dbo.df_processes d
|
|
on a.process_code =d.process_code
|
|
left join (SELECT a.palletno,MAX(a.status) as status
|
|
,max(a.createtime) as createtime
|
|
FROM [wh].[dbo].[tstockinlog] a
|
|
group by a.palletno) e
|
|
on a.pallet_nbr =e.palletno and e.status in('2','3','4')
|
|
where 1=1 " + strWhere + @"
|
|
group by c.descriptions,b.sale_order,b.customer,a.workorder,b.plan_qty,b.create_date,b.finish_time,b.OEMcustomer
|
|
)FIAN1
|
|
LEFT JOIN
|
|
(
|
|
select d.workorder,
|
|
COUNT(case WHEN b.process_code = 'N60' and C.serial_status != 'S' and (c.pallet_nbr IS NULL OR c.pallet_nbr='') THEN 1 END) as QJ,
|
|
COUNT(case WHEN b.process_code = 'N40' and C.serial_status != 'S' and (c.pallet_nbr IS NULL OR c.pallet_nbr='') THEN 1 END) as CYHJY
|
|
--COUNT(a.serial_nbr),
|
|
from (select aa.serial_nbr,MAX(aa.wks_visit_date) wks_visit_date from mes_main.dbo.trace_workstation_visit aa group by serial_nbr) a
|
|
left join mes_main.dbo.trace_workstation_visit e
|
|
on a.serial_nbr = e.serial_nbr and a.wks_visit_date = e.wks_visit_date
|
|
left join mes_main.dbo.config_workstation b
|
|
on e.wks_id = b.wks_id
|
|
left join mes_main.dbo.assembly_status c
|
|
on a.serial_nbr = c.serial_nbr
|
|
left join mes_main.dbo.wo_mfg d
|
|
on c.workorder = d.workorder
|
|
WHERE 1 = 1 " + strWhere0 + @"
|
|
group by d.workorder
|
|
)FIAN2
|
|
on FIAN1.workorder = FIAN2.workorder
|
|
";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
#region 电池片结批率
|
|
public DataTable CellBatchRateDT(string sale_order, string workorder, string area_code)
|
|
{
|
|
return dbhelp.ExecuteDataTable(CellBatchRateSql(sale_order, workorder, area_code), null);
|
|
}
|
|
|
|
public string CellBatchRateSql(string sale_order, string workorder, string area_code)
|
|
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(sale_order))
|
|
{
|
|
strWhere += "and c.sale_order = '" + sale_order + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and c.workorder = '" + workorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(area_code))
|
|
{
|
|
strWhere += " and c.area_code = '" + area_code + "' ";
|
|
}
|
|
string sql = @"select final.area_descriptions,final.wks_desc,final.orig_batch_nbr,final.supplier_code,final.Cell_type,final.SS,final.DPGL,final.nbr,final.FZPS,final.LLBL,final.CFX,final.DFX,final.BF
|
|
,CAST(CAST((final.CFX+final.DFX+final.LLBL+final.BF)*1.0*100/(case when(final.FZPS+final.CFX+final.DFX+final.LLBL+final.BF)=0 then 1 else final.FZPS+final.CFX+final.DFX+final.LLBL+final.BF end) as decimal(10,2)) as varchar(50)) +'%' as BLL
|
|
from(
|
|
SELECT d.descriptions as area_descriptions,e.wks_desc,f.orig_batch_nbr,f.supplier_code
|
|
,
|
|
k.source_desc as Cell_type
|
|
,
|
|
l.source_desc as SS
|
|
,
|
|
SUBSTRING(g.descriptions,dbo.fn_find('_',g.descriptions,5)+1,
|
|
case
|
|
when dbo.fn_find('_',g.descriptions,6)-dbo.fn_find('_',g.descriptions,5) >0 then dbo.fn_find('_',g.descriptions,6)-dbo.fn_find('_',g.descriptions,5)-2
|
|
else 0
|
|
end) as DPGL
|
|
,
|
|
j.real_nbr as nbr
|
|
,
|
|
SUM(
|
|
case
|
|
when c.cell_qty is not null then c.cell_qty
|
|
else 0
|
|
end
|
|
) as FZPS
|
|
,
|
|
sum(case
|
|
when h.CFX is not null then h.CFX
|
|
else 0
|
|
end) as CFX
|
|
,sum(case
|
|
when h.DFX is not null then h.DFX
|
|
else 0
|
|
end) as DFX
|
|
,isnull(m.LLFX,0) as LLBL
|
|
,count(CASE
|
|
WHEN b.serial_status = 'S' then 1
|
|
END)*f.serial_requirement as BF
|
|
--,sum(case
|
|
-- when h.LLBL is not null then h.LLBL
|
|
-- else 0
|
|
--end) as LLBL
|
|
|
|
FROM [mes_main].[dbo].[trace_componnet_lot] a
|
|
LEFt join mes_main.dbo.assembly_status b
|
|
on a.serial_nbr = b.serial_nbr
|
|
left join mes_main.dbo.wo_mfg c
|
|
on c.workorder = b.workorder
|
|
left join mes_main.dbo.df_areas d
|
|
on d.area_code = c.area_code
|
|
left join mes_main.dbo.config_workstation e
|
|
on e.wks_id =a.wks_id
|
|
left join [mes_main].[dbo].[pack_material_lot] f
|
|
on f.lot_nbr = a.lot_nbr
|
|
left join mes_level4_iface.dbo.master_part g
|
|
on g.bom_part_nbr = a.part_nbr
|
|
|
|
left join (select a.serial_nbr,
|
|
sum(
|
|
case
|
|
when c.defect_group_name ='串返修' then a.defect_cell_qty
|
|
end) as CFX,
|
|
SUM(
|
|
case
|
|
when c.defect_group_name ='叠返修' then a.defect_cell_qty
|
|
end) as DFX
|
|
--,SUM(
|
|
--case
|
|
--when c.defect_group_name ='来料不良' then a.defect_cell_qty
|
|
--end) as LLBL
|
|
from mes_main.dbo.defects a
|
|
left join [mes_main].[dbo].[config_defect_type] b
|
|
on a.defect_type_id = b.defect_type_id
|
|
left join mes_main.dbo.config_defect_group c
|
|
on b.defect_group_id = c.defect_group_id
|
|
group by a.serial_nbr) h
|
|
on a.serial_nbr = h.serial_nbr
|
|
left join [mes_main].[dbo].[df_processes] i
|
|
on i.process_code = b.process_code
|
|
left join mes_main.dbo.config_bom_mfg j
|
|
on j.workorder = c.workorder and j.bom_part_nbr = a.part_nbr
|
|
|
|
LEFT JOIN [mes_main].[dbo].[df_source] k
|
|
on c.cell_type = k.source_value and k.source_group_name = 'CELL_TYPE'
|
|
LEFT JOIN [mes_main].[dbo].[df_source] l
|
|
on c.busbar_type = l.source_value and l.source_group_name = 'BUSBAR'
|
|
left join
|
|
(
|
|
SELECT a.part_nbr,b.workorder,SUM(a.defect_cell_qty) as LLFX
|
|
FROM [mes_main].[dbo].[defects_lot] a
|
|
left join mes_main.dbo.pack_material_lot b
|
|
on a.lot_nbr=b.lot_nbr
|
|
group by a.part_nbr,b.workorder
|
|
) m
|
|
on m.part_nbr = f.part_nbr and m.workorder = f.workorder
|
|
|
|
where a.part_type = 'CELL' and i.process_seq > = '30'
|
|
" + strWhere + @"
|
|
--and d.descriptions = '组件4部'
|
|
--and c.workorder = '1301-191026001'
|
|
--and c.sale_order = 'ZN191000254CP'
|
|
group by d.descriptions,e.wks_desc,f.orig_batch_nbr,f.supplier_code
|
|
,g.descriptions,j.real_nbr,k.source_desc,l.source_desc,m.LLFX,f.serial_requirement
|
|
)final";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
#region 物料损耗
|
|
public DataTable SuppliesConsumedDT(string sale_order, string workorder, string workshop)
|
|
{
|
|
return dbhelp.ExecuteDataTable(SuppliesConsumedSql(sale_order, workorder, workshop), null);
|
|
}
|
|
|
|
public string SuppliesConsumedSql(string sale_order, string workorder, string workshop)
|
|
{
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(sale_order))
|
|
{
|
|
strWhere += "and c.sale_order = '" + sale_order + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and c.workorder = '" + workorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workshop))
|
|
{
|
|
strWhere += " and d.area_code = '" + workshop + "' ";
|
|
}
|
|
string sql = @"select final.workshop,final.OEMcustomer,final.workorder,final.part_nbr,final.part_type,final.descriptions,final.is_primary,
|
|
final.primary_part,final.serial_requirement,final.uom,final.orig_batch_nbr,'' SQJC,final.real_nbr,final.consume,final.LLBL,final.ZCBL
|
|
,final.BF*final.serial_requirement as BF
|
|
,case
|
|
when final.real_nbr is null then 0
|
|
else final.real_nbr-final.consume-final.ZCBL-final.LLBL
|
|
end JY
|
|
from(SELECT d.descriptions as workshop,c.OEMcustomer,b.workorder,a.part_nbr,
|
|
case
|
|
when a.part_type = 'CELL' then '电池片'
|
|
when a.part_type = 'EVA' then 'EVA'
|
|
when a.part_type = 'EVA2' then '高透EVA'
|
|
when a.part_type = 'GLASS' then '玻璃'
|
|
when a.part_type = 'GLASS2' then '玻璃2'
|
|
when a.part_type = 'BKSHEET' then '背板'
|
|
when a.part_type = 'LFRAME' then '长型材'
|
|
when a.part_type = 'SFRAME' then '短型材'
|
|
when a.part_type = 'JBOX' then '接线盒'
|
|
end as part_type,
|
|
e.descriptions,
|
|
f.is_primary,f.primary_part,f.serial_requirement,f.uom,
|
|
g.orig_batch_nbr,f.real_nbr,
|
|
SUM(f.serial_requirement) as consume,
|
|
sum(case
|
|
when h.ZCBL is not null and a.part_type = 'CELL' then h.ZCBL
|
|
else 0
|
|
end) as ZCBL,
|
|
COUNT(case when b.serial_status='S' then 1 end) BF,
|
|
i.LLFX as LLBL
|
|
from mes_main.dbo.trace_componnet_lot a
|
|
left join mes_main.dbo.assembly_status b
|
|
on b.serial_nbr = a.serial_nbr
|
|
left join mes_main.dbo.wo_mfg c
|
|
on c.workorder = b.workorder
|
|
left join mes_main.dbo.df_areas d
|
|
on c.area_code =d.area_code
|
|
left join mes_level4_iface.dbo.master_part e
|
|
on e.bom_part_nbr = a.part_nbr
|
|
left join mes_main.dbo.config_bom_mfg f
|
|
on f.bom_part_nbr = a.part_nbr and f.workorder = b.workorder
|
|
left join mes_main.dbo.pack_material_lot g
|
|
on g.lot_nbr = a.lot_nbr
|
|
|
|
left join (select a.serial_nbr,
|
|
SUM(
|
|
case
|
|
when c.defect_group_name !='来料不良' then a.defect_cell_qty
|
|
end) as ZCBL,
|
|
SUM(
|
|
case
|
|
when c.defect_group_name ='来料不良' then a.defect_cell_qty
|
|
end) as LLBL
|
|
from mes_main.dbo.defects a
|
|
left join [mes_main].[dbo].[config_defect_type] b
|
|
on a.defect_type_id = b.defect_type_id
|
|
left join mes_main.dbo.config_defect_group c
|
|
on b.defect_group_id = c.defect_group_id
|
|
group by a.serial_nbr) h
|
|
on a.serial_nbr = h.serial_nbr --and a.part_type = 'CELL'
|
|
left join
|
|
(
|
|
SELECT a.part_nbr,b.workorder,SUM(a.defect_cell_qty) as LLFX
|
|
FROM [mes_main].[dbo].[defects_lot] a
|
|
left join mes_main.dbo.pack_material_lot b
|
|
on a.lot_nbr=b.lot_nbr
|
|
group by a.part_nbr,b.workorder
|
|
)i
|
|
on g.part_nbr=i.part_nbr and g.workorder=i.workorder
|
|
where 1 = 1 and a.part_type in ('CELL','EVA','EVA2','GLASS','GLASS2','BKSHEET','LFRAME','SFRAME','JBOX')" + strWhere + @"
|
|
--and c.sale_order = '123'
|
|
group by d.descriptions,c.OEMcustomer,b.workorder,a.part_nbr,a.part_type,
|
|
e.descriptions,f.is_primary,f.primary_part,f.serial_requirement,f.uom,
|
|
g.orig_batch_nbr,f.real_nbr,i.LLFX) final";
|
|
|
|
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
#region 原料线边仓报表
|
|
public DataTable LinePositionsDT(string sale_order, string workorder)
|
|
{
|
|
return dbhelp.ExecuteDataTable(LinePositionsSql(sale_order, workorder), null);
|
|
}
|
|
|
|
public string LinePositionsSql(string sale_order, string workorder)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(sale_order))
|
|
{
|
|
strWhere += "and b.sale_order = '" + sale_order + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += "and b.workorder = '" + workorder + "' ";
|
|
}
|
|
string sql = @"
|
|
-- 订单号 组件数量 工单 物料名称 单位 料号 规格 母批次号
|
|
-- 单耗 核定用量 损耗率 损耗用量 标准用量 仓库实发量 产线领用量 订单结余量 超出/结约 报废物料
|
|
select f.sale_order,f.ZJSL,f.workorder,f.target_qty,f.part_type_desc,f.uom
|
|
,f.bom_part_nbr,f.GG,f.serial_requirement,f.EDYL,f.lost_ratio
|
|
,f.EDYL * f.lost_ratio*0.01 as SHYL,f.EDYL * f.lost_ratio*0.01+f.EDYL AS BZYL
|
|
,f.real_nbr,f.CXLYL,f.real_nbr - f.CXLYL as DDJYL,f.CXLYL-(f.EDYL * f.lost_ratio*0.01+f.EDYL) as CC
|
|
,f.BF
|
|
from
|
|
(SELECT a.sale_order,'' as ZJSL,a.workorder,a.target_qty,b.part_type_desc,
|
|
b.uom,b.bom_part_nbr,'' as GG,
|
|
--c.orig_batch_nbr,
|
|
c.serial_requirement,a.plan_qty * c.serial_requirement as EDYL,b.lost_ratio,
|
|
--a.plan_qty * c.serial_requirement*b.lost_ratio*0.01 as SHYL,sum(c.lot_qty)*b.lost_ratio*0.01+sum(c.lot_qty) as BZYL,
|
|
b.real_nbr,isnull(SUM(d.cnt),0)*c.serial_requirement as CXLYL,sum(d.BF_nbr) as BF
|
|
FROM [mes_main].[dbo].[wo_mfg] a
|
|
left join mes_main.dbo.config_bom_mfg b
|
|
on a.workorder = b.workorder
|
|
join mes_main.dbo.pack_material_lot c
|
|
on c.workorder = a.workorder and c.part_nbr = b.bom_part_nbr
|
|
left join(
|
|
SELECT a.lot_nbr,COUNT(a.serial_nbr) as cnt,COUNT(case when d.serial_status = 'S' THEN 1 end) as BF_nbr
|
|
FROM [mes_main].[dbo].trace_componnet_lot a
|
|
left join mes_main.dbo.pack_material_lot b
|
|
on a.lot_nbr = b.lot_nbr
|
|
left join mes_main.dbo.wo_mfg c
|
|
on b.workorder = c.workorder
|
|
left join mes_main.dbo.assembly_status d
|
|
on a.serial_nbr =d.serial_nbr
|
|
--where 1=1 and b.workorder = '2301-191109002' and c.sale_order ='北达'
|
|
group by a.lot_nbr) d
|
|
on c.lot_nbr =d.lot_nbr
|
|
where 1=1 " + strWhere + @"
|
|
--and a.workorder = '2301-191109002' and a.sale_order ='北达'
|
|
group by a.sale_order,a.workorder,a.target_qty,b.part_type_desc,
|
|
b.uom,b.bom_part_nbr,a.plan_qty,
|
|
--c.orig_batch_nbr,
|
|
c.serial_requirement,b.lost_ratio,b.real_nbr
|
|
)f
|
|
";
|
|
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 成品线边仓报表
|
|
public DataTable FinishProductLinePositionsDT(string area_code, string sale_order, string stations, string WorkOrder, string Container, string Palletnbr, string Serialnbr)
|
|
{
|
|
return dbhelp.ExecuteDataTable(FinishProductLinePositionsSql(area_code, sale_order, stations, WorkOrder, Container, Palletnbr, Serialnbr), null);
|
|
}
|
|
|
|
public string FinishProductLinePositionsSql(string area_code, string sale_order, string stations, string WorkOrder, string Container, string Palletnbr, string Serialnbr)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(area_code))
|
|
{
|
|
strWhere += "and e.area_code = '" + area_code + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(sale_order))
|
|
{
|
|
strWhere += "and b.sale_order = '" + sale_order + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(WorkOrder))
|
|
{
|
|
strWhere += "and b.workorderno = '" + WorkOrder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(Container))
|
|
{
|
|
strWhere += "and c.containerno = '" + Container + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(Palletnbr))
|
|
{
|
|
strWhere += "and a.pallet_nbr = '" + Palletnbr + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(Serialnbr))
|
|
{
|
|
strWhere += "and f.serial_nbr = '" + Serialnbr + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(stations))
|
|
{
|
|
if (stations == "已拼柜")
|
|
{
|
|
strWhere += "and c.containerno is not null ";
|
|
}
|
|
else if (stations == "已包装")
|
|
{
|
|
strWhere += "and c.containerno is null ";
|
|
}
|
|
}
|
|
string sql = @"
|
|
-- 订单号 组件数量 工单 物料名称 单位 料号 规格 母批次号
|
|
-- 单耗 核定用量 损耗率 损耗用量 标准用量 仓库实发量 产线领用量 订单结余量 超出/结约 报废物料
|
|
select e.descriptions,b.sale_order,a.pallet_nbr,f.serial_nbr,a.power_grade
|
|
,d.source_desc,b.product_code,
|
|
--a.pallet_qty,
|
|
a.frame_length_desc,a.jbox_type,a.current_grade
|
|
,a.final_grade,c.containerno
|
|
,case
|
|
when c.containerno is not null then '已拼柜'
|
|
else '已包装'
|
|
end as ZT
|
|
from mes_main.dbo.pack_pallets a
|
|
left join mes_main.dbo.wo_mfg b
|
|
on a.workorder = b.workorder
|
|
left join wh.dbo.tcontainerpallet c
|
|
on a.pallet_nbr =c.palletno
|
|
left join mes_main.dbo.df_source d
|
|
on d.source_group_name = 'BUSBAR' and d.source_value = b.busbar_type
|
|
left join mes_main.dbo.df_areas e
|
|
on e.area_code = b.area_code
|
|
left join mes_main.dbo.assembly_status f
|
|
on f.pallet_nbr = a.pallet_nbr
|
|
left join wh.dbo.tstockinlog g
|
|
on a.pallet_nbr = g.palletno
|
|
--left join [mes_main].[dbo].[config_power_current] e
|
|
--on e.power_grade_group_id = b.power_grade_group_id and a.power_grade = e.power_grade
|
|
WHERE 1=1 and g.palletno is null " + strWhere + @"
|
|
--AND B.area_code = '' AND B.sale_order ='' AND c.containerno is not null
|
|
";
|
|
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
//正拼柜报表sql
|
|
private string LCLReportSql(string containerno, string powergrade, string palletno, string state)
|
|
{
|
|
string sql = string.Empty;
|
|
string strWhere = string.Empty;
|
|
|
|
//if (!string.IsNullOrEmpty(StartDateTime))
|
|
//{
|
|
// strWhere += " and a.wks_visit_date >= '" + StartDateTime + "' ";
|
|
//}
|
|
//if (!string.IsNullOrEmpty(EndDateTime))
|
|
//{
|
|
// strWhere += " and a.wks_visit_date <= '" + EndDateTime + "' ";
|
|
//}
|
|
|
|
if (!string.IsNullOrEmpty(containerno))
|
|
{
|
|
strWhere += "and LCLing.containerno = '" + containerno + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(powergrade))
|
|
{
|
|
strWhere += "and LCLing.powergrade = '" + powergrade + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(palletno))
|
|
{
|
|
strWhere += "and LCLingLotid.palletno = '" + palletno + "' ";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(state))
|
|
{
|
|
strWhere += " and LCLing.state = '" + state + "' ";
|
|
}
|
|
|
|
sql = @"SELECT LCLing.containerno,LCLing.state,LCLing.powergrade,LCLing.count,LCLingLotid.palletno
|
|
FROM [wh].[dbo].[tcontainer] LCLing
|
|
left join [wh].[dbo].[tcontainerpallet] LCLingLotid
|
|
on LCLing.containerno = LCLingLotid.containerno
|
|
WHERE 1=1" + strWhere;
|
|
return sql;
|
|
}
|
|
|
|
//正拼柜报表datatable
|
|
public DataTable LCLReportDT(string powergrade, string palletno, string state, string containerno)
|
|
{
|
|
return dbhelp.ExecuteDataTable(LCLReportSql(powergrade, palletno, state, containerno), null);
|
|
}
|
|
|
|
//入库报表sql
|
|
private string TobeputinstorageSql(string locationname, string type, string pallet, string name, string containerno)
|
|
{
|
|
string sql = string.Empty;
|
|
string strWhere = string.Empty;
|
|
|
|
//if (!string.IsNullOrEmpty(StartDateTime))
|
|
//{
|
|
// strWhere += " and a.wks_visit_date >= '" + StartDateTime + "' ";
|
|
//}
|
|
//if (!string.IsNullOrEmpty(EndDateTime))
|
|
//{
|
|
// strWhere += " and a.wks_visit_date <= '" + EndDateTime + "' ";
|
|
//}
|
|
|
|
if (!string.IsNullOrEmpty(locationname))
|
|
{
|
|
strWhere += "and kw.locationname = '" + locationname + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(name))
|
|
{
|
|
strWhere += "and ck.name = '" + name + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(type))
|
|
{
|
|
strWhere += "and ck.type = '" + type + "' ";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(pallet))
|
|
{
|
|
strWhere += " and lot.pallet = '" + pallet + "' ";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(containerno))
|
|
{
|
|
strWhere += " and LCL.containerno = '" + containerno + "' ";
|
|
}
|
|
|
|
sql = @"/****** Script for SelectTopNRows command from SSMS ******/
|
|
SELECT kw.locationname,ck.name,ck.type,lot.pallet,LCL.containerno,LCL.createuser,LCL.status
|
|
FROM [wh].[dbo].[tstoragelocation] KW
|
|
left join [wh].[dbo].[tstock] CK
|
|
on kw.stockid =ck.id
|
|
left join [wh].[dbo].[treturnstocklog] lot
|
|
on kw.id =lot.storagelocationid
|
|
left join [wh].[dbo].[tcontainerpallet] LCL
|
|
on lot.id =LCL.id
|
|
WHERE 1=1" + strWhere;
|
|
return sql;
|
|
}
|
|
|
|
//入库报表datatable
|
|
public DataTable TobeputinstorageDT(string locationname, string type, string pallet, string name, string containerno)
|
|
{
|
|
return dbhelp.ExecuteDataTable(TobeputinstorageSql(locationname, type, pallet, name, containerno), null);
|
|
}
|
|
|
|
//待拼柜报表sql
|
|
private string TospellarkSql(string StartDateTime, string EndDateTime, string workorder, string power_grade, string pallet_nbr, string product_code, string final_grade, string current_grade)
|
|
{
|
|
string sql = string.Empty;
|
|
string strWhere = string.Empty;
|
|
|
|
if (!string.IsNullOrEmpty(StartDateTime))
|
|
{
|
|
strWhere += " and a.pack_date >= '" + StartDateTime + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(EndDateTime))
|
|
{
|
|
strWhere += " and a.pack_date <= '" + EndDateTime + "' ";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += "and a.workorder in (" + workorder + ") ";
|
|
}
|
|
if (!string.IsNullOrEmpty(product_code))
|
|
{
|
|
strWhere += "and a.product_code = '" + product_code + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(power_grade))
|
|
{
|
|
strWhere += "and a.power_grade = '" + power_grade + "' ";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(pallet_nbr))
|
|
{
|
|
strWhere += " and a.pallet_nbr in (" + pallet_nbr + ") ";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(final_grade))
|
|
{
|
|
strWhere += " and a.final_grade = '" + final_grade + "' ";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(current_grade))
|
|
{
|
|
strWhere += " and a.current_grade = '" + current_grade + "' ";
|
|
}
|
|
|
|
sql = @"select a.pallet_nbr,a.pack_date,a.product_code,a.workorder,a.power_grade,a.final_grade,current_grade from mes_main.dbo.pack_pallets a
|
|
left join wh.dbo.tcontainerpallet b
|
|
on a.pallet_nbr = b.palletno
|
|
left join wh.dbo.tcontainer c
|
|
on b.containerno = c.containerno
|
|
where c.containerno is null" + strWhere;
|
|
return sql;
|
|
}
|
|
|
|
//待拼柜报表datatable
|
|
public DataTable TospellarkDT(string StartDateTime, string EndDateTime, string workorder, string power_grade, string pallet_nbr, string product_code, string final_grade, string current_grade)
|
|
{
|
|
return dbhelp.ExecuteDataTable(TospellarkSql(StartDateTime, EndDateTime, workorder, power_grade, pallet_nbr, product_code, final_grade, current_grade), null);
|
|
}
|
|
|
|
//移库记录报表sql
|
|
private string tmovestocklogSql(string StartDateTime, string EndDateTime, string oldstoragelocationid, string newstoragelocationid, string pallet)
|
|
{
|
|
string sql = string.Empty;
|
|
string strWhere = string.Empty;
|
|
|
|
if (!string.IsNullOrEmpty(StartDateTime))
|
|
{
|
|
strWhere += " and a.createtime >= '" + StartDateTime + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(EndDateTime))
|
|
{
|
|
strWhere += " and a.createtime <= '" + EndDateTime + "' ";
|
|
}
|
|
|
|
//if (!string.IsNullOrEmpty(workorder))
|
|
//{
|
|
// strWhere += "and a.workorder = '" + workorder + "' ";
|
|
//}
|
|
if (!string.IsNullOrEmpty(oldstoragelocationid))
|
|
{
|
|
strWhere += "and b.locationname = '" + oldstoragelocationid + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(newstoragelocationid))
|
|
{
|
|
strWhere += "and b.locationname = '" + newstoragelocationid + "' ";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(pallet))
|
|
{
|
|
strWhere += " and a.pallet in (" + pallet + ") ";
|
|
}
|
|
|
|
//if (!string.IsNullOrEmpty(final_grade))
|
|
//{
|
|
// strWhere += " and a.final_grade = '" + final_grade + "' ";
|
|
//}
|
|
|
|
//if (!string.IsNullOrEmpty(current_grade))
|
|
//{
|
|
// strWhere += " and a.current_grade = '" + current_grade + "' ";
|
|
//}
|
|
|
|
sql = @"SELECT a.pallet,b.locationname,c.locationname,d.Username,a.createtime
|
|
FROM wh.dbo.tmovestocklog a
|
|
left join wh.dbo.tstoragelocation b
|
|
on a.oldstoragelocationid = b.id
|
|
left join wh.dbo.tstoragelocation c
|
|
on a.newstoragelocationid = c.id
|
|
left join wh.dbo.tusers d
|
|
on a.createuser =d.UserId
|
|
where 1=1 " + strWhere;
|
|
return sql;
|
|
}
|
|
|
|
//移库记录报表datatable
|
|
public DataTable tmovestocklogDT(string StartDateTime, string EndDateTime, string oldstoragelocationid, string newstoragelocationid, string pallet)
|
|
{
|
|
return dbhelp.ExecuteDataTable(tmovestocklogSql(StartDateTime, EndDateTime, oldstoragelocationid, newstoragelocationid, pallet), null);
|
|
}
|
|
|
|
//删柜记录报表sql
|
|
private string delcontainerlogSql(string StartDateTime, string EndDateTime, string container, string pallet)
|
|
{
|
|
string sql = string.Empty;
|
|
string strWhere = string.Empty;
|
|
|
|
if (!string.IsNullOrEmpty(StartDateTime))
|
|
{
|
|
strWhere += " and a.createtime >= '" + StartDateTime + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(EndDateTime))
|
|
{
|
|
strWhere += " and a.createtime <= '" + EndDateTime + "' ";
|
|
}
|
|
|
|
//if (!string.IsNullOrEmpty(workorder))
|
|
//{
|
|
// strWhere += "and a.workorder = '" + workorder + "' ";
|
|
//}
|
|
//if (!string.IsNullOrEmpty(oldstoragelocationid))
|
|
//{
|
|
// strWhere += "and b.locationname = '" + oldstoragelocationid + "' ";
|
|
//}
|
|
if (!string.IsNullOrEmpty(container))
|
|
{
|
|
strWhere += "a.container in (" + container + ") ";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(pallet))
|
|
{
|
|
strWhere += " and a.pallet in (" + pallet + ") ";
|
|
}
|
|
|
|
//if (!string.IsNullOrEmpty(final_grade))
|
|
//{
|
|
// strWhere += " and a.final_grade = '" + final_grade + "' ";
|
|
//}
|
|
|
|
//if (!string.IsNullOrEmpty(current_grade))
|
|
//{
|
|
// strWhere += " and a.current_grade = '" + current_grade + "' ";
|
|
//}
|
|
|
|
sql = @"SELECT a.pallet,a.container,a.createuser,a.createtime,remark
|
|
FROM [wh].[dbo].[tdelcontainerlog] a
|
|
where 1=1 " + strWhere;
|
|
return sql;
|
|
}
|
|
|
|
//删柜记录报表datatable
|
|
public DataTable delcontainerlogDT(string StartDateTime, string EndDateTime, string container, string pallet)
|
|
{
|
|
return dbhelp.ExecuteDataTable(delcontainerlogSql(StartDateTime, EndDateTime, container, pallet), null);
|
|
}
|
|
|
|
//退库记录报表sql
|
|
private string returnstocklogSql(string StartDateTime, string EndDateTime, string pallet)
|
|
{
|
|
string sql = string.Empty;
|
|
string strWhere = string.Empty;
|
|
|
|
if (!string.IsNullOrEmpty(StartDateTime))
|
|
{
|
|
strWhere += " and a.createtime >= '" + StartDateTime + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(EndDateTime))
|
|
{
|
|
strWhere += " and a.createtime <= '" + EndDateTime + "' ";
|
|
}
|
|
|
|
//if (!string.IsNullOrEmpty(workorder))
|
|
//{
|
|
// strWhere += "and a.workorder = '" + workorder + "' ";
|
|
//}
|
|
//if (!string.IsNullOrEmpty(oldstoragelocationid))
|
|
//{
|
|
// strWhere += "and b.locationname = '" + oldstoragelocationid + "' ";
|
|
//}
|
|
//if (!string.IsNullOrEmpty(container))
|
|
//{
|
|
// strWhere += "a.container in (" + container + ") ";
|
|
//}
|
|
|
|
if (!string.IsNullOrEmpty(pallet))
|
|
{
|
|
strWhere += " and a.pallet in (" + pallet + ") ";
|
|
}
|
|
|
|
//if (!string.IsNullOrEmpty(final_grade))
|
|
//{
|
|
// strWhere += " and a.final_grade = '" + final_grade + "' ";
|
|
//}
|
|
|
|
//if (!string.IsNullOrEmpty(current_grade))
|
|
//{
|
|
// strWhere += " and a.current_grade = '" + current_grade + "' ";
|
|
//}
|
|
|
|
sql = @"SELECT a.pallet,a.storagelocationid,a.createuser,a.createtime
|
|
FROM [wh].[dbo].[treturnstocklog] a
|
|
where 1=1 " + strWhere;
|
|
return sql;
|
|
}
|
|
|
|
//退库记录报表datatable
|
|
public DataTable returnstocklogDT(string StartDateTime, string EndDateTime, string pallet)
|
|
{
|
|
return dbhelp.ExecuteDataTable(returnstocklogSql(StartDateTime, EndDateTime, pallet), null);
|
|
}
|
|
|
|
//破片率报表sql
|
|
public string FragmentRateReportSql(string StartDateTime, string EndDateTime, string area)
|
|
{
|
|
string sql = string.Empty;
|
|
string strWhere = string.Empty;
|
|
|
|
if (!string.IsNullOrEmpty(StartDateTime))
|
|
{
|
|
strWhere += " AND a.wks_visit_date >= '" + StartDateTime + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(EndDateTime))
|
|
{
|
|
strWhere += " and a.wks_visit_date <'" + EndDateTime + "' ";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(area))
|
|
{
|
|
strWhere += " and b.area_code = '" + area + "' ";
|
|
}
|
|
|
|
sql = @"select f.YYMMDD,f.XXSL,f.LLBL,f.ZCBL
|
|
,'1.50' as LLBZ,ISNULL(f.LLBL,0)/f.XXSL * 1000 AS LLBLL
|
|
,'2.50' AS ZCBZ,ISNULL(f.ZCBL,0)/f.XXSL * 1000 AS ZCBLL
|
|
,f.AXXSL,f.AZCBL,f.BXXSL,f.BZCBL
|
|
,ISNULL(f.AZCBL,0)/case when f.AXXSL='0' then 1 else f.AXXSL end * 1000 AS AZCBLL
|
|
,ISNULL(f.BZCBL,0)/case when f.BXXSL='0' then 1 else f.BXXSL end * 1000 AS BZCBLL
|
|
From
|
|
(
|
|
select
|
|
CONVERT(VARCHAR(24),a.wks_visit_date,111) 'YYMMDD'
|
|
,COUNT(a.serial_nbr) 'XXSL'
|
|
,COUNT(case when a.DefectType = 'LL' then 1 end) 'LLBL'
|
|
,COUNT(case when a.DefectType = 'ZC' then 1 end) 'ZCBL'
|
|
,COUNT(case when a.descriptions = '白班' then 1 end) 'AXXSL'
|
|
--,COUNT(case when a.descriptions = '白班' and a.DefectType = 'LL' then 1 end) 'ALLBL'
|
|
,COUNT(case when a.descriptions = '白班' and a.DefectType = 'ZC' then 1 end) 'AZCBL'
|
|
,COUNT(case when a.descriptions = '夜班' then 1 end) 'BXXSL'
|
|
--,COUNT(case when a.descriptions = '夜班' and a.DefectType = 'LL' then 1 end) 'BLLBL'
|
|
,COUNT(case when a.descriptions = '夜班' and a.DefectType = 'ZC' then 1 end) 'BZCBL'
|
|
from
|
|
(
|
|
SELECT distinct a.serial_nbr,a.wks_visit_date,
|
|
case
|
|
when e.defect_group_name = '来料不良' then 'LL'
|
|
when e.defect_group_name <> '来料不良' and e.defect_group_name is not null then 'LL'
|
|
else 'ZCZJ'
|
|
end as DefectType
|
|
,f.descriptions
|
|
FROM [mes_main].[dbo].[trace_workstation_visit] a
|
|
left join mes_main.dbo.config_workstation b
|
|
on a.wks_id =b.wks_id
|
|
left join [mes_main].[dbo].[defects] c
|
|
on a.serial_nbr = c.serial_nbr
|
|
left join mes_main.dbo.config_defect_type d
|
|
on c.defect_type_id = d.defect_type_id
|
|
left join mes_main.dbo.config_defect_group e
|
|
on d.defect_group_id = e.defect_group_id
|
|
left join mes_main.dbo.df_shift_type f
|
|
on f.shift_type = a.shift_type
|
|
where b.process_code = 'N50'
|
|
" + strWhere + @"
|
|
)A
|
|
group by CONVERT(VARCHAR(24),a.wks_visit_date,111)
|
|
)f";
|
|
return sql;
|
|
}
|
|
|
|
#region 工单结批率界面弹出明细
|
|
public DataTable PopoutDataDT(string workshop, string workorder, string field)
|
|
{
|
|
return dbhelp.ExecuteDataTable(PopoutDataSql(workshop, workorder, field), null);
|
|
}
|
|
|
|
public string PopoutDataSql
|
|
(string workshop, string workorder, string field)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
string strValue = string.Empty;
|
|
//if (!string.IsNullOrEmpty(sale_order))
|
|
//{
|
|
// strWhere += "and b.sale_order = '" + sale_order + "' ";
|
|
//}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and a.workorder = '" + workorder + "' ";
|
|
strValue += " and d.workorder = '" + workorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workshop))
|
|
{
|
|
strWhere += " and a.area_code = '" + workshop + "' ";
|
|
strValue += " and d.area_code = '" + workshop + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(field))
|
|
{
|
|
switch (field)
|
|
{
|
|
case "zjbf":
|
|
strWhere += "and c.descriptions !='生码' and b.serial_status = 'S' ";
|
|
break;
|
|
case "smbf":
|
|
strWhere += "and c.descriptions ='生码' and b.serial_status = 'S' ";
|
|
break;
|
|
case "sm":
|
|
strWhere += "and c.descriptions ='生码' and b.serial_status != 'S' ";
|
|
break;
|
|
case "hj":
|
|
strWhere += "and c.descriptions ='焊接' and b.serial_status != 'S' ";
|
|
break;
|
|
case "dc":
|
|
strWhere += "and c.descriptions ='叠层' and b.serial_status != 'S' ";
|
|
break;
|
|
case "cy":
|
|
strWhere += "and c.descriptions ='层压' and b.serial_status != 'S' ";
|
|
break;
|
|
case "CYHJY":
|
|
strValue += "and b.process_code = 'N40' and C.serial_status != 'S' ";
|
|
break;
|
|
case "zk":
|
|
strWhere += "and c.descriptions ='装框' and b.serial_status != 'S' ";
|
|
break;
|
|
case "qx":
|
|
strWhere += "and c.descriptions ='清洗' and b.serial_status != 'S' ";
|
|
break;
|
|
case "QJ":
|
|
strValue += "and b.process_code = 'N60' and C.serial_status != 'S' ";
|
|
break;
|
|
case "bz":
|
|
strWhere += "and (b.pallet_nbr IS not null or b.process_code = 'P100') and b.serial_status != 'S' and e.palletno IS null ";
|
|
break;
|
|
}
|
|
}
|
|
string sql = string.Empty;
|
|
if (field == "bz")
|
|
{
|
|
sql = @"exec [wh].[dbo].[sp_wo_BatchRate_zx] ";
|
|
sql += string.IsNullOrEmpty(workorder) ? " @v_workorder=N''" : " @v_workorder =N'" + workorder + "'";
|
|
sql += string.IsNullOrEmpty(workshop) ? " ,@v_area_code=N''" : " ,@v_area_code=N'" + workshop + "'";
|
|
} else if (field != "CYHJY" && field != "QJ")
|
|
{
|
|
sql = @"select a.sale_order,a.workorder,b.serial_nbr,c.descriptions,
|
|
--b.process_code,
|
|
b.final_grade
|
|
from mes_main.dbo.wo_mfg a
|
|
left join mes_main.dbo.assembly_status b
|
|
on a.workorder = b.workorder
|
|
left join mes_main.dbo.df_processes c
|
|
on b.process_code =c.process_code
|
|
left join (SELECT a.palletno,MAX(a.status) as status
|
|
,max(a.createtime) as createtime
|
|
FROM [wh].[dbo].[tstockinlog] a
|
|
group by a.palletno) e
|
|
on b.pallet_nbr =e.palletno and e.status in('2','3','4')
|
|
where 1=1 and (b.pallet_nbr IS NULL OR b.pallet_nbr='') " + strWhere;
|
|
}
|
|
else
|
|
{
|
|
sql = @"select d.sale_order,d.workorder,c.serial_nbr
|
|
,e.descriptions,c.final_grade
|
|
from (select aa.serial_nbr,MAX(aa.wks_visit_date) wks_visit_date from mes_main.dbo.trace_workstation_visit aa group by serial_nbr) a
|
|
left join mes_main.dbo.trace_workstation_visit f
|
|
on a.serial_nbr = f.serial_nbr and a.wks_visit_date = f.wks_visit_date
|
|
left join mes_main.dbo.config_workstation b
|
|
on f.wks_id = b.wks_id
|
|
left join mes_main.dbo.assembly_status c
|
|
on a.serial_nbr = c.serial_nbr
|
|
left join mes_main.dbo.df_processes e
|
|
on c.process_code =e.process_code
|
|
left join mes_main.dbo.wo_mfg d
|
|
on c.workorder = d.workorder
|
|
WHERE 1 = 1 and (c.pallet_nbr IS NULL OR c.pallet_nbr='') " + strValue;
|
|
}
|
|
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
#region 生产在制弹出明细
|
|
public DataTable ProduincDT(string workshop, string workorder, string saleorder, string station, string bt, string et, string field,string worktime)
|
|
{
|
|
return dbhelp.ExecuteDataTable(ProduincSql(workshop, workorder, saleorder, station, bt, et, field,worktime), null);
|
|
}
|
|
|
|
public DataTable ProduincDT2(string workshop, string workorder, string saleorder, string station, string wksid,string bt, string et, string field,string worktime)
|
|
{
|
|
return dbhelp.ExecuteDataTable(ProduincSql2(workshop, workorder, saleorder, station, wksid,bt, et, field,worktime), null);
|
|
}
|
|
|
|
public string ProduincSql(string workshop, string workorder, string saleorder, string station, string bt, string et, string field,string worktime)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
string strValue = string.Empty;
|
|
string strValue2 = string.Empty;
|
|
|
|
//if (!string.IsNullOrEmpty(sale_order))
|
|
//{
|
|
// strWhere += "and b.sale_order = '" + sale_order + "' ";
|
|
//}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and d.workorder = '" + workorder + "' ";
|
|
strValue += " and f.workorder = '" + workorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workshop))
|
|
{
|
|
strWhere += " and d.area_code = '" + workshop + "' ";
|
|
strValue += " and f.area_code = '" + workshop + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(saleorder))
|
|
{
|
|
strWhere += " and d.sale_order = '" + saleorder + "' ";
|
|
strValue += " and f.sale_order = '" + saleorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(station))
|
|
{
|
|
strWhere += " and b.process_code = '" + station + "' ";
|
|
strValue += " and g.process_code = '" + station + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and a.wks_visit_date >= '" + bt + "' ";
|
|
strValue += " and a.wks_visit_date >= '" + bt + "' ";
|
|
strValue2 += " and a.wks_visit_date >= '" + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and a.wks_visit_date < '" + et + "' ";
|
|
strValue += " and a.wks_visit_date < '" + et + "' ";
|
|
strValue2 += " and a.wks_visit_date < '" + et + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(worktime))
|
|
{
|
|
strWhere += " and a.shift_type = '" + worktime + "' ";
|
|
strValue += " and a.shift_type ='" + worktime + "' ";
|
|
strValue2 += " and a.shift_type = '" + worktime + "' ";
|
|
}
|
|
string sql = string.Empty;
|
|
if (field == "station_nbr")
|
|
{
|
|
sql = @"SELECT
|
|
case
|
|
when c.pallet_nbr IS not null then '包装'
|
|
when max(right(b.process_code,2)) = '10' then '焊接'
|
|
when max(right(b.process_code,2)) = '15' then '叠层'
|
|
when max(right(b.process_code,2)) = '30' then '层压'
|
|
when max(right(b.process_code,2)) = '40' then '层压后检验'
|
|
when max(right(b.process_code,2)) = '45' then '装框'
|
|
when max(right(b.process_code,2)) = '50' then '清洗'
|
|
when max(right(b.process_code,2)) = '55' then 'FQC'
|
|
when max(right(b.process_code,2)) = '60' then '全检'
|
|
end station
|
|
,a.[serial_nbr],wo.nickname operator,f.descriptions class,
|
|
b.wks_desc,d.workorder,d.sale_order,CONVERT(varchar(100),max(a.wks_visit_date),120) wks_visit_date
|
|
FROM [mes_main].[dbo].[trace_workstation_visit] a
|
|
left join [mes_auth].[dbo].[df_user] wo
|
|
on a.operator=wo.username
|
|
LEFT join mes_main.dbo.config_workstation b
|
|
on a.wks_id = b.wks_id
|
|
left join mes_main.dbo.assembly_status c
|
|
on a.serial_nbr = c.serial_nbr
|
|
left join mes_main.dbo.wo_mfg d
|
|
on c.workorder = d.workorder
|
|
left join mes_main.dbo.df_areas e
|
|
on d.area_code = e.area_code
|
|
left join mes_main.dbo.df_shift_type f
|
|
on a.shift_type = f.shift_type
|
|
where 1 = 1 " + strWhere + @"
|
|
group by a.[serial_nbr],wo.nickname,f.descriptions,
|
|
a.wks_id,b.wks_desc,d.workorder,d.sale_order,c.pallet_nbr,a.wks_visit_date
|
|
order by a.wks_visit_date
|
|
";
|
|
}
|
|
if (field == "going_nbr")
|
|
{
|
|
sql = @"
|
|
select
|
|
case
|
|
when max(right(aa.ZZZD,2)) = '10' then '焊接'
|
|
when max(right(aa.ZZZD,2)) = '15' then '叠层'
|
|
when max(right(aa.ZZZD,2)) = '30' then '层压'
|
|
when max(right(aa.ZZZD,2)) = '40' then '层压后检验'
|
|
when max(right(aa.ZZZD,2)) = '45' then '装框'
|
|
when max(right(aa.ZZZD,2)) = '50' then '清洗'
|
|
when max(right(aa.ZZZD,2)) = '55' then 'FQC'
|
|
when max(right(aa.ZZZD,2)) = '60' then '全检'
|
|
when max(right(aa.ZZZD,2)) = '00' then '全检'
|
|
end station,
|
|
aa.serial_nbr,aa.nickname operator,aa.descriptions class,aa.wks_desc,aa.workorder,aa.sale_order,CONVERT(varchar(100),aa.wks_visit_date,120) wks_visit_date
|
|
from (select f.sale_order,f.workorder,a.serial_nbr,max(a.wks_visit_date) as wks_visit_date,max(g.process_code) AS ZZZD,b.area_code,b.wks_desc,wo.nickname,h.descriptions,a.wks_id
|
|
from mes_main.dbo.trace_workstation_visit a
|
|
left join [mes_auth].[dbo].[df_user] wo
|
|
on a.operator=wo.username
|
|
left join mes_main.dbo.assembly_status e
|
|
on a.serial_nbr = e.serial_nbr
|
|
left join mes_main.dbo.config_products c
|
|
on e.product_code = c.product_code
|
|
left join mes_main.dbo.config_workstation b
|
|
on a.wks_id = b.wks_id
|
|
left join mes_main.dbo.config_process d
|
|
on c.process_group_id = d.process_group_id
|
|
and e.process_code = d.process_code
|
|
left join mes_main.dbo.config_process g
|
|
on c.process_group_id = g.process_group_id
|
|
and g.process_idx-1 = d.process_idx
|
|
LEFT JOIN mes_main.DBO.wo_mfg f
|
|
ON f.workorder = e.workorder
|
|
left join mes_main.dbo.df_shift_type h
|
|
on a.shift_type = h.shift_type
|
|
where 1=1 " + strValue + @"
|
|
group by a.serial_nbr,b.area_code,wo.nickname,h.descriptions,a.wks_id,b.wks_desc,f.workorder,f.sale_order) aa
|
|
JOIN (select a.serial_nbr,MAX(a.wks_visit_date) times
|
|
from mes_main.dbo.trace_workstation_visit a
|
|
where 1=1 " + strValue2 + @"
|
|
group by a.serial_nbr) bb
|
|
on aa.serial_nbr = bb.serial_nbr and aa.wks_visit_date = bb.times
|
|
where aa.ZZZD is not null
|
|
group by aa.serial_nbr,aa.nickname,aa.descriptions,aa.wks_id,aa.wks_desc,aa.workorder,aa.sale_order,aa.wks_visit_date
|
|
order by aa.wks_visit_date
|
|
|
|
|
|
|
|
|
|
";
|
|
}
|
|
return sql;
|
|
}
|
|
|
|
public string ProduincSqlnew(string workshop, string workorder, string saleorder, string station, string bt, string et, string field)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
string strValue = string.Empty;
|
|
string strValue2 = string.Empty;
|
|
|
|
//if (!string.IsNullOrEmpty(sale_order))
|
|
//{
|
|
// strWhere += "and b.sale_order = '" + sale_order + "' ";
|
|
//}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and d.workorder = '" + workorder + "' ";
|
|
strValue += " and f.workorder = '" + workorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workshop))
|
|
{
|
|
strWhere += " and d.area_code = '" + workshop + "' ";
|
|
strValue += " and f.area_code = '" + workshop + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(saleorder))
|
|
{
|
|
strWhere += " and d.sale_order = '" + saleorder + "' ";
|
|
strValue += " and f.sale_order = '" + saleorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(station))
|
|
{
|
|
strWhere += " and b.process_code = '" + station + "' ";
|
|
strValue += " and g.process_code = '" + station + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and a.wks_visit_date >= '" + bt + "' ";
|
|
strValue += " and a.wks_visit_date >= '" + bt + "' ";
|
|
strValue2 += " and a.wks_visit_date >= '" + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and a.wks_visit_date < '" + et + "' ";
|
|
strValue += " and a.wks_visit_date < '" + et + "' ";
|
|
strValue2 += " and a.wks_visit_date < '" + et + "' ";
|
|
}
|
|
string sql = string.Empty;
|
|
if (field == "station_nbr")
|
|
{
|
|
sql = @"SELECT
|
|
case
|
|
when c.pallet_nbr IS not null then '包装'
|
|
when max(right(b.process_code,2)) = '10' then '焊接'
|
|
when max(right(b.process_code,2)) = '15' then '叠层'
|
|
when max(right(b.process_code,2)) = '30' then '层压'
|
|
when max(right(b.process_code,2)) = '40' then '层压后检验'
|
|
when max(right(b.process_code,2)) = '45' then '装框'
|
|
when max(right(b.process_code,2)) = '50' then '清洗'
|
|
when max(right(b.process_code,2)) = '55' then 'FQC'
|
|
when max(right(b.process_code,2)) = '60' then '全检'
|
|
end station
|
|
,a.[serial_nbr],a.operator worker,f.descriptions worktime,
|
|
a.wks_id,d.workorder,d.sale_order,CONVERT(varchar(100),max(a.wks_visit_date),120) wks_visit_date
|
|
FROM [mes_main].[dbo].[trace_workstation_visit] a
|
|
LEFT join mes_main.dbo.config_workstation b
|
|
on a.wks_id = b.wks_id
|
|
left join mes_main.dbo.assembly_status c
|
|
on a.serial_nbr = c.serial_nbr
|
|
left join mes_main.dbo.wo_mfg d
|
|
on c.workorder = d.workorder
|
|
left join mes_main.dbo.df_areas e
|
|
on d.area_code = e.area_code
|
|
left join mes_main.dbo.df_shift_type f
|
|
on a.shift_type = f.shift_type
|
|
where 1 = 1 " + strWhere + @"
|
|
group by a.[serial_nbr],a.operator,f.descriptions,
|
|
a.wks_id,d.workorder,d.sale_order,c.pallet_nbr";
|
|
}
|
|
if (field == "going_nbr")
|
|
{
|
|
sql = @"
|
|
select
|
|
case
|
|
when max(right(aa.ZZZD,2)) = '10' then '焊接'
|
|
when max(right(aa.ZZZD,2)) = '15' then '叠层'
|
|
when max(right(aa.ZZZD,2)) = '30' then '层压'
|
|
when max(right(aa.ZZZD,2)) = '40' then '层压后检验'
|
|
when max(right(aa.ZZZD,2)) = '45' then '装框'
|
|
when max(right(aa.ZZZD,2)) = '50' then '清洗'
|
|
when max(right(aa.ZZZD,2)) = '55' then 'FQC'
|
|
when max(right(aa.ZZZD,2)) = '60' then '全检'
|
|
when max(right(aa.ZZZD,2)) = '00' then '全检'
|
|
end station,
|
|
aa.serial_nbr,aa.operator,aa.descriptions class,aa.wks_id,aa.workorder,aa.sale_order,aa.wks_visit_date
|
|
from (select f.sale_order,f.workorder,a.serial_nbr,MAX(a.wks_visit_date) as wks_visit_date,max(g.process_code) AS ZZZD,b.area_code,a.operator,h.descriptions,a.wks_id
|
|
from mes_main.dbo.trace_workstation_visit a
|
|
left join mes_main.dbo.assembly_status e
|
|
on a.serial_nbr = e.serial_nbr
|
|
left join mes_main.dbo.config_products c
|
|
on e.product_code = c.product_code
|
|
left join mes_main.dbo.config_workstation b
|
|
on a.wks_id = b.wks_id
|
|
left join mes_main.dbo.config_process d
|
|
on c.process_group_id = d.process_group_id
|
|
and e.process_code = d.process_code
|
|
left join mes_main.dbo.config_process g
|
|
on c.process_group_id = g.process_group_id
|
|
and g.process_idx-1 = d.process_idx
|
|
LEFT JOIN mes_main.DBO.wo_mfg f
|
|
ON f.workorder = e.workorder
|
|
left join mes_main.dbo.df_shift_type h
|
|
on a.shift_type = h.shift_type
|
|
where 1=1 " + strValue + @"
|
|
group by a.serial_nbr,b.area_code,a.operator,h.descriptions,a.wks_id,f.workorder,f.sale_order) aa
|
|
JOIN (select a.serial_nbr,MAX(a.wks_visit_date) times
|
|
from mes_main.dbo.trace_workstation_visit a
|
|
where 1=1 " + strValue2 + @"
|
|
group by a.serial_nbr) bb
|
|
on aa.serial_nbr = bb.serial_nbr and aa.wks_visit_date = bb.times
|
|
where aa.ZZZD is not null
|
|
group by aa.serial_nbr,aa.operator,aa.descriptions,aa.wks_id,aa.workorder,aa.sale_order,aa.wks_visit_date
|
|
|
|
|
|
|
|
";
|
|
}
|
|
return sql;
|
|
}
|
|
|
|
public string ProduincSql2(string workshop, string workorder, string saleorder, string station,string wksid, string bt, string et, string field,string worktime)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
string strValue = string.Empty;
|
|
string strValue2 = string.Empty;
|
|
|
|
//if (!string.IsNullOrEmpty(sale_order))
|
|
//{
|
|
// strWhere += "and b.sale_order = '" + sale_order + "' ";
|
|
//}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and d.workorder = '" + workorder + "' ";
|
|
strValue += " and f.workorder = '" + workorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workshop))
|
|
{
|
|
strWhere += " and d.area_code = '" + workshop + "' ";
|
|
strValue += " and f.area_code = '" + workshop + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(saleorder))
|
|
{
|
|
strWhere += " and d.sale_order = '" + saleorder + "' ";
|
|
strValue += " and f.sale_order = '" + saleorder + "' ";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(wksid))
|
|
{
|
|
strWhere += " and a.wks_id = '" + wksid+ "' ";
|
|
strValue += " and a.wks_id = '" + wksid + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and a.wks_visit_date >= '" + bt + "' ";
|
|
strValue += " and a.wks_visit_date >= '" + bt + "' ";
|
|
strValue2 += " and a.wks_visit_date >= '" + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and a.wks_visit_date < '" + et + "' ";
|
|
strValue += " and a.wks_visit_date < '" + et + "' ";
|
|
strValue2 += " and a.wks_visit_date < '" + et + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(worktime))
|
|
{
|
|
strWhere += " and a.shift_type = '" + worktime + "' ";
|
|
strValue += " and a.shift_type ='" + worktime + "' ";
|
|
strValue2 += " and a.shift_type = '" + worktime + "' ";
|
|
}
|
|
string sql = string.Empty;
|
|
if (field == "wke_nbr")
|
|
{
|
|
sql = @"SELECT
|
|
|
|
a.[serial_nbr],wo.nickname operator,f.descriptions class,
|
|
CONVERT(varchar(100),max(a.wks_visit_date),120) wks_visit_date
|
|
FROM [mes_main].[dbo].[trace_workstation_visit] a
|
|
left join [mes_auth].[dbo].[df_user] wo
|
|
on a.operator=wo.username
|
|
LEFT join mes_main.dbo.config_workstation b
|
|
on a.wks_id = b.wks_id
|
|
left join mes_main.dbo.assembly_status c
|
|
on a.serial_nbr = c.serial_nbr
|
|
left join mes_main.dbo.wo_mfg d
|
|
on c.workorder = d.workorder
|
|
left join mes_main.dbo.df_areas e
|
|
on d.area_code = e.area_code
|
|
left join mes_main.dbo.df_shift_type f
|
|
on a.shift_type = f.shift_type
|
|
where 1 = 1 " + strWhere + @"
|
|
group by a.[serial_nbr],wo.nickname,f.descriptions,
|
|
a.wks_id,d.workorder,d.sale_order,c.pallet_nbr,a.wks_visit_date
|
|
order by a.wks_visit_date
|
|
";
|
|
}
|
|
if (field == "going_nbr")
|
|
{
|
|
sql = @"
|
|
select
|
|
case
|
|
when max(right(aa.ZZZD,2)) = '10' then '焊接'
|
|
when max(right(aa.ZZZD,2)) = '15' then '叠层'
|
|
when max(right(aa.ZZZD,2)) = '30' then '层压'
|
|
when max(right(aa.ZZZD,2)) = '40' then '层压后检验'
|
|
when max(right(aa.ZZZD,2)) = '45' then '装框'
|
|
when max(right(aa.ZZZD,2)) = '50' then '清洗'
|
|
when max(right(aa.ZZZD,2)) = '55' then 'FQC'
|
|
when max(right(aa.ZZZD,2)) = '60' then '全检'
|
|
when max(right(aa.ZZZD,2)) = '00' then '全检'
|
|
end station,
|
|
aa.serial_nbr,aa.operator,aa.descriptions class,aa.wks_id,aa.workorder,aa.sale_order,aa.wks_visit_date
|
|
from (select f.sale_order,f.workorder,a.serial_nbr,MAX(a.wks_visit_date) as wks_visit_date,max(g.process_code) AS ZZZD,b.area_code,a.operator,h.descriptions,a.wks_id
|
|
from mes_main.dbo.trace_workstation_visit a
|
|
left join mes_main.dbo.assembly_status e
|
|
on a.serial_nbr = e.serial_nbr
|
|
left join mes_main.dbo.config_products c
|
|
on e.product_code = c.product_code
|
|
left join mes_main.dbo.config_workstation b
|
|
on a.wks_id = b.wks_id
|
|
left join mes_main.dbo.config_process d
|
|
on c.process_group_id = d.process_group_id
|
|
and e.process_code = d.process_code
|
|
left join mes_main.dbo.config_process g
|
|
on c.process_group_id = g.process_group_id
|
|
and g.process_idx-1 = d.process_idx
|
|
LEFT JOIN mes_main.DBO.wo_mfg f
|
|
ON f.workorder = e.workorder
|
|
left join mes_main.dbo.df_shift_type h
|
|
on a.shift_type = h.shift_type
|
|
where 1=1 " + strValue + @"
|
|
group by a.serial_nbr,b.area_code,a.operator,h.descriptions,a.wks_id,f.workorder,f.sale_order) aa
|
|
JOIN (select a.serial_nbr,MAX(a.wks_visit_date) times
|
|
from mes_main.dbo.trace_workstation_visit a
|
|
where 1=1 " + strValue2 + @"
|
|
group by a.serial_nbr) bb
|
|
on aa.serial_nbr = bb.serial_nbr and aa.wks_visit_date = bb.times
|
|
where aa.ZZZD is not null
|
|
group by aa.serial_nbr,aa.operator,aa.descriptions,aa.wks_id,aa.workorder,aa.sale_order,aa.wks_visit_date
|
|
order by aa.wks_visit_date
|
|
|
|
|
|
|
|
";
|
|
}
|
|
|
|
|
|
|
|
|
|
return sql;
|
|
}
|
|
|
|
public string ProduincSql2new(string workshop, string workorder, string saleorder, string station, string wksid, string bt, string et, string field)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
string strValue = string.Empty;
|
|
string strValue2 = string.Empty;
|
|
|
|
//if (!string.IsNullOrEmpty(sale_order))
|
|
//{
|
|
// strWhere += "and b.sale_order = '" + sale_order + "' ";
|
|
//}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and d.workorder = '" + workorder + "' ";
|
|
strValue += " and f.workorder = '" + workorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workshop))
|
|
{
|
|
strWhere += " and d.area_code = '" + workshop + "' ";
|
|
strValue += " and f.area_code = '" + workshop + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(saleorder))
|
|
{
|
|
strWhere += " and d.sale_order = '" + saleorder + "' ";
|
|
strValue += " and f.sale_order = '" + saleorder + "' ";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(wksid))
|
|
{
|
|
strWhere += " and a.wks_id = '" + wksid + "' ";
|
|
strValue += " and a.wks_id = '" + wksid + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and a.wks_visit_date >= '" + bt + "' ";
|
|
strValue += " and a.wks_visit_date >= '" + bt + "' ";
|
|
strValue2 += " and a.wks_visit_date >= '" + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and a.wks_visit_date < '" + et + "' ";
|
|
strValue += " and a.wks_visit_date < '" + et + "' ";
|
|
strValue2 += " and a.wks_visit_date < '" + et + "' ";
|
|
}
|
|
string sql = string.Empty;
|
|
if (field == "wke_nbr")
|
|
{
|
|
sql = @"SELECT
|
|
|
|
a.[serial_nbr],a.operator worker,f.descriptions worktime,
|
|
CONVERT(varchar(100),max(a.wks_visit_date),120) wks_visit_date
|
|
FROM [mes_main].[dbo].[trace_workstation_visit] a
|
|
LEFT join mes_main.dbo.config_workstation b
|
|
on a.wks_id = b.wks_id
|
|
left join mes_main.dbo.assembly_status c
|
|
on a.serial_nbr = c.serial_nbr
|
|
left join mes_main.dbo.wo_mfg d
|
|
on c.workorder = d.workorder
|
|
left join mes_main.dbo.df_areas e
|
|
on d.area_code = e.area_code
|
|
left join mes_main.dbo.df_shift_type f
|
|
on a.shift_type = f.shift_type
|
|
where 1 = 1 " + strWhere + @"
|
|
group by a.[serial_nbr],a.operator,f.descriptions,
|
|
a.wks_id,d.workorder,d.sale_order,c.pallet_nbr";
|
|
}
|
|
if (field == "going_nbr")
|
|
{
|
|
sql = @"
|
|
select
|
|
case
|
|
when max(right(aa.ZZZD,2)) = '10' then '焊接'
|
|
when max(right(aa.ZZZD,2)) = '15' then '叠层'
|
|
when max(right(aa.ZZZD,2)) = '30' then '层压'
|
|
when max(right(aa.ZZZD,2)) = '40' then '层压后检验'
|
|
when max(right(aa.ZZZD,2)) = '45' then '装框'
|
|
when max(right(aa.ZZZD,2)) = '50' then '清洗'
|
|
when max(right(aa.ZZZD,2)) = '55' then 'FQC'
|
|
when max(right(aa.ZZZD,2)) = '60' then '全检'
|
|
when max(right(aa.ZZZD,2)) = '00' then '全检'
|
|
end station,
|
|
aa.serial_nbr,aa.operator,aa.descriptions class,aa.wks_id,aa.workorder,aa.sale_order,aa.wks_visit_date
|
|
from (select f.sale_order,f.workorder,a.serial_nbr,MAX(a.wks_visit_date) as wks_visit_date,max(g.process_code) AS ZZZD,b.area_code,a.operator,h.descriptions,a.wks_id
|
|
from mes_main.dbo.trace_workstation_visit a
|
|
left join mes_main.dbo.assembly_status e
|
|
on a.serial_nbr = e.serial_nbr
|
|
left join mes_main.dbo.config_products c
|
|
on e.product_code = c.product_code
|
|
left join mes_main.dbo.config_workstation b
|
|
on a.wks_id = b.wks_id
|
|
left join mes_main.dbo.config_process d
|
|
on c.process_group_id = d.process_group_id
|
|
and e.process_code = d.process_code
|
|
left join mes_main.dbo.config_process g
|
|
on c.process_group_id = g.process_group_id
|
|
and g.process_idx-1 = d.process_idx
|
|
LEFT JOIN mes_main.DBO.wo_mfg f
|
|
ON f.workorder = e.workorder
|
|
left join mes_main.dbo.df_shift_type h
|
|
on a.shift_type = h.shift_type
|
|
where 1=1 " + strValue + @"
|
|
group by a.serial_nbr,b.area_code,a.operator,h.descriptions,a.wks_id,f.workorder,f.sale_order) aa
|
|
JOIN (select a.serial_nbr,MAX(a.wks_visit_date) times
|
|
from mes_main.dbo.trace_workstation_visit a
|
|
where 1=1 " + strValue2 + @"
|
|
group by a.serial_nbr) bb
|
|
on aa.serial_nbr = bb.serial_nbr and aa.wks_visit_date = bb.times
|
|
where aa.ZZZD is not null
|
|
group by aa.serial_nbr,aa.operator,aa.descriptions,aa.wks_id,aa.workorder,aa.sale_order,aa.wks_visit_date
|
|
|
|
|
|
|
|
";
|
|
}
|
|
|
|
|
|
|
|
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 包装产能统计
|
|
public DataTable PackCapacityDT(string workshop, string workorder, string saleorder)
|
|
{
|
|
return dbhelp.ExecuteDataTable(PackCapacitySql(workshop, workorder, saleorder), null);
|
|
}
|
|
|
|
public string PackCapacitySql(string workshop, string workorder, string saleorder)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(saleorder))
|
|
{
|
|
strWhere += "and b.sale_order = '" + saleorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and b.workorder = '" + workorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workshop))
|
|
{
|
|
strWhere += " and b.area_code = '" + workshop + "' ";
|
|
}
|
|
string sql = @" SELECT
|
|
f.descriptions,a.workorder,b.sale_order,b.plan_qty
|
|
,COUNT(
|
|
case
|
|
when a.power_grade = c.power_grade and a.current_grade = d.current_grade then 1 end
|
|
) pack_qty
|
|
,c.power_grade powerGroup,d.current_grade currentGroup,a.final_grade grade,c.lower_power lowPower,c.upper_power upPower
|
|
,e.descriptions workType
|
|
FROM [mes_main].[dbo].[wo_mfg] b
|
|
left join [mes_main].[dbo].[assembly_status] a
|
|
on a.workorder = b.workorder
|
|
left join [mes_main].[dbo].[config_power] c
|
|
on b.power_grade_group_id = c.power_grade_group_id
|
|
--and a.power_grade =c.power_grade
|
|
left join [mes_main].[dbo].[config_power_current] d
|
|
on b.power_grade_group_id = d.power_grade_group_id and c.power_grade = d.power_grade
|
|
--and a.current_grade = d.current_grade
|
|
left join [mes_main].[dbo].[df_order_type] e
|
|
on e.order_type = b.Order_Type
|
|
left join [mes_main].[dbo].df_areas f
|
|
on b.area_code = f.area_code
|
|
where a.pallet_nbr is not null " + strWhere + @"
|
|
group by f.descriptions,a.workorder,b.sale_order,b.plan_qty
|
|
,c.power_grade,d.current_grade,a.final_grade,c.lower_power,c.upper_power
|
|
,e.descriptions";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 组件班组产量表 2020-09-01
|
|
public DataTable ShiftProductionDT(string workshop, string begintime, string endtime, string station, string workorder, string type = "",string mod="")
|
|
{
|
|
return dbhelp.ExecuteDataTable(ShiftProductionSql(workshop, begintime, endtime, station, workorder,type,mod), null);
|
|
}
|
|
|
|
public string ShiftProductionSql(string workshop, string begintime, string endtime, string station, string workorder,string type,string mod)
|
|
{
|
|
string strWhereSt = string.Empty;
|
|
string strWhereStt = string.Empty;
|
|
string strWhereEl = string.Empty;
|
|
string strWherePK = string.Empty;
|
|
|
|
if (!string.IsNullOrEmpty(workshop))
|
|
{
|
|
strWhereSt += "and c.area_code = '" + workshop + "' ";
|
|
strWhereEl += "and ff.area_code = '" + workshop + "' ";
|
|
strWherePK += "and d.area_code = '" + workshop + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(begintime))
|
|
{
|
|
strWhereSt += " and b.wks_visit_date >= '" + begintime + "' ";
|
|
strWhereEl += " and bb.wks_visit_date >= '" + begintime + "' ";
|
|
strWherePK += " and a.pack_date >= '" + begintime + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(endtime))
|
|
{
|
|
strWhereSt += " and b.wks_visit_date <= '" + endtime + "' ";
|
|
strWhereEl += " and bb.wks_visit_date <= '" + endtime + "' ";
|
|
strWherePK += " and a.pack_date <= '" + endtime + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(station))
|
|
{
|
|
strWhereSt += " and d.process_code = '" + station + "' ";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(type))
|
|
{
|
|
strWhereStt += " and dd.shift_type = '" + type + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhereSt += " c.workorder = '" + workorder + "' ";
|
|
strWhereEl += " ff.workorder = '" + workorder + "' ";
|
|
strWherePK += " d.workorder = '" + workorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(mod))
|
|
{
|
|
strWhereSt += " and e.mod_spec_value = '" + mod + "' ";
|
|
strWhereEl += " and gg.mod_spec_value = '" + mod + "' ";
|
|
strWherePK += " and c.mod_spec_value = '" + mod + "' ";
|
|
}
|
|
string sql = string.Empty;
|
|
|
|
if (string.IsNullOrWhiteSpace(type))
|
|
{
|
|
if (station != "QEL" && station != "HEL" && station != "IV" && station != "PACK")
|
|
{
|
|
sql = @"
|
|
select a.shift_type,a.descriptions shift_name,e.mod_spec_value,count(b.serial_nbr) qty
|
|
FROM [mes_main].[dbo].[df_shift_type] a
|
|
left join [mes_main].[dbo].[trace_workstation_visit] b
|
|
on a.shift_type = b.shift_type
|
|
LEFT JOIN mes_main.dbo.wo_mfg c
|
|
on b.schedule_nbr = c.workorder
|
|
left join mes_main.dbo.config_products e
|
|
on c.product_code = e.product_code
|
|
left join [mes_main].[dbo].[config_workstation] d
|
|
on d.wks_id = b.wks_id
|
|
where 1 = 1 and e.mod_spec_value is not null " + strWhereSt + @"
|
|
group by a.shift_type,a.descriptions,e.mod_spec_value
|
|
";
|
|
}
|
|
else if (station == "QEL" || station == "HEL")
|
|
{
|
|
sql = @"
|
|
select cc.shift_code shift_type,dd.descriptions shift_name,gg.mod_spec_value
|
|
,count(bb.serial_nbr) qty
|
|
from ( select a.serial_nbr,MAX(wks_visit_date) wks_visit_date
|
|
FROM [mes_level2_iface].[dbo].[el_hist] a
|
|
where a.process_code = '" + station + @"'
|
|
group by a.serial_nbr) bb
|
|
left join [mes_level2_iface].[dbo].[el_hist] aa
|
|
on aa.serial_nbr = bb.serial_nbr and aa.wks_visit_date = bb.wks_visit_date
|
|
LEFT JOIN [mes_auth].[dbo].[df_user] cc
|
|
on aa.operator = cc.username
|
|
LEFT JOIN [mes_main].[dbo].[df_shift_type] dd
|
|
on cc.shift_code = dd.shift_type
|
|
left join mes_main.dbo.assembly_status ee
|
|
on ee.serial_nbr = bb.serial_nbr
|
|
left join mes_main.dbo.wo_mfg ff
|
|
on ff.workorder = ee.workorder
|
|
left join mes_main.dbo.config_products gg
|
|
on ff.product_code = gg.product_code
|
|
where 1 = 1 " + strWhereEl + @"
|
|
group by cc.shift_code,dd.descriptions,gg.mod_spec_value
|
|
";
|
|
}
|
|
else if (station == "IV")
|
|
{
|
|
if (string.IsNullOrWhiteSpace(mod))
|
|
{
|
|
sql = @"
|
|
select cc.shift_code,dd.descriptions,gg.mod_spec_value
|
|
,count(bb.serial_nbr) qty
|
|
from ( select a.serial_nbr,MAX(wks_visit_date) wks_visit_date
|
|
FROM [mes_level2_iface].[dbo].[iv_hist] a
|
|
group by a.serial_nbr) bb
|
|
left join [mes_level2_iface].[dbo].[iv_hist] aa
|
|
on aa.serial_nbr = bb.serial_nbr and aa.wks_visit_date = bb.wks_visit_date
|
|
LEFT JOIN [mes_auth].[dbo].[df_user] cc
|
|
on aa.operator = cc.username
|
|
LEFT JOIN [mes_main].[dbo].[df_shift_type] dd
|
|
on cc.shift_code = dd.shift_type
|
|
left join mes_main.dbo.assembly_status ee
|
|
on ee.serial_nbr = bb.serial_nbr
|
|
left join mes_main.dbo.wo_mfg ff
|
|
on ff.workorder = ee.workorder
|
|
left join mes_main.dbo.config_products gg
|
|
on ff.product_code = gg.product_code
|
|
where gg.mod_spec_value is not null " + strWhereEl + @"
|
|
group by cc.shift_code,dd.descriptions,gg.mod_spec_value
|
|
";
|
|
}
|
|
else
|
|
{
|
|
sql = @"
|
|
select
|
|
--bb.serial_nbr,cc.shift_code,dd.descriptions,gg.mod_spec_value,
|
|
f.descriptions,dd.descriptions shift_name,bb.serial_nbr,gg.mod_spec_value
|
|
,'IV' as process_desc,d.wks_desc,CONVERT(nvarchar(20),bb.wks_visit_date,120) wks_visit_date
|
|
,ff.workorder,gg.product_code,h.lot_nbr,h.supplier_code,i.descriptions as supplier_desc,j.final_grade
|
|
from ( select a.serial_nbr,MAX(wks_visit_date) wks_visit_date
|
|
FROM [mes_level2_iface].[dbo].[iv_hist] a
|
|
group by a.serial_nbr) bb
|
|
left join [mes_level2_iface].[dbo].[iv_hist] aa
|
|
on aa.serial_nbr = bb.serial_nbr and aa.wks_visit_date = bb.wks_visit_date
|
|
LEFT JOIN [mes_auth].[dbo].[df_user] cc
|
|
on aa.operator = cc.username
|
|
LEFT JOIN [mes_main].[dbo].[df_shift_type] dd
|
|
on cc.shift_code = dd.shift_type
|
|
left join mes_main.dbo.assembly_status ee
|
|
on ee.serial_nbr = bb.serial_nbr
|
|
left join mes_main.dbo.wo_mfg ff
|
|
on ff.workorder = ee.workorder
|
|
left join mes_main.dbo.config_products gg
|
|
on ff.product_code = gg.product_code
|
|
left join [mes_main].[dbo].[config_workstation] d
|
|
on d.wks_id = aa.wks_id
|
|
left join mes_main.dbo.df_areas f
|
|
on f.area_code = d.area_code
|
|
left join mes_main.dbo.df_processes g
|
|
on g.process_code = d.process_code
|
|
left join mes_main.dbo.trace_componnet_lot h
|
|
on h.serial_nbr = bb.serial_nbr and h.part_type = 'CELL'
|
|
left join mes_level4_iface.dbo.master_supplier i
|
|
on h.supplier_code = i.supplier_code
|
|
left join mes_main.dbo.assembly_status j
|
|
on bb.serial_nbr = j.serial_nbr
|
|
where gg.mod_spec_value is not null " + strWhereStt + @" " + strWhereEl + @"
|
|
";
|
|
}
|
|
}
|
|
else if (station == "PACK")
|
|
{
|
|
sql = @"
|
|
select b.shift_type,e.descriptions,c.mod_spec_value,count(a.serial_nbr) qty
|
|
from[mes_main].[dbo].[assembly_status]
|
|
a
|
|
left join[mes_main].[dbo].[pack_pallets]
|
|
b
|
|
on a.pallet_nbr = b.pallet_nbr
|
|
LEFT JOIN[mes_main].[dbo].[df_shift_type]
|
|
e
|
|
on b.shift_type = e.shift_type
|
|
left join mes_main.dbo.config_products c
|
|
on b.product_code = c.product_code
|
|
left join mes_main.dbo.wo_mfg d
|
|
on d.workorder = b.workorder
|
|
where 1 = 1 and c.mod_spec_value is not null " + strWherePK + @"
|
|
group by b.shift_type, e.descriptions, c.product_code,c.mod_spec_value
|
|
";
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (station != "QEL" && station != "HEL" && station != "IV" && station != "PACK")
|
|
{
|
|
sql = @"
|
|
select f.descriptions,a.descriptions shift_name,b.serial_nbr,e.mod_spec_value
|
|
,g.descriptions as process_desc,d.wks_desc,CONVERT(nvarchar(20),b.wks_visit_date,120) wks_visit_date
|
|
,c.workorder,e.product_code,h.lot_nbr,h.supplier_code,i.descriptions as supplier_desc,j.final_grade
|
|
FROM [mes_main].[dbo].[df_shift_type] a
|
|
left join [mes_main].[dbo].[trace_workstation_visit] b
|
|
on a.shift_type = b.shift_type
|
|
LEFT JOIN mes_main.dbo.wo_mfg c
|
|
on b.schedule_nbr = c.workorder
|
|
left join mes_main.dbo.config_products e
|
|
on c.product_code = e.product_code
|
|
left join [mes_main].[dbo].[config_workstation] d
|
|
on d.wks_id = b.wks_id
|
|
left join mes_main.dbo.df_areas f
|
|
on f.area_code = d.area_code
|
|
left join mes_main.dbo.df_processes g
|
|
on g.process_code = d.process_code
|
|
left join mes_main.dbo.trace_componnet_lot h
|
|
on h.serial_nbr = b.serial_nbr and h.part_type = 'CELL'
|
|
left join mes_level4_iface.dbo.master_supplier i
|
|
on h.supplier_code = i.supplier_code
|
|
left join mes_main.dbo.assembly_status j
|
|
on b.serial_nbr = j.serial_nbr
|
|
where 1 = 1 and a.shift_type = '" + type + @"' " + strWhereSt + @"
|
|
";
|
|
}
|
|
else if (station == "QEL" || station == "HEL")
|
|
{
|
|
sql = @"
|
|
|
|
select
|
|
-- bb.serial_nbr,cc.shift_code,dd.descriptions,gg.mod_spec_value,
|
|
f.descriptions,dd.descriptions shift_name,bb.serial_nbr,gg.mod_spec_value
|
|
,'" + station + @"' as process_desc,d.wks_desc,CONVERT(nvarchar(20),bb.wks_visit_date,120) wks_visit_date
|
|
,ff.workorder,gg.product_code,h.lot_nbr,h.supplier_code,i.descriptions as supplier_desc,j.final_grade
|
|
from
|
|
( select a.serial_nbr,MAX(wks_visit_date) wks_visit_date
|
|
FROM [mes_level2_iface].[dbo].[el_hist] a
|
|
where a.process_code = '" + station + @"'
|
|
group by a.serial_nbr) bb
|
|
left join [mes_level2_iface].[dbo].[el_hist] aa
|
|
on aa.serial_nbr = bb.serial_nbr and aa.wks_visit_date = bb.wks_visit_date
|
|
LEFT JOIN [mes_auth].[dbo].[df_user] cc
|
|
on aa.operator = cc.username
|
|
LEFT JOIN [mes_main].[dbo].[df_shift_type] dd
|
|
on cc.shift_code = dd.shift_type
|
|
left join mes_main.dbo.assembly_status ee
|
|
on ee.serial_nbr = bb.serial_nbr
|
|
left join mes_main.dbo.wo_mfg ff
|
|
on ff.workorder = ee.workorder
|
|
left join mes_main.dbo.config_products gg
|
|
on ff.product_code = gg.product_code
|
|
left join [mes_main].[dbo].[config_workstation] d
|
|
on d.wks_id = aa.wks_id
|
|
left join mes_main.dbo.df_areas f
|
|
on f.area_code = d.area_code
|
|
left join mes_main.dbo.df_processes g
|
|
on g.process_code = d.process_code
|
|
left join mes_main.dbo.trace_componnet_lot h
|
|
on h.serial_nbr = bb.serial_nbr and h.part_type = 'CELL'
|
|
left join mes_level4_iface.dbo.master_supplier i
|
|
on h.supplier_code = i.supplier_code
|
|
left join mes_main.dbo.assembly_status j
|
|
on bb.serial_nbr = j.serial_nbr
|
|
where 1 = 1 and dd.shift_type='" + type+@"' " + strWhereEl + @"
|
|
";
|
|
}
|
|
else if (station == "IV")
|
|
{
|
|
sql = @"
|
|
select
|
|
--bb.serial_nbr,cc.shift_code,dd.descriptions,gg.mod_spec_value,
|
|
f.descriptions,dd.descriptions shift_name,bb.serial_nbr,gg.mod_spec_value
|
|
,'IV' as process_desc,d.wks_id,CONVERT(nvarchar(20),bb.wks_visit_date,120) wks_visit_date
|
|
,c.workorder,e.product_code,h.lot_nbr,h.supplier_code,i.descriptions as supplier_desc,j.final_grade
|
|
from ( select a.serial_nbr,MAX(wks_visit_date) wks_visit_date
|
|
FROM [mes_level2_iface].[dbo].[iv_hist] a
|
|
group by a.serial_nbr) bb
|
|
left join [mes_level2_iface].[dbo].[iv_hist] aa
|
|
on aa.serial_nbr = bb.serial_nbr and aa.wks_visit_date = bb.wks_visit_date
|
|
LEFT JOIN [mes_auth].[dbo].[df_user] cc
|
|
on aa.operator = cc.username
|
|
LEFT JOIN [mes_main].[dbo].[df_shift_type] dd
|
|
on cc.shift_code = dd.shift_type
|
|
left join mes_main.dbo.assembly_status ee
|
|
on ee.serial_nbr = bb.serial_nbr
|
|
left join mes_main.dbo.wo_mfg ff
|
|
on ff.workorder = ee.workorder
|
|
left join mes_main.dbo.config_products gg
|
|
on ff.product_code = gg.product_code
|
|
left join [mes_main].[dbo].[config_workstation] d
|
|
on d.wks_id = aa.wks_id
|
|
left join mes_main.dbo.df_areas f
|
|
on f.area_code = d.area_code
|
|
left join mes_main.dbo.df_processes g
|
|
on g.process_code = d.process_code
|
|
left join mes_main.dbo.trace_componnet_lot h
|
|
on h.serial_nbr = b.serial_nbr and h.part_type = 'CELL'
|
|
left join mes_level4_iface.dbo.master_supplier i
|
|
on h.supplier_code = i.supplier_code
|
|
left join mes_main.dbo.assembly_status j
|
|
on b.serial_nbr = j.serial_nbr
|
|
where gg.mod_spec_value is not null and dd.shift_type='" + type+@"' " + strWhereEl + @"
|
|
";
|
|
}
|
|
|
|
else if (station == "PACK")
|
|
{
|
|
sql = @"
|
|
select
|
|
--a.serial_nbr,b.shift_type,e.descriptions,c.mod_spec_value,
|
|
f.descriptions,e.descriptions shift_name,a.serial_nbr,c.mod_spec_value
|
|
,g.descriptions as process_desc,d.wks_desc
|
|
,CONVERT(nvarchar(20),a.pack_date,120) wks_visit_date
|
|
,d.workorder,c.product_code,h.lot_nbr,h.supplier_code,i.descriptions as supplier_desc,j.final_grade
|
|
from[mes_main].[dbo].[assembly_status]
|
|
a
|
|
left join[mes_main].[dbo].[pack_pallets]
|
|
b
|
|
on a.pallet_nbr = b.pallet_nbr
|
|
LEFT JOIN[mes_main].[dbo].[df_shift_type]
|
|
e
|
|
on b.shift_type = e.shift_type
|
|
left join mes_main.dbo.config_products c
|
|
on b.product_code = c.product_code
|
|
--left join mes_main.dbo.wo_mfg d
|
|
--on d.workorder = b.workorder
|
|
left join [mes_main].[dbo].[config_workstation] d
|
|
on d.wks_id = b.wks_id
|
|
left join mes_main.dbo.df_areas f
|
|
on f.area_code = d.area_code
|
|
left join mes_main.dbo.df_processes g
|
|
on g.process_code = d.process_code
|
|
left join mes_main.dbo.trace_componnet_lot h
|
|
on h.serial_nbr = a.serial_nbr and h.part_type = 'CELL'
|
|
left join mes_level4_iface.dbo.master_supplier i
|
|
on h.supplier_code = i.supplier_code
|
|
left join mes_main.dbo.assembly_status j
|
|
on a.serial_nbr = j.serial_nbr
|
|
where 1 = 1 and c.mod_spec_value is not null and e.shift_type='" + type+@"' " + strWherePK + @"
|
|
";
|
|
|
|
}
|
|
}
|
|
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
#region 每日投产包装完成率
|
|
public DataTable DayPackCompleteDT(string workshop, string workorder, string saleorder)
|
|
{
|
|
return dbhelp.ExecuteDataTable(DayPackCompleteSql(workshop, workorder, saleorder), null);
|
|
}
|
|
|
|
public string DayPackCompleteSql(string workshop, string workorder, string saleorder)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(saleorder))
|
|
{
|
|
strWhere += "and b.sale_order = '" + saleorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and b.workorder = '" + workorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workshop))
|
|
{
|
|
strWhere += " and b.area_code = '" + workshop + "' ";
|
|
}
|
|
string sql = @" select c.descriptions,a.workorder,b.sale_order,
|
|
COUNT(
|
|
case
|
|
when RIGHT(a.process_code,2)>=15 then 1
|
|
end) number,
|
|
COUNT(
|
|
case
|
|
when a.pallet_nbr is not null then 1
|
|
end
|
|
) pack,
|
|
|
|
isnull(CAST(cast(COUNT(
|
|
case
|
|
when a.pallet_nbr is not null then 1
|
|
end
|
|
)/ nullif(CAST(COUNT(
|
|
case
|
|
when RIGHT(a.process_code,2)>=15 then 1
|
|
end)AS FLOAT),0)*100 as numeric(18,2)) AS varchar(50)),0)+'%' prop
|
|
from [mes_main].[dbo].[assembly_status] a
|
|
left join [mes_main].[dbo].wo_mfg b
|
|
on a.workorder = b.workorder
|
|
LEFT JOIN mes_main.dbo.df_areas c
|
|
on b.area_code = c.area_code
|
|
where 1 = 1" + strWhere + @"
|
|
group by a.workorder,b.sale_order,c.descriptions";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
#region 生码未包装组件查询
|
|
public DataTable UnPackComponentDT(string workshop, string workorder, string saleorder)
|
|
{
|
|
return dbhelp.ExecuteDataTable(UnPackComponentSql(workshop, workorder, saleorder), null);
|
|
}
|
|
|
|
public string UnPackComponentSql(string workshop, string workorder, string saleorder)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(saleorder))
|
|
{
|
|
strWhere += "and b.sale_order = '" + saleorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and b.workorder = '" + workorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workshop))
|
|
{
|
|
strWhere += " and b.area_code = '" + workshop + "' ";
|
|
}
|
|
string sql = @" select * from (select c.descriptions,b.workorder,b.sale_order,
|
|
case
|
|
when a.pallet_nbr IS not NULL THEN '包装'
|
|
when e.process_code = 'M10' THEN '待焊接'
|
|
when e.process_code = 'M15' THEN '待叠层'
|
|
when e.process_code = 'N30' THEN '待层压'
|
|
when e.process_code = 'N40' THEN '待层压后检验'
|
|
when e.process_code = 'M45' THEN '待装框'
|
|
when e.process_code = 'N50' THEN '待清洗'
|
|
when e.process_code = 'N55' THEN '待FQC'
|
|
when e.process_code = 'N60' THEN '待全检'
|
|
when e.process_code = 'P100' THEN '待包装'
|
|
END process_code,
|
|
a.serial_nbr,
|
|
CONVERT(varchar(100), a.create_date, 120) create_date,
|
|
case
|
|
when a.pallet_nbr IS NULL then datediff(hh,a.create_date, GETDATE())
|
|
else '0'
|
|
end dull
|
|
--'operator' operator
|
|
from [mes_main].[dbo].[assembly_status] a
|
|
left join [mes_main].[dbo].wo_mfg b
|
|
on a.workorder = b.workorder
|
|
left join [mes_main].[dbo].df_areas c
|
|
on b.area_code = c.area_code
|
|
left join mes_main.dbo.config_products d
|
|
on b.product_code = d.product_code
|
|
left join mes_main.dbo.config_process e
|
|
on d.process_group_id = e.process_group_id and (a.process_idx + 1) = e.process_idx
|
|
where 1 = 1" + strWhere + @") zh
|
|
where zh.process_code != '包装'";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 材料批号查询
|
|
public DataTable MaterialBatchNumberDT(string workorder)
|
|
{
|
|
return dbhelp.ExecuteDataTable(MaterialBatchNumberSql(workorder), null);
|
|
}
|
|
|
|
public string MaterialBatchNumberSql(string workorder)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
//if (!string.IsNullOrEmpty(saleorder))
|
|
//{
|
|
// strWhere += "and b.sale_order = '" + saleorder + "' ";
|
|
//}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and a.workorder = '" + workorder + "' ";
|
|
}
|
|
//if (!string.IsNullOrEmpty(workshop))
|
|
//{
|
|
// strWhere += " and b.area_code = '" + workshop + "' ";
|
|
//}
|
|
string sql = @"select jy.part_type_desc,jl.orig_batch_nbr,jy.lot_nbr,
|
|
jy.lot_qty_remaining,jy.lot_qty,jy.real_nbr-SUM(jl.lot_qty) residue,
|
|
jy.uom,jy.supplier_code,jy.attr_value
|
|
from(select a.part_type_desc,b.orig_batch_nbr,b.lot_nbr
|
|
,b.lot_qty_remaining,b.lot_qty,
|
|
a.real_nbr,
|
|
--residue,
|
|
b.uom,b.supplier_code,
|
|
case
|
|
when a.part_type_desc = '电池片' then c.attr_value
|
|
when a.part_type_desc = 'EVA' then d.attr_value+'/'+e.attr_value
|
|
when a.part_type_desc = '高透EVA' then f.attr_value
|
|
when a.part_type_desc = '背板' then h.attr_value+'/'+i.attr_value
|
|
when a.part_type_desc = '玻璃' then j.attr_value
|
|
when a.part_type_desc = '互联条' then k.attr_value
|
|
when a.part_type_desc = '汇流条' then l.attr_value
|
|
when a.part_type_desc = '助焊剂' then m.attr_value
|
|
when a.part_type_desc = '线盒' then n.attr_value
|
|
when a.part_type_desc = '长型材' then o.attr_value+'/'+p.attr_value
|
|
when a.part_type_desc = '短型材' then q.attr_value+'/'+r.attr_value
|
|
when a.part_type_desc = '接线盒胶' then s.attr_value
|
|
when a.part_type_desc = 'AB胶' then t.attr_value
|
|
when a.part_type_desc = '型材胶' then u.attr_value
|
|
when a.part_type_desc = '隔离条' then v.attr_value
|
|
end attr_value
|
|
FROM [mes_main].[dbo].[config_bom_mfg] a
|
|
left join [mes_main].[dbo].[pack_material_lot] b
|
|
on a.bom_part_nbr = b.part_nbr and a.workorder = b.workorder
|
|
left join [mes_main].[dbo].[config_mat_attr] c
|
|
on a.bom_part_nbr = c.part_nbr and c.attr_code = 'cell_uop'
|
|
left join [mes_main].[dbo].[config_mat_attr] d
|
|
on a.bom_part_nbr = d.part_nbr and d.attr_code ='eva_length'
|
|
left join [mes_main].[dbo].[config_mat_attr] e
|
|
on a.bom_part_nbr = e.part_nbr and e.attr_code ='eva_width'
|
|
left join [mes_main].[dbo].[config_mat_attr] f
|
|
on a.bom_part_nbr = d.part_nbr and f.attr_code ='eva_length'
|
|
--left join [mes_main].[dbo].[config_mat_attr] g
|
|
--on a.bom_part_nbr = e.part_nbr and g.attr_code ='eva_width'
|
|
left join [mes_main].[dbo].[config_mat_attr] h
|
|
on a.bom_part_nbr = d.part_nbr and h.attr_code ='bks_length'
|
|
left join [mes_main].[dbo].[config_mat_attr] i
|
|
on a.bom_part_nbr = e.part_nbr and i.attr_code ='bks_width'
|
|
left join [mes_main].[dbo].[config_mat_attr] j
|
|
on a.bom_part_nbr = e.part_nbr and j.attr_code ='glass_size'
|
|
left join [mes_main].[dbo].[config_mat_attr] k
|
|
on a.bom_part_nbr = e.part_nbr and j.attr_code ='hulian_type'
|
|
left join [mes_main].[dbo].[config_mat_attr] l
|
|
on a.bom_part_nbr = e.part_nbr and j.attr_code ='huiliu_type'
|
|
left join [mes_main].[dbo].[config_mat_attr] m
|
|
on a.bom_part_nbr = e.part_nbr and m.attr_code ='Solder_type'
|
|
left join [mes_main].[dbo].[config_mat_attr] n
|
|
on a.bom_part_nbr = e.part_nbr and n.attr_code ='jbox_type'
|
|
left join [mes_main].[dbo].[config_mat_attr] o
|
|
on a.bom_part_nbr = e.part_nbr and o.attr_code ='frame_length'
|
|
left join [mes_main].[dbo].[config_mat_attr] p
|
|
on a.bom_part_nbr = e.part_nbr and p.attr_code ='frame_thickness'
|
|
left join [mes_main].[dbo].[config_mat_attr] q
|
|
on a.bom_part_nbr = e.part_nbr and q.attr_code ='frame_length'
|
|
left join [mes_main].[dbo].[config_mat_attr] r
|
|
on a.bom_part_nbr = e.part_nbr and r.attr_code ='frame_thickness'
|
|
left join [mes_main].[dbo].[config_mat_attr] s
|
|
on a.bom_part_nbr = e.part_nbr and s.attr_code ='JBOXGLUE_type'
|
|
left join [mes_main].[dbo].[config_mat_attr] t
|
|
on a.bom_part_nbr = e.part_nbr and t.attr_code ='ABGLUE_type'
|
|
left join [mes_main].[dbo].[config_mat_attr] u
|
|
on a.bom_part_nbr = e.part_nbr and u.attr_code ='FRAMEGLUE_type'
|
|
left join [mes_main].[dbo].[config_mat_attr] v
|
|
on a.bom_part_nbr = e.part_nbr and v.attr_code ='IsolatingBar_type'
|
|
where 1 = 1" + strWhere + @"
|
|
group by a.part_type_desc,b.orig_batch_nbr,b.lot_nbr
|
|
,b.lot_qty_remaining,b.lot_qty,a.real_nbr,b.uom,b.supplier_code
|
|
,c.attr_code,c.attr_value,d.attr_value,e.attr_value
|
|
,f.attr_value,h.attr_value,i.attr_value
|
|
,j.attr_value,k.attr_value,l.attr_value,m.attr_value,n.attr_value
|
|
,o.attr_value,p.attr_value,q.attr_value,r.attr_value,s.attr_value
|
|
,t.attr_value,u.attr_value,v.attr_value
|
|
) jl
|
|
left join (select a.part_type_desc,b.orig_batch_nbr,b.lot_nbr
|
|
,b.lot_qty_remaining,b.lot_qty,
|
|
a.real_nbr,
|
|
--residue,
|
|
b.uom,b.supplier_code,
|
|
case
|
|
when a.part_type_desc = '电池片' then c.attr_value
|
|
when a.part_type_desc = 'EVA' then d.attr_value+'/'+e.attr_value
|
|
when a.part_type_desc = '高透EVA' then f.attr_value
|
|
when a.part_type_desc = '背板' then h.attr_value+'/'+i.attr_value
|
|
when a.part_type_desc = '玻璃' then j.attr_value
|
|
when a.part_type_desc = '互联条' then k.attr_value
|
|
when a.part_type_desc = '汇流条' then l.attr_value
|
|
when a.part_type_desc = '助焊剂' then m.attr_value
|
|
when a.part_type_desc = '线盒' then n.attr_value
|
|
when a.part_type_desc = '长型材' then o.attr_value+'/'+p.attr_value
|
|
when a.part_type_desc = '短型材' then q.attr_value+'/'+r.attr_value
|
|
when a.part_type_desc = '接线盒胶' then s.attr_value
|
|
when a.part_type_desc = 'AB胶' then t.attr_value
|
|
when a.part_type_desc = '型材胶' then u.attr_value
|
|
when a.part_type_desc = '隔离条' then v.attr_value
|
|
end attr_value
|
|
FROM [mes_main].[dbo].[config_bom_mfg] a
|
|
left join [mes_main].[dbo].[pack_material_lot] b
|
|
on a.bom_part_nbr = b.part_nbr and a.workorder = b.workorder
|
|
left join [mes_main].[dbo].[config_mat_attr] c
|
|
on a.bom_part_nbr = c.part_nbr and c.attr_code = 'cell_uop'
|
|
left join [mes_main].[dbo].[config_mat_attr] d
|
|
on a.bom_part_nbr = d.part_nbr and d.attr_code ='eva_length'
|
|
left join [mes_main].[dbo].[config_mat_attr] e
|
|
on a.bom_part_nbr = e.part_nbr and e.attr_code ='eva_width'
|
|
left join [mes_main].[dbo].[config_mat_attr] f
|
|
on a.bom_part_nbr = d.part_nbr and f.attr_code ='eva_length'
|
|
--left join [mes_main].[dbo].[config_mat_attr] g
|
|
--on a.bom_part_nbr = e.part_nbr and g.attr_code ='eva_width'
|
|
left join [mes_main].[dbo].[config_mat_attr] h
|
|
on a.bom_part_nbr = d.part_nbr and h.attr_code ='bks_length'
|
|
left join [mes_main].[dbo].[config_mat_attr] i
|
|
on a.bom_part_nbr = e.part_nbr and i.attr_code ='bks_width'
|
|
left join [mes_main].[dbo].[config_mat_attr] j
|
|
on a.bom_part_nbr = e.part_nbr and j.attr_code ='glass_size'
|
|
left join [mes_main].[dbo].[config_mat_attr] k
|
|
on a.bom_part_nbr = e.part_nbr and j.attr_code ='hulian_type'
|
|
left join [mes_main].[dbo].[config_mat_attr] l
|
|
on a.bom_part_nbr = e.part_nbr and j.attr_code ='huiliu_type'
|
|
left join [mes_main].[dbo].[config_mat_attr] m
|
|
on a.bom_part_nbr = e.part_nbr and m.attr_code ='Solder_type'
|
|
left join [mes_main].[dbo].[config_mat_attr] n
|
|
on a.bom_part_nbr = e.part_nbr and n.attr_code ='jbox_type'
|
|
left join [mes_main].[dbo].[config_mat_attr] o
|
|
on a.bom_part_nbr = e.part_nbr and o.attr_code ='frame_length'
|
|
left join [mes_main].[dbo].[config_mat_attr] p
|
|
on a.bom_part_nbr = e.part_nbr and p.attr_code ='frame_thickness'
|
|
left join [mes_main].[dbo].[config_mat_attr] q
|
|
on a.bom_part_nbr = e.part_nbr and q.attr_code ='frame_length'
|
|
left join [mes_main].[dbo].[config_mat_attr] r
|
|
on a.bom_part_nbr = e.part_nbr and r.attr_code ='frame_thickness'
|
|
left join [mes_main].[dbo].[config_mat_attr] s
|
|
on a.bom_part_nbr = e.part_nbr and s.attr_code ='JBOXGLUE_type'
|
|
left join [mes_main].[dbo].[config_mat_attr] t
|
|
on a.bom_part_nbr = e.part_nbr and t.attr_code ='ABGLUE_type'
|
|
left join [mes_main].[dbo].[config_mat_attr] u
|
|
on a.bom_part_nbr = e.part_nbr and u.attr_code ='FRAMEGLUE_type'
|
|
left join [mes_main].[dbo].[config_mat_attr] v
|
|
on a.bom_part_nbr = e.part_nbr and v.attr_code ='IsolatingBar_type'
|
|
where 1 = 1 " + strWhere + @"
|
|
group by a.part_type_desc,b.orig_batch_nbr,b.lot_nbr
|
|
,b.lot_qty_remaining,b.lot_qty,a.real_nbr,b.uom,b.supplier_code
|
|
,c.attr_code,c.attr_value,d.attr_value,e.attr_value
|
|
,f.attr_value,h.attr_value,i.attr_value
|
|
,j.attr_value,k.attr_value,l.attr_value,m.attr_value,n.attr_value
|
|
,o.attr_value,p.attr_value,q.attr_value,r.attr_value,s.attr_value
|
|
,t.attr_value,u.attr_value,v.attr_value
|
|
) jy
|
|
on jl.orig_batch_nbr = jy.orig_batch_nbr
|
|
group by jy.part_type_desc,jl.orig_batch_nbr,jy.lot_nbr,
|
|
jy.lot_qty_remaining,jy.lot_qty,jy.uom,jy.supplier_code,jy.attr_value,jy.real_nbr ";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 本月每天各工位产能
|
|
public DataTable CurEverydayStationCapacityDT(string workshop, string station, string year, string month)
|
|
{
|
|
return dbhelp.ExecuteDataTable(CurEverydayStationCapacitySql(workshop, station, year, month), null);
|
|
}
|
|
|
|
public string CurEverydayStationCapacitySql(string workshop, string station, string year, string month)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
string strWheres = string.Empty;
|
|
string strWhere0 = string.Empty;
|
|
if (!string.IsNullOrEmpty(station))
|
|
{
|
|
strWhere0 += " and aa.Processes = '" + station + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(year))
|
|
{
|
|
strWhere += " and substring(CONVERT(VARCHAR(24),a.wks_visit_date,23),1,4) = '" + year + "' ";
|
|
strWheres += " and substring(CONVERT(VARCHAR(24),g.pack_date,23),1,4) = '" + year + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(month))
|
|
{
|
|
strWhere += " and substring(CONVERT(VARCHAR(24),a.wks_visit_date,23),6,2) = '" + month + "' ";
|
|
strWheres += " and substring(CONVERT(VARCHAR(24),g.pack_date,23),6,2) = '" + month + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workshop))
|
|
{
|
|
strWhere += " and b.area_code = '" + workshop + "' ";
|
|
strWheres += " and h.area_code = '" + workshop + "' ";
|
|
}
|
|
string sql = @" if OBJECT_ID(N'tempdb..#temp',N'U') is not null
|
|
DROP TABLE #temp
|
|
select productDate,workshop,Processes,wks_desc,dailyShift,nbr into #temp from
|
|
(select substring(CONVERT(VARCHAR(24),a.wks_visit_date,23),6,5) AS productDate,d.descriptions as workshop ,c.descriptions as Processes,b.wks_desc ,e.descriptions as dailyShift
|
|
,COUNT(a.serial_nbr) as nbr
|
|
from mes_main.dbo.trace_workstation_visit a
|
|
left join [mes_main].[dbo].[config_workstation] b
|
|
on a.wks_id = b.wks_id
|
|
left join mes_main.dbo.df_processes c
|
|
on c.process_code = b.process_code
|
|
left join mes_main.dbo.df_areas d
|
|
on b.area_code = d.area_code
|
|
left join mes_main.dbo.df_shift_type e
|
|
on a.shift_type = e.shift_type
|
|
where 1 = 1 " + strWhere + @"
|
|
group by substring(CONVERT(VARCHAR(24),a.wks_visit_date,23),6,5),b.wks_desc,c.descriptions,d.descriptions,e.descriptions
|
|
union
|
|
select substring(CONVERT(VARCHAR(24),g.pack_date,23),6,5) AS productDate,i.descriptions,'包装' Process,k.wks_desc
|
|
,j.descriptions as dailyShift,COUNT(f.serial_nbr) nbr
|
|
from mes_main.dbo.assembly_status f
|
|
join mes_main.dbo.pack_pallets g
|
|
on f.pallet_nbr = g.pallet_nbr
|
|
left join mes_main.dbo.wo_mfg h
|
|
on f.workorder = h.workorder
|
|
left join mes_main.dbo.df_areas i
|
|
on h.area_code = i.area_code
|
|
left join mes_main.dbo.df_shift_type j
|
|
on g.shift_type = j.shift_type
|
|
left join [mes_main].[dbo].[config_workstation] k
|
|
on k.wks_id = g.wks_id
|
|
where f.pallet_nbr is not null " + strWheres + @"
|
|
group by substring(CONVERT(VARCHAR(24),g.pack_date,23),6,5),i.descriptions,k.wks_desc
|
|
,j.descriptions) aa
|
|
where 1 = 1 " + strWhere0 + @"
|
|
DECLARE @sql_col VARCHAR(8000)
|
|
DECLARE @sql_str VARCHAR(MAX)
|
|
SELECT @sql_col=isnull(@sql_col+',','')+QUOTENAME(productDate) FROM #temp GROUP by QUOTENAME(productDate)
|
|
SET @sql_str ='SELECT *
|
|
FROM #temp
|
|
PIVOT
|
|
(
|
|
max(nbr) for productDate in(' + @sql_col + ')
|
|
) aa'
|
|
|
|
EXEC(@sql_str)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 站点产能看板
|
|
public DataTable StationClassYieldDT(string workshop, string station, string ytd, string time)
|
|
{
|
|
return dbhelp.ExecuteDataTable(StationClassYieldSql(workshop, station, ytd, time), null);
|
|
}
|
|
|
|
public string StationClassYieldSql(string workshop, string station, string ytd, string time)
|
|
{
|
|
//2020-05-20 09:00:00"
|
|
var beginDate ="";
|
|
var endDate = "";
|
|
string sql = string.Empty;
|
|
int hour = 0;
|
|
var currentDate = DateTime.Parse(ytd);
|
|
string ymd = currentDate.ToShortDateString().ToString();
|
|
hour = currentDate.Hour;
|
|
if (hour >= 8 && hour <20)
|
|
{
|
|
beginDate = ymd + " 08:00:00";
|
|
endDate = ymd + " 20:00:00";
|
|
|
|
|
|
sql = String.Format(@" select * from (select GZ.timeSpan,GZ.qty
|
|
from(
|
|
SELECT case when DATEPART(HH, a.wks_visit_date) >= '8' and DATEPART(HH, a.wks_visit_date) < '10' then '08'
|
|
when DATEPART(HH, a.wks_visit_date) >= '10' and DATEPART(HH, a.wks_visit_date) < '12' then '10'
|
|
when DATEPART(HH, a.wks_visit_date) >= '12' and DATEPART(HH, a.wks_visit_date) < '14' then '12'
|
|
when DATEPART(HH, a.wks_visit_date) >= '14' and DATEPART(HH, a.wks_visit_date) < '16' then '14'
|
|
when DATEPART(HH, a.wks_visit_date) >= '16' and DATEPART(HH, a.wks_visit_date) < '18' then '16'
|
|
when DATEPART(HH, a.wks_visit_date) >= '18' and DATEPART(HH, a.wks_visit_date) < '20' then '18'
|
|
else
|
|
'99'
|
|
end timeSpan,
|
|
COUNT(1) AS qty
|
|
FROM [mes_main].[dbo].[trace_workstation_visit] a
|
|
join mes_main.dbo.config_workstation b on a.wks_id = b.wks_id
|
|
where
|
|
a.wks_visit_date >='{0}' and a.wks_visit_date <'{1}'
|
|
and b.area_code = '{2}' and b.process_code='{3}'
|
|
group by
|
|
case when DATEPART(HH, a.wks_visit_date) >= '8' and DATEPART(HH, a.wks_visit_date) < '10' then '08'
|
|
when DATEPART(HH, a.wks_visit_date) >= '10' and DATEPART(HH, a.wks_visit_date) < '12' then '10'
|
|
when DATEPART(HH, a.wks_visit_date) >= '12' and DATEPART(HH, a.wks_visit_date) < '14' then '12'
|
|
when DATEPART(HH, a.wks_visit_date) >= '14' and DATEPART(HH, a.wks_visit_date) < '16' then '14'
|
|
when DATEPART(HH, a.wks_visit_date) >= '16' and DATEPART(HH, a.wks_visit_date) < '18' then '16'
|
|
when DATEPART(HH, a.wks_visit_date) >= '18' and DATEPART(HH, a.wks_visit_date) < '20' then '18'
|
|
else
|
|
'99'
|
|
end)GZ)ss where ss.timeSpan<>'99'", beginDate, endDate, workshop, station);
|
|
}
|
|
else if(hour >= 20)
|
|
{
|
|
//2020-05-20
|
|
beginDate = ymd + " 20:00:00";
|
|
endDate = DateTime.Parse(ymd).AddDays(1).AddHours(8).ToString();
|
|
//beginDate = "2020-05-09 20:00:00";
|
|
//endDate = "2020-05-10 08:00:00";
|
|
sql = String.Format(@" select * from (select GZ.timeSpan,GZ.qty
|
|
from(
|
|
SELECT case when DATEPART(HH, a.wks_visit_date) >= '20' and DATEPART(HH, a.wks_visit_date) < '22' then '20'
|
|
when DATEPART(HH, a.wks_visit_date) >= '22' and DATEPART(HH, a.wks_visit_date) < '24' then '22'
|
|
when DATEPART(HH, a.wks_visit_date) >= '24' and DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) < '02' then '00'
|
|
when DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) >= '02' and DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) < '04' then '02'
|
|
when DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) >= '04' and DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) < '06' then '04'
|
|
when DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) >= '06' and DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) < '08' then '06'
|
|
else
|
|
'99'
|
|
end timeSpan,
|
|
COUNT(1) AS qty
|
|
FROM [mes_main].[dbo].[trace_workstation_visit] a
|
|
join mes_main.dbo.config_workstation b on a.wks_id = b.wks_id
|
|
where
|
|
a.wks_visit_date >='{0}' and a.wks_visit_date <'{1}'
|
|
and b.area_code = '{2}' and b.process_code='{3}'
|
|
group by
|
|
case when DATEPART(HH, a.wks_visit_date) >= '20' and DATEPART(HH, a.wks_visit_date) < '22' then '20'
|
|
when DATEPART(HH, a.wks_visit_date) >= '22' and DATEPART(HH, a.wks_visit_date) < '24' then '22'
|
|
when DATEPART(HH, a.wks_visit_date) >= '24' and DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) < '02' then '00'
|
|
when DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) >= '02' and DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) < '04' then '02'
|
|
when DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) >= '04' and DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) < '06' then '04'
|
|
when DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) >= '06' and DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) < '08' then '06'
|
|
else
|
|
'99'
|
|
end)GZ)ss where ss.timeSpan<>'99'", beginDate, endDate, workshop, station);
|
|
}
|
|
else
|
|
{
|
|
beginDate = DateTime.Parse(ymd).AddDays(-1).AddHours(20).ToString();
|
|
endDate = ymd + " 08:00:00";
|
|
sql = String.Format(@" select * from (select GZ.timeSpan,GZ.qty
|
|
from(
|
|
SELECT case when DATEPART(HH, a.wks_visit_date) >= '20' and DATEPART(HH, a.wks_visit_date) < '22' then '20'
|
|
when DATEPART(HH, a.wks_visit_date) >= '22' and DATEPART(HH, a.wks_visit_date) < '24' then '22'
|
|
when DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) >= '00' and DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) < '02' then '00'
|
|
when DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) >= '02' and DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) < '04' then '02'
|
|
when DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) >= '04' and DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) < '06' then '04'
|
|
when DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) >= '06' and DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) < '08' then '06'
|
|
else
|
|
'99'
|
|
end timeSpan,
|
|
COUNT(1) AS qty
|
|
FROM [mes_main].[dbo].[trace_workstation_visit] a
|
|
join mes_main.dbo.config_workstation b on a.wks_id = b.wks_id
|
|
where
|
|
a.wks_visit_date >='{0}' and a.wks_visit_date <'{1}'
|
|
and b.area_code = '{2}' and b.process_code='{3}'
|
|
group by
|
|
case when DATEPART(HH, a.wks_visit_date) >= '20' and DATEPART(HH, a.wks_visit_date) < '22' then '20'
|
|
when DATEPART(HH, a.wks_visit_date) >= '22' and DATEPART(HH, a.wks_visit_date) < '24' then '22'
|
|
when DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) >= '00' and DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) < '02' then '00'
|
|
when DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) >= '02' and DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) < '04' then '02'
|
|
when DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) >= '04' and DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) < '06' then '04'
|
|
when DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) >= '06' and DATEPART(HH, DATEADD(DAY,1,a.wks_visit_date)) < '08' then '06'
|
|
else
|
|
'99'
|
|
end)GZ)ss where ss.timeSpan<>'99'", beginDate, endDate, workshop, station);
|
|
|
|
}
|
|
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 站点产能总和
|
|
public DataTable StationTotalCapacityDT(string workshop, string station, string ytd)
|
|
{
|
|
return dbhelp.ExecuteDataTable(StationTotalCapacitySql(workshop, station, ytd), null);
|
|
}
|
|
|
|
public string StationTotalCapacitySql(string workshop, string station, string ytd)
|
|
{
|
|
//2020-05-20 09:00:00"
|
|
var beginDate = "";
|
|
var endDate = "";
|
|
string sql = string.Empty;
|
|
int hour = 0;
|
|
var currentDate = DateTime.Parse(ytd);
|
|
string ymd = currentDate.ToShortDateString().ToString();
|
|
hour = currentDate.Hour;
|
|
if (hour >= 8 && hour < 20)
|
|
{
|
|
beginDate = ymd + " 08:00:00";
|
|
endDate = ymd + " 20:00:00";
|
|
}
|
|
else if (hour >= 20)
|
|
{
|
|
//2020-05-20
|
|
beginDate = ymd + " 20:00:00";
|
|
endDate = DateTime.Parse(ymd).AddDays(1).AddHours(8).ToString();
|
|
}
|
|
else
|
|
{
|
|
beginDate = DateTime.Parse(ymd).AddDays(-1).AddHours(20).ToString();
|
|
endDate = ymd + " 08:00:00";
|
|
}
|
|
sql = String.Format(@" select count(1) as totalQty from [mes_main].[dbo].[trace_workstation_visit] a
|
|
join mes_main.dbo.config_workstation b on a.wks_id = b.wks_id
|
|
where b.area_code = '{2}' and b.process_code='{3}'
|
|
and a.wks_visit_date >='{0}' and a.wks_visit_date <'{1}'", beginDate, endDate, workshop, station);
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 前道产能看板
|
|
public DataTable BeforeCapacityDT()
|
|
{
|
|
return dbhelp.ExecuteDataTable(BeforeCapacitySql(), null);
|
|
}
|
|
|
|
public string BeforeCapacitySql()
|
|
{
|
|
var beginDate = "";
|
|
var endDate = "";
|
|
string sql = string.Empty;
|
|
int hour = 0;
|
|
var currentDate = System.DateTime.Now;
|
|
string ymd = currentDate.ToShortDateString().ToString();
|
|
hour = currentDate.Hour;
|
|
if (hour >= 8 && hour < 20)
|
|
{
|
|
beginDate = ymd + " 08:00:00";
|
|
endDate = ymd + " 20:00:00";
|
|
}
|
|
else if (hour >= 20)
|
|
{
|
|
//2020-05-20
|
|
beginDate = ymd + " 20:00:00";
|
|
endDate = DateTime.Parse(ymd).AddDays(1).AddHours(8).ToString();
|
|
}
|
|
else
|
|
{
|
|
beginDate = DateTime.Parse(ymd).AddDays(-1).AddHours(20).ToString();
|
|
endDate = ymd + " 08:00:00";
|
|
}
|
|
sql = String.Format(@" select count(1) as qty,b.line_id,b.process_code from [mes_main].[dbo].[trace_workstation_visit] a
|
|
join mes_main.dbo.config_workstation b on a.wks_id = b.wks_id
|
|
where a.wks_visit_date >='{0}' and a.wks_visit_date <'{1}'
|
|
group by b.line_id,b.process_code", beginDate,endDate);
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 后道产能看板
|
|
public DataTable AfterCapacityDT()
|
|
{
|
|
return dbhelp.ExecuteDataTable(AfterCapacitySql(), null);
|
|
}
|
|
|
|
public string AfterCapacitySql()
|
|
{
|
|
var beginDate = "";
|
|
var endDate = "";
|
|
string sql = string.Empty;
|
|
int hour = 0;
|
|
var currentDate = System.DateTime.Now;
|
|
string ymd = currentDate.ToShortDateString().ToString();
|
|
hour = currentDate.Hour;
|
|
if (hour >= 8 && hour < 20)
|
|
{
|
|
beginDate = ymd + " 08:00:00";
|
|
endDate = ymd + " 20:00:00";
|
|
}
|
|
else if (hour >= 20)
|
|
{
|
|
//2020-05-20
|
|
beginDate = ymd + " 20:00:00";
|
|
endDate = DateTime.Parse(ymd).AddDays(1).AddHours(8).ToString();
|
|
}
|
|
else
|
|
{
|
|
beginDate = DateTime.Parse(ymd).AddDays(-1).AddHours(20).ToString();
|
|
endDate = ymd + " 08:00:00";
|
|
}
|
|
sql = String.Format(@" select * from (select count(1) as qty,b.line_id,b.process_code from [mes_main].[dbo].[trace_workstation_visit] a
|
|
join mes_main.dbo.config_workstation b on a.wks_id = b.wks_id
|
|
where a.wks_visit_date >='{0}' and a.wks_visit_date <'{1}'
|
|
group by b.line_id,b.process_code
|
|
union
|
|
select COUNT(1) as qty,c.line_id,c.process_code from [mes_main].[dbo].[assembly_status] a
|
|
join mes_main.dbo.pack_pallets b on a.pallet_nbr = b.pallet_nbr
|
|
join mes_main.dbo.config_workstation c on b.wks_id = c.wks_id
|
|
where a.pallet_nbr is not null and a.pack_date >='{0}' and a.pack_date <'{1}'
|
|
group by c.line_id,c.process_code) aa
|
|
where line_id != '5'
|
|
order by substring(process_code,1,3)", beginDate, endDate);
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 永臻晶科报表
|
|
|
|
public DataTable YongzhenJinkeDT(string bt,string et,string PalletLot)
|
|
{
|
|
return dbhelp.ExecuteDataTable(YongzhenJinkeSql(bt,et,PalletLot), null);
|
|
}
|
|
|
|
public string YongzhenJinkeSql(string bt, string et,string PalletLot)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
string strWhere1 = string.Empty;
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and b.wks_visit_date >= '" + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and b.wks_visit_date <= '" + et + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(PalletLot))
|
|
{
|
|
strWhere += " and a.pallet_nbr in (" + PalletLot + ") ";
|
|
}
|
|
string sql = @"(SELECT CONVERT(varchar(100),b.wks_visit_date, 120) as wks_visit_date,b.serial_nbr,g.JKWorkorder workorder,b.wks_id as ivwks_id,b.env_temp,b.sun_ref,b.ff,b.eff,b.pmax,
|
|
b.isc,b.ipm,b.voc,b.vpm,b.surf_temp,f.attr_value,'' ctm,b.rs,b.rsh,e.supplier_code cell_supplier_code,
|
|
case
|
|
when a.serial_status='G' then 'OK'
|
|
else a.serial_status
|
|
end serial_status
|
|
,d.wks_id as elwks_id,'OK' ivfile_path,a.pallet_nbr,a.final_grade,'' cir_no,'' sale_order_no,a.power_grade,
|
|
'' contract_no,'' customer_name
|
|
FROM mes_level2_iface.dbo.iv b
|
|
left join mes_main.dbo.assembly_status a
|
|
on a.serial_nbr=b.serial_nbr
|
|
left join mes_level2_iface.dbo.el d
|
|
on a.serial_nbr=d.serial_nbr and d.process_code='HEL'
|
|
left join mes_main.dbo.trace_componnet_lot e
|
|
on a.serial_nbr=e.serial_nbr and e.part_type='CELL'
|
|
left join mes_main.dbo.config_mat_attr f
|
|
on e.part_nbr=f.part_nbr and f.attr_code='cell_eff'
|
|
left join mes_main.dbo.wo_mfg g
|
|
on g.workorder=a.workorder
|
|
where 1=1 and g.customer = 'JK' " + strWhere + @"
|
|
--and c.sale_order = '11'
|
|
--and b.workorder ='' and c.area_code ='' and a.create_date >='' and a.create_date <''
|
|
|
|
)";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
#region 一次碎片率
|
|
public DataTable FragmentationDT(string machine, string workshop,string bt,string et)
|
|
{
|
|
return dbhelp.ExecuteDataTable(FragmentationSql(machine, workshop,bt,et), null);
|
|
}
|
|
|
|
public string FragmentationSql(string machine, string workshop,string bt,string et)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(machine))
|
|
{
|
|
strWhere += " and a.wks_id = '" + machine + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workshop))
|
|
{
|
|
strWhere += " and b.area_code = '" + workshop + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and a.wks_visit_date >=' " + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and a.wks_visit_date <=' " + et + "' ";
|
|
}
|
|
string sql = @" if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'tempdb..#temp') and type='U')
|
|
begin
|
|
drop table #temp --删除临时表#temp
|
|
end
|
|
select a.wks_id,d.defect_type_name,c.defect_position into #temp from mes_main.dbo.trace_workstation_visit a
|
|
join mes_main.dbo.config_workstation b
|
|
on a.wks_id = b.wks_id and b.process_code = 'M10'
|
|
LEFT JOIN mes_main.dbo.defects c
|
|
on a.serial_nbr =c.serial_nbr
|
|
left join mes_main.dbo.config_defect_type d
|
|
on c.defect_type_id = d.defect_type_id
|
|
left join mes_main.dbo.config_defect_group e
|
|
on d.defect_group_id = e.defect_group_id
|
|
where 1=1 AND e.defect_group_name in ('EL不良','叠返修','串返修') " + strWhere + @"
|
|
and c.defect_position !='' and c.defect_position is not null;
|
|
|
|
if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'tempdb..#temmp') and type='U')
|
|
begin
|
|
drop table #temmp --删除临时表#temmp
|
|
end
|
|
|
|
select wks_id,defect_type_name,sum(len(defect_position)-len(replace(defect_position,',',''))+1) as nbr
|
|
into #temmp
|
|
from #temp
|
|
group by wks_id,defect_type_name
|
|
order by wks_id,defect_type_name;
|
|
|
|
if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'tempdb..#temmmp') and type='U')
|
|
begin
|
|
drop table #temmmp --删除临时表#temmmp
|
|
end
|
|
|
|
select a.wks_id,a.defect_type_name,b.WksNbr,a.nbr,b.WksCellNbr,substring(cast(a.nbr*100.00/b.WksCellNbr as varchar(20)),1,charindex('.',a.nbr*100.00/b.WksCellNbr)+2)+'%' as defect_typeProb into #temmmp from #temmp a
|
|
left join
|
|
(
|
|
select a.wks_id,COUNT(a.serial_nbr) WksNbr,SUM(CAST( ISNULL(d.cell_qty,'0')as int)) WksCellNbr from mes_main.dbo.trace_workstation_visit a
|
|
join mes_main.dbo.config_workstation b
|
|
on a.wks_id = b.wks_id and b.process_code = 'M10'
|
|
left join mes_main.dbo.assembly_status c
|
|
on a.serial_nbr = c.serial_nbr
|
|
left join mes_main.dbo.wo_mfg d
|
|
on c.workorder = d.workorder
|
|
WHERE 1=1 " + strWhere + @"
|
|
group by a.wks_id
|
|
)b
|
|
on a.wks_id = b.wks_id
|
|
|
|
--SELECT * FROM #temmmp
|
|
|
|
DECLARE @sql_str VARCHAR(8000)
|
|
DECLARE @sql_col VARCHAR(8000)
|
|
DECLARE @EE VARCHAR(max)
|
|
SET @EE='';
|
|
select @EE = @EE+ 'ISNULL(MAX(CASE defect_type_name WHEN '''+ defect_type_name+'''THEN nbr END ),0) as '+''''+defect_type_name+''','
|
|
+'ISNULL(MAX(CASE defect_type_name WHEN '''+ defect_type_name+'''THEN defect_typeProb END ),0) as '+''''+defect_type_name+'率'','
|
|
from (SELECT defect_type_name FROM #temmmp GROUP BY defect_type_name) A
|
|
--select @EE
|
|
select @sql_col =ISNULL(@sql_col + ',','') + defect_type_name
|
|
from #temp
|
|
group by defect_type_name
|
|
|
|
SET @sql_str = '
|
|
SELECT * FROM (
|
|
SELECT wks_id as ''机台号'',WksNbr as ''过站块数'',WksCellNbr AS ''过站片数'','+@EE+' ''汇总'' AS ''汇总'' FROM #temmmp
|
|
group by wks_id,WksNbr,WksCellNbr) AS pvt
|
|
ORDER BY pvt.机台号'
|
|
--PRINT (@sql_str)
|
|
EXEC (@sql_str);
|
|
";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
#region 一次成型率
|
|
public DataTable MoldingDT(string machine,string workshop, string bt ,string et)
|
|
{
|
|
return dbhelp.ExecuteDataTable(MoldingSql(machine,workshop,bt,et), null);
|
|
}
|
|
|
|
public string MoldingSql(string machine,string workshop, string bt, string et)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(machine))
|
|
{
|
|
strWhere += " and a.wks_id = '" + machine + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workshop))
|
|
{
|
|
strWhere += " and b.area_code = '" + workshop + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and a.wks_visit_date >= '" + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and a.wks_visit_date <= '" + et + "' ";
|
|
}
|
|
string sql = @" if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'tempdb..#temp') and type='U')
|
|
begin
|
|
drop table #temp --删除临时表#temp
|
|
end
|
|
select
|
|
a.serial_nbr,a.wks_visit_date,a.wks_id,b.wks_desc,a.shift_type into #temp
|
|
from mes_main.dbo.trace_workstation_visit a
|
|
join mes_main.dbo.config_workstation b
|
|
on a.wks_id = b.wks_id and b.process_code = 'M10'
|
|
join mes_level2_iface.dbo.el c
|
|
on a.serial_nbr = c.serial_nbr and c.process_code ='QEL'
|
|
left join mes_main.dbo.assembly_status d
|
|
on c.serial_nbr = d.serial_nbr
|
|
where d.serial_nbr <>'' " + strWhere + @"
|
|
--select * from #temp
|
|
|
|
if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'tempdb..#temmp') and type='U')
|
|
begin
|
|
drop table #temmp --删除临时表#temmp
|
|
end
|
|
|
|
select a.wks_id,a.wks_desc,a.shift_type,Convert(Char(10),a.wks_visit_date,120) as wks_visit_date,count(a.serial_nbr) Wks_Nbr
|
|
,sum(case when b.serial_nbr is not null then 1 else 0 end) Wks_Bad_Nbr
|
|
into #temmp
|
|
from #temp a
|
|
left join
|
|
(
|
|
select a.serial_nbr from #temp a
|
|
left join mes_main.dbo.qc_visit b
|
|
on a.serial_nbr = b.serial_nbr
|
|
where b.serial_nbr is not null
|
|
group by a.serial_nbr
|
|
)b
|
|
on a.serial_nbr=b.serial_nbr
|
|
group by a.wks_id,a.wks_desc,a.shift_type,Convert(Char(10),a.wks_visit_date,120)
|
|
ORDER BY a.wks_id,a.wks_desc,a.shift_type,Convert(Char(10),a.wks_visit_date,120)
|
|
|
|
|
|
--select * from #temmp
|
|
|
|
DECLARE @sql_str VARCHAR(8000)
|
|
DECLARE @sql_col VARCHAR(8000)
|
|
DECLARE @EE VARCHAR(8000)
|
|
SET @EE='';
|
|
select @EE = @EE+'ISNULL(MAX(CASE wks_visit_date WHEN '''+ wks_visit_date+'''THEN Wks_Nbr END ),0) as ['+wks_visit_date+'过站数],'
|
|
+'ISNULL(MAX(CASE wks_visit_date WHEN '''+ wks_visit_date+'''THEN Wks_Nbr-Wks_Bad_Nbr END ),0) as ['+wks_visit_date+'良品数],'
|
|
+'ISNULL(MAX(CASE wks_visit_date WHEN '''+ wks_visit_date+'''THEN (Wks_Nbr-Wks_Bad_Nbr)*100/Wks_Nbr END ),0) as ['+wks_visit_date+'良品率],'
|
|
from (SELECT wks_visit_date FROM #temmp GROUP BY wks_visit_date) A
|
|
|
|
|
|
--select @EE
|
|
|
|
select @sql_col =ISNULL(@sql_col + ',','') + wks_visit_date
|
|
from #temmp
|
|
group by wks_visit_date
|
|
|
|
SET @sql_str = '
|
|
SELECT * FROM (
|
|
SELECT wks_id as ''机台'',shift_type as ''班次'','+@EE+' '' '' AS ''汇总'' FROM #temmp
|
|
group by wks_id,wks_desc,shift_type) AS pvt
|
|
ORDER BY pvt.机台'
|
|
PRINT (@sql_str)
|
|
EXEC (@sql_str);
|
|
";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
#region 数据查询
|
|
public DataTable QueryDT(string wo, string bt,string et,string text)
|
|
{
|
|
return dbhelp.ExecuteDataTable(QuerySql(wo, bt,et,text), null);
|
|
}
|
|
|
|
public string QuerySql(string wo, string bt,string et,string text)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(wo))
|
|
{
|
|
strWhere += " and a.workorder = '" + wo + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and a.[create_date] >= '" + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and a.[create_date] <= '" + et + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(text))
|
|
{
|
|
strWhere += " and a.serial_nbr in (" + text + ") ";
|
|
}
|
|
string sql = @" SELECT A.[组件编号],A.[车间编号],A.[工单类型],A.[工单号],A.[客户名称],C.[片源批号],C.[片源厂商],C.[片源颜色],D.[片源档位],E.[电池尺寸],C.[分选操作人员],F.[片源规格],A.[片源用量],B.[单片功率],H.[电池种类],G.[焊接时间],G.[机台编号],AA.[助焊剂厂商],AA.[助焊剂批号],G.[操作人员],G.[操作班次],I.[电池片效率],AB.[互联条厂商],AB.[互联条规格],J.[叠层时间],J.[叠层机台编号],K.[高透EVA规格],K.[高透EVA批号],L.[玻璃厂商],L.[玻璃规格],L.[玻璃批号],M.[汇流条厂商],M.[汇流条规格],J.[叠层操作人员],J.[叠层操作班次],N.[EVA厂商],N.[普通EVA规格],N.[普通EVA批号],AC.[背板厂商],AC.[背板规格],AC.[背板批号],M.[汇流条批号],O.[前EL测试时间],O.[前EL机台编号],O.[前EL测试结果],P.[层压时间],P.[层压机台编号],P.[层压操作人员],P.[层压操作班次],Q.[层压后检验时间],Q.[层压后检验操作人员],Q.[层压后检验操作班次],R.[装框时间],R.[装框机台编号],S.[线盒厂家],S.[线盒规格],S.[线盒批号],T.[线盒胶厂商],T.[线盒胶批号],R.[装框操作人员],R.[装框操作班次],W.[接线盒拍照时间],U.[型材厂商],U.[型材规格],U.[型材批号],V.[型材胶厂商],V.[型材胶批号],Z.[IV机台编号],Z.[测试功率],Z.[标称功率],Z.[测试时间],Z.[测试电流],X.[后EL测试时间],X.[后EL机台编号],X.[后EL测试结果],Y.[全检时间],Y.[全检机台编号],Y.[全检操作人员]
|
|
FROM
|
|
(
|
|
SELECT a.serial_nbr 组件编号,c.descriptions 车间编号,a.workorder 工单号,b.customer 客户名称,d.descriptions 工单类型,b.cell_qty 片源用量
|
|
FROM mes_main.dbo.assembly_status a
|
|
LEFT JOIN mes_main.dbo.wo_mfg b
|
|
ON a.workorder=b.workorder
|
|
LEFT JOIN mes_main.dbo.df_areas c
|
|
ON b.area_code=c.area_code
|
|
LEFT JOIN mes_main.dbo.df_wo_type d
|
|
ON b.workorder_type=d.workorder_type
|
|
WHERE 1=1 "+strWhere+ @"
|
|
)A
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号,b.part_nbr 片源批号,b.supplier_code 片源厂商,c.attr_value 片源颜色,b.operator 分选操作人员
|
|
FROM mes_main.dbo.trace_componnet_lot a
|
|
LEFT JOIN mes_main.dbo.pack_material_lot b
|
|
ON a.part_nbr=b.part_nbr AND a.lot_nbr=b.lot_nbr
|
|
LEFT JOIN mes_main.dbo.config_mat_attr c
|
|
ON b.part_nbr=c.part_nbr
|
|
WHERE a.part_type='CELL' AND c.attr_code='cell_color'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)C
|
|
ON A.[组件编号]=C.[组件编号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号,c.attr_value 片源档位
|
|
FROM mes_main.dbo.trace_componnet_lot a
|
|
LEFT JOIN mes_main.dbo.pack_material_lot b
|
|
ON a.part_nbr=b.part_nbr AND a.lot_nbr=b.lot_nbr
|
|
LEFT JOIN mes_main.dbo.config_mat_attr c
|
|
ON b.part_nbr=c.part_nbr
|
|
WHERE a.part_type='CELL' AND c.attr_code='cell_grade'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)D
|
|
ON A.[组件编号]=D.[组件编号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号,c.attr_value+'*'+c.attr_value 电池尺寸
|
|
FROM mes_main.dbo.trace_componnet_lot a
|
|
LEFT JOIN mes_main.dbo.pack_material_lot b
|
|
ON a.part_nbr=b.part_nbr AND a.lot_nbr=b.lot_nbr
|
|
LEFT JOIN mes_main.dbo.config_mat_attr c
|
|
ON b.part_nbr=c.part_nbr
|
|
WHERE a.part_type='CELL' AND c.attr_code='cell_size'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)E
|
|
ON A.[组件编号]=E.[组件编号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号, c.attr_value 片源规格
|
|
FROM mes_main.dbo.trace_componnet_lot a
|
|
LEFT JOIN mes_main.dbo.pack_material_lot b
|
|
ON a.part_nbr=b.part_nbr AND a.lot_nbr=b.lot_nbr
|
|
LEFT JOIN mes_main.dbo.config_mat_attr c
|
|
ON b.part_nbr=c.part_nbr
|
|
WHERE a.part_type='CELL' AND c.attr_code='cell_busbar'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)F
|
|
ON A.[组件编号]=F.[组件编号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号, c.attr_value 单片功率
|
|
FROM mes_main.dbo.trace_componnet_lot a
|
|
LEFT JOIN mes_main.dbo.pack_material_lot b
|
|
ON a.part_nbr=b.part_nbr AND a.lot_nbr=b.lot_nbr
|
|
LEFT JOIN mes_main.dbo.config_mat_attr c
|
|
ON b.part_nbr=c.part_nbr
|
|
WHERE a.part_type='CELL' AND c.attr_code='cell_uop'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)B
|
|
ON A.[组件编号]=B.[组件编号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号, c.attr_value 电池种类
|
|
FROM mes_main.dbo.trace_componnet_lot a
|
|
LEFT JOIN mes_main.dbo.pack_material_lot b
|
|
ON a.part_nbr=b.part_nbr AND a.lot_nbr=b.lot_nbr
|
|
LEFT JOIN mes_main.dbo.config_mat_attr c
|
|
ON b.part_nbr=c.part_nbr
|
|
WHERE a.part_type='CELL' AND c.attr_code='crys_type'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)H
|
|
ON A.[组件编号]=H.[组件编号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号, c.attr_value 电池片效率
|
|
FROM mes_main.dbo.trace_componnet_lot a
|
|
LEFT JOIN mes_main.dbo.pack_material_lot b
|
|
ON a.part_nbr=b.part_nbr AND a.lot_nbr=b.lot_nbr
|
|
LEFT JOIN mes_main.dbo.config_mat_attr c
|
|
ON b.part_nbr=c.part_nbr
|
|
WHERE a.part_type='CELL' AND c.attr_code='cell_eff'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)I
|
|
ON A.[组件编号]=I.[组件编号]
|
|
--焊接站点
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号,CONVERT(varchar(100),a.wks_visit_date, 120) 焊接时间,b.wks_desc 机台编号,a.operator 操作人员,c.descriptions 操作班次
|
|
FROM mes_main.dbo.trace_workstation_visit a
|
|
LEFT JOIN mes_main.dbo.config_workstation b
|
|
ON a.wks_id=b.wks_id
|
|
LEFT JOIN mes_main.dbo.df_shift_type c
|
|
ON a.shift_type=c.shift_type
|
|
WHERE b.process_code='M10'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)G
|
|
ON A.[组件编号]=G.[组件编号]
|
|
--叠层站点
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号,CONVERT(varchar(100),a.wks_visit_date, 120) 叠层时间,b.wks_desc 叠层机台编号,a.operator 叠层操作人员,c.descriptions 叠层操作班次
|
|
FROM mes_main.dbo.trace_workstation_visit a
|
|
LEFT JOIN mes_main.dbo.config_workstation b
|
|
ON a.wks_id=b.wks_id
|
|
LEFT JOIN mes_main.dbo.df_shift_type c
|
|
ON a.shift_type=c.shift_type
|
|
WHERE b.process_code='M15'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)J
|
|
ON A.[组件编号]=J.[组件编号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号, c.attr_value 高透EVA规格,a.part_nbr 高透EVA批号
|
|
FROM mes_main.dbo.trace_componnet_lot a
|
|
LEFT JOIN mes_main.dbo.pack_material_lot b
|
|
ON a.part_nbr=b.part_nbr AND a.lot_nbr=b.lot_nbr
|
|
LEFT JOIN mes_main.dbo.config_mat_attr c
|
|
ON b.part_nbr=c.part_nbr
|
|
WHERE a.part_type='EVA2' AND c.attr_code='eva_length'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)K
|
|
ON A.[组件编号]=K.[组件编号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号, a.supplier_code 玻璃厂商,c.attr_value 玻璃规格,a.part_nbr 玻璃批号
|
|
FROM mes_main.dbo.trace_componnet_lot a
|
|
LEFT JOIN mes_main.dbo.pack_material_lot b
|
|
ON a.part_nbr=b.part_nbr AND a.lot_nbr=b.lot_nbr
|
|
LEFT JOIN mes_main.dbo.config_mat_attr c
|
|
ON b.part_nbr=c.part_nbr
|
|
WHERE a.part_type='GLASS' AND c.attr_code='glass_size'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)L
|
|
ON A.[组件编号]=L.[组件编号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号, a.supplier_code 汇流条厂商,c.attr_value 汇流条规格,a.part_nbr 汇流条批号
|
|
FROM mes_main.dbo.trace_componnet_lot a
|
|
LEFT JOIN mes_main.dbo.pack_material_lot b
|
|
ON a.part_nbr=b.part_nbr AND a.lot_nbr=b.lot_nbr
|
|
LEFT JOIN mes_main.dbo.config_mat_attr c
|
|
ON b.part_nbr=c.part_nbr
|
|
WHERE a.part_type='HUILIU' AND c.attr_code='huiliu_type'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)M
|
|
ON A.[组件编号]=M.[组件编号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号, a.supplier_code EVA厂商,c.attr_value 普通EVA规格,a.part_nbr 普通EVA批号
|
|
FROM mes_main.dbo.trace_componnet_lot a
|
|
LEFT JOIN mes_main.dbo.pack_material_lot b
|
|
ON a.part_nbr=b.part_nbr AND a.lot_nbr=b.lot_nbr
|
|
LEFT JOIN mes_main.dbo.config_mat_attr c
|
|
ON b.part_nbr=c.part_nbr
|
|
WHERE a.part_type='EVA' AND c.attr_code='eva_length'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)N
|
|
ON A.[组件编号]=N.[组件编号]
|
|
--层压前EL站点
|
|
LEFT JOIN
|
|
(
|
|
SELECT TOP 1 a.serial_nbr 组件编号,CONVERT(varchar(100),a.wks_visit_date, 120) 前EL测试时间,f.wks_desc 前EL机台编号,a.el_grade 前EL测试结果
|
|
FROM mes_level2_iface.dbo.el a
|
|
left join [mes_main].[dbo].[config_workstation] f
|
|
on a.wks_id =f.wks_id
|
|
WHERE a.process_code='QEL'
|
|
ORDER BY a.wks_visit_date DESC
|
|
--WHERE a.serial_nbr='12001010010008'
|
|
)O
|
|
ON A.[组件编号]=O.[组件编号]
|
|
--层压站点
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号,CONVERT(varchar(100),a.wks_visit_date, 120) 层压时间,b.wks_desc 层压机台编号,a.operator 层压操作人员,c.descriptions 层压操作班次
|
|
FROM mes_main.dbo.trace_workstation_visit a
|
|
LEFT JOIN mes_main.dbo.config_workstation b
|
|
ON a.wks_id=b.wks_id
|
|
LEFT JOIN mes_main.dbo.df_shift_type c
|
|
ON a.shift_type=c.shift_type
|
|
WHERE b.process_code='N30'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)P
|
|
ON A.[组件编号]=P.[组件编号]
|
|
--层压后检验
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号,CONVERT(varchar(100),a.wks_visit_date, 120) 层压后检验时间,a.operator 层压后检验操作人员,c.descriptions 层压后检验操作班次
|
|
FROM mes_main.dbo.trace_workstation_visit a
|
|
LEFT JOIN mes_main.dbo.config_workstation b
|
|
ON a.wks_id=b.wks_id
|
|
LEFT JOIN mes_main.dbo.df_shift_type c
|
|
ON a.shift_type=c.shift_type
|
|
WHERE b.process_code='N40'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)Q
|
|
ON A.[组件编号]=Q.[组件编号]
|
|
--装框
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号,CONVERT(varchar(100),a.wks_visit_date, 120) 装框时间,b.wks_desc 装框机台编号,a.operator 装框操作人员,c.descriptions 装框操作班次
|
|
FROM mes_main.dbo.trace_workstation_visit a
|
|
LEFT JOIN mes_main.dbo.config_workstation b
|
|
ON a.wks_id=b.wks_id
|
|
LEFT JOIN mes_main.dbo.df_shift_type c
|
|
ON a.shift_type=c.shift_type
|
|
WHERE b.process_code='M45'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)R
|
|
ON A.[组件编号]=R.[组件编号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号, a.supplier_code 线盒厂家,c.attr_value 线盒规格,a.part_nbr 线盒批号
|
|
FROM mes_main.dbo.trace_componnet_lot a
|
|
LEFT JOIN mes_main.dbo.pack_material_lot b
|
|
ON a.part_nbr=b.part_nbr AND a.lot_nbr=b.lot_nbr
|
|
LEFT JOIN mes_main.dbo.config_mat_attr c
|
|
ON b.part_nbr=c.part_nbr
|
|
WHERE a.part_type='JBOX' AND c.attr_code='jbox_type'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)S
|
|
ON A.[组件编号]=S.[组件编号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号, a.supplier_code 线盒胶厂商,a.part_nbr 线盒胶批号
|
|
FROM mes_main.dbo.trace_componnet_lot a
|
|
LEFT JOIN mes_main.dbo.pack_material_lot b
|
|
ON a.part_nbr=b.part_nbr AND a.lot_nbr=b.lot_nbr
|
|
LEFT JOIN mes_main.dbo.config_mat_attr c
|
|
ON b.part_nbr=c.part_nbr
|
|
WHERE a.part_type='JBOXGLUE' AND c.attr_code='JBOXGLUE_type'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)T
|
|
ON A.[组件编号]=T.[组件编号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号, a.supplier_code 型材厂商,a.part_nbr 型材批号,c.attr_value 型材规格
|
|
FROM mes_main.dbo.trace_componnet_lot a
|
|
LEFT JOIN mes_main.dbo.pack_material_lot b
|
|
ON a.part_nbr=b.part_nbr AND a.lot_nbr=b.lot_nbr
|
|
LEFT JOIN mes_main.dbo.config_mat_attr c
|
|
ON b.part_nbr=c.part_nbr
|
|
WHERE a.part_type='LFRAME' AND c.attr_code='frame_length'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)U
|
|
ON A.[组件编号]=U.[组件编号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号, a.supplier_code 型材胶厂商,a.part_nbr 型材胶批号
|
|
FROM mes_main.dbo.trace_componnet_lot a
|
|
LEFT JOIN mes_main.dbo.pack_material_lot b
|
|
ON a.part_nbr=b.part_nbr AND a.lot_nbr=b.lot_nbr
|
|
LEFT JOIN mes_main.dbo.config_mat_attr c
|
|
ON b.part_nbr=c.part_nbr
|
|
WHERE a.part_type='FRAMEGLUE' AND c.attr_code='FRAMEGLUE_type'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)V
|
|
ON A.[组件编号]=V.[组件编号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号, CONVERT(varchar(100),a.wks_visit_date, 120) 接线盒拍照时间
|
|
FROM mes_level2_iface.dbo.el a
|
|
WHERE a.process_code='JXH'
|
|
--WHERE a.serial_nbr='12001010010008'
|
|
)W
|
|
ON A.[组件编号]=W.[组件编号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT TOP 1 a.serial_nbr 组件编号,CONVERT(varchar(100),a.wks_visit_date, 120) 后EL测试时间,f.wks_desc 后EL机台编号,a.el_grade 后EL测试结果
|
|
FROM mes_level2_iface.dbo.el a
|
|
left join [mes_main].[dbo].[config_workstation] f
|
|
on a.wks_id =f.wks_id
|
|
WHERE a.process_code='HEL'
|
|
ORDER BY a.wks_visit_date DESC
|
|
--WHERE a.serial_nbr='12001010010008'
|
|
)X
|
|
ON A.[组件编号]=X.[组件编号]
|
|
--全检
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号,CONVERT(varchar(100),a.wks_visit_date, 120) 全检时间,b.wks_desc 全检机台编号,a.operator 全检操作人员
|
|
FROM mes_main.dbo.trace_workstation_visit a
|
|
LEFT JOIN mes_main.dbo.config_workstation b
|
|
ON a.wks_id=b.wks_id
|
|
LEFT JOIN mes_main.dbo.df_shift_type c
|
|
ON a.shift_type=c.shift_type
|
|
WHERE b.process_code='N60'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)Y
|
|
ON A.[组件编号]=Y.[组件编号]
|
|
--IV
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号, d.power_grade 标称功率,c.pmax 测试功率,CONVERT(varchar(100),c.wks_visit_date, 120) 测试时间,c.ipm 测试电流,f.wks_desc IV机台编号
|
|
FROM mes_main.dbo.assembly_status a
|
|
LEFT JOIN mes_main.dbo.wo_mfg b
|
|
ON a.workorder=b.workorder
|
|
LEFT JOIN mes_main.dbo.config_power d
|
|
ON b.power_grade_group_id=d.power_grade_group_id
|
|
LEFT JOIN mes_level2_iface.dbo.iv c
|
|
ON a.serial_nbr=c.serial_nbr
|
|
left join [mes_main].[dbo].[config_workstation] f
|
|
on c.wks_id =f.wks_id
|
|
WHERE c.pmax >= d.lower_power AND c.pmax < d.upper_power
|
|
--AND a.serial_nbr='204M6L60AV000031'
|
|
)Z
|
|
ON A.[组件编号]=Z.[组件编号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号, a.supplier_code 助焊剂厂商,a.part_nbr 助焊剂批号
|
|
FROM mes_main.dbo.trace_componnet_lot a
|
|
LEFT JOIN mes_main.dbo.pack_material_lot b
|
|
ON a.part_nbr=b.part_nbr AND a.lot_nbr=b.lot_nbr
|
|
LEFT JOIN mes_main.dbo.config_mat_attr c
|
|
ON b.part_nbr=c.part_nbr
|
|
WHERE a.part_type='Solder' AND c.attr_code='Solder_type'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)AA
|
|
ON A.[组件编号]=AA.[组件编号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号, a.supplier_code 互联条厂商,c.attr_value 互联条规格
|
|
FROM mes_main.dbo.trace_componnet_lot a
|
|
LEFT JOIN mes_main.dbo.pack_material_lot b
|
|
ON a.part_nbr=b.part_nbr AND a.lot_nbr=b.lot_nbr
|
|
LEFT JOIN mes_main.dbo.config_mat_attr c
|
|
ON b.part_nbr=c.part_nbr
|
|
WHERE a.part_type='HULIAN' AND c.attr_code='hulian_type'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)AB
|
|
ON A.[组件编号]=AB.[组件编号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr 组件编号, a.supplier_code 背板厂商,c.attr_value 背板规格,a.part_nbr 背板批号
|
|
FROM mes_main.dbo.trace_componnet_lot a
|
|
LEFT JOIN mes_main.dbo.pack_material_lot b
|
|
ON a.part_nbr=b.part_nbr AND a.lot_nbr=b.lot_nbr
|
|
LEFT JOIN mes_main.dbo.config_mat_attr c
|
|
ON b.part_nbr=c.part_nbr
|
|
WHERE a.part_type='BKSHEET' AND c.attr_code='bks_length'
|
|
--AND a.serial_nbr='HLJK2002090003'
|
|
)AC
|
|
ON A.[组件编号]=AC.[组件编号]
|
|
";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
# region 上档率
|
|
public DataTable UpshiftDT(string wo, string bt, string et)
|
|
{
|
|
return dbhelp.ExecuteDataTable(UpshiftSql(wo, bt,et), null);
|
|
}
|
|
|
|
public string UpshiftSql(string wo, string bt,string et)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(wo))
|
|
{
|
|
strWhere += " and c.workorder = '" + wo+ "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and b.wks_visit_date >= '" + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and b.wks_visit_date <= '" + et + "' ";
|
|
}
|
|
string sql = @" if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'tempdb..#temp') and type='U')
|
|
begin
|
|
drop table #temp --删除临时表#temp
|
|
end
|
|
|
|
select A.serial_nbr,A.pmax,B.power_grade,c.* INTO #TEMP from
|
|
(SELECT a.serial_nbr,b.pmax,c.power_grade_group_id
|
|
FROM mes_main.dbo.assembly_status a
|
|
LEFT JOIN mes_level2_iface.dbo.iv b
|
|
ON a.serial_nbr=b.serial_nbr
|
|
LEFT JOIN mes_main.dbo.wo_mfg c
|
|
ON a.workorder=c.workorder
|
|
WHERE 1=1 " + strWhere + @" --这里绑定工单号
|
|
--这里绑定时间
|
|
) A
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.serial_nbr,d.power_grade,c.workorder
|
|
FROM mes_main.dbo.assembly_status a
|
|
LEFT JOIN mes_level2_iface.dbo.iv b
|
|
ON a.serial_nbr=b.serial_nbr
|
|
LEFT JOIN mes_main.dbo.wo_mfg c
|
|
ON a.workorder=c.workorder
|
|
LEFT JOIN mes_main.dbo.config_power d
|
|
ON c.power_grade_group_id=d.power_grade_group_id
|
|
--WHERE c.workorder='1302-200118001'
|
|
AND b.pmax >= d.lower_power
|
|
AND b.pmax < d.upper_power
|
|
) B
|
|
ON A.serial_nbr = B.serial_nbr
|
|
left join
|
|
(
|
|
select power_grade_group_id,MIN(lower_power) as lowpower,MAX(upper_power) as maxpower
|
|
from mes_main.dbo.config_power
|
|
group by power_grade_group_id
|
|
) C
|
|
on a.power_grade_group_id = c.power_grade_group_id
|
|
|
|
--SELECT * FROM #TEMP
|
|
|
|
if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'tempdb..#temp_1') and type='U')
|
|
begin
|
|
drop table #temp_1 --删除临时表#temp
|
|
end
|
|
|
|
select a.name name,a. grade grade,CONVERT(VARCHAR(20),ISNULL(COUNT(a.serial_nbr), 0)) num into #temp_1 from
|
|
(
|
|
SELECT
|
|
CASE
|
|
WHEN pmax<(cast (lowpower as int)-5) THEN '(标准功率-5)+'
|
|
WHEN pmax>=(cast (lowpower as int)-5) AND pmax <cast (lowpower as int) THEN '标准功率-5'
|
|
WHEN pmax>=cast (maxpower as int) AND pmax<(cast(maxpower as int)+5) THEN '标准功率+5'
|
|
WHEN pmax>=(cast (maxpower as int)+5) THEN '(标准功率+5)+'
|
|
else '标准功率'
|
|
END
|
|
AS 'name'
|
|
,
|
|
CASE
|
|
WHEN pmax<(cast (lowpower as int)-5) THEN ( cast(cast (lowpower as int)-10 AS VARCHAR(20))+'--')
|
|
WHEN pmax>=(cast (lowpower as int)-5) AND pmax <cast (lowpower as int) THEN ( cast(cast (lowpower as int)-5 AS VARCHAR(20))+'-')
|
|
WHEN pmax>=cast (maxpower as int) AND pmax<(cast(maxpower as int)+5) THEN ( cast(cast (maxpower as int) AS VARCHAR(20))+'+')
|
|
WHEN pmax>=(cast (maxpower as int)+5) THEN ( cast(cast (maxpower as int)+5 AS VARCHAR(20))+'++')
|
|
else cast(power_grade as VARCHAR(20))
|
|
END
|
|
AS 'grade',serial_nbr
|
|
FROM #Temp
|
|
)A
|
|
GROUP BY a.grade,a.name
|
|
order by a.grade
|
|
|
|
SELECT name,grade,num FROM #TEMP_1
|
|
|
|
UNION ALL
|
|
|
|
SELECT '上档率' name,'' grade,REPLACE(CONVERT(FLOAT,ROUND((a.num-(SELECT ISNULL(SUM(CONVERT(INT,num)), 0)
|
|
FROM #temp_1
|
|
WHERE grade LIKE '%-%')+0.0)/a.num*100, 2)), '', '')+'%' num
|
|
FROM (
|
|
SELECT SUM(CONVERT(INT,num)) num
|
|
FROM #temp_1) a
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
#region 分档机组件查询
|
|
public DataTable StepperDT(string wo, string bt, string et)
|
|
{
|
|
return dbhelp.ExecuteDataTable(StepperSql(wo, bt, et), null);
|
|
}
|
|
|
|
public string StepperSql(string wo, string bt, string et)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(wo))
|
|
{
|
|
strWhere += " and [serial_nbr] = '" + wo + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and [request_time] >= '" + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and [request_time] <= '" + et + "' ";
|
|
}
|
|
string sql = @" SELECT
|
|
[serial_nbr]
|
|
,[line_id]
|
|
,[return_value]
|
|
,CONVERT(varchar(100),[request_time], 120) as time
|
|
,[error_msg]
|
|
FROM [mes_level2_iface].[dbo].[separator_request_log]
|
|
WHERE 1=1 " + strWhere + @"
|
|
";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
#region 车间质量问题统计
|
|
public DataTable QualityDT(string wo, string bt,string et)
|
|
{
|
|
return dbhelp.ExecuteDataTable(QualitySql(wo, bt,et), null);
|
|
}
|
|
|
|
public string QualitySql(string wo, string bt,string et)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
if (!string.IsNullOrEmpty(wo))
|
|
{
|
|
strWhere += " and a.workorder = '" + wo + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and c.wks_visit_date >= '" + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and c.wks_visit_date <= '" + et + "' ";
|
|
}
|
|
string sql = @"SELECT C.[日期] ,A.[产线],A.[订单客户名称],A.[工单号],A.[组件版型],A.[报检数量],B.[A2块数],REPLACE(CONVERT(FLOAT,ROUND((B.[A2块数]+0.0)/A.[报检数量]*100, 2)), '', '')+'%' 总A2率,C.[问题明细],C.[块数],REPLACE(CONVERT(FLOAT,ROUND((C.[块数]+0.0)/B.[A2块数]*100, 2)), '', '')+'%' 问题比例,C.[评审走A1]
|
|
FROM
|
|
(
|
|
SELECT a.customer 订单客户名称,a.workorder 工单号,COUNT(b.serial_nbr) 报检数量,d.line_id 产线,a.product_code 组件版型
|
|
FROM mes_main.dbo.wo_mfg a
|
|
LEFT JOIN mes_main.dbo.assembly_status b
|
|
ON a.workorder=b.workorder
|
|
LEFT JOIN mes_main.dbo.trace_workstation_visit c
|
|
ON b.serial_nbr=c.serial_nbr
|
|
LEFT JOIN mes_main.dbo.config_workstation d
|
|
ON c.wks_id=d.wks_id
|
|
WHERE 1=1 " + strWhere + @"
|
|
--这里是绑定条件的ZC1-190224001
|
|
AND d.process_code='N60'
|
|
--AND c.wks_visit_date>='' AND c.wks_visit_date<='' --这里绑定时间条件
|
|
--AND d.line_id= --这里绑定产线条件
|
|
GROUP BY a.workorder,a.customer,d.line_id,a.product_code
|
|
)A
|
|
LEFT JOIN
|
|
(
|
|
SELECT a.workorder 工单号, COUNT(b.serial_nbr) A2块数
|
|
FROM mes_main.dbo.wo_mfg a
|
|
LEFT JOIN mes_main.dbo.assembly_status b
|
|
ON a.workorder=b.workorder
|
|
LEFT JOIN mes_main.dbo.trace_workstation_visit c
|
|
ON b.serial_nbr=c.serial_nbr
|
|
LEFT JOIN mes_main.dbo.config_workstation d
|
|
ON c.wks_id=d.wks_id
|
|
WHERE d.process_code='N60'
|
|
AND b.final_grade='A'
|
|
GROUP BY a.workorder
|
|
)B
|
|
ON A.[工单号]=B.[工单号]
|
|
LEFT JOIN
|
|
(
|
|
SELECT CONVERT(varchar(100),c.wks_visit_date, 23) 日期,f.defect_type_name 问题明细,COUNT(b.serial_nbr) 块数,a.workorder 工单号,count(g.serial_nbr) 评审走A1
|
|
FROM mes_main.dbo.wo_mfg a
|
|
LEFT JOIN mes_main.dbo.assembly_status b
|
|
ON a.workorder=b.workorder
|
|
LEFT JOIN mes_main.dbo.trace_workstation_visit c
|
|
ON b.serial_nbr=c.serial_nbr
|
|
LEFT JOIN mes_main.dbo.config_workstation d
|
|
ON c.wks_id=d.wks_id
|
|
LEFT JOIN mes_main.dbo.defects e
|
|
ON b.serial_nbr =e.serial_nbr
|
|
LEFT JOIN mes_main.dbo.config_defect_type f
|
|
ON e.defect_type_id=f.defect_type_id
|
|
LEFT JOIN mes_main.dbo.qc_visit g
|
|
ON b.serial_nbr=g.serial_nbr
|
|
WHERE a.workorder='" + wo + @"'
|
|
--这里也要绑定工单号
|
|
AND d.process_code='N60'
|
|
AND b.final_grade='A'
|
|
GROUP BY f.defect_type_name,a.workorder,CONVERT(varchar(100),c.wks_visit_date, 23)
|
|
)C
|
|
ON A.[工单号]=C.[工单号]
|
|
|
|
|
|
";
|
|
return sql;
|
|
}
|
|
#endregion
|
|
|
|
#region 在制品弹出明细
|
|
public DataTable ProduincDT(string workshop, string workorder, string saleorder, string bt, string et, string field)
|
|
{
|
|
return dbhelp.ExecuteDataTable(ProduincSql(workshop, workorder, saleorder, bt, et, field), null);
|
|
}
|
|
|
|
public string ProduincSql(string workshop, string workorder, string saleorder, string bt, string et, string field)
|
|
{
|
|
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
|
|
string strWhere = string.Empty;
|
|
string strValue = string.Empty;
|
|
string strValue2 = string.Empty;
|
|
|
|
//if (!string.IsNullOrEmpty(sale_order))
|
|
//{
|
|
// strWhere += "and b.sale_order = '" + sale_order + "' ";
|
|
//}
|
|
if (!string.IsNullOrEmpty(workorder))
|
|
{
|
|
strWhere += " and d.workorder = '" + workorder + "' ";
|
|
strValue += " and f.workorder = '" + workorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(workshop))
|
|
{
|
|
strWhere += " and d.area_code = '" + workshop + "' ";
|
|
strValue += " and f.area_code = '" + workshop + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(saleorder))
|
|
{
|
|
strWhere += " and d.sale_order = '" + saleorder + "' ";
|
|
strValue += " and f.sale_order = '" + saleorder + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(bt))
|
|
{
|
|
strWhere += " and a.wks_visit_date >= '" + bt + "' ";
|
|
strValue += " and a.wks_visit_date >= '" + bt + "' ";
|
|
strValue2 += " and a.wks_visit_date >= '" + bt + "' ";
|
|
}
|
|
if (!string.IsNullOrEmpty(et))
|
|
{
|
|
strWhere += " and a.wks_visit_date < '" + et + "' ";
|
|
strValue += " and a.wks_visit_date < '" + et + "' ";
|
|
strValue2 += " and a.wks_visit_date < '" + et + "' ";
|
|
}
|
|
string sql = string.Empty;
|
|
if (field == "station_nbr")
|
|
{
|
|
sql = @"SELECT
|
|
case
|
|
when c.pallet_nbr IS not null then '包装'
|
|
when max(right(b.process_code,2)) = '10' then '焊接'
|
|
when max(right(b.process_code,2)) = '15' then '叠层'
|
|
when max(right(b.process_code,2)) = '30' then '层压'
|
|
when max(right(b.process_code,2)) = '40' then '层压后检验'
|
|
when max(right(b.process_code,2)) = '45' then '装框'
|
|
when max(right(b.process_code,2)) = '50' then '清洗'
|
|
when max(right(b.process_code,2)) = '55' then 'FQC'
|
|
when max(right(b.process_code,2)) = '60' then '全检'
|
|
end station
|
|
,a.[serial_nbr],a.operator,f.descriptions class,
a.wks_id,d.workorder,d.sale_order,max(a.wks_visit_date) wks_visit_date
FROM [mes_main].[dbo].[trace_workstation_visit] a
LEFT join mes_main.dbo.config_workstation b
on a.wks_id = b.wks_id
left join mes_main.dbo.assembly_status c
on a.serial_nbr = c.serial_nbr
left join mes_main.dbo.wo_mfg d
on c.workorder = d.workorder
left join mes_main.dbo.df_areas e
on d.area_code = e.area_code
left join mes_main.dbo.df_shift_type f
on a.shift_type = f.shift_type
where 1 = 1 " + strWhere + @"
group by a.[serial_nbr],a.operator,f.descriptions,
a.wks_id,d.workorder,d.sale_order,c.pallet_nbr";
}
if (field == "going_nbr")
{
sql = @"
select
case
when max(right(aa.ZZZD,2)) = '10' then '焊接'
when max(right(aa.ZZZD,2)) = '15' then '叠层'
when max(right(aa.ZZZD,2)) = '30' then '层压'
when max(right(aa.ZZZD,2)) = '40' then '层压后检验'
when max(right(aa.ZZZD,2)) = '45' then '装框'
when max(right(aa.ZZZD,2)) = '50' then '清洗'
when max(right(aa.ZZZD,2)) = '55' then 'FQC'
when max(right(aa.ZZZD,2)) = '60' then '全检'
when max(right(aa.ZZZD,2)) = '00' then '全检'
end station,
aa.serial_nbr,aa.operator,aa.descriptions class,aa.wks_id,aa.workorder,aa.sale_order,aa.wks_visit_date
from (select f.sale_order,f.workorder,a.serial_nbr,MAX(a.wks_visit_date) as wks_visit_date,max(g.process_code) AS ZZZD,b.area_code,a.operator,h.descriptions,a.wks_id
from mes_main.dbo.trace_workstation_visit a
left join mes_main.dbo.assembly_status e
on a.serial_nbr = e.serial_nbr
left join mes_main.dbo.config_products c
on e.product_code = c.product_code
left join mes_main.dbo.config_workstation b
on a.wks_id = b.wks_id
left join mes_main.dbo.config_process d
on c.process_group_id = d.process_group_id
and e.process_code = d.process_code
left join mes_main.dbo.config_process g
on c.process_group_id = g.process_group_id
and g.process_idx-1 = d.process_idx
LEFT JOIN mes_main.DBO.wo_mfg f
ON f.workorder = e.workorder
left join mes_main.dbo.df_shift_type h
on a.shift_type = h.shift_type
where 1=1 " + strValue + @"
group by a.serial_nbr,b.area_code,a.operator,h.descriptions,a.wks_id,f.workorder,f.sale_order) aa
JOIN (select a.serial_nbr,MAX(a.wks_visit_date) times
from mes_main.dbo.trace_workstation_visit a
where 1=1 " + strValue2 + @"
group by a.serial_nbr) bb
on aa.serial_nbr = bb.serial_nbr and aa.wks_visit_date = bb.times
where aa.ZZZD is not null
group by aa.serial_nbr,aa.operator,aa.descriptions,aa.wks_id,aa.workorder,aa.sale_order,aa.wks_visit_date
";
}
return sql;
}
#endregion
#region 条码补打报表
public DataTable ReprintDT(string wo,string sn, string bt, string et)
{
return dbhelp.ExecuteDataTable(ReprintSql(wo,sn, bt, et), null);
}
public string ReprintSql(string wo,string sn, string bt, string et)
{
//and c.sale_order = '' and b.workorder = '' and c.area_code = '' and a.create_date >= '' and a.create_date < ''
string strWhere = string.Empty;
if (!string.IsNullOrEmpty(wo))
{
strWhere += " and b.workorder = '" + wo + "' ";
}
if (!string.IsNullOrEmpty(sn))
{
strWhere += " and a.serial_nbr = '" + sn + "' ";
}
if (!string.IsNullOrEmpty(bt))
{
strWhere += " and a.create_date >= '" + bt + "' ";
}
if (!string.IsNullOrEmpty(et))
{
strWhere += " and a.create_date <= '" + et + "' ";
}
string sql = @" select a.serial_nbr,b.workorder,CONVERT(varchar(100),a.create_date, 120) create_date,a.op_id,a.pc_id,a.Reason
FROM mes_main.dbo.assembly_Reprintlog a
left join mes_main.dbo.assembly_basis b
on a.serial_nbr=b.serial_nbr
where 1=1 " + strWhere+@"
";
return sql;
}
#endregion
#region 耐压报表
public DataTable PressureResistantInfo(string lot, string bt, string et)
{
return dbhelp.ExecuteDataTable(PressureResistantSql(lot,bt, et), null);
}
private string PressureResistantSql(string lot,string bt, string et)
{
string strwhere = "";
if (!string.IsNullOrEmpty(bt.ToString()))
{
strwhere += "and [LastTime] >= '" + Convert.ToString(bt) + "'";
strwhere += " and [LastTime] <= '" + Convert.ToString(et) + "'";
}
strwhere += String.IsNullOrEmpty(lot) ? "" : " AND [BarCode] in (" + Convert.ToString(lot) + ")";
////
string sql = @"SELECT
[BarCode]
,[MemoryId]
,[StepId]
,[UserId]
,[ReadMode]
,[Source]
,[ReadData1]
,[Limit]
,[ReadData2]
,[ReadTime]
,[ReadResult]
,[LastTime]
FROM [mes_level2_iface].[dbo].[PressureResistant]
where 1=1 " + strwhere;
return sql;
}
#endregion
#region 泛海CTM报表
public DataTable CTMReportInfo(string lot, string wo, string bt, string et, string pallet_nb)
{
return dbhelp.ExecuteDataTable(CTMReportSql(lot, wo, bt, et, pallet_nb), null);
}
public string CTMReportSql(string lot, string wo, string bt, string et, string pallet_nbr)
{
string strwhere = "";
if (!string.IsNullOrEmpty(bt.ToString()))
{
strwhere += " and iv.wks_visit_date >= '" + Convert.ToString(bt) + "'";
strwhere += " and iv.wks_visit_date <= '" + Convert.ToString(et) + "'";
}
strwhere += String.IsNullOrEmpty(wo) ? "" : " AND wm.workorder = '" + Convert.ToString(wo) + "'";
strwhere += String.IsNullOrEmpty(lot) ? "" : " AND ast.serial_nbr in (" + Convert.ToString(lot) + ")";
strwhere += String.IsNullOrEmpty(pallet_nbr) ? "" : " AND ppk.pallet_nbr = '" + Convert.ToString(pallet_nbr) + "'";
string sql = @"SELECT distinct
CONVERT(varchar(100),iv.wks_visit_date, 120) as wks_visit_date /*测试时间*/
,ast.[serial_nbr] /*组件序列号*/
,ms.[descriptions] cell_supplier/*电池片供应商*/
,case when eff.attr_code = 'cell_eff' then eff.attr_value end cell_eff/*电池片效率档*/
,case when cmc.attr_code = 'cell_uop' then cmc.attr_value end cell_uop/*单片功率*/
,case
when cmc.attr_value is null or cmc.attr_value = '' then ''
else
case when right(cmc.attr_value,1)='W' THEN
case when ISNUMERIC(left(cmc.attr_value,LEN(cmc.attr_value)-1)) = 1 then CONVERT(numeric(18,2),wm.cell_qty)* cast(left(cmc.attr_value,LEN(cmc.attr_value)-1) as float)
else 0
end
else
case when ISNUMERIC(left(cmc.attr_value,LEN(cmc.attr_value))) = 1 then CONVERT(numeric(18,2),wm.cell_qty)* cast(left(cmc.attr_value,LEN(cmc.attr_value)) as float)
else 0
end
end
--case when right(cmc.attr_value,1)='W' THEN left(cmc.attr_value,LEN(cmc.attr_value)-1)
--else cmc.attr_value
--end
end EDGL
,case
when cmc.attr_value is null or cmc.attr_value = '' then ''
else
case when right(cmc.attr_value,1)='W' THEN
case when ISNUMERIC(left(cmc.attr_value,LEN(cmc.attr_value)-1)) = 1 then
cast(cast(
case when right(cmc.attr_value,1)='W' THEN iv.[pmax]/NULLIF(cast(CONVERT(numeric(18,2),wm.cell_qty)* cast(left(cmc.attr_value,LEN(cmc.attr_value)-1) as float) as FLOAT),0)*100
else iv.[pmax]/NULLIF(cast(CONVERT(numeric(18,2),wm.cell_qty)* cast(cmc.attr_value as float) as FLOAT),0)*100
end
as numeric(18,2)) as varchar(50))+'%'
else '0%'
end
else
case when ISNUMERIC(left(cmc.attr_value,LEN(cmc.attr_value))) = 1 then
cast(cast(
case when right(cmc.attr_value,1)='W' THEN iv.[pmax]/NULLIF(cast(CONVERT(numeric(18,2),wm.cell_qty)* cast(left(cmc.attr_value,LEN(cmc.attr_value)) as float) as FLOAT),0)*100
else iv.[pmax]/NULLIF(cast(CONVERT(numeric(18,2),wm.cell_qty)* cast(cmc.attr_value as float) as FLOAT),0)*100
end
as numeric(18,2)) as varchar(50))+'%'
else '0%'
end
end
end CTM
--,case
--when cmc.attr_value is null or cmc.attr_value = '' then ''
--else
--end CTM
-- ,cast(cast(iv.[pmax]/NULLIF(cast(CONVERT(numeric(18,2),wm.cell_qty)* cast(
-- case when right(cmc.attr_value,1)='W' THEN left(cmc.attr_value,LEN(cmc.attr_value)-1)
-- else cmc.attr_value
-- end
-- as float) as FLOAT),0)*100 as numeric(18,2)) as varchar(50))+'%' fff /*投入产出比*/
,iv.[pmax] pmax
,iv.[rsh] rsh
,iv.[rs] rs
,cast(substring(cast(iv.[ff]*100.00 as varchar(100)),1,charindex('.',iv.[ff]*100.00)+2) as float) as ff
,iv.[isc] isc
,iv.[voc] voc
,iv.[ipm] imax
,iv.[vpm] vmax
,area.descriptions area_code
,iv.wks_id/*测试机台*/
,cast(iv.[surf_temp] as numeric(18,2)) surf_temp /*表面温度*/
,iv.[env_temp] env_temp /*环境温度*/
,case when bakthick.attr_code = 'bks_thickness' then bakthick.attr_value end bakthick/*背板厚度*/
,'' 电池片厚度
,case when type.attr_code = 'cell_type' then type.attr_value end cell_type/*电池片规格*/
,wm.cell_qty/*电池数量*/
,wm.mod_color
,eva.[descriptions] eva_supplier /*eva厂商*/
,bks.descriptions bks_supplier /*背板厂商*/
,glass.descriptions glass_supplier /*玻璃厂商*/
,huiliu.active_flag huiliu_supplier /*焊带厂商*/
,ab.lot_nbr celllot /*电池片批号*/
,jboxcom.lot_nbr jboxlot /*接线盒批号*/
--,CONVERT(varchar(100), ppk.[pack_date], 120) as pack_date/*封箱时间*/
--,ast.[power_grade]/*功率档位*/
--,ast.current_grade/*电流档位*/
--,ast.[product_code]/*装配件号*/
--,ast.[el_grade]/*EL等级*/
--,ast.exterior_grade/*外观等级*/
--,ast.[final_grade]/*最终等级*/
--,cpp.[descriptions]/*功率组*/
--,dst.[descriptions] shift_type/*班次*/
--,iv.[eff] eff
--,cast(iv.[eff] as numeric(18,2)) eff
--,cast(iv.[temp] as numeric(18,2)) temp
--,cast(iv.[ivfile_path] as numeric(18,2)) ivfile_path
--,iv.[surf_temp] tmod
--,case when color.attr_code = 'cell_color' then color.attr_value end cell_color/*电池颜色*/
--,case when grade.attr_code = 'cell_grade' then grade.attr_value end cell_grade/*电池片等级*/
--,CONVERT(int,wm.cell_qty)
FROM[mes_main].[dbo].[assembly_status]
ast
left join[mes_level2_iface].[dbo].[iv]
iv
on ast.[serial_nbr]=iv.[serial_nbr]
left join[mes_main].[dbo].[pack_pallets]
ppk
on ast.[pallet_nbr]=ppk.[pallet_nbr]
--left join[mes_main].[dbo].[df_pallet_status]
-- dps
--on ppk.[pallet_status]=dps.[pallet_status]
--left join[mes_main].[dbo].[df_shift_type]
-- dst
--on ppk.[shift_type]=dst.[shift_type]
--left join[mes_main].[dbo].[config_power_group]
-- cpp
--on ppk.[power_grade_group_id]=cpp.[power_grade_group_id]
LEFT join mes_main.dbo.trace_componnet_lot
ab
on ab.serial_nbr = ast.serial_nbr and ab.part_type = 'CELL'
left join[mes_level4_iface].[dbo].[master_supplier]
ms
on ab.supplier_code=ms.[supplier_code]
left join[mes_main].[dbo].[config_mat_attr]
cmc
on ab.part_nbr=cmc.[part_nbr] and cmc.attr_code = 'cell_uop'
--left join[mes_main].[dbo].[config_mat_attr]
-- color
--on ab.part_nbr=color.[part_nbr] and color.attr_code = 'cell_color'
--left join[mes_main].[dbo].[config_mat_attr]
-- grade
--on ab.part_nbr=grade.[part_nbr] and grade.attr_code = 'cell_grade'
left join[mes_main].[dbo].[config_mat_attr]
type
on ab.part_nbr=type.[part_nbr] and type.attr_code = 'cell_type'
left join[mes_main].[dbo].[config_mat_attr]
eff
on ab.part_nbr=eff.[part_nbr] and eff.attr_code = 'cell_eff'
LEFT join mes_main.dbo.trace_componnet_lot
BKSHEET
on ab.serial_nbr = ast.serial_nbr and ab.part_type = 'BKSHEET'
left join[mes_main].[dbo].[config_mat_attr]
bakthick
on BKSHEET.part_nbr=bakthick.[part_nbr] and bakthick.attr_code = 'bks_thickness'
LEFT join mes_main.dbo.trace_componnet_lot
evacom
on ast.serial_nbr = evacom.serial_nbr and evacom.part_type = 'EVA'
left join[mes_level4_iface].[dbo].[master_supplier]
eva
on evacom.supplier_code=eva.[supplier_code]
LEFT join mes_main.dbo.trace_componnet_lot
bkscom
on ast.serial_nbr = bkscom.serial_nbr and bkscom.part_type = 'BKSHEET'
left join[mes_level4_iface].[dbo].[master_supplier]
bks
on bkscom.supplier_code=bks.[supplier_code]
LEFT join mes_main.dbo.trace_componnet_lot
glasscom
on ast.serial_nbr = glasscom.serial_nbr and glasscom.part_type = 'GLASS'
left join[mes_level4_iface].[dbo].[master_supplier]
glass
on glasscom.supplier_code=glass.[supplier_code]
LEFT join mes_main.dbo.trace_componnet_lot
huiliucom
on ast.serial_nbr = huiliucom.serial_nbr and huiliucom.part_type = 'HUILIU'
left join[mes_level4_iface].[dbo].[master_supplier]
huiliu
on huiliucom.supplier_code=huiliu.[supplier_code]
LEFT join mes_main.dbo.trace_componnet_lot
jboxcom
on ast.serial_nbr = jboxcom.serial_nbr and jboxcom.part_type = 'JBOX'
left join[mes_main].[dbo].[wo_mfg]
wm
on ast.[workorder]=wm.[workorder]
left join mes_main.dbo.df_areas
area
on wm.area_code = area.area_code
where 1=1 and iv.[pmax] is not null " + strwhere;
return sql;
}
#endregion
#region 泛海材料批号报表
public DataTable MaterialLotInfo(string orignbr, string lotnbr, string wo)
{
return dbhelp.ExecuteDataTable(MaterialLotSql(orignbr, lotnbr, wo), null);
}
public string MaterialLotSql(string orignbr, string lotnbr, string wo)
{
string strwhere = "";
strwhere += String.IsNullOrEmpty(wo) ? "" : " AND a.workorder in (" + Convert.ToString(wo) + ")";
strwhere += String.IsNullOrEmpty(orignbr) ? "" : " AND a.orig_batch_nbr in (" + Convert.ToString(orignbr) + ")";
strwhere += String.IsNullOrEmpty(lotnbr) ? "" : " AND a.lot_nbr = '" + Convert.ToString(lotnbr) + "'";
string sql = @"select b.part_type_desc
,a.orig_batch_nbr
,a.lot_nbr
,a.lot_qty_remaining
,a.lot_qty
,aa.batch_qty
,a.uom
,c.descriptions supplierdesc
,case
when b.part_type = 'CELL' then d.attr_value
when b.part_type = 'EVA' then e.attr_value
when b.part_type = 'EVA2' then f.attr_value
when b.part_type = 'BKSHEET' then g.attr_value
when b.part_type = 'GLASS' then h.attr_value
when b.part_type = 'HULIAN' then i.attr_value
when b.part_type = 'HUILIU' then j.attr_value
when b.part_type = 'Solder' then k.attr_value
when b.part_type = 'JBOX' then l.attr_value
when b.part_type = 'LFRAME' then m.attr_value
when b.part_type = 'SFRAME' then n.attr_value
when b.part_type = 'JBOXGLUE' then o.attr_value
when b.part_type = 'ABGLUE' then p.attr_value
when b.part_type = 'FRAMEGLUE' then q.attr_value
when b.part_type = 'IsolatingBar' then r.attr_value
end specification
from [mes_main].[dbo].[pack_material_lot] a
left join [mes_main].[dbo].[config_bom_mfg] b
on a.workorder = b.workorder and a.part_nbr = b.bom_part_nbr
left join [mes_level4_iface].[dbo].[master_supplier] c
on a.supplier_code = c.supplier_code
left join [mes_main].[dbo].[config_mat_attr] d
on a.part_nbr = d.part_nbr and b.part_type = d.part_type and d.attr_code = 'cell_size'
left join [mes_main].[dbo].[config_mat_attr] e
on a.part_nbr = e.part_nbr and b.part_type = e.part_type and e.attr_code = 'eva_length'
left join [mes_main].[dbo].[config_mat_attr] f
on a.part_nbr = f.part_nbr and b.part_type = f.part_type and f.attr_code = 'eva_length'
left join [mes_main].[dbo].[config_mat_attr] g
on a.part_nbr = g.part_nbr and b.part_type = g.part_type and g.attr_code = 'bks_length'
left join [mes_main].[dbo].[config_mat_attr] h
on a.part_nbr = h.part_nbr and b.part_type = h.part_type and h.attr_code = 'glass_length'
left join [mes_main].[dbo].[config_mat_attr] i
on a.part_nbr = i.part_nbr and b.part_type = i.part_type and i.attr_code = 'hulian_type'
left join [mes_main].[dbo].[config_mat_attr] j
on a.part_nbr = j.part_nbr and b.part_type = j.part_type and j.attr_code = 'huiliu_type'
left join [mes_main].[dbo].[config_mat_attr] k
on a.part_nbr = k.part_nbr and b.part_type = k.part_type and k.attr_code = 'Solder_type'
left join [mes_main].[dbo].[config_mat_attr] l
on a.part_nbr = l.part_nbr and b.part_type = l.part_type and l.attr_code = 'jbox_type'
left join [mes_main].[dbo].[config_mat_attr] m
on a.part_nbr = m.part_nbr and b.part_type = m.part_type and m.attr_code = 'frame_length'
left join [mes_main].[dbo].[config_mat_attr] n
on a.part_nbr = n.part_nbr and b.part_type = n.part_type and n.attr_code = 'frame_length'
left join [mes_main].[dbo].[config_mat_attr] o
on a.part_nbr = o.part_nbr and b.part_type = o.part_type and o.attr_code = 'JBOXGLUE_type'
left join [mes_main].[dbo].[config_mat_attr] p
on a.part_nbr = p.part_nbr and b.part_type = p.part_type and p.attr_code = 'ABGLUE_type'
left join [mes_main].[dbo].[config_mat_attr] q
on a.part_nbr = q.part_nbr and b.part_type = q.part_type and q.attr_code = 'FRAMEGLUE_type'
left join [mes_main].[dbo].[config_mat_attr] r
on a.part_nbr = r.part_nbr and b.part_type = r.part_type and r.attr_code = 'IsolatingBar_type'
left join (
select a.workorder,a.orig_batch_nbr,b.part_type,sum(a.lot_qty_remaining) batch_qty
from [mes_main].[dbo].[pack_material_lot] a
left join [mes_main].[dbo].[config_bom_mfg] b
on a.workorder = b.workorder and a.part_nbr = b.bom_part_nbr
where 1 = 1" + strwhere +@"
group by a.workorder,a.orig_batch_nbr,b.part_type
) aa
on a.workorder = aa.workorder and a.orig_batch_nbr = aa.orig_batch_nbr
where 1 = 1 " + strwhere;
return sql;
}
#endregion
}
}
|