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

📄 dutydepartmentmain.aspx.cs

📁 Asp·net2·0值班管理系统源码 值班部门管理、值班人员管理、值班表管理
💻 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;

public partial class DutyDepartmentMain : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            bindDepartment();
        }
    }

    private void bindDepartment()
    {
        if (DepartmentDao.dsDepartment() == null || (DepartmentDao.dsDepartment()).Tables[0].Rows.Count == 0)
        {
            this.Label1.Visible = true;
            this.GridView1.Visible = false;
        }
        else
        {
            this.GridView1.Visible = true;
            this.GridView1.DataSource = DepartmentDao.dsDepartment();
            this.GridView1.DataBind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(this.TextBox1.Text))
        {
            this.Label2.Text = "名称不能留空!";
        }
        else if (string.IsNullOrEmpty(this.TextBox2.Text))
        {
            this.Label2.Text = "编号不能留空!";
        }
        else
        {
            DepartmentPo dp = new DepartmentPo();
            dp.DepartName = this.TextBox1.Text;
            dp.DepartId = this.TextBox2.Text;
            DepartmentDao.insertDepartment(dp);
            this.Label2.Text = "";
            this.TextBox1.Text = "";
            this.TextBox2.Text = "";
            bindDepartment();
        }

    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        this.GridView1.EditIndex = e.NewEditIndex;
        bindDepartment();

    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        this.GridView1.EditIndex = -1;
        bindDepartment();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string name = ((TextBox)(this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text;
        string id = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;

        int keyId = Int32.Parse(this.GridView1.DataKeys[e.RowIndex].Value.ToString());
        DepartmentPo dp = new DepartmentPo();
        dp.DepartId = id;
        dp.DepartName = name;
        DepartmentDao.updateDepartment(dp,keyId);
        this.GridView1.EditIndex = -1;
        bindDepartment();

    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        //删除
        int keyId = Int32.Parse(this.GridView1.DataKeys[e.RowIndex].Value.ToString());
        DepartmentDao.deleteDepart(keyId);
        bindDepartment();
    }
}

⌨️ 快捷键说明

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