Change the sql command before preview

Stimulsoft Reports.NET discussion
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Change the sql command before preview

Post by HighAley »

Hello.
[quote="marco".correa]We should like that when "report preview" is canceled the user see a message that is not a error.

Actually we are throwing a exception to cancel a report preview.

Code: Select all

            StiOptions.Engine.GlobalEvents.PreviewingReportInDesigner += (s, args) =>
            {   
               // disregard the verification below, this is only a sample to illustrate 
              //  the event that we are using and the exception raised.
                if (1 == 1)
                    throw new Exception("Visualização do relatório cancelada.");
            };
[/quote]
You still didn't write what behaviour of the Designer are you waiting for. Do you want the Designer does back to the Design tab?

If there are any error no message will be shown and users will see a blank report. You could show message using MessageBox.Show() method.

Thank you.
marco.correa
Posts: 26
Joined: Wed Nov 16, 2011 12:33 pm
Location: Blumenau, Santa Catarina, Brazil

Change the sql command before preview

Post by marco.correa »

Hello,

My doubt is how we can cancel report preview without throw a exception to the user. Today we are treating this behavior with a exception. Is there another way?

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

Change the sql command before preview

Post by Alex K. »

Hello,

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

Thank you.
marco.correa
Posts: 26
Joined: Wed Nov 16, 2011 12:33 pm
Location: Blumenau, Santa Catarina, Brazil

Change the sql command before preview

Post by marco.correa »

Follows the sample project.
Attachments
1861.TemplateUsingReport - CancelPreview.zip
(55.85 KiB) Downloaded 362 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Change the sql command before preview

Post by HighAley »

Hello.

Please, describe filterSettings.Length == 0 condition. Does it constant or could be changed at design time?

If it is unchangeable then you could pass the necessary data to report with RegData or UserDataSource methods and remove preview tab from designer.

In other case you could use next code:

Code: Select all

StiOptions.Engine.GlobalEvents.PreviewingReportInDesigner += (s, args) =>
{
    if (filterSettings.Length == 0)
    {
        StiReport rep = (s as Stimulsoft.Report.Design.StiDesignerControl).Report;
        rep.NeedsCompiling = false;
        rep.IsRendered = true;
        rep.RenderedPages.Clear();
    }
    else
    {
        StiReport rep = (s as Stimulsoft.Report.Design.StiDesignerControl).Report;
        rep.NeedsCompiling = true;
        rep.IsRendered = false;
    }
};
Thank you.
marco.correa
Posts: 26
Joined: Wed Nov 16, 2011 12:33 pm
Location: Blumenau, Santa Catarina, Brazil

Change the sql command before preview

Post by marco.correa »

Hello,

In our case the filterSetting is changeable.

We added your code but now it's printed a white screen when filterSettings.Length == 0. Is there any way to go back to "Page 1" tab or just no show anything to user ?

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

Change the sql command before preview

Post by Alex K. »

Hello,

[quote="marco".correa]Is there any way to go back to "Page 1" tab or just no show anything to user ?[/quote]

Unfortunately, it is impossible.

Thank you.
Post Reply