📄 editrole.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;
using Wrox.WebModules.Accounts.Business;
using Wrox.WebModules.Accounts;
namespace Wrox.WebModules.Accounts.Web
{
/// <summary>
/// Summary description for EditRole.
/// </summary>
public class EditRole : Wrox.ThePhile.Web.PhilePage
{
protected System.Web.UI.WebControls.Label RoleLabel;
protected System.Web.UI.WebControls.ListBox CategoryList;
protected System.Web.UI.WebControls.ListBox PermissionList;
protected Wrox.ThePhile.Web.Controls.Server.Navigator MenuNav;
protected System.Web.UI.WebControls.Button RemovePermissionButton;
protected System.Web.UI.WebControls.Button AddPermissionButton;
protected System.Web.UI.WebControls.DropDownList PermissionDropList;
protected System.Web.UI.WebControls.Button RemoveRoleButton;
protected System.Web.UI.WebControls.LinkButton ManageAssignmentsLink;
private Role currentRole;
private void DoInitialDataBind()
{
currentRole = new Role(Convert.ToInt32(Request["RoleID"]));
RoleLabel.Text = "Current Role: " + currentRole.Description;
PermissionList.Items.Clear();
RemovePermissionButton.Visible = false;
CategoryList.DataSource = currentRole.Permissions.Tables["Categories"];
CategoryList.DataTextField = "Description";
CategoryList.DataValueField = "CategoryID";
CategoryList.DataBind();
DataSet allPermissions = AccountsTool.GetAllPermissions();
PermissionDropList.DataSource = allPermissions.Tables["Permissions"];
PermissionDropList.DataTextField = "Description";
PermissionDropList.DataValueField = "PermissionID";
PermissionDropList.DataBind();
}
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
SitePrincipal currentPrincipal = (SitePrincipal)Context.User;
if (!currentPrincipal.HasPermission((int)AccountsPermissions.UpdateRoles))
{
Response.Write("You don't have sufficient permission to be using this page.");
Response.End();
}
if (!Page.IsPostBack)
{
DoInitialDataBind();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
base.OnInit(e);
InitializeComponent();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.ManageAssignmentsLink.Click += new System.EventHandler(this.ManageAssignmentsLink_Click);
this.CategoryList.SelectedIndexChanged += new System.EventHandler(this.CategoryList_SelectedIndexChanged);
this.PermissionList.SelectedIndexChanged += new System.EventHandler(this.PermissionList_SelectedIndexChanged);
this.RemovePermissionButton.Click += new System.EventHandler(this.RemovePermissionButton_Click);
this.AddPermissionButton.Click += new System.EventHandler(this.AddPermissionButton_Click);
this.RemoveRoleButton.Click += new System.EventHandler(this.RemoveRoleButton_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void SelectCategory(int categoryId, bool forceSelection)
{
if (forceSelection)
{
CategoryList.SelectedIndex = CategoryList.Items.IndexOf (
CategoryList.Items.FindByValue( categoryId.ToString() ));
}
currentRole = new Role(Convert.ToInt32(Request["RoleID"]));
DataTable categories = currentRole.Permissions.Tables["Categories"];
DataRow currentCategory = categories.Rows.Find( categoryId );
if (currentCategory != null)
{
DataRow[] permissions = currentCategory.GetChildRows("PermissionCategories");
PermissionList.Items.Clear();
foreach (DataRow currentRow in permissions)
{
PermissionList.Items.Add(
new ListItem( (string)currentRow["Description"], Convert.ToString(currentRow["PermissionID"])) );
}
}
}
private void CategoryList_SelectedIndexChanged(object sender, System.EventArgs e)
{
SelectCategory( Convert.ToInt32(CategoryList.SelectedItem.Value), false );
}
private void RemovePermissionButton_Click(object sender, System.EventArgs e)
{
int currentRole = Convert.ToInt32(Request["RoleID"]);
Role bizRole = new Role(currentRole);
bizRole.RemovePermission( Convert.ToInt32(PermissionList.SelectedItem.Value) );
DoInitialDataBind();
SelectCategory( Convert.ToInt32(Request["CategoryList"]), true );
}
private void PermissionList_SelectedIndexChanged(object sender, System.EventArgs e)
{
RemovePermissionButton.Visible = true;
}
private void AddPermissionButton_Click(object sender, System.EventArgs e)
{
int currentRole = Convert.ToInt32(Request["RoleID"]);
Role bizRole = new Role(currentRole);
bizRole.AddPermission( Convert.ToInt32(PermissionDropList.SelectedItem.Value) );
DoInitialDataBind();
SelectCategory( Convert.ToInt32(Request["CategoryList"]), true);
}
private void RemoveRoleButton_Click(object sender, System.EventArgs e)
{
int currentRole = Convert.ToInt32(Request["RoleID"]);
Role bizRole = new Role(currentRole);
bizRole.Delete();
Server.Transfer("roles.aspx");
}
private void ManageAssignmentsLink_Click(object sender, System.EventArgs e)
{
Server.Transfer("RoleAssignments.aspx?RoleID="+Request["RoleID"]);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -