private void BackToWindow(object sender, RoutedEventArgs e) { ChangeUserData changeUser = new ChangeUserData(); changeUser.Show(); this.Close(); }
private void ChangeUserdData_Click(object sender, RoutedEventArgs e) { ChangeUserData changeUserData = new ChangeUserData(); changeUserData.Show(); this.Close(); }
private void SaveChanges(object sender, RoutedEventArgs e) { SqlConnection connection = new SqlConnection(connectionString); connection.Open(); if (criterion.Text != string.Empty && searchCriterion.Text != string.Empty) { int uC = Convert.ToInt32(searchCriterion.Text); if (criterion.Text == "Логин") { if (changingCriterion.Text != CheckUser.CheckUserLogin(changingCriterion.Text)) { System.Windows.MessageBox.Show(CheckUser.CheckUserLogin(changingCriterion.Text)); return; } string mySelectQuery = "SELECT UserLogin FROM Users WHERE [UserLogin] = '" + changingCriterion.Text + "'"; using (SqlDataAdapter dataAdapter = new SqlDataAdapter(mySelectQuery, connection)) { DataTable table = new DataTable(); dataAdapter.Fill(table); if (table.Rows.Count > 0) { System.Windows.MessageBox.Show("Этот логин занят. Введите другой"); return; } else if (table.Rows.Count == 0) { using (SqlCommand lastCommnd = connection.CreateCommand()) { lastCommnd.CommandText = "UPDATE Users SET UserLogin = @login WHERE UserCode = @code"; lastCommnd.Parameters.AddWithValue("@login", changingCriterion.Text); lastCommnd.Parameters.AddWithValue("@code", uC); lastCommnd.ExecuteNonQuery(); } } } } else if (criterion.Text == "Пароль") { if (changingCriterion.Text != CheckUser.CheckUserPassword(changingCriterion.Text)) { System.Windows.MessageBox.Show(CheckUser.CheckUserPassword(changingCriterion.Text)); return; } using (SqlCommand lastCommnd = connection.CreateCommand()) { lastCommnd.CommandText = "UPDATE Users SET UserPassword = @password WHERE UserCode = @code"; lastCommnd.Parameters.AddWithValue("@password", changingCriterion.Text); lastCommnd.Parameters.AddWithValue("@code", uC); lastCommnd.ExecuteNonQuery(); } } else if (criterion.Text == "Статус администратора") { if (changingCriterion.Text != CheckUser.CheckUserStatus(changingCriterion.Text)) { System.Windows.MessageBox.Show(CheckUser.CheckUserStatus(changingCriterion.Text)); return; } using (SqlCommand lastCommnd = connection.CreateCommand()) { lastCommnd.CommandText = "UPDATE Users SET AdministratorStatus = @status WHERE UserCode = @code"; lastCommnd.Parameters.AddWithValue("@status", changingCriterion.Text); lastCommnd.Parameters.AddWithValue("@code", uC); lastCommnd.ExecuteNonQuery(); } } else if (criterion.Text == "Имя") { if (changingCriterion.Text != CheckUser.CheckUserName(changingCriterion.Text)) { System.Windows.MessageBox.Show(CheckUser.CheckUserName(changingCriterion.Text)); return; } using (SqlCommand lastCommnd = connection.CreateCommand()) { lastCommnd.CommandText = "UPDATE Users SET UserName = @name WHERE UserCode = @code"; lastCommnd.Parameters.AddWithValue("@name", changingCriterion.Text); lastCommnd.Parameters.AddWithValue("@code", uC); lastCommnd.ExecuteNonQuery(); } } else if (criterion.Text == "Фамилия") { if (changingCriterion.Text != CheckUser.CheckUserSurname(changingCriterion.Text)) { System.Windows.MessageBox.Show(CheckUser.CheckUserSurname(changingCriterion.Text)); return; } using (SqlCommand lastCommnd = connection.CreateCommand()) { lastCommnd.CommandText = "UPDATE Users SET UserSurname = @surname WHERE UserCode = @code"; lastCommnd.Parameters.AddWithValue("@surname", changingCriterion.Text); lastCommnd.Parameters.AddWithValue("@code", uC); lastCommnd.ExecuteNonQuery(); } } } else { System.Windows.MessageBox.Show("Вы не выбрали данные для изменения."); return; } MessageBoxResult mboxResult = System.Windows.MessageBox.Show("Данные обновлены. Желаете изменить что-нибудь еще?", "Предупреждение", MessageBoxButton.YesNo); if (mboxResult == MessageBoxResult.No) { ChangeUserData changeUserData = new ChangeUserData(); changeUserData.Show(); this.Close(); } connection.Close(); }