private void button_Click(object sender, RoutedEventArgs e)
 {
     workingShift             = new WorkingShift();
     workingShift.start       = DateTime.Now;
     workingShift.end         = null;
     workingShift.description = "Test Plinio Sacchetti";
     workingShift.idPerson    = 1;
     bd.WorkingShifts.Add(workingShift);
     bd.SaveChanges();
 }
        /// <summary>
        /// Remove from database the workingshifts listed in the paramater.
        /// (if the workingShif id is in the list then it is removed)
        /// </summary>
        /// <param name="wsList">List of WorkingShift to remove</param>
        /// <param name="bd">database</param>
        public static void RemoveWorkingShiftDataBase(List <WorkingShift> wsList, bd_easyplannerEntities bd)
        {
            WorkingShift wsRemove = null;

            foreach (WorkingShift ws in wsList)
            {
                wsRemove = bd.WorkingShifts.Find(ws.idShift);
                if (wsRemove != null)
                {
                    bd.WorkingShifts.Remove(wsRemove);
                }
            }

            bd.SaveChanges();
        }
示例#3
0
        /// <summary>
        /// Generating of the workingshifts from the calculated flows
        /// </summary>
        /// <returns>List of coherents shifts given the constructed graph</returns>
        public Tuple <List <WorkingShift>, List <string> > GetShifts()
        {
            List <WorkingShift> shifts   = new List <WorkingShift>();
            List <string>       problems = new List <string>();

            CalculateMaximumFlow();

            // init quotas dict
            Dictionary <ScheduleSlot, List <Tuple <Person, double> > > quotas = new Dictionary <ScheduleSlot, List <Tuple <Person, double> > >();

            foreach (FlowNode node in this.Nodes)
            {
                if (node.Type == FlowNodeType.Slot)
                {
                    quotas.Add(((SlotFlowNode)node).Slot, new List <Tuple <Person, double> >());
                }
            }

            // recup quotas
            foreach (KeyValuePair <FlowArc, double> flowDict in this.Flows)
            {
                FlowArc arc = flowDict.Key; double flow = flowDict.Value;
                switch (arc.Start.Type)
                {
                case FlowNodeType.Virtual:
                    // si flow < capacité alors personne pas complètement occupée => trop de RH
                    if (flow < arc.Capacity)
                    {
                        Person person  = ((PersonFlowNode)arc.End).Person;
                        string problem = person.firstName + " " + person.name + " : " +
                                         (arc.Capacity - flow) + " heure(s) manquante(s) pour atteindre " + person.occupancyRate + "%";
                        problems.Add(problem);
                    }
                    break;

                case FlowNodeType.Person:
                    if (flow > 0)
                    {
                        quotas[((SlotFlowNode)arc.End).Slot].Add(new Tuple <Person, double>(((PersonFlowNode)arc.Start).Person, flow));
                    }
                    break;

                case FlowNodeType.Slot:
                    // si flow < capacité alors plage pas complètement couverte => pas assez de RH
                    if (flow < arc.Capacity)
                    {
                        ScheduleSlot slot    = ((SlotFlowNode)arc.Start).Slot;
                        string       problem = DateTimeFormatInfo.CurrentInfo.GetDayName((DayOfWeek)Enum.GetValues(typeof(DayOfWeek)).GetValue(slot.dayOfWeek)) +
                                               " " + slot.startHour.ToString(@"hh\:mm") + " - " + slot.endHour.ToString(@"hh\:mm") + " : " +
                                               (arc.Capacity - flow) + " heure(s) manquante(s) pour remplir " + slot.minAttendency + " présence(s)";
                        problems.Add(problem);
                    }
                    break;

                default:
                    break;
                }
            }

            // create shifts
            foreach (KeyValuePair <ScheduleSlot, List <Tuple <Person, double> > > quotaDict in quotas)
            {
                ScheduleSlot slot = quotaDict.Key; List <Tuple <Person, double> > liste = quotaDict.Value;
                TimeSpan     start     = slot.startHour;
                TimeSpan     end       = slot.endHour;
                TimeSpan     fromThere = start;
                foreach (Tuple <Person, double> quotaTuple in liste)
                {
                    Person person = quotaTuple.Item1;; double hours = quotaTuple.Item2;
                    while (hours > 0)
                    {
                        TimeSpan     toThere = TimeSpan.FromTicks(Math.Min(end.Ticks, fromThere.Add(TimeSpan.FromHours(hours)).Ticks));
                        WorkingShift shift   = new WorkingShift();
                        DateTime     theDay  = WeekStart.AddDays(((int)slot.dayOfWeek - (int)WeekStart.DayOfWeek) % 7);
                        shift.start  = theDay.Add(fromThere);
                        shift.end    = theDay.Add(toThere);
                        shift.Person = person;
                        shifts.Add(shift);
                        hours -= toThere.Subtract(fromThere).TotalHours;
                        if (toThere == end)
                        {
                            fromThere = start;
                        }
                        else
                        {
                            fromThere = toThere;
                        }
                    }
                }
            }

            // merging contiguous shifts
            int i = 0;

            while (i < shifts.Count)
            {
                WorkingShift shiftI = shifts[i];
                int          j      = i + 1;
                while (j < shifts.Count)
                {
                    WorkingShift shiftJ = shifts[j];
                    if (shiftJ.Person == shiftI.Person)
                    {
                        if (shiftJ.start == shiftI.end)
                        {
                            shiftI.end = shiftJ.end;
                            shifts.Remove(shiftJ);
                        }
                        else if (shiftJ.end == shiftI.start)
                        {
                            shiftI.start = shiftJ.start;
                            shifts.Remove(shiftJ);
                        }
                        else
                        {
                            j++;
                        }
                    }
                    else
                    {
                        j++;
                    }
                }
                i++;
            }

            return(new Tuple <List <WorkingShift>, List <string> >(shifts, problems));
        }