Example #1
0
        public bool Actualizar(CocheEN coche)
        {
            bool update = false;

            string cmd = "update coche set marca = '" + coche.Marca + "', modelo = '" + coche.Modelo + "', precio = '" + coche.Precio + "', puertas = '" + coche.Puertas + "', motor = '" + coche.Motor + "', km = '" + coche.Km + "', anyo = '" + coche.Anyo + "', combustible = '" + coche.Tipo + "', plazas = '" + coche.Plazas + "', cambio = '" + coche.Cambio + "', color = '" + coche.Color + "' where matricula = '" + coche.Matricula + "'";

            SqlConnection con = new SqlConnection(conexion);

            try
            {
                con.Open();
                SqlCommand c = new SqlCommand(cmd, con);
                c.ExecuteNonQuery();
                update = true;
            }
            catch (Exception e)
            {
                update = false;
            }
            finally
            {
                con.Close();
            }
            return(update);
        }
Example #2
0
        public CocheEN[] ExtraerPorTipo(string tipo)
        {
            List <CocheEN> coches = new List <CocheEN>();
            CocheEN        nCar;
            string         comando = "select * from coche where tipo='" + tipo + "'";
            SqlConnection  con     = new SqlConnection(conexion);

            try
            {
                con.Open();
                SqlCommand    c  = new SqlCommand(comando, con);
                SqlDataReader dr = c.ExecuteReader();
                while (dr.Read())
                {
                    nCar = new CocheEN((string)dr[0], (string)dr[1], (string)dr[2], double.Parse((string)dr[3]), int.Parse((string)dr[4]), (string)dr[5], double.Parse((string)dr[6]), int.Parse((string)dr[7]), (string)dr[8], int.Parse((string)dr[9]), (string)dr[10], (string)dr[11], (string)dr[12]);
                    coches.Add(nCar);
                }
                dr.Close();
            }
            catch (Exception e)
            {
            }
            con.Close();
            return(coches.ToArray());
        }
Example #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            CocheEN car = new CocheEN();

            CocheEN[] listaCoche = car.ExtraerTipo("Electrico");
            DataTable tabla      = new DataTable();

            tabla.Columns.Add("Imagen");
            tabla.Columns.Add("Marca");
            tabla.Columns.Add("Modelo");
            tabla.Columns.Add("Precio");
            tabla.Columns.Add("Tipo");
            tabla.Columns.Add("Puertas");
            tabla.Columns.Add("Color");
            tabla.Columns.Add("Cambio");

            for (int i = 0; i < listaCoche.Length; i++)
            {
                DataRow row = tabla.NewRow();
                row["Imagen"]  = listaCoche[i].Imagen;
                row["Marca"]   = listaCoche[i].Marca;
                row["Modelo"]  = listaCoche[i].Modelo;
                row["Precio"]  = listaCoche[i].Precio;
                row["Color"]   = listaCoche[i].Color;
                row["Puertas"] = listaCoche[i].Puertas;
                row["Tipo"]    = listaCoche[i].Tipo;
                row["Cambio"]  = listaCoche[i].Cambio;
                tabla.Rows.Add(row);
            }

            ListProducts.DataSource = tabla;
            ListProducts.DataBind();
        }
Example #4
0
        public CocheEN[] SacarCoches()
        {
            List <CocheEN> coches = new List <CocheEN>();
            CocheEN        coche;
            string         comando = "select * from coche";
            SqlConnection  con     = new SqlConnection(conexion);

            try
            {
                con.Open();
                SqlCommand    c  = new SqlCommand(comando, con);
                SqlDataReader dr = c.ExecuteReader();
                while (dr.Read())
                {
                    coche = new CocheEN((string)dr[0], (string)dr[1], (string)dr[2], double.Parse((string)dr[3]), int.Parse((string)dr[4]), (string)dr[5], double.Parse((string)dr[6]), int.Parse((string)dr[7]), (string)dr[8], int.Parse((string)dr[9]), (string)dr[10], (string)dr[11], (string)dr[12]);
                    coches.Add(coche);
                }
                dr.Close();
            }
            catch (Exception e)
            {
            }
            con.Close();
            return(coches.ToArray());
        }
