Jumat, 09 Desember 2011

LATIHAN 35-37

Form035_36109019
--------------------------------------------
Public Class Form035_36109019
    Dim dt As New DataTable
    Dim cm As New OleDb.OleDbCommand
    Dim wahyuni As New ByIskandar.CariKeDataBaseByIskandar
    Dim uni As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/datamajemuk.ACCDB")

    Private Sub Form035_36109019_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a As New OleDb.OleDbDataAdapter
        a = New OleDb.OleDbDataAdapter("select KODEBARANG, UNIT, HARGA from detailtransaksi where notrans = '" & aa36109019.Text & "'", uni)
        a.Fill(dt)
        a.Dispose()
        dgv.DataSource = dt
    End Sub
    Private Sub gg36109019_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gg36109019.Click
        If dd36109019.Text.Length = 0 Then
            MsgBox("Isi rong itu Kode Barang na..")
            Exit Sub
        End If
        If Val(ee36109019.Text) = 0 Then
            MsgBox("Isi rong itu Unit na..")
            Exit Sub
        End If
        If Val(ff36109019.Text) = 0 Then
            MsgBox("Isi rong itu Harga na..")
            Exit Sub
        End If
        Dim dr As DataRow
        dr = dt.NewRow
        dr("KODEBARANG") = dd36109019.Text
        dr("UNIT") = ee36109019.Text
        dr("HARGA") = ff36109019.Text
        dt.Rows.Add(dr)
        dd36109019.Text = ""
        ee36109019.Text = ""
        ff36109019.Text = ""
    End Sub
    Private Sub hh36109019_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hh36109019.Click
        If aa36109019.Text.Length = 0 Then
            MsgBox("isi rong No Transaksi na..")
            Exit Sub
        End If
        If cc36109019.Text.Length = 0 Then
            MsgBox("Isi rong Jenis Transaksi na..")
            Exit Sub
        End If
        If dt.Rows.Count = 0 Then
            MsgBox("Maaf...Isi rong itu datatable na..")
            Exit Sub
        End If
        wahyuni.AturPencarianDataBase("mastertransaksi", "notrans", aa36109019.Text, 1, uni)
        If wahyuni.JumlanBaris > 0 Then
            MsgBox("Adami notrans seperti itu")
            Exit Sub
        End If
        cm = New OleDb.OleDbCommand("insert into mastertransaksi(notrans, tanggaltransaksi, jenistransaksi) values ('" & aa36109019.Text & "',#" & bb36109019.Value.Month & "/" & bb36109019.Value.Day & "/" & bb36109019.Value.Year & "#,'" & cc36109019.Text & "')", uni)
        uni.Open()
        cm.ExecuteNonQuery()
        uni.Close()
        For Each x As DataRow In dt.Rows
            cm = New OleDb.OleDbCommand("insert into detailtransaksi(notrans, kodebarang, unit, harga) values ('" & aa36109019.Text & "','" & x("kodebarang") & "','" & x("unit") & "','" & x("harga") & "')", uni)
            uni.Open()
            cm.ExecuteNonQuery()
            uni.Close()
        Next
        cm.Dispose()
        aa36109019.Text = ""
        cc36109019.Text = ""
        dt.Rows.Clear()
    End Sub
