Ejemplo n.º 1
0
        public override void LoadContent(TimeSchedulerDataSourceView view)
        {
            var interval  = view.Interval;
            var resources = view.Resources;

            foreach (var item in resources)
            {
                view.AddWorkTime(item, interval, Colors.White);
            }

            for (var i = interval.Start; i < interval.End; i = i.AddDays(1))
            {
                if (!_taskDictionary.ContainsKey(i))
                {
                    _taskDictionary.Add(i, GenerateTasks(i).ToList());
                }

                var tasks = _taskDictionary[i];
                foreach (var item in tasks)
                {
                    if (interval.IntersectsWith(item.Interval) && view.Resources.Contains(item.Resource))
                    {
                        view.AddTask(item);
                    }
                }
            }
        }
        public override void LoadContent(TimeSchedulerDataSourceView view)
        {
            var interval  = view.Interval;
            var resources = view.Resources.Cast <ResourceModel>().ToList();

            IList <TaskModel> GetTaskForDate(DateTime date)
            {
                if (!_tasks.ContainsKey(date))
                {
                    _tasks.Add(date.Date, GenerateTasks(date).ToList());
                }

                return(_tasks[date]);
            };

            foreach (var item in resources)
            {
                view.AddWorkTime(item, interval, Colors.White);
            }

            for (var i = interval.Start.Date; i <= interval.End.Date; i = i.AddDays(1))
            {
                var date        = i.Date;
                var tasks       = GetTaskForDate(date);
                var loadedTasks = tasks.Where(x => interval.IntersectsWith(x.Interval) && view.Resources.Contains(x.Resource))
                                  .OrderBy(x => x.Interval.Start).ThenBy(x => x.Interval.End).ToList();

                for (var j = 0; j < loadedTasks.Count; j++)
                {
                    var task = loadedTasks[j];
                    view.AddTask(task);
                    // Connections
                    var nextTask = tasks.FirstOrDefault(x => x.Resource.ID == task.Resource.ID + 2 && x.Interval.Start > task.Interval.End)
                                   ?? GetTaskForDate(i.AddDays(1).Date).FirstOrDefault(x => x.Resource.ID == task.Resource.ID + 2 && x.Interval.Start > task.Interval.End);
                    if (nextTask != null)
                    {
                        view.AddConnection(task, nextTask, true, Colors.DarkOrange);
                    }
                }
            }
        }
        public override void LoadContent(TimeSchedulerDataSourceView view)
        {
            var resources        = view.Resources.Cast <ResourceModel>().ToList();
            var interval         = view.Interval;
            var resourcesHashSet = resources.ToDictionary(x => x.ID);

            IList <TaskModel> GetTaskForDate(DateTime date)
            {
                if (!_tasks.ContainsKey(date))
                {
                    _tasks.Add(date.Date, GenerateTasks(date).ToList());
                }

                return(_tasks[date]);
            };

            // WorkTimes
            for (var i = 0; i <= (interval.End - interval.Start).TotalDays + 1; i++)
            {
                foreach (var item in resources)
                {
                    var start = interval.Start.Date.AddTicks(TimeSpan.TicksPerDay * i + TimeSpan.TicksPerHour * 8);
                    var end   = start.AddHours(8);

                    view.AddWorkTime(item, new DateTimeInterval(start, end), Colors.White);
                }
            }

            for (var i = interval.Start; i < interval.End; i = i.AddDays(1))
            {
                var date  = i.Date;
                var tasks = GetTaskForDate(date);
                // Tasks
                foreach (var task in tasks)
                {
                    if (interval.IntersectsWith(task.Interval) && resources.Contains(task.Resource))
                    {
                        view.AddTask(task);

                        // Connections
                        var nextTask = tasks.FirstOrDefault(x => x.Resource.ID == task.Resource.ID + 2 && x.Interval.Start > task.Interval.End)
                                       ?? GetTaskForDate(i.AddDays(1).Date).FirstOrDefault(x => x.Resource.ID == task.Resource.ID + 2 && x.Interval.Start > task.Interval.End);
                        if (nextTask != null)
                        {
                            view.AddConnection(task, nextTask, true, Colors.DarkOrange);
                        }

                        // Markers
                        if (resourcesHashSet.ContainsKey(task.Resource.ID + 1))
                        {
                            view.AddMarker(resourcesHashSet[task.Resource.ID + 1], task.Interval.End + TimeSpan.FromHours(1), Colors.IndianRed);
                        }
                    }
                }

                // Interval markers
                if (i.DayOfWeek == DayOfWeek.Sunday)
                {
                    view.AddIntervalMarker(new DateTimeInterval(date, date + TimeSpan.FromDays(1)), m_colors[1]);
                }
            }

            // Graphs
            for (var j = 0; j < resources.Count; j++)
            {
                var resource = resources[j];
                if (resource.ID % 2 == 0)
                {
                    continue;
                }

                var graph = new TimeSchedulerGraph(TimeSchedulerGraphType.StepWithFill, m_colors[resource.ID % m_colors.Length], 0, 2);

                var lastDate = DateTime.MinValue;
                graph.AddPoint(lastDate, 0);

                var random = new Random(j * 12361);
                var size   = 1000;
                var step   = view.Interval.Duration.Ticks / size;

                lastDate = view.Interval.Start;

                for (var i = 0; i < size; i++)
                {
                    if (random.Next(0, 5) == 0)
                    {
                        graph.AddPoint(lastDate + TimeSpan.FromTicks(i * step), random.NextDouble() * 2);
                    }
                }

                if (lastDate < DateTime.MaxValue)
                {
                    graph.AddPoint(DateTime.MaxValue, 0);
                }

                view.AddGraph(resources[j], graph);
            }

            // Now markers
            view.AddMarker(DateTime.Now, Colors.DodgerBlue);
        }