DESIGN DATABASE
FIELD NAME
|
TYPE
|
SIZE
|
KODE_PENERIMA
|
CHAR
|
20
|
NAMA_PENERIMA
|
CHAR
|
20
|
ALAMAT_PENERIMA
|
CHAR
|
20
|
TANGGAL_TERIMA
|
CHAR
|
20
|
DESIGN FORM PENERIMA
LISTING PROGRAM PENERIMA
Imports
MySql.Data.MySqlClient
Public Class penerima
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=
dwijuliani"
Try
db.ConnectionString = sql
db.Open()
Catch
ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Sub
bersih()
kode_penerima.Text = ""
nama_penerima.Text = ""
alamat_penerima.Text = ""
tanggal_terima.Text = ""
rubahtombol(True,
False, False, False, True)
kode_penerima.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)
baru.Enabled = btn1
simpan.Enabled = btn2
hapus.Enabled = btn3
batal.Enabled = btn4
keluar.Enabled = btn5
End Sub
Sub
buattabel()
lv.Columns.Add("kode_penerima",
80, HorizontalAlignment.Center)
lv.Columns.Add("nama_penerima",
180, HorizontalAlignment.Left)
lv.Columns.Add("alamat_penerima",
80, HorizontalAlignment.Left)
lv.Columns.Add("tanggal_terima",
100, HorizontalAlignment.Left)
lv.GridLines = True
lv.FullRowSelect = True
lv.View = View.Details
End Sub
Sub isitabel()
lv.Items.Clear()
sql = "select*from
penerima"
cmd = New
MySqlCommand(sql, db)
rs = cmd.ExecuteReader
Try
While
rs.Read
Dim
lst As New
ListViewItem
lst.Text = rs("kode_penerima")
lst.SubItems.Add(rs("nama_penerima"))
lst.SubItems.Add(rs("alamat_penerima"))
lst.SubItems.Add(rs("tanggal_terima"))
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 penerima(kode_penerima,nama_penerima,alamat_penerima,tanggal_terima)"
& _
"values('"
& kode_penerima.Text & _
"','"
& nama_penerima.Text & _
"','"
& alamat_penerima.Text & _
"','"
& tanggal_terima.Text & "')"
pesan = "data telah tersimpan"
Case
1
sql = "update
penerima set nama_penerima='" & nama_penerima.Text & "', " & _
"alamat_penerima='"
& alamat_penerima.Text & "',"
& _
"tanggal_terima='"
& tanggal_terima.Text & "' "
& _
"where
kode_penerima='" & kode_penerima.Text & "'"
pesan = "data telah terupdate"
Case
2
sql = "delete
from penerima where kode_penerima='" & kode_penerima.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_penerima.Text = rs("kode_penerima")
nama_penerima.Text = rs("nama_penerima")
alamat_penerima.Text = rs("alamat_penerima")
tanggal_terima.Text = rs("tanggal_terima")
rubahtombol(False,
True, True, True, True)
simpan.Text = "Edit"
kode_penerima.Enabled = False
End Sub
Private Sub penerima_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 baru_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles baru.Click
Call
bersih()
kode_penerima.Focus()
End Sub
Private Sub batal_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles batal.Click
Call
bersih()
kode_penerima.Focus()
End Sub
Private Sub keluar_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles keluar.Click
End
End Sub
Private Sub hapus_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles hapus.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 simpan_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles simpan.Click
If
simpan.Text = "Simpan" Then prosesdb(0) Else
prosesdb(1)
End Sub
Private Sub kode_penerima_KeyPress(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles
kode_penerima.KeyPress
Dim
tombol As Integer
= Asc(e.KeyChar)
If
tombol = 13 Then
Dim
x As String
If
kode_penerima.Text = "" Then
MsgBox("isi
kode terlebih dahulu")
Else
sql = "select
* from penerima where kode_penerima='" & kode_penerima.Text
& "'"
cmd = New
MySqlCommand(sql, db)
rs = cmd.ExecuteReader
Try
Call
showdb()
Catch
ex As Exception
x = kode_penerima.Text
bersih()
kode_penerima.Text = x
rubahtombol(False, True, False, True, False)
simpan.Text = "Simpan"
End
Try
nama_penerima.Focus()
rs.Close()
End
If
End If
End Sub
End Class
DESIGN CETAK PENERIMA
Tidak ada komentar:
Posting Komentar