Imports System.IO Imports System.Data.SqlClient Imports CLIENTE.dmModulo Imports CLIENTE.Registro 'controla password Public Class Login Inherits System.Windows.Forms.Form Public Usuario As Boolean = True #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. 'MsgBox("entro") InitializeComponent() 'MsgBox("paso") 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents PictureBox2 As System.Windows.Forms.PictureBox Friend WithEvents btnAceptar As System.Windows.Forms.Button Friend WithEvents btnCancelar As System.Windows.Forms.Button Friend WithEvents txtUsuario As System.Windows.Forms.TextBox Friend WithEvents txtClave As System.Windows.Forms.TextBox Public WithEvents lblIdPerfil As System.Windows.Forms.Label Friend WithEvents lblNombreCompleto As System.Windows.Forms.Label Friend WithEvents lblNombrePerfil As System.Windows.Forms.Label Friend WithEvents lblAM As System.Windows.Forms.Label Friend WithEvents lblAP As System.Windows.Forms.Label Friend WithEvents Panel1 As System.Windows.Forms.Panel Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents lblNombreUsuario As System.Windows.Forms.Label Friend WithEvents LinkLabel1 As System.Windows.Forms.LinkLabel Private Sub InitializeComponent() Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Login)) Me.PictureBox2 = New System.Windows.Forms.PictureBox Me.btnAceptar = New System.Windows.Forms.Button Me.btnCancelar = New System.Windows.Forms.Button Me.txtUsuario = New System.Windows.Forms.TextBox Me.txtClave = New System.Windows.Forms.TextBox Me.lblIdPerfil = New System.Windows.Forms.Label Me.lblNombreCompleto = New System.Windows.Forms.Label Me.lblNombrePerfil = New System.Windows.Forms.Label Me.lblAM = New System.Windows.Forms.Label Me.lblAP = New System.Windows.Forms.Label Me.Panel1 = New System.Windows.Forms.Panel Me.LinkLabel1 = New System.Windows.Forms.LinkLabel Me.lblNombreUsuario = New System.Windows.Forms.Label Me.Label2 = New System.Windows.Forms.Label Me.Panel1.SuspendLayout() Me.SuspendLayout() ' 'PictureBox2 ' Me.PictureBox2.Image = CType(resources.GetObject("PictureBox2.Image"), System.Drawing.Image) Me.PictureBox2.Location = New System.Drawing.Point(8, 6) Me.PictureBox2.Name = "PictureBox2" Me.PictureBox2.Size = New System.Drawing.Size(38, 36) Me.PictureBox2.TabIndex = 1 Me.PictureBox2.TabStop = False ' 'btnAceptar ' Me.btnAceptar.BackColor = System.Drawing.Color.MidnightBlue Me.btnAceptar.Cursor = System.Windows.Forms.Cursors.Hand Me.btnAceptar.FlatStyle = System.Windows.Forms.FlatStyle.Flat Me.btnAceptar.Font = New System.Drawing.Font("Tahoma", 8.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.btnAceptar.ForeColor = System.Drawing.Color.White Me.btnAceptar.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft Me.btnAceptar.Location = New System.Drawing.Point(66, 90) Me.btnAceptar.Name = "btnAceptar" Me.btnAceptar.Size = New System.Drawing.Size(74, 24) Me.btnAceptar.TabIndex = 2 Me.btnAceptar.Text = "Aceptar" ' 'btnCancelar ' Me.btnCancelar.BackColor = System.Drawing.Color.MidnightBlue Me.btnCancelar.Cursor = System.Windows.Forms.Cursors.Hand Me.btnCancelar.DialogResult = System.Windows.Forms.DialogResult.Cancel Me.btnCancelar.FlatStyle = System.Windows.Forms.FlatStyle.Flat Me.btnCancelar.Font = New System.Drawing.Font("Tahoma", 8.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.btnCancelar.ForeColor = System.Drawing.Color.White Me.btnCancelar.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft Me.btnCancelar.Location = New System.Drawing.Point(147, 90) Me.btnCancelar.Name = "btnCancelar" Me.btnCancelar.Size = New System.Drawing.Size(81, 23) Me.btnCancelar.TabIndex = 3 Me.btnCancelar.Text = "Cancelar" ' 'txtUsuario ' Me.txtUsuario.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper Me.txtUsuario.Font = New System.Drawing.Font("Tahoma", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.txtUsuario.Location = New System.Drawing.Point(110, 32) Me.txtUsuario.MaxLength = 15 Me.txtUsuario.Name = "txtUsuario" Me.txtUsuario.Size = New System.Drawing.Size(130, 23) Me.txtUsuario.TabIndex = 0 Me.txtUsuario.Text = "" ' 'txtClave ' Me.txtClave.Font = New System.Drawing.Font("Tahoma", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.txtClave.Location = New System.Drawing.Point(110, 56) Me.txtClave.MaxLength = 15 Me.txtClave.Name = "txtClave" Me.txtClave.PasswordChar = Microsoft.VisualBasic.ChrW(42) Me.txtClave.Size = New System.Drawing.Size(130, 23) Me.txtClave.TabIndex = 1 Me.txtClave.Text = "" ' 'lblIdPerfil ' Me.lblIdPerfil.Location = New System.Drawing.Point(112, 0) Me.lblIdPerfil.Name = "lblIdPerfil" Me.lblIdPerfil.Size = New System.Drawing.Size(40, 8) Me.lblIdPerfil.TabIndex = 6 ' 'lblNombreCompleto ' Me.lblNombreCompleto.Location = New System.Drawing.Point(-24, 176) Me.lblNombreCompleto.Name = "lblNombreCompleto" Me.lblNombreCompleto.Size = New System.Drawing.Size(19, 23) Me.lblNombreCompleto.TabIndex = 8 ' 'lblNombrePerfil ' Me.lblNombrePerfil.Location = New System.Drawing.Point(238, 0) Me.lblNombrePerfil.Name = "lblNombrePerfil" Me.lblNombrePerfil.Size = New System.Drawing.Size(36, 12) Me.lblNombrePerfil.TabIndex = 9 ' 'lblAM ' Me.lblAM.Location = New System.Drawing.Point(32, 16) Me.lblAM.Name = "lblAM" Me.lblAM.Size = New System.Drawing.Size(8, 23) Me.lblAM.TabIndex = 10 ' 'lblAP ' Me.lblAP.Location = New System.Drawing.Point(304, 8) Me.lblAP.Name = "lblAP" Me.lblAP.Size = New System.Drawing.Size(48, 23) Me.lblAP.TabIndex = 11 ' 'Panel1 ' Me.Panel1.BackColor = System.Drawing.Color.FromArgb(CType(202, Byte), CType(202, Byte), CType(183, Byte)) Me.Panel1.Controls.Add(Me.LinkLabel1) Me.Panel1.Controls.Add(Me.lblAM) Me.Panel1.Controls.Add(Me.txtUsuario) Me.Panel1.Controls.Add(Me.btnAceptar) Me.Panel1.Controls.Add(Me.lblNombrePerfil) Me.Panel1.Controls.Add(Me.txtClave) Me.Panel1.Controls.Add(Me.PictureBox2) Me.Panel1.Controls.Add(Me.btnCancelar) Me.Panel1.Controls.Add(Me.lblNombreUsuario) Me.Panel1.Controls.Add(Me.Label2) Me.Panel1.Location = New System.Drawing.Point(8, 8) Me.Panel1.Name = "Panel1" Me.Panel1.Size = New System.Drawing.Size(272, 152) Me.Panel1.TabIndex = 12 ' 'LinkLabel1 ' Me.LinkLabel1.LinkColor = System.Drawing.Color.FromArgb(CType(128, Byte), CType(128, Byte), CType(255, Byte)) Me.LinkLabel1.Location = New System.Drawing.Point(3, 135) Me.LinkLabel1.Name = "LinkLabel1" Me.LinkLabel1.Size = New System.Drawing.Size(141, 23) Me.LinkLabel1.TabIndex = 14 Me.LinkLabel1.TabStop = True Me.LinkLabel1.Text = "Condor Business Solutions" ' 'lblNombreUsuario ' Me.lblNombreUsuario.BackColor = System.Drawing.Color.FromArgb(CType(202, Byte), CType(202, Byte), CType(183, Byte)) Me.lblNombreUsuario.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblNombreUsuario.ForeColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(51, Byte), CType(102, Byte)) Me.lblNombreUsuario.Location = New System.Drawing.Point(46, 34) Me.lblNombreUsuario.Name = "lblNombreUsuario" Me.lblNombreUsuario.Size = New System.Drawing.Size(72, 18) Me.lblNombreUsuario.TabIndex = 11 Me.lblNombreUsuario.Text = "Usuario:" Me.lblNombreUsuario.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ' 'Label2 ' Me.Label2.BackColor = System.Drawing.Color.FromArgb(CType(202, Byte), CType(202, Byte), CType(183, Byte)) Me.Label2.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.ForeColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(51, Byte), CType(102, Byte)) Me.Label2.Location = New System.Drawing.Point(42, 56) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(72, 18) Me.Label2.TabIndex = 13 Me.Label2.Text = "Password:" Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ' 'Login ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14) Me.BackColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(51, Byte), CType(102, Byte)) Me.ClientSize = New System.Drawing.Size(290, 170) Me.Controls.Add(Me.Panel1) Me.Controls.Add(Me.lblAP) Me.Controls.Add(Me.lblNombreCompleto) Me.Controls.Add(Me.lblIdPerfil) Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon) Me.Name = "Login" Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen Me.Text = "MINDS" Me.Panel1.ResumeLayout(False) Me.ResumeLayout(False) End Sub #End Region 'Declaracion de variables globales Dim strConnection As String 'Para conectarme a la base de datos Dim dap1 As SqlDataAdapter = New SqlDataAdapter() Dim cnn1 As SqlConnection Dim cmd1 As SqlCommand Dim das1 As DataSet Dim Cadena As String Public Shared IdPerfil As String Public Shared NombreUsuario As String Public Shared NombreCompleto As String Public Shared NombrePerfil As String Dim contador As Integer Dim clCmp As clsComplejo = New clsComplejo Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click 'Me.Close() Application.Exit() End Sub Private Sub ConectarBD() 'dmModulo.SqlConnection.ConnectionString = strConnection cnn1 = New 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 LeeRegEdit() dmModulo.Conexion = False strConnection = "" dmModulo.strConnection = "" dmModulo.CadenaConexion(GetSetting("MIndsAgro", "Conexion", "TipoServidorMD", "25"), _ GetSetting("MIndsAgro", "Conexion", "Servidor", "25"), _ GetSetting("MIndsAgro", "Conexion", "BaseDatos", "25"), _ GetSetting("MIndsAgro", "Conexion", "Usuario", "25"), _ GetSetting("MIndsAgro", "Conexion", "Password", "25")) strConnection = dmModulo.strConnection Try dmModulo.SqlConnection.ConnectionString = strConnection dmModulo.SqlConnection.Open() 'Abre la conexion Conexion = True Catch dataException As Exception MessageBox.Show("No se ha podido conectar a la base de datos. Verifique con el administrador del sistema." + Chr(13) + _ "Detalles : " + Chr(13) + dataException.Message, "Mensaje de sistema", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) Finally 'dmModulo.SqlConnection.Close() 'Cierra la conexion ',modificada End Try End Sub Private Sub CambiaApariencia(ByVal Sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnAceptar.MouseMove, btnCancelar.MouseMove Try Dim Boton As Button Boton = Sender Boton.BackColor = System.Drawing.Color.Blue Boton.Font = New System.Drawing.Font("Tahoma", 10.5!, CType((System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Underline), System.Drawing.FontStyle), System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Catch ex As Exception End Try End Sub Private Sub RegresaApariencia(ByVal Sender As System.Object, ByVal e As System.EventArgs) Handles btnAceptar.MouseLeave, btnCancelar.MouseLeave Try Dim Boton As Button Boton = Sender Boton.BackColor = System.Drawing.Color.MidnightBlue Boton.Font = New System.Drawing.Font("Tahoma", 8.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Catch ex As Exception End Try End Sub Private Sub btnAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAceptar.Click Dim PasswordEncriptado As String Dim CLassReg As New LeeEditorRegistro Dim _FechaActual As String = Now 'MSGBOX = Registro.DesEncripta("246054246230070247035003031") Dim Classcom As New clsComplejo Dim Prueba As New Odbc.OdbcConnection PasswordEncriptado = Registro.Encripta(txtClave.Text) If Usuario = True Then CLassReg.LEE(clsVaribles.Conexion.ConnectionString) dmModulo.SqlConnection.ConnectionString = dmModulo.strConnection 'dmModulo.SqlConnection.ConnectionString = "DSN=MindsConeccion" dmModulo.SqlConnection.Open() 'Prueba.ConnectionString = "DSN=MindsConeccion" 'Prueba.Open() Conexion = True End If 'si dmModulo.conexion = true significa que la base esta abierta If dmModulo.Conexion = True Then Dim frmSplash As splash = New splash Dim Command As New Command Try Command.spsql = "spcbExisteUsuario '" & Trim(txtUsuario.Text) & "', '" & PasswordEncriptado & "'" 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á en " & DiasRestantes & " dias" & " ¿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") & "', '" & Me.txtUsuario.Text & "', 'A'" clCmp.sbGuardaModifica(CadSQL) '***AUDITORIA clsVaribles.varUsuario = clCmp.BuscaValores("idusuario", "usuario", "usuario = '" & My.User.Name & "'") 'AUDITORIA Dim ClassAud As New ClassMyUtils Dim varUser As Long Dim ClassComodin As New clsComplejo 'varUser = ClassComodin.BuscaValores("IdUsuario", "usuario", "usuario = '" & My.User.Name & "'") ClassAud.RT_Auditoria(clsVaribles.varUsuario, 1, 1, My.User.Name) 'ClassAud.RT_Auditoria(clsVaribles.varUsuario, 1, My.Computer.Name, "Minds Cliente", "Entrada Minds Cliente") 'FIN AUDITORIA LlamaPrincipal() '*************** 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) End If If contador >= 3 Then 'Estableco el query para bloquear la cuenta Dim SQL As String = "" SQL = "spUltimoAcceso ' " & Classcom.ObtenFecha(_FechaActual, "yyyymmdd") & "', '" & 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 End Sub Private Sub Enlazar() 'Enlazo los datos lblIdPerfil.DataBindings.Add(New Binding("Text", das1, "UsuarioPefil.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 End Sub Private Sub txtUsuario_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtUsuario.Enter txtUsuario.SelectAll() End Sub Private Sub txtClave_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtClave.Enter txtClave.SelectAll() End Sub Private Sub Cadenas_Select() Cadena = "select * from UsuarioPefil WHERE Usuario = '" Cadena = Cadena & txtUsuario.Text & "'" cmd1 = New 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 LlamaPrincipal() Try Dim frmPrincipal As mdiForm = New mdiForm 'frmPrincipal.entrar(txtUsuario.Text.Trim, txtClave.Text.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 Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.CancelButton = btnCancelar Me.AcceptButton = btnAceptar validar_textbox() End Sub Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked 'llama a una funcion que me permite enlazar a una pagina VisitLink() End Sub Sub VisitLink() Try 'Llama el metodo Process.Start para abrir el navegador por defaul y abre la URL System.Diagnostics.Process.Start("http://condorbs.com") Catch ex As Exception MessageBox.Show(ex.Message, "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub validar_textbox() 'Valida que la longuitud de la propiedad text de las cajas sea igual a 0 'para deshabilitar el boton de aceptar If (txtUsuario.Text.Length = 0 Or txtClave.Text.Length = 0) Then btnAceptar.Enabled = False Else 'si la longuitud es mayor de 0 se habilita el boton de aceptar If txtClave.Text.Length > 0 Then btnAceptar.Enabled = True End If End If End Sub Private Sub TxtUsuario_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtUsuario.TextChanged 'si la caja de texto (usuario) cambio en su propiedad text, se valida nuevamente validar_textbox() End Sub Private Sub TxtClave_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtClave.TextChanged 'si la caja de texto (contraseña) cambio en su propiedad text, se valida nuevamente validar_textbox() End Sub End Class