Exemple #1
0
        public MenuBarViewModel(ScreenSwitcher switcher)
        {
            this.switcher = switcher;

            AuthorityController.LoggedIn += (s, e) =>
            {
                CurrentUser = AuthorityController.CurrentUser;

                OpenSyncCommand.IsVisible     = AuthorityController.CurrentUserCanOpen(Screen.Sync);
                OpenDoctorsCommand.IsVisible  = AuthorityController.CurrentUserCanOpen(Screen.Doctors);
                OpenPatientsCommand.IsVisible = AuthorityController.CurrentUserCanOpen(Screen.Patients);
                OpenWordsCommand.IsVisible    = AuthorityController.CurrentUserCanOpen(Screen.Words);
                OpenVocsCommand.IsVisible     = AuthorityController.CurrentUserCanOpen(Screen.Vocabularies);
                OpenCriteriaCommand.IsVisible = AuthorityController.CurrentUserCanOpen(Screen.Criteria);
#if DEBUG
                OpenSyncCommand.IsVisible = true;
                OpenVocsCommand.IsVisible = true;
#endif
            };

            AuthorityController.LoggedOut += (s, e) =>
            {
                CurrentUser = AuthorityController.CurrentUser;
            };

            switcher.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "CurrentView")
                {
                    Visible = switcher.WithMenuBar;
                }
            };
        }
Exemple #2
0
        /// <summary>
        /// Открывает экран.
        /// </summary>
        /// <param name="screen"></param>
        /// <param name="replace">Открывать ли экран заново, если совпадает с текущим экраном.</param>
        public void OpenScreen(Screen screen, object parameter = null, bool replace = false)
        {
            if (!ac.CurrentUserCanOpen(screen))
            {
                throw new InvalidOperationException(string.Format("{0} не может открывать {1}", ac.CurrentUser, screen));
            }

            var updateCurView = replace || Screen != screen;

            Screen = screen;

            if (updateCurView)
            {
                if (_curView != null)
                {
                    _curView.Dispose();
                }

                switch (screen)
                {
                case Screen.Login:
                    var vm = new LoginViewModel();
                    if (!vm.LoggedIn)     // автовход - не открываем логин
                    {
                        CurrentView = vm;
                    }
                    break;

                case Screen.Doctors:
                    CurrentView = new DoctorsListViewModel();
                    break;

                case Screen.Sync:
                    CurrentView = new SyncViewModel(Constants.ServerConnectionInfo);
                    break;

                case Screen.Vocabularies:
                    CurrentView = new VocabularySyncViewModel(Constants.ServerConnectionInfo);
                    break;

                case Screen.Patients:
                    CurrentView = new PatientsListViewModel();
                    break;

                case Screen.Words:
                    CurrentView = new WordsListViewModel();
                    break;

                case Screen.Criteria:
                    var crVm = new CriteriaViewModel();
                    var crit = parameter as ICrit;
                    if (crit != null)
                    {
                        crVm.Open(crit);
                    }
                    CurrentView = crVm;
                    break;

                case Screen.Card:
                    var cardVm = new CardViewModel(false);
                    cardVm.LastItemRemoved += (s, e) =>
                    {
                        OpenScreen(Screen.Patients);
                    };
                    cardVm.Open(parameter, lastAppOrCourse: true);
                    CurrentView = cardVm;
                    break;

                default:
                    break;
                }
            }
            else // только открываем сущность на экране
            {
                if (screen == Screen.Card)
                {
                    (CurrentView as CardViewModel).Open(parameter);
                }
                else if (screen == Screen.Criteria)
                {
                    var crit = parameter as ICrit;
                    if (crit != null)
                    {
                        (CurrentView as CriteriaViewModel).Open(crit);
                    }
                }
            }
        }