Download - Modul praktikum vb

Transcript
Page 1: Modul praktikum vb

INPUT DATA BARANG

1. Desainlah Iterface sebagai berikut

2. Setting property sebagai berikut

Objeck Property Value

Form1 Name frmBarang.vb

Text Form Input Data Barang

GroupBox1 Text Input Detail Data Barang

GroupBox2 Text Proses

GroupBox3 Text Tampil Data Barang

Label1 Text Kode Barang

Label2 Text Nama Barang

Label3 Text Satuan

Label4 Text Harga Barang

Label5 Text Harga Jual

TextBox1 Name xkobar

Maxlength 5

TextBox2 Name xNabar

ComboBox1 Name cmbSatuan

Text -Pilihan-

TextBox3 Name Xharbar

TextAlign Right

TextBox4 Name Xharju

TextAlign Right

ListView1 Name LVBarang

Button1 Name btnAdd

Text &Add

Button2 Name btnSave

Text &Save

Page 2: Modul praktikum vb

Button3 Name btnEdit

Text &Edit

Button4 Name btnDelete

Text &Delete

Button5 Name btnCancel

Text &Cancel

Button6 Name btnClose

Text Cl&ose

3. Buat Database Penjualan dengan Tabel Database sebagai Berikut

TABEL BARANG

Field Name Type Data Keterangan

Kobar* Varchar(5) Kode Barang

Nabar Varchar(30) Nama Barang

Satuan Varchar(15) Satuan Barang

Harbar Double Harga Barang

Harju Double Harga Jual

TABEL SUPPLIER

Field Name Type Data Keterangan

Kosup* Varchar(5) Kode Supplier

Nasup Varchar(30) Nama Supplier

Alsup Varchar(35) Alamat Supplier

Telsup Varchar(12) Telepon Supplier

Emsup Varchar(30) Email Supplier

TABEL CUSTOMER

Field Name Type Data Keteranga

Kocus* Varchar(5) Kode Customer

Nacus Varchar(30) Nama Customer

Alcus Varchar(15) Alamat Customer

Telcus Varchar(12) Telepon Customer

Emcus Varchar(30) Email Customer

TABEL ADMIN

Field Name Type Data Keteranga

idAdmin* Varchar(5) ID Admin

Naad Varchar(35) Nama Admin

userID Varchar(20) User ID Admin

Password Varchar(8) Password Admin

4. Tambahkan Modul Koneksi

Menu Project>Add Module>pada name ketik nama modul misaalnya KoneksiPenjualan.vb

5. Aktifkan Mysql.Data

Menu Project>Add Reference>pada Tab .NET cari mysql.data>kemudian Click OK

6. Pada Modul KoneksiPenjualan.VB ketik kode program sebagai berikut

Imports MySql.Data.MySqlClient

Module koneksiPenjualan

Public db As New MySql.Data.MySqlClient.MySqlConnection

Public sql As String

Public cmd As MySqlCommand

Page 3: Modul praktikum vb

Public dreader As MySqlDataReader

Sub opendb()

sql = "server=localhost;uid=root;database=penjualan"

Try

db.ConnectionString = sql

db.Open()

Catch ex As Exception

End Try

End Sub

End Module

7. Pada frmbarang Buka Jendele view Code tambahkan kode program berikut

Imports MySql.Data.MySqlClient

Public Class frmBarang

Dim x As Byte

Dim z As String

End Class

8. Buka Jendela View Code frmBarang> pada combo General Pilih frmBarang(events) dan pada Declarations

pilih Load, kemudian ketik kode program sebagai berikut:

opendb()

buattabel()

isitabel()

bersihkanForm()

TampilkanSatuan()

9. Tambahkan procedure sub buattabel, kemdian ketik kode program berikut lvBarang.Columns.Add("No", 30, HorizontalAlignment.Left)

lvBarang.Columns.Add("Kode Barang", 70, HorizontalAlignment.Left)

lvBarang.Columns.Add("Nama Barang", 100, HorizontalAlignment.Left)

lvBarang.Columns.Add("Satuan", 60, HorizontalAlignment.Left)

lvBarang.Columns.Add("Harga Barang", 100, HorizontalAlignment.Right)

lvBarang.Columns.Add("Harga Jual", 100, HorizontalAlignment.Right)

lvBarang.GridLines = True

lvBarang.FullRowSelect = True

lvBarang.View = View.Details

10. Tambahkan procedure sub isitabel, kemdian ketik kode program berikut lvBarang.Items.Clear()

sql = "select * from barang order by kobar asc"

cmd = New MySqlCommand(sql, db)

dreader = cmd.ExecuteReader

Try

Dim no As Integer = 0

While dreader.Read

no = no + 1

Dim simpan As New ListViewItem

With simpan

.Text = no

.SubItems.Add(dreader("Kobar"))

.SubItems.Add(dreader("nabar"))

.SubItems.Add(dreader("satuan"))

.SubItems.Add(dreader("harbar"))

.SubItems.Add(dreader("harju"))

lvBarang.Items.Add(simpan)

End With

End While

Catch ex As Exception

Page 4: Modul praktikum vb

MessageBox.Show(ex.Message)

End Try

dreader.Close()

11. Tambahkan procedure sub bersihkanform, kemdian ketik kode program berikut xKobar.Text = ""

xnabar.Text = ""

cmbSatuan.Text = "--Pilih--"

xHarbar.Text = ""

xHarju.Text = ""

aktifitas(1)

xKobar.Enabled = True

12. Tambahkan procedure sub tampilkansatuan, kemdian ketik kode program berikut cmbSatuan.Items.Add("Pcs")

cmbSatuan.Items.Add("Botol")

cmbSatuan.Items.Add("Lusin")

cmbSatuan.Items.Add("Gross")

cmbSatuan.Items.Add("Kodi")

cmbSatuan.Items.Add("Dus")

cmbSatuan.Items.Add("Set/Unit")

cmbSatuan.Items.Add("Kg")

13. Tambahkan procedure sub rubahtombol, kemdian ketik kode program berikut Sub rubahtombol(ByVal a1 As Boolean, ByVal a2 As Boolean, ByVal a3 As Boolean,

ByVal a4 As Boolean, ByVal a5 As Boolean, ByVal a6 As Boolean, ByVal a7 As

Boolean)

btnAdd.Enabled = a1

btnSAve.Enabled = a2

btnEdit.Enabled = a3

btnCancel.Enabled = a4

btnDelete.Enabled = a5

btnClose.Enabled = a6

GroupBox1.Enabled = a7

End Sub

14. Tambahkan procedure sub aktifitas, kemdian ketik kode program berikut

Sub aktifitas(ByVal tombol As Byte)

Select Case tombol

Case 1 'awal

rubahtombol(True, False, False, False, False, True, False)

Case 2 ' Add

rubahtombol(False, True, False, True, False, False, True)

xKobar.Focus()

Case 3 ' editc

rubahtombol(False, False, True, True, True, False, True)

End Select

End Sub

15. Tambahkan procedure sub tampildata, kemdian ketik kode program berikut

dreader.Read()

xKobar.Text = dreader("kobar")

xnabar.Text = dreader("nabar")

cmbSatuan.Text = dreader("satuan")

xHarbar.Text = dreader("harbar")

xHarju.Text = dreader("harju")

16. Pada combo General Pilih btnAdd dan pada Declarations pilih Click, kemudian ketik kode program

berikut:

Page 5: Modul praktikum vb

aktifitas(2)

17. Pada combo General Pilih btncancel dan pada Declarations pilih Click, kemudian ketik kode program

berikut:

bersihkanForm()

aktifitas(1)

18. Pada combo General Pilih btnsave dan pada Declarations pilih Click, kemudian ketik kode program

berikut: If xKobar.Text = "" Or xnabar.Text = "" Or cmbSatuan.Text = "--Pilih--" Or

xHarbar.Text = "" Or xHarju.Text = "" Then

