示例#1
0
        private void btnExtraerUnico_Click(object sender, EventArgs e)
        {
            try
            {
                sfd.ShowDialog(this);

                if (Directory.Exists(Path.GetDirectoryName(sfd.FileName)))
                {
                    ResultadoStored_Str Resultado = clsBD.ExtraerPDF(Convert.ToInt32(numId.Value), Path.GetDirectoryName(sfd.FileName), Path.GetFileName(sfd.FileName));

                    if (!Resultado.HayError)
                    {
                        MessageBox.Show("Proceso finalizado", "Exportación única", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show(Resultado.Error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("El directorio no existe", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#2
0
        private void btnExtraerTodo_Click(object sender, EventArgs e)
        {
            fbd.ShowDialog(this);

            if (Directory.Exists(fbd.SelectedPath))
            {
                bool HuboErrores = false;

                for (int w = 0; w < Listado.Rows.Count; w++)
                {
                    int Cart_Id = 0;

                    int.TryParse(Listado.Rows[w][0].ToString(), out Cart_Id);
                    ResultadoStored_Str Resultado = clsBD.ExtraerPDF(Cart_Id, fbd.SelectedPath);

                    if (!Resultado.HayError)
                    {
                        lstLog.Items.Add(DateTime.Now.ToString("HH:mm:ss") + "\t" + "Archivo generado correctamente: " + Cart_Id.ToString() + ".pdf");
                    }
                    else
                    {
                        lstLog.Items.Add(DateTime.Now.ToString("HH:mm:ss") + "\t" + "Error al generar archivo: " + Cart_Id.ToString() + ".pdf | Detalle del error: " + Resultado.Error);
                        HuboErrores = true;
                    }
                }

                if (!HuboErrores)
                {
                    MessageBox.Show("Proceso finalizado", "Exportación masiva", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Consulte log para ver los detalles", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("El directorio no existe", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
示例#3
0
        public static ResultadoStored_Str ExtraerPDF(int Cart_Id, string Ruta, string NombreArchivo = "", bool DevolverError = true, int TimeOut = 0)
        {
            ResultadoStored_Str Resultado = new ResultadoStored_Str(string.Empty, string.Empty, false);
            SqlConnection       cn        = null;
            SqlCommand          cmd       = null;
            SqlParameter        param     = null;

            try
            {
                cn              = new SqlConnection(Cnx);
                cmd             = new SqlCommand(QueryBase, cn);
                cmd.CommandType = CommandType.Text;

                param       = new SqlParameter("@Cart_Id", SqlDbType.Int);
                param.Value = Cart_Id;
                cmd.Parameters.Add(param);

                cn.Open();

                if (TimeOut > 0)
                {
                    cmd.CommandTimeout = TimeOut;
                }

                using (SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    while (rdr.Read())
                    {
                        string Archivo = System.IO.Path.Combine(Ruta, Cart_Id.ToString() + ".pdf");
                        byte[] buffer  = (byte[])rdr["Cart_Archivo"];

                        if (NombreArchivo != string.Empty)
                        {
                            Archivo = System.IO.Path.Combine(Ruta, NombreArchivo);
                        }

                        if (System.IO.File.Exists(Archivo))
                        {
                            System.IO.File.Delete(Archivo);
                        }

                        System.IO.File.WriteAllBytes(Archivo, buffer);
                    }

                    rdr.Close();
                }
            }
            catch (Exception ex)
            {
                Resultado.HayError  = true;
                Resultado.Resultado = string.Empty;

                if (DevolverError)
                {
                    Resultado.Error = "Error: " + ex.Message;
                }
                else
                {
                    Resultado.Error = string.Empty;
                }
            }

            return(Resultado);
        }