public void LoginStudent() { ModelRegisterLogin stud = new ModelRegisterLogin(); List <ModelRegisterLogin> list = cl.GetAllFromStudentLogin(connectionString); try { stud = list.Find((ModelRegisterLogin x) => x.STUD_USERNAME == Int32.Parse(tbUsername.Text)); if (stud.STUD_USERNAME.ToString().Equals(tbUsername.Text) && stud.STUD_PASSWORD.ToString().Equals(tbPassword.Text)) { Response.Redirect("~/PortalHome.aspx"); return; } } catch (System.Exception) { lbNotify.Text = "Incorrect username or password. Please recheck your credentials and try again"; tbUsername.Text = ""; tbPassword.Text = ""; } lbNotify.Text = "Incorrect username or password. Please recheck your credentials and try again"; tbUsername.Text = ""; tbPassword.Text = ""; }
//This method inputs new user data into the database. public void RegisterNewLecturer() { //a try catch is used to determine if database username data matches the users input. If the pk constraint throws an error it signals that a username with the same name already exists and reflects this to the user in a message. try { var login = Int32.Parse(tbUsername.Text); var password = tbPassword.Password; var fName = tbFName.Text; var lName = tbLName.Text; var c = new ModelRegisterLogin { LECT_USERNAME = login, LECT_PASSWORD = password, LECT_FNAME = fName, LECT_LNAME = lName }; //The InsertLecturerRegData method from thr data access layer ddl performs a sql query that inserts the user input into the LecturerLogin table within the application database. cl.InsertLecturerRegData(c, connectionString); MessageBox.Show($"Registration Successful!" + "\nYou may now Login LECTURER " + tbUsername.Text + " !"); tabLoginRegister.SelectedIndex = 1; } catch (System.Exception) { MessageBox.Show("User already exists or the input for LECTURER NUMBER is not a number\nPlease try again", "Error"); tbUsername.Text = ""; tbPassword.Password = ""; } }
public void InsertUserRegData(ModelRegisterLogin user, string cs) { using (IDbConnection cnn = new SQLiteConnection(cs)) { var cmd = cnn.Query <ModelRegisterLogin>("Insert Into USER(USER_LIBRARY_CARD_ID, USER_PASSWORD,USER_FNAME,USER_LNAME) Values" + $"('{user.USER_LIBRARY_CARD_ID}','{user.USER_PASSWORD}','{user.USER_FNAME}','{user.USER_LNAME}')", new DynamicParameters()); } }
//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 = ""; } }
//Does the same as the above method but for the student user type public void LoginStudent() { ModelRegisterLogin stud = new ModelRegisterLogin(); List <ModelRegisterLogin> list = cl.GetAllFromStudentLogin(connectionString); try { stud = list.Find((ModelRegisterLogin x) => x.STUD_USERNAME == Int32.Parse(tbUsernameLog.Text)); if (stud.STUD_USERNAME.ToString().Equals(tbUsernameLog.Text) && stud.STUD_PASSWORD.ToString().Equals(tbPasswordLog.Password)) { MessageBox.Show("Login Successful !\nWelcome STUDENT " + stud.STUD_USERNAME.ToString()); MainMenuStudent ms = new MainMenuStudent(Int32.Parse(tbUsernameLog.Text)); ms.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 = ""; } }
public void RegisterNewLecturer() { try { var login = tbUsername.Text; var password = tbPassword.Password; var c = new ModelRegisterLogin { LECT_USERNAME = login, LECT_PASSWORD = password }; cl.InsertLecturerRegData(c, connectionString); MessageBox.Show($"Registration Successful!" + "\nYou may now Login, LECTURER " + tbUsername.Text + " !"); tabLoginRegister.SelectedIndex = 1; } catch (System.Exception) { MessageBox.Show("User already exists\nPlease try again", "Error"); tbUsername.Text = ""; tbPassword.Password = ""; } }
//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 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 = ""; } }
public void InsertStudentRegData(ModelRegisterLogin student, string cs) { using (IDbConnection cnn = new SQLiteConnection(cs)) { var cmd = cnn.Query <ModelRegisterLogin>("Insert Into STUDENT_LOGIN(STUD_USERNAME, STUD_PASSWORD,STUD_FNAME,STUD_LNAME) Values" + $"('{student.STUD_USERNAME}','{student.STUD_PASSWORD}','{student.STUD_FNAME}','{student.STUD_LNAME}')", new DynamicParameters()); } }
public void InsertLecturerRegData(ModelRegisterLogin lecturer, string cs) { using (IDbConnection cnn = new SQLiteConnection(cs)) { var cmd = cnn.Query <ModelRegisterLogin>("Insert Into LECTURER_LOGIN(LECT_USERNAME, LECT_PASSWORD,LECT_FNAME,LECT_LNAME) Values" + $"('{lecturer.LECT_USERNAME}','{lecturer.LECT_PASSWORD}','{lecturer.LECT_FNAME}','{lecturer.LECT_LNAME}')", new DynamicParameters()); } }
//This method inputs new user data into the database public void RegisterNewUser() { LearningGames lg = new LearningGames(); try { var login = Int32.Parse(tbUsername.Text); var password = tbPassword.Password; var fName = tbFName.Text; var lName = tbLName.Text; var c = new ModelRegisterLogin { USER_LIBRARY_CARD_ID = login, USER_PASSWORD = password, USER_FNAME = fName, USER_LNAME = lName }; cl.InsertUserRegData(c, connectionString); var ml = new ModelLeaderBoard { USER_LIBRARY_CARD_ID = login, REPLACING_BOOKS_PERSONAL_BEST = "Not Set", IDENTIFYING_AREAS_PERSONAL_BEST = 0, FINDING_CALL_NUMBERS_PERSONAL_BEST = 0 }; lg.InsertNewBlankLeaderboardRecord(ml, connectionString); MessageBox.Show($"Registration Successful!" + "\nYou may now Login, " + tbFName.Text + " !"); tabLoginRegister.SelectedIndex = 1; } catch (System.Exception) { MessageBox.Show("User already exists or the input for LIBRARY CARD ID is not a number\nPlease try again", "Error"); tbUsername.Text = ""; tbPassword.Password = ""; } }
//This method checks to see if password and username input from each textbox matches password and username data stored in the USER table in the application database. public void LoginUser() { ModelRegisterLogin user = new ModelRegisterLogin(); List <ModelRegisterLogin> list = cl.GetAllFromUser(connectionString); try { user = list.Find((ModelRegisterLogin x) => x.USER_LIBRARY_CARD_ID == Int32.Parse(tbUsernameLog.Text)); if (user == null) { MessageBox.Show("Incorrect username or password\nPlease recheck your credentials and try again", "Error"); tbUsernameLog.Text = ""; tbPasswordLog.Password = ""; } else if (user.USER_LIBRARY_CARD_ID.ToString().Equals(tbUsernameLog.Text) && user.USER_PASSWORD.ToString().Equals(tbPasswordLog.Password)) { MessageBox.Show("Login Successful !\nWelcome " + user.USER_FNAME.ToString()); MainMenu mm = new MainMenu(Int32.Parse(tbUsernameLog.Text)); mm.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 = ""; } }