MainApplicationWindow.xaml.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using OOO_WriteAndClear.DBModels;
  2. using OOO_WriteAndClear.EventBus.Signals;
  3. using OOO_WriteAndClear.MVP.Models.OrderFormerer;
  4. using OOO_WriteAndClear.MVP.MVPInterfaces;
  5. using OOO_WriteAndClear.MVP.Presenters;
  6. using OOO_WriteAndClear.MVP.Views;
  7. using OOO_WriteAndClear.MVP.Views.DisplayingUserControlManager;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Data;
  16. using System.Windows.Documents;
  17. using System.Windows.Input;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. using System.Windows.Shapes;
  21. namespace OOO_WriteAndClear.Views
  22. {
  23. /// <summary>
  24. /// Логика взаимодействия для MainApplicationWindow.xaml
  25. /// </summary>
  26. public partial class MainApplicationWindow : Window, IMainApplicationWindowContract.IView
  27. {
  28. public MainApplicationWindow()
  29. {
  30. InitializeComponent();
  31. _presenter = new MainApplicationWindowPresenter(this);
  32. _displayingUserControlManager = new DisplayingUserControlManager(this, new AuthorizationUserControl());
  33. EventBus.EventBus.GetService().Subscribe<UserWasLoggedSignal>(TransferUserToNextUC);
  34. EventBus.EventBus.GetService().Subscribe<GoToOrderCartSignal>(OpenOrderCart);
  35. EventBus.EventBus.GetService().Subscribe<BackToAuthorizationUserControlSignal>(BackAuthorizationUserControl);
  36. EventBus.EventBus.GetService().Subscribe<GoToProductsUserControlSignal>(GoToProductsUserControl);
  37. EventBus.EventBus.GetService().Subscribe<GoToOrdersUserControlSignal>(GoToOrdersUserControl);
  38. EventBus.EventBus.GetService().Subscribe<BackToFeaturesMenuUserControlSignal>(BackToMenuFeatures);
  39. EventBus.EventBus.GetService().Subscribe<ShowOrderTalonSignal>(ShowOrderTalon);
  40. }
  41. private readonly IMainApplicationWindowContract.IPresenter _presenter;
  42. /// <summary>
  43. /// Менеджер для инкапсуляции логики смены UC
  44. /// </summary>
  45. private readonly DisplayingUserControlManager _displayingUserControlManager;
  46. private void TransferUserToNextUC(UserWasLoggedSignal signal)
  47. {
  48. AddUserInAppResources(signal.User);
  49. if(signal.User.UserId == -1 || signal.User.UserRole == 1)
  50. {
  51. _displayingUserControlManager.DisplayingUserControl = new ProductsUserControl();
  52. return;
  53. }
  54. _displayingUserControlManager.DisplayingUserControl = new FeaturesMenuUserControl();
  55. return;
  56. }
  57. private void OpenOrderCart(GoToOrderCartSignal goToOrderCartSignal)
  58. {
  59. OrderCartWindow window = new OrderCartWindow(goToOrderCartSignal.OrderFormerer);
  60. window.ShowDialog();
  61. EventBus.EventBus.GetService().Invoke(new OrderCartWasClosedSignal());
  62. }
  63. private void BackAuthorizationUserControl(BackToAuthorizationUserControlSignal signal)
  64. {
  65. _displayingUserControlManager.DisplayingUserControl = new AuthorizationUserControl();
  66. }
  67. private void GoToProductsUserControl(GoToProductsUserControlSignal signal)
  68. {
  69. _displayingUserControlManager.DisplayingUserControl = new ProductsUserControl();
  70. }
  71. private void GoToOrdersUserControl(GoToOrdersUserControlSignal signal)
  72. {
  73. _displayingUserControlManager.DisplayingUserControl = new OrdersUserControl();
  74. }
  75. private void BackToMenuFeatures(BackToFeaturesMenuUserControlSignal signal)
  76. {
  77. _displayingUserControlManager.DisplayingUserControl = new FeaturesMenuUserControl();
  78. }
  79. private void ShowOrderTalon(ShowOrderTalonSignal signal)
  80. {
  81. new OrderReceipt(signal.Order).ShowDialog();
  82. }
  83. private void AddUserInAppResources(User user)
  84. {
  85. if (Application.Current.Resources.Contains("CurrentUser"))
  86. Application.Current.Resources["CurrentUser"] = user;
  87. else
  88. Application.Current.Resources.Add("CurrentUser", user);
  89. }
  90. }
  91. }