using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace KursachMukha692gr
{
    /// <summary>
    /// Логика взаимодействия для DeleteTournment.xaml
    /// </summary>
    public partial class DeleteTournment : Window
    {
        public DeleteTournment()
        {
            InitializeComponent();
        }
        private void Button_Click_Delete(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Вы действительно хотите удалить данные ", "Удаление", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                for(int i = 0; i < id_sorevi.Text.Length;i++)
                {
                    if (id_sorevi.Text.Length > 0 && id_sorevi.Text[i] >='0' && id_sorevi.Text[i] <='9')
                    {
                        DataTable dt_tournments = Delete("delete from [dbo].[sorevnovaniya] where [id] = " + id_sorevi.Text);
                        Tournments tournments = new Tournments();
                        tournments.Show();
                        Close();
                    }
                    else
                    {
                        MessageBox.Show("Поле id не заполнено");
                    }
                }
            }
        }
        private void Button_Click_Back(object sender, RoutedEventArgs e)
        {
            Tournments tournments = new Tournments();
            tournments.Show();
            Close();
        }
        public DataTable Delete(string selectSQL)
        {
            DataTable dataTable = new DataTable("dataBase");
            SqlConnection sqlConnection = new SqlConnection("server=WIN-2CL665KE0ED; Trusted_Connection=YES;DataBase=KURSACH1;");
            sqlConnection.Open();
            SqlCommand sqlCommand = sqlConnection.CreateCommand();
            sqlCommand.CommandText = selectSQL;
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
            sqlDataAdapter.Fill(dataTable);
            sqlConnection.Close();
            return dataTable;
        }
    }
}
