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>
    /// Логика взаимодействия для DeleteSpisokTrenerov.xaml
    /// </summary>
    public partial class DeleteSpisokTrenerov : Window
    {
        public DeleteSpisokTrenerov()
        {
            InitializeComponent();
        }

        private void Button_Click_Delete(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Вы действительно хотите удалить данные ", "Удаление", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                for(int i = 0; i < id_trener.Text.Length; i++)
                {
                    if (id_trener.Text.Length > 0 && id_trener.Text[i] >='0' && id_trener.Text[i] <='9')
                    {
                        DataTable dt_uch = Delete("delete from [dbo].[infotrener] where [id] = " + id_trener.Text);
                        SpisokTrenerov uch = new SpisokTrenerov();
                        uch.Show();
                        Close();
                    }
                    else
                    {
                        MessageBox.Show("Поле id не заполнено или введено не корректно");
                    }
                }
            }
        }

        private void Button_Click_Back(object sender, RoutedEventArgs e)
        {
            SpisokTrenerov trenerov = new SpisokTrenerov();
            trenerov.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;
        }
    }
}
