1.
Klik Start lalu pilih Microsoft
Visual Studio 2008
2.
Lalu akan muncul jendela awal
Microsoft Visual Studio seperti di bawah ini.
3.
Lalu pilih New Project dan beri nama
serta pilih tempat folder untuk menyimpannya.
4.
Kemudian
buat form sesuai dengan form di bawah ini.
5.
Berikut
ini adalah rumus untuk menjalankan form di atas.
Public Class
Latihan_40B_36110048
Dim bridgeRio As New OleDb.OleDbConnection("
Provider = microsoft.ace.oledb.12.0; data source = " &
Application.StartupPath & "\DataMajemuk.accdb")
Dim tabelRio As New DataTable
Public Sub
SelectData()
Dim truckRio As New OleDb.OleDbDataAdapter
truckRio = New OleDb.OleDbDataAdapter("Select
BARANG.KODEBARANG, BARANG.NAMABARANG, UNIT, HARGA, UNIT * HARGA As JUMLAH
" & _
"From DETAILTRANSAKSI Inner join BARANG on
DETAILTRANSAKSI.KODEBARANG = BARANG.KODEBARANG where NOTRANS = '"
& NO_36110048.Text & "'",
bridgeRio)
tabelRio.Rows.Clear()
truckRio.Fill(tabelRio)
truckRio.Dispose()
End Sub
Private Sub
Latihan_40B_36110048_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
SelectData()
DGV_36110048.DataSource = tabelRio
End Sub
Public Sub Hitung()
Dim Jumlah As Integer = 0
For Each row As DataGridViewRow In
DGV_36110048.Rows
Jumlah =
Jumlah + row.Cells("Jumlah").Value
Next
TOTAL_36110048.Text = Jumlah
End Sub
Private Sub
DGV_36110048_CellEndEdit(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles
DGV_36110048.CellEndEdit
If e.ColumnIndex = 0 Then
DGV_36110048.CurrentRow.Cells("NAMABARANG").Value
= ""
DGV_36110048.CurrentRow.Cells("UNIT").Value
= 0
DGV_36110048.CurrentRow.Cells("HARGA").Value = 0
DGV_36110048.CurrentRow.Cells("JUMLAH").Value
= 0
Dim Pencari As New ByIskandar.CariKeDataBaseByIskandar
Pencari.AturPencarianDataBase("BARANG",
"KODEBARANG", DGV_36110048.CurrentRow.Cells("KODEBARANG").Value, 1, bridgeRio)
If Pencari.JumlanBaris = 0 Then
MsgBox("Kode barang tersebut tidak ada")
If Latihan_383940_36110048.ShowDialog =
Windows.Forms.DialogResult.OK Then
DGV_36110048.CurrentRow.Cells("KODEBARANG").Value
= Latihan_383940_36110048.DGV_36110048.CurrentRow.Cells("KODEBARANG").Value
DGV_36110048.CurrentRow.Cells("NAMABARANG").Value
= Latihan_383940_36110048.DGV_36110048.CurrentRow.Cells("NAMABARANG").Value
Else
DGV_36110048.CurrentRow.Cells("KODEBARANG").Value
= ""
End If
Exit Sub
End If
DGV_36110048.CurrentRow.Cells("NAMABARANG").Value
= Pencari.DataTablenya.Rows(0).Item("NAMABARANG")
ElseIf e.ColumnIndex = 2 Or
e.ColumnIndex = 3 Then
DGV_36110048.CurrentRow.Cells("JUMLAH").Value
= DGV_36110048.CurrentRow.Cells("UNIT").Value
* DGV_36110048.CurrentRow.Cells("HARGA").Value
Hitung()
End If
End Sub
Private Sub
SIMPAN_36110048_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles SIMPAN_36110048.Click
If tabelRio.Rows.Count = 0 Then
MsgBox("Datanya Belum Ada, Masukkan Kode Barang, Unit dan
harganya")
Exit Sub
End If
If NO_36110048.Text <> NOLAMA_36110048.Text Then
Dim Periksa As New ByIskandar.CariKeDataBaseByIskandar
Periksa.AturPencarianDataBase("MASTERTRANSAKSI",
"NOTRANS", NO_36110048.Text, 1,
bridgeRio)
If Periksa.JumlanBaris > 0 Then
MsgBox("No Transaksi Sudah Ada, Masukkan No Transaksi yang
Lain")
Exit Sub
End If
End If
Dim Hapus As New OleDb.OleDbCommand
Hapus = New OleDb.OleDbCommand("Delete
* From MASTERTRANSAKSI Where NOTRANS = '" &
NOLAMA_36110048.Text & "'",
bridgeRio)
bridgeRio.Open()
Hapus.ExecuteNonQuery()
bridgeRio.Close()
Hapus = New OleDb.OleDbCommand("Delete
* From DETAILTRANSAKSI Where NOTRANS = '" &
NOLAMA_36110048.Text & "'",
bridgeRio)
bridgeRio.Open()
Hapus.ExecuteNonQuery()
bridgeRio.Close()
Dim Ambil As New OleDb.OleDbCommand
Ambil = New OleDb.OleDbCommand("Insert
Into MASTERTRANSAKSI (NOTRANS, TANGGALTRANSAKSI, JENISTRANSAKSI) "
& _
"Values ('" & NO_36110048.Text &
"', #" &
TGL_36110048.Value.Month & "/"
& TGL_36110048.Value.Day & "/"
& TGL_36110048.Value.Year & "#,
'" & JENIS_36110048.Text & "')",
bridgeRio)
bridgeRio.Open()
Ambil.ExecuteNonQuery()
bridgeRio.Close()
Ambil.Dispose()
For Each BarisX As DataRow In
tabelRio.Rows
Dim Simpan As New OleDb.OleDbCommand
Simpan = New OleDb.OleDbCommand("Insert
Into DETAILTRANSAKSI (NOTRANS, KODEBARANG, UNIT, HARAGA) " & _
"Values ('" & NO_36110048.Text &
"', '" & BarisX("KODEBARANG") & "', " & BarisX("UNIT") & ",
" & BarisX("HARGA")
& ")", bridgeRio)
bridgeRio.Open()
Simpan.ExecuteNonQuery()
bridgeRio.Close()
Simpan.Dispose()
Next
NO_36110048.Text = ""
JENIS_36110048.Text
= ""
tabelRio.Clear()
Latihan_40A_36110048.Isi()
Hitung()
End Sub
End Class
6.
Setelah itu, jalankan programnya.
0 komentar:
Posting Komentar