1. Form Menu
Listing Program Menu
Public Class Form1
Private Sub DokterToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
DokterToolStripMenuItem.Click
pengirim.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 LaaporanDokterToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
LaaporanDokterToolStripMenuItem.Click
laporan_pengirim.Show()
End Sub
End Class
2. Form Input
Listing Program Input
Imports
MySql.Data.MySqlClient
Public Class pengirim
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=pengirim"
Try
db.ConnectionString = sql
db.Open()
Catch
ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Sub
bersih()
kode.Text = ""
nama_pengirm.Text = ""
alamat_pengirim.Text = ""
tanggal_kirim.Text = ""
rubahtombol(True,
False, False, False, True)
kode.Enabled = True
End Sub
Sub
rubahtombol(ByRef btn1 As
Boolean, ByVal
btn2 As Boolean,
ByVal btn3 As Boolean, ByVal btn4 As Boolean, ByVal btn5 As Boolean)
BR.Enabled = btn1
SMPN.Enabled = btn2
HPS.Enabled = btn3
BTL.Enabled = btn4
KLR.Enabled = btn5
End Sub
Sub
buattabel()
lv.Columns.Add("kode",
80, HorizontalAlignment.Center)
lv.Columns.Add("nama_pengirim",
180, HorizontalAlignment.Left)
lv.Columns.Add("alamat_pengirim",
80, HorizontalAlignment.Left)
lv.Columns.Add("tanggal_kirim",
100, HorizontalAlignment.Left)
lv.GridLines = True
lv.FullRowSelect = True
lv.View = View.Details
End Sub
Sub
isitabel()
lv.Items.Clear()
sql = "select*from
pengirim"
cmd = New
MySqlCommand(sql, db)
rs = cmd.ExecuteReader
Try
While
rs.Read
Dim
lst As New
ListViewItem
lst.Text = rs("kode")
lst.SubItems.Add(rs("nama_pengirim"))
lst.SubItems.Add(rs("alamat_pengirim"))
lst.SubItems.Add(rs("tanggal_kirim"))
lv.Items.Add(lst)
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 pengirim(kode,nama_pengirim,alamat_pengirim,tanggal_kirim)"
& _
"values('"
& kode.Text & _
"','"
& nama_pengirm.Text & _
"','"
& alamat_pengirim.Text & _
"','"
& tanggal_kirim.Text & "')"
pesan = "data telah tersimpan"
Case
1
sql = "update
pengirim set nama_pengirim='" & nama_pengirm.Text & "', " & _
"alamat_pengirim='"
& alamat_pengirim.Text & "',"
& _
"tanggal_kirim='"
& tanggal_kirim.Text & "' "
& _
"where
kode='" & kode.Text & "'"
pesan = "data telah terupdate"
Case
2
sql = "delete
from pengirim where kode='" & kode.Text & "'"
pesan = "data telah dihapus"
End Select
Try
cmd = New
MySqlCommand(sql, db)
cmd.ExecuteNonQuery()
MsgBox(pesan,
MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "konfirmasi")
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_pengirm.Text = rs("nama_pengirim")
alamat_pengirim.Text = rs("alamat_pengirim")
tanggal_kirim.Text = rs("tanggal_kirim")
rubahtombol(False,
True, True, True, True)
SMPN.Text = "EDIT"
kode.Enabled = False
End Sub
Private Sub pengirim_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Call
opendb()
Call
bersih()
Call
buattabel()
Call isitabel()
End Sub
Private Sub BR_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles BR.Click
Call
bersih()
kode.Focus()
End Sub
Private Sub BTL_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles BTL.Click
Call
bersih()
kode.Focus()
End Sub
Private Sub KLR_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles KLR.Click
End
End Sub
Private Sub HPS_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles HPS.Click
Dim x As String
x = MsgBox("anda
yakin akan dihapus", MsgBoxStyle.Information + MsgBoxStyle.YesNo, "hapus")
If x =
vbYes Then
Call
prosesdb(2)
End If
End Sub
Private Sub SMPN_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles SMPN.Click
If
SMPN.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 pengirim 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
rubahtombol(False, True, False, True, False)
SMPN.Text = "SIMPAN"
End Try
nama_pengirm.Focus()
rs.Close()
End
If
End If
End Sub
End Class
3. Desain Form Cetak Laporan
Listing Program Cetak Laporan
Public Class laporan_pengirim
Private Sub crv_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim
Laporan As New
rptpengirim
With Me.crv
.DisplayGroupTree = False
.ReportSource = Laporan
.Refresh()
End With
End Sub
End Class
Tampilan Form Cetak Laporan
Demikianlah Postingan Saya NAMA: DWI JULIANI NPM: 1102127
Selamat Belajar VB Net
Tidak ada komentar:
Posting Komentar