The DevExpress.XtraScheduler.SchedulerControl.AllowAppointmentConflicts event occurs when the scheduler finds appointments that are in conflict and the SchedulerOptionsCustomization.AllowAppointmentConflicts property is set to Custom. The AppointmentConflictEventArgs class introduces the Conflicts property which returns the collection of appointments that are considered to be in conflict with the current appointment, and the Interval property that specifies the time interval of the appointment. The processed appointment is identified by the AppointmentEventArgs.Appointment property.
An instance of the AppointmentConflictEventArgs class with appropriate settings is automatically created and passed to the corresponding event's handler.

Example
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 DevExpress.XtraScheduler.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.
C# |
using DevExpress.XtraScheduler;
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;
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];
if (Object.Equals(lecture.ResourceId, roomId)) {
if (String.Compare(teacher, GetTeacher(lecture), true) == 0) {
if (lecture.Start != start || lecture.Duration != duration) {
conflictedLectures.Add(lecture);
}
else {
groups.Add(GetGroup(lecture));
}
}
else {
conflictedLectures.Add(lecture);
}
}
else {
if (String.Compare(teacher, GetTeacher(lecture), true) == 0) {
conflictedLectures.Add(lecture);
}
else {
groupsInDifferentRoomWithDifferentTeacher.Add(GetGroup(lecture));
lecturesInDifferentRoomWithDifferentTeacher.Add(lecture);
}
}
}
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();
e.Conflicts.AddRange(conflictedLectures);
}
string GetTeacher(Appointment lecture) {
object teacher = lecture.CustomFields["Teacher"];
if (teacher == null)
return String.Empty;
return teacher.ToString();
}
string GetGroup(Appointment lecture) {
object group = lecture.CustomFields["Group"];
if (group == null)
return String.Empty;
return group.ToString();
}
|
VB |
Imports DevExpress.XtraScheduler
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
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)
If Object.Equals(lecture.ResourceId, roomId) Then
If String.Compare(teacher, GetTeacher(lecture), True) = 0 Then
If (lecture.Start <> start) Or (lecture.End <> start.AddTicks(duration.Ticks)) Then
conflictedLectures.Add(lecture)
Else
groups.Add(GetGroup(lecture))
End If
Else
conflictedLectures.Add(lecture)
End If
Else
If String.Compare(teacher, GetTeacher(lecture), True) = 0 Then
conflictedLectures.Add(lecture)
Else
groupsInDifferentRoomWithDifferentTeacher.Add(GetGroup(lecture))
lecturesInDifferentRoomWithDifferentTeacher.Add(lecture)
End If
End If
Next i
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()
e.Conflicts.AddRange(conflictedLectures)
End Sub
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
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
|
System.Object
System.EventArgs
AppointmentEventArgs
AppointmentConflictEventArgs