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

166 lines
6.8 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;
using QMAPP.FJC.Entity.FeedInManage;
namespace QMAPP.FJC.DAL.Operation
{
public class MainProductCountDAL
{
#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";
if (string.IsNullOrEmpty(page.SortExpression))
{
page.SortExpression = "MATERIAL_TYPE_CODE, MATERIAL_CODE";
}
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<Epidermis>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "成品数量计划信息数据层-获取列表"
});
throw;
}
}
#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 sum(UNUSED) AS UNUSED, ");
sqlBuilder.AppendLine(" TEMP.MATERIAL_CODE, ");
sqlBuilder.AppendLine(" TEMP.MATERIAL_NAME, ");
sqlBuilder.AppendLine(" TEMP.MATERIAL_TYPE_CODE, ");
sqlBuilder.AppendLine(" TEMP.MATERIAL_TYPE_NAME ");
sqlBuilder.AppendLine(" FROM( ");
//数据表所存数据
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 ");
sqlBuilder.AppendLine(" WHERE T.USINGSTATE='0' AND T.OUTFLAG='0' AND c.MATERIAL_ATTRIBUTE='2' AND T.STATUS IN ('0','1') ");
sqlBuilder.AppendLine(" GROUP BY T.MATERIAL_CODE,M.MATERIAL_NAME,M.MATERIAL_TYPE_CODE,c.MATERIAL_TYPE_NAME");
//差额表所存实际库存数据
sqlBuilder.AppendLine(" union ");
sqlBuilder.AppendLine(" SELECT [CHECKRESULT] AS UNUSED, ");
sqlBuilder.AppendLine(" A.MATERIAL_CODE, ");
sqlBuilder.AppendLine(" M.MATERIAL_NAME, ");
sqlBuilder.AppendLine(" M.MATERIAL_TYPE_CODE, ");
sqlBuilder.AppendLine(" c.MATERIAL_TYPE_NAME ");
sqlBuilder.AppendLine(" FROM T_PP_COUNTRESULTVALUE A ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL M on M.MATERIAL_CODE=A.MATERIAL_CODE ");
sqlBuilder.AppendLine(" LEFT JOIN T_MD_MATERIAL_CLASS c on c.MATERIAL_TYPE_CODE=M.MATERIAL_TYPE_CODE ");
sqlBuilder.AppendLine(" WHERE c.MATERIAL_ATTRIBUTE='2' ");
sqlBuilder.AppendLine(")TEMP ");
//物料号
if (string.IsNullOrEmpty(condition.MATERIAL_CODE) == false)
{
whereBuilder.Append(" AND TEMP.MATERIAL_CODE = @MATERIAL_CODE");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_CODE", DataType = DbType.String, Value = condition.MATERIAL_CODE });
}
//类别
if (string.IsNullOrEmpty(condition.MATERIAL_TYPE_CODE) == false)
{
whereBuilder.Append(" AND TEMP.MATERIAL_TYPE_CODE = @MATERIAL_TYPE_CODE");
parameters.Add(new DataParameter { ParameterName = "MATERIAL_TYPE_CODE", DataType = DbType.String, Value = condition.MATERIAL_TYPE_CODE });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
sqlBuilder.AppendLine(" GROUP BY MATERIAL_CODE,MATERIAL_NAME,MATERIAL_TYPE_CODE,MATERIAL_TYPE_NAME");
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 = "MainProductCountExp";
}
return dt;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "成品信息导出获取数据错误!"
});
throw ex;
}
}
#endregion
}
}