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

178 lines
7.3 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
using QMAPP.FJC.Entity.Operation;
using QMFrameWork.Log;
using System.Data;
using QMAPP.FJC.Entity;
namespace QMAPP.FJC.DAL.WIPManage
{
/// <summary>
/// 模块编号:M7-5
/// 作 用:滞留品查询数据层
/// 作 者:王丹丹
/// 编写日期:2015年06月26日
///</summary>
public class DetentionDAL
{
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(Main condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetMainSql(condition, ref parameters);
//分页关键字段及排序
page.KeyName = "PID";
page.SortExpression = "UPDATEDATE DESC";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<Main>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "滞留品查询数据层-获取列表!"
});
throw ex;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetMainSql(Main condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT M.PID ");
sqlBuilder.AppendLine(" ,M.MAINCODE ");
sqlBuilder.AppendLine(" ,M.SKID ");
sqlBuilder.AppendLine(" ,M.SKELETONCODE ");
sqlBuilder.AppendLine(" ,M.EID ");
sqlBuilder.AppendLine(" ,M.EPIDERMISCODE ");
sqlBuilder.AppendLine(" ,M.HB ");
sqlBuilder.AppendLine(" ,M.COLOR ");
sqlBuilder.AppendLine(" ,M.MACHINECODDE ");
sqlBuilder.AppendLine(" ,M.PROCESSSTATE ");
sqlBuilder.AppendLine(" ,M.STATUS ");
sqlBuilder.AppendLine(" ,M.CURRENTPROCESS ");
sqlBuilder.AppendLine(" ,M.COMPLETEFLAG ");
sqlBuilder.AppendLine(" ,M.PRODUCELINE ");
sqlBuilder.AppendLine(" ,M.PRODUCESHIFTNAME ");
sqlBuilder.AppendLine(" ,M.PRODUCESHIFTTCODE ");
sqlBuilder.AppendLine(" ,M.OUTFLAG ");
sqlBuilder.AppendLine(" ,M.SPID ");
sqlBuilder.AppendLine(" ,M.SENDCODE ");
sqlBuilder.AppendLine(" ,M.COMPLETETIME ");
sqlBuilder.AppendLine(" ,M.CREATEUSER ");
sqlBuilder.AppendLine(" ,M.CREATEDATE ");
sqlBuilder.AppendLine(" ,M.UPDATEUSER ");
sqlBuilder.AppendLine(" ,M.UPDATEDATE ");
sqlBuilder.AppendLine(" ,C.USERNAME AS CREATEUSERNAME ");
sqlBuilder.AppendLine(" ,U.USERNAME AS UPDATEUSERNAME ");
sqlBuilder.AppendLine(" ,DATEDIFF(HH,M.UPDATEDATE,GETDATE()) AS DetentionTimeCount ");
sqlBuilder.AppendLine(" FROM T_AW_MAIN M ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER C ON C.USERID=M.CREATEUSER ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER U ON U.USERID=M.UPDATEUSER ");
sqlBuilder.AppendLine(" WHERE ");
sqlBuilder.AppendLine(" M.OUTFLAG=" + EnumGeter.OUTFLAG.INWAREHOUSE.GetHashCode().ToString());
sqlBuilder.AppendLine(" AND M.CURRENTPROCESS=" + EnumGeter.ProcessType.zongchengzhuangpei.GetHashCode().ToString());
sqlBuilder.AppendLine(" AND M.STATUS=" + EnumGeter.PRODUCTSTAUTS.QUALIFIED.GetHashCode().ToString());
//查询条件
//表皮条码
if (string.IsNullOrEmpty(condition.EPIDERMISCODE) == false)
{
sqlBuilder.Append(" AND M.EPIDERMISCODE LIKE '%'+" + "@EPIDERMISCODE" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "EPIDERMISCODE", DataType = DbType.String, Value = condition.EPIDERMISCODE });
}
//滞留时长
if (string.IsNullOrEmpty(condition.DetentionTimeCount) == false)
{
sqlBuilder.Append(" AND DATEDIFF(HH,M.UPDATEDATE,GETDATE()) <=@DetentionTimeCount");
parameters.Add(new DataParameter { ParameterName = "DetentionTimeCount", DataType = DbType.String, Value = condition.DetentionTimeCount });
}
//高低配
if (string.IsNullOrEmpty(condition.HB) == false)
{
sqlBuilder.Append(" AND M.HB =@HB");
parameters.Add(new DataParameter { ParameterName = "HB", DataType = DbType.String, Value = condition.HB });
}
//颜色
if (string.IsNullOrEmpty(condition.COLOR) == false)
{
sqlBuilder.Append(" AND M.COLOR =@COLOR");
parameters.Add(new DataParameter { ParameterName = "COLOR", DataType = DbType.String, Value = condition.COLOR });
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取导出的数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(Main model)
{
DataTable dt = null;
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
//构成查询语句
sql = this.GetMainSql(model, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
dt = session.GetTable(sql, parameters.ToArray());
dt.TableName = "T_AW_MAIN";
}
return dt;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "滞留品查询数据层-获取导出的数据!"
});
throw ex;
}
}
#endregion
}
}