Exemple #1
0
 public void AddGanttTask(GanttRow row, GanttTask task)
 {
     if (task.Start < ganttChartData.MaxDate && task.End > ganttChartData.MinDate)
     {
         row.Tasks.Add(task);
     }
 }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            List <GanttGroup> list = new List <GanttGroup>();

            for (int i = 0; i < 10; ++i)
            {
                GanttGroup ganttGroup = new GanttGroup();
                ganttGroup.Caption = "Group " + i;

                GanttRow ganttRow = new GanttRow();
                ganttRow.Caption = "test_" + i;

                GanttItem ganttItem = new GanttItem();
                ganttItem.Caption = "testItem_" + i;
                ganttItem.Start   = DateTime.Now;
                ganttItem.End     = ganttItem.Start.AddDays(7);
                ganttRow.Items.Add(ganttItem);

                ganttGroup.Rows.Add(ganttRow);

                list.Add(ganttGroup);
            }

            ganttChart.Groups = list;


            ganttChart.Start = DateTime.Now;
            ganttChart.End   = ganttChart.Start.AddDays(14);

            ganttChart.Refresh();
        }
Exemple #3
0
        private void BuildGanttChart(
            IEnumerable <ActivityModel> activities,
            DateTime projectStart,
            SlackColorFormatLookup colorFormatLookup)
        {
            if (activities == null)
            {
                return;
            }

            foreach (ActivityModel activity in activities)
            {
                GanttRowGroup rowGroup = GanttChartAreaCtrl.CreateGanttRowGroup();
                string        name     = string.IsNullOrWhiteSpace(activity.Name) ? activity.Id.ToString(CultureInfo.InvariantCulture) : activity.Name;
                GanttRow      row      = GanttChartAreaCtrl.CreateGanttRow(rowGroup, name);

                if (activity.EarliestStartTime.HasValue &&
                    activity.EarliestFinishTime.HasValue)
                {
                    CheckRowErrors(activity, row);

                    GanttChartAreaCtrl.AddGanttTask(
                        row,
                        CreateGanttTask(projectStart, activity, colorFormatLookup));
                }
            }
        }
Exemple #4
0
 private void DeregisterGanttRowEvents(GanttRow row)
 {
     row.Items.ItemsAdded      -= GanttRowItemsOnChanged;
     row.Items.ItemsReplaced   -= GanttRowItemsOnChanged;
     row.Items.ItemsRemoved    -= GanttRowItemsOnRemoved;
     row.Items.CollectionReset -= GanttRowItemsOnChanged;
     foreach (var item in row.Items)
     {
         DeregisterGanttRowItemEvents(item);
     }
 }
Exemple #5
0
        public GanttRow CreateGanttRow(GanttRowGroup rowGroup, string name)
        {
            var rowHeader = new GanttRowHeader()
            {
                Name = name
            };
            var row = new GanttRow()
            {
                RowHeader = rowHeader, Tasks = new ObservableCollection <GanttTask>()
            };

            rowGroup.Rows.Add(row);
            return(row);
        }
Exemple #6
0
 private void CheckRowErrors(ActivityModel activity, GanttRow row)
 {
     if (activity is null ||
         row is null)
     {
         return;
     }
     if (activity.FreeSlack.GetValueOrDefault() < 0 ||
         activity.TotalSlack.GetValueOrDefault() < 0 ||
         (activity.TotalSlack.GetValueOrDefault() - activity.FreeSlack.GetValueOrDefault()) < 0)
     {
         row.HasErrors = true;
     }
 }
        public void AddGanttTask(GanttRow row, GanttTask task)
        {
            if (row is null)
            {
                throw new ArgumentNullException(nameof(row));
            }
            if (task is null)
            {
                throw new ArgumentNullException(nameof(task));
            }

            if (task.Start < ganttChartData.MaxDate && task.End > ganttChartData.MinDate)
            {
                row.Tasks.Add(task);
            }
        }
Exemple #8
0
        private void CreateData(DateTime minDate, DateTime maxDate)
        {
            // Set max and min dates
            ganttControl1.Initialize(minDate, maxDate);

            // Create timelines and define how they should be presented
            TimeLine gridLineTimeLine = ganttControl1.CreateTimeLine(new PeriodHourSplitter(minDate, maxDate), FormatHour);

            // Set the timeline to atatch gridlines to
            ganttControl1.SetGridLinesTimeline(gridLineTimeLine, DetermineBackground);

            // Create rows and data
            GanttRowGroup rowgroup1 = ganttControl1.CreateGanttRowGroup();
            GanttRow      row1      = ganttControl1.CreateGanttRow(rowgroup1, "Training");
            GanttRow      row2      = ganttControl1.CreateGanttRow(rowgroup1, "Meal");

            GenerateEventsFromTable(row1, minDate, maxDate, "activity");
            GenerateEventsFromTable(row2, minDate, maxDate, "meal");
        }
