Prompting to Save Report When Closing Viewer

Stimulsoft Reports.NET discussion
Post Reply
fphealthcare
Posts: 33
Joined: Sun Jul 02, 2006 6:06 pm
Location: New Zealand

Prompting to Save Report When Closing Viewer

Post by fphealthcare »

After the report has been shown in the desinger, we want to ask the user if they would like to save the report before closing. Is there a way to do this?

We are using report.Render() to render the report, and report.Show() to show the report.

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

Prompting to Save Report When Closing Viewer

Post by Edward »

fphealthcare wrote:After the report has been shown in the desinger, we want to ask the user if they would like to save the report before closing. Is there a way to do this?
We are using report.Render() to render the report, and report.Show() to show the report.
When the Designer is Loaded for designing a report the static event StiDesigner.LoadingDesigner is fired. But in that case the designer is not visible on screen while the event is occurring. Anyway you can ask the user in that moment is he going to save a report or not after the report will be designed.

Here the code sample of such assignment:

Code: Select all

public bool WeSaveTheReport;

StiDesigner.LoadingDesigner +=new EventHandler(StiDesigner_LoadingDesigner);
StiDesigner.SavingReport += new EventHandler(StiDesigner_SavingReport);

public void StiDesigner_LoadingDesigner(object sender, EventArgs e)
{
      // Ask the user about later saving and store the result in WeSaveTheReport variable.
     StiDesigner.DontAskSaveReport = !WeSaveTheReport;
}

public void StiDesigner_SavingReport(object sender,StiSavingObjectEventArgs e)
{
   //Here the code for saving report, because StiDesigner.DontAskSaveReport does not prevent saving of the modified report.
  
  e.Processed = true;
}
Please note that static events should be assigned only once in your application.

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

Prompting to Save Report When Closing Viewer

Post by Edward »

We will add a new property which allows do not save the report modified when StiDesigner.DontAskSaveReport = true.

Thank you.
fphealthcare
Posts: 33
Joined: Sun Jul 02, 2006 6:06 pm
Location: New Zealand

Prompting to Save Report When Closing Viewer

Post by fphealthcare »

Edward wrote:When the Designer is Loaded for designing a report the static event StiDesigner.LoadingDesigner is fired. But in that case the designer is not visible on screen while the event is occurring. Anyway you can ask the user in that moment is he going to save a report or not after the report will be designed.

Here the code sample of such assignment:

Code: Select all

public bool WeSaveTheReport;

StiDesigner.LoadingDesigner +=new EventHandler(StiDesigner_LoadingDesigner);
StiDesigner.SavingReport += new EventHandler(StiDesigner_SavingReport);

public void StiDesigner_LoadingDesigner(object sender, EventArgs e)
{
      // Ask the user about later saving and store the result in WeSaveTheReport variable.
     StiDesigner.DontAskSaveReport = !WeSaveTheReport;
}

public void StiDesigner_SavingReport(object sender,StiSavingObjectEventArgs e)
{
   //Here the code for saving report, because StiDesigner.DontAskSaveReport does not prevent saving of the modified report.
  
  e.Processed = true;
}
Please note that static events should be assigned only once in your application.

Thank you.
I am very sorry. I had made a mistake in my typing. I don't want to ask the user if they want to save the report in the desinger, I want to ask them if they want to save in the VIEWER. We use report.Show() to display the report, and we want to ask the user when they close the viewer if they want to save the report or not?

Can we do this?
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Prompting to Save Report When Closing Viewer

Post by Edward »

Please use the following code:

Code: Select all

using (StiPreviewForm myForm = new StiPreviewForm())
{
    (myForm as Form).FormClosing += new FormClosingEventHandler();
    myForm.PreviewControl.Report = report;
    report.Render();
    myForm.ShowDialog();
}

public void myForm_FormClosing(object sender, FormClosingEventArgs e)
{
   if (MessageBox.Show("Do you want to store rendered report", "Form Closing Event", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1) == DialogResult.Yes)
  {
     report.SaveDocument("D:\\MyReport.mdc");
     (sender as Form).FormClosing -= new FormClosingEventHandler(myForm_FormClosing);
  }
}
Thank you.
fphealthcare
Posts: 33
Joined: Sun Jul 02, 2006 6:06 pm
Location: New Zealand

Prompting to Save Report When Closing Viewer

Post by fphealthcare »

Edward wrote:Please use the following code:

Code: Select all

using (StiPreviewForm myForm = new StiPreviewForm())
{
    (myForm as Form).FormClosing += new FormClosingEventHandler();
    myForm.PreviewControl.Report = report;
    report.Render();
    myForm.ShowDialog();
}

public void myForm_FormClosing(object sender, FormClosingEventArgs e)
{
   if (MessageBox.Show("Do you want to store rendered report", "Form Closing Event", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1) == DialogResult.Yes)
  {
     report.SaveDocument("D:\\MyReport.mdc");
     (sender as Form).FormClosing -= new FormClosingEventHandler(myForm_FormClosing);
  }
}
Thank you.
We have added the code but have been getting an error.
The complier complains
"The type or namespace name 'FormClosingEventArgs' could not be found (are you missing a using directive or an assembly reference?)"

How can we fix this?
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Prompting to Save Report When Closing Viewer

Post by Edward »

You should add the following namespace to your application:

Code: Select all

using System.Windows.Forms;
The FormClosingEventArgs is declared in this namespace.

Thank you.
Post Reply