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.Navigation; using System.Windows.Shapes; namespace WpfApp1.Pages { /// /// Логика взаимодействия для ShowPage.xaml /// public partial class ShowPage : Page { public ShowPage() { InitializeComponent(); DataGrid.ItemsSource = DataBaseClass.entities.Tours.ToList(); //LVTours.ItemsSource = DataBaseClass.entities.Tours.ToList(); Filters.Items.Add("Все значения"); List countryes = DataBaseClass.entities.Countryes. ToList(); foreach (Countryes country in countryes) { Filters.Items.Add(country.Name); } Filters.SelectedIndex = 0; Sort.Items.Add("Все записи"); Sort.Items.Add("По увеличению"); Sort.Items.Add("По уменьшению"); Sort.SelectedIndex = 0; } void Filter() { List list = DataBaseClass.entities.Tours.ToList(); if (!string.IsNullOrEmpty(Seacrh.Text) || Filters.SelectedIndex != 0) { list = DataBaseClass.entities.Tours.Where(x => x.Name.ToLower().Contains(Seacrh.Text.ToLower()) || x.Countryes.Name == (string)Filters.SelectedItem).ToList(); } //if(Filters.SelectedIndex != 0) //{ // list = DataBaseClass.entities.Tours.Where( x=> x.Countryes.Name == (string)Filters.SelectedItem).ToList(); //} switch(Sort.SelectedIndex) { case 0: break; case 1: list.Sort((x, y) => x.CountOfBilets.CompareTo(y.CountOfBilets)); break; case 2: list.Sort((x, y) => x.CountOfBilets.CompareTo(y.CountOfBilets)); list.Reverse(); break; } //LVTours.ItemsSource = list; } private void TBType_Loaded(object sender, RoutedEventArgs e) { TextBlock tb = (TextBlock)sender; tb.Text = "Типы тура:\n"; int index = Convert.ToInt32(tb.Uid); List type = DataBaseClass.entities.TourTypeOfTour.Where(x => x.IdTour == index).ToList(); foreach(TourTypeOfTour tour in type) { tb.Text += tour.TypeOfTours.Name+"\n"; } } private void Delete_Click(object sender, RoutedEventArgs e) { Button btn = (Button)sender; int index = Convert.ToInt32(btn.Uid); Tours tours = DataBaseClass.entities.Tours.FirstOrDefault(x => x.ID == index); List tour = DataBaseClass.entities.TourTypeOfTour.Where(x=> x.IdTour == index).ToList(); List toure = DataBaseClass.entities.Hotels.Where(x => x.IdTour == index).ToList(); foreach (Hotels tourTypeOfTour in toure) { DataBaseClass.entities.Hotels.Remove(tourTypeOfTour); } foreach (TourTypeOfTour tourTypeOfTour in tour) { DataBaseClass.entities.TourTypeOfTour.Remove(tourTypeOfTour); } DataBaseClass.entities.Tours.Remove(tours); DataBaseClass.entities.SaveChanges(); FrameClass.mainFrame.Navigate(new ShowPage()); } private void Red_Click(object sender, RoutedEventArgs e) { Button button = (Button)sender; int index = Convert.ToInt32(button.Uid); FrameClass.mainFrame.Navigate(new RedactPage(index)); } private void Sort_SelectionChanged(object sender, SelectionChangedEventArgs e) { Filter(); } private void Filters_SelectionChanged(object sender, SelectionChangedEventArgs e) { Filter(); } private void Seacrh_TextChanged(object sender, TextChangedEventArgs e) { Filter(); } } }