Public Class frmListRoom

    Private Sub frmListRoom_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            sql = "SELECT  `ROOMID` as 'Room Id', concat(`RNAME`, ' - ', `DOCTOR`) as 'Room', `RBEDNUM` as 'Number of Beds', `DIAGNOSIS` as 'Diagnosis', `STATION` as 'Station', `ROOMTYPE` as 'Type' FROM `tblroom`"
            result = RETRIEVEDTG(dtglist, sql)
            If result = True Then
                Dim maxrow As Integer = dtglist.Rows.Count
                lblend.Text = maxrow
                lblfirst.Text = 0
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
 
    Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
        Try
            With frmRoom
                .Show()
                .Focus()
            End With
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnedit.Click
        Try
            With frmRoom
                .TXTROOMID.Text = dtglist.CurrentRow.Cells(0).Value
                .LBLTITLE.Text = "Update Room / Ward"
                .Show()
                .Focus()
                .TXTROOMID.Visible = True
                .lblroomid.Visible = True

            End With
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub txtsearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch.TextChanged
        Try
            If txtsearch.Text = "" Then
                sql = "SELECT  `ROOMID` as 'Room Id', concat(`RNAME`, ' - ', `DOCTOR`) as 'Room', `RBEDNUM` as 'Number of Beds', `DIAGNOSIS` as 'Description', `STATION` as 'Station', `ROOMTYPE` as 'Type' FROM `tblroom`"
                result = RETRIEVEDTG(dtglist, sql)
                If result = True Then
                    Dim maxrow As Integer = dtglist.Rows.Count
                    lblend.Text = maxrow
                    lblfirst.Text = 0
                End If
            Else
                Dim CONDITION As String = "WHERE CONCAT(`ROOMID`,' ', `RNAME`,' ', `RBEDNUM`,' ', `DIAGNOSIS`,' ', `STATION`,' ' , `ROOMTYPE`) LIKE '%" & txtsearch.Text & "%'"
                sql = "SELECT  `ROOMID` as 'Room Id', concat(`RNAME`, ' - ', `DOCTOR`) as 'Room', `RBEDNUM` as 'Number of Beds', `DIAGNOSIS` as 'Description', `STATION` as 'Station', `ROOMTYPE` as 'Type' FROM `tblroom` " & CONDITION
                result = RETRIEVEDTG(dtglist, sql)
                If result = True Then
                    Dim maxrow As Integer = dtglist.Rows.Count
                    lblend.Text = maxrow
                    lblfirst.Text = 0
                End If
            End If
          
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btndel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndel.Click
        Try
            sql = "DELETE  FROM `tblroom` WHERE `ROOMID`=" & dtglist.CurrentRow.Cells(0).Value
            CUD(sql)
            sql = "DELETE  FROM `tblbed` WHERE `ROOMID`=" & dtglist.CurrentRow.Cells(0).Value
            CUD(sql)
            sql = "SELECT  `ROOMID` as 'Room Id', concat(`RNAME`, ' - ', `DOCTOR`) as 'Room', `RBEDNUM` as 'Number of Beds', `DIAGNOSIS` as 'Description', `STATION` as 'Station', `ROOMTYPE` as 'Type' FROM `tblroom`"
            result = RETRIEVEDTG(dtglist, sql)
            If result = True Then
                Dim maxrow As Integer = dtglist.Rows.Count
                lblend.Text = maxrow
                lblfirst.Text = 0
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclose.Click
        Me.Close()
    End Sub
End Class