using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.FJC.Entity.WIPManage;
using QMFrameWork.Data;
using System.Data;
using QMFrameWork.Log;
namespace QMAPP.FJC.DAL.WIPManage
{
///
/// 模块编号:M7-4
/// 作 用:低储报警信息数据层
/// 作 者:王丹丹
/// 编写日期:2015年06月19日
///
public class StorageAlarmDAL
{
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataPage GetList(StorageAlarm condition, DataPage page)
{
string sql = null;
List parameters = new List();
try
{
sql = this.GetStorageAlarmSql(condition, ref parameters);
//分页关键字段及排序
page.KeyName = "PID";
page.SortExpression = "UPDATEDATE DESC";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "低储报警信息数据层-获取列表!"
});
throw ex;
}
}
#endregion
#region 获取查询语句
///
/// 获取查询语句
///
/// 查询条件
/// 参数
/// 查询语句
private string GetStorageAlarmSql(StorageAlarm condition, ref List parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT S.PID ");
sqlBuilder.AppendLine(" ,S.PROCESSTYPE ");
sqlBuilder.AppendLine(" ,S.MINVALUE ");
sqlBuilder.AppendLine(" ,S.PRODUCEMINVALUE ");
sqlBuilder.AppendLine(" ,S.CURRENTSTORAGE ");
sqlBuilder.AppendLine(" ,S.ALARMSTATUS ");
sqlBuilder.AppendLine(" ,S.PRODUCESHIFTNAME ");
sqlBuilder.AppendLine(" ,S.PRODUCESHIFTTCODE ");
sqlBuilder.AppendLine(" ,S.PRODUCELINE ");
sqlBuilder.AppendLine(" ,S.CREATEUSER ");
sqlBuilder.AppendLine(" ,S.CREATEDATE ");
sqlBuilder.AppendLine(" ,S.UPDATEUSER ");
sqlBuilder.AppendLine(" ,S.UPDATEDATE ");
sqlBuilder.AppendLine(" FROM T_AW_STORAGEALARM S ");
//查询条件
//工序类别
if (string.IsNullOrEmpty(condition.PROCESSTYPE) == false)
{
whereBuilder.Append(" AND S.PROCESSTYPE =@PROCESSTYPE ");
parameters.Add(new DataParameter { ParameterName = "PROCESSTYPE", DataType = DbType.String, Value = condition.PROCESSTYPE });
}
//报警时间
if (string.IsNullOrEmpty(condition.CREATEDATESTART) == false)
{
whereBuilder.Append(" AND S.CREATEDATE >=@CREATEDATESTART");
parameters.Add(new DataParameter { ParameterName = "CREATEDATESTART", DataType = DbType.DateTime, Value = condition.CREATEDATESTART });
}
if (string.IsNullOrEmpty(condition.CREATEDATEEND) == false)
{
whereBuilder.Append(" AND S.CREATEDATE <=@CREATEDATEEND");
parameters.Add(new DataParameter { ParameterName = "CREATEDATEEND", DataType = DbType.String, Value = condition.CREATEDATEEND });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取导出的数据
///
/// 获取导出的数据
///
/// 查询条件
/// 数据
public DataTable GetExportData(StorageAlarm model)
{
DataTable dt = null;
string sql = null;
List parameters = new List();
try
{
//构成查询语句
sql = this.GetStorageAlarmSql(model, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
dt = session.GetTable(sql, parameters.ToArray());
dt.TableName = "T_AW_STORAGEALARM";
}
return dt;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "低储报警信息数据层-获取导出的数据!"
});
throw ex;
}
}
#endregion
}
}