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

162 lines
6.2 KiB

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using QMAPP.FJC.Entity.Injection;
using QMAPP.FJC.Entity.ProduceManage;
using QMFrameWork.Data;
using QMFrameWork.Log;
using QMAPP.FJC.Entity.FeedInManage;
namespace QMAPP.FJC.DAL.FeedInManage
{
/// <summary>
/// 模块编号:M4-3
/// 作 用:不合格品信息查询
/// 作 者:张敬贺
/// 编写日期:2015年06月15日
///</summary>
public class UnQualityDAL
{
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(Epidermis condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetQuerySql(condition, ref parameters);
//分页关键字段及排序
page.KeyName = "PID";
page.SortExpression = "UPDATEDATE DESC";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<UnQuality>(sql, parameters.ToArray(), page);
List<UnQuality> list = session.GetList<UnQuality>(sql, parameters.ToArray()).ToList<UnQuality>();
}
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 GetQuerySql(Epidermis condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT ");
sqlBuilder.AppendLine(" SUM((T.CAPACITY-T.USINGCOUNT)) AS UNUSED , ");
sqlBuilder.AppendLine(" T.MATERIAL_CODE, ");
sqlBuilder.AppendLine(" M.MATERIAL_NAME, ");
sqlBuilder.AppendLine(" M.MATERIAL_TYPE_CODE, ");
sqlBuilder.AppendLine(" c.MATERIAL_TYPE_NAME ");
sqlBuilder.AppendLine(" FROM T_AW_PRODUCT AS T ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL M on M.MATERIAL_CODE=T.MATERIAL_CODE ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL_CLASS c on c.MATERIAL_TYPE_CODE=M.MATERIAL_TYPE_CODE ");
whereBuilder.Append(" AND T.USINGSTATE='0' AND T.OUTFLAG='0' AND T.STATUS='1'");
#region 查询条件
if (string.IsNullOrEmpty(condition.PRODUCTTYPE) == false)
{
whereBuilder.Append(" AND UN.PRODUCTTYPE = @PRODUCTTYPE");
parameters.Add(new DataParameter { ParameterName = "PRODUCTTYPE", DataType = DbType.String, Value = condition.PRODUCTTYPE });
}
if (string.IsNullOrEmpty(condition.PRODUCTCODE) == false)
{
whereBuilder.Append(" AND UN.PRODUCTCODE LIKE @PRODUCTCODE");
parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = condition.PRODUCTCODE });
}
if (condition.STARTCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND UN.CREATEDATE >= @STARTCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "STARTCREATEDATE", Value = condition.STARTCREATEDATE.Date.ToString("yyyy-MM-dd HH:mm:ss") });
}
if (condition.ENDCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND UN.CREATEDATE < @ENDCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "ENDCREATEDATE", Value = condition.ENDCREATEDATE.Date.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss") });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
#endregion
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取导出的数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(Epidermis model)
{
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 = "UnQualityExp";
}
return dt;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "不合格品信息导出获取数据错误!"
});
throw ex;
}
}
#endregion
}
}