Sabtu, 19 November 2011

LATIHAN 31 APKOM

Public Class tugas31a46109033
    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 DataTable
    Public Sub ambil()
        Dim data As New OleDb.OleDbDataAdapter
        data = New OleDb.OleDbDataAdapter("SELECT* FROM barang", konek)
        itik.Rows.Clear()
        data.Fill(itik)
        data.Dispose()
    End Sub
    Private Sub tugas31a46109033_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ambil()
        DataGridView146109033.DataSource = itik
    End Sub
    Private Sub Button146109033_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button146109033.Click, Button146109033.Click
        If tugas31b46109033.Visible = False Then
            tugas31b46109033.Show()
        Else
            tugas31b46109033.Activate()
        End If
        tugas31b46109033.KB.Text = DataGridView146109033.CurrentRow.Cells("KODEBARANG").Value
        tugas31b46109033.t146109033.Text = DataGridView146109033.CurrentRow.Cells("KODEBARANG").Value
        tugas31b46109033.t246109033.Text = DataGridView146109033.CurrentRow.Cells("NAMABARANG").Value
        tugas31b46109033.t346109033.Text = DataGridView146109033.CurrentRow.Cells("HARGAJUAL").Value
        tugas31b46109033.t446109033.Text = DataGridView146109033.CurrentRow.Cells("JUMLAHBARANG").Value
    End Sub
End Class


Public Class tugas31b46109033
    Dim konek As New OleDb.OleDbConnection("provider = microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\databarang.accdb;jet OLEDB:database password=2121990")

    Private Sub Button146109033_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button146109033.Click
        If t146109033.Text.Length = 0 Then
            MsgBox("Please insert your text")
            Exit Sub
        End If
        If t246109033.Text.Length = 0 Then
            MsgBox("Please insert your text")
            Exit Sub
        End If
        If Val(t346109033.Text) = 0 Then
            MsgBox("Please insert your text")
            Exit Sub
        End If
        If Val(t446109033.Text) = 0 Then
            MsgBox("Please insert your text")
            Exit Sub
        End If
        If KB.Text <> t146109033.Text Then
            Dim PENCARI As New ByIskandar.CariKeDataBaseByIskandar
            PENCARI.AturPencarianDataBase("BARANG", "KODEBARANG", t146109033.Text, 1, konek)
            If PENCARI.JumlanBaris > 0 Then
                MsgBox("the data has been exist please insert new data")
                t146109033.Text = ""
                t246109033.Text = ""
                t346109033.Text = ""
                t446109033.Text = ""
                Exit Sub
            End If
        End If
        Dim itik As New OleDb.OleDbCommand
        itik = 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()
        itik.ExecuteNonQuery()
        konek.Close()
        itik.Dispose()
        KB.Text = ""
        t146109033.Text = ""
        t246109033.Text = ""
        t346109033.Text = ""
        t446109033.Text = ""
        tugas31a46109033.ambil()
        Me.Close()
    End Sub
End Class

Tidak ada komentar:

Posting Komentar