Esempio n. 1
0
        /// <summary>
        /// Removes a penalty sets on a croissant.
        /// </summary>
        /// <param name="date">Date to remove the penalty from.</param>
        public void RemovePenalty(DateTime date)
        {
            // Remove the penalties for this date
            var croissantsToUpdate = (from Croissant c in Croissants
                                      where c.Date.HasValue && c.Date.Value == date
                                      select c).ToList();

            foreach (var croissant in croissantsToUpdate)
            {
                croissant.Date = null;
            }

            // Sort the list of croissant to put the gaps to the right of the collection
            Croissants.BubbleSort(SortDirection.Ascending);

            // Update the list of penalties for this instance: simply remove the penalties at this date
            var penaltiesToRemove = (from p in PenaltiesAdded
                                     where p == date
                                     select p).ToList();

            foreach (var penalty in penaltiesToRemove)
            {
                PenaltiesAdded.Remove(penalty);
            }

            // TODO: Eventually, improve the removal of a penalty.
            // Right now, it is very simple: delete all penalties at this date. But it can have
            // consequences, especially it we remove a penalty on friday: 2 croissants are removed,
            // or 3 if the person didn't submit their CRA the whole week.
            // Plus, if we remove a penalty in the week and the person already has a penalty on friday
            // and didn't submit their CRA the rest of the week, the added "foutage de gueule" croissant
            // needs to be remove.
        }
Esempio n. 2
0
        /// <summary>
        /// Manages the adding of a penalty.
        /// </summary>
        /// <param name="date">Date to set the penalty on.</param>
        private void ProcessPenaltyAdding(DateTime date)
        {
            // If the person didn't reach their penalties limit, just add one.
            if (GetPenaltiesCount() < GetPenaltiesLimit())
            {
                // Search the index to place the date.
                var newDateIndex = 0;
                while (newDateIndex < GetLastDeactivatedIndex() && Croissants[newDateIndex].Date.HasValue && Croissants[newDateIndex].Date.Value <= date)
                {
                    newDateIndex++;
                }

                // Move the existing dates accordingly.
                for (int i = GetNextIndexToDeactivate(); i > newDateIndex; i--)
                {
                    Croissants[i].Date = Croissants[i - 1].Date;
                }

                Croissants[newDateIndex].Date = date;
            }
            // Otherwise, they have to bring the croissants!
            // Their penalties limit is consequently lowered by one.
            else
            {
                // Reset the date for each croissant.
                Croissants.Select(c => { c.Date = null; return(c); }).ToList();

                // Deactivate croissant.
                Croissants[GetNextIndexToDeactivate()].State = Croissant.CroissantState.IsDeactivated;

                HasToBringCroissants = true;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Adds a penalty to the line for the given date.
        /// </summary>
        /// <param name="date">Date to set the penalty on.</param>
        public void AddPenalty(DateTime date)
        {
            // Check that there is no existing penalty for the given date.
            // If that's the case, a penalty is added. Otherwise, the PenaltyAlreadyExistsAtThisDate event is raised.
            if (!Croissants.Any(c => c.Date.HasValue && c.Date.Value == date))
            {
                // Reordering the list of penalties in an ObservableCollection means new instanciation => add the new date at the correct index instead.

                int penaltiesToAdd = PenaltiesToAdd(date);

                for (int i = 0; i < penaltiesToAdd; i++)
                {
                    ProcessPenaltyAdding(date);
                }

                // A penalty was added for this instance
                // -> very simple processing...
                PenaltiesAdded.Add(date);
            }
            else
            {
                if (PenaltyAlreadyExistsAtThisDate != null)
                {
                    PenaltyAlreadyExistsAtThisDate(this, EventArgs.Empty);
                }
            }
        }