Imports System.Data.SqlClient

Public Class frmLogin

    ' TODO: Insert code to perform custom authentication using the provided username and password 
    ' (See http://go.microsoft.com/fwlink/?LinkId=35339).  
    ' The custom principal can then be attached to the current thread's principal as follows: 
    '     My.User.CurrentPrincipal = CustomPrincipal
    ' where CustomPrincipal is the IPrincipal implementation used to perform authentication. 
    ' Subsequently, My.User will return identity information encapsulated in the CustomPrincipal object
    ' such as the username, display name, etc.

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click

        If String.IsNullOrEmpty(txtUsuario.Text) Then
            MsgBox("Informe o nome do Usuário")
            txtUsuario.Focus()
        Else
            If String.IsNullOrEmpty(txtSenha.Text) Then
                MsgBox("Informe a senha de usuário")
                txtSenha.Focus()
            Else

                Dim clsLogin As New clsLogin
                intCodigo_Func = clsLogin.ValidaFuncionario(txtUsuario.Text, txtSenha.Text)

                If intCodigo_Func > 0 Then
                    blnAutenticado = True
                    intCodigo_Func = intCodigo_Func
                    Dim dr As SqlDataReader = clsLogin.UserRoleFuncionario(intCodigo_Func)
                    If dr.Read() Then
                        strRole = dr("NOME_CARGO")
                        strNomeUser = dr("NOME_FUNC")
                    End If
                    Me.Hide()
                    Dim mdiCadastro As New MDICadastro
                    With MDICadastro
                        .Show()
                    End With


                    Dim clsbanco As New clsBanco
                    Dim strsql As String
                    strsql = "select * from sysdatabases where name='SSM'"
                    dr = clsbanco.RetornaDataReaderMaster(strsql.ToString)
                    If dr.Read() Then
                        Exit Sub
                    Else
                        Dim path As String = My.Application.Info.DirectoryPath.Replace("\bin\Debug", "") & "\Documentos\SqlSSM.sql"
                        Dim strBanco As String = "SSM"
                        ExecutaSql(path, strBanco)
                    End If






                Else
                    MsgBox("Usuário ou senha não conferem")
                    txtUsuario.Focus()
                End If
            End If
        End If

    End Sub

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

End Class
