(Form Menu Dan Karyawan)
Design Form Menu
Listing Program
Public Class menu
Private Sub KaryawanToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
KaryawanToolStripMenuItem.Click
Form1.MdiParent = Me
Form1.Show()
End Sub
Private Sub JabatanToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
JabatanToolStripMenuItem.Click
Form2.MdiParent = Me
Form2.Show()
End Sub
Private Sub BagianToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
BagianToolStripMenuItem.Click
Form3.MdiParent = Me
Form3.Show()
End Sub
Private Sub KeluarProgramToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
KeluarProgramToolStripMenuItem.Click
End
End Sub
End Class
Disegn Form Saat Dijalankan
Design Form Karyawan
Listing Program
Imports
System.Data.OleDb
Public Class Form1
Public DB As OleDbConnection
Public CMD As OleDbCommand
Public ADP As OleDbDataAdapter
Public DR As OleDbDataReader
Public DS As New DataSet
Dim SQL As String
Public Sub Opendb()
Dim
LOKASI = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source =C:\vb2\penjualan.mdb"
DB = New
OleDbConnection(LOKASI)
If
DB.State = ConnectionState.Closed Then
DB.Open()
End If
End Sub
Sub
TampilRecordkaryawan()
ADP = New
OleDbDataAdapter("SELECT * FROM karyawan",
DB)
DS = New
DataSet
ADP.Fill(DS, "karyawan")
DataGridView1.DataSource = DS.Tables("karyawan")
End Sub
Sub
buttonbaru()
Btnbaru.Enabled = True
Btnsimpan.Enabled = False
Btnedit.Enabled = False
Btnhapus.Enabled = False
Btnbatal.Enabled = False
Btnkeluar.Enabled = True
End Sub
Sub
buttonedit()
Btnbaru.Enabled = False
Btnsimpan.Enabled = False
Btnedit.Enabled = True
Btnhapus.Enabled = True
Btnbatal.Enabled = True
Btnkeluar.Enabled = False
End Sub
Sub
buttonsimpan()
Btnbaru.Enabled = False
Btnsimpan.Enabled = True
Btnedit.Enabled = False
Btnhapus.Enabled = False
Btnbatal.Enabled = True
Btnkeluar.Enabled = False
End Sub
Sub
HapusText()
Nik.Text = ""
Nama.Text = ""
Jabatan.Text = ""
Jkelamin.Text = ""
Bagian.Text = ""
Call
buttonbaru()
End Sub
Private Sub Btnhapus_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnhapus.Click
SQL = "DELETE
*FROM karyawan Where Nik='" & Nik.Text & "'"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Btnbaru_Click(sender, e)
Call
TampilRecordkaryawan()
End Sub
Private Sub Btnbaru_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnbaru.Click
Call
HapusText()
Nik.Focus()
End Sub
Private Sub Btnkeluar_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnkeluar.Click
Me.Close()
End Sub
Sub
tampilkodejabatan()
kdjabatan.Items.Clear()
SQL = "select
* from jabatan"
CMD = New
OleDbCommand(SQL, DB)
DR = CMD.ExecuteReader
While
DR.Read
kdjabatan.Items.Add(DR("kdjabatan"))
End While
DR.Close()
End Sub
Private Sub Form1_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Call
Opendb()
Call
HapusText()
Call
TampilRecordkaryawan()
Call
tampilkodejabatan()
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
xkode As String
Dim xkd
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.Item(1)
xkd = DR.Item(2)
Jkelamin.Text = DR.Item(3)
Bagian.Text = DR.Item(4)
Call
buttonedit()
MsgBox("Data
ditemukan...! ")
Else
xkode = Nik.Text
Call
HapusText()
Nik.Text = xkode
Call
buttonsimpan()
DR.Close()
End
If
Nama.Focus()
kdjabatan.Text = xkd
Jabatan.Focus()
Jkelamin.Focus()
Bagian.Focus()
End If
End Sub
Private Sub Btnbatal_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnbatal.Click
Call
HapusText()
Nik.Focus()
End Sub
Private Sub Btnedit_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnedit.Click
SQL = "UPDATE
karyawan SET Nama='" & Nama.Text & "',"
& _
"Jabatan='" & kdjabatan.Text & "'," & _
"Jkelamin='" & Jkelamin.Text & "'," & _
" Bagian='" & Bagian.Text & "' " & _
" Where Nik='" & Nik.Text & "'"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Btnbaru_Click(sender, e)
Call
TampilRecordkaryawan()
End Sub
Private Sub Btnsimpan_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnsimpan.Click
SQL = "INSERT
INTO karyawan(Nik, Nama, Jabatan, Jkelamin, Bagian) " & _
"
values('" & Nik.Text & "','"
& _
Nama.Text
& "','" & _
kdjabatan.Text & "','"
& _
Jkelamin.Text & "','" & _
Bagian.Text
& "')"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Btnbaru_Click(sender, e)
Call
TampilRecordkaryawan()
Call
tampilkodejabatan()
End Sub
Private Sub kdjabatan_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
kdjabatan.SelectedIndexChanged
SQL = "SELECT
*FROM jabatan where kdjabatan='" & kdjabatan.Text & "'"
CMD = New
OleDbCommand(SQL, DB)
DR = CMD.ExecuteReader
If
DR.HasRows Then
DR.Read()
Jabatan.Text = DR("kdjabatan")
End If
End Sub
End Class
Form Saat Program Di
Jalankan
Tidak ada komentar:
Posting Komentar