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();
            }
        }
        private void BindData()
        {
            string tn = Request.QueryString["tn"];
            if (!string.IsNullOrEmpty(tn))
            {
                BLL.tel Stu = new BLL.tel();
                Model.tel mStu = new Model.tel();
                DataTable dt = Stu.select("txname='" + tn + "'");
                txtName.Text = dt.Rows[0]["txname"].ToString();
                txtMember.Text = dt.Rows[0]["txmember"].ToString();
                txtDepart.Text = dt.Rows[0]["txuser"].ToString();
                txtInfro.Text = dt.Rows[0]["txintro"].ToString();
            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string tn = Request.QueryString["tn"];
            if (tn == "")
            {
                BLL.tel Stu = new BLL.tel();
                Model.tel mStu = new Model.tel();
                mStu.txname = txtName.Text;
                mStu.txmember = txtMember.Text;
                mStu.txuser = txtInfro.Text;
                mStu.txintro = txtInfro.Text;
                Stu.insert(mStu);
                Response.Write("<script>alert('添加成功')</script>");
            }
            else
            {
                BLL.tel Stu = new BLL.tel();
                Model.tel mStu = new Model.tel();
                mStu.txname = txtName.Text;
                mStu.txmember = txtMember.Text;
                mStu.txuser = txtInfro.Text;
                mStu.txintro = txtInfro.Text;
                Stu.update(mStu, tn);
                Response.Write("<script>alert('修改成功')</script>");
            }
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("通讯录.aspx");
        }
    }
}
