Postprocessing report - Problem with ClickEvent

Stimulsoft Ultimate discussion
Post Reply
User avatar
tpontow
Posts: 206
Joined: Thu Sep 06, 2012 8:46 am
Location: Bonn, Germany

Postprocessing report - Problem with ClickEvent

Post by tpontow »

Hello Stimulsoft,

in my sample report i implemented a postprocessing step after the report is rendered. In that step i assign a random textbrush to all StiText components as follows:

Code: Select all

report.Compile();
report.CompiledReport.EndRender += DoPostProcessing;

Code: Select all

private void DoPostProcessing(object sender, EventArgs eventArgs)
        {
            StiReport report = sender as StiReport;

            if (!ReferenceEquals(report, null))
            {
                Random r = new Random();
                foreach (StiPage renderedPage in report.RenderedPages.Items)
                {
                    StiComponentsCollection componentsCollection = renderedPage.GetComponents();
                    foreach (var component in componentsCollection)
                    {
                        StiText textComponent = component as StiText;
                        if (!ReferenceEquals(textComponent, null))
                        {
                            textComponent.ComponentGuid = Guid.NewGuid().ToString();
                            textComponent.TextBrush = new StiSolidBrush(Color.FromArgb(r.Next(1, 256), r.Next(1, 256), r.Next(1, 256)));
                            textComponent.Click += TextComponentOnClick;
                        }
                    }
                }
            }

        }
This works fine so far. After that all StiText components have random colors. Great.

But i also like to register a click event to every StiText component. The handler method should output the name, value and ComponentGuid of every single text component. But that does not work. After clicking on a text component no value is shown and the handler method is called for every component with same name.

Code: Select all

 private void TextComponentOnClick(object sender, EventArgs eventArgs)
        {
            StiText text = sender as StiText;

            if (!ReferenceEquals(text, null))
            {
                Trace.WriteLine(string.Format("Click on {0} ({2}). Value: {1}", text.Name, text.TextValue, text.ComponentGuid));
            }
        }
What to do to assign a click event handler to every instance so that i can output the value/textvalue of the component i've clicked on?

I attached sample project as zip file.

Thanks
Thorsten Pontow
Attachments
Strukturtest.zip
Sample report project with postprocessing step
(4.4 MiB) Downloaded 330 times
Thorsten Pontow

It is easier to write an incorrect program than to understand a correct one. (Alan J. Perlis, Epigrams in programming No. 7)
User avatar
tpontow
Posts: 206
Joined: Thu Sep 06, 2012 8:46 am
Location: Bonn, Germany

Re: Postprocessing report - Problem with ClickEvent

Post by tpontow »

Currently i'm, using build 2013.2.1606.0.
Thorsten Pontow

It is easier to write an incorrect program than to understand a correct one. (Alan J. Perlis, Epigrams in programming No. 7)
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Postprocessing report - Problem with ClickEvent

Post by HighAley »

Hello, Thorsten.

Sorry, we need some additional time to prepare an answer for you.

Thank you.
Ivan
Posts: 960
Joined: Thu Aug 10, 2006 1:37 am

Re: Postprocessing report - Problem with ClickEvent

Post by Ivan »

Hello, Thorsten.

Please modify your code:

Code: Select all

        private void DoPostProcessing(object sender, EventArgs eventArgs)
        {
            StiReport report = sender as StiReport;

            if (!ReferenceEquals(report, null))
            {
                Random r = new Random();
                System.Collections.Hashtable names = new System.Collections.Hashtable();
                foreach (StiPage renderedPage in report.RenderedPages.Items)
                {
                    StiComponentsCollection componentsCollection = renderedPage.GetComponents();
                    foreach (var component in componentsCollection)
                    {
                        StiText textComponent = component as StiText;
                        if (!ReferenceEquals(textComponent, null))
                        {
                            textComponent.ComponentGuid = Guid.NewGuid().ToString();
                            textComponent.TextBrush = new StiSolidBrush(Color.FromArgb(r.Next(1, 256), r.Next(1, 256), r.Next(1, 256)));
                            if (!string.IsNullOrEmpty(textComponent.Name) && (!names.ContainsKey(textComponent.Name)))
                            {
                                textComponent.Click += TextComponentOnClick;
                                names[textComponent.Name] = textComponent.Name;
                            }
                        }
                    }
                }
            }

        }

        private static void TextComponentOnClick(object sender, EventArgs eventArgs)
        {
            StiText text = sender as StiText;

            if (!ReferenceEquals(text, null))
            {
                Trace.WriteLine(string.Format("Click on {0} ({2}). Value: {1}", text.Name, text.Text.Value, text.ComponentGuid));
            }
        }

Thank you.
User avatar
tpontow
Posts: 206
Joined: Thu Sep 06, 2012 8:46 am
Location: Bonn, Germany

Re: Postprocessing report - Problem with ClickEvent

Post by tpontow »

Hello Ivan,

ok, that solution works for me!

Thanks and regards
Thorsten Pontow
Thorsten Pontow

It is easier to write an incorrect program than to understand a correct one. (Alan J. Perlis, Epigrams in programming No. 7)
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Postprocessing report - Problem with ClickEvent

Post by HighAley »

Hello, Thorsten.

We are very glad to help you.
Let us know if you need any additional help.

Thank you.
User avatar
tpontow
Posts: 206
Joined: Thu Sep 06, 2012 8:46 am
Location: Bonn, Germany

Re: Postprocessing report - Problem with ClickEvent

Post by tpontow »

Hello Aleksey,

the problem was a little more complex than i thought. The report was ok all the time. But in my project i serialized the report using SaveDocument() and then i opened the report MDC-document (converted to Binary) again with a viewer control. But none of the events i had in the original report where serialized into the binary and also none of the tag value objects i used.

I solved that special problem by recreating the events after sending the binary report document to the viewer.

Thanks again and reagards
Thorsten
Thorsten Pontow

It is easier to write an incorrect program than to understand a correct one. (Alan J. Perlis, Epigrams in programming No. 7)
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Postprocessing report - Problem with ClickEvent

Post by HighAley »

Hello.

It's impossible to serialize events in mdc-document. So the only way is to add events again.

Thank you.
Post Reply