/// <summary> /// Logs in the user /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void loginButton_Click(object sender, EventArgs e) { SimpleAES encrypt = new SimpleAES(); String name = NameBox.Text; String password = PasswordBox.Text; password = encrypt.EncryptToString(password); try { Employee employee = _controller.EmployeeLogIn(name, password); if (employee == null ) { MessageBox.Show(@"No valid user found, please try your user name and password again"); } else if (employee.PositionId == 1 && employee.Enabled == 1) { MessageBox.Show(@"Valid login. Welcome Nurse " + employee.FirstName + " " + employee.LastName); employeeUser = employee; NorthwindAdmin homeN = new NorthwindAdmin(employee); homeN.Show(); this.Hide(); } else if (employee.PositionId == 3 && employee.Enabled == 1) { MessageBox.Show(@"Valid login. Welcome Admin " + employee.FirstName + " " + employee.LastName); employeeUser = employee; NorthwindAdmin homeA = new NorthwindAdmin(employee); homeA.Show(); this.Hide(); } else if ((employee.PositionId == 3 || employee.PositionId == 1) & employee.Enabled == 0) { MessageBox.Show(@"Your account is currently disabled, please contact an admin."); } else { MessageBox.Show(@"Only Nurses Or Administrators May login at this time."); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString() + "Something happened"); } }
private Employee CreateEmployee() { if ((femaleRadioButton.Checked == false) & (maleRadioButton.Checked == false)) { MessageBox.Show ( @"Please select gender."); } else { if ((femaleRadioButton.Checked == true)) { gender = "F"; } else { gender = "M"; } // This is going to check if anything needs to be fixed Boolean loginInfoSet = false; employee.Enabled = 0; if ((loginTextBox.Text.Trim().Length > 0) & (passwordTextBox.Text.Trim().Length > 0)) { Boolean uniqueLogin = true; if ((employee.Login.Trim() != loginTextBox.Text.Trim())) { uniqueLogin = _controller.VerifyUniqueLogin(loginTextBox.Text); } if (uniqueLogin) { loginInfoSet = true; employee.Login = loginTextBox.Text; SimpleAES encrypt = new SimpleAES(); employee.Password = encrypt.EncryptToString(passwordTextBox.Text); employee.Enabled = 1; } else { MessageBox.Show(@"That Login is already in use."); } } if (loginInfoSet) { if ((int.TryParse(ssnTextBox.Text, out ssn)) & (ssnTextBox.Text.Length == 9)) { if ((int.TryParse(zipTextBox.Text, out zip)) & (zipTextBox.Text.Length == 5)) { long phone; PhoneTextBox.Text = PhoneTextBox.Text.Trim(); if ((long.TryParse(PhoneTextBox.Text, out phone)) & (PhoneTextBox.Text.Length >= 10)) { if ((firstNameTextBox.Text != "") & (lastNameTextBox.Text != "") & (ssn != 0) & (zip != 0) & (addressTextBox.Text != "") & (cityTextBox.Text != "") & (StateComboBox.Text != "")) { //Check Details employee.FirstName = firstNameTextBox.Text; employee.MiddleInitial = middleInitialTextBox.Text; employee.LastName = lastNameTextBox.Text; employee.Gender = gender; employee.Ssn = ssn; employee.Zip = zip; employee.PositionId = JobBox.SelectedIndex + 1; employee.Phone = phone.ToString(); employee.Dob = dateTimePicker.Value.Date; employee.Address = addressTextBox.Text; employee.City = cityTextBox.Text; employee.State = StateComboBox.Text; return employee; } else { MessageBox.Show(@"Please check all the required fields and make sure you entered the proper information."); } } else { MessageBox.Show( @"Phone number needs to be numbers only, remove any non digit characters like -'s or ()'s and is at least 10 numbers."); } } else { MessageBox.Show( @"Please enter Zip as a number and that you have entered the right amount of numbers. Please check."); } } else { MessageBox.Show( @"Please enter Social as a number with no dashes, or you may not have entered the right amount of numbers. Please check."); } } else { MessageBox.Show(@"You need to have a login and password."); } } return null; }