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;

namespace WebApplication1
{
    public partial class cars : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string btn = Request.QueryString["m"];
            string[] arry = btn.Split(',');
            string btname = arry[0];
            
           
            btnLogin.Text = btname;
            if (btname == "修改"&&!IsPostBack)
            {
                string btid = arry[1];
                DataTable dt = (bc.select("c_carID=" +"'"+ btid+"'")).Tables[0];
                area.Text = dt.Rows[0][0].ToString().Substring(0,1);
                Textid.Text = dt.Rows[0][0].ToString().Substring(1,dt.Rows[0][0].ToString().Length-1);
                Textpp.Text = dt.Rows[0][1].ToString();
                Textdr.Text = dt.Rows[0][2].ToString();
                zhuangtai.Text = dt.Rows[0][3].ToString();
            }
        }
        BLL.Class1 bc = new BLL.Class1();
        model.car mc = new model.car();
        bool f = false;
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (btnLogin.Text == "添加")
            {
              
                if (Textid.Text != "")
                {
                    if (Textpp.Text != "")
                    {
                        if (Textdr.Text != "")
                        {
                            mc.c_carID = area.Text + Textid.Text;
                            mc.c_cartype = Textpp.Text;
                            mc.c_driver = Textdr.Text;
                            mc.c_stau = zhuangtai.Text;
                            f = bc.insercar(mc);
                            if (f)
                            {
                                Response.Write("<script>alert(' 添加成功')</script>");
                                Textid.Text = "";
                                Textpp.Text = "";
                                Textdr.Text = "";
                                zhuangtai.Text = "";
                            }
                            else
                            {
                                Response.Write("<script>alert(' 添加失败')</script>");
                            }
                        }
                        else
                        {
                            Response.Write("<script>alert(' 司机不能为空')</script>");
                        }

                    }
                    else
                    {
                        Response.Write("<script>alert('品牌不能为空')</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('车牌号不能空')</script>");
                }
            }
            if (btnLogin.Text == "修改")
            {

                string btn = Request.QueryString["m"];
                string[] arry = btn.Split(',');
                string oldcarid=arry[1];
                mc.c_carID = area.Text + Textid.Text;
                mc.c_cartype = Textpp.Text;
                mc.c_driver = Textdr.Text;
                mc.c_stau = zhuangtai.Text;
               f= bc.update(mc, oldcarid);
               if (f)
               {
                   Response.Write("<script>alert(' 修改成功')</script>");
               }
               else
               {
                   Response.Write("<script>alert(' 修改失败')</script>");
               }
            }
        }

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