Penjelasan :
Aplikasi ini bertujuan untuk menyimpan data barang dalam suatu gudang.
Screen Shoot :
Source Code :
Script koneksi.vb
Imports System.Data.OleDb
Module koneksi
Public conn As New OleDbConnection
Public sql As String
Public dttable As New DataTable
Public dtadapter As New OleDbDataAdapter
Public cmd As New OleDbCommand
Public reader As OleDbDataReader
Public ds As DataSet
Public dc As DataColumn
Sub koneksiData()
sql = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\bin\Debug\DataBarang.mdb"
conn = New OleDbConnection(sql)
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
End Sub
End Module
Script Form1.vb
Imports System.Data.OleDb
Public Class Form1
Dim Akses As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
koneksiData()
Call data()
Call kode()
Akses = "Add"
Call tombol()
End Sub
Sub tombol()
If Akses = "Add" Then
btnAdd.Enabled = True
btnEdit.Enabled = False
btnDelete.Enabled = False
ElseIf Akses = "Edit" Then
btnAdd.Enabled = False
btnEdit.Enabled = True
btnDelete.Enabled = True
End If
End Sub
Sub data()
koneksiData()
cmd = New OleDbCommand("select * from barang", conn)
ds = New DataSet
ds.Clear()
dtadapter.Fill(ds, "temporer")
dgvBarang.DataSource = (ds.Tables("temporer"))
dgvBarang.ReadOnly = True
cmd.Dispose()
conn.Close()
End Sub
Sub kode()
koneksiData()
cmd = New OleDbCommand("select top(1) kodebarang from barang order by kodebarang desc", conn)
reader = cmd.ExecuteReader
reader.Read()
If reader.HasRows Then
lblKode.Text = reader.Item(0) + 1
End If
reader.Close()
cmd.Dispose()
conn.Close()
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
koneksiData()
cmd = New OleDbCommand("insert into barang values('" & txtNama.Text & "', '" & cmbSatuan.Text & "','" & txtStok.Text & "')", conn)
cmd.ExecuteNonQuery()
cmd.Dispose()
conn.Close()
MsgBox("Data berhasil ditambahkan", MsgBoxStyle.Information, "Data Barang")
Call kosong()
Akses = "Add"
Call tombol()
Call data()
End Sub
Sub kosong()
Call kode()
txtNama.Text = ""
cmbSatuan.Text = ""
txtStok.Text = ""
End Sub
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
koneksiData()
cmd = New OleDbCommand("update barang set namabarang = '" & txtNama.Text & "', satuan = '" & cmbSatuan.Text & "', stokbarang ='" & txtStok.Text & "' where kodebarang = '" & lblKode.Text & "'", conn)
cmd.ExecuteNonQuery()
cmd.Dispose()
conn.Close()
MsgBox("Data Barang dengan kode '" & lblKode.Text & "' berhasil diubah", MsgBoxStyle.Information, "Data Barang")
Call kosong()
Akses = "Add"
Call tombol()
Call data()
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
koneksiData()
cmd = New OleDbCommand("delete barang where kodebarang = '" & lblKode.Text & "'", conn)
cmd.ExecuteNonQuery()
cmd.Dispose()
conn.Close()
MsgBox("Data Barang dengan kode '" & lblKode.Text & "' berhasil dihapus", MsgBoxStyle.Information, "Data Barang")
Call kosong()
Akses = "Add"
Call tombol()
Call data()
End Sub
Private Sub dgvBarang_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvBarang.CellDoubleClick
Akses = "Edit"
cmd = New OleDbCommand("select * from barang where kodebarang = '" & dgvBarang.SelectedCells.Item(0).Value & "'", conn)
reader = cmd.ExecuteReader
reader.Read()
If reader.HasRows Then
lblKode.Text = reader.Item(0)
txtNama.Text = reader.Item(1)
cmbSatuan.Text = reader.Item(2)
txtStok.Text = reader.Item(3)
End If
reader.Close()
cmd.Dispose()
conn.Close()
End Sub
End Class
Tidak ada komentar:
Posting Komentar