Пример #1
0
        private void dgvTeachers_SelectionChanged(object sender, EventArgs e)
        {
            if (dgvTeachers.CurrentRow == null)
            {
                return;
            }

            //NOTE: dont catch exceptions here
            lblInfo.Text = string.Empty;

            txtId.Text              = dgvTeachers.CurrentRow.Cells["id"].Value.ToString();
            txtName.Text            = dgvTeachers.CurrentRow.Cells["name"].Value.ToString();
            checkBoxIsAdmin.Checked = (bool)dgvTeachers.CurrentRow.Cells["isAdmin"].Value;

            AuthInfoAdmin auth = null;

            try
            {
                auth = DataService.SelectAuthInfoByUserID(uint.Parse(txtId.Text));
            }
            catch (Exception)
            {
                lblInfo.Text   = "Данные авторизации отсутствуют";
                txtLogin.Text  = string.Empty;
                txtAuthID.Text = string.Empty;
                return;
            }

            txtLogin.Text  = auth.login;
            txtAuthID.Text = auth.id.ToString();
        }
Пример #2
0
        private void btnUpdateAuth_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtLogin.Text) && loginValdiationComplete)
            {
                lblInfo.Text = "Данные не прошли валидацию.";
                return;
            }

            byte[] genSalt;

            AuthInfoAdmin auth = new AuthInfoAdmin()
            {
                id   = uint.Parse(txtAuthID.Text),
                hash = PasswordHashing.GetHashedPassword(txtPass.Text, out genSalt),
                salt = genSalt
            };

            try
            {
                if (DataService.UpdateAuthInfo(auth) > 0)
                {
                    lblInfo.Text = "Данные успешно изменены.";
                }
            }
            catch (Exception ex)
            {
                lblInfo.Text = string.Format("Произошла ошибка.{0}Запись не изменена.", Environment.NewLine);
                logger.Error(ex);
            }
        }
Пример #3
0
        private void btnAddAuth_Click(object sender, EventArgs e)
        {
            if (passValidationComplete && loginValdiationComplete)
            {
                lblInfo.Text = "Данные не прошли валидацию.";
                return;
            }

            byte[] genSalt;

            AuthInfoAdmin auth = new AuthInfoAdmin()
            {
                login = txtLogin.Text,
                hash  = PasswordHashing.GetHashedPassword(txtPass.Text, out genSalt),
                salt  = genSalt
            };

            try
            {
                UserInfo userInfo = new UserInfo
                {
                    id      = uint.Parse(txtId.Text),
                    Name    = txtName.Text,
                    isAdmin = checkBoxIsAdmin.Checked,
                    authID  = DataService.InsertIntoAuthInfo(auth)
                };

                if (DataService.UpdateTeachers(userInfo) > 0)
                {
                    lblInfo.Text = "Данные сохранены.";
                }
            }
            catch (Exception ex)
            {
                lblInfo.Text = string.Format("Произошла ошибка.{0}Запись не сохранена.", Environment.NewLine);
                logger.Error(ex);
            }
        }