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=mssql; Trusted_Connection=YES;DataBase=gr692_mkm;");
            connection.Open();
            string cmd = "select infotrener.id as 'Код',familiyaTrener as 'Фамилия',imyaTrener as 'Имя', otchestvoTrener as 'Отчество', dataTrener as 'Дата рождения', telephonenumTrener as 'Номер телефона',disciplina.disciplina as 'Спортивная специальность',categoryTrener as 'Тренерская категория', pol.pol_name as 'Пол' from infotrener,disciplina,pol where disciplina.id = infotrener.fk_disciplina_id and pol.id = infotrener.fk_pol_id";
            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=mssql; Trusted_Connection=YES;DataBase=gr692_mkm;");
                connection.Open();
                string cmd = "select infotrener.id as 'Код',familiyaTrener as 'Фамилия',imyaTrener as 'Имя', otchestvoTrener as 'Отчество', dataTrener as 'Дата рождения', telephonenumTrener as 'Номер телефона',disciplina.disciplina as 'Спортивная специальность',categoryTrener as 'Тренерская категория', pol.pol_name as 'Пол' from infotrener,disciplina,pol " +
                    "where disciplina.id = infotrener.fk_disciplina_id and pol.id = infotrener.fk_pol_id and (infotrener.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 disciplina.disciplina like '%" + search.Text + "%' or categoryTrener like '%" + search.Text + "%' or pol.pol_name 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=mssql; Trusted_Connection=YES;DataBase=gr692_mkm;");
                connection.Open();
                string cmd = "select infotrener.id as 'Код',familiyaTrener as 'Фамилия',imyaTrener as 'Имя', otchestvoTrener as 'Отчество', dataTrener as 'Дата рождения', telephonenumTrener as 'Номер телефона',disciplina.disciplina as 'Спортивная специальность',categoryTrener as 'Тренерская категория', pol.pol_name as 'Пол' from infotrener,disciplina,pol where disciplina.id = infotrener.fk_disciplina_id and pol.id = infotrener.fk_pol_id";
                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)
        {

        }
    }
}
