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