-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMyAppointmentEditForm.cs
278 lines (231 loc) · 10.9 KB
/
MyAppointmentEditForm.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
// Developer Express Code Central Example:
// Printing appointment details using the XtraReports Suite
//
// This example illustrates how you can print the appointment details for the
// appointments currently displayed in the Scheduler by means of the XtraReports
// Suite.
// The key point is to obtain a collection of appointments and assign it to
// the report's DataSource
// (http://documentation.devexpress.com/#XtraReports/DevExpressXtraReportsUIXtraReportBase_DataSourcetopic).
// To accomplish this, the GetAppointments
// (http://documentation.devexpress.com/#WindowsForms/DevExpressXtraSchedulerSchedulerStorageBase_GetAppointmentstopic)
// method is used to get a collection of appointments which fall within the time
// range specified by the GetVisibleIntervals
// (http://documentation.devexpress.com/#WindowsForms/DevExpressXtraSchedulerSchedulerViewBase_GetVisibleIntervalstopic)
// method.
// To display custom fields in the report, the custom fields
// (http://documentation.devexpress.com/#WindowsForms/clsDevExpressXtraSchedulerNativeCustomFieldtopic)
// should be exposed as common object properties. So a wrapper class Task is
// implemented solely for this purpose. Using the SetAppointmentFactory
// (http://documentation.devexpress.com/#WindowsForms/DevExpressXtraSchedulerAppointmentStorageBase_SetAppointmentFactorytopic)
// method, Scheduler's Appointment objects are replaced with the Task class
// instances. A TaskCollection class holds Task objects and can be used as the
// report's data source.
// Note that you should have a valid license to the
// XtraReports Suite
// (http://documentation.devexpress.com/#XtraReports/CustomDocument2162) to be able
// to use this approach in your application.
//
// You can find sample updates and versions for different programming languages here:
// http://www.devexpress.com/example=E1183
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.UI;
namespace PrintingViaReports {
public partial class MyAppointmentEditForm : DevExpress.XtraEditors.XtraForm {
SchedulerControl control;
Appointment apt;
bool openRecurrenceForm = false;
int suspendUpdateCount;
// The MyAppointmentFormController class is inherited from
// the AppointmentFormController to add custom properties.
// See its declaration below.
MyAppointmentFormController controller;
protected AppointmentStorage Appointments {
get { return control.Storage.Appointments; }
}
protected bool IsUpdateSuspended { get { return suspendUpdateCount > 0; } }
public MyAppointmentEditForm(SchedulerControl control, Appointment apt, bool openRecurrenceForm) {
this.openRecurrenceForm = openRecurrenceForm;
this.controller = new MyAppointmentFormController(control, apt);
this.apt = apt;
this.control = control;
InitializeComponent();
UpdateForm();
}
#region Recurrence
private void MyAppointmentEditForm_Activated(object sender, System.EventArgs e) {
// Required to show the recurrence form.
if (openRecurrenceForm) {
openRecurrenceForm = false;
OnRecurrenceButton();
}
}
private void btnRecurrence_Click(object sender, System.EventArgs e) {
OnRecurrenceButton();
}
void OnRecurrenceButton() {
ShowRecurrenceForm();
}
void ShowRecurrenceForm() {
if (!control.SupportsRecurrence)
return;
// Prepare to edit the appointment's recurrence.
Appointment editedAptCopy = controller.EditedAppointmentCopy;
Appointment editedPattern = controller.EditedPattern;
Appointment patternCopy = controller.PrepareToRecurrenceEdit();
AppointmentRecurrenceForm dlg = new AppointmentRecurrenceForm(patternCopy, control.OptionsView.FirstDayOfWeek,controller);
// Required for skin support.
dlg.LookAndFeel.ParentLookAndFeel = this.LookAndFeel.ParentLookAndFeel;
DialogResult result = dlg.ShowDialog(this);
dlg.Dispose();
if (result == DialogResult.Abort)
controller.RemoveRecurrence();
else
if (result == DialogResult.OK) {
controller.ApplyRecurrence(patternCopy);
if (controller.EditedAppointmentCopy != editedAptCopy)
UpdateForm();
}
UpdateIntervalControls();
}
#endregion
#region Form control events
private void dtStart_EditValueChanged(object sender, System.EventArgs e) {
if (!IsUpdateSuspended)
controller.DisplayStart = dtStart.DateTime.Date + timeStart.Time.TimeOfDay;
UpdateIntervalControls();
}
private void timeStart_EditValueChanged(object sender, System.EventArgs e) {
if (!IsUpdateSuspended)
controller.DisplayStart = dtStart.DateTime.Date + timeStart.Time.TimeOfDay;
UpdateIntervalControls();
}
private void timeEnd_EditValueChanged(object sender, System.EventArgs e) {
if (IsUpdateSuspended) return;
if (IsIntervalValid())
controller.DisplayEnd = dtEnd.DateTime.Date + timeEnd.Time.TimeOfDay;
else
timeEnd.EditValue = new DateTime(controller.DisplayEnd.TimeOfDay.Ticks);
;
}
private void dtEnd_EditValueChanged(object sender, System.EventArgs e) {
if (IsUpdateSuspended) return;
if (IsIntervalValid())
controller.DisplayEnd = dtEnd.DateTime.Date + timeEnd.Time.TimeOfDay;
else
dtEnd.EditValue = controller.DisplayEnd.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;
if (!IsUpdateSuspended)
UpdateAppointmentStatus();
UpdateIntervalControls();
}
#endregion
#region Updating Form
protected void SuspendUpdate() {
suspendUpdateCount++;
}
protected void ResumeUpdate() {
if (suspendUpdateCount > 0)
suspendUpdateCount--;
}
void UpdateForm() {
SuspendUpdate();
try {
txSubject.Text = controller.Subject;
edStatus.Status = Appointments.Statuses.GetById(controller.StatusKey);
edLabel.Label = Appointments.Labels.GetById(controller.LabelKey);
dtStart.DateTime = controller.DisplayStart.Date;
dtEnd.DateTime= controller.DisplayEnd.Date;
timeStart.Time = new DateTime(controller.DisplayStart.TimeOfDay.Ticks);
timeEnd.Time = new DateTime(controller.DisplayEnd.TimeOfDay.Ticks);
checkAllDay.Checked = controller.AllDay;
edStatus.Storage = control.Storage;
edLabel.Storage = control.Storage;
edtDescription.Text = controller.Description;
txCustomText.Text = controller.CustomText;
edtCustomColor.Color = controller.CustomColor;
} finally {
ResumeUpdate();
}
UpdateIntervalControls();
}
protected virtual void UpdateIntervalControls() {
if (IsUpdateSuspended)
return;
SuspendUpdate();
try {
dtStart.EditValue = controller.DisplayStart.Date;
dtEnd.EditValue = controller.DisplayEnd.Date;
timeStart.EditValue = new DateTime(controller.DisplayStart.TimeOfDay.Ticks);
timeEnd.EditValue = new DateTime(controller.DisplayEnd.TimeOfDay.Ticks);
timeStart.Visible = !controller.AllDay;
timeEnd.Visible = !controller.AllDay;
timeStart.Enabled = !controller.AllDay;
timeEnd.Enabled = !controller.AllDay;
}
finally {
ResumeUpdate();
}
}
void UpdateAppointmentStatus() {
AppointmentStatus currentStatus = edStatus.Status;
AppointmentStatus newStatus = controller.UpdateAppointmentStatus(currentStatus);
if (newStatus != currentStatus)
edStatus.Status = newStatus;
}
#endregion
#region Save changes
private void btnOK_Click(object sender, System.EventArgs e) {
// Required to check the appointment for conflicts.
if (!controller.IsConflictResolved())
return;
controller.Subject = txSubject.Text;
controller.SetStatus(edStatus.Status);
controller.SetLabel(edLabel.Label);
controller.AllDay = this.checkAllDay.Checked;
controller.DisplayStart = this.dtStart.DateTime.Date + this.timeStart.Time.TimeOfDay;
controller.DisplayEnd = this.dtEnd.DateTime.Date + this.timeEnd.Time.TimeOfDay;
controller.Description = edtDescription.Text;
controller.CustomText = txCustomText.Text;
controller.CustomColor = edtCustomColor.Color;
// Save all changes of the editing appointment.
controller.ApplyChanges();
}
#endregion
#region MyAppointmentFormController
public class MyAppointmentFormController : AppointmentFormController {
public string CustomText { get { return (string)EditedAppointmentCopy.CustomFields["CustomTextField"]; } set { EditedAppointmentCopy.CustomFields["CustomTextField"] = value; } }
public Color CustomColor { get { return (Color)EditedAppointmentCopy.CustomFields["CustomColorField"]; } set { EditedAppointmentCopy.CustomFields["CustomColorField"] = value; } }
string SourceCustomText { get { return (string)SourceAppointment.CustomFields["CustomTextField"]; } set { SourceAppointment.CustomFields["CustomTextField"] = value; } }
Color SourceCustomColor { get { return (Color)SourceAppointment.CustomFields["CustomColorField"]; } set { SourceAppointment.CustomFields["CustomColorField"] = value; } }
public MyAppointmentFormController(SchedulerControl control, Appointment apt) : base(control, apt) {
}
public override bool IsAppointmentChanged() {
if(base.IsAppointmentChanged())
return true;
return SourceCustomText != CustomText ||
SourceCustomColor != CustomColor;
}
protected override void ApplyCustomFieldsValues() {
SourceCustomText = CustomText;
SourceCustomColor = CustomColor;
}
}
#endregion
}
}