Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void btnPdfActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
- Properties systemProp = System.getProperties();
- p2 = loadProperties(PROP_FILE);
- // Ambil current dir
- String currentDir = systemProp.getProperty("user.dir");
- File dir = new File(currentDir);
- String reportName = "MasterFormulir.jrxml";
- String reportDirName = "report";
- File fileRpt;
- String fullPath = "";
- if (dir.isDirectory()) {
- String[] isiDir = dir.list();
- // for (int i = 0; i < isiDir.length; i++) {
- // fileRpt = new File(currentDir + File.separatorChar + isiDir[i] + File.separatorChar +
- // reportDirName + File.separatorChar + reportName);
- fileRpt = new File(currentDir + File.separatorChar +
- reportDirName + File.separatorChar + reportName);
- if (fileRpt.isFile()) { // Cek apakah file MasterFormulir.jrxml ada
- fullPath = fileRpt.toString();
- System.out.println("Found Report File at : " + fullPath);
- } // end if
- // } // end for i
- } // end if
- // Ambil Direktori tempat file RptMaster.jrxml berada
- String[] subRptDir = fullPath.split(reportName);
- System.out.println("Report Directory at : " + subRptDir[0]);
- String reportDir = subRptDir[0];
- System.out.println("Report Directory at : " + reportDir);
- // // String reportDir = systemProp.getProperty("user.dir") + File.separator + reportDirName + File.separator;
- // String reportDir = "";
- // File dirr = new File(".");
- // reportDir = dirr.getCanonicalPath()+"\\report\\";
- // System.out.println("Report Directory at : " + reportDir);
- // Ambil Kode Kategori
- final String nip = txtCetakNip.getText();
- Connection con = null;
- try {
- String jdbcDriver = "com.mysql.jdbc.Driver";
- Class.forName(jdbcDriver);
- String url = "jdbc:mysql://"+p2.getProperty("Ip Server")+"/db_simpeg";
- String user = "admin";
- String pass = "simpeg";
- con = (Connection) DriverManager.getConnection(url, user, pass);
- Statement stm = (Statement) con.createStatement();
- // Persiapkan parameter untuk Report
- Map<String, Object> parameters = new HashMap<String, Object>();
- parameters.put("nip", nip);
- parameters.put("SUBREPORT_DIR", reportDir);
- try {
- JasperReport JRpt = JasperCompileManager.compileReport(fullPath);
- JasperPrint JPrint = JasperFillManager.fillReport(JRpt, parameters, con);
- JasperViewer.viewReport(JPrint, false);
- } catch (Exception rptexcpt) {
- System.out.println("Report Can't view because : " + rptexcpt);
- }
- } catch (Exception e) {
- //System.out.println(e);
- e.printStackTrace();
- }
- this.setCursor(Cursor.getDefaultCursor());
- }
- private void btnPrinterActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
- Properties systemProp = System.getProperties();
- p2 = loadProperties(PROP_FILE);
- // Ambil current dir
- String currentDir = systemProp.getProperty("user.dir");
- File dir = new File(currentDir);
- String reportName = "MasterFormulir.jrxml";
- String reportDirName = "report";
- File fileRpt;
- String fullPath = "";
- if (dir.isDirectory()) {
- String[] isiDir = dir.list();
- // for (int i = 0; i < isiDir.length; i++) {
- // fileRpt = new File(currentDir + File.separatorChar + isiDir[i] + File.separatorChar +
- // reportDirName + File.separatorChar + reportName);
- fileRpt = new File(currentDir + File.separatorChar +
- reportDirName + File.separatorChar + reportName);
- if (fileRpt.isFile()) { // Cek apakah file MasterFormulir.jrxml ada
- fullPath = fileRpt.toString();
- System.out.println("Found Report File at : " + fullPath);
- } // end if
- // } // end for i
- } // end if
- // Ambil Direktori tempat file RptMaster.jrxml berada
- String[] subRptDir = fullPath.split(reportName);
- String reportDir = subRptDir[0];
- System.out.println("Report Directory at : " + reportDir);
- // Ambil Kode Kategori
- final String nip = txtCetakNip.getText();
- Connection con = null;
- try {
- String jdbcDriver = "com.mysql.jdbc.Driver";
- Class.forName(jdbcDriver);
- String url = "jdbc:mysql://"+p2.getProperty("Ip Server")+"/db_simpeg";
- String user = "admin";
- String pass = "simpeg";
- con = (Connection) DriverManager.getConnection(url, user, pass);
- Statement stm = (Statement) con.createStatement();
- // Persiapkan parameter untuk Report
- Map<String, Object> parameters = new HashMap<String, Object>();
- parameters.put("nip", nip);
- parameters.put("SUBREPORT_DIR", reportDir);
- try {
- JasperReport JRpt = JasperCompileManager.compileReport(fullPath);
- JasperPrint JPrint = JasperFillManager.fillReport(JRpt, parameters, con);
- JasperPrintManager.printPage(JPrint, 0, false);
- } catch (Exception rptexcpt) {
- System.out.println("Report Can't view because : " + rptexcpt);
- }
- } catch (Exception e) {
- //System.out.println(e);
- e.printStackTrace();
- }
- this.setCursor(Cursor.getDefaultCursor());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement