4.3.1.5 User Interface Detail Data User
Untuk mengakses dan memanipulasi data user, administrator harus masuk ke user interface detail data user dengan cara memilih sub menu User yang
terdapat pada menu Data. Gambar 4.8 merupakan halaman detail data user untuk bagian admnistrator.
Gambar 4.8 Halaman Detail Data User
Halaman ini menampilkan user name, password, dan bagian dari user dalam bentuk form data grid. Pada halaman detail data user ini juga terdapat tombol Add
yang berfungsi untuk menambah data user, tombol Edit yang berfungsi untuk mengupdate data user, tombol Delete yang berfungsi untuk menghapus data user,
tombol Refresh yang berfungsi untuk menampilkan keseluruhan data user yang ada di database, dan tombol Exit yang berfungsi untuk keluar dari program.
Halaman detail data user ini juga dilengkapi dengan dengan fasilitas pencarian PLAGIAT MERUPAKAN TINDAKAN TIDAK TERPUJI
user dengan kategori pencarian berdasarkan user name dan bagian. Berikut ini adalah perintah untuk user interface halaman detail data user.
Imports System.Data
Imports System.Data.SqlClient
Public Class frmDetailUser
Inherits System.Windows.Forms.Form
Public Sub Data_Grid
Dim myConn
As SqlConnection
Dim daUser
As SqlDataAdapter
Dim dsUser
As DataSet
myConn = Database myConn.Open
Dim sqlselect
As String = Select User1.User_Name User
Name,User1.Password Password,ROLE.Role Bagian from User1,ROLE Where _
ROLE.Id_Role=User1.Id_Role daUser =
New SqlDataAdaptersqlselect, myConn
dsUser = New
DataSet daUser.FilldsUser, USER1
dgUser.DataSource = dsUser dgUser.DataMember = USER1
dgUser.ReadOnly = True
myConn.Close End Sub
Private Sub dgUser_DoubleClick
ByVal sender
As Object ,
ByVal e
As System.EventArgs
Handles dgUser.DoubleClick
If isEmptySelect User1.User_Name User
Name,User1.Password Password,ROLE.ROLE Bagian from User1,ROLE Where _
ROLE.Id_Role=User1.Id_Role order by User_Name Then
MsgBoxData kosong, MsgBoxStyle.Exclamation, Info ElseIf
dgUser.IsSelecteddgUser.CurrentRowIndex Then
Dim frmDataUser
As New frmdatauser
Dim myConn
As SqlConnection
Dim myReader
As SqlDataReader
myConn = Database myConn.Open
Dim sql
As String Try
sql = Select User1.User_Name,User1.Password,ROLE.ROLE from User1,ROLE Where
_ User1.User_Name=
TrimdgUser.ItemdgUser.CurrentRowIndex, 0 and ROLE.ID_ROLE=USER1.ID_ROLE
Dim command
As SqlCommand =
New SqlCommandsql,
myConn myReader = command.ExecuteReader
If myReader.HasRows
Then While
myReader.Read frmDataUser.txtUsername.Text =
myReader.ItemUSER_NAME frmDataUser.txtPassword.Text =
myReader.ItemPASSWORD frmDataUser.cmbBagian.Text =
myReader.ItemROLE frmDataUser.flag = 1
frmDataUser.txtUsername.Enabled = False
frmDataUser.btnAdd.Enabled = False
frmDataUser.ShowDialog End While
myReader.Close Else
Clear End If
Catch ex
As Exception
MsgBoxError: ex.Source : ex.Message, MsgBoxStyle.Critical, Koneksi Error
Finally myConn.Close
End Try Else
MsgBoxPilih Data Terlebih Dahulu, MsgBoxStyle.Exclamation, Info
End If End Sub
Private Sub btnAdd_Click
ByVal sender
As System.Object,
ByVal e
As System.EventArgs
Handles btnAdd.Click
Dim frmDataUser
As New frmdatauser
frmDataUser.btnEdit.Enabled = False
frmDataUser.btnDelete.Enabled = False
frmDataUser.txtUsername.Focus frmDataUser.Show
End Sub Private Sub
btnSearch_Click ByVal
sender As
System.Object, ByVal
e As
System.EventArgs Handles
btnSearch.Click Dim
myConn As
SqlConnection If
cmbKategori.Text = Then
MsgBoxMasukan Kategori Masih Kosong, MsgBoxStyle.Exclamation, Info
cmbKategori.Focus Else
myConn = Database myConn.Open
Dim sql
As String Try
If cmbKategori.Text = User Name
Then Dim
daUser As
SqlDataAdapter Dim
dsUser As
DataSet myConn = Database
myConn.Open Dim
sqlselect As String
= Select USER1.USER_NAME as [User Name],USER1.PASSWORD as
[Password],ROLE.ROLE as [Bagian] from USER1,ROLE Where _
USER1.USER_NAME like + txtSearch.Text + and ROLE.ID_ROLE=USER1.ID_ROLE order by
USER_NAME daUser =
New SqlDataAdaptersqlselect, myConn
dsUser = New
DataSet daUser.FilldsUser, USER1
dgUser.DataSource = dsUser dgUser.DataMember = User1
dgUser.ReadOnly = True
myConn.Close Else
Dim daUser
As SqlDataAdapter
Dim dsUser
As DataSet
myConn = Database myConn.Open
Dim sqlselect
As String = Select
USER1.USER_NAME as [User Name],USER1.PASSWORD as [Password],ROLE.ROLE as [Bagian] from USER1,ROLE Where _
ROLE.ROLE like + cmbCari.Text + and ROLE.ID_ROLE=USER1.ID_ROLE order by USER_NAME
daUser = New
SqlDataAdaptersqlselect, myConn dsUser =
New DataSet
daUser.FilldsUser, USER1 dgUser.DataSource = dsUser
dgUser.DataMember = USER1 dgUser.ReadOnly =
True myConn.Close
End If Catch
ex As
Exception MsgBoxError: ex.Source : ex.Message,
MsgBoxStyle.Critical, Koneksi Error Finally
myConn.Close End Try
End If End Sub
Private Sub btnDelete_Click
ByVal sender
As System.Object,
ByVal e
As System.EventArgs
Handles btnDelete.Click
If isEmptySelect USER1.USER_NAME as User
Name,USER1.PASSWORD as Password,ROLE.ROLE as Bagian from USER1,ROLE Where ROLE.ID_ROLE=USER1.ID_ROLE order by USER_NAME
Then MsgBoxData kosong, MsgBoxStyle.Exclamation
ElseIf dgUser.IsSelecteddgUser.CurrentRowIndex
Then Dim
myConn As
SqlConnection Try
myConn = Database myConn.Open
Dim deleteUsername
As String =
TrimdgUser.ItemdgUser.CurrentRowIndex, 0 If
MessageBox.ShowApakah anda yakin akan menghapus data TrimdgUser.ItemdgUser.CurrentRowIndex, 0
?, Info, MessageBoxButtons.YesNo, MessageBoxIcon.Question = DialogResult.Yes
Then
Dim sql
As String = Delete From USER1 _
Where USER_NAME= TrimdeleteUsername
Dim command
As SqlCommand =
New SqlCommandsql, myConn
Try Dim
status As Integer
= command.ExecuteNonQuery
If status = 1
Then MsgBoxHapus Data Berhasil,
MsgBoxStyle.Information, Konfirmasi Else
MsgBoxHapus Data Gagal, MsgBoxStyle.Critical, Konfirmasi
End If Data_Grid
Clear Catch
ex As
Exception MsgBoxError: ex.Source :
ex.Message, MsgBoxStyle.Critical, Koneksi Error End Try
Else Clear
End If Clear
Data_Grid Catch
ex As
Exception MsgBoxError: ex.Source : ex.Message,
MsgBoxStyle.Critical, Koneksi Error Clear
Finally myConn.Close
End Try Else
MsgBoxPilih Data Terlebih Dahulu, MsgBoxStyle.Exclamation, Info
End If End Sub
Private Sub btnRefresh_Click
ByVal sender
As System.Object,
ByVal e
As System.EventArgs
Handles btnRefresh.Click
Clear Data_Grid
End Sub Private Sub
btnEdit_Click ByVal
sender As
System.Object, ByVal
e As
System.EventArgs Handles
btnEdit.Click If
isEmptySelect USER1.USER_NAME as User Name,USER1.PASSWORD as Password,ROLE.ROLE as Bagian from
USER1,ROLE Where ROLE.ID_ROLE=USER1.ID_ROLE order by USER_NAME Then
MsgBoxData kosong, MsgBoxStyle.Exclamation ElseIf
dgUser.IsSelecteddgUser.CurrentRowIndex Then
Dim frmDataUser
As New frmdatauser
Dim myConn
As SqlConnection
Dim myReader
As SqlDataReader
myConn = Database myConn.Open
Dim sql
As String Try
sql = Select USER1.USER_NAME,USER1.PASSWORD,ROLE.ROLE from USER1,ROLE Where
_ USER1.USER_NAME=
TrimdgUser.ItemdgUser.CurrentRowIndex, 0 and ROLE.ID_ROLE=USER1.ID_ROLE
Dim command
As SqlCommand =
New SqlCommandsql,
myConn myReader = command.ExecuteReader
If myReader.HasRows
Then While
myReader.Read frmDataUser.txtUsername.Text =
myReader.ItemUSER_NAME frmDataUser.txtPassword.Text =
myReader.ItemPASSWORD frmDataUser.cmbBagian.Text =
myReader.ItemROLE frmDataUser.txtUsername.Enabled =
False frmDataUser.flag = 1
frmDataUser.btnAdd.Enabled = False
frmDataUser.ShowDialog End While
myReader.Close Else
Clear End If
Catch ex
As Exception
MsgBoxError: ex.Source : ex.Message, MsgBoxStyle.Critical, Koneksi Error
Finally myConn.Close
End Try Else
MsgBoxPilih Data Terlebih Dahulu, MsgBoxStyle.Exclamation, Info
End If End Sub
Private Sub btnMain_Click
ByVal sender
As System.Object,
ByVal e
As System.EventArgs
Dim frmMenuUtama
As New frmUtama
frmMenuUtama.Show Me
.Hide End Sub
Private Sub btnExit_Click
ByVal sender
As System.Object,
ByVal e
As System.EventArgs
Handles btnExit.Click
End End Sub
Jika tombol Add ditekan maka akan tampil halaman data user. Halaman ini digunakan untuk memasukkan data user baru. Gambar 4.9 merupakan user
interface halaman input data user.
Gambar 4.9 Halaman Data User
Berikut ini adalah perintah untuk user interface halaman data user:
Imports System.Data
Imports System.Data.SqlClient
Public Class frmdatauser
Inherits System.Windows.Forms.Form
Public flag
As Integer Private Sub
btnAdd_Click ByVal
sender As
System.Object, ByVal
e As
System.EventArgs Handles
btnAdd.Click Try
Dim myConn
As SqlConnection
Dim myReader
As SqlDataReader
myConn = Database myConn.Open
If txtUsername.Text =
Then MsgBoxSilahkan masukkan User Name anda,
MsgBoxStyle.Information, Info txtPassword.Clear
txtUsername.Focus ElseIf
txtPassword.Text = Then
MsgBoxSilahkan masukkan Password anda,
MsgBoxStyle.Information, Info txtPassword.Focus
ElseIf cmbBagian.SelectedItem =
Then MsgBoxSilahkan pilih Bagian anda,
MsgBoxStyle.Information, Info cmbBagian.Focus
Else Dim
ans = MsgBoxAnda yakin akan menambahkan data tersebut?, MsgBoxStyle.OKCancel, Konfirmasi
If ans = 1
Then Dim
User_Name As String
Dim sqlSelect
As String = Select USER_NAME
_ From USER1 Where USER_NAME =
TrimtxtUsername.Text Dim
comm As
SqlCommand = New
SqlCommandsqlSelect, myConn myReader = comm.ExecuteReader
If myReader.HasRows
Then While
myReader.Read User_Name = myReader.ItemUSER_NAME
End While End If
myReader.Close If
User_Name = txtUsername.Text Then
MessageBox.ShowData User TrimtxtUsername.Text sudah ada , Konfirmasi,
MessageBoxButtons.OK, MessageBoxIcon.Error Clear
Else Dim
sql As String
= Insert Into USER1USER_NAME,PASSWORD,ID_ROLE _
Values TrimtxtUsername.Text , TrimtxtPassword.Text ,
TrimcmbBagian.SelectedIndex + 1 Dim
command As
SqlCommand = New
SqlCommandsql, myConn Try
Dim status
As Integer =
command.ExecuteNonQuery If
status = 1 Then
MessageBox.ShowData User TrimtxtUsername.Text telah ditambahkan, Konfirmasi,
MessageBoxButtons.OK, MessageBoxIcon.Information Clear
Else MessageBox.ShowData User
TrimtxtUsername.Text gagal ditambahkan, Konfirmasi, MessageBoxButtons.OK, MessageBoxIcon.Error
End If
Catch ex
As Exception
MsgBoxError: ex.Source : ex.Message, MsgBoxStyle.OKOnly, Koneksi Error
Clear End Try
End If End If
myConn.Close End If
Catch ex
As Exception
MsgBoxError: ex.Source : ex.Message, MsgBoxStyle.OKOnly, Koneksi Error
End Try End Sub
Private Sub btnEdit_Click
ByVal sender
As System.Object,
ByVal e
As System.EventArgs
Handles btnEdit.Click
Try Dim
myConn As
SqlConnection Dim
myReader As
SqlDataReader Dim
role_id As String
myConn = Database myConn.Open
If txtUsername.Text =
Then MsgBoxSilahkan masukkan User Name anda,
MsgBoxStyle.Information, Info txtPassword.Clear
txtUsername.Focus ElseIf
txtPassword.Text = Then
MsgBoxSilahkan masukkan Password anda, MsgBoxStyle.Information, Info
txtPassword.Focus ElseIf
cmbBagian.SelectedItem = Then
MessageBox.ShowSilahkan masukkan Bagian, MsgBoxStyle.Information, Info
txtPassword.Focus Else
Dim sqlSelect
As String = Select ID_ROLE _
From ROLE Where ROLE.ROLE= cmbBagian.Text Dim
comm As
SqlCommand = New
SqlCommandsqlSelect, myConn
myReader = comm.ExecuteReader If
myReader.HasRows Then
While myReader.Read
role_id = myReader.ItemID_ROLE End While
End If myReader.Close
If flag = 0
Then Dim
sql As String
= Insert into USER1 Set _
PASSWORD= txtPassword.Text ,ID_ROLE= TrimcmbBagian.SelectedIndex + 1 _
Where USER_NAME= txtUsername.Text Dim
command As
SqlCommand = New
SqlCommandsql, myConn Dim
status As Integer
= command.ExecuteNonQuery
If status = 1
Then MsgBoxTambah data berhasil,
MsgBoxStyle.Information, Info Clear
Else MsgBoxTambah data gagal,
MsgBoxStyle.Critical, Info End If
Else Dim
sql As String
sql = Update USER1 Set _ PASSWORD= txtPassword.Text
,ID_ROLE= TrimcmbBagian.SelectedIndex + 1 _ Where USER_NAME= txtUsername.Text
Dim command
As SqlCommand =
New SqlCommandsql, myConn
Dim status
As Integer =
command.ExecuteNonQuery If
status = 1 Then
MsgBoxUpdate Data Berhasil, MsgBoxStyle.Information, Info
Me .Close
Else MsgBoxUpdate Data Gagal,
MsgBoxStyle.Critical, Info End If
End If Clear
End If myConn.Close
Catch ex
As Exception
MsgBoxError: ex.Source : ex.Message, MsgBoxStyle.OKOnly, Koneksi Error
Clear End Try
End Sub Private Sub
btnClear_Click ByVal
sender As
System.Object, ByVal
e As
System.EventArgs Handles
btnClear.Click Clear
End Sub Private Sub
btnExit_Click ByVal
sender As
System.Object, ByVal
e As
System.EventArgs Dim
form As New
Welcome form.Show
Me .Close
End Sub
Private Sub btnDelete_Click
ByVal sender
As System.Object,
ByVal e
As System.EventArgs
Handles btnDelete.Click
Try Dim
myConn As
SqlConnection myConn = Database
myConn.Open Dim
ans = MsgBoxApakah anda yakin akan menghapus data txtUsername.Text ?, MessageBoxButtons.OKCancel,
Konfirmasi If
ans = 1 Then
Dim sql
As String = Delete From USER1 _
Where USER_NAME= txtUsername.Text Dim
command As
SqlCommand = New
SqlCommandsql, myConn
Try Dim
status As Integer
= command.ExecuteNonQuery
If status = 1
Then MsgBoxHapus data berhasil,
MsgBoxStyle.OKOnly, Info Else
MsgBoxHapus data gagal, MsgBoxStyle.OKCancel, Info
End If Clear
Catch ex
As Exception
MsgBoxError: ex.Source : ex.Message, MsgBoxStyle.OKOnly, Koneksi Error
Clear End Try
Else Clear
End If myConn.Close
Catch ex
As Exception
MsgBoxError: ex.Source : ex.Message, MsgBoxStyle.OKOnly, Koneksi Error
Clear End Try
End Sub End Class
4.3.1.6 User Interface Detail Data Perusahaan.