Exemplo n.º 1
0
        public static List<Annales> Consulta()
        {
            //Creamos un objeto SQLcommand
            SqlCommand cmdConsulta = new SqlCommand(AnnalesSQLHelper.CONSULTA_ANNALES, DBConnection.Open());
            cmdConsulta.CommandType = CommandType.StoredProcedure;

            SqlDataReader reader = cmdConsulta.ExecuteReader();

            List<Annales> itemsAnnales = new List<Annales>();

            Annales annales = null;

            while (reader.Read())
            {
                annales = new Annales();

                annales.Nombre = reader["nombre"].ToString();
                annales.Publicado = int.Parse(reader["publicado"].ToString());
                annales.Id = int.Parse(reader["id"].ToString());

                itemsAnnales.Add(annales);

            }
            DBConnection.Close(cmdConsulta.Connection);

            return itemsAnnales;
        }
Exemplo n.º 2
0
        public static int Inserta(Annales annales, int usuarioID)
        {
            SqlCommand cmdAgregarAnnales = new SqlCommand();
            // Indicamos sus parametro de CommandTExt y la Conexion. del Objeto Command
            cmdAgregarAnnales.CommandText = SQLHelpers.AnnalesSQLHelper.INSERTA_ANNALES;

            cmdAgregarAnnales.CommandType = CommandType.StoredProcedure;
            cmdAgregarAnnales.Connection = DBConnection.Open();

            SqlParameter prmAnnalesId = new SqlParameter(AnnalesSQLHelper.PARAMETRO_ID, SqlDbType.Int);
            prmAnnalesId.Direction = ParameterDirection.Output;
            cmdAgregarAnnales.Parameters.Add(prmAnnalesId);

            //Declarando los Parametros
            SqlParameter[] parametros = new SqlParameter[8];

            //Asignando Valores

            parametros[0] = new SqlParameter(AnnalesSQLHelper.PARAMETRO_NOMBRE, SqlDbType.NVarChar, 100);
            parametros[0].Value = annales.Nombre;

            parametros[1] = new SqlParameter(AnnalesSQLHelper.PARAMETRO_DESCRIPCION, SqlDbType.NVarChar);
            parametros[1].Value = annales.Descripcion;

            parametros[2] = new SqlParameter(AnnalesSQLHelper.PARAMETRO_AUTOR, SqlDbType.NVarChar, 150);
            parametros[2].Value = annales.Autor;
            //parametros[2].Value = Convert.ToDateTime("17/10/2012");

            parametros[3] = new SqlParameter(AnnalesSQLHelper.PARAMETRO_FECHA, SqlDbType.DateTime);
            parametros[3].Value = Convert.ToDateTime(annales.Fecha);

            parametros[4] = new SqlParameter(AnnalesSQLHelper.PARAMETRO_FOTO, SqlDbType.VarBinary, 7000);
            parametros[4].Value = annales.Foto;

            parametros[5] = new SqlParameter(AnnalesSQLHelper.PARAMETRO_DOCUMENTO, SqlDbType.VarBinary, 7000);
            parametros[5].Value = annales.Documento;

            parametros[6] = new SqlParameter(AnnalesSQLHelper.PARAMETRO_PUBLICADO, SqlDbType.Int);
            parametros[6].Value = Convert.ToInt32(annales.Publicado);

            parametros[7] = new SqlParameter(UsuarioSQLHelper.PARAMETRO_USUARIOID, SqlDbType.Int);
            parametros[7].Value = usuarioID;

            //Agregando nuestros parametros al command
            cmdAgregarAnnales.Parameters.AddRange(parametros);

            //Ejecutamos el NonQuery

            SqlDataReader dr = cmdAgregarAnnales.ExecuteReader();
            int ArticID = int.Parse(cmdAgregarAnnales.Parameters[AnnalesSQLHelper.PARAMETRO_ID].Value.ToString());
            dr.Close();
            DBConnection.Close(cmdAgregarAnnales.Connection);

            // Cerramos la conexion

            return ArticID;
        }
