Jumat, 02 Desember 2011

Latihan 33 - 35

Latihan 33A

Public Class Form33A_36109020
    Dim dtb As New DataTable
    Dim cmnd As New OleDb.OleDbCommand
    Dim ksr As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")

    Public Sub dhedhe()
        Dim adhe As New OleDb.OleDbDataAdapter
        adhe = New OleDb.OleDbDataAdapter("select * from barang", ksr)
        dtb.Rows.Clear()
        adhe.Fill(dtb)
        adhe.Dispose()
    End Sub

    Private Sub Form33A_36109020_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dhedhe()
        dgv_36109020.DataSource = dtb
    End Sub

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

        Form33B_36109020.t1_36109020.Text = ""
        Form33B_36109020.t2_36109020.Text = ""
        Form33B_36109020.t3_36109020.Text = ""
        Form33B_36109020.t4_36109020.Text = ""
        Form33B_36109020.KB_36109020.Text = "-"
    End Sub

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

        Form33B_36109020.t1_36109020.Text = dgv_36109020.CurrentRow.Cells("kodebarang").Value
        Form33B_36109020.t1_36109020.Text = dgv_36109020.CurrentRow.Cells("namabarang").Value
        Form33B_36109020.t1_36109020.Text = dgv_36109020.CurrentRow.Cells("hargajual").Value
        Form33B_36109020.t1_36109020.Text = dgv_36109020.CurrentRow.Cells("jumlahbarang").Value
        Form33B_36109020.KB_36109020.Text = dgv_36109020.CurrentRow.Cells("kodebarang").Value

        Form33B_36109020.Show()
    End Sub

    Private Sub hapus_36109020_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapus_36109020.Click
        cmnd = New OleDb.OleDbCommand("delete * from barang where kodebarang = '" & dgv_36109020.CurrentRow.Cells("kodebarang").Value & "'", ksr)
        ksr.Open()
        cmnd.ExecuteNonQuery()
        ksr.Close()
        cmnd.Dispose()

        dhedhe()
    End Sub
End Class


Latihan 33B

Public Class Form33B_36109020
    Dim dhedhe As New ByIskandar.CariKeDataBaseByIskandar
    Dim cmnd As New OleDb.OleDbCommand
    Dim ksr As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")

    Private Sub bersatu()
        If t1_36109020.Text.Length = 0 Then
            MsgBox("Fill the Blank")
            Exit Sub
        End If

        If t2_36109020.Text.Length = 0 Then
            MsgBox("Fill the Blank")
            Exit Sub
        End If

        If Val(t3_36109020.Text) = 0 Then
            MsgBox("Fill the Blank")
            Exit Sub
        End If

        If Val(t4_36109020.Text) = 0 Then
            MsgBox("Fill the Blank")
            Exit Sub
        End If
    End Sub

    Private Sub tambah()
        dhedhe.AturPencarianDataBase("Barang", "KodeBarang", t1_36109020.Text, 1, ksr)
        If dhedhe.JumlanBaris > 0 Then
            MsgBox("sudah ada kode seperti itu")
            Exit Sub
        End If

        cmnd = New OleDb.OleDbCommand("insert into barang (kodebarang, namabarang, hargajual, jumlahbarang) values ('" & t1_36109020.Text & "','" & t2_36109020.Text & "'," & Val(t3_36109020.Text) & "," & Val(t4_36109020.Text) & ")", ksr)
        ksr.Open()
        cmnd.ExecuteNonQuery()
        ksr.Close()
        cmnd.Dispose()

        t1_36109020.Text = ""
        t2_36109020.Text = ""
        t3_36109020.Text = ""
        t4_36109020.Text = ""

        Form33A_36109020.dhedhe()
    End Sub

    Private Sub edit()
        bersatu()
        If t1_36109020.Text <> KB_36109020.Text Then
            dhedhe.AturPencarianDataBase("Barang", "KodeBarang", t1_36109020.Text, 1, ksr)
            If dhedhe.JumlanBaris > 0 Then
                MsgBox("Adami kode barang seperti itu")
                Exit Sub
            End If
        End If

        cmnd = New OleDb.OleDbCommand("update barang set kodebarang = '" & t1_36109020.Text & "', namabarang = '" & t2_36109020.Text & "', hargajual = " & Val(t3_36109020.Text) & ", jumlahbarang = " & Val(t4_36109020.Text) & " where kodebarang = '" & KB_36109020.Text & "'", ksr)

        ksr.Open()
        cmnd.ExecuteNonQuery()
        ksr.Close()
        cmnd.Dispose()

        t1_36109020.Text = ""
        t2_36109020.Text = ""
        t3_36109020.Text = ""
        t4_36109020.Text = ""
        KB_36109020.Text = "-"

        Form33A_36109020.dhedhe()
    End Sub

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