End Class
---------------------------------------------------
Form036_36109019
--------------------------------------------------
Public Class Form036_36109019
    Dim dt As New DataTable
    Dim cm As New OleDb.OleDbCommand
    Dim wahyuni As New ByIskandar.CariKeDataBaseByIskandar
    Dim uni As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/datamajemuk.ACCDB")
    Private Sub Form036_36109019_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a As New OleDb.OleDbDataAdapter
        a = New OleDb.OleDbDataAdapter("select KODEBARANG, UNIT, HARGA from detailtransaksi where notrans = '" & aa36109019.Text & "'", uni)
        a.Fill(dt)
        a.Dispose()
        dgv.DataSource = dt
        Dim dc(1) As DataColumn
        dc(0) = dt.Columns("kodebarang")
        dt.PrimaryKey = dc
    End Sub
    Private Sub gg36109019_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gg36109019.Click
        If dd36109019.Text.Length = 0 Then
            MsgBox("Isi rong itu Kode Barang na..")
            Exit Sub
        End If
        If Val(ee36109019.Text) = 0 Then
            MsgBox("Isi rong itu Unit na..")
            Exit Sub
        End If
        If Val(ff36109019.Text) = 0 Then
            MsgBox("Isi rong itu Harga na..")
            Exit Sub
        End If
        Dim dr As DataRow
        dr = dt.Rows.Find(dd36109019.Text)
        If dr Is Nothing Then
            dr = dt.NewRow
            dr("KODEBARANG") = dd36109019.Text
            dr("UNIT") = ee36109019.Text
            dr("HARGA") = ff36109019.Text
            dt.Rows.Add(dr)
            dd36109019.Text = ""
            ee36109019.Text = ""
            ff36109019.Text = ""
        Else
            MsgBox("Kode barang itu sudah ada, mohon ganti dengan kode barang yang lain")
        End If
    End Sub
    Private Sub hh36109019_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hh36109019.Click
        If aa36109019.Text.Length = 0 Then
            MsgBox("Isi rong No Transaksi na..")
            Exit Sub
        End If
        If cc36109019.Text.Length = 0 Then
            MsgBox("Isi rong Jenis Transaksi na..")
            Exit Sub
        End If
        If dt.Rows.Count = 0 Then
            MsgBox("Maaf...Isi rong itu datatable na..")
            Exit Sub
        End If
        wahyuni.AturPencarianDataBase("mastertransaksi", "notrans", aa36109019.Text, 1, uni)
        If wahyuni.JumlanBaris > 0 Then
            MsgBox("Adami notrans seperti itu")
            Exit Sub
        End If
        cm = New OleDb.OleDbCommand("insert into mastertransaksi (notrans, tanggaltransaksi, jenistransaksi) values ('" & aa36109019.Text & "',#" & bb36109019.Value.Month & "/" & bb36109019.Value.Day & "/" & bb36109019.Value.Year & "#,'" & cc36109019.Text & "')", uni)
        uni.Open()
        cm.ExecuteNonQuery()
        uni.Close()
        For Each x As DataRow In dt.Rows
            cm = New OleDb.OleDbCommand("insert into detailtransaksi (notrans, kodebarang, unit, harga) values ('" & aa36109019.Text & "', '" & x("kodebarang") & "','" & x("unit") & "','" & x("harga") & "')", uni)
            uni.Open()
            cm.ExecuteNonQuery()
            uni.Close()
        Next
        cm.Dispose()
        aa36109019.Text = ""
        cc36109019.Text = ""
        dt.Rows.Clear()
    End Sub
