private void CheckAuthoriztion() { while (!Authorization && AuthorizationWnd) { try { AuthorizationWindow AWnd = new AuthorizationWindow(); if (AWnd.ShowDialog() == true) { List <string> login = Database.GetListOfRowsToColumn("SELECT [Логин] FROM [User] WHERE [Логин] = '" + Cryptographer.Encryption(AWnd.Login) + "'", "[Логин]"); List <string> password = Database.GetListOfRowsToColumn("SELECT [Пароль] FROM [User] WHERE [Пароль] = '" + Cryptographer.Encryption(AWnd.Password) + "'", "[Пароль]"); if (Cryptographer.Encryption(AWnd.Password) == login[0] && Cryptographer.Encryption(AWnd.Login) == password[0]) { Authorization = true; if (login[0] != Cryptographer.Encryption("Admin")) { setting.IsEnabled = false; } } } } catch (Exception) { MessageBox.Show("Проверьте правильность ввода логина и пароля", "Ошибка авторизации", MessageBoxButton.OK, MessageBoxImage.Warning); } } if (!AuthorizationWnd) { Close(); } }
static public List <string> GetListOfRowsToColumn(string query /* Строка запроса*/, string column /* Название столбца */, bool necessaryDecrypt = false /* Необходима ли дешифровка */) { dataTable = new DataTable(); List <string> listOfRows = new List <string>(); try { command = new SqlCommand("USE [Airport] " + query, connection); adapter = new SqlDataAdapter(command); connection.Open(); adapter.Fill(dataTable); int i = 0; foreach (DataRow row in dataTable.Rows) { if (necessaryDecrypt) { if (dataTable.Rows.ToString() == Cryptographer.Encryption(column)) { i++; } listOfRows.Add(Cryptographer.Decryption(row[i].ToString())); } else { if (dataTable.Columns.ToString() == column) { i++; } listOfRows.Add(row[i].ToString()); } } } catch (SqlException ex) { MessageBox.Show(ex.Message, "Исключение (SqlException)", MessageBoxButton.OK, MessageBoxImage.Warning); } catch (Exception ex) { MessageBox.Show(ex.Message, "Исключение (Exception)", MessageBoxButton.OK, MessageBoxImage.Warning); } finally { if (connection.State == ConnectionState.Open) { connection.Close(); } } return(listOfRows); }
private void User_DeleteByLogin_Click(object sender, RoutedEventArgs e) { if ((userDeleteByLogin.Items.IndexOf(userDeleteByLogin.Text) >= 0)) { user.Login = userDeleteByLogin.Text; Database.Query("DELETE FROM [User] WHERE [Логин] = '" + Cryptographer.Encryption(user.Login) + "'"); Database.Query("SELECT * FROM [User]", userGrid, necessaryDecrypt: true); UpdateAllCombobx(); } else { MessageBox.Show("Выберите логин пользователя из списка", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void User_Update_Click(object sender, RoutedEventArgs e) { if ((userUpdateLogin.Items.IndexOf(userUpdateLogin.Text) >= 0) && userUpdatePassword.Text != "" && userUpdateFullName.Text != "") { user.Login = userUpdateLogin.Text; user.Password = userUpdatePassword.Text; user.FullName = userUpdateFullName.Text; string query = "UPDATE [User] SET [Пароль] = '" + Cryptographer.Encryption(user.Password) + "', [ФИО] = '" + Cryptographer.Encryption(user.FullName) + "' WHERE [Логин] = '" + Cryptographer.Encryption(user.Login) + "'"; string[] sqlVariables = { "Login", "Password", "FullName" }; object[] obj = { Cryptographer.Encryption(user.Login), Cryptographer.Encryption(user.Password), Cryptographer.Encryption(user.FullName) }; Database.Query(query, sqlVariables, obj); Database.Query("SELECT * FROM [User]", userGrid, necessaryDecrypt: true); UpdateAllCombobx(); } else { MessageBox.Show("Проверьте, заполнены ли все поля", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void User_Add_Click(object sender, RoutedEventArgs e) { if (userAddLogin.Text != "" && userAddPassword.Text != "" && userAddFullName.Text != "") { user.Login = userAddLogin.Text; user.Password = userAddPassword.Text; user.FullName = userAddFullName.Text; string query = "INSERT INTO [User]([Логин], [Пароль], [ФИО])" + "VALUES (@Login, @Password, @FullName)"; string[] sqlVariables = { "Login", "Password", "FullName" }; object[] obj = { Cryptographer.Encryption(user.Login), Cryptographer.Encryption(user.Password), Cryptographer.Encryption(user.FullName) }; if (Database.Query(query, sqlVariables, obj) == 2627) { MessageBox.Show("Невозможно добавить новый объект, так как уже имеется пользователь с таким логином", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Warning); } Database.Query("SELECT * FROM [User]", userGrid, necessaryDecrypt: true); UpdateAllCombobx(); } else { MessageBox.Show("Проверьте, заполнены ли все поля", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void UpdateAllCombobx() { userUpdateLogin.ItemsSource = Database.GetListOfRowsToColumn("SELECT [Логин] FROM [User]", "[Логин]", necessaryDecrypt: true); userDeleteByLogin.ItemsSource = Database.GetListOfRowsToColumn("SELECT [Логин] FROM [User] WHERE [Логин] != '" + Cryptographer.Encryption("Admin") + "'", "[Логин]", necessaryDecrypt: true); }