Exemple #1
0
        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int id = Convert.ToInt32(ID_tb.Text);

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

                ID_tb.Clear(); Name_tb.Clear(); Price_tb.Clear(); Descrip_tb.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #2
0
        private void ChangeButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int    id      = Convert.ToInt32(ID_tb.Text);
                string name    = Name_tb.Text;
                string price   = Price_tb.Text;
                string descrip = Descrip_tb.Text;

                int    newid      = Convert.ToInt32(NewID_tb.Text);
                string newname    = NewName_tb.Text;
                string newprice   = NewPrice_tb.Text;
                string newdescrip = NewDescrip_tb.Text;


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

                string     cmdTxt1  = $"UPDATE Abonnement SET Name = '{newname}'  WHERE ID_client = '{id}'";
                SqlCommand command1 = new SqlCommand(cmdTxt1, connection);
                string     cmdTxt2  = $"UPDATE Abonnement SET Price = '{newprice}'  WHERE ID_client = '{id}'";
                SqlCommand command2 = new SqlCommand(cmdTxt2, connection);
                string     cmdTxt3  = $"UPDATE Abonnement SET Description = '{newdescrip}'  WHERE ID_client = '{id}'";
                SqlCommand command3 = new SqlCommand(cmdTxt3, connection);


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


                ID_tb.Clear(); Name_tb.Clear(); Price_tb.Clear(); Descrip_tb.Clear();
                NewID_tb.Clear(); NewName_tb.Clear(); NewPrice_tb.Clear(); NewDescrip_tb.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #3
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int    id      = Convert.ToInt32(ID_tb.Text);
                string name    = Name_tb.Text;
                string price   = Price_tb.Text;
                string descrip = Descrip_tb.Text;

                string        connectionString = @"Data Source =.\SQLEXPRESS; Initial Catalog = FitnessCenter; Integrated Security = True";
                SqlConnection connection       = new SqlConnection(connectionString);
                connection.Open();
                string     cmdTxt  = $"INSERT INTO Abonnement (ID_abonnement, Name, Price, Description) VALUES ('{id}', '{name}', '{price}',  '{descrip}')";
                SqlCommand command = new SqlCommand(cmdTxt, connection);
                int        number  = command.ExecuteNonQuery();
                MessageBox.Show("Изменения сохранены успешно!\nВставлено объектов: " + number, "Статус действия", MessageBoxButton.OK, MessageBoxImage.Information);

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