using System; using System.Collections.Generic; using System.Data.Entity.Validation; using System.Linq; using System.Web; using Warehouse.Models; using Warehouse.Models.mesModel; using Z.EntityFramework.Plus; namespace Warehouse.DAL.EveryStationLotInfo { public class EveryStationLotInfo { public dynamic Station_capacity(dynamic para) { using (var context = new mesModel()) { string sql = string.Empty; string strWhere = string.Empty; string strIVWhere = string.Empty; string strELWhere = string.Empty; string strPackWhere = string.Empty; if (para.checkEmpty()) { strWhere += " limit 0,1 "; strIVWhere += " limit 0,1 "; strELWhere += " limit 0,1 "; strPackWhere += " limit 0,1 "; } else { if (para.StartDTFlg == "Y") { strWhere += " and a.wks_visit_date >= '" + para.StartDateTime + "' "; strIVWhere += " and a.wks_visit_date >= '" + para.StartDateTime + "' "; strELWhere += " and a.wks_visit_date >= '" + para.StartDateTime + "' "; strPackWhere += " and a.pack_date >= '" + para.StartDateTime + "' "; } if (para.EndDTFlg == "Y") { strWhere += " and a.wks_visit_date <= '" + para.EndDateTime + "' "; strIVWhere += " and a.wks_visit_date <= '" + para.EndDateTime + "' "; strELWhere += " and a.wks_visit_date <= '" + para.EndDateTime + "' "; strPackWhere += " and a.pack_date <= '" + para.EndDateTime + "' "; } if (!string.IsNullOrEmpty(para.WorkShop)) { strWhere += " and g.area_code = '" + para.WorkShop + "' "; strIVWhere += " and g.area_code = '" + para.WorkShop + "' "; strELWhere += " and g.area_code = '" + para.WorkShop + "' "; strPackWhere += " and c.area_code = '" + para.WorkShop + "' "; } if (!string.IsNullOrEmpty(para.ModuleID)) { strWhere += " a.serial_nbr = '" + para.ModuleID + "' "; strIVWhere += " and a.serial_nbr = '" + para.ModuleID + "' "; strELWhere += " and a.serial_nbr = '" + para.ModuleID + "' "; strPackWhere += " and a.serial_nbr = '" + para.ModuleID + "' "; } if (!string.IsNullOrEmpty(para.WorkOrder)) { strWhere += " and b.workorder = '" + para.WorkOrder + "' "; strIVWhere += " and b.WorkOrder_ID = '" + para.WorkOrder + "' "; strELWhere += " and b.WorkOrder_ID = '" + para.WorkOrder + "' "; strPackWhere += " and b.WorkOrder_ID = '" + para.WorkOrder + "' "; } //if (!string.IsNullOrEmpty(para.ProduceNotice)) //{ // strWhere += " and b.ProduceNotice = '" + para.ProduceNotice + "' "; // strIVWhere += " and b.ProduceNotice = '" + para.ProduceNotice + "' "; // strELWhere += " and b.ProduceNotice = '" + para.ProduceNotice + "' "; // strPackWhere += " and b.ProduceNotice = '" + para.ProduceNotice + "' "; //} if (!string.IsNullOrEmpty(para.Banci)) { strWhere += " and h.descriptions = '" + para.Banci + "' "; strIVWhere += " and 1=2 "; strELWhere += " and 1=2 "; strPackWhere += " and and 1=2 = '" + para.Banci + "' "; } } string sql_HJ = @" select '+' EX ,'焊接' 站点,'' 序列号,'' 操作人员,'' 车间,'' 班次,'' 设备,'' 过站时间,'false' IsEx,0 'RowCount' union all SELECT '' as 序号,'焊接' 站点, a.serial_nbr,a.operator+'|' + f.nickname as 操作人员 ,g.area_code,h.descriptions,a.wks_id ,a.wks_visit_date,'','' FROM mes_main.dbo.trace_workstation_visit a left join mes_main.dbo.assembly_status b on a.serial_nbr = b.serial_nbr left join mes_auth.dbo.df_user f on a.operator = f.username left join mes_main.dbo.config_workstation g on a.wks_id = g.wks_id left join mes_main.dbo.df_shift_type h on a.shift_type = h.shift_type where g.process_code = 'M10'" + strWhere+ "group by a.serial_nbr,a.operator,f.nickname,g.area_code,a.wks_id,a.wks_visit_date,h.descriptions" ; string sql_DC = @" select '+' EX ,'叠层' 站点,'' 序列号,'' 操作人员,'' 车间,'' 班次,'' 设备,'' 过站时间,'false' IsEx,0 'RowCount' union all SELECT '' as 序号,'叠层' 站点, a.serial_nbr,a.operator+'|' + f.nickname as 操作人员 ,g.area_code,h.descriptions,a.wks_id ,a.wks_visit_date,'','' FROM mes_main.dbo.trace_workstation_visit a left join mes_main.dbo.assembly_status b on a.serial_nbr = b.serial_nbr left join mes_auth.dbo.df_user f on a.operator = f.username left join mes_main.dbo.config_workstation g on a.wks_id = g.wks_id left join mes_main.dbo.df_shift_type h on a.shift_type = h.shift_type where g.process_code = 'M15'" + strWhere + "group by a.serial_nbr,a.operator,f.nickname,g.area_code,a.wks_id,a.wks_visit_date,h.descriptions"; string sql_CY = @" select '+' EX ,'层压' 站点,'' 序列号,'' 操作人员,'' 车间,'' 班次,'' 设备,'' 过站时间,'false' IsEx,0 'RowCount' union all SELECT '' as 序号,'层压' 站点, a.serial_nbr,a.operator+'|' + f.nickname as 操作人员 ,g.area_code,h.descriptions,a.wks_id ,a.wks_visit_date,'','' FROM mes_main.dbo.trace_workstation_visit a left join mes_main.dbo.assembly_status b on a.serial_nbr = b.serial_nbr left join mes_auth.dbo.df_user f on a.operator = f.username left join mes_main.dbo.config_workstation g on a.wks_id = g.wks_id left join mes_main.dbo.df_shift_type h on a.shift_type = h.shift_type where g.process_code = 'N30'" + strWhere + "group by a.serial_nbr,a.operator,f.nickname,g.area_code,a.wks_id,a.wks_visit_date,h.descriptions"; string sql_ZK = @" select '+' EX ,'装框' 站点,'' 序列号,'' 操作人员,'' 车间,'' 班次,'' 设备,'' 过站时间,'false' IsEx,0 'RowCount' union all SELECT '' as 序号,'装框' 站点, a.serial_nbr,a.operator+'|' + f.nickname as 操作人员 ,g.area_code,h.descriptions,a.wks_id ,a.wks_visit_date,'','' FROM mes_main.dbo.trace_workstation_visit a left join mes_main.dbo.assembly_status b on a.serial_nbr = b.serial_nbr left join mes_auth.dbo.df_user f on a.operator = f.username left join mes_main.dbo.config_workstation g on a.wks_id = g.wks_id left join mes_main.dbo.df_shift_type h on a.shift_type = h.shift_type where g.process_code = 'M45'" + strWhere + "group by a.serial_nbr,a.operator,f.nickname,g.area_code,a.wks_id,a.wks_visit_date,h.descriptions"; string sql_QX = @" select '+' EX ,'清洗' 站点,'' 序列号,'' 操作人员,'' 车间,'' 班次,'' 设备,'' 过站时间,'false' IsEx,0 'RowCount' union all SELECT '' as 序号,'清洗' 站点, a.serial_nbr,a.operator+'|' + f.nickname as 操作人员 ,g.area_code,h.descriptions,a.wks_id ,a.wks_visit_date,'','' FROM mes_main.dbo.trace_workstation_visit a left join mes_main.dbo.assembly_status b on a.serial_nbr = b.serial_nbr left join mes_auth.dbo.df_user f on a.operator = f.username left join mes_main.dbo.config_workstation g on a.wks_id = g.wks_id left join mes_main.dbo.df_shift_type h on a.shift_type = h.shift_type where g.process_code = 'N50'" + strWhere + "group by a.serial_nbr,a.operator,f.nickname,g.area_code,a.wks_id,a.wks_visit_date,h.descriptions"; string sql_IV = @" select '+' EX ,'IV' 站点,'' 序列号,'' 操作人员,'' 车间,'' 班次,'' 设备,'' 过站时间,'false' IsEx,0 'RowCount' union all SELECT '' as 序号,'IV' 站点, a.serial_nbr, '' as 操作人员 ,g.area_code,'' as banci,a.wks_id ,a.wks_visit_date,'','' 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.config_workstation g on a.wks_id = g.wks_id " + strIVWhere; string sql_EL = @" select '+' EX ,'EL' 站点,'' 序列号,'' 操作人员,'' 车间,'' 班次,'' 设备,'' 过站时间,'false' IsEx,0 'RowCount' union all SELECT '' as 序号,'EL' 站点, a.serial_nbr, '' as 操作人员 ,g.area_code,'' as banci,a.wks_id ,a.wks_visit_date,'','' FROM mes_level2_iface.dbo.el a left join mes_main.dbo.assembly_status b on a.serial_nbr = b.serial_nbr left join mes_main.dbo.config_workstation g on a.wks_id = g.wks_id " + strELWhere; #region add by genhong.hu ON 2016-11-29 string sql_QJ = @" select '+' EX ,'全检' 站点,'' 序列号,'' 操作人员,'' 车间,'' 班次,'' 设备,'' 过站时间,'false' IsEx,0 'RowCount' union all SELECT '' as 序号,'全检' 站点, a.serial_nbr,a.operator+'|' + f.nickname as 操作人员 ,g.area_code,h.descriptions,a.wks_id ,a.wks_visit_date,'','' FROM mes_main.dbo.trace_workstation_visit a left join mes_main.dbo.assembly_status b on a.serial_nbr = b.serial_nbr left join mes_auth.dbo.df_user f on a.operator = f.username left join mes_main.dbo.config_workstation g on a.wks_id = g.wks_id left join mes_main.dbo.df_shift_type h on a.shift_type = h.shift_type where g.process_code = 'N60'" + strWhere + "group by a.serial_nbr,a.operator,f.nickname,g.area_code,a.wks_id,a.wks_visit_date,h.descriptions"; #endregion string sql_BZ = @"select '+' EX ,'包装' 站点,'' 序列号,'' 操作人员,'' 车间,'' 班次,'' 设备,'' 过站时间,'false' IsEx,0 'RowCount' union all SELECT '' as 序号,'包装' 站点, a.serial_nbr,'' as 操作人员 ,c.area_code,h.descriptions,b.wks_id ,a.pack_date,'','' 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.config_workstation c on b.wks_id = c.wks_id left join mes_main.dbo.df_shift_type h on b.shift_type = h.shift_type where b.pallet_status > '0' group by b.wks_id,c.area_code ,a.serial_nbr,a.pallet_nbr,a.workorder,a.product_code,a.pack_date,h.descriptions " + strPackWhere; if (!string.IsNullOrEmpty(para.Station)) { switch (para.Station) { case "M10": sql = sql_HJ; break; case "M15": sql = sql_DC; break; case "N30": sql = sql_CY; break; case "M45": sql = sql_ZK; break; case "N50": sql = sql_QX; break; case "N60": sql = sql_QJ; break; case "P100": sql = sql_BZ; break; default: sql = sql_HJ; break; } } else { sql = sql_HJ + " union all " + sql_DC + " union all " + sql_CY + " union all " + sql_ZK + " union all " + sql_QX + " union all " + sql_IV + " union all " + sql_EL + " union all " + sql_QJ + " union all " + sql_BZ; } var res = context.DynamicListFromSql(sql, null); return res; } } } }