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"; } }
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>"); } }