예제 #1
0
        public void SetNavigationService(NavigationService navigationService)
        {
            this.navigationService = navigationService;

            PageNotification pageNotification = new PageNotification();            // new PageNotification(PageNotification.NotificationType.Welcome);

            navigationService.Navigate(pageNotification);
        }
        public void ShowErrorScreen(Exception e, bool isQueryException)
        {
            Dispatcher.BeginInvoke((Action)(() => {
                if (FrameMain.NavigationService.Content is PageNotification)
                {
                    PageNotification currentPage = FrameMain.NavigationService.Content as PageNotification;
                    if (currentPage.CurrentNotificationType == PageNotification.NotificationType.DbError)
                    {
                        return;
                    }
                }

                FrameMain.NavigationService.Navigate(
                    new PageNotification(PageNotification.NotificationType.DbError, exception: e, isQueryException: isQueryException));
            }));
        }
        public MainWindow()
        {
            InitializeComponent();

            instance = this;

            KeyDown += (s, e) => {
                if (!e.Key.Equals(Key.Escape))
                {
                    return;
                }

                ShutdownApp("Закрытие по нажатию клавиши ESC");
            };

            StartCheckDbAvailability();
            _ = ExcelInterop.Instance;

            PageNotification pageNotification = new PageNotification(PageNotification.NotificationType.Welcome);

            FrameMain.Navigate(pageNotification);
            DataContext = BindingValues.Instance;

            autoCloseTimer = new DispatcherTimer {
                Interval = TimeSpan.FromSeconds(Properties.Settings.Default.AutoCloseTimerIntervalInSeconds)
            };

            autoCloseTimer.Tick += AutoCloseTimer_Tick;
            FrameMain.Navigated += FrameMain_Navigated;
            PreviewMouseDown    += MainWindow_PreviewMouseDown;

            if (Debugger.IsAttached)
            {
                Cursor      = Cursors.Arrow;
                WindowState = WindowState.Normal;
                Width       = 1280;
                Height      = 1024;
                Topmost     = false;
            }
        }
        private async void TimerDbAvailability_Tick(object sender, EventArgs e)
        {
            if (dateTimeStart.Date != DateTime.Now.Date)
            {
                ShutdownApp("Автоматическое завершение работы");
            }

            if (FrameMain.NavigationService.Content is PageNotification)
            {
                PageNotification currentPage = FrameMain.NavigationService.Content as PageNotification;
                if (currentPage.CurrentNotificationType == PageNotification.NotificationType.DbError)
                {
                    return;
                }
            }

            Logging.ToLog("MainWindow - Проверка доступности БД");

            try {
                await Task.Run(() => { DataHandle.Instance.CheckDbAvailable(); }).ConfigureAwait(false);
            } catch (Exception exc) {
                ShowErrorScreen(exc, false);
            }
        }