Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Data.OleDb
- Public Class FUsers
- Sub Kosongkan()
- txtUser.Clear()
- TxtPassword.Clear()
- txtNama.Clear()
- cboStatus.Text = ""
- txtUser.Focus()
- Call TampilStatus_user()
- Call TampilGrid()
- End Sub
- Sub TampilGrid()
- DA = New OleDbDataAdapter("select * from Users", Conn)
- DS = New DataSet
- DA.Fill(DS)
- DGV.DataSource = DS.Tables(0)
- dgv.Columns(0).HeaderText = "User Name"
- dgv.Columns(1).HeaderText = "Password"
- dgv.Columns(2).HeaderText = "Nama User"
- dgv.Columns(3).HeaderText = "Status"
- dgv.ReadOnly = True
- End Sub
- Sub DataBaru()
- 'txtUser.Clear()
- cboStatus.Text = ""
- TxtPassword.Clear()
- txtNama.Focus()
- End Sub
- Sub Ketemu()
- txtUser.Text = DR.Item("IdUser")
- TxtPassword.Text = DR.Item("Password")
- txtNama.Text = DR.Item("Nama")
- cboStatus.Text = DR.Item("Status")
- txtNama.Focus()
- End Sub
- Sub TampilStatus_user()
- CMD = New OleDbCommand("select distinct Status from Users", Conn)
- DR = CMD.ExecuteReader
- cboStatus.Items.Clear()
- Do While DR.Read
- cboStatus.Items.Add(DR.Item("Status"))
- Loop
- End Sub
- Private Sub FUsers_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Call Koneksi()
- Call Kosongkan()
- End Sub
- Private Sub btnBatal_Click(sender As Object, e As EventArgs) Handles btnBatal.Click
- Call Kosongkan()
- End Sub
- Private Sub btnSimpan_Click(sender As Object, e As EventArgs) Handles btnSimpan.Click
- CMD = New OleDbCommand("select IdUser from Users where IdUser='" & txtUser.Text & "'", Conn)
- DR = CMD.ExecuteReader
- DR.Read()
- Try
- If Not DR.HasRows Then
- Dim simpan As String = "insert into Users values ('" & txtUser.Text & "','" & TxtPassword.Text & "','" & txtNama.Text & "','" & cboStatus.Text & "')"
- CMD = New OleDbCommand(simpan, Conn)
- CMD.ExecuteNonQuery()
- Else
- Dim edit As String = "update Users set [Password]='" & TxtPassword.Text & "', [Nama]='" & txtNama.Text & "', [Status]='" & cboStatus.Text & "' where IdUser='" & txtUser.Text & "' "
- CMD = New OleDbCommand(edit, Conn)
- CMD.ExecuteNonQuery()
- End If
- Catch ex As Exception
- MsgBox(ex.ToString)
- End Try
- Call Kosongkan()
- End Sub
- Private Sub dgv_CellMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgv.CellMouseClick
- Try
- txtUser.Text = dgv.Rows(e.RowIndex).Cells(0).Value
- TxtPassword.Text = dgv.Rows(e.RowIndex).Cells(1).Value
- txtNama.Text = dgv.Rows(e.RowIndex).Cells(2).Value
- cboStatus.Text = dgv.Rows(e.RowIndex).Cells(3).Value
- Catch ex As Exception
- MsgBox(ex.Message)
- End Try
- End Sub
- Private Sub btnHapus_Click(sender As Object, e As EventArgs) Handles btnHapus.Click
- Try
- If txtUser.Text = "" Then
- MsgBox("User harus diisi")
- txtUser.Focus()
- Exit Sub
- End If
- If MessageBox.Show("yakin akan dihapus..?", "", MessageBoxButtons.YesNo) = DialogResult.Yes Then
- Dim hapus As String = "delete * from Users where IdUser='" & txtUser.Text & "'"
- CMD = New OleDbCommand(hapus, Conn)
- CMD.ExecuteNonQuery()
- Call Kosongkan()
- Else
- Call Kosongkan()
- End If
- Catch ex As Exception
- MsgBox(ex.Message)
- End Try
- End Sub
- Private Sub txtUser_LostFocus(sender As Object, e As EventArgs) Handles txtUser.LostFocus
- Try
- CMD = New OleDbCommand("select * from Users where IdUser='" & txtUser.Text & "'", Conn)
- DR = CMD.ExecuteReader
- DR.Read()
- If Not DR.HasRows Then
- Call DataBaru()
- Else
- Call Ketemu()
- End If
- Catch ex As Exception
- MsgBox(ex.Message)
- End Try
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement