/
Form1.cs
146 lines (128 loc) · 7.01 KB
/
Form1.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
#region #usings
using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.Drawing;
using System.Drawing.Drawing2D;
#endregion #usings
namespace CustomDrawDemo {
public partial class Form1 : Form {
#region InitialDataConstants
public static Random RandomInstance = new Random();
public static string[] Users = new string[] {"Peter Dolan", "Ryan Fischer", "Richard Fisher",
"Tom Hamlett", "Mark Hamilton", "Steve Lee", "Jimmy Lewis", "Jeffrey W McClain",
"Andrew Miller", "Dave Murrel", "Bert Parkins", "Mike Roller", "Ray Shipman",
"Paul Bailey", "Brad Barnes", "Carl Lucas", "Jerry Campbell"};
#endregion
Color[] colorArray = { Color.Red, Color.Green, Color.Blue, Color.Black };
public Form1() {
InitializeComponent();
FillResources(schedulerDataStorage1, 5);
InitAppointments();
schedulerControl1.Start = DateTime.Now;
schedulerControl1.ActiveViewType = SchedulerViewType.Timeline;
schedulerControl1.Appearance.Appointment.ForeColor = Color.Gray;
schedulerControl1.TimelineView.AppointmentDisplayOptions.SnapToCellsMode = AppointmentSnapToCellsMode.Never;
schedulerControl1.TimelineView.AppointmentDisplayOptions.StatusDisplayType = AppointmentStatusDisplayType.Bounds;
schedulerControl1.DayView.AppointmentDisplayOptions.SnapToCellsMode = AppointmentSnapToCellsMode.Never;
schedulerControl1.DayView.AppointmentDisplayOptions.StatusDisplayType = AppointmentStatusDisplayType.Bounds;
schedulerControl1.TimelineView.Scales.Clear();
schedulerControl1.TimelineView.Scales.Add(new TimeScaleDay());
schedulerControl1.TimelineView.Scales.Add(new TimeScaleHour());
schedulerControl1.TimelineView.Scales[1].Width = 100;
TimelineView view = schedulerControl1.ActiveView as TimelineView;
view.AppointmentDisplayOptions.AllowHtmlText = true;
UpdateControls();
}
#region InitialDataLoad
void FillResources(SchedulerDataStorage storage, int count) {
int cnt = Math.Min(count, Users.Length);
for(int i = 1; i <= cnt; i++)
storage.Resources.Items.Add(storage.CreateResource(Guid.NewGuid(), Users[i - 1]));
}
void InitAppointments() {
this.schedulerDataStorage1.Appointments.Mappings.Start = "StartTime";
this.schedulerDataStorage1.Appointments.Mappings.End = "EndTime";
this.schedulerDataStorage1.Appointments.Mappings.Subject = "Subject";
this.schedulerDataStorage1.Appointments.Mappings.AllDay = "AllDay";
this.schedulerDataStorage1.Appointments.Mappings.Description = "Description";
this.schedulerDataStorage1.Appointments.Mappings.Label = "Label";
this.schedulerDataStorage1.Appointments.Mappings.Location = "Location";
this.schedulerDataStorage1.Appointments.Mappings.RecurrenceInfo = "RecurrenceInfo";
this.schedulerDataStorage1.Appointments.Mappings.ReminderInfo = "ReminderInfo";
this.schedulerDataStorage1.Appointments.Mappings.ResourceId = "OwnerId";
this.schedulerDataStorage1.Appointments.Mappings.Status = "Status";
this.schedulerDataStorage1.Appointments.Mappings.Type = "EventType";
CustomEventList eventList = new CustomEventList();
GenerateEvents(eventList);
this.schedulerDataStorage1.Appointments.DataSource = eventList;
}
void GenerateEvents(CustomEventList eventList) {
int count = schedulerDataStorage1.Resources.Count;
for(int i = 0; i < count; i++) {
Resource resource = schedulerDataStorage1.Resources[i];
string subjPrefix = resource.Caption + "'s ";
eventList.Add(CreateEvent(eventList, subjPrefix + "meeting", resource.Id, 1, 5));
eventList.Add(CreateEvent(eventList, subjPrefix + "travel", resource.Id, 4, 6));
eventList.Add(CreateEvent(eventList, subjPrefix + "phone call", resource.Id, 5, 10));
}
}
CustomEvent CreateEvent(CustomEventList eventList, string subject, object resourceId, int status, int label) {
CustomEvent apt = new CustomEvent(eventList);
apt.Subject = subject;
apt.OwnerId = resourceId;
Random rnd = RandomInstance;
int rangeInMinutes = 60 * 24;
apt.StartTime = DateTime.Today + TimeSpan.FromMinutes(rnd.Next(0, rangeInMinutes));
apt.EndTime = apt.StartTime + TimeSpan.FromMinutes(rnd.Next(0, rangeInMinutes / 4));
apt.Status = status;
apt.Label = label;
return apt;
}
#endregion
#region Update Controls
private void UpdateControls() {
cbView.EditValue = schedulerControl1.ActiveViewType;
rgrpGrouping.EditValue = schedulerControl1.GroupType;
}
private void rgrpGrouping_SelectedIndexChanged(object sender, System.EventArgs e) {
schedulerControl1.GroupType = (SchedulerGroupType)rgrpGrouping.EditValue;
}
private void schedulerControl_ActiveViewChanged(object sender, System.EventArgs e) {
cbView.EditValue = schedulerControl1.ActiveViewType;
}
private void cbView_SelectedIndexChanged(object sender, System.EventArgs e) {
schedulerControl1.ActiveViewType = (SchedulerViewType)cbView.EditValue;
}
#endregion
#region #InitAppointmentDisplayText
Random r = new Random();
private void schedulerControl1_InitAppointmentDisplayText(object sender, AppointmentDisplayTextEventArgs e) {
string[] stringArray = e.Text.Split(' ');
StringBuilder builder = new StringBuilder();
foreach(string str in stringArray)
builder.Append(string.Concat("<color=", r.Next(0, 255), ",", r.Next(0, 255), ",", r.Next(0, 255), ">", str, " ", "</color>"));
e.Text = builder.ToString();
}
#endregion #CustomDrawAppointment
#region #CustomDrawAppointmentBackground
private void schedulerControl1_CustomDrawAppointmentBackground(object sender, CustomDrawObjectEventArgs e) {
AppointmentViewInfo aptViewInfo = e.ObjectInfo as AppointmentViewInfo;
if(aptViewInfo == null)
return;
if(aptViewInfo.Selected) {
Rectangle r = e.Bounds;
Brush brRect = aptViewInfo.Status.GetBrush();
e.Cache.FillRectangle(brRect, r);
e.Cache.DrawRectangle(Pens.Blue, r);
e.Handled = true;
}
}
#endregion #CustomDrawAppointmentBackground
}
}