private void btnSignIn_Click(object sender, EventArgs e) { string username = txtUsername.Text; string password = txtPassword.Text; if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password)) //make sure both fields are filled in { MessageBox.Show("Please enter in both a username and password."); } else if (isValidUser(username, password)) //checks to see if the account is valid { if (username.Contains('?')) //usernames can't contain '?' { lblErrMsg.Text = "Invalid Username or Password. Try again."; } else { string accType = getAccType(username); int accID = getID(username); //lblErrMsg.Text = accType + accID.ToString(); switch (accType) { case "Student": //send ID to student form StudentMain a = new StudentMain(accID); a.Show(); this.Hide(); break; case "Faculty": //send ID to faculty form FacultyMain g = new FacultyMain(accID); g.Show(); this.Hide(); break; default: //Admin account //open admin form (shouldn't need ID?) AdminMain f = new AdminMain(); f.Show(); this.Hide(); break; } } } else { lblErrMsg.Text = "Invalid Username or Password. Try again."; } }
private void btnExit_Click(object sender, EventArgs e) //sends you back to the correct form { if (action == REQUEST) { Login g = new Login(); g.Show(); this.Dispose(); } else { AdminMain g = new AdminMain(); g.Show(); this.Dispose(); } }
private void CreateStudent_FormClosed(object sender, FormClosedEventArgs e) //send you back to the correct form { if (action == REQUEST) { Login g = new Login(); g.Show(); this.Dispose(); } else { AdminMain g = new AdminMain(); g.Show(); this.Dispose(); } }
private void backToMain(string accountType) { //check the user's accountType and use that to take them to the right main form if (accountType == "Student") { StudentMain g = new StudentMain(id); g.Show(); this.Dispose(); } else if (accountType == "Faculty") { FacultyMain g = new FacultyMain(id); g.Show(); this.Dispose(); } else if (accountType == "Administrator") { AdminMain g = new AdminMain(); g.Show(); this.Dispose(); } }
private void btnAdd_Click(object sender, EventArgs e) { string fname = txtFirstname.Text; //gets information from the form fields string lname = txtLastname.Text; string username = txtUsername.Text; string password = txtPassword.Text; string phone = txtPhoneNumber.Text; string email = txtEmail.Text; string accounttype = "Student"; bool tutor = cbxTutor.Checked; bool tutee = cbxTutee.Checked; TutorMasterDBEntities4 db = new TutorMasterDBEntities4(); if (goodToAdd(fname, lname, username, password, phone, email, tutor, tutee)) //checks if the form is filled out appropriately { if (action == EDIT) //if the user is editing a student { if (tutor) //save the classes if student is a tutor { saveClasses(); } else //if tutor status has been removed, remove all the classes they were approved for/had requested { if ((bool)(from row in db.Students where row.ID == accID select row.Tutor).First()) { removeAllClasses(); } } User updateUser = (from row in db.Users where row.ID == accID select row).Single(); //get the user object from the database updateUser.FirstName = fname; //update the object to admin input updateUser.LastName = lname; updateUser.Username = username; updateUser.Password = password; updateUser.PhoneNumber = phone; updateUser.Email = email; updateUser.AccountType = accounttype; Student updateStudent = (from row in db.Students where row.ID == accID select row).Single(); //get the Student object from the database updateStudent.Tutor = tutor; //update the object to admin input updateStudent.Tutee = tutee; db.SaveChanges(); //save changes AdminMain g = new AdminMain(); //return to admin main g.Show(); this.Dispose(); } else //user is in request or create mode { int ID = getNextID(); //gets ID for new user if (action == REQUEST) //if in request mode, adds the indicator to the end of the username { username += "?"; } saveNewUser(fname, lname, username, password, email, phone, accounttype, ID); //saves the user and student account to the database saveNewTutorTutee(tutor, tutee, ID); if (tutor) //if tutor, sends appropriate tutor requests { int numDepartments = tvClasses.Nodes.Count; for (int i = 0; i < numDepartments; i++) //loop through departments { int numNodes = tvClasses.Nodes[i].Nodes.Count; //for each class in a department for (int j = 0; j < numNodes; j++) { TreeNode tn = tvClasses.Nodes[i].Nodes[j]; if (tn.Checked) //check if the class is checked { TutorMaster.TutorRequest request = new TutorMaster.TutorRequest(); //create the request request.Key = getNextRequestKey(); request.ID = ID; string classCode = (from row in db.Classes where row.ClassName == tn.Text select row.ClassCode).First(); request.ClassCode = classCode; addRequest(request); //add request to database } } } } uncheckTree(); //reset the form txtFirstname.Text = ""; txtLastname.Text = ""; txtUsername.Text = ""; txtPassword.Text = ""; txtPhoneNumber.Text = ""; txtEmail.Text = ""; cbxTutor.Checked = false; cbxTutee.Checked = false; if (action == CREATE) //show user appropriate message { MessageBox.Show("Student has been added to the database."); } else { MessageBox.Show("Request has been sent to the administrator."); } } } }