📄 roleadmin.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 qminoa.DA;
using qminoa.Common;
namespace qminoa.Webs.sysSecurity
{
public class Roleadmin : qminoa.Webs.PageBase
{
protected System.Web.UI.WebControls.DataList RolesList;
protected System.Web.UI.WebControls.TextBox RoleName;
protected System.Web.UI.WebControls.TextBox RoleDescription;
protected System.Web.UI.WebControls.LinkButton AddRoleBtn;
protected System.Web.UI.WebControls.Label lblErr;
private void Page_Load(object sender, System.EventArgs e)
{
this.PageBegin("角色管理",true);
if (Page.IsPostBack == false)
{
BindData();
}
}
#region Web Form Designer generated code
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);
this.AddRoleBtn.Click += new System.EventHandler(this.AddRoleBtn_Click);
this.RolesList.ItemCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.RolesList_ItemCommand);
this.RolesList.ItemDataBound += new System.Web.UI.WebControls.DataListItemEventHandler(this.OnAttachScript);
}
#endregion
private void BindData()
{
AdminDB admin = new AdminDB();
RolesList.DataSource = admin.GetAllRoles();
RolesList.DataBind();
}
private void RolesList_ItemCommand(object sender, DataListCommandEventArgs e)
{
AdminDB admin = new AdminDB();
int RoleID = (int) RolesList.DataKeys[e.Item.ItemIndex];
String RoleName=((System.Web.UI.WebControls.Label)e.Item.FindControl("lbRoleName")).Text;
String RoleDescription=((System.Web.UI.WebControls.Label)e.Item.FindControl("lbRoleDescription")).Text;
if (e.CommandName == "edit")
{
if(this.EmpRightCode >= 3)
Response.Redirect("RolesFuncUsers.aspx?roleid=" +RoleID,false);
else
JScript.Alert("您没有权限进行此操作!");
}
else if (e.CommandName == "delete")
{
if(this.EmpRightCode == 4)
{
if(admin.DeleteFuncRoleUser(RoleID,"role"))
{
this.WriteOptLog("删除角色"+RoleID.ToString()+"信息");
JScript.Alert("删除成功!");
}
else
{
JScript.Alert("数据库中存在此项相关索引,删除失败!");
}
BindData();
}
else
{
JScript.Alert("您没有权限进行此操作!");
}
}
}
private void OnAttachScript (object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
ImageButton button = (ImageButton) e.Item.FindControl("Imagebutton2");
button.Attributes.Add ("onclick",
"return confirm (\"确定要删除此项记录吗?\");");
}
}
private void AddRoleBtn_Click(object sender, System.EventArgs e)
{
if(this.EmpRightCode >=2 )
{
if(RoleName.Text.ToString()!="")
{
bool result = (new AdminDB()).InsertRoleInfo(RoleName.Text.ToString(),RoleDescription.Text.ToString());
BindData();
RoleName.Text = "";
RoleDescription.Text = "";
}
}
else
{
JScript.Alert("您没有权限进行此操作!");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -