TUGAS KELOMPOK
Assalamualaikum , Hai kembali lagi di sini ,
Oke sekarang kita akan membahas cara membuat aplikasi pertokoan menggunakan vb.net sebagai bahasa pemrograman dan SQL Server sebagai databasenya.
Yuk langsung saja ..
Cara mengkoneksikan vb.net dan database SQL Server
Imports System.Data.SqlClient
Module koneksi
Public comSQL As New SqlClient.SqlCommand
Public Sql As String
Public conn As New SqlConnection
Public str As String = "Data Source = LENOVO
;initial catalog =201553072 ;trusted_connection = true"
Public Sub buka_koneksi()
If conn.State = ConnectionState.Closed Then
conn.ConnectionString = str
Try
conn.Open()
Catch ex As Exception
MsgBox("Koneksi gagal :"
& ex.ToString)
End Try
End If
End Sub
Public Sub tutup_koneksi()
If conn.State = ConnectionState.Open Then
Try
conn.Close()
Catch ex As Exception
MsgBox("gagal menutup koneksi :" & ex.ToString)
End Try
End If
End Sub
End Module
1. Menu
Form Menu
Public Class form_menu
Private Sub
KeluarToolStripMenuItem_Click_1(sender As Object, e As EventArgs) Handles KeluarToolStripMenuItem.Click
Close()
End Sub
Private Sub
DataBarangToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DataBarangToolStripMenuItem.Click
form_barang.MdiParent = Me
form_barang.Show()
form_supplier.Hide()
End Sub
Private Sub
DataSupplierToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
DataSupplierToolStripMenuItem.Click
form_supplier.MdiParent = Me
form_supplier.Show()
form_pembelian.Hide()
End Sub
Private Sub
DataPembelianToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
DataPembelianToolStripMenuItem.Click
form_pembelian.MdiParent = Me
form_pembelian.Show()
form_barang.Hide()
End Sub
End Class
2. Form Barang
Form Barang
- - Save
Private Sub btnsave_Click(sender As Object, e As EventArgs) Handles btnsave.Click
buka_koneksi()
Sql = "insert into barang values
('"
& kdbrg.Text & "', '" & nmbrg.Text & "', '" & jnsbrg.Text & "', '" & harga.Text & "', '" & jumlah.Text & "', '" & kadaluarsa.Text &
"')"
comSQL = New SqlCommand(Sql, conn)
Try
comSQL.ExecuteNonQuery()
MsgBox("Data Berhasil Disimpan")
Catch ex As Exception
MsgBox("Data Gagal Disimpan
!!!")
End Try
Call updatedata()
Call bersih()
tutup_koneksi()
End Sub
- - Edit
Private Sub btnedit_Click(sender As Object, e As EventArgs) Handles btnedit.Click
buka_koneksi()
Sql = "UPDATE barang SET
nmbrg='"
& nmbrg.Text & "', jnsbrg='" & jnsbrg.Text & "',
harga='"
& harga.Text & "', jumlah='" & jumlah.Text & "',
kadaluarsa='" & kadaluarsa.Text & "' WHERE kdbrg='" & kdbrg.Text & "'"
comSQL = New SqlCommand(Sql, conn)
Try
comSQL.ExecuteNonQuery()
MsgBox("Update berhasil")
kdbrg.Enabled = True
btnsave.Enabled = True
Catch ex As Exception
MsgBox("Update gagal !!")
End Try
Call updatedata()
Call bersih()
tutup_koneksi()
End Sub
- - Delete
Private Sub btndelete_Click(sender As Object, e As EventArgs) Handles btndelete.Click
Dim pesan As String
pesan = MsgBox("Apakah Anda Ingin Menghapus
Data ini ?", vbYesNo, "Konfirmasi")
If pesan = 6 Then
hapusbarang()
kdbrg.Enabled = True
btnsave.Enabled = True
End If
End Sub
- - Laporan
Private Sub
btnlap_Click(sender As Object, e As EventArgs) Handles
btnlap.Click
laporanbrg.Show()
End Sub
- - Close
Private Sub btnclose_Click(sender As Object, e As EventArgs) Handles btnclose.Click
Close()
End Sub
3. Form Supplier
Form Supplier
- - Edit
Imports System.Data.SqlClient
Public Class form_supplier
Sub updatedata()
buka_koneksi()
Sql = "select *from supplier"
Dim da As New SqlDataAdapter(Sql, conn)
Dim ds As New DataSet
da.Fill(ds)
Dim dt As New DataTable
For Each dt In ds.Tables
dgvsupplier.DataSource = dt
Next
tutup_koneksi()
End Sub
- - Simpan
Private Sub btnsave_Click(sender As Object, e As EventArgs) Handles btnsave.Click
buka_koneksi()
Sql = "insert into supplier values
('"
& kdsup.Text & "', '" & nmsup.Text & "', '" & tgllhr.Text & "', '" & alamat.Text & "', '" & tlpkntr.Text & "', '" & cbjekel.Text & "', '" & email.Text & "', '" & txtjnsproduk.Text
& "')"
comSQL = New SqlCommand(Sql, conn)
Try
comSQL.ExecuteNonQuery()
MsgBox("Data Berhasil Disimpan")
Catch ex As Exception
MsgBox("Data Gagal Disimpan
!!!")
End Try
Call updatedata()
Call bersih()
tutup_koneksi()
End Sub
- - Hapus
Private Sub btndelete_Click(sender As Object, e As EventArgs) Handlesbtndelete.Click
Dim pesan As String
pesan = MsgBox("Apakah Anda Ingin Menghapus
Data ini ?", vbYesNo, "Konfirmasi")
If pesan = 6 Then
hapussupplier()
kdsup.Enabled = True
btnsave.Enabled = True
End If
End Sub
- - Laporan
Private Sub btnlaporan_Click(sender As Object, e As EventArgs) Handles btnlaporan.Click
lapsupplier.Show()
End Sub
- - Close
Private Sub btnclose_Click(sender As Object, e As EventArgs) Handles btnclose.Click
Close()
End Sub
4. Form Pembelian
- - Save
Private Sub btnsave_Click(sender As Object, e As EventArgs) Handles btnsave.Click
buka_koneksi()
Sql = "insert into pembelian values
('"
& nonota.Text & "', '" & kodebrg.Text & "', '" & kodesup.Text & "', '" & tglbeli.Text & "', '" & jumlahbeli.Text &
"', '" & hargabeli.Text & "', '" & total.Text & "')"
comSQL = New SqlCommand(Sql, conn)
Try
comSQL.ExecuteNonQuery()
MsgBox("Data Berhasil Disimpan")
Catch ex As Exception
MsgBox("Data Gagal Disimpan
!!!")
End Try
Call updatedata()
Call bersih()
tutup_koneksi()
End Sub
- - Edit
Private Sub btnedit_Click(sender As Object, e As EventArgs) Handles btnedit.Click
buka_koneksi()
Sql = "UPDATE supplier SET
kdbrg='"
& kodebrg.Text & "', kdsup='" & kodesup.Text & "',
tanggalbeli='" & tglbeli.Text & "', jumlahbeli='" & jumlahbeli.Text & "',
hargabeli='" & hargabeli.Text & "', total='" & total.Text & "' WHERE
nonota='"
& nonota.Text & "'"
comSQL = New SqlCommand(Sql, conn)
Try
comSQL.ExecuteNonQuery()
MsgBox("Update berhasil")
nonota.Enabled = True
btnsave.Enabled = True
Catch ex As Exception
MsgBox("Update gagal !!")
End Try
Call updatedata()
Call bersih()
tutup_koneksi()
End Sub
- - Delete
Private Sub btndelete_Click(sender As Object, e As EventArgs) Handles btndelete.Click
Dim pesan As String
pesan = MsgBox("Apakah Anda Ingin Menghapus
Data ini ?", vbYesNo, "Konfirmasi")
If pesan = 6 Then
hapuspembelian()
nonota.Enabled = True
btnsave.Enabled = True
End If
End Sub
- - Laporan
Private Sub btnlap_Click(sender As Object, e As EventArgs) Handles btnlap.Click
lappembelian.Show()
End Sub
- - Close
Private Sub btnclose_Click(sender As Object, e As EventArgs) Handles btnclose.Click
Close()
End Sub
Nah itu yang bisa kita sampaikan ,
Terima kasih , semoga bermanfaat
Wassalamualaikum ...
Tidak ada komentar:
Posting Komentar