예제 #1
0
        /// <summary>
        /// Creator: Chuck Baxter
        /// Created: 3/18/2020
        /// Approver: Carl Davis, 3/18/2020
        /// Approver:
        ///
        /// The method when the submit add new species button is clicked, calls the animal manager
        /// to add it to the database
        /// <remarks>
        /// Updater:
        /// Updated:
        /// Update:
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSubmitAnimalAddSpecies_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(txtNewAnimalSpecies.Text))
            {
                MessageBox.Show("Please enter the new animal species");
                return;
            }
            if (String.IsNullOrEmpty(txtNewAnimalSpeciesDescription.Text))
            {
                MessageBox.Show("Please enter the animal species description");
                return;
            }

            try
            {
                if (_animalManager.AddNewAnimalSpecies(txtNewAnimalSpecies.Text, txtNewAnimalSpeciesDescription.Text))
                {
                    WPFErrorHandler.SuccessMessage("Animal Species Successfully Added");

                    canEditAnimalSpecies.Visibility = Visibility.Hidden;
                }
            }
            catch (Exception ex)
            {
                WPFErrorHandler.ErrorMessage(ex.Message + "\n\n" + ex.InnerException.Message);
                canEditAnimalSpecies.Visibility = Visibility.Hidden;
            }
        }
예제 #2
0
        /// <summary>
        /// Creator: Chuck Baxter
        /// Created: 3/18/2020
        /// Approver: Carl Davis, 3/18/2020
        /// Approver:
        ///
        /// The method when the submit update species button is clicked, calls the animal manager
        /// to update it in the database
        /// <remarks>
        /// Updater:
        /// Updated:
        /// Update:
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSubmitAnimalEditSpecies_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(cmbEditSpecies.Text))
            {
                MessageBox.Show("Please enter the animal species that you wish to update");
                return;
            }
            if (String.IsNullOrEmpty(txtEditAnimalSpecies.Text))
            {
                MessageBox.Show("Please enter the animal species that you wish to update");
                return;
            }
            if (String.IsNullOrEmpty(txtEditAnimalSpeciesDescription.Text))
            {
                MessageBox.Show("Please enter the animal species' description that you wish to update");
                return;
            }

            try
            {
                if (_animalManager.EditAnimalSpecies(cmbEditSpecies.Text, txtEditAnimalSpecies.Text, txtEditAnimalSpeciesDescription.Text))
                {
                    WPFErrorHandler.SuccessMessage("Animal Species Successfully Updated");
                    canEditAnimalSpecies.Visibility = Visibility.Hidden;
                }
            }
            catch (Exception ex)
            {
                WPFErrorHandler.ErrorMessage(ex.Message + "\n\n" + ex.InnerException.Message);
                canEditAnimalSpecies.Visibility = Visibility.Hidden;
                txtEditAnimalSpecies.Text       = "";
            }
        }
예제 #3
0
        /// <summary>
        /// Creator: Chuck Baxter
        /// Created: 3/12/2020
        /// Approver: Austin Gee, 3/12/2020
        /// Approver:
        ///
        /// The method that saves the edits to the animal
        /// </summary>
        /// <remarks>
        ///
        /// Updater:
        /// Updated:
        /// Update:
        /// </remarks>
        private void BtnSubmitAnimalEdit_Click(object sender, RoutedEventArgs e)
        {
            string arrival = cndEditArrivalDate.SelectedDate.ToString();
            string dob     = cndEditDob.SelectedDate.ToString();

            if (String.IsNullOrEmpty(txtEditAnimalName.Text))
            {
                MessageBox.Show("Please enter the animal's name");
                return;
            }
            if (String.IsNullOrEmpty(txtEditAnimalBreed.Text))
            {
                MessageBox.Show("Please enter the animal's breed");
                return;
            }
            if (String.IsNullOrEmpty(cmbEditAnimalSpecies.Text))
            {
                MessageBox.Show("Please enter the animal's species");
                return;
            }
            if (String.IsNullOrEmpty(arrival))
            {
                MessageBox.Show("Please enter the animal's arrival date");
                return;
            }
            if (String.IsNullOrEmpty(dob))
            {
                cndDob.SelectedDate = DateTime.Parse("01/01/2000");
                return;
            }

            Animal newAnimal = new Animal();

            newAnimal.AnimalName      = txtEditAnimalName.Text;
            newAnimal.AnimalSpeciesID = cmbEditAnimalSpecies.Text;
            newAnimal.AnimalBreed     = txtEditAnimalBreed.Text;
            newAnimal.ArrivalDate     = (DateTime)cndEditArrivalDate.SelectedDate;
            newAnimal.Dob             = (DateTime)cndEditDob.SelectedDate;

            try
            {
                if (_animalManager.EditAnimal(selectedAnimal, newAnimal))
                {
                    WPFErrorHandler.SuccessMessage("Animal Successfully Updated");

                    canViewAnimalList.Visibility = Visibility.Visible;
                    canEditAnimal.Visibility     = Visibility.Hidden;
                    refreshActiveData();
                    chkActive.IsChecked = false;
                }
            }
            catch (Exception ex)
            {
                WPFErrorHandler.ErrorMessage(ex.Message + "\n\n" + ex.InnerException.Message);
                canIndividualAnimal.Visibility = Visibility.Visible;
                canEditAnimal.Visibility       = Visibility.Hidden;
                refreshActiveData();
                chkActive.IsChecked = false;
            }
        }
        /// <summary>
        /// Creator: Lane Sandburg
        /// Created: 04/09/2020
        /// Approver: Jordan Lindo
        ///
        /// save button creates availbilities from lasi of availabilites
        /// </summary>
        /// <remarks>
        /// Updater:
        /// Updated:
        /// Update:
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSaveAvail_Click(object sender, RoutedEventArgs e)
        {
            bool isCreated = false;

            foreach (EmployeeAvailability availability in availabilities)
            {
                try
                {
                    isCreated = _employeeAvailabilityManager.CreateNewEmployeeAvailability(availability);
                }
                catch (Exception ex)
                {
                    WPFErrorHandler.ErrorMessage(ex.Message, "Validation");
                }
            }
            if (isCreated)
            {
                WPFErrorHandler.SuccessMessage("Create new user availability was successful");
            }


            canAddAvailability.Visibility = Visibility.Hidden;
            canUserView.Visibility        = Visibility.Visible;
            btnViewUserRoles.IsEnabled    = true;
        }
