private void addUserBtn_Click(object sender, RoutedEventArgs e)
        {
            UserInfo       ui  = new UserInfo((ushort)(users.Count + 1), "Новыйпользователь", 1, groups[0].Name, UserInfo.Roles.USER);
            EditUserWindow euw = new EditUserWindow(ui, groups.FindAll(item => item.Name[0] != UsefulThings.DELETED_MARK));

            euw.changePassChb.IsChecked = true;
            euw.changePassChb.IsEnabled = false;
            if (euw.ShowDialog().Value)
            {
                string newLogin = euw.loginEdit.Text;
                if (users.Find(item => item.Login.Equals(newLogin)) != null)
                {
                    MessageBox.Show("Пользователь с таким логином уже существует", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                else
                {
                    SHA1 sha = SHA1.Create();
                    ui.Login  = newLogin;
                    ui.Digest = UsefulThings.ENCODING.GetString(sha.ComputeHash(UsefulThings.ENCODING.GetBytes(euw.pass1Edit.Password)));
                    ui.Digest = UsefulThings.replaceControlChars(ui.Digest);
                    ui.Gid    = (euw.groupCB.SelectedItem as GroupInfo).Id;
                    ui.Group  = (euw.groupCB.SelectedItem as GroupInfo).Name;
                    ui.Role   = (UserInfo.Roles)Enum.Parse(typeof(UserInfo.Roles), euw.roleCB.SelectedItem.ToString());
                    users.Add(ui);
                    usersListView.Items.Add(ui);
                }
            }
        }
        private void editUserBtn_Click(object sender, RoutedEventArgs e)
        {
            UserInfo       ui  = usersListView.SelectedItem as UserInfo;
            EditUserWindow euw = new EditUserWindow(ui, groups.FindAll(item => item.Name[0] != UsefulThings.DELETED_MARK));

            if (ui.Uid == 1 || Session.userInfo.Role == UserInfo.Roles.USER)
            {
                euw.groupCB.IsEnabled = false;
                euw.roleCB.IsEnabled  = false;
            }
            if (euw.ShowDialog().Value)
            {
                string          newLogin  = euw.loginEdit.Text;
                List <UserInfo> namesakes = users.FindAll(item => item.Login.Equals(newLogin));
                if (namesakes.Count > 1 || namesakes.Count == 1 && namesakes[0].Uid != (usersListView.SelectedItem as UserInfo).Uid)
                {
                    MessageBox.Show("Пользователь с таким логином уже существует", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                else
                {
                    SHA1   sha       = SHA1.Create();
                    string newDigest = UsefulThings.ENCODING.GetString(sha.ComputeHash(UsefulThings.ENCODING.GetBytes(euw.pass1Edit.Password)));
                    newDigest = UsefulThings.replaceControlChars(newDigest);

                    bool isContinue = true;
                    if ((!newLogin.Equals(ui.Login) || !newDigest.Equals(ui.Digest)) && Session.userInfo.Role == UserInfo.Roles.USER)
                    {
                        bool passEntered;
                        do
                        {
                            AskPasswordWindow apw = new AskPasswordWindow();
                            passEntered = apw.ShowDialog().Value;
                            string confirmDigest = UsefulThings.ENCODING.GetString(sha.ComputeHash(UsefulThings.ENCODING.GetBytes(apw.passEdit.Password)));
                            confirmDigest = UsefulThings.replaceControlChars(confirmDigest);
                            isContinue    = passEntered && confirmDigest.Equals(ui.Digest);
                            if (passEntered && !isContinue)
                            {
                                MessageBox.Show("Прежний пароль введён неверно! Повторите ввод.", "Неверный пароль", MessageBoxButton.OK, MessageBoxImage.Warning);
                            }
                        } while (passEntered && !isContinue);
                    }

                    if (isContinue)
                    {
                        int index = usersListView.SelectedIndex;
                        ui.Login  = newLogin;
                        ui.Digest = newDigest;
                        ui.Gid    = (euw.groupCB.SelectedItem as GroupInfo).Id;
                        ui.Group  = (euw.groupCB.SelectedItem as GroupInfo).Name;
                        ui.Role   = (UserInfo.Roles)Enum.Parse(typeof(UserInfo.Roles), euw.roleCB.SelectedItem.ToString());
                        reloadUsers();
                        usersListView.SelectedIndex = index;

                        if (Session.userInfo.Uid == ui.Uid)
                        {
                            Session.userInfo = new UserInfo(ui);
                        }
                    }
                }
            }
        }