Exemplo n.º 1
0
        protected override void PerformDataBinding(IEnumerable schedulingData)
        {
            // don't bind in design mode
            if (DesignMode)
            {
                return;
            }

            base.PerformDataBinding(schedulingData);

            // Verify data exists.
            if (schedulingData != null)
            {

                TimeSpan tmpTS;
                TimeSpan oneDay = TimeSpan.FromDays(1);
                maxTOD = TimeSpan.Zero.Subtract(TimeSpan.FromMinutes(userTZ));
                minTOD = oneDay;

                foreach (ITimeBlock tb in schedulingData)
                {
                    tmpTS = tb.Start.AddMinutes(userTZ).TimeOfDay;
                    if (minTOD > tmpTS)
                        minTOD = tmpTS;
                    tmpTS = tmpTS.Add(TimeSpan.FromSeconds(tb.Duration));
                    if (tmpTS.TotalHours < 24)
                    {
                        if (maxTOD < tmpTS)
                        {
                            maxTOD = tmpTS;
                        }
                    }
                    else if (tmpTS.TotalHours == 24)
                    {
                        maxTOD = tmpTS;
                    }
                    else
                    {
                        minTOD = TimeSpan.Zero;
                        maxTOD = TimeSpan.FromHours(24);
                        break;
                    }
                }
                if (bindReservations)
                { // should be Reservations
                    reservations = new List<Reservation>();
                    foreach (Reservation r in schedulingData)
                    {
                        reservations.Add(r);
                    }
                }
                else
                {  // should be TimePeriods
                    TimeBlock range = new TimeBlock(StartTime, EndTime);
                    periods = new List<TimePeriod>();
                    foreach (TimePeriod tp in schedulingData)
                    {
                        if(range.Contains(tp)){
                            periods.Add(tp);
                        }
                        else if (range.Intersects(tp))
                        {
                            TimeBlock tmpTB = range.Intersection(tp);
                            periods.Add(new TimePeriod(tmpTB.Start, tmpTB.Duration, tp.quantum));
                        }
                    }
                    TimeBlock[] scheduledTBs = TimeBlock.Remaining(new TimeBlock[] { range }, periods.ToArray());
                    if (scheduledTBs != null && scheduledTBs.Length > 0)
                    {
                        periods.AddRange(TimePeriod.MakeArray(scheduledTBs, 0));
                    }
                    periods.Sort();
                }
            }
            else
            {
                minTOD = TimeSpan.Zero;
                maxTOD = TimeSpan.FromHours(24);
                periods = new List<TimePeriod>();
                periods.Add(new TimePeriod(StartTime, EndTime, 0));
            }
        }
        protected override void PerformDataBinding(IEnumerable schedulingData)
        {
            // don't bind in design mode
            if (DesignMode)
            {
                return;
            }
            base.PerformDataBinding(schedulingData);
            
            MinTOD = TimeSpan.Zero;
            MaxTOD = oneDay;
            // Verify data exists.
            if (schedulingData != null)
            {

                if (NumDays == 1)
                {
                    TimeSpan tmpTS;
                    TimeSpan tmpMinTOD = oneDay;

                    //Check the first timeBlock
                    IEnumerator eTB = schedulingData.GetEnumerator();
                    if (eTB.MoveNext())
                    {
                        tmpTS = (( TimeBlock)eTB.Current).Start.AddMinutes(userTZ).TimeOfDay;
                        if (tmpMinTOD > tmpTS)
                        {
                            tmpMinTOD = tmpTS;
                            MinTOD = tmpMinTOD;
                        }

                    }
                
                }
                if (bindReservations)
                { // should be Reservations
                    reservations = new List<Reservation>();
                    foreach (Reservation r in schedulingData)
                    {
                        reservations.Add(r);
                    }
                }
                else
                {  // should be TimePeriods
                    TimeBlock range = new TimeBlock(StartTime, EndTime);
                    periods = new List<TimePeriod>();
                    foreach (TimePeriod tp in schedulingData)
                    {
                        if(range.Contains(tp)){
                            periods.Add(tp);
                        }
                        else if (range.Intersects(tp))
                        {
                            TimeBlock tmpTB = range.Intersection(tp);
                            periods.Add(new TimePeriod(tmpTB.Start, tmpTB.Duration, tp.quantum));
                        }
                    }
                    TimeBlock[] scheduledTBs = TimeBlock.Remaining(new TimeBlock[] { range }, periods.ToArray());
                    if (scheduledTBs != null && scheduledTBs.Length > 0)
                    {
                        periods.AddRange(TimePeriod.MakeArray(scheduledTBs, 0));
                    }
                    periods.Sort();
                }
            }
            else
            {
                
                periods = new List<TimePeriod>();
                periods.Add(new TimePeriod(StartTime, EndTime, 0));
            }
        }