Ini adalah tutorial keempat atau saya sebut Part 4 dalam membuat Aplikasi Penjualan Menggunakan Visual Basic .NET Database MySQL. di Part 4 ini kita akan membuat Tabel Barang yang mempunyai fungsi sebagai data barang yang akan dijual kepada pelanggan. Selain membuat Tabel barang kita juga akan membuat form Barang beserta kodingnya
Mari kita lanjut :
Silahkan buat tabel dengan nama : tbl_barang
Design tabel barang adalah sebagai berikut
Jika sudah membuat tbl_barang
mari kita lanjut ke project aplikasi penjualan yang telah kita buat
Klik Project –> Add Windows Form
Buatlah Form dengan nama : FormMasterBarang.vb
design form seperti gambar paling atas
kemudian masukan koding dibawah ini :
Imports System.Data.Odbc
Public Class FormMasterBarang
Sub KondisiAwal()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
ComboBox1.Text = ""
TextBox1.Enabled = False
TextBox2.Enabled = False
TextBox3.Enabled = False
TextBox4.Enabled = False
ComboBox1.Enabled = False
Button1.Enabled = True
Button2.Enabled = True
Button3.Enabled = True
Button1.Text = "Input"
Button2.Text = "Edit"
Button3.Text = "Hapus"
Button4.Text = "Tutup"
Call Koneksi()
Da = New OdbcDataAdapter("Select * From tbl_barang", Conn)
Ds = New DataSet
Da.Fill(Ds, "tbl_barang")
DataGridView1.DataSource = Ds.Tables("tbl_barang")
DataGridView1.ReadOnly = True
End Sub
Sub SiapIsi()
TextBox1.Enabled = True
TextBox2.Enabled = True
TextBox3.Enabled = True
TextBox4.Enabled = True
ComboBox1.Enabled = True
End Sub
Private Sub FormMasterBarang_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call KondisiAwal()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "Input" Then
Button1.Text = "Simpan"
Button2.Enabled = False
Button3.Enabled = False
Button4.Text = "Batal"
Call SiapIsi()
Else
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or Textbox4.Text = "" Then
MsgBox("Silahkan isi semua Field")
Else
Call Koneksi()
Dim InputData As String = "insert into tbl_barang values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & ComboBox1.Text & "')"
Cmd = New OdbcCommand(InputData, Conn)
Cmd.ExecuteNonQuery()
MsgBox("Input Data Berhasil")
Call KondisiAwal()
End If
End If
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(13) Then
Call Koneksi()
Cmd = New OdbcCommand("Select * From tbl_barang where kodebarang='" & TextBox1.Text & "'", Conn)
Rd = Cmd.ExecuteReader
Rd.Read()
If Not Rd.HasRows Then
MsgBox("Kode barang tidak Ada")
Else
TextBox1.Text = Rd.Item("Kodebarang")
TextBox2.Text = Rd.Item("Namabarang")
TextBox3.Text = Rd.Item("hargabarang")
TextBox4.Text = Rd.Item("jumlahbarang")
ComboBox1.Text = Rd.Item("satuanbarang")
End If
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 Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button4.Text = "Tutup" Then
Me.Close()
Else
Call KondisiAwal()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If Button3.Text = "Hapus" Then
Button3.Text = "Delete"
Button1.Enabled = False
Button2.Enabled = False
Button4.Text = "Batal"
Call SiapIsi()
Else
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or Textbox4.Text = "" Then
MsgBox("Silahkan isi semua Field")
Else
Call Koneksi()
Dim HapusData As String = "Delete from tbl_barang where kodebarang='" & TextBox1.Text & "'"
Cmd = New OdbcCommand(HapusData, Conn)
Cmd.ExecuteNonQuery()
MsgBox("Hapus Data Berhasil")
Call KondisiAwal()
End If
End If
End Sub
Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
End Sub
Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
End Sub
End Class
Link Video Tutorial diatas, bisa anda lihat di Link dibawah :
Demikian Cara Membuat Aplikasi Penjualan VB .NET Database MySQL – #Part 4, semoga bermnfaat dan ikuti terus tutorial selanjutnya.