SchedulerOptionsCustomization.AllowAppointmentConflicts Property

Gets or sets whether a user is allowed to share the schedule time between two or more appointments.

Namespace: DevExpress.XtraScheduler

Assembly: DevExpress.XtraScheduler.v19.2.Core.dll

Declaration

[DefaultValue(AppointmentConflictsMode.Allowed)]
public AppointmentConflictsMode AllowAppointmentConflicts { get; set; }
<DefaultValue(AppointmentConflictsMode.Allowed)>
Public Property AllowAppointmentConflicts As AppointmentConflictsMode

Property Value

Type Default Description
AppointmentConflictsMode

Allowed

An AppointmentConflictsMode enumeration value specifying whether the time interval of two or more appointments can intersect or not, if these appointments belong to the same resource(s).

Remarks

By default, end users can share the schedule time between two or more appointments. Use the AllowAppointmentConflicts property to control the availability of such functionality to end-users.

If this property is set to AppointmentConflictsMode.Allowed, the time interval of two or more appointments can intersect and sharing the schedule time between the appointments is allowed. Set the AllowAppointmentConflicts property to AppointmentConflictsMode.Forbidden to prevent scheduling (or rescheduling) of two or more appointments for the same time.

NOTE

If the AllowAppointmentConflicts property is set to AppointmentConflictsMode.Custom, then whether an end-user is allowed to share the schedule time between two or more appointments or not is decided in the SchedulerControl.AllowAppointmentConflicts event handler.

Change the Conflict Message

When a conflict occurs, the Scheduler shows a message box that notifies users about this conflict. The code below illustrates how to change this message box text.


public Form1() {
    InitializeComponent();
    SchedulerResLocalizer.Active = new CustomSchedulerResLocalizer();
}

public class CustomSchedulerResLocalizer : SchedulerResLocalizer {
    public override string GetLocalizedString(SchedulerStringId id) {
        if(id == SchedulerStringId.Msg_Conflict)
            return "_YOUR_CUSTOM_MESSAGE_TEXT_";
        else 
            return base.GetLocalizedString(id);
    }    
}

Example

The following code snippet illustrates handling of the SchedulerControl.AllowAppointmentConflicts event for conflict resolution. When an appointment is modified or created, and the SchedulerOptionsCustomization.AllowAppointmentConflicts property is set to AppointmentConflictsMode.Custom, the AllowAppointmentConflicts event occurs. The code in the event handler checks whether the time interval of the modified appointment intersects with other appointments, including recurrent series and exceptions. If such an appointment is found, it is added to the AppointmentConflictEventArgs.Conflicts collection. If the collection has at least one element, a conflict occurs and the Scheduler cancels changes.

    // Concurrent appointments with the same resource are not allowed.
    scheduler.OptionsCustomization.AllowAppointmentConflicts = AppointmentConflictsMode.Custom;
    scheduler.AllowAppointmentConflicts += Scheduler_AllowAppointmentConflicts;

    scheduler.Storage.Appointments.Clear();
    scheduler.GroupType = SchedulerGroupType.Resource;
    Appointment apt1 = scheduler.Storage.Appointments.CreateAppointment(AppointmentType.Normal, DateTime.Now, DateTime.Now.AddHours(2));
    apt1.ResourceId = scheduler.Storage.Resources[0].Id;
    scheduler.Storage.Appointments.Add(apt1);
    Appointment apt2 = scheduler.Storage.Appointments.CreateAppointment(AppointmentType.Normal, DateTime.Now, DateTime.Now.AddHours(2));
    apt2.ResourceId = scheduler.Storage.Resources[1].Id;
    scheduler.Storage.Appointments.Add(apt2);
static void Scheduler_AllowAppointmentConflicts(object sender, AppointmentConflictEventArgs e) {
    e.Conflicts.Clear();
    FillConflictedAppointmentsCollection(e.Conflicts, e.Interval, ((SchedulerControl)sender).Storage.Appointments.Items, e.AppointmentClone);
}
static void FillConflictedAppointmentsCollection(AppointmentBaseCollection conflicts, TimeInterval interval,
    AppointmentBaseCollection collection, Appointment currApt) {
    for (int i = 0; i < collection.Count; i++) {
        Appointment apt = collection[i];
        if (new TimeInterval(apt.Start, apt.End).IntersectsWith(interval) & !(apt.Start == interval.End || apt.End == interval.Start)) {
            if (apt.ResourceId == currApt.ResourceId) {
                conflicts.Add(apt);
            }
        }
        if (apt.Type == AppointmentType.Pattern) {
            FillConflictedAppointmentsCollection(conflicts, interval, apt.GetExceptions(), currApt);
        }
    }
}
See Also