Page 1 of 2

Overriding the StiDesigner.SavingReport event occurs twice in Ribbon GUI

Posted: Mon Jan 31, 2011 10:42 am
by TheOmniAdam
Hi,

I successfully input an event handler that overrides the usual save fearture of the Report Scheduler by looking at the event SavingReport and instead saves the file serialized to a database as an image. What I'm stuck on now is that if I change the GUI to Ribbon, this save override gets called twice under every circumstance that this document saves instead of once. This means when I either save a new report or modify the old one but choose to save as, it brings up my dialogbox twice.

Again, this only happen in Ribbon GUI. Is there a way to get around this? I only want it to call once per save

Thanks
-Adam

Overriding the StiDesigner.SavingReport event occurs twice in Ribbon GUI

Posted: Tue Feb 01, 2011 3:16 am
by Alex K.
Hello,

Please send us sample project data which reproduses the issue.

Thank you.

Overriding the StiDesigner.SavingReport event occurs twice in Ribbon GUI

Posted: Tue Feb 01, 2011 9:22 am
by TheOmniAdam
This is just the creation and call of the report designer itself within the main project flow

Code: Select all

public sub DesignReport (byval strFileName as String)
            Dim Report As Stimulsoft.Report.StiReport = New Stimulsoft.Report.StiReport
            Report.ScriptLanguage = Stimulsoft.Report.StiReportLanguageType.VB
            Report.RegData("DataSet", grdPreviewResults.DataSource)
            Report.Load(strFileName)
            [b]AddHandler Stimulsoft.Report.Design.StiDesigner.SavingReport, AddressOf clsQPReports.SaveWithoutDialog[/b]
            Report.Design()
            Report.Dispose()
End Sub
This is a class with all the calls regarding StiReports

Code: Select all

Public Sub SaveWithoutDialog(byVal sender as Object, ByVal e as Stimulsoft.Report.Design.StiSavingObjectEventArgs)
        'Check if this is initial save or save as option
        If LastPathSaved Is Nothing Or e.SaveAs = True Then
            Dim strTempSave As String = System.IO.Path.GetTempPath & "Report" & Now().ToString("MM_dd_yyyy HH_mm_ss") & ".mrt"
            Dim service As New Stimulsoft.Report.SaveLoad.StiXmlReportSLService()
            MyBase.Save(service, strTempSave)
            [b]Call SaveToDataBase(True, strTempSave)[/b]
        Else
            'If it is just a save, sometimes saving too frequently causes it to error out since it is still looking at the file
            Dim boolSaveWorked As Boolean = False
            Try
                MyBase.Save(LastPathSaved)
                boolSaveWorked = True
            Catch ex As Exception
            End Try
            'If so, perform a new save and use the new file as reference from now on, ignoring the old
            If boolSaveWorked = False Then
                Dim strTempSave As String = System.IO.Path.GetTempPath & "Report" & Now().ToString("MM_dd_yyyy HH_mm_ss") & ".mrt"
                Dim service As New Stimulsoft.Report.SaveLoad.StiXmlReportSLService()
                MyBase.Save(service, strTempSave)
            End If
            [b]Call SaveToDataBase(False, LastPathSaved)[/b]
        End If
        e.Processed = True
    End Sub

Public Sub SaveToDataBase(ByVal createNew As Boolean, ByVal filePath As String)
        'This call will save a serialized copy of the temporary saved .mrt file from the temp folder into the  Database
        Dim designer As New QP.ReportDesignerFile()
        Dim dt As DataTable = designer.RetrieveReportDesignerFile(DesignerID)
        Dim reportName As String = Me.ReportName
        Dim strDesignerFile As String = filePath
        Dim strComments As String = ""
        'Distinguish between creating a new 
        If dt.Rows.Count > 0 And createNew = False Then
            reportName = dt.Rows(0).Item(2).ToString
            strComments = dt.Rows(0).Item(3).ToString
            DesignerID = designer.SaveReportDesignerFile(DesignerID, reportName, strDesignerFile, strComments)
        Else
            Dim frmNewDesigner As New pfrmNewDesigner(reportName)
            Dim formResult As DialogResult
            formResult = frmNewDesigner.ShowDialog()
            reportName = frmNewDesigner.txtReportName.Text
            strComments = frmNewDesigner.txtComments.Text
            If reportName = "" Or formResult = DialogResult.Cancel Then
                Exit Sub
            End If
            DesignerID = 0
            DesignerID = designer.SaveReportDesignerFile(DesignerID, reportName, strDesignerFile, strComments)
            If ReportID  0 Then
                Dim tblTemp As DataTable = designer.ReportRelationships(ReportID)
                Dim boolDefault As Boolean = tblTemp.Rows.Count <= 0
                designer.SaveReportRelationship(ReportID, DesignerID, boolDefault)
            End If
        End If
        LastPathSaved = filePath
    End Sub
