using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
using QMAPP.Entity.Report;
namespace QMAPP.DAL.Report
{
///
/// 用户权限查询
///
public class QueryUserPowerDAL:BaseDAL
{
#region 获取用户权限信息
///
/// 获取用户权限信息
///
/// 查询条件
/// 数据页
public DataPage GetUserPowerList(PowerQyCondition condition, DataPage page)
{
string sql = "";
List parameters = new List();
try
{
sql = this.GetQuerySql(condition, parameters);
using (IDataSession session = AppDataFactory.CreateMainSession())
{
sql = this.ChangeSqlByDB(sql, session);
if (string.IsNullOrEmpty(page.SortExpression))
{
page.SortExpression = "USERNAME,ROLEID,AUTHORITYID";
}
page = session.GetDataPage(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
throw;
}
}
#endregion
#region 获取导出的数据
///
/// 获取导出的数据
///
/// 查询条件
/// 数据
public DataTable GetExportData(PowerQyCondition condition)
{
DataTable dt = null;
string sql = null;
List parameters = new List();
try
{
//构成查询语句
sql = this.GetQuerySql(condition,parameters);
sql += " ORDER BY USERNAME,ROLEID,AUTHORITYID";
using (IDataSession session = AppDataFactory.CreateMainSession())
{
dt = session.GetTable(sql, parameters.ToArray());
dt.TableName = "T_BD_CORP";
}
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取查询语句
private string GetQuerySql(PowerQyCondition condition,List parameters)
{
string sql = "";
string where = "";
sql = @"SELECT U1.USERID,U1.LOGINUSERID,U1.USERNAME,U1.ORGANID,T1.AUTHORITYID,'' AS ROLEID,'' AS ROLENAME,'' AS ORGANNAME,'' AS AUTHORITYNAME
FROM T_QM_ORGAIZATIONAUTHORITY T1,T_QM_USERORGAIZATION T2,T_QM_USER U1
WHERE T1.ORGAID = T2.ORGAID AND T2.USERID = U1.USERID [WHERE]
UNION
SELECT U1.USERID,U1.LOGINUSERID,U1.USERNAME,U1.ORGANID,T1.AUTHORITYID,T1.ROLEID,'' AS ROLENAME,'' AS ORGANNAME,'' AS AUTHORITYNAME
FROM T_QM_ROLEAUTHORITY T1,T_QM_USERROLE T2,T_QM_USER U1
WHERE T1.ROLEID = T2.ROLEID AND T2.USERID = U1.USERID [WHERE]
UNION
SELECT U1.USERID,U1.LOGINUSERID,U1.USERNAME,U1.ORGANID,T2.AUTHORITYID,'' AS ROLEID,'' AS ROLENAME,'' AS ORGANNAME,'' AS AUTHORITYNAME
FROM T_QM_USERAUTHORITY T2,T_QM_USER U1
WHERE T2.USERID = U1.USERID [WHERE]";
if (string.IsNullOrEmpty(condition.LOGINUSERID) == false)
{
where += " AND U1.LOGINUSERID = @LOGINUSERID";
parameters.Add(new DataParameter("LOGINUSERID", condition.LOGINUSERID));
}
if (string.IsNullOrEmpty(condition.ORGANID) == false)
{
where += " AND U1.ORGANID = @ORGANID";
parameters.Add(new DataParameter("ORGANID", condition.ORGANID));
}
sql = sql.Replace("[WHERE]", where);
return sql;
}
#endregion
}
}