Friday, November 1, 2013

Contoh Program Penjualan Barang Menggunakan Listview Pada VB.Net

Public Class Penjualan_Barang

    Private Sub Penjualan_Barang_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For x = 1 To 8
            Kode_Barang.Items.Add("KOO" & x)
        Next
        LV.Columns.Add("Kode Barang", 100, HorizontalAlignment.Center)
        LV.Columns.Add("Nama Barang", 100, HorizontalAlignment.Center)
        LV.Columns.Add("Harga Barang", 100, HorizontalAlignment.Center)
        LV.Columns.Add("Stok", 50, HorizontalAlignment.Center)
        LV.Columns.Add("Jumlah Beli", 100, HorizontalAlignment.Center)
        LV.Columns.Add("Total Harga", 100, HorizontalAlignment.Center)
        LV.GridLines = True
        LV.FullRowSelect = True
        LV.View = View.Details
    End Sub

    Private Sub Kode_Barang_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Kode_Barang.SelectedIndexChanged
        Select Case Kode_Barang.Text
            Case "KOO1"
                Nama_Barang.Text = "Laptop"
                Harga_Barang.Text = 6000000
                Stok.Text = 6
            Case "KOO2"
                Nama_Barang.Text = "VCD"
                Harga_Barang.Text = 200000
                Stok.Text = 9
            Case "KOO3"
                Nama_Barang.Text = "Kulkas"
                Harga_Barang.Text = 5000000
                Stok.Text = 7
            Case "KOO4"
                Nama_Barang.Text = "Flasdisk"
                Harga_Barang.Text = 75000
                Stok.Text = 5
            Case "KOO5"
                Nama_Barang.Text = "TV"
                Harga_Barang.Text = 2000000
                Stok.Text = 2
            Case "KOO6"
                Nama_Barang.Text = "Dispenser"
                Harga_Barang.Text = 500000
                Stok.Text = 3
            Case "KOO7"
                Nama_Barang.Text = "Hardisk"
                Harga_Barang.Text = 1000000
                Stok.Text = 1
            Case Else
                Nama_Barang.Text = "DVD Eksternal"
                Harga_Barang.Text = 500000
                Stok.Text = 10
        End Select
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Me.Close()
    End Sub

    Private Sub Jumlah_Beli_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Jumlah_Beli.KeyPress
        If e.KeyChar = Chr(13) Then
            If Val(Jumlah_Beli.Text) > Val(Stok.Text) Then
                MsgBox("Stok Barang Tidak Cukup")
            Else
                Total_Harga.Text = Val(Jumlah_Beli.Text) * Val(Harga_Barang.Text)
            End If
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        LV.Items.Remove(LV.SelectedItems(0))
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim simpan As New ListViewItem
        simpan.Text = Kode_Barang.Text
        simpan.SubItems.Add(Nama_Barang.Text)
        simpan.SubItems.Add(Harga_Barang.Text)
        simpan.SubItems.Add(Stok.Text)
        simpan.SubItems.Add(Jumlah_Beli.Text)
        simpan.SubItems.Add(Total_Harga.Text)
        LV.Items.Add(simpan)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        LV.Items.Clear()
    End Sub
End Class



Hasil :


No comments: