Public Class Form37
Dim I As New OleDb.OleDbConnection("Provider=microsoft.ACE.OLEDB.12.0;data source=" & Application.StartupPath & "\DATAMAJEMUK.accdb")
Dim CI As New DataTable
Dim CT As DataRow
Private Sub Form37_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim X As New OleDb.OleDbDataAdapter
X = 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= '" & a.Text & "'", I)
X.Fill(CI)
X.Dispose()
Dim dataPrimary(1) As DataColumn
dataPrimary(0) = CI.Columns("KODEBARANG")
CI.PrimaryKey = dataPrimary
DataGridView1.DataSource = CI
End Sub
Private Sub TOTALJumlah()
Dim TOT As Double = 0
For Each x As DataRow In CI.Rows
TOT = TOT + x("JUMLAH")
Next
L.Text = TOT
End Sub
Private Sub d_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles d.Leave
If d.Text.Length = 0 Then
Exit Sub
End If
Dim cari As New ByIskandar.CariKeDataBaseByIskandar
cari.AturPencarianDataBase("BARANG", "KODEBARANG", d.Text, 1, I)
If cari.JumlanBaris > 0 Then
d.Text = cari.DataTablenya.Rows(0).Item("KODEBARANG")
J.Text = cari.DataTablenya.Rows(0).Item("NAMABARANG")
Else
MsgBox("Kode barang tersebut tidak ada")
Exit Sub
End If
End Sub
Private Sub d_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles d.TextChanged
J.Text = ""
ee.Text = ""
f.Text = ""
End Sub
Private Sub ee_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ee.TextChanged
K.Text = Val(ee.Text) * Val(f.Text)
End Sub
Private Sub g_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles g.Click
If d.Text.Length = 0 Then
MsgBox("Kode barang sudah ada")
Exit Sub
End If
If J.Text.Length = 0 Then
MsgBox("Nama barang sudah ada")
End If
If Val(ee.Text) = 0 Then
MsgBox("Masukkan unit barang")
Exit Sub
End If
If Val(f.Text) = 0 Then
MsgBox("Masukkan harga barang barang")
Exit Sub
End If
CT = CI.Rows.Find(d.Text)
If CT Is Nothing Then
CT = CI.NewRow
CT("KODEBARANG") = d.Text
Else
MsgBox("Maaf kodebarang sudah ada")
Exit Sub
End If
CT = CI.NewRow
CT("KODEBARANG") = d.Text
CT("NAMABARANG") = J.Text
CT("UNIT") = ee.Text
CT("HARGA") = f.Text
CT("JUMLAH") = K.Text
CI.Rows.Add(CT)
d.Text = ""
J.Text = ""
ee.Text = ""
f.Text = ""
TOTALJumlah()
End Sub
Private Sub h_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles h.Click
If a.Text.Length = 0 Then
MsgBox("No. transaksi sudah ada")
Exit Sub
End If
If c.Text.Length = 0 Then
MsgBox("Jenis transaksi sudah ada")
Exit Sub
End If
If CI.Rows.Count = 0 Then
MsgBox("Jumlah baris tidak terisi")
Exit Sub
End If
Dim cari As New ByIskandar.CariKeDataBaseByIskandar
cari.AturPencarianDataBase("MASTERTRANSAKSI", "NOTRANS", a.Text, 1, I)
If cari.JumlanBaris > 0 Then
MsgBox("data tersebut sudah ada")
Exit Sub
End If
Dim CC As New OleDb.OleDbCommand
CC = New OleDb.OleDbCommand("INSERT INTO MASTERTRANSAKSI (NOTRANS, TANGGALTRANSAKSI, JENISTRANSAKSI) VALUES ('" & a.Text & "', #" & b.Value.Month & "/" & b.Value.Day & "/" & b.Value.Year & "#, '" & c.Text & "')", I)
I.Open()
CC.ExecuteNonQuery()
I.Close()
For Each X As DataRow In CI.Rows
CC = New OleDb.OleDbCommand("INSERT INTO DETAILTRANSAKSI (NOTRANS, KODEBARANG, UNIT, HARGA) VALUES ('" & a.Text & "','" & X("KODEBARANG") & "'," & X("UNIT") & ", " & X("HARGA") & ")", I)
I.Open()
CC.ExecuteNonQuery()
I.Close()
CC.Dispose()
Next
a.Text = ""
c.Text = ""
K.Text = ""
CI.Rows.Clear()
TOTALJumlah()
End Sub
End Class
Tidak ada komentar:
Posting Komentar