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

public partial class SystemManage_AreaManage : System.Web.UI.Page
{
    private static readonly string sqlcmd1 = "select * from CLIENT_AREA order by id desc";
    private readonly static string sqlcmd2 = "delete from CLIENT_AREA where id =";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Convert.ToString(Session["username"]) == "")
        {
            Response.Write("<script language=javascript>alert('请登录');location='../login.aspx'</script>");
            return;
        }
        if (!IsPostBack)
        {
            this.Bind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("AddArea.aspx");
    }

    public void Bind()
    {
        using (SqlConnection sqlconn = new SqlConnection(Tools.strConn))
        {
            sqlconn.Open();
            SqlDataAdapter sda = new SqlDataAdapter(sqlcmd1, sqlconn);
            DataSet ds = new DataSet("CLIENT_AREA");
            sda.Fill(ds, "CLIENT_AREA");
            GridView1.DataSource = ds.Tables["CLIENT_AREA"];
            GridView1.DataKeyNames = new string[] { "id" };
            GridView1.DataBind();
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        this.Bind();
    }

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
        using (SqlConnection sqlconn = new SqlConnection(Tools.strConn))
        {
            sqlconn.Open();
            SqlCommand cmd = new SqlCommand((sqlcmd2 + id), sqlconn);
            cmd.ExecuteNonQuery();
            this.Bind();
        }
    }
}