End Class
------------------------------------------------
Form037_36109019
------------------------------------------------
Public Class Form037_36109019
    Dim dt As New DataTable
    Dim cm As New OleDb.OleDbCommand
    Dim wahyuni As New ByIskandar.CariKeDataBaseByIskandar
    Dim uni As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Datamajemuk.ACCDB")
    Private Sub Form037_36109019_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a As New OleDb.OleDbDataAdapter
        a = New OleDb.OleDbDataAdapter("select barang.KODEBARANG, barang.NAMABARANG, detailtransaksi.UNIT, detailtransaksi.HARGA, detailtransaksi.unit*harga as JUMLAH from barang inner join detailtransaksi on barang.kodebarang = detailtransaksi.kodebarang where notrans ='" & aa_36109019.Text & "'", uni)
        dt.Rows.Clear()
        a.Fill(dt)
        a.Dispose()
        Dim dc(1) As DataColumn
        dc(0) = dt.Columns("kodebarang")
        dt.PrimaryKey = dc
        dgv.DataSource = dt
    End Sub
    Private Sub nyai()
        Dim nyai1 As Integer = 0
        For Each nyai2 As DataRow In dt.Rows
            nyai1 += nyai2("JUMLAH")
        Next
        jj_36109019.Text = nyai1
    End Sub
    Private Sub ff_36109019_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ff_36109019.TextChanged
        hh_36109019.Text = Val(ff_36109019.Text) * Val(gg_36109019.Text)
    End Sub
    Private Sub dd_36109019_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles dd_36109019.Leave
        If dd_36109019.Text.Length = 0 Then
            Exit Sub
        End If
        wahyuni.AturPencarianDataBase("barang", "kodebarang", dd_36109019.Text, 1, uni)
        If wahyuni.JumlanBaris > 0 Then
            dd_36109019.Text = wahyuni.DataTablenya.Rows(0).Item("KODEBARANG")
            ee_36109019.Text = wahyuni.DataTablenya.Rows(0).Item("NAMABARANG")
        Else
            MsgBox("Kode barang itu tidak ada..")
            Exit Sub
        End If
    End Sub
    Private Sub dd_36109019_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dd_36109019.TextChanged
        ee_36109019.Text = ""
        ff_36109019.Text = ""
        gg_36109019.Text = ""
    End Sub
    Private Sub ii_36109019_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ii_36109019.Click
        If dd_36109019.Text.Length = 0 Then
            MsgBox("Isi rong itu Kode Barang na..")
            Exit Sub
        End If
        If Val(ff_36109019.Text) = 0 Then
            MsgBox("Isi rong itu Unit na..")
            Exit Sub
        End If
        If Val(gg_36109019.Text) = 0 Then
            MsgBox("Isi rong itu Harga na..")
            Exit Sub
        End If
        Dim dr As DataRow
        dr = dt.Rows.Find(dd_36109019.Text)
        If dr Is Nothing Then
            dr = dt.NewRow
            dr("KODEBARANG") = dd_36109019.Text
            dr("NAMABARANG") = ee_36109019.Text
            dr("UNIT") = Val(ff_36109019.Text)
            dr("HARGA") = Val(gg_36109019.Text)
            dr("JUMLAH") = Val(hh_36109019.Text)
            dt.Rows.Add(dr)
            dd_36109019.Text = ""
            ff_36109019.Text = ""
            gg_36109019.Text = ""
        Else
            MsgBox("Kode barang itu sudah ada, mohon ganti dengan kode barang yang lain...")
        End If
        nyai()
    End Sub
    Private Sub kk_36109019_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kk_36109019.Click
        If aa_36109019.Text.Length = 0 Then
            MsgBox("Isi rong No Transaksi na..")
            Exit Sub
        End If
        If cc_36109019.Text.Length = 0 Then
            MsgBox("isi rong Jenis Transaksi na..")
            Exit Sub
        End If
        If dt.Rows.Count = 0 Then
            MsgBox("Maaf..Isi rong itu datatable na..")
            Exit Sub
        End If
        wahyuni.AturPencarianDataBase("mastertransaksi", "notrans", aa_36109019.Text, 1, uni)
        If wahyuni.JumlanBaris > 0 Then
            MsgBox("Adami no trans seperti itu...")
            Exit Sub
        End If
        cm = New OleDb.OleDbCommand("insert into mastertransaksi (notrans, tanggaltransaksi, jenistransaksi) values ('" & aa_36109019.Text & "',#" & bb_36109019.Value.Month & "/" & bb_36109019.Value.Day & "/" & bb_36109019.Value.Year & "#,'" & cc_36109019.Text & "')", uni)
        uni.Open()
        cm.ExecuteNonQuery()
        uni.Close()
        For Each x As DataRow In dt.Rows
            cm = New OleDb.OleDbCommand("insert into detailtransaksi (notrans, kodebarang, unit, harga) values ('" & aa_36109019.Text & "','" & x("kodebarang") & "','" & x("unit") & "','" & x("harga") & "')", uni)
            uni.Open()
            cm.ExecuteNonQuery()
            uni.Close()
        Next
        cm.Dispose()
        aa_36109019.Text = ""
        cc_36109019.Text = ""
        dt.Rows.Clear()
        nyai()
    End Sub
