Deskripsi Latihan_40A_36110038
Form Latihan_40A terdapat tiga
object yaitu Label , Button dan DataGridView:
Object Label
Terdapat satu label (DATA TRANSAKSI)
Object Button
Terdapat tiga object button (Hapus,
Tambah dan Edit). Tombol hapus digunakan untuk mengapus data pada objek
DataGridView yang diinginkan. Tombol Tambah digunakan untuk menambah data pada
objek DataGridView melalui form Latihan_40B_36110038. Sedengkan Tombol Simpan
digunakan untuk mengubah data yang ada pada objek datagridview sesuai yang
diinginkan melalui form Latihan_40B_36110038.
Object Data GridView
Terdapat satu data gridview yang
digunakan untuk menampilkan data.
Script Unique
Button "hapus" (hps_36110038)
Dim comman As New
OleDb.OleDbCommand
comman = New
OleDb.OleDbCommand("Delete * From
MASTERTRANSAKSI Where NOTRANS = '" &
dgv1_36110038.CurrentRow.Cells("NOTRANS").Value
& "'", connec)
Button "Tambah" (tambah_36110038)
If
Latihan_40B_36110038.Visible = False Then
Latihan_40B_36110038.Show()
Else
Latihan_40B_36110038.Activate()
Latihan_40B_36110038.WindowState =
FormWindowState.Normal
Latihan_40B_36110038.nolama_36110038.Text = "-"
End If
Button "edit" (edit_36110038)
If
Latihan_40B_36110038.Visible = False Then
Latihan_40B_36110038.Show()
Else
Latihan_40B_36110038.Activate()
Latihan_40B_36110038.WindowState =
FormWindowState.Normal
End If
Even
hps_36110038.Click
tambah_36110038.Click
edit_36110038.Click
Prosedur penyelesaian
1.
Buka Project_36110038 yang telah
dibuat sebelumnya.
2.
Buka visual basic Kumpulan_Latihan_36110038
yang telah dibuat sebelumnya
.
3.
Buat form baru dengan nama Latihan_40A_36110038
sesuai form dibawah in
i.
4. Ganti
semua nama objek yang ada selain label menggunakan "Properties
Window" sesuai dengan yang diinginkan dengan menambahkan stambuk
dibelakang nama obyek.
5. Klik
2x pada kotak design untuk membuka lembar VB untuk menuliskan rumusnya. Masukkan
rumus berikut untuk menyelesaikan Latihan_40A
Public Class Latihan_40A_36110038
Dim connec As New
OleDb.OleDbConnection(" Provider =
microsoft.ace.oledb.12.0; data source = " &
Application.StartupPath & "\DataMajemuk.accdb")
Dim tabel1 As New DataTable
Dim tabel2 As New DataTable
Dim dataset
As New DataSet
Dim Binding
As New
BindingSource
Dim
Binding2 As New
BindingSource
Public Sub Isi()
Dim
adapter As New
OleDb.OleDbDataAdapter
tabel2.Rows.Clear()
tabel1.Rows.Clear()
adapter = New
OleDb.OleDbDataAdapter("Select * "
& _
"From
MASTERTRANSAKSI", connec)
adapter.Fill(tabel1)
adapter = New
OleDb.OleDbDataAdapter("Select NOTRANS,
DETAILTRANSAKSI.KODEBARANG, NAMABARANG, HARGA, UNIT, UNIT * HARGA As JUMLAH
" & _
"From DETAILTRANSAKSI Inner Join BARANG on
DETAILTRANSAKSI.KODEBARANG = BARANG.KODEBARANG", connec)
adapter.Fill(tabel2)
adapter.Dispose()
End Sub
Private Sub Latihan_40A_36110038_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Isi()
dgv1_36110038.DataSource = tabel1
dgv2_36110038.DataSource = tabel2
dataset.Tables.Add(tabel1)
dataset.Tables.Add(tabel2)
tabel1.TableName = "Induk"
tabel2.TableName = "Sub"
dataset.Relations.Add(New DataRelation("Relasi",
dataset.Tables("Induk").Columns("NOTRANS"), dataset.Tables("Sub").Columns("NOTRANS")))
Binding.DataSource = dataset
Binding.DataMember = "Induk"
Binding2.DataSource = Binding
Binding2.DataMember = "Relasi"
dgv1_36110038.DataSource = Binding
dgv2_36110038.DataSource = Binding2
End Sub
Private Sub hps_36110038_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles hps_36110038.Click
Dim
comman As New
OleDb.OleDbCommand
comman = New
OleDb.OleDbCommand("Delete * From
MASTERTRANSAKSI Where NOTRANS = '" &
dgv1_36110038.CurrentRow.Cells("NOTRANS").Value
& "'", connec)
If
MsgBox("Apakah Anda Yakin Menghapusnya?",
MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
connec.Open()
comman.ExecuteNonQuery()
comman = New
OleDb.OleDbCommand("Delete * From
DETAILTRANSAKSI Where NOTRANS = '" & dgv1_36110038.CurrentRow.Cells("NOTRANS").Value & "'", connec)
comman.ExecuteNonQuery()
connec.Close()
comman.Dispose()
End If
Isi()
End Sub
Private Sub tambah_36110038_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles tambah_36110038.Click
If
Latihan_40B_36110038.Visible = False Then
Latihan_40B_36110038.Show()
Else
Latihan_40B_36110038.Activate()
Latihan_40B_36110038.WindowState =
FormWindowState.Normal
Latihan_40B_36110038.nolama_36110038.Text = "-"
End If
Latihan_40B_36110038.no_36110038.Text =
""
Latihan_40B_36110038.jns_36110038.Text
= ""
Latihan_40B_36110038.ttl_36110038.Text
= ""
Latihan_40B_36110038.SelectData()
Latihan_40B_36110038.Hitung()
End Sub
Private Sub edit_36110038_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles edit_36110038.Click
If
Latihan_40B_36110038.Visible = False Then
Latihan_40B_36110038.Show()
Else
Latihan_40B_36110038.Activate()
Latihan_40B_36110038.WindowState =
FormWindowState.Normal
End If
Latihan_40B_36110038.no_36110038.Text =
dgv1_36110038.CurrentRow.Cells("NOTRANS").Value
Latihan_40B_36110038.nolama_36110038.Text =
dgv1_36110038.CurrentRow.Cells("NOTRANS").Value
Latihan_40B_36110038.jns_36110038.Text
= dgv1_36110038.CurrentRow.Cells("JENISTRANSAKSI").Value
Latihan_40B_36110038.SelectData()
Latihan_40B_36110038.Hitung()
End Sub
End Class
6.
Tekan
F5 pada keyboard untuk menjalankan form.
Tidak ada komentar:
Posting Komentar