/
Form1.vb
139 lines (116 loc) · 6.2 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
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
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports DevExpress.XtraScheduler
Imports System.Collections.Generic
Namespace SchedulerFindAptByRow
Public Partial Class Form1
Inherits Form
Private appointmentRowDictionaryField As Dictionary(Of Object, Appointment) = New Dictionary(Of Object, Appointment)()
Private rowAppointmentDictionaryField As Dictionary(Of Appointment, Object) = New Dictionary(Of Appointment, Object)()
Public Sub New()
InitializeComponent()
End Sub
Protected ReadOnly Property AppointmentRowDictionary As Dictionary(Of Object, Appointment)
Get
Return appointmentRowDictionaryField
End Get
End Property
Protected ReadOnly Property RowAppointmentDictionary As Dictionary(Of Appointment, Object)
Get
Return rowAppointmentDictionaryField
End Get
End Property
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
' TODO: This line of code loads data into the 'carsDBDataSet.Cars' table. You can move, or remove it, as needed.
carsTableAdapter.Fill(carsDBDataSet.Cars)
' TODO: This line of code loads data into the 'carsDBDataSet.CarScheduling' table. You can move, or remove it, as needed.
carSchedulingTableAdapter.Fill(carsDBDataSet.CarScheduling)
schedulerStorage1.Resources.DataSource = carsDBDataSet.Cars
schedulerStorage1.Appointments.DataSource = carsDBDataSet.CarScheduling
dataGridView1.DataSource = carsDBDataSet.CarScheduling
If schedulerStorage1.Appointments.Count > 0 Then schedulerControl1.Start = schedulerStorage1.Appointments(0).Start
End Sub
Private Sub schedulerStorage1_AppointmentCollectionLoaded(ByVal sender As Object, ByVal e As EventArgs)
For Each apt As Appointment In schedulerStorage1.Appointments.Items
Dim apts As AppointmentBaseCollection = New AppointmentBaseCollection()
apts.Add(apt)
RegisterAppointmentRows(apts)
If apt.Type = AppointmentType.Pattern Then
RegisterAppointmentRows(apt.GetExceptions())
End If
Next
End Sub
Private Sub schedulerStorage1_AppointmentCollectionCleared(ByVal sender As Object, ByVal e As EventArgs)
AppointmentRowDictionary.Clear()
RowAppointmentDictionary.Clear()
End Sub
Private Sub schedulerStorage1_AppointmentsInserted(ByVal sender As Object, ByVal e As PersistentObjectsEventArgs)
Dim apts As AppointmentBaseCollection = CType(e.Objects, AppointmentBaseCollection)
For Each apt As Appointment In apts
Dim row As DataRow = GetAppointmentRow(apt)
RegisterAppointmentRow(row, apt)
Next
End Sub
Private Sub schedulerStorage1_AppointmentsDeleted(ByVal sender As Object, ByVal e As PersistentObjectsEventArgs)
Dim apts As AppointmentBaseCollection = CType(e.Objects, AppointmentBaseCollection)
For Each apt As Appointment In apts
Dim row As DataRow = CType(RowAppointmentDictionary(apt), DataRow)
AppointmentRowDictionary.Remove(row)
RowAppointmentDictionary.Remove(apt)
Next
End Sub
Private Sub RegisterAppointmentRows(ByVal apts As AppointmentBaseCollection)
For Each apt As Appointment In apts
Dim row As DataRow = GetAppointmentRow(apt)
RegisterAppointmentRow(row, apt)
Next
End Sub
Private Sub RegisterAppointmentRow(ByVal row As DataRow, ByVal apt As Appointment)
If Not AppointmentRowDictionary.ContainsKey(row) Then
AppointmentRowDictionary.Add(row, apt)
End If
If Not RowAppointmentDictionary.ContainsKey(apt) Then
RowAppointmentDictionary.Add(apt, row)
End If
End Sub
Private Function GetAppointmentRow(ByVal apt As Appointment) As DataRow
Return CType(schedulerStorage1.GetObjectRow(apt), DataRowView).Row
End Function
Protected Function FindAppointmentByRow(ByVal row As DataRow) As Appointment
If AppointmentRowDictionary.ContainsKey(row) Then
Return AppointmentRowDictionary(row)
Else
Return Nothing
End If
End Function
Private Sub dataGridView1_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
UpdateLabelVisible(False)
If dataGridView1.SelectedRows.Count <> 0 Then
Dim rowIndex As Integer = dataGridView1.Rows.IndexOf(dataGridView1.SelectedRows(0))
Dim row As DataRow = carsDBDataSet.CarScheduling.Rows(rowIndex)
Dim apt As Appointment = FindAppointmentByRow(row)
schedulerControl1.Services.AppointmentSelection.ClearSelection()
If apt IsNot Nothing Then
If apt.Type = AppointmentType.Pattern OrElse apt.Type = AppointmentType.DeletedOccurrence Then
UpdateLabelVisible(True)
Return
End If
schedulerControl1.ActiveView.SelectAppointment(apt)
End If
End If
End Sub
Private Sub schedulerControl1_Click(ByVal sender As Object, ByVal e As EventArgs)
UpdateLabelVisible(False)
End Sub
Private Sub UpdateLabelVisible(ByVal visible As Boolean)
lbNoAppointment.Visible = visible
End Sub
Private Sub dataGridView1_CellFormatting(ByVal sender As Object, ByVal e As DataGridViewCellFormattingEventArgs)
If Equals(dataGridView1.Columns(e.ColumnIndex).DataPropertyName, "EventType") Then e.Value = CType(Convert.ToInt32(e.Value), AppointmentType).ToString()
End Sub
Private Sub dataGridView1_CellValueNeeded(ByVal sender As Object, ByVal e As DataGridViewCellValueEventArgs)
If Equals(dataGridView1.Columns(e.ColumnIndex).Name, "Number") Then e.Value = e.RowIndex
End Sub
End Class
End Namespace