Exemplo n.º 1
0
 public void print(boolean withPrintDialog) {
   try {
     JasperPrintManager.printReport(makeReport(), withPrintDialog);
   } catch (JRException e) {
     e.printStackTrace();
   }
 }
 public void print() throws JRException {
   long start = System.currentTimeMillis();
   try {
     JasperPrintManager.printReport(
         new FileInputStream(new File(TMP_DIR + ALL_CHARTS_REPORT_JRPRINT)), true);
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   }
   System.err.println("Printing time : " + (System.currentTimeMillis() - start));
 }
Exemplo n.º 3
0
  public static byte[] printReport(
      final File filejrxml, Map<String, Object> param, final Connection conn, String reportFormat)
      throws IOException, NamingException, SQLException, JRException {

    final JasperPrint jasperPrintTemp = getJasperPrint(filejrxml, param, conn);

    JasperPrintManager.printReport(jasperPrintTemp, false);
    JRExporter exporter = getJREXporter(reportFormat);

    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, byteArrayOutputStream);
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrintTemp);
    exporter.exportReport();

    return byteArrayOutputStream.toByteArray();
  }
Exemplo n.º 4
0
  public String execute() {
    JasperPrint jasperPrint =
        (JasperPrint) ActionContext.getContext().getSession().get(ORStatics.JASPERPRINT);

    report = (Report) ActionContext.getContext().getSession().get(ORStatics.REPORT);

    if (jasperPrint != null && jasperPrint.getPages() != null) {
      pageCount = jasperPrint.getPages().size();
    }

    if (!"image".equals(submitType)) return SUCCESS;

    byte[] imageData = null;

    if (jasperPrint != null) {
      try {
        BufferedImage image =
            (BufferedImage) JasperPrintManager.printPageToImage(jasperPrint, pageIndex - 1, zoom);
        imageData = new SunPNGEncoderAdapter().encode(image);
      } catch (Exception e) {
        addActionError(e.getMessage());
        log.error(e.toString());
      }
    }

    if (imageData != null) {

      HttpServletResponse response = ServletActionContext.getResponse();

      try {
        response.setContentLength(imageData.length);
        ServletOutputStream ouputStream = response.getOutputStream();
        ouputStream.write(imageData, 0, imageData.length);
        ouputStream.flush();
        ouputStream.close();
      } catch (IOException ioe) {
        log.warn(ioe.toString());
      }
    }

    return NONE;
  }
