Example #1
0
        protected void grdNovedades_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Ver")
            {
                string sError = "";
                try
                {
                    if (int.Parse(e.CommandArgument.ToString()) > 0)
                    {
                        nNovedad unaNovedadN = new nNovedad();
                        oNovedad unaNovedadO = new oNovedad();
                        sError = unaNovedadN.Buscar_Uno(int.Parse(e.CommandArgument.ToString()), ref unaNovedadO);

                        hId.Value = unaNovedadO.id.ToString();
                        lblTituloVer.Text = unaNovedadO.titulo;
                        imgMuestraEditar.ImageUrl = "\\Novedad\\" + unaNovedadO.imagen;
                        lblCuerpoVer.Text = unaNovedadO.cuerpo;

                        formVer.Visible = true;

                    }
                }
                catch (Exception ex)
                {
                    Response.Write("<script type='text/javascript' language='javascript'> alert('" + sError + "');</script>");
                }
            }
        }
Example #2
0
        protected void BtnModificar_Click(object sender, EventArgs e)
        {
            oNovedad unaNovedadModif = new oNovedad();
            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 = "\\Novedad\\" + Path.GetFileName(myFile.FileName);

                            // Write data into a file
                            WriteToFile(Server.MapPath(strFilename), ref myData);
                            imgMuestraEditar.ImageUrl = ".." + strFilename;
                            //imagen = strFilename.Substring(strFilename.LastIndexOf("\\") + 1);

                            unaNovedadModif.imagen = imagenEditar;
                        }
                    }
                }
                else
                {
                    unaNovedadModif.imagen = imagenEditar;
                }
            }

            unaNovedadModif.id = int.Parse(hId.Value.ToString());
            unaNovedadModif.titulo = txtTituloEditar.Text;
            unaNovedadModif.imagen = imagenEditar;
            unaNovedadModif.cuerpo = txtCuerpoEditar.Text;

            nNovedad nNovedad = new nNovedad();
            nNovedad.Modificar(unaNovedadModif);

            string sError = cargar_Grilla();

            formModificar.Visible = false;
            vioImagen = false;
        }
Example #3
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 = "\\Novedades\\" + Path.GetFileName(myFile.FileName);

                            // Write data into a file
                            WriteToFile(Server.MapPath(strFilename), ref myData);
                            imgMuestra.ImageUrl = ".." + strFilename;
                            //imagen = strFilename.Substring(strFilename.LastIndexOf("\\") + 1);
                        }
                    }

                    oNovedad unaNovedad = new oNovedad();
                    unaNovedad.titulo = txtTitulo.Text;
                    unaNovedad.imagen = imagen;
                    unaNovedad.cuerpo = txtCuerpo.Text;

                    nNovedad nNovedad = new nNovedad();
                    nNovedad.Alta(ref unaNovedad);

                    string sError = cargar_Grilla();
                }
            }
            else
            {
                Response.Write("<script type='text/javascript' language='javascript'> alert('La imagen seleccionada ya se encuentra cargada.');</script>");
            }
        }
Example #4
0
        public string Alta(ref oNovedad pE_Novedad)
        {
            try
            {
                string[,] strParameters = { { "@pE_titulo", pE_Novedad.titulo },
                                            { "@pE_imagen", pE_Novedad.imagen},
                                            { "@pE_cuerpo", pE_Novedad.cuerpo}};

                pE_Novedad.id = int.Parse(oCon.ExecScalar("web_Novedad_Alta", CommandType.StoredProcedure, strParameters).ToString());

                return "";

            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
Example #5
0
        public string Buscar_Uno(long pE_Id, ref oNovedad pS_Novedad)
        {
            string sError = "";
            try
            {
                SqlDataReader dr = null;

                string[,] strParameters = { { "@pE_Id", pE_Id.ToString() } };

                dr = oCon.ExecReader("web_Novedad_BuscarUno", CommandType.StoredProcedure, strParameters);

                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        pS_Novedad.id = Convert.ToInt32(dr["id"].ToString());
                        pS_Novedad.titulo = (dr["titulo"] == DBNull.Value ? "" : dr["titulo"].ToString());
                        pS_Novedad.imagen = (dr["imagen"] == DBNull.Value ? "" : dr["imagen"].ToString());
                        pS_Novedad.cuerpo = (dr["cuerpo"] == DBNull.Value ? "" : dr["cuerpo"].ToString());
                    }
                }
                else
                {
                    throw new Exception("La Novedad seleccionada no existe");
                }

                dr.Close();
                dr = null;
            }
            catch (Exception ex)
            {
                sError = ex.Message;
            }

            return sError;
        }
Example #6
0
 public string Modificar(oNovedad pE_Novedad)
 {
     return dNovedad.Modificar(pE_Novedad);
 }
Example #7
0
 public string Buscar_Uno(long pE_Id, ref oNovedad pS_Novedad)
 {
     return dNovedad.Buscar_Uno(pE_Id, ref pS_Novedad);
 }
Example #8
0
 public string Alta(ref oNovedad pE_Novedad)
 {
     return dNovedad.Alta(ref pE_Novedad);
 }
Example #9
0
        public string Modificar(oNovedad pE_Novedad)
        {
            try
            {
                string[,] strParameters = {{"@pE_id",pE_Novedad.id.ToString()},
                                        {"@pE_titulo",pE_Novedad.titulo},
                                        {"@pE_imagen",pE_Novedad.imagen},
                                        {"@pE_cuerpo",pE_Novedad.cuerpo}};

                oCon.ExecNonQuery("web_Novedad_Modificar", CommandType.StoredProcedure, strParameters);

                return "";

            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
Example #10
0
        protected void grdNovedades_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Editar")
            {
                string sError = "";
                try
                {
                    if (int.Parse(e.CommandArgument.ToString()) > 0)
                    {
                        nNovedad unaNovedadN = new nNovedad();
                        oNovedad unaNovedadO = new oNovedad();
                        sError = unaNovedadN.Buscar_Uno(int.Parse(e.CommandArgument.ToString()), ref unaNovedadO);

                        hId.Value = unaNovedadO.id.ToString();
                        txtTituloEditar.Text = unaNovedadO.titulo;
                        imgMuestraEditar.ImageUrl = unaNovedadO.imagen;
                        txtCuerpoEditar.Text = unaNovedadO.cuerpo;
                        formModificar.Visible = true;

                    }
                }
                catch (Exception ex)
                {
                    Response.Write("<script type='text/javascript' language='javascript'> alert('" + sError + "');</script>");
                }
            }
            else
            {
                if (e.CommandName == "Eliminar")
                {
                    string sError = "";
                    if (int.Parse(e.CommandArgument.ToString()) > 0)
                    {
                        try
                        {
                            nNovedad unaNovedadN = new nNovedad();
                            oNovedad unaNovedadO = new oNovedad();
                            sError = unaNovedadN.Eliminar(e.CommandArgument.ToString());
                            cargar_Grilla();
                        }
                        catch (Exception ex)
                        {
                            Response.Write("<script type='text/javascript' language='javascript'> alert('" + ex.Message + "');</script>");
                        }
                    }
                }
            }
        }