Membuat data karyawan dengan nggunakan database Microsoft access

Diposting oleh Selamat datang di blog on Selasa, 04 Februari 2014

1. Buat table pada accessnya seperti gambar dibawah ini
Gambar 1.1

Gambar 1.2

Gambar 1.3
2. Buka program visual studio 2008

3. Design from seperti gambar dibawah ini
    Dan simpan dengan “Sistem Informasi Penggajian Karyawann cv.Smart Solution”
    Dengan menggunakan menu strip seperti gambar dibawah ini

Gambar 1.4


Cara membuat menu strip seperti gambar diatas adalah

  • Pada control command pilih menus and toolbars
  • Pilih menu strip
  • Maka akan muncul gambar seperti dibawah ini
  • Pada tupy here ketik “file” dan design seperti gambar 1.4

1. tambah form baru dan beri nama masing - masing form tersebut dengan nama pegawai,bagian,jabatan

Gambar.1.5

Gambar 1.5


Gambar 1.6
2. klik menu project pada menubar  lalu pilih add moduls
3. pada form moduls ketik perintah seperti dibawah ini

 Imports System.Data.OleDb

Module Module1
    Public DB As OleDbConnection
    Public cmd As OleDbCommand
    Public ADP As OleDbDataAdapter
    Public DR As OleDbDataReader
    Public DS As New DataSet
    Public SQL As String

    Public Sub OPENDB()
        Dim LOKASI = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=E:\VBDatabase\tria.mdb"
        DB = New OleDbConnection(LOKASI)
        If DB.State = ConnectionState.Closed Then
            DB.Open()
        End If
    End Sub

    Sub TAMPILGRID(ByVal obj As Object, ByVal ctable As String)
        SQL = "SELECT * FROM " & ctable
        ADP = New OleDbDataAdapter(SQL, DB)
        DS = New DataSet
        ADP.Fill(DS, ctable)
        obj.DataSource = DS.Tables(ctable)
    End Sub

    Sub IsikanCombo(ByVal cbo As Object, ByVal ctable As String, ByVal cfield As String)
        cbo.Items.Clear()
        SQL = "select " & cfield & " from " & ctable
        cmd = New OleDbCommand(SQL, DB)
        DR = cmd.ExecuteReader
        While DR.Read
            cbo.Items.Add(DR(cfield))
        End While
        DR.Close()
    End Sub

End Module

pada form 1 ketik perintah seperti dibawah ini

Public Class Form1

    Private Sub DataBagianToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataBagianToolStripMenuItem.Click
        data_bagian.MdiParent = Me
        data_bagian.Show()
    End Sub

    Private Sub DataPegawaiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataPegawaiToolStripMenuItem.Click
        data_pegawai.MdiParent = Me
        data_pegawai.Show()
    End Sub

    Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
        jabatan.MdiParent = Me
        jabatan.Show()
    End Sub
End Class

pada form pegawai ketik perintah dibawah ini


