List of usage examples for com.itextpdf.text.pdf PdfPTable PdfPTable
public PdfPTable(final PdfPTable table)
PdfPTable
. From source file:com.solidmaps.webapp.report.MapCivilPdfGenerator.java
License:Open Source License
private void createProductsTable(Document doc) throws DocumentException { DecimalFormat dc = new DecimalFormat("########0.00"); // specify column widths float[] columnWidths = { 2f, 2f, 2f, 2f, 2f, 2.5f }; // create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); // set table width a percentage of the page width table.setWidthPercentage(100f);//from w w w . j a v a2s . com // insert column headings insertCell(table, "PRODUTO", Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, "SALDO DO TRIMESTRE ANTERIOR", Element.ALIGN_CENTER, fontHeaderTableSmall); insertCell(table, "COMPRAS", Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, "VENDAS", Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, "CONSUMO", Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, "ESTOQUE PARA O TRIMESTRE SEGUINTE", Element.ALIGN_CENTER, fontHeaderTableSmall); table.setHeaderRows(1); for (InvoiceInventoryMapEntity productMap : listProductMapVO) { BigDecimal qtdNextPeriod = productMap.getQtdInventoryPreviusTrimester() .add(productMap.getQtdBuyProduct()).subtract(productMap.getQtdSellProduct()) .subtract(productMap.getQtdUtilization()); // Cria a tabela com os Produtos insertCell(table, productMap.getProduct().getName(), Element.ALIGN_CENTER, fontHeaderTableSmall); insertCell(table, dc.format(productMap.getQtdInventoryPreviusTrimester()), Element.ALIGN_CENTER, fontHeaderTableSmall); insertCell(table, dc.format(productMap.getQtdBuyProduct()), Element.ALIGN_CENTER, fontHeaderTableSmall); insertCell(table, dc.format(productMap.getQtdSellProduct()), Element.ALIGN_CENTER, fontHeaderTableSmall); insertCell(table, dc.format(productMap.getQtdUtilization()), Element.ALIGN_CENTER, fontHeaderTableSmall); insertCell(table, dc.format(qtdNextPeriod), Element.ALIGN_CENTER, fontHeaderTableSmall); } doc.add(table); }
From source file:com.solidmaps.webapp.report.MapCivilPdfGenerator.java
License:Open Source License
private void createInvoiceTable(Document doc) throws DocumentException { doc.add(Chunk.NEWLINE);/*from w w w. ja va 2s .c o m*/ // Ajusta o cabealho float[] columnHeader = { 1f }; PdfPTable tableHeader = new PdfPTable(columnHeader); tableHeader.setWidthPercentage(100f); insertCell(tableHeader, "\n RELAO DE COMPRAS DURANTE O TRIMESTRE \n", Element.ALIGN_CENTER, fontText); doc.add(tableHeader); doc.add(Chunk.NEWLINE); // specify column widths float[] columnWidths = { 2f, 2f, 2f, 2f, 2f, 2f, 2.5f, 2f }; // create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); // set table width a percentage of the page width table.setWidthPercentage(100f); // insert column headings insertCell(table, "Data:", Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, "Empresa Vendedora", Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, "Endereo", Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, "Cidade/UF", Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, "CEP", Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, "N. nota Fiscal", Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, "Produto", Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, "Quantidade", Element.ALIGN_CENTER, fontHeaderTable); table.setHeaderRows(1); for (InvoiceProductEntity invoiceProduct : this.listInvoices) { insertCell(table, DateUtils.format(invoiceProduct.getInvoice().getDateCreate()), Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, invoiceProduct.getInvoice().getProvider().getCnpj(), Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, invoiceProduct.getInvoice().getProvider().getStreet(), Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, invoiceProduct.getInvoice().getProvider().getCity(), Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, invoiceProduct.getInvoice().getProvider().getCep(), Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, invoiceProduct.getInvoice().getNumInvoice(), Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, invoiceProduct.getProduct().getProductOfficial().getName(), Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, invoiceProduct.getQtdProduct() + invoiceProduct.getTypeQtdProduct(), Element.ALIGN_CENTER, fontHeaderTable); } doc.add(table); }
From source file:com.solidmaps.webapp.report.MapExercitoPdfGenerator.java
License:Open Source License
private void createFooter(Document doc) throws DocumentException { Calendar cal = Calendar.getInstance(); PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100f);// www . j ava2 s . com table.setHeaderRows(0); table.getDefaultCell().setBorder(PdfPCell.NO_BORDER); StringBuilder sbData = new StringBuilder(); sbData.append(company.getCity()).append(" / ").append(company.getState()).append(", ") .append(cal.get(Calendar.DAY_OF_MONTH)).append(" de ").append(DateUtils.getMonthName(cal)) .append(" de ").append(cal.get(Calendar.YEAR)).append("\n\n"); insertCell(table, sbData.toString(), Element.ALIGN_RIGHT, fontHeaderTableBig, false); insertCell(table, "_________________________________________________ \n Nome: " + company.getUserResponsable().getName() + " \n Cargo: " + company.getUserResponsable().getOffice(), Element.ALIGN_RIGHT, fontHeaderTable, false); doc.add(Chunk.NEWLINE); doc.add(table); }
From source file:com.solidmaps.webapp.report.MapExercitoPdfGenerator.java
License:Open Source License
private void createProductsTable(Document doc) throws DocumentException { Paragraph paragraph = new Paragraph("RESUMO GERAL"); paragraph.setFont(fontText);//from w w w .j ava2s. c o m DecimalFormat dc = new DecimalFormat("########0.00"); // specify column widths float[] columnWidths = { 2f, 2f, 2f, 2f, 2f, 2f, 2.5f }; // create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); // set table width a percentage of the page width table.setWidthPercentage(100f); // insert column headings insertCell(table, "PRODUTO:", Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, "GUIA DE TR?FEGO N:", Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, "ENTRADA", Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, "ESTOQUE DO TRIMESTRE ANTERIOR", Element.ALIGN_CENTER, fontHeaderTableSmall); insertCell(table, "CONSUMO", Element.ALIGN_CENTER, fontHeaderTable); insertCell(table, "ESTOQUE PARA O TRIMESTRE SEGUINTE", Element.ALIGN_CENTER, fontHeaderTableSmall); insertCell(table, "PROCEDNCIA (RAZO SOCIAL, ENDEREO,CIDADE, CEP, E N.DO CERTIFICADO DE REGISTRO)", Element.ALIGN_CENTER, fontHeaderTableTiny); table.setHeaderRows(1); for (InvoiceInventoryMapEntity productMap : listProductMapVO) { String companyCell = "PROCEDNCIA (" + company.getName() + ", " + company.getStreet() + ", " + company.getCity() + ", " + company.getCep() + ", " + license.getNumRegister() + ")"; // Calcula o estoque para o Trimestre seguinte BigDecimal qtdNextPeriod = productMap.getQtdInventoryPreviusTrimester() .add(productMap.getQtdBuyProduct()).subtract(productMap.getQtdSellProduct()) .subtract(productMap.getQtdUtilization()); // Cria a tabela com os Produtos insertCell(table, productMap.getProduct().getName(), Element.ALIGN_CENTER, fontHeaderTableSmall); insertCell(table, productMap.getTrafficGuide(), Element.ALIGN_CENTER, fontHeaderTableSmall); insertCell(table, dc.format(productMap.getQtdBuyProduct()), Element.ALIGN_CENTER, fontHeaderTableSmall); insertCell(table, dc.format(productMap.getQtdInventoryPreviusTrimester()), Element.ALIGN_CENTER, fontHeaderTableSmall); insertCell(table, dc.format(productMap.getQtdUtilization()), Element.ALIGN_CENTER, fontHeaderTableSmall); insertCell(table, dc.format(qtdNextPeriod), Element.ALIGN_CENTER, fontHeaderTableSmall); insertCell(table, companyCell, Element.ALIGN_CENTER, fontHeaderTableSmall); } doc.add(paragraph); doc.add(table); doc.add(Chunk.NEWLINE); }
From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java
private void createTable(Document doc, RequerimentFederalEnum type, LicensePFEntity license, List<ProductOfficialEntity> listProducts) throws DocumentException { // create PDF table with the given widths PdfPTable table = new PdfPTable(4); // set table width a percentage of the page width table.setWidthPercentage(100f);//from www .j a v a2 s. c o m this.createCompany(table, license); // Alterao Cadastral this.createAlteracaoCadastral(table, type); // Descrio this.insertHeaderCell(table, "3 - DESCREVER AS PRINCIPAIS ALTERAES OCORRIDAS", 4); this.insertCell(table, this.createProductsText(listProducts, type), 4); // Uso Oficial this.insertCellProtocol(table, license); // Footer this.createFooter(table); // Table pai PdfPTable tableFather = new PdfPTable(1); tableFather.setWidthPercentage(100f); PdfPCell cellFather = new PdfPCell(table); cellFather.setBorderWidth(2); tableFather.addCell(cellFather); doc.add(this.createHeader()); doc.add(tableFather); }
From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java
private void insertCellProtocol(PdfPTable table, LicensePFEntity license) { PdfPTable tableProtocol = new PdfPTable(1); tableProtocol.setWidthPercentage(100f); Paragraph officialPhrase = new Paragraph("USO OFICIAL" + SEPARATOR, FONT_PARAGRAPH); officialPhrase.setAlignment(Element.ALIGN_LEFT); Paragraph protocolPhrase = new Paragraph("ETIQUETA PROTOCOLO" + SEPARATOR_DOUBLE + SEPARATOR_DOUBLE + SEPARATOR_DOUBLE + SEPARATOR_DOUBLE + SEPARATOR_DOUBLE + SEPARATOR, FONT_PROTOCOL); protocolPhrase.setAlignment(Element.ALIGN_LEFT); Paragraph obsPhrase = new Paragraph("Observao Importante!" + SEPARATOR, FONT_HEADER); Paragraph obsStringPhrase = new Paragraph( "Protocolar este Anexo somente quando no conjugado com a alterao efetiva ou a renovao da licena.", FONT_PARAGRAPH);/*from w ww . j a v a2 s .c om*/ Paragraph fullPhrase = new Paragraph(); fullPhrase.add(officialPhrase); fullPhrase.add(protocolPhrase); fullPhrase.add(obsPhrase); fullPhrase.add(obsStringPhrase); PdfPCell cell = new PdfPCell(fullPhrase); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPadding(5f); tableProtocol.addCell(cell); PdfPCell cellProtocol = new PdfPCell(tableProtocol); cellProtocol.setColspan(2); table.addCell(cellProtocol); table.addCell(this.createCellEtiqueta(license)); }
From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java
private PdfPCell createCellEtiqueta(LicensePFEntity license) { PdfPTable tableProtocol = new PdfPTable(3); tableProtocol.setWidthPercentage(100f); this.insertCell(tableProtocol, "LOCAL E DATA" + SEPARATOR_DOUBLE + license.getCompany().getState() + ", " + DateUtils.format(Calendar.getInstance()), 3); this.insertCell(tableProtocol, "REPRESENTANTE LEGAL" + SEPARATOR_DOUBLE + license.getCompany().getUserResponsable().getName(), 3); this.insertCell(tableProtocol, "IDENTIDADE (N - RGO - UF)" + SEPARATOR_DOUBLE + license.getCompany().getUserResponsable().getRg(), 2); this.insertCell(tableProtocol, "CPF" + SEPARATOR_DOUBLE + license.getCompany().getUserResponsable().getCpf(), 1); this.insertCell(tableProtocol, "DDD" + SEPARATOR_DOUBLE + license.getCompany().getUserResponsable().getPhoneDDD(), 1); this.insertCell(tableProtocol, "TELEFONE" + SEPARATOR_DOUBLE + license.getCompany().getUserResponsable().getPhoneNumber(), 1); this.insertCell(tableProtocol, "FAX" + SEPARATOR_DOUBLE + license.getCompany().getUserResponsable().getNumFax(), 1); this.insertCell(tableProtocol, "ASSINATURA" + SEPARATOR_DOUBLE + "________________________________________", 3);/* w w w .j a va 2 s. c om*/ PdfPCell cell = new PdfPCell(tableProtocol); cell.setColspan(4); return cell; }
From source file:com.systemevent.jsfclass.util.PdfEvento.java
public PdfPTable Tabla_compleja() { //creamos una tabla con 3 columnas PdfPTable mitablacompleja = new PdfPTable(3); //aadimos texto con formato a la primera celda PdfPCell celda = new PdfPCell(new Paragraph("Historial de Observaciones", FontFactory.getFont("arial", // fuente 22, // tamao Font.BOLD, // estilo BaseColor.RED))); // color //unimos esta celda con otras 2 celda.setColspan(3);/*from www . ja v a2 s . c o m*/ //alineamos el contenido al centro celda.setHorizontalAlignment(Element.ALIGN_CENTER); // aadimos un espaciado celda.setPadding(12.0f); //colocamos un color de fondo celda.setBackgroundColor(BaseColor.GRAY); //se aade a la tabla mitablacompleja.addCell(celda); //fila 2 celda = new PdfPCell(new Paragraph("AUDITORIA DE SISTEMAS")); celda.setColspan(2); celda.setBackgroundColor(BaseColor.GREEN); mitablacompleja.addCell(celda); celda = new PdfPCell(new Paragraph("Aprobado")); celda.setBackgroundColor(BaseColor.LIGHT_GRAY); mitablacompleja.addCell(celda); //fila 3 celda = new PdfPCell(new Paragraph("COMPILADORES")); celda.setColspan(2); celda.setBackgroundColor(BaseColor.YELLOW); mitablacompleja.addCell(celda); celda = new PdfPCell(new Paragraph("Reprobado")); celda.setBackgroundColor(BaseColor.LIGHT_GRAY); mitablacompleja.addCell(celda); //fila 4 celda = new PdfPCell(new Paragraph("Prog. Bajo Nivel")); celda.setColspan(2); celda.setBackgroundColor(BaseColor.CYAN); mitablacompleja.addCell(celda); celda = new PdfPCell(new Paragraph("Eximido")); celda.setBackgroundColor(BaseColor.LIGHT_GRAY); mitablacompleja.addCell(celda); //fila 5 mitablacompleja.addCell("Conclusion"); celda = new PdfPCell(new Paragraph("GET A LIFE!!!")); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); celda.setColspan(2); celda.setBackgroundColor(BaseColor.ORANGE); mitablacompleja.addCell(celda); // se retorna la tabla return mitablacompleja; }
From source file:com.thelinh.gui.PreviewExam.java
private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrintActionPerformed if (this.txtExamCode.getText().equals("")) { JOptionPane.showMessageDialog(this, "Hy nhp m ?"); } else {/*from w w w . j a v a 2 s. c o m*/ JFileChooser fc = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF files (*.pdf)", "pdf"); fc.setFileFilter(filter); int rt = fc.showSaveDialog(this); if (rt == JFileChooser.APPROVE_OPTION) { String filepath = fc.getSelectedFile().getPath(); if (filepath.indexOf(".") == -1) { filepath = filepath + ".pdf"; } String dafilepath = (new StringBuffer(filepath)).insert(filepath.length() - 4, ".da").toString(); try { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(filepath)); document.open(); // Add title Paragraph p = new Paragraph("Tr?ng ?i h?c Bch Khoa H Ni", timesBold_25); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(5); document.add(p); p = new Paragraph("?? thi mn " + this.lbSubject.getText(), timesBold_25); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(25); document.add(p); p = new Paragraph( "Ng?i ra ?: " + Controller.getCurrentAdmin().getAdminName() + ", Ngy ra ?: " + (new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime())), times_15); p.setAlignment(Element.ALIGN_LEFT); p.setSpacingAfter(5); document.add(p); p = new Paragraph("M ?: " + this.txtExamCode.getText() + " Th?i gian lm bi: " + spTime.getValue().toString() + " pht", timesBold_15); p.setSpacingAfter(25); document.add(p); for (int i = 0; i < this.questionList.size(); i++) { Question question = this.questionList.get(i); ArrayList<Answer> answerList = AnswerSql .getAnswersByQuestionId(question.getQuestionId().trim()); Phrase questionNumber = new Phrase("Cu " + (i + 1) + ": ", timesBold_15); Phrase questionContent = new Phrase(question.getQuestion(), times_15); Paragraph questionTitle = new Paragraph(); questionTitle.add(questionNumber); questionTitle.add(questionContent); document.add(questionTitle); PdfPTable table = new PdfPTable(2); for (int j = 0; j < answerList.size(); j++) { Answer ans = answerList.get(j); Phrase cap = new Phrase(Character.toString((char) (j + 65)) + ". ", timesBold_15); Phrase answerContent = new Phrase(ans.getAnswer(), times_15); Phrase elem = new Phrase(); elem.add(cap); elem.add(answerContent); PdfPCell cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setPhrase(elem); cell.setFixedHeight(25); table.addCell(cell); } document.add(table); } document.close(); // if (Desktop.isDesktopSupported()) { // try { // File myFile = new File(filepath); // Desktop.getDesktop().open(myFile); // } catch (IOException ex) { // // no application registered for PDFs // System.out.println(ex.toString()); // } // } document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(dafilepath)); document.open(); // Add title p = new Paragraph("Tr?ng ?i h?c Bch Khoa H Ni", timesBold_25); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(5); document.add(p); p = new Paragraph("?? thi mn " + this.lbSubject.getText(), timesBold_25); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(25); document.add(p); p = new Paragraph( "Ng?i ra ?: " + Controller.getCurrentAdmin().getAdminName() + ", Ngy ra ?: " + (new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime())), times_15); p.setAlignment(Element.ALIGN_LEFT); p.setSpacingAfter(5); document.add(p); p = new Paragraph("M ?: " + this.txtExamCode.getText() + " Th?i gian lm bi: " + spTime.getValue().toString() + " pht", timesBold_15); p.setSpacingAfter(25); document.add(p); for (int i = 0; i < this.questionList.size(); i++) { Question question = this.questionList.get(i); ArrayList<Answer> answerList = AnswerSql .getAnswersByQuestionId(question.getQuestionId().trim()); Phrase questionNumber = new Phrase("Cu " + (i + 1) + ": ", timesBold_15); Phrase questionContent = new Phrase(question.getQuestion(), times_15); Paragraph questionTitle = new Paragraph(); questionTitle.add(questionNumber); questionTitle.add(questionContent); document.add(questionTitle); PdfPTable table = new PdfPTable(2); for (int j = 0; j < answerList.size(); j++) { Answer ans = answerList.get(j); Phrase cap = new Phrase(Character.toString((char) (j + 65)) + ". ", timesBold_15); Phrase answerContent = null; if (ans.getYesNo()) { answerContent = new Phrase(ans.getAnswer(), timesBold_15); } else { answerContent = new Phrase(ans.getAnswer(), times_15); } Phrase elem = new Phrase(); elem.add(cap); elem.add(answerContent); PdfPCell cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setPhrase(elem); cell.setFixedHeight(25); table.addCell(cell); } document.add(table); } document.close(); } catch (FileNotFoundException | DocumentException ex) { Logger.getLogger(PreviewExam.class.getName()).log(Level.SEVERE, null, ex); } } } }
From source file:com.thelinh.gui.Statistics.java
private void btnExportReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportReportActionPerformed Document document = new Document() { };//from w w w . ja va2 s.c om try { JFileChooser jfc = new JFileChooser("Save File"); if (jfc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { // String content = this.txtReport.getText(); jfc.setDialogTitle("Save File"); FileOutputStream fos = new FileOutputStream(jfc.getSelectedFile()); PdfWriter.getInstance(document, fos); // Font rfont = FontFactory.getFont("resources/fonts/vuArial.ttf", IDENTITY_H, true); Font rfont = new Font(BaseFont.createFont("resources/fonts/vuTimesBold.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); document.open(); document.add(new Paragraph( " TRNG ?I HC B?CH KHOA H NI", rfont)); if (k == 1) { document.add(new Paragraph( "\t\t TH?NG K MN HC\n", rfont)); String sqlSubject1 = "SELECT Count(SubjectId) AS subjectAll FROM Subjects"; String sqlSubject2 = "SELECT Subjects.SubjectName AS subjectChap, Count(*) AS subjectNumber FROM Chaps,Subjects WHERE Chaps.SubjectId = Subjects.SubjectId GROUP BY Subjects.SubjectName"; ResultSet rs1 = LoadTable.Display(sqlSubject1); ResultSet rs2 = LoadTable.Display(sqlSubject2); try { if (rs1.next()) { document.add(new Paragraph( "Tng s mn h?c l " + rs1.getInt("subjectAll") + "\n", rfont)); } document.add(new Paragraph("Thng k s chng ca mn h?c: \n\n", rfont)); PdfPTable table = new PdfPTable(2); PdfPCell header1 = new PdfPCell(new Paragraph("Mn h?c", rfont)); PdfPCell header2 = new PdfPCell(new Paragraph("S chng", rfont)); table.addCell(header1); table.addCell(header2); while (rs2.next()) { PdfPCell header3 = new PdfPCell(new Paragraph(rs2.getString("subjectChap"), rfont)); table.addCell(header3); PdfPCell header4 = new PdfPCell(new Paragraph("" + rs2.getInt("subjectNumber"))); table.addCell(header4); } document.add(table); } catch (SQLException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } } else if (k == 2) { try { document.add(new Paragraph( "\t\t TH?NG K CU HI\n", rfont)); String sqlQuestion1 = "SELECT Count(QuestionId) AS questionAll FROM Questions"; String sqlQuestion2 = "SELECT SubjectName AS subjectName, Count(QuestionId) AS questionSubject FROM Questions,Subjects WHERE Subjects.SubjectId = Questions.SubjectId GROUP BY Subjects.SubjectName"; ResultSet rs1 = LoadTable.Display(sqlQuestion1); ResultSet rs2 = LoadTable.Display(sqlQuestion2); if (rs1.next()) { document.add(new Paragraph( "Tng s cu h?i l " + rs1.getInt("questionAll") + "\n", rfont)); } document.add(new Paragraph("Thng k s cu h?i ca mn h?c: \n\n", rfont)); PdfPTable table = new PdfPTable(2); PdfPCell header1 = new PdfPCell(new Paragraph("Mn h?c", rfont)); PdfPCell header2 = new PdfPCell(new Paragraph("S cu h?i", rfont)); table.addCell(header1); table.addCell(header2); while (rs2.next()) { PdfPCell header3 = new PdfPCell(new Paragraph(rs2.getString("subjectName"), rfont)); table.addCell(header3); PdfPCell header4 = new PdfPCell(new Paragraph("" + rs2.getInt("questionSubject"))); table.addCell(header4); } document.add(table); } catch (SQLException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } } else if (k == 3) { try { document.add(new Paragraph( "\t\t TH?NG K NGI DNG\n", rfont)); String sqlUser1 = "SELECT Count(UserId) AS userAll FROM Users"; String sqlUser2 = "SELECT Class AS className, Count(UserId) AS userClass FROM Users GROUP BY Class"; ResultSet rs1 = LoadTable.Display(sqlUser1); ResultSet rs2 = LoadTable.Display(sqlUser2); if (rs1.next()) { document.add(new Paragraph( "Tng s ng?i dng l " + rs1.getInt("userAll") + "\n", rfont)); } document.add(new Paragraph("Thng k s h?c sinh ca lp: \n\n", rfont)); PdfPTable table = new PdfPTable(2); PdfPCell header1 = new PdfPCell(new Paragraph("Lp", rfont)); PdfPCell header2 = new PdfPCell(new Paragraph("S h?c sinh", rfont)); table.addCell(header1); table.addCell(header2); while (rs2.next()) { PdfPCell header3 = new PdfPCell(new Paragraph(rs2.getString("className"), rfont)); table.addCell(header3); PdfPCell header4 = new PdfPCell(new Paragraph("" + rs2.getInt("userClass"))); table.addCell(header4); } document.add(table); } catch (SQLException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } } else if (k == 4) { document.add(new Paragraph( "\t\t TH?NG K KT QU\n", rfont)); String sqlResult1 = "SELECT Count(*) AS resultAll FROM Results"; String sqlResult2 = "SELECT Count(*) AS exam1 FROM Results WHERE Result <= 4"; String sqlResult3 = "SELECT Count(*) AS exam2 FROM Results WHERE Result > 4 AND Result < 6"; String sqlResult4 = "SELECT Count(*) AS exam3 FROM Results WHERE Result >= 6 AND Result < 8"; String sqlResult5 = "SELECT Count(*) AS exam4 FROM Results WHERE Result >= 8"; ResultSet rs1 = LoadTable.Display(sqlResult1); ResultSet rs2 = LoadTable.Display(sqlResult2); ResultSet rs3 = LoadTable.Display(sqlResult3); ResultSet rs4 = LoadTable.Display(sqlResult4); ResultSet rs5 = LoadTable.Display(sqlResult5); if (rs1.next()) { document.add( new Paragraph("Tng s bi thi l " + rs1.getInt("resultAll") + "\n", rfont)); } document.add(new Paragraph("Thng k im thi: \n\n", rfont)); PdfPTable table = new PdfPTable(2); PdfPCell header1 = new PdfPCell(new Paragraph("?im", rfont)); PdfPCell header2 = new PdfPCell(new Paragraph("S bi thi", rfont)); table.addCell(header1); table.addCell(header2); PdfPCell header3 = new PdfPCell(new Paragraph("<= 4")); table.addCell(header3); if (rs2.next()) { PdfPCell header4 = new PdfPCell(new Paragraph(rs2.getInt("exam1"))); table.addCell(header4); } PdfPCell header5 = new PdfPCell(new Paragraph("> 4 v < 6")); table.addCell(header5); if (rs3.next()) { PdfPCell header6 = new PdfPCell(new Paragraph(rs3.getInt("exam2"))); table.addCell(header6); } PdfPCell header7 = new PdfPCell(new Paragraph(">= 6 v < 8")); table.addCell(header7); if (rs4.next()) { PdfPCell header8 = new PdfPCell(new Paragraph(rs4.getInt("exam3"))); table.addCell(header8); } PdfPCell header9 = new PdfPCell(new Paragraph(">= 8")); table.addCell(header9); if (rs5.next()) { PdfPCell header10 = new PdfPCell(new Paragraph(rs5.getInt("exam4"))); table.addCell(header10); } document.add(table); } document.add(new Paragraph( " H Ni, ngy 09 thng 12 nm 2016\n", rfont)); document.add(new Paragraph( " Gio Vin\n", rfont)); document.add(new Paragraph( " " + Controller.getCurrentAdmin().getAdminName() + "\n", rfont)); document.close(); JOptionPane.showMessageDialog(null, "Save success"); } } catch (FileNotFoundException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Statistics.class.getName()).log(Level.SEVERE, null, ex); } }