using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using QMAPP.DAL;
using QMAPP.Entity;
using QMAPP.FJC.Entity.EM;
using QMFrameWork.Data;
using QMFrameWork.Log;
namespace QMAPP.FJC.DAL.FuntionDescriptionDAL
{
public class FuntionDescriptionDAL : BaseDAL
{
#region 获取功能模块下拉框
///
/// 获取信息
///
/// 条件
/// 信息
public List GetModelNameCombox()
{
List parameters = new List();
try
{
string sql = "SELECT MODELNAME FROM T_QM_FUNTIONDESCRIPTION group by MODELNAME";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.GetList(sql, parameters.ToArray()).ToList();
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "热点查询-获取功能模块下拉框"
});
throw;
}
}
#endregion
#region 获取菜单项下拉框
///
/// 获取信息
///
/// 条件
/// 信息
public List GetMenuNameCombox(string ModelName)
{
List parameters = new List();
try
{
string sql = "SELECT MENUNAME FROM T_QM_FUNTIONDESCRIPTION where MODELNAME='" + ModelName + "' group by MENUNAME";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
return session.GetList(sql, parameters.ToArray()).ToList();
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "热点查询-获取菜单项下拉框"
});
throw;
}
}
#endregion
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataPage GetCountList(FuntionDescription condition, DataPage page)
{
string sql = null;
List parameters = new List();
try
{
sql = this.GetQuerySql(condition, ref parameters);
//分页关键字段及排序
page.KeyName = "MODELNAME";
page.SortExpression = "MODELNAME";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
page = session.GetDataPage(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "热点查询-获取列表"
});
throw;
}
}
#endregion
#region 获取查询语句
///
/// 获取查询语句
///
/// 查询条件
/// 参数
/// 查询语句
private string GetQuerySql(FuntionDescription condition, ref List parameters)
{
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder whereBuilder = new StringBuilder();
try
{
//构成查询语句
sqlBuilder.AppendLine(" SELECT MODELNAME,MENUNAME,FUNCTIONNAME,count(1) as useCount FROM T_QM_FUNCTIONRECORDER t1,T_QM_FUNTIONDESCRIPTION t2 ");
whereBuilder.Append(" where t1.CONTROLLER=t2.CONTROLLER and t1.action=t2.action");
//查询条件
if (string.IsNullOrEmpty(condition.MODELNAME) == false)
{
whereBuilder.Append(" AND MODELNAME =@MODELNAME");
parameters.Add(new DataParameter { ParameterName = "MODELNAME", DataType = DbType.String, Value = condition.MODELNAME });
}
if (string.IsNullOrEmpty(condition.MENUNAME.Trim()) == false)
{
whereBuilder.Append(" AND MENUNAME =@MENUNAME");
parameters.Add(new DataParameter { ParameterName = "MENUNAME", DataType = DbType.String, Value = condition.MENUNAME });
}
if (string.IsNullOrEmpty(condition.STARTCREATEDATE) == false)
{
whereBuilder.Append(" AND CREATEDATE >= @STARTCREATEDATE");
parameters.Add(new DataParameter { ParameterName = "STARTCREATEDATE", DataType = DbType.String, Value = condition.STARTCREATEDATE });
}
if (string.IsNullOrEmpty(condition.ENDCREATEDATE) == false)
{
whereBuilder.Append(" AND CREATEDATE <= @ENDCREATEDATE");
parameters.Add(new DataParameter { ParameterName = "ENDCREATEDATE", DataType = DbType.String, Value = condition.ENDCREATEDATE });
}
if (whereBuilder.Length > 0)
{
//sqlBuilder.Append(" WHERE " + whereBuilder.ToString().Substring(4));
sqlBuilder.Append(whereBuilder);
}
sqlBuilder.AppendLine(" group by MODELNAME,MENUNAME,FUNCTIONNAME ");
return sqlBuilder.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}