How to report all occurrences of appointments in a RadScheduler control within a specific date range using Telerik Reporting

At first sight, reporting all appointments sounds a pretty straightforward task - all that is needed is to execute a single SQL SELECT query over the appointments table of the database. However, the tricky moment here is that all appointments, including the recurrent ones are stored as a single record and despite a recurring appointment may occur 100 times, it will be reported as 1 item. Well, the key here is to parse the RecurrenceRule so that we can get all occurrences of the recurrent appointment.

Before we start we have to make sure that we have installed Telerik Reporting. The attached project works with Q1 2010 version.
Below are some key steps made to edit the initial example:
1. Make sure you have the ReportService.svc file in the Web project with this content:

Cancel the upcoming Wizard since some custom steps will be made in order to feed the report.
After that you will have an empty designer at which you can drag and drop controls from the ToolBox:

A step describing how it is designed appears later in the article.
3. First, a set of objects are needed in order to be reported. In this case the objects are appointments (or should represent ones) and should be returned by a method (named GetAllAppointmentsFlatted() in our case) which will later be called by the report. The problem here is that recurrent appointments in RadScheduler are represented by one Appointment object with a RecurrenceRule, which means that they will appear as a single record in the report if we return them as they are in the database. A way to “flatten” such appointments is needed so that object representing each occurrence is provided to the Telerik Report. That is why the GetOccurrences(this IAppointment appointment, DateTime from, DateTime to) extension method in RadScheduler’s API will be very convenient in this case:

publicIEnumerable GetAllAppointmentsFlatted()

{

…

if(schedulerAppointment.RecurrenceRule != null)

{

// this gets all occurrences within some interval of time, in this case: +- 100 days from today, ORDERED BY Start

The date range is set to +-100 days, because if there is a recurring appointment with RecurrenceRule set to forever there will be an overload of occurrences.NOTE: In order to use the API of RadScheduler at this stage, two references should be added to the Web project:

Telerik.Windows.Controls.Scheduler

System.Windows (Silverlight 4)

4. Next step is to make our report use the method we have just created.
From the ToolBox drag and drop on the designer surface an ObjectDataSource control. The ObjectDataSource control represents a data object that acts as a data-interface for the data bound controls. To configure it we have to choose Select a Business Object->Scheduler Reports->Report1-> <GetAllAppointmentsFlatted>.

5. Once having the report data, we should take care of how it will look like. The design in the article is achieved with several TextBoxes arranged like so:

6. Finally, a ReportViewer is needed in the Silverlight project in order to display the report:

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.