Imports System.Data.OleDb
Public Class data_pegawai

    Sub RubahButton(ByVal L0 As Boolean, ByVal L1 As Boolean, ByVal L2 As Boolean, ByVal L3 As Boolean, ByVal L4 As Boolean, ByVal L5 As Boolean)
        btnbaru.Enabled = L0
        btnsimpan.Enabled = L1
        btnedit.Enabled = L2
        btnhapus.Enabled = L3
        btnbatal.Enabled = L4
        btnkeluar.Enabled = L5
    End Sub

    Sub hapus()
        nik.Text = ""
        nama.Text = ""
        bagian.Text = ""
        jabatan.Text = ""
        gajipokok.Text = ""
        tlahir.Text = ""
        tgllahir.Text = ""
        tglmasuk.Text = ""
        Call RubahButton(True, False, False, False, False, True)
    End Sub

    Sub prosesDB(ByVal aksi As Byte)
        Select Case aksi
            Case 0
                SQL = "insert into karyawan(nik,nama,jabatan,gajipokok,tlahir,tgllahir,tglmasuk)" & _
                                        "values('" & nik.Text & "','" & _
                                                    nama.Text & "','" & _
                                                    bagian.Text & "','" & _
                                                    jabatan.Text & "','" & _
                                                    gajipokok.Text & "','" & _
                                                    tlahir.Text & "','" & _
                                                    tgllahir.Text & "','" & _
                                                    tglmasuk.Text & "')"
            Case 1
                SQL = "update karyawan set nama='" & nama.Text & "', " & _
                            "bagian = '" & bagian.Text & "', " & _
                            "jabatan = '" & jabatan.Text & "', " & _
                            "gajipokok = '" & gajipokok.Text & "', " & _
                            "tlahir = '" & tlahir.Text & "', " & _
                            "tgllahir = '" & tgllahir.Text & "', " & _
                            "tglmasuk= '" & tglmasuk.Text & "' " & _
                            " where kode = '" * nik.Text & "','"
            Case 2
                SQL = "delete from karyawan where nik='" & nik.Text & "'"
        End Select
        cmd = New OleDbCommand(SQL, DB)
        cmd.ExecuteNonQuery()
        Call hapus()
        Call TAMPILGRID(GRID, "karyawan")
        Call IsikanCombo(nik, "karyawan", "nik")
        GRID.Focus()
    End Sub

    Private Sub data_pegawai_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call OPENDB()
        Call hapus()
        Call TAMPILGRID(GRID, "karyawan")
        Call IsikanCombo(nik, "karyawan", "nik")
        Cari.Items.Add("nik")
        Cari.Items.Add("nama")
        Cari.Items.Add("jabatan")
        Cari.Items.Add("gajipokok")
        Cari.Items.Add("tlahir")
        Cari.Items.Add("tgllahir")
        Cari.Items.Add("tglmasuk")

    End Sub

    Private Sub btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
        Call prosesDB(2)
    End Sub

    Private Sub btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
        Me.Close()
    End Sub

    Private Sub btnbaru_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbaru.Click
        Call hapus()
        GRID.Focus()
    End Sub

    Private Sub nik_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles nik.KeyPress
        Dim tombol As Integer = Asc(e.KeyChar)
        Dim xkaryawan As String
        If tombol = 13 Then
            SQL = "select * from karyawan where nik='" & nik.Text & "'"
            cmd = New OleDbCommand(SQL, DB)
            DR = cmd.ExecuteReader
            DR.Read()
            If DR.HasRows = True Then
                nama.Text = DR("nama")
                bagian.Text = DR("bagian")
                jabatan.Text = DR("jabatan")
                gajipokok.Text = DR("gajipokok")
                tlahir.Text = DR("tempatlahir")
                tgllahir.Text = DR("tgllahir")
                tglmasuk.Text = DR("tglmasuk")
                Call RubahButton(False, False, True, True, True, False)
            Else
                xkaryawan = nik.Text
                Call hapus()
                nik.Text = xkaryawan
                Call RubahButton(False, True, False, False, True, False)
            End If
            DR.Close()
            nama.Focus()
        End If
    End Sub

    Private Sub nik_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nik.SelectedIndexChanged

    End Sub

    Private Sub btnbatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbatal.Click
        Call hapus()
        nik.Focus()
    End Sub

    Private Sub btnedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnedit.Click
        Call prosesDB(1)
    End Sub

    Private Sub btnsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
        Call prosesDB(0)
    End Sub
End Class
Pada form bagian ketik perintah dibawah ini
Imports System.Data.OleDb

