PageListOfService.xaml.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 School
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для PageListOfService.xaml
  19. /// </summary>
  20. public partial class PageListOfService : Page
  21. {
  22. public static string admin;
  23. public PageListOfService()
  24. {
  25. InitializeComponent();
  26. ListService.ItemsSource = DBase.DB.Service.ToList();
  27. Sorting.SelectedIndex = 0;
  28. Filtering.SelectedIndex = 0;
  29. CountService.Text = DBase.DB.Service.ToList().Count + "/" + DBase.DB.Service.ToList().Count;
  30. if (admin == "0000")
  31. {
  32. Service.btn_admin = Visibility.Visible;
  33. AddService.Visibility = Visibility.Visible;
  34. }
  35. else
  36. {
  37. Service.btn_admin = Visibility.Collapsed;
  38. AddService.Visibility = Visibility.Collapsed;
  39. }
  40. }
  41. void Filter()
  42. {
  43. List<Service> services = new List<Service>();
  44. services = DBase.DB.Service.ToList();
  45. //Поиск по названию
  46. if (!string.IsNullOrWhiteSpace(SearchName.Text)) // Проверка пустую запись и запись состоящую из пробелов
  47. {
  48. services = services.Where(x => x.Title.ToLower().Contains(SearchName.Text.ToLower())).ToList();
  49. }
  50. if (!string.IsNullOrWhiteSpace(SearchDescription.Text))
  51. {
  52. List<Service> description = services.Where(x => x.Description != null).ToList();
  53. if (description.Count > 0)
  54. {
  55. services = description.Where(x => x.Description.ToLower().Contains(SearchDescription.Text.ToLower())).ToList();
  56. }
  57. else
  58. {
  59. MessageBox.Show("Записей с таким описанием нет");
  60. SearchDescription.Text = "";
  61. }
  62. }
  63. //Фильтрация по размеру скидки
  64. switch (Filtering.SelectedIndex)
  65. {
  66. case 0:
  67. {
  68. services = services.ToList();
  69. }
  70. break;
  71. case 1:
  72. {
  73. services = services.Where(x => ((x.Discount >= 0) && (x.Discount * 100 < 5))).ToList();
  74. }
  75. break;
  76. case 2:
  77. {
  78. services = services.Where(x => ((x.Discount * 100 >= 5) && (x.Discount * 100 < 15))).ToList();
  79. }
  80. break;
  81. case 3:
  82. {
  83. services = services.Where(x => ((x.Discount * 100 >= 15) && (x.Discount * 100 < 30))).ToList();
  84. }
  85. break;
  86. case 4:
  87. {
  88. services = services.Where(x => ((x.Discount * 100 >= 30) && (x.Discount * 100 < 70))).ToList();
  89. }
  90. break;
  91. case 5:
  92. {
  93. services = services.Where(x => ((x.Discount * 100 >= 70) && (x.Discount * 100 < 100))).ToList();
  94. }
  95. break;
  96. }
  97. //сортировка
  98. switch (Sorting.SelectedIndex)
  99. {
  100. case 0:
  101. {
  102. services.Sort((x, y) => x.Cost.CompareTo(y.Cost));
  103. }
  104. break;
  105. case 1:
  106. {
  107. services.Sort((x, y) => x.Cost.CompareTo(y.Cost));
  108. services.Reverse();
  109. }
  110. break;
  111. }
  112. ListService.ItemsSource = services;
  113. if (services.Count == 0)
  114. {
  115. MessageBox.Show("нет записей");
  116. CountService.Text = DBase.DB.Service.ToList().Count + "/" + DBase.DB.Service.ToList().Count;
  117. SearchName.Text = "";
  118. SearchDescription.Text = "";
  119. Sorting.SelectedIndex = 0;
  120. Filtering.SelectedIndex = 0;
  121. }
  122. CountService.Text = services.Count + "/" + DBase.DB.Service.ToList().Count;
  123. }
  124. private void SearchName_TextChanged(object sender, TextChangedEventArgs e)
  125. {
  126. Filter();
  127. }
  128. private void SearchDescription_TextChanged(object sender, TextChangedEventArgs e)
  129. {
  130. Filter();
  131. }
  132. private void Filtering_SelectionChanged(object sender, SelectionChangedEventArgs e)
  133. {
  134. Filter();
  135. }
  136. private void Sorting_SelectionChanged(object sender, SelectionChangedEventArgs e)
  137. {
  138. Filter();
  139. }
  140. private void Delete_Click(object sender, RoutedEventArgs e)
  141. {
  142. Button btn = (Button)sender;
  143. int id = Convert.ToInt32(btn.Uid);
  144. Service serv = DBase.DB.Service.FirstOrDefault(x => x.ID == id);
  145. List<ClientService> clientservices = DBase.DB.ClientService.Where(x => x.ServiceID == serv.ID).ToList();
  146. if (clientservices.Count > 0)
  147. {
  148. MessageBox.Show("Данную услугу нельзя удалить");
  149. }
  150. else
  151. {
  152. DBase.DB.Service.Remove(serv);
  153. DBase.DB.SaveChanges();
  154. ClassFrame.newFrame.Navigate(new PageListOfService());
  155. }
  156. }
  157. private void AddService_Click(object sender, RoutedEventArgs e)
  158. {
  159. ClassFrame.newFrame.Navigate(new AddPage());
  160. }
  161. private void Update_Click(object sender, RoutedEventArgs e)
  162. {
  163. Button btn = (Button)sender;
  164. int id = Convert.ToInt32(btn.Uid);
  165. Service service = DBase.DB.Service.FirstOrDefault(x => x.ID == id);
  166. ClassFrame.newFrame.Navigate(new AddPage(service));
  167. }
  168. private void SingUp_Click(object sender, RoutedEventArgs e)
  169. {
  170. Button btn = (Button)sender;
  171. int id = Convert.ToInt32(btn.Uid);
  172. Service service = DBase.DB.Service.FirstOrDefault(x => x.ID == id);
  173. ClassFrame.newFrame.Navigate(new PageAddNote(service));
  174. }
  175. private void Home_Click(object sender, RoutedEventArgs e)
  176. {
  177. ClassFrame.newFrame.Navigate(new HomePage("0000"));
  178. }
  179. }
  180. }