Exemplo n.º 3
0
        /*******************************************************************************************/
        public Annales ConsultarUnAnnales(int idAnnales)
        {
            Annales ann = new Annales();
            try
            {
                SqlCommand cmdConsulta = new SqlCommand();
                cmdConsulta.CommandText = AnnalesSQLHelper.CONSULTA_UN_ANNALES;
                cmdConsulta.CommandType = CommandType.StoredProcedure;
                cmdConsulta.Connection = DBConnection.Open();

                SqlParameter parametro = new SqlParameter();
                parametro = new SqlParameter(AnnalesSQLHelper.PARAMETRO_ID, SqlDbType.Int);
                parametro.Value = idAnnales;
                cmdConsulta.Parameters.Add(parametro);

                SqlDataReader drConsulta = cmdConsulta.ExecuteReader();

                while (drConsulta.Read())
                {
                    ann.Id = drConsulta.GetInt32(0);
                    ann.Nombre = drConsulta.GetString(1);
                    ann.Descripcion = drConsulta.GetString(2);
                    ann.Autor = drConsulta.GetString(3);
                    ann.Fecha = drConsulta.GetString(4);
                    //ann.Foto = drConsulta.GetString(5);
                    //ann.Documento = drConsulta.GetString(6);
                    ann.Publicado = drConsulta.GetInt32(7);

                }

                DBConnection.Close(cmdConsulta.Connection);
            }
            catch (Exception exc)
            {
                Console.Write(exc);
            }
            return ann;
        }
