Public Class frmPhysician

    Private Sub frmPhysician_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Call btnNew_Click(sender, e)
        Catch ex As Exception
            Me.Text = ex.Message
            Beep()
            'MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            If txtname.Text = "" Or cboType.Text = "" Then
                MsgBox("All fields are requierd!", MsgBoxStyle.Exclamation)
            Else
                sql = "SELECT * FROM `tbldoctor` WHERE  `DOCID`=" & txtid.Text
                result = RETRIEVESINGLE(sql)
                If result = True Then
                    sql = "UPDATE `tbldoctor` SET `DOCNAME` = '" & txtname.Text & "', `DOCFIELDS`='" & cboType.Text & "',CONTACTNUM='" & txtcontact.Text & "' WHERE  `DOCID`=" & txtid.Text
                    result = CUD(sql)
                    If result = True Then
                        MsgBox("Record has been updated into the datatbase.")
                       Call btnNew_Click(sender, e)
                    Else
                        MsgBox("Query cannot be execute. Please contact administrator.", MsgBoxStyle.Exclamation)
                    End If
                Else
                    sql = "INSERT INTO `tbldoctor` (`DOCID`, `DOCNAME`, `DOCFIELDS`,CONTACTNUM) VALUES (" & txtid.Text & ",'" & txtname.Text & "','" & cboType.Text & "','" & txtcontact.Text & "')"
                    result = CUD(sql)
                    If result = True Then
                        MsgBox("New Record has been saved into the datatbase.")

                        updateautonumbercateg("docid")
                        Call btnNew_Click(sender, e)
                    Else
                        MsgBox("Query cannot be execute. Please contact administrator.", MsgBoxStyle.Exclamation)
                    End If

                End If
            End If
          

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

    Private Sub dtgList_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dtgList.CellClick
        Try
            txtid.Text = dtgList.CurrentRow.Cells(0).Value
            txtname.Text = dtgList.CurrentRow.Cells(1).Value
            cboType.Text = dtgList.CurrentRow.Cells(2).Value
            txtcontact.Text = dtgList.CurrentRow.Cells(3).Value
        Catch ex As Exception
            Me.Text = ex.Message
        End Try
    End Sub

    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
        Try
            cleartext(GroupBox1)
            loadautonumbercateg("docid", txtid)
            sql = "SELECT DOCFIELDS,DOCID FROM `tbldoctor`"
            fillcboD(sql, cboType, "DOCFIELDS", "DOCID")
            sql = "SELECT  `DOCID` AS 'ID', `DOCNAME` AS 'NAME', `DOCFIELDS` AS 'TYPE',CONTACTNUM AS 'CONTACT #' FROM `tbldoctor` "
            RETRIEVEDTG(dtgList, sql)
        Catch ex As Exception
            Me.Text = 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