Public Class Entry_Data_Penumpang
Private Sub tombol_input_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tombol_input.Click
Call simpan()
End Sub
Private Sub tombol_edit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tombol_edit.Click
Call ubah()
End Sub
Sub simpan()
If tombol_input.Text = "Input" Then
Call Koneksi()
tombol_input.Text = "Simpan"
tombol_edit.Enabled = False
tombol_delete.Enabled = False
tombol_exit.Text = "Batal"
Else
If no_text.Text = "" Then Exit Sub
If nm_text.Text = "" Then Exit Sub
Call cekrecord()
Try
If hasilcek = "False" Then
Call Koneksi()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "insert into penumpang values('" & no_text.Text & "','" & nm_text.Text & "','" & alamat_text.Text & "','" & nomer_text.Text & "')"
Tampil.ExecuteNonQuery()
Call Koneksi()
Call kosong()
MsgBox("Data Telah Tersimpan")
Else
MsgBox("Data sudah ada, silahkan cek data yang diinput", MsgBoxStyle.Critical, "Input Data")
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Sub kosong()
no_text.Text = ""
nm_text.Text = ""
alamat_text.Text = ""
nomer_text.Text = ""
End Sub
Sub cekrecord()
Call Koneksi()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "select * from penumpang where no_penumpang='" & Trim(no_text.Text) & "'"
Tampilkan = Tampil.ExecuteReader
If Tampilkan.HasRows = True Then
hasilcek = True
Else
hasilcek = False
End If
Call tutupKoneksi()
End Sub
Sub Hapus()
If tombol_delete.Text = "Delete" Then
Call kosong()
no_text.Text = ""
nm_text.Text = ""
tombol_delete.Text = "Ok"
tombol_input.Enabled = False
tombol_edit.Enabled = False
tombol_exit.Text = "Batal"
no_text.Focus()
Else
If no_text.Text = "" Then Exit Sub
If nm_text.Text = "" Then Exit Sub
Try
Call Koneksi()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "delete from penumpang where no_penumpang='" & Trim(no_text.Text) & "'"
Tampil.ExecuteNonQuery()
Call kosong()
MsgBox("Data Telah Dihapus")
Call kosong()
no_text.Focus()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Sub ubah()
If tombol_edit.Text = "Edit" Then
Call kosong()
tombol_edit.Text = "Simpan"
tombol_input.Enabled = False
tombol_delete.Enabled = False
tombol_exit.Text = "Batal"
no_text.Focus()
Else
If no_text.Text = "" Then Exit Sub
If nm_text.Text = "" Then Exit Sub
Try
Call Koneksi()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "update penumpang set nm_penumpang ='" & Trim(nm_text.Text) & "',alamat = '" & alamat_text.Text & "',no_tlp = '" & nomer_text.Text & "' where no_penumpang = '" & Trim(no_text.Text) & "'"
Tampil.ExecuteNonQuery()
Call kosong()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
End Sub
Sub netral()
tombol_input.Enabled = True
tombol_input.Text = "Input"
tombol_edit.Enabled = True
tombol_edit.Text = "Edit"
tombol_delete.Enabled = True
tombol_delete.Text = "Delete"
tombol_exit.Text = "Exit"
End Sub
Private Sub tombol_exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tombol_exit.Click
If tombol_exit.Text = "Exit" Then
Me.Close()
Else
Call netral()
End If
End Sub
Private Sub tombol_delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tombol_delete.Click
Call Hapus()
End Sub
Private Sub no_text_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles no_text.KeyPress
If e.KeyChar = Chr(Keys.Enter) Then
If tombol_edit.Text = "Save" Then
Call cekrecord()
If hasilcek = False Then
nm_text.Focus()
Else
MsgBox("Kode sudah ada, silahkan ganti kode lain", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Infromasi")
no_text.Focus()
End If
Else
Call Koneksi()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "select * from penumpang where no_penumpang='" & Trim(no_text.Text) & "'"
Tampilkan = Tampil.ExecuteReader
If no_text.Text = "" Then
MsgBox("Masukan Data Terlebih Dahulu", MsgBoxStyle.Information, "Pesan")
Else
If Tampilkan.HasRows = True Then
While Tampilkan.Read()
If IsDBNull(Tampilkan("no_penumpang")) Then
nm_text.Focus()
Else
nm_text.Text = Tampilkan("nm_penumpang")
alamat_text.Text = Tampilkan("alamat")
nomer_text.Text = Tampilkan("no_tlp")
End If
End While
Else
MsgBox("Data tidak diketemukan", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Tambah Data")
End If
End If
End If
End If
End Sub
End Class