Latihan 34A

Public Class Form34A_36109020
    Private Sub DaftarBarangToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DAFTARBARANGToolStripMenuItem.Click
        If Form34B_36109020.Visible = False Then
            Form34B_36109020.MdiParent = Me
            Form34B_36109020.Show()
        Else
            Form34B_36109020.Activate()
        End If
    End Sub

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

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

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


Latihan 34B

Public Class Form34B_36109020
    Dim dtb As New DataTable
    Dim cmnd As New OleDb.OleDbCommand
    Dim ksr As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")

    Public Sub dhedhe()
        Dim a As New OleDb.OleDbDataAdapter
        a = New OleDb.OleDbDataAdapter("select * from barang", ksr)
        dtb.Rows.Clear()
        a.Fill(dtb)
        a.Dispose()
    End Sub

    Private Sub Form34B_36109020_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dhedhe()
        dgv_36109020.DataSource = dtb
    End Sub
    Private Sub tambah_36109020_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tambah_36109020.Click
        If Form34C_36109020.Visible = False Then
            Form34C_36109020.MdiParent = Me.MdiParent
            Form34C_36109020.Show()
        Else
            Form34C_36109020.Activate()
        End If

        Form34C_36109020.t1_36109020.Text = ""
        Form34C_36109020.t2_36109020.Text = ""
        Form34C_36109020.t3_36109020.Text = ""
        Form34C_36109020.t4_36109020.Text = ""
        Form34C_36109020.KB_36109020.Text = "-"
    End Sub

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

        Form34C_36109020.t1_36109020.Text = dgv_36109020.CurrentRow.Cells("kodebarang").Value
        Form34C_36109020.t2_36109020.Text = dgv_36109020.CurrentRow.Cells("namabarang").Value
        Form34C_36109020.t3_36109020.Text = dgv_36109020.CurrentRow.Cells("hargajual").Value
        Form34C_36109020.t4_36109020.Text = dgv_36109020.CurrentRow.Cells("jumlahbarang").Value
        Form34C_36109020.KB_36109020.Text = dgv_36109020.CurrentRow.Cells("kodebarang").Value

        Form34C_36109020.Show()
    End Sub

    Private Sub hapus_36109020_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapus_36109020.Click
        cmnd = New OleDb.OleDbCommand("delete * from barang where kodebarang = '" & dgv_36109020.CurrentRow.Cells("kodebarang").Value & "'", ksr)
        ksr.Open()
        cmnd.ExecuteNonQuery()
        ksr.Close()
        cmnd.Dispose()

        dhedhe()
    End Sub
End Class



Latihan 34C

Public Class Form34C_36109020
    Dim dhedhe As New ByIskandar.CariKeDataBaseByIskandar
    Dim cmnd As New OleDb.OleDbCommand
    Dim ksr As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")

    Private Sub bersatu()
        If t1_36109020.Text.Length = 0 Then
            MsgBox("Fill the blank please")
            Exit Sub
        End If

        If t2_36109020.Text.Length = 0 Then
            MsgBox("Fill the blank please")
            Exit Sub
        End If

        If Val(t3_36109020.Text) = 0 Then
            MsgBox("Fill the blank please")
            Exit Sub
        End If

        If Val(t4_36109020.Text) = 0 Then
            MsgBox("Fill the blank please")
            Exit Sub
        End If
    End Sub

    Private Sub tambah()
        bersatu()
        dhedhe.AturPencarianDataBase("Barang", "KodeBarang", t1_36109020.Text, 1, ksr)
        If dhedhe.JumlanBaris > 0 Then
            MsgBox("kode barang seperti itu sudah ada")
            Exit Sub
        End If

        cmnd = New OleDb.OleDbCommand("insert into barang(kodebarang, namabarang, hargajual, jumlahbarang) values ('" & t1_36109020.Text & "','" & t2_36109020.Text & "'," & Val(t3_36109020.Text) & "," & Val(t4_36109020.Text) & ")", ksr)
        ksr.Open()
        cmnd.ExecuteNonQuery()
        ksr.Close()
        cmnd.Dispose()

        t1_36109020.Text = ""
        t2_36109020.Text = ""
        t3_36109020.Text = ""
        t4_36109020.Text = ""

        Form34B_36109020.dhedhe()
    End Sub

    Private Sub edit()
        bersatu()
        If t1_36109020.Text <> KB_36109020.Text Then
            dhedhe.AturPencarianDataBase("Barang", "KodeBarang", t1_36109020.Text, 1, ksr)
            If dhedhe.JumlanBaris > 0 Then
                MsgBox("kode barang seperti itu sudah ada")
                Exit Sub
            End If
        End If

        cmnd = New OleDb.OleDbCommand("update barang set kodebarang = '" & t1_36109020.Text & "', namabarang = '" & t2_36109020.Text & "', hargajual = " & Val(t3_36109020.Text) & ", jumlahbarang = " & Val(t4_36109020.Text) & " where kodebarang = '" & KB_36109020.Text & "'", ksr)
        ksr.Open()
        cmnd.ExecuteNonQuery()
        ksr.Close()
        cmnd.Dispose()

        t1_36109020.Text = ""
        t2_36109020.Text = ""
        t3_36109020.Text = ""
        t4_36109020.Text = ""
        KB_36109020.Text = "-"

        Form34B_36109020.dhedhe()
    End Sub

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



