Minggu, 20 November 2011

TUGAS APKOM LATIHAN 27-30


Public Class LATIHAN27_46109051

   
    Public Class LATIHAN27_46109051

    Dim WAHDA As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\DATABARANG.accdb;jet oledb:database password=WAHDANIAH")

    Private Sub save_46109051_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save_46109051.Click
        If t1_46109051.Text.Length = 0 Then
            MsgBox("Isi dulu sayang yang kosong")
            Exit Sub
        End If

        If t2_46109051.Text.Length = 0 Then
            MsgBox("Isi dulu sayang yang kosong")
            Exit Sub
        End If

        If Val(t3_46109051.Text) = 0 Then
            MsgBox("Isi dulu sayang yang kosong")
            Exit Sub
        End If

        If Val(t4_46109051.Text) = 0 Then
            MsgBox("Isi dulu sayang yang kosong")
            Exit Sub
        End If

        Dim Niah As New OleDb.OleDbCommand
        Niah = New OleDb.OleDbCommand("insert into barang (kodebarang, namabarang, hargajual, jumlahbarang) values ('" & t1_46109051.Text & "','" & t2_46109051.Text & "'," & Val(t3_46109051.Text) & "," & Val(t4_46109051.Text) & ")", WAHDA)

        wahda.Open()
        Niah.ExecuteNonQuery()
        WAHDA.Close()
        Niah.Dispose()

        t1_46109051.Text = ""
        t2_46109051.Text = ""
        t3_46109051.Text = ""
        t4_46109051.Text = ""

    End Sub

End Class



LATIHAN 28A
Public Class LATIHAN28A_46109051

    Dim go As New OleDb.OleDbConnection("provider = microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\databarang.accdb;jet OLEDB:database password=WAHDANIAH")
    Dim take As New DataTable

    Public Sub ambildata()
        Dim data As New OleDb.OleDbDataAdapter
        data = New OleDb.OleDbDataAdapter("SELECT*from BARANG", go)
        take.Rows.Clear()
        data.Fill(take)
        data.Dispose()
    End Sub

    Private Sub LATIHAN28A_46109051_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ambildata()
        dg46109051.DataSource = take
    End Sub

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

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub
End Class









LATIHAN 28B
Public Class LATIHAN28B_46109051
    Dim go As New OleDb.OleDbConnection("provider = microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\databarang.accdb;jet OLEDB:database password=WAHDANIAH")
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles simpan.Click
        If TB146109051.Text.Length = 0 Then
            MsgBox("please insert your text")
            Exit Sub
        End If
        If TB246109051.Text.Length = 0 Then
            MsgBox("please insert your text")
            Exit Sub
        End If
        If Val(TB346109051.Text) = 0 Then
            MsgBox("please insert your text")
            Exit Sub
        End If
        If Val(TB446109051.Text) = 0 Then
            MsgBox("please insert your text")
            Exit Sub
        End If

    Dim PENCARI As New ByIskandar.CariKeDataBaseByIskandar
        PENCARI.AturPencarianDataBase("BARANG", "KODEBARANG", TB146109051.Text, 1, go)
        If PENCARI.JumlanBaris > 0 Then
            MsgBox("the data has been exist please insert new data")
            TB146109051.Text = ""
            TB246109051.Text = ""
            TB346109051.Text = ""
            TB446109051.Text = ""
            Exit Sub
        End If
Dim Cm As New OleDb.OleDbCommand
        Cm = New OleDb.OleDbCommand("INSERT INTO BARANG(KODEBARANG,NAMABARANG,HARGAJUAL,JUMLAHBARANG)VALUES ('" & TB146109051.Text & "','" & TB246109051.Text & "'," & Val(TB346109051.Text) & "," & Val(TB446109051.Text) & " )", go)
        go.Open()
        Cm.ExecuteNonQuery()
        go.Close()
        Cm.Dispose()
        TB146109051.Text = ""
        TB246109051.Text = ""
        TB346109051.Text = ""
        TB446109051.Text = ""
        LATIHAN28A_46109051.ambildata()
        Me.Close()
    End Sub

    End Class