Exemplo n.º 5
0
  public ActionForward print(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws JRException, IOException, ServletException {
    MemberManager mm = (MemberManager) getBean(IConstants.MEMBER_MANAGER_BEAN_NAME);
    StudAffairManager sm = (StudAffairManager) getBean("studAffairManager");
    StudAffairDAO dao = (StudAffairDAO) getBean("studAffairDAO");
    HttpSession session = request.getSession(false);
    DynaActionForm aForm = (DynaActionForm) form;
    UserCredential user = (UserCredential) session.getAttribute("Credential");

    String qty = aForm.getString("qty").trim();
    boolean setupPrinter = false;
    boolean isPrint = false;

    ActionMessages messages = new ActionMessages();

    if (!qty.equals("")) {
      String idno = user.getMember().getIdno();
      String prefix = idno.substring(idno.length() - 5);
      int q = Integer.parseInt(qty);
      String[] codes = new String[q];
      String rano = prefix + this.getRandom(4);
      String hql = "From AssessPaper Where serviceNo='" + rano + "' And idno='" + idno + "'";

      // 建立服務編號
      boolean isUniq = false;
      for (int j = 0; j < q; j++) {
        while (true) {
          rano = prefix + this.getRandom(4);
          isUniq = true;
          if (dao.submitQuery(hql).isEmpty()) {
            // 檢查服務編號是否重複
            for (int k = 0; k < j; k++) {
              if (rano == codes[k]) {
                isUniq = false;
                break;
              }
            }
            if (isUniq) {
              codes[j] = rano;
              break;
            }
          }
        }
      }
      // Insert into DB
      ActionMessages msg = mm.addNewAssessPaper(idno, codes);
      if (!msg.isEmpty()) {
        messages.add(
            ActionMessages.GLOBAL_MESSAGE, new ActionMessage("MessageN1", "滿意度調查列印資料新增失敗:" + msg));
        saveErrors(request, messages);
        setContentPage(request, "personnel/AssessPaperPrint.jsp");
        return mapping.findForward(IConstants.ACTION_MAIN_NAME);
      }

      // TODO: print the paper in pdf format
      String reportSourceFile = "/WEB-INF/reports/AssessPaper.jrxml";
      String reportCompiledFile = "/WEB-INF/reports/AssessPaper.jasper";
      List<Object> printData = new ArrayList<Object>();
      ServletContext context = request.getSession().getServletContext();
      JasperReportUtils.initJasperReportsClasspath(request);

      printData = fillPrintData(codes);

      DecimalFormat df = new DecimalFormat(",##0.0");
      File reportFile = null;
      reportFile = new File(context.getRealPath(reportCompiledFile));
      // 需要時再編譯即可
      // if (!reportFile.exists()) {
      JasperReportUtils.compileJasperReports(context.getRealPath(reportSourceFile));
      reportFile = new File(context.getRealPath(reportCompiledFile));
      if (!reportFile.exists())
        throw new JRRuntimeException("查無\"AssessPaper.jasper\"檔案,請電洽電算中心,謝謝!!");
      // }

      Map<String, String> parameters = new HashMap<String, String>();

      JasperReport jasperReport = (JasperReport) JRLoader.loadObject(reportFile.getPath());

      parameters.put("idno", idno);
      parameters.put("userName", user.getMember().getName());
      parameters.put("PrintDate", Toolket.Date2Str(new Date())); // 列印日期

      String[] fields = {
        "serviceNo0",
        "serviceNo1",
        "serviceNo2",
        "serviceNo3",
        "serviceNo4",
        "serviceNo5",
        "serviceNo6",
        "serviceNo7",
        "serviceNo8",
        "serviceNo9"
      };

      JasperPrint jasperPrint =
          JasperFillManager.fillReport(
              jasperReport, parameters, new HibernateQueryResultDataSource(printData, fields));
      // jasperPrint.
      // 列印或預覽
      if (isPrint) {
        JasperPrintManager.printReport(jasperPrint, setupPrinter);
      } else {
        byte[] bytes =
            JasperRunManager.runReportToPdf(
                jasperReport, parameters, new HibernateQueryResultDataSource(printData, fields));

        Calendar td = Calendar.getInstance();
        String ran =
            ""
                + (td.get(Calendar.MINUTE))
                + (td.get(Calendar.SECOND))
                + (td.get(Calendar.MILLISECOND));
        String ranDir = "/WEB-INF/reports/temp/" + ran;

        File tempdir = new File(context.getRealPath(ranDir));
        if (!tempdir.exists()) tempdir.mkdirs();

        OutputStream os =
            new BufferedOutputStream(
                new FileOutputStream(new File(context.getRealPath(ranDir + "/AssessPaper.pdf"))));
        JasperExportManager.exportReportToPdfStream(jasperPrint, os);
        JasperReportUtils.printPdfToFrontEnd(response, bytes);
        os.close();
        Toolket.deleteDIR(tempdir);
        return null;
      }

    } else {
      messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("MessageN1", "請輸入欲列印張數!"));
      saveErrors(request, messages);
    }
    setContentPage(request, "personnel/AssessPaperPrint.jsp");
    return unspecified(mapping, form, request, response);
  }
 public void print() throws JRException {
   long start = System.currentTimeMillis();
   JasperPrintManager.printReport("build/reports/DataSourceReport.jrprint", true);
   System.err.println("Printing time : " + (System.currentTimeMillis() - start));
 }
