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

162 lines
6.2 KiB

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using QMAPP.FJC.Entity.WarnManage;
using QMFrameWork.Data;
using QMFrameWork.Log;
namespace QMAPP.FJC.DAL.EquipMentAlarmManage
{
/// <summary>
/// 模块编号:M6-1设备报警记录查询
/// 作 用:设备报警记录查询
/// 作 者:张敬贺
/// 编写日期:2015年06月17日
///</summary>
public class EquipMentAlarmDAL
{
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(WarnInfo 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<WarnInfo>(sql, parameters.ToArray(), page);
List<WarnInfo> list = session.GetList<WarnInfo>(sql, parameters.ToArray()).ToList<WarnInfo>();
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "设备报警信息获取列表错误!"
});
throw ex;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetQuerySql(WarnInfo condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.Append(@"SELECT WI.PID
,WI.WARNTYPE
,WI.WARNCODE
,WI.WARNDESCRIBE
,WI.ISDEAL
,WI.ISDONE
,WI.CREATETYPE
,MEMO
,WI.CREATEDATE
,WI.CREATEUSER
,WI.UPDATEUSER
,WI.UPDATEDATE
,C.USERNAME AS CREATEUSERNAME
,U.USERNAME AS UPDATEUSERNAME
FROM T_AW_WARNINFO WI
LEFT JOIN T_QM_USER C ON C.USERID = WI.CREATEUSER
LEFT JOIN T_QM_USER U ON U.USERID = WI.UPDATEUSER ");
whereBuilder.Append(" AND WARNTYPE=" + QMAPP.FJC.Entity.EnumGeter.WARNTYPE.EquipMentAlarm.GetHashCode().ToString() + "");
#region 查询条件
//报警代码
if (string.IsNullOrEmpty(condition.WARNCODE) == false)
{
whereBuilder.Append(" AND WI.WARNCODE LIKE @WARNCODE ");
parameters.Add(new DataParameter { ParameterName = "WARNCODE", DataType = DbType.String, Value = "%" + condition.WARNCODE + "%" });
}
if (condition.STARTCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND WI.CREATEDATE >= @STARTCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "STARTCREATEDATE", Value = condition.STARTCREATEDATE });
}
if (condition.ENDCREATEDATE != DateTime.MinValue)
{
whereBuilder.Append(" AND WI.CREATEDATE <=@ENDCREATEDATE");
parameters.Add(new DataParameter() { DataType = DbType.String, ParameterName = "ENDCREATEDATE", Value = condition.ENDCREATEDATE });
}
if (whereBuilder.Length > 0)
{
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
}
#endregion
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取导出的数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(WarnInfo 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 = "EquipMentAlarmExp";
}
return dt;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "设备报警信息导出获取数据错误!"
});
throw ex;
}
}
#endregion
}
}