Exemple #9
0
        private void BuildGanttChart(
            IEnumerable <ActivityModel> activities,
            ResourceSeriesSetModel resourceSeriesSet,
            DateTime projectStart,
            SlackColorFormatLookup colorFormatLookup)
        {
            if (activities == null || resourceSeriesSet?.Scheduled == null)
            {
                return;
            }

            IDictionary <int, ActivityModel> activityLookup = activities.ToDictionary(x => x.Id);

            foreach (ResourceSeriesModel resourceSeries in resourceSeriesSet.Scheduled)
            {
                ResourceScheduleModel resourceSchedule = resourceSeries.ResourceSchedule;

                if (resourceSchedule != null)
                {
                    GanttRowGroup rowGroup = GanttChartAreaCtrl.CreateGanttRowGroup(resourceSeries.Title);

                    foreach (ScheduledActivityModel scheduledctivity in resourceSchedule.ScheduledActivities)
                    {
                        if (activityLookup.TryGetValue(scheduledctivity.Id, out ActivityModel activity))
                        {
                            string   name = string.IsNullOrWhiteSpace(scheduledctivity.Name) ? scheduledctivity.Id.ToString(CultureInfo.InvariantCulture) : scheduledctivity.Name;
                            GanttRow row  = GanttChartAreaCtrl.CreateGanttRow(rowGroup, name);

                            if (activity.EarliestStartTime.HasValue &&
                                activity.EarliestFinishTime.HasValue)
                            {
                                CheckRowErrors(activity, row);

                                GanttChartAreaCtrl.AddGanttTask(
                                    row,
                                    CreateGanttTask(projectStart, activity, colorFormatLookup));
                            }
                        }
                    }
                }
            }
        }
