예제 #1
0
  /**
   * Generates and displays <b>BA Unit</b> report.
   *
   * @param appBean Application bean containing data for the report.
   */
  public static JasperPrint getLodgementReport(
      LodgementBean lodgementBean, Date dateFrom, Date dateTo) {
    HashMap inputParameters = new HashMap();
    Date currentdate = new Date(System.currentTimeMillis());
    inputParameters.put("REPORT_LOCALE", Locale.getDefault());

    inputParameters.put("CURRENT_DATE", currentdate);

    inputParameters.put("USER", SecurityBean.getCurrentUser().getFullUserName());
    inputParameters.put("FROMDATE", dateFrom);
    inputParameters.put("TODATE", dateTo);
    LodgementBean[] beans = new LodgementBean[1];
    beans[0] = lodgementBean;
    JRDataSource jds = new JRBeanArrayDataSource(beans);
    try {
      return JasperFillManager.fillReport(
          ReportManager.class.getResourceAsStream("/reports/LodgementReportSamoa.jasper"),
          inputParameters,
          jds);
    } catch (JRException ex) {
      LogUtility.log(LogUtility.getStackTraceAsString(ex), Level.SEVERE);
      MessageUtility.displayMessage(
          ClientMessage.REPORT_GENERATION_FAILED, new Object[] {ex.getLocalizedMessage()});
      return null;
    }
  }
  public void ejecutarReporte(String codigo) {
    try {
      cn = Conexion.realizarConexion();
      String master = System.getProperty("user.dir") + "\\src\\reportes\\reporteEmpleado.jasper";
      System.out.println("master: " + master);
      if (master == null) {
        showMessageDialog(null, "No se encontro el archivo", "Error", 0);
        System.exit(2);
      }

      JasperReport masterReport = null;
      try {
        masterReport = (JasperReport) JRLoader.loadObject(master);
      } catch (JRException ex) {
        showMessageDialog(null, "MasterReport:" + ex.getMessage(), "Error", 0);
        System.exit(3);
      }

      Map parametro = new HashMap();
      parametro.put("chr_emplcodigo", codigo);

      JasperPrint jasperPrint = JasperFillManager.fillReport(masterReport, parametro, cn);

      JasperViewer jviewer = new JasperViewer(jasperPrint, false);
      jviewer.setTitle("Reporte");
      jviewer.setVisible(true);
    } catch (ClassNotFoundException ex) {
      showMessageDialog(null, ex.getMessage(), "Error", 0);
    } catch (SQLException ex) {
      showMessageDialog(null, ex.getMessage(), "Error", 0);
    } catch (Exception ex) {
      showMessageDialog(null, ex.getMessage(), "Error", 0);
    } finally {
      try {
        cn.close();
      } catch (Exception ex) {
        showMessageDialog(null, ex.getMessage(), "Error", 0);
      }
    }
  }