OrdersUserControl.xaml.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using OOO_WriteAndClear.DBModels;
  2. using OOO_WriteAndClear.EventBus.Signals;
  3. using OOO_WriteAndClear.MVP.Models.ProductsUserControlModel;
  4. using OOO_WriteAndClear.MVP.MVPInterfaces;
  5. using OOO_WriteAndClear.MVP.Presenters;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Navigation;
  19. using System.Windows.Shapes;
  20. namespace OOO_WriteAndClear.MVP.Views
  21. {
  22. /// <summary>
  23. /// Логика взаимодействия для OrdersUserControl.xaml
  24. /// </summary>
  25. public partial class OrdersUserControl : UserControl, IOrdersUserControlContract.View
  26. {
  27. public OrdersUserControl()
  28. {
  29. InitializeComponent();
  30. _presenter = new OrdersUserControlPresenter(this);
  31. SetUserData();
  32. }
  33. private void Back_ButtonClick(object sender, RoutedEventArgs e) =>
  34. EventBus.EventBus.GetService().Invoke(new BackToFeaturesMenuUserControlSignal());
  35. private void SetUserData()
  36. {
  37. User user = (User)Application.Current.Resources["CurrentUser"];
  38. DisplayingUserName.Text = user.UserSurname
  39. + " "
  40. + user.UserName
  41. + " "
  42. + user.UserPatronymic;
  43. DisplayingUserRole.Text = user.UserRoleNavigation.RoleName;
  44. }
  45. private void OrdersUserControlLoaded(object sender, RoutedEventArgs e)
  46. {
  47. SetFilterComboBox();
  48. SetSortingComboBox();
  49. _isInitialized = true;
  50. FirstInitializeOrdersListView();
  51. }
  52. private Task UpdateOrdersListView()
  53. {
  54. return Task.Run(() =>
  55. {
  56. _presenter.UpdateOrdersFromDB();
  57. Dispatcher.BeginInvoke(new Action(() =>
  58. {
  59. OrderListView.ItemsSource = _presenter.Orders;
  60. }));
  61. });
  62. }
  63. private void SetFilterComboBox()
  64. {
  65. FilterComboBox.ItemsSource = Filters;
  66. FilterComboBox.SelectedIndex = 0;
  67. }
  68. private void SetSortingComboBox()
  69. {
  70. SortComboBox.ItemsSource = SortingVarients;
  71. SortComboBox.SelectedIndex = 0;
  72. }
  73. private List<FilterByDiscountParameters> Filters = new List<FilterByDiscountParameters>()
  74. {
  75. new FilterByDiscountParameters(0, 100),
  76. new FilterByDiscountParameters(0, 10),
  77. new FilterByDiscountParameters(10, 15),
  78. new FilterByDiscountParameters(15, 100),
  79. };
  80. private List<string> SortingVarients = new List<string>()
  81. {
  82. "По возрастанию",
  83. "По убыванию"
  84. };
  85. private IOrdersUserControlContract.Presenter _presenter;
  86. private bool _isInitialized = false;
  87. private void FilterChanged_SelectionChangedComboBox(object sender, SelectionChangedEventArgs e)
  88. {
  89. if (!_isInitialized)
  90. return;
  91. FilterAndSortOrders();
  92. }
  93. private void SortChanged_SelectionChangedComboBox(object sender, SelectionChangedEventArgs e)
  94. {
  95. if (!_isInitialized)
  96. return;
  97. FilterAndSortOrders();
  98. }
  99. private void FilterAndSortOrders()
  100. {
  101. FilterByDiscountParameters filterByDiscountParameters = (FilterByDiscountParameters)FilterComboBox.SelectedItem;
  102. string sortingVarients = (string)SortComboBox.SelectedItem;
  103. Task.Run(() =>
  104. {
  105. ICollection<Order> orders = _presenter.UpdateOrdersListForSortingAndFilting(
  106. filterByDiscountParameters
  107. , sortingVarients);
  108. Dispatcher.BeginInvoke(() =>
  109. {
  110. OrderListView.ItemsSource = orders;
  111. });
  112. });
  113. }
  114. private async Task FirstInitializeOrdersListView()
  115. {
  116. await UpdateOrdersListView();
  117. FilterAndSortOrders();
  118. }
  119. }
  120. }