ShowProductPage.xaml.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Entity;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Security.Cryptography.Xml;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. using Write_erase.Classes;
  19. using static Write_erase.Classes.RoleClass;
  20. namespace Write_erase.UserPages
  21. {
  22. /// <summary>
  23. /// Логика взаимодействия для ShowProductPage.xaml
  24. /// </summary>
  25. public partial class ShowProductPage : Page
  26. {
  27. RoleUser nowRole;
  28. User nowUser;
  29. List<Product> products = DataBaseClass.entity.Product.ToList();
  30. string Click = "";
  31. int id;
  32. public ShowProductPage()
  33. {
  34. InitializeComponent();
  35. List<User> users = DataBaseClass.entity.User.Where(x => x.UserID == id).ToList();
  36. foreach (User user in users)
  37. {
  38. FIO.Text = user.UserPatronymic + " " + user.UserName + " " + user.UserSurname;
  39. }
  40. ProductPanelUser.ItemsSource = DataBaseClass.entity.Product.ToList();
  41. CBDiscount.Items.Add("Все диапазоны");
  42. CBDiscount.Items.Add("0-9,99%");
  43. CBDiscount.Items.Add("10-14,99%");
  44. CBDiscount.Items.Add("15% и более");
  45. CBDiscount.SelectedIndex = 0;
  46. TBShowAll.Text = "Всего товаров: " + DataBaseClass.entity.Product.ToList().Count;
  47. nowRole = RoleUser.Noname;
  48. }
  49. public ShowProductPage(int id)
  50. {
  51. id = id;
  52. InitializeComponent();
  53. List<User> users = DataBaseClass.entity.User.Where(x=> x.UserID == id).ToList();
  54. foreach (User user in users)
  55. {
  56. FIO.Text = user.UserPatronymic + " " + user.UserName + " " + user.UserSurname;
  57. }
  58. ProductPanelUser.ItemsSource = DataBaseClass.entity.Product.ToList();
  59. CBDiscount.Items.Add("Все диапазоны");
  60. CBDiscount.Items.Add("0-9,99%");
  61. CBDiscount.Items.Add("10-14,99%");
  62. CBDiscount.Items.Add("15% и более");
  63. CBDiscount.SelectedIndex = 0;
  64. TBShowAll.Text = "Всего товаров: " + DataBaseClass.entity.Product.ToList().Count;
  65. nowRole = RoleUser.User;
  66. nowUser = DataBaseClass.entity.User.FirstOrDefault(x => x.UserID == id);
  67. }
  68. private void Filter()
  69. {
  70. switch (CBDiscount.SelectedIndex)
  71. {
  72. case 0: products = DataBaseClass.entity.Product.ToList(); break;
  73. case 1: products = DataBaseClass.entity.Product.Where(x => x.ProductDiscountAmount / 100 < 0.0999).ToList(); break;
  74. case 2: products = DataBaseClass.entity.Product.Where(x => x.ProductDiscountAmount / 100 >= 10 && x.ProductDiscountAmount / 100 < 0.1499).ToList(); break;
  75. case 3: products = DataBaseClass.entity.Product.Where(x => x.ProductDiscountAmount / 100 >= 0.15).ToList(); break;
  76. }
  77. ProductPanelUser.ItemsSource = products;
  78. TBShowPart.Text = "Показано предложений: " + products.Count;
  79. }
  80. private void Sorter()
  81. {
  82. if (!string.IsNullOrWhiteSpace(TBXSearch.Text))
  83. {
  84. products = DataBaseClass.entity.Product.Where(x => x.ProductName.ToLower().Contains(TBXSearch.Text.ToLower())).ToList();
  85. }
  86. if (RBUp.IsChecked == true)
  87. {
  88. products.Sort((x, y) => x.ProductCost.CompareTo(y.ProductCost));
  89. }
  90. else if (RBDown.IsChecked == true)
  91. {
  92. products.Sort((x, y) => x.ProductCost.CompareTo(y.ProductCost));
  93. products.Reverse();
  94. }
  95. else if (RBDefault.IsChecked == true)
  96. {
  97. products.Sort((x, y) => x.ProductArticleNumber.CompareTo(y.ProductArticleNumber));
  98. }
  99. if (products.Count == 0)
  100. {
  101. MessageBox.Show("Товаров с таким диапазоном скидок нет");
  102. }
  103. ProductPanelUser.ItemsSource = products;
  104. TBShowPart.Text = "Показано предложений: " + products.Count;
  105. }
  106. private void RBUp_Click(object sender, RoutedEventArgs e)
  107. {
  108. Sorter();
  109. }
  110. private void RBDown_Click(object sender, RoutedEventArgs e)
  111. {
  112. Sorter();
  113. }
  114. private void RBDefault_Click(object sender, RoutedEventArgs e)
  115. {
  116. Sorter();
  117. }
  118. private void CBDiscount_SelectionChanged(object sender, SelectionChangedEventArgs e)
  119. {
  120. Filter();
  121. }
  122. private void TBXSearch_TextChanged(object sender, TextChangedEventArgs e)
  123. {
  124. Sorter();
  125. }
  126. private void Delete_Click(object sender, RoutedEventArgs e)
  127. {
  128. }
  129. private void Add_Click(object sender, RoutedEventArgs e)
  130. {
  131. Product p = DataBaseClass.entity.Product.FirstOrDefault(x => x.ProductArticleNumber == ((Product)ProductPanelUser.SelectedItem).ProductArticleNumber);
  132. if (p != null)
  133. {
  134. switch (((MenuItem)sender).Header)
  135. {
  136. case "Добавить к заказу":
  137. if (BascketClass.bascket.Contains(p))
  138. {
  139. p.CountProduct++;
  140. }
  141. else
  142. {
  143. p.CountProduct++;
  144. BascketClass.bascket.Add(p);
  145. }
  146. Basket.Visibility = Visibility.Visible;
  147. break;
  148. case "Удалить из заказа":
  149. if (BascketClass.bascket.Contains(p) && p.CountProduct > 1)
  150. {
  151. p.CountProduct--;
  152. }
  153. else if (BascketClass.bascket.Contains(p) && p.CountProduct == 1)
  154. {
  155. p.CountProduct--;
  156. BascketClass.bascket.Remove(p);
  157. Basket.Visibility = Visibility.Hidden;
  158. }
  159. break;
  160. }
  161. }
  162. }
  163. private void Back_Click(object sender, RoutedEventArgs e)
  164. {
  165. FrameClass.MFrame.Navigate(new MainPages.AutorizePage());
  166. }
  167. private void Basket_Click(object sender, RoutedEventArgs e)
  168. {
  169. BasketWindow bw;
  170. if (nowRole == RoleUser.Noname)
  171. bw = new BasketWindow(BascketClass.bascket);
  172. else
  173. bw = new BasketWindow(BascketClass.bascket, nowUser);
  174. bw.ShowDialog();
  175. if (BascketClass.bascket.Count > 0)
  176. Basket.Visibility = Visibility.Visible;
  177. else
  178. Basket.Visibility = Visibility.Collapsed;
  179. }
  180. }
  181. }