using System;
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;
public partial class _Default : System.Web.UI.Page 
{

    SqlConnection sqlcon;
    string ConStr = "server=(local);user id=myzf;pwd=123456;database=SQL_Data";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)    //首次执行页面时执行如下代码
        {
            sqlcon = new SqlConnection(ConStr);
            string SqlStr = "select * from 仓库信息";
            SqlDataAdapter ada = new SqlDataAdapter(SqlStr, sqlcon);
            sqlcon.Open();
            DataSet ds = new DataSet();
            ada.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataKeyNames = new string[] { "仓库号" };
            GridView1.DataBind();
            sqlcon.Close();
        }

    }
    protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
    {
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
            if (CheckBox2.Checked == true)
            {
                cbox.Checked = true;
            }
            else
            {
                cbox.Checked = false;
            }
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        CheckBox2.Checked = false;
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
            cbox.Checked = false;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        sqlcon = new SqlConnection(ConStr);
        SqlCommand sqlcom;
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
            if (cbox.Checked == true)
            {

                string sqlstr = "delete from 仓库信息 where 仓库号='" + GridView1.DataKeys[i].Value + "'";
                sqlcon.Open();
                sqlcom = new SqlCommand(sqlstr, sqlcon);
                sqlcom.ExecuteNonQuery();
                sqlcon.Close();
            }
        }
        string SqlStr = "select * from 仓库信息";
        SqlDataAdapter ada = new SqlDataAdapter(SqlStr, sqlcon);
        sqlcon.Open();
        DataSet ds = new DataSet();
        ada.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataKeyNames = new string[] { "仓库号" };
        GridView1.DataBind();
        sqlcon.Close();
    }
}
