Rabu, 14 Desember 2011

Script Visual Basic Apkomp 4 PNUP - FORM33 A & FORM33 B -

Public Class Form33A_36109006
    Dim dt As New DataTable
    Dim rr As New OleDb.OleDbCommand
    Dim mhh006 As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")

    Public Sub harun()
        Dim muhharun As New OleDb.OleDbDataAdapter
        muhharun = New OleDb.OleDbDataAdapter("select * from barang", mhh006)
        dt.Rows.Clear()
        muhharun.Fill(dt)
        muhharun.Dispose()
    End Sub

    Private Sub Latihan_33A_36109006_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        harun()
        dgv_36109006.DataSource = dt
    End Sub

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

        Form33B_36109006.kb1_36109006.Text = ""
        Form33B_36109006.nb_36109006.Text = ""
        Form33B_36109006.hj_36109006.Text = ""
        Form33B_36109006.jb_36109006.Text = ""
        Form33B_36109006.ee_36109006.Text = "-"
    End Sub

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

        Form33B_36109006.kb1_36109006.Text = dgv_36109006.CurrentRow.Cells("kodebarang").Value
        Form33B_36109006.nb_36109006.Text = dgv_36109006.CurrentRow.Cells("namabarang").Value
        Form33B_36109006.hj_36109006.Text = dgv_36109006.CurrentRow.Cells("hargajual").Value
        Form33B_36109006.jb_36109006.Text = dgv_36109006.CurrentRow.Cells("jumlahbarang").Value
        Form33B_36109006.ee_36109006.Text = dgv_36109006.CurrentRow.Cells("kodebarang").Value

        Form33B_36109006.Show()
    End Sub
    Private Sub hapus_36109006_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapus_36109006.Click
        rr = New OleDb.OleDbCommand("delete * from barang where kodebarang = '" & dgv_36109006.CurrentRow.Cells("kodebarang").Value & "'", mhh006)
        mhh006.Open()
        rr.ExecuteNonQuery()
        mhh006.Close()
        rr.Dispose()

        harun()

    End Sub


End Class


Public Class Form33B_36109006
    Dim harun As New ByIskandar.CariKeDataBaseByIskandar
    Dim rr As New OleDb.OleDbCommand
    Dim mhh As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")

    Private Sub indonesia()
        If kb1_36109006.Text.Length = 0 Then
            MsgBox("Isi yang kosong")
            Exit Sub
        End If

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

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

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

    Private Sub tambah()
        indonesia()
        harun.AturPencarianDataBase("Barang", "KodeBarang", kb1_36109006.Text, 1, mhh)
        If harun.JumlanBaris > 0 Then
            MsgBox("Kode barang sudah ada")
            Exit Sub
        End If

        rr = New OleDb.OleDbCommand("insert into barang (kodebarang, namabarang, hargajual, jumlahbarang) values ('" & kb1_36109006.Text & "','" & nb_36109006.Text & "'," & Val(hj_36109006.Text) & "," & Val(jb_36109006.Text) & ")", mhh)
        mhh.Open()
        rr.ExecuteNonQuery()
        mhh.Close()
        rr.Dispose()

        kb1_36109006.Text = ""
        nb_36109006.Text = ""
        hj_36109006.Text = ""
        jb_36109006.Text = ""

        Form33A_36109006.harun()
    End Sub

    Private Sub edit()
        indonesia()
        If kb1_36109006.Text <> ee_36109006.Text Then
            harun.AturPencarianDataBase("Barang", "KodeBarang", kb1_36109006.Text, 1, mhh)
            If harun.JumlanBaris > 0 Then
                MsgBox("Kode barang sudah ada")
                Exit Sub
            End If
        End If

        rr = New OleDb.OleDbCommand("update barang set kodebarang = '" & kb1_36109006.Text & "', namabarang = '" & nb_36109006.Text & "', hargajual = " & Val(hj_36109006.Text) & ", jumlahbarang = " & Val(jb_36109006.Text) & " where kodebarang = '" & ee_36109006.Text & "'", mhh)

        mhh.Open()
        rr.ExecuteNonQuery()
        mhh.Close()
        rr.Dispose()

        kb1_36109006.Text = ""
        nb_36109006.Text = ""
        hj_36109006.Text = ""
        jb_36109006.Text = ""
        ee_36109006.Text = "-"

        Form33A_36109006.harun()
    End Sub

    Private Sub save_36109006_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save_36109006.Click
        If ee_36109006.Text = "-" Then
            tambah()
        Else
            edit()
        End If
    End Sub

End Class

0 komentar:

Posting Komentar

Diberdayakan oleh Blogger.

BTricks