Public Class data_bagian

    Sub RubahButton(ByVal L0 As Boolean, ByVal L1 As Boolean, ByVal L2 As Boolean, ByVal L3 As Boolean, ByVal L4 As Boolean, ByVal L5 As Boolean)
        btnbaru.Enabled = L0
        btnsimpan.Enabled = L1
        btnedit.Enabled = L2
        btnhapus.Enabled = L3
        btnbatal.Enabled = L4
        btnkeluar.Enabled = L5
    End Sub

    Sub hapus()
        kdbagian.Text = ""
        nmbagian.Text = ""
        pimpinan.Text = ""
        tlpn.Text = ""
        Call RubahButton(True, False, False, False, False, True)
    End Sub

    Sub prosesDB(ByVal aksi As Byte)
        Select Case aksi
            Case 0
                SQL = "insert into bagian(kdbagian,nmbagian,pimpinan,telp)" & _
                                        "values('" & kdbagian.Text & "','" & _
                                                    nmbagian.Text & "','" & _
                                                    pimpinan.Text & "','" & _
                                                    tlpn.Text & "')"
            Case 1
                SQL = "update bagaian set nmbagian='" & nmbagian.Text & "', " & _
                            "pimpinan = '" & pimpinan.Text & "', " & _
                            "telp= '" & tlpn.Text & "' " & _
                            " where kdbagian = '" * kdbagian.Text & "','"
            Case 2
                SQL = "delete from bagian where kdbagian='" & kdbagian.Text & "'"
        End Select
        cmd = New OleDbCommand(SQL, DB)
        cmd.ExecuteNonQuery()
        Call hapus()
        Call TAMPILGRID(GRID, "Bagian")
        Call IsikanCombo(kdbagian, "Bagian", "kdbagian")
        GRID.Focus()
    End Sub
    Private Sub btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
        Call prosesDB(2)
    End Sub

    Private Sub btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
        Me.Close()
    End Sub

    Private Sub data_bagian_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call OPENDB()
        Call hapus()
        Call TAMPILGRID(GRID, "Bagian")
        Call IsikanCombo(kdbagian, "Bagian", "kdbagian")
        Cari.Items.Add("kdBagian")
        Cari.Items.Add("nmBagian")
        Cari.Items.Add("pimpinan")
        Cari.Items.Add("telp")
    End Sub

    Private Sub btnbaru_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbaru.Click
        Call hapus()
        GRID.Focus()
    End Sub

    Private Sub kdbagian_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles kdbagian.KeyPress
        Dim tombol As Integer = Asc(e.KeyChar)
        Dim xbagian As String
        If tombol = 13 Then
            Sql = "select * from bagian where KDbagian='" & kdbagian.Text & "'"
            cmd = New OleDbCommand(Sql, DB)
            DR = cmd.ExecuteReader
            DR.Read()
            If DR.HasRows = True Then
                pimpinan.Text = DR("pimpinan")
                nmbagian.Text = DR("nmbagian")
                tlpn.Text = DR("telp")
                Call RubahButton(False, False, True, True, True, False)
            Else
                xbagian = kdbagian.Text
                Call hapus()
                kdbagian.Text = xbagian
                Call RubahButton(False, True, False, False, True, False)
            End If
            DR.Close()
            nmbagian.Focus()
        End If
    End Sub

    Private Sub btnbatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbatal.Click
        Call hapus()
        kdbagian.Focus()
    End Sub

    Private Sub btnedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnedit.Click
        Call prosesDB(1)
    End Sub

    Private Sub btnsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
        Call prosesDB(0)
    End Sub

    Private Sub Search_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Search.TextChanged
        Sql = "SELECT * FROM bagian where " & Cari.Text & " like '%" & Search.Text & "%'"
        ADP = New OleDbDataAdapter(Sql, DB)
        DS = New DataSet
        ADP.Fill(DS, "bagian")
        GRID.DataSource = DS.Tables("bagian")
    End Sub

    Private Sub kdbagian_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kdbagian.SelectedIndexChanged

    End Sub
End Class

10. Pada form jabatan ketik perintah seperti dibawah ini