Exemple #10
0
        private void GenerateEventsFromTable(GanttRow row, DateTime minDate, DateTime maxDate, string tableName)
        {
            string          dateFormat = "yyyy-MM-dd";
            string          sql        = $"SELECT * FROM {tableName} WHERE AppDate BETWEEN #{minDate.ToString(dateFormat)}# AND #{maxDate.ToString(dateFormat)}#";
            DatabaseManager dbManager  = new DatabaseManager();
            DataTable       dt         = dbManager.QueryAsDataTable(sql);

            foreach (DataRow dataRow in dt.Rows)
            {
                string date       = dataRow["AppDate"].ToString();
                string startTime  = dataRow["StartTime"].ToString();
                string endTime    = dataRow["EndTime"].ToString();
                string id         = dataRow["ID"].ToString();
                string eventColor = eventColor = Colors.Beige.ToString();;

                DateTime startDay  = DateTime.Parse(startTime);
                DateTime entDay    = DateTime.Parse(endTime);
                string   eventName = " ";
                if (tableName == "activity")
                {
                    eventName  = dataRow["Type"].ToString();
                    eventColor = Colors.DeepSkyBlue.ToString();
                }
                else if (tableName == "meal")
                {
                    eventName  = dataRow["Type"].ToString() + ": " + dataRow["MealName"].ToString();
                    eventColor = Colors.GreenYellow.ToString();
                }

                ganttControl1.AddGanttTask(row, new GanttTask()
                {
                    Start = startDay,
                    End   = entDay,
                    Name  = eventName,
                    Table = tableName,
                    AppID = int.Parse(id),
                    Color = eventColor
                });
            }
        }
        public GanttRow CreateGanttRow(GanttRowGroup rowGroup, string name)
        {
            if (rowGroup is null)
            {
                throw new ArgumentNullException(nameof(rowGroup));
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException(nameof(name));
            }

            GanttRowHeader rowHeader = new GanttRowHeader()
            {
                Name = name
            };
            var row = new GanttRow()
            {
                RowHeader = rowHeader, Tasks = new ObservableCollection <GanttTask>()
            };

            rowGroup.Rows.Add(row);
            return(row);
        }
        private void BuildGanttChart(
            IEnumerable <ActivityModel> activities,
            DateTime projectStart,
            SlackColorFormatLookup colorFormatLookup)
        {
            if (activities == null)
            {
                return;
            }

            foreach (ActivityModel activity in activities)
            {
                GanttRowGroup rowGroup = GanttChartAreaCtrl.CreateGanttRowGroup();
                GanttRow      row      = GanttChartAreaCtrl.CreateGanttRow(rowGroup, activity.Name);

                if (activity.EarliestStartTime.HasValue &&
                    activity.EarliestFinishTime.HasValue)
                {
                    GanttChartAreaCtrl.AddGanttTask(
                        row,
                        CreateGanttTask(projectStart, activity, colorFormatLookup));
                }
            }
        }
        private void BuildGanttChart(
            IList <IDependentActivity <int> > dependentActivities,
            DateTime projectStart,
            SlackColorFormatLookup colorFormatLookup)
        {
            if (dependentActivities == null)
            {
                return;
            }

            foreach (IDependentActivity <int> activity in dependentActivities)
            {
                GanttRowGroup rowGroup = GanttChartAreaCtrl.CreateGanttRowGroup();
                GanttRow      row      = GanttChartAreaCtrl.CreateGanttRow(rowGroup, activity.Name);

                if (activity.EarliestStartTime.HasValue &&
                    activity.EarliestFinishTime.HasValue)
                {
                    GanttChartAreaCtrl.AddGanttTask(
                        row,
                        CreateGanttTask(projectStart, activity, colorFormatLookup));
                }
            }
        }
        private void Calculate(object sender, RoutedEventArgs e)
        {
            costs          = CreateCostsMatrix(costs_TextBoxes);
            lists          = JohnsonAlgorithm.CreateLists(costs);
            queue          = JohnsonAlgorithm.ConnectLists(lists[0], lists[1]);
            QueueList.Text = "Kolejka: " + String.Join(",", queue);
            axis           = JohnsonAlgorithm.CreateTasksAxis(costs, queue);
            Axis1.Text     = String.Join(" ", axis[0]);
            Axis2.Text     = String.Join(" ", axis[1]);
            cost.Text      = axis[1].Count.ToString();
            Utilities.PlayFadeAnim(SBResult);



            //GENERATE gannt list
            int      totalDuration = 0;
            GanttRow machine1      = new GanttRow();

            //Machine 1


            for (int i = 0; i < queue.Count; i++)
            {
                Gantt gantt = new Gantt(totalDuration, costs[0, queue[i] - 1], queue[i].ToString());
                machine1.elements.Add(gantt);
                totalDuration += costs[0, queue[i] - 1];
            }
            //Machine 2
            totalDuration = 0;
            GanttRow machine2 = new GanttRow();

            for (int i = 0; i < queue.Count; i++)
            {
                if (totalDuration > machine1.GetDurationTillEndOf(i + 1))
                {
                    Gantt gantt = new Gantt(totalDuration, costs[1, queue[i] - 1], queue[i].ToString());
                    machine2.elements.Add(gantt);
                    totalDuration += costs[1, queue[i] - 1];
                }
                else
                {
                    Gantt gantt = new Gantt(machine1.GetDurationTillEndOf(i + 1), costs[1, queue[i] - 1], queue[i].ToString());
                    machine2.elements.Add(gantt);
                    totalDuration = machine1.GetDurationTillEndOf(i + 1) + costs[1, queue[i] - 1];
                }
            }
            try
            {
                machine2.FillEmptySpaces();
                machine1.header = "Masz1";
                machine2.header = "Masz2";
                GanttChart ganttChart = new GanttChart();
                ganttChart.rows.Add(machine1);
                ganttChart.rows.Add(machine2);
                ganttChart.DrawChart(ganttGrid);
            }
            catch (Exception ex)
            {
                Utilities.showErrorMessage(ex.Message);
            }
        }
        private void BuildGanttChart(
            IList <IDependentActivity <int> > dependentActivities,
            IList <ResourceSeriesDto> resourceSeriesSet,
            IList <IResourceSchedule <int> > resourceSchedules,
            DateTime projectStart,
            SlackColorFormatLookup colorFormatLookup)
        {
            if (dependentActivities == null || resourceSeriesSet == null || resourceSchedules == null)
            {
                return;
            }

            IDictionary <int, IDependentActivity <int> > activityLookup = dependentActivities.ToDictionary(x => x.Id);

            int spareResourceCount = 1;

            for (int resourceIndex = 0; resourceIndex < resourceSchedules.Count; resourceIndex++)
            {
                IResourceSchedule <int>           resourceSchedule    = resourceSchedules[resourceIndex];
                IList <IScheduledActivity <int> > scheduledActivities = resourceSchedule?.ScheduledActivities;

                if (scheduledActivities == null)
                {
                    continue;
                }

                var stringBuilder = new StringBuilder();
                if (resourceSchedule.Resource != null)
                {
                    if (string.IsNullOrWhiteSpace(resourceSchedule.Resource.Name))
                    {
                        stringBuilder.Append($@"Resource {resourceSchedule.Resource.Id}");
                    }
                    else
                    {
                        stringBuilder.Append(resourceSchedule.Resource.Name);
                    }
                }
                else
                {
                    stringBuilder.Append($@"Resource {spareResourceCount}");
                    spareResourceCount++;
                }

                string        resourceName = stringBuilder.ToString();
                GanttRowGroup rowGroup     = GanttChartAreaCtrl.CreateGanttRowGroup(resourceName);

                foreach (IScheduledActivity <int> scheduledctivity in resourceSchedule.ScheduledActivities)
                {
                    if (activityLookup.TryGetValue(scheduledctivity.Id, out IDependentActivity <int> activity))
                    {
                        GanttRow row = GanttChartAreaCtrl.CreateGanttRow(rowGroup, activity.Name);

                        if (activity.EarliestStartTime.HasValue &&
                            activity.EarliestFinishTime.HasValue)
                        {
                            GanttChartAreaCtrl.AddGanttTask(
                                row,
                                CreateGanttTask(projectStart, activity, colorFormatLookup));
                        }
                    }
                }
            }
        }