Exemplo n.º 1
0
 private void limpiarErrores()
 {
     NombreUsuarioerrorProvider.Clear();
     PasserrorProvider.Clear();
     ConfPassTextBox.Clear();
     BuscarerrorProvider.Clear();
 }
Exemplo n.º 2
0
        private bool ValidarTextbox()
        {
            if (string.IsNullOrEmpty(UserNameTextBox.Text) && string.IsNullOrEmpty(PassTextBox.Text) && string.IsNullOrEmpty(ConfPassTextBox.Text))
            {
                NombreUsuarioerrorProvider.SetError(UserNameTextBox, "Favor ingresar el nombre de Usuario");
                PasserrorProvider.SetError(PassTextBox, "Favor ingresar la contraseña del usuario");
                ConfPasserrorProvider.SetError(ConfPassTextBox, "Favor confirmar comtraseña");
                MessageBox.Show("Favor llenar todos los campos obligatorios");
            }
            if (string.IsNullOrEmpty(UserNameTextBox.Text))
            {
                NombreUsuarioerrorProvider.SetError(UserNameTextBox, "Favor ingresar el nombre de Usuario");
                return(false);
            }

            if (string.IsNullOrEmpty(PassTextBox.Text))
            {
                NombreUsuarioerrorProvider.Clear();
                PasserrorProvider.SetError(PassTextBox, "Favor ingresar la contraseña del usuario");
                return(false);
            }

            if (string.IsNullOrEmpty(ConfPassTextBox.Text))
            {
                NombreUsuarioerrorProvider.Clear();
                PasserrorProvider.Clear();
                ConfPasserrorProvider.SetError(ConfPassTextBox, "Favor confirmar comtraseña");
                return(false);
            }

            if (ConfPassTextBox.Text != PassTextBox.Text)
            {
                NombreUsuarioerrorProvider.Clear();
                PasserrorProvider.Clear();
                ConfPassTextBox.Clear();
                ConfPasserrorProvider.SetError(ConfPassTextBox, "La contraseña no coincide");
                return(false);
            }



            return(true);
        }
        private void AddEditButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (isChange)
                {
                    if ((PassTextBox.Text == "" || PassTextBox.Text == " ") && (ConfPassTextBox.Text == "" || ConfPassTextBox.Text == " ") && (LoginTextBox.Text != "" || LoginTextBox.Text != " "))
                    {
                        string       Command  = "Update Пользователи SET Имя_Пользователя=@login Where Имя_Пользователя=@oldLogin";
                        SqlParameter newLogin = new SqlParameter("login", LoginTextBox.Text);
                        SqlParameter oldLogin = new SqlParameter("oldLogin", Login);
                        StaticProcesser.ExecuteCommand(Command, newLogin, oldLogin);
                        this.Dispose();
                    }
                    else
                    {
                        if (PassTextBox.Text == ConfPassTextBox.Text && LoginTextBox.Text != "" && LoginTextBox.Text != " ")
                        {
                            string       newhashedPass = StaticProcesser.ComputeHash(PassTextBox.Text, new MD5CryptoServiceProvider());
                            SqlParameter newLogin      = new SqlParameter("login", LoginTextBox.Text);
                            SqlParameter newHashedPass = new SqlParameter("newHashedPass", newhashedPass);
                            SqlParameter oldLogin      = new SqlParameter("oldLogin", Login);
                            string       Command       = "Update Пользователи SET Имя_Пользователя=@login, Пароль=@newHashedPass Where Имя_Пользователя=@oldLogin";
                            StaticProcesser.ExecuteCommand(Command, newLogin, newHashedPass, oldLogin);
                            this.Dispose();
                        }
                    }
                }
                else
                {
                    if ((PassTextBox.Text == "" || PassTextBox.Text == " ") && (ConfPassTextBox.Text == "" || ConfPassTextBox.Text == " ") && (LoginTextBox.Text == "" || LoginTextBox.Text == " "))
                    {
                        MessageBox.Show("Заполните все поля!");
                        LoginTextBox.Focus();
                    }
                    else
                    {
                        if (PassTextBox.Text == ConfPassTextBox.Text)
                        {
                            string       newhashedPass = StaticProcesser.ComputeHash(PassTextBox.Text, new MD5CryptoServiceProvider());
                            SqlParameter newLogin      = new SqlParameter("login", LoginTextBox.Text);
                            SqlParameter newHashedPass = new SqlParameter("newHashedPass", newhashedPass);

                            string Command = "Insert INTO Пользователи (Имя_Пользователя,Пароль) VALUES (@login,@newHashedPass)";
                            StaticProcesser.ExecuteCommand(Command, newLogin, newHashedPass);
                            this.Dispose();
                        }
                        else
                        {
                            PassTextBox.Clear();
                            ConfPassTextBox.Clear();
                            PassTextBox.Focus();
                            MessageBox.Show("Пароли не совпадают!");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                StaticHelper.ErrorNotifier(ex);
            }
        }