This repository has been archived by the owner on Oct 16, 2023. It is now read-only.
/
SchedulerViewModel.cs
101 lines (82 loc) · 3.76 KB
/
SchedulerViewModel.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Windows;
using System.Windows.Input;
using DevExpress.Xpf.Core.Commands;
using System.Collections.ObjectModel;
namespace SchedulerBindToObservableCollectionWpf {
public class SchedulerViewModel {
public ObservableCollection<ModelAppointment> Appointments { get; private set; }
public ObservableCollection<ModelResource> Resources { get; private set; }
public ICommand AddNewAppointmentCommand { get; private set; }
public ICommand GetSourceObjectCommand { get; private set; }
public SchedulerViewModel() {
Appointments = new ObservableCollection<ModelAppointment>();
Resources = new ObservableCollection<ModelResource>();
AddNewAppointmentCommand = new DevExpress.Xpf.Mvvm.DelegateCommand<object>(AddNewAppointmentCommandExecute);
GetSourceObjectCommand = new DevExpress.Xpf.Mvvm.DelegateCommand<object>(GetSourceObjectCommandExecute);
AddTestData();
}
private void AddNewAppointmentCommandExecute(object parameter) {
DateTime baseTime = DateTime.Today;
ModelAppointment apt = new ModelAppointment() {
StartTime = baseTime.AddHours(3),
EndTime = baseTime.AddHours(4),
Subject = "Test3",
Location = "Office",
Description = "Test procedure",
Price = 20m
};
Appointments.Add(apt);
}
private void GetSourceObjectCommandExecute(object parameter) {
DevExpress.Xpf.Scheduler.SchedulerStorage storage = (DevExpress.Xpf.Scheduler.SchedulerStorage)parameter;
if (storage.AppointmentStorage.Count > 0) {
ModelAppointment apt = (ModelAppointment)storage.AppointmentStorage[0].GetSourceObject(storage.GetCoreStorage());
// Alternative: ModelAppointment apt = (ModelAppointment)storage.GetObjectRow(storage.AppointmentStorage[0]);
MessageBox.Show("First Appointment Price: " + apt.Price.ToString());
}
}
private void AddTestData() {
ModelResource res1 = new ModelResource() {
Id = 0,
Name = "Computer1",
Color = ToRgb(System.Drawing.Color.Yellow)
};
ModelResource res2 = new ModelResource() {
Id = 1,
Name = "Computer2",
Color = ToRgb(System.Drawing.Color.Green)
};
ModelResource res3 = new ModelResource() {
Id = 2,
Name = "Computer3",
Color = ToRgb(System.Drawing.Color.Blue)
};
Resources.Add(res1);
Resources.Add(res2);
Resources.Add(res3);
DateTime baseTime = DateTime.Today;
ModelAppointment apt1 = new ModelAppointment() {
StartTime = baseTime.AddHours(1),
EndTime = baseTime.AddHours(2),
Subject = "Test",
Location = "Office",
Description = "Test procedure",
Price = 10m
};
ModelAppointment apt2 = new ModelAppointment() {
StartTime = baseTime.AddHours(2),
EndTime = baseTime.AddHours(3),
Subject = "Test2",
Location = "Office",
Description = "Test procedure",
ResourceId = "<ResourceIds>\r\n<ResourceId Type=\"System.Int32\" Value=\"0\" />\r\n<ResourceId Type=\"System.Int32\" Value=\"1\" />\r\n</ResourceIds>"
};
Appointments.Add(apt1);
Appointments.Add(apt2);
}
private int ToRgb(System.Drawing.Color color) {
return color.B << 16 | color.G << 8 | color.R;
}
}
}