Imports System.Data.SqlClient
Public Class frmList
    Dim col As New AutoCompleteStringCollection
    Private Sub frmList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        loadDate()
    End Sub

    Sub loadDate()
        cm = New SqlCommand("select * from tblBilling order by date", cn)
        dr = cm.ExecuteReader
        While dr.Read
            col.Add(dr.Item("date").ToString())
        End While
        dr.Close()
        txtDate.AutoCompleteMode = AutoCompleteMode.Suggest
        txtDate.AutoCompleteSource = AutoCompleteSource.CustomSource
        txtDate.AutoCompleteCustomSource = col
    End Sub

    Private Sub txtDate_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDate.TextChanged
        If txtDate.Text = "" Then
            ListView1.Items.Clear()
            lblCash.Text = "0.0"
            lblCount.Text = "0"
        End If
    End Sub

    Private Sub txtDate_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtDate.KeyDown
        If e.KeyCode = Keys.Enter Then
            ListView1.Items.Clear()
            Try
                cm = New SqlCommand("select * from vwTransaction where date like '" & txtDate.Text & "' order by name", cn)
                dr = cm.ExecuteReader
                If dr.HasRows Then
                    While dr.Read
                        lst = ListView1.Items.Add(dr.Item(0).ToString) ' id
                        lst.SubItems.Add(dr.Item(1).ToString) 'name
                        lst.SubItems.Add(dr.Item(2).ToString) 'address
                        lst.SubItems.Add(dr.Item(3).ToString) 'age
                        lst.SubItems.Add(dr.Item(4).ToString) 'orno
                        lst.SubItems.Add(dr.Item(5).ToString) 'seatno
                        lst.SubItems.Add(dr.Item(6).ToString) 'classification
                        lst.SubItems.Add(String.Format("{0:0.0}", dr.Item(7))) 'payment
                        lst.SubItems.Add(dr.Item(8)) 'cargo
                        lst.SubItems.Add(String.Format("{0:0.0}", dr.Item(9))) 'cp
                        lst.SubItems.Add(String.Format("{0:0.0}", dr.Item(10))) 'total
                        lst.SubItems.Add(String.Format("{0:0.0}", dr.Item(11))) 'cash
                        lst.SubItems.Add(String.Format("{0:0.0}", dr.Item(12))) 'change
                        lst.SubItems.Add(dr.Item(13).ToString) 'date
                        lst.SubItems.Add(dr.Item(14).ToString) 'time
                    End While
                    dr.Close()
                    lblCount.Text = recordCount("select count(date) from vwTransaction where date like '" & txtDate.Text & "'")
                    Dim cash As Double = recordCount("select sum(payment) from vwTransaction where date like '" & txtDate.Text & "'")
                    lblCash.Text = String.Format("{0:0.0}", cash)
                Else
                    MessageBox.Show("Record not found.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                    dr.Close()
                End If
                dr.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If
    End Sub

    Private Sub btnView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnView.Click
        If is_empty(txtDate) = True Then Exit Sub
        frmCenter.auditTrail(uID, "Print the list of " & txtDate.Text & "")
        frmCenter.dawat(uID, loginDate)
        frmReportList.ShowDialog()
    End Sub
End Class