using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
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 System.Xml.Linq;

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindDataGrid();
            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("添加修改部门.aspx?id=" + "");
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("main.aspx");
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            BLL.dept dep = new BLL.dept();
            gvwDep.DataSource = dep.select("deptid='" + TextBox2.Text + "'");
            gvwDep.DataBind();
        }

        public void bindDataGrid()
        {
            BLL.dept dep = new BLL.dept();
            gvwDep.DataSource = dep.select("");
            gvwDep.DataKeyNames = new string[] { "deptid" };
            gvwDep.DataBind();
        }

        protected void gvwDep_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string deptrid = e.CommandArgument.ToString();
            if (e.CommandName == "Edit")
            {
                Response.Redirect("添加修改部门.aspx?id=" + deptrid);
            }
        }

        protected void gvwDep_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string deptrid = this.gvwDep.DataKeys[e.RowIndex].Value.ToString();
            BLL.dept dep = new BLL.dept();
            dep.delete(deptrid);
            Response.Write("<script>alert('删除成功')</script>");
            bindDataGrid();
        }
    }
}
