corelibraries-devexpress-dot-xtrascheduler-dot-appointmentconflicteventargs-cff45153.md
Gets the collection of appointments which are considered to be conflicting with the current appointment.
Namespace : DevExpress.XtraScheduler
Assembly : DevExpress.XtraScheduler.v25.2.Core.Desktop.dll
NuGet Package : DevExpress.Scheduler.CoreDesktop
public AppointmentBaseCollection Conflicts { get; }
Public ReadOnly Property Conflicts As AppointmentBaseCollection
| Type | Description |
|---|---|
| AppointmentBaseCollection |
An AppointmentBaseCollection object which contains all appointments which are in conflict with the current one.
|
The Conflicts property contains all appointments which are considered to be conflicting with the current appointment (the appointment for which this event was raised) by the XtraScheduler. The current appointment can be accessed via the AppointmentEventArgs.Appointment property.
Note
If the Conflicts collection is empty after the SchedulerControl.AllowAppointmentConflicts event has occurred, this will indicate that there are no conflicts. If there is at least one item in the Conflicts collection, it is considered that there is a conflict, and in this case the operation can not be performed by an end-user.
This example demonstrates how to manually determine whether there are appointment conflicts or not in some particular situations. If you’re not satisfied with the automatic conflicts determination of the XtraScheduler (when appointments are considered to conflict if they have the same resource and their time intervals intersect), you can set the SchedulerOptionsCustomization.AllowAppointmentConflicts property to Custom and handle the SchedulerControl.AllowAppointmentConflicts event to perform your own conflict determination.
In the following example it’s assumed that an appointment is a lecture conducted by a teacher in a classroom, and several groups of students may be present at the same lecture at the same time. Two appointments are consider to be in conflict in the following situations.
Two different lecturers are scheduled to conduct a lecture at the same time in the same room.
The same lecturer is scheduled to conduct different lectures at the same time in different rooms.
The same group is scheduled at the same time in different rooms.
using DevExpress.XtraScheduler;
// ...
// Appointment = Lecture
// Resource = Room
// appointment.CustomFields["Teacher"] = Teacher
// appointment.CustomFields["Group"] = Group of Students
// Start of the AllowAppointmentConflicts event handler.
// ==================================================
private void schedulerControl1_AllowAppointmentConflicts(object sender,
AppointmentConflictEventArgs e) {
Appointment currentLecture = e.Appointment;
object roomId = currentLecture.ResourceId;
string teacher = GetTeacher(currentLecture);
string group = GetGroup(currentLecture);
DateTime start = currentLecture.Start;
TimeSpan duration = currentLecture.Duration;
// e.Conflicts contains all the lectures held at the same time.
// All of them the SchedulerControl considers to be conflicting.
AppointmentBaseCollection lecturesInTheSameTime = e.Conflicts;
AppointmentBaseCollection conflictedLectures = new AppointmentBaseCollection();
AppointmentBaseCollection lecturesInDifferentRoomWithDifferentTeacher =
new AppointmentBaseCollection();
ArrayList groupsInDifferentRoomWithDifferentTeacher = new ArrayList();
ArrayList groups = new ArrayList();
int count = lecturesInTheSameTime.Count;
for (int i = 0; i < count; i++) {
Appointment lecture = lecturesInTheSameTime[i];
// Check if the lecture is in the same room.
if (Object.Equals(lecture.ResourceId, roomId)) {
// Check if the lecture is by the same teacher.
if (String.Compare(teacher, GetTeacher(lecture), true) == 0) {
if (lecture.Start != start || lecture.Duration != duration) {
// Conflict! Lecture with a bad time frame.
conflictedLectures.Add(lecture);
}
else {
// No conflict!
groups.Add(GetGroup(lecture));
}
}
// Lecture by a different teacher.
else {
// Conflict! Lecture by a different teacher in the same room.
conflictedLectures.Add(lecture);
}
}
// Lecture in a different room.
else {
// Lecture by the same teacher.
if (String.Compare(teacher, GetTeacher(lecture), true) == 0) {
// Conflict! Lecture of the same teacher in the different room.
conflictedLectures.Add(lecture);
}
// Lecture by a different teacher.
else {
// No conflict! Lecture by a different teacher in a different room.
groupsInDifferentRoomWithDifferentTeacher.Add(GetGroup(lecture));
lecturesInDifferentRoomWithDifferentTeacher.Add(lecture);
}
}
}
// Search for the groups which should be in different rooms at the same time.
count = groups.Count;
for (int i = 0; i < count; i++) {
int conflictIndex = groupsInDifferentRoomWithDifferentTeacher.IndexOf(groups[i]);
if (conflictIndex >= 0)
conflictedLectures.Add(lecturesInDifferentRoomWithDifferentTeacher[conflictIndex]);
}
e.Conflicts.Clear();
// If the conflictedLectures will contain no lectures after this event has occured,
// then e.Conflicts will be empty and this will indicate that there are no conflicts.
e.Conflicts.AddRange(conflictedLectures);
}
// End of the AllowAppointmentConflicts event handler.
// ==================================================
// Additional functions.
// ====================
// Determines the teacher for the specified lecture.
string GetTeacher(Appointment lecture) {
object teacher = lecture.CustomFields["Teacher"];
if (teacher == null)
return String.Empty;
return teacher.ToString();
}
// Determines the group for the specified lecture.
string GetGroup(Appointment lecture) {
object group = lecture.CustomFields["Group"];
if (group == null)
return String.Empty;
return group.ToString();
}
Imports DevExpress.XtraScheduler
' ...
' Appointment = Lecture
' Resource = Room
' appointment.CustomFields["Teacher"] = Teacher
' appointment.CustomFields["Group"] = Group of Students
' Start of the AllowAppointmentConflicts event handler.
' ==================================================
Private Sub OnAllowAppointmentConflicts(sender As Object, e As AppointmentConflictEventArgs) _
Handles SchedulerControl1.AllowAppointmentConflicts
Dim currentLecture As Appointment = e.Appointment
Dim roomId As Object = currentLecture.ResourceId
Dim teacher As String = GetTeacher(currentLecture)
Dim group As String = GetGroup(currentLecture)
Dim start As DateTime = currentLecture.Start
Dim duration As TimeSpan = currentLecture.Duration
' e.Conflicts contains all the lectures held at the same time.
' All of them the SchedulerControl considers to be conflicting.
Dim lecturesInTheSameTime As AppointmentBaseCollection = e.Conflicts
Dim conflictedLectures As New AppointmentBaseCollection()
Dim lecturesInDifferentRoomWithDifferentTeacher As New AppointmentBaseCollection()
Dim groupsInDifferentRoomWithDifferentTeacher As New ArrayList()
Dim groups As New ArrayList()
Dim count As Integer = lecturesInTheSameTime.Count
Dim i As Integer
For i = 0 To count - 1
Dim lecture As Appointment = lecturesInTheSameTime(i)
' Check if the lecture is in the same room.
If Object.Equals(lecture.ResourceId, roomId) Then
' Check if the lecture is by the same teacher.
If String.Compare(teacher, GetTeacher(lecture), True) = 0 Then
If (lecture.Start <> start) Or (lecture.End <> start.AddTicks(duration.Ticks)) Then
' Conflict! Lecture with a bad time frame.
conflictedLectures.Add(lecture)
Else
' No conflict!
groups.Add(GetGroup(lecture))
End If
' Lecture by a different teacher.
Else
' Conflict! Lecture by a different teacher in the same room.
conflictedLectures.Add(lecture)
End If
' Lecture in a different room.
Else
' Lecture by the same teacher.
If String.Compare(teacher, GetTeacher(lecture), True) = 0 Then
' Conflict! Lecture of the same teacher in the different room.
conflictedLectures.Add(lecture)
' Lecture by a different teacher.
Else
' No conflict! Lecture by different teacher in a different room.
groupsInDifferentRoomWithDifferentTeacher.Add(GetGroup(lecture))
lecturesInDifferentRoomWithDifferentTeacher.Add(lecture)
End If
End If
Next i
' Search for the groups which should be in different rooms at the same time.
count = groups.Count
For i = 0 To count - 1
Dim conflictIndex As Integer = groupsInDifferentRoomWithDifferentTeacher.IndexOf(groups(i))
If conflictIndex >= 0 Then
conflictedLectures.Add(lecturesInDifferentRoomWithDifferentTeacher(conflictIndex))
End If
Next i
e.Conflicts.Clear()
' If the conflictedLectures will contain no lectures after this event occured, then e.Conflicts
' will be empty and this will indicate that there are no conflicts.
e.Conflicts.AddRange(conflictedLectures)
End Sub
' End of the AllowAppointmentConflicts event handler.
' ==================================================
' Additional functions.
' --------------------
' Determines the teacher for the specified lecture.
Function GetTeacher(lecture As Appointment) As String
Dim teacher As Object = lecture.CustomFields("Teacher")
If teacher Is Nothing Then
Return String.Empty
End If
Return teacher.ToString()
End Function
' Determines the group for the specified lecture.
Function GetGroup(lecture As Appointment) As String
Dim group As Object = lecture.CustomFields("Group")
If group Is Nothing Then
Return String.Empty
End If
Return group.ToString()
End Function
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Conflicts 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-resolve-appointment-conflicts/CS/DXApplication1/Form1.cs#L86
e.Conflicts.Clear();
FillConflictedAppointmentsCollection(e.Conflicts, e.Interval, ((SchedulerControl)sender).DataStorage.Appointments.Items, e.AppointmentClone);
}
winforms-scheduler-resolve-appointment-conflicts/VB/DXApplication1/Form1.vb#L77
e.Conflicts.Clear()
FillConflictedAppointmentsCollection(e.Conflicts, e.Interval, CType(sender, SchedulerControl).DataStorage.Appointments.Items, e.AppointmentClone)
End Sub
See Also
AppointmentConflictEventArgs Class