Form Menu
Listing Program Menu
Public Class Menu_Utama
Private Sub DataPesananToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
DataPesananToolStripMenuItem.Click
Form3.Show()
End Sub
Private Sub KeluarProgramToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
KeluarProgramToolStripMenuItem.Click
End
End Sub
Private Sub LapKamarToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
LapKamarToolStripMenuItem.Click
Dim
laporan As New
Rptpesanan
cetak.CrystalReportViewer1.ReportSource
= laporan
cetak.Show()
End Sub
End Class
Form Input
Listing Program Input
Imports
MySql.Data.MySqlClient
Public Class Form3
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=karaoke"
Try
db.ConnectionString = sql
db.Open()
Catch
ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Sub
bersih()
kode.Text = ""
nama.Text = ""
harga.Text = ""
RUBAHBUTTON(True,
False, False, False, False, True)
kode.Enabled = True
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)
Btnbaru.Enabled = Btn1
Btnsimpan.Enabled = Btn2
Btnedit.Enabled = Btn3
Btnhapus.Enabled = Btn4
Btnbatal.Enabled = Btn5
Btnkeluar.Enabled = Btn6
End Sub
Sub
buattabel()
Lv.Columns.Add("kode",
80, HorizontalAlignment.Center)
lv.Columns.Add("nama",
180, HorizontalAlignment.Left)
Lv.Columns.Add("harga",
80, HorizontalAlignment.Left)
lv.GridLines = True
lv.FullRowSelect = True
lv.View = View.Details
End Sub
Sub
ISITABEL()
lv.Items.Clear()
sql = "select
* from pesanan"
cmd = New
MySqlCommand(sql, db)
rs = cmd.ExecuteReader
Try
While
rs.Read
Dim
ist As New
ListViewItem
ist.Text = rs("kode")
ist.SubItems.Add(rs("nama"))
ist.SubItems.Add(rs("harga"))
lv.Items.Add(ist)
End
While
Catch
ex As Exception
MsgBox(ex.Message)
End Try
rs.Close()
End Sub
Sub
prosesdb(ByVal log As
Integer)
Dim
pesan As String
= ""
Select Case log
Case
0
sql = "insert
into pesanan(kode, nama, harga)" & _
"values
('" & kode.Text & _
"','"
& nama.Text & _
"','"
& harga.Text & "')"
pesan = "data telah disimpan"
Case
1
sql = "update
pesanan set nama='" & nama.Text & "',
" & _
"harga='"
& harga.Text & "'," &
_
"where
kode='" & kode.Text & "'"
pesan = "telah di update"
Case
2
sql = "delete
from pesanan where kode='" & kode.Text & "'"
pesan = "data telah dihapus"
End Select
Try
cmd = New
MySqlCommand(sql, db)
cmd.ExecuteNonQuery()
MsgBox(pesan,
MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "komfirmasi")
Call
bersih()
Call
ISITABEL()
Catch
ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Sub
showdb()
rs.Read()
kode.Text = rs("kode")
nama.Text = rs("nama")
harga.Text = rs("harga")
RUBAHBUTTON(False,
False, True, True, True, False)
Btnedit.Text = "update"
kode.Enabled = False
End Sub
Private Sub Form3_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Call
opendb()
Call
bersih()
Call
ISITABEL()
Call
buattabel()
End Sub
Private Sub Btnbaru_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnbaru.Click
Call
bersih()
kode.Focus()
End Sub
Private Sub Btnedit_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnedit.Click
If
Btnedit.Text = "update" Then prosesdb(0) Else
prosesdb(1)
End Sub
Private Sub Btnhapus_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnhapus.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 Btnkeluar_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnkeluar.Click
Me.Close()
End Sub
Private Sub Btnbatal_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnbatal.Click
Call
bersih()
kode.Focus()
End Sub
Private Sub Btnsimpan_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnsimpan.Click
If
Btnsimpan.Text = "simpan" Then prosesdb(0) Else
prosesdb(1)
End Sub
Private Sub Kode_KeyPress(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles
kode.KeyPress
Dim
tombol As Integer
= Asc(e.KeyChar)
If
tombol = 13 Then
Dim
x As String
If
kode.Text = "" Then
MsgBox("isi
kode terlebih dahulu")
Else
sql = "select*
from pesanan where kode='" & kode.Text & "'"
cmd = New
MySqlCommand(sql, db)
rs = cmd.ExecuteReader
Try
Call
showdb()
Catch
ex As Exception
x = kode.Text
bersih()
kode.Text = x
RUBAHBUTTON(False, True, False, False, True, False)
Btnsimpan.Text = "simpan"
End
Try
nama.Focus()
rs.Close()
End
If
End If
End Sub
End Class
Tampilan Form Cetak Laporan
Demikilahlah postingan saya
Nama : Yusni Dewi NPM : 1102088
Selamat Belajar
VB Net
Tidak ada komentar:
Posting Komentar