JRResultSetDataSource jasperresultset;
JasperPrint jasperPrint = new JasperPrint();
Connection connection;
JInternalFrameReportViewer reportviewer;
Icon reportIcon;
JRPrintServiceExporter exporter;
PrintServiceAttributeSet serviceAttributeSet;
String reportFilename = "";
mod.setModuleId(moduleId);
if (mod.getModuleProperties() == true)
{
reportFilename = Common.report_path + JUtility.removeExtensionFromFilename(mod.getReportFilename(), ".jrxml") + ".jasper";
if (parameterValues==null)
{
parameterValues = new HashMap<String, Object>();
}
parameterValues.putAll(stdparams);
printQueue = JUtility.replaceNullStringwithBlank(printQueue);
if (printQueue.equals(""))
{
printQueue = JPrint.getDefaultPrinterQueueName();
}
else
{
if (JPrint.getDefaultPrinterQueueName().equals(printQueue) == false)
{
JPrint.setPreferredPrinterQueueName(printQueue);
}
}
try
{
//jasperReport = (JasperReport) JRLoader.loadObjectFromLocation(Common.report_path + JUtility.removeExtensionFromFilename(mod.getReportFilename(), ".jrxml")+ ".jasper");
//jasperReport = (JasperReport) RepositoryUtil.getReport(Common.report_path + JUtility.removeExtensionFromFilename(mod.getReportFilename(), ".jrxml")+ ".jasper");
connection = Common.hostList.getHost(Common.selectedHostID).getConnection(Common.sessionID);
sql = JUtility.replaceNullStringwithBlank(sql);
if (sql.isEmpty())
{
if (preparedstatement==null)
{
parameterValues.put(JRParameter.REPORT_CONNECTION, connection);
jasperPrint = JasperFillManager.fillReport(reportFilename, parameterValues, connection);
}
else
{
resultset = preparedstatement.executeQuery();
jasperresultset = new JRResultSetDataSource(resultset);
parameterValues.put(JRParameter.REPORT_DATA_SOURCE, jasperresultset);
parameterValues.put(JRParameter.REPORT_CONNECTION, connection);
jasperPrint = JasperFillManager.fillReport(reportFilename, parameterValues, jasperresultset);
}
}
else
{
statement = Common.hostList.getHost(Common.selectedHostID).getConnection(Common.sessionID).createStatement();
statement.setFetchSize(1);
resultset = statement.executeQuery(sql);
jasperresultset = new JRResultSetDataSource(resultset);
parameterValues.put(JRParameter.REPORT_DATA_SOURCE, jasperresultset);
parameterValues.put(JRParameter.REPORT_CONNECTION, connection);
jasperPrint = JasperFillManager.fillReport(reportFilename, parameterValues, jasperresultset);
}
if (mod.isPrintPreview() == true)
{
reportviewer = new JInternalFrameReportViewer(jasperPrint, false);
reportIcon = Common.imageIconloader.getImageIcon(Common.image_report);
reportviewer.setFrameIcon(reportIcon);
reportviewer.setLocation(JLaunchMenu.getNextWindowPosition().x, JLaunchMenu.getNextWindowPosition().y);
Common.mainForm.desktopPane.add(reportviewer);
reportviewer.setVisible(true);
reportviewer.setSelected(true);
}
else
{
exporter = new JRPrintServiceExporter();
exporter.setParameter(JRPrintServiceExporterParameter.JASPER_PRINT, jasperPrint);
serviceAttributeSet = new HashPrintServiceAttributeSet();
serviceAttributeSet.add(new PrinterName(JPrint.getPrinterShortName(JPrint.getPreferredPrinterQueueName()), null));
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, serviceAttributeSet);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, mod.isPrintDialog());
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(new Copies(mod.getPrintCopies()));
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
exporter.exportReport();
/* Alternative method
exporter = new JRPrintServiceExporter();
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();