Hello,
We've designed our application in a way that a report is stored as a string in a database field, then pulled down to show or edit. I'm trying to find a way to avoid creating a temporary file to edit a report, thus I'm setting the report object in the editor instance and it shows the report just fine. However, when a user clicks Save in the editor menu, the report designer asks for a file name and saves the report on a disk.
Is there a way to intercept the Report Saving event in the editor to suppress the original behavior and instead just take the report instance from the designer, serialize it into and push it back to the database? An example of how to inject my own handler into the Report Saving event would be highly appreciated!
Thank you!
Intercepting Save/Load events for a report in Report Designer
Intercepting Save/Load events for a report in Report Designer
Hi,
You need to attach to the static event 'SavingReport' on the StiDesigner object
You should only attach to this event once as it is a static event. All saving events on a report through the designer will pass through this handler.
Your handler function could then do something like this:
And to initally load your report from the string you could do something like this:
You need to attach to the static event 'SavingReport' on the StiDesigner object
Code: Select all
Stimulsoft.Report.Design.StiDesigner.SavingReport += new Stimulsoft.Report.Design.StiSavingObjectEventHandler(StiDesigner_SavingReport);
Your handler function could then do something like this:
Code: Select all
void StiDesigner_SavingReport(object sender, Stimulsoft.Report.Design.StiSavingObjectEventArgs e)
{
//Get the referenced Designer control
Stimulsoft.Report.Design.StiDesignerControl designerControl = sender as Stimulsoft.Report.Design.StiDesignerControl;
//Get the Report open in the designer control
Stimulsoft.Report.StiReport report = designerControl.Report;
//Convert Report to String
string reportString = report.SaveToString();
//*** Save Report String to Database here
//
bool saved = true; //hard coded for demonstration
//
//***
//Error Saving Report?
if (!saved)
{
e.Processed = false;
MessageBox.Show("There was an error saving the Report.\nPlease try again.");
}
}
And to initally load your report from the string you could do something like this:
Code: Select all
private void btnLoad_Click(object sender, EventArgs e)
{
Stimulsoft.Report.StiReport report = new Stimulsoft.Report.StiReport();
//Load your Report String from Database
//Do a Fake Load to demonstrate report String retrieval
string reportString = new Stimulsoft.Report.StiReport().SaveToString();
//Load the Report based on the string data
report.LoadFromString(reportString);
//Open Designer
report.Design();
}
Intercepting Save/Load events for a report in Report Designer
Brendan,
Thanks a lot for such detailed example! Much appreciated!
It's a good starting point.
Best Regards.
Thanks a lot for such detailed example! Much appreciated!
It's a good starting point.
Best Regards.