Public Class Tugas37_36109067
Dim V As New OleDb.OleDbConnection("Provider=microsoft.ACE.OLEDB.12.0;data source=" & Application.StartupPath & "\DATAMAJEMUK.accdb")
Dim dt1 As New DataTable
Dim dr1 As DataRow
Private Sub Latihan37017_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim L As New OleDb.OleDbDataAdapter
L = New OleDb.OleDbDataAdapter("Select BARANG.KODEBARANG, BARANG.NAMABARANG, DETAILTRANSAKSI.UNIT, DETAILTRANSAKSI.HARGA, DETAILTRANSAKSI.UNIT*DETAILTRANSAKSI.HARGA AS JUMLAH from DETAILTRANSAKSI INNER JOIN BARANG ON DETAILTRANSAKSI.KODEBARANG=BARANG.KODEBARANG WHERE NOTRANS= '" & tb1.Text & "'", V)
L.Fill(dt1)
L.Dispose()
Dim dataPrimary(1) As DataColumn
dataPrimary(0) = dt1.Columns("KODEBARANG")
dt1.PrimaryKey = dataPrimary
dgv1.DataSource = dt1
End Sub
Private Sub TOTALJUMLAH()
Dim TOT As Double = 0
For Each x As DataRow In dt1.Rows
TOT = TOT + x("JUMLAH")
Next
total.Text = TOT
End Sub
Private Sub tb3_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles tb3.Leave
If tb3.Text.Length = 0 Then
Exit Sub
End If
Dim Pencari As New ByIskandar.CariKeDataBaseByIskandar
Pencari.AturPencarianDataBase("BARANG", "KODEBARANG", tb3.Text, 1, V)
If Pencari.JumlanBaris > 0 Then
tb3.Text = Pencari.DataTablenya.Rows(0).Item("KODEBARANG")
tb4.Text = Pencari.DataTablenya.Rows(0).Item("NAMABARANG")
Else
MsgBox("Kode barang tersebut tidak ada")
Exit Sub
End If
End Sub
Private Sub tb3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb3.TextChanged
tb4.Text = ""
tb5.Text = ""
tb6.Text = ""
End Sub
Private Sub tb5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb5.TextChanged, tb6.TextChanged
tb7.Text = Val(tb5.Text) * Val(tb6.Text)
End Sub
Private Sub tambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tambah.Click
'a'
If tb3.Text.Length = 0 Then
MsgBox("Kode barang sudah ada")
Exit Sub
End If
If tb4.Text.Length = 0 Then
MsgBox("Nama barang sudah ada")
End If
If Val(tb5.Text) = 0 Then
MsgBox("Masukkan unit barang")
Exit Sub
End If
If Val(tb6.Text) = 0 Then
MsgBox("Masukkan harga barang barang")
Exit Sub
End If
'b'
dr1 = dt1.Rows.Find(tb3.Text)
If dr1 Is Nothing Then
dr1 = dt1.NewRow
dr1("KODEBARANG") = tb3.Text
Else
MsgBox("Maaf kodebarang sudah ada")
Exit Sub
End If
'c'
dr1 = dt1.NewRow
dr1("KODEBARANG") = tb3.Text
dr1("NAMABARANG") = tb4.Text
dr1("UNIT") = tb5.Text
dr1("HARGA") = tb6.Text
dr1("JUMLAH") = tb7.Text
dt1.Rows.Add(dr1)
'd'
tb3.Text = ""
tb4.Text = ""
tb5.Text = ""
tb6.Text = ""
'e'
TOTALJUMLAH()
End Sub
Private Sub Simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
'a'
If tb1.Text.Length = 0 Then
MsgBox("No. transaksi sudah ada")
Exit Sub
End If
If tb2.Text.Length = 0 Then
MsgBox("Jenis transaksi sudah ada")
Exit Sub
End If
'b'
If dt1.Rows.Count = 0 Then
MsgBox("Jumlah baris tidak terisi")
Exit Sub
End If
'c'
Dim pencari As New ByIskandar.CariKeDataBaseByIskandar
pencari.AturPencarianDataBase("MASTERTRANSAKSI", "NOTRANS", tb1.Text, 1, V)
If pencari.JumlanBaris > 0 Then
MsgBox("data tersebut sudah ada")
Exit Sub
End If
'd'
Dim MV As New OleDb.OleDbCommand
MV = New OleDb.OleDbCommand("INSERT INTO MASTERTRANSAKSI (NOTRANS, TANGGALTRANSAKSI, JENISTRANSAKSI) VALUES ('" & tb1.Text & "', #" & dtp.Value.Month & "/" & dtp.Value.Day & "/" & dtp.Value.Year & "#, '" & tb2.Text & "')", V)
V.Open()
MV.ExecuteNonQuery()
V.Close()
'e'
For Each X As DataRow In dt1.Rows
MV = New OleDb.OleDbCommand("INSERT INTO DETAILTRANSAKSI (NOTRANS, KODEBARANG, UNIT, HARGA) VALUES ('" & tb1.Text & "','" & X("KODEBARANG") & "'," & X("UNIT") & ", " & X("HARGA") & ")", V)
V.Open()
MV.ExecuteNonQuery()
V.Close()
MV.Dispose()
Next
'f'
tb1.Text = ""
tb2.Text = ""
tb7.Text = ""
'g'
dt1.Rows.Clear()
'h'
TOTALJUMLAH()
End Sub
End Class
Dim V As New OleDb.OleDbConnection("Provider=microsoft.ACE.OLEDB.12.0;data source=" & Application.StartupPath & "\DATAMAJEMUK.accdb")
Dim dt1 As New DataTable
Dim dr1 As DataRow
Private Sub Latihan37017_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim L As New OleDb.OleDbDataAdapter
L = New OleDb.OleDbDataAdapter("Select BARANG.KODEBARANG, BARANG.NAMABARANG, DETAILTRANSAKSI.UNIT, DETAILTRANSAKSI.HARGA, DETAILTRANSAKSI.UNIT*DETAILTRANSAKSI.HARGA AS JUMLAH from DETAILTRANSAKSI INNER JOIN BARANG ON DETAILTRANSAKSI.KODEBARANG=BARANG.KODEBARANG WHERE NOTRANS= '" & tb1.Text & "'", V)
L.Fill(dt1)
L.Dispose()
Dim dataPrimary(1) As DataColumn
dataPrimary(0) = dt1.Columns("KODEBARANG")
dt1.PrimaryKey = dataPrimary
dgv1.DataSource = dt1
End Sub
Private Sub TOTALJUMLAH()
Dim TOT As Double = 0
For Each x As DataRow In dt1.Rows
TOT = TOT + x("JUMLAH")
Next
total.Text = TOT
End Sub
Private Sub tb3_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles tb3.Leave
If tb3.Text.Length = 0 Then
Exit Sub
End If
Dim Pencari As New ByIskandar.CariKeDataBaseByIskandar
Pencari.AturPencarianDataBase("BARANG", "KODEBARANG", tb3.Text, 1, V)
If Pencari.JumlanBaris > 0 Then
tb3.Text = Pencari.DataTablenya.Rows(0).Item("KODEBARANG")
tb4.Text = Pencari.DataTablenya.Rows(0).Item("NAMABARANG")
Else
MsgBox("Kode barang tersebut tidak ada")
Exit Sub
End If
End Sub
Private Sub tb3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb3.TextChanged
tb4.Text = ""
tb5.Text = ""
tb6.Text = ""
End Sub
Private Sub tb5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb5.TextChanged, tb6.TextChanged
tb7.Text = Val(tb5.Text) * Val(tb6.Text)
End Sub
Private Sub tambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tambah.Click
'a'
If tb3.Text.Length = 0 Then
MsgBox("Kode barang sudah ada")
Exit Sub
End If
If tb4.Text.Length = 0 Then
MsgBox("Nama barang sudah ada")
End If
If Val(tb5.Text) = 0 Then
MsgBox("Masukkan unit barang")
Exit Sub
End If
If Val(tb6.Text) = 0 Then
MsgBox("Masukkan harga barang barang")
Exit Sub
End If
'b'
dr1 = dt1.Rows.Find(tb3.Text)
If dr1 Is Nothing Then
dr1 = dt1.NewRow
dr1("KODEBARANG") = tb3.Text
Else
MsgBox("Maaf kodebarang sudah ada")
Exit Sub
End If
'c'
dr1 = dt1.NewRow
dr1("KODEBARANG") = tb3.Text
dr1("NAMABARANG") = tb4.Text
dr1("UNIT") = tb5.Text
dr1("HARGA") = tb6.Text
dr1("JUMLAH") = tb7.Text
dt1.Rows.Add(dr1)
'd'
tb3.Text = ""
tb4.Text = ""
tb5.Text = ""
tb6.Text = ""
'e'
TOTALJUMLAH()
End Sub
Private Sub Simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
'a'
If tb1.Text.Length = 0 Then
MsgBox("No. transaksi sudah ada")
Exit Sub
End If
If tb2.Text.Length = 0 Then
MsgBox("Jenis transaksi sudah ada")
Exit Sub
End If
'b'
If dt1.Rows.Count = 0 Then
MsgBox("Jumlah baris tidak terisi")
Exit Sub
End If
'c'
Dim pencari As New ByIskandar.CariKeDataBaseByIskandar
pencari.AturPencarianDataBase("MASTERTRANSAKSI", "NOTRANS", tb1.Text, 1, V)
If pencari.JumlanBaris > 0 Then
MsgBox("data tersebut sudah ada")
Exit Sub
End If
'd'
Dim MV As New OleDb.OleDbCommand
MV = New OleDb.OleDbCommand("INSERT INTO MASTERTRANSAKSI (NOTRANS, TANGGALTRANSAKSI, JENISTRANSAKSI) VALUES ('" & tb1.Text & "', #" & dtp.Value.Month & "/" & dtp.Value.Day & "/" & dtp.Value.Year & "#, '" & tb2.Text & "')", V)
V.Open()
MV.ExecuteNonQuery()
V.Close()
'e'
For Each X As DataRow In dt1.Rows
MV = New OleDb.OleDbCommand("INSERT INTO DETAILTRANSAKSI (NOTRANS, KODEBARANG, UNIT, HARGA) VALUES ('" & tb1.Text & "','" & X("KODEBARANG") & "'," & X("UNIT") & ", " & X("HARGA") & ")", V)
V.Open()
MV.ExecuteNonQuery()
V.Close()
MV.Dispose()
Next
'f'
tb1.Text = ""
tb2.Text = ""
tb7.Text = ""
'g'
dt1.Rows.Clear()
'h'
TOTALJUMLAH()
End Sub
End Class
Tidak ada komentar:
Posting Komentar