LATIHAN 29
Public Class LATIHAN29_46109051
    Dim go As New OleDb.OleDbConnection("provider = microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\databarang.accdb;jet OLEDB:database password=WAHDANIAH")

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If kb46109051.Text.Length = 0 Then
            MsgBox("please insert your text")
            Exit Sub
        End If
        If TB146109051.Text.Length = 0 Then
            MsgBox("please insert your text")
            Exit Sub
        End If
        If TB246109051.Text.Length = 0 Then
            MsgBox("please insert your text")
            Exit Sub
        End If
        If Val(TB346109051.Text) = 0 Then
            MsgBox("please insert your text")
            Exit Sub
        End If
        If Val(TB446109051.Text) = 0 Then
            MsgBox("please insert your text")
            Exit Sub
        End If
        Dim PENCARI As New ByIskandar.CariKeDataBaseByIskandar
        PENCARI.AturPencarianDataBase("BARANG","KODEBARANG", TB146109051.Text, 1, go)
        If PENCARI.JumlanBaris > 0 Then
            MsgBox("the data has been exist please insert new data")
            kb46109051.Text = ""
            TB246109051.Text = ""
            TB346109051.Text = ""
            TB446109051.Text = ""
            Exit Sub
        End If

        Dim Cm As New OleDb.OleDbCommand
        Cm = New OleDb.OleDbCommand("update BARANG set KODEBARANG ='" & TB146109051.Text & "' , NAMABARANG = '" & TB246109051.Text & "' , HARGAJUAL=" & Val(TB346109051.Text) & ", JUMLAHBARANG =" & Val(TB446109051.Text) & " where KODEBARANG ='" & kb46109051.Text & "'", go)
        go.Open()
        Cm.ExecuteNonQuery()
        go.Close()
        Cm.Dispose()
        kb46109051.Text = ""
        TB146109051.Text = ""
        TB246109051.Text = ""
        TB346109051.Text = ""
        TB446109051.Text = ""
    End Sub
End Class
LATIHAN 30A
Public Class LATIHAN30A_46109051
    Dim nia As New OleDb.OleDbConnection("provider = microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\databarang.accdb;jet OLEDB:database password=WAHDANIAH")
    Dim ambil As New DataTable

    Public Sub ambildata()
        Dim data As New OleDb.OleDbDataAdapter
        data = New OleDb.OleDbDataAdapter("SELECT* FROM BARANG", nia)
        ambil.Rows.Clear()
        data.Fill(ambil)
        data.Dispose()
    End Sub

    Private Sub LATIHAN30A_46109051_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ambildata()
        dg46109051.DataSource = ambil
    End Sub
    Private Sub Button1_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If LATIHAN30B_46109051.Visible = False Then
            LATIHAN30B_46109051.Show()
        Else
            LATIHAN30B_46109051.Activate()
        End If
        LATIHAN30B_46109051.kb46109051.Text = dg46109051.CurrentRow.Cells("KODEBARANG").Value
        LATIHAN30B_46109051.TB146109051.Text = dg46109051.CurrentRow.Cells("KODEBARANG").Value
        LATIHAN30B_46109051.TB246109051.Text = dg46109051.CurrentRow.Cells("NAMABARANG").Value
        LATIHAN30B_46109051.TB346109051.Text = dg46109051.CurrentRow.Cells("HARGAJUAL").Value
        LATIHAN30B_46109051.TB446109051.Text = dg46109051.CurrentRow.Cells("JUMLAHBARANG").Value
    End Sub
End Class












LATIHAN30B
Public Class LATIHAN30B_46109051

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

    Private Sub Button1_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TB146109051.Text.Length = 0 Then
            MsgBox("please insert your text")
            Exit Sub
        End If
        If TB246109051.Text.Length = 0 Then
            MsgBox("please insert your text")
            Exit Sub
        End If
        If Val(TB346109051.Text) = 0 Then
            MsgBox("please insert your text")
            Exit Sub
        End If
        If Val(TB446109051.Text) = 0 Then
            MsgBox("please insert your text")
            Exit Sub
        End If
        If kb46109051.Text <> TB146109051.Text Then
            Dim PENCARI As New ByIskandar.CariKeDataBaseByIskandar
            PENCARI.AturPencarianDataBase("BARANG","KODEBARANG", TB146109051.Text, 1, nia)
            If PENCARI.JumlanBaris > 0 Then
                MsgBox("the data has been exist please insert new data")
                TB146109051.Text = ""
                TB246109051.Text = ""
                TB346109051.Text = ""
                TB446109051.Text = ""
                Exit Sub
            End If
        End If

        Dim Cm As New OleDb.OleDbCommand
        Cm = New OleDb.OleDbCommand("update BARANG set KODEBARANG ='" & TB146109051.Text & "', NAMABARANG = '" & TB246109051.Text & "', HARGAJUAL=" & Val(TB346109051.Text) & ", JUMLAHBARANG=" & Val(TB446109051.Text) & " where KODEBARANG='" & kb46109051.Text & "'", nia)
        nia.Open()
        Cm.Dispose()
        kb46109051.Text = ""
        TB146109051.Text = ""
        TB246109051.Text = ""
        TB346109051.Text = ""
        TB446109051.Text = ""
        LATIHAN30A_46109051.ambildata()
        Me.Close()
    End Sub
End Class