天津投入产出系统后端
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.
 
 
 
 
 
 

741 lines
38 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
using QMAPP.MESReport.Entity.LineQTY;
using QMAPP.DAL;
using System.Data;
using QMAPP.Entity.QueryTL;
using QMAPP.MD.DAL;
using QMAPP.MD.Entity;
using QMFrameWork.Log;
namespace QMAPP.MESReport.DAL.LineQTY
{
/// <summary>
/// 生产完成率分析
/// 于子清
/// 2017-10-23
/// </summary>
public class QTYCompletionRateDAL : BaseDAL
{
public List<QTYCompletionRateDModel> GetAllListOld(QTYCompletionRateDModel condition)
{
List<QTYCompletionRateDModel> list = new List<QTYCompletionRateDModel>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<QTYCompletionRateDModel>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
public List<QTYCompletionRateDModel> GetAllListNew1(QTYCompletionRateDModel condition)
{
List<QTYCompletionRateDModel> list = new List<QTYCompletionRateDModel>();
string sql = null;
//20180123周晓东-增加班次查询条件
var shiftList = new FJC.DAL.Basic.ProduceShiftDAL().GetList(new FJC.Entity.Basic.ProduceShift());
DateTime startDate = new DateTime();
DateTime endDate = new DateTime();
var shiftCode = "";
foreach (var shift in shiftList)
{
startDate = Convert.ToDateTime(shift.PSSTART.ToString("HH:mm:ss"));
endDate = Convert.ToDateTime(shift.PSEND.ToString("HH:mm:ss"));
var now = Convert.ToDateTime(DateTime.Now.ToString("HH:mm:ss"));
shiftCode = shift.PRODUCESHIFTTCODE;
if (DateTime.Compare(now, startDate) > 0 && DateTime.Compare(endDate, now) > 0)
{
break;
}
}
var dstart = startDate.ToString("yyyy-MM-dd HH:mm:ss");
var dend = endDate.ToString("yyyy-MM-dd HH:mm:ss");
var dday = DateTime.Now.ToString("yyyy-MM-dd");
//测试数据
//dstart = "2018/01/15 07:30:01";
//dend = "2018/01/15 16:30:00";
List<DataParameter> parameters = new List<DataParameter>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//查出T_AW_MAINOPERATION表里的注塑件完成数量
sql = "SELECT count([PID]) as COMPLETE_QTY,MATERIAL_CODE FROM T_AW_MAINOPERATION where CREATEDATE>'" + dstart + "' and CREATEDATE<'" + dend + "' and WORKCENTER_CODE='INJECTION_AREA' group by MATERIAL_CODE order by MATERIAL_CODE";
var pmList = session.GetList<QTYCompletionRateDModel>(sql, parameters.ToArray());
LogManager.LogHelper.Info(new LogInfo()
{
Tag = "注塑件完成数量",
Info = sql
});
//查出T_PP_ORDERPLAN表里的注塑件计划数量
sql = "select sum(QTY) as QTY,MATERIAL_CODE from T_PP_ORDERPLAN where DATEDIFF(DAY,PLAN_DATE,'" + dday + "')=0 and SHIFT_CODE='" + shiftCode + "' and WORKCENTER_CODE='INJECTION_AREA' group by MATERIAL_CODE order by MATERIAL_CODE";
var opList = session.GetList<QTYCompletionRateDModel>(sql, parameters.ToArray());
LogManager.LogHelper.Info(new LogInfo()
{
Tag = "注塑件计划数量",
Info = sql
});
List<Material> materialList= new MaterialDAL().GetMaterialList(new Material());
//添加完成数量
if (pmList != null && pmList.Count>0)
{
foreach (var item in pmList)
{
//零件名称
if (!string.IsNullOrEmpty(item.MATERIAL_CODE))
{
var material = materialList.FirstOrDefault(x => x.MATERIAL_CODE == item.MATERIAL_CODE);
if (material != null)
{
item.MATERIAL_NAME = material.MATERIAL_NAME;
item.MATERIAL_SHORT = material.MATERIAL_SHORT;
if (string.IsNullOrEmpty(material.MATERIAL_SHORT))
{
item.MATERIAL_SHORT = material.MATERIAL_CODE;
}
}
}
if (opList != null && opList.Count > 0)
{
var item_ORDERPLAN =
opList.FirstOrDefault(x => x.MATERIAL_CODE == item.MATERIAL_CODE);
//计划数量
if (item_ORDERPLAN != null)
{
item.QTY = item_ORDERPLAN.QTY;
//移除重复的MATERIAL_CODE
opList.Remove(item_ORDERPLAN);
}
}
list.Add(item);
}
}
//添加完成数量list里没有的MATERIAL_CODE
if (opList != null && opList.Count>0)
{
foreach (var item in opList)
{
//零件名称
if (!string.IsNullOrEmpty(item.MATERIAL_CODE))
{
var material = materialList.FirstOrDefault(x => x.MATERIAL_CODE == item.MATERIAL_CODE);
if (material != null)
{
item.MATERIAL_NAME = material.MATERIAL_NAME;
item.MATERIAL_SHORT = material.MATERIAL_SHORT;
if (string.IsNullOrEmpty(material.MATERIAL_SHORT))
{
item.MATERIAL_SHORT = material.MATERIAL_CODE;
}
}
}
list.Add(item);
}
}
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
public List<QTYCompletionRateDModel> GetAllListNew2(QTYCompletionRateDModel condition)
{
List<QTYCompletionRateDModel> list = new List<QTYCompletionRateDModel>();
string sql = null;
//20180123周晓东-增加班次查询条件
var shiftList = new ShiftDAL().GetAllShift(new Shift__());
DateTime startDate = new DateTime();
DateTime endDate = new DateTime();
var shiftCode = "";
foreach (var shift in shiftList)
{
startDate = Convert.ToDateTime(shift.WORK_START_TIME.ToString("HH:mm:ss"));
endDate = Convert.ToDateTime(shift.WORK_END_TIME.ToString("HH:mm:ss"));
var now = Convert.ToDateTime(DateTime.Now.ToString("HH:mm:ss"));
shiftCode = shift.SHIFT_CODE;
if (DateTime.Compare(now, startDate) > 0 && DateTime.Compare(endDate, now) > 0)
{
break;
}
}
var dstart = startDate.ToString("yyyy-MM-dd HH:mm:ss");
var dend = endDate.ToString("yyyy-MM-dd HH:mm:ss");
var dday = DateTime.Now.ToString("yyyy-MM-dd");
//测试数据
//dstart = "2018/01/15 07:30:01";
//dend = "2018/01/15 16:30:00";
List<DataParameter> parameters = new List<DataParameter>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//查出T_AW_MAIN表里的门板件完成数量
//sql = "SELECT count([PID]) as COMPLETE_QTY,MATERIAL_CODE FROM T_AW_PRODUCT where CREATEDATE>'" + dstart + "' and CREATEDATE<'" + dend + "' and WORKCENTER_CODE='BORADPASSY' and exists(select 1 from T_MD_MATERIAL_CLASS mc where mc.MATERIAL_TYPE_CODE=MATERIAL_TYPE and mc.MATERIAL_ATTRIBUTE='2') group by MATERIAL_CODE";
//修改-闫&张 20180227
sql = "SELECT count(1) as COMPLETE_QTY,T_AW_PRODUCT.MATERIAL_CODE FROM T_AW_PRODUCT left join T_MD_MATERIAL M ON T_AW_PRODUCT.MATERIAL_CODE=M.MATERIAL_CODE where T_AW_PRODUCT.CREATEDATE>'" + dstart + "' and T_AW_PRODUCT.CREATEDATE<'" + dend + "' and M.PROJECTCODE='VW371 DP' and exists(select 1 from T_MD_MATERIAL_CLASS mc where mc.MATERIAL_TYPE_CODE=MATERIAL_TYPE and mc.MATERIAL_ATTRIBUTE='2') group by T_AW_PRODUCT.MATERIAL_CODE,M.COLOR,M.HBTYPE order by M.COLOR,M.HBTYPE,T_AW_PRODUCT.MATERIAL_CODE";
var pmList = session.GetList<QTYCompletionRateDModel>(sql, parameters.ToArray());
LogManager.LogHelper.Info(new LogInfo()
{
Tag = "门板件完成数量",
Info = sql
});
//查出T_PP_ORDERPLAN表里的门板件计划数量
//sql = "select sum(QTY) as QTY,MATERIAL_CODE from T_PP_ORDERPLAN where PLAN_DATE>'" + dstart + "' and PLAN_DATE<'" + dend + "' and WORKCENTER_CODE='BORADPASSY' group by MATERIAL_CODE";
//修改-闫&张 20180227
sql = "select sum(QTY) as QTY,T_PP_ORDERPLAN.MATERIAL_CODE from T_PP_ORDERPLAN INNER join T_MD_MATERIAL M ON T_PP_ORDERPLAN.MATERIAL_CODE=M.MATERIAL_CODE where DATEDIFF(DAY,PLAN_DATE,'" + dday + "')=0 and SHIFT_CODE='" + shiftCode + "' and M.PROJECTCODE='VW371 DP' and exists(select 1 from T_MD_MATERIAL_CLASS mc where mc.MATERIAL_TYPE_CODE=M.MATERIAL_TYPE_CODE and mc.MATERIAL_ATTRIBUTE='2') group by T_PP_ORDERPLAN.MATERIAL_CODE,M.COLOR,M.HBTYPE order by M.COLOR,M.HBTYPE,T_PP_ORDERPLAN.MATERIAL_CODE";
var opList = session.GetList<QTYCompletionRateDModel>(sql, parameters.ToArray());
LogManager.LogHelper.Info(new LogInfo()
{
Tag = "门板件计划数量",
Info = sql
});
List<Material> materialList = new MaterialDAL().GetMaterialList(new Material());
//添加完成数量
if (pmList != null && pmList.Count > 0)
{
foreach (var item in pmList)
{
//零件名称
if (!string.IsNullOrEmpty(item.MATERIAL_CODE))
{
var material = materialList.FirstOrDefault(x => x.MATERIAL_CODE == item.MATERIAL_CODE);
if (material != null)
{
item.MATERIAL_NAME = material.MATERIAL_NAME;
item.MATERIAL_SHORT = material.MATERIAL_SHORT;
if (string.IsNullOrEmpty(material.MATERIAL_SHORT))
{
item.MATERIAL_SHORT = material.MATERIAL_CODE;
}
}
}
if (opList != null && opList.Count > 0)
{
var item_ORDERPLAN =
opList.FirstOrDefault(x => x.MATERIAL_CODE == item.MATERIAL_CODE);
//计划数量
if (item_ORDERPLAN != null)
{
item.QTY = item_ORDERPLAN.QTY;
//移除重复的MATERIAL_CODE
opList.Remove(item_ORDERPLAN);
}
}
list.Add(item);
}
}
//添加完成数量list里没有的MATERIAL_CODE
if (opList != null && opList.Count > 0)
{
foreach (var item in opList)
{
//零件名称
if (!string.IsNullOrEmpty(item.MATERIAL_CODE))
{
var material = materialList.FirstOrDefault(x => x.MATERIAL_CODE == item.MATERIAL_CODE);
if (material != null)
{
item.MATERIAL_NAME = material.MATERIAL_NAME;
item.MATERIAL_SHORT = material.MATERIAL_SHORT;
if (string.IsNullOrEmpty(material.MATERIAL_SHORT))
{
item.MATERIAL_SHORT = material.MATERIAL_CODE;
}
}
}
list.Add(item);
}
}
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
public List<QTYCompletionRateDModel> GetAllListNew3(QTYCompletionRateDModel condition)
{
List<QTYCompletionRateDModel> list = new List<QTYCompletionRateDModel>();
string sql = null;
//20180123周晓东-增加班次查询条件
var shiftList = new ShiftDAL().GetAllShift(new Shift__());
DateTime startDate = new DateTime();
DateTime endDate = new DateTime();
var shiftCode = "";
foreach (var shift in shiftList)
{
startDate = Convert.ToDateTime(shift.WORK_START_TIME.ToString("HH:mm:ss"));
endDate = Convert.ToDateTime(shift.WORK_END_TIME.ToString("HH:mm:ss"));
var now = Convert.ToDateTime(DateTime.Now.ToString("HH:mm:ss"));
shiftCode = shift.SHIFT_CODE;
if (DateTime.Compare(now, startDate) > 0 && DateTime.Compare(endDate, now) > 0)
{
break;
}
}
var dstart = startDate.ToString("yyyy-MM-dd HH:mm:ss");
var dend = endDate.ToString("yyyy-MM-dd HH:mm:ss");
var dday = DateTime.Now.ToString("yyyy-MM-dd");
//测试数据
//dstart = "2018/01/23 07:30:01";
//dend = "2018/01/23 16:30:00";
List<DataParameter> parameters = new List<DataParameter>();
try
{
using (IDataSession session = AppDataFactory.CreateMainSession())
{
//查出T_AW_MAIN表里的仪表板件完成数量
//sql = "SELECT count([PID]) as COMPLETE_QTY,MATERIAL_CODE FROM T_AW_MAIN where CREATEDATE>'" + dstart + "' and CREATEDATE<'" + dend + "' and WORKCENTER_CODE='BORAIPASSY' group by MATERIAL_CODE";
//修改-闫&张 20180227
sql = "SELECT count(1) as COMPLETE_QTY,T_AW_PRODUCT.MATERIAL_CODE FROM T_AW_PRODUCT left join T_MD_MATERIAL M ON T_AW_PRODUCT.MATERIAL_CODE=M.MATERIAL_CODE where T_AW_PRODUCT.CREATEDATE>'" + dstart + "' and T_AW_PRODUCT.CREATEDATE<'" + dend + "' and M.PROJECTCODE='VW371 IP' and exists(select 1 from T_MD_MATERIAL_CLASS mc where mc.MATERIAL_TYPE_CODE=MATERIAL_TYPE and mc.MATERIAL_ATTRIBUTE='2') group by T_AW_PRODUCT.MATERIAL_CODE,M.COLOR,M.HBTYPE order by M.COLOR,M.HBTYPE,T_AW_PRODUCT.MATERIAL_CODE";
var pmList = session.GetList<QTYCompletionRateDModel>(sql, parameters.ToArray());
//记录日志
LogManager.LogHelper.Info(new LogInfo()
{
UserName = "仪表板件完成数量",
Info = sql
});
//查出T_PP_ORDERPLAN表里的仪表板计划数量
//sql = "select sum(QTY) as QTY,MATERIAL_CODE from T_PP_ORDERPLAN where PLAN_DATE>'" + dstart + "' and PLAN_DATE<'" + dend + "' and WORKCENTER_CODE='BORAIPASSY' group by MATERIAL_CODE";
//修改-闫&张 20180227
sql = "select sum(QTY) as QTY,T_PP_ORDERPLAN.MATERIAL_CODE from T_PP_ORDERPLAN INNER join T_MD_MATERIAL M ON T_PP_ORDERPLAN.MATERIAL_CODE=M.MATERIAL_CODE where DATEDIFF(DAY,PLAN_DATE,'" + dday + "')=0 and SHIFT_CODE='" + shiftCode + "' and M.PROJECTCODE='VW371 IP' and exists(select 1 from T_MD_MATERIAL_CLASS mc where mc.MATERIAL_TYPE_CODE=M.MATERIAL_TYPE_CODE and mc.MATERIAL_ATTRIBUTE='2') group by T_PP_ORDERPLAN.MATERIAL_CODE,M.COLOR,M.HBTYPE order by M.COLOR,M.HBTYPE,T_PP_ORDERPLAN.MATERIAL_CODE";
var opList = session.GetList<QTYCompletionRateDModel>(sql, parameters.ToArray());
LogManager.LogHelper.Info(new LogInfo()
{
Tag = "仪表板件计划数量",
Info = sql
});
List<Material> materialList = new MaterialDAL().GetMaterialList(new Material());
//添加完成数量
if (pmList != null && pmList.Count > 0)
{
foreach (var item in pmList)
{
//零件名称
if (!string.IsNullOrEmpty(item.MATERIAL_CODE))
{
var material = materialList.FirstOrDefault(x => x.MATERIAL_CODE == item.MATERIAL_CODE);
if (material != null)
{
item.MATERIAL_NAME = material.MATERIAL_NAME;
item.MATERIAL_SHORT = material.MATERIAL_SHORT;
if (string.IsNullOrEmpty(material.MATERIAL_SHORT))
{
item.MATERIAL_SHORT = material.MATERIAL_CODE;
}
}
}
if (opList != null && opList.Count > 0)
{
var item_ORDERPLAN =
opList.FirstOrDefault(x => x.MATERIAL_CODE == item.MATERIAL_CODE);
//计划数量
if (item_ORDERPLAN != null)
{
item.QTY = item_ORDERPLAN.QTY;
//移除重复的MATERIAL_CODE
opList.Remove(item_ORDERPLAN);
}
}
list.Add(item);
}
}
//添加完成数量list里没有的MATERIAL_CODE
if (opList != null && opList.Count > 0)
{
foreach (var item in opList)
{
//零件名称
if (!string.IsNullOrEmpty(item.MATERIAL_CODE))
{
var material = materialList.FirstOrDefault(x => x.MATERIAL_CODE == item.MATERIAL_CODE);
if (material != null)
{
item.MATERIAL_NAME = material.MATERIAL_NAME;
item.MATERIAL_SHORT = material.MATERIAL_SHORT;
if (string.IsNullOrEmpty(material.MATERIAL_SHORT))
{
item.MATERIAL_SHORT = material.MATERIAL_CODE;
}
}
}
list.Add(item);
}
}
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
public List<QTYCompletionRateDModel> GetAllList(QTYCompletionRateDModel condition)
{
List<QTYCompletionRateDModel> list = new List<QTYCompletionRateDModel>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
var workcenter = "";
var sqltemp1 = "";
var sqltemp2 = "";
if (string.IsNullOrEmpty(condition.WORKCENTER_CODE))
{
return list;
}
if (condition.WORKCENTER_CODE == "0")
{
workcenter = "INJECTION_AREA";
sqltemp1 = "SELECT count(1) as COMPLETE_QTY,MATERIAL_CODE FROM T_AW_MAINOPERATION M where WORKCENTER_CODE='INJECTION_AREA' ";
sqltemp2 = "select sum(QTY) as QTY,MATERIAL_CODE from T_PP_ORDERPLAN M where WORKCENTER_CODE='INJECTION_AREA' ";
}
else if (condition.WORKCENTER_CODE == "1")
{
workcenter = "VW371_DPASSYLINE";
sqltemp1 = "SELECT count(1) as COMPLETE_QTY ,M.MATERIAL_CODE FROM T_AW_PRODUCT M left join T_MD_MATERIAL TM ON M.MATERIAL_CODE=TM.MATERIAL_CODE where M.WORKCENTER_CODE='VW371_DPASSYLINE' and exists(select 1 from T_MD_MATERIAL_CLASS mc where mc.MATERIAL_TYPE_CODE=MATERIAL_TYPE and mc.MATERIAL_ATTRIBUTE='2') ";
sqltemp2 = "select sum(QTY) as QTY,M.MATERIAL_CODE from T_PP_ORDERPLAN M INNER join T_MD_MATERIAL TM ON M.MATERIAL_CODE=TM.MATERIAL_CODE where M.WORKCENTER_CODE='VW371_DPASSYLINE' and exists(select 1 from T_MD_MATERIAL_CLASS mc where mc.MATERIAL_TYPE_CODE=TM.MATERIAL_TYPE_CODE and mc.MATERIAL_ATTRIBUTE='2')";
}
else if (condition.WORKCENTER_CODE == "2")
{
workcenter = "BORAIPASSY";
sqltemp1 = "SELECT count(1) as COMPLETE_QTY ,M.MATERIAL_CODE FROM T_AW_PRODUCT M left join T_MD_MATERIAL TM ON M.MATERIAL_CODE=TM.MATERIAL_CODE where TM.PROJECTCODE='VW331/5CN IP' and exists(select 1 from T_MD_MATERIAL_CLASS mc where mc.MATERIAL_TYPE_CODE=MATERIAL_TYPE and mc.MATERIAL_ATTRIBUTE='2') ";
sqltemp2 = "select sum(QTY) as QTY,M.MATERIAL_CODE from T_PP_ORDERPLAN M INNER join T_MD_MATERIAL TM ON M.MATERIAL_CODE=TM.MATERIAL_CODE where TM.PROJECTCODE='VW331/5CN IP' and exists(select 1 from T_MD_MATERIAL_CLASS mc where mc.MATERIAL_TYPE_CODE=TM.MATERIAL_TYPE_CODE and mc.MATERIAL_ATTRIBUTE='2') ";
}
else
{
workcenter = condition.WORKCENTER_CODE;
sqltemp1 = "SELECT count(1) as COMPLETE_QTY ,M.MATERIAL_CODE FROM T_AW_PRODUCT M left join T_MD_MATERIAL TM ON M.MATERIAL_CODE=TM.MATERIAL_CODE where M.WORKCENTER_CODE='" + condition.WORKCENTER_CODE + "' and exists(select 1 from T_MD_MATERIAL_CLASS mc where mc.MATERIAL_TYPE_CODE=MATERIAL_TYPE and mc.MATERIAL_ATTRIBUTE='2') ";
sqltemp2 = "select sum(QTY) as QTY,M.MATERIAL_CODE from T_PP_ORDERPLAN M INNER join T_MD_MATERIAL TM ON M.MATERIAL_CODE=TM.MATERIAL_CODE where M.WORKCENTER_CODE='" + condition.WORKCENTER_CODE + "' and exists(select 1 from T_MD_MATERIAL_CLASS mc where mc.MATERIAL_TYPE_CODE=TM.MATERIAL_TYPE_CODE and mc.MATERIAL_ATTRIBUTE='2') ";
}
if (string.IsNullOrEmpty(condition.START_DATE) == false && string.IsNullOrEmpty(condition.END_DATE) == false)
{
var startDate = condition.START_DATE +" 00:00:00";
var endDate = condition.END_DATE + " 23:59:59";
sqltemp1 += " and m.CREATEDATE >= '" + startDate + "' and m.CREATEDATE <= '" + endDate + "' group by M.MATERIAL_CODE ";
sqltemp2 += " and m.PLAN_DATE >= '" + startDate + "' and m.PLAN_DATE <= '" + endDate + "' group by M.MATERIAL_CODE ";
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = sqltemp1;
var pmList = session.GetList<QTYCompletionRateDModel>(sql, parameters.ToArray());
sql = sqltemp2;
var opList = session.GetList<QTYCompletionRateDModel>(sql, parameters.ToArray());
List<Material> materialList = new MaterialDAL().GetMaterialList(new Material());
//添加完成数量
if (pmList != null && pmList.Count > 0)
{
foreach (var item in pmList)
{
//零件名称
if (!string.IsNullOrEmpty(item.MATERIAL_CODE))
{
var material = materialList.FirstOrDefault(x => x.MATERIAL_CODE == item.MATERIAL_CODE);
if (material != null)
{
item.MATERIAL_NAME = material.MATERIAL_NAME;
item.MATERIAL_SHORT = material.MATERIAL_SHORT;
if (string.IsNullOrEmpty(material.MATERIAL_SHORT))
{
item.MATERIAL_SHORT = material.MATERIAL_CODE;
}
}
}
if (opList != null && opList.Count > 0)
{
var item_ORDERPLAN =
opList.FirstOrDefault(x => x.MATERIAL_CODE == item.MATERIAL_CODE);
//计划数量
if (item_ORDERPLAN != null)
{
item.QTY = item_ORDERPLAN.QTY;
//移除重复的MATERIAL_CODE
opList.Remove(item_ORDERPLAN);
}
}
list.Add(item);
}
}
//添加完成数量list里没有的MATERIAL_CODE
if (opList != null && opList.Count > 0)
{
foreach (var item in opList)
{
//零件名称
if (!string.IsNullOrEmpty(item.MATERIAL_CODE))
{
var material = materialList.FirstOrDefault(x => x.MATERIAL_CODE == item.MATERIAL_CODE);
if (material != null)
{
item.MATERIAL_NAME = material.MATERIAL_NAME;
item.MATERIAL_SHORT = material.MATERIAL_SHORT;
if (string.IsNullOrEmpty(material.MATERIAL_SHORT))
{
item.MATERIAL_SHORT = material.MATERIAL_CODE;
}
}
}
list.Add(item);
}
}
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql(QTYCompletionRateDModel condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder sqlBuilder2 = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
string group = " group by day(tppo.PLAN_DATE),year(tppo.PLAN_DATE),month(tppo.PLAN_DATE) order by year(tppo.PLAN_DATE),month(tppo.PLAN_DATE) ";
//构成查询语句
if (condition.TYPE_COUNT=="MONTH")
{
//月统计
sqlBuilder.AppendLine("select year(tppo.PLAN_DATE) tyear,month(tppo.PLAN_DATE) tday,sum(COMPLETE_QTY) COMPLETE_QTY,sum(QTY) QTY from T_PP_ORDERPLAN tppo ");
group = " group by year(tppo.PLAN_DATE),month(tppo.PLAN_DATE) order by year(tppo.PLAN_DATE),month(tppo.PLAN_DATE)";
}
else if (condition.TYPE_COUNT=="WEEK")
{
//周统计
sqlBuilder.AppendLine("select year(tppo.PLAN_DATE) tyear,DateName(week,DATEADD(DAY,-1,tppo.PLAN_DATE)) tday,sum(COMPLETE_QTY) COMPLETE_QTY,sum(QTY) QTY from T_PP_ORDERPLAN tppo ");
group = " group by year(tppo.PLAN_DATE),DateName(week,DATEADD(DAY,-1,tppo.PLAN_DATE)) order by year(tppo.PLAN_DATE),DateName(week,DATEADD(DAY,-1,tppo.PLAN_DATE))";
}
else
{
//日统计
sqlBuilder.AppendLine("select year(tppo.PLAN_DATE) tyear,month(tppo.PLAN_DATE) tmonth, day(tppo.PLAN_DATE) tday,sum(COMPLETE_QTY) COMPLETE_QTY,sum(QTY) QTY from T_PP_ORDERPLAN tppo ");
}
if (string.IsNullOrEmpty(condition.START_DATE) == false)
{
whereBuilder.Append(" AND tppo.PLAN_DATE >= @START_DATE ");
parameters.Add(new DataParameter { ParameterName = "START_DATE", DataType = DbType.DateTime, Value = condition.START_DATE });
}
if (string.IsNullOrEmpty(condition.END_DATE) == false)
{
whereBuilder.Append(" AND tppo.PLAN_DATE <= @END_DATE ");
parameters.Add(new DataParameter { ParameterName = "END_DATE", DataType = DbType.DateTime, Value = condition.END_DATE });
}
if (string.IsNullOrEmpty(condition.MATERIAL_CODE) == false)
{
whereBuilder.Append(" AND tppo.MATERIAL_CODE = @MATERIAL_CODE ");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
}
//2018/1/16闫永刚
//暂时增加仪表板查询
whereBuilder.Append(" AND tppo.workcenter_code='BORAIPASSY'");
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
sqlBuilder.Append(group);
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
private string GetQuerySqlNew(QTYCompletionRateDModel condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder sqlBuilder2 = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
string group = " group by day(tppo.PLAN_DATE),year(tppo.PLAN_DATE),month(tppo.PLAN_DATE) order by year(tppo.PLAN_DATE),month(tppo.PLAN_DATE) ";
//构成查询语句
if (condition.TYPE_COUNT == "MONTH")
{
//月统计
sqlBuilder.AppendLine("select year(tppo.PLAN_DATE) tyear,month(tppo.PLAN_DATE) tday,sum(COMPLETE_QTY) COMPLETE_QTY,sum(QTY) QTY from T_PP_ORDERPLAN tppo ");
group = " group by year(tppo.PLAN_DATE),month(tppo.PLAN_DATE) order by year(tppo.PLAN_DATE),month(tppo.PLAN_DATE)";
}
else if (condition.TYPE_COUNT == "WEEK")
{
//周统计
sqlBuilder.AppendLine("select year(tppo.PLAN_DATE) tyear,DateName(week,DATEADD(DAY,-1,tppo.PLAN_DATE)) tday,sum(COMPLETE_QTY) COMPLETE_QTY,sum(QTY) QTY from T_PP_ORDERPLAN tppo ");
group = " group by year(tppo.PLAN_DATE),DateName(week,DATEADD(DAY,-1,tppo.PLAN_DATE)) order by year(tppo.PLAN_DATE),DateName(week,DATEADD(DAY,-1,tppo.PLAN_DATE))";
}
else
{
//日统计
sqlBuilder.AppendLine("select year(tppo.PLAN_DATE) tyear,month(tppo.PLAN_DATE) tmonth, day(tppo.PLAN_DATE) tday,sum(COMPLETE_QTY) COMPLETE_QTY,sum(QTY) QTY from T_PP_ORDERPLAN tppo ");
}
if (string.IsNullOrEmpty(condition.START_DATE) == false)
{
whereBuilder.Append(" AND tppo.PLAN_DATE >= @START_DATE ");
parameters.Add(new DataParameter { ParameterName = "START_DATE", DataType = DbType.DateTime, Value = condition.START_DATE });
}
if (string.IsNullOrEmpty(condition.END_DATE) == false)
{
whereBuilder.Append(" AND tppo.PLAN_DATE <= @END_DATE ");
parameters.Add(new DataParameter { ParameterName = "END_DATE", DataType = DbType.DateTime, Value = condition.END_DATE });
}
if (string.IsNullOrEmpty(condition.MATERIAL_CODE) == false)
{
whereBuilder.Append(" AND tppo.MATERIAL_CODE = @MATERIAL_CODE ");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
}
//2018/1/16闫永刚
//暂时增加仪表板查询
whereBuilder.Append(" AND tppo.workcenter_code='BORAIPASSY'");
//20180123周晓东-增加班次查询条件
var shiftList = new ShiftDAL().GetAllShift(new Shift__());
//var shiftCode = "";
foreach (var shift in shiftList)
{
var wst = Convert.ToDateTime(shift.WORK_START_TIME.ToString("HH:mm:ss"));
var wet = Convert.ToDateTime(shift.WORK_END_TIME.ToString("HH:mm:ss"));
var now = Convert.ToDateTime(DateTime.Now.ToString("HH:mm:ss"));
if (DateTime.Compare(now, wst)>0 && DateTime.Compare(wet, now)>0)
{
whereBuilder.Append(" AND tppo.SHIFT_CODE='" + shift.SHIFT_CODE + "'");
break;
}
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
sqlBuilder.Append(group);
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取导出的数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(QTYCompletionRateDModel model)
{
var workcenter = "注塑";
if (model.WORKCENTER_CODE == "1")
{
workcenter = "门板";
}
else if (model.WORKCENTER_CODE == "2")
{
workcenter = "仪表板";
}
var list = GetAllList(model);
foreach (var lq in list)
{
lq.WORKCENTER_NAME = workcenter;
}
return CopyToDataTable(list);
//DataTable dt = null;
//string sql = null;
//List<DataParameter> parameters = new List<DataParameter>();
//try
//{
// //构成查询语句
// sql = this.GetQuerySql(model, ref parameters);
// using (IDataSession session = AppDataFactory.CreateMainSession())
// {
// dt = session.GetTable(sql, parameters.ToArray());
// dt.TableName = "ProductInExp";
// }
// return dt;
//}
//catch (Exception ex)
//{
// LogManager.LogHelper.Error(new LogInfo()
// {
// ErrorInfo = ex,
// Tag = ex.StackTrace,
// Info = "导出获取数据错误!"
// });
// throw ex;
//}
}
//把list转换成DataTable
public static DataTable CopyToDataTable<T>(IEnumerable<T> array)
{
var ret = new DataTable();
foreach (PropertyDescriptor dp in TypeDescriptor.GetProperties(typeof(T)))
ret.Columns.Add(dp.Name);
foreach (T item in array)
{
var Row = ret.NewRow();
foreach (PropertyDescriptor dp in TypeDescriptor.GetProperties(typeof(T)))
Row[dp.Name] = dp.GetValue(item);
ret.Rows.Add(Row);
}
return ret;
}
#endregion
}
}