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>
    /// Логика взаимодействия для SpisokTrenerov.xaml
    /// </summary>
    public partial class SpisokTrenerov : Window
    {
        public SpisokTrenerov()
        {
            InitializeComponent();
            InitializeComponent();
            SqlConnection connection = new SqlConnection("server=WIN-2CL665KE0ED; Trusted_Connection=YES;DataBase=KURSACH1;");
            connection.Open();
            string cmd = "select id,familiyaTrener as 'Фамилия',imyaTrener as 'Имя', otchestvoTrener as 'Отчество', dataTrener as 'Дата рождения', telephonenumTrener as 'Номер телефона',fk_disciplina_id as 'Спортивная специальность',categoryTrener as 'Тренерская категория', fk_pol_id as 'Пол' from infotrener";
            SqlCommand createcommand = new SqlCommand(cmd, connection);
            createcommand.ExecuteNonQuery();

            SqlDataAdapter sql = new SqlDataAdapter(createcommand);
            DataTable dt = new DataTable("infotrener");
            sql.Fill(dt);
            infotrenergrid.ItemsSource = dt.DefaultView;
            connection.Close();
        }

        private void Button_Click_add(object sender, RoutedEventArgs e)
        {
            AddTrener trener = new AddTrener();
            trener.Show();
            Close();
        }

        private void Button_Click_delete(object sender, RoutedEventArgs e)
        {
            DeleteSpisokTrenerov trenerov = new DeleteSpisokTrenerov();
            trenerov.Show();
            Close();
        }

        private void Button_Click_Back(object sender, RoutedEventArgs e)
        {
            KabinetAdmina kabinet = new KabinetAdmina();
            kabinet.Show();
            Close();
        }

        private void Button_Click_update(object sender, RoutedEventArgs e)
        {
            ViborTrenerUpdate trenerUpdate = new ViborTrenerUpdate();
            trenerUpdate.Show();
            Close();
        }

        private void Button_Click_Search(object sender, RoutedEventArgs e)
        {
            if (search.Text.Length > 0)
            {
                SqlConnection connection = new SqlConnection("server=WIN-2CL665KE0ED; Trusted_Connection=YES;DataBase=KURSACH1;");
                connection.Open();
                string cmd = "select id,familiyaTrener as 'Фамилия',imyaTrener as 'Имя', otchestvoTrener as 'Отчество', otchestvoTrener as 'Дата рождения', telephonenumTrener as 'Номер телефона',fk_disciplina_id as 'Спортивная специальность',categoryTrener as 'Тренерская категория', fk_pol_id as 'Пол' from infotrener" +
                    " where id like '%" + search.Text + "%' or familiyaTrener like '%" + search.Text + "%' or imyaTrener like '%" + search.Text + "%' or otchestvoTrener like '%" + search.Text + "%' or otchestvoTrener like '%" + search.Text + "%' or telephonenumTrener like '%" + search.Text + "%' or fk_disciplina_id like '%" + search.Text + "%' or categoryTrener like '%" + search.Text + "%' or fk_pol_id like '%" + search.Text + "%'";
                SqlCommand createcommand = new SqlCommand(cmd, connection);
                createcommand.ExecuteNonQuery();
                SqlDataAdapter sql = new SqlDataAdapter(createcommand);
                DataTable dt = new DataTable("sorevi");
                sql.Fill(dt);
                infotrenergrid.ItemsSource = dt.DefaultView;
                connection.Close();
            }
            else if (search.Text.Length == 0)
            {
                SqlConnection connection = new SqlConnection("server=WIN-2CL665KE0ED; Trusted_Connection=YES;DataBase=KURSACH1;");
                connection.Open();
                string cmd = "select id,familiyaTrener as 'Фамилия',imyaTrener as 'Имя', otchestvoTrener as 'Отчество', dataTrener as 'Дата рождения', telephonenumTrener as 'Номер телефона',fk_disciplina_id as 'Спортивная специальность',categoryTrener as 'Тренерская категория', fk_pol_id as 'Пол' from infotrener";
                SqlCommand createcommand = new SqlCommand(cmd, connection);
                createcommand.ExecuteNonQuery();
                SqlDataAdapter sql = new SqlDataAdapter(createcommand);
                DataTable dt = new DataTable("sorevi");
                sql.Fill(dt);
                infotrenergrid.ItemsSource = dt.DefaultView;
                connection.Close();
            }
        }

        private void search_TextChanged(object sender, TextChangedEventArgs e)
        {

        }
    }
}
