Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

FOMR PENDAFTARAN

Imports MySql.Data.MySqlClient
Public Class FormPendaftaran
Sub NomorOtomatis()
Dim cmd As New MySqlCommand
Dim mDA As New MySqlDataAdapter("select * from pendaftaran where Nomor in (select
max(Nomor) from Pendaftaran) order by Nomor asc", konek)
Dim dt As New DataTable
Dim rd As MySqlDataReader
rd = cmd.ExecuteReader
rd.Read()
If Not rd.HasRows Then
TNomor.Text = Format(Now, "yyMMdd") + "0001"
Else
If Microsoft.VisualBasic.Left(rd.GetString(0), 6) <> Format(Now, "yyMMdd") Then
TNomor.Text = Format(Now, "yyMMdd") + "0001"
Else
TNomor.Text = rd.GetString(0) + 1
End If
End If
End Sub
Sub Tampilkan()
Dim mDA As New MySqlDataAdapter("select * from pendaftaran", konek)
Dim dt As New DataTable
mDA.Fill(dt)
DGV.DataSource = dt
DGV.Refresh()
End Sub
Sub segarkan()
TNomor.Text = ""
TNopol.Text = ""
TTanggal.Text = ""
TPemilik.Text = ""
TJenis.Text = ""
TKeluhan.Text = ""
End Sub
Sub coba()
Try
Call bukaDB()
Dim mDA As New MySqlDataAdapter("select * from pendaftaran", konek)
Dim dt As New DataTable
mDA.Fill(dt)
DGV.DataSource = dt
DGV.Refresh()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub FormPendaftaran_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DbbengkelDataSet3.pendaftaran' table. You can
move, or remove it, as needed.
Me.PendaftaranTableAdapter.Fill(Me.DbbengkelDataSet1.pendaftaran)
Call bukaDB()

Call coba()
Call NomorOtomatis()
Call Tampilkan()
TTanggal.Text = Today
End Sub
Private Sub CmdSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles CmdSimpan.Click
Dim sqlsimpan As String = "insert into pendaftaran
(Nomor,No_Pol,Nama,Jenis_Kend,Keluhan) values('" & TNomor.Text & "','" & TNopol.Text & "','" &
TPemilik.Text & "','" & TJenis.Text & "','" & TKeluhan.Text & "')"
Try
Call bukaDB()
With sqlcommand
.CommandText = sqlsimpan
.Connection = sqlconnection
.ExecuteNonQuery()
segarkan()
MsgBox("databerhasil disimpan")
End With
Call coba()
Catch ex As Exception
MsgBox(ex.Message)
sqlcommand.Dispose()
tutupdb()
End Try
End Sub
Private Sub CmdHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles CmdHapus.Click
Dim pesan As Integer
pesan = MsgBox("Apakah anda yakin ingin menghapus data : " & TNomor.Text & " ?",
vbQuestion + vbYesNo, "Tutorial Blog Guzko")
If pesan = vbYes Then
Try
bukaDB()
Dim mDA As New MySqlDataAdapter("DELETE FROM pendaftaran where nomor = '" &
TNomor.Text & "'", konek)
Dim dt As New DataTable
mDA.Fill(dt)
DGV.Refresh()
segarkan()
Call coba()
Catch ex As Exception
MsgBox(ex.Message)
tutupdb()
End Try
End If
End Sub
Private Sub CmdUbah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles CmdUbah.Click
Dim pesan As Integer
pesan = MsgBox("Apakah anda yakin ingin meng-update data dengan nomor : " &
TNomor.Text & " ?", vbQuestion + vbYesNo)
Try
bukaDB()

Dim mDA As New MySqlDataAdapter("UPDATE pendaftaran SET nama = '" & TPemilik.Text
& "'," & _
"No_Pol = '" & TNopol.Text & "'," & "Jenis_Kend = '" & TJenis.Text & "',
" & "Keluhan = '" & TKeluhan.Text & "'WHERE nomor = '" & TNomor.Text & "'", konek)
Dim dt As New DataTable
mDA.Fill(dt)
DGV.Refresh()
segarkan()
MsgBox("Data dengan nomor : " & TNomor.Text & " berhasil diupdate")
Call coba()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub CmdTutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles CmdTutup.Click
Me.Close()
End Sub
Private Sub TxtCari_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TxtCari.TextChanged
If RbNama.Checked = True Then
Dim mDA As New MySqlDataAdapter("Select * from pendaftaran where Nama '%" &
TxtCari.Text & "%' order by Nama asc", konek)
Dim dt As New DataTable
mDA.Fill(dt)
DGV.DataSource = dt
DGV.Refresh()
DGV.ReadOnly = True
ElseIf RbNopol.Checked = True Then
Dim mDA As New MySqlDataAdapter("Select * from pendaftaran where No_Pol like '%" &
TxtCari.Text & "%' order by No_Pol asc", konek)
Dim dt As New DataTable
mDA.Fill(dt)
DGV.DataSource = dt
DGV.Refresh()
DGV.ReadOnly = True
End If
End Sub
Private Sub TTanggal_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TTanggal.TextChanged
TTanggal.Text = Today
End Sub
Private Sub TNomor_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TNomor.TextChanged
Call NomorOtomatis()
End Sub
End Class

Modul koneksi
Imports MySql.Data.MySqlClient
Imports MySql.Data.MySqlClient.MySqlConnection
Module modkoneksi
Public konek As String = "server = localhost;userid = root; password=;database= dbbengkel;"
Public sqlconnection As New MySqlConnection
Public sqlcommand As New MySqlCommand
Public sqladapter As New MySqlDataAdapter
Public konfirmasi As New MsgBoxResult
Public sqlreader As MySqlDataReader
Public cur As New Form
Public Sub bukaDB()
If sqlconnection.State = ConnectionState.Closed Then
sqlconnection.ConnectionString = konek
sqlconnection.Open()
'msgbox("sukses")
End If
End Sub
Public Sub tutupdb()
With sqlconnection
.Dispose()
.Close()
End With
End Sub
End Module

You might also like