Exemplo n.º 7
0
  public static void main(String args[]) {
    // [pdf/printlangusng] [directoryREPORT] [directoryPDF] [filereport] [filepdf] [kondisi]
    // path di pak edy "F:/SERVERLAMA/wamp/www/potensi/dist/logoNU.png"

    String direktoryReport = "/media/apps/pakedy/depak/potensi/dist/";
    String directoyPDF = "/media/apps/pakedy/depak/potensi/pdf/";
    if (!debugging) {
      direktoryReport = args[1];
      directoyPDF = args[2];
    }

    String fileReport = "", qryData = "", thisCondition = "", pdfDestination = "", forAwhile = "";
    java.util.Map parameter = new java.util.HashMap();

    fileReport = direktoryReport + args[3] + ".jasper";
    if (args[3].equalsIgnoreCase("rincianKabupaten")
        || args[3].equalsIgnoreCase("rincianKecamatan")
        || args[3].equalsIgnoreCase("rincianDesa")) {
      fileReport = direktoryReport + "rincianPropinsi.jasper";
    }

    if (args[3].equalsIgnoreCase("newaasetLaporan")) {
      try {
        if (args[5] != null) {
          if (args[5].length() > 0) {
            thisCondition += " propid = " + args[5] + " ";
          }
        }
      } catch (Exception ex) {
      }

      try {
        if (args[6] != null) {
          if (args[6].length() > 0) {
            if (thisCondition.length() > 0) {
              thisCondition += " and ";
            }
            thisCondition += " kabid = " + args[6] + " ";
          }
        }
      } catch (Exception ex) {
      }

      try {
        if (args[7] != null) {
          if (args[7].length() > 0) {
            if (thisCondition.length() > 0) {
              thisCondition += " and ";
            }
            thisCondition += " kecid = " + args[7] + " ";
          }
        }
      } catch (Exception ex) {
      }
      if (thisCondition.length() > 0) {
        thisCondition = " where " + thisCondition;
      }
      qryData =
          "select id,jenis_aset,ket_jenis,nama_aset,lokasi,ranting,kecid"
              + ",(select b.namaKota from tbkota b where b.kotaID=kabid) as namaKabupaten"
              + ",(select a.namaKecamatan from tbkecamatan a where a.kecamatanID=kecid) as namaKecamatan"
              + ",(select c.namaKelurahan from tbkelurahan c where c.kelurahanID=kelid ) as  namaKelurahan"
              + "  from newaset"
              + thisCondition
              + " order by kecid,id";
    } else if (args[3].equalsIgnoreCase("rincianPropinsi")) {
      qryData =
          "SELECT newaset.jenis_aset, klasifikasi_aset.jenis, golongan.golongan,format(count(*),0) as jmlView, "
              + "count(*) as jumlah "
              + "FROM (newaset) "
              + "JOIN klasifikasi_aset ON newaset.jenis_aset = klasifikasi_aset.kode_klasifikasi "
              + "JOIN golongan ON klasifikasi_aset.golongan = golongan.id WHERE newaset.propid = "
              + args[5]
              + " GROUP BY newaset.jenis_aset, klasifikasi_aset.jenis, golongan.golongan ORDER BY jenis_aset asc";
    } else if (args[3].equalsIgnoreCase("rincianKabupaten")) {
      qryData =
          "SELECT newaset.jenis_aset, klasifikasi_aset.jenis, golongan.golongan,format(count(*),0) as jmlView, "
              + "count(*) as jumlah "
              + "FROM (newaset) "
              + "JOIN klasifikasi_aset ON newaset.jenis_aset = klasifikasi_aset.kode_klasifikasi "
              + "JOIN golongan ON klasifikasi_aset.golongan = golongan.id WHERE newaset.kabid = "
              + args[5]
              + " GROUP BY newaset.jenis_aset, klasifikasi_aset.jenis, golongan.golongan ORDER BY jenis_aset asc";
    } else if (args[3].equalsIgnoreCase("rincianKecamatan")) {
      qryData =
          "SELECT newaset.jenis_aset, klasifikasi_aset.jenis, golongan.golongan,format(count(*),0) as jmlView, "
              + "count(*) as jumlah "
              + "FROM (newaset) "
              + "JOIN klasifikasi_aset ON newaset.jenis_aset = klasifikasi_aset.kode_klasifikasi "
              + "JOIN golongan ON klasifikasi_aset.golongan = golongan.id WHERE newaset.kecid = "
              + args[5]
              + " GROUP BY newaset.jenis_aset, klasifikasi_aset.jenis, golongan.golongan ORDER BY jenis_aset asc";
    } else if (args[3].equalsIgnoreCase("rincianDesa")) {
      qryData =
          "SELECT newaset.jenis_aset, klasifikasi_aset.jenis, golongan.golongan,format(count(*),0) as jmlView, "
              + "count(*) as jumlah "
              + "FROM (newaset) "
              + "JOIN klasifikasi_aset ON newaset.jenis_aset = klasifikasi_aset.kode_klasifikasi "
              + "JOIN golongan ON klasifikasi_aset.golongan = golongan.id WHERE newaset.kelid = "
              + args[5]
              + " GROUP BY newaset.jenis_aset, klasifikasi_aset.jenis, golongan.golongan ORDER BY jenis_aset asc";
    } else if (args[3].equalsIgnoreCase("levelKabupaten")) {
      qryData =
          "select a.kabid,b.namaKota,count(*) as jumlah,format(count(*),0) as jmlView "
              + "from newaset a inner join tbkota b on a.kabid = b.kotaID where a.propid = "
              + args[5]
              + " group by a.kabid,b.namaKota order by b.namaKota";
    } else if (args[3].equalsIgnoreCase("levelKecamatan")) {
      qryData =
          "select a.kecid,b.namaKecamatan,count(*) as jumlah,"
              + "format(count(*),0) as jmlView from newaset a "
              + "inner join tbkecamatan b on a.kecid = b.kecamatanID where a.kabid = "
              + args[5]
              + " group by a.kecid,b.namaKecamatan "
              + "order by b.namaKecamatan";
    } else if (args[3].equalsIgnoreCase("levelDesa")) {
      qryData =
          "select a.kelid,b.namaKelurahan,count(*) as jumlah,format(count(*),0) as jmlView "
              + "from newaset a "
              + "inner join tbkelurahan b on a.kelid = b.kelurahanID where a.kecid ="
              + args[5]
              + " group by a.kelid,b.namaKelurahan order by b.namaKelurahan";
    } else if (args[3].equalsIgnoreCase("rekapEntry")) {
      qryData =
          "select createdby,count(*) as jumlah,format(count(*),0) as jmlView "
              + " from newaset group by createdby order by createdby";
    } else if (args[3].equalsIgnoreCase("rekapEntryPerson")) {
      int i = 6;
      boolean ada = true;
      while (ada) {
        try {
          if (i < 7) forAwhile += args[i];
          else forAwhile += " " + args[i];
          i++;
        } catch (Exception ex) {
          ada = false;
        }
      }
      qryData =
          "select DATE_FORMAT(created, '%d/%m/%Y') as created,"
              + "count(*) as jumlah,format(count(*),0) as jmlView "
              + "from newaset where createdby = '"
              + forAwhile
              + "' group by created order by created";
    }

    String klaSS = "jdbc:mysql://localhost/potensi?user=nujatim&password=klaser";
    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      java.sql.Connection conec = java.sql.DriverManager.getConnection(klaSS);
      parameter.put("qryData", qryData);

      if (args[3].equalsIgnoreCase("rincianPropinsi")) {
        String namaPropinsi = args[6];
        int i = 7;
        boolean ada = true;
        while (ada) {
          try {
            namaPropinsi += " " + args[i];
            i++;
          } catch (Exception ex) {
            ada = false;
          }
        }
        parameter.put(
            "rinciTitel", "Rincian Jumlah masing-masing obyek di Propinsi " + namaPropinsi);
      } else if (args[3].equalsIgnoreCase("rincianKabupaten")) {
        String namaKabupaten = args[6];
        int i = 7;
        boolean ada = true;
        while (ada) {
          try {
            namaKabupaten += " " + args[i];
            i++;
          } catch (Exception ex) {
            ada = false;
          }
        }
        parameter.put("rinciTitel", "Rincian Jumlah masing-masing obyek di " + namaKabupaten);
      } else if (args[3].equalsIgnoreCase("rincianKecamatan")) {
        String namaKecamatan = args[6];
        int i = 7;
        boolean ada = true;
        while (ada) {
          try {
            namaKecamatan += " " + args[i];
            i++;
          } catch (Exception ex) {
            ada = false;
          }
        }
        parameter.put("rinciTitel", "Rincian Jumlah masing-masing obyek di " + namaKecamatan);
      } else if (args[3].equalsIgnoreCase("rincianDesa")) {
        String namaDesa = args[6];
        int i = 7;
        boolean ada = true;
        while (ada) {
          try {
            namaDesa += " " + args[i];
            i++;
          } catch (Exception ex) {
            ada = false;
          }
        }
        parameter.put("rinciTitel", "Rincian Jumlah masing-masing obyek di Desa " + namaDesa);
      } else if (args[3].equalsIgnoreCase("levelKabupaten")) {
        String namaPropinsi = args[6];
        int i = 7;
        boolean ada = true;
        while (ada) {
          try {
            namaPropinsi += " " + args[i];
            i++;
          } catch (Exception ex) {
            ada = false;
          }
        }
        parameter.put("namaPropinsi", namaPropinsi);
      } else if (args[3].equalsIgnoreCase("levelKecamatan")) {
        String namaKabupaten = args[6];
        int i = 7;
        boolean ada = true;
        while (ada) {
          try {
            namaKabupaten += " " + args[i];
            i++;
          } catch (Exception ex) {
            ada = false;
          }
        }
        parameter.put("namaKabupaten", namaKabupaten);
      } else if (args[3].equalsIgnoreCase("levelDesa")) {
        String namaKecamatan = args[6];
        int i = 7;
        boolean ada = true;
        while (ada) {
          try {
            namaKecamatan += " " + args[i];
            i++;
          } catch (Exception ex) {
            ada = false;
          }
        }
        parameter.put("namaKecamatan", namaKecamatan);
      } else if (args[3].equalsIgnoreCase("rekapEntryPerson")) {
        parameter.put("person", forAwhile);
        parameter.put("total", args[5]);
      }

      parameter.put("imgPath", direktoryReport + "logoNU.png");
      net.sf.jasperreports.engine.JasperPrint jasperPrint =
          net.sf.jasperreports.engine.JasperFillManager.fillReport(fileReport, parameter, conec);
      if (debugging) {
        net.sf.jasperreports.view.JasperViewer jasperViewer =
            new net.sf.jasperreports.view.JasperViewer(jasperPrint, false);
        jasperViewer.setDefaultCloseOperation(javax.swing.JFrame.HIDE_ON_CLOSE);
        jasperViewer.setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);
        jasperViewer.setTitle("Laporan Aset");
        jasperViewer.setVisible(true);
      }

      if (args[0].equalsIgnoreCase("pdf")) {
        pdfDestination = directoyPDF + args[4] + ".pdf";
        net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfFile(
            jasperPrint, pdfDestination);
      } else if (args[0].equalsIgnoreCase("cetak")) {
        net.sf.jasperreports.engine.JasperPrintManager.printReport(jasperPrint, false);
      }

      System.exit(0);
    } catch (Exception ex) {
      System.out.println(" error " + ex.getMessage());
      System.exit(0);
    }
  }