/// <summary> /// Creator: Ben Hanna /// Created: 3/4/2020 /// Approver: Chuck Baxter, 3/5/2020 /// Approver: /// /// Updates a single handling notes record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="notes"></param> /// <returns> Number of Rows effected</returns> public int InsertAnimalHandlingNotes(AnimalHandlingNotes notes) { int notesID = 0; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_insert_handling_notes_record", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@AnimalID", notes.AnimalID); cmd.Parameters.AddWithValue("@UserID", notes.UserID); cmd.Parameters.AddWithValue("@AnimalHandlingNotes", notes.HandlingNotes); cmd.Parameters.AddWithValue("@TemperamentWarning", notes.TemperamentWarning); cmd.Parameters.AddWithValue("@UpdateDate", notes.UpdateDate); try { conn.Open(); notesID = Convert.ToInt32(cmd.ExecuteScalar()); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(notesID); }
public void TestUpdateHandlingRecordBadValue() { // Arrange IAnimalHandlingManager handlingManager = new AnimalHandlingManager(_handlingAccessor); AnimalHandlingNotes oldNotes = new AnimalHandlingNotes() { HandlingNotesID = 0, UserID = 100000, AnimalID = 100000, HandlingNotes = "notes", TemperamentWarning = "calm", UpdateDate = DateTime.Now }; AnimalHandlingNotes newNotes = new AnimalHandlingNotes() { HandlingNotesID = 0, UserID = 100000, AnimalID = 100000, HandlingNotes = "new notes", TemperamentWarning = "happy", UpdateDate = DateTime.Now }; // Act bool actualResult = handlingManager.EditAnimalHandlingNotes(oldNotes, newNotes); //Assert }
/// <summary> /// Creator: Ben Hanna /// Created: 3/5/2020 /// Approver: /// Approver:Chuck Baxter, 3/5/2020 /// /// Remade original constructor so the program wont throw an error when the home page is loaded. /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> public HandlingControls() { InitializeComponent(); _oldNotes = new AnimalHandlingNotes(); _handlingManager = new AnimalHandlingManager(); _animalManager = new AnimalManager(); _updateMode = false; }
/// <summary> /// Creator: Ben Hanna /// Created: 2/22/2020 /// Approver: Steven Cardona /// Approver: /// /// Constructor for this page. /// </summary> /// <remarks> /// Updater: Ben Hanna /// Updated: 3/2/2020 /// Update: Added a statement to set _updateMode to false, as well as a user object to populate the UserID field. /// Approver: Chuck Baxter, 3/5/2020 /// </remarks> public HandlingControls(PetUniverseUser user) { InitializeComponent(); this._user = user; _oldNotes = new AnimalHandlingNotes(); _handlingManager = new AnimalHandlingManager(); _animalManager = new AnimalManager(); _updateMode = false; }
/// <summary> /// Creator: Ben Hanna /// Created: 2/22/2020 /// Approver: Steven Cardona /// Approver: /// /// Double click handling notes datagrid to select a set of handling notes records /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="sender"></param> /// <param name="e"></param> private void dgHandlingNotesList_MouseDoubleClick(object sender, MouseButtonEventArgs e) { _oldNotes = (AnimalHandlingNotes)dgHandlingNotesList.SelectedItem; txtHandlingNotesID.Text = _oldNotes.HandlingNotesID.ToString(); txtAnimalID.Text = _oldNotes.AnimalID.ToString(); txtUserID.Text = _oldNotes.UserID.ToString(); txtHandlingNotes.Text = _oldNotes.HandlingNotes; txtTemperment.Text = _oldNotes.TemperamentWarning; dpHandlingUpdateDate.SelectedDate = _oldNotes.UpdateDate; btnUpdateRecord.IsEnabled = true; btnUpdateRecord.Visibility = Visibility.Visible; }
/// <summary> /// Creator: Ben Hanna /// Created: 2/28/2020 /// Approver: Chuck Baxter, 3/5/2020 /// Approver: /// /// Simlates adding a record to the database. Gives a deliberate error depending on the PK value. /// </summary> /// <remarks> /// Updater: Zach Behrensmeyer /// Updated: 4/9/2020 /// Update: Updated return value so we weren't using a magic number /// </remarks> /// <param name="notes"></param> /// <returns> Represents the number of rows effected. </returns> public int InsertAnimalHandlingNotes(AnimalHandlingNotes notes) { int result = 0; if (notes.HandlingNotesID == 1) { _handlingList.Add(notes); result = 1; } else { throw new ApplicationException("Unit Test Insert Handling Notes Exception"); } return(result); }
/// <summary> /// Creator: Ben Hanna /// Created: 2/3/2020 /// Approver: Chuck Baxter, 3/5/2020 /// Approver: /// /// Adds a record to the animal handling notes table. /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="handlingNotes"></param> /// <returns></returns> public bool AddAnimalHandlingNotes(AnimalHandlingNotes handlingNotes) { bool result = false; try { result = _handlingAccessor.InsertAnimalHandlingNotes(handlingNotes) > 0; } catch (Exception ex) { throw new ApplicationException("Handling Record not added", ex); } return(result); }
/// <summary> /// Creator: Ben Hanna /// Created: 3/5/2020 /// Approver: Chuck Baxter, 3/5/2020 /// Approver: /// /// Updates a single animal handling notes record. /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="oldNotes"></param> /// <param name="newNotes"></param> /// <returns></returns> public bool EditAnimalHandlingNotes(AnimalHandlingNotes oldNotes, AnimalHandlingNotes newNotes) { bool result = false; try { result = 1 == _handlingAccessor.UpdateAnimalHandlingNotes(oldNotes, newNotes); } catch (Exception ex) { throw new ApplicationException("Update failed", ex); } return(result); }
/// <summary> /// Creator: Ben Hanna /// Created: 2/29/2020 /// Approver: Chuck Baxter, 3/5/2020 /// /// Simulates a method to Update a an existing handling record. /// </summary> /// <remarks> /// Updater: Zach Behrensmeyer /// Updated: 4/9/2020 /// Update: Updated return value so we weren't using a magic number /// </remarks> /// <param name="oldNotes"></param> /// <param name="newNotes"></param> /// <returns></returns> public int UpdateAnimalHandlingNotes(AnimalHandlingNotes oldNotes, AnimalHandlingNotes newNotes) { int result; AnimalHandlingNotes note = (_handlingList.Find(n => n.HandlingNotesID == oldNotes.HandlingNotesID)); if (note != null) { int i = _handlingList.IndexOf(note); _handlingList[i] = newNotes; result = 1; } else { throw new ApplicationException("data not found"); } return(result); }
/// <summary> /// Creator: Ben Hanna /// Created: 2/21/2020 /// Approver: Carl Davis, 2/21/2020 /// Approver: Chuck Baxter, 2/21/2020 /// /// Select a list of AnimalHandlingNotes objects by their shared animal ID /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="animalID"></param> /// <returns>The list of animal handling notes</returns> public List <AnimalHandlingNotes> SelectAllHandlingNotesByAnimalID(int animalID) { List <AnimalHandlingNotes> notes = new List <AnimalHandlingNotes>(); var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_handling_notes_by_animal_id"); cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@AnimalID", SqlDbType.Int); cmd.Parameters["@AnimalID"].Value = animalID; try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { var note = new AnimalHandlingNotes(); note.HandlingNotesID = reader.GetInt32(0); note.UserID = reader.GetInt32(4); note.HandlingNotes = reader.GetString(1); note.TemperamentWarning = reader.GetString(2); note.UpdateDate = reader.GetDateTime(3); note.AnimalID = animalID; notes.Add(note); } } reader.Close(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(notes); }
/// <summary> /// Creator: Ben Hanna /// Created: 3/4/2020 /// Approver: Chuck Baxter, 3/5/2020 /// Approver: /// /// Updates a single handling notes record /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="oldNotes"></param> /// <param name="newNotes"></param> /// <returns> Number of rows effected </returns> public int UpdateAnimalHandlingNotes(AnimalHandlingNotes oldNotes, AnimalHandlingNotes newNotes) { int rows = 0; // connecttion var conn = DBConnection.GetConnection(); // cmd var cmd = new SqlCommand("sp_update_handling_notes_record"); cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; //Automatically assumes the value is an int32. Decimal and money are more ambiguous cmd.Parameters.AddWithValue("@AnimalHandlingNotesID", oldNotes.HandlingNotesID); cmd.Parameters.AddWithValue("@NewAnimalID", newNotes.AnimalID); cmd.Parameters.AddWithValue("@NewUserID", newNotes.UserID); cmd.Parameters.AddWithValue("@NewAnimalHandlingNotes", newNotes.HandlingNotes); cmd.Parameters.AddWithValue("@NewTemperamentWarning", newNotes.TemperamentWarning); cmd.Parameters.AddWithValue("@NewUpdateDate", newNotes.UpdateDate); cmd.Parameters.AddWithValue("@OldAnimalID", oldNotes.AnimalID); cmd.Parameters.AddWithValue("@OldUserID", oldNotes.UserID); cmd.Parameters.AddWithValue("@OldAnimalHandlingNotes", oldNotes.HandlingNotes); cmd.Parameters.AddWithValue("@OldTemperamentWarning", oldNotes.TemperamentWarning); cmd.Parameters.AddWithValue("@OldUpdateDate", oldNotes.UpdateDate); try { conn.Open(); rows = cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(rows); }
/// <summary> /// Creator: Ben Hanna /// Created: 2/21/2020 /// Approver: Carl Davis, 2/21/2020 /// Approver: Chuck Baxter, 2/21/2020 /// /// Select a single AnimalHandlingNotes record by it's primary key /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="handlingNotesID"></param> /// <returns>The animal handling notes object</returns> public AnimalHandlingNotes SelectHandlingNotesByID(int handlingNotesID) { AnimalHandlingNotes note = null; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_handling_notes_by_id"); cmd.Connection = conn; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@AnimalHandlingNotesID", handlingNotesID); try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows) { note = new AnimalHandlingNotes() { HandlingNotesID = handlingNotesID, AnimalID = reader.GetInt32(0), UserID = reader.GetInt32(4), HandlingNotes = reader.GetString(1), TemperamentWarning = reader.GetString(2), UpdateDate = reader.GetDateTime(3) }; } reader.Close(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(note); }
public void TestAddAnimalHandlingNotesFail() { // Arrange IAnimalHandlingManager handlingManager = new AnimalHandlingManager(_handlingAccessor); AnimalHandlingNotes notes = new AnimalHandlingNotes() { HandlingNotesID = 0, AnimalID = 1000000, UserID = 100000, HandlingNotes = "Notes notes notes notes", TemperamentWarning = "Very mean. No touch.", UpdateDate = DateTime.Now }; // Act bool actualResult = handlingManager.AddAnimalHandlingNotes(notes); //Assert }
public void TestAddAnimalHandlingNotesSuccess() { // Arrange IAnimalHandlingManager handlingManager = new AnimalHandlingManager(_handlingAccessor); const bool expectedResult = true; AnimalHandlingNotes notes = new AnimalHandlingNotes() { HandlingNotesID = 1, AnimalID = 1000000, UserID = 100000, HandlingNotes = "Notes notes notes notes", TemperamentWarning = "Very mean. No touch.", UpdateDate = DateTime.Now }; // Act bool actualResult = handlingManager.AddAnimalHandlingNotes(notes); // Assert Assert.AreEqual(expectedResult, actualResult); }
/// <summary> /// Creator: Ben Hanna /// Created: 3/2/2020 /// Approver: Chuck Baxter, 3/5/2020 /// Approver: /// /// Does the validation, then creates a handling record object and passes it to the manager class to be added to the database. /// Then, the button hides itself and unhides and reenables the original buttons /// </summary> /// <remarks> /// Updater: Ben Hanna /// Updated: 5/1/2020 /// Update: Added a validation fixes to verivy the animal ID exists in the DB /// Approver: Ryan Morganti, 5/3/2020 /// </remarks> /// <remarks> /// Updater: Ben Hanna /// Updated: 5/6/2020 /// Update: Made validation feedback more clear. /// Approver: Cash Carlson, 5/6/2020 /// </remarks> /// <param name="sender"></param> /// <param name="e"></param> private void btnSubmitHandlingRecord_Click(object sender, RoutedEventArgs e) { bool animalExists = false; int animalID; int userID; List <Animal> animals = _animalManager.RetrieveAllAnimalProfiles(); if (String.IsNullOrEmpty(txtAnimalID.Text)) { MessageBox.Show("Please enter the animal's ID."); return; } if (String.IsNullOrEmpty(txtHandlingNotes.Text)) { MessageBox.Show("Please enter some handling notes for this animal."); return; } if (String.IsNullOrEmpty(txtUserID.Text)) { MessageBox.Show("Please enter the Current User's ID."); return; } if (String.IsNullOrEmpty(txtTemperment.Text)) { MessageBox.Show("Please describe the temperament of the animal."); return; } if (!int.TryParse(txtAnimalID.Text, out animalID)) { MessageBox.Show("ID fields may only contain whole number values."); return; } else if (!int.TryParse(txtUserID.Text, out userID)) { MessageBox.Show("ID fields may only contain whole number values."); return; } else { foreach (Animal a in animals) { if (a.AnimalID == animalID) { animalExists = true; break; } } if (animalExists) { try { AnimalHandlingNotes newNotes = new AnimalHandlingNotes() { AnimalID = animalID, UserID = userID, HandlingNotes = txtHandlingNotes.Text, TemperamentWarning = txtTemperment.Text, UpdateDate = DateTime.Now }; if (_updateMode) { if (_handlingManager.EditAnimalHandlingNotes(_oldNotes, newNotes)) { MessageBox.Show("Record Edited Successfully.", "Result"); } RefreshHandlingNotes(); } else { if (_handlingManager.AddAnimalHandlingNotes(newNotes)) { MessageBox.Show("Data Added Successfully.", "Result"); } } } catch (Exception ex) { WPFErrorHandler.ErrorMessage(ex.Message + "\n\n" + ex.InnerException.Message); } finally { DeactivateEditingFields(); } } else { MessageBox.Show("Specified animal does not exist in Database."); return; } } }