Back to Devexpress

AppointmentConflictsCalculator.CalculateConflicts(Appointment, TimeInterval) Method

corelibraries-devexpress-dot-xtrascheduler-dot-native-dot-appointmentconflictscalculator-dot-calculateconflicts-x28-devexpress-dot-xtrascheduler-dot-appointment-devexpress-dot-xtrascheduler-dot-timeinterval-x29.md

latest6.9 KB
Original Source

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

NuGet Package : DevExpress.Scheduler.Core

Declaration

csharp
public virtual AppointmentBaseCollection CalculateConflicts(
    Appointment appointment,
    TimeInterval interval
)
vb
Public Overridable Function CalculateConflicts(
    appointment As Appointment,
    interval As TimeInterval
) As AppointmentBaseCollection

Parameters

NameTypeDescription
appointmentAppointment

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

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

csharp
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.DataStorage.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;
    }
}
vb
Private Shared Sub scheduler_CustomDrawAppointmentBackground(ByVal sender As Object, ByVal e As CustomDrawObjectEventArgs)
    Dim scheduler As SchedulerControl = TryCast(sender, SchedulerControl)
    Dim viewInfo As AppointmentViewInfo = (TryCast(e.ObjectInfo, DevExpress.XtraScheduler.Drawing.AppointmentViewInfo))
    Dim apt As Appointment = viewInfo.Appointment
    Dim allAppointments As AppointmentBaseCollection = scheduler.ActiveView.GetAppointments()
    Dim aCalculator As New AppointmentConflictsCalculator(allAppointments)
    Dim visibleInterval As TimeInterval = scheduler.ActiveView.GetVisibleIntervals().Interval
    Dim isConflict As Boolean = aCalculator.CalculateConflicts(apt, visibleInterval).Count <> 0
    ' Paint conflict appointments with a red and white hatch brush.
    If isConflict Then
        Dim rect As Rectangle = e.Bounds
        Dim brush As Brush = e.Cache.GetSolidBrush(scheduler.DataStorage.Appointments.Labels.GetById(apt.LabelKey).GetColor())
        e.Graphics.FillRectangle(brush, rect)
        rect.Inflate(-3, -3)
        Dim hatchBrush As New HatchBrush(HatchStyle.WideUpwardDiagonal, Color.Red, Color.White)
        e.Graphics.FillRectangle(hatchBrush, rect)
        e.Handled = True
    End If
End Sub

See Also

AppointmentConflictsCalculator Class

AppointmentConflictsCalculator Members

DevExpress.XtraScheduler.Native Namespace