123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- using OOO_WriteAndClear.DBModels;
- using OOO_WriteAndClear.EventBus.Signals;
- using OOO_WriteAndClear.MVP.Models.ProductsUserControlModel;
- using OOO_WriteAndClear.MVP.MVPInterfaces;
- using OOO_WriteAndClear.MVP.Presenters;
- 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 OOO_WriteAndClear.MVP.Views
- {
- /// <summary>
- /// Логика взаимодействия для OrdersUserControl.xaml
- /// </summary>
- public partial class OrdersUserControl : UserControl, IOrdersUserControlContract.View
- {
- public OrdersUserControl()
- {
- InitializeComponent();
- _presenter = new OrdersUserControlPresenter(this);
- SetUserData();
- }
- private void Back_ButtonClick(object sender, RoutedEventArgs e) =>
- EventBus.EventBus.GetService().Invoke(new BackToFeaturesMenuUserControlSignal());
- private void SetUserData()
- {
- User user = (User)Application.Current.Resources["CurrentUser"];
- DisplayingUserName.Text = user.UserSurname
- + " "
- + user.UserName
- + " "
- + user.UserPatronymic;
- DisplayingUserRole.Text = user.UserRoleNavigation.RoleName;
- }
- private void OrdersUserControlLoaded(object sender, RoutedEventArgs e)
- {
- SetFilterComboBox();
- SetSortingComboBox();
- _isInitialized = true;
- FirstInitializeOrdersListView();
- }
- private Task UpdateOrdersListView()
- {
- return Task.Run(() =>
- {
- _presenter.UpdateOrdersFromDB();
- Dispatcher.BeginInvoke(new Action(() =>
- {
- OrderListView.ItemsSource = _presenter.Orders;
- }));
- });
- }
- private void SetFilterComboBox()
- {
- FilterComboBox.ItemsSource = Filters;
- FilterComboBox.SelectedIndex = 0;
- }
- private void SetSortingComboBox()
- {
- SortComboBox.ItemsSource = SortingVarients;
- SortComboBox.SelectedIndex = 0;
- }
- private List<FilterByDiscountParameters> Filters = new List<FilterByDiscountParameters>()
- {
- new FilterByDiscountParameters(0, 100),
- new FilterByDiscountParameters(0, 10),
- new FilterByDiscountParameters(10, 15),
- new FilterByDiscountParameters(15, 100),
- };
- private List<string> SortingVarients = new List<string>()
- {
- "По возрастанию",
- "По убыванию"
- };
- private IOrdersUserControlContract.Presenter _presenter;
- private bool _isInitialized = false;
- private void FilterChanged_SelectionChangedComboBox(object sender, SelectionChangedEventArgs e)
- {
- if (!_isInitialized)
- return;
- FilterAndSortOrders();
- }
- private void SortChanged_SelectionChangedComboBox(object sender, SelectionChangedEventArgs e)
- {
- if (!_isInitialized)
- return;
- FilterAndSortOrders();
- }
- private void FilterAndSortOrders()
- {
- FilterByDiscountParameters filterByDiscountParameters = (FilterByDiscountParameters)FilterComboBox.SelectedItem;
- string sortingVarients = (string)SortComboBox.SelectedItem;
- Task.Run(() =>
- {
- ICollection<Order> orders = _presenter.UpdateOrdersListForSortingAndFilting(
- filterByDiscountParameters
- , sortingVarients);
- Dispatcher.BeginInvoke(() =>
- {
- OrderListView.ItemsSource = orders;
- });
- });
-
- }
- private async Task FirstInitializeOrdersListView()
- {
- await UpdateOrdersListView();
- FilterAndSortOrders();
- }
- }
- }
|