ShowPage.xaml.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace WpfApp1.Pages
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для ShowPage.xaml
  19. /// </summary>
  20. public partial class ShowPage : Page
  21. {
  22. public ShowPage()
  23. {
  24. InitializeComponent();
  25. DataGrid.ItemsSource = DataBaseClass.entities.Tours.ToList();
  26. //LVTours.ItemsSource = DataBaseClass.entities.Tours.ToList();
  27. Filters.Items.Add("Все значения");
  28. List<Countryes> countryes = DataBaseClass.entities.Countryes.
  29. ToList();
  30. foreach (Countryes country in countryes)
  31. {
  32. Filters.Items.Add(country.Name);
  33. }
  34. Filters.SelectedIndex = 0;
  35. Sort.Items.Add("Все записи");
  36. Sort.Items.Add("По увеличению");
  37. Sort.Items.Add("По уменьшению");
  38. Sort.SelectedIndex = 0;
  39. }
  40. void Filter()
  41. {
  42. List<Tours> list = DataBaseClass.entities.Tours.ToList();
  43. if (!string.IsNullOrEmpty(Seacrh.Text) || Filters.SelectedIndex != 0)
  44. {
  45. list = DataBaseClass.entities.Tours.Where(x => x.Name.ToLower().Contains(Seacrh.Text.ToLower()) || x.Countryes.Name == (string)Filters.SelectedItem).ToList();
  46. }
  47. //if(Filters.SelectedIndex != 0)
  48. //{
  49. // list = DataBaseClass.entities.Tours.Where( x=> x.Countryes.Name == (string)Filters.SelectedItem).ToList();
  50. //}
  51. switch(Sort.SelectedIndex)
  52. {
  53. case 0: break;
  54. case 1: list.Sort((x, y) => x.CountOfBilets.CompareTo(y.CountOfBilets)); break;
  55. case 2: list.Sort((x, y) => x.CountOfBilets.CompareTo(y.CountOfBilets)); list.Reverse(); break;
  56. }
  57. //LVTours.ItemsSource = list;
  58. }
  59. private void TBType_Loaded(object sender, RoutedEventArgs e)
  60. {
  61. TextBlock tb = (TextBlock)sender;
  62. tb.Text = "Типы тура:\n";
  63. int index = Convert.ToInt32(tb.Uid);
  64. List<TourTypeOfTour> type = DataBaseClass.entities.TourTypeOfTour.Where(x => x.IdTour == index).ToList();
  65. foreach(TourTypeOfTour tour in type)
  66. {
  67. tb.Text += tour.TypeOfTours.Name+"\n";
  68. }
  69. }
  70. private void Delete_Click(object sender, RoutedEventArgs e)
  71. {
  72. Button btn = (Button)sender;
  73. int index = Convert.ToInt32(btn.Uid);
  74. Tours tours = DataBaseClass.entities.Tours.FirstOrDefault(x => x.ID == index);
  75. List<TourTypeOfTour> tour = DataBaseClass.entities.TourTypeOfTour.Where(x=> x.IdTour == index).ToList();
  76. List<Hotels> toure = DataBaseClass.entities.Hotels.Where(x => x.IdTour == index).ToList();
  77. foreach (Hotels tourTypeOfTour in toure)
  78. {
  79. DataBaseClass.entities.Hotels.Remove(tourTypeOfTour);
  80. }
  81. foreach (TourTypeOfTour tourTypeOfTour in tour)
  82. {
  83. DataBaseClass.entities.TourTypeOfTour.Remove(tourTypeOfTour);
  84. }
  85. DataBaseClass.entities.Tours.Remove(tours);
  86. DataBaseClass.entities.SaveChanges();
  87. FrameClass.mainFrame.Navigate(new ShowPage());
  88. }
  89. private void Red_Click(object sender, RoutedEventArgs e)
  90. {
  91. Button button = (Button)sender;
  92. int index = Convert.ToInt32(button.Uid);
  93. FrameClass.mainFrame.Navigate(new RedactPage(index));
  94. }
  95. private void Sort_SelectionChanged(object sender, SelectionChangedEventArgs e)
  96. {
  97. Filter();
  98. }
  99. private void Filters_SelectionChanged(object sender, SelectionChangedEventArgs e)
  100. {
  101. Filter();
  102. }
  103. private void Seacrh_TextChanged(object sender, TextChangedEventArgs e)
  104. {
  105. Filter();
  106. }
  107. }
  108. }