Exemplo n.º 4
0
        public bool ModificarAnnales(Annales annales)
        {
            bool Exito = false;

            SqlCommand cmdModificar = new SqlCommand();

            cmdModificar.CommandText = AnnalesSQLHelper.UPDATE_ANNALES;
            cmdModificar.CommandType = CommandType.StoredProcedure;
            cmdModificar.Connection = DBConnection.Open();

            SqlParameter[] parametros = new SqlParameter[8];

            parametros[0] = new SqlParameter(AnnalesSQLHelper.PARAMETRO_ID, SqlDbType.Int);
            parametros[0].Value = annales.Id;

            parametros[1] = new SqlParameter(AnnalesSQLHelper.PARAMETRO_NOMBRE, SqlDbType.NVarChar, 100);
            parametros[1].Value = annales.Nombre;

            parametros[2] = new SqlParameter(AnnalesSQLHelper.PARAMETRO_DESCRIPCION, SqlDbType.NVarChar);
            parametros[2].Value = annales.Descripcion;

            parametros[3] = new SqlParameter(AnnalesSQLHelper.PARAMETRO_AUTOR, SqlDbType.NVarChar, 150);
            parametros[3].Value = annales.Autor;

            parametros[4] = new SqlParameter(AnnalesSQLHelper.PARAMETRO_FECHA, SqlDbType.DateTime);
            parametros[4].Value = Convert.ToDateTime(annales.Fecha);

            parametros[5] = new SqlParameter(AnnalesSQLHelper.PARAMETRO_FOTO, SqlDbType.VarBinary, 7000);
            parametros[5].Value = annales.Foto;

            parametros[6] = new SqlParameter(AnnalesSQLHelper.PARAMETRO_DOCUMENTO, SqlDbType.VarBinary, 7000);
            parametros[6].Value = annales.Documento;

            parametros[7] = new SqlParameter(AnnalesSQLHelper.PARAMETRO_PUBLICADO, SqlDbType.Int);
            parametros[7].Value = Convert.ToInt32(annales.Publicado);

            cmdModificar.Parameters.AddRange(parametros);
            cmdModificar.ExecuteReader();

            DBConnection.Close(cmdModificar.Connection);

            Exito = true;

            return Exito;
        }
        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            if (idAnnales != 0)//es modificacion
            {
                Models.Annales annales = new Models.Annales();
                //annales.Foto = hiddenFoto.Value;
                //annales.Documento = HiddenDoc.Value;

                //string ubicacionfoto = null;
                //string ubicaciondoc = null;
                bool fileOK = false;
                bool fileOK2 = false;
                //String path = Server.MapPath("~/FotosAnnales/");
                //string rutafotos = "/FotosAnnales/";
                //String path2 = Server.MapPath("~/DocAnnales/");
                //string rutaDoc = "/DocAnnales/";
                bool avanza = false;
                bool avanza2 = false;
                /*if (fileFoto.PostedFile != null && fileFoto.PostedFile.ContentLength >0) {
                }*/
                if (fileFoto.HasFile)
                {
                    String fileExtension =
                        System.IO.Path.GetExtension(fileFoto.FileName).ToLower();
                    String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
                    for (int i = 0; i < allowedExtensions.Length; i++)
                    {
                        if (fileExtension == allowedExtensions[i])
                        {
                            fileOK = true;
                        }
                    }
                }

                if (fileFoto2.HasFile)
                {
                    String fileExtension2 = System.IO.Path.GetExtension(fileFoto2.FileName).ToLower();
                    String[] allowedExtensions2 = { ".pdf" };
                    for (int i = 0; i < allowedExtensions2.Length; i++)
                    {
                        if (fileExtension2 == allowedExtensions2[i])
                        {
                            fileOK2 = true;
                        }
                    }
                }

                if (fileFoto.HasFile && fileOK)
                {
                    //subir archivo
                    //string nombreArchivo = DateTime.Now.ToString("ddMMyyyyhhmmss") + fileFoto.FileName;
                    //ubicacionfoto = path + nombreArchivo;
                    //fileFoto.PostedFile.SaveAs(ubicacionfoto);
                    //annales.Foto = rutafotos + nombreArchivo;
                    avanza = true;
                }
                else
                {
                    if (fileFoto.HasFile && !fileOK)
                    {
                        avanza = false;
                    }
                    else
                    {
                        avanza = true;
                    }
                }

                if (fileFoto2.HasFile && fileOK2)
                {
                    //subir archivo
                    //string nombreArchivo2 = DateTime.Now.ToString("ddMMyyyyhhmmss") + fileFoto2.FileName;
                    //ubicaciondoc = path2 + nombreArchivo2;
                    //fileFoto2.PostedFile.SaveAs(ubicaciondoc);
                    //annales.Documento = rutaDoc + nombreArchivo2;

                    avanza2 = true;
                }
                else
                {
                    if (fileFoto2.HasFile && !fileOK2)
                    {
                        avanza2 = false;
                    }
                    else
                    {
                        avanza2 = true;
                    }
                }

                if (avanza && avanza2)
                {
                    //proceder a hacer la modificacion
                    annales.Id = idAnnales;
                    annales.Nombre = txtNombre.Text;
                    annales.Descripcion = txtDescripcion.Text;
                    annales.Autor = txtAutor.Text;
                    annales.Fecha = txtFecha.Text;

                    HttpPostedFile ImgFile = fileFoto.PostedFile;
                    Byte[] byteImage = new Byte[fileFoto.PostedFile.ContentLength];
                    ImgFile.InputStream.Read(byteImage, 0, fileFoto.PostedFile.ContentLength);
                    annales.Foto = byteImage;

                    HttpPostedFile PdfFile = fileFoto2.PostedFile;
                    Byte[] bytePdf = new Byte[fileFoto2.PostedFile.ContentLength];
                    PdfFile.InputStream.Read(bytePdf, 0, fileFoto2.PostedFile.ContentLength);
                    annales.Documento = bytePdf;

                    if (CheckPublicado.Checked)
                    {
                        annales.Publicado = 1;
                    }
                    else
                    {
                        annales.Publicado = 0;
                    }

                    this.lblMensaje.Visible = true;

                    try
                    {
                        AnnalesDAO daoModifica = new AnnalesDAO();

                        if (daoModifica.ModificarAnnales(annales))
                        {
                            this.lblMensaje.Text = "Se Modificó correctamente Annales con ID = " + idAnnales;
                        }
                        else
                            this.lblMensaje.Text = "Ocurrió un error al tratar de modificar Annales";
                    }
                    catch (Exception exc)
                    {
                        Response.Write("Ocurrió un error " + exc);
                    }
                }
                else
                {
                    if (!avanza)
                    {
                        Label1.Text = "No se aceptan archivos de este tipo";
                    }
                    if (!avanza2)
                    {
                        Label2.Text = "No se aceptan archivos de este tipo";
                    }
                }

            }
            else
            {
                /**
                Verificamos que el usuario haya subido el archivo
                */
                //string ubicacionfoto = null;
                //string ubicaciondoc = null;
                Boolean fileOK = false;
                Boolean fileOK2 = false;
                //String path = Server.MapPath("~/FotosAnnales/");
                //string rutafotos = "/FotosAnnales/";
                //String path2 = Server.MapPath("~/DocAnnales/");
                //string rutaDoc = "/DocAnnales/";

                if (fileFoto.HasFile && fileFoto2.HasFile)
                {
                    String fileExtension = System.IO.Path.GetExtension(fileFoto.FileName).ToLower();
                    String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
                    for (int i = 0; i < allowedExtensions.Length; i++)
                    {
                        if (fileExtension == allowedExtensions[i])
                        {
                            fileOK = true;
                        }
                    }

                    String fileExtension2 = System.IO.Path.GetExtension(fileFoto2.FileName).ToLower();
                    String[] allowedExtensions2 = { ".pdf" };
                    for (int ii = 0; ii < allowedExtensions2.Length; ii++)
                    {
                        if (fileExtension2 == allowedExtensions2[ii])
                        {
                            fileOK2 = true;
                        }
                    }
                }

                if (fileOK && fileOK2)
                {
                    try
                    {
                        //string nombreArchivofoto = DateTime.Now.ToString("ddMMyyyyhhmmss") + fileFoto.FileName;
                        //ubicacionfoto = path + nombreArchivofoto;

                        //fileFoto.PostedFile.SaveAs(ubicacionfoto);

                        //string nombreArchivoDoc = DateTime.Now.ToString("ddMMyyyyhhmmss") + fileFoto2.FileName;
                        //ubicaciondoc = path2 + nombreArchivoDoc;

                        //fileFoto2.PostedFile.SaveAs(ubicaciondoc);
                        //Label2.Text = "File uploaded!";

                        Models.Annales annales = new Models.Annales();
                        annales.Nombre = txtNombre.Text;
                        annales.Descripcion = txtDescripcion.Text;
                        annales.Autor = txtAutor.Text;
                        annales.Fecha = txtFecha.Text;
                        //annales.Foto = rutafotos + nombreArchivofoto;
                        //annales.Documento = rutaDoc + nombreArchivoDoc;

                        HttpPostedFile ImgFile = fileFoto.PostedFile;
                        Byte[] byteImage = new Byte[fileFoto.PostedFile.ContentLength];
                        ImgFile.InputStream.Read(byteImage, 0, fileFoto.PostedFile.ContentLength);
                        annales.Foto = byteImage;

                        HttpPostedFile PdfFile = fileFoto2.PostedFile;
                        Byte[] bytePdf = new Byte[fileFoto2.PostedFile.ContentLength];
                        PdfFile.InputStream.Read(bytePdf, 0, fileFoto2.PostedFile.ContentLength);
                        annales.Documento = bytePdf;
                        if (CheckPublicado.Checked)
                        {
                            annales.Publicado = 1;
                        }
                        else
                        {
                            annales.Publicado = 0;
                        }

                        try
                        {

                            this.lblMensaje.Visible = true;

                            int NiditoID = AnnalesDAO.Inserta(annales, int.Parse(Session["id"].ToString()));

                            this.lblMensaje.Text = "Se ingreso correctamente Annales con ID = " + NiditoID;
                            this.resetControles();

                        }
                        catch (Exception exe)
                        {
                            this.lblMensaje.Visible = true;
                            this.lblMensaje.Text = "Error Mensaje:" + exe;
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Write(ex);
                        Label1.Text = "File could not be uploaded.";
                        Label2.Text = "File could not be uploaded.";
                    }
                }
                else
                {
                    Label1.Text = "Cannot accept files of this type.";
                    Label2.Text = "Cannot accept files of this type.";
                }
                /*Terminamos de verificar lo del archivo*/
            }
        }