End Class

Selasa, 29 November 2011

LATIHAN 32B-34

Public Class Form032B_36109019
    Dim wahyuni As New ByIskandar.CariKeDataBaseByIskandar
    Dim cm As New OleDb.OleDbCommand
    Dim uni As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")


    Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
        If t1_36109019.Text.ength = 0 Then
            MsgBox("Isi rong itu yang  kosong")
            Exit Sub
        End If

        If t2_36109019.Text.Length = 0 Then
            MsgBox("Isi rong itu yang kosong")
            Exit Sub
        End If

        If Val(t3_36109019.Text) = 0 Then
            MsgBox("Isi rong itu yang kosong")
            Exit Sub
        End If

        If Val(t4_36109019.Text) = 0 Then
            MsgBox("Isi rong itu yang kosong")
            Exit Sub
        End If

        wahyuni.AturPencarianDataBase("Barang", "KodeBarang", t1_36109019.Text, 1, uni)
        If wahyuni.JumlanBaris > 0 Then
            MsgBox("Adami kode barang seperti itu")
            Exit Sub
        End If

        cm = New OleDb.OleDbCommand("insert into barang (kodebarang, namabarang, hargajual, jumlahbarang) values ('" & t1_36109019.Text & "','" & t2_36109019.Text & "'," & Val(t3_36109019.Text) & "," & Val(t4_36109019.Text) & ")", uni)
        uni.Open()
        cm.ExecuteNonQuery()
        uni.Close()
        cm.Dispose()

        t1_36109019.Text = ""
        t2_36109019.Text = ""
        t3_36109019.Text = ""
        t4_36109019.Text = ""

        Form032A_36109019.wahyuni()
    End Sub
End Class
-------------------------------------------------------------------------------------------------------------------------

Public Class Form032C_36109019
    Dim wahyuni As New ByIskandar.CariKeDataBaseByIskandar
    Dim cm As New OleDb.OleDbCommand
    Dim uni As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If t1_36109019.Text.Length = 0 Then
            MsgBox("Isi rong itu yang kosong")
            Exit Sub
        End If

        If t2_36109019.Text.Length = 0 Then
            MsgBox("Isi rong itu yang kosong")
            Exit Sub
        End If

        If Val(t3_36109019.Text) = 0 Then
            MsgBox("Isi rong itu yang kosong")
            Exit Sub
        End If

        If Val(t4_36109019.Text) = 0 Then
            MsgBox("Isi rong itu yang kosong")
            Exit Sub
        End If

        If t1_36109019.Text <> KB.Text Then
            wahyuni.AturPencarianDataBase("Barang", "KodeBarang", t1_36109019.Text, 1, uni)
            If wahyuni.JumlanBaris > 0 Then
                MsgBox("Adami kode barang seperti itu")
                Exit Sub
            End If
        End If

        cm = New OleDb.OleDbCommand("update barang set kodebarang = '" & t1_36109019.Text & "', namabarang = '" & t2_36109019.Text & "', hargajual = " & Val(t3_36109019.Text) & ", jumlahbarang = " & Val(t4_36109019.Text) & " where kodebarang = '" & KB.Text & "'", uni)

        uni.Open()
        cm.ExecuteNonQuery()
        uni.Close()
        cm.Dispose()

        t1_36109019.Text = ""
        t2_36109019.Text = ""
        t3_36109019.Text = ""
        t4_36109019.Text = ""
        KB.Text = ""

        Form032A_36109019.wahyuni()

    End Sub
End Class
-------------------------------------------------------------------------------------------------------------------------

