ServicesPage.xaml.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 Nastya.Pages
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для ServicesPage.xaml
  19. /// </summary>
  20. public partial class ServicesPage : Page
  21. {
  22. public ServicesPage()
  23. {
  24. InitializeComponent();
  25. // 1 - админ, 2 - пользователь
  26. if (App.CurrentUser.Roleld == 1)
  27. {
  28. BtnAddService.Visibility = Visibility.Visible;
  29. }
  30. else
  31. {
  32. BtnAddService.Visibility= Visibility.Collapsed;
  33. }
  34. ComboDiscount.SelectedIndex = 0;
  35. ComboSortBy.SelectedIndex = 0;
  36. UpdateServices();
  37. }
  38. private void BtnAddService_Click(object sender, RoutedEventArgs e)
  39. {
  40. NavigationService.Navigate(new AddEditServicePage());
  41. }
  42. private void BtnEdit_Click(object sender, RoutedEventArgs e)
  43. {
  44. var currentService = (sender as Button).DataContext as Entities.Service;
  45. NavigationService.Navigate(new AddEditServicePage(currentService));
  46. }
  47. private void BtnDelete_Click(object sender, RoutedEventArgs e)
  48. {
  49. var currentService = (sender as Button).DataContext as Entities.Service;
  50. if (MessageBox.Show($"Вы уверены, что хотите удалить услугу: " +
  51. $"{currentService.Title}?", "Внимание",
  52. MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
  53. {
  54. App.Context.Service.Remove(currentService);
  55. App.Context.SaveChanges();
  56. UpdateServices();
  57. }
  58. }
  59. private void ComboSortBy_SelectionChanged(object sender, SelectionChangedEventArgs e)
  60. {
  61. UpdateServices();
  62. }
  63. private void ComboDiscount_SelectionChanged(object sender, SelectionChangedEventArgs e)
  64. {
  65. UpdateServices();
  66. }
  67. private void TBoxSearch_TextChanged(object sender, TextChangedEventArgs e)
  68. {
  69. UpdateServices();
  70. }
  71. private void UpdateServices()
  72. {
  73. var services = App.Context.Service.ToList();
  74. if (ComboSortBy.SelectedIndex == 0)
  75. services = services.OrderBy( p => p.CostWithDiscount).ToList();
  76. else
  77. services = services.OrderByDescending( p => p.CostWithDiscount).ToList();
  78. if (ComboDiscount.SelectedIndex == 1)
  79. services = services.Where( p => p.Discount >= 0 && p.Discount < 0.05).ToList();
  80. if (ComboDiscount.SelectedIndex == 2)
  81. services = services.Where(p => p.Discount >= 0.05 && p.Discount < 0.15).ToList();
  82. if (ComboDiscount.SelectedIndex == 3)
  83. services = services.Where(p => p.Discount >= 0.15 && p.Discount < 0.30).ToList();
  84. if (ComboDiscount.SelectedIndex == 4)
  85. services = services.Where(p => p.Discount >= 0.30 && p.Discount < 0.70).ToList();
  86. if (ComboDiscount.SelectedIndex == 5)
  87. services = services.Where(p => p.Discount >= 0.70 && p.Discount <= 1).ToList();
  88. services = services.Where( p => p.Title.ToLower()
  89. .Contains(TBoxSearch.Text.ToLower())).ToList();
  90. LViewServices.ItemsSource = services;
  91. }
  92. private void Page_Loaded(object sender, RoutedEventArgs e)
  93. {
  94. UpdateServices();
  95. }
  96. private void Page_Loaded_1(object sender, RoutedEventArgs e)
  97. {
  98. }
  99. public string AdminControlsVisibility
  100. {
  101. get
  102. {
  103. if (App.CurrentUser.Roleld == 1)
  104. {
  105. return "Visible";
  106. }
  107. else
  108. {
  109. return "Collapsed";
  110. }
  111. }
  112. }
  113. }
  114. }