Kamis, 15 Desember 2016

Membuka Access

Public Class Form1

    Private Sub BtnAdd_Click(sender As Object, e As EventArgs) Handles BtnAdd.Click


        If BtnAdd.Text = "Add" Then
            namabrg.Text = ""
            kodebrg.Text = ""
            kuantitas.Text = ""
            harga.Text = ""
            totharga.Text = ""
            namabrg.Focus()
            BtnAdd.Text = "Save"
        Else

            Objek.Open()
            Dim Add As String = "INSERT INTO TabelSupermarket values ('" & namabrg.Text & "', '" & kodebrg.Text & "', '" & kuantitas.Text & "', '" & harga.Text.Text & "', '" & totharga.Text & "')"
            Dim oCMD = New OleDbCommand(Add, Objek)

            oCMD.ExecuteNonQuery()
            Objek.Close()
            MsgBox("Sukses")
            BtnAdd.Text = "Add"
        End If
    End Sub


    End Sub

    Private Sub BtnFind_Click(sender As Object, e As EventArgs) Handles BtnFind.Click

        Dim Kode As String = InputBox("Masukkan Nama")
        If Not Len(Kode) = 0 Then
            Objek.Close()
            Objek.Open()

            Dim Cari As String = "SELECT * FROM DaftarWP where nama = '" + Kode + "'"
            Dim oCMD = New OleDbCommand(Cari, Objek)
            xReader = oCMD.ExecuteReader

            If xReader.HasRows Then
                xReader.Read()
                namabrg.Text = xReader("tipe")
                kodebrg.Text = xReader("nama")
                kuantitas.Text = xReader("ukuran")
                harga.Text = xReader("umur")
                totharga.Text = xReader("harga")

            Else
                MsgBox("namaWP" + Kode + "tidak ada")
                namabrg.Text = ""
                kodebrg.Text = ""
                kuantitas.Text = ""
                harga.Text.Text = ""
                totharga.Text = ""
                namabrg.Focus()
            End If
        End If
    End Sub

    End Sub

    Private Sub btnEdit_Click(sender As Object, e As EventArgs) Handles btnEdit.Click
        Objek.Close()
        Objek.Open()
        Dim Ubah As String = "UPDATE DaftarWP set tipe = '" & namabrg.Text & "', ukuran = '" & kodebrg.Text & "', umur = '" & kuantitas.Text & "', harga = '" & txtharga.Text & "' where nama = '" & txtnama.Text & "'"
        Dim oCMD = New OleDbCommand(Ubah, Objek)

        oCMD.ExecuteNonQuery()
        Objek.Close()
        MsgBox("Sukses")
    End Sub

    End Sub

    Private Sub btnView_Click(sender As Object, e As EventArgs) Handles btnView.Click
        Form2.Show()
    End Sub



    End Sub

    Private Sub BtnPrint_Click(sender As Object, e As EventArgs) Handles BtnPrint.Click

        Form3.Show()
    End Sub



    End Sub

    Private Sub BtnClose_Click(sender As Object, e As EventArgs) Handles BtnClose.Click
        Me.Close()
    End Sub
    End Sub

    Private Sub BtnDelete_Click(sender As Object, e As EventArgs) Handles BtnDelete.Click
        Objek.Close()
        Objek.Open()

        Dim Hapus As String = "DELETE FROM TabelSupermarket where tipe = '" & txttipe.Text & "'"
        Dim oCMD = New OleDbCommand(Hapus, Objek)
        oCMD.ExecuteNonQuery()

        namabrg.Text = ""
        kodebrg.Text = ""
        kuantitas.Text = ""
        harga.Text.Text = ""
        totharga.Text = ""
        namabrg.Focus()

        MsgBox("Data berhasil dihapus")
    End Sub
    End Sub
End Class