123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace Practic.Pages
- {
- /// <summary>
- /// Логика взаимодействия для ServicesPage.xaml
- /// </summary>
- public partial class ServicesPage : Page
- {
- public ServicesPage()
- {
- InitializeComponent();
- LViewServices.ItemsSource = App.Context.Service.ToList();
- // 1 - админ, 2 - пользователь
- if (App.CurrentUser.Roleld == 1)
- {
- BtnAddService.Visibility = Visibility.Visible;
- }
- else
- {
- BtnAddService.Visibility = Visibility.Collapsed;
- }
- ComboDiscount.SelectedIndex = 0;
- ComboSortBy.SelectedIndex = 0;
- UpdateServices();
- }
- private void BtnAddService_Click(object sender, RoutedEventArgs e)
- {
- NavigationService.Navigate(new AddEditServicePage());
- }
- private void BtnEdit_Click(object sender, RoutedEventArgs e)
- {
- var currentSevice = (sender as Button).DataContext as Entities.Service;
- NavigationService.Navigate(new AddEditServicePage(currentSevice));
- }
- private void BtnDelete_Click(object sender, RoutedEventArgs e)
- {
- var currentService = (sender as Button).DataContext as Entities.Service;
- if (MessageBox.Show($"Вы уверены, что хотите удалить услугу:" + $"{currentService.Title}?", "Внимание!", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
- {
- App.Context.Service.Remove(currentService);
- App.Context.SaveChanges();
- UpdateServices();
- }
- }
- private void ComboSortBy_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- UpdateServices();
- }
- private void ComboDiscount_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- UpdateServices();
- }
- private void TBoxSearh_TextChanged(object sender, TextChangedEventArgs e)
- {
- UpdateServices();
- }
- private void UpdateServices()
- {
- var services = App.Context.Service.ToList();
- //Сортировка по цене
- if (ComboSortBy.SelectedIndex == 0)
- services = services.OrderBy(p => p.CostWithDiscount).ToList();
- else
- services = services.OrderByDescending(p => p.CostWithDiscount).ToList();
- // Фильтрация по рамеру скидки
- if (ComboDiscount.SelectedIndex == 1)
- services = services.Where(p => p.Discount >= 0 && p.Discount < 0.05).ToList();
- if (ComboDiscount.SelectedIndex == 2)
- services = services.Where(p => p.Discount >= 0.05 && p.Discount < 0.15).ToList();
- if (ComboDiscount.SelectedIndex == 3)
- services = services.Where(p => p.Discount >= 0.15 && p.Discount < 0.30).ToList();
- if (ComboDiscount.SelectedIndex == 4)
- services = services.Where(p => p.Discount >= 0.30 && p.Discount < 0.70).ToList();
- if (ComboDiscount.SelectedIndex == 5)
- services = services.Where(p => p.Discount >= 0.70 && p.Discount <= 1).ToList();
- // Поиск по названию (регистронезависимый)
- services = services.Where(p => p.Title.ToLower().Contains(TBoxSearh.Text.ToLower())).ToList();
- LViewServices.ItemsSource= services;
- }
- private void Page_Loaded (object sender, EventArgs e)
- {
- UpdateServices();
- }
- }
- }
|