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;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string connectionString = "Data Source=zf;Initial Catalog=SQL_Data;Integrated Security=True";
            DataClassesDataContext db = new DataClassesDataContext(connectionString);
            var result = from r in db.仓库
                         select r;
            GridView1.DataSource = result;
            GridView1.DataBind();
        }
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ((LinkButton)(e.Row.Cells[4].Controls[0])).Attributes.Add("onclick", "return confirm('确定要删除吗？')");
        }
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string connectionString = "Data Source=zf;Initial Catalog=SQL_Data;Integrated Security=True";
        DataClassesDataContext db = new DataClassesDataContext(connectionString);
        var result = from r in db.仓库
                   where r.仓库号 == GridView1.DataKeys[e.RowIndex].Value.ToString() 
                    select r;
        db.仓库.DeleteAllOnSubmit(result);
        db.SubmitChanges();
        string connectionString1 = "Data Source=zf;Initial Catalog=SQL_Data;Integrated Security=True";
        DataClassesDataContext db1 = new DataClassesDataContext(connectionString1);
        var result1 = from r in db1.仓库
                     select r;
        GridView1.DataSource = result1;
        GridView1.DataBind();
    }
}
