In this blog lets discuss simple approach to create a distinct record in a separate table for each occurrence of a recurring appointment. We'll handle following scenarios :
- Create a distinct record in a separate table for each occurrence of a recurring appointment.
- Not create a separate record for non-recurring appointments.
Binding C1Scheduler to a Data Source
The first step is to bind the C1Scheduler to a data source. We will follow the steps as it is to bind the scheduler to a simple Appointment table using the steps mentioned in the documentation.
Creating a Recurrence Table
In the database designer, the recurrence table needs an extra field to reference the master appointment (Parent).
If the master appointments table uses a GUID instead of an integer as the id column, then the recurrence table needs to follow suit.
Saving Occurrences of Recurring Appointment
In the screen designer of the CalendarScreen, click Add Data Item and add the entity for this table (Recurrences).
Now create a handler for Saved event of the screen. The Saved handler for the screen looks like this:
partial void Calendar_Saved()
DataWorkspace workspace = this.Application.CreateDataWorkspace();
C1.C1Schedule.AppointmentCollection acoll = scheduler.DataStorage.AppointmentStorage.Appointments;
foreach (C1.C1Schedule.Appointment a in acoll)
int key = (int)a.Key;
if (!this.Recurrences.Any(r => r.Parent == key))
C1.C1Schedule.AppointmentList alist = acoll.GetOccurrences(a, a.Start, a.Start.AddYears(1));
foreach (C1.C1Schedule.Appointment aa in alist)
Recurrence rec = workspace.ApplicationData.Recurrences.AddNew();
rec.Subject = aa.Subject;
rec.StartTime = aa.Start;
rec.EndTime = aa.End;
rec.Location = aa.Location;
rec.Body = aa.Body;
rec.Properties = aa.GetAppointmentProperties();
rec.Parent = key;
Download the sample for detailed implementation.