ActiveReports 8 - Section Report With Main Report and SubReport - activereports

I am developing a Section report using ActiveReports 8. I have a Main report with a detail line that has five text boxes bound to data. The detail line also has two unbound text boxes that are defined but are not bound to data. I am attempting to populate these two unbound fields by data coming from the subreport.
I am part way there BUT the unbound fields are getting populated one detail line late. If this makes sense?
Have tried using different events ... cannot seem to find the right combination.

You can get data from the SubReport by creating a property or two in the SubReport and access the property values in the main report's Detail Section's Format event and assign it to the unbound TextBoxes. Something like:
private void detail_Format(object sender, EventArgs e)
{
subReport1.Report = rpt;
rpt.Run();
textBox3.Text = rpt.SubReportValue.ToString();
}
private void MainReport_ReportStart(object sender, EventArgs e)
{
rpt = new ChildReport();
}
We have also replied to you on the ActiveReports forum post with a demo application - http://arhelp.grapecity.com/groups/topic/activereports-8-section-report-with-parent-and-subreport/

Related

Start JasperReport subreport on new page, but not when launched as main report

I have a JasperReport named 'Receipt' that can be launched as a:
subreport in a Summary band, to display any receipts
main report, to display a particular receipt
How can I start a new page before any receipts, when it is used as a subreport, but suppress the new page if there are no receipts?
Setting isTitleNewPage="true" works when it is used in the subreport case, but causes the Detail band to be displayed on the second page when it is used as a main report.
Using a Break prior to the subreport means a redundant page is used if there are no receipts.
I solved it by:
Adding a Boolean isSubReport parameter to the report
in the Detail band, adding a Break, with a Print When Expression set to:
$V{PAGE_NUMBER} == 1 && $P{isSubReport}
In the parent report, passing the parameter isSubReport with value TRUE()
Feels like there should be a cleaner solution, but it seems to work.

Why crystal reports sub report does not display some fields on viewer

I have crystal report with main report and sub report. Main report contains group sections.
I have linked sub report with main report using id. When I preview it on preview tab, both main and sub reports are working and displaying correct data.
But, when I preview it on the viewer with my application, main report data shows correct, but some sub report fields are not visible. I have noticed that, when I put the ID field to view in sub report, it shows a number of records. but only ID field is shown, and other fields are not visible.
I have set two record sets to main report and sub report. it seems records are returning data, but sub report does not shows them. Can anyone please point me in right direction to solve this?
Not sure how you are loading your report in the Crystal viewer, but keep in mind that if your report uses subreports, in your code when you are loading the report, you need to also set the data source for each subreport. See the following incomplete code snippet:
//SET DATASOURCE FOR EACH SUBREPORT IN REPORT
foreach (CrystalDecisions.CrystalReports.Engine.Section section in CrystalReportSource2.ReportDocument.ReportDefinition.Sections)
{
// In each section we need to loop through all the reporting objects
foreach (CrystalDecisions.CrystalReports.Engine.ReportObject reportObject in section.ReportObjects)
{
if (reportObject.Kind == ReportObjectKind.SubreportObject)
{
SubreportObject subReport = (SubreportObject)reportObject;
ReportDocument subDocument = subReport.OpenSubreport(subReport.SubreportName);
foreach (CrystalDecisions.CrystalReports.Engine.Table table in subDocument.Database.Tables)
{
// Cache the logon info block
TableLogOnInfo logOnInfo = table.LogOnInfo;
// Set the connection
logOnInfo.ConnectionInfo = crConnectionInfo;
// Apply the connection to the table!
table.ApplyLogOnInfo(logOnInfo);
}
}
}
}

How to pass a list of objects from a Java application to the sub-report?

