Beispiel #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);
            }
        }
Beispiel #2
0
        private void CargarDatos()
        {
            IBLLSysUserRolDTO _BLLUser = new BLLSysUserRolDTO();



            // Configuracion del DataGridView para que se vea bien la imagen.
            dgvDatos.AutoGenerateColumns = false;
            //  dgvDatos.RowTemplate.Height = 100;
            dgvDatos.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;



            // Cargar el DataGridView
            this.dgvDatos.DataSource = _BLLUser.GetAllSysUser();
            this.dgvDatos.Sort(this.dgvDatos.Columns[1], ListSortDirection.Ascending);
        }
Beispiel #3
0
        private void toolStripBtnSalvarUsuario_Click(object sender, EventArgs e)
        {
            SysUser oSysUser = null;

            try
            {
                IBLLSysUserRolDTO _IBLLUser = new BLLSysUserRolDTO();

                oSysUser = new SysUser();


                oSysUser.Login = this.txtUsuario.Text;

                oSysUser.Password = this.txtContrasena.Text;

                oSysUser.IDUser = int.Parse(this.txtIdUser.Text);

                oSysUser.IdRol = int.Parse(this.txtIdRol.Text);


                oSysUser = _IBLLUser.SaveSysUser(oSysUser);

                if (oSysUser != null)
                {
                    this.CargarDatos();
                }
            }
            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);
            }
        }
Beispiel #4
0
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            SysUserRolDTO oSysUserRolDTO = new SysUserRolDTO();

            IBLLSysUserRolDTO _BLLSysUser = new BLLSysUserRolDTO();

            try
            {
                if (this.dgvDatos.SelectedRows.Count > 0)
                {
                    oSysUserRolDTO = this.dgvDatos.SelectedRows[0].DataBoundItem as SysUserRolDTO;
                    if (MessageBox.Show($"¿Seguro que desea borrar el registro {oSysUserRolDTO.Login} {oSysUserRolDTO.IDUser}?", "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        _BLLSysUser.DeleteSysUser(oSysUserRolDTO.Login);
                        this.CargarDatos();
                    }
                }
                else
                {
                    MessageBox.Show("Seleccione el registro !", "Atención", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            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);
            }
        }
Beispiel #5
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();
                }
            }
        }