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.
157 lines
6.1 KiB
157 lines
6.1 KiB
4 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using QMAPP.FJC.Entity.EnergyManage;
|
||
|
using System.Data;
|
||
|
using QMFrameWork.Data;
|
||
|
using QMFrameWork.Log;
|
||
|
|
||
|
namespace QMAPP.FJC.DAL.EnergyManage
|
||
|
{
|
||
|
public class MeterReadingsDAL
|
||
|
{
|
||
|
#region ��ȡ�б�
|
||
|
/// <summary>
|
||
|
/// ��ȡ�б�
|
||
|
/// </summary>
|
||
|
/// <param name="condition">����</param>
|
||
|
/// <param name="page">����ҳ</param>
|
||
|
/// <returns>����ҳ</returns>
|
||
|
public DataPage GetList(Meter condition, DataPage page)
|
||
|
{
|
||
|
string sql = null;
|
||
|
List<DataParameter> parameters = new List<DataParameter>();
|
||
|
try
|
||
|
{
|
||
|
sql = this.GetQuerySql(condition, ref parameters);
|
||
|
//��ҳ�ؼ��ֶμ�����
|
||
|
page.KeyName = "PID";
|
||
|
page.SortExpression = "EQPT_CODE";
|
||
|
using (IDataSession session = AppDataFactory.CreateMainSession())
|
||
|
{
|
||
|
page = session.GetDataPage<Meter>(sql, parameters.ToArray(), page);
|
||
|
}
|
||
|
return page;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "FIS �ƻ���Ϣ���ݲ�-��ȡ�б�"
|
||
|
});
|
||
|
throw;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region ��ȡ��ѯ����
|
||
|
/// <summary>
|
||
|
/// ��ȡ��ѯ����
|
||
|
/// </summary>
|
||
|
/// <param name="user">��ѯ����</param>
|
||
|
/// <param name="parameters">����</param>
|
||
|
/// <returns>��ѯ����</returns>
|
||
|
private string GetQuerySql(Meter condition, ref List<DataParameter> parameters)
|
||
|
{
|
||
|
StringBuilder sqlBuilder = new StringBuilder();
|
||
|
StringBuilder whereBuilder = new StringBuilder();
|
||
|
try
|
||
|
{
|
||
|
//���ɲ�ѯ����E.PID,
|
||
|
sqlBuilder.AppendLine(" SELECT ");
|
||
|
sqlBuilder.AppendLine(" E.EQUIPMENT_NAME AS EQPT_NAME , ");
|
||
|
sqlBuilder.AppendLine(" E.EQUIPMENT_CODE AS EQPT_CODE , ");
|
||
|
sqlBuilder.AppendLine(" SUM(R.DIFF_WITH_LAST) AS CONSUME ");
|
||
|
sqlBuilder.AppendLine(" FROM T_EM_METER_READINGS AS R ");
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_EM_METER AS M ON R.METER_PID=M.PID ");
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_MD_EQUIPMENT AS E ON E.EQUIPMENT_CODE=M.EQPT_CODE ");
|
||
|
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_MD_FACTORY AS F ON F.FACTORY_CODE=M.FACTORY_CODE ");
|
||
|
sqlBuilder.AppendLine(" LEFT JOIN T_MD_WORKCENTER AS W ON W.WORKCENTER_CODE=E.WORKCENTER_CODE ");
|
||
|
//��ѯ����
|
||
|
|
||
|
//������
|
||
|
if (string.IsNullOrEmpty(condition.FACTORY_CODE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND M.FACTORY_CODE = @FACTORY_CODE");
|
||
|
parameters.Add(new DataParameter { ParameterName = "FACTORY_CODE", DataType = DbType.String, Value = condition.FACTORY_CODE });
|
||
|
}
|
||
|
//�豸��
|
||
|
if (string.IsNullOrEmpty(condition.EQPT_CODE) == false)
|
||
|
{
|
||
|
whereBuilder.Append(" AND EQPT_CODE= @EQPT_CODE");
|
||
|
parameters.Add(new DataParameter { ParameterName = "EQPT_CODE", DataType = DbType.String, Value = condition.EQPT_CODE });
|
||
|
}
|
||
|
//�������ı���
|
||
|
//if (string.IsNullOrEmpty(condition.WORKCENTER_CODE) == false)
|
||
|
//{
|
||
|
// whereBuilder.Append(" AND E.WORKCENTER_CODE=@WORKCENTER_CODE");
|
||
|
// parameters.Add(new DataParameter { ParameterName = "WORKCENTER_CODE", DataType = DbType.String, Value = condition.WORKCENTER_CODE });
|
||
|
//}
|
||
|
////��ʼʱ��
|
||
|
//if (condition.ONLINETIMESTART != DateTime.MinValue)
|
||
|
//{
|
||
|
// whereBuilder.Append(" AND R.READ_TIME >= @ONLINETIMESTART");
|
||
|
// parameters.Add(new DataParameter { ParameterName = "ONLINETIMESTART", DataType = DbType.String, Value = condition.ONLINETIMESTART });
|
||
|
//}
|
||
|
//if (condition.ONLINETIMEEND != DateTime.MinValue)
|
||
|
//{
|
||
|
// whereBuilder.Append(" AND R.READ_TIME <= @ONLINETIMEEND");
|
||
|
// parameters.Add(new DataParameter { ParameterName = "ONLINETIMEEND", DataType = DbType.String, Value = condition.ONLINETIMEEND });
|
||
|
//}
|
||
|
|
||
|
if (whereBuilder.Length > 0)
|
||
|
{
|
||
|
sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
|
||
|
}
|
||
|
sqlBuilder.AppendLine(" GROUP BY E.EQUIPMENT_NAME,E.EQUIPMENT_CODE ");
|
||
|
return sqlBuilder.ToString();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region ��ȡ����������
|
||
|
/// <summary>
|
||
|
/// ��ȡ����������
|
||
|
/// </summary>
|
||
|
/// <param name="user">��ѯ����</param>
|
||
|
/// <returns>����</returns>
|
||
|
public DataTable GetExportData(Meter 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 = "EqptConsumeExp";
|
||
|
}
|
||
|
return dt;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogManager.LogHelper.Error(new LogInfo()
|
||
|
{
|
||
|
ErrorInfo = ex,
|
||
|
Tag = ex.StackTrace,
|
||
|
Info = "�豸������Ϣ������ȡ���ݴ���!"
|
||
|
});
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
}
|
||
|
}
|