Imports System.Data.OleDb
Public Class jabatan
    Sub RubahButton(ByVal L0 As Boolean, ByVal L1 As Boolean, ByVal L2 As Boolean, ByVal L3 As Boolean, ByVal L4 As Boolean, ByVal L5 As Boolean)
        btnbaru.Enabled = L0
        btnsimpan.Enabled = L1
        btnedit.Enabled = L2
        btnhapus.Enabled = L3
        btnbatal.Enabled = L4
        btnkeluar.Enabled = L5
    End Sub

    Sub hapus()
        kdjabatan.Text = ""
        nmjabatan.Text = ""
        TUNJANGAN.Text = ""
        Call RubahButton(True, False, False, False, False, True)
    End Sub

    Sub prosesDB(ByVal aksi As Byte)
        Select Case aksi
            Case 0
                SQL = "insert into jabatan(kdjabatan,jabatan,tunjangan)" & _
                                        "values('" & kdjabatan.Text & "','" & _
                                                    nmjabatan.Text & "','" & _
                                                    TUNJANGAN.Text & "')"
            Case 1
                SQL = "update jabatan set jabatan='" & nmjabatan.Text & "', " & _
                            "tunjangan= '" & TUNJANGAN.Text & "' " & _
                            " where kdjabatan = '" * kdjabatan.Text & "','"
            Case 2
                SQL = "delete from jabatan where kdjabatan='" & kdjabatan.Text & "'"
        End Select
        cmd = New OleDbCommand(SQL, DB)
        cmd.ExecuteNonQuery()
        Call hapus()
        Call TAMPILGRID(GRID, "jabatan")
        Call IsikanCombo(kdjabatan, "jabatan", "kdjabatan")
        GRID.Focus()
    End Sub

    Private Sub jabatan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Cari.Items.Add("nik")
        Cari.Items.Add("nama")
        Cari.Items.Add("jabatan")
        Cari.Items.Add("gajipokok")
        Cari.Items.Add("tlahir")
        Cari.Items.Add("tgllahir")
        Cari.Items.Add("tglmasuk")
        Call OPENDB()
        Call TAMPILGRID(GRID, "jabatan")
        Call IsikanCombo(kdjabatan, "jabatan", "kdjabatan")
    End Sub

    Private Sub btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
        Call prosesDB(2)
    End Sub

    Private Sub btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
        Me.Close()
    End Sub

    Private Sub btnbaru_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbaru.Click
        Call hapus()
        GRID.Focus()
    End Sub

    Private Sub kdjabatan_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles kdjabatan.KeyPress
        Dim tombol As Integer = Asc(e.KeyChar)
        Dim xjabatan As String
        If tombol = 13 Then
            SQL = "select * from jabatan where kdjabatan='" & kdjabatan.Text & "'"
            cmd = New OleDbCommand(SQL, DB)
            DR = cmd.ExecuteReader
            DR.Read()
            If DR.HasRows = True Then
                nmjabatan.Text = DR("nmjabatan")
                TUNJANGAN.Text = DR("tunjangan")
                Call RubahButton(False, False, True, True, True, False)
            Else
                xjabatan = kdjabatan.Text
                Call hapus()
                kdjabatan.Text = xjabatan
                Call RubahButton(False, True, False, False, True, False)
            End If
            DR.Close()
            nmjabatan.Focus()
        End If
    End Sub

    Private Sub kdjabatan_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kdjabatan.SelectedIndexChanged

    End Sub

    Private Sub btnbatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbatal.Click
        Call hapus()
        kdjabatan.Focus()
    End Sub

    Private Sub btnedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnedit.Click
        Call prosesDB(1)
    End Sub

    Private Sub btnsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
        Call prosesDB(0)
    End Sub

    Private Sub nmjabatan_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nmjabatan.TextChanged

    End Sub
End Class

{ 0 komentar ... read them below or add one }

Posting Komentar