/
MyAppointmentEditForm.vb
281 lines (237 loc) · 8.61 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
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraScheduler
Imports DevExpress.XtraScheduler.UI
Namespace ReminderCustomActions
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
Private WithEvents checkAllDay As DevExpress.XtraEditors.CheckEdit
' Note that the MyAppointmentFormController class is inherited from
' the AppointmentFormController one to add custom properties.
' See its declaration at the end of this file.
Private controller As MyAppointmentFormController
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
'
' Required for Windows Form Designer support
'
SuspendUpdate()
InitializeComponent()
ResumeUpdate()
UpdateForm()
'
' TODO: Add any constructor code after InitializeComponent call
'
End Sub
Protected ReadOnly Property Appointments() As IAppointmentStorage
Get
Return control.DataStorage.Appointments
End Get
End Property
Protected ReadOnly Property IsUpdateSuspended() As Boolean
Get
Return suspendUpdateCount > 0
End Get
End Property
Protected Sub SuspendUpdate()
suspendUpdateCount += 1
End Sub
Protected Sub ResumeUpdate()
If suspendUpdateCount > 0 Then
suspendUpdateCount -= 1
End If
End Sub
Private Sub btnAddRec_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 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 skins 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
Private Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
' Required to check appointment's conflicts.
If Not controller.IsConflictResolved() Then
Return
End If
controller.Subject = txSubject.Text
controller.SetStatus(edStatus.AppointmentStatus)
controller.SetLabel(edLabel.AppointmentLabel)
controller.AllDay = Me.checkAllDay.Checked
controller.Start = Me.dtStart.DateTime.Date + Me.timeStart.Time.TimeOfDay
controller.End = Me.dtEnd.DateTime.Date + Me.timeEnd.Time.TimeOfDay
controller.ResourceIds.AddRange(appointmentResourcesEdit1.ResourceIds)
controller.CustomPrice = calcPrice.Value
' Save all changes made to the appointment edited in a form.
controller.ApplyChanges()
End Sub
Private Sub UpdateForm()
SuspendUpdate()
Try
txSubject.Text = controller.Subject
edStatus.AppointmentStatus = Appointments.Statuses.GetById(controller.StatusKey)
edLabel.AppointmentLabel = Appointments.Labels.GetById(controller.LabelKey)
dtStart.DateTime = controller.Start.Date
dtEnd.DateTime = controller.End.Date
timeStart.Time = Date.MinValue.AddTicks(controller.Start.TimeOfDay.Ticks)
timeEnd.Time = Date.MinValue.AddTicks(controller.End.TimeOfDay.Ticks)
checkAllDay.Checked = controller.AllDay
edStatus.Storage = control.DataStorage
edLabel.Storage = control.DataStorage
appointmentResourcesEdit1.SchedulerControl=control
Dim resourceIds As AppointmentResourceIdCollection = appointmentResourcesEdit1.ResourceIds
resourceIds.BeginUpdate()
Try
resourceIds.Clear()
resourceIds.AddRange(controller.ResourceIds)
Finally
resourceIds.EndUpdate()
End Try
Dim canEditResource As Boolean = controller.CanEditResource
appointmentResourcesEdit1.Enabled = canEditResource
lblResource.Enabled = canEditResource
calcPrice.Value = controller.CustomPrice
Finally
ResumeUpdate()
End Try
UpdateIntervalControls()
End Sub
Private Sub MyAppointmentEditForm_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
' Required to show the recurrence form.
If openRecurrenceForm Then
openRecurrenceForm = False
OnRecurrenceButton()
End If
End Sub
Private Sub dtStart_EditValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtStart.EditValueChanged
If Not IsUpdateSuspended Then
controller.Start = dtStart.DateTime.Date + timeStart.Time.TimeOfDay
End If
UpdateIntervalControls()
End Sub
Protected Overridable Sub UpdateIntervalControls()
If IsUpdateSuspended Then
Return
End If
SuspendUpdate()
Try
dtStart.EditValue = controller.Start.Date
dtEnd.EditValue = controller.End.Date
timeStart.EditValue = controller.Start.TimeOfDay
timeEnd.EditValue = controller.End.TimeOfDay
dtStart.Enabled = Not controller.AllDay
dtEnd.Enabled = Not controller.AllDay
timeStart.Enabled = Not controller.AllDay
timeEnd.Enabled = Not controller.AllDay
Finally
ResumeUpdate()
End Try
End Sub
Private Sub timeStart_EditValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles timeStart.EditValueChanged
If Not IsUpdateSuspended Then
controller.Start = 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.End = dtEnd.DateTime + timeEnd.Time.TimeOfDay
Else
timeEnd.EditValue = controller.End.TimeOfDay
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.End = dtEnd.DateTime + timeEnd.Time.TimeOfDay
Else
dtEnd.EditValue = controller.End.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
Private Sub UpdateAppointmentStatus()
Dim currentStatus As IAppointmentStatus = edStatus.AppointmentStatus
Dim newStatus As IAppointmentStatus = controller.UpdateStatus(currentStatus)
If newStatus IsNot currentStatus Then
edStatus.AppointmentStatus = newStatus
End If
End Sub
End Class
Public Class MyAppointmentFormController
Inherits AppointmentFormController
Public Property CustomPrice() As Decimal
Get
Return If(EditedAppointmentCopy.CustomFields("CustomPrice") IsNot Nothing, DirectCast(EditedAppointmentCopy.CustomFields("CustomPrice"), Decimal), 0)
End Get
Set(ByVal value As Decimal)
EditedAppointmentCopy.CustomFields("CustomPrice") = value
End Set
End Property
Private Property SourceCustomPrice() As Decimal
Get
Return DirectCast(SourceAppointment.CustomFields("CustomPrice"), Decimal)
End Get
Set(ByVal value As Decimal)
SourceAppointment.CustomFields("CustomPrice") = 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 SourceCustomPrice <> CustomPrice
End Function
Protected Overrides Sub ApplyCustomFieldsValues()
SourceCustomPrice = CustomPrice
End Sub
End Class
End Namespace