-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListUser.vb
More file actions
142 lines (123 loc) · 4.8 KB
/
ListUser.vb
File metadata and controls
142 lines (123 loc) · 4.8 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
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
Public Class ListUser
Private isAddNew As Boolean
Private recordId As Integer
Private Sub InsertState()
ButtonTambah.Enabled = False
ButtonHapus.Enabled = False
ButtonUbah.Enabled = False
ButtonSimpan.Enabled = True
isAddNew = True
End Sub
Private Sub EditState()
ButtonTambah.Enabled = True
ButtonHapus.Enabled = True
ButtonUbah.Enabled = False
ButtonSimpan.Enabled = True
isAddNew = False
End Sub
Private Sub ViewState()
ButtonTambah.Enabled = True
ButtonHapus.Enabled = False
ButtonUbah.Enabled = True
ButtonSimpan.Enabled = False
End Sub
Private Sub SetControl(ByVal value As Boolean)
For Each control As Control In From control1 As Control In SplitContainer1.Panel1.Controls Where Not (TypeOf control1 Is Button) And Not (TypeOf control1 Is Label)
control.Enabled = value
Next
End Sub
Private Sub LoadList()
DataGridView1.DataSource = UserBusinessObject.GetList()
End Sub
Private Sub ClearAllField()
For Each control As Control In From control1 As Control In SplitContainer1.Panel1.Controls Where (TypeOf control1 Is TextBox)
control.Text = ""
Next
End Sub
Private Sub LoadRecord()
If DataGridView1.CurrentRow Is Nothing Then
Return
End If
recordId = Convert.ToInt32(DataGridView1.CurrentRow.Cells("ID").Value)
Dim kelas = UserBusinessObject.GetUser(recordId)
If kelas Is Nothing Then
Return
End If
TextBoxUserName.Text = kelas.Username
TextBoxPassword.Text = kelas.Password
TextBoxReTypePassword.Text = kelas.Password
SetControl(False)
End Sub
Private Sub ButtonTambahClick(ByVal sender As System.Object, ByVal e As EventArgs) Handles ButtonTambah.Click
InsertState()
ClearAllField()
SetControl(True)
End Sub
Private Sub ButtonUbahClick(ByVal sender As System.Object, ByVal e As EventArgs) Handles ButtonUbah.Click
EditState()
SetControl(True)
End Sub
Private Sub ButtonSimpanClick(ByVal sender As System.Object, ByVal e As EventArgs) Handles ButtonSimpan.Click
If isAddNew Then
InsertUser()
Else
UpdateUser()
End If
End Sub
Private Sub UpdateUser()
If MessageBox.Show(Me, "Update data username " + TextBoxUserName.Text + " ?", "Konfirmasi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then
Return
End If
Try
Dim muser As New MasterUser
PopulateUser(muser)
muser.ID = recordId
UserBusinessObject.UpdateUser(muser)
LoadList()
Catch ex As Exception
MessageBox.Show(Me, GetMessage(ex), "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub InsertUser()
If MessageBox.Show(Me, "Simpan data username " + TextBoxUserName.Text + " ?", "Konfirmasi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then
Return
End If
Try
Dim muser As New MasterUser
PopulateUser(muser)
UserBusinessObject.InsertUser(muser)
LoadList()
Catch ex As Exception
MessageBox.Show(Me, GetMessage(ex), "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub PopulateUser(ByVal masterUser As MasterUser)
With masterUser
.IsAdministrator = CheckBoxAdministrator.Checked
.Password = TextBoxPassword.Text
.Username = TextBoxUserName.Text
End With
End Sub
Private Sub ButtonHapusClick(ByVal sender As System.Object, ByVal e As EventArgs) Handles ButtonHapus.Click
If MessageBox.Show(Me, "Hapus data username " + TextBoxUserName.Text + " ?", "Konfirmasi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then
Return
End If
Try
UserBusinessObject.DeleteUser(recordId)
LoadList()
Catch ex As Exception
MessageBox.Show(Me, GetMessage(ex), "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub ButtonRefreshClick(ByVal sender As System.Object, ByVal e As EventArgs) Handles ButtonRefresh.Click
LoadList()
End Sub
Private Sub ListUserLoad(ByVal sender As System.Object, ByVal e As EventArgs) Handles MyBase.Load
LoadList()
AddHandler DataGridView1.SelectionChanged, AddressOf DataGridViewSelectionChanged
End Sub
Private Sub DataGridViewSelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
ViewState()
LoadRecord()
End Sub
End Class