0% found this document useful (0 votes)
9 views6 pages

Contoh Relasi Antar Form Pada

Uploaded by

bimajayanusa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Contoh Relasi Antar Form Pada

Uploaded by

bimajayanusa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

PRAKTIKUM PROGRAM CLIENT SERVER

Buatlah database Dengan Struktur Sebagai Berikut :

CREATE DATABASE dbsewa;

USE dbsewa;

CREATE TABLE buku (


idbuku INT(11) PRIMARY KEY AUTO_INCREMENT,
judulbuku VARCHAR(30),
) ENGINE=INNODB;

CREATE TABLE sewa (


kodesewa CHAR(10)PRIMARY KEY,
tglsewa DATE ,
namapenyewa VARCHAR(30),
sewaidbuku INT,
lamasewa INT,
FOREIGN KEY (sewaidbuku) REFERENCES buku (idbuku) ON UPDATE
CASCADE
) ENGINE=INNODB;

Desain Form
PRAKTIKUM PROGRAM CLIENT SERVER

Koding Pada FORM1

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)

'tambahkan button edit


Dim chapus As New DataGridViewButtonColumn
chapus.Name = "chapus"
chapus.HeaderText = ""
chapus.FlatStyle = FlatStyle.Popup
chapus.DefaultCellStyle.ForeColor = Color.Red
chapus.Text = "Hapus"
chapus.Width = 50
chapus.UseColumnTextForButtonValue = True
dg.Columns.Add(chapus)
End Sub

Sub tampil(ByVal sql As String)


kon.Close()
kon.Open()
perintah.Connection = kon
perintah.CommandType = CommandType.Text
perintah.CommandText = sql
mda.SelectCommand = perintah
ds.Tables.Clear()
mda.Fill(ds, "data")
dg.DataSource = (ds.Tables("data"))
setdg()
kon.Close()
End Sub
PRAKTIKUM PROGRAM CLIENT SERVER

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

Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs)


Handles Me.Activated
dg.Columns.Clear()
Call tampil("QUERY ISI SENDIRI ")
Call setdg()
Call buattombol()
End Sub

Private Sub tkode_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles tkode.TextChanged
Call cekkode()
End Sub
PRAKTIKUM PROGRAM CLIENT SERVER

Private Sub dg_CellContentClick(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.DataGridViewCellEventArgs) Handles dg.CellContentClick
i = dg.CurrentRow.Index
id = dg.Rows.Item(i).Cells(0).Value
If e.ColumnIndex = 5 Then
tkode.Text = id
tkode.Enabled = False
btsimpan.Text = "UPDATE"

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

Private Sub btsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles btsimpan.Click
If btsimpan.Text = "SIMPAN" Then
kon.Open()
perintah.Connection = kon
perintah.CommandType = CommandType.Text
perintah.CommandText = " QUERY ISI SENDIRI "

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

Private Sub btcari_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles btcari.Click
Form2.ShowDialog()
End Sub
End Class
PRAKTIKUM PROGRAM CLIENT SERVER

Koding Pada Form2


Imports MySql.Data.MySqlClient
Public Class Form2
Dim strkon As String = "server=localhost;uid=root;database=dbsewa"
Dim kon As New MySqlConnection(strkon)
Dim perintah As New MySqlCommand
Dim mda As New MySqlDataAdapter
Dim ds As New DataSet
Dim cek As MySqlDataReader
Dim i As Integer
Dim id, judul As String

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 tampil(ByVal sql As String)


kon.Close()
kon.Open()
perintah.Connection = kon
perintah.CommandType = CommandType.Text
perintah.CommandText = sql
mda.SelectCommand = perintah
ds.Tables.Clear()
mda.Fill(ds, "data")
dg.DataSource = (ds.Tables("data"))
setdg()
kon.Close()
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

Private Sub btsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles btsimpan.Click
kon.Open()
perintah.Connection = kon
perintah.CommandType = CommandType.Text
perintah.CommandText = "QUERY ISI SENDIRI"
perintah.ExecuteNonQuery()
kon.Close()
MsgBox("Data Sukses Tersimpan", MsgBoxStyle.Information, "Informasi")
End Sub

Private Sub Form2_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Activated
dg.Columns.Clear()
Call tampil("QUERY ISI SENDIRI")
Call setdg()
Call buattombol()
End Sub
PRAKTIKUM PROGRAM CLIENT SERVER

Private Sub dg_CellContentClick(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.DataGridViewCellEventArgs) Handles dg.CellContentClick
i = dg.CurrentRow.Index
id = dg.Rows.Item(i).Cells(0).Value
judul = dg.Rows.Item(i).Cells(1).Value
If e.ColumnIndex = 2 Then
Form1.tidbuku.Text = id
Form1.tbuku.Text = judul
Me.Close()

End If
End Sub
End Class

Hasil Running Program :

You might also like