100% found this document useful (1 vote)
150 views

Coding Petugas

This document contains code for managing petugas (staff) data in a database. It includes subroutines for clearing fields, entering new data, displaying data in a grid, and saving, editing, deleting, and closing records. The code handles opening connections, executing SQL statements, validating input, and controlling the flow between forms and fields.

Uploaded by

Yusman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
150 views

Coding Petugas

This document contains code for managing petugas (staff) data in a database. It includes subroutines for clearing fields, entering new data, displaying data in a grid, and saving, editing, deleting, and closing records. The code handles opening connections, executing SQL statements, validating input, and controlling the flow between forms and fields.

Uploaded by

Yusman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

//Coding Petugas

Imports System.Data.OleDb
Public Class Petugas
Sub Kosongkan()
TKode.Text = ""
TNama.Text = ""
TPassword.Text = ""
CBOStatus.Text = ""
TKode.Focus()
End Sub
Sub DataBaru()
TNama.Text = ""
TPassword.Text = ""
CBOStatus.Text = ""
TNama.Focus()
End Sub
Sub Tampilkan()
da = New OleDbDataAdapter("Select * from Petugas ORDER BY 1", Conn)
ds = New DataSet
ds.Clear()
da.Fill(ds, "Petugas")
DGV.DataSource = (ds.Tables("Petugas"))
DGV.ReadOnly = True
End Sub
Sub TampilstatusPTG()
CBOStatus.Items.Clear()
cmd = New OleDbCommand("select distinct statusPTG from Petugas",
Conn)
rd = cmd.ExecuteReader
While rd.Read
CBOStatus.Items.Add(rd.GetString(0))
End While
End Sub
Private Sub Petugas_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Call Koneksi()
Call Tampilkan()
CBOStatus.Items.Add("ADMINISTRATOR")
CBOStatus.Items.Add("OPERATOR")
CBOStatus.Items.Add("USER")
End Sub
Private Sub TKode_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TKode.KeyPress
If e.KeyChar = Chr(13) Then
TKode.Text = UCase(TKode.Text)
cmd = New OleDbCommand("select * from Petugas where kodePTG='"
& TKode.Text & "'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows = True Then
TNama.Text = rd.GetString(1)
TPassword.Text = rd.GetString(2)

CBOStatus.Text = rd.GetString(3)
TNama.Focus()
Else
Call DataBaru()
TNama.Focus()
End If
End If
End Sub
Private Sub TNama_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TNama.KeyPress
If e.KeyChar = Chr(13) Then
TPassword.Focus()
TNama.Text = UCase(TNama.Text)
End If
End Sub
Private Sub TPassword_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TPassword.KeyPress
If e.KeyChar = Chr(13) Then CBOStatus.Focus()
End Sub
Private Sub CmbStatus_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles CBOStatus.KeyPress
If e.KeyChar = Chr(13) Then CmdSimpan.Focus()
End Sub
Private Sub CmdSimpan_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles CmdSimpan.Click
If TKode.Text = "" Or TNama.Text = "" Or TPassword.Text = "" Or
CBOStatus.Text = "" Then
MsgBox("Data Belum Lengkap")
Exit Sub
Else
cmd = New OleDbCommand("Select * from Petugas where kodePTG='"
& TKode.Text & "'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If Not rd.HasRows Then
Dim sqltambah As String = "Insert into
Petugas(kodePTG,namaPTG,PasswordPTG,StatusPTG) values " & _
"('" & TKode.Text & "','" & TNama.Text & "','" &
TPassword.Text & "','" & CBOStatus.Text & "')"
cmd = New OleDbCommand(sqltambah, Conn)
cmd.ExecuteNonQuery()
Call Kosongkan()
Call Tampilkan()
Else
Dim sqledit As String = "Update Petugas set " & _
"NamaPTG='" & TNama.Text & "', " & _
"PasswordPTG='" & TPassword.Text & "', " & _
"StatusPTG='" & CBOStatus.Text & "' where kodePTG='" &
TKode.Text & "'"
cmd = New OleDbCommand(sqledit, Conn)
cmd.ExecuteNonQuery()
Call Kosongkan()

Call Tampilkan()
End If
End If
End Sub
Private Sub CmdBatal_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles CmdBatal.Click
Call Kosongkan()
End Sub
Private Sub CmdTutup_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles CmdTutup.Click
Me.Close()
End Sub
Private Sub CmdHapus_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles CmdHapus.Click
If TKode.Text = "" Then
MsgBox("Isi kode Petugas terlebih dahulu")
TKode.Focus()
Exit Sub
Else
If MessageBox.Show("Yakin akan dihapus..?", "",
MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
cmd = New OleDbCommand("Delete * from Petugas where
kodePTG='" & TKode.Text & "'", Conn)
cmd.ExecuteNonQuery()
Call Kosongkan()
Call Tampilkan()
Else
Call Kosongkan()
End If
End If
End Sub
End Class

You might also like