コード例 #1
0
        /// <summary>
        /// Metodo que exporta a excel, segun los datos que se le pasen como parametro.
        /// </summary>
        /// <param name="Mov"></param>
        /// <param name="Almacen"></param>
        /// <param name="Tabla"></param>
        public static void Exportar_Excel(string Mov, string Almacen, ListView Tabla)
        {
            SaveFileDialog fichero = new SaveFileDialog();

            fichero.Filter   = "Archivo Excel 2007 (*.xls)|*.xls";
            fichero.FileName = "Respaldo " + Mov + " [ " + Almacen + " ]";
            if (fichero.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    string[]     st = new string[Tabla.Columns.Count];
                    StreamWriter sw = new StreamWriter(fichero.FileName, false);
                    sw.AutoFlush = true;
                    string dat = "\n";

                    for (int col = 0; col < Tabla.Columns.Count; col++)
                    {
                        dat = dat + "\t" + Convert.ToString(Tabla.Columns[col].Text);
                    }
                    sw.WriteLine(dat);

                    int    rowIndex = 1;
                    int    row      = 0;
                    string st1      = "";
                    for (row = 0; row < Tabla.Items.Count; row++)
                    {
                        if (rowIndex <= Tabla.Items.Count)
                        {
                            rowIndex++;
                        }
                        st1 = "\n";
                        for (int col = 0; col < Tabla.Columns.Count; col++)
                        {
                            st1 = st1 + "\t" + Convert.ToString(Tabla.Items[row].SubItems[col].Text);
                        }
                        sw.WriteLine(st1);
                    }
                    sw.Close();
                    MessageBox.Show("Proceso Completado", "Exportar Datos", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    EMensaje.Error("Error : " + ex, "Ruta del error : ET/Herramientas/Exportar_Excel");
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Metodos que exporta a pdf un reporte de inventario.
        /// </summary>
        public static void Exportar_Inventario()
        {
            SaveFileDialog fichero = new SaveFileDialog();

            fichero.Filter   = "PDF (*.pdf)|*.pdf";
            fichero.FileName = "Reporte de Inventario" + "[" + DateTime.Now.ToString("dd-MM-yyyy") + "]";
            if (fichero.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(fichero.FileName, FileMode.Create));
                    doc.AddTitle("Bytesoft, C.A.");
                    doc.AddCreator("Jorman Ortega");
                    doc.Open();
                    PdfPTable table = new PdfPTable(3);
                    table.HorizontalAlignment = 0;
                    table.TotalWidth          = 300f;
                    table.WidthPercentage     = 100;
                    Font     Fuente_Inicial = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, BaseColor.BLACK);
                    PdfPCell CeldaI         = new PdfPCell(new Phrase("Reporte de Inventario al : " + DateTime.Now.ToString("dd/MMMM/yyyy"), Fuente_Inicial));
                    CeldaI.HorizontalAlignment = 1;
                    CeldaI.BorderWidth         = 1;
                    CeldaI.Colspan             = 3;
                    table.AddCell(CeldaI);
                    doc.Add(table);
                    doc.Add(new Paragraph(" "));
                    doc.Add(new Paragraph(" "));
                    Font      Fuente   = new Font(Font.FontFamily.COURIER, 8, Font.NORMAL, BaseColor.BLACK);
                    PdfPTable tableI   = new PdfPTable(4);
                    PdfPCell  CeldaII  = new PdfPCell(new Phrase("Nombre :", Fuente));
                    PdfPCell  CeldaIII = new PdfPCell(new Phrase("Usuario :", Fuente));
                    PdfPCell  CeldaIV  = new PdfPCell(new Phrase("", Fuente));
                    PdfPCell  CeldaV   = new PdfPCell(new Phrase("Fecha Creacion", Fuente));
                    tableI.HorizontalAlignment   = 0;
                    tableI.WidthPercentage       = 100;
                    CeldaII.HorizontalAlignment  = 1;
                    CeldaIII.HorizontalAlignment = 1;
                    CeldaV.HorizontalAlignment   = 1;
                    CeldaII.BorderWidth          = 1;
                    CeldaIII.BorderWidth         = 1;
                    CeldaIV.BorderWidth          = 0;
                    CeldaV.BorderWidth           = 1;
                    tableI.AddCell(CeldaII);
                    tableI.AddCell(CeldaIII);
                    tableI.AddCell(CeldaIV);
                    tableI.AddCell(CeldaV);
                    doc.Add(tableI);
                    PdfPTable _tableI   = new PdfPTable(4);
                    PdfPCell  _CeldaII  = new PdfPCell(new Phrase(EUsuarios.Nombre + " " + EUsuarios.Apellido, Fuente));
                    PdfPCell  _CeldaIII = new PdfPCell(new Phrase(EUsuarios.Usuario, Fuente));
                    PdfPCell  _CeldaIV  = new PdfPCell(new Phrase("", Fuente));
                    PdfPCell  _CeldaV   = new PdfPCell(new Phrase(DateTime.Today.ToString("dd-MM-yyyy"), Fuente));
                    _tableI.HorizontalAlignment   = 0;
                    _tableI.WidthPercentage       = 100;
                    _CeldaII.HorizontalAlignment  = 1;
                    _CeldaIII.HorizontalAlignment = 1;
                    _CeldaV.HorizontalAlignment   = 1;
                    _CeldaII.BorderWidth          = 1;
                    _CeldaIII.BorderWidth         = 1;
                    _CeldaIV.BorderWidth          = 0;
                    _CeldaV.BorderWidth           = 1;
                    _tableI.AddCell(_CeldaII);
                    _tableI.AddCell(_CeldaIII);
                    _tableI.AddCell(_CeldaIV);
                    _tableI.AddCell(_CeldaV);
                    doc.Add(_tableI);
                    doc.Add(new Paragraph(" "));
                    doc.Add(new Paragraph(" "));
                    PdfPTable Inventario = new PdfPTable(12);
                    Inventario.HorizontalAlignment = 0;
                    Inventario.WidthPercentage     = 100;
                    PdfPCell CI   = new PdfPCell(new Phrase("Codigo", Fuente));
                    PdfPCell CIII = new PdfPCell(new Phrase("Inv. Inicial", Fuente));
                    PdfPCell CIV  = new PdfPCell(new Phrase("Entradas", Fuente));
                    PdfPCell CV   = new PdfPCell(new Phrase("Salidas", Fuente));
                    PdfPCell CVII = new PdfPCell(new Phrase("Inv. Final", Fuente));
                    CI.BorderWidth           = 1;
                    CI.HorizontalAlignment   = 1;
                    CI.Colspan               = 2;
                    CIII.BorderWidth         = 1;
                    CIII.HorizontalAlignment = 1;
                    CIII.Colspan             = 2;
                    CIV.BorderWidth          = 1;
                    CIV.HorizontalAlignment  = 1;
                    CIV.Colspan              = 2;
                    CV.BorderWidth           = 1;
                    CV.HorizontalAlignment   = 1;
                    CV.Colspan               = 2;
                    CVII.BorderWidth         = 1;
                    CVII.HorizontalAlignment = 1;
                    CVII.Colspan             = 2;
                    Inventario.AddCell(CI);
                    Inventario.AddCell(CIII);
                    Inventario.AddCell(CIV);
                    Inventario.AddCell(CV);
                    Inventario.AddCell(CVII);
                    doc.Add(Inventario);
                    PdfPTable _Inventario = new PdfPTable(11);
                    _Inventario.HorizontalAlignment = 0;
                    _Inventario.WidthPercentage     = 100;
                    PdfPCell _CI   = new PdfPCell(new Phrase("Material", Fuente));
                    PdfPCell _CI_  = new PdfPCell(new Phrase("Costo", Fuente));
                    PdfPCell _I1   = new PdfPCell(new Phrase("Unidad Inicial", Fuente));
                    PdfPCell _I2   = new PdfPCell(new Phrase("Costo Inicial", Fuente));
                    PdfPCell _II1  = new PdfPCell(new Phrase("Unidad Entradas", Fuente));
                    PdfPCell _II2  = new PdfPCell(new Phrase("Costo Entradas", Fuente));
                    PdfPCell _II3  = new PdfPCell(new Phrase("Precio Venta", Fuente));
                    PdfPCell _III1 = new PdfPCell(new Phrase("Unidad Salidas", Fuente));
                    PdfPCell _III2 = new PdfPCell(new Phrase("Costo Salidas", Fuente));
                    PdfPCell _CIII = new PdfPCell(new Phrase("Unidades Final", Fuente));
                    PdfPCell _CIV  = new PdfPCell(new Phrase("Costo Final", Fuente));
                    _CI.BorderWidth   = 1;
                    _CI.Colspan       = 1;
                    _CI_.BorderWidth  = 1;
                    _CI_.Colspan      = 1;
                    _I1.BorderWidth   = 1;
                    _I2.BorderWidth   = 1;
                    _II1.BorderWidth  = 1;
                    _II2.BorderWidth  = 1;
                    _II3.BorderWidth  = 1;
                    _III1.BorderWidth = 1;
                    _III2.BorderWidth = 1;
                    _CIII.BorderWidth = 1;
                    _CIV.BorderWidth  = 1;

                    _CI.HorizontalAlignment   = 1;
                    _CI_.HorizontalAlignment  = 1;
                    _I1.HorizontalAlignment   = 1;
                    _I2.HorizontalAlignment   = 1;
                    _II1.HorizontalAlignment  = 1;
                    _II2.HorizontalAlignment  = 1;
                    _II3.HorizontalAlignment  = 1;
                    _III1.HorizontalAlignment = 1;
                    _III2.HorizontalAlignment = 1;
                    _CIII.HorizontalAlignment = 1;
                    _CIV.HorizontalAlignment  = 1;

                    _Inventario.AddCell(_CI);
                    _Inventario.AddCell(_CI_);
                    _Inventario.AddCell(_I1);
                    _Inventario.AddCell(_I2);
                    _Inventario.AddCell(_II1);
                    _Inventario.AddCell(_II2);
                    _Inventario.AddCell(_II3);
                    _Inventario.AddCell(_III1);
                    _Inventario.AddCell(_III2);
                    _Inventario.AddCell(_CIII);
                    _Inventario.AddCell(_CIV);
                    doc.Add(_Inventario);
                    Añadir_Datos_Inventario();

                    PdfPTable _Inventario_ = new PdfPTable(11);
                    _Inventario_.HorizontalAlignment = 0;
                    _Inventario_.WidthPercentage     = 100;
                    PdfPCell Total = new PdfPCell(new Phrase("Totales :", Fuente));
                    Total.Colspan             = 2;
                    Total.HorizontalAlignment = 2;
                    Total.BorderWidth         = 1;
                    PdfPCell Total_Inicial = new PdfPCell(new Phrase(_Total_Inicial, Fuente));
                    Total_Inicial.Colspan             = 2;
                    Total_Inicial.HorizontalAlignment = 1;
                    Total_Inicial.BorderWidth         = 1;
                    PdfPCell Total_Entradas = new PdfPCell(new Phrase(_Total_Entradas, Fuente));
                    Total_Entradas.Colspan             = 2;
                    Total_Entradas.HorizontalAlignment = 1;
                    Total_Entradas.BorderWidth         = 1;
                    PdfPCell Total_Salidas = new PdfPCell(new Phrase(_Total_Salidas, Fuente));
                    Total_Salidas.Colspan             = 3;
                    Total_Salidas.HorizontalAlignment = 1;
                    Total_Salidas.BorderWidth         = 1;
                    PdfPCell Total_Final = new PdfPCell(new Phrase(_Total_Final, Fuente));
                    Total_Final.Colspan             = 2;
                    Total_Final.HorizontalAlignment = 1;
                    Total_Final.BorderWidth         = 1;
                    _Inventario_.AddCell(Total);
                    _Inventario_.AddCell(Total_Inicial);
                    _Inventario_.AddCell(Total_Entradas);
                    _Inventario_.AddCell(Total_Salidas);
                    _Inventario_.AddCell(Total_Final);
                    doc.Add(_Inventario_);
                    doc.Close();
                    writer.Close();
                }
                catch
                {
                    EMensaje.Informacion("No puede generar el archivo 2 veces. ingrese nuevamente al modulo de reportes", "Informacion");
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Metodo que exporta los movimientos segun el parametro que reciba.
        /// </summary>
        /// <param name="Movimiento"></param>
        public static void Exportar_Movimiento(string Movimiento)
        {
            SaveFileDialog fichero = new SaveFileDialog();

            fichero.Filter = "PDF (*.pdf)|*.pdf";
            switch (Movimiento)
            {
            case "Entradas/Salidas":
                fichero.FileName = "Movimientos al." + "[" + DateTime.Now.ToString("dd-MM-yyyy") + "]";
                if (fichero.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        PdfWriter writer = PdfWriter.GetInstance(Documento_Todos, new FileStream(fichero.FileName, FileMode.Create));
                        Documento_Todos.Open();
                        Agregar_Encabezados_Todos();
                        Añadir_Tabla_Todos();
                        Documento_Todos.Close();
                        writer.Close();
                    }
                    catch
                    {
                        EMensaje.Informacion("No puede generar el archivo 2 veces.Reinicie el Sistema", "Informacion");
                    }
                }
                break;

            case "Entrada":
                fichero.FileName = "Entradas al." + "[" + DateTime.Now.ToString("dd-MM-yyyy") + "]";
                if (fichero.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        PdfWriter writer = PdfWriter.GetInstance(Documento_Entrada, new FileStream(fichero.FileName, FileMode.Create));
                        Documento_Entrada.Open();
                        Agregar_Encabezados_Entradas();
                        parametro = Movimiento;
                        Añadir_Tabla_Entrada();
                        Documento_Entrada.CloseDocument();
                        Documento_Entrada.Close();
                        writer.Close();
                    }
                    catch
                    {
                        EMensaje.Informacion("No puede generar el archivo 2 veces.Reinicie el Sistema", "Informacion");
                    }
                }
                break;

            case "Salida":
                fichero.FileName = "Salidas al." + "[" + DateTime.Now.ToString("dd-MM-yyyy") + "]";
                if (fichero.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        PdfWriter writer = PdfWriter.GetInstance(Documento_Salida, new FileStream(fichero.FileName, FileMode.Create));
                        Documento_Salida.Open();
                        Agregar_Encabezados_Salidas();
                        parametro = Movimiento;
                        Añadir_Tabla_Salida();
                        Documento_Salida.CloseDocument();
                        Documento_Salida.Close();
                        writer.Close();
                    }
                    catch
                    {
                        EMensaje.Informacion("No puede generar el archivo 2 veces.Reinicie el Sistema", "Informacion");
                    }
                }
                break;
            }
        }