ASPxSchedulerDataWebControlBase.AppointmentInserting Event
Occurs before an appointment is added to the AppointmentBaseCollection collection and allows you to cancel the operation.
Namespace: DevExpress.Web.ASPxScheduler
Assembly: DevExpress.Web.ASPxScheduler.v24.2.dll
Declaration
Event Data
The AppointmentInserting event's data class is PersistentObjectCancelEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Cancel | Gets or sets whether to cancel the operation. |
Object | Gets the persistent object (appointment, resource or appointment dependency) for which the event occurs. Inherited from PersistentObjectEventArgs. |
Remarks
The AppointmentInserting event is raised before an appointment is added to the AppointmentBaseCollection collection and allows you to cancel the operation.
The event parameter’s PersistentObjectEventArgs.Object property gets the appointment being inserted. To cancel insertion, set the PersistentObjectCancelEventArgs.Cancel property to true
. To validate appointment insertion, you can get properties of the appointment being inserted by casting the e.Object parameter to the Appointment type.
Note
Do not modify the appointment’s data source or data binding within this event handler. It results in the current appointment being disposed of, and consequently, an unhandled exception occurs.
Tip
To initialize a new appointment, you can also use the ASPxScheduler.InitNewAppointment event.
Example
The following example illustrates how to use the ASPxSchedulerDataWebControlBase.AppointmentInserting
event. On this event, the scheduler creates regular (non-recurring) appointments (AppointmentType.Normal) instead of appointments that serve as the patterns for the other recurring appointments (AppointmentType.Pattern) if the latter don’t have the end date.
The scheduler generates and inserts regular appointments into the storage based on recurring occurrences. The OccurrenceCalculator class allows you to obtain recurring occurrences for a current recurring chain (RecurrenceInfo). Two custom fields are used to consider generated appointments as occurrences of a single series (these field values will be further used to remove entire series). The e.Cancel parameter allows you to cancel insertion of a recurring pattern into a storage.
Note
It is not allowed to created recurring series with the “No End Date” option.
protected void ASPxScheduler1_AppointmentInserting(object sender, PersistentObjectCancelEventArgs e) {
if(isLocked) return;
ASPxSchedulerStorage storage = sender as ASPxSchedulerStorage;
Appointment newAppointment = e.Object as Appointment;
if(newAppointment.Type == AppointmentType.Pattern) {
if(newAppointment.RecurrenceInfo.Range != RecurrenceRange.NoEndDate) {
isLocked = true;
OccurrenceCalculator calc = OccurrenceCalculator.CreateInstance(newAppointment.RecurrenceInfo);
TimeInterval processedInterval = new TimeInterval(newAppointment.RecurrenceInfo.Start, newAppointment.RecurrenceInfo.End);
AppointmentBaseCollection calculatedOccurrences = calc.CalcOccurrences(processedInterval, newAppointment);
// Creates standard appointments instead of appointments that serve as the patterns for the other recurring appointments
storage.BeginUpdate();
for(int i = 0; i < calculatedOccurrences.Count; i++) {
Appointment newRegularOccurrence = storage.CreateAppointment(AppointmentType.Normal);
newRegularOccurrence.AllDay = calculatedOccurrences[i].AllDay;
newRegularOccurrence.Description = calculatedOccurrences[i].Description;
newRegularOccurrence.LabelKey = calculatedOccurrences[i].LabelKey;
newRegularOccurrence.Location = calculatedOccurrences[i].Location;
newRegularOccurrence.ResourceId = calculatedOccurrences[i].ResourceId;
newRegularOccurrence.Start = calculatedOccurrences[i].Start;
newRegularOccurrence.End = calculatedOccurrences[i].End;
newRegularOccurrence.StatusKey = calculatedOccurrences[i].StatusKey;
newRegularOccurrence.Subject = calculatedOccurrences[i].Subject;
newRegularOccurrence.CustomFields["LessonCompleted"] = calculatedOccurrences[i].CustomFields["LessonCompleted"];
newRegularOccurrence.CustomFields["CustomRecurringFlag"] = true;
newRegularOccurrence.CustomFields["CustomRecurringID"] = newAppointment.RecurrenceInfo.Id.ToString();
storage.Appointments.Add(newRegularOccurrence);
}
storage.EndUpdate();
isLocked = false;
}
else {
ASPxScheduler1.JSProperties["cpCallbackError"] = "You cannot create endless recurring series ('No End Date' option)";
}
e.Cancel = true;
}
}