/// <summary> /// Gets the password digest as a byte array. /// </summary> /// <param name="userName">The user name to look up</param> /// <returns>A byte array representing the password digest</returns> public static User GetUserByID(int userID) { String role = PersonDB.GetPersonRole(userID); User theUser = new User(); try { switch (role) { case "Nurse": theUser = NurseDB.GetNurseByID(userID); break; case "Doctor": theUser = DoctorDB.GetDoctorByID(userID); break; case "Administrator": theUser = AdministratorDB.GetAdministratorByID(userID); break; default: break; } } catch (Exception) { throw; } return theUser; }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); oldUser = UserController.GetUserByID(userID); cbUserRole.Items.IndexOf(oldUser.UserRole); tbUserName.Text = oldUser.UserName; tbLastName.Text = oldUser.LastName; tbMiddleInitial.Text = oldUser.MiddleInitial.ToString(); tbFirstName.Text = oldUser.FirstName; tbBirthdate.Value = oldUser.DateOfBirth; cbGender.SelectedIndex = oldUser.Gender.ToString().ToLower().Equals("m") ? 0 : 1; tbSSN.Text = oldUser.Ssn; tbAddress.Text = oldUser.Address; tbCity.Text = oldUser.City; cbState.Text = oldUser.State; tbZip.Text = oldUser.Zip; tbPhone.Text = oldUser.Phone; }
public static int AddAdministrator(User admin) { int adminID = -1; try { adminID = PersonDB.AddPerson((Person) admin); if (adminID != -1) { AdministratorDB.AddAdministrator(adminID, admin); } else { throw new Exception("Error adding the administrator to the Database"); } } catch (Exception ex) { MessageBox.Show("Administrator Controller: " + ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK); } return adminID; }
public static bool AddAdministrator(int personID, User admin) { try { using (SqlConnection connection = HealthCareDBConnection.GetConnection()) { string insertStatement = "INSERT Administrator (personID, password) VALUES (@ID, @PASSWORD)"; using (SqlCommand insertCommand = new SqlCommand(insertStatement, connection)) { insertCommand.Parameters.AddWithValue("@PASSWORD", admin.GetPasswordHash()); insertCommand.Parameters.AddWithValue("@ID", personID); connection.Open(); insertCommand.ExecuteNonQuery(); return true; } } } catch { return false; } }
public static int AddNurse(User nurse) { int nurseId = -1; try { nurseId = PersonDB.AddPerson((Person) nurse); if (nurseId == -1) { throw new Exception("Error adding the nurse to the Database"); } else { NurseDB.AddNurse(nurseId, nurse); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK); } return nurseId; }
internal static int AddDoctor(User doctor) { int doctorId = -1; try { doctorId = PersonDB.AddPerson((Person) doctor); if (doctorId == -1) { throw new Exception("Error adding the doctor to the Database"); } else { DoctorDB.AddDoctor(doctorId, doctor); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK); } return doctorId; }
internal static bool UpdateUser(User oldUser, User newUser) { bool success = false; try { success = PersonDB.UpdateUser(oldUser, newUser); } catch (Exception) { throw; } return success; }
private void saveButton_Click(object sender, EventArgs e) { try { if (Validator.AreAllPresent(controls)) { User newUser = new User(); newUser.LastName = tbLastName.Text; if (tbMiddleInitial.Text != "") { newUser.MiddleInitial = tbMiddleInitial.Text.ToCharArray()[0]; } newUser.FirstName = tbFirstName.Text; newUser.DateOfBirth = tbBirthdate.Value; newUser.Gender = cbGender.SelectedItem.ToString().ToCharArray()[0]; tbSSN.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; newUser.Ssn = tbSSN.Text; tbSSN.TextMaskFormat = MaskFormat.IncludeLiterals; newUser.Address = tbAddress.Text; if (tbAptNum.Text != "") { newUser.Address += " Apt. #: " + tbAptNum.Text; } newUser.City = tbCity.Text; newUser.State = cbState.Text; tbZip.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; newUser.Zip = tbZip.Text; tbZip.TextMaskFormat = MaskFormat.IncludeLiterals; tbPhone.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; newUser.Phone = tbPhone.Text; tbPhone.TextMaskFormat = MaskFormat.IncludeLiterals; newUser.UserRole = oldUser.UserRole; newUser.UserName = oldUser.UserName; bool edited = UserController.UpdateUser(oldUser, newUser); if (!edited) throw new Exception("Update unsuccessful!"); Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
internal static User GetAdministratorByID(int id) { User theUser = new User(); try { using (SqlConnection connection = HealthCareDBConnection.GetConnection()) { string updateStatement = "SELECT d.password, p.* FROM Administrator d INNER JOIN Person p on d.personID = p.personID WHERE d.personID=@ID"; using (SqlCommand selectCommand = new SqlCommand(updateStatement, connection)) { selectCommand.Parameters.AddWithValue("@ID", id); connection.Open(); using (SqlDataReader reader = selectCommand.ExecuteReader()) { while (reader.Read()) { theUser.UserName = reader["userName"].ToString(); theUser.UserRole = reader["userRole"].ToString(); theUser.PersonId = (int)reader["personID"]; theUser.Ssn = reader["ssn"].ToString(); theUser.FirstName = reader["firstName"].ToString(); theUser.MiddleInitial = !DBNull.Value.Equals(reader["middleInitial"]) ? Convert.ToChar(reader["middleInitial"].ToString()) : Convert.ToChar(" "); theUser.LastName = reader["lastName"].ToString(); theUser.DateOfBirth = (DateTime)reader["dateOfBirth"]; theUser.Gender = Convert.ToChar(reader["gender"].ToString()); theUser.Address = reader["address"].ToString(); theUser.City = reader["city"].ToString(); theUser.State = reader["state"].ToString(); theUser.Zip = reader["zip"].ToString(); theUser.Phone = reader["phone"].ToString(); } } } } } catch { throw; } return theUser; }
private int addUser(User person) { int result = -1; if (!isAuthenticatedUser()) { Patient newPatient = PatientController.CreatePatient(person.LastName, 'a', person.FirstName, person.DateOfBirth.ToString(), person.Gender, person.Ssn, person.Address, person.City, person.State, person.Zip, person.Phone); result = PatientController.AddPatient(newPatient); } else { User newUser = person; newUser.UserName = tbUserName.Text; newUser.SetPassword(tbPassword.Text); if (cbRole.Text == UserType.DOCTOR.ToString()) { newUser.UserRole = "Doctor"; result = DoctorController.AddDoctor(newUser); } else if (cbRole.Text == UserType.ADMINISTRATOR.ToString()) { newUser.UserRole = "Administrator"; result = AdministratorController.AddAdministrator(newUser); } else if (cbRole.Text == UserType.NURSE.ToString()) { newUser.UserRole = "Nurse"; result = NurseController.AddNurse(newUser); } } return result; }
public bool UpdateNurse(User oldNurse, User newNurse) { return PersonDB.UpdateUser(oldNurse, newNurse); }
public bool UpdateDoctor(User oldDoctor, User newDoctor) { return PersonDB.UpdateUser(oldDoctor, newDoctor); }
public static bool UpdateUser(User oldPerson, User newPerson) { bool success = false; int i = 0; try { using (SqlConnection connection = HealthCareDBConnection.GetConnection()) { string updateStatement = "UPDATE Person SET " + "ssn = @NewSsn, " + "lastName = @NewLastName, " + "middleInitial = @NewMiddleInitial, " + "firstName = @NewFirstName, " + "dateOfBirth = @NewDateOfBirth, " + "gender = @NewGender, " + "address = @NewAddress, " + "city = @NewCity, " + "state = @NewState, " + "phone = @NewPhone " + "userName = @NewUserName " + "userRole = @NewUserRole " + "WHERE personID = @OldPersonID " + "AND ssn = @OldSsn " + "AND lastName = @OldLastName " + "AND (middleInitial = @OldMiddleInitial " + "OR (middleInitial IS NULL AND @OldMiddleInitial IS NULL)) " + "AND firstName = @OldFirstName " + "AND dateOfBirth = @OldDateOfBirth " + "AND gender = @OldGender " + "AND address = @OldAddress " + "AND city = @OldCity " + "AND state = @OldState " + "AND zip = @OldZip " + "AND phone = @OldPhone" + "AND (userName = @OldUserName " + "OR (userName IS NULL AND @OldUserName IS NULL)) " + "AND (userRole = @OldUserRole " + "OR (userRole IS NULL AND @OldUserRole IS NULL)) "; using (SqlCommand updateCommand = new SqlCommand(updateStatement, connection)) { if (newPerson.Ssn.Length == 9) updateCommand.Parameters.AddWithValue("@NewSsn", newPerson.Ssn); else return false; updateCommand.Parameters.AddWithValue("@NewLastName", newPerson.LastName); if (newPerson.MiddleInitial.Equals(null)) updateCommand.Parameters.AddWithValue("@NewMiddleInitial", DBNull.Value); else updateCommand.Parameters.AddWithValue("@NewMiddleInitial", newPerson.MiddleInitial); updateCommand.Parameters.AddWithValue("@NewFirstName", newPerson.FirstName); updateCommand.Parameters.AddWithValue("@NewDateOfBirth", newPerson.DateOfBirth); updateCommand.Parameters.AddWithValue("@NewGender", newPerson.Gender); updateCommand.Parameters.AddWithValue("@NewAddress", newPerson.Address); updateCommand.Parameters.AddWithValue("@NewCity", newPerson.City); updateCommand.Parameters.AddWithValue("@NewState", newPerson.State); if (newPerson.Zip.Length == 5 && (int.TryParse(newPerson.Zip, out i) == true)) updateCommand.Parameters.AddWithValue("@NewZip", newPerson.Zip); else return false; updateCommand.Parameters.AddWithValue("@NewPhone", newPerson.Phone); if (newPerson.UserName == null) updateCommand.Parameters.AddWithValue("@NewUserName", DBNull.Value); else updateCommand.Parameters.AddWithValue("@NewUserName", newPerson.UserName); if (newPerson.UserRole == null) updateCommand.Parameters.AddWithValue("@NewUserRole", DBNull.Value); else updateCommand.Parameters.AddWithValue("@NewUserRole", newPerson.UserRole); updateCommand.Parameters.AddWithValue("@OldPersonID", oldPerson.PersonId); updateCommand.Parameters.AddWithValue("@OldSsn", oldPerson.Ssn); updateCommand.Parameters.AddWithValue("@OldLastName", oldPerson.LastName); if (oldPerson.MiddleInitial.Equals(null)) updateCommand.Parameters.AddWithValue("@OldMiddleInitial", DBNull.Value); else updateCommand.Parameters.AddWithValue("@OldMiddleInitial", oldPerson.MiddleInitial); updateCommand.Parameters.AddWithValue("@OldFirstName", oldPerson.FirstName); updateCommand.Parameters.AddWithValue("@OldDateOfBirth", oldPerson.DateOfBirth); updateCommand.Parameters.AddWithValue("@OldGender", oldPerson.Gender); updateCommand.Parameters.AddWithValue("@OldAddress", oldPerson.Address); updateCommand.Parameters.AddWithValue("@OldCity", oldPerson.City); updateCommand.Parameters.AddWithValue("@OldState", oldPerson.State); updateCommand.Parameters.AddWithValue("@OldZip", oldPerson.Zip); updateCommand.Parameters.AddWithValue("@OldPhone", oldPerson.Phone); if (oldPerson.UserName == null) updateCommand.Parameters.AddWithValue("@OldUserName", DBNull.Value); else updateCommand.Parameters.AddWithValue("@OldUserName", oldPerson.UserName); if (oldPerson.UserRole == null) updateCommand.Parameters.AddWithValue("@OldUserRole", DBNull.Value); else updateCommand.Parameters.AddWithValue("@OldUserRole", oldPerson.UserRole); connection.Open(); int count = updateCommand.ExecuteNonQuery(); if (count > 0) { success = true; } else { success = false; } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK); } return success; }
private void addButton_Click(object sender, EventArgs e) { User newUser = new User(); //Add username and password to the validation if (isAuthenticatedUser()) { controls.Add(tbUserName); controls.Add(tbPassword); } try { if (Validator.AreAllPresent(controls)) { newUser.LastName = tbLastName.Text; if (tbMiddleInitial.Text != "") { newUser.MiddleInitial = tbMiddleInitial.Text.ToCharArray()[0]; } newUser.FirstName = tbFirstName.Text; newUser.DateOfBirth = dateBirthDate.Value; newUser.Gender = cbGender.SelectedItem.ToString().ToCharArray()[0]; tbSSN.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; newUser.Ssn = tbSSN.Text; tbSSN.TextMaskFormat = MaskFormat.IncludeLiterals; newUser.Address = tbAddress.Text; if (tbApt.Text != "") { newUser.Address += " Apt. #: " + tbApt.Text; } newUser.City = tbCity.Text; newUser.State = cbState.Text; tbZip.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; newUser.Zip = tbZip.Text; tbZip.TextMaskFormat = MaskFormat.IncludeLiterals; tbPhone.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; newUser.Phone = tbPhone.Text; tbPhone.TextMaskFormat = MaskFormat.IncludeLiterals; int added = addUser(newUser); if (added == -1) throw new Exception("Add unsuccessful!"); else { MessageBox.Show("Successfully added " + newUser.FullName + " with User ID of: " + added + "!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); } Close(); } } catch (Exception ex) { MessageBox.Show("Add User Form: " + ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
internal static List<User> GetAllAdministrators() { List<User> adminList = new List<User>(); try { using (SqlConnection connection = HealthCareDBConnection.GetConnection()) { string selectStatement = "SELECT * from Person pe " + "JOIN Administrator ad ON pe.personID = ad.personID "; using (SqlCommand selectCommand = new SqlCommand(selectStatement, connection)) { connection.Open(); using (SqlDataReader reader = selectCommand.ExecuteReader()) { while (reader.Read()) { User admin = new User(); admin.PersonId = (int)reader["personID"]; admin.Ssn = reader["ssn"].ToString(); admin.FirstName = reader["firstName"].ToString(); admin.MiddleInitial = !DBNull.Value.Equals(reader["middleInitial"]) ? Convert.ToChar(reader["middleInitial"].ToString()) : Convert.ToChar(" "); admin.LastName = reader["lastName"].ToString(); admin.DateOfBirth = (DateTime)reader["dateOfBirth"]; admin.Gender = Convert.ToChar(reader["gender"].ToString()); admin.Address = reader["address"].ToString(); admin.City = reader["city"].ToString(); admin.State = reader["state"].ToString(); admin.Zip = reader["zip"].ToString(); admin.Phone = reader["phone"].ToString(); admin.UserName = reader["userName"].ToString(); admin.SetPassword((byte[]) reader["password"]); adminList.Add(admin); } } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK); } return adminList; }
public bool UpdateAdministrator(User oldAdministrator, User newAdministrator) { return PersonDB.UpdateUser(oldAdministrator, newAdministrator); }
/// <summary> /// Private instantiator for singleton. /// </summary> private GlobalVars() { CurrentUser = new User(); }