-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLessonSelectDialog.vb
More file actions
74 lines (57 loc) · 2.37 KB
/
LessonSelectDialog.vb
File metadata and controls
74 lines (57 loc) · 2.37 KB
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
Public Class LessonSelectDialog
Public Class LessonListItem
Public ID As Integer
Public Name As String
Public Sub New(id As Integer, name As String)
Me.ID = id
Me.Name = name
End Sub
Public Overrides Function ToString() As String
Return Me.Name
End Function
End Class
Dim StudentID As Integer
Public Sub New(studentID As Integer)
InitializeComponent()
Me.StudentID = studentID
UpdateLessonsList()
End Sub
Private Sub CancelActionButton_Click(sender As Object, e As EventArgs) Handles CancelActionButton.Click
Me.DialogResult = DialogResult.Cancel
Me.Close()
End Sub
Private Sub OkButton_Click(sender As Object, e As EventArgs) Handles OkButton.Click
Me.DialogResult = DialogResult.OK
Me.Close()
End Sub
Private Sub UpdateLessonsList(Optional nameSearch As String = Nothing)
LessonsList.Items.Clear()
Dim lessons As DataRowCollection
If nameSearch <> Nothing Then
nameSearch = nameSearch.Trim()
End If
If nameSearch = Nothing Or nameSearch = "" Then
lessons = GetDataTable("SELECT * FROM [Lessons] WHERE [ID] NOT IN
(SELECT [Lesson] FROM [StudentsLessons] WHERE [Student] = " & Me.StudentID & ")").Rows
Else
lessons = DB.GetDataTable("SELECT * FROM [Lessons] WHERE [ID] NOT IN
(SELECT [Lesson] FROM [StudentsLessons] WHERE [Student] = " & Me.StudentID & ")
AND Name LIKE '%" & nameSearch & "%'").Rows
End If
For Each row As DataRow In lessons
Dim id = row.Item("ID")
Dim name = row.Item("Name")
LessonsList.Items.Add(New LessonListItem(id, name))
Next
End Sub
Public Function SelectedLessonsIDs() As IEnumerable(Of Integer)
Dim ret = New List(Of Integer)
For Each item As LessonListItem In LessonsList.SelectedItems
ret.Add(item.ID)
Next
Return ret
End Function
Private Sub SearchTextBox_TextChanged(sender As Object, e As EventArgs) Handles SearchTextBox.TextChanged
UpdateLessonsList(SearchTextBox.Text)
End Sub
End Class