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 secar : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
            }
        }
        public static SqlConnection conn = null;
        public static SqlCommand cmd = null;
        public static string connstr = ConfigurationSettings.AppSettings["connstr"];

        public void bind()
        {
            BLL.Class1 bc = new BLL.Class1();
            gvwDep.DataSource = bc.select("");
            gvwDep.DataKeyNames = new string[] { "c_carID" };
            gvwDep.DataBind();
        }

        protected void btnAdd_Click(object sender, EventArgs e)

        {
            Response.Redirect("cars.aspx?m="+btnAdd.Text);
        }

        

        protected void gvwDep_RowCommand(object sender, GridViewCommandEventArgs e)
        {
           
            string carid = e.CommandArgument.ToString();
            if (e.CommandName == "Edit")
            {
                Response.Redirect("cars.aspx?m=" + "修改," + carid);
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            BLL.Class1 bc = new BLL.Class1();
            if (TextBox2.Text != "")
            {
                DataSet d=bc.select("c_carID=" + "'" + TextBox2.Text + "'");
                try
                {
                    if (d.Tables[0].Rows[0].ToString() != "")
                    {
                        gvwDep.DataSource = bc.select("c_carID=" + "'" + TextBox2.Text + "'");
                        gvwDep.DataKeyNames = new string[] { "c_carID" };
                        gvwDep.DataBind();
                        Response.Write(d.Tables[0].ToString());
                    }
                }
                catch
                {
                    Response.Write("<script>alert(' 您要查找的车辆不存在','提示')</script>");
                }
            }
            else
                bind();
        }

        protected void gvwDep_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            BLL.Class1 bc = new BLL.Class1();
            if (bc.delete(gvwDep.DataKeys[e.RowIndex].Value.ToString()))
            {
                Response.Write("<script>alert(' 删除成功')</script>");
                bind();
            }
            else
                Response.Write("<script>alert(' 删除失败')</script>");
        }

       

        
        

       
    }
}
