This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
CustomAppointmentEditForm.cs
210 lines (181 loc) · 7.38 KB
/
CustomAppointmentEditForm.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
using System;
using System.Windows.Forms;
using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.UI;
using DevExpress.XtraScheduler.Native;
// ...
namespace iCalendarDemo {
public partial class CustomAppointmentEditForm : DevExpress.XtraEditors.XtraForm {
SchedulerControl control;
Appointment apt;
int suspendUpdateCount;
private DevExpress.XtraEditors.CheckEdit checkAllDay;
// Note that the MyAppointmentFormController class is inherited from
// the AppointmentFormController one to add custom properties.
// See its declaration at the end of this file.
MyAppointmentFormController controller;
public CustomAppointmentEditForm(SchedulerControl control, Appointment apt) {
this.controller = new MyAppointmentFormController(control, apt);
this.apt = apt;
this.control = control;
//
// Required for Windows Form Designer support
//
SuspendUpdate();
InitializeComponent();
ResumeUpdate();
UpdateForm();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
protected IAppointmentStorage Appointments { get { return control.Storage.Appointments; } }
protected internal bool IsNewAppointment { get { return controller != null ? controller.IsNewAppointment : true; } }
protected bool IsUpdateSuspended { get { return suspendUpdateCount > 0; } }
protected void SuspendUpdate() {
suspendUpdateCount++;
}
protected void ResumeUpdate() {
if (suspendUpdateCount > 0)
suspendUpdateCount--;
}
private void btnOK_Click(object sender, System.EventArgs e) {
// Required to check appointment's conflicts.
if (!controller.IsConflictResolved())
return;
controller.Subject = txSubject.Text;
controller.SetLabel(edtLabel.AppointmentLabel);
controller.AllDay = this.checkAllDay.Checked;
controller.Start = this.dtStart.DateTime.Date + this.timeStart.Time.TimeOfDay;
controller.End = this.dtEnd.DateTime.Date + this.timeEnd.Time.TimeOfDay;
controller.Attendees = txAttendees.Text;
// Save all changes made to the appointment edited in a form.
controller.ApplyChanges();
}
void UpdateForm() {
SuspendUpdate();
try {
txSubject.Text = controller.Subject;
tbLocation.Text = controller.Location;
tbDescription.Text = controller.Description;
edtLabel.AppointmentLabel = Appointments.Labels.GetById(controller.LabelKey);
dtStart.DateTime = controller.Start.Date;
dtEnd.DateTime = controller.End.Date;
timeStart.Time = DateTime.MinValue.AddTicks(controller.Start.TimeOfDay.Ticks);
timeEnd.Time = DateTime.MinValue.AddTicks(controller.End.TimeOfDay.Ticks);
checkAllDay.Checked = controller.AllDay;
edtLabel.Storage = control.Storage;
txAttendees.Text = controller.Attendees;
bool remindersEnabled = control.RemindersEnabled;
chkReminder.Enabled = remindersEnabled;
chkReminder.Visible = remindersEnabled;
chkReminder.Checked = controller.HasReminder;
UpdateReminderCombo();
UpdateFormCaption();
}
finally {
ResumeUpdate();
}
UpdateIntervalControls();
}
protected internal virtual void UpdateFormCaption() {
this.Text = SchedulerUtils.FormatAppointmentFormCaption(controller.AllDay, controller.Subject, false);
}
protected internal virtual void UpdateReminderCombo() {
if (controller.HasReminder)
cbReminder.Duration = controller.ReminderTimeBeforeStart;
else
cbReminder.Text = String.Empty;
bool remindersEnabled = control.RemindersEnabled;
cbReminder.Enabled = remindersEnabled && controller.HasReminder;
cbReminder.Visible = remindersEnabled;
}
private void dtStart_EditValueChanged(object sender, System.EventArgs e) {
if (!IsUpdateSuspended)
controller.Start = dtStart.DateTime.Date + timeStart.Time.TimeOfDay;
UpdateIntervalControls();
}
protected virtual void UpdateIntervalControls() {
if (IsUpdateSuspended)
return;
SuspendUpdate();
try {
dtStart.EditValue = controller.Start.Date;
dtEnd.EditValue = controller.End.Date;
timeStart.EditValue = controller.Start.TimeOfDay;
timeEnd.EditValue = controller.End.TimeOfDay;
Appointment editedAptCopy = controller.EditedAppointmentCopy;
bool showControls = IsNewAppointment || editedAptCopy.Type != AppointmentType.Pattern;
dtStart.Enabled = showControls;
dtEnd.Enabled = showControls;
bool enableTime = showControls && !controller.AllDay;
timeStart.Visible = enableTime;
timeStart.Enabled = enableTime;
timeEnd.Visible = enableTime;
timeEnd.Enabled = enableTime;
checkAllDay.Enabled = showControls;
}
finally {
ResumeUpdate();
}
}
private void timeStart_EditValueChanged(object sender, System.EventArgs e) {
if (!IsUpdateSuspended)
controller.Start = dtStart.DateTime.Date + timeStart.Time.TimeOfDay;
UpdateIntervalControls();
}
private void timeEnd_EditValueChanged(object sender, System.EventArgs e) {
if (IsUpdateSuspended) return;
if (IsIntervalValid())
controller.End = dtEnd.DateTime + timeEnd.Time.TimeOfDay;
else
timeEnd.EditValue = controller.End.TimeOfDay;
}
private void dtEnd_EditValueChanged(object sender, System.EventArgs e) {
if (IsUpdateSuspended) return;
if (IsIntervalValid())
controller.End = dtEnd.DateTime + timeEnd.Time.TimeOfDay;
else
dtEnd.EditValue = controller.End.Date;
}
bool IsIntervalValid() {
DateTime start = dtStart.DateTime + timeStart.Time.TimeOfDay;
DateTime end = dtEnd.DateTime + timeEnd.Time.TimeOfDay;
return end >= start;
}
private void checkAllDay_CheckedChanged(object sender, System.EventArgs e) {
controller.AllDay = this.checkAllDay.Checked;
UpdateIntervalControls();
}
private void tbDescription_EditValueChanged(object sender, EventArgs e) {
if (IsUpdateSuspended) return;
controller.Description = tbDescription.Text;
}
private void tbLocation_EditValueChanged(object sender, EventArgs e) {
if (IsUpdateSuspended) return;
controller.Location = tbLocation.Text;
}
private void txAttendees_EditValueChanged(object sender, EventArgs e) {
controller.Attendees = txAttendees.Text;
}
private void chkReminder_CheckedChanged(object sender, EventArgs e) {
controller.HasReminder = chkReminder.Checked;
UpdateReminderCombo();
}
}
public class MyAppointmentFormController : AppointmentFormController {
public string Attendees { get { return Convert.ToString(EditedAppointmentCopy.CustomFields["RecipientsData"]); } set { EditedAppointmentCopy.CustomFields["RecipientsData"] = value; } }
string SourceAttendees { get { return Convert.ToString(SourceAppointment.CustomFields["RecipientsData"]); } set { SourceAppointment.CustomFields["RecipientsData"] = value; } }
public MyAppointmentFormController(SchedulerControl control, Appointment apt)
: base(control, apt) {
}
public override bool IsAppointmentChanged() {
if (base.IsAppointmentChanged())
return true;
return SourceAttendees != Attendees;
}
protected override void ApplyCustomFieldsValues() {
SourceAttendees = Attendees;
}
}
}