using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using QMAPP.FJC.Entity.WarnManage;
using QMFrameWork.Data;
namespace QMAPP.FJC.DAL.EquipMentAlarmManage
{
///
/// 模块编号:M6-2
/// 作 用:设备停机记录查询
/// 作 者:王丹丹
/// 编写日期:2015年06月18日
///
public class EquipMentMaintainDAL
{
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataPage GetList(EquipMentMaintain condition, DataPage page)
{
string sql = null;
List parameters = new List();
try
{
sql = this.GetEquipMentMaintainSql(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)
{
throw ex;
}
}
#endregion
#region 获取查询语句
///
/// 获取查询语句
///
/// 查询条件
/// 参数
/// 查询语句
private string GetEquipMentMaintainSql(EquipMentMaintain condition, ref List parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.Append(" SELECT EM.PID ");
sqlBuilder.Append(" ,EM.MID ");
sqlBuilder.Append(" ,EM.MACHINENAME ");
sqlBuilder.Append(" ,EM.MACHINECODDE ");
sqlBuilder.Append(" ,EM.PROCESSTYPE ");
sqlBuilder.Append(" ,EM.WARNTYPE ");
sqlBuilder.Append(" ,EM.DOWNTIMESTART ");
sqlBuilder.Append(" ,EM.DOWNTIMEEND ");
sqlBuilder.Append(" ,EM.DOWNTIMEREMARK ");
sqlBuilder.Append(" ,EM.MEMO ");
sqlBuilder.Append(" ,EM.CREATEUSER ");
sqlBuilder.Append(" ,EM.CREATEDATE ");
sqlBuilder.Append(" ,EM.UPDATEUSER ");
sqlBuilder.Append(" ,EM.UPDATEDATE ");
sqlBuilder.Append(" ,C.USERNAME AS CREATEUSERNAME ");
sqlBuilder.Append(" ,U.USERNAME AS UPDATEUSERNAME ");
sqlBuilder.Append(" ,MI.PRODUCELINE ");
sqlBuilder.Append(" ,MI.STATUS ");
sqlBuilder.Append(" FROM T_AW_EQUIPMENTMAINTAIN EM ");
sqlBuilder.Append(" LEFT JOIN T_BD_MACHINEINFO MI ON MI.PID=EM.MID ");
sqlBuilder.Append(" LEFT JOIN T_QM_USER C ON C.USERID=EM.CREATEUSER ");
sqlBuilder.Append(" LEFT JOIN T_QM_USER U ON U.USERID=EM.UPDATEUSER ");
//查询条件
//设备名称
if (string.IsNullOrEmpty(condition.MACHINENAME) == false)
{
whereBuilder.Append(" AND EM.MACHINENAME LIKE '%'+" + "@MACHINENAME" + "+'%'");
parameters.Add(new DataParameter { ParameterName = "MACHINENAME", DataType = DbType.String, Value = condition.MACHINENAME });
}
//设备停机时间
if (string.IsNullOrEmpty(condition.DOWNTIMESTARTTXT) == false)
{
whereBuilder.Append(" AND EM.DOWNTIMESTART >=@DOWNTIMESTARTTXT");
parameters.Add(new DataParameter { ParameterName = "DOWNTIMESTARTTXT", DataType = DbType.DateTime, Value = condition.DOWNTIMESTARTTXT });
}
if (string.IsNullOrEmpty(condition.DOWNTIMEENDTXT) == false)
{
whereBuilder.Append(" AND EM.DOWNTIMEEND <=@DOWNTIMEENDTXT");
parameters.Add(new DataParameter { ParameterName = "DOWNTIMEENDTXT", DataType = DbType.String, Value = condition.DOWNTIMEENDTXT });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取导出的数据
///
/// 获取导出的数据
///
/// 查询条件
/// 数据
public DataTable GetExportData(EquipMentMaintain model)
{
DataTable dt = null;
string sql = null;
List parameters = new List();
try
{
//构成查询语句
sql = this.GetEquipMentMaintainSql(model, ref parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
dt = session.GetTable(sql, parameters.ToArray());
dt.TableName = "T_AW_EQUIPMENTMAINTAIN";
}
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}