Exemplo n.º 1
0
        public bool AddNewExperiment(CreateExperimentInfo newExperimentInfo)
        {
            VisDashboardDataDataContext db = new VisDashboardDataDataContext();

            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    Experiment newExperiment = new Experiment
                    {
                        Name      = newExperimentInfo.Name,
                        CreatorID = newExperimentInfo.CreatorID
                    };

                    db.Experiments.InsertOnSubmit(newExperiment);
                    db.SubmitChanges();
                }
                catch (SqlException e)
                {
                    MessageBox.Show("Database Error: " + e.Message, "Experiment 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);
        }
Exemplo n.º 2
0
        public bool AddNewExperiment(CreateExperimentInfo newExperimentInfo)
        {
            VisDashboardDataDataContext db = new VisDashboardDataDataContext();

            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    Experiment newExperiment = new Experiment
                    {
                        Name = newExperimentInfo.Name,
                        CreatorID = newExperimentInfo.CreatorID
                    };

                    db.Experiments.InsertOnSubmit(newExperiment);
                    db.SubmitChanges();
                }
                catch (SqlException e)
                {
                    MessageBox.Show("Database Error: " + e.Message, "Experiment 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;
        }
Exemplo n.º 3
0
        private void newExpMenuItem_Click(object sender, RoutedEventArgs e)
        {
            // Create new experiment information
            CreateExperimentInfo newExperimentInfo = new CreateExperimentInfo();
            newExperimentInfo.CreatorID = userDataModel.User.UserID;

            // Instantiate the dialog box
            CreateExperimentDialog dlg = new CreateExperimentDialog();

            // Configure the dialog box
            dlg.Owner = this;
            dlg.DataContext = newExperimentInfo;

            // 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 (experimentDataModel.AddNewExperiment(newExperimentInfo))
                {
                    // Reload the experiments
                    experimentDataModel.LoadUserExperiments(userDataModel.User);
                }
            }
        }