Design Pendaftaran :
Codding Pendaftaran :
Imports System.Data.Odbc
Public Class Pendaftaran
Sub NomorOtomatis()
cmd = New OdbcCommand("Select * from pendaftaran where Nomor in (select max(Nomor) from Pendaftaran) order by Nomor desc", Conn)
rd = cmd.ExecuteReader
rd.Read()
If Not rd.HasRows Then
TxtNomor.Text = Format(Now, "yyMMdd") + "0001"
Else
If Microsoft.VisualBasic.Left(rd.GetString(0), 6) <> Format(Now, "yyMMdd") Then
TxtNomor.Text = Format(Now, "yyMMdd") + "0001"
Else
TxtNomor.Text = rd.GetString(0) + 1
End If
End If
End Sub
Sub Kosongkan()
TxtNopol.Clear()
TxtJenis.Clear()
TxtPemilik.Clear()
TxtKeluhan.Clear()
TxtNopol.Focus()
End Sub
Sub Tampilkan()
da = New OdbcDataAdapter("Select * from pendaftaran", Conn)
ds = New DataSet
ds.Clear()
da.Fill(ds, "pendaftaran")
DGV.DataSource = (ds.Tables("pendaftaran"))
DGV.ReadOnly = True
End Sub
Private Sub Pendaftaran_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call Koneksi()
Call NomorOtomatis()
Call Tampilkan()
TxtTanggal.Text = Today
End Sub
Private Sub TxtNopol_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtNopol.KeyPress
TxtNopol.MaxLength = 10
If e.KeyChar = Chr(13) Then
If TxtNopol.Text = "" Then
MsgBox("Nomor polisi wajib disii")
Else
TxtJenis.Focus()
End If
End If
End Sub
Private Sub TxtNopol_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtNopol.TextChanged
End Sub
Private Sub TxtPemilik_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtPemilik.KeyPress
If e.KeyChar = Chr(13) Then
If TxtPemilik.Text = "" Then
MsgBox("Nama pemilik wajib disii")
Else
TxtKeluhan.Focus()
End If
End If
End Sub
Private Sub TxtPemilik_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtPemilik.TextChanged
End Sub
Private Sub TxtJenis_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtJenis.KeyPress
If e.KeyChar = Chr(13) Then
If TxtJenis.Text = "" Then
MsgBox("Jenis kendaraan wajib disii")
Else
TxtPemilik.Focus()
End If
End If
End Sub
Private Sub TxtJenis_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtJenis.TextChanged
End Sub
Private Sub TxtKeluhan_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtKeluhan.KeyPress
If e.KeyChar = Chr(13) Then
If TxtKeluhan.Text = "" Then
MsgBox("Keluhan kendaraan masih kosong")
Else
btnSimpan.Focus()
End If
End If
End Sub
Private Sub btnBatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBatal.Click
Call Kosongkan()
End Sub
Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpan.Click
If TxtNopol.Text = "" Or TxtJenis.Text = "" Or TxtPemilik.Text = "" Or TxtKeluhan.Text = "" Then
MsgBox("Data belum lengkap")
Else
cmd = New OdbcCommand("Select * from pendaftaran where Nopol='" & TxtNopol.Text & "' and date(Tanggal)='" & TxtTanggal.Text & "'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If Not rd.HasRows Then
Dim Simpan As String = "insert into pendaftaran(Nomor,Tanggal,Nopol,Nama,Kendaraan,Keluhan,Status) values ('" & TxtNomor.Text & "','" & TxtTanggal.Text & "','" & TxtNopol.Text & "','" & TxtPemilik.Text & "','" & TxtJenis.Text & "','" & TxtKeluhan.Text & "','0')"
cmd = New OdbcCommand(Simpan, Conn)
cmd.ExecuteNonQuery()
Else
Dim ubah As String = "update pendaftaran set Nama='" & TxtPemilik.Text & "',Kendaraan='" & TxtJenis.Text & "' ,Keluhan='" & TxtKeluhan.Text & "' where Nopol='" & TxtNopol.Text & "' and cdate(tanggal)='" & TxtTanggal.Text & "'"
cmd = New OdbcCommand(ubah, Conn)
cmd.ExecuteNonQuery()
End If
Call NomorOtomatis()
Call Tampilkan()
Call Kosongkan()
End If
End Sub
Private Sub btnTutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTutup.Click
Me.Close()
End Sub
End Class
0 Post a Comment:
Post a Comment