Synchronize drop relationships - Urgent

Stimulsoft Reports.Flex discussion
Locked
hugo
Posts: 359
Joined: Fri Mar 08, 2013 10:46 am

Synchronize drop relationships - Urgent

Post by hugo »

Hello,

I'm using your engine only to preview and the print until now succesfully.
Now I'm starting using the export to pdf and e-mail feature (without preview). I managed to do this, however to put this to work I was forced to add the following lines to work:
report.dictionary.synchronize();
report.render();

But now I'm facing a new major problem with the line of code report.dictionary.synchronize() that drops the relationships. How can I workaround this preserving the relationships created in the designer ?
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Synchronize drop relationships - Urgent

Post by HighAley »

Hello.

Could you describe your issue more detailed?
With full code listing.

Thank you.
hugo
Posts: 359
Joined: Fri Mar 08, 2013 10:46 am

Re: Synchronize drop relationships - Urgent

Post by hugo »

Hello Aleksey,

This is how I preview a report (works great with relation tables master-detail):

Code: Select all

private function onLoadComplete(event:Event):void
{
	var loader:URLLoader = event.target as URLLoader;
	var reportString:String = loader.data as String;
			
	var report:StiReport = new StiReport();
	report.loadReportFromString(reportString);
	report.regDataSet(DATASETNAME, DATASETNAME, dataSet);

	viewer.report = report;
}
I need now to export a report to PDF (without preview to send to e-mail), so I changed to preview code to:

Code: Select all

private function onLoadComplete(event:Event):void
{
	var loader:URLLoader = event.target as URLLoader;
	var reportString:String = loader.data as String;
			
	var report:StiReport = new StiReport();
	report.loadReportFromString(reportString);
	report.regDataSet(DATASETNAME, DATASETNAME, dataSet);

	report.dictionary.synchronize();
	report.render();

	var service:StiPdfExportService = new StiPdfExportService();
	var settings:StiPdfExportSettings = new StiPdfExportSettings();
	var buffer:ByteArray = new ByteArray();
	service.exportPdf(report, buffer, settings);
}
Without the to new lines the report don't work (blank page) out of the viewer:

Code: Select all

report.dictionary.synchronize();
report.render();
For one hand this 2 new lines print to pdf without the viewer but also drop de relationships define in the StimulsoftFx-Designer and then you see all the lines from all table master repeated on all pages.

I just need to know how to avoid report.dictionary.synchronize() as before but working with StiPdfExportService without the viewer OR need to know how to rebuild the relationships by code after the synchronize call.

Regards,
Hugo.
hugo
Posts: 359
Joined: Fri Mar 08, 2013 10:46 am

Re: Synchronize drop relationships - Urgent

Post by hugo »

After spend many hours on this and study your report engine in more detail, I finally managed to fix the relations problem (master-detail) that are dropped from the designer definition when we call report.dictionary.synchronize() at runtime.

Now I finally got a stable code that respects the report definition and works in both viewer mode as export mode (without viewer) and supports relations between tables as many as defined.

Regards,
Hugo.
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Synchronize drop relationships - Urgent

Post by HighAley »

Hello.

Could you write your solution here?

Thank you.
hugo
Posts: 359
Joined: Fri Mar 08, 2013 10:46 am

Re: Synchronize drop relationships - Urgent

Post by hugo »

This a part of code from my Stimulsoft wrapper:

Code: Select all

//build the dataset relations from the report template
for each (var relation:StiDataRelation in report.dictionary.relations)
{
	var parentColumns:ArrayCollection = new ArrayCollection();
	for each (var parentColumn:String in relation.parentColumns)
	{
		parentColumns.addItem(dataSet.tables.getByName(relation.parentSource.name).columns.getByName(parentColumn));
	}
				
	var childColumns:ArrayCollection = new ArrayCollection();
	for each (var childColumn:String in relation.childColumns)
	{
		childColumns.addItem(dataSet.tables.getByName(relation.childSource.name).columns.getByName(childColumn));
	}
				
	dataSet.relations.add(new DataRelation(relation.relationName, parentColumns.toArray(), childColumns.toArray()));
}
//the following line is necessary otherwise the report engine will not assume the new dataset relations
report.dictionary.relations.clear();

//register the new dataset with data and sync with the report data
report.regDataSet(DATASETNAME, DATASETNAME, dataSet);
report.dictionary.synchronize();

//start rendering the report
report.render();
As you can see, now I created the relations in dataSet before the synchronize and then cleared your dictionary because internally there is a check about this for sure and will avoid to use this workaround.

This code was tested in preview as pdf export (without preview) and in both single and master-detail reports.

On my honest opinion, this should be done inside regDataSet automatically and you can see how much generic my code is (there isn't nothing hardcoded), so this work even if I use more than one relation or more than one field in the relations.

In a search in this forum I founded a lot of requests about this relation master-detail problem so this should fix the problem (for me it's fixed even in my wrapper).

You welcome :),
Hugo.
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Synchronize drop relationships - Urgent

Post by HighAley »

Hello.

Thank you for the solution.
Let us know if you need any additional help.

Thank you.
Locked