Sub reports in main report using wrong data

Stimulsoft Reports.NET discussion
Post Reply
User avatar
John
Posts: 132
Joined: Tue Feb 01, 2011 3:56 am
Location: England

Sub reports in main report using wrong data

Post by John »

Hallo Support,

I have an unusual issue which a customer in our live system recently pointed out.
I am dynamically creating a main report with sub-reports in c#. In this particular case, two of the sub reports come from the same MRT which is saved as c# code in my project. This template is in the attached zip (ComparisonTable.mrt), along with test data.
The main report is filled using

Code: Select all

Select allmainReport.SubReports.Add(stiReport, false, false);
This main report has no dataset of its own, it is simply a container for the sub-reports.
Each sub-report which uses the ComparisonTable template gets its own instance of the class. The data in the dataset contains a mixture of texts and byte arrays for the icons. When I run the code in the debugger and stop once each sub-report has rendered, I can save the sub reports and view them - here, the data is fine, no problem. After each sub-report has been rendered it is added to the main report using the code above.
Now the strange phenomenon arises: the first "ComparisonTable" report is using the icons from the dataset for the second "ComparisonTable" report but it is using the texts from its own dataset!

Even though the "ComparisonTable" reports have exactly the same structure and typified dataset they should be completely separate once added to the main report. It seems to me as though the icons from the second dataset are being cached internally in some way and then used for displaying in the first report.

I would be most grateful for your assistance here.

Best regards,

John Kitching

In the attachment:
- ComparisonTable.mrt and test data
- Table1.pdf: the first sub-report of ComparisonTable, saved while running in the debugger
- Table2.pdf: the second sub-report of ComparisonTable
- FinalReport.pdf: the main report containing the 2 sub-reports (and some other stuff which can be ignored)
Attachments
ReportIssue.zip
The various files described
(671.52 KiB) Downloaded 178 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Sub reports in main report using wrong data

Post by HighAley »

Hello.

Please, send us a sample project which reproduces the issue for analysis.

Thank you.
User avatar
John
Posts: 132
Joined: Tue Feb 01, 2011 3:56 am
Location: England

Re: Sub reports in main report using wrong data

Post by John »

Hello Aleksey,

please find attached a simple project, built with Visual Studio 2010 and c# which demonstrates the issue.
Having run the project, in the "Output" folder you can see the two individual reports, each saved before being added to the main report. The main report itself is also saved.
On comparing the start of the main report with the contents of SubReport1.pdf you can see where the icons are being used from the second sub-report.

Best regards,

John Kitching
Attachments
Sample.zip
Project for reproducing the behaviour
(2.52 MiB) Downloaded 209 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Sub reports in main report using wrong data

Post by HighAley »

Hello.

Your code in the End Render event of the page goes through the all Rendered Pages. So when this event runs in the second sub-report it goes through the first sub-report too and you get duplicated images.
Due we don't have your report templates we changed your code in the report class.

Code: Select all

        public void Report_BeginRender(object sender, System.EventArgs e)
        {
            store = new Hashtable();
            counter = 0;

            startPageIndex = RenderedPages.Count;   // !!!
        }

        public void Report_EndRender(object sender, System.EventArgs e)
        {
            for (int index = startPageIndex; index < this.RenderedPages.Count; index++)     // !!!
            {
                StiPage page = this.RenderedPages[index];       // !!!
                foreach (StiComponent comp in page.GetComponents())
                {
                    if (comp is StiView && comp.TagValue != null)
                    {
                        object obj = (store as Hashtable)[comp.TagValue];
                        if (obj != null)
                        {
                            (comp as StiView).ImageToDraw = (Image)obj;
                        }
                    }
                }
            };
        }
Thank you.
User avatar
John
Posts: 132
Joined: Tue Feb 01, 2011 3:56 am
Location: England

Re: Sub reports in main report using wrong data

Post by John »

Hello Aleksey,

that's excellent - a simple and easy solution. I'd never have found it by myself though.

Thanks and regards

John Kitching
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Sub reports in main report using wrong data

Post by HighAley »

Hello, John.
John wrote:that's excellent - a simple and easy solution. I'd never have found it by myself though.
We are always glad to help you.
Let us know if you need any additional help.

Thank you.
Post Reply