/
MyAppointmentEditForm.vb
330 lines (282 loc) · 12.7 KB
/
MyAppointmentEditForm.vb
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
' 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
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports DevExpress.XtraEditors
Imports DevExpress.XtraScheduler
Imports DevExpress.XtraScheduler.UI
Namespace PrintingViaReports
Partial Public Class MyAppointmentEditForm
Inherits DevExpress.XtraEditors.XtraForm
Private control As SchedulerControl
Private apt As Appointment
Private openRecurrenceForm As Boolean = False
Private suspendUpdateCount As Integer
' The MyAppointmentFormController class is inherited from
' the AppointmentFormController to add custom properties.
' See its declaration below.
Private controller As MyAppointmentFormController
Protected ReadOnly Property Appointments() As AppointmentStorage
Get
Return control.Storage.Appointments
End Get
End Property
Protected ReadOnly Property IsUpdateSuspended() As Boolean
Get
Return suspendUpdateCount > 0
End Get
End Property
Public Sub New(ByVal control As SchedulerControl, ByVal apt As Appointment, ByVal openRecurrenceForm As Boolean)
Me.openRecurrenceForm = openRecurrenceForm
Me.controller = New MyAppointmentFormController(control, apt)
Me.apt = apt
Me.control = control
InitializeComponent()
UpdateForm()
End Sub
#Region "Recurrence"
Private Sub MyAppointmentEditForm_Activated(ByVal sender As Object, ByVal e As System.EventArgs)
' Required to show the recurrence form.
If openRecurrenceForm Then
openRecurrenceForm = False
OnRecurrenceButton()
End If
End Sub
Private Sub btnRecurrence_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRecurrence.Click
OnRecurrenceButton()
End Sub
Private Sub OnRecurrenceButton()
ShowRecurrenceForm()
End Sub
Private Sub ShowRecurrenceForm()
If Not control.SupportsRecurrence Then
Return
End If
' Prepare to edit the appointment's recurrence.
Dim editedAptCopy As Appointment = controller.EditedAppointmentCopy
Dim editedPattern As Appointment = controller.EditedPattern
Dim patternCopy As Appointment = controller.PrepareToRecurrenceEdit()
Dim dlg As New AppointmentRecurrenceForm(patternCopy, control.OptionsView.FirstDayOfWeek,controller)
' Required for skin support.
dlg.LookAndFeel.ParentLookAndFeel = Me.LookAndFeel.ParentLookAndFeel
Dim result As DialogResult = dlg.ShowDialog(Me)
dlg.Dispose()
If result = DialogResult.Abort Then
controller.RemoveRecurrence()
Else
If result = DialogResult.OK Then
controller.ApplyRecurrence(patternCopy)
If controller.EditedAppointmentCopy IsNot editedAptCopy Then
UpdateForm()
End If
End If
End If
UpdateIntervalControls()
End Sub
#End Region
#Region "Form control events"
Private Sub dtStart_EditValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtStart.EditValueChanged
If Not IsUpdateSuspended Then
controller.DisplayStart = dtStart.DateTime.Date + timeStart.Time.TimeOfDay
End If
UpdateIntervalControls()
End Sub
Private Sub timeStart_EditValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles timeStart.EditValueChanged
If Not IsUpdateSuspended Then
controller.DisplayStart = dtStart.DateTime.Date + timeStart.Time.TimeOfDay
End If
UpdateIntervalControls()
End Sub
Private Sub timeEnd_EditValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles timeEnd.EditValueChanged
If IsUpdateSuspended Then
Return
End If
If IsIntervalValid() Then
controller.DisplayEnd = dtEnd.DateTime.Date + timeEnd.Time.TimeOfDay
Else
timeEnd.EditValue = New Date(controller.DisplayEnd.TimeOfDay.Ticks)
End If
End Sub
Private Sub dtEnd_EditValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtEnd.EditValueChanged
If IsUpdateSuspended Then
Return
End If
If IsIntervalValid() Then
controller.DisplayEnd = dtEnd.DateTime.Date + timeEnd.Time.TimeOfDay
Else
dtEnd.EditValue = controller.DisplayEnd.Date
End If
End Sub
Private Function IsIntervalValid() As Boolean
Dim start As Date = dtStart.DateTime + timeStart.Time.TimeOfDay
Dim [end] As Date = dtEnd.DateTime + timeEnd.Time.TimeOfDay
Return [end] >= start
End Function
Private Sub checkAllDay_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles checkAllDay.CheckedChanged
controller.AllDay = Me.checkAllDay.Checked
If Not IsUpdateSuspended Then
UpdateAppointmentStatus()
End If
UpdateIntervalControls()
End Sub
#End Region
#Region "Updating Form"
Protected Sub SuspendUpdate()
suspendUpdateCount += 1
End Sub
Protected Sub ResumeUpdate()
If suspendUpdateCount > 0 Then
suspendUpdateCount -= 1
End If
End Sub
Private Sub 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 Date(controller.DisplayStart.TimeOfDay.Ticks)
timeEnd.Time = New Date(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()
End Try
UpdateIntervalControls()
End Sub
Protected Overridable Sub UpdateIntervalControls()
If IsUpdateSuspended Then
Return
End If
SuspendUpdate()
Try
dtStart.EditValue = controller.DisplayStart.Date
dtEnd.EditValue = controller.DisplayEnd.Date
timeStart.EditValue = New Date(controller.DisplayStart.TimeOfDay.Ticks)
timeEnd.EditValue = New Date(controller.DisplayEnd.TimeOfDay.Ticks)
timeStart.Visible = Not controller.AllDay
timeEnd.Visible = Not controller.AllDay
timeStart.Enabled = Not controller.AllDay
timeEnd.Enabled = Not controller.AllDay
Finally
ResumeUpdate()
End Try
End Sub
Private Sub UpdateAppointmentStatus()
Dim currentStatus As AppointmentStatus = edStatus.Status
Dim newStatus As AppointmentStatus = controller.UpdateAppointmentStatus(currentStatus)
If newStatus IsNot currentStatus Then
edStatus.Status = newStatus
End If
End Sub
#End Region
#Region "Save changes"
Private Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
' Required to check the appointment for conflicts.
If Not controller.IsConflictResolved() Then
Return
End If
controller.Subject = txSubject.Text
controller.SetStatus(edStatus.Status)
controller.SetLabel(edLabel.Label)
controller.AllDay = Me.checkAllDay.Checked
controller.DisplayStart = Me.dtStart.DateTime.Date + Me.timeStart.Time.TimeOfDay
controller.DisplayEnd = Me.dtEnd.DateTime.Date + Me.timeEnd.Time.TimeOfDay
controller.Description = edtDescription.Text
controller.CustomText = txCustomText.Text
controller.CustomColor = edtCustomColor.Color
' Save all changes of the editing appointment.
controller.ApplyChanges()
End Sub
#End Region
#Region "MyAppointmentFormController"
Public Class MyAppointmentFormController
Inherits AppointmentFormController
Public Property CustomText() As String
Get
Return CStr(EditedAppointmentCopy.CustomFields("CustomTextField"))
End Get
Set(ByVal value As String)
EditedAppointmentCopy.CustomFields("CustomTextField") = value
End Set
End Property
Public Property CustomColor() As Color
Get
Return CType(EditedAppointmentCopy.CustomFields("CustomColorField"), Color)
End Get
Set(ByVal value As Color)
EditedAppointmentCopy.CustomFields("CustomColorField") = value
End Set
End Property
Private Property SourceCustomText() As String
Get
Return CStr(SourceAppointment.CustomFields("CustomTextField"))
End Get
Set(ByVal value As String)
SourceAppointment.CustomFields("CustomTextField") = value
End Set
End Property
Private Property SourceCustomColor() As Color
Get
Return CType(SourceAppointment.CustomFields("CustomColorField"), Color)
End Get
Set(ByVal value As Color)
SourceAppointment.CustomFields("CustomColorField") = value
End Set
End Property
Public Sub New(ByVal control As SchedulerControl, ByVal apt As Appointment)
MyBase.New(control, apt)
End Sub
Public Overrides Function IsAppointmentChanged() As Boolean
If MyBase.IsAppointmentChanged() Then
Return True
End If
Return SourceCustomText <> CustomText OrElse SourceCustomColor <> CustomColor
End Function
Protected Overrides Sub ApplyCustomFieldsValues()
SourceCustomText = CustomText
SourceCustomColor = CustomColor
End Sub
End Class
#End Region
End Class
End Namespace