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;
using System.Data.SqlClient;

namespace WebApplication1
{
    public partial class 通讯录 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindDataGrid();
            }
        }
        public void bindDataGrid()
        {
            BLL.tel bt = new BLL.tel();
            gvwTel.DataSource = bt.select("");
            gvwTel.DataKeyNames = new string[] { "txname" };
            gvwTel.DataBind();
        }

        protected void gvwTel_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string tname = e.CommandArgument.ToString();
            if (e.CommandName == "Edit")
            {
                Response.Redirect("添加修改通讯录.aspx?tn=" + tname);
            }
        }

        protected void gvwTel_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string txname = this.gvwTel.DataKeys[e.RowIndex].Value.ToString();
            BLL.tel bt = new BLL.tel();
            bt.delete(txname);
            Response.Write("<script>alert('删除成功')</script>");
            bindDataGrid();
        }

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

        protected void Button1_Click(object sender, EventArgs e)
        {
            BLL.tel bt = new BLL.tel();
            gvwTel.DataSource = bt.select("txname='" + TextBox1.Text + "'");
            gvwTel.DataBind();
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("添加修改通讯录.aspx?tn=" + "");
        }
    }
}
