public void ExperimentsUtilityTest()
 {
     ExperimentsUtility util = new ExperimentsUtility();
     daoExperiments dao = new daoExperiments();
     Experiments exp = new Experiments();
     exp.ID = 999999;
     exp.Alias = "UnitTest";
     exp.Title = "UnitTest";
     exp.SDate = DateTime.Now.ToShortDateString();
     exp.EDate = DateTime.Now.ToShortDateString();
     exp.Hypo = "UnitTest";
     util.SetExperiment(exp);
     exp = null;
     exp = util.Experiment;
     if (exp == null)
         Assert.Fail("Experiment was not set");
     else
     {
         exp.ID = 999999;
         exp.Alias = "UnitTest";
         exp.Title = "UnitTest";
         exp.SDate = DateTime.Now.ToShortDateString();
         exp.EDate = DateTime.Now.ToShortDateString();
         exp.Hypo = "UnitTest";
         util.SetExperiment(exp);
         if (util.Experiment.ID != 999999)
             Assert.Fail("Experiment ID is incorrect.  ID = " + exp.ID.ToString());
         else if (!util.Experiment.Alias.Equals("UnitTest"))
             Assert.Fail("Experiment Alias is incorrect");
         else if (!util.Experiment.Title.Equals("UnitTest"))
             Assert.Fail("Experiment Title is incorrect");
         else if (!util.Experiment.SDate.Equals(DateTime.Now.ToShortDateString()))
             Assert.Fail("Experiment start date is incorrect");
         else if (!util.Experiment.EDate.Equals(DateTime.Now.ToShortDateString()))
             Assert.Fail("Experiment end date is incorrect");
         else if (!util.Experiment.Hypo.Equals("UnitTest"))
             Assert.Fail("Experiment hypothesis is incorrect");
         else
             Assert.Pass("Experiment should set");
     }
 }
Пример #2
0
        public int insertRecord(Experiments e, bool bIsUnitTest)
        {
            int id = 0;
            NpgsqlCMD = new NpgsqlCommand();
            NpgsqlCMD.CommandText = @"
                                   Insert into experiments (EX_ID, EX_ALIAS, EX_TITLE, EX_SDATE, EX_EDATE, EX_HYPOTHESIS, ex_parent_id) 
                                   VALUES (nextval('experiments_id_seq'), :alias, :title, :sdate, :edate,:hypo,:parent)
                                   returning ex_id
                                   ";

            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("alias", NpgsqlDbType.Varchar));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("title", NpgsqlDbType.Varchar));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("sdate", NpgsqlDbType.Date));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("edate", NpgsqlDbType.Date));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("hypo", NpgsqlDbType.Text));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("parent", NpgsqlDbType.Integer));
            NpgsqlCMD.Parameters[0].Value = e.Alias;
            NpgsqlCMD.Parameters[1].Value = e.Title;
            NpgsqlCMD.Parameters[2].Value = Convert.ToDateTime(e.SDate);
            NpgsqlCMD.Parameters[3].Value = Convert.ToDateTime(e.EDate);
            NpgsqlCMD.Parameters[4].Value = e.Hypo;
            if (e.ParentEx > 0)
                NpgsqlCMD.Parameters[5].Value = e.ParentEx;
            else
                NpgsqlCMD.Parameters[5].Value = 0;

            NpgsqlParameter ExIDOutput = new NpgsqlParameter("id", NpgsqlDbType.Integer);
            ExIDOutput.Direction = ParameterDirection.Output;
            NpgsqlCMD.Parameters.Add(ExIDOutput);

            id = GlobalVariables.GlobalConnection.InsertDataAndGetID(NpgsqlCMD);

            if (id <= 0)
            {
                if(!bIsUnitTest)
                    MessageBox.Show("Error inserting experiment.", "Insert Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return 0;
            }
            else if(!bIsUnitTest)
                MessageBox.Show("Experiment successfully inserted.", "Picture Inserted", MessageBoxButtons.OK, MessageBoxIcon.Information);


            if (!bIsUnitTest)
            {
                if (GlobalVariables.ADUserName.ToUpper().Equals("JAMES"))
                    daoPermissions.insertPermissions(id, GlobalVariables.ADUserName, "Owner");
                else
                {
                    daoPermissions.insertPermissions(id, GlobalVariables.ADUserName, "Owner");
                    daoPermissions.insertPermissions(id, "James", "Admin");
                }
            }
            return id;
        }
 public void SetExperiment(Experiments Experiment)
 {
     GlobalVariables.Experiment = Experiment;
 }
Пример #4
0
        public void updateRecord(Experiments e, bool bIsUnitTest)
        { 
            NpgsqlCMD = new NpgsqlCommand();
            NpgsqlCMD.CommandText = @"Update experiments 
                              Set EX_ALIAS = :alias, 
                              EX_TITLE  = :title,
                              EX_SDATE  = :sdate,
                              EX_EDATE  = :edate,
                              EX_HYPOTHESIS  = :hypo,
                              EX_PARENT_ID = :parent
                              Where EX_ID = :exID";

            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("alias", NpgsqlDbType.Varchar));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("title", NpgsqlDbType.Varchar));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("sdate", NpgsqlDbType.Date));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("edate", NpgsqlDbType.Date));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("hypo", NpgsqlDbType.Text));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("exID", NpgsqlDbType.Integer));
            NpgsqlCMD.Parameters.Add(new NpgsqlParameter("parent", NpgsqlDbType.Integer));
            NpgsqlCMD.Parameters[0].Value = e.Alias;
            NpgsqlCMD.Parameters[1].Value = e.Title;
            NpgsqlCMD.Parameters[2].Value = Convert.ToDateTime(e.SDate);
            NpgsqlCMD.Parameters[3].Value = Convert.ToDateTime(e.EDate);
            NpgsqlCMD.Parameters[4].Value = e.Hypo;
            NpgsqlCMD.Parameters[5].Value = e.ID;
            if (e.ParentEx > 0)
                NpgsqlCMD.Parameters[6].Value = e.ParentEx;
            else
                NpgsqlCMD.Parameters[6].Value = e.ID;

            if (GlobalVariables.GlobalConnection.updateData(NpgsqlCMD) && !bIsUnitTest)
                MessageBox.Show("Experiment successfully updated.", "Data Updated", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else if(!bIsUnitTest)
                MessageBox.Show("Error updating experiment.", "Update Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
 public ExperimentsUtility()
 {
     Experiment = new Experiments();
 }