Coding VB 2008
Aplikasi Penggajian
Form Login
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
'Button Ok
If UCase(UsernameTextBox.Text) = "MU" And UCase(PasswordTextBox.Text) = "88" Then
FormProgressBarLogin.Show()
FormProgressBarLogin.Timer1.Enabled = True
FormProgressBarLogin.Show()
Me.Hide()
Exit Sub
Else
counter = counter + 1
If counter = 3 Then
MessageBox.Show("anda sudah 3 kali salah")
End
End If
MessageBox.Show("login salah" + Chr(13) + "anda mempunyai " & 3 -
counter & " kali untuk mencoba" + Chr(13) + "login ulang",
"Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Me.Close()
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
'Button cancel
Me.Close()
End Sub
End Class
Form Progressbar
Public Class FormProgressBarLogin
Private
Sub btndetikProgress_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btndetikProgress.Click
Timer1.Enabled = True 'aktifkan timer
btndetikProgress.Text = "sedang proses"
Timer1.Interval = 100 'set interval menjadi 100
ProgressBar1.Value = 0 'kembalikan nilai progressbar menjadi 0
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Static tiktok As Integer
tiktok = tiktok + 1
ProgressBar1.Value = tiktok
btndetikProgress.Text = tiktok & " % "
If ProgressBar1.Value = ProgressBar1.Maximum Then
Timer1.Enabled = False 'non aktifkan timer1 saat nilai statis=nilai max progressbar1
tiktok = 0 'kembalikan nilai status menjadi 0
Me.Hide()
FormMenuUtama.Show()
End If
End Sub
End Class
__________________________________________________
Form Menu Awal
Public Class FormMenuUtama
Private
Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles ExitToolStripMenuItem.Click
If MsgBox("do you want to Exit?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "exit") = MsgBoxResult.Yes Then
MsgBox("thank you!!", MsgBoxStyle.Information, "end")
End
ElseIf MsgBoxResult.No Then
MsgBox("try again", MsgBoxStyle.Critical, "retry")
End If
End Sub
Private
Sub HitungGajiToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles HitungGajiToolStripMenuItem.Click
FormPenggajian.Show()
End Sub
Private
Sub LihatSlipGajiToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles
LihatSlipGajiToolStripMenuItem.Click
FormLihatData.Show()
End Sub
End Class
_________________________________________________________________________________
From Penggajian
Public Class FormPenggajian
Dim jenis As String
Private Sub rdLaki_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdLaki.CheckedChanged
jenis = "Laki-Laki"
End Sub
Private
Sub rdPerempuan_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles rdPerempuan.CheckedChanged
jenis = "Perempuan"
End Sub
Private Sub FormDataKaryawan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cmbJabatan.Items.Clear()
cmbJabatan.Items.Add("Manager")
cmbJabatan.Items.Add("Supervisor")
cmbJabatan.Items.Add("Staff Karyawan")
End Sub
Public Sub nol()
txtNik.Text = ""
txtNama.Text = ""
RDlaki.Checked = False
RDPerempuan.Checked = False
txtalamat.Text = ""
txttelepon.Text = ""
DTtanggal.Text = Today
txtjamkerja.Text = ""
txtJamLembur.Text = ""
txtgajiPokok.Text = ""
txtUmkn.Text = ""
txtUlembur.Text = ""
txtUtransport.Text = ""
lblTotalGaji.Text = "--"
lblHslGajiPokok.Text = "--"
Label5.Text = "--"
txtgajiPokok.Focus()
End Sub
Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpan.Click
GajiKaryawan.BukaDatabase()
'insert into tblKaryawan values
('NIP','Nama','JenisKelamin','alamat','telepon','tempatlahir','statuskaryawan','jabatan','tanggalmasuk')
GajiKaryawan.perintahSQL.CommandText = "insert into tblGajikaryawan
values ('" & txtNik.Text & "','" & txtNama.Text & "','"
& jenis & "','" & txtAlamat.Text & "','" &
txtTelepon.Text & "','" & cmbJabatan.Text & "','" &
Format(DTtanggal.Value, "MM/dd/yyyy") & "','" &
lblTotalGaji.Text & "')"
GajiKaryawan.perintahSQL.ExecuteNonQuery()
GajiKaryawan.tutupdatabase()
MsgBox("Data Telah Disimpan!!!", MsgBoxStyle.Information, "INFO")
nol()
End Sub
Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
Dim f = MsgBox("Apakah anda yakin ingin keluar?", vbYesNo, "KONFIRMASI")
If f = vbYes Then
MsgBox("Terimakasih telah menggunakan program ini.", MsgBoxStyle.DefaultButton1, "KONFIRMASI")
Me.Close()
ElseIf f = vbNo Then
Exit Sub
End If
End Sub
Private Sub btnHitung_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHitung.Click
txtUtransport.Text = txtgajiPokok.Text * 0.075
lblTotalGaji.Text = (Val(txtgajiPokok.Text) + Val(txtUmkn.Text) + Val(txtUlembur.Text) + Val(txtUtransport.Text))
End Sub
Private
Sub txtjamkerja_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txtjamkerja.TextChanged
If txtjamkerja.Text <> "" Then
Select Case txtjamkerja.Text
Case Is >= 192
txtJamLembur.Text = txtjamkerja.Text - 192
txtUlembur.Text = txtJamLembur.Text * 10000
Case Else
txtJamLembur.Text = txtjamkerja.Text * 0
txtUlembur.Text = txtJamLembur.Text * 0
End Select
End If
End Sub
Private Sub rdGol1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdGol1.CheckedChanged
lblHslGajiPokok.Text = 950000
txtgajiPokok.Text = 950000
txtUtransport.Text = 120000
End Sub
Private Sub rdGol2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdGol2.CheckedChanged
lblHslGajiPokok.Text = 1300000
txtgajiPokok.Text = 1300000
txtUtransport.Text = 160000
End Sub
Private Sub rdGol3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdGol3.CheckedChanged
lblHslGajiPokok.Text = 1600000
txtgajiPokok.Text = 1600000
txtUtransport.Text = 200000
End Sub
Private
Sub rdManager_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles rdManager.CheckedChanged
lblHslGajiPokok.Text = 0.1 * Val(txtgajiPokok.Text)
txtUmkn.Text = 0.3 * Val(txtgajiPokok.Text)
End Sub
Private
Sub rdSpvisor_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles rdSpvisor.CheckedChanged
lblHslGajiPokok.Text = 0.05 * Val(txtgajiPokok.Text)
txtUmkn.Text = 0.2 * Val(txtgajiPokok.Text)
End Sub
Private
Sub rdStaff_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles rdStaff.CheckedChanged
lblHslGajiPokok.Text = 0.025 * Val(txtgajiPokok.Text)
txtUmkn.Text = 0.1 * Val(txtgajiPokok.Text)
End Sub
Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
txtNik.Text = ""
txtNama.Text = ""
rdLaki.Checked = False
rdPerempuan.Checked = False
txtAlamat.Text = ""
txtTelepon.Text = ""
DTtanggal.Text = Today
txtjamkerja.Text = ""
txtJamLembur.Text = ""
txtgajiPokok.Text = ""
txtUmkn.Text = ""
txtUlembur.Text = ""
txtUtransport.Text = ""
lblTotalGaji.Text = "--"
lblHslGajiPokok.Text = "--"
Label5.Text = "--"
txtgajiPokok.Focus()
End Sub
End Class
Form Lihat Data
Public Class FormLihatData
Public Sub tampildata()
GajiKaryawan.ds.Clear()
GajiKaryawan.BukaDatabase()
GajiKaryawan.perintahSQL.CommandText = "select * from TblGajiKaryawan"
GajiKaryawan.da.SelectCommand = GajiKaryawan.perintahSQL
GajiKaryawan.da.Fill(GajiKaryawan.ds, "TblGajiKaryawan")
DGVdatagaji.DataSource = GajiKaryawan.ds
DGVdatagaji.DataMember = "TblGajiKaryawan"
DGVdatagaji.ReadOnly = True
GajiKaryawan.tutupdatabase()
End Sub
Private Sub btncari_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncari.Click
If cmbparameter.SelectedIndex = -1 Or txtnilaiparameter.Text = "" Then
MsgBox("harus dipilih", MsgBoxStyle.Information, "INFO")
Else
GajiKaryawan.ds.Clear()
GajiKaryawan.BukaDatabase()
GajiKaryawan.perintahSQL.CommandType = CommandType.Text
'combo box yang ke -0:NIP
If cmbparameter.SelectedIndex = 0 Then
GajiKaryawan.perintahSQL.CommandText = "select * from TblGajiKaryawan
where NIK like'%" & txtnilaiparameter.Text & "%'"
'combo box yang ke -1:nama
ElseIf cmbparameter.SelectedIndex = 1 Then
GajiKaryawan.perintahSQL.CommandText = "select * from TblGajiKaryawan
where nama like'%" & txtnilaiparameter.Text & "%'"
'combo box yang ke - 2:alamat
ElseIf cmbparameter.SelectedIndex = 2 Then
GajiKaryawan.perintahSQL.CommandText = "select * from TblGajiKaryawan
where alamat like'%" & txtnilaiparameter.Text & "%'"
'combo box yang ke -3:telepon
ElseIf cmbparameter.SelectedIndex = 3 Then
GajiKaryawan.perintahSQL.CommandText = "select * from TblGajiKaryawan
where telepon like'%" & txtnilaiparameter.Text & "%'"
'combo box yang ke -4:jabatan
ElseIf cmbparameter.SelectedIndex = 4 Then
GajiKaryawan.perintahSQL.CommandText = "select * from TblGajiKaryawan
where jabatan like'%" & txtnilaiparameter.Text & "%'"
ElseIf cmbparameter.SelectedIndex = 5 Then
GajiKaryawan.perintahSQL.CommandText = "select * from TblGajiKaryawan
where TotalGaji like'%" & txtnilaiparameter.Text & "%'"
End If
GajiKaryawan.da.SelectCommand = GajiKaryawan.perintahSQL
GajiKaryawan.da.Fill(GajiKaryawan.ds, "TblGajiKaryawan")
DGVdatagaji.DataSource = GajiKaryawan.ds
DGVdatagaji.DataMember = "TblGajiKaryawan"
DGVdatagaji.ReadOnly = True
GajiKaryawan.tutupdatabase()
End If
End Sub
Private Sub FormLihatData_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
tampildata()
End Sub
End Class
Class Gaji Karyawan.vb
Public Class GajiKaryawan
'membuat file koneksi
Public Shared koneksi As New SqlClient.SqlConnection
Public Shared perintahSQL As New SqlClient.SqlCommand
'data adapter : untunk mengambil data dari database dan menampungnya pada dataset
Public Shared da As New SqlClient.SqlDataAdapter
'data set : untuk menampilkan tabel yang pada database
Public Shared ds As New DataSet
'data reader : untuk membaca dan menampilkan data lebih cepat dan efisien
Public Shared ketemu As SqlClient.SqlDataReader
Public Shared Sub BukaDatabase()
Try
koneksi.ConnectionString = "Data Source=DOSEN\SQLEXPRESS;Initial Catalog=dbGaji;Integrated Security=True"
koneksi.Open()
perintahSQL.Connection = koneksi
Catch ex As Exception
MsgBox("koneksi database gagal!!!", MsgBoxStyle.Information, "error")
End Try
End Sub
Public Shared Sub tutupdatabase()
koneksi.Close()
koneksi.ConnectionString = Nothing
End Sub
End Class