HENDIKA

Saturday, 7 December 2013

kasus : program untuk mencari total pembayaran tv

Berikut design vb 2008 seperti di bawah ini :






















Tulisan yang berwarna merah merupakan name dari masing-masing komponen dan sediakan juga satu timer.
lalu kopi paste koding dibawah ini :

Public Class Form2
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.StartPosition = FormStartPosition.CenterScreen
        Diskon.Enabled = False
        total_bayar.Enabled = False
        total_harga.Enabled = False
        Btn_keluar.Image = ImageList1.Images(0)
        StatusStrip1.Items(2).Text = Format(Now, "dddd") & ", " & Format(Now, "dd MMM yyyy")
        rubahtombol(0, 0, 0, 0, 1, 1, 0, 0, 0)
        no_penjualan.Focus()
        kode_barang.Items.Add("TS001")
        kode_barang.Items.Add("TS002")
        kode_barang.Items.Add("SN001")
        kode_barang.Items.Add("SN002")
        buattable()
    End Sub
    Sub rubahtombol(ByVal a1 As Boolean, ByVal a2 As Boolean, ByVal a3 As Boolean, ByVal a4 As Boolean, ByVal a5 As Boolean, ByVal a6 As Boolean, ByVal a7 As Boolean, ByVal a8 As Boolean, ByVal a9 As Boolean)
        Btn_simpan.Enabled = a1
        btn_bersih.Enabled = a2
        btn_hapussemua.Enabled = a3
        btn_hapusyangdipilih.Enabled = a4
        Btn_keluar.Enabled = a5
        no_penjualan.Enabled = a6
        kode_barang.Enabled = a7
        nama_barang.Enabled = a8
        harga.Enabled = a8
        jumlah_beli.Enabled = a9
    End Sub

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

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        StatusStrip1.Items(4).Text = "   Jam   " & Date.Now.ToString("hh:mm:ss")
    End Sub

    Private Sub no_pembelian_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles no_penjualan.KeyDown
        If e.KeyCode = Keys.Return Then
            If no_penjualan.Text = "" Then
                MsgBox("No Pembelian Harus diisi", , "Informasi")
            Else
                rubahtombol(0, 1, 0, 0, 1, 0, 1, 0, 0)
                kode_barang.Focus()
            End If
        End If
        If lv.Items.Count = 0 Then
            btn_hapussemua.Enabled = False
        Else
            btn_hapussemua.Enabled = True
        End If
    End Sub

    Private Sub kode_barang_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kode_barang.SelectedIndexChanged
        Dim x As String = Microsoft.VisualBasic.Left(kode_barang.Text, 2)
        Dim y As String = Microsoft.VisualBasic.Right(kode_barang.Text, 3)
        If x = "TS" And y = "001" Then
            nama_barang.Text = "Toshiba 21 Inc"
            harga.Text = 1950000
        ElseIf x = "TS" And y = "002" Then
            nama_barang.Text = "Toshiba 41 Inc"
            harga.Text = 4750000
        ElseIf x = "SN" And y = "001" Then
            nama_barang.Text = "Sony 21 Inc"
            harga.Text = 1900000
        Else
            nama_barang.Text = "Toshiba 41 Inc"
            harga.Text = 4600000
        End If
        rubahtombol(0, 1, 0, 0, 1, 0, 1, 0, 1)
        jumlah_beli.Focus()
        If lv.Items.Count = 0 Then
            btn_hapussemua.Enabled = False
        Else
            btn_hapussemua.Enabled = True
        End If
    End Sub

    Private Sub jumlah_beli_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles jumlah_beli.KeyPress
        If Asc(e.KeyChar) = 13 Then
            total_harga.Text = harga.Text * jumlah_beli.Text
            If total_harga.Text > 2500000 Then
                Diskon.Text = 0.1 * total_harga.Text
            Else
                Diskon.Text = ""
            End If
            total_bayar.Text = total_harga.Text - Val(Diskon.Text)
            rubahtombol(1, 1, 0, 0, 1, 0, 1, 0, 1)
            Btn_simpan.Focus()
        End If
        If lv.Items.Count = 0 Then
            btn_hapussemua.Enabled = False
        Else
            btn_hapussemua.Enabled = True
        End If
    End Sub
    Sub buattable()
        With lv
            .Columns.Add("No Pembelian", 90, HorizontalAlignment.Center)
            .Columns.Add("Kode Barang", 90, HorizontalAlignment.Left)
            .Columns.Add("Nama Barang", 90, HorizontalAlignment.Left)
            .Columns.Add("Harga", 60, HorizontalAlignment.Right)
            .Columns.Add("Jumlah Beli", 66, HorizontalAlignment.Right)
            .Columns.Add("Total Harga", 90, HorizontalAlignment.Right)
            .Columns.Add("Diskon", 90, HorizontalAlignment.Right)
            .Columns.Add("Total Bayar", 90, HorizontalAlignment.Right)
            .GridLines = True
            .FullRowSelect = True
            .View = View.Details
        End With
    End Sub
    Sub isitabel()
        Dim isi As New ListViewItem
        Dim angka As Integer
        With isi
            .Text = no_penjualan.Text
            .SubItems.Add(kode_barang.Text)
            .SubItems.Add(nama_barang.Text)
            .SubItems.Add(harga.Text)
            .SubItems.Add(jumlah_beli.Text)
            .SubItems.Add(total_harga.Text)
            .SubItems.Add(Diskon.Text)
            .SubItems.Add(total_bayar.Text)
            lv.Items.Add(isi)
        End With
    End Sub
    Sub bersih()
        no_penjualan.Text = ""
        kode_barang.Text = ""
        nama_barang.Text = ""
        harga.Text = ""
        jumlah_beli.Text = ""
        total_harga.Text = ""
        Diskon.Text = ""
        total_bayar.Text = ""
    End Sub

    Private Sub Btn_simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_simpan.Click
        btn_hapussemua.Enabled = True
        isitabel()
        rubahtombol(0, 0, 1, 0, 1, 1, 0, 0, 0)
        bersih()
        no_penjualan.Focus()
    End Sub

    Private Sub btn_hapussemua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_hapussemua.Click
        lv.Items.Clear()
        btn_hapussemua.Enabled = False
        no_penjualan.Focus()
    End Sub

    Private Sub btn_bersih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_bersih.Click
        rubahtombol(0, 0, 0, 0, 1, 1, 0, 0, 0)
        bersih()
        If lv.Items.Count = 0 Then
            btn_hapussemua.Enabled = False
        Else
            btn_hapussemua.Enabled = True
        End If
        no_penjualan.Focus()
    End Sub

    Private Sub btn_hapusyangdipilih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_hapusyangdipilih.Click
        If lv.SelectedItems.Count <> 0 Then
            For Each i As ListViewItem In lv.SelectedItems
                lv.Items.Remove(i)
            Next
        Else
            btn_hapusyangdipilih.Enabled = False
        End If
        btn_hapusyangdipilih.Enabled = False
        If lv.Items.Count = 0 Then
            btn_hapussemua.Enabled = False
        Else
            btn_hapussemua.Enabled = True
        End If
        no_penjualan.Focus()
    End Sub

    Private Sub no_pembelian_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles no_penjualan.TextChanged
        If no_penjualan.Text = "" Then
            btn_bersih.Enabled = False
        Else
            btn_bersih.Enabled = True
        End If
    End Sub

    Private Sub lv_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lv.Click
        If lv.SelectedItems.Count <> 0 Then
            btn_hapusyangdipilih.Enabled = True
        Else
            btn_hapusyangdipilih.Enabled = False
        End If
    End Sub

    Private Sub jumlah_beli_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles jumlah_beli.TextChanged

    End Sub
End Class


disini saya nama dorm nya form2

dan selamat mencoba :)

0 komentar:

Post a Comment