pgTours.xaml.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для pgTours.xaml
  19. /// </summary>
  20. public partial class pgTours : Page
  21. {
  22. List<Tour> tours;
  23. List<Type> tourTypes;
  24. public pgTours()
  25. {
  26. InitializeComponent();
  27. BaseConnect.BaseModel = new ToursEntities();
  28. tours = BaseConnect.BaseModel.Tour.ToList();
  29. lbTours.ItemsSource = tours;
  30. tourTypes = BaseConnect.BaseModel.Type.ToList();
  31. Type type = new Type();
  32. type.Name = "Все типы";
  33. //type.Id = 10;
  34. tourTypes.Insert(0, type);
  35. cbType.ItemsSource = tourTypes;
  36. cbType.SelectedValuePath = "Id";
  37. cbType.DisplayMemberPath = "Name";
  38. cbType.SelectedIndex = 0;
  39. decimal fullP =0;
  40. foreach(Tour tour in tours)
  41. {
  42. fullP += tour.fullPrice;
  43. }
  44. rSummPrice.Text = fullP.ToString();
  45. }
  46. public void filter()
  47. {
  48. List<Tour> filt = BaseConnect.BaseModel.Tour.ToList();
  49. if (cbType.SelectedIndex != 0)
  50. {
  51. Type tepe = tourTypes.FirstOrDefault(x => x.Id == (int)cbType.SelectedValue);
  52. filt = filt.Where(x => x.TourType.Contains(tepe.Name)).ToList();
  53. }
  54. else
  55. {
  56. filt = BaseConnect.BaseModel.Tour.ToList();
  57. }
  58. if (chbIsActual.IsChecked == true)
  59. {
  60. filt = filt.Where(x => x.IsActual == true).ToList();
  61. }
  62. if(cbSort.SelectedIndex!=-1)
  63. {
  64. if(cbSort.SelectedIndex == 1)
  65. filt = filt.OrderBy(x=>x.Price).ToList();
  66. if(cbSort.SelectedIndex == 2)
  67. {
  68. filt = filt.OrderBy(x => x.Price).ToList();
  69. filt.Reverse();
  70. }
  71. }
  72. decimal fullP = 0;
  73. filt = filt.Where(x => x.Name.Contains(tbName.Text)).ToList();
  74. lbTours.ItemsSource = filt;
  75. foreach (Tour tour in filt)
  76. {
  77. fullP += tour.fullPrice;
  78. }
  79. rSummPrice.Text = fullP.ToString();
  80. }
  81. private void cbType_SelectionChanged(object sender, SelectionChangedEventArgs e)
  82. {
  83. filter();
  84. }
  85. private void tbName_TextChanged(object sender, TextChangedEventArgs e)
  86. {
  87. filter();
  88. }
  89. private void chbIsActual_Checked(object sender, RoutedEventArgs e)
  90. {
  91. filter();
  92. }
  93. private void chbIsActual_Unchecked(object sender, RoutedEventArgs e)
  94. {
  95. filter();
  96. }
  97. private void cbSort_SelectionChanged(object sender, SelectionChangedEventArgs e)
  98. {
  99. filter();
  100. }
  101. private void btnHotel_Click(object sender, RoutedEventArgs e)
  102. {
  103. LoadPages.frmMain.Navigate(new pgHotels());
  104. }
  105. }
  106. }