BAB IV. IMPLEMENTASI SISTEM
4.3 User Interface
4.3.1 User Interface Proses Transaksi Administrator
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
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 SqlDataAdapter(sqlselect, myConn) dsUser = New DataSet
daUser.Fill(dsUser, "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 isEmpty("Select 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
MsgBox("Data kosong", MsgBoxStyle.Exclamation, "Info")
ElseIf (dgUser.IsSelected(dgUser.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='" &
Trim(dgUser.Item(dgUser.CurrentRowIndex, 0)) & "' and ROLE.ID_ROLE=USER1.ID_ROLE"
Dim command As SqlCommand = New SqlCommand(sql, myConn)
myReader = command.ExecuteReader()
If myReader.HasRows Then While myReader.Read()
myReader.Item("USER_NAME") frmDataUser.txtPassword.Text = myReader.Item("PASSWORD") frmDataUser.cmbBagian.Text = myReader.Item("ROLE") 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
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.Critical, "Koneksi Error !!")
Finally
myConn.Close()
End Try
Else
MsgBox("Pilih 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
MsgBox("Masukan 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
" USER1.USER_NAME like '%" + txtSearch.Text + "%' and ROLE.ID_ROLE=USER1.ID_ROLE order by USER_NAME"
daUser = New SqlDataAdapter(sqlselect, myConn) dsUser = New DataSet
daUser.Fill(dsUser, "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 SqlDataAdapter(sqlselect, myConn) dsUser = New DataSet
daUser.Fill(dsUser, "USER1") dgUser.DataSource = dsUser dgUser.DataMember = ("USER1") dgUser.ReadOnly = True myConn.Close() End If Catch ex As Exception
MsgBox("Error: " & 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 isEmpty("Select 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
MsgBox("Data kosong", MsgBoxStyle.Exclamation)
ElseIf (dgUser.IsSelected(dgUser.CurrentRowIndex)) Then Dim myConn As SqlConnection
Try
myConn = Database() myConn.Open()
Dim deleteUsername As String = Trim(dgUser.Item(dgUser.CurrentRowIndex, 0))
If (MessageBox.Show("Apakah anda yakin akan
menghapus data " & Trim(dgUser.Item(dgUser.CurrentRowIndex, 0)) & " ?", "Info", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes) Then
Dim sql As String = "Delete From USER1" & _ " Where USER_NAME='" & Trim(deleteUsername) & "'"
Dim command As SqlCommand = New
SqlCommand(sql, myConn)
Try
Dim status As Integer = command.ExecuteNonQuery()
If status = 1 Then
MsgBox("Hapus Data Berhasil", MsgBoxStyle.Information, "Konfirmasi")
Else
MsgBox("Hapus Data Gagal", MsgBoxStyle.Critical, "Konfirmasi")
End If
Data_Grid() Clear()
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.Critical, "Koneksi Error !")
End Try Else Clear() End If Clear() Data_Grid() Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.Critical, "Koneksi Error !")
Clear()
Finally
myConn.Close()
End Try Else
MsgBox("Pilih 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 isEmpty("Select 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
MsgBox("Data kosong", MsgBoxStyle.Exclamation)
ElseIf (dgUser.IsSelected(dgUser.CurrentRowIndex)) Then Dim frmDataUser As New frmdatauser
Dim myConn As SqlConnection
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='" &
Trim(dgUser.Item(dgUser.CurrentRowIndex, 0)) & "' and ROLE.ID_ROLE=USER1.ID_ROLE"
Dim command As SqlCommand = New SqlCommand(sql, myConn) myReader = command.ExecuteReader() If myReader.HasRows Then While myReader.Read() frmDataUser.txtUsername.Text = myReader.Item("USER_NAME") frmDataUser.txtPassword.Text = myReader.Item("PASSWORD") frmDataUser.cmbBagian.Text = myReader.Item("ROLE") 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
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.Critical, "Koneksi Error !!")
Finally
myConn.Close()
End Try Else
MsgBox("Pilih 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
MsgBox("Silahkan masukkan User Name anda", MsgBoxStyle.Information, "Info")
txtPassword.Clear() txtUsername.Focus()
ElseIf txtPassword.Text = "" Then
MsgBoxStyle.Information, "Info") txtPassword.Focus()
ElseIf cmbBagian.SelectedItem = "" Then
MsgBox("Silahkan pilih Bagian anda", MsgBoxStyle.Information, "Info")
cmbBagian.Focus()
Else
Dim ans = MsgBox("Anda 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 ='" & Trim(txtUsername.Text) & "'"
Dim comm As SqlCommand = New
SqlCommand(sqlSelect, myConn) myReader = comm.ExecuteReader() If myReader.HasRows Then While myReader.Read() User_Name = myReader.Item("USER_NAME") End While End If myReader.Close()
If User_Name = txtUsername.Text Then
MessageBox.Show("Data User " & Trim(txtUsername.Text) & " sudah ada ", "Konfirmasi", MessageBoxButtons.OK, MessageBoxIcon.Error)
Clear()
Else
Dim sql As String = "Insert Into
USER1(USER_NAME,PASSWORD,ID_ROLE)" & _
" Values('" & Trim(txtUsername.Text) & "','" & Trim(txtPassword.Text) & "','" &
Trim(cmbBagian.SelectedIndex + 1) & "')"
Dim command As SqlCommand = New
SqlCommand(sql, myConn)
Try
Dim status As Integer = command.ExecuteNonQuery()
If status = 1 Then
MessageBox.Show("Data User " & Trim(txtUsername.Text) & " telah ditambahkan", "Konfirmasi", MessageBoxButtons.OK, MessageBoxIcon.Information)
Clear()
Else
MessageBox.Show("Data User " & Trim(txtUsername.Text) & " gagal ditambahkan", "Konfirmasi", MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Koneksi Error !!")
Clear() End Try End If End If myConn.Close() End If Catch ex As Exception
MsgBox("Error: " & 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
MsgBox("Silahkan masukkan User Name anda", MsgBoxStyle.Information, "Info")
txtPassword.Clear() txtUsername.Focus()
ElseIf txtPassword.Text = "" Then
MsgBox("Silahkan masukkan Password anda", MsgBoxStyle.Information, "Info")
txtPassword.Focus()
ElseIf cmbBagian.SelectedItem = "" Then
MessageBox.Show("Silahkan 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 SqlCommand(sqlSelect, myConn) myReader = comm.ExecuteReader() If myReader.HasRows Then While myReader.Read() role_id = myReader.Item("ID_ROLE") End While End If myReader.Close() If flag = 0 Then
Dim sql As String = " Insert into USER1 Set" & _
" PASSWORD='" & txtPassword.Text &
"',ID_ROLE='" & Trim(cmbBagian.SelectedIndex + 1) & "'" & _ " Where USER_NAME='" & txtUsername.Text & "'"
Dim command As SqlCommand = New
SqlCommand(sql, myConn)
Dim status As Integer = command.ExecuteNonQuery()
If status = 1 Then
MsgBox("Tambah data berhasil", MsgBoxStyle.Information, "Info")
Clear()
Else
MsgBox("Tambah data gagal", MsgBoxStyle.Critical, "Info")
End If Else
Dim sql As String
sql = "Update USER1 Set" & _
" PASSWORD='" & txtPassword.Text & "',ID_ROLE='" & Trim(cmbBagian.SelectedIndex + 1) & "'" & _
" Where USER_NAME='" & txtUsername.Text & "'"
Dim command As SqlCommand = New
SqlCommand(sql, myConn)
Dim status As Integer = command.ExecuteNonQuery()
If status = 1 Then
MsgBox("Update Data Berhasil", MsgBoxStyle.Information, "Info")
Me.Close()
Else
MsgBox("Update Data Gagal", MsgBoxStyle.Critical, "Info") End If End If Clear() End If myConn.Close() Catch ex As Exception
MsgBox("Error: " & 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()
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 = MsgBox("Apakah 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 SqlCommand(sql, myConn)
Try
Dim status As Integer = command.ExecuteNonQuery()
If status = 1 Then
MsgBox("Hapus data berhasil", MsgBoxStyle.OKOnly, "Info")
Else
MsgBox("Hapus data gagal", MsgBoxStyle.OKCancel, "Info")
End If
Clear()
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Koneksi Error !")
Clear() End Try Else Clear() End If myConn.Close() Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Koneksi Error !")
Clear()
End Try End Sub
End Class