MsgBox("Isi data Dengan benar ")

Else

x = MsgBox("Save?", MsgBoxStyle.Information + MsgBoxStyle.YesNo, "Save")

If x = vbYes Then

simpandata(1)

bersihkanForm()

Else

bersihkanForm()

End If

End If

19. Tambahkan procedure sub simpandata, kemudian ketik kode program berikut

Sub simpandata(ByVal simpan As Byte)

Dim pesan As String = Nothing

Select Case simpan

Case 1 'Menyimpan Data

sql = "insert into barang values('" & xKobar.Text & "','" & _

xnabar.Text & "','" & _

cmbSatuan.Text & "','" & _

xHarbar.Text & "','" & _

xHarju.Text & "')"

pesan = "Data Sudah disimpan"

Case 2 'Update Data

sql = "update Barang set nabar='" & xnabar.Text & _

"', satuan='" & cmbSatuan.Text & _

"', harbar='" & xHarbar.Text & _

"', Harju='" & xHarju.Text & _

"' where kobar='" & xKobar.Text & "'"

pesan = "Data Sudah si Edit"

Case 3 'Delete Data

sql = "delete from Barang where kobar='" & xKobar.Text & "'"

pesan = "Data sudah di hapus "

End Select

Try

cmd = New MySqlCommand(sql, db)

cmd.ExecuteNonQuery()

isitabel()

MsgBox(pesan)

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

End Sub

20. Pada combo General Pilih btnEdit dan pada Declarations pilih Click, kemudian ketik kode program

