Advertisement
binjeeclick

fuser

Nov 28th, 2018
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 4.15 KB | None | 0 0
  1. Imports System.Data.OleDb
  2. Public Class FUsers
  3.     Sub Kosongkan()
  4.         txtUser.Clear()
  5.         TxtPassword.Clear()
  6.         txtNama.Clear()
  7.         cboStatus.Text = ""
  8.         txtUser.Focus()
  9.         Call TampilStatus_user()
  10.         Call TampilGrid()
  11.     End Sub
  12.     Sub TampilGrid()
  13.         DA = New OleDbDataAdapter("select * from Users", Conn)
  14.         DS = New DataSet
  15.         DA.Fill(DS)
  16.         DGV.DataSource = DS.Tables(0)
  17.         dgv.Columns(0).HeaderText = "User Name"
  18.         dgv.Columns(1).HeaderText = "Password"
  19.         dgv.Columns(2).HeaderText = "Nama User"
  20.         dgv.Columns(3).HeaderText = "Status"
  21.         dgv.ReadOnly = True
  22.     End Sub
  23.     Sub DataBaru()
  24.         'txtUser.Clear()
  25.         cboStatus.Text = ""
  26.         TxtPassword.Clear()
  27.         txtNama.Focus()
  28.     End Sub
  29.     Sub Ketemu()
  30.         txtUser.Text = DR.Item("IdUser")
  31.         TxtPassword.Text = DR.Item("Password")
  32.         txtNama.Text = DR.Item("Nama")
  33.         cboStatus.Text = DR.Item("Status")
  34.         txtNama.Focus()
  35.     End Sub
  36.     Sub TampilStatus_user()
  37.         CMD = New OleDbCommand("select distinct Status from Users", Conn)
  38.         DR = CMD.ExecuteReader
  39.         cboStatus.Items.Clear()
  40.         Do While DR.Read
  41.             cboStatus.Items.Add(DR.Item("Status"))
  42.         Loop
  43.     End Sub
  44.     Private Sub FUsers_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  45.         Call Koneksi()
  46.         Call Kosongkan()
  47.     End Sub
  48.     Private Sub btnBatal_Click(sender As Object, e As EventArgs) Handles btnBatal.Click
  49.         Call Kosongkan()
  50.     End Sub
  51.  
  52.     Private Sub btnSimpan_Click(sender As Object, e As EventArgs) Handles btnSimpan.Click
  53.         CMD = New OleDbCommand("select IdUser from Users where IdUser='" & txtUser.Text & "'", Conn)
  54.         DR = CMD.ExecuteReader
  55.         DR.Read()
  56.         Try
  57.             If Not DR.HasRows Then
  58.                 Dim simpan As String = "insert into Users values ('" & txtUser.Text & "','" & TxtPassword.Text & "','" & txtNama.Text & "','" & cboStatus.Text & "')"
  59.                 CMD = New OleDbCommand(simpan, Conn)
  60.                 CMD.ExecuteNonQuery()
  61.             Else
  62.                 Dim edit As String = "update Users set [Password]='" & TxtPassword.Text & "', [Nama]='" & txtNama.Text & "', [Status]='" & cboStatus.Text & "' where IdUser='" & txtUser.Text & "' "
  63.                 CMD = New OleDbCommand(edit, Conn)
  64.                 CMD.ExecuteNonQuery()
  65.             End If
  66.         Catch ex As Exception
  67.             MsgBox(ex.ToString)
  68.         End Try
  69.         Call Kosongkan()
  70.     End Sub
  71.     Private Sub dgv_CellMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgv.CellMouseClick
  72.         Try
  73.             txtUser.Text = dgv.Rows(e.RowIndex).Cells(0).Value
  74.             TxtPassword.Text = dgv.Rows(e.RowIndex).Cells(1).Value
  75.             txtNama.Text = dgv.Rows(e.RowIndex).Cells(2).Value
  76.             cboStatus.Text = dgv.Rows(e.RowIndex).Cells(3).Value
  77.         Catch ex As Exception
  78.             MsgBox(ex.Message)
  79.         End Try
  80.     End Sub
  81.  
  82.     Private Sub btnHapus_Click(sender As Object, e As EventArgs) Handles btnHapus.Click
  83.         Try
  84.             If txtUser.Text = "" Then
  85.                 MsgBox("User harus diisi")
  86.                 txtUser.Focus()
  87.                 Exit Sub
  88.             End If
  89.             If MessageBox.Show("yakin akan dihapus..?", "", MessageBoxButtons.YesNo) = DialogResult.Yes Then
  90.                 Dim hapus As String = "delete * from Users where IdUser='" & txtUser.Text & "'"
  91.                 CMD = New OleDbCommand(hapus, Conn)
  92.                 CMD.ExecuteNonQuery()
  93.                 Call Kosongkan()
  94.             Else
  95.                 Call Kosongkan()
  96.             End If
  97.         Catch ex As Exception
  98.             MsgBox(ex.Message)
  99.         End Try
  100.     End Sub
  101.     Private Sub txtUser_LostFocus(sender As Object, e As EventArgs) Handles txtUser.LostFocus
  102.         Try
  103.             CMD = New OleDbCommand("select * from Users where IdUser='" & txtUser.Text & "'", Conn)
  104.             DR = CMD.ExecuteReader
  105.             DR.Read()
  106.             If Not DR.HasRows Then
  107.                 Call DataBaru()
  108.             Else
  109.                 Call Ketemu()
  110.             End If
  111.         Catch ex As Exception
  112.             MsgBox(ex.Message)
  113.         End Try
  114.     End Sub
  115. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement