Kali ini saya akan membagikan sedikit tentang Menghitung Barang Menggunakan ListView pada VB 2008.
1). Rancangan
2). Koding
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
KodeBrg()
Buattabel()
Bersih()
Nopembelian.Text = 1
End Sub
Sub CeKNoFaktur()
Dim i As String
i = 1
If Nopembelian.Text = 1 Then
Nopembelian.Text = i + 1
Else
Nopembelian.Text = Val(i) + Val(Nopembelian.Text)
End If
End Sub
Sub Buattabel()
With Lv
.GridLines = True
.FullRowSelect = True
.View = View.Details
.Columns.Add("No Faktur", 80)
.Columns.Add("Kode Brg", 100)
.Columns.Add("Nama Brg", 160)
.Columns.Add("Satuan", 100)
.Columns.Add("Harga", 100)
.Columns.Add("Jumlah Beli", 100)
.Columns.Add("Total Harga", 120)
End With
End Sub
Sub KodeBrg()
Kode.Items.Add("TS001")
Kode.Items.Add("TS002")
Kode.Items.Add("VG001")
Kode.Items.Add("VG002")
End Sub
Sub IsiTabel()
Dim lst As New ListViewItem
With lst
.Text = Nopembelian.Text
.SubItems.Add(Kode.Text)
.SubItems.Add(Nama.Text)
.SubItems.Add(Merk.Text)
.SubItems.Add(Harga.Text)
.SubItems.Add(Jumlah.Text)
.SubItems.Add(Total.Text)
End With
Lv.Items.Add(lst)
CekTotal()
End Sub
Sub Bersih()
Kode.Text = ""
Nama.Text = ""
Merk.Text = ""
Jumlah.Text = ""
Harga.Text = ""
Total.Text = ""
Nopembelian.Enabled = False
Total.Enabled = False : Nama.Enabled = False
Merk.Enabled = False : Harga.Enabled = False : Totalbayar.Enabled = False
End Sub
Sub CekTotal()
Dim bobot As Long
Dim I As Integer
bobot = 0
For I = 0 To lv.Items.Count - 1
bobot = bobot + Val(Lv.Items(I).SubItems(6).Text)
Next
Totalbayar.Text = "Rp. " & Format(bobot, "###,###,###")
End Sub
Private Sub Kode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Kode.SelectedIndexChanged
Dim x, y As String
x = Strings.Left(Kode.Text, 2)
y = Strings.Right(Kode.Text, 3)
Select Case x
Case "TS"
Merk.Text = "Toshiba"
Select Case y
Case "001"
Nama.Text = "FlashDisk 4GB"
Harga.Text = 105000
Case "002"
Nama.Text = "FlashDisk 2GB"
Harga.Text = 75000
End Select
Case "VG"
Merk.Text = "V_Gen"
Select Case y
Case "001"
Nama.Text = "FlashDisk 4GB"
Harga.Text = 90000
Case "002"
Nama.Text = "FlashDisk 2GB"
Harga.Text = 60000
End Select
End Select
Jumlah.Focus()
End Sub
Private Sub Simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Simpan.Click
IsiTabel()
Bersih()
CeKNoFaktur()
End Sub
Private Sub Jumlah_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Jumlah.KeyPress
If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then
e.Handled = True
End If
End Sub
Private Sub Jumlah_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Jumlah.TextChanged
If Jumlah.Text = "" Then
Exit Sub
Else
Total.Text = Harga.Text * Jumlah.Text
End If
End Sub
Private Sub Hapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Hapus.Click
Lv.Items.Clear()
Totalbayar.Text = ""
End Sub
Private Sub Batal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Batal.Click
Bersih()
End Sub
Private Sub HapusData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HapusData.Click
Lv.Items.Remove(Lv.SelectedItems(0))
Dim bobot As Long
Dim I As Integer
bobot = 0
For I = 0 To Lv.Items.Count - 1
bobot = Val(Lv.Items(I).SubItems(6).Text) - bobot
Next
Totalbayar.Text = "Rp. " & Format(bobot, "###,###,###")
End Sub
Private Sub Keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Keluar.Click
Me.Close()
End Sub
End Class
Selesai, silahkan disikat kodingnya gan....
Coppas dari: http://citrashare.blogspot.co.id/2013/12/perhitungan-penjualan-barang.html
0 komentar:
Speak up your mind
Tell us what you're thinking... !