MainPage.xaml.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using practica12.Classs;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. namespace practica12.Pages
  18. {
  19. /// <summary>
  20. /// Логика взаимодействия для MainPage.xaml
  21. /// </summary>
  22. public partial class MainPage : Page
  23. {
  24. List<Tour> listFilter = Base.ep.Tour.ToList();
  25. List<Tour> list = Base.ep.Tour.ToList();
  26. public MainPage()
  27. {
  28. InitializeComponent();
  29. lvListTour.ItemsSource = Base.ep.Tour.ToList();
  30. List<Type> type = Base.ep.Type.ToList();
  31. ComboBox1.Items.Add("Все типы");
  32. for (int i = 0; i < type.Count; i++)
  33. {
  34. ComboBox1.Items.Add(type[i].Name);
  35. }
  36. ComboBox1.SelectedIndex = 0;
  37. Sort.SelectedIndex = 0;
  38. }
  39. private void cbActual_Checked(object sender, RoutedEventArgs e)
  40. {
  41. Filter();
  42. }
  43. private void btn_hotel_Click(object sender, RoutedEventArgs e)
  44. {
  45. FrameClass.MainFrame.Navigate(new HotelPage());
  46. }
  47. public void Filter()
  48. {
  49. string t = ComboBox1.SelectedValue.ToString();
  50. int index = ComboBox1.SelectedIndex;
  51. List<TypeOfTour> types = Base.ep.TypeOfTour.Where(z => z.Type.Name == t).ToList();
  52. if (index != 0)
  53. {
  54. listFilter = new List<Tour>();
  55. foreach (TypeOfTour tot in types)
  56. {
  57. foreach (Tour tour in list)
  58. {
  59. if (tour.Id == tot.TourId)
  60. {
  61. listFilter.Add(tour);
  62. }
  63. }
  64. }
  65. }
  66. else
  67. {
  68. listFilter = Base.ep.Tour.ToList();
  69. }
  70. if (!string.IsNullOrWhiteSpace(Search.Text))
  71. {
  72. listFilter = listFilter.Where(z => z.Name.ToLower().Contains(Search.Text.ToLower())).ToList();
  73. }
  74. if (cbActual.IsChecked == true)
  75. {
  76. listFilter = listFilter.Where(z => z.IsActual == true).ToList();
  77. }
  78. switch (Sort.SelectedIndex)
  79. {
  80. case 1:
  81. listFilter.Sort((x, y) => x.Price.CompareTo(y.Price));
  82. break;
  83. case 2:
  84. listFilter.Sort((x, y) => x.Price.CompareTo(y.Price));
  85. listFilter.Reverse();
  86. break;
  87. }
  88. lvListTour.ItemsSource = listFilter;
  89. int price = 0;
  90. foreach (Tour tour in listFilter)
  91. {
  92. price += (int)tour.Price * tour.TicketCount;
  93. }
  94. tbTotalCostOfTours.Text = string.Format("Общая стоимость туров: {0:C2}", price);
  95. if (listFilter.Count == 0)
  96. {
  97. MessageBox.Show("нет записей");
  98. }
  99. }
  100. private void ComboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
  101. {
  102. Filter();
  103. }
  104. private void Sort_SelectionChanged(object sender, SelectionChangedEventArgs e)
  105. {
  106. Filter();
  107. }
  108. private void Search_TextChanged(object sender, TextChangedEventArgs e)
  109. {
  110. Filter();
  111. }
  112. }
  113. }