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

149 lines
5.8 KiB

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
{
///</summary>
/// 模块编号:M6-2
/// 作 用:设备停机记录查询
/// 作 者:王丹丹
/// 编写日期:2015年06月18日
///</summary>
public class EquipMentMaintainDAL
{
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(EquipMentMaintain condition, DataPage page)
{
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
try
{
sql = this.GetEquipMentMaintainSql(condition, ref parameters);
//分页关键字段及排序
page.KeyName = "PID";
page.SortExpression = "UPDATEDATE DESC";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage<EquipMentMaintain>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取查询语句
/// <summary>
/// 获取查询语句
/// </summary>
/// <param name="user">查询条件</param>
/// <param name="parameters">参数</param>
/// <returns>查询语句</returns>
private string GetEquipMentMaintainSql(EquipMentMaintain condition, ref List<DataParameter> 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 获取导出的数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(EquipMentMaintain model)
{
DataTable dt = null;
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
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
}
}