Delaying loading of data

Stimulsoft Reports.NET discussion
jmiller
Posts: 91
Joined: Mon Sep 20, 2010 12:18 pm

Delaying loading of data

Post by jmiller »

I am trying to come up with a way of delaying the population of data until the report is actually rendered. The data is determined in code and is not in an SQL database. Here is how I thought I might be able to do this.

1. My C# program creates
a. the StiReport object
b. add the assembly reference where the data can be provided
c. loads a schema from an xsd file
d. adds script to the Report.BeginRender.
2. This script would call one of my assembly's functions.
3. Inside this function is where I wanted to fill in the data.

The reason I am doing this is so that the report can be designed and data only retrieved when rendering (the gathering of data can take a long time).

Unfortunately I can't get any data to appear in the report. I am guessing Stimulsoft has already expected actual data before the Report.BeginRender event is called.

Am I doing something wrong or is there a better way to accomplish this?

My main program:
private void button1_Click(object sender, EventArgs e)
{
StiReport report = new StiReport();

DataSet dataSet = new DataSet("Test");
dataSet.ReadXmlSchema("TestData.xsd");

report.Dictionary.ImportXMLSchema(dataSet);

string[] refDlls = report.ReferencedAssemblies;
string[] newRefDlls = new string[refDlls.Length + 1];

int ind = 0;
foreach (string refDll in refDlls)
newRefDlls[ind++] = refDll;
newRefDlls[ind] = "DataProvider.dll";

report.ReferencedAssemblies = newRefDlls;

report.BeginRenderEvent.Script = "DataProvider.DataProvider.LoadData(this);";

report.Design(true);

}



My data provider code:
static public class DataProvider
{
static public void LoadData(StiReport report)
{
DataSet dataSet = report.Dictionary.GetDataSet("Test");

dataSet.ReadXml("TestData.xml");

}

}
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Delaying loading of data

Post by Alex K. »

Hello,

Can you please send us a sample project for analysis.

Thank you.
jmiller
Posts: 91
Joined: Mon Sep 20, 2010 12:18 pm

Re: Delaying loading of data

Post by jmiller »

Sorry it took a while but I was out of town.
Attachments
StimulsoftTest.zip
(14.72 KiB) Downloaded 418 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Delaying loading of data

Post by HighAley »

Hello.

Please, try to add reference on the DataProvider asssembly to the StimulsoftBusinessObjectsTest project.

Look at the attached image.
Attachments
AddReferenceProject.png
AddReferenceProject.png (27.59 KiB) Viewed 5285 times
jmiller
Posts: 91
Joined: Mon Sep 20, 2010 12:18 pm

Re: Delaying loading of data

Post by jmiller »

I wasn't haven't a problem with the DataProvider assembly being called (I did try adding the DataProvider project and the problem still occurs). I am trying to have such that the data is not determined until the report is being rendered. I want to design the report with just the schema.

For example, my DataProvider.LoadData() method is being called. I even put a breakpoint in there and VS does stop at it, but no matter what I do I cannot get data to be determined at this point.

In one case my LoadData() has the code below. The variable newRow1 has no columns defined, even the columns were defined in the schema and I am able to design a report with the columns.
StiDataSource dataSrc = report.Dictionary.DataSources[0];
DataSet dataSet = report.Dictionary.GetDataSet("Test");
DataRow newRow1 = dataSet.Tables[0].NewRow();
// An exception occurrs here because there are columns in datarow
newRow1[0] = "ABC0001";
newRow1[1] = new DateTime(2012, 3, 17);
dataSet.Tables[0].Rows.Add(newRow1);

So I tried just reading in data from an xml file. This time it does not crash, but no data appears.
dataSet.ReadXml("TestData.xml");


In short in VS, I run my program. Click on the button on the form. This opens the Stimulsoft designer with a data connection and data source defined from a schema file. I drop a data band on the report and simply put a field from the data source on it. I then run the report (I hit F5). DataProvider.LoadData() gets called. I want the data to now be determined and sent to Stimulsoft to render.

My reasoning for this is that my data is not accessible via SQL - I have to use some sort of business object concept. The other caveat is that my data can take some time to calculate and be produced and I have found using most of the business object concepts require the reading of all the data to determine the schema. So I went and provided the schema, but now I can't tell Stimulsoft to generate the data only when it is being rendered.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Delaying loading of data

Post by HighAley »

Hello.

At first when reading of XML Schema the name of DataSet is changing from "Test" to "LoanData".

Please, try to get XML Schema but not the DataSet:

Code: Select all

DataSet dataSet = report.Dictionary.ExportXMLSchema("LoanData");
Do you really what to use BeginRender event to load data? Because this event will be called on each preview of the report. It will slow your project.

Thank you.
jmiller
Posts: 91
Joined: Mon Sep 20, 2010 12:18 pm

Re: Delaying loading of data

Post by jmiller »

I will try your suggestion with the xml schema.

I am not sure if I want to use BeginRender or not. I am open to suggestions on the best way to do what I want to do. This was just a way I was thinking of. My data is not stored in a database. It is calculated in C# code. It does heavy duty calculations and can sometimes take over 15 minutes to render. I just want the user to be able to design the report using the schema of the data and when they are ready to "run" the report, that is when my C# code will go and do all of its calculations.

So again, let me ask, knowing what I stated above:
- what is the best way to allow a user to design a report without waiting for all of the data to be calculated (I have the schema) and then when the user "previews" or hits F5, the data is calculated. yes, the preview or hitting F5 will take over 15 minutes, but at least they can design it without waiting.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Delaying loading of data

Post by HighAley »

Hello.
jmiller wrote:So I tried just reading in data from an xml file. This time it does not crash, but no data appears.
dataSet.ReadXml("TestData.xml");
When you are trying to read xml data you should be sure that data have already been calculated.

Let us know about the results when you'll try to load xml schema.

Thank you.
jmiller
Posts: 91
Joined: Mon Sep 20, 2010 12:18 pm

Re: Delaying loading of data

Post by jmiller »

I still could not get that working. I am not sure if I am explaining the problem I am trying to solve, so I am uploading an updated sample program. In this sample, a Windows form is shown with a simple button. When the button is clicked all I want is the designer to come up quickly and allow me to design a report based on the data's schema. Again, it is not SQL. My data is based on List<>, which needs to get populated.

So, what happens is that when I click the button, my list of records is getting calculated. I put a sleep function in there to simulate the tme it takes to compute a record. As you can see when you click the button it takes a while for the designer to come up. This is what I don't want to happen. I have a schema so why can't I just go in and design the report based on the schema. Only when I preview or run with F5 do I want the data to actually be computed.

Conceptually isn't what i want to do the same as an SQL base data source. If my "select * from table" had 100 millions records you aren't reading in 100 million records before I can design a report. I can design the report because Stimulsoft knows the schema from "select * from table". I am trying to do the same thing but with my own business object data.
jmiller
Posts: 91
Joined: Mon Sep 20, 2010 12:18 pm

Re: Delaying loading of data

Post by jmiller »

Here is the zip.
Post Reply