/
Scheduling.vb
271 lines (226 loc) · 9.84 KB
/
Scheduling.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
' Developer Express Code Central Example:
' Scheduler - How to implement a custom Edit Appointment Form with custom fields
'
' This example illustrates how to implement a custom Appointment Form and display
' it instead of the default one.
'
' To include a custom Appointment Form to the
' SchedulerPartial view, the
' MVCxSchedulerOptionsForms.SetAppointmentFormTemplateContent Method
' (ms-help://DevExpress.NETv12.2/DevExpress.AspNet/DevExpressWebMvcMVCxSchedulerOptionsForms_SetAppointmentFormTemplateContenttopic.htm)
' should be handled.
' To add custom fields to the Appointment Form, implement a
' custom AppointmentFormTemplateContainer
' (ms-help://DevExpress.NETv12.2/DevExpress.AspNet/clsDevExpressWebASPxSchedulerAppointmentFormTemplateContainertopic.htm)
' and substitute the default container with your custom one by handling the
' ASPxScheduler.AppointmentFormShowing Event
' (ms-help://DevExpress.NETv12.2/DevExpress.AspNet/DevExpressWebASPxSchedulerASPxScheduler_AppointmentFormShowingtopic.htm).
' See
' Also:
' http://www.devexpress.com/scid=E2924
' http://www.devexpress.com/scid=E3984
'
' You can find sample updates and versions for different programming languages here:
' http://www.devexpress.com/example=E4520
Imports System.Collections
Imports System.Linq
Imports DevExpress.Web.Mvc
Imports System.ComponentModel.DataAnnotations
Imports System
Imports DevExpressMvcApplication1.Models
Imports DevExpress.Web
Imports DevExpress.Web.ASPxScheduler
Imports DevExpress.XtraScheduler
Public Class SchedulerDataObject
Public Property Appointments As IEnumerable
Public Property Resources As IEnumerable
End Class
Public Class SchedulerDataHelper
Public Shared Function GetResources() As IEnumerable
Dim db As CarsDataContext = New CarsDataContext()
Return From res In db.Cars Select res
End Function
Public Shared Function GetAppointments() As IEnumerable
Dim db As CarsDataContext = New CarsDataContext()
Return From apt In db.CarSchedulings Select apt
End Function
Public Shared Iterator Function GetReminders(ByVal rawDataSource As IEnumerable) As IEnumerable
For Each item As ListEditItem In rawDataSource
Yield New With {item.Value, item.Text}
Next
End Function
Public Shared ReadOnly Property DataObject As SchedulerDataObject
Get
Return New SchedulerDataObject() With {.Appointments = GetAppointments(), .Resources = GetResources()}
End Get
End Property
Private Shared defaultAppointmentStorageField As MVCxAppointmentStorage
Public Shared ReadOnly Property DefaultAppointmentStorage As MVCxAppointmentStorage
Get
If defaultAppointmentStorageField Is Nothing Then defaultAppointmentStorageField = CreateDefaultAppointmentStorage()
Return defaultAppointmentStorageField
End Get
End Property
Private Shared Function CreateDefaultAppointmentStorage() As MVCxAppointmentStorage
Dim appointmentStorage As MVCxAppointmentStorage = New MVCxAppointmentStorage()
appointmentStorage.Mappings.AppointmentId = "ID"
appointmentStorage.Mappings.Start = "StartTime"
appointmentStorage.Mappings.End = "EndTime"
appointmentStorage.Mappings.Subject = "Subject"
appointmentStorage.Mappings.Description = "Description"
appointmentStorage.Mappings.Location = "Location"
appointmentStorage.Mappings.AllDay = "AllDay"
appointmentStorage.Mappings.Type = "EventType"
appointmentStorage.Mappings.RecurrenceInfo = "RecurrenceInfo"
appointmentStorage.Mappings.ReminderInfo = "ReminderInfo"
appointmentStorage.Mappings.Label = "Label"
appointmentStorage.Mappings.Status = "Status"
appointmentStorage.Mappings.ResourceId = "CarId"
appointmentStorage.CustomFieldMappings.Add("Price", "Price")
appointmentStorage.CustomFieldMappings.Add("ContactInfo", "ContactInfo")
appointmentStorage.CustomFieldMappings.Add("CarId", "CarId")
Return appointmentStorage
End Function
Private Shared defaultResourceStorageField As MVCxResourceStorage
Public Shared ReadOnly Property DefaultResourceStorage As MVCxResourceStorage
Get
If defaultResourceStorageField Is Nothing Then defaultResourceStorageField = CreateDefaultResourceStorage()
Return defaultResourceStorageField
End Get
End Property
Private Shared Function CreateDefaultResourceStorage() As MVCxResourceStorage
Dim resourceStorage As MVCxResourceStorage = New MVCxResourceStorage()
resourceStorage.Mappings.ResourceId = "ID"
resourceStorage.Mappings.Caption = "Model"
Return resourceStorage
End Function
Public Shared Sub InsertAppointment(ByVal appt As CarScheduling)
If appt Is Nothing Then Return
Dim db As CarsDataContext = New CarsDataContext()
appt.ID = appt.GetHashCode()
db.CarSchedulings.InsertOnSubmit(appt)
db.SubmitChanges()
End Sub
Public Shared Sub UpdateAppointment(ByVal appt As CarScheduling)
If appt Is Nothing Then Return
Dim db As CarsDataContext = New CarsDataContext()
Dim query As CarScheduling = CType((From carSchedule In db.CarSchedulings Where carSchedule.ID = appt.ID Select carSchedule).SingleOrDefault(), CarScheduling)
query.ID = appt.ID
query.StartTime = appt.StartTime
query.EndTime = appt.EndTime
query.AllDay = appt.AllDay
query.Subject = appt.Subject
query.Description = appt.Description
query.Location = appt.Location
query.RecurrenceInfo = appt.RecurrenceInfo
query.ReminderInfo = appt.ReminderInfo
query.Status = appt.Status
query.EventType = appt.EventType
query.Label = appt.Label
query.CarId = appt.CarId
query.ContactInfo = appt.ContactInfo
query.Price = appt.Price
db.SubmitChanges()
End Sub
Public Shared Sub RemoveAppointment(ByVal appt As CarScheduling)
Dim db As CarsDataContext = New CarsDataContext()
Dim query As CarScheduling = CType((From carSchedule In db.CarSchedulings Where carSchedule.ID = appt.ID Select carSchedule).SingleOrDefault(), CarScheduling)
db.CarSchedulings.DeleteOnSubmit(query)
db.SubmitChanges()
End Sub
End Class
Public Class CustomAppointmentTemplateContainer
Inherits AppointmentFormTemplateContainer
Public Sub New(ByVal scheduler As MVCxScheduler)
MyBase.New(scheduler)
End Sub
Public Overloads ReadOnly Property ResourceDataSource As IEnumerable
Get
Return SchedulerDataHelper.GetResources()
End Get
End Property
Public Overloads ReadOnly Property ReminderDataSource As IEnumerable
Get
Return SchedulerDataHelper.GetReminders(MyBase.ReminderDataSource)
End Get
End Property
Public ReadOnly Property ContactInfo As String
Get
Return Convert.ToString(Appointment.CustomFields("ContactInfo"))
End Get
End Property
Public ReadOnly Property Price As Decimal?
Get
Dim priceRawValue As Object = Appointment.CustomFields("Price")
Return If(priceRawValue Is DBNull.Value, 0, CType(priceRawValue, Decimal?))
End Get
End Property
Public ReadOnly Property CarId As Integer?
Get
Dim lCarId As Object = Appointment.ResourceId
Return If(lCarId Is ResourceEmpty.Id, 1, CType(lCarId, Integer?)) ' select first resource if empty
End Get
End Property
End Class
Public Class Schedule
Public Sub New()
End Sub
Public Sub New(ByVal carScheduling As CarScheduling)
If carScheduling IsNot Nothing Then
ID = carScheduling.ID
EventType = carScheduling.EventType
Label = carScheduling.Label
AllDay = carScheduling.AllDay
Location = carScheduling.Location
CarId = carScheduling.CarId
Status = carScheduling.Status
RecurrenceInfo = carScheduling.RecurrenceInfo
ReminderInfo = carScheduling.ReminderInfo
Subject = carScheduling.Subject
Price = carScheduling.Price
StartTime = carScheduling.StartTime.Value
EndTime = carScheduling.EndTime.Value
Description = carScheduling.Description
ContactInfo = carScheduling.ContactInfo
End If
End Sub
Public Property ID As Integer
Public Property EventType As Integer?
Public Property Label As Integer?
Public Property AllDay As Boolean
Public Property Location As String
Public Property CarId As Object
Public Property Status As Integer?
Public Property RecurrenceInfo As String
Public Property ReminderInfo As String
<Required(ErrorMessage:="The Subject must contain at least one character.")>
Public Property Subject As String
Public Property Price As Decimal?
<Required>
Public Property StartTime As Date
<Required>
Public Property EndTime As Date
Public Property Description As String
Public Property ContactInfo As String
Public Property HasReminder As Boolean
Public Property Reminder As Reminder
Public Overridable Sub Assign(ByVal source As Schedule)
If source IsNot Nothing Then
ID = source.ID
EventType = source.EventType
Label = source.Label
AllDay = source.AllDay
Location = source.Location
CarId = source.CarId
Status = source.Status
RecurrenceInfo = source.RecurrenceInfo
ReminderInfo = source.ReminderInfo
Subject = source.Subject
Price = source.Price
StartTime = source.StartTime
EndTime = source.EndTime
Description = source.Description
ContactInfo = source.ContactInfo
End If
End Sub
End Class