Sabtu, 19 November 2011

LATIHAN 34 APKOM

Public Class tugas34a46109033
    Private Sub DAFTARBARANGToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DAFTARBARANGToolStripMenuItem.Click
        If tugas34b46109033.Visible = False Then
            tugas34b46109033.MdiParent = Me.MdiParent
            tugas34b46109033.Show()
        Else
            tugas34b46109033.Activate()
        End If
    End Sub
    Private Sub INPUTBARANGToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles INPUTBARANGToolStripMenuItem.Click
        If tugas34c46109033.Visible = False Then
            tugas34c46109033.MdiParent = Me.MdiParent
            tugas34c46109033.Show()
        Else
            tugas34c46109033.Activate()
        End If
    End Sub
    Private Sub ToolStripButton146109033_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ToolStripButton146109033.Click
        If tugas34b46109033.Visible = False Then
            tugas34b46109033.MdiParent = Me.MdiParent
            tugas34b46109033.Show()
        Else
            tugas34b46109033.Activate()
        End If
    End Sub
    Private Sub ToolStripButton246109033_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ToolStripButton246109033.Click
        If tugas34c46109033.Visible = False Then
            tugas34c46109033.MdiParent = Me.MdiParent
            tugas34c46109033.Show()
        Else
            tugas34c46109033.Activate()
        End If
    End Sub
End Class


Public Class tugas34b46109033
    Dim konek As New OleDb.OleDbConnection("provider = microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\databarang.accdb;jet OLEDB:database password=2121990")
    Dim tm As New DataTable
    Public Sub ambil()
        Dim itik As New OleDb.OleDbDataAdapter
        itik = New OleDb.OleDbDataAdapter("select * from barang", konek)
        tm.Rows.Clear()
        itik.Fill(tm)
        itik.Dispose()
    End Sub
    Private Sub tugas34b46109033_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ambil()
        DataGridView146109033.DataSource = tm
    End Sub
    Private Sub Button2461099033_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button246109033.Click
        If tugas34c46109033.Visible = False Then
            tugas34c46109033.Show()
        Else
            tugas34c46109033.Activate()
        End If
    End Sub
    Private Sub Button146109033_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button146109033.Click
        If tugas34c46109033.Visible = False Then
            tugas34c46109033.Show()
        Else
            tugas34c46109033.Activate()
        End If
        tugas34c46109033.KB.Text = DataGridView146109033.CurrentRow.Cells("KODEBARANG").Value
        tugas34c46109033.t146109033.Text = DataGridView146109033.CurrentRow.Cells("KODEBARANG").Value
        tugas34c46109033.t246109033.Text = DataGridView146109033.CurrentRow.Cells("NAMABARANG").Value
        tugas34c46109033.t346109033.Text = DataGridView146109033.CurrentRow.Cells("HARGAJUAL").Value
        tugas34c46109033.t446109033.Text = DataGridView146109033.CurrentRow.Cells("JUMLAHBARANG").Value()
    End Sub
End Class



Public Class tugas34c46109033
    Dim konek As New OleDb.OleDbConnection("provider = microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\databarang.accdb;jet OLEDB:database password=2121990")
    Dim tm As New ByIskandar.CariKeDataBaseByIskandar
    Private Sub tambah()
        If t146109033.Text.Length = 0 Then
            MsgBox("kode barang belum terisi")
            Exit Sub
        End If
        If t246109033.Text.Length = 0 Then
            MsgBox("nama barang belum terisi")
            Exit Sub
        End If
        If Val(t346109033.Text) = 0 Then
            MsgBox("harga jual belum diisi")
            Exit Sub
        End If
        If Val(t446109033.Text) = 0 Then
            MsgBox("JUMLAH BELUM TERISI")
            Exit Sub
        End If
        tm.AturPencarianDataBase("barang", "kode barang", t146109033.Text, 1, konek)

        If tm.JumlanBaris > 0 Then
            MsgBox("kode sudah ada")
            Exit Sub
        End If
        Dim go As New OleDb.OleDbCommand
        go = New OleDb.OleDbCommand("insert into barang(kodebarang,namabarang,hargajual,jumlahbarang) Values('" & t146109033.Text & "','" & t246109033.Text & "'," & Val(t346109033.Text) & "," & Val(t446109033.Text) & ")", konek)
        konek.Open()
        go.ExecuteNonQuery()
        konek.Close()
        go.Dispose()
        t146109033.Text = ""
        t246109033.Text = ""
        t346109033.Text = ""
        t446109033.Text = ""
        tugas33a46109033.ambil()
    End Sub
    Private Sub edit()
        If t146109033.Text.Length = 0 Then
            MsgBox("kode barang belum terisi")
            Exit Sub
        End If
        If t246109033.Text.Length = 0 Then
            MsgBox("nama barang belum terisi")
            Exit Sub
        End If
        If Val(t346109033.Text) = 0 Then
            MsgBox("harga jual belum diisi")
            Exit Sub
        End If
        If Val(t446109033.Text) = 0 Then
            MsgBox("JUMLAH BELUM TERISI")
            Exit Sub
        End If
        If KB.Text <> t146109033.Text Then
            tm.AturPencarianDataBase("barang", "kode barang", t146109033.Text, 1, konek)

            If tm.JumlanBaris > 0 Then
                MsgBox("kode sudah ada")
                Exit Sub
            End If
        End If
        Dim go As New OleDb.OleDbCommand
        go = New OleDb.OleDbCommand("update barang set kodebarang ='" & t146109033.Text & "',namabarang='" & t246109033.Text & "',hargajual=" & Val(t346109033.Text) & ", jumlahbarang=" & Val(t446109033.Text) & "where kodebarang='" & KB.Text & "'", konek)
        konek.Open()
        go.ExecuteNonQuery()
        konek.Close()
        go.Dispose()
        t146109033.Text = ""
        t246109033.Text = ""
        t346109033.Text = ""
        t446109033.Text = ""
        KB.Text = "-"
        tugas33a46109033.ambil()
    End Sub
    Private Sub Button146109033_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button146109033.Click
        If KB.Text = "-" Then
            tambah()
        Else
            edit()
        End If
    End Sub
End Class

Tidak ada komentar:

Posting Komentar