Jumat, 25 November 2011

APKOM 4 (Latihan 31-32)

Latihan 31A

Public Class Latihan31A_36109005
    Dim DT As New DataTable
    Dim HP As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")
    Public Sub ISMI()
        Dim AD As New OleDb.OleDbDataAdapter
        AD = New OleDb.OleDbDataAdapter("select * from barang", HP)
        DT.Rows.Clear()
        AD.Fill(DT)
        AD.Dispose()
    End Sub
    Private Sub Latihan31A_36109005_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ISMI()
        DGV_36109005.DataSource = DT
    End Sub
    Private Sub EDIT_36109005_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EDIT_36109005.Click
        If Latihan31B_36109005.Visible = False Then
            Latihan31B_36109005.Show()
        Else
            Latihan31B_36109005.Activate()
        End If

        Latihan31B_36109005.KB_36109005.Text = DGV_36109005.CurrentRow.Cells("kodebarang").Value
        Latihan31B_36109005.t1_36109005.Text = DGV_36109005.CurrentRow.Cells("kodebarang").Value
        Latihan31B_36109005.t2_36109005.Text = DGV_36109005.CurrentRow.Cells("namabarang").Value
        Latihan31B_36109005.t3_36109005.Text = DGV_36109005.CurrentRow.Cells("hargajual").Value
        Latihan31B_36109005.t4_36109005.Text = DGV_36109005.CurrentRow.Cells("jumlahbarang").Value

        Latihan31B_36109005.Show()
    End Sub
End Class

Latihan 31B

Public Class Latihan31B_36109005
    Dim ISMI As New ByIskandar.CariKeDataBaseByIskandar
    Dim CM As New OleDb.OleDbCommand
    Dim MISCOL As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")
    Private Sub Simpan_36109005_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Simpan_36109005.Click
        If t1_36109005.Text.Length = 0 Then
            MsgBox("Masukkan teks")
            Exit Sub
        End If

        If t2_36109005.Text.Length = 0 Then
            MsgBox("Masukkan teks")
            Exit Sub
        End If

        If Val(t3_36109005.Text) = 0 Then
            MsgBox("Masukkan teks")
            Exit Sub
        End If

        If Val(t4_36109005.Text) = 0 Then
            MsgBox("Masukkan teks")
            Exit Sub
        End If

        If t1_36109005.Text <> KB_36109005.Text Then
            ISMI.AturPencarianDataBase("Barang", "KodeBarang", t1_36109005.Text, 1, MISCOL)
            If ISMI.JumlanBaris > 0 Then
                MsgBox("Kode Barang Sudah Ada")
                Exit Sub
            End If
        End If

        CM = New OleDb.OleDbCommand("update barang set kodebarang = '" & t1_36109005.Text & "', namabarang = '" & t2_36109005.Text & "', hargajual = " & Val(t3_36109005.Text) & ", jumlahbarang = " & Val(t4_36109005.Text) & " where kodebarang = '" & KB_36109005.Text & "'", MISCOL)

        MISCOL.Open()
        CM.ExecuteNonQuery()
        MISCOL.Close()
        CM.Dispose()

        t1_36109005.Text = ""
        t2_36109005.Text = ""
        t3_36109005.Text = ""
        t4_36109005.Text = ""
        KB_36109005.Text = "-"

        Latihan31A_36109005.ISMI()
    End Sub
End Class 
Latihan 32A

Public Class Latihan32A_36109005
    Dim DT As New DataTable
    Dim SS As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")
    Public Sub ISMI()
        Dim AD As New OleDb.OleDbDataAdapter
        AD = New OleDb.OleDbDataAdapter("select * from barang", SS)
        DT.Rows.Clear()
        AD.Fill(DT)
        AD.Dispose()
    End Sub
    Private Sub Latihan32A_36109005_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ISMI()
        DGV_36109005.DataSource = DT
    End Sub
    Private Sub T_36109005_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles T_36109005.Click
        If Latihan32B_36109005.Visible = False Then
            Latihan32B_36109005.Show()
        Else
            Latihan32B_36109005.Activate()
        End If

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

        Latihan32C_36109005.KB_36109005.Text = DGV_36109005.CurrentRow.Cells("kodebarang").Value
        Latihan32C_36109005.t1_36109005.Text = DGV_36109005.CurrentRow.Cells("kodebarang").Value
        Latihan32C_36109005.t2_36109005.Text = DGV_36109005.CurrentRow.Cells("namabarang").Value
        Latihan32C_36109005.t3_36109005.Text = DGV_36109005.CurrentRow.Cells("hargajual").Value
        Latihan32C_36109005.t4_36109005.Text = DGV_36109005.CurrentRow.Cells("jumlahbarang").Value

        Latihan32C_36109005.Show()
    End Sub
End Class

Latihan 32B

Public Class Latihan32B_36109005
    Dim IMMY As New ByIskandar.CariKeDataBaseByIskandar
    Dim KALI As New OleDb.OleDbCommand
    Dim BAGI As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" & Application.StartupPath & "\DataBarang.ACCDB")
    Private Sub Simpan_36109005_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Simpan_36109005.Click
        If t1_36109005.Text.Length = 0 Then
            MsgBox("Masukkan teks")
            Exit Sub
        End If

        If t2_36109005.Text.Length = 0 Then
            MsgBox("Masukkan teks")
            Exit Sub
        End If

        If Val(t3_36109005.Text) = 0 Then
            MsgBox("Masukkan Teks")
            Exit Sub
        End If

        If Val(t4_36109005.Text) = 0 Then
            MsgBox("Masukkan teks")
            Exit Sub
        End If

        Dim PENCARI As New ByIskandar.CariKeDataBaseByIskandar
        PENCARI.AturPencarianDataBase("BARANG", "KODEBARANG", t1_36109005.Text, 1, BAGI)

        If PENCARI.JumlanBaris > 0 Then
            MsgBox("Kode Barang Sudah Ada")

            t1_36109005.Text = " "
            t2_36109005.Text = " "
            t3_36109005.Text = " "
            t4_36109005.Text = " "
            Exit Sub
        End If

        Dim MI As New OleDb.OleDbCommand
        MI = New OleDb.OleDbCommand("INSERT INTO BARANG (KODEBARANG, NAMABARANG, HARGAJUAL, JUMLAHBARANG) VALUES ('" & t1_36109005.Text & "','" & t2_36109005.Text & "', " & Val(t3_36109005.Text) & "," & Val(t4_36109005.Text) & ")", BAGI)
        BAGI.Open()
        MI.ExecuteNonQuery()
        BAGI.Close()
        MI.Dispose()

        t1_36109005.Text = " "
        t2_36109005.Text = " "
        t3_36109005.Text = " "
        t4_36109005.Text = " "
    End Sub
End Class 
Latihan 32C

Public Class Latihan32C_36109005
    Dim IM As New OleDb.OleDbCommand
    Dim ISMI As New ByIskandar.CariKeDataBaseByIskandar
    Dim MI As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")
    Private Sub Simpan_36109005_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Simpan_36109005.Click
        If t1_36109005.Text.Length = 0 Then
            MsgBox("Masukkan teks")
            Exit Sub
        End If

        If t2_36109005.Text.Length = 0 Then
            MsgBox("Masukkan teks")
            Exit Sub
        End If

        If Val(t3_36109005.Text) = 0 Then
            MsgBox("Masukkan teks")
            Exit Sub
        End If

        If Val(t4_36109005.Text) = 0 Then
            MsgBox("Masukkan teks")
            Exit Sub
        End If

        If kb_36109005.Text <> t1_36109005.Text Then

            ISMI.AturPencarianDataBase("Barang", "KodeBarang", t1_36109005.Text, 1, MI)
            If ISMI.JumlanBaris > 0 Then
                MsgBox("Kode Barang Sudah Ada")
                Exit Sub
            End If
        End If

        IM = New OleDb.OleDbCommand("update barang set kodebarang = '" & t1_36109005.Text & "', namabarang = '" & t2_36109005.Text & "', hargajual = " & Val(t3_36109005.Text) & ", jumlahbarang = " & Val(t4_36109005.Text) & " where kodebarang = '" & KB_36109005.Text & "'", MI)
        MI.Open()
        IM.ExecuteNonQuery()
        MI.Close()
        IM.Dispose()

        KB_36109005.Text = ""
        t1_36109005.Text = ""
        t2_36109005.Text = ""
        t3_36109005.Text = ""
        t4_36109005.Text = ""

        Latihan32A_36109005.ISMI()
    End Sub
End Class

Tidak ada komentar:

Posting Komentar