Ejemplo n.º 1
0
 /// <summary>
 /// 获取所有权限
 /// </summary>
 /// <returns>返回权限集合</returns>
 public List<Competence> GetAllCompetence()
 {
     List<Competence> list = new List<Competence>();
     try
     {
         string sql = "select * from Competence";
         using (SqlDataReader reder = db.GetReader(sql))
         {
             while (reder.Read())
             {
                 Competence c = new Competence((int)reder["CompetenceId"], (int)reder["ParentCompetenceId"], reder["CompetenceName"].ToString(), (int)reder["CompetenceMenu"]);
                 list.Add(c);
             }
         }
         return list;
     }
     catch (SqlException ex)
     {
         throw new Exception("数据库异常!原因:" + ex.Message);
     }
     catch (Exception ex)
     {
         throw new Exception("未知异常!原因:" + ex.Message);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 获取权限组的所有权限
 /// </summary>
 /// <param name="CompetenceId">权限组Id</param>
 /// <param name="RoleId">权限组</param>
 /// <returns>返回权限集合</returns>
 public List<Competence> GetChildrenCompetence(int CompetenceId, int RoleId)
 {
     List<Competence> list = new List<Competence>();
     try
     {
         string sql = "select * from vw_RoleCompetence where ParentCompetenceId=@CompetenceId and RoleId=@RoleId";
         SqlParameter[] sp = new SqlParameter[]
         {
             new SqlParameter("@CompetenceId", CompetenceId),
              new SqlParameter("@RoleId", RoleId)
         };
         using (SqlDataReader reder = db.GetReader(sql, sp))
         {
             while (reder.Read())
             {
                 Competence c = new Competence((int)reder["CompetenceId"], (int)reder["ParentCompetenceId"], reder["CompetenceName"].ToString(), (int)reder["MenuId"]);
                 list.Add(c);
             }
         }
         return list;
     }
     catch (SqlException ex)
     {
         throw new Exception("数据库异常!原因:" + ex.Message);
     }
     catch (Exception ex)
     {
         throw new Exception("未知异常!原因:" + ex.Message);
     }
 }