This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
AppointmentConflicts.cs
82 lines (78 loc) · 4.26 KB
/
AppointmentConflicts.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.Drawing;
using DevExpress.XtraScheduler.Native;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
namespace SchedulerAPISample.CodeExamples
{
class AppointmentConflicts
{
static void AllowAppointmentConflictsEvent(SchedulerControl scheduler) {
#region #AllowAppointmentConflictsEvent
// Concurrent appointments with the same resource are not allowed.
scheduler.OptionsCustomization.AllowAppointmentConflicts = AppointmentConflictsMode.Custom;
scheduler.AllowAppointmentConflicts += Scheduler_AllowAppointmentConflicts;
scheduler.Storage.Appointments.Clear();
scheduler.GroupType = SchedulerGroupType.Resource;
Appointment apt1 = scheduler.Storage.Appointments.CreateAppointment(AppointmentType.Normal, DateTime.Now, DateTime.Now.AddHours(2));
apt1.ResourceId = scheduler.Storage.Resources[0].Id;
scheduler.Storage.Appointments.Add(apt1);
Appointment apt2 = scheduler.Storage.Appointments.CreateAppointment(AppointmentType.Normal, DateTime.Now, DateTime.Now.AddHours(2));
apt2.ResourceId = scheduler.Storage.Resources[1].Id;
scheduler.Storage.Appointments.Add(apt2);
#endregion #AllowAppointmentConflictsEvent
}
#region #@AllowAppointmentConflictsEvent
static void Scheduler_AllowAppointmentConflicts(object sender, AppointmentConflictEventArgs e) {
e.Conflicts.Clear();
FillConflictedAppointmentsCollection(e.Conflicts, e.Interval, ((SchedulerControl)sender).Storage.Appointments.Items, e.AppointmentClone);
}
static void FillConflictedAppointmentsCollection(AppointmentBaseCollection conflicts, TimeInterval interval,
AppointmentBaseCollection collection, Appointment currApt) {
for (int i = 0; i < collection.Count; i++) {
Appointment apt = collection[i];
if (new TimeInterval(apt.Start, apt.End).IntersectsWith(interval) & !(apt.Start == interval.End || apt.End == interval.Start)) {
if (apt.ResourceId == currApt.ResourceId) {
conflicts.Add(apt);
}
}
if (apt.Type == AppointmentType.Pattern) {
FillConflictedAppointmentsCollection(conflicts, interval, apt.GetExceptions(), currApt);
}
}
}
#endregion #@AllowAppointmentConflictsEvent
static void ConflictCalculator(SchedulerControl scheduler)
{
#region #ConflictCalculator
scheduler.CustomDrawAppointmentBackground += scheduler_CustomDrawAppointmentBackground;
scheduler.ActiveView.LayoutChanged();
#endregion #ConflictCalculator
}
#region #@ConflictCalculator
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;
}
}
#endregion #@ConflictCalculator
}
}