corelibraries-devexpress-dot-xtrascheduler-dot-native-dot-appointmentconflictscalculator-dot-calculateconflicts-x28-devexpress-dot-xtrascheduler-dot-appointment-devexpress-dot-xtrascheduler-dot-timeinterval-x29.md
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
public virtual AppointmentBaseCollection CalculateConflicts(
Appointment appointment,
TimeInterval interval
)
Public Overridable Function CalculateConflicts(
appointment As Appointment,
interval As TimeInterval
) As AppointmentBaseCollection
| 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.
|
| Type | Description |
|---|---|
| AppointmentBaseCollection |
An AppointmentBaseCollection object, which contains conflicting appointments.
|
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:
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.
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;
}
}
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