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.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace WebApplication1
{
    public partial class 添加修改部门 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        private void BindData()
        {
            string id = Request.QueryString["id"];
            if (!string.IsNullOrEmpty(id))
            {
                BLL.dept Stu = new BLL.dept();
                Model.dept mStu = new Model.dept();
                DataTable dt = Stu.select("deptid='" + id + "'");
                txtNum.Text = dt.Rows[0]["deptid"].ToString();
                txtNam.Text = dt.Rows[0]["deptname"].ToString();
                txtInfo.Text = dt.Rows[0]["deptintro"].ToString();
            }
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string id = Request.QueryString["id"];
            if (id == "")
            {
                BLL.dept Stu = new BLL.dept();
                Model.dept mStu = new Model.dept();
                mStu.deptid = txtNum.Text;
                mStu.deptname = txtNam.Text;
                mStu.deptintro = txtInfo.Text;
                Stu.insert(mStu);
                Response.Write("<script>alert('添加成功')</script>");
            }
            else
            {
                BLL.dept Stu = new BLL.dept();
                Model.dept mStu = new Model.dept();
                mStu.deptid = txtNum.Text;
                mStu.deptname = txtNam.Text;
                mStu.deptintro = txtInfo.Text;
                Stu.update(mStu, id);
                Response.Write("<script>alert('修改成功')</script>");
            }
        }
        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("部门管理.aspx");
        }
    }
}
