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
{
///
/// Логика взаимодействия для OrdersUserControl.xaml
///
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 Filters = new List()
{
new FilterByDiscountParameters(0, 100),
new FilterByDiscountParameters(0, 10),
new FilterByDiscountParameters(10, 15),
new FilterByDiscountParameters(15, 100),
};
private List SortingVarients = new List()
{
"По возрастанию",
"По убыванию"
};
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 orders = _presenter.UpdateOrdersListForSortingAndFilting(
filterByDiscountParameters
, sortingVarients);
Dispatcher.BeginInvoke(() =>
{
OrderListView.ItemsSource = orders;
});
});
}
private async Task FirstInitializeOrdersListView()
{
await UpdateOrdersListView();
FilterAndSortOrders();
}
}
}