Example #5
0
        //Saca la lista de coches asociados a la cesta
        public List <CocheEN> SacarCoches(string id)
        {
            List <CocheEN> coches = new List <CocheEN>();
            CocheEN        coche;
            string         comando = "select * from coche join CochesCesta on coche.matricula = CochesCesta.Coche where CochesCesta.Id = '" + id + "'";
            SqlConnection  con     = new SqlConnection(conexion);

            try
            {
                con.Open();
                SqlCommand    c  = new SqlCommand(comando, con);
                SqlDataReader dr = c.ExecuteReader();
                while (dr.Read())
                {
                    coche = new CocheEN((string)dr[0], (string)dr[1], (string)dr[2], double.Parse((string)dr[3]), int.Parse((string)dr[4]), (string)dr[5], double.Parse((string)dr[6]), int.Parse((string)dr[7]), (string)dr[8], int.Parse((string)dr[9]), (string)dr[10], (string)dr[11], (string)dr[12]);
                    coches.Add(coche);
                }
                dr.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            con.Close();
            return(coches);
        }
Example #6
0
        protected void Delete_Click(object sender, EventArgs e)
        {
            ClienteEN cli = new ClienteEN();

            cli = cli.sacarCliente(Session["Usuario"].ToString());
            CocheEN coche = new CocheEN();

            coche.SacarCoche(((ImageButton)sender).CommandArgument);
            CestaEN cesta = new CestaEN();

            cesta.SacarCesta(cli.nifCliente);
            cesta.DeleteCoche(coche);
            cesta.Actualizar();
        }
Example #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string  matricula = Request.QueryString["matricula"];
            CocheEN car       = new CocheEN();

            CocheEN Coche = car.SacarCar(matricula);

            DataTable tabla = new DataTable();

            tabla.Columns.Add("Matricula");
            tabla.Columns.Add("Marca");
            tabla.Columns.Add("Modelo");
            tabla.Columns.Add("Precio");
            tabla.Columns.Add("Puertas");
            tabla.Columns.Add("Motor");
            tabla.Columns.Add("Km");
            tabla.Columns.Add("Anyo");
            tabla.Columns.Add("Tipo");
            tabla.Columns.Add("Plazas");
            tabla.Columns.Add("Cambio");
            tabla.Columns.Add("Color");
            tabla.Columns.Add("Imagen");


            DataRow row = tabla.NewRow();

            row["Matricula"] = Coche.Matricula;
            row["Marca"]     = Coche.Marca;
            row["Modelo"]    = Coche.Modelo;
            row["Precio"]    = Coche.Precio;
            row["Puertas"]   = Coche.Puertas;
            row["Motor"]     = Coche.Motor;
            row["Km"]        = Coche.Km;
            row["Anyo"]      = Coche.Anyo;
            row["Tipo"]      = Coche.Tipo;
            row["Plazas"]    = Coche.Plazas;
            row["Cambio"]    = Coche.Cambio;
            row["Color"]     = Coche.Color;
            row["Imagen"]    = Coche.Imagen;
            tabla.Rows.Add(row);


            ListProducts.DataSource = tabla;
            ListProducts.DataBind();
        }
