Public Class LATIHAN_039_36109075
Dim ALFATIH As New OleDb.OleDbConnection("Provider=microsoft.ACE.OLEDB.12.0;data source=" & Application.StartupPath & "\DataMajemuk.accdb")
Dim LORENZO As DataTable
Private Sub LATIHAN_039_36109075_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Q As New OleDb.OleDbDataAdapter
Q = 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= '" & nt075.Text & "'", ALFATIH)
Q.Fill(LORENZO)
Q.Dispose()
Dim dataPrimary(1) As DataColumn
dataPrimary(0) = LORENZO.Columns("KODEBARANG")
LORENZO.PrimaryKey = dataPrimary
DGV075.DataSource = LORENZO
End Sub
Private Sub TOTALJUMLAH()
Dim TOT As Double = 0
For Each a As DataRow In LORENZO.Rows
TOT = TOT + a("jumlah")
Next
tot075.Text = TOT
End Sub
Private Sub DGV075_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV075.CellEndEdit
If DGV075.Columns(e.ColumnIndex).Name = "KODEBARANG" Then
'Cari nama barang'
DGV075.CurrentRow.Cells("NAMABARANG").Value = ""
DGV075.CurrentRow.Cells("UNIT").Value = 0
DGV075.CurrentRow.Cells("HARGA").Value = 0
DGV075.CurrentRow.Cells("JUMLAH").Value = 0
Dim Pencari As New ByIskandar.CariKeDataBaseByIskandar
Pencari.AturPencarianDataBase("BARANG", "KODEBARANG", DGV075.CurrentRow.Cells("KODEBARANG").Value, 1, ALFATIH)
'Menampilkan nama barang jika isi kolom kodebarang ditemukan oleh proses diatas'
If Pencari.JumlanBaris > 0 Then
DGV075.CurrentRow.Cells("NAMABARANG").Value = Pencari.DataTablenya.Rows(0).Item("NAMABARANG")
Else
DGV075.CurrentRow.Cells("KODEBARANG").Value = ""
If LATIHAN_383940_075.ShowDialog = Windows.Forms.DialogResult.OK Then
DGV075.CurrentRow.Cells("KODEBARANG").Value = LATIHAN_383940_075.DGV38_075.CurrentRow.Cells("KODEBARANG").Value
DGV075.CurrentRow.Cells("NAMABARANG").Value = LATIHAN_383940_075.DGV38_075.CurrentRow.Cells("NAMABARANG").Value
End If
End If
ElseIf DGV075.Columns(e.ColumnIndex).Name = "UNIT" Or DGV075.Columns(e.ColumnIndex).Name = "HARGA" Then
DGV075.CurrentRow.Cells("JUMLAH").Value = DGV075.CurrentRow.Cells("UNIT").Value * DGV075.CurrentRow.Cells("HARGA").Value
TOTALJUMLAH()
End If
End Sub
Private Sub simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles simpan.Click
If nt075.Text.Length = 0 Then
MsgBox("No. transaksi sudah ada")
Exit Sub
End If
If jt075.Text.Length = 0 Then
MsgBox("Jenis transaksi sudah ada")
Exit Sub
End If
If LORENZO.Rows.Count = 0 Then
MsgBox("Jumlah baris tidak terisi")
Exit Sub
End If
Dim pencari As New ByIskandar.CariKeDataBaseByIskandar
pencari.AturPencarianDataBase("MASTERTRANSAKSI", "NOTRANS", nt075.Text, 1, ALFATIH)
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 ('" & nt075.Text & "', #" & DTP075.Value.Month & "/" & DTP075.Value.Day & "/" & DTP075.Value.Year & "#, '" & jt075.Text & "')", ALFATIH)
ALFATIH.Open()
CM.ExecuteNonQuery()
ALFATIH.Close()
For Each X As DataRow In LORENZO.Rows
CM = New OleDb.OleDbCommand("INSERT INTO DETAILTRANSAKSI (NOTRANS, KODEBARANG, UNIT, HARGA) VALUES ('" & nt075.Text & "','" & X("KODEBARANG") & "'," & X("UNIT") & ", " & X("HARGA") & ")", ALFATIH)
ALFATIH.Open()
CM.ExecuteNonQuery()
ALFATIH.Close()
CM.Dispose()
Next
nt075.Text = ""
jt075.Text = ""
LORENZO.Rows.Clear()
End Sub
End Class
Tidak ada komentar:
Posting Komentar