Because of the way the system works, it has to serialize a saved copy of the complete .mrt file- it can't use any of the internal serializations that StiReports includes which is why it saves it to the users temporary folder using the default save feature- however EVERY save feature has an override included in the clsQPReports that ignores the base save call in case it slips through the event handler calling e.processed = true.

Overriding the StiDesigner.SavingReport event occurs twice in Ribbon GUI

Posted: Thu Feb 03, 2011 2:46 am
by Alex K.
Hello,

Plesae remove from your code the following string

Code: Select all

Report.Dispose()
Thank you.

Overriding the StiDesigner.SavingReport event occurs twice in Ribbon GUI

Posted: Thu Feb 03, 2011 10:48 am
by TheOmniAdam
This does not fix the problem and I'm not sure how it would. Report.Design() calls a modal window so report.dispose doesn't come into play until I close the designer. Nevertheless I tried it and it didn't work so I still need help. The save overrides are meant to occur within the Report Designer in place of the usual Save and Save As functions- and they do! I just can't stop them from repeatedly saving (In the case of the Ribbon GUI only for some strange reason).

Also, when working with a New report designer file, no matter how many times I save, it calls the save with the SaveAs = true. Is there a flag I have to set to avoid making every save a SaveAs with a new Report? In my override I call the same base save function of the stimulsoft report designer but this still doesn't get set in the process.

Overriding the StiDesigner.SavingReport event occurs twice in Ribbon GUI

Posted: Thu Feb 03, 2011 11:02 am
by ACordero
Did you try restarting it?

Thanks

Overriding the StiDesigner.SavingReport event occurs twice in Ribbon GUI

Posted: Sun Feb 06, 2011 3:33 am
by Ivan
Hello,

Please try to modify your code:

Code: Select all

public sub DesignReport (byval strFileName as String)
            Dim Report As Stimulsoft.Report.StiReport = New Stimulsoft.Report.StiReport
            Report.ScriptLanguage = Stimulsoft.Report.StiReportLanguageType.VB

            Report.IsModified = False

            Report.RegData("DataSet", grdPreviewResults.DataSource)
            Report.Load(strFileName)
            [b]AddHandler Stimulsoft.Report.Design.StiDesigner.SavingReport, AddressOf clsQPReports.SaveWithoutDialog[/b]
            Report.Design()
            Report.Dispose()
End Sub
Thank you.

Overriding the StiDesigner.SavingReport event occurs twice in Ribbon GUI

Posted: Mon Feb 07, 2011 9:38 am
by TheOmniAdam
That is helpful- this seems to stop it from saving twice on a "Save As" However when working with a new Report Designer file, it still calls my save method and therefore my save dialogbox twice. Any additional advice or insight?

Overriding the StiDesigner.SavingReport event occurs twice in Ribbon GUI

Posted: Tue Feb 08, 2011 2:24 am
by Alex K.
Hello,

When you click a button each time, you sign up for the event of saving a report in the designer. And it turns out that in a few clicks, your code is executed several times. Correct your code as follows.

Code: Select all

AddHandler Stimulsoft.Report.Design.StiDesigner.SavingReport, AddressOf clsQPReports.SaveWithoutDialog
Report.Design()
RemoveHandler Stimulsoft.Report.Design.StiDesigner.SavingReport, AddressOf clsQPReports.SaveWithoutDialog
Thank you.

Overriding the StiDesigner.SavingReport event occurs twice in Ribbon GUI

Posted: Tue Feb 08, 2011 10:25 am
by TheOmniAdam
That seems to have remedied the problem, and I'm grateful, but in testing to ensure this solution worked I came across another problem. When I create a new document, it ALWAYS treats saving as a new save, even if I've already saved it. How can I tell it in the override that it's no longer a new save?