Example #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            CocheEN coc = new CocheEN();

            CocheEN[] listaCoches = coc.MostrarCoches();

            DataTable tabla = new DataTable();

            tabla.Columns.Add("Matricula");
            tabla.Columns.Add("Marca");
            tabla.Columns.Add("Modelo");
            tabla.Columns.Add("Precio");
            tabla.Columns.Add("Puertas");
            tabla.Columns.Add("Motor");
            tabla.Columns.Add("Km");
            tabla.Columns.Add("Anyo");
            tabla.Columns.Add("Tipo");
            tabla.Columns.Add("Plazas");
            tabla.Columns.Add("Cambio");
            tabla.Columns.Add("Color");
            tabla.Columns.Add("Imagen");

            for (int i = 0; i < listaCoches.Length; i++)
            {
                DataRow row = tabla.NewRow();
                row["Matricula"] = listaCoches[i].Matricula;
                row["Marca"]     = listaCoches[i].Marca;
                row["Modelo"]    = listaCoches[i].Modelo;
                row["Puertas"]   = listaCoches[i].Puertas;
                row["Motor"]     = listaCoches[i].Motor;
                row["Km"]        = listaCoches[i].Km;
                row["Anyo"]      = listaCoches[i].Anyo;
                row["Tipo"]      = listaCoches[i].Tipo;
                row["Plazas"]    = listaCoches[i].Plazas;
                row["Cambio"]    = listaCoches[i].Cambio;
                row["Color"]     = listaCoches[i].Color;
                row["Imagen"]    = listaCoches[i].Imagen;
                tabla.Rows.Add(row);
            }


            ListProducts.DataSource = tabla;
            ListProducts.DataBind();
        }
Example #9
0
        /*Con esta funcion insertaremos un coche en nuestra base de datos
         * devolvera verdadero cuando se inserte correctamente en caso contrario
         * devolvera false
         */
        public bool InsertarCoche(CocheEN c)
        {
            bool   insert  = false;
            string comando = "Insert into Coche (matricula,marca,modelo,precio,puertas,motor,km,anyo,tipo,plazas,cambio,color,imagen) values ('" + c.Matricula + "','" + c.Marca + "','" + c.Modelo + "','" + c.Precio + "','" + c.Puertas + "','" + c.Motor + "','" + c.Km + "','" + c.Anyo + "','" + c.Tipo + "','" + c.Plazas + "','" + c.Cambio + "','" + c.Color + "','" + c.Imagen + "')";

            SqlConnection con = new SqlConnection(conexion);

            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand(comando, con);
                cmd.ExecuteNonQuery();
                insert = true;
            }
            catch (Exception e)
            {
            }
            con.Close();
            return(insert);
        }
Example #10
0
        public CocheEN SacarCoche(string matricula)
        {
            CocheEN       coche   = new CocheEN();
            string        comando = "select * from coche where matricula = '" + matricula + "'";
            SqlConnection con     = new SqlConnection(conexion);

            try
            {
                con.Open();
                SqlCommand    c  = new SqlCommand(comando, con);
                SqlDataReader dr = c.ExecuteReader();
                dr.Read();
                coche = new CocheEN((string)dr[0], (string)dr[1], (string)dr[2], double.Parse((string)dr[3]), int.Parse((string)dr[4]), (string)dr[5], double.Parse((string)dr[6]), int.Parse((string)dr[7]), (string)dr[8], int.Parse((string)dr[9]), (string)dr[10], (string)dr[11], (string)dr[12]);

                dr.Close();
            }
            catch (Exception e)
            {
            }
            con.Close();
            return(coche);
        }
