Page 1 of 1
Load data from service within a report
Posted: Thu Sep 22, 2011 8:58 am
by ChristianMyksvoll
Hi.
I need to load data from within a report after collecting some report criteria in a report form. So far I have solved this the following way:
Program code:
Code: Select all
var reportService = new ReportService();
var report = new StiReport();
report.Load("report.mrt");
report.RegData("ReportService", reportService);
report.DesignWithWpf();
Button click event for a form within the report that I use to collect data:
Code: Select all
IReportService reportService = this.Dictionary.DataSources["ReportService") as IReportService;
IList personList = reportService.FindPersons("Christian");
foreach(Person person in personList)
{
MessageBox.Show(person.Name);
}
This is working as expected, showing the names in messageboxes. How do I make use of the personList in the report? I want to use personList as a datasource for a DataBand, but I have not found a way to do this yet.
Load data from service within a report
Posted: Fri Sep 23, 2011 4:23 am
by Alex K.
Hello,
Please try to use the following code:
Code: Select all
report.RegBusinessObject(reportService);
Thank you.
Load data from service within a report
Posted: Fri Sep 23, 2011 4:37 am
by ChristianMyksvoll
Hi.
I am not sure you understood my question correctly.
My problem is not how to access the reportService object. I already manage to call the method reportService.FindPersons("Christian") from within the report code.
I have a correctly filled IList of Person objects (I have verified this by showing each person's name in a message box).
What I need now is to make use of this dynamically loaded list and display each person's properties in a StiDataBand in the report. Is this possible?
Load data from service within a report
Posted: Fri Sep 23, 2011 6:29 am
by Alex K.
Hello,
Sorry, perhaps we did not understand your question correctly. Just to make it clear, do you want to set a business object for the data band from your application code or report code? If possible, please send a sample project for analysis.
Thank you.
Load data from service within a report
Posted: Fri Sep 23, 2011 6:51 am
by ChristianMyksvoll
I want to set a business object from the report code.
Here is what I am trying to do:
1) User opens the report from my application
2) A form in the report is displayed to the user where he types a search string and clicks an Ok-button
3) In the Ok-button click event, I call the method FindPersons in the reportService object
4) The FindPersons method returns an IList of Person objects
5) I want to display data from this list in a StiDataBand
6) The generated report is displayed to the user
I will set up a test project as soon as possible and post it in this thread.
Load data from service within a report
Posted: Fri Sep 23, 2011 7:35 am
by ChristianMyksvoll
I have now attached a test project to the first post in this thread.
Load data from service within a report
Posted: Mon Sep 26, 2011 6:11 am
by Alex K.
Hello,
Please check the modified report in attachment.
Thank you.
Load data from service within a report
Posted: Mon Sep 26, 2011 7:01 am
by ChristianMyksvoll
That works just the way I want it :biggrin:
For everyone else that may be interested in the solution, here is the final source code for the button click event in the report:
Code: Select all
IReportService reportService = this.Dictionary.DataSources["MetaData"].GetData("ReportService") as IReportService;
IList personList = reportService.FindPersons("Flintstone");
//this.Dictionary.DataSources.Remove(this.Dictionary.DataSources["PersonList"]);
this.RegData("PersonList", personList);
PersonList is an already registered datasource that contains no actual data, but I need it to be able to connect a databand to it.
When replacing a datasource with new content, removing the old one is obviously not necessary (the commented line). It actually gave me nothing but trouble. As usual, Keep It Simple Stupid :shame:
Load data from service within a report
Posted: Mon Sep 26, 2011 11:02 pm
by Andrew
Hello,
Thank you for sharing your experience with other developers.