246 lines
9.3 KiB
VB.net
246 lines
9.3 KiB
VB.net
|
Public Class frmLoginWindows
|
|||
|
|
|||
|
'Declaracion de variables globales
|
|||
|
Dim strConnection As String
|
|||
|
'Para conectarme a la base de datos
|
|||
|
Dim dap1 As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter()
|
|||
|
Dim cnn1 As SqlClient.SqlConnection
|
|||
|
Dim cmd1 As SqlClient.SqlCommand
|
|||
|
|
|||
|
Public Shared IdPerfil As String
|
|||
|
Public Shared NombreUsuario As String
|
|||
|
Public Shared NombreCompleto As String
|
|||
|
Public Shared NombrePerfil As String
|
|||
|
|
|||
|
Dim das1 As DataSet
|
|||
|
Dim Cadena As String
|
|||
|
Dim contador As Integer
|
|||
|
Dim clCmp As clsComplejo = New clsComplejo
|
|||
|
Public Usuario As Boolean = True
|
|||
|
|
|||
|
Private Sub frmLoginWindows_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
|
|||
|
|
|||
|
If clsVaribles.VarProcesoOK Then
|
|||
|
|
|||
|
Me.Visible = False
|
|||
|
Me.Hide()
|
|||
|
|
|||
|
End If
|
|||
|
|
|||
|
End Sub
|
|||
|
|
|||
|
Private Sub frmLoginWindows_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
|||
|
|
|||
|
Dim PasswordEncriptado As String
|
|||
|
Dim ClassReg As New LeeEditorRegistro
|
|||
|
Dim _FechaActual As String = Now
|
|||
|
Dim Classcom As New clsComplejo
|
|||
|
|
|||
|
Me.Visible = True
|
|||
|
|
|||
|
'PasswordEncriptado = Registro.Encripta(txtClave.Text)
|
|||
|
'If usuario = True Then
|
|||
|
ClassReg.LEE(clsVaribles.Conexion.ConnectionString)
|
|||
|
dmModulo.SqlConnection.ConnectionString = dmModulo.strConnection
|
|||
|
'dmModulo.SqlConnection.ConnectionString = "Persist Security Info=False;Integrated Security=SSPI;Server(Local)"
|
|||
|
|
|||
|
Try
|
|||
|
|
|||
|
dmModulo.SqlConnection.Open()
|
|||
|
|
|||
|
Catch ex As Exception
|
|||
|
Chklista.Items.Add("Couldn't Connect to MINDS.Please Contact Your Administrator (Windows Authentication)")
|
|||
|
Exit Sub
|
|||
|
|
|||
|
End Try
|
|||
|
|
|||
|
Conexion = True
|
|||
|
|
|||
|
'End If
|
|||
|
'si dmModulo.conexion = true significa que la base esta abierta
|
|||
|
My.Application.DoEvents()
|
|||
|
|
|||
|
If Conexion = True Then
|
|||
|
|
|||
|
Chklista.Items.Add("Connecting to MINDS Database...")
|
|||
|
|
|||
|
Else
|
|||
|
|
|||
|
Chklista.Items.Add("Couldn't Connect to MINDS.Please Contact Your Administrator")
|
|||
|
|
|||
|
End If
|
|||
|
|
|||
|
If dmModulo.Conexion = True Then
|
|||
|
'Dim frmSplash As splash = New splash
|
|||
|
Dim Command As New Command
|
|||
|
Try
|
|||
|
|
|||
|
Chklista.Items.Add("Authenticating User in MINDS...")
|
|||
|
'Command.spsql = "spcbExisteUsuario '" & Trim(txtUsuario.Text) & "', '" & PasswordEncriptado & "'"
|
|||
|
Command.spsql = "spcbExisteUsuarioWindows '" & Trim(My.User.Name) & "'"
|
|||
|
Command.Count(Command.spsql)
|
|||
|
If Command.Datos > 0 Then
|
|||
|
'usuario = True
|
|||
|
Me.Visible = False
|
|||
|
Me.Hide()
|
|||
|
'frmSplash.Show()
|
|||
|
Application.DoEvents()
|
|||
|
'**************
|
|||
|
'frmSplash.Close()
|
|||
|
'frmSplash.Dispose()
|
|||
|
ConectarBD()
|
|||
|
Enlazar()
|
|||
|
'Verifico cuanto dias tiene el password
|
|||
|
Dim fila As DataRow
|
|||
|
Dim Fecha As String
|
|||
|
Dim FechaOld As Date
|
|||
|
Static Dim dias As Integer
|
|||
|
Dim Result As DialogResult
|
|||
|
fila = das1.Tables(0).Rows(0)
|
|||
|
Fecha = fila("FCambioPassword")
|
|||
|
FechaOld = CDate(Fecha)
|
|||
|
dias = DateDiff(DateInterval.Day, FechaOld, Now) 'Obtiene el numero de dias
|
|||
|
|
|||
|
'If dias >= 7 Then
|
|||
|
' Dim DiasRestantes As Integer = 15 - dias
|
|||
|
' If DiasRestantes <= 0 Then
|
|||
|
' MessageBox.Show("Es necesario que cambies tu password", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Information)
|
|||
|
' Dim frmCamPas As CambioPassword = New CambioPassword
|
|||
|
' frmCamPas.ShowDialog()
|
|||
|
' Else
|
|||
|
' 'Result = MessageBox.Show("Tu password Caducar<61> en " & DiasRestantes & " dias" & " <20>Deseas cambiarlo ahora?", "MINDS", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
|
|||
|
' 'If Result = DialogResult.Yes Then
|
|||
|
' ' Dim frmCamPas As CambioPassword = New CambioPassword
|
|||
|
' ' frmCamPas.ShowDialog()
|
|||
|
' 'End If
|
|||
|
' End If
|
|||
|
'End If
|
|||
|
' MsgBox(dias)
|
|||
|
|
|||
|
'Establesco el query para grabar la fecha del ultimo acceso
|
|||
|
Dim CadSQL As String = ""
|
|||
|
CadSQL = "spUltimoAcceso ' " & Classcom.ObtenFecha(_FechaActual, "yyyymmdd") & "', '" & My.User.Name & "', 'A'"
|
|||
|
clCmp.sbGuardaModifica(CadSQL)
|
|||
|
|
|||
|
Chklista.Items.Add("Accessing Aplication...")
|
|||
|
|
|||
|
clsVaribles.VarProcesoOK = True
|
|||
|
|
|||
|
'AUDITORIA
|
|||
|
Dim ClassAud As New ClassMyUtils
|
|||
|
Dim varUser As Long
|
|||
|
Dim ClassComodin As New clsComplejo
|
|||
|
|
|||
|
varUser = ClassComodin.BuscaValores("IdUsuario", "usuario", "usuario = '" & My.User.Name & "'")
|
|||
|
clsVaribles.varUsuario = varUser
|
|||
|
ClassAud.RT_Auditoria(clsVaribles.varUsuario, 1, 1, My.User.Name)
|
|||
|
|
|||
|
' ClassAud.RT_Auditoria(varUser, 1, My.Computer.Name, "Minds Cliente", "Minds Cliente")
|
|||
|
'FIN AUDITORIA
|
|||
|
|
|||
|
|
|||
|
'BTAceptar.PerformClick()
|
|||
|
|
|||
|
'***************
|
|||
|
Else
|
|||
|
Usuario = False
|
|||
|
contador = contador + 1 ' Se utiliza para indicar q el usuario solo puede hacer tres intentos de conexion
|
|||
|
'MessageBox.Show("No existe su cuenta de usuario en el sistema o no es un usuario activo.", "Mensaje del sistema", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
|
|||
|
Chklista.Items.Add("Couldn't Authenticate to MINDS.Please Contact Your Administrator")
|
|||
|
End If
|
|||
|
|
|||
|
'If contador >= 3 Then
|
|||
|
' 'Estableco el query para bloquear la cuenta
|
|||
|
' Dim SQL As String = ""
|
|||
|
' SQL = "spUltimoAcceso ' " & _FechaActual & "', '" & Me.txtUsuario.Text & "', 'B'"
|
|||
|
' clCmp.sbGuardaModifica(SQL)
|
|||
|
' MsgBox("tu cuenta ha sido bloqueada consulta al administrador del sistema")
|
|||
|
' Application.Exit() 'cierra todo el sistema
|
|||
|
'End If
|
|||
|
Catch a As Exception
|
|||
|
MessageBox.Show(a.Message)
|
|||
|
Finally
|
|||
|
'dmModulo.SqlConnection.Close() 'Cierra la conexion ',modificada
|
|||
|
End Try
|
|||
|
End If
|
|||
|
|
|||
|
|
|||
|
If clsVaribles.VarProcesoOK Then
|
|||
|
Me.Visible = False
|
|||
|
Me.Hide()
|
|||
|
|
|||
|
LlamaPrincipal()
|
|||
|
|
|||
|
End If
|
|||
|
|
|||
|
|
|||
|
End Sub
|
|||
|
|
|||
|
Private Sub ConectarBD()
|
|||
|
'dmModulo.SqlConnection.ConnectionString = strConnection
|
|||
|
cnn1 = New SqlClient.SqlConnection(dmModulo.strConnection)
|
|||
|
Cadenas_Select()
|
|||
|
Try
|
|||
|
cnn1.Open()
|
|||
|
'MsgBox("base abierta")
|
|||
|
Llenar_Dataset()
|
|||
|
Catch er As Exception
|
|||
|
MessageBox.Show("Error en el metodo ConectarBD. " & er.Message)
|
|||
|
Finally
|
|||
|
cnn1.Close()
|
|||
|
End Try
|
|||
|
End Sub
|
|||
|
|
|||
|
Private Sub Enlazar()
|
|||
|
'Enlazo los datos
|
|||
|
lblidperfil.DataBindings.Add(New Binding("Text", das1, "idPerfil"))
|
|||
|
lblNombreUsuario.DataBindings.Add(New Binding("Text", das1, "UsuarioPefil.Usuario"))
|
|||
|
lblNombrePerfil.DataBindings.Add(New Binding("Text", das1, "UsuarioPefil.NombrePerfil"))
|
|||
|
lblNombreCompleto.DataBindings.Add(New Binding("Text", das1, "UsuarioPefil.Nombre"))
|
|||
|
lblAP.DataBindings.Add(New Binding("Text", das1, "UsuarioPefil.APaterno"))
|
|||
|
lblAM.DataBindings.Add(New Binding("Text", das1, "UsuarioPefil.AMaterno"))
|
|||
|
'Asigancion de valores para compartir en toda la aplicacion+
|
|||
|
IdPerfil = lblIdPerfil.Text
|
|||
|
NombreUsuario = lblNombreUsuario.Text
|
|||
|
NombreCompleto = lblNombreCompleto.Text & " "
|
|||
|
NombreCompleto = NombreCompleto & lblAP.Text & " "
|
|||
|
NombreCompleto = NombreCompleto & lblAM.Text
|
|||
|
NombrePerfil = lblNombrePerfil.Text
|
|||
|
clsVaribles.VarPerfil = das1.Tables(0).Rows(0).Item("idperfil")
|
|||
|
|
|||
|
End Sub
|
|||
|
Private Sub LlamaPrincipal()
|
|||
|
Try
|
|||
|
Dim frmPrincipal As mdiForm = New mdiForm
|
|||
|
'frmPrincipal.entrar(My.User.Name.Trim) 'MARCA ERROR ESTA LINEA
|
|||
|
'frmPrincipal.IsMdiContainer = True
|
|||
|
frmPrincipal.Show()
|
|||
|
|
|||
|
Catch er As Exception
|
|||
|
MessageBox.Show(er.Message & " Error al cargar el formulario principal")
|
|||
|
End Try
|
|||
|
End Sub
|
|||
|
|
|||
|
Private Sub Cadenas_Select()
|
|||
|
Cadena = "select * from UsuarioPefil WHERE Usuario = '"
|
|||
|
Cadena = Cadena & My.User.Name & "'"
|
|||
|
cmd1 = New SqlClient.SqlCommand(Cadena, cnn1)
|
|||
|
dap1.SelectCommand = cmd1
|
|||
|
End Sub
|
|||
|
|
|||
|
Private Sub Llenar_Dataset()
|
|||
|
'Lleno el dataset con la vista usurioPerfil
|
|||
|
das1 = New DataSet
|
|||
|
dap1.Fill(das1, "UsuarioPefil")
|
|||
|
'MsgBox("llene dateset")
|
|||
|
End Sub
|
|||
|
|
|||
|
Private Sub BTAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTAceptar.Click
|
|||
|
|
|||
|
Me.Visible = False
|
|||
|
Me.Hide()
|
|||
|
|
|||
|
LlamaPrincipal()
|
|||
|
|
|||
|
End Sub
|
|||
|
End Class
|