Imports MySql.Data.MySqlClient
Module user
    Public con As MySqlConnection = mysqldb()
 
    Public Sub login(ByVal username As Object, ByVal pass As Object)
        Try

            con.Open()
            reloadtxt("SELECT * FROM user WHERE user_name= '" & username & "' and pass = sha1('" & pass & "')")

           
            If dt.Rows.Count > 0 Then
                If dt.Rows(0).Item("type") = "Administrator" Then
                    MsgBox("You have successfully logged in as an " & dt.Rows(0).Item("type"))
                    With Form1
                        .btnLogin.Text = "Logout"
                        '.btnAdmit.Visible = True
                        '.btnStation.Visible = True
                        '.btnDischarge.Visible = True
                        .btnRooms.Visible = True
                        .btnPatient.Visible = True
                        .btnPhysician.Visible = True
                        .btnManageUser.Visible = True
                        .btnDiagnosis.Visible = True
                        .btnReport.Visible = True
                        .lbluser.Text = dt.Rows(0).Item("name") & "/ " & dt.Rows(0).Item("type")
                    End With

                    frm_Login.Close()
                ElseIf dt.Rows(0).Item("type") = "ER" Then
                    MsgBox("You have successfully logged in as a " & dt.Rows(0).Item("type"))

                    With Form1
                        .Show()
                        .btnLogin.Text = "Logout"
                        .btnAdmit.Visible = True
                        .lbluser.Text = dt.Rows(0).Item("name") & "/ " & dt.Rows(0).Item("type")

                        frm_Login.Close()
                    End With


                ElseIf dt.Rows(0).Item("type") = "Station 1" Then
                    MsgBox("You have successfully logged in as a " & dt.Rows(0).Item("type"))

                    With Form1
                        .Show()
                        .btnLogin.Text = "Logout" 
                        .btnStation.Visible = True
                        .btnDischarge.Visible = True
                         
                        .lbluser.Text = dt.Rows(0).Item("name") & "/ " & dt.Rows(0).Item("type")
                        frm_Login.Close()
                    End With
                ElseIf dt.Rows(0).Item("type") = "Station 2" Then
                    MsgBox("You have successfully logged in as a " & dt.Rows(0).Item("type"))

                    With Form1
                        .Show()
                        .btnLogin.Text = "Logout" 
                        .btnStation.Visible = True
                        .btnDischarge.Visible = True
                       
                        .lbluser.Text = dt.Rows(0).Item("name") & "/ " & dt.Rows(0).Item("type")
                        frm_Login.Close()
                    End With
                 
                End If

            Else
                MsgBox("Acount doest not exist!", MsgBoxStyle.Information)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        con.Close()
        da.Dispose()
    End Sub
    Public Sub append(ByVal sql As String, ByVal field As String, ByVal txt As Object)
        reloadtxt(sql)
        Try
            Dim r As DataRow
            txt.AutoCompleteCustomSource.Clear()
            For Each r In dt.Rows
                txt.AutoCompleteCustomSource.Add(r.Item(field).ToString)
            Next
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
       

    End Sub
End Module
