-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewStudentForm.vb
More file actions
38 lines (31 loc) · 1.46 KB
/
NewStudentForm.vb
File metadata and controls
38 lines (31 loc) · 1.46 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
Public Class NewStudentForm
Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
Dim n = NameTextBox.Text
Dim s = SurnameTextBox.Text
Dim no = NoTextBox.Text
Dim isSuccess =
DB.ExecuteNonQuery("INSERT INTO Students ([No], [Name], [Surname]) VALUES(" & no & ", '" & n & "','" & s & "')")
If isSuccess Then
Me.DialogResult = DialogResult.OK
Me.Close()
End If
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 NameTextBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles NameTextBox.KeyPress
e.Handled = BlockKey(e.KeyChar)
End Sub
Private Sub SurnameTextBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles SurnameTextBox.KeyPress
e.Handled = BlockKey(e.KeyChar)
End Sub
Private Sub NoTextBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles NoTextBox.KeyPress
e.Handled = BlockKey(e.KeyChar, True)
End Sub
Private Function BlockKey(key As Char, Optional numberRequired As Boolean = False) As Boolean
Return key <> ChrW(Keys.Back) And
((numberRequired And Not Char.IsNumber(key)) Or
(Not numberRequired And Char.IsNumber(key)))
End Function
End Class