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

📄 branchmanage.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.DAL;
using Office.BLL;

public partial class PersonManage_BranchManager : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            this.MyBind();
            this.btn_save.Enabled = false;
        }
    }
    //数据绑定
    private void MyBind()
    {
        this.GridView1.DataSource = BranchInfoManager.GetAllBranchInfos();
        this.GridView1.DataBind();
    }

    //数据插入
    public void InsertBranch()
    {
        BranchInfo branch = new BranchInfo();
        branch.BranchName = this.txt_branchname.Text;
        branch.BranchShortName = this.txt_branchDesc.Text;

        BranchInfoManager.AddBranchInfo(branch);
        this.txt_branchname.Text = "";
        this.txt_branchDesc.Text = "";
        this.MyBind();
    }
    //数据获得
    public void GetBranch(Int32 branchId)
    {
        BranchInfo branch = BranchInfoManager.GetBranchInfoByBranchId(branchId);
        if(branch != null)
        {
            this.txt_branchname.Text = branch.BranchName;
            this.txt_branchDesc.Text = branch.BranchShortName;
        }
    }

    //数据修改
    public void UpdateBranch()
    {
        BranchInfo branch = new BranchInfo();
        branch.BranchId = Int32.Parse(ViewState["branchid"].ToString());
        branch.BranchName = this.txt_branchname.Text;
        branch.BranchShortName = this.txt_branchDesc.Text;
        BranchInfoManager.ModifyBranchInfo(branch);
        this.MyBind();
    }
    //添加事件
    protected void Button1_Click(object sender, EventArgs e)
    {
        this.InsertBranch();
        MyBind();
    }
    //修改事件
    protected void bt_save_Click(object sender, EventArgs e)
    {
        btn_add.Enabled = true;
        btn_save.Enabled = false;
        this.UpdateBranch();
        MyBind();
    }
    //GridView事件处理
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //修改
        if (e.CommandName == "modify")
        {
            btn_save.Enabled = true;
            btn_add.Enabled = false;
            Int32 branchId = Int32.Parse(e.CommandArgument.ToString());
            ViewState["branchid"] = branchId;
            this.GetBranch(branchId);
            MyBind();
        }
        //删除
        if (e.CommandName == "dele")
        {
            BranchInfoManager.DeleteBranchInfoById(Int32.Parse(e.CommandArgument.ToString()));
            MyBind();
        }
    }
    //GridView数据行绑定事件
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "oldcolor=this.style.backgroundColor;this.style.backgroundColor='lightYellow'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=oldcolor");

            ImageButton ibn = e.Row.FindControl("ImageButton2") as ImageButton;
            if (ibn != null)
            {
                ibn.Attributes.Add("onclick", "return confirm('你确定要删除该机构吗?')");
            }
        }
    }
}

⌨️ 快捷键说明

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