Skip to main content
A newer version of this page is available. .

AppointmentConflictsCalculator.CalculateConflicts(Appointment, TimeInterval) Method

Returns a collection of appointments that conflict with the specified one, within the time interval.

Namespace: DevExpress.XtraScheduler.Native

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

Declaration

public virtual AppointmentBaseCollection CalculateConflicts(
    Appointment appointment,
    TimeInterval interval
)

Parameters

Name Type Description
appointment Appointment

An Appointment object to be checked for conflicts with appointments in the AppointmentConflictsCalculator collection.

interval TimeInterval

A TimeInterval object, representing the time span for which the check is performed.

Returns

Type Description
AppointmentBaseCollection

An AppointmentBaseCollection object, which contains conflicting appointments.

Remarks

Use this method to check whether the newly created or updated appointment conflicts with existing appointments. It is extremely helpful for appointments created or modified via code at run-time.

The technique used to calculate the conflicting appointments is described below.

Each appointment from a collection contained within the AppointmentConflictsCalculator class is examined according to the following rules:

  1. Appointments of the AppointmentType.Normal type with spans outside the specified time interval, do not conflict.
  2. Appointments associated with different resources do not conflict.
  3. For an appointment of the AppointmentType.Pattern type, we have to inspect its chain of occurrences. Two patterns with RecurrenceRange.NoEndDate recurrence ranges are presumed not to be in conflict.
  4. The OccurrenceCalculator methods are used to get information on occurrences and exceptions. These items are checked for conflict with the appointment in question.

Example

The following code snippet is the SchedulerControl.CustomDrawAppointmentBackground event handler. It uses the AppointmentConflictsCalculator.CalculateConflicts method to determine whether a current appointment (whose background is being painted) conflicts with another appointment(s). A conflict means that appointments share a time interval and/or resource. Conflicting appointments are painted with a red-white hatched brush.

AppointmentConflictsCalculator

private static void scheduler_CustomDrawAppointmentBackground(object sender, CustomDrawObjectEventArgs e)
{
    SchedulerControl scheduler = sender as SchedulerControl;
    AppointmentViewInfo viewInfo = (e.ObjectInfo as DevExpress.XtraScheduler.Drawing.AppointmentViewInfo);
    Appointment apt = viewInfo.Appointment;
    AppointmentBaseCollection allAppointments = scheduler.ActiveView.GetAppointments();
    AppointmentConflictsCalculator aCalculator = new AppointmentConflictsCalculator(allAppointments);
    TimeInterval visibleInterval = scheduler.ActiveView.GetVisibleIntervals().Interval;
    bool isConflict = aCalculator.CalculateConflicts(apt, visibleInterval).Count != 0;
    // Paint conflict appointments with a red and white hatch brush.
    if (isConflict)
    {
        Rectangle rect = e.Bounds;
        Brush brush = e.Cache.GetSolidBrush(scheduler.Storage.Appointments.Labels.GetById(apt.LabelKey).GetColor());
        e.Graphics.FillRectangle(brush, rect);
        rect.Inflate(-3, -3);
        HatchBrush hatchBrush = new HatchBrush(HatchStyle.WideUpwardDiagonal, Color.Red, Color.White);
        e.Graphics.FillRectangle(hatchBrush, rect);
        e.Handled = true;
    }
}
See Also