示例#1
0
        public static void CheckConnection(eMammalIntegrationWindow window, bool loadProject = false)
        {
            eMammalMySQLOps db = new eMammalMySQLOps();

            bool isConnectionOpen = false;

            while (isConnectionOpen == false)
            {
                Thread.Sleep(200);
                isConnectionOpen = db.OpenConnectionIfNotOpen(true);
            }
            window.Dispatcher.BeginInvoke(new Action(() =>
            {
                Common.SetMessage(window, Constants.DATABASE_AVAILABLE, false, false);

                window.Tab.Visibility = Visibility.Visible;

                if (loadProject)
                {
                    window.Loadproject();
                }

                window.Tab.SelectedIndex = 0;
                window.Tab.IsEnabled     = true;

                window.IsEnabled = true;

                window.ButtonBack.Visibility = Visibility.Hidden;
                window.ReactivateButton(window.ButtonNext);
                window.ReactivateButton(window.ButtonBrowse);
            }));
        }
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            if (db.OpenConnectionIfNotOpen(true))
            {
                logger.Info(Constants.LOG_MESSAGE_APP_CONNECTED_TO_DATABASE);

                Loadproject();
                logger.Info(Constants.LOG_MESSAGE_PROJECT_LOADED);
            }
            else
            {
                logger.Info(Constants.LOG_APP_COULD_NOT_CONNECT_TO_DATABASE);

                Common.SetMessage(this, Constants.DATABASE_CONNECTION_ERROR, true, true);

                this.IsEnabled = false;

                DisableButton(ButtonNext);
                DisableButton(ButtonBack);
                DisableButton(ButtonBrowse);

                this.Activate();

                Thread thread = new Thread(() => Common.CheckConnection(this, true));
                thread.Start();
            }
        }