Esempio n. 1
0
        private void ChangeButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int    id    = Convert.ToInt32(ID_tb.Text);
                string login = Login_tb.Text;
                string pass  = Password_tb.Text;

                int    newid    = Convert.ToInt32(ID_tb_Copy.Text);
                string newlogin = Login_tb_Copy.Text;
                string newpass  = Password_tb_Copy.Text;

                string        connectionString = @"Data Source =.\SQLEXPRESS; Initial Catalog = FitnessCenter; Integrated Security = True";
                SqlConnection connection       = new SqlConnection(connectionString);
                connection.Open();

                string     cmdTxt1  = $"UPDATE Administrators SET Login = '******'  WHERE ID_admin = '{id}'";
                SqlCommand command1 = new SqlCommand(cmdTxt1, connection);
                string     cmdTxt2  = $"UPDATE Administrators SET Password = '******'  WHERE ID_admin = '{id}'";
                SqlCommand command2 = new SqlCommand(cmdTxt2, connection);

                command1.ExecuteNonQuery(); command2.ExecuteNonQuery();
                MessageBox.Show("Изменения сохранены успешно!", "Статус действия", MessageBoxButton.OK, MessageBoxImage.Information);

                ID_tb.Clear(); Login_tb.Clear(); Password_tb.Clear();
                ID_tb_Copy.Clear(); Login_tb_Copy.Clear(); Password_tb_Copy.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 2
0
        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int    id    = Convert.ToInt32(ID_tb.Text);
                string login = Login_tb.Text;
                string pass  = Password_tb.Text;

                string        connectionString = @"Data Source =.\SQLEXPRESS; Initial Catalog = FitnessCenter; Integrated Security = True";
                SqlConnection connection       = new SqlConnection(connectionString);
                connection.Open();
                SqlCommand command = new SqlCommand($"DELETE  Administrators  WHERE ID_admin = '{id}'", connection);
                int        number  = command.ExecuteNonQuery();
                MessageBox.Show("Изменения сохранены успешно!\nУдалено объектов: " + number, "Статус действия", MessageBoxButton.OK, MessageBoxImage.Information);

                ID_tb.Clear(); Login_tb.Clear(); Password_tb.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }