Пример #1
0
        private void btnIng_Click_1(object sender, EventArgs e)
        {
            contadorIntentos = contadorIntentos + 1;
            int    i  = 0;
            int    id = -1;
            string pass;

            if ((!string.IsNullOrEmpty(tbxUserId.Text) && !int.TryParse(tbxUserId.Text, out i)) || string.IsNullOrEmpty(tbxUserId.Text) || string.IsNullOrWhiteSpace(tbxUserId.Text))
            {
                showInfo("El campo de Id usuario vacio o con formato equivocado! \nPor favor ingrese unicamente numeros!");
                tbxUserId.Clear();
                if (contadorIntentos > 5)
                {
                    showInfo("Alcanzo el numero maximo de Intentos! \nPor favor comuniquese con el departamento de Informatica!");
                    Close();
                }
            }
            else
            {
                id = int.Parse(tbxUserId.Text);

                if (string.IsNullOrWhiteSpace(tbxPassword.Text) || string.IsNullOrEmpty(tbxPassword.Text))
                {
                    showInfo("El campo de Password se encuentra vacio! \nPor favor ingrese su Password!");
                    if (contadorIntentos > 5)
                    {
                        showInfo("Alcanzo el numero maximo de Intentos! \nPor favor comuniquese con el departamento de Informatica!");
                        Close();
                    }
                }
                else
                {
                    pass = cryptoEngine.Encrypt(tbxPassword.Text);

                    /*user = usuariosDal.GetUsuario(id);*/
                    //showInfo("Password: "******" Encryptada: " + pass);
                    /*Validanado usuario*/
                    if (usuariosDal.isRealUser(id))
                    {
                        if (usuariosDal.isValidPassword(pass, id))
                        {
                            try
                            {
                                int?   id2       = Convert.ToInt32(tbxUserId.Text);
                                string password2 = tbxPassword.Text;

                                using (context = new BDContext())
                                {
                                    int?rol = context.sp_RetornaRolUsuario(id2, password2).FirstOrDefault() ?? -1;


                                    if (rol == 1)
                                    {
                                        //CARGA EL FORM PRINCIPAL DE USUARIO ADMINISTRADOR
                                        this.Hide();
                                        Inicio form = new Inicio();
                                        form.ShowDialog();
                                        form.Dispose();
                                        this.Show();
                                    }
                                    else
                                    {
                                        //CARGA EL FORM PRINCIPAL DE UN USUARIO NORMAL
                                        this.Hide();
                                        InicioNoAdmin form = new InicioNoAdmin();
                                        form.ShowDialog();
                                        form.Dispose();
                                        this.Show();
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("" + ex);
                            }
                        }
                        else
                        {
                            tbxUserId.Clear();
                            tbxPassword.Clear();
                            MessageBox.Show("Los datos ingresados no son correctos! \nPor favor ingrese sus datos!", "Error");
                            tbxUserId.Text   = "";
                            tbxPassword.Text = "";

                            if (contadorIntentos > 5)
                            {
                                showInfo("Alcanzo el numero maximo de Intentos! \nPor favor comuniquese con el departamento de Informatica!");
                                Close();
                            }
                        }
                    }
                    else
                    {
                        tbxUserId.Clear();
                        tbxPassword.Clear();
                        showInfo("Los datos ingresados no son correctos! \nPor favor ingrese sus datos!");
                        if (contadorIntentos > 5)
                        {
                            showInfo("Alcanzo el numero maximo de Intentos! \nPor favor comuniquese con el departamento de Informatica!");
                            Close();
                        }
                    }
                }
            }
        }