Capturing report new and report open events in the report designer

Stimulsoft Reports.NET discussion
jing
Posts: 50
Joined: Fri Jan 26, 2007 12:47 am
Location: New Zealand

Capturing report new and report open events in the report designer

Post by jing »

Hi,

How do I capture the event when the user is creating a new report and when the report open button is pushed in the Report Designer?

I would like to reset the database connection when that happens.

thanks
jing
Posts: 50
Joined: Fri Jan 26, 2007 12:47 am
Location: New Zealand

Capturing report new and report open events in the report designer

Post by jing »

Ok, I managed to capture the event when the report open button is pushed.

Here is my code:

Code: Select all

AddHandler Stimulsoft.Report.Design.StiDesigner.LoadingReport, AddressOf TestFunction

Private Sub TestFunction(ByVal sender As Object, ByVal e As Stimulsoft.Report.Design.StiLoadingObjectEventArgs)

        If OpenFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then

               Dim designer As Stimulsoft.Report.Design.StiDesigner = sender
               designer.Report.Dictionary.Clear()
               designer.OpenFile(OpenFileDialog.FileName)
               Dim database As Dictionary.StiSqlDatabase = designer.Report.Dictionary.Databases("Exonet")
              database.ConnectionString = "Data Source=" & db.Server & ";Initial Catalog=exonet_copy619;User Id=" & db.UserID & ";Password=" & db.Password

        End If
End Sub
It works fine except that when I try to create a new report by pushing the "New Report" button, the database connection string is still set to the report I opened before.

I need the database connection to set to the orginal settings (ie. When I opened the designer originally, I set it to point at database "x_exonet"). How can I get around this?

thanks
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Capturing report new and report open events in the report designer

Post by Edward »

So if I understood in the right way you need to set a previous Connection for the report which will be created after pressing the New Report button?

Please describe with more detail.

Thank you.
jing
Posts: 50
Joined: Fri Jan 26, 2007 12:47 am
Location: New Zealand

Capturing report new and report open events in the report designer

Post by jing »

I would like to set a new database connection after pressing the New Report button - so I need to have control over the new report event I think.

Can this be done?

thanks
jing
Posts: 50
Joined: Fri Jan 26, 2007 12:47 am
Location: New Zealand

Capturing report new and report open events in the report designer

Post by jing »

Futher on report open button event,

Does StiDesigner.LoadingReport only called when I click the open button in the Designer?

Because for some reason the event is sometimes called multiple times.... I can't find a pattern to it, sometimes it happens, sometimes it doesn't.

I suspect it's something to do with the designer, When I called designer.OpenFile(reportfilename) or designer.report.load(reportfilename)...

Is there a way to determine when the report has finished loading in the designer? I can put a thread to sleep while it is loading to stop it calling the event !!

Any help on this will be great (Also, is there a documentation on all methods?)

Thanks
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Capturing report new and report open events in the report designer

Post by Vital »

jing wrote:Futher on report open button event,

Does StiDesigner.LoadingReport only called when I click the open button in the Designer?

Because for some reason the event is sometimes called multiple times.... I can't find a pattern to it, sometimes it happens, sometimes it doesn't.

I suspect it's something to do with the designer, When I called designer.OpenFile(reportfilename) or designer.report.load(reportfilename)...

Is there a way to determine when the report has finished loading in the designer? I can put a thread to sleep while it is loading to stop it calling the event !!

Any help on this will be great (Also, is there a documentation on all methods?)

Thanks
If you add event handler to LoadingReport event then standard event handler is skipped. If you need call standard event handler you need add following code:

Code: Select all

e.Processed = false;
If you want fully process this operation then you need manually load report to designer.

Thank you.
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Capturing report new and report open events in the report designer

Post by Vital »

We have added following static events:

Code: Select all

StiDesigner.LoadedReport//Occurs only if report loaded successfully
StiDesigner.SavedReport//Occurs only if report saved successfully
StiDesigner.CreatedReport//Occurs only if report created successfully
StiDesigner.CreatingReport
Thank you.
jing
Posts: 50
Joined: Fri Jan 26, 2007 12:47 am
Location: New Zealand

Capturing report new and report open events in the report designer

Post by jing »

We have added following static events:

StiDesigner.LoadedReport//Occurs only if report loaded successfully
StiDesigner.SavedReport//Occurs only if report saved successfully
StiDesigner.CreatedReport//Occurs only if report created successfully
StiDesigner.CreatingReport
Which build contains these events? I am using build StimulReport.Net 2007.02.16 R2005 and I can't see these events yet.
If you want fully process this operation then you need manually load report to designer.
I am doing this, but the LoadingReport is sometimes called multiple times - I only needed to call it once (I don't quite understand why it is sometimes called multiple times) ... Here is my code

Code: Select all

AddHandler Stimulsoft.Report.Design.StiDesigner.LoadingReport, AddressOf OpenMyReportFile

Private Sub OpenMyReportFile(ByVal sender As Object, ByVal e As Stimulsoft.Report.Design.StiLoadingObjectEventArgs)
        If _loadingReport = False Then
            _loadingReport = True

            Dim dialogR As Windows.Forms.DialogResult = Nothing
            dialogR = MyOpenFile.ShowDialog

            If dialogR = Windows.Forms.DialogResult.Cancel Then
                _loadingReport = False
                Exit Sub
            End If

            If dialogR = Windows.Forms.DialogResult.OK Then

                Dim designer As Stimulsoft.Report.Design.StiDesigner = sender

                designer.Report.Dictionary.Clear()

                designer.Report.Load(MyOpenFile.FileName)

                For Each d As Dictionary.StiSqlDatabase In designer.Report.Dictionary.Databases
                    d.ConnectionString = "Data Source=" & db.Server & ";Initial Catalog= " & db.Database & ";User Id=" & db.UserID & ";Password=" & db.Password
                Next


                _loadingReport = False
            End If
        End If

    End Sub

Any help on this please
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Capturing report new and report open events in the report designer

Post by Vital »

Sorry, build will be available only today.
We will check problem with multiple events running.

Thank you.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Capturing report new and report open events in the report designer

Post by Edward »

Please define a static constructor for your form (for example Form1). It is gets a guarantee that Event Handler OpenMyReportFile will be added to the static event StiDesigner.LoadingReport only once.

Code: Select all

Shared Sub New()
      AddHandler StiDesigner.LoadingReport, New StiLoadingObjectEventHandler(AddressOf Form1.OpenMyReportFile)
End Sub
Thank you.
Post Reply