Exemplo n.º 1
0
        /// <summary>
        /// Confirms if the user wants to delete the given availabilities.
        /// </summary>
        /// <param name="itemToDelete"></param>
        private void confirmDeleteAvailability(CurrentAvailabilities itemToDelete)
        {
            string startString = itemToDelete.BlockStartTime.ToShortDateString() + " " + itemToDelete.BlockStartTime.ToShortTimeString();
            string endString   = itemToDelete.BlockEndTime.ToShortDateString() + " " + itemToDelete.BlockEndTime.ToShortTimeString();


            string displayMessage = "Are you sure you want to delete: \n" + startString + " : " + endString + "\n and related schedules?";


            MessageBoxResult result = MessageBox.Show(displayMessage, "Alert", MessageBoxButton.YesNo);

            switch (result)
            {
            case MessageBoxResult.Yes:

                //remove the object from entity framework
                db.CurrentAvailabilities.Remove(itemToDelete);
                db.SaveChanges();
                MessageBox.Show("Availability and Schedules Deleted.");
                loadEmployeeData(SelectedStaff);

                break;

            case MessageBoxResult.No:
                break;
            }
        }
Exemplo n.º 2
0
            public CurrentSchedule       thisSchedule;     //the schedule, if it exists.


            public ScheduleItem(CurrentAvailabilities ta, CurrentSchedule ts = null)
            {
                thisAvailability = ta;
                thisSchedule     = ts;

                availableStartTime = thisAvailability.BlockStartTime;
                availableEndTime   = thisAvailability.BlockEndTime;


                //if sst is null, set is null, and vice versa

                if (ts != null)
                {
                    scheduleStartTime = thisSchedule.BlockStartTime;
                    scheduleEndTime   = (DateTime)thisSchedule.BlockEndTime;
                    scheduleString    = scheduleStartTime.ToShortTimeString() + " - " + scheduleEndTime.ToShortTimeString();
                }
                else
                {
                    scheduleStartTime = new DateTime();
                    scheduleEndTime   = new DateTime();
                    scheduleString    = "";
                }



                availabilityString = availableStartTime.ToShortTimeString() + " - " + availableEndTime.ToShortTimeString();
            }
 /// <summary>
 /// Cehcks if the availability is unique and the start and end times are in the right order.
 /// </summary>
 /// <param name="thisAvailability"></param>
 /// <returns></returns>
 private bool validAvailability(CurrentAvailabilities thisAvailability)
 {
     if (orderedAvailability(thisAvailability) && uniqueAvailability(thisAvailability))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
 /// <summary>
 /// Returns true if the availability is a ordered correctly (start occures before end).
 /// </summary>
 /// <param name="thisAvailability"></param>
 /// <returns></returns>
 private bool orderedAvailability(CurrentAvailabilities thisAvailability)
 {
     if (thisAvailability.BlockStartTime < thisAvailability.BlockEndTime)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
        /// <summary>
        /// Checks if a given availability falls within an existing availability, and if it's valid.
        /// </summary>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        private bool uniqueAvailability(CurrentAvailabilities thisAvailability)
        {
            //check for existing availabilities that overlap with the start time of the new one
            int startTimeOverlap = db.CurrentAvailabilities
                                   .Where(CA => CA.StaffId == thisAvailability.StaffId)
                                   .Where(CA => thisAvailability.BlockStartTime >= CA.BlockStartTime)
                                   .Where(CA => thisAvailability.BlockStartTime <= CA.BlockEndTime)
                                   .Count();

            if (startTimeOverlap != 0)
            {
                return(false);
            }
            else
            {
                //check fo existing availabilities that overlap iwth the end time of the new one.
                int endTimeOverlap = db.CurrentAvailabilities
                                     .Where(CA => CA.StaffId == thisAvailability.StaffId)
                                     .Where(CA => thisAvailability.BlockEndTime >= CA.BlockStartTime)
                                     .Where(CA => thisAvailability.BlockEndTime <= CA.BlockEndTime)
                                     .Count();

                if (endTimeOverlap != 0)
                {
                    return(false);
                }
                else
                {
                    //check for existing availabilities that occur within the start and end times of the new one.
                    int newEncompassesOld = db.CurrentAvailabilities
                                            .Where(CA => CA.StaffId == thisAvailability.StaffId)
                                            .Where(CA => thisAvailability.BlockStartTime <= CA.BlockStartTime)
                                            .Where(CA => thisAvailability.BlockEndTime >= CA.BlockEndTime)
                                            .Count();

                    if (newEncompassesOld != 0)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
        }
        //MARK: SETTING AN EXISTING AVAILABILITY

        /// <summary>
        /// The user selectes an existing availability
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ExistingAvailsCB_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            usingExistingAvailability = true;
            NewSchedETCB.IsEnabled    = true;
            NewSchedSTCB.IsEnabled    = true;

            currentAvailItem thisExistingAvailability = (currentAvailItem)ExistingAvailsCB.SelectedItem;

            existingAvailability = thisExistingAvailability.thisAvailability;

            if (newScheduleItem != null)
            {
                newScheduleItem.AvailabilityId = existingAvailability.Id;
                newScheduleItem.BlockStartTime = existingAvailability.BlockStartTime;
                newScheduleItem.BlockEndTime   = existingAvailability.BlockEndTime;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Handles the user deleting an availability
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteAvailability_Click(object sender, RoutedEventArgs e)
        {
            writeDebug("Deleting Availability");

            //Get the MenuItem
            var menuItem = (MenuItem)sender;

            //Get the ContextMenu to which the menuItem belongs
            var contextMenu = (ContextMenu)menuItem.Parent;

            //Find the item that was right clicked.
            var item = (DataGrid)contextMenu.PlacementTarget;

            //get the cells (the row) that was selected.
            ScheduleItem ScheduleItemToDelete = (ScheduleItem)item.SelectedCells[0].Item;

            CurrentAvailabilities availabilityToDelete = ScheduleItemToDelete.thisAvailability;


            confirmDeleteAvailability(availabilityToDelete);
        }
 public currentAvailItem(CurrentAvailabilities availability)
 {
     thisAvailability = availability;
     displayString    = thisAvailability.BlockStartTime.ToString() + " - " + thisAvailability.BlockEndTime.ToString();
 }