Example #1
0
        public static List <MasteryTest> SelectKlassesMasteryTests(int klassID)
        {
            List <MasteryTest> masteryTests = new List <MasteryTest>();

            //make the query the safe way by binding values to prevent SQL injection
            string     query         = "SELECT * FROM tests WHERE KlassID = @klassID AND TestType = 'Mastery Test'";
            SqlCommand selectCommand = new SqlCommand(query, conn);

            selectCommand.Parameters.AddWithValue("@klassID", klassID);

            try
            {
                conn.Open();

                SqlDataReader reader = selectCommand.ExecuteReader();

                while (reader.Read())
                {
                    MasteryTest masteryTest = new MasteryTest();

                    masteryTest.Id                = Convert.ToInt32(reader["Id"]);
                    masteryTest.TimeLimit         = TimeSpan.ParseExact(reader["TimeLimit"].ToString(), "hh\\:mm\\:ss", CultureInfo.InvariantCulture);
                    masteryTest.RandomlyGenerated = Convert.ToBoolean(reader["RandomlyGenerated"]);
                    masteryTest.MasteryLevel      = Convert.ToInt32(reader["MinLevel"]);

                    masteryTests.Add(masteryTest);
                }
                reader.Close();

                foreach (MasteryTest m in masteryTests) //add the questions to the test objects
                {
                    m.Questions = SelectQuestions(m.Id);
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show("Database SQL Exception\n\n" + ex.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show("Generic Exception.\n\n" + ex.ToString());
            }
            finally
            {
                if (conn != null && conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            return(masteryTests);
        }
Example #2
0
        private void btnGenerateTests_Click(object sender, EventArgs e)
        {
            btnGenerateTests.Text    = "Generating Tests";
            btnGenerateTests.Enabled = false;

            for (int ml = 1; ml <= 12; ml++)
            {
                MasteryTest masteryTest = new MasteryTest();
                int         numberOfQuestions;
                TimeSpan    questionTimeLimit = new TimeSpan(0, 1, 0);
                TimeSpan    testTimeLimit     = new TimeSpan(1, 0, 0);
                decimal     passThreshhold    = 1;

                numberOfQuestions = Convert.ToInt32(cboNumberOfQuestions.SelectedItem);


                switch (cboQuestionSpeed.SelectedItem.ToString())
                {
                case "Slow":

                    if (ml >= 1 && ml <= 3)
                    {
                        questionTimeLimit = new TimeSpan(0, 0, 45);
                    }
                    else if (ml >= 4 && ml <= 6)
                    {
                        questionTimeLimit = new TimeSpan(0, 1, 0);
                    }
                    else if (ml >= 7 && ml <= 9)
                    {
                        questionTimeLimit = new TimeSpan(0, 0, 45);
                    }
                    else if (ml >= 10 && ml <= 12)
                    {
                        questionTimeLimit = new TimeSpan(0, 3, 0);
                    }

                    break;

                case "Medium":

                    if (ml >= 1 && ml <= 3)
                    {
                        questionTimeLimit = new TimeSpan(0, 0, 30);
                    }
                    else if (ml >= 4 && ml <= 6)
                    {
                        questionTimeLimit = new TimeSpan(0, 0, 45);
                    }
                    else if (ml >= 7 && ml <= 9)
                    {
                        questionTimeLimit = new TimeSpan(0, 0, 30);
                    }
                    else if (ml >= 10 && ml <= 12)
                    {
                        questionTimeLimit = new TimeSpan(0, 2, 0);
                    }

                    break;

                case "Fast":

                    if (ml >= 1 && ml <= 3)
                    {
                        questionTimeLimit = new TimeSpan(0, 0, 15);
                    }
                    else if (ml >= 4 && ml <= 6)
                    {
                        questionTimeLimit = new TimeSpan(0, 0, 30);
                    }
                    else if (ml >= 7 && ml <= 9)
                    {
                        questionTimeLimit = new TimeSpan(0, 0, 15);
                    }
                    else if (ml >= 10 && ml <= 12)
                    {
                        questionTimeLimit = new TimeSpan(0, 1, 0);
                    }

                    break;
                }

                switch (cboPassThreshhold.SelectedItem.ToString())
                {
                case "70%":

                    passThreshhold = .7m;

                    break;

                case "80%":

                    passThreshhold = .8m;

                    break;

                case "90%":

                    passThreshhold = .9m;

                    break;

                case "95%":

                    passThreshhold = .95m;

                    break;

                case "100%":

                    passThreshhold = 1m;

                    break;
                }

                masteryTest.MasteryLevel      = ml;
                masteryTest.Questions         = Question.GenerateRandomQuestions(ml, questionTimeLimit, numberOfQuestions);
                masteryTest.TimeLimit         = TimeSpan.FromTicks(questionTimeLimit.Ticks * numberOfQuestions);
                masteryTest.PassThreshhold    = passThreshhold;
                masteryTest.RandomlyGenerated = true;

                MathWizDB.InsertTest(klassID, masteryTest, "Mastery Test", masteryTest.PassThreshhold, masteryTest.MasteryLevel, masteryTest.MasteryLevel);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }

            btnGenerateTests.Text    = "Generate Tests";
            btnGenerateTests.Enabled = false;
        }
Example #3
0
 //full constructor
 public GradedMasteryTest(MasteryTest masteryTest, bool passed, int numberAttempts, decimal score, TimeSpan timeTakenToComplete, DateTime dateTaken, List <GradedQuestion> rightlyAnsweredQuestions, List <GradedQuestion> wronglyAnsweredQuestions, string feedback = "") : base(score, timeTakenToComplete, dateTaken, rightlyAnsweredQuestions, wronglyAnsweredQuestions, feedback)
 {
     this.MasteryTest    = masteryTest;
     this.Passed         = passed;
     this.NumberAttempts = numberAttempts;
 }