Example #1
0
        public void imprimirPapeletasFaltantes(String codComi, String nom, int tip)
        {
            try
            {
                BDTal     tal = new BDTal();
                DataTable ds  = tal.GetByIdAll(codComi, tip);
                if (ds != null)
                {
                    BDSistema sis = new BDSistema();
                    String    dir = sis.Directorio();
                    if (dir != null)
                    {
                        //Ubicación del reporte
                        string ubicacionReporte = @dir + "\\reportePapFaltantes_" + codComi + ".pdf";
                        //Creacion de reporte con iTextSharp
                        Document  reporte = new Document(PageSize.LETTER);
                        PdfWriter writer  = PdfWriter.GetInstance(reporte, new FileStream(ubicacionReporte, FileMode.Create));

                        //Abriendo Archivo
                        reporte.Open();

                        Font _standardFont = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.NORMAL, BaseColor.BLACK);

                        //Añadiendo titulo
                        reporte.AddTitle("Reporte de papeletas faltantes " + codComi);
                        reporte.AddAuthor("Sistema de Gestión de papeletas Poltran v1.1");

                        //Encabezado de reporte
                        reporte.Add(new iTextSharp.text.Paragraph("Reporte de Papeletas Faltantes "));
                        reporte.Add(Chunk.NEWLINE);
                        int       nrocol = 6;
                        PdfPTable tablaDatosPrincipales = new PdfPTable(nrocol);
                        tablaDatosPrincipales.WidthPercentage = 80;

                        //Configurando titulo de las columnas de datos por fila
                        PdfPCell clNroPapeleta = new PdfPCell(new Phrase("Nro. Papeleta", _standardFont));
                        clNroPapeleta.BorderWidth       = 0;
                        clNroPapeleta.BorderWidthBottom = 0.50f;

                        PdfPCell clFalta = new PdfPCell(new Phrase("Falta", _standardFont));
                        clFalta.BorderWidth       = 0;
                        clFalta.BorderWidthBottom = 0.50f;

                        PdfPCell clEstado = new PdfPCell(new Phrase("Estado", _standardFont));
                        clEstado.BorderWidth       = 0;
                        clEstado.BorderWidthBottom = 0.50f;

                        PdfPCell clid;
                        PdfPCell clnom;
                        if (tip == 1)
                        {
                            clid                   = new PdfPCell(new Phrase("Codigo CIP", _standardFont));
                            clid.BorderWidth       = 0;
                            clid.BorderWidthBottom = 0.50f;

                            clnom                   = new PdfPCell(new Phrase("Nombre de Efectivo", _standardFont));
                            clnom.BorderWidth       = 0;
                            clnom.BorderWidthBottom = 0.75f;
                        }
                        else
                        {
                            clid                   = new PdfPCell(new Phrase("Codigo", _standardFont));
                            clid.BorderWidth       = 0;
                            clid.BorderWidthBottom = 0.50f;

                            clnom                   = new PdfPCell(new Phrase("Nombre de Comisaria", _standardFont));
                            clnom.BorderWidth       = 0;
                            clnom.BorderWidthBottom = 0.75f;
                        }

                        PdfPCell clfec = new PdfPCell(new Phrase("Fecha de Envio", _standardFont));
                        clfec.BorderWidth       = 0;
                        clfec.BorderWidthBottom = 0.50f;

                        tablaDatosPrincipales.AddCell(clNroPapeleta);
                        tablaDatosPrincipales.AddCell(clFalta);
                        tablaDatosPrincipales.AddCell(clEstado);
                        tablaDatosPrincipales.AddCell(clid);
                        tablaDatosPrincipales.AddCell(clnom);
                        tablaDatosPrincipales.AddCell(clfec);

                        PdfPTable tablaDatosConsulta = new PdfPTable(nrocol);
                        tablaDatosConsulta.WidthPercentage = 80;
                        foreach (DataRow dr in ds.Rows)
                        {
                            //Recorriendo la lista y llenando el reporte
                            clNroPapeleta = new PdfPCell(new Phrase(dr["numero_papeleta"].ToString(), _standardFont));

                            String f = (dr["falta"].ToString() == "True") ? "1" : "0";
                            clFalta = new PdfPCell(new Phrase(f, _standardFont));

                            clEstado = new PdfPCell(new Phrase(dr["estado"].ToString(), _standardFont));

                            clid = new PdfPCell(new Phrase(dr["id"].ToString(), _standardFont));

                            clnom = new PdfPCell(new Phrase(dr["nombre"].ToString(), _standardFont));

                            clfec = new PdfPCell(new Phrase(dr["fecha_entrega"].ToString(), _standardFont));

                            tablaDatosConsulta.AddCell(clNroPapeleta);
                            tablaDatosConsulta.AddCell(clFalta);
                            tablaDatosConsulta.AddCell(clEstado);
                            tablaDatosConsulta.AddCell(clid);
                            tablaDatosConsulta.AddCell(clnom);
                            tablaDatosConsulta.AddCell(clfec);
                        }

                        reporte.Add(new iTextSharp.text.Paragraph("Lista de Papeletas Faltantes " + nom));
                        reporte.Add(tablaDatosPrincipales);
                        reporte.Add(tablaDatosConsulta);
                        reporte.Close();
                        writer.Close();

                        //Confirmacion de creacion de reporte y apertura automatica del reporte en pdf
                        MessageBox.Show("Reporte creado con exito");
                        System.Diagnostics.Process.Start(ubicacionReporte);
                    }
                }
                else
                {
                    String str = (tip == 1) ? " efectivo" : "a comisaria";
                    MessageBox.Show("Seleccione un" + str + "...");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
        }