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

167 lines
7.0 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
using QMFrameWork.Log;
using QMAPP.FJC.Entity.WIPManage;
using System.Data;
namespace QMAPP.FJC.DAL.WIPManage
{
/// <summary>
/// 模块编号:M7-3
/// 作 用:在制品出库信息
/// 作 者:王济
/// 编写日期:2015年07月07日
///</summary>
public class WIPOutRecorderDAL
{
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(WIPOutRecorder condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
//sql = "SELECT * FROM T_AW_WIPOUTRECORDER";
sql = this.GetQuerySql(condition, ref parameters);
page.KeyName = "PID";
page.SortExpression = "UPDATEDATE DESC";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<WIPOutRecorder>(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(WIPOutRecorder condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.Append("SELECT M.PID");
sqlBuilder.AppendLine(",M.PRODUCTCODE");
sqlBuilder.AppendLine(",M.COUNT");
sqlBuilder.AppendLine(",M.STATUS");
sqlBuilder.AppendLine(",M.MACHINENAME");
sqlBuilder.AppendLine(",M.MACHINECODDE");
sqlBuilder.AppendLine(",M.PRODUCESHIFTNAME");
sqlBuilder.AppendLine(",M.PRODUCESHIFTTCODE");
sqlBuilder.AppendLine(",M.PRODUCELINE");
sqlBuilder.AppendLine(",M.OUTTIME");
sqlBuilder.AppendLine(",G.USERNAME AS CREATEUSER");
sqlBuilder.AppendLine(",M.CREATEDATE");
sqlBuilder.AppendLine(",K.USERNAME AS UPDATEUSER");
sqlBuilder.AppendLine(",M.UPDATEDATE");
sqlBuilder.AppendLine(",C.PROCESSNAME AS PROCESSTYPE ");
sqlBuilder.AppendLine(",U.PRODUCTNAME AS PRODUCTTYPE ");
sqlBuilder.Append(" FROM T_AW_WIPOUTRECORDER M ");
sqlBuilder.AppendLine(" LEFT JOIN T_BD_PROCESSINFO C ON C.PROCESSTYPE=M.PROCESSTYPE ");
sqlBuilder.AppendLine(" LEFT JOIN T_BD_PRODUCTBASIC U ON U.PRODUCTTYPE=M.PRODUCTTYPE ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER G ON G.USERID=M.CREATEUSER ");
sqlBuilder.AppendLine(" LEFT JOIN T_QM_USER K ON K.USERID=M.UPDATEUSER ");
//查询条件
//工序类别
if (string.IsNullOrEmpty(condition.PROCESSTYPE) == false)
{
whereBuilder.Append(" AND M.PROCESSTYPE = @PROCESSTYPE ");
parameters.Add(new DataParameter { ParameterName = "PROCESSTYPE", DataType = DbType.String, Value = condition.PROCESSTYPE });
}
//条形码
if (string.IsNullOrEmpty(condition.PRODUCTCODE) == false)
{
whereBuilder.Append(" AND M.PRODUCTCODE LIKE '%'+" + "@PRODUCTCODE" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "PRODUCTCODE", DataType = DbType.String, Value = condition.PRODUCTCODE });
}
//零件类别
if (string.IsNullOrEmpty(condition.PRODUCTTYPE) == false)
{
whereBuilder.Append(" AND M.PRODUCTTYPE = @PRODUCTTYPE ");
parameters.Add(new DataParameter { ParameterName = "PRODUCTTYPE", DataType = DbType.String, Value = condition.PRODUCTTYPE });
}
if (condition.STARTCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND M.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 M.CREATEDATE < @ENDCREATEDATE ");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "ENDCREATEDATE", Value = condition.ENDCREATEDATE.Date.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss") });
}
whereBuilder.Append("AND M.STATUS = '1'");
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#region 获取导出的数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(WIPOutRecorder 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_WIPOUTRECORDER";
}
return dt;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "在制品出库信息数据层-获取导出的数据!"
});
throw ex;
}
}
#endregion
}
}