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.
144 lines
5.2 KiB
144 lines
5.2 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using QMAPP.FJC.Entity.Operation;
|
|
using QMFrameWork.Data;
|
|
using QMFrameWork.Log;
|
|
using System.Data;
|
|
|
|
namespace QMAPP.FJC.DAL.Basic
|
|
{
|
|
/// <summary>
|
|
/// 不合格品数量查询
|
|
/// </summary>
|
|
public class UnQualityProductDAL
|
|
{
|
|
#region 获取列表
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <param name="condition">条件</param>
|
|
/// <param name="page">数据页</param>
|
|
/// <returns>数据页</returns>
|
|
public DataPage GetList(Product condition, DataPage page)
|
|
{
|
|
string sql = null;
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql = this.GetQuerySql(condition, ref parameters);
|
|
//分页关键字段及排序
|
|
page.KeyName = "PRODUCTTYPE";
|
|
if (string.IsNullOrEmpty(page.SortExpression))
|
|
{
|
|
page.SortExpression = "PRODUCTTYPE DESC";
|
|
}
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
page = session.GetDataPage<Product>(sql, parameters.ToArray(), page);
|
|
|
|
List<Product> list = session.GetList<Product>(sql, parameters.ToArray()).ToList<Product>();
|
|
}
|
|
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(Product condition, ref List<DataParameter> parameters)
|
|
{
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
StringBuilder whereBuilder = new StringBuilder();
|
|
try
|
|
{
|
|
//构成查询语句
|
|
sqlBuilder.Append(@"SELECT
|
|
ROW_NUMBER() OVER(ORDER BY P.PRODUCTTYPE) AS PID,
|
|
P.PRODUCTTYPE,
|
|
M.MATERIAL_TYPE,
|
|
P.MATERIAL_CODE,
|
|
SUM(P.CAPACITY) AS CAPACITY
|
|
FROM T_AW_PRODUCT P
|
|
LEFT JOIN T_AW_MATERIALTYPE M ON M.MATERIAL_CODE=P.MATERIAL_CODE");
|
|
whereBuilder.Append(" AND P.STATUS ='1'");
|
|
|
|
#region 查询条件
|
|
if (string.IsNullOrEmpty(condition.PRODUCTTYPE) == false)
|
|
{
|
|
whereBuilder.Append(" AND P.PRODUCTTYPE = @PRODUCTTYPE ");
|
|
parameters.Add(new DataParameter { ParameterName = "PRODUCTTYPE", DataType = DbType.String, Value = condition.PRODUCTTYPE });
|
|
}
|
|
if (string.IsNullOrEmpty(condition.PRODUCTCODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND P.MATERIAL_CODE LIKE @MATERIAL_CODE ");
|
|
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
|
|
}
|
|
if (whereBuilder.Length > 0)
|
|
{
|
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4) + "GROUP BY P.PRODUCTTYPE,P.MATERIAL_CODE,M.MATERIAL_TYPE");
|
|
}
|
|
|
|
#endregion
|
|
|
|
return sqlBuilder.ToString();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取导出的数据
|
|
/// <summary>
|
|
/// 获取导出的数据
|
|
/// </summary>
|
|
/// <param name="user">查询条件</param>
|
|
/// <returns>数据</returns>
|
|
public DataTable GetExportData(Product 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 = "UnQualityProductExp";
|
|
}
|
|
return dt;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "不合格品信息导出获取数据错误!"
|
|
});
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|