Public Class Form040A_46109023
Dim conect As New OleDb.OleDbConnection("provider = microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\datamajemuk.accdb;Jet OLEDB:Database Password=ngekngek")
Dim cim1 As New DataTable
Dim cim2 As New DataTable
Dim yuni As New DataSet
Dim cimi1 As New BindingSource
Dim cimi2 As New BindingSource
Public Sub sri1()
Dim bunga As New OleDb.OleDbDataAdapter
cim2.Rows.Clear()
cim1.Rows.Clear()
bunga = New OleDb.OleDbDataAdapter("select * from mastertransaksi", conect)
bunga.Fill(cim1)
bunga = New OleDb.OleDbDataAdapter("select detailtransaksi.notrans, barang.kodebarang, barang.namabarang, detailtransaksi.unit, detailtransaksi.harga, detailtransaksi.unit*harga as jumlah from barang inner join detailtransaksi on barang.kodebarang = detailtransaksi.kodebarang", conect)
bunga.Fill(cim2)
End Sub
Private Sub Latihan40A_46109023_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
sri1()
yuni.Tables.Add(cim1)
yuni.Tables.Add(cim2)
cim1.TableName = "amri"
cim2.TableName = "amri2"
yuni.Relations.Add(New DataRelation("bunga", yuni.Tables("amri").Columns("notrans"), yuni.Tables("amri2").Columns("notrans")))
cimi1.DataSource = yuni
cimi1.DataMember = "ical"
cimi2.DataSource = cimi1
cimi2.DataMember = "bunga"
Dim dc(1) As DataColumn
dc(0) = cim1.Columns("notrans")
cim1.PrimaryKey = dc
DATA1_46109023.DataSource = cimi1
DATA2_46109023.DataSource = cimi2
End Sub
Private Sub H46109023_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles H46109023.Click
Dim cimcim As New OleDb.OleDbCommand
cimcim = New OleDb.OleDbCommand("delete * from mastertransaksi where notrans = '" & DATA1_46109023.CurrentRow.Cells("notrans").Value & "'", conect)
conect.Open()
cimcim.ExecuteNonQuery()
conect.Close()
cimcim = New OleDb.OleDbCommand("delete * from detailtransaksi where notrans = '" & DATA1_46109023.CurrentRow.Cells("notrans").Value & "'", conect)
conect.Open()
cimcim.ExecuteNonQuery()
conect.Close()
cimcim.Dispose()
sri1()
End Sub
Private Sub TM46109023_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TM46109023.Click
If Form40B_46109023.Visible = False Then
Form40B_46109023.Show()
Else
Form40B_46109023.Activate()
End If
Form40B_46109023.NT46109023.Text = ""
Form40B_46109023.JT46109023.Text = ""
Form40B_46109023.TS46109001.Text = "-"
Form40B_46109023.saadah2()
Form40B_46109023.saadah3()
End Sub
Private Sub E46109023_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles E46109023.Click
If Form40B_46109023.Visible = False Then
Form40B_46109023.Show()
Else
Form40B_46109023.Activate()
End If
Form40B_46109023.NT46109023.Text = DATA1_46109023.CurrentRow.Cells("notrans").Value
Form40B_46109023.T46109023.Value = DATA1_46109023.CurrentRow.Cells("tanggaltransaksi").Value
Form40B_46109023.JT46109023.Text = DATA1_46109023.CurrentRow.Cells("jenistransaksi").Value
Form40B_46109023.TS46109001.Text = DATA1_46109023.CurrentRow.Cells("notrans").Value
Form40B_46109023.sri2()
Form40B_46109023.sri3()
End Sub
Private Sub DATA1_46109023_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DATA1_46109023.CellContentClick
End Sub
End Class
Public Class Form40B_46109023
Dim conect As New OleDb.OleDbConnection("provider = microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\datamajemuk.accdb;Jet OLEDB:Database Password=cimi")
Dim ismi As New DataTable
Dim sri As New ByIskandar.CariKeDataBaseByIskandar
Dim cimi As New OleDb.OleDbCommand
Public Sub sri2()
Dim bunga As New OleDb.OleDbDataAdapter
bunga = New OleDb.OleDbDataAdapter("select barang.KODEBARANG, barang.NAMABARANG, detailtransaksi.UNIT, detailtransaksi.HARGA, detailtransaksi.unit * detailtransaksi.harga as JUMLAH from barang inner join detailtransaksi on barang.kodebarang = detailtransaksi.kodebarang where notrans = '" & NT46109023.Text & "'", conect)
ismi.Rows.Clear()
bunga.Fill(ismi)
End Sub
Public Sub sri3()
Dim total As Integer = 0
For Each x As DataRow In ismi.Rows
total += x("Jumlah")
Next
TOT46109023.Text = total
End Sub
Private Sub sri4()
If NT46109023.Text.Length = 0 Then
MsgBox("Isi rong itu Notransnya..")
Exit Sub
End If
If JT46109023.Text.Length = 0 Then
MsgBox("Isi rong itu Jenis Transaksinya..")
Exit Sub
End If
If ismi.Rows.Count = 0 Then
MsgBox("Isi rong itu datatable k..")
Exit Sub
End If
End Sub
Private Sub tambah()
sri4()
sri.AturPencarianDataBase("mastertransaksi", "notrans", NT46109023.Text, 1, conect)
If sri.JumlanBaris > 0 Then
MsgBox("Adami notrans seperti itu..")
Exit Sub
End If
cimi = New OleDb.OleDbCommand("insert into mastertransaksi (notrans, tanggaltransaksi, jenistransaksi) values ('" & NT46109023.Text & "',#" & T46109023.Value.Month & "/" & T46109023.Value.Day & "/" & T46109023.Value.Year & "#, '" & JT46109023.Text & "')", conect)
conect.Open()
cimi.ExecuteNonQuery()
conect.Close()
For Each x As DataRow In ismi.Rows
cimi = New OleDb.OleDbCommand("insert into detailtransaksi (notrans, kodebarang, unit, harga) values ('" & NT46109023.Text & "', '" & x("kodebarang") & "', '" & x("unit") & "', '" & x("harga") & "') ", conect)
conect.Open()
cimi.ExecuteNonQuery()
conect.Close()
Next
cimi.Dispose()
NT46109023.Text = ""
JT46109023.Text = ""
TOT46109023.Text = ""
TS46109001.Text = "-"
ismi.Rows.Clear()
Form040A_46109023.sri1()
End Sub
Public Sub edit()
sri4()
If NT46109023.Text <> TS46109001.Text Then
sri.AturPencarianDataBase("mastertransaksi", "notrans", NT46109023.Text, 1, conect)
If sri.JumlanBaris > 0 Then
MsgBox("Adami Notrans seperti itu,,mohon ganti..")
Exit Sub
End If
End If
cimi = New OleDb.OleDbCommand("delete * from mastertransaksi where notrans = '" & TS46109001.Text & "'", conect)
conect.Open()
cimi.ExecuteNonQuery()
conect.Close()
cimi = New OleDb.OleDbCommand("insert into mastertransaksi(notrans, tanggaltransaksi, jenistransaksi) values ('" & NT46109023.Text & "',#" & T46109023.Value.Month & "/" & T46109023.Value.Day & "/" & T46109023.Value.Year & "#, '" & JT46109023.Text & "')", conect)
conect.Open()
cimi.ExecuteNonQuery()
conect.Close()
cimi = New OleDb.OleDbCommand("delete * from detailtransaksi where notrans = '" & TS46109001.Text & "'", conect)
conect.Open()
cimi.ExecuteNonQuery()
conect.Close()
For Each x As DataRow In ismi.Rows
cimi = New OleDb.OleDbCommand("insert into detailtransaksi(notrans, kodebarang, unit, harga) values ('" & NT46109023.Text & "', '" & x("kodebarang") & "', '" & x("unit") & "', '" & x("harga") & "')", conect)
conect.Open()
cimi.ExecuteNonQuery()
conect.Close()
Next
cimi.Dispose()
NT46109023.Text = ""
JT46109023.Text = ""
TOT46109023.Text = ""
TS46109001.Text = "-"
ismi.Rows.Clear()
Form040A_46109023.sri1()
End Sub
Private Sub Form040A_46109023_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
sri2()
Dim dc(1) As DataColumn
dc(0) = ismi.Columns("kodebarang")
ismi.PrimaryKey = dc
ismi.Columns("unit").DefaultValue = 0
ismi.Columns("harga").DefaultValue = 0
ismi.Columns("jumlah").DefaultValue = 0
DATA46109023.DataSource = ismi
End Sub
Private Sub DATA46109023_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DATA46109023.CellEndEdit
If DATA46109023.Columns(e.ColumnIndex).Name = "KODEBARANG" Then
DATA46109023.CurrentRow.Cells("NAMABARANG").Value = ""
DATA46109023.CurrentRow.Cells("UNIT").Value = 0
DATA46109023.CurrentRow.Cells("HARGA").Value = 0
DATA46109023.CurrentRow.Cells("JUMLAH").Value = 0
sri.AturPencarianDataBase("barang", "kodebarang", DATA46109023.CurrentRow.Cells("KODEBARANG").Value, 1, conect)
If sri.JumlanBaris > 0 Then
DATA46109023.CurrentRow.Cells("NAMABARANG").Value = sri.DataTablenya.Rows(0).Item("NAMABARANG")
Else
DATA46109023.CurrentRow.Cells("NAMABARANG").Value = ""
If Form383940_46109023.ShowDialog = Windows.Forms.DialogResult.OK Then
DATA46109023.CurrentRow.Cells("KODEBARANG").Value = Form383940_46109023.DATA46109023.CurrentRow.Cells("KODEBARANG").Value
DATA46109023.CurrentRow.Cells("NAMABARANG").Value = Form383940_46109023.DATA46109023.CurrentRow.Cells("NAMABARANG").Value
End If
End If
ElseIf DATA46109023.Columns(e.ColumnIndex).Name = "UNIT" Or DATA46109023.Columns(e.ColumnIndex).Name = "HARGA" Then
DATA46109023.CurrentRow.Cells("JUMLAH").Value = DATA46109023.CurrentRow.Cells("UNIT").Value * DATA46109023.CurrentRow.Cells("HARGA").Value
sri3()
End If
End Sub
Private Sub S46109023_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles S46109023.Click
If S46109023.Text = "-" Then
tambah()
Else
edit()
End If
End Sub
Private Sub DATA46109023_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles DATA46109023.DataError
MsgBox("Terjadi sedikit kesalahan...")
End Sub
End Class
Tidak ada komentar:
Posting Komentar