Sie sind auf Seite 1von 5

Mata Kuliah : Pemrograman Akuntansi – KA 4B

Pertemuan :3
NIM : 4.41.16.1.23
Nama : Shalsabila

FORM AKUN

Kode Program:
Public Class FrmAkun
Dim strsql As String
Dim proses As New ClsKoneksi
Dim tabel As DataTable
Dim pil As Byte = 1 '1=insert data
Dim i As Integer = 0
Private Sub tombol(ByVal x As Boolean)
cmdtambah.Enabled = x
cmdsimpan.Enabled = Not x
cmdkoreksi.Enabled = x
cmdhapus.Enabled = x
cmdbatal.Enabled = Not x
cmdkeluar.Enabled = x
cmdawal.Enabled = x
cmdakhir.Enabled = x
cmdsebelum.Enabled = x
cmdsesudah.Enabled = x
End Sub
Private Sub aktif(ByVal x As Boolean)
txtkdakun.Enabled = x
txtnama.Enabled = x
txtsaldo.Enabled = x
End Sub
Private Sub kosong()
txtkdakun.Text = ""
txtnama.Text = ""
txtsaldo.Text = ""
End Sub
Private Sub baca_data(ByVal posisi As Integer)
If posisi = 0 Then
txtkdakun.Text = dgAkun.Rows(0).Cells(0).Value 'kodeAkun
txtnama.Text = dgAkun.Rows(0).Cells(1).Value 'namaAkun
txtsaldo.Text = dgAkun.Rows(0).Cells(2).Value 'saldoAwal
Else
txtkdakun.Text = dgAkun.Rows(dgAkun.CurrentCell.RowIndex).Cells(0).Value 'kodeAkun
txtnama.Text = dgAkun.Rows(dgAkun.CurrentCell.RowIndex).Cells(1).Value 'namaAkun
txtsaldo.Text = dgAkun.Rows(dgAkun.CurrentCell.RowIndex).Cells(2).Value
End If
End Sub

Private Sub FrmAkun_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Activated
tombol(True)
aktif(False)
End Sub
Private Sub FrmAkun_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
refreshGrid()
baca_data(0)
load_cbocari(tabel, cbocari)
cbocari.SelectedIndex = 0
End Sub
Public Sub load_cbocari(ByVal DT As DataTable, ByVal cbocari As ComboBox)
Dim name(DT.Columns.Count) As String
Dim i As Integer = 0
For Each column As DataColumn In DT.Columns
name(i) = column.ColumnName
cbocari.Items.Add(name(i))
i += 1 'i=i+1 / i++
Next
End Sub
Private Sub refreshGrid()
Try
tabel = proses.ExecuteQuery("select * from akun order by kodeakun")
Me.dgAkun.DataSource = tabel
With Me.dgAkun
.Columns(0).HeaderText = "Kode Akun"
.Columns(1).HeaderText = "Nama Akun"
.Columns(2).HeaderText = "Saldo Awal"
.Columns(0).Width = 100
.Columns(1).Width = 200
.Columns(2).Width = 100
End With
Catch ex As Exception
MsgBox(ex, MsgBoxStyle.Exclamation, "Warning")
End Try
End Sub
Private Sub refreshGridCari(ByVal namakolom As String, ByVal sCari As String)
Try
tabel = proses.ExecuteQuery("select * from akun where " & Trim(namakolom) & _
" like ('%" & Trim(sCari) & "%') order by kodeakun")
Me.dgAkun.DataSource = tabel
With Me.dgAkun
.Columns(0).HeaderText = "Kode Akun"
.Columns(1).HeaderText = "Nama Akun"
.Columns(2).HeaderText = "Saldo Awal"
.Columns(0).Width = 100
.Columns(1).Width = 200
.Columns(2).Width = 100
End With
Catch ex As Exception
MsgBox(ex, MsgBoxStyle.Exclamation, "Warning")
End Try
End Sub
Private Sub cmdkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles cmdkeluar.Click
Me.Close()
End Sub

