Minggu, 02 Juni 2013

Latihan Listview Perhitungan Penjualan Barang

mesran.net




Public Class Form2
    Sub BuatTabel()
        lv.Columns.Add("Penjual", 80, HorizontalAlignment.Center)
        lv.Columns.Add("Kode Barang", 100, HorizontalAlignment.Left)
        lv.Columns.Add("Nama Barang", 100, HorizontalAlignment.Left)
        lv.Columns.Add("Merk", 100, HorizontalAlignment.Left)
        lv.Columns.Add("Jumlah Jual", 100, HorizontalAlignment.Left)
        lv.Columns.Add("Harga", 100, HorizontalAlignment.Left)
        lv.Columns.Add("Total Harga", 100, HorizontalAlignment.Left)

        lv.View = View.Details
        lv.GridLines = True
        lv.FullRowSelect = True
    End Sub
    Sub isitabel()
        Dim lst As New ListViewItem
        lst.Text = penjual.Text
        lst.SubItems.Add(kdbrg.Text)
        lst.SubItems.Add(nmbrg.Text)
        lst.SubItems.Add(merk.Text)
        lst.SubItems.Add(jmljual.Text)
        lst.SubItems.Add(harga.Text)
        lst.SubItems.Add(Total.Text)
        lv.Items.Add(lst)
    End Sub

    Private Sub kdbrg_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kdbrg.SelectedIndexChanged
        Dim X As String
        Dim y As String

        X = Microsoft.VisualBasic.Left(kdbrg.Text, 2)
        y = Microsoft.VisualBasic.Right(kdbrg.Text, 3)
        Select Case X
            Case "AP" : merk.Text = "APPLE"
            Case "HP" : merk.Text = "HP"

        End Select
        Select Case y
            Case "001" : nmbrg.Text = "LAPTOP CORE i3"
            Case "002" : nmbrg.Text = "LAPTOP CORE i5"
        End Select

        If X = "AP" And y = "001" Then
            harga.Text = 7500000
        ElseIf X = "AP" And y = "002" Then
            harga.Text = 8987000
        ElseIf X = "HP" And y = "001" Then
            harga.Text = 8500000
        ElseIf X = "HP" And y = "002" Then
            harga.Text = 8907000



        End If

    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        BuatTabel()

        kdbrg.Items.Add("AP001")
        kdbrg.Items.Add("AP002")
        kdbrg.Items.Add("HP001")
        kdbrg.Items.Add("HP002")

    End Sub

    Private Sub btnbatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbatal.Click
        penjual.Text = ""
        kdbrg.Text = ""
        nmbrg.Text = ""
        merk.Text = ""
        jmljual.Text = ""
        harga.Text = ""
    End Sub

    Private Sub btnhps_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhps.Click
        End
    End Sub

    Private Sub pembeli_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles penjual.TextChanged

    End Sub

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lv.SelectedIndexChanged

    End Sub

    Private Sub hapussemua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapussemua.Click
        lv.Items.Clear()
    End Sub

    Private Sub hapusdipilih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapusdipilih.Click
        lv.Items.Remove(lv.SelectedItems(0))
    End Sub

    Private Sub simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles simpan.Click
        isitabel()
        penjual.Text = ""
        kdbrg.Text = ""
        nmbrg.Text = ""
        merk.Text = ""
        jmljual.Text = ""
        harga.Text = ""
        Total.Text = ""

    End Sub

    Private Sub Btnproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnproses.Click
        Total.Text = harga.Text * jmljual.Text
    End Sub

    Private Sub harga_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles harga.TextChanged

    End Sub
End Class