Kamis, 24 November 2011

APKOM 4 (Latihan 27-28)

Latihan 27

Public Class Latihan27_36109005
    Dim Ismi As New ByIskandar.CariKeDataBaseByIskandar
    Dim KendaraanSimpan As New OleDb.OleDbCommand
    Dim Jalan 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, Jalan)

        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 Cm As New OleDb.OleDbCommand
        Cm = 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) & ")", Jalan)
        Jalan.Open()
        Cm.ExecuteNonQuery()
        Jalan.Close()
        Cm.Dispose()

        t1_36109005.Text = " "
        t2_36109005.Text = " "
        t3_36109005.Text = " "
        t4_36109005.Text = " "
    End Sub
End Class

Latihan 28A

Public Class Latihan28A_36109005
    Dim DT As New DataTable
    Dim IMMHY As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")
    Public Sub ISMI()
        Dim IM As New OleDb.OleDbDataAdapter
        IM = New OleDb.OleDbDataAdapter("select * from barang", IMMHY)
        DT.Rows.Clear()
        IM.Fill(DT)
        IM.Dispose()
    End Sub
    Private Sub Latihan28A_36109005_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ISMI()
        DGV_36109005.DataSource = DT
    End Sub
    Private Sub IN_36109005_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IN_36109005.Click
        If Latihan28B_36109005.Visible = False Then
            Latihan28B_36109005.Show()
        Else
            Latihan28B_36109005.Activate()
        End If
    End Sub
    Private Sub TU_36109005_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TU_36109006.Click
        Close()
    End Sub

End Class

Latihan 28B

Public Class Latihan28B_36109005
    Dim Ismi As New ByIskandar.CariKeDataBaseByIskandar
    Dim KendaraanSimpan As New OleDb.OleDbCommand
    Dim Jalan 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, Jalan)

        If PENCARI.JumlanBaris > 0 Then
            MsgBox("Data sudah dimasukkan")

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

        Dim Cm As New OleDb.OleDbCommand
        Cm = 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) & ")", Jalan)
        Jalan.Open()
        Cm.ExecuteNonQuery()
        Jalan.Close()
        Cm.Dispose()

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

    End Sub
End Class

Tidak ada komentar:

Posting Komentar