Private Sub cmdtambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles cmdtambah.Click
tombol(False)
aktif(True)
kosong()
pil = 1
End Sub

Private Sub cmdsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles cmdsimpan.Click
Dim msql As String
If pil = 1 Then
msql = "insert into akun " _
& "values('" & txtkdakun.Text & "','" & _
txtnama.Text & "'," & _
Val(txtsaldo.Text) & ")"
Else 'koreksi
msql = "update akun set NamaAkun='" & _
txtnama.Text _
& "', SaldoAwal=" & Val(txtsaldo.Text) _
& " where KodeAkun='" & txtkdakun.Text & "'"
End If
proses.ExecuteNonQuery(msql)
tombol(True)
aktif(False)
refreshGrid()
MsgBox("Berhasil disimpan...", vbInformation, "Info")
End Sub
Private Sub cmdbatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles cmdbatal.Click
tombol(True)
aktif(False)
End Sub

Private Sub cmdhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles cmdhapus.Click
Dim psn As Long
psn = MsgBox("Yakin ingin menghapus data ini?", vbQuestion + vbYesNo, "Pesan")
If psn = vbYes Then
proses.ExecuteNonQuery("delete from akun where kodeakun='" & txtkdakun.Text & "'")
End If
refreshGrid()
End Sub

Private Sub txtcari_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles txtcari.TextChanged
refreshGridCari(cbocari.Text, txtcari.Text)
End Sub

Private Sub cmdawal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles cmdawal.Click
Dim nextRow As DataGridViewRow = dgAkun.Rows(0)
dgAkun.CurrentCell = nextRow.Cells(0)
nextRow.Selected = True
baca_data(1)
End Sub

Private Sub cmdsesudah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles cmdsesudah.Click
Dim maxRowIndex As Integer = (Me.dgAkun.Rows.Count - 1 - 1)
Dim curDataGridViewRow As DataGridViewRow = dgAkun.CurrentRow
Dim curRowIndex As Integer = curDataGridViewRow.Index

If (curRowIndex >= maxRowIndex) Then


MsgBox("Tidak ada baris lagi")
Else
Dim nextRow As DataGridViewRow = dgAkun.Rows(curRowIndex + 1)
dgAkun.CurrentCell = nextRow.Cells(0)
nextRow.Selected = True
End If
baca_data(1)
End Sub

Private Sub cmdakhir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles cmdakhir.Click
Dim maxRowIndex As Integer = (Me.dgAkun.Rows.Count - 1 - 1)
Dim nextRow As DataGridViewRow = dgAkun.Rows(maxRowIndex)
dgAkun.CurrentCell = nextRow.Cells(0)
nextRow.Selected = True
baca_data(1)
End Sub

Private Sub cmdsebelum_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles cmdsebelum.Click
Dim maxRowIndex As Integer = (Me.dgAkun.Rows.Count - 1 - 1)
Dim curDataGridViewRow As DataGridViewRow = dgAkun.CurrentRow
Dim curRowIndex As Integer = curDataGridViewRow.Index

If (curRowIndex < 1) Then


MsgBox("Rekam pertama...")
Else
Dim nextRow As DataGridViewRow = dgAkun.Rows(curRowIndex - 1)
dgAkun.CurrentCell = nextRow.Cells(0)
nextRow.Selected = True
End If
End Sub
Private Sub cmdkoreksi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles cmdkoreksi.Click
pil = 2
aktif(True)
tombol(False)
txtkdakun.Enabled = False
txtnama.Focus()
End Sub

Private Sub dgAkun_CellContentClick(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.DataGridViewCellEventArgs) Handles dgAkun.CellContentClick
baca_data(1)
End Sub

Private Sub dgAkun_CellMouseClick(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgAkun.CellMouseClick
baca_data(1)
End Sub
End Class

Das könnte Ihnen auch gefallen