Exemplo n.º 1
0
        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>");
            }
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
 private bool imagenExiste(string imagen)
 {
     nBanner unBannerN = new nBanner();
     return unBannerN.Buscar_Uno(imagen);
 }
Exemplo n.º 4
0
        private string cargar_Grilla()
        {
            string sError = "";

            DataTable dt = new DataTable();

            nBanner unBannerN = new nBanner();
            sError = unBannerN.Buscar_Todos(ref dt);

            grdBanners.DataSource = dt;
            grdBanners.DataBind();

            return sError;
        }
Exemplo n.º 5
0
        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>");
                }
            }
        }
Exemplo n.º 6
0
        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>();
        }