Sambalado
Sambalado
PRATIKUM
DAFTAR ISI
1. Database
1.1 Entiry Relationship Diagram ……………………………………………………………………………………. 2
1.2 Table Structure ………………………………..…………………………………………………………………….. 3
2. Memulai Project ………………………………………………………………………………………………………………… 5
3. Class Connection ……………………………………………………………………………………………………………….. 6
4. Form 9
4.1 Form Karyawan ……………………………..…………………………………………………………………….. 9
4.2 Form Main Menu …………………………………......…………………………………………………………. 16
4.3 Form Login ………………………………………………………………………………………………………….. 17
4.4 Form Flash .…………………………………………………………………………………………………..…….. 20
4.5 Form Barang ……………………………………………………………………………………………………….. 21
4.6 From Supplier ……………………………………………………………………………………………………... 25
pg. 1
INVENTORY
1. Database
Database atau biasa disebut basis data adalah sekumpulan data atau informasi yang terdiri atas satu
atau lebih tabel yang saling berhubungan antara satu dengan yang lain, di mana seseorang atau lebih
mempunyai wewenang untuk mengakses data tersebut, baik untuk menambah, mengganti,
mengedit, menghapus data dalam tabel-tabel tersebut. Lebih sederhananya pengertian Database
merupakan kumpulan dari informasi yang disimpan dalam komputer dan saling berhubungan satu
sama lain secara siste-matik. Database ini dikelola dan dapat digunakan untuk keperluan tertentu.
Buatlah sebuah database dengan nama Inventory, dalam pembuatan database dapat menggunakan
salah satu DBMS sebagai berikut :
Microsoft Access 2007 atau Microsoft Access 2010
SQL Server
pg. 2
INVENTORY
pg. 3
INVENTORY
NamaTable : TPemesanan
pg. 4
INVENTORY
2. Memulai Project
1. Buka visual Basic 2008
2. Klik New dan kemudian Project
pg. 5
INVENTORY
3. Class Connection
Class Connection adalah class yang akan digunakan untuk koneksi database
pg. 6
INVENTORY
Imports Microsoft.VisualBasic
Imports System.Data.Sql
Cn.Open()
pg. 7
INVENTORY
End Function
Ds = New Data.DataSet
Da.Fill(Ds)
Dt = Ds.Tables(0)
Return Dt
Dt = Nothing
Ds = Nothing
Da = Nothing
Cmd = Nothing
CloseConn()
End Function
pg. 8
INVENTORY
4. Form
4.1 Form Pegawai
Pembuatan form Pegawai
1. Klik kanan Inventory
2. Pilih Add dan kemudian Window Form
pg. 9
INVENTORY
pg. 10
INVENTORY
Text &Hapus
Button Name TutupBtn
Text &Tutup
Groupbox Text Cari Berdasarkan
RadioButton Name CariNip
Text NIP
RadioButton Name CariNmPegawai
Text Nama Pegawai
Textbox Name txtCariData
DataGridView Name dgPegawai
1. Mendefisikan variable
Sub Kode_Otomatis()
tblPegawai = Proses.ExecuteQuery("Select * From TPegawai order by
NIP desc")
If tblPegawai.Rows.Count = 0 Then
txtNIP.Text = "KP-000001"
Else
With tblPegawai.Rows(0)
txtNIP.Text = .Item("NIP")
End With
If Len(txtNIP.Text) = 1 Then
txtNIP.Text = "KP-00000" & txtNIP.Text & ""
ElseIf Len(txtNIP.Text) = 2 Then
txtNIP.Text = "KP-0000" & txtNIP.Text & ""
ElseIf Len(txtNIP.Text) = 3 Then
txtNIP.Text = "KP-000" & txtNIP.Text & ""
ElseIf Len(txtNIP.Text) = 4 Then
txtNIP.Text = "KP-00" & txtNIP.Text & ""
ElseIf Len(txtNIP.Text) = 5 Then
txtNIP.Text = "KP-0" & txtNIP.Text & ""
pg. 11
INVENTORY
Sub Bersih()
txtNIP.Text = ""
txtNama.Text = ""
txtAlm.Text = ""
txtTlp.Text = ""
Call Kode_Otomatis()
Call Data_Record()
SimpanBtn.Enabled = True
UbahBtn.Enabled = False
HapusBtn.Enabled = False
End Sub
If rdLaki.Checked Then
JenisKelamin = "1"
Else
JenisKelamin = "2"
End If
pg. 12
INVENTORY
SQL = "Insert Into TPegawai Values ('" & txtNIP.Text & "','" &
txtNama.Text & "' ,'" & dLahir.Value & "','" & JenisKelamin & "' ,'" &
txtAlm.Text & "' ,'" & txtTlp.Text & "')"
Proses.ExecuteNonQuery(SQL)
MessageBox.Show("Data Baru telah disimpan..!!", "Penyimpanan
Sukses", MessageBoxButtons.OK, MessageBoxIcon.Information)
Call Bersih()
End Sub
pg. 13
INVENTORY
SQL = "Update TPegawai Set nama_pgw = '" & txtNama.Text & "',
tgl_lahir_pgw = '" & dLahir.Value & "', jk_pgw ='" & JenisKelamin & "',
alamat_pgw= '" & txtAlm.Text & "',telp_pgw='" & txtTlp.Text & "' where NIP =
'" & txtNIP.Text & "'"
Proses.ExecuteNonQuery(SQL)
With DgPegawai
txtNIP.Text = .Item(0, .CurrentRow.Index).Value
txtNama.Text = .Item(1, .CurrentRow.Index).Value
dLahir.Text = .Item(2, .CurrentRow.Index).Value
If .Item(3, .CurrentRow.Index).Value = "1" Then
rdLaki.Checked = True
Else
rdPerempuan.Checked = True
End If
txtAlm.Text = .Item(4, .CurrentRow.Index).Value
txtTlp.Text = .Item(5, .CurrentRow.Index).Value
End With
SimpanBtn.Enabled = False : UbahBtn.Enabled = True :
HapusBtn.Enabled = True
BatalBtn.Enabled = True
End Sub
pg. 14
INVENTORY
End If
End Sub
13. Buatlah event untuk menjalankan prosedur CariNIP_CheckedChanged dengan
cara mengklik radio button cariNIP, tujuannya adalah untuk menempatkan
kursor pada posisi CariNIP text box dengan pilihan cari berdasarkan
piliahn NIP Pegawai.
pg. 15
INVENTORY
MenuStrip
ToolStrip
StatusStrip
pg. 16
INVENTORY
pg. 17
INVENTORY
Langkah-langkah pengkodingan
1. Mendefisikan variable
Dim Proses As New clsConnection
Dim tblLogin As DataTable
Sub Hapus()
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Then ctl.Text = ""
Next
txtUser.Focus()
End Sub
End Class
pg. 18
INVENTORY
End If
End Sub
pg. 19
INVENTORY
End If
End Sub
pg. 20
INVENTORY
pg. 21
INVENTORY
Text &Tutup
DataGridView Name dgJenisBarang
1. Mendefisikan variable
Sub Data_Record()
tblJnsBrg = Proses.ExecuteQuery("Select * From Tbarang order by
id_barang asc")
DGJenisBarang.DataSource = tblJnsBrg
DGJenisBarang.Columns(1).Width = 130
End Sub
Sub Kode_Otomatis()
tblJnsBrg = Proses.ExecuteQuery("Select * From TBarang order by
id_barang desc")
If tblJnsBrg.Rows.Count = 0 Then
txtKodeBarang.Text = "1"
Else
With tblJnsBrg.Rows(0)
txtKodeBarang.Text = .Item("id_barang")
End With
txtKodeBarang.Text = Val(txtKodeBarang.Text) + 1
End If
End Sub
Sub bersih()
Call Data_Record()
Call Kode_Otomatis()
SimpanBtn.Enabled = True
UbahBtn.Enabled = False
HapusBtn.Enabled = False
txtKodeBarang.Enabled = False
txtNamaBarang.Text = ""
pg. 22
INVENTORY
txtHrgBeli.Text = ""
txtHrgJual.Text = ""
txtStok.Text = ""
txtNamaBarang.Focus()
End Sub
Me.Top = 0
Me.Left = 0
Call bersih()
End Sub
pg. 23
INVENTORY
pg. 24
INVENTORY
pg. 25
INVENTORY
pg. 26
INVENTORY
1. Mendefisikan variable
Sub Data_Record()
tblsuplier = Proses.ExecuteQuery("Select * From TPemasok
order by id_Pemasok asc")
DgSupplier.DataSource = tblsuplier
DgSupplier.Columns(1).Width = 150
DgSupplier.Columns(2).Width = 435
End Sub
Sub Kode_Otomatis()
tblsuplier = Proses.ExecuteQuery("Select * From TPemasok
order by id_pemasok desc")
If tblsuplier.Rows.Count = 0 Then
txtKodeSupplier.Text = "S001"
Else
With tblsuplier.Rows(0)
txtKodeSupplier.Text = .Item("id_pemasok")
End With
txtKodeSupplier.Text =
Val(Microsoft.VisualBasic.Mid(txtKodeSupplier.Text, 4, 3)) + 1
If Len(txtKodeSupplier.Text) = 1 Then
txtKodeSupplier.Text = "S00" & txtKodeSupplier.Text
& ""
ElseIf Len(txtKodeSupplier.Text) = 2 Then
txtKodeSupplier.Text = "S0" & txtKodeSupplier.Text &
""
ElseIf Len(txtKodeSupplier.Text) = 3 Then
pg. 27
INVENTORY
Sub Bersih()
txtNIP.Text = ""
txtNama.Text = ""
txtAlm.Text = ""
txtTlp.Text = ""
Call Kode_Otomatis()
Call Data_Record()
SimpanBtn.Enabled = True
UbahBtn.Enabled = False
HapusBtn.Enabled = False
End Sub
pg. 28
INVENTORY
pg. 29
INVENTORY
End With
SimpanBtn.Enabled = False : UbahBtn.Enabled = True :
HapusBtn.Enabled = True
BatalBtn.Enabled = True : TutupBtn.Enabled = False
End Sub
pg. 30
INVENTORY
Else
DgSupplier.DataSource = tblsuplier
End If
ElseIf CariNamaSupplier.Checked = True Then
tblsuplier = Proses.ExecuteQuery("Select * From TPemasok
Where nama_pemasok Like '%" & txtCariData.Text & "%'")
If tblsuplier.Rows.Count = 0 Then
DgSupplier.DataSource = tblsuplier
txtCariData.Focus()
Else
DgSupplier.DataSource = tblsuplier
End If
ElseIf Carikontak.Checked = True Then
tblsuplier = Proses.ExecuteQuery("Select * From TPemasok
Where cp_pemasok Like '%" & txtCariData.Text & "%'")
If tblsuplier.Rows.Count = 0 Then
DgSupplier.DataSource = tblsuplier
txtCariData.Focus()
Else
DgSupplier.DataSource = tblsuplier
End If
End If
End Sub
pg. 31