TableData.xaml.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Drawing.Drawing2D;
  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 MusicSmth
  18. {
  19. /// <summary>
  20. /// Логика взаимодействия для TableData.xaml
  21. /// </summary>
  22. public partial class TableData : Page
  23. {
  24. int id;
  25. public TableData(int UsId)
  26. {
  27. InitializeComponent();
  28. Music DB = new Music();
  29. List<string> s = new List<string>() { "Без фильтров", "По дате", "По цене" };
  30. ConcertData.ItemsSource = DB.Concerts.ToList();
  31. List<Cities> cit = DB.Cities.ToList();
  32. CityFilter.Items.Add("Все города");
  33. foreach(Cities i in cit)
  34. {
  35. CityFilter.Items.Add(i.City);
  36. }
  37. Sort.ItemsSource = s;
  38. Sort.SelectedItem = "Без фильтров";
  39. CityFilter.SelectedIndex = 0;
  40. id = UsId;
  41. }
  42. public void FindCity(object sender, RoutedEventArgs e)
  43. {
  44. TextBlock city = (TextBlock)sender;
  45. int index = Convert.ToInt32(city.Uid);
  46. Music DB = new Music();
  47. string c = DB.Cities.Where(x=>x.ID_City == index).Select(x=>x.City).First();
  48. city.Text = c;
  49. }
  50. private void CountTracked(object sender, RoutedEventArgs e)
  51. {
  52. TextBlock count = (TextBlock)sender;
  53. int index = Convert.ToInt32(count.Uid);
  54. Music DB = new Music();
  55. int tracked = DB.Tracked_Concerts.Where(x=>x.ID_Concert == index).Count();
  56. count.Text = "Количество отметок " + tracked.ToString();
  57. }
  58. private void DateTill(object sender, RoutedEventArgs e)
  59. {
  60. TextBlock id = (TextBlock)sender;
  61. int index = Convert.ToInt32(id.Uid);
  62. Music DB = new Music();
  63. DateTime date = (DateTime)DB.Concerts.Where(x=>x.ID_Concert==index).Select(x=>x.Date).First();
  64. DateTime today = DateTime.Now;
  65. TimeSpan diff = date.Subtract(today);
  66. id.Text = "Дней до концерта "+diff.Days.ToString();
  67. }
  68. public void Back(object sender, EventArgs e)
  69. {
  70. MainFrame.mframe.Navigate(new AdminPage(id));
  71. }
  72. public void Add(object sender, EventArgs e)
  73. {
  74. MainFrame.mframe.Navigate(new AddConcert(id));
  75. }
  76. public void Edit(object sender, EventArgs e)
  77. {
  78. Button but = (Button)sender;
  79. int index = Convert.ToInt32(but.Uid);
  80. MainFrame.mframe.Navigate(new AddConcert(index, id));
  81. }
  82. public void Delete(object sender, EventArgs e)
  83. {
  84. Music DB = new Music();
  85. Button butt = (Button)sender;
  86. int index = Convert.ToInt32(butt.Uid);
  87. Concerts concert = DB.Concerts.Where(x=>x.ID_Concert == index).FirstOrDefault();
  88. switch (MessageBox.Show("Отменить концерт?", "concert", MessageBoxButton.YesNo, MessageBoxImage.Question))
  89. {
  90. case MessageBoxResult.Yes:
  91. DB.Concerts.Remove(concert);
  92. MessageBox.Show("Концерта больше нет");
  93. DB.SaveChanges();
  94. MainFrame.mframe.Navigate(new TableData(id));
  95. break;
  96. case MessageBoxResult.No:
  97. MessageBox.Show("Ну нет так нет");
  98. break;
  99. }
  100. }
  101. public void Filter()
  102. {
  103. Music DB = new Music();
  104. List<Concerts> ConcFilter = new List<Concerts>();
  105. if (CityFilter.SelectedIndex != 0)
  106. {
  107. List<Places> pl = DB.Places.ToList();
  108. int index = Convert.ToInt32(pl.Where(x => x.ID_City == CityFilter.SelectedIndex).Select(x => x.ID_Place).FirstOrDefault());
  109. ConcFilter = DB.Concerts.Where(x => x.ID_Place == index).ToList();
  110. }
  111. else
  112. {
  113. ConcFilter = DB.Concerts.ToList();
  114. }
  115. if(InThisYear.IsChecked == true)
  116. {
  117. int year = DateTime.Now.Year;
  118. DateTime end = new DateTime(year, 12, 31);
  119. ConcFilter = ConcFilter.Where(x => x.Date <= end).ToList();
  120. }
  121. if (!string.IsNullOrWhiteSpace(Search.Text))
  122. {
  123. ConcFilter = ConcFilter.Where(x => x.Name.ToLower().Contains(Search.Text.ToLower())).ToList();
  124. }
  125. if(Sort.SelectedItem.ToString()=="По дате" && Up.IsChecked == true)
  126. {
  127. ConcFilter = ConcFilter.OrderBy(x => x.Date).ToList();
  128. }
  129. if(Sort.SelectedItem.ToString() == "По дате" && Down.IsChecked == true)
  130. {
  131. ConcFilter = ConcFilter.OrderByDescending(x => x.Date).ToList();
  132. }
  133. if(Sort.SelectedItem.ToString()=="По цене" && Up.IsChecked==true)
  134. {
  135. ConcFilter = ConcFilter.OrderBy(x=>(x.Lowest_Price + x.Highest_Price) / 2).ToList();
  136. }
  137. if (Sort.SelectedItem.ToString() == "По цене" && Down.IsChecked == true)
  138. {
  139. ConcFilter = ConcFilter.OrderByDescending(x => (x.Lowest_Price + x.Highest_Price) / 2).ToList();
  140. }
  141. ConcertData.ItemsSource = ConcFilter;
  142. }
  143. private void CityChanged(object sender, SelectionChangedEventArgs e)
  144. {
  145. Filter();
  146. }
  147. private void CheckedChanged(object sender, RoutedEventArgs e)
  148. {
  149. Filter();
  150. }
  151. private void SearchChange(object sender, TextChangedEventArgs e)
  152. {
  153. Filter();
  154. }
  155. private void SortChanged(object sender, SelectionChangedEventArgs e)
  156. {
  157. Filter();
  158. }
  159. private void Up_Checked(object sender, RoutedEventArgs e)
  160. {
  161. Filter();
  162. }
  163. private void Down_Checked(object sender, RoutedEventArgs e)
  164. {
  165. Filter();
  166. }
  167. }
  168. }