//This method manage the event that arrive on the Start Button private void Start_button_Click(object sender, RoutedEventArgs e) { if (configuration == null) { MessageBoxResult result = MessageBox.Show("We are sorry!\n" + "There was an error during the loading of the configuration\n" + "Do you want to restart the application?", "Restart the application", MessageBoxButton.YesNo); if (result == MessageBoxResult.No) { this.Close(); Environment.Exit(-1); } else { this.Hide(); MainWindow newMainWindow = new MainWindow(); newMainWindow.Show(); this.Close(); return; } } this.Hide(); //Start of the critical section in the middle of 2 window try { //Instantiation of the Statistic Window and closing this window Statistic_Window newStatisticWindow = new Statistic_Window(configuration, this.mode); newStatisticWindow.Show(); this.Close(); } catch (Exception ex) { //In case of exception I have to free the lockObject Console.WriteLine(ex.StackTrace); Console.WriteLine(ex.Message); MessageBox.Show("We are sorry!\n" + "An error occure in the critical section before the opening of the Statistic window!\n"); Environment.Exit(-1); } return; }
//--------------- This method manage the ok button click event ------------------------------------------- private void Ok_button_Click(object sender, RoutedEventArgs e) { //Here there is no need to do something because the value is saved in the attribute of the window if (mode == Features.Window_Mode.Load) { string nameConf = selectedValue; if (nameConf != null) { Configuration configuration = null; try { configuration = Configuration.LoadConfiguration(nameConf); } catch (Exception) { Handle_DB_Error(); } if (configuration == null) { MessageBoxResult result = MessageBox.Show("We are sorry!\n" + "There was an error during the load of the configuration\n" + "Do you want to restart the application?", "Restart the application", MessageBoxButton.YesNo); if (result == MessageBoxResult.No) { this.Close(); Environment.Exit(-1); } else { this.Hide(); MainWindow newMainWindow = new MainWindow(); newMainWindow.Show(); this.Close(); return; } } this.Hide(); //Start of the critical section in the middle of 2 window try { //Instantiation of the Statistic Window and closing this window Statistic_Window newStatisticWindow = new Statistic_Window(configuration, this.mode); newStatisticWindow.Show(); this.Close(); } catch (Exception ex) { //In case of exception I have to free the lockObject Console.WriteLine(ex.StackTrace); Console.WriteLine(ex.Message); MessageBox.Show("We are sorry!\n" + "An error occure in the critical section before the opening of the Statistic window!\n"); Environment.Exit(-1); } } } else if (mode == Features.Window_Mode.Modify) { string nameConf = selectedValue; if (nameConf != null) { Configuration configuration = null; //Retrive the configuration from the DB try { configuration = Configuration.LoadConfiguration(nameConf); } catch (Exception) { Handle_DB_Error(); } //Managing the case where the configuration is null if (configuration == null) { MessageBoxResult result = MessageBox.Show("We are sorry!\n" + "There was an error during the load of the configuration\n" + "Do you want to restart the application?", "Restart the application", MessageBoxButton.YesNo); if (result == MessageBoxResult.No) { this.Close(); Environment.Exit(-1); } else { this.Hide(); MainWindow newMainWindow = new MainWindow(); newMainWindow.Show(); this.Close(); return; } } //All is went good so let's go to the setup this.Hide(); Setup_Window modifyConfiguration = new Setup_Window(Features.Window_Mode.Modify, configuration); modifyConfiguration.Show(); this.Close(); return; } } else if (mode == Features.Window_Mode.Remove) { string configuration_to_remove = selectedValue; if (configuration_to_remove != null) { try { Configuration.RemoveConfiguration(configuration_to_remove); } catch (Exception) { Handle_DB_Error(); } this.Hide(); MainWindow mainWindow = new MainWindow(); mainWindow.Show(); this.Close(); return; } } }