应该感谢那些指出你错误的人

借我三千虎骑,复我泱泱中华!

博客园 首页 新随笔 联系 订阅 管理

using System;
using System.Data;
using System.Web;
using System.Web.Caching;
using TIMS.WEB.PublicClass.DataBase;

namespace TIMS.WEB.PublicClass.User
{

 /// <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);
  }
  //--------------------------------------------------------------------------------------------------------
 }
}

posted on 2006-05-21 05:36  落拓孤鸿  阅读(404)  评论(0编辑  收藏  举报