Public Class frmListPatient
    Dim condition As String
    Private Sub frmListPatient_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            sql = "SELECT `CASENUM` as 'Case Number', concat(`LNAME`, ', ' , `FNAME`) as 'Name', `PADD` as 'Address', `GENDER` as 'Gender', `CIVILSTATUS` as 'CivilStatus', `PHILHEALTH` as 'Philhealth',ADMITTED as 'Admitted' FROM `tblpatient` "
            RETRIEVEDTG(dtgList, sql)
            dtgList.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells)
        Catch ex As Exception

        End Try
    End Sub

    Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
        Try
            condition = "concat(`CASENUM`, ' ' ,`LNAME`, ' ' , `FNAME`) LIKE '%" & txtSearch.Text & "%'"
            sql = "SELECT `CASENUM` as 'Case Number', concat(`LNAME`, ', ' , `FNAME`) as 'Name', `PADD` as 'Address', `GENDER` as 'Gender', `CIVILSTATUS` as 'CivilStatus', `PHILHEALTH` as 'Philhealth',ADMITTED as 'Admitted' FROM `tblpatient` WHERE " & condition
            RETRIEVEDTG(dtgList, sql)
            dtgList.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub dtgList_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtgList.DoubleClick
        Try


            sql = "SELECT * FROM tblpatient WHERE ADMITTED=1 AND CASENUM= " & dtgList.CurrentRow.Cells(0).Value
            result = RETRIEVESINGLE(sql)
            If result = True Then
                MsgBox("Patient is already admitted.", MsgBoxStyle.Exclamation)
            Else
                frmEr.txtpatientCasenum.Text = dtgList.CurrentRow.Cells(0).Value
                Me.Close()
                frmEr.Show()
                frmEr.Focus()
            End If

        Catch ex As Exception

        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub

    Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        Try
            sql = "SELECT * FROM tblpatient WHERE CASENUM =" & dtgList.CurrentRow.Cells(0).Value
            reports(sql, "patientId", frmPatienId.CrystalReportViewer1) 
            With frmPatienId
                .Show()
                .Focus()
            End With
        Catch ex As Exception

        End Try
    End Sub
End Class