Anda di halaman 1dari 10

Nama : Wahyu Hanifudin

NPM : 19402135

Kelas : SI EL-41/19

UAS Pemrograman Visual II

Membuat Program Toko Sepatuku menggunakan Visual Studio 2010 dan SQL Server
Management Studio 2008

1. Buka Software SQL Server Management Studio 2008


2. Buat Database dengan nama Penjualan_Barang

3. Buat 2 Tabel, Tabel Barang dan Tabel Transaksi


4. Buatlah tampilan form dengan menggunakan Visual Studio 2010, seperti di bawah ini :

5. Atur Propertinya, sebagai berikut :

No. Object Properti Nilai Properti


1. Form1 Name Form1

2. Label1-Label8 Text Sesuai yang ada ditampilan form

3. Textbox1 Name Kode_Barang


Textbox2 Name Nama_Barang
Textbox3 Name Cari
Textbox4 Name No_Jual
Textbox5 Name Total_Jual
4. Button1-Button9 Text Sesuai yang ada ditampilan form
Button1 Name btCari
Button2 Name btNew
Button3 Name btCancel
Button4 Name btClose
Button5 Name btSave
Button6 Name btUbah
Button7 Name Bthapus
Button8 Name btProses
Button9 Name btDelete
5. GroupBox1 Text Master Barang
GroupBox2 Text Transaksi
6. DataGridView1 Name dgvbarang
DataGridView2 Name dgvtransaksi
7. DateTimePicker Name Tanggal_Jual
8. ComboBox1 Name Jenis_Barang
ComboBox2 Name Ukuran_Barang

6. Tambahkan Kode Program Seperti Tampilan Berikut ini :

Imports System.Data
Imports System.Data.SqlClient

Public Class Form1


Public koneksi As String
Public sql1, sql2, sql3, sql4 As String
Public conn As SqlClient.SqlConnection = Nothing
Public cmd As SqlClient.SqlCommand = Nothing
Public dtadapter As SqlClient.SqlDataAdapter = Nothing
Public dtreader As SqlClient.SqlDataReader = Nothing
Public dttable As New DataTable

