using System;
using System.Collections.Generic;
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;
using System.Windows.Navigation;
using System.Data.SqlClient;
using System.Data;

namespace KursachMukha692gr
{
    /// <summary>
    /// Логика взаимодействия для Raspisaniye.xaml
    /// </summary>
    public partial class Raspisaniye : Window
    {
        public Raspisaniye()
        {
            InitializeComponent();
            SqlConnection connection = new SqlConnection("server=WIN-2CL665KE0ED; Trusted_Connection=YES;DataBase=KURSACH1;");
            connection.Open();
            string cmd = "select id,fk_den_nedeli_id as 'id дня недели', fk_vremya_zanyatiya_id as 'id время занятия', fk_gruppi_id as 'id группы', fk_disciplina_id as 'id дисциплины',fk_zal_trenirovki_id as 'id зала тренировки',fk_trener_id as 'id тренера',fk_corpus_id as 'id корпуса' from RASPISANIYE";
            SqlCommand createcommand = new SqlCommand(cmd, connection);
            createcommand.ExecuteNonQuery();
            
            SqlDataAdapter sql = new SqlDataAdapter(createcommand);
            DataTable dt = new DataTable("raspisaniyes");
            sql.Fill(dt);
            raspisaniyegrid.ItemsSource = dt.DefaultView;
            connection.Close();
        }
        private void Button_Click_Back(object sender, RoutedEventArgs e)
        {
            KabinetAdmina kab = new KabinetAdmina();
            kab.Show();
            Close();
        }

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

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

        private void Button_Click_update(object sender, RoutedEventArgs e)
        {
            ViborUpdateRaspisaniye updateRaspisaniye = new ViborUpdateRaspisaniye();
            updateRaspisaniye.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,fk_den_nedeli_id as 'id дня недели', fk_vremya_zanyatiya_id as 'id время занятия', fk_gruppi_id as 'Номер группы', fk_disciplina_id as 'id дисциплины',fk_zal_trenirovki_id as 'id зала тренировки',fk_trener_id as 'id тренера',fk_corpus_id as 'id корпуса' from RASPISANIYE" +
                    " where id like '%" + search.Text + "%' or fk_den_nedeli_id like '%" + search.Text + "%' or fk_vremya_zanyatiya_id like '%" + search.Text + "%' or fk_gruppi_id like '%" + search.Text + "%' or fk_disciplina_id like '%" + search.Text + "%' or fk_zal_trenirovki_id like '%" + search.Text + "%' or fk_trener_id like '%" + search.Text + "%' or fk_trener_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);
                raspisaniyegrid.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,fk_den_nedeli_id as 'id дня недели', fk_vremya_zanyatiya_id as 'id время занятия', fk_gruppi_id as 'id группы', fk_disciplina_id as 'id дисциплины',fk_zal_trenirovki_id as 'id зала тренировки',fk_trener_id as 'id тренера',fk_corpus_id as 'id корпуса' from RASPISANIYE";
                SqlCommand createcommand = new SqlCommand(cmd, connection);
                createcommand.ExecuteNonQuery();
                SqlDataAdapter sql = new SqlDataAdapter(createcommand);
                DataTable dt = new DataTable("sorevi");
                sql.Fill(dt);
                raspisaniyegrid.ItemsSource = dt.DefaultView;
                connection.Close();
            }
        }

        private void search_TextChanged(object sender, TextChangedEventArgs e)
        {

        }
    } 
}
