You are on page 1of 8

Nama : Salsabila Tasmara

Nim : 0702192027

Prodi : Sistem Informasi-2/ Semester III

Matkul : Pemograman Visual

1. Database

2. Design Form
3. Source Code

Imports MySql.Data.MySqlClient
Public Class Form1
Public db As New MySql.Data.MySqlClient.MySqlConnection
Public sql As String
Public cmd As MySqlCommand
Public rs As MySqlDataReader

Sub opendb()
sql = "server=localhost;uid=root;pwd=;database=UAS_db"
Try
db.ConnectionString = sql
db.Open()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Sub BuatTabel()
LV.Columns.Add("ID Property", 40, HorizontalAlignment.Center)
LV.Columns.Add("Type", 40, HorizontalAlignment.Left)
LV.Columns.Add("L. Tanah", 131, HorizontalAlignment.Left)
LV.Columns.Add("L. Bangunan", 65, HorizontalAlignment.Left)
LV.Columns.Add("Tahun", 65, HorizontalAlignment.Left)
LV.Columns.Add("Spesifikasi", 131, HorizontalAlignment.Left)
LV.Columns.Add("Modal", 55, HorizontalAlignment.Left)
LV.Columns.Add("Jual", 55, HorizontalAlignment.Left)
LV.GridLines = True
LV.FullRowSelect = True
LV.View = View.Details
End Sub

Sub IsiTabel()
LV.Items.Clear()
sql = "Select*From Property"
cmd = New MySqlCommand(sql, db)
rs = cmd.ExecuteReader
Try
While rs.Read
Dim lst As New ListViewItem
lst.Text = rs("idprop")
lst.SubItems.Add(rs("type"))
lst.SubItems.Add(rs("luas_tanah"))
lst.SubItems.Add(rs("luas_bangunan"))
lst.SubItems.Add(rs("tahun_pembuatan"))
lst.SubItems.Add(rs("spesifikasi"))
lst.SubItems.Add(rs("harga_modal"))
lst.SubItems.Add(rs("harga_jual"))
LV.Items.Add(lst)
End While
Catch ex As Exception
MsgBox(ex.Message)
End Try
rs.Close()
End Sub

Sub Clear()
idp.Text = ""
type.Text = ""
luast.Text = ""
luasb.Text = ""
tahun.Text = ""
spek.Text = ""
modal.Text = ""
jual.Text = ""
End Sub

Sub RubahButton(ByVal Btn1 As Boolean, ByVal Btn2 As Boolean, ByVal Btn3 As


Boolean, ByVal Btn4 As Boolean, ByVal Btn5 As Boolean, ByVal Btn6 As Boolean)
create.Enabled = Btn1
read.Enabled = Btn2
update.Enabled = Btn3
delete.Enabled = Btn4
clr.Enabled = Btn5
ext.Enabled = Btn6
End Sub

Sub ProsesDB(ByVal log As Integer)


Dim Pesan As String = ""
Select Case log
Case 0
sql = "insert into Property(idprop, type, luas_tanah,
luas_bangunan, tahun_pembuatan, spesifikasi, harga_modal, harga_jual)" &
"values('" & idp.Text & "', '" & type.Text & "', '" & luast.Text & "', '" &
luasb.Text & "', '" & tahun.Text & "', '" & spek.Text & "', '" & modal.Text & "',
'" & jual.Text & "')"
Pesan = "Data telah disimpan!"
Case 1
sql = "update Property set type='" & type.Text & "', luas_tanah='"
& luast.Text & "', luas_bangunan='" & luasb.Text & "', tahun_pembuatan='" &
tahun.Text & "', spesifikasi='" & spek.Text & "', harga_modal='" & modal.Text &
"', harga_jual='" & jual.Text & "' where idprop='" & idp.Text & "'"
Pesan = "Data telah diupdate!"
Case 2
sql = "delete from Property where idprop='" & idp.Text & "'"
Pesan = "Data telah dihapus!"
End Select
Try
cmd = New MySqlCommand(sql, db)
cmd.ExecuteNonQuery()
MsgBox(Pesan, MsgBoxStyle.Information + MsgBoxStyle.OkOnly,
"Konfirmasi")
Call Clear()
Call IsiTabel()
create.Text = "Create"
read.Enabled = True
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Sub ShowDB()
rs.Read()
idp.Text = rs("idprop")
type.Text = rs("type")
luast.Text = rs("luas_tanah")
luasb.Text = rs("luas_bangunan")
tahun.Text = rs("tahun_pembuatan")
spek.Text = rs("spesifikasi")
modal.Text = rs("harga_modal")
jual.Text = rs("harga_jual")
RubahButton(False, True, True, False, True, False)
type.Focus()
End Sub

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


System.EventArgs) Handles MyBase.Load
Call opendb()
Call BuatTabel()
Call IsiTabel()
End Sub

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


System.EventArgs) Handles read.Click
Dim harga As String
harga = Microsoft.VisualBasic.Left(type.Text, 1)
Select Case harga
Case 1
modal.Text = "200000000"
jual.Text = Val(modal.Text) * 10 / 100 + Val(modal.Text)
Case 2
modal.Text = "250000000"
jual.Text = Val(modal.Text) * 12 / 100 + Val(modal.Text)
Case 3
modal.Text = "420000000"
jual.Text = Val(modal.Text) * 15 / 100 + Val(modal.Text)
Case 4
modal.Text = "550000000"
jual.Text = Val(modal.Text) * 18 / 100 + Val(modal.Text)
End Select
End Sub
Private Sub create_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles create.Click
If create.Text = "Create" Then ProsesDB(0) Else ProsesDB(1)
End Sub

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


System.EventArgs) Handles delete.Click
Dim x As String
x = MsgBox("Anda yakin ingin menghapus?", MsgBoxStyle.Information +
MsgBoxStyle.YesNo, "Hapus")
If x = vbYes Then
Call ProsesDB(2)
End If
End Sub

Private Sub LV_MouseClick(ByVal sender As Object, ByVal e As


System.Windows.Forms.MouseEventArgs) Handles LV.MouseClick
Dim aidi As String = LV.SelectedItems(0).SubItems(0).Text
Dim tip As String = LV.SelectedItems(0).SubItems(1).Text
Dim tnh As String = LV.SelectedItems(0).SubItems(2).Text
Dim bgn As String = LV.SelectedItems(0).SubItems(3).Text
Dim thn As String = LV.SelectedItems(0).SubItems(4).Text
Dim spk As String = LV.SelectedItems(0).SubItems(5).Text
Dim mdl As String = LV.SelectedItems(0).SubItems(6).Text
Dim jl As String = LV.SelectedItems(0).SubItems(7).Text

idp.Text = aidi
type.Text = tip
luast.Text = tnh
luasb.Text = bgn
tahun.Text = thn
spek.Text = spk
modal.Text = mdl
jual.Text = jl
End Sub

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


System.EventArgs) Handles clr.Click
Call Clear()
idp.Focus()
End Sub

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


System.EventArgs) Handles ext.Click
Me.Close()
End Sub

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


System.EventArgs) Handles update.Click
If idp.Text = "" Then
MsgBox("Isi ID Terlebih Dahulu")
Else
ProsesDB(1)
End If

End Sub
End Class
4. Layout Create

5. Update
6. Simpan

7. Delete

8. Crystal repot

You might also like