I have a report with one bar chart and one table. these two elements are filled by the list of objects which is passed from my Java application to the report.
Now I want to put these two elements in two different sub-reports, but I do not know how I can pass the list of objects to the sub-reports. I have added the fields of each object as a field in master report and as a parameter in sub-report, but it does not work.
Can anyone help me to solve this problem?
Something like this:
Pass collection into main report as parameter and use this parameter in DataSource for subreports:
// java-code for main report
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(listOfObject);
Map<String, Object> params = new HashMap<String, Object>();
params.put("myList", listOfObject);
jasperPrint = JasperFillManager.fillReport(jasperReport, params, ds);
// end java-code
(may be
JasperFillManager.fillReport(jasperReport, params, new JREmptyDataSource())
if you don't need to display data in main report)
Define in main.jrxml report parameter myList as java.util.Collection
Add subreports into main report (into summary band)
Set in main report for subreports properties:
Connection type = Use a datasource expression
Data Source Expression = new JRBeanCollectionDataSource($P{myList})
Define in subreports desired field (based on listOfObjects).

dynamicjasper addConcatenatedReport in a frame

Is it possible to concatenate subReports in a frame placed in the detail band? The goal is to display these subReports and the previous defined elements in the Detail section from a Template.
If I use dynamicReportBuilder.setTemplateFile(TEMPLATE); and dynamicReportBuilder.addConcatenatedReport(subreport); to insert the subreports in the detail Report, which is loaded from the Template, the previous defined elements in the Detail setion of the report template dissapear. So I am looking for the way to conserve these elements.
Based on your comment it seems like one of two things is happening.
1) You have the sub-report defined in the Detail band of the Template file.
In this case it will not work. The Detail band in the template file should be empty. If this is the case it is more than likely just ignoring what ever you have there and doing everything else. Check out the HOW-TO Use custum jrxml templates for more information.
2) dynamicReportBuilder.addConcatenatedReport(subreport); does not do what you think it does.
This method appends a second report to the end of the first report. Think of it more as a batch. It is the same thing as setting a value for JASPER_PRINT_LIST as an export Parameter when using the Jasper Reports API directly. Check out the HOW-TO Add Concatenated Reports for more information.
Dynamic Jasper is a great library, but is really only designed to work with standard tabular reports. It has support for some advanced features, including sub-reports, but it can be limiting.
From what I can find so far, it appears you can only add sub-reports to the Group Headers and Group Footers. So in your case you will probably need to add a Group to report first using GroupBuilder. Then you can add the sub-report to the Group Footer. The trick for the group is to make sure that each row will end up being its own group by picking the appropriate fields to group on.
You can look at the code examples in the HOW-TO Add labels in group header and footer to see how to build the groups.
To see how to add sub-reports to the report you can use DynamicReportBuilder.addSubreportInGroupFooter() method. For more details about this part and an example check out HOW-TO Add Subreports (fast way).
The other option you have is to not use Dynamic Jasper for this particular report, and just use jrxml files and the Jasper Report's API to do it yourself. It may or may not be easier depending on your setup.
By Ricardo Mariaca. This code is the solution, Thank to Ricardo and Dynamic Report
private void build() {
try {
JasperPdfExporterBuilder pdfExporterBuilder = export
.pdfExporter(PDF_FILE);
JasperReportBuilder jasperReportBuilderMain = report()
.columns(
col.column("Item", "item", type.stringType()),
col.column("Quantity", "quantity",
type.integerType()),
col.column("Unit price", "unitprice",
type.bigDecimalType()))
.setDataSource(createSubreportDataSource())
// .detail(cmp.subreport(createSubreport()))
.setWhenNoDataType(WhenNoDataType.ALL_SECTIONS_NO_DETAIL);
JasperReportBuilder jasperReportBuilderDisclaimer = report()
.setPageFormat(PageType.A4, PageOrientation.LANDSCAPE)
.summary(cmp.subreport(jasperReportBuilderMain))
.summaryWithPageHeaderAndFooter()
.setWhenNoDataType(WhenNoDataType.ALL_SECTIONS_NO_DETAIL)
.columnHeader(
cmp.text("first page header").setFixedHeight(50))
.columnFooter(
cmp.text(DISCLAIMER).setStretchWithOverflow(true)
.setFixedHeight(250))
.pageHeader(
Templates
.createTitleComponent("Ricardo Mariaca Approach"))
.pageFooter(Templates.footerComponent).show()
.toPdf(pdfExporterBuilder);
} catch (DRException e) {
e.printStackTrace();
}
}
private JRDataSource createSubreportDataSource() {
DRDataSource dataSource = new DRDataSource("item", "quantity",
"unitprice");
for (int i = 0; i < 180; i++) {
dataSource.add("Book", (int) (Math.random() * 10) + 1,
new BigDecimal(Math.random() * 100 + 1));
}
return dataSource;
}
}

JasperReports: unrecoverable multipage subreports

For example i have Master report that contains several multipage subreports. I want them to be displayed in order that is set in master report (prints the first subreport and then prints second). When i add these subreports into master datail band, they cover each other.
How can i do such thing?
Thank you
Have you tried putting each subreport in its own detail band? Or, if you're putting the subs in an array, include another variable like "reportName" or "reportNumber" and group the subreport detail bands by that variable, so each time the variable changes a new group is created for the new subreport. Doing it that way would also let you put a group header for each subreport which you could then customize with variables and/parameters. Just a thought.
I found the satisfied solution:
i fill all my reports separately, but export them by JRPdfExporter:
List jasList = new ArrayList();
jasList.add(jp_1);
jasList.add(jp_2);
jasList.add(jp_3);
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasList);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "batch.pdf");
exporter.setParameter(JRPdfExporterParameter.IS_CREATING_BATCH_MODE_BOOKMARKS, Boolean.TRUE);
exporter.exportReport();
They will be ordered in list order and bookmarks will be generated