protected void btnGuardar_Click(object sender, EventArgs e) { if (imagen != "") { // Create a name for the file to store HttpPostedFile myFile = fuImagen.PostedFile; if (!imagenExiste(imagen)) { if (myFile.FileName != null & myFile.FileName != "") { int nFileLen = myFile.ContentLength; // Allocate a buffer for reading of the file // make sure the size of the file is > 0 if (nFileLen > 0) { byte[] myData = new byte[nFileLen]; myFile.InputStream.Read(myData, 0, nFileLen); // Create a name for the file to store string strFilename = "\\Banners\\" + Path.GetFileName(myFile.FileName); // Write data into a file WriteToFile(Server.MapPath(strFilename), ref myData); imgMuestra.ImageUrl = ".." + strFilename; //imagen = strFilename.Substring(strFilename.LastIndexOf("\\") + 1); } } oBanner unBanner = new oBanner(); unBanner.nombre = txtNombre.Text; unBanner.imagen = imagen; unBanner.columna = ddlColumna.SelectedValue; unBanner.activo = chkActivo.Checked; unBanner.link = txtLink.Text; nBanner nBanner = new nBanner(); nBanner.Alta(ref unBanner); string sError = cargar_Grilla(); } } else { Response.Write("<script type='text/javascript' language='javascript'> alert('La imagen seleccionada ya se encuentra cargada.');</script>"); } }
public string Alta(ref oBanner pE_Banner) { try { string[,] strParameters = { { "@pE_nombre", pE_Banner.nombre }, { "@pE_imagen", pE_Banner.imagen}, { "@pE_activo", (pE_Banner.activo==true?"1":"0")}, { "@pE_columna", pE_Banner.columna}, { "@pE_link", pE_Banner.link}}; pE_Banner.id = int.Parse(oCon.ExecScalar("web_Banner_Alta", CommandType.StoredProcedure, strParameters).ToString()); return ""; } catch (Exception ex) { return ex.Message; } }
public string Buscar_Uno(long pE_Id, ref oBanner pS_Banner) { string sError = ""; try { SqlDataReader dr = null; string[,] strParameters = { { "@pE_Id", pE_Id.ToString() } }; dr = oCon.ExecReader("web_Banner_BuscarUno", CommandType.StoredProcedure, strParameters); if (dr.HasRows) { while (dr.Read()) { pS_Banner.id = Convert.ToInt32(dr["id"].ToString()); pS_Banner.nombre = (dr["nombre"] == DBNull.Value ? "" : dr["nombre"].ToString()); pS_Banner.imagen = (dr["imagen"] == DBNull.Value ? "" : dr["imagen"].ToString()); pS_Banner.activo = (dr["activo"].ToString().ToLower() == "false" ? false : true); pS_Banner.columna = (dr["columna"] == DBNull.Value ? "" : dr["columna"].ToString()); pS_Banner.link = (dr["link"] == DBNull.Value ? "" : dr["link"].ToString()); } } else { throw new Exception("El banner seleccionado no existe"); } dr.Close(); dr = null; } catch (Exception ex) { sError = ex.Message; } return sError; }
public string Modificar(oBanner pE_Banner) { try { string[,] strParameters = {{"@pE_id",pE_Banner.id.ToString()}, {"@pE_nombre",pE_Banner.nombre}, {"@pE_imagen",pE_Banner.imagen}, {"@pE_activo",pE_Banner.activo.ToString()}, {"@pE_columna",pE_Banner.columna}, {"@pE_link",pE_Banner.link}}; oCon.ExecNonQuery("web_Banner_Modificar", CommandType.StoredProcedure, strParameters); return ""; } catch (Exception ex) { return ex.Message; } }
protected void BtnModificar_Click(object sender, EventArgs e) { oBanner unBannerModificar = new oBanner(); if (vioImagen) imagenEditar = imgMuestraEditar.ImageUrl.Substring(imgMuestraEditar.ImageUrl.LastIndexOf("\\") + 1); //btnVerImagenEditar_Click(sender, e); if (imagenEditar != "") { // Create a name for the file to store if (!vioImagen) { HttpPostedFile myFile = fuImagenEditar.PostedFile; if (myFile.FileName != null & myFile.FileName != "") { int nFileLen = myFile.ContentLength; // Allocate a buffer for reading of the file // make sure the size of the file is > 0 if (nFileLen > 0) { byte[] myData = new byte[nFileLen]; myFile.InputStream.Read(myData, 0, nFileLen); // Create a name for the file to store string strFilename = "\\Banners\\" + Path.GetFileName(myFile.FileName); // Write data into a file WriteToFile(Server.MapPath(strFilename), ref myData); imgMuestraEditar.ImageUrl = ".." + strFilename; //imagen = strFilename.Substring(strFilename.LastIndexOf("\\") + 1); unBannerModificar.imagen = imagenEditar; } } } else { unBannerModificar.imagen = imagenEditar; } } unBannerModificar.id = int.Parse(hId.Value.ToString()); unBannerModificar.nombre = txtNombreEditar.Text; unBannerModificar.columna = ddlColumnaEditar.SelectedValue; unBannerModificar.imagen = imagenEditar; unBannerModificar.activo = chkActivoEditar.Checked; nBanner nBanner = new nBanner(); nBanner.Modificar(unBannerModificar); string sError = cargar_Grilla(); formModificar.Visible = false; vioImagen = false; }
protected void grdBanners_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Editar") { string sError = ""; try { if (int.Parse(e.CommandArgument.ToString()) > 0) { nBanner unBannerN = new nBanner(); oBanner unBannerO = new oBanner(); sError = unBannerN.Buscar_Uno(int.Parse(e.CommandArgument.ToString()), ref unBannerO); hId.Value = unBannerO.id.ToString(); txtNombreEditar.Text = unBannerO.nombre; imgMuestraEditar.ImageUrl = unBannerO.imagen; chkActivoEditar.Checked = unBannerO.activo; ddlColumnaEditar.SelectedValue = unBannerO.columna; txtLinkEditar.Text = unBannerO.link; formModificar.Visible = true; //HtmlGenericControl formModificar = new HtmlGenericControl("formModificar"); //formModificar.FindControl(""); } } catch (Exception ex) { Response.Write("<script type='text/javascript' language='javascript'> alert('" + sError + "');</script>"); } } }
public string Modificar(oBanner pE_Banner) { return dBanner.Modificar(pE_Banner); }
public string Buscar_Uno(long pE_Id, ref oBanner pS_Banner) { return dBanner.Buscar_Uno(pE_Id, ref pS_Banner); }
public string Alta(ref oBanner pE_Banner) { return dBanner.Alta(ref pE_Banner); }
private List<oBanner> carga_ListaBanners() { List<oBanner> banners = new List<oBanner>(); nBanner bannerN = new nBanner(); DataTable dt = new DataTable(); string sError = bannerN.Buscar_TodosInicio(ref dt); foreach (DataRow dr in dt.Rows) { oBanner unBanner = new oBanner(); unBanner.id = Convert.ToInt32(dr["id"].ToString()); unBanner.nombre = (dr["nombre"] == DBNull.Value ? "" : dr["nombre"].ToString()); unBanner.imagen = (dr["imagen"] == DBNull.Value ? "" : dr["imagen"].ToString()); unBanner.activo = (dr["activo"].ToString().ToLower() == "false" ? false : true); unBanner.columna = (dr["columna"] == DBNull.Value ? "" : dr["columna"].ToString()); unBanner.link = (dr["link"] == DBNull.Value ? "" : dr["link"].ToString()); banners.Add(unBanner); } return banners.Where(a => a.activo == true).ToList<oBanner>(); }