-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataHelper.cs
77 lines (63 loc) · 3.28 KB
/
DataHelper.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
using DevExpress.XtraScheduler;
using System;
using System.Collections.Generic;
using System.Drawing;
namespace CustomAppointmentFlyoutExample {
static class DataHelper {
public static Random RandomInstance = new Random();
public static List<CustomResourceSourceObject> CustomResourceCollection = new List<CustomResourceSourceObject>();
public static List<CustomAppointmentSourceObject> CustomEventList = new List<CustomAppointmentSourceObject>();
public static void InitResources(SchedulerStorage storage) {
ResourceMappingInfo mappings = storage.Resources.Mappings;
mappings.Id = "ResID";
mappings.Caption = "Name";
CustomResourceCollection.Add(CreateCustomResource(1, "Max Fowler", Color.PowderBlue));
CustomResourceCollection.Add(CreateCustomResource(2, "Nancy Drewmore", Color.PaleVioletRed));
CustomResourceCollection.Add(CreateCustomResource(3, "Pak Jang", Color.PeachPuff));
storage.Resources.DataSource = CustomResourceCollection;
}
public static CustomResourceSourceObject CreateCustomResource(int res_id, string caption, Color ResColor) {
CustomResourceSourceObject cr = new CustomResourceSourceObject();
cr.ResID = res_id;
cr.Name = caption;
return cr;
}
public static void InitAppointments(SchedulerStorage storage) {
AppointmentMappingInfo mappings = storage.Appointments.Mappings;
mappings.Start = "StartTime";
mappings.End = "EndTime";
mappings.Subject = "Subject";
mappings.AllDay = "AllDay";
mappings.Description = "Description";
mappings.Label = "Label";
mappings.Location = "Location";
mappings.RecurrenceInfo = "RecurrenceInfo";
mappings.ReminderInfo = "ReminderInfo";
mappings.ResourceId = "OwnerId";
mappings.Status = "Status";
mappings.Type = "EventType";
GenerateEvents(CustomEventList, storage);
storage.Appointments.DataSource = CustomEventList;
}
public static void GenerateEvents(List<CustomAppointmentSourceObject> eventList, SchedulerStorage storage) {
int count = storage.Resources.Count;
for (int i = 0; i < count; i++) {
Resource resource = storage.Resources[i];
string subjPrefix = resource.Caption + "'s ";
eventList.Add(CreateEvent(subjPrefix + "meeting", resource.Id, 2, 5, 14));
eventList.Add(CreateEvent(subjPrefix + "travel", resource.Id, 3, 6, 10));
eventList.Add(CreateEvent(subjPrefix + "talk", resource.Id, 0, 4, 16));
}
}
public static CustomAppointmentSourceObject CreateEvent(string subject, object resourceId, int status, int label, int sHour) {
CustomAppointmentSourceObject apt = new CustomAppointmentSourceObject();
apt.Subject = subject;
apt.OwnerId = resourceId;
apt.StartTime = DateTime.Today.AddHours(RandomInstance.Next(12));
apt.EndTime = apt.StartTime.AddHours(RandomInstance.Next(4) + 1);
apt.Status = status;
apt.Label = label;
return apt;
}
}
}