Back to Devexpress

SchedulerOptionsCustomization.AllowAppointmentConflicts Property

corelibraries-devexpress-dot-xtrascheduler-dot-scheduleroptionscustomization.md

latest12.4 KB
Original Source

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.v25.2.Core.Desktop.dll

NuGet Package : DevExpress.Scheduler.CoreDesktop

Declaration

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

Property Value

TypeDefaultDescription
AppointmentConflictsModeAllowed

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).

|

Available values:

NameDescription
Allowed

Appointments conflicts are allowed. This means that appointment intervals can intersect for the same resource (or for at least for one of the resources to which they belong, if resources are shared).

| | Forbidden |

Appointments conflicts are forbidden. This means that appointment intervals can’t intersect each other for the same resource (or for at least for one of the resources to which they belong, if resources are shared).

| | Custom |

Whether the conflicts are resolved or not is determined manually in the corresponding event handler.

|

Property Paths

You can access this nested property as listed below:

LibraryObject TypePath to AllowAppointmentConflicts
WinForms ControlsSchedulerControl

.OptionsCustomization .AllowAppointmentConflicts

| | ASP.NET Bootstrap Controls | BootstrapScheduler |

.OptionsEditing .AllowAppointmentConflicts

| | ASP.NET MVC Extensions | SchedulerSettings |

.OptionsCustomization .AllowAppointmentConflicts

| | ASP.NET Web Forms Controls | ASPxScheduler |

.OptionsCustomization .AllowAppointmentConflicts

|

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.

csharp
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);
    }    
}
vb
Public Sub New()
    InitializeComponent()
    SchedulerResLocalizer.Active = New CustomSchedulerResLocalizer()
 End Sub

Public Class CustomSchedulerResLocalizer
    Inherits SchedulerResLocalizer

    Public Overrides Function GetLocalizedString(ByVal id As SchedulerStringId) As String
        If id Is SchedulerStringId.Msg_Conflict Then
            Return "_YOUR_CUSTOM_MESSAGE_TEXT_"
        Else
            Return MyBase.GetLocalizedString(id)
        End If
    End Function
End Class

Example

This example handles the SchedulerControl.AllowAppointmentConflicts event to prevent movement of an appointment to a range where another appointment exists. The SchedulerOptionsCustomization.AllowAppointmentConflicts property is set to AppointmentConflictsMode.Custom to process appointment conflicts in a custom manner.

The code in the SchedulerControl.AllowAppointmentConflicts 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.

To paint conflicts, the example handles the SchedulerControl.CustomDrawAppointmentBackground event. The AppointmentConflictsCalculator.CalculateConflicts method is called in this event handler to get the current conflicts.

View Example

csharp
schedulerControl1.OptionsCustomization.AllowAppointmentConflicts = AppointmentConflictsMode.Custom;
//...
private void SchedulerControl1_AllowAppointmentConflicts(object sender, AppointmentConflictEventArgs e) {
    e.Conflicts.Clear();
    FillConflictedAppointmentsCollection(e.Conflicts, e.Interval, ((SchedulerControl)sender).DataStorage.Appointments.Items, e.AppointmentClone);
}

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);
        }
    }
}
vb
schedulerControl1.OptionsCustomization.AllowAppointmentConflicts = AppointmentConflictsMode.Custom
'...
Private Sub SchedulerControl1_AllowAppointmentConflicts(ByVal sender As Object, ByVal e As AppointmentConflictEventArgs)
    e.Conflicts.Clear()
    FillConflictedAppointmentsCollection(e.Conflicts, e.Interval, DirectCast(sender, SchedulerControl).DataStorage.Appointments.Items, e.AppointmentClone)
End Sub

Private Sub FillConflictedAppointmentsCollection(ByVal conflicts As AppointmentBaseCollection, ByVal interval As TimeInterval, ByVal collection As AppointmentBaseCollection, ByVal currApt As Appointment)
    For i As Integer = 0 To collection.Count - 1
        Dim apt As Appointment = collection(i)
        If (New TimeInterval(apt.Start, apt.End)).IntersectsWith(interval) And Not (apt.Start = interval.End OrElse apt.End = interval.Start) Then
            If apt.ResourceId = currApt.ResourceId Then
                conflicts.Add(apt)
            End If
        End If
        If apt.Type = AppointmentType.Pattern Then
            FillConflictedAppointmentsCollection(conflicts, interval, apt.GetExceptions(), currApt)
        End If
    Next i
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the AllowAppointmentConflicts property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-scheduler-enforce-task-dependencies-gantt-view/CS/GanttRestrictions/Form1.cs#L27

csharp
this.schedulerControl1.OptionsCustomization.AllowAppointmentConflicts = AppointmentConflictsMode.Custom;
this.schedulerControl1.AllowAppointmentConflicts+=new AppointmentConflictEventHandler(schedulerControl1_AllowAppointmentConflicts);

winforms-scheduler-resolve-appointment-conflicts/CS/DXApplication1/Form1.cs#L45

csharp
schedulerControl1.OptionsCustomization.AllowAppointmentConflicts = AppointmentConflictsMode.Custom;
schedulerControl1.AllowAppointmentConflicts += SchedulerControl1_AllowAppointmentConflicts;

winforms-scheduler-enforce-task-dependencies-gantt-view/VB/GanttRestrictions/Form1.vb#L24

vb
AddHandler appointmentsTableAdapter.Adapter.RowUpdated, New SqlRowUpdatedEventHandler(AddressOf appointmentsTableAdapter_RowUpdated)
schedulerControl1.OptionsCustomization.AllowAppointmentConflicts = AppointmentConflictsMode.Custom
AddHandler schedulerControl1.AllowAppointmentConflicts, New AppointmentConflictEventHandler(AddressOf schedulerControl1_AllowAppointmentConflicts)

winforms-scheduler-resolve-appointment-conflicts/VB/DXApplication1/Form1.vb#L36

vb
schedulerControl1.Start = Date.Now
schedulerControl1.OptionsCustomization.AllowAppointmentConflicts = AppointmentConflictsMode.Custom
AddHandler schedulerControl1.AllowAppointmentConflicts, AddressOf SchedulerControl1_AllowAppointmentConflicts

See Also

How to: Handle Appointment Conflicts

SchedulerOptionsCustomization Class

SchedulerOptionsCustomization Members

DevExpress.XtraScheduler Namespace