//This method checks to see if password and username input from each textbox matches password and username data stored in the LecturerLogin table of the application database. public void LoginLecturer() { ModelRegisterLogin lect = new ModelRegisterLogin(); //Generic collections List <T> is used to hold all the lecturer login details for processing. The list is instantiated using a method that retrieves all the login details from the application database, LecturerLogin. List <ModelRegisterLogin> list = cl.GetAllFromLecturerLogin(connectionString); //A lambda expression combined with a try catch is used to determines if the users username input taken from the login texbox matchs any username objects of the Model Class ModelRegisterLogin - this Model Class holds properties for both the lecturer and student user types. try { lect = list.Find((ModelRegisterLogin x) => x.LECT_USERNAME == Int32.Parse(tbUsernameLog.Text)); //The lambda expression above checks if any dataabase username data matches the user input from the username texbox. if (lect.LECT_USERNAME.ToString().Equals(tbUsernameLog.Text) && lect.LECT_PASSWORD.ToString().Equals(tbPasswordLog.Password)) { MessageBox.Show("Login Successful !\nWelcome LECTURER " + lect.LECT_USERNAME.ToString()); ; MainMenuLecturer mml = new MainMenuLecturer(Int32.Parse(tbUsernameLog.Text)); mml.Show(); this.Close(); } else { //if a username is found but the password doesnt match then this message will be displayed to the user MessageBox.Show("Incorrect username or password\nPlease recheck your credentials and try again", "Error"); tbUsernameLog.Text = ""; tbPasswordLog.Password = ""; } } catch (System.Exception) { //If no username match is found the application will throw an error which indicates that no such data with in the database matches that of the user data. //If this is so then the application displays the following message. MessageBox.Show("Incorrect username or password\nPlease recheck your credentials and try again", "Error"); tbUsernameLog.Text = ""; tbPasswordLog.Password = ""; } }
//This button click event returns the user to the lecturer dashboard private void BtMainMenu_Click(object sender, RoutedEventArgs e) { MainMenuLecturer mml = new MainMenuLecturer(currentUser); mml.Show(); this.Close(); }
public void LoginLecturer() { ModelRegisterLogin lect = new ModelRegisterLogin(); List <ModelRegisterLogin> list = cl.GetAllFromLecturerLogin(connectionString); try { lect = list.Find((ModelRegisterLogin x) => x.LECT_USERNAME == tbUsernameLog.Text); if (lect.LECT_USERNAME.ToString().Equals(tbUsernameLog.Text) && lect.LECT_PASSWORD.ToString().Equals(tbPasswordLog.Password)) { MessageBox.Show("Login Successful !,\n Welcome LECTURER " + lect.LECT_USERNAME.ToString()); MainMenuLecturer mml = new MainMenuLecturer(); mml.Show(); this.Close(); } else { MessageBox.Show("Incorrect username or password\nPlease recheck your credentials and try again", "Error"); tbUsernameLog.Text = ""; tbPasswordLog.Password = ""; } } catch (System.Exception) { MessageBox.Show("Incorrect username or password\nPlease recheck your credentials and try again", "Error"); tbUsernameLog.Text = ""; tbPasswordLog.Password = ""; } }
//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(); }