1. FPetugas
Imports MySql.Data.MySqlClient
Public Class FPetugas
Dim conn As New Koneksi
Dim msql As String
Sub simpan()
msql = "SELECT*FROM petugas where kodepts =’" & Trim(TextBoxKdPts.Text) & "‘"
Try
CMD = New MySqlCommand(msql, conn.konek)
DTreader = CMD.ExecuteReader()
If DTreader.HasRows Then
MessageBox.Show("Kode Petugas sudah ada ", "error", MessageBoxButtons.OK, MessageBoxIcon.Information)
DTreader.Close()
conn.konek.Close()
Exit Sub
Else
DTreader.Close()
End If
Try
msql = "insert into petugas(kodepts,namapts,alamatpts,nohp,kelamin)" & _
"values(‘" & Me.TextBoxKdPts.Text & "‘," & _
"‘" & Me.TextBoxNamaPts.Text & "‘," & _
"‘" & Me.TextBoxAlamatPts.Text & "‘," & _
"‘" & Me.TextBoxNoHp.Text & "‘," & _
"‘" & Me.ComboBoxKelamin.Text & "‘)"
CMD = New MySqlCommand(msql, conn.konek)
CMD.ExecuteNonQuery()
Call bersih()
Catch ex As Exception
MessageBox.Show("Data gagal disimpan ", "error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Catch ex As Exception
End Try
End Sub
Sub bersih()
TextBoxKdPts.Clear()
TextBoxNamaPts.Clear()
TextBoxAlamatPts.Clear()
TextBoxNoHp.Clear()
ComboBoxKelamin.Text = "Laki-laki"
TextBoxKdPts.Focus()
End Sub
Sub periksainput()
If TextBoxKdPts.Text = "" Then
MessageBox.Show("Kode Petugas belum diisi")
TextBoxKdPts.Focus()
ElseIf TextBoxNamaPts.Text = "" Then
MessageBox.Show("Nama Petugas belum diisi")
TextBoxNamaPts.Focus()
ElseIf TextBoxAlamatPts.Text = "" Then
MessageBox.Show("Alamat belum diisi")
TextBoxAlamatPts.Focus()
ElseIf TextBoxNoHp.Text = "" Then
MessageBox.Show("No Hp belum diisi")
TextBoxNoHp.Focus()
ElseIf ComboBoxKelamin.Text = "" Then
MessageBox.Show("Jenis Kelamin belum diisi")
ComboBoxKelamin.Focus()
Else
Call simpan()
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
FormAwal.Show()
Me.Close()
FormAwal.Enabled = True
End Sub
Sub tampilData()
msql = " Select * From petugas order by kodepts asc"
DTtable.Clear()
DTtable = New DataTable
DTadapter = New MySqlDataAdapter(msql, conn.konek)
DTadapter.Fill(DTtable)
With Me.DataGridView1
.DataSource = DTtable
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.AllowUserToAddRows = False
End With
DTtable.Dispose()
DTadapter.Dispose()
conn.konek.Close()
End Sub
Sub Perbaikandata()
msql = "update petugas set namapts =’" & Trim(TextBoxNamaPts.Text) & "‘," & _
"alamatpts=’" & Trim(Me.TextBoxAlamatPts.Text) & "‘," & _
"nohp=’" & Trim(Me.TextBoxNoHp.Text) & "‘," & _
"kelamin=’" & Trim(Me.ComboBoxKelamin.Text) & "‘," & _
"kodepts=’" & Trim(Me.TextBoxKdPts.Text) & "‘ " & _
"where kodepts=’" & Trim(Me.TextBoxKdPts.Text) & "‘"
Try
CMD = New MySqlCommand(msql, conn.konek)
CMD.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show("Data gagal diperbaiki")
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call periksainput()
Call tampilData()
End Sub
Private Sub FPetugas_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call tampilData()
Call bersih()
FormAwal.Enabled = False
Button2.Enabled = False
Button3.Enabled = False
End Sub
Sub tampilkeform()
Me.TextBoxKdPts.Text = Me.DataGridView1.SelectedCells(0).Value
Me.TextBoxNamaPts.Text = Me.DataGridView1.SelectedCells(1).Value
Me.TextBoxAlamatPts.Text = Me.DataGridView1.SelectedCells(2).Value
Me.TextBoxNoHp.Text = Me.DataGridView1.SelectedCells(3).Value
Me.ComboBoxKelamin.Text = Me.DataGridView1.SelectedCells(4).Value
End Sub
Sub hapusdata()
msql = " delete From petugas where kodepts =’" & Trim(TextBoxKdPts.Text) & "‘"
Try
CMD = New MySqlCommand(msql, conn.konek)
CMD.ExecuteNonQuery()
Call bersih()
Catch ex As Exception
MessageBox.Show("Data gagal dihapus")
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Call Perbaikandata()
Call tampilData()
Call bersih()
Button1.Enabled = True
Button2.Enabled = False
Button3.Enabled = False
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Call hapusdata()
Call tampilData()
Call bersih()
Button3.Enabled = False
Button2.Enabled = False
Button1.Enabled = True
End Sub
Private Sub DataGridView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseClick
Call tampilkeform()
Button1.Enabled = False
Button2.Enabled = True
Button3.Enabled = True
End Sub
End Class