Contoh Relasi Antar Form Pada
Contoh Relasi Antar Form Pada
USE dbsewa;
Desain Form
PRAKTIKUM PROGRAM CLIENT SERVER
Imports MySql.Data.MySqlClient
Public Class Form1
Dim strkon As String = "server=localhost;uid=root;database=dbsewa"
Dim kon As New MySqlConnection(strkon)
Dim perintah As New MySqlCommand
Dim totbay, totharga, diskon As Double
Dim mda As New MySqlDataAdapter
Dim ds As New DataSet
Dim cek As MySqlDataReader
Dim i As Integer
Dim id, judul As String
Sub bersih()
tkode.Text = ""
tnama.Text = ""
tidbuku.Text = ""
tbuku.Text = ""
tlama.Text = ""
End Sub
Sub buattombol()
'tambahkan button edit
Dim cedit As New DataGridViewButtonColumn
cedit.Name = "cedit"
cedit.HeaderText = ""
cedit.FlatStyle = FlatStyle.Popup
cedit.DefaultCellStyle.ForeColor = Color.DarkGreen
cedit.Text = "Edit"
cedit.Width = 50
cedit.UseColumnTextForButtonValue = True
dg.Columns.Add(cedit)
Sub setdg()
dg.Columns(0).HeaderText = "Kode Sewa"
dg.Columns(1).HeaderText = "Tanggal Sewa"
dg.Columns(2).HeaderText = "Nama Penyewa"
dg.Columns(3).HeaderText = "Judul Buku"
dg.Columns(4).HeaderText = "Lama Sewa"
dg.Columns(0).Width = 100
dg.Columns(1).Width = 130
dg.Columns(2).Width = 150
dg.Columns(3).Width = 150
dg.Columns(4).Width = 80
End Sub
Sub cekkode()
kon.Open()
perintah.Connection = kon
perintah.CommandType = CommandType.Text
perintah.CommandText = "SELECT
kodesewa,tglsewa,namapenyewa,sewaidbuku,lamasewa,judulbuku from sewa " & _
" join buku on sewaidbuku=idbuku where kodesewa='" & tkode.Text & "'"
cek = perintah.ExecuteReader
cek.Read()
If cek.HasRows Then
dtsewa.Value = cek.Item("tglsewa")
tnama.Text = cek.Item("namapenyewa")
tidbuku.Text = cek.Item("sewaidbuku")
tbuku.Text = cek.Item("judulbuku")
tlama.Text = cek.Item("lamasewa")
End If
kon.Close()
End Sub
End If
If e.ColumnIndex = 9 Then
Dim x As Byte
x = MsgBox("Hapus data Penyewaan dengan kode " & id & " ?",
MsgBoxStyle.Critical + vbYesNo, "Konfirmasi")
If x = vbYes Then
kon.Open()
perintah.Connection = kon
perintah.CommandType = CommandType.Text
perintah.CommandText = " QUERY ISI SENDIRI "
perintah.ExecuteNonQuery()
kon.Close()
dg.Columns.Clear()
Call tampil("QUERY ISI SENDIRI ")
Call setdg()
Call buattombol()
Call bersih()
tkode.Enabled = True
End If
End If
End Sub
perintah.ExecuteNonQuery()
kon.Close()
MsgBox("Data Sukses Tersimpan", MsgBoxStyle.Information, "Informasi")
Call bersih()
Else
kon.Open()
perintah.Connection = kon
perintah.CommandType = CommandType.Text
perintah.CommandText = " QUERY ISI SENDIRI "
perintah.ExecuteNonQuery()
kon.Close()
MsgBox("Data Sukses DiUpdate", MsgBoxStyle.Information, "Informasi")
btsimpan.Text = "SIMPAN"
Call bersih()
tkode.Enabled = True
End If
End Sub
Sub buattombol()
'tambahkan button edit
Dim cpilih As New DataGridViewButtonColumn
cpilih.Name = "cpilih"
cpilih.HeaderText = ""
cpilih.FlatStyle = FlatStyle.Popup
cpilih.DefaultCellStyle.ForeColor = Color.DarkGreen
cpilih.Text = "Pilih"
cpilih.Width = 50
cpilih.UseColumnTextForButtonValue = True
dg.Columns.Add(cpilih)
End Sub
Sub setdg()
dg.Columns(0).HeaderText = "ID Buku"
dg.Columns(1).HeaderText = "Judul Buku"
g.Columns(0).Width = 80
dg.Columns(1).Width = 200
End Sub
End If
End Sub
End Class