/
SchedulerDataHelper.vb
137 lines (126 loc) · 5.98 KB
/
SchedulerDataHelper.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
Imports System.Collections
Imports System.Linq
Imports DevExpressMvcSchedulerFetchAppointments
Imports DevExpress.Web.Mvc
Imports DevExpress.XtraScheduler
Imports System
Imports DevExpress.Web.ASPxScheduler
Imports DevExpressMvcSchedulerFetchAppointments.Models
#Region "#schedulerdataobject"
Public Class SchedulerDataObject
Public Property Appointments() As IEnumerable
Public Property Resources() As IEnumerable
Public Property FetchAppointments() As DevExpress.Web.Mvc.FetchAppointmentsMethod
End Class
#End Region ' #schedulerdataobject
Public Class SchedulerDataHelper
Public Shared Function GetResources() As IEnumerable
Dim db As New SchedulingDataClassesDataContext()
Return From res In db.DBResources _
Select res
End Function
Public Shared Function GetAppointments() As IEnumerable
Dim db As New SchedulingDataClassesDataContext()
Return From apt In db.DBAppointments _
Select apt
End Function
#Region "#fetchappointmentshelpermethod"
Public Shared Function FetchAppointmentsHelperMethod(ByVal args As FetchAppointmentsEventArgs) As Object
args.ForceReloadAppointments = True
Dim db As New SchedulingDataClassesDataContext()
Return db.DBAppointments.Where(Function(e) (Convert.ToDateTime(e.StartDate) > args.Interval.Start AndAlso Convert.ToDateTime(e.EndDate) < args.Interval.End))
End Function
#End Region ' #fetchappointmentshelpermethod
Public Shared ReadOnly Property DataObject() As SchedulerDataObject
Get
Dim sdo As New SchedulerDataObject()
sdo.Appointments = GetAppointments()
sdo.Resources = GetResources()
sdo.FetchAppointments = AddressOf FetchAppointmentsHelperMethod
Return sdo
End Get
End Property
Private Shared defaultAppointmentStorage_Renamed As MVCxAppointmentStorage
Public Shared ReadOnly Property DefaultAppointmentStorage() As MVCxAppointmentStorage
Get
If defaultAppointmentStorage_Renamed Is Nothing Then
defaultAppointmentStorage_Renamed = CreateDefaultAppointmentStorage()
End If
Return defaultAppointmentStorage_Renamed
End Get
End Property
Private Shared Function CreateDefaultAppointmentStorage() As MVCxAppointmentStorage
Dim appointmentStorage As New MVCxAppointmentStorage()
appointmentStorage.Mappings.AppointmentId = "UniqueID"
appointmentStorage.Mappings.Start = "StartDate"
appointmentStorage.Mappings.End = "EndDate"
appointmentStorage.Mappings.Subject = "Subject"
appointmentStorage.Mappings.Description = "Description"
appointmentStorage.Mappings.Location = "Location"
appointmentStorage.Mappings.AllDay = "AllDay"
appointmentStorage.Mappings.Type = "Type"
appointmentStorage.Mappings.RecurrenceInfo = "RecurrenceInfo"
appointmentStorage.Mappings.ReminderInfo = "ReminderInfo"
appointmentStorage.Mappings.Label = "Label"
appointmentStorage.Mappings.Status = "Status"
appointmentStorage.Mappings.ResourceId = "ResourceID"
Return appointmentStorage
End Function
Private Shared defaultResourceStorage_Renamed As MVCxResourceStorage
Public Shared ReadOnly Property DefaultResourceStorage() As MVCxResourceStorage
Get
If defaultResourceStorage_Renamed Is Nothing Then
defaultResourceStorage_Renamed = CreateDefaultResourceStorage()
End If
Return defaultResourceStorage_Renamed
End Get
End Property
Private Shared Function CreateDefaultResourceStorage() As MVCxResourceStorage
Dim resourceStorage As New MVCxResourceStorage()
resourceStorage.Mappings.ResourceId = "ResourceID"
resourceStorage.Mappings.Caption = "ResourceName"
Return resourceStorage
End Function
Public Shared Sub InsertAppointment(ByVal appt As DBAppointment)
If appt Is Nothing Then
Return
End If
Dim db As New SchedulingDataClassesDataContext()
appt.UniqueID = appt.GetHashCode()
db.DBAppointments.InsertOnSubmit(appt)
db.SubmitChanges()
End Sub
Public Shared Sub UpdateAppointment(ByVal appt As DBAppointment)
If appt Is Nothing Then
Return
End If
Dim db As New SchedulingDataClassesDataContext()
Dim query As DBAppointment = CType(( _
From carSchedule In db.DBAppointments _
Where carSchedule.UniqueID = appt.UniqueID _
Select carSchedule).SingleOrDefault(), DBAppointment)
query.UniqueID = appt.UniqueID
query.StartDate = appt.StartDate
query.EndDate = appt.EndDate
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.Type = appt.Type
query.Label = appt.Label
query.ResourceID = appt.ResourceID
db.SubmitChanges()
End Sub
Public Shared Sub RemoveAppointment(ByVal appt As DBAppointment)
Dim db As New SchedulingDataClassesDataContext()
Dim query As DBAppointment = CType(( _
From carSchedule In db.DBAppointments _
Where carSchedule.UniqueID = appt.UniqueID _
Select carSchedule).SingleOrDefault(), DBAppointment)
db.DBAppointments.DeleteOnSubmit(query)
db.SubmitChanges()
End Sub
End Class