Private Sub Form1_Leave(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Leave


cmd.Dispose()
conn.Close()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


MyBase.Load
koneksi = "Data Source= WAHYU\SQLEXPRESS;Initial Catalog=Penjualan_Barang;Integrated
Security=True"
conn = New SqlClient.SqlConnection(koneksi)
conn.Open()
Call refresh_data1()
Call refresh_data2()
End Sub

Sub refresh_data1()
sql2 = "select * from Tb_Barang"
dtadapter = New SqlDataAdapter(sql2, conn)
dttable = New DataTable
'CST.Clear()
dtadapter.Fill(dttable)
dgvbarang.DataSource = dttable
End Sub
Sub refresh_data2()
sql2 = "select * from Tb_Transaksi"
dtadapter = New SqlDataAdapter(sql2, conn)
Dim CST As New DataTable
CST.Clear()
dtadapter.Fill(CST)
dgvtransaksi.DataSource = CST
End Sub
Sub kosong()
Me.Kode_Barang.Text = ""
Me.Nama_Barang.Text = ""
Me.Ukuran_Barang.Text = ""
Me.Jenis_Barang.Text = ""
Me.No_Jual.Text = ""
Me.Total_Jual.Text = ""
Me.Cari.Text = ""
Me.Tanggal_Jual.Text = ""

End Sub
Private Sub btCari_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btCari.Click
Dim cari As String
cari = InputBox("Masukan Kode Barang", "Pencarian")
sql3 = "select * from Tb_Barang where Kode_Barang = '" & cari & "'"
dtadapter = New SqlDataAdapter(sql3, conn)
Dim CST As New DataTable
CST.Clear()
dtadapter.Fill(CST)
dgvbarang.DataSource = CST
End Sub

Private Sub btnew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles btnew.Click
kosong()
End Sub

Private Sub btcancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles btcancel.Click
Me.Kode_Barang.Focus()
Me.Nama_Barang.Text = ""
Me.Ukuran_Barang.Text = ""
Me.Jenis_Barang.Text = ""
Me.Cari.Text = ""
Me.No_Jual.Text = ""
Me.Total_Jual.Text = ""
Me.Tanggal_Jual.Text = ""
MsgBox("Data Sudah digagalkan", MsgBoxStyle.Information, "Perhatian")

End Sub

Private Sub btclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles btclose.Click
btclose.Text = MsgBox("Apakah anda ingin keluar dari Aplikasi ?", vbQuestion +
vbOKCancel, "Perhatian")
If btclose.Text = vbOK Then
End
End If

End Sub

Private Sub btsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles btsave.Click
sql1 = "Insert into Tb_Barang values('" & Me.Kode_Barang.Text & "','" &
Me.Nama_Barang.Text & "','" & Me.Ukuran_Barang.Text & "','" & Me.Jenis_Barang.Text & "')"
cmd = New SqlClient.SqlCommand(sql1)
cmd.Connection = conn
cmd.ExecuteNonQuery()
MsgBox("Data Sudah Disimpan", MsgBoxStyle.Information, "Perhatian")
refresh_data1()

End Sub

Private Sub btdelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles btdelete.Click
If MsgBox("Anda ingin hapus data", vbYesNo + vbQuestion, "Hapus") = vbYes Then
sql4 = "delete from Tb_Transaksi where No_Jual = '" & Me.No_Jual.Text & " ')"
cmd = New SqlClient.SqlCommand(sql4)
cmd.Connection = conn
cmd.ExecuteNonQuery()
Call refresh_data2()
End If
End Sub
Private Sub btproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btproses.Click
sql1 = "Insert into Tb_Transaksi values('" & Me.No_Jual.Text & "','" &
Me.Total_Jual.Text & "','" & Me.Tanggal_Jual.Text & " ')"
cmd = New SqlClient.SqlCommand(sql1)
cmd.Connection = conn
cmd.ExecuteNonQuery()
MsgBox("Data Tersimpan", MsgBoxStyle.Information, "Perhatian")
refresh_data2()
End Sub

Private Sub btubah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


btubah.Click
If MsgBox("Anda yakin ingin merubah data", vbYesNo + vbQuestion, "Hapus") = vbYes Then
sql4 = "update Tb_Barang set nama = '" & Nama_Barang.Text & "', ukuran = '" &
Ukuran_Barang.Text & "', jenis = '" & Jenis_Barang.Text & "' where Tb_Barang = '" &
Kode_Barang.Text & " ')"
cmd = New SqlClient.SqlCommand(sql4)
cmd.Connection = conn
cmd.ExecuteNonQuery()
Call refresh_data1()
End If

End Sub

Private Sub tbUkuran_Barang_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Ukuran_Barang.SelectedIndexChanged
Ukuran_Barang.Items.Add("40")
Ukuran_Barang.Items.Add("42")
Ukuran_Barang.Items.Add("43")

End Sub

Private Sub tbJenis_Barang_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Jenis_Barang.SelectedIndexChanged
Jenis_Barang.Items.Add("Adidas")
Jenis_Barang.Items.Add("Converse")
Jenis_Barang.Items.Add("Reebok")
End Sub

Private Sub bthapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles bthapus.Click
If MsgBox("Anda ingin hapus data", vbYesNo + vbQuestion, "Hapus") = vbYes Then
sql4 = "delete from Tb_Barang where Kode_Barang = '" & Me.Kode_Barang.Text & " ')"
cmd = New SqlClient.SqlCommand(sql4)
cmd.Connection = conn
cmd.ExecuteNonQuery()
Call refresh_data1()
End If
End Sub

End Class
7. Hasil
- Tampilan program saat dijalankan

- Tampilan Pencarian

- Tampilan Buat baru


- Tampilan Cancel

- Tampilan Close
- Tampilan Save

- Tampilan Ubah
- Tampilan Proses
- Tampilan Delete

8. Terimakasih

Anda mungkin juga menyukai