Change the sql command before preview

Stimulsoft Reports.NET discussion
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,

We need to change a SQL command on a DataSource before "report preview" of the StiDesignerControl.

Where can we put this code to change the SQL of the DataSource?

We added this code below on PreviewingReportInDesigner event but the sql changed not affected the report being viewed.

Code: Select all

StiSqlSource sqlSource = (report.Dictionary.DataSources[0] as StiSqlSource);
sqlSource.SqlCommand = "SELECT * FROM TABLE WHERE {MYVARIABLE};              
Thank you.
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 need to change a SQL command on a DataSource before "report preview" of the StiDesignerControl.

Where can we put this code to change the SQL of the DataSource?

We added this code below on PreviewingReportInDesigner event but the sql changed not affected the report being viewed.

Code: Select all

StiSqlSource sqlSource = (report.Dictionary.DataSources[0] as StiSqlSource);
sqlSource.SqlCommand = "SELECT * FROM TABLE WHERE {MYVARIABLE};              
[/quote]
It's impossible to do it in the PreviewingReportInDesigner event because the event is called after compiling report.

Please, describe why are you trying to change Sql Command and we'll try to find a way out.

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,

After your answer I put the code on "ReportCompiling" event and it worked. Is it right to maintain the code there?

How I proceed to cancel a preview using an event ?

Thank you.
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]After your answer I put the code on "ReportCompiling" event and it worked. Is it right to maintain the code there?

How I proceed to cancel a preview using an event ?[/quote]
We need more time to prepare an answer for you.

Thank you.
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]How I proceed to cancel a preview using an event ?[/quote]
Please, describe your problem more detailed.

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,

We need to do some verifications before report be displayed.

If some verification fail, we need to cancel the preview of report and show a message to user.

Thank you.
Brainstorm
Posts: 31
Joined: Thu Feb 17, 2011 1:54 pm
Location: Cuiaba, Brazil

Change the sql command before preview

Post by Brainstorm »

Normally we run the designer after a "print button" click event, inside that event we do the necessary checks (read: queries) before doing the actual select that will load the report datasets.
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 need to do some verifications before report be displayed.

If some verification fail, we need to cancel the preview of report and show a message to user.[/quote]
What behaviour are you waiting from Designer? If there any problem the report will not be rendered.

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,

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.");
            };

Thank you.
Attachments
1848.Sem título.png
1848.Sem título.png (35.83 KiB) Viewed 4455 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.
[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.
Post Reply