Quiz Susulan – Soal 1

Berikut ini saya tampilkan form design untuk mencari total pembayaran air menggunakan VB ListView :

Gambar

Listing program :

Public Class Form1

    Sub BuatTabel()

        LV.Columns.Add(“Kode Pelanggan”, 100, HorizontalAlignment.Center)

        LV.Columns.Add(“Nama”, 100, HorizontalAlignment.Left)

        LV.Columns.Add(“Tipe”, 100, HorizontalAlignment.Left)

        LV.Columns.Add(“Daerah”, 100, HorizontalAlignment.Left)

        LV.Columns.Add(“Harga M3”, 100, HorizontalAlignment.Left)

        LV.Columns.Add(“Biaya Beban”, 100, HorizontalAlignment.Left)

        LV.Columns.Add(“Pemakaian Air”, 100, HorizontalAlignment.Left)

        LV.Columns.Add(“Total Tagihan”, 100, HorizontalAlignment.Left)

        LV.Columns.Add(“Pajak”, 100, HorizontalAlignment.Left)

        LV.Columns.Add(“Total Pembayaran”, 100, HorizontalAlignment.Left)

        LV.View = View.Details

        LV.GridLines = True

        LV.FullRowSelect = True

    End Sub

    Sub IsiTabel()

        Dim Lst As New ListViewItem

        Lst.Text = kodepelanggan.Text

        Lst.SubItems.Add(nama.Text)

        Lst.SubItems.Add(tipe.Text)

        Lst.SubItems.Add(daerah.Text)

        Lst.SubItems.Add(hargaM3.Text)

        Lst.SubItems.Add(biayabeban.Text)

        Lst.SubItems.Add(pemakaianair.Text)

        Lst.SubItems.Add(totaltagihan.Text)

        Lst.SubItems.Add(pajak.Text)

        Lst.SubItems.Add(totalpembayaran.Text)

        LV.Items.Add(Lst)

    End Sub

 

 

 

    Private Sub hapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapus.Click

        kodepelanggan.Text = “”

        nama.Text = “”

        tipe.Text = “”

        totaltagihan.Text = “”

        hargaM3.Text = “”

        pajak.Text = “”

        totalpembayaran.Text = “”

        pemakaianair.Text = “”

        daerah.Text = “”

        biayabeban.Text = “”

 

    End Sub

 

 

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

        kodepelanggan.Items.Add(“TOK-MED-100”)

        kodepelanggan.Items.Add(“PAB-BEL-101”)

        kodepelanggan.Items.Add(“SWA-BEL-102”)

        kodepelanggan.Items.Add(“PAB-MED-103”)

        kodepelanggan.Items.Add(“RUM-MED-104”)

 

        BuatTabel()

    End Sub

 

    Private Sub kodepelanggan_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kodepelanggan.SelectedIndexChanged

        Dim x As String

        x = Microsoft.VisualBasic.Right(kodepelanggan.Text, 3)

 

 

 

        If x = “100” Then

            nama.Text = “deni”

        ElseIf x = “101” Then

            nama.Text = “priadi”

        ElseIf x = “102” Then

            nama.Text = “laia”

        ElseIf x = “103” Then

            nama.Text = “dennipri”

        End If

 

 

        x = Microsoft.VisualBasic.Left(kodepelanggan.Text, 3)

 

        If x = “PAB” Then

            hargaM3.Text = 500

            biayabeban.Text = 250000

            tipe.Text = “Pabrik”

        ElseIf x = “TOK” Then

            hargaM3.Text = 500

            biayabeban.Text = 25000

            tipe.Text = “Toko”

        ElseIf x = “RUM” Then

            hargaM3.Text = 500

            biayabeban.Text = 10000

            tipe.Text = “Rumah”

        ElseIf x = “SWA” Then

            hargaM3.Text = 200

            biayabeban.Text = 15000

            tipe.Text = “Swalayan”

        End If

 

        x = Microsoft.VisualBasic.Mid(kodepelanggan.Text, 5, 3)

        If x = “MED” Then

            daerah.Text = “Medan”

        ElseIf x = “BEL” Then

            daerah.Text = “Belawan”

        End If

    End Sub

 

    Private Sub pemakaianair_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles pemakaianair.KeyPress

        If Asc(e.KeyChar) = 13 Then

            totaltagihan.Text = hargaM3.Text * pemakaianair.Text + Val(biayabeban.Text)

            pajak.Text = 0.01 * totaltagihan.Text

            totalpembayaran.Text = Val(totaltagihan.Text) + Val(pajak.Text)

        End If

    End Sub

 

    Private Sub keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keluar.Click

        End

    End Sub

 

    Private Sub simpankelv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles simpankelv.Click

        IsiTabel()

        kodepelanggan.Text = “”

        nama.Text = “”

        tipe.Text = “”

        totaltagihan.Text = “”

        hargaM3.Text = “”

        pajak.Text = “”

        totalpembayaran.Text = “”

        pemakaianair.Text = “”

        daerah.Text = “”

        biayabeban.Text = “”

 

    End Sub

 

    Private Sub hapusdataygdipilih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapusdataygdipilih.Click

        LV.Items.Remove(LV.SelectedItems(0))

    End Sub

 

    Private Sub hapussemuadata_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapussemuadata.Click

        LV.Items.Clear()

    End Sub

End Class

 

Demikian disampaikan, terimakasih… 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s