How to: Create a Report without Visible Scheduler Control
- 2 minutes to read
Sometimes, all you need to do is print the schedules based on the data obtained from a data source. In this case, the visible form containing the Scheduler control and the editing capability provided by the Report Designer are unnecessary. Suppose your application works on the server and the end-user can only specify the report’s template and the time interval.
To accomplish this task the stand-alone SchedulerStorage is created. It is bound to data, and can play the role of the data source for the report’s print adapter.
A new XtraSchedulerReport object is created. The ready-made report layout is already available. It is contained in the report template which has been constructed using the Report Designer. Use the XtraReport.LoadLayout method to load the report’s template and the SchedulerControlPrintAdapter.SetSourceObject method to specify the previously created SchedulerStorage as the data source for the report.
The SchedulerPrintAdapter.TimeInterval, SchedulerPrintAdapter.FirstDayOfWeek, XtraSchedulerReport.PrintColorSchema and other options can be used to customize the report. For advanced customizations, a set of Validate* events, such as the SchedulerPrintAdapter.ValidateAppointments, SchedulerPrintAdapter.ValidateResources, SchedulerPrintAdapter.ValidateTimeIntervals, or SchedulerPrintAdapter.ValidateWorkTime can be helpful. For example, use the ValidateAppointments event to filter appointments and display only recurring ones.
The following code illustrates the technique described above:
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-load-an-xtraschedulerreport-from-template-e1389
// Create a new Scheduler Storage SchedulerStorage storage = new SchedulerStorage(); // Load schedule data into the storage DataHelper.FillStorageData(storage); // Create a new report XtraSchedulerReport report = new XtraSchedulerReport(); // Load the report template report.LoadLayout(DataHelper.GetTemplate()); // Specify the print adapter which provides data for the report if(report.SchedulerAdapter != null) report.SchedulerAdapter.SetSourceObject(storage); else report.SchedulerAdapter = new SchedulerStoragePrintAdapter(storage); // Specify the time inteval for the report and set the required options report.SchedulerAdapter.TimeInterval = new TimeInterval(new DateTime(2010, 07, 12), new DateTime(2010, 08, 01)); report.SchedulerAdapter.FirstDayOfWeek = DevExpress.XtraScheduler.FirstDayOfWeek.Saturday; report.PrintColorSchema = PrintColorSchema.FullColor; // Implement appointment filtering report.SchedulerAdapter.ValidateAppointments += new AppointmentsValidationEventHandler(SchedulerAdapter_ValidateAppointments); // Preview the report ReportPrintTool rpt = new ReportPrintTool(report); rpt.ShowPreviewDialog();