/// <summary> /// Creator: Ethan Murphy /// Created: 4/27/2020 /// Approver: /// /// Deletes an existing animal vet appointment record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="vetAppointment">Record to be deleted</param> /// <returns>Rows affected</returns> public int DeleteAnimalVetAppointment(AnimalVetAppointment vetAppointment) { int rows = 0; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_delete_animal_vet_record", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@AnimalVetAppointmentID", vetAppointment.VetAppointmentID); cmd.Parameters.AddWithValue("@AnimalID", vetAppointment.AnimalID); cmd.Parameters.AddWithValue("@UserID", vetAppointment.UserID); cmd.Parameters.AddWithValue("@AppointmentDate", vetAppointment.AppointmentDateTime); cmd.Parameters.AddWithValue("@AppointmentDescription", vetAppointment.AppointmentDescription); cmd.Parameters.AddWithValue("@ClinicAddress", vetAppointment.ClinicAddress); cmd.Parameters.AddWithValue("@VetName", vetAppointment.VetName); try { conn.Open(); rows = cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(rows); }
/// <summary> /// Creator: Ethan Murphy /// Created: 4/28/2020 /// Approver: Carl Davis 4/30/2020 /// /// Sets vet appointment to active or inactive /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="vetAppointment">Record to change</param> /// <param name="active">State to be changed to</param> /// <returns>Rows affected</returns> public int SetVetAppointmentActiveStatus(AnimalVetAppointment vetAppointment, bool active) { int rows = 0; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_activate_animal_vet_record", conn); if (!active) { cmd.CommandText = "sp_deactivate_animal_vet_record"; } cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@AnimalVetAppointmentID", vetAppointment.VetAppointmentID); try { conn.Open(); rows = cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(rows); }
/// <summary> /// Creator: Ethan Murphy /// Created: 2/22/2020 /// Approver: Zach Behrensmeyer /// /// Sets the _selectedAppointment to the selected record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> private void DgAppointmentList_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (dgAppointmentList.SelectedItem != null) { _selectedAppointment = (AnimalVetAppointment)dgAppointmentList.SelectedItem; txtAnimal.Text = _selectedAppointment.AnimalName; } }
/// <summary> /// Creator: Ethan Murphy /// Created: 4/28/2020 /// Approver: Carl Davis 4/30/2020 /// /// Deactivates an active vet appointment /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// /// <param name="vetAppointment">Record to be updated</param> /// <returns>Update successful</returns> public bool DeactivateVetAppointment(AnimalVetAppointment vetAppointment) { try { return(_vetAppointmentAccessor.SetVetAppointmentActiveStatus(vetAppointment, false) == 1); } catch (Exception ex) { throw new ApplicationException("Failed to deactivate", ex); } }
/// <summary> /// Creator: Ethan Murphy /// Created: 4/27/2020 /// Approver: Carl Davis 4/30/2020 /// /// Deletes an existing vet appointment record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="vetAppointment">Record to be deleted</param> /// <returns>Delete successful</returns> public bool RemoveAnimalVetAppointment(AnimalVetAppointment vetAppointment) { try { return(_vetAppointmentAccessor.DeleteAnimalVetAppointment(vetAppointment) == 1); } catch (Exception ex) { throw new ApplicationException("Failed to delete", ex); } }
/// <summary> /// Creator: Ethan Murphy /// Created: 3/1/2020 /// Approver: Ben Hanna, 3/6/2020 /// Approver: /// /// Edits an existing animal vet appointment record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="oldVetAppointment">Existing vet appointment</param> /// <param name="newVetAppointment">Updated vet appointment</param> /// <returns>Edit successful</returns> public bool EditAnimalVetAppointmentRecord(AnimalVetAppointment oldVetAppointment, AnimalVetAppointment newVetAppointment) { try { return(_vetAppointmentAccessor.UpdateVetAppointment(oldVetAppointment, newVetAppointment)); } catch (Exception ex) { throw new ApplicationException("Failed to update record", ex); } }
/// <summary> /// Creator: Ethan Murphy /// Created: 2/7/2020 /// Approver: Carl Davis 2/14/2020 /// Approver: Chuck Baxter 2/14/2020 /// /// Creates aninmal vet appointment record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="animalVetAppointment">Animal vet appointment to add</param> /// <returns>Insert successful</returns> public bool AddAnimalVetAppointmentRecord(AnimalVetAppointment animalVetAppointment) { try { return(_vetAppointmentAccessor.InsertVetAppointment(animalVetAppointment)); } catch (Exception ex) { throw new ApplicationException("Failed to add record: ", ex); } }
/// <summary> /// Creator: Ethan Murphy /// Created: 2/9/2020 /// Approver: Chuck Baxter 2/14/2020 /// Approver: Carl Davis 2/14/2020 /// /// Populates controls with supplied data /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> private void PopulateFields(AnimalVetAppointment vetAppointment) { txtAnimalName.Text = vetAppointment.AnimalName; dateAppointmentDate.SelectedDate = vetAppointment.AppointmentDateTime; cboAppointmentTime.Text = vetAppointment.AppointmentDateTime.ToShortTimeString(); txtClinicAddress.Text = vetAppointment.ClinicAddress; txtVetName.Text = vetAppointment.VetName; txtDescription.Text = vetAppointment.AppointmentDescription; chkSetActive.IsChecked = vetAppointment.Active; if (vetAppointment.FollowUpDateTime != null) { dateFollowUp.SelectedDate = vetAppointment.FollowUpDateTime; cboFollowupTime.Text = vetAppointment.AppointmentDateTime.ToShortTimeString(); } }
/// <summary> /// Creator: Ethan Murphy /// Created: 3/1/2020 /// Approver: Ben Hanna, 3/6/2020 /// Approver: /// /// Updates an existing fake vet appointment record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="oldAnimalVetAppointment">The existing record</param> /// <param name="newAnimalVetAppointment">The updated record</param> /// <returns>Insert succesful</returns> public bool UpdateVetAppointment(AnimalVetAppointment oldAnimalVetAppointment, AnimalVetAppointment newAnimalVetAppointment) { bool result = false; if (_vetAppointments.Contains(oldAnimalVetAppointment)) { _vetAppointments.Remove(oldAnimalVetAppointment); _vetAppointments.Add(newAnimalVetAppointment); } if (_vetAppointments.Contains(newAnimalVetAppointment) && !_vetAppointments.Contains(oldAnimalVetAppointment)) { result = true; } return(result); }
/// <summary> /// Creator: Ethan Murphy /// Created: 3/1/2020 /// Approver: Ben Hanna, 3/6/2020 /// Approver: /// /// Updates an existing vet appointment record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="oldAnimalVetAppointment">The existing record</param> /// <param name="newAnimalVetAppointment">The updated record</param> /// <returns>Insert succesful</returns> public bool UpdateVetAppointment(AnimalVetAppointment oldAnimalVetAppointment, AnimalVetAppointment newAnimalVetAppointment) { bool result = false; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_update_vet_appointment", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@AnimalVetAppointmentID", oldAnimalVetAppointment.VetAppointmentID); cmd.Parameters.AddWithValue("@OldAnimalID", oldAnimalVetAppointment.AnimalID); cmd.Parameters.AddWithValue("@OldUserID", oldAnimalVetAppointment.UserID); cmd.Parameters.AddWithValue("@OldAppointmentDate", oldAnimalVetAppointment.AppointmentDateTime); cmd.Parameters.AddWithValue("@OldAppointmentDescription", oldAnimalVetAppointment.AppointmentDescription); cmd.Parameters.AddWithValue("@OldClinicAddress", oldAnimalVetAppointment.ClinicAddress); cmd.Parameters.AddWithValue("@OldVetName", oldAnimalVetAppointment.VetName); cmd.Parameters.AddWithValue("@NewAnimalID", newAnimalVetAppointment.AnimalID); cmd.Parameters.AddWithValue("@NewUserID", newAnimalVetAppointment.UserID); cmd.Parameters.AddWithValue("@NewAppointmentDate", newAnimalVetAppointment.AppointmentDateTime); cmd.Parameters.AddWithValue("@NewAppointmentDescription", newAnimalVetAppointment.AppointmentDescription); cmd.Parameters.AddWithValue("@NewClinicAddress", newAnimalVetAppointment.ClinicAddress); cmd.Parameters.AddWithValue("@NewVetName", newAnimalVetAppointment.VetName); cmd.Parameters.Add("@NewFollowUpDate", SqlDbType.DateTime); if (newAnimalVetAppointment.FollowUpDateTime == null) { cmd.Parameters["@NewFollowUpDate"].Value = DBNull.Value; } else { cmd.Parameters["@NewFollowUpDate"].Value = newAnimalVetAppointment.FollowUpDateTime; } try { conn.Open(); result = cmd.ExecuteNonQuery() == 1; } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(result); }
/// <summary> /// Creator: Ethan Murphy /// Created: 3/9/2020 /// Approver: Carl Davis 3/13/2020 /// /// Sets the form controls to their default state /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> private void DisableAddMode() { ResetFields(); txtPrescriptionName.IsEnabled = false; txtDosage.IsEnabled = false; txtInterval.IsEnabled = false; dateStartDate.IsEnabled = false; dateEndDate.IsEnabled = false; txtAdministrationMethod.IsEnabled = false; txtDescription.IsEnabled = false; dgAppointmentList.Visibility = Visibility.Hidden; lblSearchAnimal.Visibility = Visibility.Hidden; txtAnimalName.Visibility = Visibility.Hidden; btnSaveEdit.Content = "Edit"; dgAppointmentList.ItemsSource = null; _selectedAppointment = null; chkActive.IsChecked = false; }
public void TestActivatingRecord() { // Arrange bool result = false; IVetAppointmentManager manager = new VetAppointmentManager(_vetAppointmentAccessor); AnimalVetAppointment vetAppointment = new AnimalVetAppointment() { VetAppointmentID = 1, Active = false }; // Act result = manager.ActivateVetAppointment(vetAppointment); // Assert Assert.IsTrue(result); }
/// <summary> /// Creator: Ethan Murphy /// Created: 4/28/2020 /// Approver: Carl Davis 4/30/2020 /// /// Selects all vet appointments record by active/inactive /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="active">Active status</param> /// <returns>List of vet appointment</returns> public List <AnimalVetAppointment> SelectVetAppointmentsByActive(bool active) { List <AnimalVetAppointment> vetAppointments = new List <AnimalVetAppointment>(); var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_animal_vet_records_by_active", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Active", active); try { conn.Open(); var reader = cmd.ExecuteReader(); while (reader.Read()) { AnimalVetAppointment vetAppointment = new AnimalVetAppointment() { VetAppointmentID = reader.GetInt32(0), AnimalID = reader.GetInt32(1), AnimalName = reader.GetString(2), AppointmentDateTime = reader.GetDateTime(3), AppointmentDescription = reader.GetString(4), ClinicAddress = reader.GetString(5), VetName = reader.GetString(6), FollowUpDateTime = reader[7] as DateTime?, UserID = reader.GetInt32(8), Active = reader.GetBoolean(9) }; vetAppointments.Add(vetAppointment); } } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(vetAppointments); }
/// <summary> /// Creator: Ethan Murphy /// Created: 2/7/2020 /// Approver: Carl Davis 2/14/2020 /// Approver: Chuck Baxter 2/14/2020 /// /// Inserts a fake animal vet appointment record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="animalVetAppointment">An AnimalVetAppointment object</param> /// <returns>Insert succesful</returns> public bool InsertVetAppointment(AnimalVetAppointment animalVetAppointment) { bool result = false; _vetAppointments.Add(animalVetAppointment); try { if (_vetAppointments[_vetAppointments.Count - 1] == animalVetAppointment) { result = true; } } catch (Exception ex) { throw ex; } return(result); }
/// <summary> /// Creator: Ethan Murphy /// Created: 4/28/2020 /// Approver: Carl Davis 4/30/2020 /// /// Sets vet appointment to active or inactive /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="vetAppointment">Record to change</param> /// <param name="active">State to be changed to</param> /// <returns>Rows affected</returns> public int SetVetAppointmentActiveStatus(AnimalVetAppointment vetAppointment, bool active) { int rows = 0; var foundRecord = _vetAppointments .Where(v => v.VetAppointmentID == vetAppointment.VetAppointmentID) .FirstOrDefault(); if (foundRecord != null) { int index = _vetAppointments.IndexOf(foundRecord); foundRecord.Active = active; if (_vetAppointments[index].Active == active) { rows = 1; } } return(rows); }
/// <summary> /// Creator: Ethan Murphy /// Created: 4/27/2020 /// Approver: /// /// Deletes an existing animal vet appointment record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="vetAppointment">Record to be deleted</param> /// <returns>Rows affected</returns> public int DeleteAnimalVetAppointment(AnimalVetAppointment vetAppointment) { int rows = 0; int startingCount = _vetAppointments.Count; var foundRecord = _vetAppointments.Where(v => v.VetAppointmentID == vetAppointment.VetAppointmentID && v.AnimalID == vetAppointment.AnimalID && v.UserID == vetAppointment.UserID && v.AppointmentDateTime == vetAppointment.AppointmentDateTime && v.AppointmentDescription == vetAppointment.AppointmentDescription && v.ClinicAddress == vetAppointment.ClinicAddress && v.VetName == vetAppointment.VetName).FirstOrDefault(); if (foundRecord != null) { _vetAppointments.Remove(foundRecord); } rows = startingCount - _vetAppointments.Count; return(rows); }
public void TestUpdateAnimalVetAppointmentRecord() { // Arrange bool result = false; IVetAppointmentManager vetAppointmentManager = new VetAppointmentManager(_vetAppointmentAccessor); AnimalVetAppointment oldRecord = new AnimalVetAppointment() { VetAppointmentID = 1, AnimalID = 1, AnimalName = "qwerty", UserID = 1, AppointmentDateTime = DateTime.Now, AppointmentDescription = "asdf", ClinicAddress = "1234 asdf", VetName = "awerga", FollowUpDateTime = null, Active = true }; AnimalVetAppointment newRecord = new AnimalVetAppointment() { VetAppointmentID = 1, AnimalID = 1, AnimalName = "qwerty", UserID = 3, AppointmentDateTime = DateTime.Now, AppointmentDescription = "awefuhioawefouh", ClinicAddress = "1234 test", VetName = "awerga", FollowUpDateTime = DateTime.Now, Active = true }; // Act vetAppointmentManager.AddAnimalVetAppointmentRecord(oldRecord); result = vetAppointmentManager.EditAnimalVetAppointmentRecord(oldRecord, newRecord); // Assert Assert.IsTrue(result); }
/// <summary> /// Creator: Ethan Murphy /// Created: 2/7/2020 /// Approver: Carl Davis 2/14/2020 /// Approver: Chuck Baxter 2/14/2020 /// /// Gets all animal vet appointment records /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <returns>List of animal vet appointment</returns> public List <AnimalVetAppointment> SelectAllVetAppointments() { List <AnimalVetAppointment> vetAppointments = new List <AnimalVetAppointment>(); var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_all_vet_appointments", conn); try { conn.Open(); var reader = cmd.ExecuteReader(); while (reader.Read()) { AnimalVetAppointment vetAppointment = new AnimalVetAppointment() { VetAppointmentID = reader.GetInt32(0), AnimalID = reader.GetInt32(1), AnimalName = reader.GetString(2), AppointmentDateTime = reader.GetDateTime(3), AppointmentDescription = reader.GetString(4), ClinicAddress = reader.GetString(5), VetName = reader.GetString(6), FollowUpDateTime = reader[7] as DateTime?, UserID = reader.GetInt32(8) }; vetAppointments.Add(vetAppointment); } } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(vetAppointments); }
public void TestDeletingInValidAppointmentRecord() { // Arrange bool result = false; IVetAppointmentManager manager = new VetAppointmentManager(_vetAppointmentAccessor); AnimalVetAppointment vetAppointment = new AnimalVetAppointment() { VetAppointmentID = 1, AnimalID = 1, UserID = 10000, AppointmentDateTime = DateTime.Now, AppointmentDescription = "test", ClinicAddress = "test", VetName = "test" }; // Act result = manager.RemoveAnimalVetAppointment(vetAppointment); // Assert Assert.IsFalse(result); }
public void TestAddAnimalVetAppointmentRecord() { // Arrange bool result = false; IVetAppointmentManager vetAppointmentManager = new VetAppointmentManager(_vetAppointmentAccessor); AnimalVetAppointment animalVetAppointment = new AnimalVetAppointment() { AnimalID = 4, VetAppointmentID = 4, AnimalName = "Test", UserID = 4, FollowUpDateTime = null, AppointmentDateTime = DateTime.Now, ClinicAddress = "Test", VetName = "Test", AppointmentDescription = "Test" }; // Act result = vetAppointmentManager.AddAnimalVetAppointmentRecord(animalVetAppointment); // Assert Assert.IsTrue(result); }
/// <summary> /// Creator: Ethan Murphy /// Created: 4/27/2020 /// Approver: Carl Davis 4/30/2020 /// /// Button click event to delete vet appointment record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> private void btnDelete_Click(object sender, RoutedEventArgs e) { AnimalVetAppointment appointment = (AnimalVetAppointment)dgAppointments.SelectedItem; if (appointment == null) { return; } string message = "Are you sure you want to delete the vet appointment record for " + appointment.AnimalName + " on " + appointment.AppointmentDateTime.ToShortDateString() + "? If you're unsure please deactivate the record instead, as deletions can't be undone!"; if (MessageBox.Show(message, "Confirm Delete", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { try { if (_vetAppointmentManager.RemoveAnimalVetAppointment(appointment)) { MessageBox.Show("Record deleted!"); BtnClose_Click(null, null); RefreshList(); DisableEditMode(); } else { throw new ApplicationException("Delete failed"); } } catch (Exception ex) { string error = ex.InnerException == null ? ex.Message : ex.Message + "\n\n" + ex.InnerException.Message; MessageBox.Show(error); } } }
/// <summary> /// Creator: Ethan Murphy /// Created: 2/7/2020 /// Approver: Carl Davis 2/14/2020 /// Approver: Chuck Baxter 2/14/2020 /// /// Validates all submitted information and saves a record /// </summary> /// <remarks> /// Updater: Ethan Murphy /// Updated: 3/1/2020 /// Update: Utlilized validation utility and added edit functionality /// Approver: Ben Hanna, 3/6/2020 /// </remarks> private void BtnSaveEdit_Click(object sender, RoutedEventArgs e) { if (btnSaveEdit.Content.Equals("Save")) { if (_selectedAnimal == null && _editMode == false) { MessageBox.Show("No animal selected. Please double click on the " + "desired animal in the list on the right"); return; } else if (_editMode) { _selectedAnimal = new Animal(); _selectedAnimal.AnimalID = ((AnimalVetAppointment)dgAppointments.SelectedItem).AnimalID; } if (dateAppointmentDate.SelectedDate == null) { MessageBox.Show("Please select an appointment date"); return; } if (cboAppointmentTime.SelectedItem == null) { MessageBox.Show("Please select an appointment time"); return; } if (!txtVetName.Text.IsValidVetName()) { MessageBox.Show("Vet name can't be blank!"); return; } if (!txtClinicAddress.Text.IsValidClinicAddress()) { MessageBox.Show("Clinic address is invalid"); return; } if (!txtDescription.Text.IsValidAppointmentDescription()) { MessageBox.Show("Please enter a more descriptive description"); return; } AnimalVetAppointment animalVetAppointment = new AnimalVetAppointment() { AnimalID = _selectedAnimal.AnimalID, AnimalName = _selectedAnimal.AnimalName, UserID = _user.PUUserID, AppointmentDateTime = DateTime.Parse( dateAppointmentDate.SelectedDate.Value.ToShortDateString() + " " + cboAppointmentTime.SelectedValue), ClinicAddress = txtClinicAddress.Text, VetName = txtVetName.Text, AppointmentDescription = txtDescription.Text, FollowUpDateTime = null }; if (_editMode) { if ((dateFollowUp.SelectedDate != null && cboFollowupTime.SelectedItem == null) || (dateFollowUp.SelectedDate == null && cboFollowupTime.SelectedItem != null)) { MessageBox.Show("If you select a follow up date you must select a time also and vice versa." + " You can select the 'Clear Follow Up' button to not have one set."); return; } if (dateFollowUp.SelectedDate != null && cboFollowupTime.SelectedItem != null) { animalVetAppointment.FollowUpDateTime = DateTime.Parse( dateFollowUp.SelectedDate.Value.ToShortDateString() + " " + cboFollowupTime.SelectedValue); } try { if (_vetAppointmentManager.EditAnimalVetAppointmentRecord( (AnimalVetAppointment)dgAppointments.SelectedItem, animalVetAppointment)) { MessageBox.Show("Record updated!"); BtnClose_Click(null, null); RefreshList(); DisableEditMode(); } else { throw new ApplicationException(); } } catch (Exception ex) { string message = ex == null ? "Failed to update record" : ex.Message + " " + ex.InnerException; MessageBox.Show(message); } } else { try { if (_vetAppointmentManager.AddAnimalVetAppointmentRecord(animalVetAppointment)) { MessageBox.Show("Appointment has been scheduled!"); DisableAddMode(); BtnClose_Click(null, null); RefreshList(); } else { throw new ApplicationException(); } } catch (Exception ex) { string message = ex == null ? "Failed to save record" : ex.Message + " " + ex.InnerException; MessageBox.Show(message); } } } else if (btnSaveEdit.Content.Equals("Edit")) { EnableEditMode(); } }