Public Class Latihan_39059
Dim A As New OleDb.OleDbConnection("Provider=microsoft.ACE.OLEDB.12.0;data source=" & Application.StartupPath & "\DATAMAJEMUK.accdb")
Dim dt As New DataTable
Private Sub Latihan_39059_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= '" & nota059.Text & "'", A)
X.Fill(dt)
X.Dispose()
Dim dataPrimary(1) As DataColumn
dataPrimary(0) = dt.Columns("KODEBARANG")
dt.PrimaryKey = dataPrimary
chika059.DataSource = dt
End Sub
Private Sub TOTALJUMLAH()
Dim TOT As Double = 0
For Each x As DataRow In dt.Rows
TOT = TOT + x("JUMLAH")
Next
TOTAL.Text = TOT
End Sub
Private Sub chika059_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles chika059.CellContentClick
If chika059.Columns(e.ColumnIndex).Name = "KODEBARANG" Then
'Cari nama barang'
chika059.CurrentRow.Cells("NAMABARANG").Value = ""
chika059.CurrentRow.Cells("UNIT").Value = 0
chika059.CurrentRow.Cells("HARGA").Value = 0
chika059.CurrentRow.Cells("JUMLAH").Value = 0
Dim Pencari As New ByIskandar.CariKeDataBaseByIskandar
Pencari.AturPencarianDataBase("BARANG", "KODEBARANG", chika059.CurrentRow.Cells("KODEBARANG").Value, 1, A)
'Menampilkan nama barang jika isi kolom kodebarang ditemukan oleh proses diatas'
If Pencari.JumlanBaris > 0 Then
chika059.CurrentRow.Cells("NAMABARANG").Value = Pencari.DataTablenya.Rows(0).Item("NAMABARANG")
Else
chika059.CurrentRow.Cells("KODEBARANG").Value = ""
If Latihan_383940.ShowDialog = Windows.Forms.DialogResult.OK Then
chika059.CurrentRow.Cells("KODEBARANG").Value = Latihan_383940.cika059.CurrentRow.Cells("KODEBARANG").Value
chika059.CurrentRow.Cells("NAMABARANG").Value = Latihan_383940.cika059.CurrentRow.Cells("NAMABARANG").Value
End If
End If
ElseIf chika059.Columns(e.ColumnIndex).Name = "UNIT" Or chika059.Columns(e.ColumnIndex).Name = "HARGA" Then
chika059.CurrentRow.Cells("JUMLAH").Value = chika059.CurrentRow.Cells("UNIT").Value * chika059.CurrentRow.Cells("HARGA").Value
TOTALJUMLAH()
End If
End Sub
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
If nota059.Text.Length = 0 Then
MsgBox("No. transaksi sudah ada")
Exit Sub
End If
If jetran.Text.Length = 0 Then
MsgBox("Jenis transaksi sudah ada")
Exit Sub
End If
If dt.Rows.Count = 0 Then
MsgBox("Jumlah baris tidak terisi")
Exit Sub
End If
Dim pencari As New ByIskandar.CariKeDataBaseByIskandar
pencari.AturPencarianDataBase("MASTERTRANSAKSI", "NOTRANS", nota059.Text, 1, A)
If pencari.JumlanBaris > 0 Then
MsgBox("data tersebut sudah ada")
Exit Sub
End If
Dim CM As New OleDb.OleDbCommand
CM = New OleDb.OleDbCommand("INSERT INTO MASTERTRANSAKSI (NOTRANS, TANGGALTRANSAKSI, JENISTRANSAKSI) VALUES ('" & nota059.Text & "', #" & date059.Value.Month & "/" & date059.Value.Day & "/" & date059.Value.Year & "#, '" & jetran.Text & "')", A)
A.Open()
CM.ExecuteNonQuery()
A.Close()
For Each X As DataRow In dt.Rows
CM = New OleDb.OleDbCommand("INSERT INTO DETAILTRANSAKSI (NOTRANS, KODEBARANG, UNIT, HARGA) VALUES ('" & nota059.Text & "','" & X("KODEBARANG") & "'," & X("UNIT") & ", " & X("HARGA") & ")", A)
A.Open()
CM.ExecuteNonQuery()
A.Close()
CM.Dispose()
Next
nota059.Text = ""
jetran.Text = ""
dt.Rows.Clear()
End Sub
End Class
Tidak ada komentar:
Posting Komentar