DESIGN DATABASE
FIELD NAME
|
TYPE
|
SIZE
|
KODE_POS
|
CHAR
|
20
|
PROVINSI
|
CHAR
|
20
|
KABUPATEN_KOTA
|
CHAR
|
20
|
DESIGN FORM KODE POS
LISTING PROGRAM KODE POS
Imports
MySql.Data.MySqlClient
Public Class kode_pos
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()
kodepos.Text = ""
provinsi.Text = ""
kabupaten_kota.Text = ""
rubahtombol(True,
False, False, False, True)
kodepos.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_pos",
80, HorizontalAlignment.Center)
lv.Columns.Add("provinsi",
80, HorizontalAlignment.Left)
lv.Columns.Add("kabupaten_kota",
180, HorizontalAlignment.Left)
lv.GridLines = True
lv.FullRowSelect = True
lv.View = View.Details
End Sub
Sub
isitabel()
lv.Items.Clear()
sql = "select*from
kode_pos"
cmd = New
MySqlCommand(sql, db)
rs = cmd.ExecuteReader
Try
While
rs.Read
Dim
lst As New
ListViewItem
lst.Text = rs("kode_pos")
lst.SubItems.Add(rs("provinsi"))
lst.SubItems.Add(rs("kabupaten_kota"))
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 kode_pos(kode_pos,provinsi,kabupaten_kota)" & _
"values('"
& kodepos.Text & _
"','"
& provinsi.Text & _
"','"
& kabupaten_kota.Text & "')"
pesan = "data telah tersimpan"
Case
1
sql = "update
kode_pos set provinsi='" & provinsi.Text & "', " & _
"kabupaten_kota='"
& kabupaten_kota.Text & "' "
& _
"where
kode_pos='" & kodepos.Text & "'"
pesan = "data telah terupdate"
Case
2
sql = "delete
from kode_pos where kode_pos='" & kodepos.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()
kodepos.Text = rs("kode_pos")
provinsi.Text = rs("provinsi")
kabupaten_kota.Text = rs("kabupaten_kota")
rubahtombol(False,
True, True, True, True)
simpan.Text = "Edit"
kodepos.Enabled = False
End Sub
Private Sub kode_pos_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()
kodepos.Focus()
End Sub
Private Sub batal_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles batal.Click
Call
bersih()
kodepos.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 kodepos_KeyPress(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles
kodepos.KeyPress
Dim
tombol As Integer
= Asc(e.KeyChar)
If
tombol = 13 Then
Dim
x As String
If
kodepos.Text = "" Then
MsgBox("isi
kode terlebih dahulu")
Else
sql = "select
* from kode_pos where kode_pos='" & kodepos.Text & "'"
cmd = New
MySqlCommand(sql, db)
rs = cmd.ExecuteReader
Try
Call
showdb()
Catch
ex As Exception
x = kodepos.Text
bersih()
kodepos.Text = x
rubahtombol(False, True, False, True, False)
simpan.Text = "Simpan"
End
Try
provinsi.Focus()
rs.Close()
End
If
End If
End Sub
End Class
DESIGN CETAK KODE POS
Tidak ada komentar:
Posting Komentar