Public Class Form033A_36109019
    Dim dt As New DataTable
    Dim cm As New OleDb.OleDbCommand
    Dim uni As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")

    Public Sub wahyuni()
        Dim a As New OleDb.OleDbDataAdapter
        a = New OleDb.OleDbDataAdapter("select * from barang", uni)
        dt.Rows.Clear()
        a.Fill(dt)
        a.Dispose()
    End Sub
    Private Sub Form033A_36109019_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        wahyuni()
        dgv.DataSource = dt
    End Sub

    Private Sub tambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tambah.Click
        If Form033B_36109019.Visible = False Then
            Form033B_36109019.Show()
        Else
            Form033B_36109019.Activate()
        End If

        Form033B_36109019.t1_36109019.Text = ""
        Form033B_36109019.t2_36109019.Text = ""
        Form033B_36109019.t3_36109019.Text = ""
        Form033B_36109019.t4_36109019.Text = ""
        Form033B_36109019.KB.Text = "-"
    End Sub

    Private Sub edit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles edit.Click
        If Form033B_36109019.Visible = False Then
            Form033B_36109019.Show()
        Else
            Form033B_36109019.Activate()
        End If

        Form033B_36109019.t1_36109019.Text = dgv.CurrentRow.Cells("kodebarang").Value
        Form033B_36109019.t2_36109019.Text = dgv.CurrentRow.Cells("namabarang").Value
        Form033B_36109019.t3_36109019.Text = dgv.CurrentRow.Cells("hargajual").Value
        Form033B_36109019.t4_36109019.Text = dgv.CurrentRow.Cells("jumlahbarang").Value
        Form033B_36109019.KB.Text = dgv.CurrentRow.Cells("kodebarang").Value

        Form033B_36109019.Show()
    End Sub

    Private Sub hapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapus.Click
        cm = New OleDb.OleDbCommand("delete * from barang where kodebarang = '" & dgv.CurrentRow.Cells("kodebarang").Value & "'", uni)
        uni.Open()
        cm.ExecuteNonQuery()
        uni.Close()
        cm.Dispose()

        wahyuni()
    End Sub
End Class
-------------------------------------------------------------------------------------------------------------------------

Public Class Form033B_36109019
    Dim wahyuni As New ByIskandar.CariKeDataBaseByIskandar
    Dim cm As New OleDb.OleDbCommand
    Dim uni As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")

    Private Sub indonesia()
        If t1_36109019.Text.Length = 0 Then
            MsgBox("Isi rong itu yang kosong")
            Exit Sub
        End If

        If t2_36109019.Text.Length = 0 Then
            MsgBox("Isi rong itu yang kosong")
            Exit Sub
        End If

        If Val(t3_36109019.Text) = 0 Then
            MsgBox("Isi rong itu yang kosong")
            Exit Sub
        End If

        If Val(t4_36109019.Text) = 0 Then
            MsgBox("Isi rong itu yang kosong")
            Exit Sub
        End If
    End Sub

    Private Sub tambah()
        indonesia()
        wahyuni.AturPencarianDataBase("Barang", "KodeBarang", t1_36109019.Text, 1, uni)
        If wahyuni.JumlanBaris > 0 Then
            MsgBox("Adami kode barang seperti itu")
            Exit Sub
        End If

        cm = New OleDb.OleDbCommand("insert into barang (kodebarang, namabarang, hargajual, jumlahbarang) values ('" & t1_36109019.Text & "','" & t2_36109019.Text & "'," & Val(t3_36109019.Text) & "," & Val(t4_36109019.Text) & ")", uni)
        uni.Open()
        cm.ExecuteNonQuery()
        uni.Close()
        cm.Dispose()

        t1_36109019.Text = ""
        t2_36109019.Text = ""
        t3_36109019.Text = ""
        t4_36109019.Text = ""

        Form033A_36109019.wahyuni()
    End Sub

    Private Sub edit()
        indonesia()
        If t1_36109019.Text <> KB.Text Then
            wahyuni.AturPencarianDataBase("Barang", "KodeBarang", t1_36109019.Text, 1, uni)
            If wahyuni.JumlanBaris > 0 Then
                MsgBox("Adami kode barang seperti itu")
                Exit Sub
            End If
        End If

        cm = New OleDb.OleDbCommand("update barang set kodebarang = '" & t1_36109019.Text & "', namabarang = '" & t2_36109019.Text & "', hargajual = " & Val(t3_36109019.Text) & ", jumlahbarang = " & Val(t4_36109019.Text) & " where kodebarang = '" & KB.Text & "'", uni)

        uni.Open()
        cm.ExecuteNonQuery()
        uni.Close()
        cm.Dispose()

        t1_36109019.Text = ""
        t2_36109019.Text = ""
        t3_36109019.Text = ""
        t4_36109019.Text = ""
        KB.Text = "-"

        Form033A_36109019.wahyuni()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If KB.Text = "-" Then
            tambah()
        Else
            edit()
        End If
    End Sub
