Selasa, 24 Januari 2012

VB-Net Halaman 32

PublicClass Form1
Dim LST As ListViewItem
PrivateSub kode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kode.SelectedIndexChanged
SelectCase kode.Text
Case"TS001"
                Microsoft.VisualBasic.Right(kode.Text, 3)
                nama.Text = "Flashdisk 4GB"
                Microsoft.VisualBasic.Left(kode.Text, 2)
                merk.Text = "Toshiba"
Case"TS002"
                Microsoft.VisualBasic.Right(kode.Text, 3)
                nama.Text = "Flashdisk 2GB"
                Microsoft.VisualBasic.Left(kode.Text, 2)
                merk.Text = "Toshiba"
Case"VG001"
                Microsoft.VisualBasic.Right(kode.Text, 3)
                nama.Text = "Flashdisk 4GB"
                Microsoft.VisualBasic.Left(kode.Text, 2)
                merk.Text = "V-Gen"
Case"VG002"
                Microsoft.VisualBasic.Right(kode.Text, 3)
                nama.Text = "Flashdisk 2GB"
                Microsoft.VisualBasic.Left(kode.Text, 2)
                merk.Text = "V-gen"
EndSelect

If kode.Text = "TS001"Then
            harga.Text = "105000"
ElseIf kode.Text = "TS002"Then
            harga.Text = "75000"
ElseIf kode.Text = "VG001"Then
            harga.Text = "90000"
ElseIf kode.Text = "VG002"Then
            harga.Text = "60000"
EndIf
EndSub

PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
        kode.Items.Add("TS001")
        kode.Items.Add("TS002")
        kode.Items.Add("VG001")
        kode.Items.Add("VG002")

        buat_table()
        kosong()

EndSub
Sub buat_table()
With LV
            .Items.Clear()
            .FullRowSelect = True
            .GridLines = True
            .View = View.Details

            .Columns.Add("No Pembelian", 100)
            .Columns.Add("Kode Barang", 100)
            .Columns.Add("Nama Barang", 100, HorizontalAlignment.Center)
            .Columns.Add("Merk", 100, HorizontalAlignment.Left)
            .Columns.Add(" Harga ", 100, HorizontalAlignment.Left)
            .Columns.Add("Jumlah Beli", 100, HorizontalAlignment.Left)
            .Columns.Add("Total Harga", 100, HorizontalAlignment.Left)

EndWith
EndSub
Sub simpan()
        LST = Me.LV.Items.Add(Me.nomor.Text)
        LST.SubItems.Add(Me.kode.Text)
        LST.SubItems.Add(Me.nama.Text)
        LST.SubItems.Add(Me.merk.Text)
        LST.SubItems.Add(Me.harga.Text)
        LST.SubItems.Add(Me.jumlah.Text)
        LST.SubItems.Add(Me.total.Text)

EndSub


Sub kosong()
        nama.Text = ""
        nomor.Text = ""
        kode.Text = ""
        merk.Text = ""
        harga.Text = ""
        jumlah.Text = ""
        total.Text = ""
        nomor.Focus()
EndSub



PrivateSub btnhapuspilih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapuspilih.Click
If LV.SelectedItems.Count <> 0 Then

            LV.Items.Remove(LV.SelectedItems(0))
Else
            MsgBox("Maaf Anda Belum"&"Memilih Data Yang Akan di Hapus")
EndIf
EndSub

PrivateSub btnsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
Call simpan()
EndSub

PrivateSub btnbersih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbersih.Click
        kosong()
        nomor.Focus()

EndSub

PrivateSub btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
Dim tanya AsString
        tanya = MsgBox("Apakah Anda Yakin Ingin Keluar?"& vbCrLf &"Harus Yakin", MsgBoxStyle.Question + MsgBoxStyle.YesNo)
If tanya = vbYes Then
Me.Close()
Else
ExitSub
EndIf
EndSub

PrivateSub btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
        LV.Items.Clear()
EndSub

PrivateSub jumlah_KeyPress(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles jumlah.KeyPress
        total.Text = Val(jumlah.Text) * Val(harga.Text)
EndSub

EndClass


Hasil nya akan seperti ini :

Tidak ada komentar:

Posting Komentar