Bismillah
Silahkan ikuti dengan seksama langkah-langkah berikut ini.
1. Buat database di MYSQL dengan nama db_evoting
2. Kemudian design tabel seperti, pola gambar berikut ini:
Nama tabel : t_sekolah
Nama tabel : t_calon
Nama tabel: t_foto
3. Jika pembuatan database dan tabel sudah selesai, selanjutnya kita buka aplikasi VB.NET dan design form serta mengetikkan codingnya, menyerupai berikut ini:
a. Tambahkan Modul kemudian ketik coding koneksi database berikut ini:
b. Buat Form Input Identitas Sekolah
Objek yang dipakai : Label, Textbox, dan Button. Setting properties diubahsuaikan sendiri.
Ketik codingnya :
c. Buat Form Input Calon
Objek yang digunakan: Label, Textbox, Button, Groupbox, Picturebox, OpenFileDialog1. Setting properties disesuaikan.
Ketikkan codingnya:
d. Buat Form Surat Suara
Objek yang dipakai : Label, Button, Picturebox. Setting properties disesuaikan.
Ketikkan codingnya:
e. Buat Form Login
Objek yang digunakan: Label, LinkLabel, Textbox, Button, Picturebox. Settingan properties disesuaikan.
Ketik codingnya:
4. Jika design form dan pengetikkan codingnya sudah selesai, maka selanjutnya tinggal di jalankan (Tekan F5), jangan lupa sebelumnya atur terlebih dahulu Startup Formnya pada Form Login.
Baca juga : Cara Mengkoneksikan Client Server pada VB.NET dengan database MYSQL
Baca juga : Cara Membuat Modul Koneksi di VB.NET
Sahabat baiq yang berbahagia. Di periode digital ini, proses transformasi banyak sekali acara yang bersifat konvensional sudah banyak beralih ke cara digital (terkomputerisasi). Satu diantaranya yaitu proses pemilihan kepala negara atau kawasan yang dibeberapa negara sudah beralih dengan memakai komputer dan lebih dikenal dengan istilah e-voting. E-voting merupakan salah satu bentuk transformasi dari cara konvensional menjadi terkomputerisasi. Bagaimana dengan di Indonesia? Ada beberapa acara di negara kita tercinta juga yang sudah melaksanakan transformasi dari cara konvensional menjadi terkomputerisasi, semisal Ujian Nasional Berbasis Komputer (UNBK). Namun demikian, untuk pemilihan presiden atau kepada kawasan memang belum menerapkan e-voting ini, akan tetapi dalam skala kecil semisal pemilihan ketua OSIS di beberapa sekolah hal tersebut sudah dilakukan.
OK, sobat baiq, kali ini saya akan coba membuatkan wacana cara menciptakan aplikasi e-voting dengan memakai VB.NET berbasis client server dengan database MYSQL.
Bagaimana cara menciptakan aplikasi e-voting di VB.NET?
Silahkan ikuti dengan seksama langkah-langkah berikut ini.
1. Buat database di MYSQL dengan nama db_evoting
2. Kemudian design tabel seperti, pola gambar berikut ini:
Nama tabel : t_sekolah
Nama tabel : t_calon
Nama tabel: t_foto
3. Jika pembuatan database dan tabel sudah selesai, selanjutnya kita buka aplikasi VB.NET dan design form serta mengetikkan codingnya, menyerupai berikut ini:
a. Tambahkan Modul kemudian ketik coding koneksi database berikut ini:
Imports System.Data.Odbc
Module Module1
Public konek As OdbcConnection
Public da As OdbcDataAdapter
Public ds As DataSet
Public cmd As OdbcCommand
Public rd As OdbcDataReader
Public str As String
Sub Koneksi()
str = "driver={mysql odbc 3.51 driver};database=db_evoting;server=localhost;uid=pabaiq;pwd=12345"
konek = New OdbcConnection(str)
If konek.State = ConnectionState.Closed Then
konek.Open()
End If
End Sub
End Module
Module Module1
Public konek As OdbcConnection
Public da As OdbcDataAdapter
Public ds As DataSet
Public cmd As OdbcCommand
Public rd As OdbcDataReader
Public str As String
Sub Koneksi()
str = "driver={mysql odbc 3.51 driver};database=db_evoting;server=localhost;uid=pabaiq;pwd=12345"
konek = New OdbcConnection(str)
If konek.State = ConnectionState.Closed Then
konek.Open()
End If
End Sub
End Module
b. Buat Form Input Identitas Sekolah
Objek yang dipakai : Label, Textbox, dan Button. Setting properties diubahsuaikan sendiri.
Ketik codingnya :
Public Class Form6
Private Sub TxtJmlS_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtJmlS.TextChanged
LblJmlP.Text = Val(TxtJmlS.Text) + Val(TxtJmlG.Text)
End Sub
Private Sub TxtJmlG_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtJmlG.TextChanged
LblJmlP.Text = Val(TxtJmlS.Text) + Val(TxtJmlG.Text)
End Sub
Sub Simpan()
str = "insert into t_sekolah (nps,nama_sekolah,tahun_pelajaran,jML_siswa,jML_guru,jML_pemilih)" & _
"values ('" & TxtNPS.Text & "', UPPER ('" & TxtNamaSekolah.Text & "'), '" & TxtTP.Text & "','" & TxtJmlS.Text & "','" & TxtJmlG.Text & "','" & LblJmlP.Text & "')"
cmd = New Odbc.OdbcCommand(str, konek)
cmd.ExecuteNonQuery()
End Sub
Private Sub Form6_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
Kosong()
NonAktif()
End Sub
Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Koneksi()
End Sub
Sub Kosong()
TxtNPS.Clear()
TxtNamaSekolah.Clear()
TxtTP.Clear()
TxtJmlS.Clear()
TxtJmlG.Clear()
LblJmlP.Text = ""
TxtNPS.Focus()
End Sub
Sub Aktif()
TxtNPS.Enabled = True
TxtNamaSekolah.Enabled = True
TxtTP.Enabled = True
TxtJmlS.Enabled = True
TxtJmlG.Enabled = True
LblJmlP.Enabled = True
End Sub
Sub NonAktif()
TxtNPS.Enabled = False
TxtNamaSekolah.Enabled = False
TxtTP.Enabled = False
TxtJmlS.Enabled = False
TxtJmlG.Enabled = False
LblJmlP.Enabled = False
End Sub
Private Sub BtnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnKeluar.Click
If BtnKeluar.Text = "&Keluar" Then
Me.Close()
Else
Kosong()
NonAktif()
BtnSimpan.Text = "&Tambah"
BtnKeluar.Text = "&Keluar"
End If
End Sub
Private Sub BtnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSimpan.Click
If BtnSimpan.Text = "&Simpan" Then
Simpan()
BtnSimpan.Text = "&Tambah"
BtnKeluar.Text = "&Keluar"
Kosong()
NonAktif()
ElseIf BtnSimpan.Text = "&Tambah" Then
BtnSimpan.Text = "&Simpan"
BtnKeluar.Text = "&Batal"
Aktif()
Kosong()
Else
str = "update T_sekolah set nama_sekolah='" & TxtNamaSekolah.Text & "',tahun_pelajaran='" & TxtTP.Text & "',jml_siswa='" & TxtJmlS.Text & "', jml_guru='" & TxtJmlG.Text & "', jml_pemilih='" & LblJmlP.Text & "' where nps='" & TxtNPS.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
cmd.ExecuteNonQuery()
BtnSimpan.Text = "&Tambah"
BtnKeluar.Text = "&Keluar"
Kosong()
NonAktif()
End If
End Sub
Private Sub TxtNPS_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtNPS.TextChanged
str = "select * from t_SEKOLAH where nps='" & TxtNPS.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
TxtNamaSekolah.Text = rd.Item("nama_sekolah")
TxtTP.Text = rd.Item("tahun_pelajaran")
TxtJmlS.Text = rd.Item("jml_siswa")
TxtJmlG.Text = rd.Item("jml_guru")
LblJmlP.Text = rd.Item("jml_pemilih")
BtnSimpan.Text = "&Update"
BtnKeluar.Text = "&Batal"
BtnHapus.Enabled = True
Else
TxtNamaSekolah.Clear()
TxtTP.Clear()
TxtJmlS.Clear()
TxtJmlG.Clear()
LblJmlP.Text = ""
TxtNPS.Focus()
BtnHapus.Enabled = False
End If
End Sub
Private Sub BtnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHapus.Click
str = "delete from t_sekolah where nps='" & TxtNPS.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
cmd.ExecuteNonQuery()
Kosong()
NonAktif()
BtnHapus.Enabled = False
End Sub
End Class
Private Sub TxtJmlS_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtJmlS.TextChanged
LblJmlP.Text = Val(TxtJmlS.Text) + Val(TxtJmlG.Text)
End Sub
Private Sub TxtJmlG_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtJmlG.TextChanged
LblJmlP.Text = Val(TxtJmlS.Text) + Val(TxtJmlG.Text)
End Sub
Sub Simpan()
str = "insert into t_sekolah (nps,nama_sekolah,tahun_pelajaran,jML_siswa,jML_guru,jML_pemilih)" & _
"values ('" & TxtNPS.Text & "', UPPER ('" & TxtNamaSekolah.Text & "'), '" & TxtTP.Text & "','" & TxtJmlS.Text & "','" & TxtJmlG.Text & "','" & LblJmlP.Text & "')"
cmd = New Odbc.OdbcCommand(str, konek)
cmd.ExecuteNonQuery()
End Sub
Private Sub Form6_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
Kosong()
NonAktif()
End Sub
Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Koneksi()
End Sub
Sub Kosong()
TxtNPS.Clear()
TxtNamaSekolah.Clear()
TxtTP.Clear()
TxtJmlS.Clear()
TxtJmlG.Clear()
LblJmlP.Text = ""
TxtNPS.Focus()
End Sub
Sub Aktif()
TxtNPS.Enabled = True
TxtNamaSekolah.Enabled = True
TxtTP.Enabled = True
TxtJmlS.Enabled = True
TxtJmlG.Enabled = True
LblJmlP.Enabled = True
End Sub
Sub NonAktif()
TxtNPS.Enabled = False
TxtNamaSekolah.Enabled = False
TxtTP.Enabled = False
TxtJmlS.Enabled = False
TxtJmlG.Enabled = False
LblJmlP.Enabled = False
End Sub
Private Sub BtnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnKeluar.Click
If BtnKeluar.Text = "&Keluar" Then
Me.Close()
Else
Kosong()
NonAktif()
BtnSimpan.Text = "&Tambah"
BtnKeluar.Text = "&Keluar"
End If
End Sub
Private Sub BtnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSimpan.Click
If BtnSimpan.Text = "&Simpan" Then
Simpan()
BtnSimpan.Text = "&Tambah"
BtnKeluar.Text = "&Keluar"
Kosong()
NonAktif()
ElseIf BtnSimpan.Text = "&Tambah" Then
BtnSimpan.Text = "&Simpan"
BtnKeluar.Text = "&Batal"
Aktif()
Kosong()
Else
str = "update T_sekolah set nama_sekolah='" & TxtNamaSekolah.Text & "',tahun_pelajaran='" & TxtTP.Text & "',jml_siswa='" & TxtJmlS.Text & "', jml_guru='" & TxtJmlG.Text & "', jml_pemilih='" & LblJmlP.Text & "' where nps='" & TxtNPS.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
cmd.ExecuteNonQuery()
BtnSimpan.Text = "&Tambah"
BtnKeluar.Text = "&Keluar"
Kosong()
NonAktif()
End If
End Sub
Private Sub TxtNPS_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtNPS.TextChanged
str = "select * from t_SEKOLAH where nps='" & TxtNPS.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
TxtNamaSekolah.Text = rd.Item("nama_sekolah")
TxtTP.Text = rd.Item("tahun_pelajaran")
TxtJmlS.Text = rd.Item("jml_siswa")
TxtJmlG.Text = rd.Item("jml_guru")
LblJmlP.Text = rd.Item("jml_pemilih")
BtnSimpan.Text = "&Update"
BtnKeluar.Text = "&Batal"
BtnHapus.Enabled = True
Else
TxtNamaSekolah.Clear()
TxtTP.Clear()
TxtJmlS.Clear()
TxtJmlG.Clear()
LblJmlP.Text = ""
TxtNPS.Focus()
BtnHapus.Enabled = False
End If
End Sub
Private Sub BtnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHapus.Click
str = "delete from t_sekolah where nps='" & TxtNPS.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
cmd.ExecuteNonQuery()
Kosong()
NonAktif()
BtnHapus.Enabled = False
End Sub
End Class
c. Buat Form Input Calon
Objek yang digunakan: Label, Textbox, Button, Groupbox, Picturebox, OpenFileDialog1. Setting properties disesuaikan.
Ketikkan codingnya:
Imports System.Data.Odbc
Public Class Form2
Private PathFile As String = Nothing
Private Sub BtnFoto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFoto.Click
On Error Resume Next
OpenFileDialog1.Filter = "JPG Files(*.jpg)|*.jpg|JPEG Files(*.jpeg)|*.jpeg|GIF Files(*.gif)|*.gif|PNG Files(*.png)|*.png|BMP files(*.bmp)|*.bmp|"
OpenFileDialog1.FileName = ""
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PicPaslon.SizeMode = PictureBoxSizeMode.StretchImage
PicPaslon.Image = New Bitmap(OpenFileDialog1.FileName)
'BtnPilih.Enabled = True
PathFile = OpenFileDialog1.FileName
TxtNamaFoto.Text = PathFile.Substring(PathFile.LastIndexOf("\") + 1)
LblLokasiFoto.Text = OpenFileDialog1.FileName
PicPaslon.Image = Image.FromFile(LblLokasiFoto.Text)
End If
PicPaslon.Visible = True
AKTIF()
End Sub
Sub KOSONG()
TxtNo.Clear()
TxtCaket.Clear()
TxtCawaket.Clear()
TxtNamaFoto.Clear()
LblLokasiFoto.Text = ""
End Sub
Sub NONAKTIF()
TxtNo.Enabled = False
TxtCaket.Enabled = False
TxtCawaket.Enabled = False
TxtNamaFoto.Enabled = False
End Sub
Sub AKTIF()
TxtNo.Enabled = True
TxtCaket.Enabled = True
TxtCawaket.Enabled = True
TxtNamaFoto.Enabled = True
End Sub
Sub Simpan_Foto()
Try
str = "Insert into t_foto(no_urut,nama_foto,lokasi_foto)values(?,?,?)"
Dim mycomm As OdbcCommand = New OdbcCommand(str, konek)
With mycomm.Parameters
.Add("?", OdbcType.VarChar, 10).Value = TxtNo.Text.Trim
.Add("?", OdbcType.VarChar, 50).Value = TxtNamaFoto.Text.Trim
.Add("?", OdbcType.VarChar, 100).Value = LblLokasiFoto.Text.Trim
End With
mycomm.ExecuteNonQuery()
mycomm = Nothing
'MsgBox("Menympan gambar berhasil", MsgBoxStyle.MsgBoxSetForeground, "Save Gambar")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Sub Simpan()
str = "insert into t_calon (no_urut,nama_caketu,nama_cawaketu)" & _
"values ('" & TxtNo.Text & "', UPPER ('" & TxtCaket.Text & "'), UPPER ('" & TxtCawaket.Text & "'))"
cmd = New Odbc.OdbcCommand(str, konek)
cmd.ExecuteNonQuery()
BtnFoto.Enabled = False
BtnTambah.Text = "&TAMBAH"
End Sub
Private Sub BtnTambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnTambah.Click
If BtnTambah.Text = "&TAMBAH" Then
BtnTambah.Text = "&SIMPAN"
BtnFoto.Enabled = True
BtnEdit.Text = "&BATAL"
BtnEdit.Enabled = True
KOSONG()
AKTIF()
TxtNo.Focus()
GBFoto.Visible = True
ElseIf BtnTambah.Text = "&SIMPAN" Then
If TxtNo.Text = "" Or TxtCaket.Text = "" Or TxtCawaket.Text = "" Then
KOSONG()
AKTIF()
TxtNo.Focus()
Else
Simpan()
Simpan_Foto()
PicPaslon.Hide()
KOSONG()
NONAKTIF()
BtnEdit.Text = "&Simpan Perbaikan"
BtnEdit.Enabled = False
End If
Else
KOSONG()
NONAKTIF()
BtnTambah.Text = "&TAMBAH"
BtnEdit.Enabled = False
BtnFoto.Enabled = False
End If
End Sub
Private Sub TxtNo_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtNo.TextChanged
TxtNoFoto.Text = TxtNo.Text
str = "select * from t_calon where no_urut='" & TxtNo.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
Public Class Form2
Private PathFile As String = Nothing
Private Sub BtnFoto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFoto.Click
On Error Resume Next
OpenFileDialog1.Filter = "JPG Files(*.jpg)|*.jpg|JPEG Files(*.jpeg)|*.jpeg|GIF Files(*.gif)|*.gif|PNG Files(*.png)|*.png|BMP files(*.bmp)|*.bmp|"
OpenFileDialog1.FileName = ""
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PicPaslon.SizeMode = PictureBoxSizeMode.StretchImage
PicPaslon.Image = New Bitmap(OpenFileDialog1.FileName)
'BtnPilih.Enabled = True
PathFile = OpenFileDialog1.FileName
TxtNamaFoto.Text = PathFile.Substring(PathFile.LastIndexOf("\") + 1)
LblLokasiFoto.Text = OpenFileDialog1.FileName
PicPaslon.Image = Image.FromFile(LblLokasiFoto.Text)
End If
PicPaslon.Visible = True
AKTIF()
End Sub
Sub KOSONG()
TxtNo.Clear()
TxtCaket.Clear()
TxtCawaket.Clear()
TxtNamaFoto.Clear()
LblLokasiFoto.Text = ""
End Sub
Sub NONAKTIF()
TxtNo.Enabled = False
TxtCaket.Enabled = False
TxtCawaket.Enabled = False
TxtNamaFoto.Enabled = False
End Sub
Sub AKTIF()
TxtNo.Enabled = True
TxtCaket.Enabled = True
TxtCawaket.Enabled = True
TxtNamaFoto.Enabled = True
End Sub
Sub Simpan_Foto()
Try
str = "Insert into t_foto(no_urut,nama_foto,lokasi_foto)values(?,?,?)"
Dim mycomm As OdbcCommand = New OdbcCommand(str, konek)
With mycomm.Parameters
.Add("?", OdbcType.VarChar, 10).Value = TxtNo.Text.Trim
.Add("?", OdbcType.VarChar, 50).Value = TxtNamaFoto.Text.Trim
.Add("?", OdbcType.VarChar, 100).Value = LblLokasiFoto.Text.Trim
End With
mycomm.ExecuteNonQuery()
mycomm = Nothing
'MsgBox("Menympan gambar berhasil", MsgBoxStyle.MsgBoxSetForeground, "Save Gambar")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Sub Simpan()
str = "insert into t_calon (no_urut,nama_caketu,nama_cawaketu)" & _
"values ('" & TxtNo.Text & "', UPPER ('" & TxtCaket.Text & "'), UPPER ('" & TxtCawaket.Text & "'))"
cmd = New Odbc.OdbcCommand(str, konek)
cmd.ExecuteNonQuery()
BtnFoto.Enabled = False
BtnTambah.Text = "&TAMBAH"
End Sub
Private Sub BtnTambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnTambah.Click
If BtnTambah.Text = "&TAMBAH" Then
BtnTambah.Text = "&SIMPAN"
BtnFoto.Enabled = True
BtnEdit.Text = "&BATAL"
BtnEdit.Enabled = True
KOSONG()
AKTIF()
TxtNo.Focus()
GBFoto.Visible = True
ElseIf BtnTambah.Text = "&SIMPAN" Then
If TxtNo.Text = "" Or TxtCaket.Text = "" Or TxtCawaket.Text = "" Then
KOSONG()
AKTIF()
TxtNo.Focus()
Else
Simpan()
Simpan_Foto()
PicPaslon.Hide()
KOSONG()
NONAKTIF()
BtnEdit.Text = "&Simpan Perbaikan"
BtnEdit.Enabled = False
End If
Else
KOSONG()
NONAKTIF()
BtnTambah.Text = "&TAMBAH"
BtnEdit.Enabled = False
BtnFoto.Enabled = False
End If
End Sub
Private Sub TxtNo_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtNo.TextChanged
TxtNoFoto.Text = TxtNo.Text
str = "select * from t_calon where no_urut='" & TxtNo.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
TxtCaket.Text = rd.Item("nama_caketu")
TxtCawaket.Text = rd.Item("nama_cawaketu")
If TxtNo.Text = "" Then
KOSONG()
BtnTambah.Text = "&SIMPAN"
BtnEdit.Text = "&BATAL"
BtnEdit.Enabled = True
ElseIf TxtNo.Text > rd.Item("no_urut") Then
BtnTambah.Text = "&SIMPAN"
BtnEdit.Text = "&BATAL"
BtnEdit.Enabled = True
Else
BtnEdit.Text = "&Simpan Perbaikan"
BtnEdit.Enabled = True
BtnTambah.Text = "&BATAL"
End If
Else
TxtCaket.Clear()
TxtCawaket.Clear()
End If
End Sub
Private Sub Form2_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
NONAKTIF()
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Koneksi()
End Sub
Private Sub TxtNoFoto_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtNoFoto.TextChanged
str = "select * from t_foto where no_urut='" & TxtNoFoto.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
TxtNamaFoto.Text = rd.Item("nama_foto")
LblLokasiFoto.Text = rd.Item("lokasi_foto")
PicPaslon.ImageLocation = rd.Item("lokasi_foto")
PicPaslon.SizeMode = PictureBoxSizeMode.StretchImage
Else
TxtNamaFoto.Clear()
LblLokasiFoto.Text = ""
GBFoto.Visible = False
End If
GBFoto.Visible = True
End Sub
Sub EditCalon()
str = "update T_calon set nama_caketu=UPPER('" & TxtCaket.Text & "'),nama_cawaketu=UPPER('" & TxtCawaket.Text & "')where no_urut='" & TxtNo.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
cmd.ExecuteNonQuery()
End Sub
Sub EditFoto()
Try
str = "update T_foto set nama_foto=?,lokasi_foto=? where no_urut='" & TxtNoFoto.Text & "'"
Dim mycomm As OdbcCommand = New OdbcCommand(str, konek)
With mycomm.Parameters
' .Add("?", OdbcType.VarChar, 10).Value = TxtNo.Text.Trim
.Add("?", OdbcType.VarChar, 50).Value = TxtNamaFoto.Text.Trim
.Add("?", OdbcType.VarChar, 100).Value = LblLokasiFoto.Text.Trim
End With
mycomm.ExecuteNonQuery()
mycomm = Nothing
'MsgBox("Menympan gambar berhasil", MsgBoxStyle.MsgBoxSetForeground, "Save Gambar")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub BtnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEdit.Click
If BtnEdit.Text = "&Simpan Perbaikan" Then
EditCalon()
EditFoto()
KOSONG()
NONAKTIF()
BtnEdit.Enabled = False
BtnTambah.Text = "&TAMBAH"
Else
KOSONG()
NONAKTIF()
BtnEdit.Enabled = False
BtnEdit.Text = "&Simpan Perbaikan"
BtnTambah.Text = "&TAMBAH"
BtnFoto.Enabled = False
End If
End Sub
End Class
If rd.HasRows Then
TxtCaket.Text = rd.Item("nama_caketu")
TxtCawaket.Text = rd.Item("nama_cawaketu")
If TxtNo.Text = "" Then
KOSONG()
BtnTambah.Text = "&SIMPAN"
BtnEdit.Text = "&BATAL"
BtnEdit.Enabled = True
ElseIf TxtNo.Text > rd.Item("no_urut") Then
BtnTambah.Text = "&SIMPAN"
BtnEdit.Text = "&BATAL"
BtnEdit.Enabled = True
Else
BtnEdit.Text = "&Simpan Perbaikan"
BtnEdit.Enabled = True
BtnTambah.Text = "&BATAL"
End If
Else
TxtCaket.Clear()
TxtCawaket.Clear()
End If
End Sub
Private Sub Form2_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
NONAKTIF()
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Koneksi()
End Sub
Private Sub TxtNoFoto_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtNoFoto.TextChanged
str = "select * from t_foto where no_urut='" & TxtNoFoto.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
TxtNamaFoto.Text = rd.Item("nama_foto")
LblLokasiFoto.Text = rd.Item("lokasi_foto")
PicPaslon.ImageLocation = rd.Item("lokasi_foto")
PicPaslon.SizeMode = PictureBoxSizeMode.StretchImage
Else
TxtNamaFoto.Clear()
LblLokasiFoto.Text = ""
GBFoto.Visible = False
End If
GBFoto.Visible = True
End Sub
Sub EditCalon()
str = "update T_calon set nama_caketu=UPPER('" & TxtCaket.Text & "'),nama_cawaketu=UPPER('" & TxtCawaket.Text & "')where no_urut='" & TxtNo.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
cmd.ExecuteNonQuery()
End Sub
Sub EditFoto()
Try
str = "update T_foto set nama_foto=?,lokasi_foto=? where no_urut='" & TxtNoFoto.Text & "'"
Dim mycomm As OdbcCommand = New OdbcCommand(str, konek)
With mycomm.Parameters
' .Add("?", OdbcType.VarChar, 10).Value = TxtNo.Text.Trim
.Add("?", OdbcType.VarChar, 50).Value = TxtNamaFoto.Text.Trim
.Add("?", OdbcType.VarChar, 100).Value = LblLokasiFoto.Text.Trim
End With
mycomm.ExecuteNonQuery()
mycomm = Nothing
'MsgBox("Menympan gambar berhasil", MsgBoxStyle.MsgBoxSetForeground, "Save Gambar")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub BtnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEdit.Click
If BtnEdit.Text = "&Simpan Perbaikan" Then
EditCalon()
EditFoto()
KOSONG()
NONAKTIF()
BtnEdit.Enabled = False
BtnTambah.Text = "&TAMBAH"
Else
KOSONG()
NONAKTIF()
BtnEdit.Enabled = False
BtnEdit.Text = "&Simpan Perbaikan"
BtnTambah.Text = "&TAMBAH"
BtnFoto.Enabled = False
End If
End Sub
End Class
d. Buat Form Surat Suara
Objek yang dipakai : Label, Button, Picturebox. Setting properties disesuaikan.
Ketikkan codingnya:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Koneksi()
str = "select * from t_calon where no_urut='" & Label1.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
LblCaket1.Text = rd.Item(1)
LblCawaket1.Text = rd.Item(2)
End If
str = "select * from t_foto where no_urut='" & Label1.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
Picpaslon1.ImageLocation = rd.Item("lokasi_foto")
Picpaslon1.SizeMode = PictureBoxSizeMode.StretchImage
End If
str = "select * from t_calon where no_urut='" & Label2.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
LblCaket2.Text = rd.Item(1)
LblCawaket2.Text = rd.Item(2)
End If
str = "select * from t_foto where no_urut='" & Label2.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
Picpaslon2.ImageLocation = rd.Item("lokasi_foto")
Picpaslon2.SizeMode = PictureBoxSizeMode.StretchImage
End If
str = "select * from t_calon where no_urut='" & Label3.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
LblCaket3.Text = rd.Item(1)
LblCawaket3.Text = rd.Item(2)
End If
str = "select * from t_foto where no_urut='" & Label3.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
Picpaslon3.ImageLocation = rd.Item("lokasi_foto")
Picpaslon3.SizeMode = PictureBoxSizeMode.StretchImage
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
str = "update t_calon set jumlah_suara= jumlah_suara + 1 where no_urut='" & Label1.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
cmd.ExecuteNonQuery()
'MsgBox("Terimakasih sudah ikut berpartisipasi memilih", MsgBoxStyle.OkOnly, "Logout")
Me.Close()
Form8.Show()
' Form3.Show()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
str = "update t_calon set jumlah_suara= jumlah_suara + 1 where no_urut='" & Label2.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
cmd.ExecuteNonQuery()
Me.Close()
Form8.Show()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
str = "update t_calon set jumlah_suara= jumlah_suara + 1 where no_urut='" & Label3.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
cmd.ExecuteNonQuery()
Me.Close()
Form8.Show()
End Sub
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Me.Close()
Form3.Show()
End Sub
End Class
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Koneksi()
str = "select * from t_calon where no_urut='" & Label1.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
LblCaket1.Text = rd.Item(1)
LblCawaket1.Text = rd.Item(2)
End If
str = "select * from t_foto where no_urut='" & Label1.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
Picpaslon1.ImageLocation = rd.Item("lokasi_foto")
Picpaslon1.SizeMode = PictureBoxSizeMode.StretchImage
End If
str = "select * from t_calon where no_urut='" & Label2.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
LblCaket2.Text = rd.Item(1)
LblCawaket2.Text = rd.Item(2)
End If
str = "select * from t_foto where no_urut='" & Label2.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
Picpaslon2.ImageLocation = rd.Item("lokasi_foto")
Picpaslon2.SizeMode = PictureBoxSizeMode.StretchImage
End If
str = "select * from t_calon where no_urut='" & Label3.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
LblCaket3.Text = rd.Item(1)
LblCawaket3.Text = rd.Item(2)
End If
str = "select * from t_foto where no_urut='" & Label3.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
Picpaslon3.ImageLocation = rd.Item("lokasi_foto")
Picpaslon3.SizeMode = PictureBoxSizeMode.StretchImage
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
str = "update t_calon set jumlah_suara= jumlah_suara + 1 where no_urut='" & Label1.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
cmd.ExecuteNonQuery()
'MsgBox("Terimakasih sudah ikut berpartisipasi memilih", MsgBoxStyle.OkOnly, "Logout")
Me.Close()
Form8.Show()
' Form3.Show()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
str = "update t_calon set jumlah_suara= jumlah_suara + 1 where no_urut='" & Label2.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
cmd.ExecuteNonQuery()
Me.Close()
Form8.Show()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
str = "update t_calon set jumlah_suara= jumlah_suara + 1 where no_urut='" & Label3.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
cmd.ExecuteNonQuery()
Me.Close()
Form8.Show()
End Sub
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Me.Close()
Form3.Show()
End Sub
End Class
e. Buat Form Login
Objek yang digunakan: Label, LinkLabel, Textbox, Button, Picturebox. Settingan properties disesuaikan.
Ketik codingnya:
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
End
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(13) Then
If TextBox1.Text = "admin" Then
Me.Hide()
Form4.Show()
Else
MsgBox("Anda tidak mempunyai akses", vbOKOnly, "e-voting v.1.0")
End If
End If
End Sub
Private Sub Form3_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
TextBox1.Text = ""
TextBox1.Focus()
End Sub
Dim kalimat As String
Dim panjang As Integer
Dim jalan As Boolean
Private Sub Form1_Leave(ByVal sender As Object, ByVal e As System.EventArgs)
jalan = False
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If jalan Then
kalimat = Microsoft.VisualBasic.Right(kalimat, panjang - 1) & _
Microsoft.VisualBasic.Left(kalimat, 2)
LinkLabel2.Text = kalimat
LinkLabel2.Refresh()
Else
Timer1.Enabled = False
End If
Me.Text = Microsoft.VisualBasic.Right$(Me.Text, Len(Me.Text) - 1) + Microsoft.VisualBasic.Left$(Me.Text, 1)
End Sub
Sub validasisisasuara()
str = "select * from t_sekolah where nps='" & lblkodesekolah.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
lbljmlsuara.Text = rd.Item("jml_pemilih")
End If
str = "SELECT sum(jumlah_suara) as total FROM t_calon "
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
LblTotalSuara.Text = rd.Item("total")
End If
lblsisasuara.Text = Val(lbljmlsuara.Text) - Val(LblTotalSuara.Text)
End Sub
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Koneksi()
jalan = True
kalimat = "e-voting v.1.0 [by:pabaiq] "
panjang = Len(kalimat)
LinkLabel2.Text = kalimat
LinkLabel2.Refresh()
Timer1.Enabled = True
validasisisasuara()
Pickpu.Location = New Point((Me.Width - Pickpu.Width) \ 2, (Me.Height - Pickpu.Height) \ 2)
End Sub
Private Sub BtnMasuk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnMasuk.Click
If lblsisasuara.Text <> "0" Then
Me.Hide()
Form1.Show()
Else
MsgBox("Anda sudah tidak mempunyai akses", vbOKOnly, "e-voting v.1.0")
End If
End Sub
End Class
End
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(13) Then
If TextBox1.Text = "admin" Then
Me.Hide()
Form4.Show()
Else
MsgBox("Anda tidak mempunyai akses", vbOKOnly, "e-voting v.1.0")
End If
End If
End Sub
Private Sub Form3_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
TextBox1.Text = ""
TextBox1.Focus()
End Sub
Dim kalimat As String
Dim panjang As Integer
Dim jalan As Boolean
Private Sub Form1_Leave(ByVal sender As Object, ByVal e As System.EventArgs)
jalan = False
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If jalan Then
kalimat = Microsoft.VisualBasic.Right(kalimat, panjang - 1) & _
Microsoft.VisualBasic.Left(kalimat, 2)
LinkLabel2.Text = kalimat
LinkLabel2.Refresh()
Else
Timer1.Enabled = False
End If
Me.Text = Microsoft.VisualBasic.Right$(Me.Text, Len(Me.Text) - 1) + Microsoft.VisualBasic.Left$(Me.Text, 1)
End Sub
Sub validasisisasuara()
str = "select * from t_sekolah where nps='" & lblkodesekolah.Text & "'"
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
lbljmlsuara.Text = rd.Item("jml_pemilih")
End If
str = "SELECT sum(jumlah_suara) as total FROM t_calon "
cmd = New Odbc.OdbcCommand(str, konek)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
LblTotalSuara.Text = rd.Item("total")
End If
lblsisasuara.Text = Val(lbljmlsuara.Text) - Val(LblTotalSuara.Text)
End Sub
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Koneksi()
jalan = True
kalimat = "e-voting v.1.0 [by:pabaiq] "
panjang = Len(kalimat)
LinkLabel2.Text = kalimat
LinkLabel2.Refresh()
Timer1.Enabled = True
validasisisasuara()
Pickpu.Location = New Point((Me.Width - Pickpu.Width) \ 2, (Me.Height - Pickpu.Height) \ 2)
End Sub
Private Sub BtnMasuk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnMasuk.Click
If lblsisasuara.Text <> "0" Then
Me.Hide()
Form1.Show()
Else
MsgBox("Anda sudah tidak mempunyai akses", vbOKOnly, "e-voting v.1.0")
End If
End Sub
End Class
4. Jika design form dan pengetikkan codingnya sudah selesai, maka selanjutnya tinggal di jalankan (Tekan F5), jangan lupa sebelumnya atur terlebih dahulu Startup Formnya pada Form Login.
Baca juga : Cara Mengkoneksikan Client Server pada VB.NET dengan database MYSQL
Baca juga : Cara Membuat Modul Koneksi di VB.NET
Demikian ulasan wacana cara menciptakan e-voting di VB.NET berbasis clientserver dengan database MYSQL. Selebihnya silahkan analisa sendiri terkait dengan penamaan objek untuk di sesuaikan dengan codingnya biar tidak terjadi bug. Selain itu, dapat juga dikembangkan dengan melengkapi Form Menu Utama, Form Rekapitulasi, Form Tampilan Quick Count dan lain sebagainya. Terimakasih sudah berkunjung, semoga bermanfaat.
1 Komentar untuk "Cara Menciptakan E-Voting Dengan Vb.Net"
hmmm....sepertinya saya kenal artikel ini... (maaf mas dapet dari pabaiq.blogspot.com) ya...