Skip to main content

ASPxScheduler.AllowAppointmentConflicts Event

Occurs when the scheduler finds appointments that are in conflict, and the SchedulerOptionsCustomization.AllowAppointmentConflicts property is set to AppointmentConflictsMode.Custom.

Namespace: DevExpress.Web.ASPxScheduler

Assembly: DevExpress.Web.ASPxScheduler.v24.2.dll

Declaration

public event AppointmentConflictEventHandler AllowAppointmentConflicts

Event Data

The AllowAppointmentConflicts event's data class is AppointmentConflictEventArgs. The following properties provide information specific to this event:

Property Description
Appointment Gets the appointment for which the event was raised. Inherited from AppointmentEventArgs.
AppointmentClone Gets the clone of the appointment being processed in the SchedulerControl.AllowAppointmentConflicts or the SchedulerControl.AllowAppointmentConflicts events.
Conflicts Gets the collection of appointments which are considered to be conflicting with the current appointment.
Interval Gets the time interval which the event was raised for.

The event data class exposes the following methods:

Method Description
RemoveConflictsWithDifferentResource(AppointmentBaseCollection, Object) Removes all the conflicting appointments from the specified collection whose Appointment.ResourceId doesn’t match the specified Id.

Remarks

By default, the scheduler doesn’t allow creating/updating appointments with intersecting intervals. The AllowAppointmentConflicts event allows you to provide custom logic and extend the default mechanism of calculating appointment conflicts.

Refer to the SchedulerControl.AllowAppointmentConflicts topic, to learn more.

Example

The following example illustrates how to use the ASPxScheduler.AllowAppointmentConflicts event to handle custom conflicts before creating and updating appointments. This approach overrides a predefined mechanism of resolving appointments conflicts. The predefined mechanism does not allow you to create appointments with intersecting intervals for the same resource. The following code illustrates how to extend this mechanism and prevent creating appointments with intersecting intervals for the same locations. JS Properties are used to pass a custom error to the client. Then, this error will be displayed within an alert window.

protected void ASPxScheduler1_AllowAppointmentConflicts(object sender, AppointmentConflictEventArgs e) {
    ASPxScheduler scheduler = sender as ASPxScheduler;
    bool isLocationConflict = false;
    if(e.Conflicts.Count == 0 || (e.Conflicts.Count == 1 && e.Conflicts[0].Id.Equals(e.Appointment.Id))) {
        AppointmentBaseCollection visibleAppts = scheduler.ActiveView.GetAppointments();
        List<Appointment> conflictedAppts = visibleAppts.Where(appt => !appt.Id.Equals(e.Appointment.Id) && appt.Location.Equals(e.Appointment.Location)).ToList();

        foreach(Appointment conflictedAppointment in conflictedAppts) {
            if(Convert.ToBoolean(conflictedAppointment.CustomFields["LessonCompleted"])) continue;

            if(conflictedAppointment.Start < e.Interval.End && conflictedAppointment.End > e.Interval.End) {
                e.Conflicts.Add(conflictedAppointment);
                isLocationConflict = true;
            }
            else if(conflictedAppointment.End > e.Interval.Start && conflictedAppointment.Start < e.Interval.Start) {
                e.Conflicts.Add(conflictedAppointment);
                isLocationConflict = true;
            }
            else if(conflictedAppointment.Start == e.Interval.Start && conflictedAppointment.End == e.Interval.End) {
                e.Conflicts.Add(conflictedAppointment);
                isLocationConflict = true;
            }
        }
    }
    if(isLocationConflict) {
        scheduler.JSProperties["cpCallbackError"] = "There are lessons with the same time in the same class";
    }
}
See Also