Public Class credits
    Dim dsp As New DataSet  'to display table
    Dim dap As New OleDb.OleDbDataAdapter 'to display table

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Button1.Enabled = True
        Button2.Enabled = True
        Button3.Enabled = False
        Button4.Enabled = False
        clr()
      

    End Sub
    Sub clr()

        TextBox2.Text = ""
        ComboBox1.Text = ""
       

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Button1.Enabled = True
        Button2.Enabled = False
        Button3.Enabled = False
        Button4.Enabled = False

        qry("select * from payment where cardno='" & ComboBox1.Text & "'")
        If dr.Read = True Then
            MsgBox("already exist")
            Exit Sub

        End If
        dr.Close()
        qry1(" insert into payment values('" & ComboBox1.Text & "','" & TextBox2.Text & "')")

        fill()

        clr()

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Button1.Enabled = True
        Button2.Enabled = False
        Button3.Enabled = False
        Button4.Enabled = False

        qry1("update payment set cardno='" & ComboBox1.Text & "',amount='" & TextBox2.Text & "' where cardno='" & ComboBox1.Text & "'")
        clr()
        fill()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Button1.Enabled = True
        Button2.Enabled = False
        Button3.Enabled = False
        Button4.Enabled = False

        qry1("delete from payment  where cardno='" & ComboBox1.Text & "'")
        fill()
        clr()

    End Sub
    Sub dtp(ByVal s As String) 'function is used to display a table
        If con.State = ConnectionState.Open Then
            con.Close()
        End If
        con.Open()
        dap = New OleDb.OleDbDataAdapter(s, con)

    End Sub
    Sub fill()
        dtp("select * from payment")
        dsp.Clear()
        dap.Fill(dsp, "payment")
        DataGridView1.DataSource = dsp
        DataGridView1.DataMember = dsp.Tables(0).ToString
    End Sub

    Private Sub DataGridView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick
        Button1.Enabled = True
        Button2.Enabled = False
        Button3.Enabled = True
        Button4.Enabled = True
        Dim dt
        dt = DataGridView1.SelectedCells(0).Value.ToString

        qry("select * from payment where cardno='" & dt & "'")
        If dr.Read = True Then
            ComboBox1.Text = dr.Item(0).ToString
            TextBox2.Text = dr.Item(1).ToString

        End If
        dr.Close()

    End Sub

    Private Sub credits_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Button1.Enabled = True
        Button2.Enabled = False
        Button3.Enabled = False
        Button4.Enabled = False

        qry("select * from VehicleDetails")
        Do While dr.Read() = True
            ComboBox1.Items.Add(dr.Item(0).ToString)
        Loop

        fill()



    End Sub
End Class