예제 #5
0
        /// <summary>
        /// Creator: Chuck Baxter
        /// Created: 4/16/2020
        /// Approver: Ethan Murphy, 4/16/2020
        ///
        /// Saving a new animal activity type
        /// </summary>
        /// <remarks>
        /// Updater:
        /// Updated:
        /// Update:
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreateActivtyTypeSave_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(txtActivityName.Text))
            {
                MessageBox.Show("Please enter the name of the new activity type.");
                return;
            }
            if (String.IsNullOrEmpty(txtActivityNotes.Text))
            {
                MessageBox.Show("Please enter the description of the new activity type.");
                return;
            }
            AnimalActivityType animalActivityType = new AnimalActivityType();

            animalActivityType.ActivityTypeId = txtActivityName.Text;
            animalActivityType.Description    = txtActivityNotes.Text;

            try
            {
                if (_activityManager.AddAnimalActivityType(animalActivityType))
                {
                    WPFErrorHandler.SuccessMessage("Activity Type Successfully Added");
                    cmbActivityType.ItemsSource   = _activityManager.RetrieveAllAnimalActivityTypes().Select(a => a.ActivityTypeId);
                    cmbActivityType.SelectedIndex = 0;
                    canActivityTypes.Visibility   = Visibility.Hidden;
                }
            }
            catch (Exception ex)
            {
                WPFErrorHandler.ErrorMessage(ex.Message + "\n\n" + ex.InnerException.Message);
                canActivityTypes.Visibility = Visibility.Hidden;
            }
        }
예제 #6
0
        /// <summary>
        /// Creator: Zoey McDonald
        /// Created: 3/2/2020
        /// Approver: Timothy Lickteig
        ///
        /// Makes sure the data is submited when clicked.
        /// </summary>
        /// <remarks>
        /// Updater:
        /// Updated:
        /// Update:
        /// </remarks>
        private void BtnSubmitTreatmentRecordAdd_Click(object sender, RoutedEventArgs e)
        {
            string treatmentDate = cndTreatmentDate.SelectedDate.ToString();

            if (String.IsNullOrEmpty(txtFormName.Text))
            {
                MessageBox.Show("Please enter the form name");
                return;
            }
            if (String.IsNullOrEmpty(txtTreatmentDescription.Text))
            {
                MessageBox.Show("Please enter the treatment description");
                return;
            }
            if (String.IsNullOrEmpty(txtReason.Text))
            {
                MessageBox.Show("Please enter the reason for the animal's treatment");
                return;
            }
            if (String.IsNullOrEmpty(txtUrgency.Text))
            {
                MessageBox.Show("Please enter the urgency for the animal's treatment");
                return;
            }

            TreatmentRecord newTreatmentRecord = new TreatmentRecord();

            newTreatmentRecord.VetID                = txtVetID.Text;
            newTreatmentRecord.FormName             = txtFormName.Text;
            newTreatmentRecord.TreatmentDescription = txtTreatmentDescription.Text;
            newTreatmentRecord.Notes                = txtNotes.Text;
            newTreatmentRecord.Reason               = txtReason.Text;
            newTreatmentRecord.TreatmentDate        = cndTreatmentDate.DisplayDate;

            try
            {
                if (_treatmentRecordManager.AddNewTreatmentRecord(newTreatmentRecord))
                {
                    WPFErrorHandler.SuccessMessage("Animal Successfully Added");

                    canViewTreatmentRecords.Visibility = Visibility.Visible;
                    canAddTreatmentRecord.Visibility   = Visibility.Hidden;
                    dgTreatmentRecords.Visibility      = Visibility.Visible;
                    refreshTreatmentRecordData();
                }
            }
            catch (Exception ex)
            {
                WPFErrorHandler.ErrorMessage(ex.Message + "\n\n" + ex.InnerException.Message);
                canViewTreatmentRecords.Visibility = Visibility.Visible;
                canAddTreatmentRecord.Visibility   = Visibility.Hidden;
            }
        }
