Beispiel #1
0
        public PageNotification(NotificationType type, string replacement = "", bool returnBack = false,
                                Exception exception = null, bool?isQueryException = null)
        {
            InitializeComponent();
            Console.WriteLine(@"http://CONSTRUCT_PageNotification.type." + type);

            Logging.ToLog("PageNotification - Отображение страницы типа: " + type);

            CurrentNotificationType = type;
            this.returnBack         = returnBack;

            string textTop    = string.Empty;
            string textBottom = string.Empty;

            ControlsFactory.ImageType imageType = ControlsFactory.ImageType.NotificationRegistry;
            string textToShow = string.Empty;

            title = Properties.Resources.title_notification;
            this.isQueryException = isQueryException;

            switch (type)
            {
            case NotificationType.Welcome:
                textToShow = Properties.Resources.notification_welcome;
                title      = Properties.Resources.title_welcome;
                MediaElementWelcomeAnimation.Visibility = Visibility.Visible;
                TextBlockAboutDeveloper.Visibility      = Visibility.Visible;
                GridImage.Visibility = Visibility.Hidden;
                KeepAlive            = true;
                isError = false;
                break;

            case NotificationType.NumberNotFound:
                textToShow = Properties.Resources.notification_nothing_found;
                imageType  = ControlsFactory.ImageType.NotificationNumberNotFound;
                break;

            case NotificationType.NoAppointmentsForNow:
                textToShow = Properties.Resources.notification_no_appointmetns_for_now;
                imageType  = ControlsFactory.ImageType.NotificationAppointmentsNotAvailable;
                break;

            case NotificationType.NameNotCorrect:
                textToShow = Properties.Resources.notification_wrong_name;
                imageType  = ControlsFactory.ImageType.NotificationWrongNumber;
                break;

            case NotificationType.FirstVisit:
                textToShow = Properties.Resources.notification_first_visit;
                imageType  = ControlsFactory.ImageType.NotificationFirstVisit;
                break;

            case NotificationType.VisitRegistryToCheckIn:
                textToShow            = Properties.Resources.notification_need_go_to_registry;
                ButtonInfo.Visibility = Visibility.Visible;
                ButtonInfo.Style      = BindingValues.Instance.StyleRoundCorner;
                break;

            case NotificationType.DbError:
                textToShow = Properties.Resources.notification_db_not_available;
                title      = Properties.Resources.title_welcome;

                TextBlockAboutDeveloper.Visibility = Visibility.Visible;
                imageType = ControlsFactory.ImageType.NotificationDbError;
                TextBlockTapToContinue.Visibility = Visibility.Collapsed;
                TextBlockBottom.Margin            = new Thickness(0);
                isError = true;

                SetupErrorNotification(exception);

                break;

            case NotificationType.Cash:
                imageType  = ControlsFactory.ImageType.NotificationCash;
                textToShow = Properties.Resources.notification_cash;
                break;

            case NotificationType.CheckInFailed:
                imageType  = ControlsFactory.ImageType.NotificationDbError;
                textToShow = Properties.Resources.notification_check_in_failed;
                TextBlockAboutDeveloper.Visibility = Visibility.Visible;
                isError = true;
                break;

            case NotificationType.AlreadyChecked:
                imageType  = ControlsFactory.ImageType.NotificationRegistry;
                textToShow = Properties.Resources.notification_already_checked;
                break;

            default:
                break;
            }

            ImageCenter.Source = ControlsFactory.GetImage(imageType);

            string[] splittedTextToShow = textToShow.Split(new string[] { "\r\n\r\n" }, StringSplitOptions.None);
            TextBlockTop.Text = splittedTextToShow[0].Replace("*", replacement);

            if (splittedTextToShow.Length > 1)
            {
                TextBlockBottom.Text = splittedTextToShow[1];
            }

            DataContext = BindingValues.Instance;

            IsVisibleChanged += (s, e) => {
                if ((bool)e.NewValue)
                {
                    BindingValues.Instance.SetUpMainWindow(title, true, isError);

                    if (CurrentNotificationType == NotificationType.DbError)
                    {
                        return;
                    }
                    Console.WriteLine("---PageNotification_PreviewMouseDown subscribe");
                    MainWindow.Instance.PreviewMouseDown += PageNotification_PreviewMouseDown;
                }
                else
                {
                    Console.WriteLine("---PageNotification_PreviewMouseDown unsubscribe");
                    MainWindow.Instance.PreviewMouseDown -= PageNotification_PreviewMouseDown;
                }
            };
        }
        public PageNotificationViewModel(NotificationType type, string replacement = "", bool returnBack = false, Exception exception = null)
        {
            CurrentNotificationType = type;
            this.returnBack         = returnBack;
            //MainWindow.ConfigurePage(this);
            TextBlockBottom.Foreground        = Properties.Settings.Default.BrushTextDisabledForeground;
            TextBlockTapToContinue.Foreground = Properties.Settings.Default.BrushTextDisabledForeground;

            string textTop    = string.Empty;
            string textBottom = string.Empty;

            ControlsFactory.ImageType imageType = ControlsFactory.ImageType.NotificationRegistry;
            string textToShow = string.Empty;

            title = Properties.Resources.title_notification;

            switch (type)
            {
            case NotificationType.Welcome:
                textToShow = Properties.Resources.notification_welcome;
                title      = Properties.Resources.title_welcome;
                MediaElementWelcomeAnimation.Visibility = Visibility.Visible;
                TextBlockAboutDeveloper.Visibility      = Visibility.Visible;
                GridImage.Visibility = Visibility.Hidden;
                KeepAlive            = true;
                isError = false;
                break;

            case NotificationType.NumberNotFound:
                textToShow = Properties.Resources.notification_nothing_found;
                imageType  = ControlsFactory.ImageType.NotificationNumberNotFound;
                break;

            case NotificationType.NoAppointmentsForNow:
                textToShow = Properties.Resources.notification_no_appointmetns_for_now;
                break;

            case NotificationType.NameNotCorrect:
                textToShow = Properties.Resources.notification_wrong_name;
                break;

            case NotificationType.FirstVisit:
                textToShow = Properties.Resources.notification_first_visit;
                break;

            case NotificationType.CardBlocked:
                textToShow = Properties.Resources.notification_need_go_to_registry;
                break;

            case NotificationType.DbError:
                textToShow = Properties.Resources.notification_db_not_available;
                title      = Properties.Resources.title_welcome;
                TextBlockAboutDeveloper.Visibility = Visibility.Visible;
                imageType = ControlsFactory.ImageType.NotificationDbError;
                TextBlockTapToContinue.Visibility = Visibility.Collapsed;
                TextBlockBottom.Margin            = new Thickness(0);
                isError = true;

                if (exception != null)
                {
                    string msg = exception.Message + Environment.NewLine + exception.StackTrace;
                    if (exception.InnerException != null)
                    {
                        msg += Environment.NewLine + Environment.NewLine + exception.InnerException.Message +
                               Environment.NewLine + exception.InnerException.StackTrace;
                    }

                    Mail.SendMail("Ошибка в работе инфомата", msg, Properties.Settings.Default.MailTo);
                }

                DispatcherTimer dispatcherTimer = new DispatcherTimer()
                {
                    Interval = TimeSpan.FromMinutes(1)
                };

                dispatcherTimer.Tick += (s, e) => {
                    try {
                        DataHandle.CheckDbAvailable();
                        PageNotification_PreviewMouseDown(null, null);
                    } catch (Exception exc) {
                        Logging.ToLog("PageNotification - " + exc.Message + Environment.NewLine + exc.StackTrace);
                    }
                };
                dispatcherTimer.Start();

                break;

            default:
                break;
            }

            ImageCenter.Source = ControlsFactory.GetImage(imageType);
            string[] splittedTextToShow = textToShow.Split(new string[] { "\r\n\r\n" }, StringSplitOptions.None);
            TextBlockTop.Text = splittedTextToShow[0].Replace("*", replacement);

            if (splittedTextToShow.Length > 1)
            {
                TextBlockBottom.Text = splittedTextToShow[1];
            }

            Loaded           += PageNotification_Loaded;
            IsVisibleChanged += PageNotification_IsVisibleChanged;
        }