示例#1
0
        private void frmPrincipal_Load(object sender, EventArgs e)
        {
            IBLLSysUserRolDTO _BLLUser = new BLLSysUserRolDTO();

            try
            {
                this.Text = Application.ProductName + " Versión:  " + Application.ProductVersion;
                Utilitarios.CultureInfo();
                toolStripStatusLblMensaje.Text = "Usuario Conectado: " + Settings.Default.User;

                foreach (var item in _BLLUser.GetSysUserByFilter(Settings.Default.User))
                {
                    if (item.IdRol == 1)
                    {
                        MessageBox.Show("Usuario Administrador");
                    }
                    if (item.IdRol == 2)
                    {
                        MessageBox.Show("Usuario para uso de procesos");
                        this.toolStripMenuItemMantenimientos.Enabled   = false;
                        this.administracionToolStripMenuItem.Enabled   = false;
                        this.reportesToolStripMenuItemReportes.Enabled = false;
                    }
                    if (item.IdRol == 3)
                    {
                        MessageBox.Show("Usuario para uso de reportes");
                        this.toolStripMenuItemMantenimientos.Enabled   = false;
                        this.administracionToolStripMenuItem.Enabled   = false;
                        this.reportesToolStripMenuItemReportes.Enabled = true;
                        this.toolStripMenuItemProcesos.Enabled         = false;
                    }
                }



                if (!Directory.Exists(@"C:\temp"))
                {
                    Directory.CreateDirectory(@"C:\temp");
                }


                _MyLogControlEventos.InfoFormat("Conectado a Form Principal");
                // Seguridad();
            }
            catch (Exception er)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat("Message        {0}\n", er.Message);
                msg.AppendFormat("Source         {0}\n", er.Source);
                msg.AppendFormat("InnerException {0}\n", er.InnerException);
                msg.AppendFormat("StackTrace     {0}\n", er.StackTrace);
                msg.AppendFormat("TargetSite     {0}\n", er.TargetSite);
                // Log error
                _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString());
                // Mensaje de Error
                MessageBox.Show("Se ha producido el siguiente error " + er.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#2
0
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            // Debe validar los datos requeridos
            IBLLSysUserRolDTO _BLLUser  = new BLLSysUserRolDTO();
            IBLLLogin         _BLLLogin = new BLLLogin();

            epError.Clear();

            try
            {
                if (string.IsNullOrEmpty(this.txtUsuario.Text))
                {
                    epError.SetError(txtUsuario, "Usuario requerido");
                    this.txtUsuario.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(this.txtContrasena.Text))
                {
                    epError.SetError(txtContrasena, "Contraseá requerida");
                    this.txtContrasena.Focus();
                    return;
                }


                Settings.Default.Login    = "******";
                Settings.Default.Password = "******";

                _BLLLogin.Login(Settings.Default.Login,
                                Settings.Default.Password);



                foreach (var item in _BLLUser.GetSysUserByFilter(this.txtUsuario.Text))
                {
                    if (item.Login == this.txtUsuario.Text && item.Password == this.txtContrasena.Text)
                    {
                        // Log de errores
                        _MyLogControlEventos.InfoFormat("Entró a la aplicación");
                        Settings.Default.User = txtUsuario.Text.Trim();
                        this.DialogResult     = DialogResult.OK;
                    }
                }
            }
            catch (Exception er)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat("Message        {0}\n", er.Message);
                msg.AppendFormat("Source         {0}\n", er.Source);
                msg.AppendFormat("InnerException {0}\n", er.InnerException);
                msg.AppendFormat("StackTrace     {0}\n", er.StackTrace);
                msg.AppendFormat("TargetSite     {0}\n", er.TargetSite);
                msg.AppendFormat("Usuario        {0}\n", Settings.Default.Login);

                _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString());


                // Incrementar el contador
                contador++;

                // Si el mensaje es "Error de inicio de sesión del usuario" es un error de usuario inválido
                if (er.Message.Trim().Contains("Error de inicio de sesión del usuario") == true || er.Message.Trim().Contains("Login failed") == true)
                {
                    MessageBox.Show("Usuario inválido, intento No " + contador, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    // otro Error
                    MessageBox.Show("Error ->" + er.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                // Si el contador es 3 cierre la aplicación
                if (contador == 3)
                {
                    // se devuelve Cancel
                    this.DialogResult = DialogResult.Cancel;
                    Application.Exit();
                }
            }
        }