(Form Jabatan Dan Bagian)
Design Form Jabatan
Listing Program
Imports
System.Data.OleDb
Public Class Form2
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
TampilRecordjabatan()
ADP = New
OleDbDataAdapter("SELECT * FROM jabatan",
DB)
DS = New
DataSet
ADP.Fill(DS, "jabatan")
DataGridView1.DataSource = DS.Tables("jabatan")
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()
kdjabatan.Text = ""
nmjabatan.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 jabatan Where kdjabatan='" & kdjabatan.Text & "'"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Btnbaru_Click(sender, e)
Call
TampilRecordjabatan()
End Sub
Private Sub Btnbaru_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnbaru.Click
Call
HapusText()
kdjabatan.Focus()
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 Form2_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Call
Opendb()
Call
HapusText()
Call
TampilRecordjabatan()
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
xkode 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")
Call
buttonedit()
MsgBox("Data
ditemukan...! ")
Else
xkode = kdjabatan.Text
Call
HapusText()
kdjabatan.Text = xkode
Call
buttonsimpan()
End
If
nmjabatan.Focus()
End If
End Sub
Private Sub Btnbatal_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnbatal.Click
Call
HapusText()
kdjabatan.Focus()
End Sub
Private Sub Btnedit_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnedit.Click
SQL = "UPDATE
jabatan SET nmjabatan='" & nmjabatan.Text & "' " & _
" Where kdjabatan='" &
kdjabatan.Text & "'"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Btnbaru_Click(sender, e)
Call
TampilRecordjabatan()
End Sub
Private Sub Btnsimpan_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnsimpan.Click
SQL = "INSERT
INTO jabatan(kdjabatan, nmjabatan) " & _
"
values('" & kdjabatan.Text & "','"
& _
nmjabatan.Text & "')"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Btnbaru_Click(sender, e)
Call
TampilRecordjabatan()
End Sub
End Class
Design Form Bagian
Listing Program
Imports
System.Data.OleDb
Public Class Form3
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
TampilRecordbagian()
ADP = New
OleDbDataAdapter("SELECT * FROM bagian",
DB)
DS = New
DataSet
ADP.Fill(DS, "bagian")
DataGridView1.DataSource = DS.Tables("bagian")
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()
kdbagian.Text = ""
nmbagian.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 bagian Where kdbagian='" & kdbagian.Text & "'"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Btnbaru_Click(sender, e)
Call
TampilRecordbagian()
End Sub
Private Sub Btnbaru_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnbaru.Click
Call
HapusText()
kdbagian.Focus()
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 Form3_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Call
Opendb()
Call
HapusText()
Call
TampilRecordbagian()
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
xkode 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
nmbagian.Text = DR("nmbagian")
Call
buttonedit()
MsgBox("Data
ditemukan...! ")
Else
xkode = kdbagian.Text
Call
HapusText()
kdbagian.Text = xkode
Call
buttonsimpan()
End
If
nmbagian.Focus()
End If
End Sub
Private Sub Btnbatal_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnbatal.Click
Call
HapusText()
kdbagian.Focus()
End Sub
Private Sub Btnedit_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnedit.Click
SQL = "UPDATE
bagian SET nmbagian='" & nmbagian.Text & "' " & _
" Where kdbagian='" & kdbagian.Text
& "'"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Btnbaru_Click(sender, e)
Call
TampilRecordbagian()
End Sub
Private Sub Btnsimpan_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnsimpan.Click
SQL = "INSERT
INTO bagian(kdbagian, nmbagian) " & _
"
values('" & kdbagian.Text & "','"
& _
nmbagian.Text & "')"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Btnbaru_Click(sender, e)
Call
TampilRecordbagian()
End Sub
End Class
Tidak ada komentar:
Posting Komentar