Latihan 35

Public Class Form35_36109020
    Dim dtb As New DataTable
    Dim cmnd As New OleDb.OleDbCommand
    Dim dhedhe As New ByIskandar.CariKeDataBaseByIskandar
    Dim ksr As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/datamajemuk.ACCDB")

    Private Sub Form35_36109020_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim f As New OleDb.OleDbDataAdapter
        f = New OleDb.OleDbDataAdapter("select KODEBARANG, UNIT, HARGA from detailtransaksi where notrans = '" & notrans_36109020.Text & "'", ksr)
        f.Fill(dtb)
        f.Dispose()

        dgv_36109020.DataSource = dtb
    End Sub

    Private Sub tambah_36109020_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tambah_36109020.Click
        If kb_36109020.Text.Length = 0 Then
            MsgBox("Isilah kode barang tersebut")
            Exit Sub
        End If

        If Val(unit_36109020.Text) = 0 Then
            MsgBox("isilah unitnyaa")
            Exit Sub
        End If

        If Val(harga_36109020.Text) = 0 Then
            MsgBox("Isilah harga barang tersebut")
            Exit Sub
        End If

        Dim dr As DataRow
        dr = dtb.NewRow
        dr("KODEBARANG") = kb_36109020.Text
        dr("UNIT") = unit_36109020.Text
        dr("HARGA") = harga_36109020.Text

        dtb.Rows.Add(dr)

        kb_36109020.Text = ""
        unit_36109020.Text = ""
        harga_36109020.Text = ""
    End Sub

    Private Sub simpan_36109020_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles simpan_36109020.Click
        If notrans_36109020.Text.Length = 0 Then
            MsgBox("isi rong No Transaksi na..")
            Exit Sub
        End If

        If jenis_36109020.Text.Length = 0 Then
            MsgBox("Isi rong Jenis Transaksi na..")
            Exit Sub
        End If

        If dtb.Rows.Count = 0 Then
            MsgBox("Maaf...Isi rong itu datatable na..")
            Exit Sub
        End If

        dhedhe.AturPencarianDataBase("mastertransaksi", "notrans", notrans_36109020.Text, 1, ksr)
        If dhedhe.JumlanBaris > 0 Then
            MsgBox("Adami notrans seperti itu")
            Exit Sub
        End If

        cmnd = New OleDb.OleDbCommand("insert into mastertransaksi(notrans, tanggaltransaksi, jenistransaksi) values ('" & notrans_36109020.Text & "',#" & tgl_36109020.Value.Month & "/" & tgl_36109020.Value.Day & "/" & tgl_36109020.Value.Year & "#,'" & jenis_36109020.Text & "')", ksr)
        ksr.Open()
        cmnd.ExecuteNonQuery()
        ksr.Close()

        For Each x As DataRow In dtb.Rows
            cmnd = New OleDb.OleDbCommand("insert into detailtransaksi(notrans, kodebarang, unit, harga) values ('" & notrans_36109020.Text & "','" & x("kodebarang") & "','" & x("unit") & "','" & x("harga") & "')", ksr)
            ksr.Open()
            cmnd.ExecuteNonQuery()
            ksr.Close()
        Next
        cmnd.Dispose()

        notrans_36109020.Text = ""
        jenis_36109020.Text = ""

        dtb.Rows.Clear()
    End Sub
End Class