Imports System.Data.SqlClient
Public Class frmPayment

    Private Sub frmPayment_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        payment()
    End Sub

    Sub payment()
        ListView1.Items.Clear()
        Try
            cm = New SqlCommand("select * from tblPayment", cn)
            dr = cm.ExecuteReader
            While dr.Read
                lst = ListView1.Items.Add(dr.Item(0).ToString)
                lst.SubItems.Add(dr.Item(1).ToString)
                lst.SubItems.Add(String.Format("{0:0.0}", dr.Item(2)))
            End While
            dr.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    'Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
    '    If is_empty(txtPass) = True Then Exit Sub
    '    If is_empty(txtPay) = True Then Exit Sub
    '    Try
    '        cm = New SqlCommand("insert into tblPayment values('" & txtPass.Text & "','" & txtPay.Text & "')", cn)
    '        cm.ExecuteNonQuery()
    '        MessageBox.Show("Successfully saved", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
    '        payment()
    '        txtPass.Clear()
    '        txtPay.Clear()
    '    Catch ex As Exception
    '        MsgBox(ex.Message)
    '    End Try
    'End Sub

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
        txtPass.Text = ListView1.FocusedItem.SubItems(1).Text
        txtPay.Text = ListView1.FocusedItem.SubItems(2).Text
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If is_empty(txtPass) = True Then Exit Sub
        If is_empty(txtPay) = True Then Exit Sub
        Try
            cm = New SqlCommand("update tblPayment set passenger = '" & txtPass.Text & "', payment = '" & CDbl(txtPay.Text) & "' where id like '" & ListView1.FocusedItem.Text & "'", cn)
            cm.ExecuteNonQuery()
            MessageBox.Show("Successfully updated", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
            frmCenter.auditTrail(uID, "update " & txtPass.Text & " payment to P" & txtPay.Text & "")
            frmCenter.dawat(uID, loginDate)
            payment()
            txtPass.Clear()
            txtPay.Clear()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    'Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    '    If is_empty(txtPass) = True Then Exit Sub
    '    If is_empty(txtPay) = True Then Exit Sub
    '    Try
    '        cm = New SqlCommand("delete from tblPayment where id like '" & ListView1.FocusedItem.Text & "'", cn)
    '        cm.ExecuteNonQuery()
    '        MessageBox.Show("Successfully deleted", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
    '        payment()
    '        txtPass.Clear()
    '        txtPay.Clear()
    '    Catch ex As Exception
    '        MsgBox(ex.Message)
    '    End Try
    'End Sub
End Class