cancel
Showing results for 
Search instead for 
Did you mean: 

Refreshing ReportDocument without reloading data from database

Former Member
0 Kudos

Hi,

I'm using "Crystal Reports for Visual Studio" version 13.0.13.1597, more specific CrystalReportViewer and ReportDocument.

How do I get the report to refresh when I change the paper orientation?

For instance: I show the user the PageSetupDialog, user switches from Portrait to Landscape. After the dialog is closed, I give the report these new settings:

this.report.PrintOptions.CopyFrom(pageSetupDialog.PrinterSettings, pageSetupDialog.PageSettings);

Now the preview should update the report to show it (for instance) in landscape. To do this, I'm using viewer.RefreshReport() right now. But this also triggers that the data is retrieved from the database again.

Is there any way to trigger a reformatting (or "layout update") of the report without the need of also querying the database again?

Thanks,

Markus

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Markus,

This will not work because there is no Viewer.Refresh. What the Refresh button does on the viewer is it does a complete report object.refresh.

Using CopyTo or any other change is being applied to the ReportDocument and not being applied to the viewer, you have already sent the report to the viewer so only way to refresh the page is to reload the report which hits the database again.

But I like the idea of being able to do a refresh on a preview without triggering a DB refresh.

Add you idea to Idea place - https://ideas.sap.com/

And I'll send them a separate e-mail and pass on the info to DEV and see what they have to say about being able to do this...

Can you specify why you need this? Obvious but need it in writing.

Thanks

Don

0 Kudos

I found a way to make this work.

Here's my work flow:

1. Open the report

2. Log onto the database

3. Preview the report using a View Report button

4. Change the paper size etc. and use RAS to update the printer info:

     rptClientDoc.PrintOutputController.ModifyPrintOptions(newOpts);

     I have a separate button for updating the selected printer options. should be the same as you are doing.

There is a RAS equivolent CopyTo API also.

5. Hit the View Report button again. I have a separate button to view the report. It simply checks if RAS modified the report and then sets the viewer to the appropriate RPT or RCD object.

In #4 I set a flag to use the RAS object and then test which one to use in my View Report button:

try

{

    if (!IsRpt)

    {

        crystalReportViewer1.ReportSource = rptClientDoc.ReportSource;

    }

    else

    {

        crystalReportViewer1.ReportSource = rpt;

    }

}

catch (Exception ex)

{

    btnSQLStatement.Text = "ERROR: " + ex.Message;

}

Confirmed using SQL Profiler when I hit the View report the second time it is not hitting the DB again.

If you are not using a View Report button then disable the Refresh button and create your own, search here for a sample on how to enable your own print button and you'll find a sample app attached.

Thanks again

Don

PS - I will not be pinging DEV to add this ability to the Viewer.

ido_millet
Active Contributor
0 Kudos

Don, why not simply re-assign the ReportSource property of the viewer after using CopyFrom to set the PrintOptions?  In other words, is the button step really necessary.

By the way, just a reminder that it would be nice if the Development team could make the visual effect of re-assigning the ReportSource smoother.

0 Kudos

Hi Ido,

That may work also, I just found one way of making it work in my main test app. He did not say what his work flow is so I just gave him mine.

Technically you don't need to open the report using the engine at all and can simply set the Viewer.ReportSource = RPT. So it's a limitation of the viewer not having control over the log on info when the refresh button is clicked.

Possibly I will ask DEV what the options are for this....

Add the request to Idea Place anyways, They do look at them.

Thanks again

Don

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Don,

thanks for your answer. I tried it and your suggestion works (it does update the report without firing SQL statements).

As a follow-up: are there any convenience methods to convert .Net PrinterSettings/PageSettings into Crystal classes (e.g. PrintOptionsClass, PageMargins, etc.) and vice versa? It seems a bit tedious.

For instance I'm using the PageSetupDialog, I give this dialog my current (.Net) PrinterSettings and PageSettings. Dialog is shown, user changes orientation and margins (don't know what else might change), the dialog gives me the new (.Net) PageSettings. So now I have to create a PrintOptionsClass and update it manually with all values of my PageSettings instance (I'm a bit worried that I might miss some important properties)

The CrystalDecisions.CrystalReports.Engine.PrintOptions class used by the ReportDocument has the nice methods "CopyFrom" and "CopyTo" which work on .Net PrinterSettings/PageSettings.

In contrast, the CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptionsClass has "CopyFromPrinterSettingsAndPageSettings" and "CopyToPrinterSettingsAndPageSettings" which works with EromPrinterSettings and EromPageSettings.

So I can help myself somewhat now, but I think it would be nice to have extension methods or something that provide the conversion between .Net and Crystal classes here. Or maybe something already exists and I just couldn't find it? I found PrintingConverter and PrintOptionsConverter, but nothing for the whole PrinterSettings/PageSettings.

Thanks,

Markus

0 Kudos

Hi Markus,

Great and yes it can be tedious... The change we made in .NET was to remove the specific steps that did a lot of this for in previous SDK's because everyone seemed to always want something slightly different,  we left it all up to you to do the coding.

And due to the way .NET Framework handles printing it's the only way we could...

See if this sample attached will help you. I was written by DEV so it covers everything that should be required. After unzipping the attached file then rename the file to *.zip and the whole project is there.

Don