public bool AddNewConfig(CreateConfigInfo newConfigInfo) { VisDashboardDataDataContext db = new VisDashboardDataDataContext(); using (TransactionScope ts = new TransactionScope()) { try { Config newConfig = new Config { Name = newConfigInfo.Name, ExperimentID = newConfigInfo.ExperimentID }; db.Configs.InsertOnSubmit(newConfig); db.SubmitChanges(); } catch (SqlException e) { MessageBox.Show("Database Error: " + e.Message, "Config Creation Failed", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } finally { ts.Complete(); ts.Dispose(); db = null; } } return(true); }
public bool AddNewConfig(CreateConfigInfo newConfigInfo) { VisDashboardDataDataContext db = new VisDashboardDataDataContext(); using (TransactionScope ts = new TransactionScope()) { try { Config newConfig = new Config { Name = newConfigInfo.Name, ExperimentID = newConfigInfo.ExperimentID }; db.Configs.InsertOnSubmit(newConfig); db.SubmitChanges(); } catch (SqlException e) { MessageBox.Show("Database Error: " + e.Message, "Config Creation Failed", MessageBoxButton.OK, MessageBoxImage.Error); return false; } catch (Exception e) { Console.WriteLine(e.Message); return false; } finally { ts.Complete(); ts.Dispose(); db = null; } } return true; }
private void newConfMenuItem_Click(object sender, RoutedEventArgs e) { // Create new configuration information CreateConfigInfo newConfigInfo = new CreateConfigInfo(); if (experimentDataModel.CurExperiment == null) { return; } newConfigInfo.ExperimentID = experimentDataModel.CurExperiment.ExperimentID; // Instantiate the dialog box CreateConfigurationDialog dlg = new CreateConfigurationDialog(); // Configure the dialog box dlg.Owner = this; dlg.DataContext = newConfigInfo; // Open the dialog box modally dlg.ShowDialog(); // Process data entered by user if dialog box is accepted if (dlg.DialogResult == true) { // Try to add this new user to the database if (configDataModel.AddNewConfig(newConfigInfo)) { // Reload the Configurations configDataModel.LoadExperimentConfigs(experimentDataModel.CurExperiment); } } }