ListTourPage.xaml.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 ПодготовкаКДемо1.Pages
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для ListTourPage.xaml
  19. /// </summary>
  20. public partial class ListTourPage : Page
  21. {
  22. public ListTourPage()
  23. {
  24. InitializeComponent();
  25. ListTours.ItemsSource = Tour.getListTour();
  26. ComboBoxSelectType.DisplayMemberPath = "Tour";
  27. ComboBoxSelectType.SelectedValuePath = "id";
  28. List<TypeTour> typeTours = BaseConnect.BaseModel.TypeTour.ToList();
  29. TypeTour typeTour = new TypeTour();
  30. typeTour.Tour = "Все";
  31. typeTours.Insert(0, typeTour);
  32. ComboBoxSelectType.ItemsSource = typeTours;
  33. decimal price=0;
  34. foreach (Tour tour in Tour.getListTour())
  35. {
  36. price += tour.Price;
  37. }
  38. AllPrice.Text = "Общая цена: " + Math.Round(price, 2).ToString() + " руб";
  39. }
  40. private void TextBoxSearch_TextChanged(object sender, TextChangedEventArgs e)
  41. {
  42. Filter();
  43. }
  44. private void Filter()
  45. {
  46. List<Tour> tours = Tour.getListTour();
  47. if (TextBoxSearch.Text != "")
  48. {
  49. tours = tours.Where(x=>x.Name.Contains(TextBoxSearch.Text)).ToList();
  50. }
  51. if (ComboBoxSelectType.SelectedItem != null&& ComboBoxSelectType.SelectedIndex !=0)
  52. {
  53. TypeTour typeTour = BaseConnect.BaseModel.TypeTour.FirstOrDefault(x => x.id == ComboBoxSelectType.SelectedIndex);
  54. tours = tours.Where(x => x.TypeTour.Contains(typeTour.Tour)).ToList();
  55. }
  56. if (ComboBoxSelectType.SelectedIndex == 0)
  57. {
  58. if (TextBoxSearch.Text != "")
  59. {
  60. tours = tours.Where(x => x.Name.Contains(TextBoxSearch.Text)).ToList();
  61. }
  62. else
  63. {
  64. tours = Tour.getListTour();
  65. RadioUp.IsChecked = false;
  66. RadioDown.IsChecked = false;
  67. }
  68. }
  69. if ((bool)CheckBoxIsActual.IsChecked)
  70. {
  71. tours = tours.Where(x=>x.IsActual==true).ToList();
  72. }
  73. ListTours.ItemsSource = tours;
  74. }
  75. private void ComboBoxSelectType_SelectionChanged(object sender, SelectionChangedEventArgs e)
  76. {
  77. Filter();
  78. }
  79. private void CheckBoxIsActual_Checked(object sender, RoutedEventArgs e)
  80. {
  81. Filter();
  82. }
  83. private void RadioButton_Checked(object sender, RoutedEventArgs e)
  84. {
  85. RadioDown.IsChecked = false;
  86. List<Tour> tours = (List<Tour>)ListTours.ItemsSource;
  87. tours=tours.OrderBy(x=>x.Price).ToList();
  88. ListTours.ItemsSource = tours;
  89. }
  90. private void RadioButton_Checked_1(object sender, RoutedEventArgs e)
  91. {
  92. RadioUp.IsChecked = false;
  93. List<Tour> tours = (List<Tour>)ListTours.ItemsSource;
  94. tours=tours.OrderBy(x => x.Price).ToList();
  95. tours.Reverse();
  96. ListTours.ItemsSource = tours;
  97. }
  98. }
  99. }