⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rolemanage.aspx.cs

📁 办公系统办公系统办公系统办公系统办公系统办公系统办公系统办公系统办公系统办公系统办公系统办公系统办公系统办公系统办公系统
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Office.Model;
using Office.BLL;

public partial class SysManage_RoleManage_RoleManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Bind();
            this.btnSave.Enabled = false;
        }
    }
    //数据绑定
    private void Bind()
    {
        this.GridView1.DataSource = RoleInfoManager.GetAllRoleInfos();
        this.GridView1.DataBind();
    }
    //添加
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        RoleInfo role = new RoleInfo();
        role.RoleName = TextBox1.Text;
        role.RoleDesc = TextBox2.Text;
        RoleInfoManager.AddRoleInfo(role);
        Bind();
        setContorl();
    }
    //初始化控件属性值
    private void setContorl()
    {
        this.TextBox1.Text = "";
        this.TextBox2.Text = "";
    }
    //GridView数据行绑定事件
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //在数据行进行绑定时添加光标称进、移出的效果,并设背景
            e.Row.Attributes.Add("onmouseover", "this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#FFFBD1'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor");

            ImageButton img = e.Row.FindControl("ImageButton2") as ImageButton;
            if (img != null)
            {
                img.Attributes.Add("onclick", "JavaScript:return confirm('你确定要删除吗?')");
            }
        }
    }
    //GridView命令行处理事件
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //修改
        if (e.CommandName == "modify")
        {
            Int32 roleId = Int32.Parse(e.CommandArgument.ToString());
            RoleInfo role = RoleInfoManager.GetRoleInfoByRoleId(roleId);
            this.TextBox1.Text = role.RoleName;
            this.TextBox2.Text = role.RoleDesc;
            ViewState["RoleId"] = role.RoleId;
            this.btnSave.Enabled = true;
            this.btnAdd.Enabled = false;
        }
        //删除
        if (e.CommandName == "del")
        {
            Int32 roleId = Int32.Parse(e.CommandArgument.ToString());
            RoleInfoManager.DeleteRoleInfoById(roleId);
            Bind();
            setContorl();
        }
        //分配权限
        if (e.CommandName == "link")
        {
            Int32 roleId = Int32.Parse(e.CommandArgument.ToString());
            Response.Redirect("DistributeRole.aspx?RID=" + roleId);
        }
    }
    //保存修改后的数据
    protected void btnSave_Click(object sender, EventArgs e)
    {
        RoleInfo role = new RoleInfo();
        role.RoleId = Int32.Parse(ViewState["RoleId"].ToString());
        role.RoleName = TextBox1.Text;
        role.RoleDesc = TextBox2.Text;
        RoleInfoManager.ModifyRoleInfo(role);
        this.btnSave.Enabled = false;
        this.btnAdd.Enabled = true;
        Bind();
        setContorl();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -