Exemple #1
0
        public MainWindowViewModel(Window mainwindow)
        {
            log.Debug(">>> Program started. <<<");

            MainWindow = mainwindow;

            try
            {
                // Set database connection.
                if (!DatabaseConnection.TestConnection())
                {
                    log.Debug("Can't connect to database. => Opening connection setup window.");
                    SetupConnectionWindow SCW = new SetupConnectionWindow();
                    SCW.ShowDialog();
                    if (!DatabaseConnection.TestConnection())
                    {
                        log.Debug("Database connection wasn't set.");
                        CloseWindow();
                        return;
                    }
                }

                // New user.
                if (UserLogin.IsEmptyUserDatabase())
                {
                    log.Debug("User datatable is empty. => Opening new user window.");
                    NotificationProvider.Info("Welcome First User!", "Please, set a username and a password.");
                    NewUserWindow NUW = new NewUserWindow();
                    NUW.ShowDialog();
                    if (UserLogin.IsEmptyUserDatabase())
                    {
                        log.Debug("User wasn't added.");
                        CloseWindow();
                        return;
                    }
                }

                // Login.
                log.Debug("Opening login window.");
                LoginWindow LW = new LoginWindow();
                LW.ShowDialog();
                if (UserLogin.LoginedUser == "")
                {
                    log.Debug("Not logged in.");
                    CloseWindow();
                    return;
                }
            }
            catch (Exception ex)
            {
                log.Fatal("Program initialization error.", ex);
                MessageBox.Show("Program initialization error.\nCheck RedLog.txt for more information.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                CloseWindow();
                return;
            }
        }
 private void Setup(object parameter)
 {
     Views.SetupConnectionWindow setupWindow = new SetupConnectionWindow();
     setupWindow.ShowDialog();
 }