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.
264 lines
11 KiB
264 lines
11 KiB
4 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using QMFrameWork.Data;
|
||
|
using QMAPP.FJC.Entity.WIPManage;
|
||
|
using QMFrameWork.Log;
|
||
|
using QMAPP.FJC.Entity.Produce;
|
||
|
using System.Data;
|
||
|
using QMAPP.FJC.Entity.Basic;
|
||
|
|
||
|
|
||
|
namespace QMAPP.FJC.DAL.WIPManage
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 模块编号:M7-1
|
||
|
/// 作 用:在制品库存
|
||
|
/// 作 者:王济
|
||
|
/// 编写日期:2015年07月06日
|
||
|
///</summary>
|
||
|
public class WIPInventoryDAL
|
||
|
{
|
||
|
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 = "PID";
|
||
|
page.SortExpression = "UPDATEDATE DESC";
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
page = session.GetDataPage<Product>(sql, parameters.ToArray(), page);
|
||
|
}
|
||
|
|
||
|
return page;
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "低储报警信息数据层-获取列表!"
|
||
|
});
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 获取查询语句
|
||
|
/// </summary>
|
||
|
/// <param name="user">查询条件</param>
|
||
|
/// <param name="parameters">参数</param>
|
||
|
/// <returns>查询语句</returns>
|
||
|
public string GetQuerySql(Product condition, ref List<DataParameter> parameters)
|
||
|
{
|
||
|
StringBuilder sqlBuilder = new StringBuilder();
|
||
|
StringBuilder whereBuilderSet = new StringBuilder();
|
||
|
StringBuilder whereBuilderMain = new StringBuilder();
|
||
|
try
|
||
|
{
|
||
|
//构成查询语句
|
||
|
sqlBuilder.Append("SELECT C.PID");
|
||
|
sqlBuilder.AppendLine(",C.PRODUCTCODE");
|
||
|
sqlBuilder.AppendLine(",M.PRODUCTNAME AS PRODUCTTYPE");
|
||
|
sqlBuilder.AppendLine(",M.PROCESSNAME AS CURRENTPROCESS");
|
||
|
sqlBuilder.AppendLine(",C.MACHINENAME");
|
||
|
sqlBuilder.AppendLine(",C.MACHINECODDE");
|
||
|
sqlBuilder.AppendLine(",C.PRODUCESHIFTNAME");
|
||
|
sqlBuilder.AppendLine(",C.PRODUCESHIFTTCODE");
|
||
|
sqlBuilder.AppendLine(",C.USINGSTATE");
|
||
|
|
||
|
sqlBuilder.AppendLine(",C.MATERIAL_CODE");
|
||
|
sqlBuilder.AppendLine(",MT.MATERIAL_TYPE");
|
||
|
|
||
|
sqlBuilder.AppendLine(",C.STATUS");
|
||
|
sqlBuilder.AppendLine(",C.OUTFLAG");
|
||
|
sqlBuilder.AppendLine(",G.USERNAME AS CREATEUSER");
|
||
|
sqlBuilder.AppendLine(",M.CREATEDATE");
|
||
|
sqlBuilder.AppendLine(",K.USERNAME AS UPDATEUSER");
|
||
|
sqlBuilder.AppendLine(",M.UPDATEDATE");
|
||
|
sqlBuilder.Append(" FROM T_BD_PROCESSSET M ");
|
||
|
sqlBuilder.AppendLine(" INNER JOIN T_AW_PRODUCT C ON C.PRODUCTTYPE=M.PRODUCTTYPE AND C.CURRENTPROCESS=M.PROCESSTYPE ");
|
||
|
sqlBuilder.AppendLine("LEFT JOIN T_AW_MATERIALTYPE MT ON MT.MATERIAL_CODE=C.MATERIAL_CODE ");
|
||
|
sqlBuilder.AppendLine(" INNER JOIN T_BD_PRODUCTBASIC U ON U.PRODUCTTYPE=M.PRODUCTTYPE ");
|
||
|
sqlBuilder.AppendLine(" INNER JOIN T_QM_USER G ON G.USERID=M.CREATEUSER ");
|
||
|
sqlBuilder.AppendLine(" INNER JOIN T_QM_USER K ON K.USERID=M.UPDATEUSER ");
|
||
|
//查询条件
|
||
|
//工序类别
|
||
|
if (string.IsNullOrEmpty(condition.CURRENTPROCESS) == false)
|
||
|
{
|
||
|
whereBuilderSet.Append(" AND M.PROCESSTYPE = @PROCESSTYPE ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "PROCESSTYPE", DataType = DbType.String, Value = condition.CURRENTPROCESS });
|
||
|
}
|
||
|
//设备编号
|
||
|
if (string.IsNullOrEmpty(condition.MACHINECODDE) == false)
|
||
|
{
|
||
|
whereBuilderSet.Append(" AND C.MACHINECODDE LIKE '%'+" + "@MACHINECODDE" + "+'%'");
|
||
|
parameters.Add(new DataParameter { ParameterName = "MACHINECODDE", DataType = DbType.String, Value = condition.MACHINECODDE });
|
||
|
}
|
||
|
//条形码
|
||
|
if (string.IsNullOrEmpty(condition.PRODUCTCODE) == false)
|
||
|
{
|
||
|
whereBuilderSet.Append(" AND C.PRODUCTCODE LIKE '%'+" + "@PRODUCTCODE" + "+'%'");
|
||
|
parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = condition.PRODUCTCODE });
|
||
|
}
|
||
|
//零件类别
|
||
|
if (string.IsNullOrEmpty(condition.PRODUCTTYPE) == false)
|
||
|
{
|
||
|
whereBuilderSet.Append(" AND M.PRODUCTTYPE = @PRODUCTTYPES ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "PRODUCTTYPES", DataType = DbType.String, Value = condition.PRODUCTTYPE });
|
||
|
}
|
||
|
|
||
|
whereBuilderSet.Append(" AND M.WIPSET='1'");
|
||
|
|
||
|
if (whereBuilderSet.Length > 0)
|
||
|
{
|
||
|
sqlBuilder.Append(" WHERE " + whereBuilderSet.ToString().Substring(4));
|
||
|
}
|
||
|
sqlBuilder.AppendLine(" UNION ");
|
||
|
sqlBuilder.Append("SELECT C.PID");
|
||
|
sqlBuilder.AppendLine(",C.EPIDERMISCODE");
|
||
|
sqlBuilder.AppendLine(",M.PRODUCTNAME AS PRODUCTTYPE");
|
||
|
sqlBuilder.AppendLine(",M.PROCESSNAME AS CURRENTPROCESS");
|
||
|
sqlBuilder.AppendLine(",'' AS MACHINENAME");
|
||
|
sqlBuilder.AppendLine(",C.MACHINECODDE");
|
||
|
sqlBuilder.AppendLine(",C.PRODUCESHIFTNAME");
|
||
|
sqlBuilder.AppendLine(",C.PRODUCESHIFTTCODE");
|
||
|
sqlBuilder.AppendLine(",'' AS USINGSTATE");
|
||
|
|
||
|
sqlBuilder.AppendLine(",'' AS MATERIAL_CODE");
|
||
|
sqlBuilder.AppendLine(",'' AS MATERIAL_TYPE");
|
||
|
|
||
|
sqlBuilder.AppendLine(",C.STATUS");
|
||
|
sqlBuilder.AppendLine(",C.OUTFLAG");
|
||
|
sqlBuilder.AppendLine(",G.USERNAME AS CREATEUSER");
|
||
|
sqlBuilder.AppendLine(",M.CREATEDATE");
|
||
|
sqlBuilder.AppendLine(",K.USERNAME AS UPDATEUSER");
|
||
|
sqlBuilder.AppendLine(",M.UPDATEDATE");
|
||
|
sqlBuilder.Append(" FROM T_BD_PROCESSSET M ");
|
||
|
sqlBuilder.AppendLine(" INNER JOIN T_AW_MAIN C ON C.CURRENTPROCESS=M.PROCESSTYPE ");
|
||
|
sqlBuilder.AppendLine(" INNER JOIN T_BD_PRODUCTBASIC U ON U.PRODUCTTYPE=M.PRODUCTTYPE ");
|
||
|
sqlBuilder.AppendLine(" INNER JOIN T_QM_USER G ON G.USERID=M.CREATEUSER ");
|
||
|
sqlBuilder.AppendLine(" INNER JOIN T_QM_USER K ON K.USERID=M.UPDATEUSER ");
|
||
|
|
||
|
//查询条件
|
||
|
//工序类别
|
||
|
if (string.IsNullOrEmpty(condition.CURRENTPROCESS) == false)
|
||
|
{
|
||
|
whereBuilderMain.Append(" AND M.PROCESSTYPE = @CURRENTPROCESS ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "CURRENTPROCESS", DataType = DbType.String, Value = condition.CURRENTPROCESS });
|
||
|
}
|
||
|
//设备编号
|
||
|
if (string.IsNullOrEmpty(condition.MACHINECODDE) == false)
|
||
|
{
|
||
|
whereBuilderMain.Append(" AND C.MACHINECODDE LIKE '%'+" + "@MACHINECODDES" + "+'%'");
|
||
|
parameters.Add(new DataParameter { ParameterName = "MACHINECODDES", DataType = DbType.String, Value = condition.MACHINECODDE });
|
||
|
}
|
||
|
//条形码
|
||
|
if (string.IsNullOrEmpty(condition.PRODUCTCODE) == false)
|
||
|
{
|
||
|
whereBuilderMain.Append(" AND C.EPIDERMISCODE LIKE '%'+" + "@EPIDERMISCODE" + "+'%'");
|
||
|
parameters.Add(new DataParameter { ParameterName = "EPIDERMISCODE", DataType = DbType.String, Value = condition.PRODUCTCODE });
|
||
|
}
|
||
|
//零件类别
|
||
|
if (string.IsNullOrEmpty(condition.PRODUCTTYPE) == false)
|
||
|
{
|
||
|
whereBuilderMain.Append(" AND M.PRODUCTTYPE = @PRODUCTTYPE ");
|
||
|
parameters.Add(new DataParameter { ParameterName = "PRODUCTTYPE", DataType = DbType.String, Value = condition.PRODUCTTYPE });
|
||
|
}
|
||
|
|
||
|
whereBuilderMain.Append(" AND M.WIPSET='1'");
|
||
|
|
||
|
if (whereBuilderMain.Length > 0)
|
||
|
{
|
||
|
sqlBuilder.Append(" WHERE " + whereBuilderMain.ToString().Substring(4));
|
||
|
}
|
||
|
return sqlBuilder.ToString();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
#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 = "T_AW_PRODUCT";
|
||
|
}
|
||
|
return dt;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "在制品库存信息数据层-获取导出的数据!"
|
||
|
});
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
|
||
|
#region 获取工具合集
|
||
|
/// <summary>
|
||
|
/// 获取列表
|
||
|
/// </summary>
|
||
|
/// <param name="condition">条件</param>
|
||
|
/// <param name="page">数据页</param>
|
||
|
/// <returns>数据页</returns>
|
||
|
public List<Product> GetList(Product condition)
|
||
|
{
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
List<Product> psList = new List<Product>();
|
||
|
try
|
||
|
{
|
||
|
sql = this.GetQuerySql(condition, ref parameters);
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
psList = session.GetList<Product>(sql, parameters.ToArray()).ToList();
|
||
|
}
|
||
|
return psList;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "班次信息数据层-获取列表"
|
||
|
});
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
}
|
||
|
}
|