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

123 lines
4.3 KiB

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
{
/// <summary>
/// 用户权限查询
/// </summary>
public class QueryUserPowerDAL:BaseDAL
{
#region 获取用户权限信息
/// <summary>
/// 获取用户权限信息
/// </summary>
/// <param name="condition">查询条件</param>
/// <param name="page">数据页</param>
public DataPage GetUserPowerList(PowerQyCondition condition, DataPage page)
{
string sql = "";
List<DataParameter> parameters = new List<DataParameter>();
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<PowerQueryResult>(sql, parameters.ToArray(), page);
}
return page;
}
catch (Exception ex)
{
throw;
}
}
#endregion
#region 获取导出的数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataTable GetExportData(PowerQyCondition condition)
{
DataTable dt = null;
string sql = null;
List<DataParameter> parameters = new List<DataParameter>();
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<DataParameter> 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
}
}