Exemplo n.º 1
0
        protected void getReport(List <Entities.ClassRoom> listClassRoom)
        {
            try
            {
                List <Entities.ClassRoom> listRoom     = listClassRoom;
                System.IO.MemoryStream    memoryStream = new System.IO.MemoryStream();
                text::Document            pdfDoc       = new text::Document(text::PageSize.A4, 10, 10, 10, 10);
                pdfDoc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
                PdfWriter.GetInstance(pdfDoc, memoryStream);
                pdfDoc.Open();

                String imagepath           = Server.MapPath("../../images/page-icons");
                iTextSharp.text.Image deas = iTextSharp.text.Image.GetInstance(imagepath + "/DEAS-logo.jpg");
                deas.ScaleToFit(140f, 120f);
                //Give space before image
                deas.SpacingBefore = 10f;
                //Give some space after the image
                deas.SpacingAfter = 1f;
                deas.Alignment    = text::Element.ALIGN_LEFT;
                pdfDoc.Add(deas);

                text::Paragraph title = new text::Paragraph();
                title.Font      = text::FontFactory.GetFont("dax-black", 32, new text::BaseColor(0, 51, 102));
                title.Alignment = text::Element.ALIGN_CENTER;
                title.Add("\n\n Reporte de Aulas\n\n\n\n");
                pdfDoc.Add(title);

                PdfPTable oPTable = new PdfPTable(6);
                oPTable.TotalWidth    = 100;
                oPTable.SpacingBefore = 20f;
                oPTable.SpacingAfter  = 30f;
                oPTable.AddCell("Descripción");
                oPTable.AddCell("Capacidad");
                oPTable.AddCell("Programa");
                oPTable.AddCell("Tipo de Aula");
                oPTable.AddCell("Localizacion");
                oPTable.AddCell("Estado");

                if (listRoom.Count > 0)
                {
                    foreach (Entities.ClassRoom pRoom in listRoom)
                    {
                        oPTable.AddCell(pRoom.num_room);
                        oPTable.AddCell(pRoom.size.ToString());
                        oPTable.AddCell(pRoom.oProgram.name);
                        oPTable.AddCell(pRoom.oClassRoomsType.description);
                        oPTable.AddCell(pRoom.oLocation.oHeadquarters.description + " - " + pRoom.oLocation.building + " - " + pRoom.oLocation.module);
                        oPTable.AddCell((pRoom.state == 1 ? "Activo" : "Inactivo"));
                    }
                }
                else
                {
                    PdfPCell cell = new PdfPCell(new text::Phrase("No existen aulas registrados."));
                    cell.Colspan             = 5;
                    cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
                    oPTable.AddCell(cell);
                }

                pdfDoc.Add(oPTable);
                pdfDoc.Close();

                byte[] bytes = memoryStream.ToArray();
                memoryStream.Close();
                Response.Clear();
                Response.ContentType = "application/pdf";
                Response.AddHeader("Content-Disposition", "attachment; filename=Aulas.pdf");
                Response.ContentType = "application/pdf";
                Response.Buffer      = true;
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.BinaryWrite(bytes);
                Response.End();
                Response.Close();
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }
Exemplo n.º 2
0
        protected void btnReport_Click(object sender, EventArgs e)
        {
            try
            {
                List <Entities.Teacher> listTeacher  = TeacherBLL.getInstance().getAll();
                System.IO.MemoryStream  memoryStream = new System.IO.MemoryStream();
                text::Document          pdfDoc       = new text::Document(text::PageSize.A4, 10, 10, 10, 10);
                pdfDoc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
                PdfWriter.GetInstance(pdfDoc, memoryStream);
                pdfDoc.Open();

                String imagepath           = Server.MapPath("../../images/page-icons");
                iTextSharp.text.Image deas = iTextSharp.text.Image.GetInstance(imagepath + "/DEAS-logo.jpg");
                deas.ScaleToFit(140f, 120f);
                //Give space before image
                deas.SpacingBefore = 10f;
                //Give some space after the image
                deas.SpacingAfter = 1f;
                deas.Alignment    = text::Element.ALIGN_LEFT;
                pdfDoc.Add(deas);

                text::Paragraph title = new text::Paragraph();
                title.Font      = text::FontFactory.GetFont("dax-black", 32, new text::BaseColor(0, 51, 102));
                title.Alignment = text::Element.ALIGN_CENTER;
                title.Add("\n\n Reporte de Profesores \n\n\n\n");
                pdfDoc.Add(title);

                PdfPTable oPTable = new PdfPTable(5);
                oPTable.TotalWidth    = 100;
                oPTable.SpacingBefore = 20f;
                oPTable.SpacingAfter  = 30f;
                oPTable.AddCell("Identificación");
                oPTable.AddCell("Nombre Completo");
                oPTable.AddCell("Teléfono");
                oPTable.AddCell("Correo Electrónico");
                oPTable.AddCell("Estado");

                if (listTeacher.Count > 0)
                {
                    foreach (Entities.Teacher pTeacher in listTeacher)
                    {
                        oPTable.AddCell(pTeacher.id);
                        oPTable.AddCell(pTeacher.name + " " + pTeacher.lastName);
                        oPTable.AddCell(pTeacher.cellPhone);
                        oPTable.AddCell(pTeacher.email);
                        oPTable.AddCell((pTeacher.state == 1 ? "Activo" : "Inactivo"));
                    }
                }
                else
                {
                    PdfPCell cell = new PdfPCell(new text::Phrase("No existen profesores registrados."));
                    cell.Colspan             = 5;
                    cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
                    oPTable.AddCell(cell);
                }

                pdfDoc.Add(oPTable);
                pdfDoc.Close();

                byte[] bytes = memoryStream.ToArray();
                memoryStream.Close();
                Response.Clear();
                Response.ContentType = "application/pdf";
                Response.AddHeader("Content-Disposition", "attachment; filename=Profesores.pdf");
                Response.ContentType = "application/pdf";
                Response.Buffer      = true;
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.BinaryWrite(bytes);
                Response.End();
                Response.Close();
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }