123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using OOO_WriteAndClear.DBModels;
- using OOO_WriteAndClear.EventBus.Signals;
- using OOO_WriteAndClear.MVP.Models.OrderFormerer;
- using OOO_WriteAndClear.MVP.MVPInterfaces;
- using OOO_WriteAndClear.MVP.Presenters;
- using OOO_WriteAndClear.MVP.Views;
- using OOO_WriteAndClear.MVP.Views.DisplayingUserControlManager;
- 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.Shapes;
- namespace OOO_WriteAndClear.Views
- {
- /// <summary>
- /// Логика взаимодействия для MainApplicationWindow.xaml
- /// </summary>
- public partial class MainApplicationWindow : Window, IMainApplicationWindowContract.IView
- {
- public MainApplicationWindow()
- {
- InitializeComponent();
- _presenter = new MainApplicationWindowPresenter(this);
- _displayingUserControlManager = new DisplayingUserControlManager(this, new AuthorizationUserControl());
- EventBus.EventBus.GetService().Subscribe<UserWasLoggedSignal>(TransferUserToNextUC);
- EventBus.EventBus.GetService().Subscribe<GoToOrderCartSignal>(OpenOrderCart);
- EventBus.EventBus.GetService().Subscribe<BackToAuthorizationUserControlSignal>(BackAuthorizationUserControl);
- EventBus.EventBus.GetService().Subscribe<GoToProductsUserControlSignal>(GoToProductsUserControl);
- EventBus.EventBus.GetService().Subscribe<GoToOrdersUserControlSignal>(GoToOrdersUserControl);
- EventBus.EventBus.GetService().Subscribe<BackToFeaturesMenuUserControlSignal>(BackToMenuFeatures);
- EventBus.EventBus.GetService().Subscribe<ShowOrderTalonSignal>(ShowOrderTalon);
- }
- private readonly IMainApplicationWindowContract.IPresenter _presenter;
- /// <summary>
- /// Менеджер для инкапсуляции логики смены UC
- /// </summary>
- private readonly DisplayingUserControlManager _displayingUserControlManager;
- private void TransferUserToNextUC(UserWasLoggedSignal signal)
- {
- AddUserInAppResources(signal.User);
- if(signal.User.UserId == -1 || signal.User.UserRole == 1)
- {
- _displayingUserControlManager.DisplayingUserControl = new ProductsUserControl();
- return;
- }
- _displayingUserControlManager.DisplayingUserControl = new FeaturesMenuUserControl();
- return;
- }
- private void OpenOrderCart(GoToOrderCartSignal goToOrderCartSignal)
- {
- OrderCartWindow window = new OrderCartWindow(goToOrderCartSignal.OrderFormerer);
- window.ShowDialog();
- EventBus.EventBus.GetService().Invoke(new OrderCartWasClosedSignal());
- }
- private void BackAuthorizationUserControl(BackToAuthorizationUserControlSignal signal)
- {
- _displayingUserControlManager.DisplayingUserControl = new AuthorizationUserControl();
- }
- private void GoToProductsUserControl(GoToProductsUserControlSignal signal)
- {
- _displayingUserControlManager.DisplayingUserControl = new ProductsUserControl();
- }
- private void GoToOrdersUserControl(GoToOrdersUserControlSignal signal)
- {
- _displayingUserControlManager.DisplayingUserControl = new OrdersUserControl();
- }
- private void BackToMenuFeatures(BackToFeaturesMenuUserControlSignal signal)
- {
- _displayingUserControlManager.DisplayingUserControl = new FeaturesMenuUserControl();
- }
- private void ShowOrderTalon(ShowOrderTalonSignal signal)
- {
- new OrderReceipt(signal.Order).ShowDialog();
- }
- private void AddUserInAppResources(User user)
- {
- if (Application.Current.Resources.Contains("CurrentUser"))
- Application.Current.Resources["CurrentUser"] = user;
- else
- Application.Current.Resources.Add("CurrentUser", user);
- }
- }
- }
|