예제 #7
0
        /// <summary>
        /// Creator: Jordan Lindo
        /// Created: 4/1/2020
        /// Approver: Chase Schulte
        ///
        /// This saves the changes made to a temporary list.
        /// </summary>
        /// <remarks>
        /// Updater:
        /// Updated:
        /// Update:
        ///
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            BaseScheduleLine selected = (BaseScheduleLine)dgBaseSchedule.SelectedItem;
            bool             done     = false;

            for (int i = 0; i < _newLines.Count && !done; i++)
            {
                if (_newLines.ElementAt(i).ShiftTimeID.Equals(selected.ShiftTimeID) && _newLines.ElementAt(i).ERoleID.Equals(selected.ERoleID))
                {
                    _newLines.ElementAt(i).Count = cboCount.SelectedIndex;
                    done = true;
                }
            }
            WPFErrorHandler.SuccessMessage(selected.ERoleID + " count set to " + cboCount.SelectedIndex);
            setDataGird();
            canEditBaseSchedule.Visibility = Visibility.Hidden;
            canBaseSchedule.Visibility     = Visibility.Visible;
        }
        /// <summary>
        /// Creator: Ben Hanna
        /// Created: 3/18/2020
        /// Approver: Carl Davis, 3/19/2020
        /// Approver: 
        /// 
        /// Triggers the logic to add the DateOut field to the record
        /// </summary>
        /// <remarks>
        /// Updater:
        /// Updated:
        /// Update:
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddDateOut_Click(object sender, RoutedEventArgs e)
        {
            oldKennel.AnimalKennelDateOut = DateTime.Now;

            try
            {
                if (_kennelManager.SetDateOut(oldKennel))
                {
                    btnAddDateOut.IsEnabled = false;
                    txtDateOut.Text = oldKennel.AnimalKennelDateOut.ToString();

                    WPFErrorHandler.SuccessMessage("Date Out successfully addded.");
                }
            }
            catch (Exception ex)
            {
                WPFErrorHandler.ErrorMessage(ex.Message + "\n\n" + ex.InnerException);
            }
        }
        /// <summary>
        /// Creator: Jordan Lindo
        /// Created: 2/15/2020
        /// Approver: Alex Diers
        ///
        /// This button click listener sends the data for creating a new department record to the logic layer
        /// </summary>
        /// <remarks>
        /// Updater: NA
        /// Updated: NA
        /// Update: NA
        ///
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddDepartmentSave_Click(object sender, RoutedEventArgs e)
        {
            string departmentID = txtAddDepartmentDepartmentName.Text;
            string description  = txtAddDepartmentDescription.Text;

            if (ValidateERole.checkDepartmentID(departmentID) && ValidateERole.checkDescription(description))
            {
                try
                {
                    if (_departmentManager.AddDepartment(departmentID, description))
                    {
                        ShiftTimeManager _shiftTimeManger = new ShiftTimeManager();
                        try
                        {
                            foreach (PetUniverseShiftTime shiftTime in DEFAULT_SHIFTTIMES)
                            {
                                shiftTime.DepartmentID = departmentID;
                                _shiftTimeManger.AddShiftTime(shiftTime);
                            }
                        }
                        catch (Exception ex)
                        {
                            WPFErrorHandler.ErrorMessage("failed to save departments Default Shift Times. " + ex.Message);
                        }

                        WPFErrorHandler.SuccessMessage("Department added, with default shift times");
                        canAddDepartment.Visibility  = Visibility.Hidden;
                        canDepartmentList.Visibility = Visibility.Visible;
                        showDGDepartments();
                    }
                    else
                    {
                        WPFErrorHandler.ErrorMessage("Department not added.");
                    }
                }
                catch (Exception ex)
                {
                    WPFErrorHandler.ErrorMessage("Department failed to save. " + ex.Message);
                }
            }
예제 #10
0
        /// <summary>
        /// Creator: Michael Thompson
        /// Created: 2/19/2020
        /// Approver: Austin Gee
        ///
        /// Method to validate that there is a description and a photo path and sends that data to the database
        /// </summary>
        /// <remarks>
        /// Updater: Michael Thompsom
        /// Updated: 4/28/2020
        /// Update: To book specifications
        /// Approver: Austin Gee
        /// </remarks>
        private void BtnSubmitAnimalUpdate_Click(object sender, RoutedEventArgs e)
        {
            if (currentPetProfile.Source != null)
            {
                if (String.IsNullOrEmpty(txtAnimalProfileDescription.Text))
                {
                    MessageBox.Show("Please enter the animal's profile description");
                    return;
                }

                var    selectedItem = dgAnimalProfiles.SelectedItem;
                string ID           = (dgAnimalProfiles.SelectedCells[0].Column.GetCellContent(selectedItem) as TextBlock).Text;
                try
                {
                    int animalID = Int32.Parse(ID);

                    string profileDescription   = txtAnimalProfileDescription.Text;
                    byte[] profileImage         = imgToByteArray(currentPetProfile.Source as BitmapImage);
                    string profileImageMimeType = "jpg";
                    _animalManager.UpdatePetProfile(animalID, profileDescription, profileImage, profileImageMimeType);
                    WPFErrorHandler.SuccessMessage("Animal Successfully Updated");
                    ClearDisplay();
                }
                catch (Exception ex)
                {
                    WPFErrorHandler.ErrorMessage(ex.Message + "\n\n" + ex.InnerException.Message);
                    ClearDisplay();
                }
                currentPetProfile.Source = new BitmapImage();
                lblAnimalBreed.Content   = "";
                lblAnimalName.Content    = "";
                txtAnimalProfileDescription.Clear();
                lblAnimalSpecies.Content = "";
            }
            else
            {
                WPFErrorHandler.ErrorMessage("Please supply an Image");
            }
        }
예제 #11
0
        /// <summary>
        /// Creator: Jordan Lindo
        /// Created: 4/1/2020
        /// Approver: Chase Schulte
        ///
        /// This stores the changes in the data store.
        /// </summary>
        /// <remarks>
        /// Updater:
        /// Updated:
        /// Update:
        ///
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSetBaseSchedule_Click(object sender, RoutedEventArgs e)
        {
            BaseScheduleVM newBaseScheduleVM = new BaseScheduleVM
            {
                BaseScheduleLines = _newLines,
                CreatingUserID    = _user.PUUserID,
                CreationDate      = DateTime.Now
            };

            try
            {
                _baseScheduleManager.AddBaseSchedule(newBaseScheduleVM);
                getBaseScheduleVM();
                WPFErrorHandler.SuccessMessage("Base Schedule Added.");
                setNewLines();
                setDataGird();
            }
            catch (Exception ex)
            {
                WPFErrorHandler.ErrorMessage("Schedule not added. " + ex.Message);
            }
        }
예제 #12
0
        /// <summary>
        /// Creator: Chuck Baxter
        /// Created: 4/16/2020
        /// Approver: Ethan Murphy, 4/16/2020
        ///
        /// Deleting animal activity type
        /// </summary>
        /// <remarks>
        /// Updater:
        /// Updated:
        /// Update:
        /// </remarks
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDeleteActivtyTypeSave_Click(object sender, RoutedEventArgs e)
        {
            AnimalActivityType animalActivityType = new AnimalActivityType();

            animalActivityType.ActivityTypeId = (string)cmbSelectActivityType.SelectedItem;
            try
            {
                if (_activityManager.DeleteAnimalActivityType(animalActivityType))
                {
                    WPFErrorHandler.SuccessMessage("Activity Type Successfully Deleted");
                    cmbActivityType.ItemsSource   = _activityManager.RetrieveAllAnimalActivityTypes().Select(a => a.ActivityTypeId);
                    cmbActivityType.SelectedIndex = 0;
                    canActivityTypes.Visibility   = Visibility.Hidden;
                }
            }
            catch (Exception ex)
            {
                WPFErrorHandler.ErrorMessage(ex.Message + "\n\n"
                                             + "Make sure you are not attempting to delete an activity type that has records."
                                             + "\n\n" + ex.InnerException.Message);
                canActivityTypes.Visibility = Visibility.Hidden;
            }
        }
예제 #13
0
        /// <summary>
        /// Creator: Chuck Baxter
        /// Created: 3/18/2020
        /// Approver: Carl Davis, 3/18/2020
        /// Approver:
        ///
        /// The method when the submit delete species button is clicked, calls the animal manager
        /// to delete it from the database
        /// <remarks>
        /// Updater:
        /// Updated:
        /// Update:
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSubmitAnimalDeleteSpecies_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(cmbDeleteSpecies.Text))
            {
                MessageBox.Show("Please enter the animal species that you wish to delete");
                return;
            }

            try
            {
                if (_animalManager.DeleteAnimalSpecies(cmbDeleteSpecies.Text))
                {
                    WPFErrorHandler.SuccessMessage("Animal Species Successfully Deleted");

                    canEditAnimalSpecies.Visibility = Visibility.Hidden;
                }
            }
            catch (Exception ex)
            {
                WPFErrorHandler.ErrorMessage(ex.Message + "\n\n" + "no animals can be this species before deletion" + "\n\n" + ex.InnerException.Message);
                canEditAnimalSpecies.Visibility = Visibility.Hidden;
            }
        }
        /// <summary>
        /// Creator: Ben Hanna
        /// Created: 4/2/2020
        /// Approver: Carl Davis 4/4/2020
        /// Approver:
        ///
        /// The button that triggers the process for saving record data.
        /// </summary>
        /// <remarks>
        /// Updater:
        /// Updated:
        /// Update:
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSubmitCleaningRecord_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtUserID.Text) || !int.TryParse(txtUserID.Text, out int num1))
            {
                MessageBox.Show("Please enter a valid user id");
                return;
            }
            if (string.IsNullOrEmpty(txtKennelID.Text) || !int.TryParse(txtKennelID.Text, out int num2))
            {
                MessageBox.Show("Please enter a valid kennel id");
                return;
            }
            if (string.IsNullOrEmpty(cndCleaningDate.SelectedDate.ToString()))
            {
                MessageBox.Show("Please select the cleaning date");
                return;
            }
            if (txtNotes.Text.Length > 250)
            {
                MessageBox.Show("Notes field is too long. Please enter again.");
                return;
            }

            try
            {
                AnimalKennelCleaningRecord newCleaningRecord = new AnimalKennelCleaningRecord
                {
                    UserID         = num1,
                    AnimalKennelID = num2,
                    Date           = (DateTime)cndCleaningDate.SelectedDate,
                    Notes          = txtNotes.Text
                };
                if (isAddMode)
                {
                    if (_cleaningManager.AddKennelCleaningRecord(newCleaningRecord))
                    {
                        WPFErrorHandler.SuccessMessage("Cleaning Record successfully added.");
                        CloseCleaningCanvas();
                    }
                    else
                    {
                        MessageBox.Show("Cleaning record was not added.");
                    }
                }
                else
                {
                    if (_cleaningManager.EditKennelCleaningRecord(_oldCleaningRecord, newCleaningRecord))
                    {
                        WPFErrorHandler.SuccessMessage("Cleaning Record successfully edited.");
                        CloseCleaningCanvas();
                    }
                    else
                    {
                        MessageBox.Show("Cleaning record was not edited.");
                    }
                }
            }
            catch (Exception ex)
            {
                WPFErrorHandler.ErrorMessage(ex.Message, "Save");
            }
        }
        /// <summary>
        /// Creator: Ben Hanna
        /// Created: 2/22/2020
        /// Approver: Steven Cardona
        /// Approver:
        /// 
        /// Add animal kennel location record to the database 
        /// </summary>
        /// <remarks>
        /// Updater: Ben Hanna
        /// Updated: 3/17/2020
        /// Update: Added an extra code path for editing as opposed to adding.
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSubmitKennelAdd_Click(object sender, RoutedEventArgs e)
        {
            int userID;
            int animalID;

            if (String.IsNullOrEmpty(txtAnimalID.Text))
            {
                MessageBox.Show("Please enter the animal's ID");
                return;
            }
            if (String.IsNullOrEmpty(txtUserID.Text))
            {
                MessageBox.Show("Please enter the User's ID");
                return;
            }
            if (!int.TryParse(txtAnimalID.Text, out animalID))
            {
                MessageBox.Show("ID fields may only contain whole numbers.");
                return;
            }
            else if (!int.TryParse(txtUserID.Text, out userID))
            {
                MessageBox.Show("ID fields may only contain whole numbers.");
                return;
            }
            else
            {

                AnimalKennel newKennel = new AnimalKennel()
                {
                    AnimalID = animalID,
                    UserID = userID,
                    AnimalKennelInfo = txtKennelInfo.Text
                };

                try
                {
                    if (addMode)
                    {
                        newKennel.AnimalKennelDateIn = DateTime.Now;
                        _kennelManager.AddKennelRecord(newKennel);
                        WPFErrorHandler.SuccessMessage("Kennel Record Successfully Added");
                    }
                    else
                    {
                        newKennel.AnimalKennelDateIn = oldKennel.AnimalKennelDateIn;
                        newKennel.AnimalKennelDateOut = oldKennel.AnimalKennelDateOut;
                        _kennelManager.EditKennelRecord(oldKennel, newKennel);
                        WPFErrorHandler.SuccessMessage("Kennel Record Successfully Edited");
                    }

                    ResetFields();
                }
                catch (Exception ex)
                {
                    WPFErrorHandler.ErrorMessage(ex.Message + "\n\n" + ex.InnerException.Message);
                }
                finally
                {
                    oldKennel = null;
                    RefreshData();

                }
                canView.Visibility = Visibility.Visible;
                canAddRecord.Visibility = Visibility.Hidden;
            }
        }