berikut: x = MsgBox("Update?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "Edit")

Page 6: Modul praktikum vb

If x = vbYes Then

simpandata(2)

bersihkanForm()

Else

bersihkanForm()

End If

21. Pada combo General Pilih btnDelete dan pada Declarations pilih Click, kemudian ketik kode program

berikut: x = MsgBox("Delete?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "Delete")

If x = vbYes Then

simpandata(3)

bersihkanForm()

Else

bersihkanForm()

End If

22. Pada combo General Pilih xkobar dan pada Declarations pilih keydown, kemudian ketik kode program

berikut: If e.KeyCode = Keys.Return Then

If xKobar.Text = "" Then

MsgBox("maaf.... data belum lengkap !!!")

Else

sql = "select *from barang where kobar='" & xKobar.Text & "'"

cmd = New MySqlCommand(sql, db)

dreader = cmd.ExecuteReader

Try

tampildata()

aktifitas(3)

MsgBox("Data Sudah Ada ")

xKobar.Enabled = False

Catch ex As Exception

Z = xKobar.Text

bersihkanForm()

xKobar.Text = Z

aktifitas(2)

End Try

End If

dreader.Close()

xnabar.Focus()

End If

23. Pada combo General Pilih LVBarang dan pada Declarations pilih click, kemudian ketik kode program

berikut: xKobar.Text = lvBarang.SelectedItems(0).SubItems(1).Text

sql = "select *from barang where kobar='" & xKobar.Text & "'"

cmd = New MySqlCommand(sql, db)

dreader = cmd.ExecuteReader

Try

MsgBox("Data Siap Untuk di Ubah")

tampildata()

xKobar.Enabled = False

aktifitas(3)

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

dreader.Close()

Page 7: Modul praktikum vb

24. Pada combo General Pilih btnClose dan pada Declarations pilih click, kemudian ketik kode program berikut: Me.Close()

25. Pada combo General Pilih xharbar dan pada Declarations pilih Keypress, kemudian ketik kode program

berikut: If e.KeyChar = ChrW(13) Then

btnSAve.Focus()

End If

26. Pada combo General Pilih xharbar dan pada Declarations pilih TextChanged, kemudian ketik kode

program berikut: xHarju.Text = (0.1 * Val(xHarbar.Text)) + Val(xHarbar.Text)

27. Pada combo General Pilih xnabar dan pada Declarations pilih Keypress, kemudian ketik kode program

berikut: If e.KeyChar = ChrW(13) Then

cmbSatuan.Focus()

End If

28. Pada combo General Pilih xnabar dan pada Declarations pilih Keypress, kemudian ketik kode program berikut:

If e.KeyChar = ChrW(13) Then

xHarbar.Focus()

End If

Page 8: Modul praktikum vb

FORM INPUT DATA SUPPLIER

1. Desainlah Iterface sebagai berikut

2. Setting property sebagai berikut

Objeck Property Value

Form1 Name frmsupplier.vb

Text Form Input Data Supplier

GroupBox1 Text Input Detail Data Supplier

GroupBox2 Text Proses

GroupBox3 Text Tampil Data Supplier

Label1 Text Kode Supplier

Label2 Text Nama Supplier

Label3 Text Alamat Supplier

Label4 Text Telepon Supplier

Label5 Text Email Supplier

TextBox1 Name xkosup

Maxlength 5

TextBox2 Name xNasup

TextBox3 Name xalsup

TextBox4 Name xtelsup

TextBox5 Name xemsup

ListView1 Name LVSupplier

Button1 Name btnAdd

Text &Add

Button2 Name btnSave

Text &Save

Button3 Name btnEdit

Text &Edit

Page 9: Modul praktikum vb

Button4 Name btnDelete

Text &Delete

Button5 Name btnCancel

Text &Cancel

Button6 Name btnClose

Text Cl&ose

2. Pada frmsupplier Buka Jendele view Code tambahkan kode program berikut

Imports MySql.Data.MySqlClient

Public Class frmBarang

Dim x As Byte

Dim z As String

End Class

3. Buka Jendela View Code frmsupplier> pada combo General Pilih frmSupplier(events) dan pada

Declarations pilih Load, kemudian ketik kode program sebagai berikut:

opendb()

buattabel()

isitabel()

bersihkanForm()

4. Tambahkan procedure sub buattabel, kemdian ketik kode program berikut

Sub buattabel()

LVSupplier.Columns.Add("No", 30, HorizontalAlignment.Left)

LVSupplier.Columns.Add("Kode Supplier", 80, HorizontalAlignment.Left)

LVSupplier.Columns.Add("Nama Supplier", 120, HorizontalAlignment.Left)

LVSupplier.Columns.Add("Alamat Supplier", 150, HorizontalAlignment.Left)

LVSupplier.Columns.Add("Telepon", 80, HorizontalAlignment.Left)

LVSupplier.Columns.Add("Email", 100, HorizontalAlignment.Left)

LVSupplier.GridLines = True

LVSupplier.FullRowSelect = True

LVSupplier.View = View.Details

End Sub

5. Tambahkan procedure sub isitabel, kemdian ketik kode program berikut

Sub isitabel()

LVSupplier.Items.Clear()

sql = "select * from supplier order by kosup asc"

cmd = New MySqlCommand(sql, db)

dreader = cmd.ExecuteReader

Try

Dim no As Integer = 0

While dreader.Read

no = no + 1

Dim simpan As New ListViewItem

With simpan

.Text = no

.SubItems.Add(dreader("kosup"))

.SubItems.Add(dreader("nasup"))

.SubItems.Add(dreader("alsup"))

.SubItems.Add(dreader("telsup"))

.SubItems.Add(dreader("emsup"))

LVSupplier.Items.Add(simpan)

End With

End While

Page 10: Modul praktikum vb

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

dreader.Close()

End Sub

6. Tambahkan procedure sub bersihkanform, kemdian ketik kode program berikut

Sub bersihkanForm()

xKosup.Text = ""

xNasup.Text = ""

xalsup.Text = ""

xtelsup.Text = ""

xemsup.Text = ""

aktifitas(1)

xKosup.Enabled = True

End Sub

7. Tambahkan procedure sub rubahtombol, kemdian ketik kode program berikut

Sub rubahtombol(ByVal a1 As Boolean, ByVal a2 As Boolean, ByVal a3 As Boolean,

ByVal a4 As Boolean, ByVal a5 As Boolean, ByVal a6 As Boolean, ByVal a7 As

Boolean)

btnAdd.Enabled = a1

btnSave.Enabled = a2

btnEdit.Enabled = a3

btnCancel.Enabled = a4

btnDelete.Enabled = a5

btnClose.Enabled = a6

GroupBox1.Enabled = a7

End Sub

8. Tambahkan procedure sub aktifitas, kemdian ketik kode program berikut

Sub aktifitas(ByVal tombol As Byte)

Select Case tombol

Case 1 'awal

rubahtombol(True, False, False, False, False, True, False)

Case 2 ' Add

rubahtombol(False, True, False, True, False, False, True)

xKosup.Focus()

Case 3 ' editc

rubahtombol(False, False, True, True, True, False, True)

End Select

End Sub

9. Tambahkan procedure sub tampildata, kemdian ketik kode program berikut

Sub tampildata()

dreader.Read()

xKosup.Text = dreader("kosup")

xNasup.Text = dreader("nasup")

xalsup.Text = dreader("alsup")

xtelsup.Text = dreader("telsup")

xemsup.Text = dreader("emsup")

End Sub

10. Pada combo General Pilih btnAdd dan pada Declarations pilih Click, kemudian ketik kode program

berikut:

aktifitas(2)

Page 11: Modul praktikum vb

11. Pada combo General Pilih btncancel dan pada Declarations pilih Click, kemudian ketik kode program

berikut:

bersihkanForm()

aktifitas(1)

12. Pada combo General Pilih btnsave dan pada Declarations pilih Click, kemudian ketik kode program

berikut:

If xKosup.Text = "" Or xNasup.Text = "" Or xalsup.Text = "--Pilih--" Or

xtelsup.Text = "" Or xemsup.Text = "" Then

MsgBox("Isi data Dengan benar ")

Else

x = MsgBox("Save?", MsgBoxStyle.Information + MsgBoxStyle.YesNo, "Save")

If x = vbYes Then

simpandata(1)

bersihkanForm()

Else

bersihkanForm()

End If

End If

13. Tambahkan procedure sub simpandata, kemudian ketik kode program berikut

Sub simpandata(ByVal simpan As Byte)

Dim pesan As String = Nothing

Select Case simpan

Case 1 'Menyimpan Data

sql = "insert into supplier values('" & xKosup.Text & "','" & _

xNasup.Text & "','" & _

xalsup.Text & "','" & _

xtelsup.Text & "','" & _

xemsup.Text & "')"

pesan = "Data Sudah disimpan"

Case 2 'Update Data

sql = "update Supplier set nasup='" & xNasup.Text & _

"', alsup='" & xalsup.Text & _

"', telsup='" & xtelsup.Text & _

"', emsup='" & xemsup.Text & _

"' where kosup='" & xKosup.Text & "'"

pesan = "Data Sudah si Edit"

Case 3 'Delete Data

sql = "delete from supplier where kosup='" & xKosup.Text & "'"

pesan = "Data sudah di hapus "

End Select

Try

cmd = New MySqlCommand(sql, db)

cmd.ExecuteNonQuery()

isitabel()

MsgBox(pesan)

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

End Sub

14. Pada combo General Pilih btnEdit dan pada Declarations pilih Click, kemudian ketik kode program

berikut:

x = MsgBox("Update?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "Edit")

Page 12: Modul praktikum vb

If x = vbYes Then

simpandata(2)

bersihkanForm()

Else

bersihkanForm()

End If

15. Pada combo General Pilih btnDelete dan pada Declarations pilih Click, kemudian ketik kode program

berikut:

x = MsgBox("Delete?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "Delete")

If x = vbYes Then

simpandata(3)

bersihkanForm()

Else

bersihkanForm()

End If

16. Pada combo General Pilih xkosup dan pada Declarations pilih keydown, kemudian ketik kode program

berikut:

If e.KeyCode = Keys.Return Then

If xKosup.Text = "" Then

MsgBox("maaf.... data belum lengkap !!!")

Else

sql = "select *from supplier where kosup='" & xKosup.Text & "'"

cmd = New MySqlCommand(sql, db)

dreader = cmd.ExecuteReader

Try

tampildata()

aktifitas(3)

MsgBox("Data Sudah Ada ")

xKosup.Enabled = False

Catch ex As Exception

z = xKosup.Text

bersihkanForm()

xKosup.Text = z

aktifitas(2)

End Try

End If

dreader.Close()

xNasup.Focus()

End If

17. Pada combo General Pilih LVSupplier dan pada Declarations pilih click, kemudian ketik kode program

berikut:

xKosup.Text = LVSupplier.SelectedItems(0).SubItems(1).Text

sql = "select *from supplier where kosup='" & xKosup.Text & "'"

cmd = New MySqlCommand(sql, db)

dreader = cmd.ExecuteReader

Try

MsgBox("Data Siap Untuk di Ubah")

tampildata()

xKosup.Enabled = False

aktifitas(3)

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

dreader.Close()

Page 13: Modul praktikum vb

18. Pada combo General Pilih btnClose dan pada Declarations pilih click, kemudian ketik kode program

berikut:

Me.Close()

19. Pada combo General Pilih xemsup dan pada Declarations pilih Keypress, kemudian ketik kode program

berikut:

If e.KeyChar = ChrW(13) Then

btnSave.Focus()

End If

20. Pada combo General Pilih xnasup dan pada Declarations pilih Keypress, kemudian ketik kode program

berikut:

If e.KeyChar = ChrW(13) Then

xalsup.Focus()

End If

21. Pada combo General Pilih xtelsup dan pada Declarations pilih Keypress, kemudian ketik kode program

berikut:

If e.KeyChar = ChrW(13) Then

xemsup.Focus()

End If

22. Pada combo General Pilih xalsup dan pada Declarations pilih Keypress, kemudian ketik kode program

berikut:

If e.KeyChar = ChrW(13) Then

xtelsup.Focus()

End If

Page 14: Modul praktikum vb

FORM INPUT DATA CUSTOMER

1. Desainlah Iterface sebagai berikut

2. Setting property sebagai berikut

Objeck Property Value

Form1 Name frmCustomer.vb

Text Form Input Data Customer

GroupBox1 Text Input Detail Data Customer

GroupBox2 Text Proses

GroupBox3 Text Tampil Data Customer

Label1 Text Kode Customer

Label2 Text Nama Customer

Label3 Text Alamat Customer

Label4 Text Telepon Customer

Label5 Text Email Customer

TextBox1 Name Xkocus

Maxlength 5

TextBox2 Name xNacus

TextBox3 Name Xalcus

TextBox4 Name Xtelcus

TextBox5 Name xemcus

ListView1 Name LVCustomer

Button1 Name btnAdd

Text &Add

Button2 Name btnSave

Text &Save

Button3 Name btnEdit

Text &Edit

Page 15: Modul praktikum vb

Button4 Name btnDelete

Text &Delete

Button5 Name btnCancel

Text &Cancel

Button6 Name btnClose

Text Cl&ose

3. Pada frmcustomer Buka Jendele view Code tambahkan kode program berikut

Imports MySql.Data.MySqlClient

Public Class frmcustomer

Dim x As Byte

Dim z As String

End Class

4. Buka Jendela View Code frmsupplier> pada combo General Pilih frmCustomer(events) dan pada

Declarations pilih Load, kemudian ketik kode program sebagai berikut:

opendb()

buattabel()

isitabel()

bersihkanForm()

5. Tambahkan procedure sub buattabel, kemdian ketik kode program berikut

Sub buattabel()

LVCustomer.Columns.Add("No", 30, HorizontalAlignment.Left)

LVCustomer.Columns.Add("Kode Customer", 80, HorizontalAlignment.Left)

LVCustomer.Columns.Add("Nama Customer", 120, HorizontalAlignment.Left)

LVCustomer.Columns.Add("Alamat Customer", 150, HorizontalAlignment.Left)

LVCustomer.Columns.Add("Telepon", 80, HorizontalAlignment.Left)

LVCustomer.Columns.Add("Email", 100, HorizontalAlignment.Left)

LVCustomer.GridLines = True

LVCustomer.FullRowSelect = True

LVCustomer.View = View.Details

End Sub

6. Tambahkan procedure sub isitabel, kemdian ketik kode program berikut

Sub isitabel()

LVCustomer.Items.Clear()

sql = "select * from Customer order by kocus asc"

cmd = New MySqlCommand(sql, db)

dreader = cmd.ExecuteReader

Try

Dim no As Integer = 0

While dreader.Read

no = no + 1

Dim simpan As New ListViewItem

With simpan

.Text = no

.SubItems.Add(dreader("kocus"))

.SubItems.Add(dreader("nacus"))

.SubItems.Add(dreader("alcus"))

.SubItems.Add(dreader("telcus"))

.SubItems.Add(dreader("emcus"))

LVSupplier.Items.Add(simpan)

End With

End While

Page 16: Modul praktikum vb

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

dreader.Close()

End Sub

7. Tambahkan procedure sub bersihkanform, kemdian ketik kode program berikut

Sub bersihkanForm()

xKocus.Text = ""

xNacus.Text = ""

xalcus.Text = ""

xtelcus.Text = ""

xemcus.Text = ""

aktifitas(1)

xKocus.Enabled = True

End Sub

8. Tambahkan procedure sub rubahtombol, kemdian ketik kode program berikut

Sub rubahtombol(ByVal a1 As Boolean, ByVal a2 As Boolean, ByVal a3 As Boolean,

ByVal a4 As Boolean, ByVal a5 As Boolean, ByVal a6 As Boolean, ByVal a7 As

Boolean)

btnAdd.Enabled = a1

btnSave.Enabled = a2

btnEdit.Enabled = a3

btnCancel.Enabled = a4

btnDelete.Enabled = a5

btnClose.Enabled = a6

GroupBox1.Enabled = a7

End Sub

9. Tambahkan procedure sub aktifitas, kemdian ketik kode program berikut

Sub aktifitas(ByVal tombol As Byte)

Select Case tombol

Case 1 'awal

rubahtombol(True, False, False, False, False, True, False)

Case 2 ' Add

rubahtombol(False, True, False, True, False, False, True)

xKosup.Focus()

Case 3 ' editc

rubahtombol(False, False, True, True, True, False, True)

End Select

End Sub

10. Tambahkan procedure sub tampildata, kemdian ketik kode program berikut

Sub tampildata()

dreader.Read()

xKocus.Text = dreader("kocus")

xNacus.Text = dreader("nacus")

xalcus.Text = dreader("alcus")

xtelcus.Text = dreader("telcus")

xemcus.Text = dreader("emcus")

End Sub

11. Pada combo General Pilih btnAdd dan pada Declarations pilih Click, kemudian ketik kode program

berikut:

aktifitas(2)

Page 17: Modul praktikum vb

12. Pada combo General Pilih btncancel dan pada Declarations pilih Click, kemudian ketik kode program

berikut:

bersihkanForm()

aktifitas(1)

13. Pada combo General Pilih btnsave dan pada Declarations pilih Click, kemudian ketik kode program

berikut:

If xKocus.Text = "" Or xNacus.Text = "" Or xalcus.Text = "" Or

xtelcus.Text = "" Or xemcus.Text = "" Then

MsgBox("Isi data Dengan benar ")

Else

x = MsgBox("Save?", MsgBoxStyle.Information + MsgBoxStyle.YesNo, "Save")

If x = vbYes Then

simpandata(1)

bersihkanForm()

Else

bersihkanForm()

End If

End If

14. Tambahkan procedure sub simpandata, kemudian ketik kode program berikut

Sub simpandata(ByVal simpan As Byte)

Dim pesan As String = Nothing

Select Case simpan

Case 1 'Menyimpan Data

sql = "insert into customer values('" & xKocus.Text & "','" & _

xNacus.Text & "','" & _

xalcus.Text & "','" & _

xtelcus.Text & "','" & _

xemcus.Text & "')"

pesan = "Data Sudah disimpan"

Case 2 'Update Data

sql = "update customer set nacus='" & xNacus.Text & _

"', alcus='" & xalcus.Text & _

"', telcus='" & xtelcus.Text & _

"', emcus='" & xemcus.Text & _

"' where kocus='" & xKocus.Text & "'"

pesan = "Data Sudah si Edit"

Case 3 'Delete Data

sql = "delete from customer where kocus='" & xKocus.Text & "'"

pesan = "Data sudah di hapus "

End Select

Try

cmd = New MySqlCommand(sql, db)

cmd.ExecuteNonQuery()

isitabel()

MsgBox(pesan)

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

End Sub

15. Pada combo General Pilih btnEdit dan pada Declarations pilih Click, kemudian ketik kode program

berikut:

x = MsgBox("Update?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "Edit")

If x = vbYes Then

Page 18: Modul praktikum vb

simpandata(2)

bersihkanForm()

Else

bersihkanForm()

End If

16. Pada combo General Pilih btnDelete dan pada Declarations pilih Click, kemudian ketik kode program

berikut:

x = MsgBox("Delete?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "Delete")

If x = vbYes Then

simpandata(3)

bersihkanForm()

Else

bersihkanForm()

End If

17. Pada combo General Pilih xkocus dan pada Declarations pilih keydown, kemudian ketik kode program

berikut:

If e.KeyCode = Keys.Return Then

If xKocus.Text = "" Then

MsgBox("maaf.... data belum lengkap !!!")

Else

sql = "select *from customer where kocus='" & xKocus.Text & "'"

cmd = New MySqlCommand(sql, db)

dreader = cmd.ExecuteReader

Try

tampildata()

aktifitas(3)

MsgBox("Data Sudah Ada ")

xKocus.Enabled = False

Catch ex As Exception

z = xKocus.Text

bersihkanForm()

xKocus.Text = z

aktifitas(2)

End Try

End If

dreader.Close()

xNacus.Focus()

End If

18. Pada combo General Pilih LVCustomer dan pada Declarations pilih click, kemudian ketik kode program

berikut:

xKocus.Text = LVCustomer.SelectedItems(0).SubItems(1).Text

sql = "select *from Customer where kocus='" & xKocus.Text & "'"

cmd = New MySqlCommand(sql, db)

dreader = cmd.ExecuteReader

Try

MsgBox("Data Siap Untuk di Ubah")

tampildata()

xKocus.Enabled = False

aktifitas(3)

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

dreader.Close()

Page 19: Modul praktikum vb

19. Pada combo General Pilih btnClose dan pada Declarations pilih click, kemudian ketik kode program

berikut:

Me.Close()

20. Pada combo General Pilih xemcus dan pada Declarations pilih Keypress, kemudian ketik kode program

berikut:

If e.KeyChar = ChrW(13) Then

btnSave.Focus()

End If

21. Pada combo General Pilih xnacus dan pada Declarations pilih Keypress, kemudian ketik kode program

berikut:

If e.KeyChar = ChrW(13) Then

xalcus.Focus()

End If

22. Pada combo General Pilih xtelcus dan pada Declarations pilih Keypress, kemudian ketik kode program

berikut:

If e.KeyChar = ChrW(13) Then

xemcus.Focus()

End If

23. Pada combo General Pilih xalcus dan pada Declarations pilih Keypress, kemudian ketik kode program

berikut:

If e.KeyChar = ChrW(13) Then

xtelcus.Focus()

End If

Page 20: Modul praktikum vb

FORM PENGELOLAAN DATA ADMIN

1. Desainlah Iterface sebagai berikut

3. Setting property sebagai berikut

Objeck Property Value

Form1 Name frmAdmin.vb

Text Form Pengelolaan Data Admin

GroupBox1 Text Input Detail Data Admin

GroupBox2 Text Proses

GroupBox3 Text Tampil Data Admin

Label1 Text Id Admin

Label2 Text Nama Admin

Label3 Text User ID

Label4 Text Password

TextBox1 Name xID

Maxlength 5

TextBox2 Name xNaid

TextBox3 Name XUserID

TextBox4 Name XPassword

PasswordChar *

ListView1 Name LVAdmin

Button1 Name btnAdd

Text &Add

Button2 Name btnSave

Text &Save

Button3 Name btnEdit

Text &Edit

Button4 Name btnDelete

Text &Delete

Button5 Name btnCancel

Text &Cancel

Page 21: Modul praktikum vb

Button6 Name btnClose

Text Cl&ose

4. Pada frmdataadmin Buka Jendele view Code tambahkan kode program berikut

Imports MySql.Data.MySqlClient

Public Class frmBarang

Dim x As Byte

Dim z As String

End Class

5. Buka Jendela View Code frmDataadmin> pada combo General Pilih frmDataAdmin(events) dan pada

Declarations pilih Load, kemudian ketik kode program sebagai berikut:

opendb()

buattabel()

isitabel()

bersihkanForm()

6. Tambahkan procedure sub buattabel, kemdian ketik kode program berikut

Sub buattabel()

LVAdmin.Columns.Add("No", 30, HorizontalAlignment.Left)

LVAdmin.Columns.Add("Id Admin", 70, HorizontalAlignment.Left)

LVAdmin.Columns.Add("Nama Admin", 120, HorizontalAlignment.Left)

LVAdmin.Columns.Add("User ID", 80, HorizontalAlignment.Left)

LVAdmin.Columns.Add("Password", 100, HorizontalAlignment.Right)

LVAdmin.GridLines = True

LVAdmin.FullRowSelect = True

LVAdmin.View = View.Details

End Sub 7. Tambahkan procedure sub isitabel, kemdian ketik kode program berikut

Sub isitabel()

LVSupplier.Items.Clear()

sql = "select * from admin order by idadmin asc"

cmd = New MySqlCommand(sql, db)

dreader = cmd.ExecuteReader

Try

Dim no As Integer = 0

While dreader.Read

no = no + 1

Dim simpan As New ListViewItem

With simpan

.Text = no

. SubItems.Add(dreader("idadmin"))

.SubItems.Add(dreader("naad"))

.SubItems.Add(dreader("userid"))

.SubItems.Add(dreader("password"))

LVSupplier.Items.Add(simpan)

End With

End While

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

dreader.Close()

End Sub

8. Tambahkan procedure sub bersihkanform, kemdian ketik kode program berikut

Page 22: Modul praktikum vb

Sub bersihkanForm()

xIdAdmin.Text = ""

xNaAd.Text = ""

xUserID.Text = ""

xPassword.Text = ""

aktifitas(1)

xIdAdmin.Enabled = True

End Sub

9. Tambahkan procedure sub rubahtombol, kemdian ketik kode program berikut

Sub rubahtombol(ByVal a1 As Boolean, ByVal a2 As Boolean, ByVal a3 As Boolean,

ByVal a4 As Boolean, ByVal a5 As Boolean, ByVal a6 As Boolean, ByVal a7 As

Boolean)

btnAdd.Enabled = a1

btnSave.Enabled = a2

btnEdit.Enabled = a3

btnCancel.Enabled = a4

btnDelete.Enabled = a5

btnClose.Enabled = a6

GroupBox1.Enabled = a7

End Sub

10. Tambahkan procedure sub aktifitas, kemdian ketik kode program berikut

Sub aktifitas(ByVal tombol As Byte)

Select Case tombol

Case 1 'awal

rubahtombol(True, False, False, False, False, True, False)

Case 2 ' Add

rubahtombol(False, True, False, True, False, False, True)

xKosup.Focus()

Case 3 ' editc

rubahtombol(False, False, True, True, True, False, True)

End Select

End Sub

11. Tambahkan procedure sub tampildata, kemdian ketik kode program berikut

Sub tampildata()

dreader.Read()

xIdAdmin.Text = dreader("idadmin")

xNaAd.Text = dreader("naad")

xUserID.Text = dreader("userid")

xPassword.Text = dreader("password")

End Sub

12. Pada combo General Pilih btnAdd dan pada Declarations pilih Click, kemudian ketik kode program

berikut:

aktifitas(2)

13. Pada combo General Pilih btncancel dan pada Declarations pilih Click, kemudian ketik kode program

berikut:

bersihkanForm()

aktifitas(1)

Page 23: Modul praktikum vb

14. Pada combo General Pilih btnsave dan pada Declarations pilih Click, kemudian ketik kode program

berikut:

If xIdAdmin.Text = "" Or xNaAd.Text = "" Or xUserID.Text = "" Or xPassword.Text

= "" Then

MsgBox("Isi data Dengan benar ")

Else

x = MsgBox("Save?", MsgBoxStyle.Information + MsgBoxStyle.YesNo, "Save")

If x = vbYes Then

simpandata(1)

bersihkanForm()

Else

bersihkanForm()

End If

End If

15. Tambahkan procedure sub simpandata, kemudian ketik kode program berikut

Sub simpandata(ByVal simpan As Byte)

Dim pesan As String = Nothing

Select Case simpan

Case 1 'Menyimpan Data

sql = "insert into admin values('" & xIdAdmin.Text & "','" & _

xNaAd.Text & "','" & _

xUserID.Text & "','" & _

xPassword.Text & "')"

pesan = "Data Sudah disimpan"

Case 2 'Update Data

sql = "update admin set naad='" & xNaAd.Text & _

"', userid='" & xUserID.Text & _

"', password='" & xPassword.Text & _

"' where idadmin='" & xIdAdmin.Text & "'"

pesan = "Data Sudah si Edit"

Case 3 'Delete Data

sql = "delete from admin where idadmin='" & xIdAdmin.Text & "'"

pesan = "Data sudah di hapus "

End Select

Try

cmd = New MySqlCommand(sql, db)

cmd.ExecuteNonQuery()

isitabel()

MsgBox(pesan)

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

End Sub

16. Pada combo General Pilih btnEdit dan pada Declarations pilih Click, kemudian ketik kode program

berikut:

x = MsgBox("Update?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "Edit")

If x = vbYes Then

simpandata(2)

bersihkanForm()

Else

bersihkanForm()

End If

17. Pada combo General Pilih btnDelete dan pada Declarations pilih Click, kemudian ketik kode program

berikut:

x = MsgBox("Delete?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "Delete")

Page 24: Modul praktikum vb

If x = vbYes Then

simpandata(3)

bersihkanForm()

Else

bersihkanForm()

End If

18. Pada combo General Pilih xidadmin dan pada Declarations pilih keydown, kemudian ketik kode program

berikut:

If e.KeyCode = Keys.Return Then

If xIdAdmin.Text = "" Then

MsgBox("maaf.... data belum lengkap !!!")

Else

sql = "select *from admin where idadmin='" & xIdAdmin.Text & "'"

cmd = New MySqlCommand(sql, db)

dreader = cmd.ExecuteReader

Try

tampildata()

aktifitas(3)

MsgBox("Data Sudah Ada ")

xIdAdmin.Enabled = False

Catch ex As Exception

z = xIdAdmin.Text

bersihkanForm()

xIdAdmin.Text = z

aktifitas(2)

End Try

End If

dreader.Close()

xNaAd.Focus()

End If

19. Pada combo General Pilih LVAdmin dan pada Declarations pilih click, kemudian ketik kode program

berikut:

xIdAdmin.Text = LVAdmin.SelectedItems(0).SubItems(1).Text

sql = "select *from admin where idadmin='" & xIdAdmin.Text & "'"

cmd = New MySqlCommand(sql, db)

dreader = cmd.ExecuteReader

Try

MsgBox("Data Siap Untuk di Ubah")

tampildata()

xIdAdmin.Enabled = False

aktifitas(3)

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

dreader.Close()

20. Pada combo General Pilih btnClose dan pada Declarations pilih click, kemudian ketik kode program

berikut:

Me.Close()

21. Pada combo General Pilih xpassword dan pada Declarations pilih Keypress, kemudian ketik kode

program berikut:

If e.KeyChar = ChrW(13) Then

btnSave.Focus()

Page 25: Modul praktikum vb

End If

22. Pada combo General Pilih xnaad dan pada Declarations pilih Keypress, kemudian ketik kode program

berikut:

If e.KeyChar = ChrW(13) Then

xuserid.Focus()

End If

23. Pada combo General Pilih xuserid dan pada Declarations pilih Keypress, kemudian ketik kode program

berikut:

If e.KeyChar = ChrW(13) Then

xpassword.Focus()

End If

Page 26: Modul praktikum vb

FORM PEMESANAN BARANG

1. Rancanglah Interface sebagai berikut

2. Setting Property dari form Interface di atas sebagai berikut

Objeck Property Value

Form1 Name frmPemesanan.vb

Text Form Pemesanan Barang

GroupBox1 Text -

Label1 Text Tanggal Transaksi

Label2 Text No Faktur

TextBox1 Name xNofak

DateTimePicker1 Name DTPTglTransaksi

Format Custom

CustomFormat yyyy-MM-dd

GroupBox2 Text Input Supplier

Label3 Text Kode

Label4 Text Nama

Label5 Text Alamat

Label6 Text Telepon

ComboBox1 Name cmbKosup

Text -Pilih-

TextBox2 Name xNasup

TextBox3 Name xAlsup

TextBox4 Name xTelsup

GroupBox3 Text Input Barang

Label7 Text Kode

Label8 Text Nama

Label9 Text Harga

Page 27: Modul praktikum vb

Label10 Text Jumlah

ComboBox2 Name cmbKobar

Text -Pilih-

TextBox5 Name xNabar

TextBox6 Name xHarbar

TextBox7 Name xJumlah

GroupBox4 Text List Pemesanan

ListView1 Name LVPemesanan

Label11 Text Total

Font Bold True

TextBox8 Name xTotal

TextAlign Right

FontBold True

Button1 Name btnNew

Text &New

Button2 Name btnSave

Text &Save

Button3 Name btnDelete

Text &Delete

Button4 Name btnCancel

Text &Cancel

Button5 Name btnClose

Text Cl&ose

Button6 Name btnCariNofak

Text Cari No &Faktur

3. Buatlah Tabel Pemesanan sebagai Berikut

TABEL PEMESANAN

Field Name Type Data Keterangan

NoFak Varchar(20) No. Faktur

tglPesan Date Tanggl Pesan

Kosup Varchar(5) Kode Supplier

Kobar Varchar(5) Kode Barang

Jumlah Double Jumlah Barang dipesan

4. Buka Jendelea View Code pada frmPemesanan kemudian ketik program sebagai berikut

Imports MySql.Data.MySqlClient

Public Class FrmPemesanan

Dim Hasil As Double

End Class

5. pada combo General Pilih frmPesanan(events) dan pada Declarations pilih Load, kemudian ketik kode

program sebagai berikut:

opendb()

buattabel()

tampilkodesupplier()

tampilkodebarang()

bersih()

Page 28: Modul praktikum vb

6. Tambahkan Procedure BuatTabel

Sub buattabel()

With LVPemesanan

.Columns.Add("Kode Barang", 80, HorizontalAlignment.Left)

.Columns.Add("Nama Barang", 120, HorizontalAlignment.Left)

.Columns.Add("Harga Barang", 80, HorizontalAlignment.Right)

.Columns.Add("Jumlah Beli", 80, HorizontalAlignment.Right)

.Columns.Add("Total Harga", 120, HorizontalAlignment.Center)

.GridLines = True

.FullRowSelect = True

.View = View.Details

End With

End Sub

7. Tambahkan procedure TampilKodeSupplier

Sub tampilkodesupplier()

sql = "select * from supplier order by kosup asc"

cmd = New MySqlCommand(sql, db)

dreader = cmd.ExecuteReader

Try

While dreader.Read()

cmbKoSup.Items.Add(dreader("kosup"))

End While

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

dreader.Close()

End Sub

9. Tambahkan Procedure TampilKodeBarang

Sub tampilkodebarang()

sql = "select *from barang order by kobar asc"

cmd = New MySqlCommand(sql, db)

dreader = cmd.ExecuteReader

Try

While dreader.Read

cmbKobar.Items.Add(dreader("kobar"))

End While

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

dreader.Close()

End Sub

10. Tambahkan Procedure Bersih

Sub bersih()

cmbKoSup.Text = "--Pilih--"

xNasup.Text = ""

xAlsup.Text = ""

xTelsup.Text = ""

cmbKobar.Text = "--Pilih--"

xNabar.Text = ""

xHarbar.Text = ""

xJumlah.Text = ""

LVPemesanan.Items.Clear()

aktifitas(1)

tampilnofaktur()

Page 29: Modul praktikum vb

End Sub

11. Tambahkan Procedure RubahTombol

Sub rubahtombol(ByVal a1 As Boolean, ByVal a2 As Boolean, ByVal a3 As Boolean,

ByVal a4 As Boolean, ByVal a5 As Boolean, ByVal gk As Boolean, ByVal gb As

Boolean)

btnNew.Enabled = a1

btnSave.Enabled = a2

btnDelete.Enabled = a3

btnCancel.Enabled = a4

btnClose.Enabled = a5

GroupBox2.Enabled = gk

GroupBox3.Enabled = gb

End Sub

12. Tambahkan Procedure Aktifitas

Sub aktifitas(ByVal tombol As Byte)

Select Case tombol

Case 1 'baru

rubahtombol(True, False, False, False, True, False, False)

xNofak.Enabled = False

Case 2 'Save

rubahtombol(False, False, True, False, False, True, True)

Case 3 'hapus

rubahtombol(False, False, True, True, False, False, False)

Case 4

rubahtombol(False, True, True, False, False, True, True)

End Select

End Sub

13. Tambahkan Procedure TampilNoFaktur

Sub tampilnofaktur()

sql = "select *from pemesanan order by nofak desc"

cmd = New MySqlCommand(sql, db)

dreader = cmd.ExecuteReader

Try

If dreader.Read = 0 Then

xNofak.Text = "1000"

Else

xNofak.Text = dreader("nofak") + 1

End If

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

dreader.Close()

End Sub

14. Tambahkan Procedure BersihBarang

Sub bersihbarang()

cmbKobar.Text = "--Pilih--"

xNabar.Text = ""

xHarbar.Text = ""

xJumlah.Text = ""

cmbKobar.Focus()

End Sub

15. Tambahkan Procedure TampilSupplier

Page 30: Modul praktikum vb

Sub tampilsuplier()

dreader.Read()

cmbKoSup.Text = dreader!kosup

xNasup.Text = dreader!nasup

xAlsup.Text = dreader!alsup

xTelsup.Text = dreader!telsup

End Sub

16. Tambahkan Procedure TampilBarang

Sub tampilbarang()

dreader.Read()

cmbKobar.Text = dreader!kobar

xNabar.Text = dreader!nabar

xHarbar.Text = dreader!harbar

End Sub

17. Tambahkan Fuction Cekisi

Function cekisi() As Boolean

cekisi = False

For i = 0 To LVPemesanan.Items.Count - 1

If cmbKobar.Text = LVPemesanan.Items(i).Text Then

cekisi = True

Exit Function

End If

Next

End Function

18. Tambahkan procedure IsiTabel

Sub isitabel()

Dim lst As New ListViewItem

With lst

.Text = cmbKobar.Text

.SubItems.Add(xNabar.Text)

.SubItems.Add(xHarbar.Text)

.SubItems.Add(xJumlah.Text)

.SubItems.Add(xHarbar.Text * xJumlah.Text)

LVPemesanan.Items.Add(lst)

End With

End Sub

19. Tambahkan Procedure CekTotal

Sub cektotal()

Dim total As Long = 0

For i = 0 To LVPemesanan.Items.Count - 1

total = total + Val(LVPemesanan.Items(i).SubItems(4).Text)

Next

xTotal.Text = Format(total, "###,###,###")

If xTotal.Text = "" Then

Exit Sub

Else

hasil = xTotal.Text

End If

End Sub

20. Pada Jendela View Code General Pilih btnSave dan pada Declarations Pilih Click dan lengkapi

kode program sbb

Page 31: Modul praktikum vb

Dim x As String

If cmbKoSup.Text = "" Or xNasup.Text = "" Or xAlsup.Text = "" Or

xTelsup.Text = "" Then

MsgBox("Isi Data Dengan Benar !!!")

Else

x = MsgBox("Simpan Data..!", MsgBoxStyle.Information +

MsgBoxStyle.YesNo, "Conform")

If x = vbYes Then

simpandata()

lagi()

cektotal()

End If

End If

21. Pada Jendela View Code General Pilih btnDelete dan pada Declarations Pilih Click dan lengkapi

kode program sbb

If MsgBox("apakah Anda Ingin Menghapus data Ini ??", MsgBoxStyle.Information +

MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then

sql = "delete from pemesanan where nofak='" & xNofak.Text & "'"

Try

cmd = New MySqlCommand(sql, db)

cmd.ExecuteNonQuery()

MsgBox("Data Sudah Di Hapus")

bersih()

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

Else

bersih()

End If

22. Pada Jendela View Code General Pilih btnCancel dan pada Declarations Pilih Click dan lengkapi

kode program sbb

aktifitas(1)

bersih()

cektotal()

23. Pada Jendela View Code General Pilih btnClose dan pada Declarations Pilih Click dan lengkapi

kode program sbb Me.Close()

24. Pada Jendela View Code General Pilih LVPemesanan dan pada Declaration Pilih Click dan

lengkapi kode program sbb

cmbKobar.Text = LVPemesanan.SelectedItems(0).SubItems(0).Text

xJumlah.Text = LVPemesanan.SelectedItems(0).SubItems(3).Text

25. Tambahkan Procedure Lagi

Sub lagi()

cmbKoSup.Text = "--Pilih--"

xNasup.Text = ""

xAlsup.Text = ""

cmbKobar.Text = "--Pilih--"

xNabar.Text = ""

xHarbar.Text = ""

xJumlah.Text = ""

LVPemesanan.Items.Clear()

tampilnofaktur()

Page 32: Modul praktikum vb

End Sub

26. Tambahkan Procedeure SimpanData

Sub simpandata()

Dim xkobar1, xjumlah1 As String

Dim xtanggal As Date

Dim x As String

xtanggal = Format(DTPTglTransaksi.Value, "yyyy-MM-dd")

For i As Integer = 0 To LVPemesanan.Items.Count - 1

xkobar1 = LVPemesanan.Items(i).SubItems(0).Text

xjumlah1 = LVPemesanan.Items(i).SubItems(3).Text

sql = "insert into pemesanan values('" & xNofak.Text & "','" & _

DTPTglTransaksi.Text & "','" & _

cmbKoSup.Text & "','" & _

xkobar1 & "','" & _

xjumlah1 & "')"

Try

cmd = New MySqlCommand(sql, db)

cmd.ExecuteNonQuery()

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

Next

x = MsgBox("Data Sudah Tersimpan!,Transaksi Lagi?", MsgBoxStyle.Information

+ MsgBoxStyle.YesNo, "Confirm")

If x = vbYes Then

aktifitas(4)

End If

End Sub

27. Pada Jendela View Code General Pilih cmbkobar dan pada Declaration Pilih

SelectedIndexChaged dan lengkapi kode program sbb

sql = "select *from barang where kobar='" & cmbKobar.Text & "'"

cmd = New MySqlCommand(sql, db)

dreader = cmd.ExecuteReader

Try

tampilbarang()

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

dreader.Close()

xJumlah.Focus()

28. Pada Jendela View Code General Pilih cmbkosup dan pada Declaration Pilih

SelectedIndexChaged dan lengkapi kode program sbb

sql = "select *from supplier where kosup='" & cmbKoSup.Text & "'"

cmd = New MySqlCommand(sql, db)

dreader = cmd.ExecuteReader

Try

tampilsuplier()

Catch ex As Exception

End Try

dreader.Close()

29. Pada Jendela View Code General Pilih xjumlah dan pada Declaration Pilih Keydown dan lengkapi

kode program sbb

If e.KeyCode = Keys.Return Then

If xJumlah.Text = "" Then

Page 33: Modul praktikum vb

MsgBox("Jumlah Beli Tidak Boleh Kosong!!!")

Exit Sub

Else

If Not cekisi() Then

isitabel()

cektotal()

bersihbarang()

aktifitas(4)

Else

MsgBox("Data Sudah Ada")

bersihbarang()

End If

End If

End If

30. Pada Jendela View Code General Pilih xjumlah dan pada Declaration Pilih TextCahanged dan

lengkapi kode program sbb

If Not IsNumeric(xJumlah.Text) Then

xJumlah.Text = ""

End If

31. Pada Jendela View Code General Pilih btnNew dan pada Declarations Pilih Click dan lengkapi

kode program sbb aktifitas(2)

32. Pada Jendela View Code General Pilih btnCariNofak dan pada Declarations Pilih Click dan

lengkapi kode program sbb

Dim cari As String

cari = InputBox("Masukkan No Faktur", "Find No faktur")

sql = "SELECT p.nofak,p.tglpesan,p.kosup,p.kobar,p.jumlah," & _

"a.kosup,a.nasup,a.alsup,a.telsup, " & _

"b.kobar,b.nabar,b.satuan,b.harbar " & _

"FROM barang as b, supplier as a, pemesanan as p " & _

"WHERE p.kosup = a.kosup AND p.kobar = b.kobar " & _

"And p.nofak='" & cari & "'"

cmd = New MySqlCommand(sql, db)

dreader = cmd.ExecuteReader

LVPemesanan.Items.Clear()

While dreader.Read()

Try

Dim lst As New ListViewItem

With lst

.Text = dreader("kobar")

.SubItems.Add(dreader("nabar"))

.SubItems.Add(dreader("harbar"))

.SubItems.Add(dreader("jumlah"))

.SubItems.Add(dreader("jumlah") * dreader("harbar"))

LVPemesanan.Items.Add(lst)

DTPTglTransaksi.Text = dreader("tglpesan")

xNofak.Text = dreader("nofak")

cmbKoSup.Text = dreader!kosup

xNasup.Text = dreader!nasup

xAlsup.Text = dreader!alsup

xTelsup.Text = dreader!telsup

aktifitas(3)

End With

Catch ex As Exception

End Try

Page 34: Modul praktikum vb

End While

cektotal()

dreader.Close()

FORM PENJUALAN

FORM MENU UTAMA

1. Tambahkan form pada Project>kemudian seting propertynya sebagai berikut

Objeck Property Value

Form1 Name frmMenuUtama.vb

Text Menu Utama System Informasi Penjualan

Windowstate Maximized

IsMdiContainer True 2. Tambahkan MenuStrip dari Jendela Toolbox, kemudian setting Menu Sebagai Berikut

No Level 0 Level1

Property Value Property Value

1 Text &File

Name mnuFile

2

Text &Barang

Name mnuBarang

Shortcut Key Ctrl +B

3

Text &Supplier

Name mnuSupplier

Shortcut Key Ctrl + S

4

Text &Customer

Name mnuCustomer

Shortcut Key Ctrl +C

5 Text -

6

Text &Admin

Name mnuAdmin

Shortcut Key Ctrl +A

7

Text E&xit

Name mnuExit

Shortcut Key Ctrl + X

8 Text &Transaksi

Name mnuTransaksi

9

Text &Pemesanan

Name frmPemesanan

Shortcut Key Ctrl + P

10

Text Pen&jualan

Name mnuPenjualan

Shortcut Key Ctrl + J

11 Text &Laporan

Name mnuLaporan

12

Text Data Barang

Name mnuLapBarang

Shortcut Key Ctrl + F1

13

Text Data Supplier

Name mnuLapSupplier

Shortcut Key Ctrl + F2

14 Text Data Customer

Page 35: Modul praktikum vb

Name mnuLapCustomer

Shortcut Key Ctrl + F3

15 Text -

16

Text Data Pemesanan

Name mnuLapPemesanan

Shortcut Key Ctrl + F4

17

Text Data Penjualan

Name mnuLapPenjualan

Shortcut Key Ctrl + F4

3. Buka Jendela View Code frmMenuUtama, kemudian pada combo General Pilih mnuExit pada

declarations pilih click, kemudia ketik program sbb

Dim pesan As String

pesan = MsgBox("Keluar dari system..?", MsgBoxStyle.Information +

MsgBoxStyle.YesNo, "Exit")

If pesan = vbYes Then

End

Else

Exit Sub

End If

4. Pada combo General Pilih mnubarang pada declarations pilih click, kemudia ketik program sbb frmBarang.MdiParent = Me frmBarang.Show()

5. Pilih mnusupplier pada declarations pilih click, kemudia ketik program sbb frmSupplier.MdiParent = Me FrmSupplier.Show()

6. Pilih mnucustomer pada declarations pilih click, kemudia ketik program sbb frmCustomer.MdiParent = Me FrmCustomer.Show()

7. Pilih mnuAdmin pada declarations pilih click, kemudia ketik program sbb

FrmDataAdmin.MdiParent = Me

FrmDataAdmin.Show()

8. Pilih mnuPemesanan pada declarations pilih click, kemudia ketik program sbb frmPemesanan.MdiParent = Me frmPemesanan.show()

9. Pilih mnuPenjualan pada declarations pilih click, kemudia ketik program sbb frmPenjualan.MdiParent = Me frmpenjualan.show()

10. Pilih mnuLapBarang pada declarations pilih click, kemudia ketik program sbb frmLapBarang.MdiParent = Me frmlapBarang.show()

11. Pilih mnuLapSupplier pada declarations pilih click, kemudia ketik program sbb

Page 36: Modul praktikum vb

frmLapSupplier.MdiParent = Me frmlapsupplier.show()

12. Pilih mnuLapCustomer pada declarations pilih click, kemudia ketik program sbb frmLapCustomer.MdiParent = Me FrmLapCustomer.Show()

13. Pilih mnuLapPemesanan pada declarations pilih click, kemudia ketik program sbb frmLapPemesanan.MdiParent = Me frmLapPemesanan.show()

14. Pilih mnuLapPenjualan pada declarations pilih click, kemudia ketik program sbb frmLapPenjualan.MdiParent = Me frmLapPenjualan.show()

FORM LOGIN

1. Tambahkan form dengan menglick menu project>add windows form>padacategories pilih windows

form>pada template pilih Login Form>click tombol Add sehingga muncul form sebagai berikut

2. Setting Popertynys sebagai berikut

Objeck Property Value

LoginForm1 Text Login System

3. Buka jendela view code Form Login kemudian ketik program sbb

Imports MySql.Data.MySqlClient

Public Class LoginForm1

End Class

4. Pada combo General Pilih LoginForm1 kemudian pada combo Decrlarations Pilih Load ,kemudian ketik

program sebagai berikut

opendb()

5. Pada combo General Pilih cancel kemudian pada combo Decrlarations Pilih Click ,kemudian ketik

program sebagai berikut

Page 37: Modul praktikum vb

Me.Close()

6. Buat Procedure CheckAdmin

Sub checkAdmin()

If UsernameTextBox.Text = "" Or PasswordTextBox.Text = "" Then

MsgBox("Isi data Dengan Benar")

Exit Sub

End If

sql = "select *from admin where userid='" & UsernameTextBox.Text & "'"

cmd = New MySqlCommand(sql, db)

dreader = cmd.ExecuteReader

Try

While dreader.Read

If dreader("userid") = UsernameTextBox.Text And dreader("password") =

PasswordTextBox.Text Then

FrmMenuUtama.Show()

Me.Hide()

Else

Dim pesan As String = "Salah"

MsgBox(pesan, , "Informasi") : dreader.Close()

UsernameTextBox.Text = ""

PasswordTextBox.Text = ""

UsernameTextBox.Focus()

End If

End While

Catch ex As Exception

End Try

dreader.Close()

End If

End Sub

7. Pada combo General Pilih OK kemudian pada combo Decrlarations Pilih Click kemudian ketik program

sebagai berikut

checkAdmin()

8. Pada combo General Pilih PasswordTextBox kemudian pada combo Decrlarations Pilih Keydown

kemudian ketik program sebagai berikut

If e.KeyCode = Keys.Return Then

checkAdmin()

End If

Page 38: Modul praktikum vb

MEMBUAT LAPORAN DATA BARANG

1. Instal MyODBC Driver terlebih dahulu>

2. Click Start>Click Control Panel>click ODBC

3. Pada jendele ODBC Data Source Administrator click tombol Add>kemudian cari dan click MYSQL

ODBC….Driver>kemudian click Finish

4. Muncul jendela Mysql Conector/ODBC Data Source Configuration

5. Ketik Nama Koneksi pada Data Source Name, sebagai Contoh KoneksiPenjualan

Pada server ketik nama server localhost

Pada user ketik nama user root

Pada Password ketik nama password(jika ada)

Pada Database Pilih database yang di inginkan

6. Untuk menguji koneksi click tombol Test, kemudian jika konek click tombol OK

7. Untuk Mengakhiri click tombol OK

8. Pada Projek click Menu Project>pada categories pilih Reporting>Pada Templates pilih Crystal

Report>pada name ketik nama laporan, sebagai contoh LapDataBarang.rpt kemudian click Tombol

Add

9. Pada jendela Crystal Reports Gallery Click OK

10. Pada Jendela Standart Report Creation Wizzard>Click Create New Connection>click ODBC(R DO)

11. Pada Jendela ODBC(RDO) pilih data source name >kemudian click Next >kemudia ketik userID dan

Password jika ada> kemudian pilih table database laporan yang diiginkan>kemudian click tombol

>(add) kemudian click tombol Finish

12. Pada jendela Filed explorer click and drag field –field laporan yang akan di desain pada jendela

LapDataBarang Desain(desain sesuai format yang anda inginkan)

13. Tambahkan form baru pada project kemudian, pada toolbox double click icon crystalreportviewer ,

sehinggan racangan interface sebagai berikut

Page 39: Modul praktikum vb

14. Setting propertynya sebagai berikut

Objeck Property Value

Form1 Name frmLapBarang

Text Laporan Data Barang

Windowstate Maximized

CrystalReportViewer1 Name CRVBarang

15. Buka Jendele ViewCode frmLaporanBarang, kemudian pada combo general pilih frmLapBarang Events

dan pada combo declarations pilih Load, kemudian ketik kode program sebagai berikut

Dim laporan As New LaporanBarang

With CRVBarang

.DisplayGroupTree = False

.ReportSource = laporan

.RefreshReport()

End With

16. Ulangi Langkah yang sama untuk membuat laporan Data Supplier, data Customer, data pemesanan

barang dan data penjualan barang

Catatan:

Di dalam mendesain, laporan dibutukan kreatifitas anda untuk mendesain laporan sesuai dengan yang

dinginkan oleh user, untuk itu dibutuhkan responsive anda dalam mengolah laporan sesuai dengan

fasilitas yang disediakan pada jendela lembaran kerja membuat laporan