/// <summary> /// Creator: Ethan Murphy /// Created: 2/16/2020 /// Approver: Carl Davis 2/21/2020 /// Approver: /// /// Creates an animal prescription record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="animalPrescription">An AnimalPrescription object</param> /// <returns>Creation succesful</returns> public bool CreateAnimalPrescriptionRecord(AnimalPrescriptionVM animalPrescription) { bool result = false; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_create_animal_prescription_record", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@AnimalID", animalPrescription.AnimalID); cmd.Parameters.AddWithValue("@AnimalVetAppointmentID", animalPrescription.AnimalVetAppointmentID); cmd.Parameters.AddWithValue("@PrescriptionName", animalPrescription.PrescriptionName); cmd.Parameters.AddWithValue("@Dosage", animalPrescription.Dosage); cmd.Parameters.AddWithValue("@MedicationInterval", animalPrescription.Interval); cmd.Parameters.AddWithValue("@AdministrationMethod", animalPrescription.AdministrationMethod); cmd.Parameters.AddWithValue("@StartDate", animalPrescription.StartDate); cmd.Parameters.AddWithValue("@EndDate", animalPrescription.EndDate); cmd.Parameters.AddWithValue("@Description", animalPrescription.Description); try { conn.Open(); result = cmd.ExecuteNonQuery() == 1; } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(result); }
/// <summary> /// Creator: Ethan Murphy /// Created: 3/15/2020 /// Approver: Carl Davis 3/19/2020 /// /// Updates a fake animal prescription record /// for testing purposes /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="oldAnimalPrescriptionVM">Existing record</param> /// <param name="newAnimalPrescriptionVM">Updated record</param> /// <returns>Update successful</returns> public bool UpdateAnimalPrescriptionRecord(AnimalPrescriptionVM oldAnimalPrescriptionVM, AnimalPrescriptionVM newAnimalPrescriptionVM) { var foundRecord = AnimalPrescriptionVMs.Find(p => p.AnimalPrescriptionID == oldAnimalPrescriptionVM.AnimalPrescriptionID && p.AnimalID == oldAnimalPrescriptionVM.AnimalID && p.AnimalVetAppointmentID == oldAnimalPrescriptionVM.AnimalVetAppointmentID && p.PrescriptionName == oldAnimalPrescriptionVM.PrescriptionName && p.Dosage == oldAnimalPrescriptionVM.Dosage && p.Interval == oldAnimalPrescriptionVM.Interval && p.AdministrationMethod == oldAnimalPrescriptionVM.AdministrationMethod && p.StartDate == oldAnimalPrescriptionVM.StartDate && p.EndDate == oldAnimalPrescriptionVM.EndDate && p.Description == oldAnimalPrescriptionVM.Description); if (foundRecord != null) { AnimalPrescriptionVMs[AnimalPrescriptionVMs.IndexOf(foundRecord)] = newAnimalPrescriptionVM; if (!AnimalPrescriptionVMs.Contains(foundRecord) && AnimalPrescriptionVMs.Contains(newAnimalPrescriptionVM)) { return(true); } } return(false); }
/// <summary> /// Creator: Ethan Murphy /// Created: 4/25/2020 /// Approver: Chuck Baxter 4/27/2020 /// /// Deletes an existing animal prescription record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="animalPrescription">Record to be deleted</param> /// <returns>Rows updated</returns> public int DeleteAnimalPrescriptionRecord(AnimalPrescriptionVM animalPrescription) { int rows = 0; int startingCount = AnimalPrescriptionVMs.Count; var foundRecord = AnimalPrescriptionVMs.Where( p => p.AnimalPrescriptionID == animalPrescription.AnimalPrescriptionID && p.AnimalID == animalPrescription.AnimalID && p.AnimalVetAppointmentID == animalPrescription.AnimalVetAppointmentID && p.PrescriptionName == animalPrescription.PrescriptionName && p.Dosage == animalPrescription.Dosage && p.Interval == animalPrescription.Interval && p.AdministrationMethod == animalPrescription.AdministrationMethod && p.StartDate == animalPrescription.StartDate && p.EndDate == animalPrescription.EndDate && p.Description == animalPrescription.Description && p.Active == animalPrescription.Active).FirstOrDefault(); if (foundRecord != null) { AnimalPrescriptionVMs.Remove(foundRecord); } rows = startingCount - AnimalPrescriptionVMs.Count; return(rows); }
public void TestAddingNewAnimalPrescriptionsRecord() { // Arrange bool result = false; IAnimalPrescriptionManager animalPrescriptionManager = new AnimalPrescriptionsManager(_animalPrescriptionsAccessor); AnimalPrescriptionVM animalPrescription = new AnimalPrescriptionVM() { AnimalID = 5, AnimalPrescriptionID = 5, AnimalVetAppointmentID = 5, PrescriptionName = "test5", Dosage = 2.0M, Interval = "2 times a day", AdministrationMethod = "Oral", StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(2), Description = "test5", AnimalName = "wefyawaw" }; // Act result = animalPrescriptionManager.AddAnimalPrescriptionRecord(animalPrescription); // Assert Assert.IsTrue(result); }
public void TestDeleteNonExistentAnimalPrescriptionRecord() { // Arrange bool result = false; IAnimalPrescriptionManager manager = new AnimalPrescriptionsManager(_animalPrescriptionsAccessor); AnimalPrescriptionVM animalPrescription = new AnimalPrescriptionVM() { AnimalID = 5, AnimalPrescriptionID = 100, AnimalVetAppointmentID = 1, PrescriptionName = "testfawefawef", Dosage = 2.0M, Interval = "2 times a dayawfeawef", AdministrationMethod = "Oral", StartDate = DateTime.Parse("3/20/2020"), EndDate = DateTime.Parse("4/15/2020"), Description = "test", AnimalName = "fawuief", Active = true }; // Act result = manager.DeleteAnimalPrescriptionRecord(animalPrescription); // Assert Assert.IsFalse(result); }
/// <summary> /// Creator: Ethan Murphy /// Created: 4/25/2020 /// Approver: Chuck Baxter 4/27/2020 /// /// Click event for deleting a prescription record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> private void btnDelete_Click(object sender, RoutedEventArgs e) { AnimalPrescriptionVM animalPrescription = (AnimalPrescriptionVM)dgPrescriptions.SelectedItem; if (animalPrescription == null) { return; } string message = "Are you sure you want to delete the " + animalPrescription.PrescriptionName + " record for " + animalPrescription.AnimalName + "? Please deactivate the record instead " + "unless you're sure you want to delete!"; if (MessageBox.Show(message, "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { try { if (_animalPrescriptionManager.DeleteAnimalPrescriptionRecord(animalPrescription)) { MessageBox.Show("Record deleted"); DisableEditMode(); RefreshPrescriptionsList(); canViewPrescription.Visibility = Visibility.Hidden; canView.Visibility = Visibility.Visible; } else { throw new ApplicationException("Record not found"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
/// <summary> /// Creator: Ethan Murphy /// Created: 2/16/2020 /// Approver: Carl Davis 2/21/2020 /// Approver: /// /// Creates an animal prescription record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="animalPrescription">An AnimalPrescription object</param> /// <returns>Creation succesful</returns> public bool AddAnimalPrescriptionRecord(AnimalPrescriptionVM animalPrescription) { try { return(_animalPrescriptionsAccessor.CreateAnimalPrescriptionRecord(animalPrescription)); } catch (Exception ex) { throw new ApplicationException("Failed to create record", ex); } }
/// <summary> /// Creator: Ethan Murphy /// Created: 4/25/2020 /// Approver: Chuck Baxter 4/27/2020 /// /// Deletes an existing animal prescription record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="animalPrescription">Record to be deleted</param> /// <returns>Delete successful</returns> public bool DeleteAnimalPrescriptionRecord(AnimalPrescriptionVM animalPrescription) { try { return(_animalPrescriptionsAccessor.DeleteAnimalPrescriptionRecord(animalPrescription) == 1); } catch (Exception ex) { throw new ApplicationException("Record not deleted", ex); } }
/// <summary> /// Creator: Ethan Murphy /// Created: 2/16/2020 /// Approver: Carl Davis 2/21/2020 /// /// Creates a fake animal prescription record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="AnimalPrescriptionVM">An AnimalPrescriptionVM object</param> /// <returns>Creation succesful</returns> public bool CreateAnimalPrescriptionRecord(AnimalPrescriptionVM AnimalPrescriptionVM) { bool result = false; AnimalPrescriptionVMs.Add(AnimalPrescriptionVM); if (AnimalPrescriptionVMs[AnimalPrescriptionVMs.Count - 1] == AnimalPrescriptionVM) { result = true; } return(result); }
/// <summary> /// Creator: Ethan Murphy /// Created: 3/9/2020 /// Approver: Carl Davis 3/13/2020 /// /// Populates the form controls when /// a record is opened /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> private void PopulateFields(AnimalPrescriptionVM animalPrescription) { txtPrescriptionName.Text = animalPrescription.PrescriptionName; txtDosage.Text = animalPrescription.Dosage.ToString(); txtInterval.Text = animalPrescription.Interval; dateStartDate.SelectedDate = animalPrescription.StartDate; dateEndDate.SelectedDate = animalPrescription.EndDate; txtAdministrationMethod.Text = animalPrescription.AdministrationMethod; txtDescription.Text = animalPrescription.Description; txtAnimal.Text = animalPrescription.AnimalName; chkActive.IsChecked = animalPrescription.Active; }
/// <summary> /// Creator: Ethan Murphy /// Created: 3/15/2020 /// Approver: Carl Davis 3/19/2020 /// /// Edits an existing animal prescription record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="oldAnimalPrescription">Existing record</param> /// <param name="newAnimalPrescription">Updated record</param> /// <returns>Edit successful</returns> public bool EditAnimalPrescriptionRecord(AnimalPrescriptionVM oldAnimalPrescription, AnimalPrescriptionVM newAnimalPrescription) { try { return(_animalPrescriptionsAccessor.UpdateAnimalPrescriptionRecord( oldAnimalPrescription, newAnimalPrescription)); } catch (Exception ex) { throw new ApplicationException("Failed to update record", ex); } }
/// <summary> /// Creator: Ethan Murphy /// Created: 3/15/2020 /// Approver: Carl Davis 3/19/2020 /// /// Updates an existing animal prescription record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="oldAnimalPrescription">Existing record</param> /// <param name="newAnimalPrescription">Record to replace the existing one</param> /// <returns>Update successful</returns> public bool UpdateAnimalPrescriptionRecord(AnimalPrescriptionVM oldAnimalPrescription, AnimalPrescriptionVM newAnimalPrescription) { bool result = false; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_update_animal_prescription", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@OldAnimalPrescriptionID", oldAnimalPrescription.AnimalPrescriptionID); cmd.Parameters.AddWithValue("@OldAnimalID", oldAnimalPrescription.AnimalID); cmd.Parameters.AddWithValue("@OldAnimalVetAppointmentID", oldAnimalPrescription.AnimalVetAppointmentID); cmd.Parameters.AddWithValue("@OldPrescriptionName", oldAnimalPrescription.PrescriptionName); cmd.Parameters.AddWithValue("@OldDosage", oldAnimalPrescription.Dosage); cmd.Parameters.AddWithValue("@OldInterval", oldAnimalPrescription.Interval); cmd.Parameters.AddWithValue("@OldAdministrationMethod", oldAnimalPrescription.AdministrationMethod); cmd.Parameters.AddWithValue("@OldStartDate", oldAnimalPrescription.StartDate); cmd.Parameters.AddWithValue("@OldEndDate", oldAnimalPrescription.EndDate); cmd.Parameters.AddWithValue("@OldDescription", oldAnimalPrescription.Description); cmd.Parameters.AddWithValue("@NewAnimalID", newAnimalPrescription.AnimalID); cmd.Parameters.AddWithValue("@NewAnimalVetAppointmentID", newAnimalPrescription.AnimalVetAppointmentID); cmd.Parameters.AddWithValue("@NewPrescriptionName", newAnimalPrescription.PrescriptionName); cmd.Parameters.AddWithValue("@NewDosage", newAnimalPrescription.Dosage); cmd.Parameters.AddWithValue("@NewInterval", newAnimalPrescription.Interval); cmd.Parameters.AddWithValue("@NewAdministrationMethod", newAnimalPrescription.AdministrationMethod); cmd.Parameters.AddWithValue("@NewStartDate", newAnimalPrescription.StartDate); cmd.Parameters.AddWithValue("@NewEndDate", newAnimalPrescription.EndDate); cmd.Parameters.AddWithValue("@NewDescription", newAnimalPrescription.Description); try { conn.Open(); result = cmd.ExecuteNonQuery() == 1; } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(result); }
/// <summary> /// Creator: Ethan Murphy /// Created: 4/26/2020 /// Approver: Chuck Baxter 4/27/2020 /// /// Selects animal prescriptions by active/inactive status /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="active">Active status</param> /// <returns>List of animal prescriptions</returns> public List <AnimalPrescriptionVM> SelectAnimalPrescriptionsByActive(bool active) { List <AnimalPrescriptionVM> animalPrescriptions = new List <AnimalPrescriptionVM>(); var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_animal_prescriptions_by_active", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Active", active); try { conn.Open(); var reader = cmd.ExecuteReader(); while (reader.Read()) { AnimalPrescriptionVM animalPrescription = new AnimalPrescriptionVM() { AnimalPrescriptionID = reader.GetInt32(0), AnimalID = reader.GetInt32(1), AnimalVetAppointmentID = reader.GetInt32(2), PrescriptionName = reader.GetString(3), Dosage = reader.GetDecimal(4), Interval = reader.GetString(5), AdministrationMethod = reader.GetString(6), StartDate = reader.GetDateTime(7), EndDate = reader.GetDateTime(8), Description = reader.GetString(9), AnimalName = reader.GetString(10), Active = reader.GetBoolean(11) }; animalPrescriptions.Add(animalPrescription); } } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(animalPrescriptions); }
public void TestUpdateNonExistentAnimalPrescriptionRecord() { // Arrange bool result = false; AnimalPrescriptionVM existingRecord = new AnimalPrescriptionVM() { AnimalID = 500, AnimalPrescriptionID = 1241, AnimalVetAppointmentID = 1214, PrescriptionName = "test", Dosage = 2.0M, Interval = "2 times a day", AdministrationMethod = "Oral", StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(2), Description = "test", AnimalName = "fawuief" }; AnimalPrescriptionVM newRecord = new AnimalPrescriptionVM() { AnimalID = 1, AnimalPrescriptionID = 1, AnimalVetAppointmentID = 1, PrescriptionName = "wefafawef", Dosage = 4.0M, Interval = "3 times a day", AdministrationMethod = "Oral", StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(2), Description = "test", AnimalName = "fawuief" }; IAnimalPrescriptionManager manager = new AnimalPrescriptionsManager(_animalPrescriptionsAccessor); // Act result = manager.EditAnimalPrescriptionRecord( existingRecord, newRecord); // Assert Assert.IsFalse(result); }
/// <summary> /// Creator: Ethan Murphy /// Created: 2/16/2020 /// Approver: Carl Davis 3/19/2020 /// /// Save button click event. Saves a new animal /// prescription record /// </summary> /// <remarks> /// Updater: Ethan Murphy /// Updated: 3/15/2020 /// Update: Added edit functionality /// </remarks> private void BtnSaveEdit_Click(object sender, RoutedEventArgs e) { if (btnSaveEdit.Content.Equals("Save")) { if (_selectedAppointment == null && editMode == false) { MessageBox.Show("Please select a corresponding vet appointment " + "by double clicking a record on the right"); return; } if (txtPrescriptionName.Text == "") { MessageBox.Show("Prescription name can't be blank!"); return; } if (txtDosage.Text == "") { MessageBox.Show("Dosage can't be blank"); return; } try { Decimal.Parse(txtDosage.Text); } catch (Exception) { MessageBox.Show("Invalid dosage entered. Please enter a number"); return; } if (txtInterval.Text == "") { MessageBox.Show("Interval can't be blank"); return; } if (txtAdministrationMethod.Text == "") { MessageBox.Show("Administration method can't be blank"); return; } if (dateStartDate.SelectedDate == null) { MessageBox.Show("Please select a start date"); return; } if (dateEndDate.SelectedDate == null) { MessageBox.Show("Please select an end date"); return; } AnimalPrescriptionVM animalPrescription = new AnimalPrescriptionVM() { AnimalID = editMode == true ? ((AnimalPrescription)dgPrescriptions.SelectedItem).AnimalID : _selectedAppointment.AnimalID, AnimalVetAppointmentID = editMode == true ? ((AnimalPrescription)dgPrescriptions.SelectedItem) .AnimalVetAppointmentID : _selectedAppointment.VetAppointmentID, PrescriptionName = txtPrescriptionName.Text, Dosage = Decimal.Parse(txtDosage.Text), Interval = txtInterval.Text, AdministrationMethod = txtAdministrationMethod.Text, StartDate = (DateTime)dateStartDate.SelectedDate, EndDate = (DateTime)dateEndDate.SelectedDate, Description = txtDescription.Text }; if (editMode) { try { if (_animalPrescriptionManager.EditAnimalPrescriptionRecord( (AnimalPrescriptionVM)dgPrescriptions.SelectedItem, animalPrescription)) { MessageBox.Show("Record updated!"); DisableEditMode(); RefreshPrescriptionsList(); canViewPrescription.Visibility = Visibility.Hidden; canView.Visibility = Visibility.Visible; } else { throw new ApplicationException(); } } catch (Exception ex) { string message = ex == null ? "Record failed to update" : ex.Message + " " + ex.InnerException; MessageBox.Show(message); } } else { try { if (_animalPrescriptionManager.AddAnimalPrescriptionRecord(animalPrescription)) { MessageBox.Show("Record added!"); DisableAddMode(); RefreshPrescriptionsList(); canViewPrescription.Visibility = Visibility.Hidden; canView.Visibility = Visibility.Visible; } else { throw new ApplicationException(); } } catch (Exception ex) { string message = ex == null ? "Record not added" : ex.Message + " " + ex.InnerException; MessageBox.Show(message); } } } else { EnableEditMode(); } }