Assalamu'alaikum...
bertemu lagi di postingan visual basic. kali ini saya akan membuat aplikasi penjualan/cicilan rumah berbasis database menggunakan Ms.Access. disini terdapat empat form,yang pertama form login, yang kedua form menu utama, yang ketiga form input, dan yang terakhir form 1.
pertama buat tabel database
Dibawah ini adalah perancangan database yang diberi nama tabelinput
Form Login
Source Code :
Imports System.Data.OleDb
Public Class FormLogin
Dim x, y
Private Sub jalankansql(ByVal sQl As String)
konek()
Dim objcmd As New OleDb.OleDbCommand
Try
objcmd.Connection = conn
objcmd.CommandType = CommandType.Text
objcmd.CommandText = sQl
objcmd.ExecuteNonQuery()
objcmd.Dispose()
MsgBox("Data Sudah Disimpan", vbInformation)
Catch ex As Exception
MsgBox("Tidak Bisa Menyimpan Data ke Database" & ex.Message)
End Try
End Sub
Private Sub butmasuk_Click(sender As Object, e As EventArgs) Handles butmasuk.Click
If textnama.Text = "" Or textsandi.Text = "" Then
MsgBox("Data Login Belum Lengkap")
Exit Sub
Else
konek()
CMD = New OleDbCommand("select * from tablepetugas where NamaPengguna ='" & textnama.Text & "' and KataSandi ='" & textsandi.Text & "'", conn)
RD = CMD.ExecuteReader
RD.Read()
If RD.HasRows Then
Me.Hide()
MenuUtama.Show()
textnama.Text = ""
textsandi.Text = ""
Else
MsgBox("Kode Admin atau Password Salah !")
End If
End If
End Sub
Private Sub butkeluar_Click(sender As Object, e As EventArgs) Handles butkeluar.Click
Dim x = MsgBox("Anda Yakin ?", MsgBoxStyle.OkCancel + MsgBoxStyle.Information, "Informasi")
If x = vbOK Then
Me.Close()
End If
End Sub
Private Sub FormLogin_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class
Public Class FormLogin
Dim x, y
Private Sub jalankansql(ByVal sQl As String)
konek()
Dim objcmd As New OleDb.OleDbCommand
Try
objcmd.Connection = conn
objcmd.CommandType = CommandType.Text
objcmd.CommandText = sQl
objcmd.ExecuteNonQuery()
objcmd.Dispose()
MsgBox("Data Sudah Disimpan", vbInformation)
Catch ex As Exception
MsgBox("Tidak Bisa Menyimpan Data ke Database" & ex.Message)
End Try
End Sub
Private Sub butmasuk_Click(sender As Object, e As EventArgs) Handles butmasuk.Click
If textnama.Text = "" Or textsandi.Text = "" Then
MsgBox("Data Login Belum Lengkap")
Exit Sub
Else
konek()
CMD = New OleDbCommand("select * from tablepetugas where NamaPengguna ='" & textnama.Text & "' and KataSandi ='" & textsandi.Text & "'", conn)
RD = CMD.ExecuteReader
RD.Read()
If RD.HasRows Then
Me.Hide()
MenuUtama.Show()
textnama.Text = ""
textsandi.Text = ""
Else
MsgBox("Kode Admin atau Password Salah !")
End If
End If
End Sub
Private Sub butkeluar_Click(sender As Object, e As EventArgs) Handles butkeluar.Click
Dim x = MsgBox("Anda Yakin ?", MsgBoxStyle.OkCancel + MsgBoxStyle.Information, "Informasi")
If x = vbOK Then
Me.Close()
End If
End Sub
Private Sub FormLogin_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class
Form Menu Utama
Source Code :
Public Class MenuUtama
Private Sub TambahToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles TambahToolStripMenuItem.Click
FormInput.Show()
Dim DataTambah As New FormInput
FormInput.MdiParent() = Me
Form1.Close()
End Sub
Private Sub TutupToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles TutupToolStripMenuItem.Click
Dim x = MsgBox("Apakah Anda Yakin ingin Keluar?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "KONFIRMASI")
If x = vbYes Then
Me.Close()
'End
End If
End Sub
Private Sub PencarianToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PencarianToolStripMenuItem.Click
Dim Datacari As New Form1
Form1.MdiParent() = Me
FormInput.Close()
Form1.Show()
End Sub
Private Sub MenuUtama_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class
Form Input
Source Code :
Imports System.Data.OleDb
Public Class FormInput
Dim x, y
Dim simpan As String
Dim edit As String
Private Sub jalankansql(ByVal sQl As String)
konek()
Dim objcmd As New OleDb.OleDbCommand
Try
objcmd.Connection = conn
objcmd.CommandType = CommandType.Text
objcmd.CommandText = sQl
objcmd.ExecuteNonQuery()
objcmd.Dispose()
MsgBox("Data Sudah Disimpan", vbInformation)
Catch ex As Exception
MsgBox("Tidak Bisa Menyimpan Data ke Database" & ex.Message)
End Try
End Sub
Public Sub clear()
cmbtanggal.Text = ""
cmbbulan.Text = ""
cmbtahun.Text = ""
TextBox1.Text = ""
id1.Text = ""
id2.Text = ""
id3.Text = ""
harrumah.Text = ""
tbwaktu.Text = ""
biayaawal.Text = ""
cicilan.Text = ""
tanah.Text = ""
kamar.Text = ""
tamu.Text = ""
klrga.Text = ""
mushola.Text = ""
dapur.Text = ""
kmandi.Text = ""
garasi.Text = ""
gudang.Text = ""
cbcicilan1.Text = ""
cicilan1.Text = ""
End Sub
Private Sub FormInput_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For a = 1 To 31
cmbtanggal.Items.Add(a)
Next
For b = 1 To 12
cmbbulan.Items.Add(b)
Next
For c = 2017 To 2025
cmbtahun.Items.Add(c)
Next
For d = 1 To 24
cbcicilan1.Items.Add(d)
Next
End Sub
Private Sub cmbbulan_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbbulan.SelectedIndexChanged
Select Case cmbbulan.Text
Case 1
bulan.Text = "Januari"
Case 2
bulan.Text = "Februari"
Case 3
bulan.Text = "Maret"
Case 4
bulan.Text = "April"
Case 5
bulan.Text = "Mei"
Case 6
bulan.Text = "Juni"
Case 7
bulan.Text = "Juli"
Case 8
bulan.Text = "Agustus"
Case 9
bulan.Text = "September"
Case 10
bulan.Text = "Oktober"
Case 11
bulan.Text = "November"
Case 12
bulan.Text = "Desember"
End Select
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles bttutup.Click
MenuUtama.Show()
Me.Hide()
End Sub
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
TextBox2.Text = "A"
tanah.Text = "50"
kamar.Text = "4"
tamu.Text = "1"
klrga.Text = "2"
dapur.Text = "1"
kmandi.Text = "3"
garasi.Text = "1"
gudang.Text = "1"
mushola.Text = "1"
tbwaktu.Text = "24"
harrumah.Text = "200000000"
End Sub
Private Sub RadioButton7_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton7.CheckedChanged
TextBox2.Text = "B"
tanah.Text = "40"
kamar.Text = "3"
tamu.Text = "1"
klrga.Text = "2"
dapur.Text = "1"
kmandi.Text = "2"
garasi.Text = "1"
gudang.Text = "1"
mushola.Text = "1"
tbwaktu.Text = "24"
harrumah.Text = "180000000"
End Sub
Private Sub RadioButton5_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton5.CheckedChanged
TextBox2.Text = "C"
tanah.Text = "30"
kamar.Text = "3"
tamu.Text = "1"
klrga.Text = "1"
dapur.Text = "1"
kmandi.Text = "2"
garasi.Text = "1"
gudang.Text = "1"
mushola.Text = "1"
tbwaktu.Text = "24"
harrumah.Text = "160000000"
End Sub
Private Sub RadioButton8_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton8.CheckedChanged
TextBox2.Text = "D"
tanah.Text = "20"
kamar.Text = "2"
tamu.Text = "1"
klrga.Text = "1"
dapur.Text = "1"
kmandi.Text = "1"
garasi.Text = "1"
gudang.Text = "1"
mushola.Text = "0"
tbwaktu.Text = "24"
harrumah.Text = "140000000"
End Sub
Private Sub cbcicilan1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbcicilan1.SelectedIndexChanged
Select Case cbcicilan1.Text
Case 1
cicilan1.Text = "23"
Case 2
cicilan1.Text = "22"
Case 3
cicilan1.Text = "21"
Case 4
cicilan1.Text = "20"
Case 5
cicilan1.Text = "19"
Case 6
cicilan1.Text = "18"
Case 7
cicilan1.Text = "17"
Case 8
cicilan1.Text = "16"
Case 9
cicilan1.Text = "15"
Case 10
cicilan1.Text = "14"
Case 11
cicilan1.Text = "13"
Case 12
cicilan1.Text = "12"
Case 13
cicilan1.Text = "11"
Case 14
cicilan1.Text = "10"
Case 15
cicilan1.Text = "9"
Case 16
cicilan1.Text = "8"
Case 17
cicilan1.Text = "7"
Case 18
cicilan1.Text = "6"
Case 19
cicilan1.Text = "5"
Case 20
cicilan1.Text = "4"
Case 21
cicilan1.Text = "3"
Case 22
cicilan1.Text = "2"
Case 23
cicilan1.Text = "1"
Case 24
cicilan1.Text = "0"
End Select
End Sub
Private Sub cmbtahun_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbtahun.SelectedIndexChanged
TextBox1.Text = cmbtanggal.Text + "-" + Strings.Left(bulan.Text, 3) + "-" + cmbtahun.Text
End Sub
Private Sub harrumah_KeyPress(sender As Object, e As KeyPressEventArgs) Handles harrumah.KeyPress
Dim harga1, hasil As Integer
harga1 = harrumah.Text
hasil = (harga1 * 10) / 100
biayaawal.Text = hasil
End Sub
Private Sub har1_TextChanged(sender As Object, e As EventArgs) Handles harrumah.TextChanged
End Sub
Private Sub tbwaktu_KeyPress(sender As Object, e As KeyPressEventArgs) Handles tbwaktu.KeyPress
Dim harga1, hasil As Integer
harga1 = harrumah.Text
hasil = (harga1 * 10) / 100
biayaawal.Text = hasil
End Sub
Private Sub biayaawal_KeyPress(sender As Object, e As KeyPressEventArgs) Handles biayaawal.KeyPress
Dim harga1, harga2, harga3, hasil As Integer
harga1 = harrumah.Text
harga2 = tbwaktu.Text
harga3 = biayaawal.Text
hasil = (harga1 - harga3) / harga2
cicilan.Text = hasil
End Sub
Private Sub btsimpan_Click(sender As Object, e As EventArgs) Handles btsimpan.Click
conn.Close()
conn.Open()
If TextBox1.Text = "" Or id1.Text = "" Or id2.Text = "" Or id3.Text = "" Or TextBox2.Text = "" Or tanah.Text = "" Or kamar.Text = "" Or tamu.Text = "" Or klrga.Text = "" Or mushola.Text = "" Or dapur.Text = "" Or kmandi.Text = "" Or gudang.Text = "" Or gudang.Text = "" Then
MsgBox("Data Belum Lengkap")
End If
simpan = "INSERT INTO tableinput (Tanggal, NoPembelian, Nama, Alamat, TipeRumah, LuasTanah, Kamar, RuangTamu, RuangKeluarga, Mushola, Dapur, KamarMandi, Garasi, Gudang) VALUES ('" & TextBox1.Text & "','" & id1.Text & "','" & id2.Text & "','" & id3.Text & "','" & TextBox2.Text & "','" & tanah.Text & "','" & kamar.Text & "','" & tamu.Text & "','" & klrga.Text & "','" & mushola.Text & "','" & dapur.Text & "','" & kmandi.Text & "','" & garasi.Text & "','" & gudang.Text & "')"
jalankansql(simpan)
MsgBox("Berhasil Di Simpan", vbInformation)
clear()
cmbtanggal.Focus()
End Sub
Private Sub bttambah_Click(sender As Object, e As EventArgs) Handles bttambah.Click
clear()
End Sub
Private Sub btubah_Click(sender As Object, e As EventArgs) Handles btubah.Click
conn.Close()
conn.Open()
edit = "UPDATE tableinput SET Tanggal ='" & TextBox1.Text & "',Nama ='" & id2.Text & "',Alamat ='" & id3.Text & "',TipeRumah ='" & TextBox2.Text & "',LuasTanah ='" & tanah.Text & "',Kamar ='" & kamar.Text & "',RuangTamu='" & tamu.Text & "',RuangKeluarga ='" & klrga.Text & "',Mushola ='" & mushola.Text & "',Dapur ='" & dapur.Text & "',KamarMandi ='" & kmandi.Text & "',Garasi ='" & garasi.Text & "',Gudang ='" & gudang.Text & "' WHERE NoPembelian=" & id1.Text & ""
jalankansql(edit)
MsgBox("Berhasil Di Ubah", vbInformation)
clear()
cmbtanggal.Focus()
End Sub
Private Sub btncari_Click(sender As Object, e As EventArgs) Handles btncari.Click
Dim x As String = id1.Text
conn.Close()
conn.Open()
CMD = New OleDbCommand("SELECT * FROM tableinput where NoPembelian like '%" + x + "%'", conn)
RD = CMD.ExecuteReader
RD.Read()
If RD.HasRows Then
DA = New OleDbDataAdapter("select * from tableinput where NoPembelian like '%" + x + "%'", conn)
DS = New DataSet
DA.Fill(DS, "Ketemu")
TextBox1.Text = RD.Item(0)
id2.Text = RD.Item(2)
id3.Text = RD.Item(3)
TextBox2.Text = RD.Item(4)
tanah.Text = RD.Item(5)
kamar.Text = RD.Item(6)
tamu.Text = RD.Item(7)
klrga.Text = RD.Item(8)
mushola.Text = RD.Item(9)
dapur.Text = RD.Item(10)
kmandi.Text = RD.Item(11)
garasi.Text = RD.Item(12)
gudang.Text = RD.Item(13)
Else
id1.Text = "No Pembeli Tidak Ada"
id1.Text = ""
id1.Focus()
End If
RD.Close()
End Sub
Private Sub Label23_Click(sender As Object, e As EventArgs) Handles Label23.Click
End Sub
End Class
Form 1/Form Datagridview
Screenshoot Database Ms.Access
Selesai, semoga bermanfaat
Tidak ada komentar:
Posting Komentar