动态权限分配
时间:2010-11-26 来源:初学软件
BLL层
/// <summary>
/// 查询父节点
/// </summary>
/// <returns></returns>
public static DataTable checkrole()
{
return roledal.checkrole();
}
/// <summary>
/// 查询子节点
/// </summary>
/// <param name="pid"></param>
/// <returns></returns>
public static DataTable checkroles(int pid)
{
return roledal.checkroles(pid);
}
/// <summary>
/// 查询角色拥有的权限
/// </summary>
/// <param name="rid"></param>
/// <returns></returns>
public static DataTable chekrolerrid(int rid)
{
return roledal.chekrolerid(rid);
}
/// <summary>
/// 判断节点是否存在
/// </summary>
/// <param name="rid"></param>
/// <param name="pid"></param>
/// <returns></returns>
public static bool chekroleridandpid(int rid, int pid)
{
return roledal.checkroleridandpid(rid, pid);
}
/// <summary>
/// 添加一个节点
/// </summary>
/// <param name="rid"></param>
/// <param name="pid"></param>
/// <returns></returns>
public static int insertrole(int rid, int pid)
{
return roledal.insertrole(rid,pid);
}
/// <summary>
/// 删除一个节点
/// </summary>
/// <param name="rid"></param>
/// <param name="pid"></param>
/// <returns></returns>
public static int deleterole(int rid, int pid)
{
return roledal.delererole(rid, pid);
}
DAL层
/// <summary>
/// 查询父节点
/// </summary>
/// <returns></returns>
public static DataTable checkrole()
{
string sql = "select P_Id,P_Name from Permission where ParentNOdeId=0 ";
return DBHelper.GetDataSet(sql);
}
/// <summary>
/// 查询子节点
/// </summary>
/// <param name="pid"></param>
/// <returns></returns>
public static DataTable checkroles(int pid)
{
string sql = "select P_Id,P_Name from Permission where ParentNOdeId='" + pid + "'";
return DBHelper.GetDataSet(sql);
}
/// <summary>
/// 查询角色所拥有的权限
/// </summary>
/// <param name="rid"></param>
/// <returns></returns>
public static DataTable chekrolerid(int rid)
{
string sql = "select RP_Pid from Role_Per where RP_Rid='"+rid+"'";
return DBHelper.GetDataSet(sql);
}
/// <summary>
/// 判断节点是否存在
/// </summary>
/// <param name="rid"></param>
/// <param name="pid"></param>
/// <returns></returns>
public static bool checkroleridandpid(int rid, int pid)
{
string sql = "select * from Role_Per where RP_Rid="+rid+"and RP_Pid="+pid+"";
SqlDataReader dr= DBHelper.GetReader(sql);
if (dr.Read())
{
dr.Close();
return true;
}
else
{
dr.Close();
return false;
}
}
/// <summary>
/// 添加一个节点
/// </summary>
/// <param name="rid"></param>
/// <param name="pid"></param>
/// <returns></returns>
public static int insertrole(int rid, int pid)
{
string sql = "insert into Role_Per(RP_Rid,RP_Pid) values("+rid+","+pid+")";
return DBHelper.ExecuteCommand(sql);
}
/// <summary>
/// 删除一个节点
/// </summary>
/// <param name="rid"></param>
/// <param name="pid"></param>
/// <returns></returns>
public static int delererole(int rid, int pid)
{
string sql = "delete Role_Per where RP_Rid="+rid+"and RP_Pid"+pid+"";
return DBHelper.ExecuteCommand(sql);
}
Model层和表就不写啦太麻烦啦