private void btnDeleteSelectedUser_Click(object sender, EventArgs e) { int id = Convert.ToInt32(dgvUsers.Rows[dgvUsers.CurrentCell.RowIndex].Cells[0].Value); string username = dgvUsers.Rows[dgvUsers.CurrentCell.RowIndex].Cells[1].Value.ToString(); DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this user?", "Confirm Delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) //delete the user if they confirm yes { if (rdoAdmins.Checked) //check for the type of user (admin,teacher,parent,student) { MathWizDB.DeleteUser("admin", id, username); } else if (rdoTeachers.Checked) { MathWizDB.DeleteUser("teacher", id, username); } else if (rdoParents.Checked) { MathWizDB.DeleteUser("parent", id, username); } else if (rdoStudents.Checked) { MathWizDB.DeleteUser("student", id, username); } lblDeleted.Text = username + " was deleted"; lblDeleted.Show(); btnRefresh_Click(null, null); } else if (dialogResult == DialogResult.No) { lblDeleted.Text = "Delete cancelled"; lblDeleted.Show(); } }
private void backgroundWorkerInsertData_DoWork(object sender, DoWorkEventArgs e) { switch (this.Tag.ToString()) { case "Admin": Admin newAdmin = new Admin(username, firstName, lastName, password); MathWizDB.InsertAdmin(newAdmin); break; case "Teacher": Teacher newTeacher = new Teacher(username, firstName, lastName, password); MathWizDB.InsertTeacher(newTeacher); break; case "Parent": Parent newParent = new Parent(username, firstName, lastName, password); MathWizDB.InsertParent(newParent); break; case "Student": Student newStudent = new Student(username, firstName, lastName, password); MathWizDB.InsertStudent(newStudent, parentID, klassID); break; } }
private void btnDeleteTest_Click(object sender, EventArgs e) { int testID = Convert.ToInt32(dgvTests.Rows[dgvTests.CurrentCell.RowIndex].Cells[0].Value); int gradedTestID; DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this test?", "Confirm Delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) //delete the test if they confirm yes { // Grab the graded_test id with the test id (I'm assuming/hoping that testid is unique with this select) gradedTestID = MathWizDA.SelectGradedTestIDViaTestID(testID); //Delete the Graded Questions with the Graded Test ID MathWizDB.DeleteGradedQuestions(gradedTestID); //Delete the actual Graded Test with the Standard Test ID MathWizDB.DeleteGradedTestWithTestID(testID); //Delete Normal Questions with the Standard Test ID MathWizDB.DeleteNormalQuestions(testID); //Finally, delete the normal standard test MathWizDB.DeleteNormalTest(testID); } }
//Thread for saving the graded test (and sometimes the practice test void backgroundWorkerSaveTest_DoWork(object sender, DoWorkEventArgs e) { switch (this.Tag.ToString()) { case "placement": //just insert the graded test MathWizDB.InsertGradedTest(gradedPlacementTest, student.Id, gradedPlacementTest.PlacementTest.Id, "Placement Test", gradedPlacementTest.RecommendedLevel); //update student's mastery level MathWizDB.UpdateMasteryLevel(student.Username, gradedPlacementTest.RecommendedLevel); break; case "practice": //first insert the test since the teacher did not make it, but the student just generated it gradedPracticeTest.PracticeTest.Id = MathWizDB.InsertTest(klass.Id, gradedPracticeTest.PracticeTest, "Practice Test", 0, gradedPracticeTest.PracticeTest.MinLevel, gradedPracticeTest.PracticeTest.MaxLevel); //then insert the graded test. The insertGradedTest method also inserts the graded Questions gradedPracticeTest.Id = MathWizDB.InsertGradedTest(gradedPracticeTest, student.Id, gradedPracticeTest.PracticeTest.Id, "Practice Test"); break; case "mastery": //just insert the graded test MathWizDB.InsertGradedTest(gradedMasteryTest, student.Id, gradedMasteryTest.MasteryTest.Id, "Mastery Test", 0, 1, gradedMasteryTest.Passed); break; } }
private void btnChange_Click(object sender, EventArgs e) { if (Validation.IsInteger(txtNewMasteryLevel) && Validation.IsWithinRangeInclusive(txtNewMasteryLevel, 12, 0)) { int newML = Convert.ToInt32(txtNewMasteryLevel.Text); MathWizDB.UpdateMasteryLevel(username, newML); this.Close(); } }
public static int InsertTest(int klassID, Test test, string testType, decimal passThreshold, int minLevel, int maxLevel) { test.Id = 0; //Everything besides TestType can be null string insertStatement = "INSERT INTO tests (KlassID, TestType, TimeLimit, RandomlyGenerated, PassThreshHold, MinLevel, MaxLevel)" + " OUTPUT INSERTED.Id" //get the last inserted ID + " VALUES(@KlassID, @Type, @TimeLimit, @RNG, @PassThreshold, @MinLevel, @MaxLevel)"; // create command object with SQL query and link to connection object SqlCommand Cmd = new SqlCommand(insertStatement, conn); // create your parameters and add values from object Cmd.Parameters.AddWithValue("@KlassID", klassID); Cmd.Parameters.AddWithValue("@Type", testType); Cmd.Parameters.AddWithValue("@TimeLimit", test.TimeLimit); Cmd.Parameters.AddWithValue("@RNG", test.RandomlyGenerated); Cmd.Parameters.AddWithValue("@PassThreshold", passThreshold); Cmd.Parameters.AddWithValue("@MinLevel", minLevel); Cmd.Parameters.AddWithValue("@MaxLevel", maxLevel); try { // Open the connection conn.Open(); // execute the query test.Id = Convert.ToInt32(Cmd.ExecuteScalar()); if (conn != null && conn.State == ConnectionState.Open) { conn.Close(); } //now insert the questions in the test for (int i = 0; i < test.Questions.Count; i++) { test.Questions[i].Id = MathWizDB.InsertQuestion(test.Questions[i], test.Id); } } catch (SqlException ex) { MessageBox.Show(ex.Message); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (conn != null && conn.State == ConnectionState.Open) { conn.Close(); } } return(test.Id); }
private void btnCreateTest_Click(object sender, EventArgs e) { btnCreateTest.Text = "Creating Test"; btnCreateTest.Enabled = false; //if form validation is good then if (ValidateForm()) { int numberOfQuestions = Convert.ToInt32(cboNumberOfQuestions.SelectedItem); int numberOfQuestionsPerML = numberOfQuestions / 12; //take a few questions from each mastery level TimeSpan questionTimeLimit = new TimeSpan(0, 1, 0); PlacementTest placementTest = new PlacementTest(); for (int ml = 1; ml <= 12; ml++) //get questions from each mastery level { //make custom timelimits for each question depending on complexity questionTimeLimit = CalculateQuestionTimeLimit(cboQuestionSpeed.SelectedItem.ToString(), ml); //get the questions for just the current mastery level in this for loop List <Question> tempQuestionList = Question.GenerateRandomQuestions(ml, questionTimeLimit, numberOfQuestionsPerML); foreach (Question q in tempQuestionList) //add current mastery level questions to the actual placement test { placementTest.Questions.Add(q); } } //set other attributes of the test placementTest.MinLevel = 1; placementTest.MaxLevel = 12; placementTest.TimeLimit = TimeSpan.FromTicks(questionTimeLimit.Ticks * numberOfQuestions); //insert it placementTest.Id = MathWizDB.InsertTest(klassID, placementTest, "Placement Test", 0, placementTest.MinLevel, placementTest.MaxLevel); this.Close(); if (placementTest.Id > 0) { MessageBox.Show("Your new randomly generated Placement test has been created"); } else { MessageBox.Show("Failed to create placement test", "error"); } } else { MessageBox.Show("A placement test has already been created for this class.", "error"); } btnCreateTest.Text = "Create Test"; btnCreateTest.Enabled = true; }
//Delete Student Button private void button2_Click(object sender, EventArgs e) { int id = Convert.ToInt32(dgvStudents.Rows[dgvStudents.CurrentCell.RowIndex].Cells[0].Value); string username = dgvStudents.Rows[dgvStudents.CurrentCell.RowIndex].Cells[1].Value.ToString(); DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this student?", "Confirm Delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) //delete the user if they confirm yes { MathWizDB.DeleteUser("student", id, username); } }
private void backgroundWorkerUpdatePassword_DoWork(object sender, DoWorkEventArgs e) { string userType = MathWizDA.FindUserType(username_G); switch (userType) { case "admin": user = new Admin(); break; case "teacher": user = new Teacher(); break; case "parent": user = new Parent(); break; case "student": user = new Student(); break; } string passwordHash = user.HashPassword(txtNewPassword.Text); MathWizDB.UpdatePassword(userType, username_G, passwordHash); }
private void btnCreateClass_Click(object sender, EventArgs e) { if (txtClassName.Text != "" && cmbTeacher.SelectedIndex != -1) { string klassName = txtClassName.Text; int teacherID = allTeachers[cmbTeacher.SelectedIndex].Id; Klass newKlass = new Klass(klassName); MathWizDB.InsertKlass(newKlass, teacherID); lblAdded.Text = newKlass.KlassName + " was successfully added"; lblAdded.Show(); } else { MessageBox.Show("Class Name and Teacher are required"); } }
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; }
//MARK Button Handlers private void btnStartFinish_Click(object sender, EventArgs e) { if (btnStartFinish.Text == "Start Test") //start test, show the first question { testFinished = false; btnStartFinish.Text = "Finish Test"; btnStartFinish.Hide(); gbxQuestion.Show(); currentQuestionNum = 0; //array starts at 0 timerTest.Start(); switch (this.Tag.ToString()) { case "placement": ShowQuestion(gradedPlacementTest.PlacementTest.Questions[currentQuestionNum]); break; case "practice": ShowQuestion(gradedPracticeTest.PracticeTest.Questions[currentQuestionNum]); break; case "mastery": ShowQuestion(gradedMasteryTest.MasteryTest.Questions[currentQuestionNum]); break; } } else if (btnStartFinish.Text == "Finish Test") //finish test, record score, write score to db { switch (this.Tag.ToString()) //record information for the completed test { case "placement": gradedPlacementTest.Score = (decimal)gradedPlacementTest.CorrectlyAnsweredQuestions.Count / (decimal)(gradedPlacementTest.CorrectlyAnsweredQuestions.Count + (decimal)gradedPlacementTest.WronglyAnsweredQuestions.Count) * 100; gradedPlacementTest.TimeTakenToComplete = gradedPlacementTest.PlacementTest.TimeLimit - TimeSpan.ParseExact(lblTimerTest.Text, "mm\\:ss", CultureInfo.InvariantCulture); gradedPlacementTest.DateTaken = DateTime.Now; gradedPlacementTest.Feedback = gradedPlacementTest.Score.ToString(); int minLevelWrong = 12; for (int i = 0; i < gradedPlacementTest.WronglyAnsweredQuestions.Count; i++) { if (gradedPlacementTest.WronglyAnsweredQuestions[i].Question.MasteryLevel < minLevelWrong) { minLevelWrong = gradedPlacementTest.WronglyAnsweredQuestions[i].Question.MasteryLevel; } } gradedPlacementTest.RecommendedLevel = minLevelWrong; MessageBox.Show("You have been placed at Mastery Level: " + gradedPlacementTest.RecommendedLevel.ToString() + "\nYour Score was: " + gradedPlacementTest.Score.ToString("###.##")); break; case "practice": gradedPracticeTest.Score = (decimal)gradedPracticeTest.CorrectlyAnsweredQuestions.Count / (decimal)(gradedPracticeTest.CorrectlyAnsweredQuestions.Count + (decimal)gradedPracticeTest.WronglyAnsweredQuestions.Count) * 100; gradedPracticeTest.TimeTakenToComplete = gradedPracticeTest.PracticeTest.TimeLimit - TimeSpan.ParseExact(lblTimerTest.Text, "mm\\:ss", CultureInfo.InvariantCulture); gradedPracticeTest.DateTaken = DateTime.Now; gradedPracticeTest.Feedback = gradedPracticeTest.Score.ToString(); MessageBox.Show("Your Score was: " + gradedPracticeTest.Score.ToString()); break; case "mastery": gradedMasteryTest.Score = (decimal)gradedMasteryTest.CorrectlyAnsweredQuestions.Count / (decimal)(gradedMasteryTest.CorrectlyAnsweredQuestions.Count + (decimal)gradedMasteryTest.WronglyAnsweredQuestions.Count) * 100; gradedMasteryTest.TimeTakenToComplete = gradedMasteryTest.MasteryTest.TimeLimit - TimeSpan.ParseExact(lblTimerTest.Text, "mm\\:ss", CultureInfo.InvariantCulture); gradedMasteryTest.DateTaken = DateTime.Now; gradedMasteryTest.Feedback = gradedMasteryTest.Score.ToString(); if (gradedMasteryTest.Score > gradedMasteryTest.MasteryTest.PassThreshhold) //determine whether they passed or not. { gradedMasteryTest.Passed = true; MathWizDB.UpdateMasteryLevel(student.Username, ++student.MasteryLevel); //bump the master level up MessageBox.Show("You scored " + gradedMasteryTest.Score.ToString("###.##") + " and have now passed to level " + student.MasteryLevel); } else { gradedMasteryTest.Passed = false; MessageBox.Show("You scored " + gradedMasteryTest.Score.ToString("###.##") + " and will need to take this test again"); } break; } //write test to database in another thread backgroundWorkerSaveTest.RunWorkerAsync(); } }