//Does the same as the above method but for the student user type public void RegisterNewStudent() { try { var login = Int32.Parse(tbUsername.Text); var password = tbPassword.Password; var fName = tbFName.Text; var lName = tbLName.Text; var c = new ModelRegisterLogin { STUD_USERNAME = login, STUD_PASSWORD = password, STUD_FNAME = fName, STUD_LNAME = lName }; cl.InsertStudentRegData(c, connectionString); TestOp to = new TestOp(); List <ModelTest> Tests = new List <ModelTest>(); List <string> testToDo = new List <string>(); Tests = to.GetAllTests(connectionString); foreach (var test in Tests) { if (!testToDo.Contains(test.Test_Name)) { testToDo.Add(test.Test_Name); } } TestResult tr = new TestResult(); foreach (var test in testToDo) { var tName = test; var tEntry = new ModelStudentResult { STUD_USERNAME = login, STUD_FNAME = fName, STUD_LNAME = lName, TEST_NAME = test, TEST_RESULT = "Test not done" }; tr.InsertTestToBeTaken(tEntry, connectionString); } MessageBox.Show($"Registration Successful!" + "\nYou may now Login, STUDENT " + tbUsername.Text + " !"); tabLoginRegister.SelectedIndex = 1; } catch (System.Exception) { MessageBox.Show("User already exists or the input for STUDENT NUMBER is not a number\nPlease try again", "Error"); tbUsername.Text = ""; tbPassword.Password = ""; } }
public void UpdateStudentResult(ModelStudentResult sr, string cs) { using (IDbConnection cnn = new SQLiteConnection(cs)) { var cmd = cnn.Query <ModelStudentResult>("Update STUDENT_RESULT set TEST_RESULT = '" + sr.TEST_RESULT + "' where STUD_USERNAME = '******' and TEST_NAME = '" + sr.TEST_NAME + "'", new DynamicParameters()); } }
public void InsertTestToBeTaken(ModelStudentResult sr, string cs) { using (IDbConnection cnn = new SQLiteConnection(cs)) { var cmd = cnn.Query <ModelStudentResult>("Insert Into STUDENT_RESULT(STUD_USERNAME,STUD_FNAME,STUD_LNAME,TEST_NAME,TEST_RESULT)Values" + $"('{sr.STUD_USERNAME}','{sr.STUD_FNAME}','{sr.STUD_LNAME}','{sr.TEST_NAME}','{sr.TEST_RESULT}')", new DynamicParameters()); } }
public void SaveResult(int user, string test, double mark) { var username = user; var result = mark.ToString(); var testName = test; try { var r = new ModelStudentResult { STUD_USERNAME = user, TEST_NAME = testName, TEST_RESULT = result }; tr.UpdateStudentResult(r, connectionString); } catch (Exception) { MessageBox.Show("Update Failed"); } }
//this method uses a List <T> of the type MultipleChoice to load data into the Test table through a ModelTest object public void SubmitTestToDb() { int i = 1; foreach (var mTest in CurrentTestQuestions) { var testName = mTest.Name; var questionNumber = i; var question = mTest.Question; var optionA = mTest.OptionA; var optionB = mTest.OptionB; var optionC = mTest.OptionC; var optionD = mTest.OptionD; var correctAnswer = mTest.CorrectAnswer; var newTest = new ModelTest { Test_Name = testName, QuestionNumber = questionNumber, Test_Question = question, Option_A = optionA, Option_B = optionB, Option_C = optionC, Option_D = optionD, Correct_Answer = correctAnswer }; mt.InsertNewTest(newTest, connectionString); i++; } List <ModelRegisterLogin> students = rl.GetAllFromStudentLogin(connectionString); foreach (var student in students) { var username = student.STUD_USERNAME; var fName = student.STUD_FNAME; var lName = student.STUD_LNAME; var tName = lbShowTestName.Content.ToString(); var tEntry = new ModelStudentResult { STUD_USERNAME = username, STUD_FNAME = fName, STUD_LNAME = lName, TEST_NAME = tName, TEST_RESULT = "Test not done" }; tr.InsertTestToBeTaken(tEntry, connectionString); } MessageBox.Show("Test " + lbShowTestName.Content + " was submitted successfully\nStudents may now take it!", "Test Saved Successfully"); MainMenuLecturer mml = new MainMenuLecturer(currentUser); mml.Show(); this.Hide(); }