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

329 lines
13 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
using QMAPP.MESReport.Entity.LineQTY;
using QMAPP.DAL;
using System.Data;
using QMAPP.MESReport.Entity.Tables;
using System.ComponentModel;
namespace QMAPP.MESReport.DAL.LineQTY
{
public class ShipmentCountDAL : BaseDAL
{
#region 获取门板信息
/// <summary>
/// 生产发运统计
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<ShipmentCountConditionModel> GetDPList(ShipmentCountConditionModel condition)
{
List<ShipmentCountConditionModel> list = new List<ShipmentCountConditionModel>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetDPQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<ShipmentCountConditionModel>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetDPQuerySql(ShipmentCountConditionModel condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder sqlBuilder2 = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
string groupexp = "CONVERT(VARCHAR(20),SCANDATE,23)"; ;
switch (condition.TYPE_COUNT)
{
case "DAY":
{
break;
}
case "MONTH":
{
groupexp = "CAST(YEAR(SCANDATE) AS VARCHAR)+'年'+CAST(DATEPART(M,SCANDATE) AS VARCHAR)+'月'";
break;
}
case "WEEK":
{
groupexp = "CAST(YEAR(SCANDATE) AS VARCHAR)+'年'+CAST(DATEPART(WK,SCANDATE) AS VARCHAR)+'th周'";
break;
}
}
sqlBuilder.AppendLine(" SELECT MIN(QTY) AS QTY,HBTYPE as MATERIAL_NAME,COLOR as MATERIAL_CODE,TDAY");
sqlBuilder.AppendLine("FROM (");
sqlBuilder.AppendLine("select count(1) as QTY");
sqlBuilder.AppendFormat(" ,{0} AS TDAY ", groupexp);
sqlBuilder.AppendLine(",M.HBTYPE,M.COLOR,M.MATERIAL_CODE");
sqlBuilder.AppendLine("from T_PP_FISORDERSENDDETAIL F ");
sqlBuilder.AppendLine("LEFT JOIN T_PP_PASCARDDETAILS T ");
sqlBuilder.AppendLine("ON T.FISDETAILID=F.FIS_PID ");
sqlBuilder.AppendLine("left join T_MD_MATERIAL m ");
sqlBuilder.AppendLine("on m.MATERIAL_CODE=f.MATERIAL_CODE ");
sqlBuilder.AppendLine("WHERE 1=1 ");
sqlBuilder.AppendLine("AND HBTYPE IS NOT NULL");
sqlBuilder.AppendLine("AND SCANDATE IS NOT NULL");
if (string.IsNullOrEmpty(condition.WORKCENTER_CODE) == false)
{
List<string> strlist = condition.WORKCENTER_CODE.Split('/').ToList<string>();
sqlBuilder.AppendLine("and f.WORKCENTER_CODE IN (");
for (int i = 0; i < strlist.Count; i++)
{
sqlBuilder.AppendFormat("'{0}'", strlist[i]);
if ((i + 1) != strlist.Count)
{
sqlBuilder.AppendLine(",");
}
}
sqlBuilder.AppendLine(")");
}
if (string.IsNullOrEmpty(condition.START_DATE) == false)
{
sqlBuilder.AppendFormat("and t.SCANDATE >'{0}' ", condition.START_DATE);
parameters.Add(new DataParameter { ParameterName = "SCANDATE", DataType = DbType.DateTime, Value = condition.START_DATE });
}
if (string.IsNullOrEmpty(condition.END_DATE) == false)
{
sqlBuilder.AppendFormat("and t.SCANDATE<'{0}'", Convert.ToDateTime(condition.END_DATE).AddDays(1).ToShortDateString());
}
sqlBuilder.AppendFormat(" GROUP BY {0},M.HBTYPE,M.COLOR,M.MATERIAL_CODE)TEMP1 ", groupexp);
sqlBuilder.AppendLine(" GROUP BY HBTYPE,COLOR,TDAY ");
sqlBuilder.AppendLine(" ORDER BY TDAY ASC ");
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取仪表板信息
/// <summary>
/// 生产发运统计
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public List<ShipmentCountConditionModel> GetIPList(ShipmentCountConditionModel condition)
{
List<ShipmentCountConditionModel> list = new List<ShipmentCountConditionModel>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetIPQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<ShipmentCountConditionModel>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetIPQuerySql(ShipmentCountConditionModel condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder sqlBuilder2 = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
string groupexp = "CONVERT(VARCHAR(20),SCANDATE,23)"; ;
switch (condition.TYPE_COUNT)
{
case "DAY":
{
break;
}
case "MONTH":
{
groupexp = "CAST(YEAR(SCANDATE) AS VARCHAR)+'年'+CAST(DATEPART(M,SCANDATE) AS VARCHAR)+'月'";
break;
}
case "WEEK":
{
groupexp = "CAST(YEAR(SCANDATE) AS VARCHAR)+'年'+CAST(DATEPART(WK,SCANDATE) AS VARCHAR)+'th周'";
break;
}
}
sqlBuilder.AppendLine("select count(1) as QTY");
sqlBuilder.AppendFormat(" ,{0} AS TDAY ", groupexp);
sqlBuilder.AppendLine(",M.MATERIAL_SHORT as MATERIAL_NAME,'' AS MATERIAL_CODE");
sqlBuilder.AppendLine("from T_PP_FISORDERSENDDETAIL F ");
sqlBuilder.AppendLine("LEFT JOIN T_PP_PASCARDDETAILS T ");
sqlBuilder.AppendLine("ON T.FISDETAILID=F.FIS_PID ");
sqlBuilder.AppendLine("left join T_MD_MATERIAL m ");
sqlBuilder.AppendLine("on m.MATERIAL_CODE=f.MATERIAL_CODE ");
sqlBuilder.AppendLine("WHERE 1=1 ");
sqlBuilder.AppendLine("AND HBTYPE IS NOT NULL");
sqlBuilder.AppendLine("AND SCANDATE IS NOT NULL");
if (string.IsNullOrEmpty(condition.WORKCENTER_CODE) == false)
{
List<string> strlist = condition.WORKCENTER_CODE.Split('/').ToList<string>();
sqlBuilder.AppendLine("and f.WORKCENTER_CODE IN (");
for (int i = 0; i < strlist.Count; i++)
{
sqlBuilder.AppendFormat("'{0}'", strlist[i]);
if ((i + 1) != strlist.Count)
{
sqlBuilder.AppendLine(",");
}
}
sqlBuilder.AppendLine(")");
}
if (string.IsNullOrEmpty(condition.START_DATE) == false)
{
sqlBuilder.AppendFormat("and t.SCANDATE >'{0}' ", condition.START_DATE);
parameters.Add(new DataParameter { ParameterName = "SCANDATE", DataType = DbType.DateTime, Value = condition.START_DATE });
}
if (string.IsNullOrEmpty(condition.END_DATE) == false)
{
sqlBuilder.AppendFormat("and t.SCANDATE<'{0}'", Convert.ToDateTime(condition.END_DATE).AddDays(1).ToShortDateString());
}
sqlBuilder.AppendFormat(" GROUP BY {0},M.MATERIAL_SHORT,M.MATERIAL_CODE ", groupexp);
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取物料产品列表
/// <summary>
/// 获取物料产品列表
/// </summary>
/// <param name="condition"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public List<ShipmentCountConditionModel> GetWList()
{
List<ShipmentCountConditionModel> list = new List<ShipmentCountConditionModel>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = @"SELECT MATERIAL_CODE,MATERIAL_NAME
FROM T_MD_MATERIAL M
LEFT JOIN T_MD_MATERIAL_CLASS MC
ON M.MATERIAL_TYPE_CODE=MC.MATERIAL_TYPE_CODE
WHERE MC.MATERIAL_ATTRIBUTE='2' and PROJECTCODE='VW331 DP'
ORDER BY M.MATERIAL_NAME";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<ShipmentCountConditionModel>(sql, parameters.ToArray()).ToList();
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取导出的数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(ShipmentCountConditionModel model)
{
List<ShipmentCountConditionModel> list = new List<ShipmentCountConditionModel>();
//门板
if (model.WORKCENTER_CODE == "DPLFY/DPRFY")
{
list = GetDPList(model);
}
//仪表板
else if (model.WORKCENTER_CODE.StartsWith("IPFY"))
{
list = GetIPList(model);
foreach (ShipmentCountConditionModel item in list)
{
item.MaterialValue = item.MATERIAL_NAME;
}
}
return CopyToDataTable(list);
}
/// <summary>
/// 把list转换成DataTable
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="array"></param>
/// <returns></returns>
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
}
}