This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
Form1.vb
111 lines (92 loc) · 3.68 KB
/
Form1.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
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports DevExpress.XtraScheduler
Namespace WindowsFormsApplication1
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Public Shared RandomInstance As New Random()
Private CustomResourceCollection As New BindingList(Of CustomResource)()
Private CustomEventList As New BindingList(Of CustomAppointment)()
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
InitResources()
InitAppointments()
schedulerControl1.Start = DateTime.Now
schedulerControl1.GroupType = DevExpress.XtraScheduler.SchedulerGroupType.Resource
Dim scales As TimeScaleCollection = schedulerControl1.TimelineView.Scales
scales.BeginUpdate()
Try
scales.Clear()
scales.Add(New MyTimeScaleMinutesInterval(TimeSpan.FromMinutes(12)))
scales.Add(New MyTimeScaleHoursInterval())
scales.Add(New MyTimeScaleDaysInterval())
scales.EndUpdate()
Finally
scales.EndUpdate()
End Try
End Sub
Private Sub InitResources()
Dim mappings As ResourceMappingInfo = Me.schedulerStorage1.Resources.Mappings
mappings.Id = "ResID"
mappings.Caption = "Name"
CustomResourceCollection.Add(CreateCustomResource(1, "Max Fowler", Color.PowderBlue))
CustomResourceCollection.Add(CreateCustomResource(2, "Nancy Drewmore", Color.PaleVioletRed))
CustomResourceCollection.Add(CreateCustomResource(3, "Pak Jang", Color.PeachPuff))
Me.schedulerStorage1.Resources.DataSource = CustomResourceCollection
End Sub
Private Function CreateCustomResource(ByVal res_id As Integer, ByVal caption As String, ByVal ResColor As Color) As CustomResource
Dim cr As New CustomResource()
cr.ResID = res_id
cr.Name = caption
Return cr
End Function
Private Sub InitAppointments()
Dim mappings As AppointmentMappingInfo = Me.schedulerStorage1.Appointments.Mappings
mappings.Start = "StartTime"
mappings.End = "EndTime"
mappings.Subject = "Subject"
mappings.AllDay = "AllDay"
mappings.Description = "Description"
mappings.Label = "Label"
mappings.Location = "Location"
mappings.RecurrenceInfo = "RecurrenceInfo"
mappings.ReminderInfo = "ReminderInfo"
mappings.ResourceId = "OwnerId"
mappings.Status = "Status"
mappings.Type = "EventType"
GenerateEvents(CustomEventList)
Me.schedulerStorage1.Appointments.DataSource = CustomEventList
End Sub
Private Sub GenerateEvents(ByVal eventList As BindingList(Of CustomAppointment))
Dim count As Integer = schedulerStorage1.Resources.Count
For i As Integer = 0 To count - 1
Dim resource As Resource = schedulerStorage1.Resources(i)
Dim subjPrefix As String = resource.Caption & "'s "
eventList.Add(CreateEvent(subjPrefix & "meeting", resource.Id, 2, 5))
eventList.Add(CreateEvent(subjPrefix & "travel", resource.Id, 3, 6))
eventList.Add(CreateEvent(subjPrefix & "phone call", resource.Id, 0, 10))
Next i
End Sub
Private Function CreateEvent(ByVal subject As String, ByVal resourceId As Object, ByVal status As Integer, ByVal label As Integer) As CustomAppointment
Dim apt As New CustomAppointment()
apt.Subject = subject
apt.OwnerId = resourceId
Dim rnd As Random = RandomInstance
Dim rangeInMinutes As Integer = 60 * 24
apt.StartTime = DateTime.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
End Class
End Namespace