Public Class frmStation1
   
    Private Sub frmStation1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try 
            sql = "SELECT ROOMID,RNAME as 'Menu' FROM `tblroom` WHERE  `STATION`=" & lblstation.Text
            RETRIEVEDTG(dtgMenu, sql) 
            dtgMenu.Columns(0).Visible = False
            dtgMenu.RowTemplate.Height = 100


            btnBPrec.Visible = False
            btnIVFRecord.Visible = False
            btnPrmNew.Visible = False
            btnResultRec.Visible = False
            btnMedicalChecklist.Visible = False
        Catch ex As Exception
            MsgBox(ex.Message & " " & sql)
        End Try
    End Sub
   
 
    Private Sub dtgMenu_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dtgMenu.CellClick
        Try

  

            sql = "SELECT P.`CASENUM`,ADMITTINGID, CONCAT(`LNAME` , ' , ' ,`FNAME`) as 'Patient' FROM `tblpatient` P , `tbladmitting` A  WHERE `ADMITTED`=1 AND P.`CASENUM`=A.`CASENUM` AND  A.`ROOMID`=" & dtgMenu.CurrentRow.Cells(0).Value
            RETRIEVEDTG(dtglistPatients, sql)
            dtglistPatients.Columns(0).Visible = False
            dtglistPatients.Columns(1).Visible = False
            dtglistPatients.SelectionMode = False



            dtgListmedication.Columns.Clear()
            dtgListBPRec.Columns.Clear()
            dtgListPRNRec.Columns.Clear()

            btnBPrec.Visible = False
            btnIVFRecord.Visible = False
            btnPrmNew.Visible = False
            btnResultRec.Visible = False
            btnMedicalChecklist.Visible = False
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub dtglistPatients_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dtglistPatients.CellClick
 
        showStationList(Me)
    End Sub

 
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        'Try


        '    For i = 0 To dtgListPRNRec.Rows.Count - 2
        '        With dtgListPRNRec.Rows(i)
        '            Dim time As Date = .Cells(2).FormattedValue
        '            'Dim id = .Cells(0).Value
        '            ''MsgBox(.Cells(0).Value)



        '            sql = "SELECT * FROM `tblprnmedication` WHERE CASENUM=" & dtglistPatients.CurrentRow.Cells(1).Value & _
        '           " AND `ADMITTINGID`=" & dtglistPatients.CurrentRow.Cells(0).Value
        '            result = RETRIEVESINGLE_DIS_MSG(sql)
        '            If result = True Then
        '                If dt.Rows(i).Item(0) = .Cells(0).Value.ToString Then
        '                    sql = "UPDATE `tblprnmedication` SET `PRNDATE`='" & DISPLAYDATE(.Cells(1).FormattedValue, "yyyy-MM-dd") & _
        '                          "', `PRNTIME`='" & Format(time, "HH:mm:ss") & _
        '                          "', `DRUGSNAME`='" & .Cells(3).Value & _
        '                          "', `DOSAGE`='" & .Cells(4).Value & _
        '                          "', `ROUTE`='" & .Cells(5).Value & _
        '                          "', `REMARKS`='" & .Cells(6).Value & _
        '                          "' WHERE  `CASENUM`=" & dtglistPatients.CurrentRow.Cells(0).Value & _
        '                          " AND `ADMITTINGID`=" & dtglistPatients.CurrentRow.Cells(1).Value
        '                    result = CUD(sql)
        '                    If result = False Then
        '                        MsgBox("error to update tblprnmedication", MsgBoxStyle.Exclamation)
        '                    End If


        '                End If
        '            Else
        '                If .Cells(0).Value.ToString = "" Then
        '                    sql = "INSERT INTO `tblprnmedication` " & _
        '                         " (`CASENUM`, `ADMITTINGID`, `PRNDATE`, `PRNTIME`, `DRUGSNAME`, `DOSAGE`, `ROUTE`, `REMARKS` ) " & _
        '                         " VALUES (" & dtglistPatients.CurrentRow.Cells(0).Value & _
        '                         "," & dtglistPatients.CurrentRow.Cells(1).Value & _
        '                         ",'" & DISPLAYDATE(.Cells(1).FormattedValue, "yyyy-MM-dd") & _
        '                         "','" & Format(time, "HH:mm:ss") & _
        '                         "','" & .Cells(3).Value & "','" & .Cells(4).Value & _
        '                         "','" & .Cells(5).Value & "','" & .Cells(6).Value & "')"
        '                    result = CUD(sql)
        '                    If result = False Then
        '                        MsgBox("error to save tblprnmedication", MsgBoxStyle.Exclamation)
        '                    End If
        '                End If
        '            End If
        '        End With
        '    Next
        '    For r = 0 To dtgListBPRec.Rows.Count - 2

        '        With dtgListBPRec.Rows(r)
        '            sql = "SELECT * FROM `tblbprecord` WHERE CASENUM=" & dtglistPatients.CurrentRow.Cells(1).Value & _
        '           " AND `ADMITTINGID`=" & dtglistPatients.CurrentRow.Cells(0).Value
        '            result = RETRIEVESINGLE(sql)

        '            Dim date_time As Date = .Cells(1).FormattedValue

        '            If result = True Then
        '                If dt.Rows(r).Item(0) = .Cells(0).Value Then
        '                    sql = "Update tblbprecord SET `BPDATE`='" & Format(date_time, "yyyy-MM-dd HH:mm:ss") & "' , `BP`='" & .Cells(2).Value & "', `PR`='" & .Cells(3).Value & "', `RR`='" & .Cells(4).Value & "'  WHERE`BPID`=" & .Cells(0).FormattedValue
        '                    CUD(sql)
        '                    If result = False Then
        '                        MsgBox("error to update tblbprecord", MsgBoxStyle.Exclamation)
        '                    End If
        '                End If
        '            Else
        '                If .Cells(0).Value.ToString = "" Then
        '                    sql = "INSERT INTO `tblbprecord` ( `CASENUM`, `ADMITTINGID`, `BPDATE`, `BP`, `PR`, `RR`) " & _
        '                                               " VALUES (" & dtglistPatients.CurrentRow.Cells(0).Value & "," & dtglistPatients.CurrentRow.Cells(1).Value & _
        '                                               ",'" & Format(date_time, "yyyy-MM-dd HH:mm:ss") & "','" & .Cells(2).Value & "','" & .Cells(3).Value & "','" & .Cells(4).Value & "' )"
        '                    result = CUD(sql)
        '                    If result = False Then
        '                        MsgBox("error to update tblbprecord", MsgBoxStyle.Exclamation)
        '                    End If
        '                End If

        '            End If
        '        End With
        '    Next 
        '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

    Private Sub btnPrmNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrmNew.Click
        With frmPRMmed
            .lblCaseNum.Text = dtglistPatients.CurrentRow.Cells(0).Value
            .lblAdmitting.Text = dtglistPatients.CurrentRow.Cells(1).Value
            .Show()
            .Focus()

        End With
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIVFRecord.Click
        With frmIVFmed
            .Panel2.Visible = True
            .Panel1.Visible = False
            .lblCaseNum.Text = dtglistPatients.CurrentRow.Cells(0).Value
            .lblAdmitting.Text = dtglistPatients.CurrentRow.Cells(1).Value
            .Show()
            .Focus()
        End With
      
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBPrec.Click
        With frmBPrec
            .lblCaseNum.Text = dtglistPatients.CurrentRow.Cells(0).Value
            .lblAdmitting.Text = dtglistPatients.CurrentRow.Cells(1).Value
            .Show()
            .Focus()
        End With
    End Sub

    Private Sub dtgIVFRecord_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtgIVFRecord.DoubleClick
        Try
            With frmIVFmed
                .lblIVFID.Text = dtgIVFRecord.CurrentRow.Cells(0).Value
                .lblCaseNum.Text = dtglistPatients.CurrentRow.Cells(0).Value
                .lblAdmitting.Text = dtglistPatients.CurrentRow.Cells(1).Value
                '.txtupdate_bottle.Text = dtgIVFRecord.CurrentRow.Cells(2).Value
                .Show()
                .Focus()
                .Panel2.Visible = False
                .Panel1.Visible = True
            End With

            sql = " SELECT  *  FROM `tblivfrecord`   " & _
                  " WHERE  `IVFID`  = " & dtgIVFRecord.CurrentRow.Cells(0).Value
            result = RETRIEVESINGLE(sql)
            If result = True Then
                With dt.Rows(0)
                    Dim strTime As Date = .Item("STARTEDTIME")
                    frmIVFmed.txtupdate_bottle.Text = .Item("BOTTLENUM")
                    frmIVFmed.txtupdate_KindSol.Text = .Item("KINDOFSOLUTION")
                    frmIVFmed.txtupdate_Amount.Text = .Item("IVFAMOUNT")
                    frmIVFmed.txtupdate_Medication.Text = .Item("MEDICATIONADDERT")
                    frmIVFmed.txtupdate_rate.Text = .Item("IVFRATE")
                    frmIVFmed.txtupdate_Nurse.Text = .Item("STARTNURSE")
                    frmIVFmed.txtnurse2.Text = .Item("ENDNURSE")
                    frmIVFmed.txtivfRemarks.Text = .Item("IVFREMARKS")
                    frmIVFmed.dtpupdate_startTime.Text = .Item("STARTEDTIME")
                    'frmIVFmed.dtpEndTime.Value = Format(.Item("ENDEDTIME"), "MM/dd/yyy h:m:s tt")
                    'frmIVFmed.dtpDate.Value = DISPLAYDATE(.Item("ENDDATE"), "MM/dd/yyyy")

                End With
            End If

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

    Private Sub dtgIVFRecord_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dtgIVFRecord.CellContentClick

    End Sub

    Private Sub btnMedicalChecklist_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMedicalChecklist.Click
        With frmNursesNotes
            .lblCaseNum.Text = dtglistPatients.CurrentRow.Cells(0).Value
            .lblAdmitting.Text = dtglistPatients.CurrentRow.Cells(1).Value
            .Show()
            .Focus()
        End With
    End Sub
End Class