Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.51 KB | None | 0 0
  1. private void btnPdfActionPerformed(java.awt.event.ActionEvent evt) {
  2. // TODO add your handling code here:
  3. this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  4. Properties systemProp = System.getProperties();
  5. p2 = loadProperties(PROP_FILE);
  6.  
  7. // Ambil current dir
  8. String currentDir = systemProp.getProperty("user.dir");
  9.  
  10. File dir = new File(currentDir);
  11. String reportName = "MasterFormulir.jrxml";
  12. String reportDirName = "report";
  13.  
  14. File fileRpt;
  15. String fullPath = "";
  16. if (dir.isDirectory()) {
  17. String[] isiDir = dir.list();
  18. // for (int i = 0; i < isiDir.length; i++) {
  19. // fileRpt = new File(currentDir + File.separatorChar + isiDir[i] + File.separatorChar +
  20. // reportDirName + File.separatorChar + reportName);
  21.  
  22. fileRpt = new File(currentDir + File.separatorChar +
  23. reportDirName + File.separatorChar + reportName);
  24.  
  25. if (fileRpt.isFile()) { // Cek apakah file MasterFormulir.jrxml ada
  26. fullPath = fileRpt.toString();
  27. System.out.println("Found Report File at : " + fullPath);
  28. } // end if
  29. // } // end for i
  30. } // end if
  31.  
  32. // Ambil Direktori tempat file RptMaster.jrxml berada
  33. String[] subRptDir = fullPath.split(reportName);
  34. System.out.println("Report Directory at : " + subRptDir[0]);
  35. String reportDir = subRptDir[0];
  36. System.out.println("Report Directory at : " + reportDir);
  37.  
  38. // // String reportDir = systemProp.getProperty("user.dir") + File.separator + reportDirName + File.separator;
  39. // String reportDir = "";
  40. // File dirr = new File(".");
  41. // reportDir = dirr.getCanonicalPath()+"\\report\\";
  42. // System.out.println("Report Directory at : " + reportDir);
  43.  
  44. // Ambil Kode Kategori
  45. final String nip = txtCetakNip.getText();
  46. Connection con = null;
  47. try {
  48. String jdbcDriver = "com.mysql.jdbc.Driver";
  49. Class.forName(jdbcDriver);
  50. String url = "jdbc:mysql://"+p2.getProperty("Ip Server")+"/db_simpeg";
  51. String user = "admin";
  52. String pass = "simpeg";
  53.  
  54. con = (Connection) DriverManager.getConnection(url, user, pass);
  55. Statement stm = (Statement) con.createStatement();
  56.  
  57. // Persiapkan parameter untuk Report
  58. Map<String, Object> parameters = new HashMap<String, Object>();
  59. parameters.put("nip", nip);
  60. parameters.put("SUBREPORT_DIR", reportDir);
  61.  
  62. try {
  63. JasperReport JRpt = JasperCompileManager.compileReport(fullPath);
  64. JasperPrint JPrint = JasperFillManager.fillReport(JRpt, parameters, con);
  65. JasperViewer.viewReport(JPrint, false);
  66. } catch (Exception rptexcpt) {
  67. System.out.println("Report Can't view because : " + rptexcpt);
  68. }
  69. } catch (Exception e) {
  70. //System.out.println(e);
  71. e.printStackTrace();
  72. }
  73. this.setCursor(Cursor.getDefaultCursor());
  74.  
  75. }
  76.  
  77. private void btnPrinterActionPerformed(java.awt.event.ActionEvent evt) {
  78. // TODO add your handling code here:
  79. this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  80. Properties systemProp = System.getProperties();
  81. p2 = loadProperties(PROP_FILE);
  82.  
  83. // Ambil current dir
  84. String currentDir = systemProp.getProperty("user.dir");
  85.  
  86. File dir = new File(currentDir);
  87. String reportName = "MasterFormulir.jrxml";
  88. String reportDirName = "report";
  89.  
  90. File fileRpt;
  91. String fullPath = "";
  92. if (dir.isDirectory()) {
  93. String[] isiDir = dir.list();
  94. // for (int i = 0; i < isiDir.length; i++) {
  95. // fileRpt = new File(currentDir + File.separatorChar + isiDir[i] + File.separatorChar +
  96. // reportDirName + File.separatorChar + reportName);
  97. fileRpt = new File(currentDir + File.separatorChar +
  98. reportDirName + File.separatorChar + reportName);
  99.  
  100. if (fileRpt.isFile()) { // Cek apakah file MasterFormulir.jrxml ada
  101. fullPath = fileRpt.toString();
  102. System.out.println("Found Report File at : " + fullPath);
  103. } // end if
  104. // } // end for i
  105. } // end if
  106.  
  107. // Ambil Direktori tempat file RptMaster.jrxml berada
  108. String[] subRptDir = fullPath.split(reportName);
  109. String reportDir = subRptDir[0];
  110. System.out.println("Report Directory at : " + reportDir);
  111.  
  112. // Ambil Kode Kategori
  113. final String nip = txtCetakNip.getText();
  114. Connection con = null;
  115. try {
  116. String jdbcDriver = "com.mysql.jdbc.Driver";
  117. Class.forName(jdbcDriver);
  118. String url = "jdbc:mysql://"+p2.getProperty("Ip Server")+"/db_simpeg";
  119. String user = "admin";
  120. String pass = "simpeg";
  121.  
  122. con = (Connection) DriverManager.getConnection(url, user, pass);
  123. Statement stm = (Statement) con.createStatement();
  124.  
  125. // Persiapkan parameter untuk Report
  126. Map<String, Object> parameters = new HashMap<String, Object>();
  127. parameters.put("nip", nip);
  128. parameters.put("SUBREPORT_DIR", reportDir);
  129.  
  130. try {
  131. JasperReport JRpt = JasperCompileManager.compileReport(fullPath);
  132. JasperPrint JPrint = JasperFillManager.fillReport(JRpt, parameters, con);
  133. JasperPrintManager.printPage(JPrint, 0, false);
  134. } catch (Exception rptexcpt) {
  135. System.out.println("Report Can't view because : " + rptexcpt);
  136. }
  137. } catch (Exception e) {
  138. //System.out.println(e);
  139. e.printStackTrace();
  140. }
  141. this.setCursor(Cursor.getDefaultCursor());
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement