You are on page 1of 5

Public kode As String = ""

Sub buatkolom()
DataGridView1.Columns(0).HeaderText = "ID"
DataGridView1.Columns(1).HeaderText = "Tahun"
DataGridView1.Columns(2).HeaderText = "Nominal"
End Sub

Sub tampil()
Try
adapter = New MySql.Data.MySqlClient.MySqlDataAdapter("select
id_spp,tahun,nominal from spp", conn)
ds = New DataSet
adapter.Fill(ds, "spp")
DataGridView1.DataSource = ds.Tables(0)
Call buatkolom()
Catch ex As Exception
End Try
End Sub
Sub cari()
Try
adapter = New MySql.Data.MySqlClient.MySqlDataAdapter("select
id_spp,tahun,nominal from spp where tahun like '%" & TextBox1.Text & "%' ", conn)
ds = New DataSet
adapter.Fill(ds, "kelas")
DataGridView1.DataSource = ds.Tables(0)
Call buatkolom()
Catch ex As Exception
End Try
End Sub

Sub urutasc()
Try
adapter = New MySql.Data.MySqlClient.MySqlDataAdapter("select
id_spp,tahun,nominal from spp order by id_spp asc", conn)
ds = New DataSet
adapter.Fill(ds, "spp")
DataGridView1.DataSource = ds.Tables(0)
Call buatkolom()
Catch ex As Exception
End Try
End Sub

Sub urutdesc()
Try
adapter = New MySql.Data.MySqlClient.MySqlDataAdapter("select
id_spp,tahun,nominal from spp order by id_spp desc", conn)
ds = New DataSet
adapter.Fill(ds, "spp")
DataGridView1.DataSource = ds.Tables(0)
Call buatkolom()
Catch ex As Exception
End Try
End Sub

Sub proses()
TextBox1.Text = ""
RadioButton1.Checked = False
RadioButton2.Checked = False
TextBox2.Text = ""
TextBox2.Enabled = False
TextBox3.Text = ""
TextBox3.Enabled = False
Button1.Enabled = True
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = True
Button6.Enabled = True
End Sub
Sub proses1()
TextBox1.Text = ""
RadioButton1.Checked = False
RadioButton2.Checked = False
TextBox2.Text = ""
TextBox2.Enabled = True
TextBox3.Text = ""
TextBox3.Enabled = True
Button1.Enabled = False
Button2.Enabled = True
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = True
Button6.Enabled = True
End Sub

Private Sub SPP_Load(sender As Object, e As EventArgs) Handles MyBase.Load


Call ambilkoneksi()
Call tampil()
Call proses()
End Sub

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles


TextBox1.TextChanged
Call cari()
End Sub

Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles


RadioButton1.CheckedChanged
Call urutasc()
End Sub

Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles


RadioButton2.CheckedChanged
Call urutdesc()
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Call proses1()
TextBox2.Focus()
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


If TextBox2.Text = "" Or TextBox3.Text = "" Then
MsgBox("Data Tidak Boleh Kosong", MsgBoxStyle.Information, "Informasi")
Exit Sub
Else
Try
strsql = "Insert Into spp values('" & kode & "','" & TextBox2.Text & "' ,
'" & TextBox3.Text & "')"
cmd = New MySql.Data.MySqlClient.MySqlCommand(strsql, conn)
cmd.ExecuteNonQuery()
MsgBox("Data Berhasil Diproses", MsgBoxStyle.Information, "Informasi")
Call tampil()
Call proses()
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Critical, "Error")
End Try
End If
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


If TextBox2.Text = "" Or TextBox3.Text = "" Then
MsgBox("Data Tidak Boleh Kosong", MsgBoxStyle.Information, "Informasi")
Exit Sub
Else
Try
strsql = "update spp set tahun='" & TextBox2.Text & "'," &
"nominal='" & TextBox3.Text & "'" &
"Where id_spp='" & kode & "'"
cmd = New MySql.Data.MySqlClient.MySqlCommand(strsql, conn)
cmd.ExecuteNonQuery()
MsgBox("Data Berhasil Diproses", MsgBoxStyle.Information, "Informasi")
Call tampil()
Call proses()
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Critical, "Error")
End Try
End If
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click


If kode = "" Then
MsgBox("Pilih Data Yang Ingin Di Update atau Di Hapus",
MsgBoxStyle.Information, "Informasi")
Exit Sub
Else
Dim a As String
a = MsgBox("Apakah Anda Akan Menghapus Data Dengan ID : " & kode,
MsgBoxStyle.YesNo, "Konfirmasi")
If a = vbYes Then
strsql = "delete from spp where id_spp='" & kode & "'"
cmd = New MySql.Data.MySqlClient.MySqlCommand(strsql, conn)
cmd.ExecuteNonQuery()
Call tampil()
Call proses()
MsgBox("Data Berhasil dihapus", MsgBoxStyle.Information, "Informasi")
Else
Call tampil()
Call proses()
End If
End If
End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click


Call tampil()
Call proses()
End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click


Dim a As String
a = MsgBox("Apakah Anda Ingin Keluar?", MsgBoxStyle.YesNo, "Informasi")
If a = vbYes Then
MsgBox("Anda Berhasil Keluar", MsgBoxStyle.Information, "informasi")
Me.Dispose()
Else
Call proses()
End If
End Sub

Private Sub DataGridView1_CellContentClick(sender As Object, e As


DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

End Sub

Private Sub DataGridView1_CellMouseClick(sender As Object, e As


DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
Call proses1()
Try
kode = DataGridView1.Rows(e.RowIndex).Cells(0).Value
TextBox2.Text = DataGridView1.Rows(e.RowIndex).Cells(1).Value
TextBox3.Text = DataGridView1.Rows(e.RowIndex).Cells(2).Value
Button1.Enabled = False
Button2.Enabled = False
Button3.Enabled = True
Button4.Enabled = True
Button5.Enabled = True
Button6.Enabled = True
Catch ex As Exception
MsgBox("Data yang Dipilih tidak ada", MsgBoxStyle.Information, "Informasi")
End Try
End Sub

You might also like