Saturday, August 25, 2012

VB 2008 : Coding Form Aplikasi Penggajian


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 GajiKaryawan.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

bagian yang di warnai dengan warna kuning, ganti dengan database Sql masing"...
bagi sobat yang belum mengerti cara mengganti database-nya...comment di posting ini..

bagi sobat seewebsters yang gak mau repot buat Form nya, sobat seewebsters bisa download DISINI

bagi sobat seewebsters yang Copas posting ini jangan lupa menyertakan sumbernya seewebsters.blogspot.com
bagi sobat seewebsters yang telah membaca postingan ini hendaknya meninggalkan commend pada blog ini.


Saya Yakin, Anda Adalah Golongan Pembaca Yang Baik.
Yang Selalu Meninggalkan Komentar Di Artikel Ini.



10 comments:

  1. thz aplikasi ny..posting ny bermanfaat utk saya.

    ReplyDelete
  2. thx posting ny gan..

    ReplyDelete
  3. thanks bro aplikasinya..

    ReplyDelete
  4. Gan,,,Cara ganti databasenya gimana ya ? tolong bantuannya, makasihhh... :))

    ReplyDelete
    Replies
    1. database ny udah d bwat blom...
      klu udah klik data, add new data source...udah tu next aj...entar ad kolom pilihan database yang akan digunakan agan, lalu klik new connections dst.

      nah dibawah nya ada tulisan conection string...klik tanda [+] lalu copy semua.

      Delete
  5. jarang2 ada programmer baik hati gini. makasih ya gan info dan ilmunya

    ReplyDelete