Sabtu, 19 November 2011

LATIHAN 33 APKOM

Public Class tugas33a46109033
    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 data As New OleDb.OleDbDataAdapter
        data = New OleDb.OleDbDataAdapter("select * from barang", konek)
        tm.Rows.Clear()
        data.Fill(tm)
        data.Dispose()
    End Sub
    Private Sub tugas33a46109033_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ambil()
        DataGridView146109033.DataSource = tm
    End Sub
    Private Sub Button246109033_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button246109033.Click
        If tugas33b46109033.Visible = False Then
            tugas33b46109033.Show()
        Else
            tugas33b46109033.Activate()
        End If
    End Sub
    Private Sub Button146109033_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button146109033.Click
        If tugas33b46109033.Visible = False Then
            tugas33b46109033.Show()
        Else
            tugas33b46109033.Activate()
        End If
        tugas33b46109033.KB.Text = DataGridView146109033.CurrentRow.Cells("KODEBARANG").Value
        tugas33b46109033.t146109033.Text = DataGridView146109033.CurrentRow.Cells("KODEBARANG").Value
        tugas33b46109033.t246109033.Text = DataGridView146109033.CurrentRow.Cells("NAMABARANG").Value
        tugas33b46109033.t346109033.Text = DataGridView146109033.CurrentRow.Cells("HARGAJUAL").Value
        tugas33b46109033.t446109033.Text = DataGridView146109033.CurrentRow.Cells("JUMLAHBARANG").Value
    End Sub
    Private Sub Button346109033_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button346109033.Click
        Dim itik As New OleDb.OleDbCommand
        itik = New OleDb.OleDbCommand("DELETE * FROM BARANG WHERE KODEBARANG='" & DataGridView146109033.CurrentRow.Cells("KODEBARANG").Value & "'", konek)
        konek.Open()
        itik.ExecuteNonQuery()
        konek.Close()
        itik.Dispose()
        ambil()
    End Sub
End Class



Public Class tugas33b46109033
    Dim konek As New OleDb.OleDbConnection("provider = microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\databarang.accdb;jet OLEDB:database password=2121990")
    Dim itik As New ByIskandar.CariKeDataBaseByIskandar
    Private Sub Button146109033_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button146109033.Click
        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 barang")
            Exit Sub
        End If
        itik.AturPencarianDataBase("barang", "kodebarang", t146109033.Text, 1, konek)
        If itik.JumlanBaris > 0 Then
            MsgBox("kode sudah ada")
            Exit Sub
        End If
        Dim com As New OleDb.OleDbCommand
        com = New OleDb.OleDbCommand("insert into barang(kodebarang,namabarang,hargajual,jumlahbarang) Values('" & t146109033.Text & "','" & t246109033.Text & "'," & Val(t346109033.Text) & "," & Val(t446109033.Text) & ")", konek)
        konek.Open()
        com.ExecuteNonQuery()
        konek.Close()
        com.Dispose()
        t146109033.Text = ""
        t246109033.Text = ""
        t346109033.Text = ""
        t446109033.Text = ""
        Tugas33a46109033.ambil()
    End Sub
End Class

Tidak ada komentar:

Posting Komentar