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

137 lines
5.1 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.FJC.Entity.Equipment;
using QMFrameWork.Data;
using System.Data;
namespace QMAPP.FJC.DAL.Equipment
{
/// <summary>
/// 设备维修保养记录
/// </summary>
public class EquipMentRecordDAL
{
#region 获取列表
/// <summary>
/// 获取列表
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(EquipMentRecord 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<EquipMentRecord>(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(EquipMentRecord condition, ref List<DataParameter> parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.Append(" SELECT EM.PID ");
sqlBuilder.Append(" ,EM.REPAIECODE ");
sqlBuilder.Append(" ,EM.REPAIETYPE ");
sqlBuilder.Append(" ,EM.MACHINECODDE ");
sqlBuilder.Append(" ,EM.FAULTCODE ");
sqlBuilder.Append(" ,EM.GENRATIONWAY ");
sqlBuilder.Append(" ,EM.SOLUTION ");
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_EQP_EQUIPMENTRECORD 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.REPAIESTARTTXT) == false)
{
whereBuilder.Append(" AND EM.REPAIESTART >=@REPAIESTARTTXT");
parameters.Add(new DataParameter { ParameterName = "REPAIESTARTTXT", DataType = DbType.DateTime, Value = condition.REPAIESTARTTXT });
}
if (string.IsNullOrEmpty(condition.REPAIEENDTXT) == false)
{
whereBuilder.Append(" AND EM.REPAIEEND <=@REPAIEENDTXT");
parameters.Add(new DataParameter { ParameterName = "REPAIEENDTXT", DataType = DbType.String, Value = condition.REPAIEENDTXT });
}
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(EquipMentRecord 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_EQP_EQUIPMENTRECORD";
}
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}