Exemplo n.º 1
0
 /// <summary>
 /// Creator: Michael Thompson
 /// Created: 2/19/2020
 /// Approver: Austin Gee
 /// Method to refresh the data grid
 /// </summary>
 /// <remarks>
 /// Updater:
 /// Updated:
 /// Update:
 /// </remarks>
 private void refreshData()
 {
     try
     {
         dgAnimalProfiles.ItemsSource = _animalManager.RetrieveAllAnimalProfiles();
     }
     catch (Exception ex)
     {
         WPFErrorHandler.ErrorMessage(ex.Message + "\n\n" + ex.InnerException.Message);
     }
 }
        /// <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;
                }
            }
        }