Sneaker.xaml.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 SneakersSkakunov
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для Sneaker.xaml
  19. /// </summary>
  20. public partial class Sneaker : Page
  21. {
  22. int id;
  23. private void Revert(object sender, RoutedEventArgs e)
  24. {
  25. MainFrame.mframe.Navigate(new AdminPage(id));
  26. }
  27. private void Addendum(object sender, RoutedEventArgs e)
  28. {
  29. MainFrame.mframe.Navigate(new Add());
  30. }
  31. public Sneaker()
  32. {
  33. InitializeComponent();
  34. Sniker DB = new Sniker();
  35. SneakerList.ItemsSource = DB.Sneakers.ToList();
  36. List<string> s = new List<string>() { "Без фильтров", "По цене" };
  37. List<Brand> brd = DB.Brand.ToList();
  38. brnds.Items.Add("Все бренды");
  39. foreach (Brand i in brd)
  40. {
  41. brnds.Items.Add(i.Label);
  42. }
  43. RBNow.ItemsSource = s;
  44. RBNow.SelectedItem = "Без фильтров";
  45. brnds.SelectedIndex = 0;
  46. }
  47. public void brands(object sender, RoutedEventArgs e)
  48. {
  49. TextBlock brand = (TextBlock)sender;
  50. int index = Convert.ToInt32(brand.Uid);
  51. Sniker DB = new Sniker();
  52. string a = DB.Brand.Where(x => x.id_Brand == index).Select(x => x.Label).First();
  53. brand.Text = "Брэнд: " + a;
  54. }
  55. //public void models(object sender, RoutedEventArgs e)
  56. //{
  57. // TextBlock model = (TextBlock)sender;
  58. // int index = Convert.ToInt32(model.Uid);
  59. // Sniker DB = new Sniker();
  60. // string b = DB.Model.Where(x => x.id_model == index).Select(x => x.Model1 + " ").First();
  61. // model.Text = "Модель: " + b;
  62. //}
  63. public void Colors(object sender, RoutedEventArgs e)
  64. {
  65. TextBlock color = (TextBlock)sender;
  66. int index = Convert.ToInt32(color.Uid);
  67. Sniker DB = new Sniker();
  68. string c = DB.Sneakers.Where(x => x.id_Sneakers == index).Select(x => x.Colors + " ").First();
  69. color.Text = "Цвет: " + c;
  70. }
  71. public void prices(object sender, RoutedEventArgs e)
  72. {
  73. TextBlock price = (TextBlock)sender;
  74. int index = Convert.ToInt32(price.Uid);
  75. Sniker DB = new Sniker();
  76. string d = DB.Sneakers.Where(x => x.id_Sneakers == index).Select(x => x.Price + " ").First().ToString();
  77. price.Text = "Цена: " + d + "р.";
  78. }
  79. //public void Date(object sender, RoutedEventArgs e)
  80. //{
  81. // TextBlock data = (TextBlock)sender;
  82. // int index = Convert.ToInt32(data.Uid);
  83. // Sniker DB = new Sniker();
  84. // string d = DB.Cheque.Where(x => x.id_Cheque == index).Select(x => x.Date_of_formation + " ").First().ToString();
  85. // data.Text = "Дата: " + d;
  86. //}
  87. public void Sizes(object sender, RoutedEventArgs e)
  88. {
  89. TextBlock size = (TextBlock)sender;
  90. int index = Convert.ToInt32(size.Uid);
  91. Sniker DB = new Sniker();
  92. string c = DB.Sneakers.Where(x => x.id_Sneakers == index).Select(x => x.Size + " ").First();
  93. size.Text = "Размер: " + c;
  94. }
  95. private void Button_Click(object sender, RoutedEventArgs e)
  96. {
  97. Button tb = (Button)sender;
  98. int index = Convert.ToInt32(tb.Uid);
  99. Sniker DB = new Sniker();
  100. MainFrame.mframe.Navigate(new Add());
  101. }
  102. private void Delete(object sender, RoutedEventArgs e)
  103. {
  104. Button tb = (Button)sender;
  105. int index = Convert.ToInt32(tb.Uid);
  106. Sniker DB = new Sniker();
  107. Sneakers SneakerRemove = DB.Sneakers.FirstOrDefault(x => x.id_Sneakers == index);
  108. switch (MessageBox.Show("Удалить Кроссовки?", "SneakerInsurance", MessageBoxButton.YesNo, MessageBoxImage.Question))
  109. {
  110. case MessageBoxResult.Yes:
  111. DB.Sneakers.Remove(SneakerRemove);
  112. MessageBox.Show("Кроссовки были удалены");
  113. DB.SaveChanges();
  114. MainFrame.mframe.Navigate(new Sneaker());
  115. break;
  116. case MessageBoxResult.No:
  117. MessageBox.Show("Кроссовки не были удалены");
  118. break;
  119. }
  120. }
  121. public void Filter()
  122. {
  123. Sniker DB = new Sniker();
  124. List<Sneakers> snkFilter = new List<Sneakers>();
  125. if (brnds.SelectedIndex != 0)
  126. {
  127. List<Brand> br = DB.Brand.ToList();
  128. int index = Convert.ToInt32(br.Where(x => x.id_Brand == brnds.SelectedIndex).Select(x => x.id_Brand).FirstOrDefault());
  129. snkFilter = DB.Sneakers.Where(x => x.id_Brand == index).ToList();
  130. }
  131. else
  132. {
  133. snkFilter = DB.Sneakers.ToList();
  134. }
  135. if (!string.IsNullOrWhiteSpace(Clr.Text))
  136. {
  137. snkFilter = snkFilter.Where(x => x.Colors.ToString().Contains(Clr.Text.ToString())).ToList();
  138. }
  139. if (RBNow.SelectedItem.ToString() == "По цене" && RBUp.IsChecked == true)
  140. {
  141. snkFilter = snkFilter.OrderBy(x => x.Price).ToList();
  142. }
  143. if (RBNow.SelectedItem.ToString() == "По цене" && RBDown.IsChecked == true)
  144. {
  145. snkFilter = snkFilter.OrderByDescending(x => x.Price).ToList();
  146. }
  147. SneakerList.ItemsSource = snkFilter;
  148. }
  149. private void TBSearch_TextChanged(object sender, TextChangedEventArgs e)
  150. {
  151. Filter();
  152. }
  153. private void CBFilterBreed_SelectionChanged(object sender, SelectionChangedEventArgs e)
  154. {
  155. Filter();
  156. }
  157. private void CBOnly_Checked(object sender, RoutedEventArgs e)
  158. {
  159. Filter();
  160. }
  161. private void CBOnly_Unchecked(object sender, RoutedEventArgs e)
  162. {
  163. Filter();
  164. }
  165. private void RBUp_Checked(object sender, RoutedEventArgs e)
  166. {
  167. Filter();
  168. }
  169. private void SortChanged(object sender, SelectionChangedEventArgs e)
  170. {
  171. Filter();
  172. }
  173. }
  174. }