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.
393 lines
16 KiB
393 lines
16 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using QMFrameWork.Data;
|
|
using QMAPP.FJC.Entity.FeedInManage;
|
|
using QMFrameWork.Log;
|
|
using System.Data;
|
|
|
|
namespace QMAPP.FJC.DAL.WIPManage
|
|
{
|
|
/// <summary>
|
|
/// 20171013gzf
|
|
/// </summary>
|
|
public class WIPProductCountDAL
|
|
{
|
|
#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_CODE DESC";
|
|
}
|
|
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 ");
|
|
sqlBuilder.AppendLine(" ROW_NUMBER() over(order by M.MATERIAL_NAME) AS ROW_NUMBER, ");
|
|
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 (c.MATERIAL_ATTRIBUTE='1' OR c.MATERIAL_ATTRIBUTE='0' ) ");
|
|
//查询条件
|
|
|
|
//物料号
|
|
if (string.IsNullOrEmpty(condition.MATERIAL_CODE) == false)
|
|
{
|
|
whereBuilder.Append(" AND M.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 M.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 T.MATERIAL_CODE, M.MATERIAL_NAME,M.MATERIAL_TYPE_CODE,c.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 = "WIPProductCountExp";
|
|
}
|
|
return dt;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace,
|
|
Info = "在制品信息导出获取数据错误!"
|
|
});
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 获取IMS注塑数据数量
|
|
/// </summary>
|
|
/// <param name="materialtype"></param>
|
|
/// <param name="materialcode"></param>
|
|
/// <returns></returns>
|
|
public DataPage GetIMSCount(string materialtype, string materialcode,DataPage page)
|
|
{
|
|
StringBuilder sql = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
sql.AppendLine("SELECT ROW_NUMBER() OVER(ORDER BY P.MATERIAL_CODE) AS ROW_NUMBER ");
|
|
sql.AppendLine(" ,P.MATERIAL_CODE ");
|
|
//sql.AppendLine(" ,P.CAPACITY ");
|
|
sql.AppendLine(" ,P.COUNTVALUE AS CAPACITY ");
|
|
sql.AppendLine(" ,M.MATERIAL_NAME ");
|
|
sql.AppendLine(" ,M.MATERIAL_TYPE_CODE ");
|
|
sql.AppendLine(" ,MC.MATERIAL_TYPE_NAME ");
|
|
//sql.AppendLine(" FROM (SELECT MATERIAL_CODE ");
|
|
//sql.AppendLine(" ,SUM(COUNTVALUE) AS CAPACITY ");
|
|
//sql.AppendLine(" FROM T_AW_PRODUCTCOUNT ");
|
|
//sql.AppendLine(" WHERE PRODUCTCODE LIKE 'CFAA%' ");
|
|
//sql.AppendLine(" GROUP BY MATERIAL_CODE) AS P ");
|
|
sql.AppendLine(" FROM T_AW_PRODUCTCOUNT AS P ");
|
|
sql.AppendLine(" LEFT JOIN T_MD_MATERIAL AS M ");
|
|
sql.AppendLine(" ON M.MATERIAL_CODE=p.MATERIAL_CODE ");
|
|
sql.AppendLine(" LEFT JOIN T_MD_MATERIAL_CLASS AS MC ");
|
|
sql.AppendLine(" ON M.MATERIAL_TYPE_CODE=MC.MATERIAL_TYPE_CODE ");
|
|
//sql.AppendLine(" WHERE M.MATERIAL_CODE IS NOT NULL ");
|
|
sql.AppendLine(" WHERE M.MATERIAL_CODE IS NOT NULL AND P.PROTYPE=0 ");
|
|
if (!string.IsNullOrEmpty(materialcode))
|
|
{
|
|
sql.AppendLine(" AND P.MATERIAL_CODE=@materialcode");
|
|
parameters.Add(new DataParameter("materialcode", materialcode));
|
|
}
|
|
if (!string.IsNullOrEmpty(materialtype))
|
|
{
|
|
sql.AppendLine(" AND M.MATERIAL_TYPE_CODE=@materialtype");
|
|
parameters.Add(new DataParameter("materialtype", materialtype));
|
|
}
|
|
|
|
page.KeyName = "PID";
|
|
if (string.IsNullOrEmpty(page.SortExpression))
|
|
{
|
|
page.SortExpression = "MATERIAL_CODE DESC";
|
|
}
|
|
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
var s = session.GetTable(sql.ToString(), parameters.ToArray());
|
|
return session.GetDataPage<Epidermis>(sql.ToString(), parameters.ToArray(), page);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace
|
|
});
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取塑料件消耗数量
|
|
/// </summary>
|
|
/// <param name="materialtype"></param>
|
|
/// <param name="materialcode"></param>
|
|
/// <returns></returns>
|
|
public List<Epidermis> GetPlasticPartUsingCount(string materialtype, string materialcode)
|
|
{
|
|
StringBuilder sql = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
|
|
sql.AppendLine("SELECT P.MATERIAL_CODE ");
|
|
sql.AppendLine(" ,SUM(USINGCOUNT) AS USINGCOUNT ");
|
|
sql.AppendLine(" FROM T_AW_PRODUCT AS P ");
|
|
sql.AppendLine(" WHERE 1=1 ");
|
|
if (!string.IsNullOrEmpty(materialcode))
|
|
{
|
|
sql.AppendLine(" AND P.MATERIAL_CODE=@materialcode");
|
|
parameters.Add(new DataParameter("materialcode", materialcode));
|
|
}
|
|
if (!string.IsNullOrEmpty(materialtype))
|
|
{
|
|
sql.AppendLine(" AND P.MATERIAL_TYPE=@materialtype");
|
|
parameters.Add(new DataParameter("materialtype", materialtype));
|
|
}
|
|
sql.AppendLine(" GROUP BY P.MATERIAL_CODE ");
|
|
sql.AppendLine("HAVING SUM(USINGCOUNT)>0");
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
return session.GetList<Epidermis>(sql.ToString(), parameters.ToArray()).ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace
|
|
});
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取塑料件报废数量
|
|
/// </summary>
|
|
/// <param name="materialtype"></param>
|
|
/// <param name="materialcode"></param>
|
|
/// <returns></returns>
|
|
public List<Epidermis> GetPlasticPartScrapCount(string materialtype, string materialcode)
|
|
{
|
|
StringBuilder sql = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
|
|
sql.AppendLine("SELECT S.MATERIAL_CODE ");
|
|
sql.AppendLine(" ,SUM(S.MENDNUMBER) AS USINGCOUNT ");
|
|
sql.AppendLine(" FROM T_AW_MENDRECORDER AS S ");
|
|
sql.AppendLine(" WHERE S.MENDRESULT='2' ");
|
|
if (!string.IsNullOrEmpty(materialcode))
|
|
{
|
|
sql.AppendLine(" AND S.MATERIAL_CODE=@materialcode");
|
|
parameters.Add(new DataParameter("materialcode", materialcode));
|
|
}
|
|
if (!string.IsNullOrEmpty(materialtype))
|
|
{
|
|
sql.AppendLine(" AND S.MATERIAL_TYPE_CODE=@materialtype");
|
|
parameters.Add(new DataParameter("materialtype", materialtype));
|
|
}
|
|
sql.AppendLine(" GROUP BY S.MATERIAL_CODE ");
|
|
sql.AppendLine("HAVING SUM(S.MENDNUMBER)>0");
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
return session.GetList<Epidermis>(sql.ToString(), parameters.ToArray()).ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace
|
|
});
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取塑料件盘点差额
|
|
/// </summary>
|
|
/// <param name="materialtype"></param>
|
|
/// <param name="materialcode"></param>
|
|
/// <returns></returns>
|
|
public List<Epidermis> GetPlasticPartCounting(string materialtype, string materialcode)
|
|
{
|
|
StringBuilder sql = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
|
|
sql.AppendLine("SELECT C.MATERIAL_CODE ");
|
|
sql.AppendLine(" ,C.CHECKRESULT AS USINGCOUNT ");
|
|
sql.AppendLine(" FROM T_PP_COUNTRESULTVALUE AS C ");
|
|
sql.AppendLine(" LEFT JOIN T_MD_MATERIAL AS M ");
|
|
sql.AppendLine(" ON M.MATERIAL_CODE=C.MATERIAL_CODE ");
|
|
sql.AppendLine(" WHERE 1=1 ");
|
|
if (!string.IsNullOrEmpty(materialcode))
|
|
{
|
|
sql.AppendLine(" AND C.MATERIAL_CODE=@materialcode");
|
|
parameters.Add(new DataParameter("materialcode", materialcode));
|
|
}
|
|
if (!string.IsNullOrEmpty(materialtype))
|
|
{
|
|
sql.AppendLine(" AND M.MATERIAL_TYPE_CODE=@materialtype");
|
|
parameters.Add(new DataParameter("materialtype", materialtype));
|
|
}
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
return session.GetList<Epidermis>(sql.ToString(), parameters.ToArray()).ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace
|
|
});
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取塑料件盘点差额
|
|
/// </summary>
|
|
/// <param name="materialtype"></param>
|
|
/// <param name="materialcode"></param>
|
|
/// <returns></returns>
|
|
public List<Epidermis> GetPlasticPartOut(string materialtype, string materialcode)
|
|
{
|
|
StringBuilder sql = new StringBuilder();
|
|
List<DataParameter> parameters = new List<DataParameter>();
|
|
try
|
|
{
|
|
|
|
sql.AppendLine("SELECT C.MATERIAL_CODE ");
|
|
sql.AppendLine(" ,COUNT(*) AS USINGCOUNT ");
|
|
sql.AppendLine(" FROM T_AW_PRODUCTOUT AS C ");
|
|
sql.AppendLine(" LEFT JOIN T_MD_MATERIAL AS M ");
|
|
sql.AppendLine(" ON M.MATERIAL_CODE=C.MATERIAL_CODE ");
|
|
sql.AppendLine(" WHERE 1=1 ");
|
|
if (!string.IsNullOrEmpty(materialcode))
|
|
{
|
|
sql.AppendLine(" AND C.MATERIAL_CODE=@materialcode");
|
|
parameters.Add(new DataParameter("materialcode", materialcode));
|
|
}
|
|
if (!string.IsNullOrEmpty(materialtype))
|
|
{
|
|
sql.AppendLine(" AND M.MATERIAL_TYPE_CODE=@materialtype");
|
|
parameters.Add(new DataParameter("materialtype", materialtype));
|
|
}
|
|
sql.AppendLine(" GROUP BY C.MATERIAL_CODE");
|
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
|
{
|
|
return session.GetList<Epidermis>(sql.ToString(), parameters.ToArray()).ToList();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogManager.LogHelper.Error(new LogInfo()
|
|
{
|
|
ErrorInfo = ex,
|
|
Tag = ex.StackTrace
|
|
});
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|