protected void btn_buscar_Click(object sender, EventArgs e) { try { if (ddl_seleccionar.SelectedIndex == 0) { Response.Write("<script>alert('Debe asociar la imagen a un Proyecto, Servicio o Empresa.');</script>"); } else if (ddl_seleccionar.SelectedIndex == 1) { if (ddl_nombrePro.SelectedIndex != 0) { MantenedorFotosProyectos man = new MantenedorFotosProyectos(); string nombre = ddl_nombrePro.SelectedValue; txt_id.Text = man.BuscarFoto(nombre).Rows[0][0].ToString(); txt_descripcion.Text = man.BuscarFoto(nombre).Rows[0][1].ToString(); ddl_pro.Text = man.BuscarFoto(nombre).Rows[0][2].ToString(); txt_nombreimagen.Text = man.BuscarFoto(nombre).Rows[0][4].ToString(); SqlConnection sql = new SqlConnection(Conexion.CadenaDeConexion()); string query = "select imagen from fotoproyecto where nombreimagen='" + nombre + "'"; SqlCommand cm = new SqlCommand(query, sql); sql.Open(); cm.CommandTimeout = 0; byte[] img = (byte[])cm.ExecuteScalar(); System.Drawing.Image rImg = null; using (MemoryStream ms = new MemoryStream(img)) { rImg = System.Drawing.Image.FromStream(ms); imgPreview.ImageUrl = "data:image;base64," + Convert.ToBase64String(img); } } else { Response.Write("<script>alert('Debe seleccionar una imagen.');</script>"); } } else if (ddl_seleccionar.SelectedIndex == 2) { if (ddl_nombreServ.SelectedIndex != 0) { MantenedorFotosServicios man = new MantenedorFotosServicios(); string nombre = ddl_nombreServ.SelectedValue; txt_id.Text = man.BuscarFotoServicio(nombre).Rows[0][0].ToString(); txt_descripcion.Text = man.BuscarFotoServicio(nombre).Rows[0][1].ToString(); ddl_ser.Text = man.BuscarFotoServicio(nombre).Rows[0][3].ToString(); txt_nombreimagen.Text = man.BuscarFotoServicio(nombre).Rows[0][4].ToString(); SqlConnection sql = new SqlConnection(Conexion.CadenaDeConexion()); string query = "select imagen from fotoServicio where nombreimagen='" + nombre + "'"; SqlCommand cm = new SqlCommand(query, sql); sql.Open(); cm.CommandTimeout = 0; byte[] img = (byte[])cm.ExecuteScalar(); System.Drawing.Image rImg = null; using (MemoryStream ms = new MemoryStream(img)) { rImg = System.Drawing.Image.FromStream(ms); imgPreview.ImageUrl = "data:image;base64," + Convert.ToBase64String(img); } } else { Response.Write("<script>alert('Debe seleccionar una imagen.');</script>"); } } else { if (ddl_nombreEmp.SelectedIndex != 0) { MantenedorFotosEmpresa man = new MantenedorFotosEmpresa(); string nombre = ddl_nombreEmp.SelectedValue; txt_id.Text = man.BuscarFotoEmpresa(nombre).Rows[0][0].ToString(); txt_descripcion.Text = man.BuscarFotoEmpresa(nombre).Rows[0][1].ToString(); ddl_emp.Text = man.BuscarFotoEmpresa(nombre).Rows[0][3].ToString(); txt_nombreimagen.Text = man.BuscarFotoEmpresa(nombre).Rows[0][4].ToString(); SqlConnection sql = new SqlConnection(Conexion.CadenaDeConexion()); string query = "select imagen from fotoEmpresa where nombreimagen='" + nombre + "'"; SqlCommand cm = new SqlCommand(query, sql); sql.Open(); cm.CommandTimeout = 0; byte[] img = (byte[])cm.ExecuteScalar(); System.Drawing.Image rImg = null; using (MemoryStream ms = new MemoryStream(img)) { rImg = System.Drawing.Image.FromStream(ms); imgPreview.ImageUrl = "data:image;base64," + Convert.ToBase64String(img); } } else { Response.Write("<script>alert('Debe seleccionar una imagen.');</script>"); } } } catch (Exception ex) { Response.Write("<script>alert('" + ex.Message + "');</script>"); } }
protected void boton_eliminar_Click(object sender, EventArgs e) { try { if (ddl_seleccionar.SelectedIndex == 1) { if (txt_nombreimagen.Text.Trim().Length > 0) { MantenedorFotosProyectos ManCont = new MantenedorFotosProyectos(); if (ManCont.BuscarFoto(txt_nombreimagen.Text).Rows.Count > 0) { FotoProyecto foto = new FotoProyecto(); foto.NombreImagen = txt_nombreimagen.Text; ManCont.EliminarFoto(foto); Response.Write("<script>alert('Eliminada correctamente.');</script>"); ddl_nombrePro.SelectedIndex = 0; txt_nombreimagen.Text = ""; txt_descripcion.Text = ""; ddl_pro.SelectedIndex = 0; imgPreview.ImageUrl = "https://pngimage.net/wp-content/uploads/2018/05/agregar-png.png"; } else { Response.Write("<script>alert('La imagen no existe.');</script>"); } } else { Response.Write("<script>alert('Debe ingresar el nombre de la imagen a eliminar.');</script>"); } } else if (ddl_seleccionar.SelectedIndex == 2) { if (txt_nombreimagen.Text.Trim().Length > 0) { MantenedorFotosServicios ManCont = new MantenedorFotosServicios(); if (ManCont.BuscarFotoServicio(txt_nombreimagen.Text).Rows.Count > 0) { FotoServicio foto = new FotoServicio(); foto.NombreImagen = txt_nombreimagen.Text; ManCont.EliminarFotoServicio(foto); Response.Write("<script>alert('Eliminada correctamente.');</script>"); ddl_nombreServ.SelectedIndex = 0; txt_nombreimagen.Text = ""; txt_descripcion.Text = ""; ddl_pro.SelectedIndex = 0; imgPreview.ImageUrl = "https://pngimage.net/wp-content/uploads/2018/05/agregar-png.png"; } else { Response.Write("<script>alert('La imagen no existe.');</script>"); } } else { Response.Write("<script>alert('Debe ingresar el nombre de la imagen a eliminar.');</script>"); } } else if (ddl_seleccionar.SelectedIndex == 3) { if (txt_nombreimagen.Text.Trim().Length > 0) { MantenedorFotosEmpresa ManCont = new MantenedorFotosEmpresa(); if (ManCont.BuscarFotoEmpresa(txt_nombreimagen.Text).Rows.Count > 0) { FotoEmpresa foto = new FotoEmpresa(); foto.NombreImagen = txt_nombreimagen.Text; ManCont.EliminarFotoEmpresa(foto); Response.Write("<script>alert('Eliminada correctamente.');</script>"); ddl_nombreEmp.SelectedIndex = 0; txt_nombreimagen.Text = ""; txt_descripcion.Text = ""; ddl_pro.SelectedIndex = 0; imgPreview.ImageUrl = "https://pngimage.net/wp-content/uploads/2018/05/agregar-png.png"; } else { Response.Write("<script>alert('La imagen no existe.');</script>"); } } else { Response.Write("<script>alert('Debe ingresar el nombre de la imagen a eliminar.');</script>"); } } else { Response.Write("<script>alert('Debe asociar la imagen a un Proyecto, Servicio o Empresa.');</script>"); } } catch (Exception ex) { Response.Write("<script>alert('" + ex.Message + "');</script>"); } }