Purview_User_Manage_Top.aspx.cs:用户权限管理之 选择用户
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace YljWeb._Admin.Purview_Manage
{
/// <summary>
/// Purview_User_Manage_Top 的摘要说明。
/// </summary>
public class Purview_User_Manage_Top : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lbl_Select_Username;
protected System.Web.UI.WebControls.DropDownList ddl_username;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
this.ddl_username.Attributes.Add("onchange","javascript:self.location=\"?username=\"+this.options[this.selectedIndex].value");
if(!Page.IsPostBack)//该页是否是为响应客户端而产生的或者是否是首次访问,系统自动生成
{
DropBind();
}
if( Request["username"] != null)
{
Session["Purview_User_Username"] = Request["username"];
this.lbl_Select_Username.Text = Session["Purview_User_Username"].ToString();
this.ddl_username.SelectedValue = Session["Purview_User_Username"].ToString();
this.Response.Write("<script language=\"javascript\">parent.location.reload();</"+"script>");
}
if( Session["Purview_User_Username"] != null)
{
this.lbl_Select_Username.Text = Session["Purview_User_Username"].ToString();
this.ddl_username.SelectedValue = Session["Purview_User_Username"].ToString();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DropBind()
{
string strSql = "Select * from AdminUser";
DataSet myds1= new DataSet();
myds1 = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet(strSql);
/////////////// 填充 搜索 中下拉列表 ///////////
this.ddl_username.DataSource = myds1.Tables[0].DefaultView;
this.ddl_username.DataTextField = "username";
this.ddl_username.DataValueField = "username";
this.ddl_username.DataBind();
//////////////// 以下两条代码为什么会无效? 而在 News_Add.aspx 中却有效 ///////////////////////////////////////////
this.ddl_username.Items.Add(new ListItem(" 请选择用户 ","0"));
this.ddl_username.SelectedValue="0";
}
}
}
Purview_User_Manage_Left.aspx:系统所有的权限(功能)树
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace YljWeb._Admin.Purview_Manage
{
/// <summary>
/// Purview_User_Manage_Left 的摘要说明。
/// </summary>
public class Purview_User_Manage_Left : System.Web.UI.Page
{
protected Microsoft.Web.UI.WebControls.TreeView TreeViewAll;
protected System.Web.UI.WebControls.Label lbl_Curnodeid;
protected YljWeb.Classes.TreeControl tree=new YljWeb.Classes.TreeControl();
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)//该页是否是为响应客户端而产生的或者是否是首次访问,系统自动生成
{
BindTreeViewAll();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void BindTreeViewAll()
{
string str_Sql="select * from Purview_All order by order_id";
if (YljWeb.Classes.SqlConn.IsExist(str_Sql)) // 遍历树
{
tree.BindTreeView1("nodeid","parentid","location","mytext",str_Sql,"middFrame","Purview_User_Manage_Midd.aspx",lbl_Curnodeid,TreeViewAll);
}
}
}
}
Purview_User_Manage_Midd.aspx:用户权限管理的操作部分
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace YljWeb._Admin.Purview_Manage
{
/// <summary>
/// Purview_User_Manage_Midd 的摘要说明。
/// </summary>
public class Purview_User_Manage_Midd : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lbl_select_node;
protected System.Web.UI.WebControls.Button btn_purview_add;
protected System.Web.UI.WebControls.Label lbl_purview_retract;
protected System.Web.UI.WebControls.Button btn_purview_retract;
protected string selusername;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(Request["location"]!=null )
{
if( Session["Purview_User_Username"]!=null)
{
selusername = Session["Purview_User_Username"].ToString();
this.lbl_select_node.Text = Request["location"].ToString();
this.lbl_select_node.Visible = false;
this.btn_purview_add.Enabled = true;
if(Request["location"].ToString() != "0_1_")
{
Check_ParentNode_State();
}
}
else
{
this.ShowErrMsg("请先选择用户!");
}
}
if(Request["location2"]!=null && Session["Purview_User_Username"]!=null)
{
if( Session["Purview_User_Username"]!=null)
{
this.lbl_purview_retract.Text = Request["location2"].ToString();
this.lbl_purview_retract.Visible = false;
this.btn_purview_retract.Enabled = true;
selusername = Session["Purview_User_Username"].ToString();
}
else
{
this.ShowErrMsg("请先选择用户!");
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btn_purview_add.Click += new System.EventHandler(this.btn_purview_add_Click);
this.btn_purview_retract.Click += new System.EventHandler(this.btn_purview_retract_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btn_purview_retract_Click(object sender, System.EventArgs e)
{
string strSqlUpdate="Update Purview_User_Have set state = 0 where username='"+ selusername +"' and location like '"+ this.lbl_purview_retract.Text +"%'";
YljWeb.Classes.SqlConn.ExecuteSql(strSqlUpdate);
this.lbl_purview_retract.Text = "成功收回";
this.Response.Write("<script language=\"javascript\">parent.frames(\"rightFrame\").document.location.reload();</"+"script>");
Response.Write("<meta http-equiv=refresh content=0;url=Purview_User_Manage_Midd.aspx>");
}
private void btn_purview_add_Click(object sender, System.EventArgs e)
{
string strSqlUpdate="Update Purview_User_Have set state = 1 where username='"+ selusername +"' and location = '"+ this.lbl_select_node.Text +"'";
YljWeb.Classes.SqlConn.ExecuteSql(strSqlUpdate);
this.lbl_select_node.Text = "成功填加";
this.Response.Write("<script language=\"javascript\">parent.frames(\"rightFrame\").document.location.reload();</"+"script>");
Response.Write("<meta http-equiv=refresh content=0;url=Purview_User_Manage_Midd.aspx>");
}
private void Check_ParentNode_State()
{
string str_Sql="select parentid from Purview_User_Have where username='"+ selusername +"' and location = '"+ Request["location"].ToString() +"'";
DataSet ds = YljWeb.Classes.SqlConn.ExecuteSqlForDataSet(str_Sql);
DataRow dr = ds.Tables[0].Rows[0];
string str_parentid = dr[0].ToString();
string str_Sql2="select * from Purview_User_Have where username='"+ selusername +"' and location = '"+ str_parentid +"' and state = 1 ";
if( !YljWeb.Classes.SqlConn.IsExist(str_Sql2) )
{
this.ShowErrMsg("请先填加其上一级权限!");
this.lbl_select_node.Text = "";
this.btn_purview_add.Enabled = false;
}
}
/// <summary>
/// ////////////////////////////// 弹出消息框 ////////////////////////////////////////
/// </summary>
/// <param name="MsgStr"></param>
private void ShowErrMsg(string MsgStr)
{
this.Response.Write("<script language='javascript'>");
this.Response.Write("alert('" +MsgStr + "');");
this.Response.Write("</script>");
}
}
}
Purview_User_Manage_Right.aspx:用户已经有的权限树
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace YljWeb._Admin.Purview_Manage
{
/// <summary>
/// Purview_User_Manage_Right 的摘要说明。
/// </summary>
public class Purview_User_Manage_Right : System.Web.UI.Page
{
protected Microsoft.Web.UI.WebControls.TreeView TreeViewHave;
protected System.Web.UI.WebControls.Label lbl_Curnodeid;
protected YljWeb.Classes.TreeControl tree=new YljWeb.Classes.TreeControl();
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)//该页是否是为响应客户端而产生的或者是否是首次访问,系统自动生成
{
if( Session["Purview_User_Username"] != null)
{
BindTreeViewHave();
}
else
{
this.lbl_Curnodeid.Visible = true;
this.lbl_Curnodeid.Text = "请选择用户!";
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void BindTreeViewHave()
{
string username = Session["Purview_User_Username"].ToString();
string str_Sql="select * from Purview_User_Have where username ='"+ username +"'and state = 1 order by order_id";
if (YljWeb.Classes.SqlConn.IsExist(str_Sql)) // 遍历树
{
tree.BindTreeView2("nodeid","parentid","location","mytext",str_Sql,"middFrame","Purview_User_Manage_Midd.aspx",lbl_Curnodeid,TreeViewHave);
}
}
}
}