예제 #16
0
        /// <summary>
        /// Creator: Kaleb Bachert
        /// Created: 4/28/2020
        /// Approver:
        ///
        /// Updates the Shift in the Database if a User was Selected
        /// </summary>
        /// <remarks>
        /// Updater: NA
        /// Updated: NA
        /// Update: NA
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            //No Replacement Employee is selected
            if (cmbShiftReplacementEmployees.SelectedItem.Equals("-- Select a Replacement --"))
            {
                WPFErrorHandler.ErrorMessage("You must first select a replacement Employee. If no replacement Employees appear, none fit the criteria for replacement.", "Input");
            }
            //Replacement Employee is selected
            else
            {
                //The date, startTime and endTime of the shift, and the length of the shift in hours
                DateTime shiftDate = Convert.ToDateTime(txtShiftDate.Text);
                TimeSpan startTime = TimeSpan.Parse(txtShiftStartTime.Text);
                TimeSpan endTime   = TimeSpan.Parse(txtShiftEndTime.Text);
                double   shiftHours;

                //If the shift stays in a single day
                if (endTime > startTime)
                {
                    shiftHours = (endTime - startTime).TotalHours;
                }
                //The Shift starts the previous night, and ends in the morning
                else
                {
                    //Last second of the night
                    TimeSpan dayEnd = new TimeSpan(23, 59, 59);
                    //First second of the morning
                    TimeSpan dayStart = new TimeSpan(0, 0, 0);

                    //Get difference between end of shift and start of day, add it to difference between start of shift and end of night
                    shiftHours = (endTime - dayStart).TotalHours + (dayEnd - startTime).TotalHours;
                }

                try
                {
                    //Converts selected Email (replacement User) to a PetUniverseUser
                    PetUniverseUser replacementUser = _userManager.getUserByEmail(cmbShiftReplacementEmployees.SelectedItem.ToString());

                    //Gets the start and end date of the schedule the shift is in, used to determine the hours worked that week
                    ScheduleWithHoursWorked scheduleContainingTheShift = _shiftManager.RetrieveScheduleHoursByUserAndDate(replacementUser.PUUserID, shiftDate);

                    //This will be the hours worked if the Shift change is confirmed
                    double projectedHoursWorked;

                    //The week of the schedule that this shift is in, 1 or 2
                    int weekNumber;

                    //If shiftDate is before the second Sunday of the Schedule
                    if (shiftDate < scheduleContainingTheShift.ScheduleStartDate.AddDays(7))
                    {
                        projectedHoursWorked = scheduleContainingTheShift.FirstWeekHours + shiftHours;
                        weekNumber           = 1;
                    }
                    //ShiftDate is on or after the second Sunday of the Schedule
                    else
                    {
                        projectedHoursWorked = scheduleContainingTheShift.SecondWeekHours + shiftHours;
                        weekNumber           = 2;
                    }

                    MessageBoxResult confirmApproval;

                    //The User will have more than 40 hours that week if this is approved
                    if (projectedHoursWorked > 40)
                    {
                        confirmApproval = MessageBox.Show("This change will set " + replacementUser.FirstName.ToUpper() + " " + replacementUser.LastName.ToUpper() +
                                                          "'s" + Environment.NewLine + "hours for the week to: " + projectedHoursWorked + Environment.NewLine +
                                                          "Are you certain you want to commit this schedule change?" + Environment.NewLine + "THIS ACTION CANNOT BE UNDONE!",
                                                          "Confirm Approval?", MessageBoxButton.YesNo, MessageBoxImage.Question);
                    }
                    //Hours will not go over 40
                    else
                    {
                        confirmApproval = MessageBox.Show("Are you certain you want to give " + replacementUser.FirstName.ToUpper() + " " + replacementUser.LastName.ToUpper() +
                                                          " this shift?" + Environment.NewLine + "THIS ACTION CANNOT BE UNDONE!", "Confirm Approval?", MessageBoxButton.YesNo, MessageBoxImage.Question);
                    }

                    //Shift change Confirmed and ready to be replaced with the selected replacement Employee
                    if (confirmApproval == MessageBoxResult.Yes)
                    {
                        int originalEmployeeID = _shiftVm.EmployeeID;

                        //Decrease old employee's hours worked, increase the new employee's hours, save the new employee in the Shift's User field
                        _shiftManager.EditEmployeeHoursWorked(originalEmployeeID, scheduleContainingTheShift.ScheduleID, weekNumber, shiftHours * -1);
                        _shiftManager.EditEmployeeHoursWorked(replacementUser.PUUserID, scheduleContainingTheShift.ScheduleID, weekNumber, shiftHours);
                        _shiftManager.EditShiftUserWorking(_shiftVm.ShiftID, replacementUser.PUUserID, originalEmployeeID);

                        WPFErrorHandler.SuccessMessage("Shift Change Successful!");

                        //Return to View Schedule page
                        this.DialogResult = true;
                    }
                }
                catch (Exception ex)
                {
                    WPFErrorHandler.ErrorMessage(ex.InnerException.Message, ex.Message);
                    this.Close();
                }
            }
        }
        /// <summary>
        /// Creator: Steven Cardona
        /// Created: 02/10/2020
        /// Approver: Zach Behrensmeyer
        ///
        /// Create a new user by clicking save
        /// </summary>
        /// <remarks>
        /// Updater: Steven Cardona
        /// Updated: 03/01/2020
        /// Update: Added Address validation checks
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSaveUser_Click(object sender, RoutedEventArgs e)
        {
            bool isCreated = false;

            PetUniverseUser newUser = new PetUniverseUser();

            // Validate First Name
            if (!txtFirstName.Text.IsValidFirstName())
            {
                "First Name cannot be blank".ErrorMessage("Validation");
                //WPFErrorHandler.ErrorMessage("First name cannot be blank", "Validation");
                txtFirstName.Text = "";
                txtFirstName.Focus();
                return;
            }
            else
            {
                newUser.FirstName = txtFirstName.Text;
            }

            // Validate Last Name
            if (!txtLastName.Text.IsValidLastName())
            {
                WPFErrorHandler.ErrorMessage("Last name cannot be blank", "Validation");
                txtLastName.Text = "";
                txtLastName.Focus();
                return;
            }
            else
            {
                newUser.LastName = txtLastName.Text;
            }

            // Validate Email
            if (!txtEmail.Text.IsValidEmail())
            {
                WPFErrorHandler.ErrorMessage("Invalid email address", "Validation");
                txtEmail.Text = "";
                txtEmail.Focus();
                return;
            }
            else
            {
                newUser.Email = txtEmail.Text;
            }

            // Validate Phone Number
            try
            {
                if (!txtPhoneNumber.Value.ToString().IsValidPhoneNumber())
                {
                    WPFErrorHandler.ErrorMessage("Invalid Phone Number", "Validation");
                    txtPhoneNumber.Text = "";
                    txtPhoneNumber.Focus();
                    return;
                }
                else
                {
                    newUser.PhoneNumber = txtPhoneNumber.Value.ToString();
                }
            }
            catch (Exception ex)
            {
                WPFErrorHandler.ErrorMessage(ex.Message, "Validation");
                txtPhoneNumber.Text = "";
                txtPhoneNumber.Focus();
                return;
            }

            // Validate City
            if (!txtCity.Text.IsValidCity())
            {
                string message = string.IsNullOrEmpty(txtCity.Text)
                    ? "City cannot be blank"
                    : "City must be less than 20 characters long";
                WPFErrorHandler.ErrorMessage(message, "Validation");
                txtCity.Text = "";
                txtCity.Focus();
                return;
            }
            else
            {
                newUser.City = txtCity.Text;
            }

            // Validate State
            if (cmbState.SelectedItem == null || !cmbState.SelectedItem.ToString().IsValidState())
            {
                WPFErrorHandler.ErrorMessage("Please select a state", "Validation");
                cmbState.Focus();
                return;
            }
            else
            {
                newUser.State = cmbState.SelectedItem.ToString();
            }

            // Validate Zipcode
            try
            {
                if (!txtZipcode.Text.IsValidState())
                {
                    WPFErrorHandler.ErrorMessage("Invalid Zipcode", "Validation");
                    txtZipcode.Text = "";
                    txtZipcode.Focus();
                    return;
                }
                else
                {
                    newUser.ZipCode = txtZipcode.Text;
                }
            }
            catch (Exception ex)
            {
                WPFErrorHandler.ErrorMessage(ex.Message, "Validation");
            }

            try
            {
                if (!txtAddress1.Text.IsValidAddress1())
                {
                    WPFErrorHandler.ErrorMessage("Invalid Address Line 1", "Validation");
                    txtAddress1.Text = "";
                    txtAddress1.Focus();
                    return;
                }
                else
                {
                    newUser.Address1 = txtAddress1.Text;
                }
            }
            catch (Exception ex)
            {
                WPFErrorHandler.ErrorMessage(ex.Message, "Validation");
            }

            try
            {
                if (!txtAddress1.Text.IsValidAddress2())
                {
                    WPFErrorHandler.ErrorMessage("Invalid Address Line 2", "Validation");
                    txtAddress2.Text = "";
                    txtAddress2.Focus();
                    return;
                }
                else
                {
                    if (!string.IsNullOrEmpty(txtAddress2.Text))
                    {
                        newUser.Address2 = txtAddress2.Text;
                    }
                    else
                    {
                        newUser.Address2 = null;
                    }
                }
            }
            catch (Exception ex)
            {
                WPFErrorHandler.ErrorMessage(ex.Message, "Validation");
            }

            newUser.Active = (bool)chkActive.IsChecked;

            try
            {
                if (_editMode == true && _originalUser == null)
                {
                    isCreated = _userManager.CreateNewUser(newUser);
                    if (isCreated)
                    {
                        WPFErrorHandler.SuccessMessage("Create new user was successful, add starting availability.");

                        canAddUser.Visibility = Visibility.Hidden;

                        canAddAvailability.Visibility = Visibility.Visible;
                    }
                    canAddUser.Visibility = Visibility.Hidden;
                }
                else if (_editMode == true && _originalUser != null)
                {
                    bool isUpdated = _userManager.UpdateUser(_originalUser, newUser);
                    if (isUpdated)
                    {
                        WPFErrorHandler.SuccessMessage("Information was updated for " + newUser.FirstName + " " +
                                                       newUser.LastName);
                    }

                    canAddUser.Visibility  = Visibility.Hidden;
                    canUserView.Visibility = Visibility.Visible;
                }

                deactivateEditMode();
                RefreshDgUserList();
            }
            catch (Exception ex)
            {
                LogicLayerErrorHandler.UserCreationErrorMessage(ex.Message, ex.InnerException.Message);
            }
        }
        /// <summary>
        ///     AUTHOR: Timothy Lickteig
        ///     DATE: 2020-02-06
        ///     DESCRIPTION: Event handler for the submit button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSubmitButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.txtShiftTitle.Text == "Shift Title" || this.txtShiftTitle.Text == "")
            {
                MessageBox.Show("Shift Title Cannot be Blank");
            }
            else if (null == this.dteShiftDate.SelectedDate)
            {
                MessageBox.Show("Shift Date Cannot be Blank");
            }
            else if (this.txtShiftDescription.Text == "Shift Description" || this.txtShiftDescription.Text == "")
            {
                MessageBox.Show("Shift Description Cannot be Blank");
            }
            else if ((DateTime.Compare((DateTime)dteShiftDate.SelectedDate, DateTime.Now.Date)) < 0)
            {
                MessageBox.Show("Shift Date cannot be before today");
            }
            else
            {
                if (this.txtShiftNotes.Text == "Shift Notes")
                {
                    this.txtShiftNotes.Text = "";
                }

                int startHour   = Convert.ToInt32(this.cboShiftStartHour.SelectedItem);
                int startMinute = Convert.ToInt32(this.cboShiftStartMinute.SelectedItem);
                if ((string)this.cboShiftStartAMorPM.SelectedItem == "PM")
                {
                    startHour = startHour + 12;
                }
                if (startHour == 24)
                {
                    startHour = 12;
                }
                else if (startHour == 12)
                {
                    startHour = 0;
                }

                int endHour   = Convert.ToInt32(this.cboShiftEndHour.SelectedItem);
                int endMinute = Convert.ToInt32(this.cboShiftEndMinute.SelectedItem);
                if ((string)this.cboShiftEndAMorPM.SelectedItem == "PM")
                {
                    endHour = endHour + 12;
                }
                if (endHour == 24)
                {
                    endHour = 12;
                }
                else if (endHour == 12)
                {
                    endHour = 0;
                }

                _volunteerShift.IsSpecialEvent     = (bool)chkIsSpecialEvent.IsChecked;
                _volunteerShift.Recurrance         = (string)cboRecurrance.SelectedItem;
                _volunteerShift.ShiftDescription   = txtShiftDescription.Text;
                _volunteerShift.ShiftStartTime     = new TimeSpan(startHour, startMinute, 0);
                _volunteerShift.ShiftEndTime       = new TimeSpan(endHour, endMinute, 0);
                _volunteerShift.ShiftNotes         = txtShiftNotes.Text;
                _volunteerShift.ShiftTitle         = txtShiftTitle.Text;
                _volunteerShift.VolunteerShiftDate = (DateTime)dteShiftDate.SelectedDate;

                try
                {
                    if ((_volunteerShiftAccessor.AddVolunteerShift(_volunteerShift)) == 1)
                    {
                        WPFErrorHandler.SuccessMessage("Shift Added");
                    }
                    else
                    {
                        MessageBox.Show("Shift Failed to Add");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }