Latihan 32A
Public Class Form32A_36109020
Dim dtb As New DataTable
Dim ksr As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")
Public Sub dhedhe()
Dim daf As New OleDb.OleDbDataAdapter
daf = New OleDb.OleDbDataAdapter("select * from barang", ksr)
dtb.Rows.Clear()
daf.Fill(dtb)
daf.Dispose()
End Sub
Private Sub Latihan_32A_022_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dhedhe()
dgv_36109020.DataSource = dtb
End Sub
Private Sub tambah_36109020_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tambah_36109020.Click
If Form32B_36109020.Visible = False Then
Form32B_36109020.Show()
Else
Form32B_36109020.Activate()
End If
End Sub
Private Sub edit_36109020_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles edit_36109020.Click
If Form32C_36109020.Visible = False Then
Form32C_36109020.Show()
Else
Form32C_36109020.Activate()
End If
Form32C_36109020.t1_36109020.Text = dgv_36109020.CurrentRow.Cells("kodebarang").Value
Form32C_36109020.t2_36109020.Text = dgv_36109020.CurrentRow.Cells("namabarang").Value
Form32C_36109020.t3_36109020.Text = dgv_36109020.CurrentRow.Cells("hargajual").Value
Form32C_36109020.t4_36109020.Text = dgv_36109020.CurrentRow.Cells("jumlahbarang").Value
Form32C_36109020.KB_36109020.Text = dgv_36109020.CurrentRow.Cells("kodebarang").Value
Form32C_36109020.Show()
End Sub
End Class
Latihan 32B
Public Class Form32B_36109020
Dim dhedhe As New ByIskandar.CariKeDataBaseByIskandar
Dim cmnd As New OleDb.OleDbCommand
Dim ksr As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")
Private Sub save_36109020_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save_36109020.Click
If t1_36109020.Text.Length = 0 Then
MsgBox("Fill the blank")
Exit Sub
End If
If t2_36109020.Text.Length = 0 Then
MsgBox("Fill the blank")
Exit Sub
End If
If Val(t3_36109020.Text) = 0 Then
MsgBox("Fill the blank")
Exit Sub
End If
If Val(t4_36109020.Text) = 0 Then
MsgBox("Fill the blank")
Exit Sub
End If
dhedhe.AturPencarianDataBase("Barang", "KodeBarang", t1_36109020.Text, 1, ksr)
If dhedhe.JumlanBaris > 0 Then
MsgBox("kode seperti sudah ada")
Exit Sub
End If
cmnd = New OleDb.OleDbCommand("insert into barang (kodebarang, namabarang, hargajual, jumlahbarang) values ('" & t1_36109020.Text & "','" & t2_36109020.Text & "'," & Val(t3_36109020.Text) & "," & Val(t4_36109020.Text) & ")", ksr)
ksr.Open()
cmnd.ExecuteNonQuery()
ksr.Close()
cmnd.Dispose()
t1_36109020.Text = ""
t2_36109020.Text = ""
t3_36109020.Text = ""
t4_36109020.Text = ""
Form32A_36109020.dhedhe()
End Sub
End Class
Latihan 32C
Public Class Form32C_36109020
Dim dhedhe As New ByIskandar.CariKeDataBaseByIskandar
Dim cmnd As New OleDb.OleDbCommand
Dim ksr As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Databarang.ACCDB")
Private Sub save_36109020_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save_36109020.Click
If t1_36109020.Text.Length = 0 Then
MsgBox("Fill the blank")
Exit Sub
End If
If t2_36109020.Text.Length = 0 Then
MsgBox("Fill the blank")
Exit Sub
End If
If Val(t3_36109020.Text) = 0 Then
MsgBox("Fill the blank")
Exit Sub
End If
If Val(t4_36109020.Text) = 0 Then
MsgBox("Fill the blank")
Exit Sub
End If
If t1_36109020.Text <> KB_36109020.Text Then
dhedhe.AturPencarianDataBase("Barang", "KodeBarang", t1_36109020.Text, 1, ksr)
If dhedhe.JumlanBaris > 0 Then
MsgBox("Kode Seperti itu sudah ada")
Exit Sub
End If
End If
cmnd = New OleDb.OleDbCommand("update barang set kodebarang = '" & t1_36109020.Text & "', namabarang = '" & t2_36109020.Text & "', hargajual = " & Val(t3_36109020.Text) & ", jumlahbarang = " & Val(t4_36109020.Text) & " where kodebarang = '" & KB_36109020.Text & "'", ksr)
ksr.Open()
cmnd.ExecuteNonQuery()
ksr.Close()
cmnd.Dispose()
t1_36109020.Text = ""
t2_36109020.Text = ""
t3_36109020.Text = ""
t4_36109020.Text = ""
KB_36109020.Text = ""
Form32A_36109020.dhedhe()
End Sub
End Class
Tidak ada komentar:
Posting Komentar