您的位置:首页 > 其它

使用缓存控制用户权限类

2006-05-18 23:03 363 查看
using System;
using System.Data;
using System.Web;
using System.Web.Caching;
using TIMS.WEB.PublicClass.DataBase;

namespace TIMS.WEB.PublicClass.User
{
/*
Explain:
用户权限
*/
/// <summary>
/// 用户角色
/// </summary>
public class UserRole
{
private static string USERROLEKEY = "ROLEDIST";
private static string TABLENAME = "TM_SYS_ROLEDIST";
private static string SQL = "Select LogName, RoleName From TM_SYS_ROLEDIST";
private static string MANAROLE = "Admin";
//--------------------------------------------------------------------------------------------------------
public UserRole()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
//--------------------------------------------------------------------------------------------------------
/// <summary>
/// 取得角色分配
/// </summary>
/// <returns></returns>
private static DataSet GetRoleDist()
{
DataSet RoleDist = null;
if(! IsNULL())
{
RoleDist = (DataSet)HttpContext.Current.Cache[USERROLEKEY]; /* */
}

return(RoleDist);
}
//--------------------------------------------------------------------------------------------------------
/// <summary>
/// 判断缓存中用户信息是否存在
/// </summary>
/// <returns></returns>
private static bool IsNULL()
{
if(HttpContext.Current.Cache[USERROLEKEY] != null) /* */
{
return(false);
}
else
{
return(! LoadRoleDist());
}
}
//--------------------------------------------------------------------------------------------------------
/// <summary>
/// 加载角色分配
/// </summary>
/// <returns></returns>
public static bool LoadRoleDist()
{
DataSet dsRoleDist = null;
OracleDB oracleDB = new OracleDB();
try
{
dsRoleDist = oracleDB.GetDataSet(SQL,TABLENAME);
}
catch
{}
oracleDB.CloseCon();
if(dsRoleDist != null)
{
HttpContext.Current.Cache.Insert(USERROLEKEY,dsRoleDist); /* */
return(true);
}
else
{
return(false);
}
}
//--------------------------------------------------------------------------------------------------------
/// <summary>
/// 判断用户是否是专工
/// </summary>
/// <param name="SystemAB">true:专工;false:非专工;</param>
/// <returns>用户登录名</returns>
/// <returns>系统缩写</returns>
public static bool Power(string LogName, string RoleName)
{
string filter = "LogName = '" + LogName + "' and RoleName = '" + RoleName + "'";
DataSet RoleDist = GetRoleDist();

if(RoleDist != null)
{
DataRow [] SelRow;
SelRow = RoleDist.Tables[TABLENAME].Select(filter);
if(SelRow.Length == 1)
{
return(true);
}
else
{
return(false);
}
}
else
{
return(false);
}
}
//--------------------------------------------------------------------------------------------------------
/// <summary>
/// 判断用户是否是管理员
/// </summary>
/// <param name="LogName"></param>
/// <returns></returns>
public static bool IsAdmin(string LogName)
{
string filter = "LogName = '" + LogName + "' and RoleName = '" + MANAROLE + "'";
DataSet RoleDist = GetRoleDist();

if(RoleDist != null)
{
DataRow [] SelRow;
SelRow = RoleDist.Tables[TABLENAME].Select(filter);
if(SelRow.Length == 1)
{
return(true);
}
else
{
return(false);
}
}
else
{
return(false);
}
}
//--------------------------------------------------------------------------------------------------------
/// <summary>
/// 清空缓存
/// </summary>
/// <returns></returns>
public static bool ClearCache()
{
try
{
HttpContext.Current.Cache.Remove(USERROLEKEY); /* */
return(true);
}
catch
{
}
return(false);
}
//--------------------------------------------------------------------------------------------------------
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: