-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.vb
148 lines (136 loc) · 5.62 KB
/
admin.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
140
141
142
143
144
145
146
147
148
Imports System.Data.Odbc
Public Class admin
Dim selectedAdminID, level As String
Dim DGVResetPasswordColumnButton As New DataGridViewButtonColumn
Sub showData()
dbconnection()
da = New OdbcDataAdapter("SELECT * FROM admin", conn)
ds = New DataSet
da.Fill(ds, "admin")
AdminDataGridView.DataSource = ds.Tables("admin")
conn.Close()
End Sub
Sub DGVButton()
DGVDeleteColumnButton.Name = "DGVDeleteColumnButton"
DGVDeleteColumnButton.HeaderText = ""
DGVDeleteColumnButton.FlatStyle = FlatStyle.Popup
DGVDeleteColumnButton.DefaultCellStyle.ForeColor = Color.Red
DGVDeleteColumnButton.Text = "Delete"
DGVDeleteColumnButton.Width = 50
DGVDeleteColumnButton.UseColumnTextForButtonValue = True
AdminDataGridView.Columns.Add(DGVDeleteColumnButton)
DGVEditColumnButton.Name = "DGVEditColumnButton"
DGVEditColumnButton.HeaderText = ""
DGVEditColumnButton.FlatStyle = FlatStyle.Popup
DGVEditColumnButton.DefaultCellStyle.ForeColor = Color.DarkGreen
DGVEditColumnButton.Text = "Edit"
DGVEditColumnButton.Width = 50
DGVEditColumnButton.UseColumnTextForButtonValue = True
AdminDataGridView.Columns.Add(DGVEditColumnButton)
End Sub
Sub SetDGVHeader()
AdminDataGridView.Columns(0).HeaderText = "ID"
AdminDataGridView.Columns(1).HeaderText = "Name"
AdminDataGridView.Columns(2).HeaderText = "Username"
AdminDataGridView.Columns(3).HeaderText = "Password"
AdminDataGridView.Columns(4).HeaderText = "Level"
End Sub
Sub DeleteRecord(param As String)
If MessageBox.Show("Are you sure want to delete admin with username '" & param & "'?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
dbconnection()
command = "DELETE FROM admin WHERE id='" & param & "'"
query = New OdbcCommand(command, conn)
query.ExecuteNonQuery()
If MessageBox.Show("Admin Deleted", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information) = DialogResult.OK Then
showData()
End If
End If
conn.Close()
End Sub
Sub UpdateRecord(param As String)
admindetail.Show()
admindetail.Text = "Edit Admin Information"
admindetail.SaveButton.Text = "Update"
admindetail.PasswordLabel.Text = "New Password"
admindetail.UsernameTextBox.Enabled = False
'Load employee old data
dbconnection()
command = "SELECT * FROM admin WHERE id='" & param & "'"
query = New OdbcCommand(command, conn)
reader = query.ExecuteReader()
While reader.Read()
If reader.HasRows Then
admindetail.NameTextBox.Text = reader.Item("name")
admindetail.UsernameTextBox.Text = reader.Item("username")
admindetail.PasswordTextBox.Text = reader.Item("password")
level = reader.Item("level")
If level = "cashier" Then
admindetail.CashierRadioButton.Checked = True
Else
admindetail.AdminRadioButton.Checked = True
End If
End If
End While
conn.Close()
End Sub
Private Sub SearchTextBox_TextChanged(sender As Object, e As EventArgs) Handles SearchTextBox.TextChanged
If SearchTextBox.Text = "" Then
Timer.Enabled = True
Else
Timer.Enabled = False
End If
dbconnection()
command = "SELECT * FROM admin WHERE name LIKE '%' '" & SearchTextBox.Text & "' '%' OR username LIKE '%' '" & SearchTextBox.Text & "' '%' OR id LIKE '%' '" & SearchTextBox.Text & "'"
da = New OdbcDataAdapter(command, conn)
ds = New DataSet
da.Fill(ds, "admin")
AdminDataGridView.DataSource = ds.Tables("admin")
If AdminDataGridView.RowCount > 0 Then
Dim row As Integer
With AdminDataGridView
row = .CurrentRow.Index
selectedAdminID = .Item(0, row).Value
End With
End If
conn.Close()
End Sub
Private Sub admin_Load(sender As Object, e As EventArgs) Handles MyBase.Load
showData()
DGVButton()
SetDGVHeader()
End Sub
Private Sub AddAdminButton_Click(sender As Object, e As EventArgs) Handles AddAdminButton.Click
admindetail.Show()
Me.Hide()
End Sub
Private Sub BackButton_Click(sender As Object, e As EventArgs) Handles BackButton.Click
main.Show()
Me.Dispose()
End Sub
Private Sub admin_Closed(sender As Object, e As EventArgs) Handles Me.Closed
Me.Dispose()
main.Show()
End Sub
Private Sub Timer_Tick(sender As Object, e As EventArgs) Handles Timer.Tick
AdminDataGridView.Columns.Clear()
showData()
SetDGVHeader()
DGVButton()
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub AdminDataGridView_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles AdminDataGridView.CellClick
If AdminDataGridView.RowCount > 0 Then
Dim row As Integer
With AdminDataGridView
row = .CurrentRow.Index
selectedAdminID = .Item(0, row).Value
If e.ColumnIndex = 6 Then
DeleteRecord(selectedAdminID)
ElseIf e.ColumnIndex = 7 Then
UpdateRecord(selectedAdminID)
End If
End With
End If
End Sub
End Class