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

221 lines
8.8 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;
namespace QMAPP.MESReport.DAL.LineQTY
{
/// <summary>
/// 生产每日工序设备情况统计-数据层对象
/// 创建人:李炳海
/// 创建时间:2017.09.22
/// </summary>
public class LineDWQTYCountDAL:BaseDAL
{
/// <summary>
/// 获取各工序设备日生产情况
/// </summary>
public DataPage GetDayEquQTYByWorkCell(LineQtyCondition condition, DataPage page)
{
return page;
}
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(LineDayQTYCount condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
//分页关键字段及排序
page.KeyName = "EQUIPMENT_CODE";
if (string.IsNullOrEmpty(page.SortExpression))
{
page.SortExpression = "STATIS_DATE DESC , CREATEDATE";
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<LineDayQTYCount>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <returns>全部集合</returns>
public List<LineDayQTYCount> GetAllList(LineDayQTYCount condition)
{
List<LineDayQTYCount> list = new List<LineDayQTYCount>();
List<LineDayQTYCount> listNew = new List<LineDayQTYCount>();
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
list = session.GetList<LineDayQTYCount>(sql, parameters.ToArray()).ToList();
listNew.AddRange(list);
}
return list;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql(LineDayQTYCount condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine("select convert(nvarchar(20),(OK_QTY*100/QTY))+'%' as OK_QTY_LV");
sqlBuilder.AppendLine(@",tsa.[PID]
,tsa.[WORKCENTER_CODE]
,tsa.[FACTORY_CODE]
,tsa.[EQUIPMENT_CODE]
,tsa.[WORKCELL_CODE]
,tsa.[MATRIAL_CODE] AS [MATERIAL_CODE]
2 years ago
,ma.MATERIAL_NAME
,tsa.[SHIFT_CODE]
,CONVERT(VARCHAR(10),tsa.[STATIS_DATE],120) as STATIS_DATE
,tsa.[QTY]
,tsa.[OK_QTY]
,tsa.[NOK_QTY]
,tsa.[REWORK_QTY]
,tsa.[CREATEDATE]
,tsa.[UPDATEDATE]");
sqlBuilder.AppendLine(",eq.MACHINENAME AS EQUIPMENT_NAME");
sqlBuilder.AppendLine(",tmw.WORKCELL_NAME ");
sqlBuilder.AppendLine("from T_SA_WORKCELLQTYCOUNT tsa ");
sqlBuilder.AppendLine("inner join T_BD_MACHINEINFO eq ");
sqlBuilder.AppendLine("on eq.MACHINECODDE =tsa.EQUIPMENT_CODE ");
sqlBuilder.AppendLine("inner join T_MD_WORKCELL tmw ");
sqlBuilder.AppendLine("on tmw.WORKCELL_CODE =tsa.WORKCELL_CODE ");
sqlBuilder.AppendLine("inner join T_MD_PROCESS_ROUTE_WORKCELL_SEQ tmprw ");
sqlBuilder.AppendLine("on tmprw.WORKCELL_CODE =tsa.WORKCELL_CODE ");
2 years ago
sqlBuilder.AppendLine("inner join T_MD_MATERIAL ma ");
sqlBuilder.AppendLine("on ma.MATERIAL_CODE =tsa.MATRIAL_CODE ");
if (string.IsNullOrEmpty(condition.START_DATE) == false)
{
whereBuilder.Append(" AND STATIS_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 STATIS_DATE <= @END_DATE ");
parameters.Add(new DataParameter { ParameterName = "END_DATE", DataType = DbType.DateTime, Value = condition.END_DATE });
}
if (string.IsNullOrEmpty(condition.WORKCELL_CODE) == false)
{
whereBuilder.Append(" AND tsa.WORKCELL_CODE = @WORKCELL_CODE ");
parameters.Add(new DataParameter { ParameterName = "WORKCELL_CODE", DataType = DbType.String, Value = condition.WORKCELL_CODE });
}
if (string.IsNullOrEmpty(condition.EQUIPMENT_NAME) == false)
{
whereBuilder.Append(" AND tsa.EQUIPMENT_CODE = @EQUIPMENT_CODE ");
parameters.Add(new DataParameter { ParameterName = "EQUIPMENT_CODE", DataType = DbType.String, Value = condition.EQUIPMENT_NAME });
}
if (string.IsNullOrEmpty(condition.WORKCENTER_CODE) == false)
{
whereBuilder.Append(" AND tsa.WORKCENTER_CODE = @WORKCENTER_CODE ");
parameters.Add(new DataParameter { ParameterName = "WORKCENTER_CODE", DataType = DbType.String, Value = condition.WORKCENTER_CODE });
}
if (string.IsNullOrEmpty(condition.ROUTE_CODE) == false)
{
whereBuilder.Append(" AND ROUTE_CODE = @ROUTE_CODE ");
parameters.Add(new DataParameter { ParameterName = "ROUTE_CODE", DataType = DbType.String, Value = condition.ROUTE_CODE });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
//sqlBuilder.Append(" order by STATIS_DATE desc, CREATEDATE ");
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
public DataTable GetExportData(LineDayQTYCount condition)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
DataTable dt = null;
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
//构成查询语句
2 years ago
sqlBuilder.Append("select tsa.*,ma.MATERIAL_NAME from T_SA_WORKCELLQTYCOUNT as tsa inner join T_MD_MATERIAL ma on ma.MATERIAL_CODE = tsa.MATRIAL_CODE ");
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(whereBuilder.ToString());
}
2 years ago
sqlBuilder.Append(" ORDER BY tsa.STATIS_DATE DESC ");
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = this.ChangeSqlByDB(sqlBuilder.ToString(), session);
dt = session.GetTable(sql, parameters.ToArray());
dt.TableName = "T_SA_WORKCELLQTYCOUNT";
}
return dt;
}
catch (Exception ex)
{
throw;
}
}
}
}