/
Default.aspx.vb
117 lines (101 loc) · 6.02 KB
/
Default.aspx.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
Imports System
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DevExpress.XtraScheduler
Namespace WebApplication1
Public Partial Class [Default]
Inherits Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub ObjectDataSourceResources_ObjectCreated(ByVal sender As Object, ByVal e As ObjectDataSourceEventArgs)
If Session("CustomResourceDataSource") Is Nothing Then
Session("CustomResourceDataSource") = New CustomResourceDataSource(GetCustomResources())
End If
e.ObjectInstance = Session("CustomResourceDataSource")
End Sub
Private Function GetCustomResources() As BindingList(Of CustomResource)
Dim resources As BindingList(Of CustomResource) = New BindingList(Of CustomResource)()
resources.Add(CreateCustomResource(1, "Max Fowler"))
resources.Add(CreateCustomResource(2, "Nancy Drewmore"))
resources.Add(CreateCustomResource(3, "Pak Jang"))
Return resources
End Function
Private Function CreateCustomResource(ByVal res_id As Integer, ByVal caption As String) As CustomResource
Dim cr As CustomResource = New CustomResource()
cr.ResID = res_id
cr.Name = caption
Return cr
End Function
Public RandomInstance As Random = New Random()
Private Function CreateCustomAppointment(ByVal subject As String, ByVal resourceId As Object, ByVal status As Integer, ByVal label As Integer) As CustomAppointment
Dim apt As CustomAppointment = New CustomAppointment()
apt.Subject = subject
apt.OwnerId = resourceId
Dim rnd As Random = RandomInstance
Dim rangeInMinutes As Integer = 60 * 24
apt.StartTime = Date.Today + TimeSpan.FromMinutes(rnd.Next(0, rangeInMinutes))
apt.EndTime = apt.StartTime + TimeSpan.FromMinutes(rnd.Next(0, rangeInMinutes \ 4))
apt.Status = status
apt.Label = label
Return apt
End Function
Protected Sub ObjectDataSourceAppointment_ObjectCreated(ByVal sender As Object, ByVal e As ObjectDataSourceEventArgs)
If Session("CustomAppointmentDataSource") Is Nothing Then
Session("CustomAppointmentDataSource") = New CustomAppointmentDataSource(GetCustomAppointments())
End If
e.ObjectInstance = Session("CustomAppointmentDataSource")
End Sub
Private Function GetCustomAppointments() As BindingList(Of CustomAppointment)
Dim appointments As BindingList(Of CustomAppointment) = New BindingList(Of CustomAppointment)()
Dim resources As CustomResourceDataSource = TryCast(Session("CustomResourceDataSource"), CustomResourceDataSource)
If resources IsNot Nothing Then
For Each item As CustomResource In resources.Resources
Dim subjPrefix As String = item.Name & "'s "
appointments.Add(CreateCustomAppointment(subjPrefix & "meeting", item.ResID, 2, 5))
appointments.Add(CreateCustomAppointment(subjPrefix & "travel", item.ResID, 3, 6))
appointments.Add(CreateCustomAppointment(subjPrefix & "phone call", item.ResID, 0, 10))
Next
End If
Return appointments
End Function
Protected Sub ASPxScheduler1_PopupMenuShowing(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxScheduler.PopupMenuShowingEventArgs)
e.Menu.ClientSideEvents.PopUp = "OnClientPopupMenuShowing"
If e.Menu.MenuId = SchedulerMenuItemId.AppointmentMenu Then
Dim newItemCopy As DevExpress.Web.MenuItem = New DevExpress.Web.MenuItem()
newItemCopy.Name = "CopyAppointment"
newItemCopy.Text = "Copy"
newItemCopy.ItemStyle.Font.Bold = True
e.Menu.Items.Add(newItemCopy)
e.Menu.JSProperties("cpMenuName") = "AppointmentMenu"
End If
If e.Menu.MenuId = SchedulerMenuItemId.DefaultMenu Then
Dim newItemPaste As DevExpress.Web.MenuItem = New DevExpress.Web.MenuItem()
newItemPaste.Name = "PasteAppointment"
newItemPaste.Text = "Paste"
newItemPaste.ItemStyle.Font.Bold = True
e.Menu.Items.Insert(0, newItemPaste)
e.Menu.JSProperties("cpMenuName") = "DefaultMenu"
End If
End Sub
Protected Sub ASPxScheduler1_CustomCallback(ByVal sender As Object, ByVal e As DevExpress.Web.CallbackEventArgsBase)
If Equals(e.Parameter, "PasteAppointment") AndAlso Not Equals(hdCopiedAppointmentID.Value, "") Then
Dim copyAppointmentID As Integer = Convert.ToInt32(hdCopiedAppointmentID.Value)
Dim sourceAppointment As Appointment = ASPxScheduler1.Storage.Appointments.GetAppointmentById(copyAppointmentID)
If sourceAppointment IsNot Nothing Then
Dim newAppointment As Appointment = ASPxScheduler1.Storage.CreateAppointment(sourceAppointment.Type)
newAppointment.Description = sourceAppointment.Description
newAppointment.LabelKey = sourceAppointment.LabelKey
newAppointment.Location = sourceAppointment.Location
newAppointment.ResourceId = ASPxScheduler1.SelectedResource.Id
newAppointment.Subject = sourceAppointment.Subject
newAppointment.StatusKey = sourceAppointment.StatusKey
newAppointment.Start = ASPxScheduler1.SelectedInterval.Start
newAppointment.End = newAppointment.Start + sourceAppointment.Duration
ASPxScheduler1.Storage.Appointments.Add(newAppointment)
ASPxScheduler1.JSProperties("cpCallBackParameter") = "PasteAppointment"
End If
End If
End Sub
End Class
End Namespace