End Class
-------------------------------------------------------------------------------------------------------------------------

Public Class Form034A_36109019

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        If Form034B_36109019.Visible = False Then
            Form034B_36109019.MdiParent = Me
            Form034B_36109019.Show()
        Else
            Form034B_36109019.Activate()
        End If
    End Sub
    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        If Form034C_36109019.Visible = False Then
            Form034C_36109019.MdiParent = Me
            Form034C_36109019.Show()
        Else
            Form034C_36109019.Activate()
        End If
    End Sub

    Private Sub INPUTBARANGToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles INPUTBARANGToolStripMenuItem.Click
        If Form034C_36109019.Visible = False Then
            Form034C_36109019.MdiParent = Me
            Form034C_36109019.Show()
        Else
            Form034C_36109019.Activate()
        End If
    End Sub

    Private Sub DAFTARBARANGToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DAFTARBARANGToolStripMenuItem.Click
        If Form034B_36109019.Visible = False Then
            Form034B_36109019.MdiParent = Me
            Form034B_36109019.Show()
        Else
            Form034B_36109019.Activate()
        End If
    End Sub

End Class
-------------------------------------------------------------------------------------------------------------------------

Public Class Form034B_36109019
    Dim dt As New DataTable
    Dim cm As New OleDb.OleDbCommand
    Dim uni As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")
    Public Sub wahyuni()
        Dim a As New OleDb.OleDbDataAdapter
        a = New OleDb.OleDbDataAdapter("select * from barang", uni)
        dt.Rows.Clear()
        a.Fill(dt)
        a.Dispose()
    End Sub
    Private Sub Form034B_36109019_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        wahyuni()
        dgv.DataSource = dt
    End Sub

    Private Sub tambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tambah.Click
        If Form034C_36109019.Visible = False Then
            Form034C_36109019.MdiParent = Me.MdiParent
            Form034C_36109019.Show()
        Else
            Form034C_36109019.Activate()
        End If

        Form034C_36109019.t1_36109019.Text = dgv.CurrentRow.Cells("kodebarang").Value
        Form034C_36109019.t2_36109019.Text = dgv.CurrentRow.Cells("namabarang").Value
        Form034C_36109019.t3_36109019.Text = dgv.CurrentRow.Cells("hargajual").Value
        Form034C_36109019.t4_36109019.Text = dgv.CurrentRow.Cells("jumlahbarang").Value
        Form034C_36109019.KB.Text = dgv.CurrentRow.Cells("kodebarang").Value

        Form034C_36109019.Show()
    End Sub

    Private Sub edit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles edit.Click
        If Form034C_36109019.Visible = False Then
            Form034C_36109019.MdiParent = Me.MdiParent
            Form034C_36109019.Show()
        Else
            Form034C_36109019.Activate()
        End If

        Form034C_36109019.t1_36109019.Text = dgv.CurrentRow.Cells("kodebarang").Value
        Form034C_36109019.t2_36109019.Text = dgv.CurrentRow.Cells("namabarang").Value
        Form034C_36109019.t3_36109019.Text = dgv.CurrentRow.Cells("hargajual").Value
        Form034C_36109019.t4_36109019.Text = dgv.CurrentRow.Cells("jumlahbarang").Value
        Form034C_36109019.KB.Text = dgv.CurrentRow.Cells("kodebarang").Value

        Form034C_36109019.Show()
    End Sub

    Private Sub hapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapus.Click
        cm = New OleDb.OleDbCommand("delete * from barang where kodebarang = '" & dgv.CurrentRow.Cells("kodebarang").Value & "'", uni)
        uni.Open()
        cm.ExecuteNonQuery()
        uni.Close()
        cm.Dispose()

        wahyuni()
    End Sub
