HENDIKA

Saturday, 7 December 2013


Design form 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 Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.StartPosition = FormStartPosition.CenterScreen
        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_pembelian.Focus()
        kode_barang.Items.Add("TS001")
        kode_barang.Items.Add("TS002")
        kode_barang.Items.Add("VG001")
        kode_barang.Items.Add("VG002")
        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_pembelian.Enabled = a6
        kode_barang.Enabled = a7
        nama_barang.Enabled = a8
        merk.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_pembelian.KeyDown
        If e.KeyCode = Keys.Return Then
            If no_pembelian.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)
        Select Case x
            Case "TS"
                merk.Text = "Toshiba"
            Case Else
                merk.Text = "V-GEN"
        End Select
        Select Case y
            Case "001"
                nama_barang.Text = "Flashdisk 4GB"
            Case Else
                nama_barang.Text = "Flashdisk 2GB"
        End Select
        If x = "TS" And y = "001" Then
            harga.Text = 105000
        ElseIf x = "TS" And y = "002" Then
            harga.Text = 75000
        ElseIf x = "VG" And y = "001" Then
            harga.Text = 90000
        Else
            harga.Text = 60000
        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
            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("Merk", 60, HorizontalAlignment.Left)
            .Columns.Add("Harga", 60, HorizontalAlignment.Right)
            .Columns.Add("Jumlah Beli", 66, HorizontalAlignment.Right)
            .Columns.Add("Total Harga", 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_pembelian.Text
            .SubItems.Add(kode_barang.Text)
            .SubItems.Add(nama_barang.Text)
            .SubItems.Add(merk.Text)
            .SubItems.Add(harga.Text)
            .SubItems.Add(jumlah_beli.Text)
            .SubItems.Add(total_harga.Text)
            lv.Items.Add(isi)
        End With
    End Sub
    Sub bersih()
        no_pembelian.Text = ""
        kode_barang.Text = ""
        nama_barang.Text = ""
        merk.Text = ""
        harga.Text = ""
        jumlah_beli.Text = ""
        total_harga.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_pembelian.Focus()
    End Sub

    Private Sub btn_hapus_semua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_hapussemua.Click
        lv.Items.Clear()
        btn_hapussemua.Enabled = False
        no_pembelian.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_pembelian.Focus()
    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 btn_hapusdatayangdipilih_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_pembelian.Focus()
    End Sub

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


disini saya nama dorm nya form1

dan selamat mencoba :)






















0 komentar:

Post a Comment