This is a migrated thread and some comments may be shown as answers.

Silverlight Reportviewer Print event

5 Answers 265 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 16 Nov 2010, 12:48 AM
Hi,

I am using Telerik Reporting Q2 2010 in silverlight 4 application. To show report, I am using Telerik reportviewer in xaml file.
My requirement is to update status in database if report is printed and its very crucial requirement.
I tried several ways and looked into Telerik help as well as googling but could not found any meaningful solution.
Please help me finding a solution or at least a workaround.

A quick help will be greatly appreciated.

-Jono

5 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 18 Nov 2010, 06:11 PM
Hello Jonathan,

Currently the Silverlight Report Viewer doesn't expose a Print event. However you can add a Print button and handle on Click event to call a service. You will need a WCF service with a UpdataDatabase() method and within the button click event you have to call the service's UpdataDatabase() method that will update the database. In order to print with the button you will need the report viewer model and invoke the reportViewerModel.PrintReportCommand.Execute(null). Additionally you will have to hide the report viewer's print button. Because the Silverlight Report Viewer is a template you can easily change it with Expression Blend.


Check out the attached sample solution.

Greetings,
Peter
the Telerik team
Get started with Telerik Reporting. Watch the numerous videos.
0
Jonathan
Top achievements
Rank 1
answered on 19 Nov 2010, 05:18 AM
Thanks very much!
'll look into this.

Thanks,
Jono
0
Lauren
Top achievements
Rank 1
answered on 28 Jun 2011, 08:28 AM
Hi,
Thank you for the post, that's exactly what i was looking for.

One more question though, In the example, it seems the database is updated wether the user click on OK or Cancel once the Print dialog is open.
Is there a way to know if the user cancelled the print and update the database only if the report has actually been printed ?

Thanks for your help.
Lauren
0
Ricky
Top achievements
Rank 1
answered on 23 Sep 2013, 09:24 PM
Hello,

I have the exact same type of requirement that Jonathan has: update something in the database after the printing has occured. I am using WCF with Silverlight 4 front end coupled with Telerik Reporting Q2 2011. I used Expression blend to explictly include the template and commented out the built in print button. 

telerik dialog buttons from template:

<telerik:DialogBox x:Name="PrintDialog" Visibility="Collapsed">
                                                            <Grid Width="270">
                                                                <Grid.RowDefinitions>
                                                                    <RowDefinition Height="100"/>
                                                                    <RowDefinition Height="auto"/>
                                                                </Grid.RowDefinitions>
                                                                <Grid HorizontalAlignment="Stretch" Margin="20" VerticalAlignment="Center">
                                                                    <Grid.RowDefinitions>                                                                        <RowDefinition/>
                                                                        <RowDefinition Height="auto"/>
                                                                    </Grid.RowDefinitions>
                                                                    <TextBlock HorizontalAlignment="Center" TextAlignment="Center" Text="{Binding PrintProgress}" VerticalAlignment="Center"/>
                                                                    <telerik1:RadProgressBar x:Name="PrintProgressBar" Grid.Row="1" Style="{StaticResource ProgressBarStyle}" Visibility="Collapsed"/>
                                                                </Grid>
                                                                <Grid Grid.Row="1">
                                                                    <Grid.ColumnDefinitions>
                                                                        <ColumnDefinition Width="*"/>
                                                                        <ColumnDefinition Width="auto"/>
                                                                        <ColumnDefinition Width="auto"/>
                                                                    </Grid.ColumnDefinitions>
                                                                    <telerik1:RadButton Content="Print" Grid.Column="1" Command="{Binding PrintDocumentCommand}" Click="RadButton_Click" Margin="5" Padding="10, 3" telerik1:StyleManager.Theme="{StaticResource Theme}"/>
                                                                    <telerik1:RadButton Content="Cancel" Grid.Column="2" Command="{Binding CancelPrintDocumentCommand}" Margin="5" Padding="10, 3" telerik1:StyleManager.Theme="{StaticResource Theme}"/>
                                                                </Grid>
                                                            </Grid>
                                                        </telerik:DialogBox>



My print button button click event to show the Telerik Print Dialog:

private void Button_Click()
 {
         var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(this.reportViewer1, 0);
         var reportViewerModel = (ReportViewerModel)(layoutRoot.DataContext);
  
         //if (reportViewerModel.State.Equals("ViewerPageState"))
             reportViewerModel.PrintReportCommand.Execute(null);
 }


RadButton Print Click Event to perform the Async call to update database that form has been printed:

private void RadButton_Click(object sender, RoutedEventArgs e)
{
      CurrentViewModel.StoreFormLetter();
}


Everything seems to work fine: user hits my Submit button to show a the telerik print dialog with Print & Cancel, 
and clicking Print will update the database and give the browser's print dialog to appear.

However, if the user clicks Cancel, then clicks Submit - the telerik PrintDialog doesn't appear. Instead it goes
straight to the browser's print dialog. Because I have my Async call tied to the Telerik PrintDialog's Print button 
being clicked, it will never update the database that the print actually occured because the button was never clicked.

Why is the PrintDialog only showing up in the first instance of calling: reportViewerModel.PrintReportCommand.Execute(null);?

* Sorry for the bad formatting - I will clean this up tomorrow*
0
Stef
Telerik team
answered on 27 Sep 2013, 04:18 PM
Hi Ricky,

Using the latest Telerik Reporting version, when the print button tied to the Button_Click handler is clicked, it invokes the print dialog every time. If the Silverlight ReportViewer.UseNativePrinting Property is set to true, executing the ReportViewerModel.PrintReportCommand invokes a confirmation window before proceeding with the print operation, otherwise the viewer uses True Print, which is based on the browser's PDF plugin, and there appears the browser's print dialog.

If you need further help, we will need more details how the database update method is called after the PrintReportCommand is executed. It will be easier if you can send us a sample project illustrating your scenario in a support ticket.
 
Regards,
Stef
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

Tags
General Discussions
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Peter
Telerik team
Jonathan
Top achievements
Rank 1
Lauren
Top achievements
Rank 1
Ricky
Top achievements
Rank 1
Stef
Telerik team
Share this question
or