End Class
-------------------------------------------------------------------------------------------------------------------------

Public Class Form034C_36109019
    Dim wahyuni As New ByIskandar.CariKeDataBaseByIskandar
    Dim cm As New OleDb.OleDbCommand
    Dim uni As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")

    Private Sub indonesia()
        If t1_36109019.Text.Length = 0 Then
            MsgBox("Isi rong itu yang kosong")
            Exit Sub
        End If

        If t2_36109019.Text.Length = 0 Then
            MsgBox("Isi rong itu yang kosong")
            Exit Sub
        End If

        If Val(t3_36109019.Text) = 0 Then
            MsgBox("Isi rong itu yang kosong")
            Exit Sub
        End If

        If Val(t4_36109019.Text) = 0 Then
            MsgBox("Isi rong itu yang kosong")
            Exit Sub
        End If
    End Sub
    Private Sub tambah()
        indonesia()
        wahyuni.AturPencarianDataBase("Barang", "KodeBarang", t1_36109019.Text, 1, uni)
        If wahyuni.JumlanBaris > 0 Then
            MsgBox("Adami kode barang seperti itu")
            Exit Sub
        End If

        cm = New OleDb.OleDbCommand("insert into barang(kodebarang, namabarang, hargajual, jumlahbarang) values ('" & t1_36109019.Text & "','" & t2_36109019.Text & "'," & Val(t3_36109019.Text) & "," & Val(t4_36109019.Text) & ")", uni)
        uni.Open()
        cm.ExecuteNonQuery()
        uni.Close()
        cm.Dispose()

        t1_36109019.Text = ""
        t2_36109019.Text = ""
        t3_36109019.Text = ""
        t4_36109019.Text = ""

        Form034B_36109019.wahyuni()
    End Sub

    Private Sub edit()
        indonesia()
        If t1_36109019.Text <> KB.Text Then
            wahyuni.AturPencarianDataBase("Barang", "KodeBarang", t1_36109019.Text, 1, uni)
            If wahyuni.JumlanBaris > 0 Then
                MsgBox("Adami kode barang seperti itu")
                Exit Sub
            End If
        End If

        cm = New OleDb.OleDbCommand("update barang set kodebarang = '" & t1_36109019.Text & "', namabarang = '" & t2_36109019.Text & "', hargajual = " & Val(t3_36109019.Text) & ", jumlahbarang = " & Val(t4_36109019.Text) & " where kodebarang = '" & KB.Text & "'", uni)
        uni.Open()
        cm.ExecuteNonQuery()
        uni.Close()
        cm.Dispose()

        t1_36109019.Text = ""
        t2_36109019.Text = ""
        t3_36109019.Text = ""
        t4_36109019.Text = ""
        KB.Text = "-"

        Form034B_36109019.wahyuni()
    End Sub

    Private Sub simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles simpan.Click
        If KB.Text = "-" Then
            tambah()
        Else
            edit()
        End If
    End Sub
End Class