Minggu, 17 Januari 2016

Program Pemakaian Listrik menggunakan Listview dengan VB Net 2008

senin 18 januari 2016




Buatlah program untuk menampilkan hasil ke listview untuk Kasus Pemrograman Pemakaian Listrik

Kemudian Masuk kan Listing Program Berikut:

Public Class Form1
    Sub buattable()
        lv.Columns.Add("No Pelanggan", 60, HorizontalAlignment.Center)
        lv.Columns.Add("nama daerah", 80, HorizontalAlignment.Center)
        lv.Columns.Add("tipe", 70, HorizontalAlignment.Center)
        lv.Columns.Add("Biaya", 65, HorizontalAlignment.Center)
        lv.Columns.Add("Harga PerKWH", 65, HorizontalAlignment.Center)
        lv.Columns.Add("Meter Sekarang", 80, HorizontalAlignment.Center)
        lv.Columns.Add("Meter Lalu", 70, HorizontalAlignment.Center)
        lv.Columns.Add("Pemakaian", 65, HorizontalAlignment.Center)
        lv.Columns.Add("Total Tagihan", 65, HorizontalAlignment.Center)
        lv.Columns.Add("Pajak", 65, HorizontalAlignment.Center)
        lv.Columns.Add("Pembayaran", 65, HorizontalAlignment.Center)

        Lv.GridLines = True
        Lv.FullRowSelect = True
        Lv.View = View.Details
    End Sub
    Sub isitable()
        Dim x As New ListViewItem
        With x
            .Text = nmr.Text
            .SubItems.Add(daerah.Text)
            .SubItems.Add(tipe.Text)
            .SubItems.Add(Bbeban.Text)
            .SubItems.Add(kwh.Text)
            .SubItems.Add(MMini.Text)
            .SubItems.Add(MMlalu.Text)
            .SubItems.Add(pemakai.Text)
            .SubItems.Add(total.Text)
            .SubItems.Add(pajak.Text)
            .SubItems.Add(bayar.Text)
            lv.Items.Add(x)
        End With

    End Sub

    Sub add_daerah()
        With daerah
            .Items.Add("MEDAN")
            .Items.Add("BELAWAN")
            .Items.Add("AKSARA")
            .Items.Add("MARENDAL")
            .Items.Add("BINJAI")
            .Items.Add("LUBUK PAKAM")
        End With
    End Sub
    Sub add_tipe()
        With tipe
            .Items.Add("TOKO")
            .Items.Add("RUMAH")
            .Items.Add("SWALAYAN")
            .Items.Add("PABRIK")
        End With
    End Sub


    Private Sub tipe_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tipe.SelectedIndexChanged
        If tipe.Text = "TOKO" Then
            Bbeban.Text = 150000
            kwh.Text = 500
        ElseIf tipe.Text = "RUMAH" Then
            kwh.Text = 200
            Bbeban.Text = 50000
        ElseIf tipe.Text = "SWALAYAN" Then
            kwh.Text = 1500
            Bbeban.Text = 400000
        ElseIf tipe.Text = "PABRIK" Then
            kwh.Text = 1000
            Bbeban.Text = 1000000
        End If

        MMini.Text = ""
        MMlalu.Text = ""
        pemakai.Text = ""
        total.Text = ""
        pajak.Text = ""
        bayar.Text = ""
        nmr.Text = ""
    End Sub
    Sub bersih()
        nmr.Text = ""
        daerah.Text = ""
        tipe.Text = ""
        Bbeban.Text = ""
        kwh.Text = ""
        MMini.Text = ""
        MMlalu.Text = ""
        pemakai.Text = ""
        total.Text = ""
        pajak.Text = ""
        bayar.Text = ""
    End Sub
    Sub add_nmr()
        Dim x, y, z As String
        x = Microsoft.VisualBasic.Left(daerah.Text, 3)
        y = Microsoft.VisualBasic.Left(tipe.Text, 3)
        z = "00" & (tipe.SelectedIndex + 1)
        nmr.Text = x & "-" & y & "-" & z
    End Sub
    Private Sub MMlalu_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MMlalu.KeyPress
        If e.KeyChar = Chr(13) Then
            If MMlalu.Text = "" Or MMini.Text = "" Then
                MsgBox("Isi Dengan Benar")
            Else
                If IsNumeric(MMlalu.Text) = True And IsNumeric(MMini.Text) = True Then

                    pemakai.Text = MMini.Text - MMlalu.Text
                    total.Text = Bbeban.Text + (pemakai.Text * kwh.Text)
                    pajak.Text = (15 / 100) * total.Text
                    bayar.Text = Val(total.Text) + Val(pajak.Text)
                    Call add_nmr()
                Else
                    MsgBox("isi dengan angka !!!")
                    pemakai.Text = ""
                    total.Text = ""
                    pajak.Text = ""
                    bayar.Text = ""
                    nmr.Text = ""

                End If
            End If
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call add_daerah()
        Call add_tipe()
        Call buattable()
    End Sub

    Private Sub daerah_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles daerah.SelectedIndexChanged
        Dim i As String
        i = daerah.Text
        bersih()
        daerah.Text = i

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        bersih()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        isitable()
    End Sub

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

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


Demikilahlah postingan saya  Nama : (Martua panggabean)  NPM : 14110534)

Tidak ada komentar:

Posting Komentar