Dibawah ini adalah contoh pemrograman dasar Vb.net 2008 yang membahas tentang penggajian karyawan menggunakan ListView
Imports System.Drawing
Public Class MENU
Private Sub LOGINToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LOGINToolStripMenuItem.Click
login.ShowDialog()
End Sub
Private Sub LOGOUTToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LOGOUToolStripMenuItem.Click
login.Close()
End Sub
Private Sub EXITToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EXITToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub BtnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnBrowse.Click
Dim bukaGambar As New Windows.Forms.OpenFileDialog
bukaGambar.Filter = "File Gambar(*.bmp; *.jpg;*.GIF)|*.BMP;*.JPG;*.GIF|All files(*.*)|*.*"
If bukaGambar.ShowDialog = Windows.Forms.DialogResult.OK Then
Me.Poto.Image = Image.FromFile(bukaGambar.FileName)
Else
MsgBox("Pilih Gambar Dulu", MsgBoxStyle.Exclamation, "Error")
End If
TextBox1.Text = bukaGambar.FileName.ToString
End Sub
End Class
Public Class login
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim buka As New PENGGAJIAN_KARYAWAN
ProgressBar1.Value += 2.5
If ProgressBar1.Value = 100 Then
Timer1.Dispose()
MessageBox.Show("Selamat Datang:" & vbCrLf & txtUserName.Text & "!!!!!")
Me.Visible = False
buka.ShowDialog()
Me.Hide()
End If
End Sub
Sub login()
Dim User, pass As String
User = "hardi"
pass = "12345"
If txtUserName.Text = User And txtPassword.Text = pass Then
Timer1.Enabled = True
Else
txtUserName.Text = ""
txtPassword.Text = ""
MessageBox.Show("User salah dan password salah!!!!!")
txtUserName.Focus()
txtUserName.Clear()
txtPassword.Focus()
txtUserName.Clear()
PENGGAJIAN_KARYAWAN.Close()
Timer1.Enabled = False
End If
End Sub
Private Sub btnmasuk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmasuk.Click
Call login()
End Sub
Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click
Close()
End Sub
End Class
Public Class PENGGAJIAN_KARYAWAN
Sub buattabel()
LV.Columns.Add("JABATAN", 120, HorizontalAlignment.Center)
LV.Columns.Add("GAJI POKOK", 120, HorizontalAlignment.Left)
LV.Columns.Add("STATUS", 120, HorizontalAlignment.Left)
LV.Columns.Add("TUNJANGAN ISTRI", 120, HorizontalAlignment.Left)
LV.Columns.Add("JUMLAH ANAK", 120, HorizontalAlignment.Left)
LV.Columns.Add("TUNJANGAN ANAK", 120, HorizontalAlignment.Left)
LV.Columns.Add("PAJAK", 80, HorizontalAlignment.Left)
LV.Columns.Add("LEMBUR", 80, HorizontalAlignment.Left)
LV.Columns.Add("UPAH LEMBUR", 120, HorizontalAlignment.Left)
LV.Columns.Add("TOTAL", 80, HorizontalAlignment.Left)
LV.View = View.Details
LV.GridLines = True
LV.FullRowSelect = True
End Sub
Sub isitabel()
Dim lst As New ListViewItem
lst.Text = cmbJabatan.Text
lst.SubItems.Add(txtGajiPokok.Text)
lst.SubItems.Add(cmbstatus.Text)
lst.SubItems.Add(txtTunjanganIstri.Text)
lst.SubItems.Add(txtJumlahAnak.Text)
lst.SubItems.Add(txttunjangananak.Text)
lst.SubItems.Add(txtpajak.Text)
lst.SubItems.Add(txtlembur.Text)
lst.SubItems.Add(txtUpahLembur.Text)
lst.SubItems.Add(txttotal.Text)
LV.Items.Add(lst)
End Sub
Sub GAJI()
If cmbJabatan.Text = "MANDOR" Then
txtGajiPokok.Text = 1750000
txtpajak.Text = (txtGajiPokok.Text * 1.5) / 100
ElseIf cmbJabatan.Text = "KEPALA BAGIAN" Then
txtGajiPokok.Text = 2500000
txtpajak.Text = (txtGajiPokok.Text * 1.5) / 100
ElseIf cmbJabatan.Text = "STAF" Then
txtGajiPokok.Text = 1250000
txtpajak.Text = (txtGajiPokok.Text * 1.5) / 100
End If
End Sub
Sub TUNJANGAN_ISTRI()
If cmbstatus.Text = "MENIKAH" Then
txtTunjanganIstri.Text = (txtGajiPokok.Text * 9) / 100
ElseIf cmbstatus.Text = "BELUM MENIKAH" Then
txtTunjanganIstri.Text = "0"
txttunjangananak.Text = "0"
txtJumlahAnak.Text = "0"
End If
End Sub
Sub TUNJANGAN_ANAK()
If cmbstatus.Text = "MENIKAH" Then
If txtJumlahAnak.Text = "1" Then
txttunjangananak.Text = (txtGajiPokok.Text * 3) / 100
ElseIf txtJumlahAnak.Text >= "2" Then
txttunjangananak.Text = (txtGajiPokok.Text * 7) / 100
End If
ElseIf cmbstatus.Text = "BELUM MENIKAH" Then
txtJumlahAnak.Text = "0"
txttunjangananak.Text = "0"
txtTunjanganIstri.Text = "0"
End If
End Sub
Sub proses()
If cmbJabatan.Text = "MANDOR" Then
txtUpahLembur.Text = (txtlembur.Text * 7500)
ElseIf cmbJabatan.Text = "KEPALA BAGIAN" Then
txtUpahLembur.Text = (txtlembur.Text * 10000)
ElseIf cmbJabatan.Text = "STAF" Then
txtUpahLembur.Text = (txtlembur.Text * 5000)
End If
End Sub
Sub bersih()
cmbJabatan.Text = ""
txtGajiPokok.Text = ""
cmbstatus.Text = ""
txtTunjanganIstri.Text = ""
txtJumlahAnak.Text = ""
txttunjangananak.Text = ""
txtpajak.Text = ""
txtlembur.Text = ""
txtUpahLembur.Text = ""
txttotal.Text = ""
End Sub
Private Sub PENGGAJIAN_KARYAWAN_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
buattabel()
cmbJabatan.Items.Add("MANDOR")
cmbJabatan.Items.Add("KEPALA BAGIAN")
cmbJabatan.Items.Add("STAF")
cmbstatus.Items.Add("MENIKAH")
cmbstatus.Items.Add("BELUM MENIKAH")
End Sub
Private Sub cmbJabatan_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbJabatan.SelectedIndexChanged
Call GAJI()
End Sub
Private Sub cmbstatus_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbstatus.SelectedIndexChanged
Call TUNJANGAN_ISTRI()
End Sub
Private Sub txtJumlahAnak_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtJumlahAnak.TextChanged
Call TUNJANGAN_ANAK()
End Sub
Private Sub txtlembur_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtlembur.KeyPress
Dim tombol As Integer = Asc(e.KeyChar)
If tombol = 13 Then
Call proses()
End If
End Sub
Private Sub btnsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
Call isitabel()
Call bersih()
End Sub
Private Sub btnproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnproses.Click
txttotal.Text = (Val(txtGajiPokok.Text) + Val(txtTunjanganIstri.Text) + Val(txttunjangananak.Text) + Val(txtlembur.Text)) - txtpajak.Text
Call proses()
End Sub
Private Sub btnbatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbatal.Click
Call bersih()
End Sub
Private Sub btnHapusDipilih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHapusDipilih.Click
LV.Items.Remove(LV.SelectedItems(0))
End Sub
Private Sub btnHapusSemua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHapusSemua.Click
LV.Items.Clear()
End Sub
Private Sub btnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKeluar.Click
Me.Close()
End Sub
End Class
hasil :
JAWABAN QUIZ HARI SENIN NO 3
klik disini untuk kasus[..]
klik untuk melihat kasus :
BalasHapushttp://mesran.wordpress.com/2012/01/21/latihan-vb-net-menggunakan-listview/