Example #11
0
        protected void Button_click(object sender, EventArgs e)
        {
            bool    insert  = false;
            CocheEN car     = new CocheEN();
            string  pla     = Request.Form["Plaza"];
            string  precios = Request.Form["Precio"];
            string  puertas = Request.Form["Puertas"];
            string  kms     = Request.Form["Km"];
            string  anyo    = Request.Form["Anyos"];

            car.Marca     = Request.Form["Marca"];
            car.Modelo    = Request.Form["Modelo"];
            car.Precio    = Convert.ToDouble(precios);
            car.Puertas   = Convert.ToInt32(puertas);
            car.Matricula = Request.Form["Matricula"];
            car.Motor     = Request.Form["Motor"];
            car.Km        = Convert.ToDouble(kms);
            car.Anyo      = Convert.ToInt32(anyo);
            car.Cambio    = Request.Form["Cambio"];
            car.Plazas    = Convert.ToInt32(pla);
            car.Tipo      = Request.Form["Tipo"];
            car.Color     = Request.Form["Color"];

            if ((file1.PostedFile != null) && (file1.PostedFile.ContentLength > 0))
            {
                if (file1.Value.EndsWith(".JPG") || file1.Value.EndsWith(".jpg") ||
                    file1.Value.EndsWith(".ico") || file1.Value.EndsWith(".ICO") ||
                    file1.Value.EndsWith(".gif") || file1.Value.EndsWith(".GIF") ||
                    file1.Value.EndsWith(".png") || file1.Value.EndsWith(".PNG"))
                {
                    string fn           = System.IO.Path.GetFileName(file1.PostedFile.FileName);
                    string SaveLocation = Server.MapPath(@"../Styles/images/products") + "//" + fn;

                    try
                    {
                        file1.PostedFile.SaveAs(SaveLocation);
                        Label1.Text = "El archivo se ha cargado.";
                        car.Imagen  = fn;
                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex.Message);
                    }
                }
                else
                {
                    Label1.Text = "No se pudo cargar el archivo seleccionado, por favor seleccione una imagen .jpg, .gif o .png";
                }
            }

            if (CheckBox1.Checked)
            {
                insert = car.InsertarCoche();
                if (insert == true)
                {
                    Response.Write("<script>window.alert('Se ha puesto a la venta su coche');</script>");
                }
                else
                {
                    Response.Write("<script>window.alert('No se ha podido poner a la venta, contacte con nosotros para cualquier duda');</script>");
                }
            }
            else
            {
                lab1.Text = "Debe de aceptar los terminos y condiciones";
            }
        }
Example #12
0
        protected void Button_click(object sender, EventArgs e)
        {
            bool    insert  = false;
            CocheEN car     = new CocheEN();
            string  pla     = Request.Form["Plaza"];
            string  precios = Request.Form["Precio"];
            string  puertas = Request.Form["Puertas"];
            string  kms     = Request.Form["Km"];
            string  anyo    = Request.Form["Anyos"];

            car.Marca     = Request.Form["Marca"];
            car.Modelo    = Request.Form["Modelo"];
            car.Precio    = Convert.ToDouble(precios);
            car.Puertas   = Convert.ToInt32(puertas);
            car.Matricula = Request.Form["Matricula"];
            car.Motor     = Request.Form["Motor"];
            car.Km        = Convert.ToDouble(kms);
            car.Anyo      = Convert.ToInt32(anyo);
            car.Cambio    = Request.Form["Cambio"];
            car.Plazas    = Convert.ToInt32(pla);
            car.Tipo      = Request.Form["Tipo"];
            car.Color     = Request.Form["Color"];

            if ((file1.PostedFile != null) && (file1.PostedFile.ContentLength > 0))
            {
                //comprobamos que el formato es el correcto para una fotografia
                if (file1.Value.EndsWith(".JPG") || file1.Value.EndsWith(".jpg") ||
                    file1.Value.EndsWith(".ico") || file1.Value.EndsWith(".ICO") ||
                    file1.Value.EndsWith(".gif") || file1.Value.EndsWith(".GIF") ||
                    file1.Value.EndsWith(".png") || file1.Value.EndsWith(".PNG"))
                {
                    string fn           = System.IO.Path.GetFileName(file1.PostedFile.FileName);
                    string SaveLocation = Server.MapPath(@"/Styles/images/products") + "//" + fn;

                    try
                    {
                        file1.PostedFile.SaveAs(SaveLocation);
                        //string SaveLocation2 = Server.MapPath("/ICoches/") + fn;
                        car.Imagen = fn;
                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex.Message);
                    }
                }
                else
                {
                    Response.Write("<script>window.alert('No es el formato correcto de imagen');</script>");
                }
            }


            insert = car.InsertarCoche();
            if (insert == true)
            {
                Response.Write("<script>window.alert('Se ha puesto a la venta el coche');</script>");
            }
            else
            {
                Response.Write("<script>window.alert('No se ha podido poner a la venta');</script>");
            }
        }
Example #13
0
 public bool InsertarCoche(CocheEN coche)
 {
     return(true);
 }