Belajar bahasa pemograman
from menu utama
listing program
Public Class Form1
Private Sub KaryawanToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
KaryawanToolStripMenuItem.Click
karyawan.Show()
End Sub
Private Sub BagianToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
BagianToolStripMenuItem.Click
bagian.Show()
End Sub
Private Sub JabatanToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
JabatanToolStripMenuItem.Click
jabatan.Show()
End Sub
Private Sub KeluarToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles KeluarToolStripMenuItem.Click
Me.Close()
End Sub
End Class
form karyawan
listing program
Imports
System.Data.OleDb
Public Class karyawan
Public DB As OleDbConnection
Public CMD As OleDbCommand
Public ADP As OleDbDataAdapter
Public DR As OleDbDataReader
Public DS As DataSet
Dim SQL As String
Public Sub OPENDB()
Dim
LOKASI = "Provider=Microsoft.jet.OLEDB.4.0;Data
Source=C:\Novi\DATABASE3.mdb"
DB = New
OleDbConnection(LOKASI)
If
DB.State = ConnectionState.Closed Then
DB.Open()
End If
End Sub
Sub
Recordkaryawan()
ADP = New OleDbDataAdapter("SELECT*FROM karyawan", DB)
DS = New
DataSet
ADP.Fill(DS, "karyawan")
DataGridView1.DataSource = DS.Tables("karyawan")
End Sub
Sub BARU()
Button1.Enabled = True
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = False
Button6.Enabled = True
End Sub
Sub EDIT()
Button1.Enabled = False
Button2.Enabled = False
Button3.Enabled = True
Button4.Enabled = True
Button5.Enabled = True
Button6.Enabled = False
End Sub
Sub
SIMPAN()
Button1.Enabled = False
Button2.Enabled = True
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = True
Button6.Enabled = False
End Sub
Sub
Hapustext()
nik.Text = ""
nama.Text = ""
Call
BARU()
End Sub
Private Sub karyawan_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Call
OPENDB()
Call
Hapustext()
Call
Recordkaryawan()
jenis_kelamin.Items.Add("WANITA")
jenis_kelamin.Items.Add("LAKI-LAKI")
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
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(2)
bagian.Text = DR.Item(4)
Call
EDIT()
MsgBox("Data
ditemukan!")
Else
xkode = nik.Text
Call
Hapustext()
nik.Text = xkode
Call
SIMPAN()
End
If
nama.Focus()
End If
End Sub
Private Sub nik_TextChanged(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles nik.TextChanged
End Sub
Private Sub Button1_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Call
Hapustext()
nik.Focus()
End Sub
Private Sub Button5_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Call
Hapustext()
nik.Focus()
End Sub
Private Sub Button6_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button6.Click
Me.Close()
End Sub
Private Sub Button4_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
SQL = "DELETE
FROM karyawan where nik='" & nik.Text & "'"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Button1_Click(sender, e)
Call
Recordkaryawan()
End Sub
Private Sub Button2_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
SQL = "insert
into karyawan (NIK, Nama, Jenis_Kelamin, Bagian)" & _
"
values ('" & nik.Text & "','"
& _
nama.Text & "','" & _
jenis_kelamin.Text &
"','" & _
bagian.Text & "')"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Button1_Click(sender, e)
Call
Recordkaryawan()
End Sub
Private Sub Button3_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
SQL = "UPDATE
karyawan SET nama='" & nama.Text & "',"
& _
"jenis_kelamin ='" & jenis_kelamin.Text & "'," & _
"bagian='" & bagian.Text & "' " & _
"where nik='" & nik.Text & "'"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Button1_Click(sender, e)
Call
Recordkaryawan()
End Sub
End Class
form bagian
listing program
Imports
System.Data.OleDb
Public Class bagian
Public DB As OleDbConnection
Public CMD As OleDbCommand
Public ADP As OleDbDataAdapter
Public DR As OleDbDataReader
Public DS As DataSet
Dim SQL As String
Public Sub OPENDB()
Dim
LOKASI = "Provider=Microsoft.jet.OLEDB.4.0;Data
Source=C:\kiki\DATABASE3.mdb"
DB = New
OleDbConnection(LOKASI)
If
DB.State = ConnectionState.Closed Then
DB.Open()
End If
End Sub
Sub
Recordbagian()
ADP = New
OleDbDataAdapter("SELECT*FROM bagian",
DB)
DS = New
DataSet
ADP.Fill(DS, "bagian")
DataGridView1.DataSource = DS.Tables("bagian")
End Sub
Sub BARU()
Button1.Enabled = True
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = False
Button6.Enabled = True
End Sub
Sub EDIT()
Button1.Enabled = False
Button2.Enabled = False
Button3.Enabled = True
Button4.Enabled = True
Button5.Enabled = True
Button6.Enabled = False
End Sub
Sub
SIMPAN()
Button1.Enabled = False
Button2.Enabled = True
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = True
Button6.Enabled = False
End Sub
Sub
Hapustext()
TextBox1.Text = ""
TextBox2.Text = ""
Call
BARU()
End Sub
Private Sub bagian_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Call
OPENDB()
Call
Hapustext()
Call
Recordbagian()
End Sub
Private Sub Button6_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button6.Click
Me.Close()
End Sub
Private Sub TextBox1_KeyPress(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles
TextBox1.KeyPress
Dim
tombol As Integer
= Asc(e.KeyChar)
Dim
xkode As String
If
tombol = 13 Then
SQL = "SELECT
* FROM bagian where kdbagian='" & TextBox1.Text & "'"
CMD = New
OleDbCommand(SQL, DB)
DR = CMD.ExecuteReader
DR.Read()
If
DR.HasRows = True Then
TextBox2.Text = DR.Item(2)
Call
EDIT()
MsgBox("Data
ditemukan!")
Else
xkode = TextBox1.Text
Call
Hapustext()
TextBox1.Text = xkode
Call
SIMPAN()
End
If
TextBox2.Focus()
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button5_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Call
Hapustext()
TextBox1.Focus()
End Sub
Private Sub Button1_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Call
Hapustext()
TextBox1.Focus()
End Sub
Private Sub Button4_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
SQL = "DELETE
FROM bagian where kdbagian='" & TextBox1.Text & "'"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Button1_Click(sender, e)
Call
Recordbagian()
End Sub
Private Sub Button2_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
SQL = "insert
into bagian (kdbagian, Nmbagian)" & _
" values ('" & TextBox1.Text & "','" & _
TextBox2.Text & "')"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Button1_Click(sender, e)
Call
Recordbagian()
End Sub
Private Sub Button3_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
SQL = "UPDATE
bagian SET nmbagian='" & TextBox2.Text & "' " & _
"where kdbagian='" &
TextBox1.Text & "'"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Button1_Click(sender, e)
Call
Recordbagian()
End Sub
End Class
form jabatan
listing program
Imports
System.Data.OleDb
Public Class jabatan
Public DB As OleDbConnection
Public CMD As OleDbCommand
Public ADP As OleDbDataAdapter
Public DR As OleDbDataReader
Public DS As DataSet
Dim SQL As String
Public Sub OPENDB()
Dim
LOKASI = "Provider=Microsoft.jet.OLEDB.4.0;Data
Source=C:\kiki\DATABASE3.mdb"
DB = New
OleDbConnection(LOKASI)
If
DB.State = ConnectionState.Closed Then
DB.Open()
End If
End Sub
Sub
Recordjabatan()
ADP = New
OleDbDataAdapter("SELECT*FROM jabatan",
DB)
DS = New
DataSet
ADP.Fill(DS, "jabatan")
DataGridView1.DataSource = DS.Tables("jabatan")
End Sub
Sub BARU()
Button1.Enabled = True
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = False
Button6.Enabled = True
End Sub
Sub EDIT()
Button1.Enabled = False
Button2.Enabled = False
Button3.Enabled = True
Button4.Enabled = True
Button5.Enabled = True
Button6.Enabled = False
End Sub
Sub
SIMPAN()
Button1.Enabled = False
Button2.Enabled = True
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = True
Button6.Enabled = False
End Sub
Sub
Hapustext()
TextBox1.Text = ""
TextBox2.Text = ""
Call
BARU()
End Sub
Private Sub bagian_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Call
OPENDB()
Call
Hapustext()
Call
Recordjabatan()
End Sub
Private Sub jabatan_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Call
Hapustext()
TextBox1.Focus()
End Sub
Private Sub Button5_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Call
Hapustext()
TextBox1.Focus()
End Sub
Private Sub Button6_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button6.Click
Me.Close()
End Sub
Private Sub TextBox1_KeyPress(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles
TextBox1.KeyPress
Dim
tombol As Integer
= Asc(e.KeyChar)
Dim
xkode As String
If
tombol = 13 Then
SQL = "SELECT
* FROM jabatan where kdjabatan='" & TextBox1.Text & "'"
CMD = New
OleDbCommand(SQL, DB)
DR = CMD.ExecuteReader
DR.Read()
If
DR.HasRows = True Then
TextBox2.Text = DR.Item(2)
Call
EDIT()
MsgBox("Data
ditemukan!")
Else
xkode = TextBox1.Text
Call
Hapustext()
TextBox1.Text = xkode
Call
SIMPAN()
End
If
TextBox2.Focus()
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button2_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
SQL = "insert
into jabatan (kdjabatan, Nmjabatan)" & _
" values ('" & TextBox1.Text & "','" & _
TextBox2.Text & "')"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Button1_Click(sender, e)
Call
Recordjabatan()
End Sub
Private Sub Button3_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
SQL = "UPDATE
jabatan SET nmjabatan='" & TextBox2.Text & "' " & _
"where
kdjabatan='" & TextBox1.Text & "'"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Button1_Click(sender, e)
Call
Recordjabatan()
End Sub
Private Sub Button4_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
SQL = "DELETE
FROM jabatan where kdjabatan='" & TextBox1.Text & "'"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Button1_Click(sender, e)
Call
Recordjabatan()
End Sub
End Class
Table Karyawan
ID
|
NIK
|
Nama
|
Jenis_kelamin
|
Bagian
|
1
|
12342
|
Novi
|
Perempuan
|
ob
|
2
|
34532
|
Anggie
|
Laki-laki
|
Sekretaris
|
3
|
23456
|
Novret
|
Perempuan
|
Derektur
|
4
|
12345
|
mesran
|
Laki-laki
|
sekretaris
|
|
|
|
|
|
Table
jabatan
ID
|
KDjabatan
|
Nmjabatatan
|
1
|
12345
|
Waloyo
|
2
|
67895
|
Dwi
|
3
|
87653
|
mesran
|
Table
bagian
ID
|
Kdbagian
|
Nmbagian
|
1
|
23456
|
Sani
|
2
|
34567
|
Tuyem
|
3
|
12345
|
mesran
|
0 komentar:
Posting Komentar