Skip to main content

AppointmentConflictEventArgs.Conflicts Property

Gets the collection of appointments which are considered to be conflicting with the current appointment.

Namespace: DevExpress.XtraScheduler

Assembly: DevExpress.XtraScheduler.v24.1.Core.Desktop.dll

NuGet Package: DevExpress.Scheduler.CoreDesktop

Declaration

public AppointmentBaseCollection Conflicts { get; }

Property Value

Type Description
AppointmentBaseCollection

An AppointmentBaseCollection object which contains all appointments which are in conflict with the current one.

Remarks

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.

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 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();
}

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.

See Also