Esempio n. 1
0
        public MainWindow()
        {
            InitializeComponent();

            GanttChartItem task1 = ScheduleChartDataGrid.Items[0].GanttChartItems[0];

            task1.Start           = DateTime.Today.Add(TimeSpan.Parse("08:00:00"));
            task1.Finish          = DateTime.Today.Add(TimeSpan.Parse("16:00:00"));
            task1.CompletedFinish = DateTime.Today.Add(TimeSpan.Parse("12:00:00"));

            GanttChartItem task21 = ScheduleChartDataGrid.Items[0].GanttChartItems[1];

            task21.Start              = DateTime.Today.Add(TimeSpan.Parse("12:00:00"));
            task21.Finish             = DateTime.Today.AddDays(2).Add(TimeSpan.Parse("16:00:00"));
            task21.AssignmentsContent = "50%";

            GanttChartItem task22 = ScheduleChartDataGrid.Items[1].GanttChartItems[0];

            task22.Start  = DateTime.Today.AddDays(1).Add(TimeSpan.Parse("12:00:00"));
            task22.Finish = DateTime.Today.AddDays(2).Add(TimeSpan.Parse("16:00:00"));

            GanttChartItem task3 = ScheduleChartDataGrid.Items[2].GanttChartItems[0];

            task3.Start  = DateTime.Today.Add(TimeSpan.Parse("08:00:00"));
            task3.Finish = DateTime.Today.AddDays(2).Add(TimeSpan.Parse("16:00:00"));

            GanttChartItem task4 = ScheduleChartDataGrid.Items[3].GanttChartItems[0];

            task4.Start  = DateTime.Today.Add(TimeSpan.Parse("08:00:00"));
            task4.Finish = DateTime.Today.AddDays(1).Add(TimeSpan.Parse("16:00:00"));

            GanttChartItem task5 = ScheduleChartDataGrid.Items[3].GanttChartItems[1];

            task5.Start  = DateTime.Today.AddDays(3).Add(TimeSpan.Parse("10:00:00"));
            task5.Finish = DateTime.Today.AddDays(3).Add(TimeSpan.Parse("16:00:00"));

            GanttChartItem task6 = ScheduleChartDataGrid.Items[3].GanttChartItems[2];

            task6.Start  = DateTime.Today.AddDays(1).Add(TimeSpan.Parse("12:00:00"));
            task6.Finish = DateTime.Today.AddDays(2).Add(TimeSpan.Parse("12:00:00"));

            for (int i = 5; i <= 16; i++)
            {
                ScheduleChartItem item = new ScheduleChartItem {
                    Content = "Resource " + i
                };
                for (int j = 1; j <= (i - 1) % 4 + 1; j++)
                {
                    item.GanttChartItems.Add(
                        new GanttChartItem
                    {
                        Content         = "Task " + i + "." + j,
                        Start           = DateTime.Today.AddDays(i + (i - 1) * (j - 1)),
                        Finish          = DateTime.Today.AddDays(i * 2 + (i - 1) * (j - 1) + 1),
                        CompletedFinish = DateTime.Today.AddDays(i + (i - 1) * (j - 1)).AddDays((i + j) % 5 == 2 ? 2 : 0)
                    });
                }
                ScheduleChartDataGrid.Items.Add(item);
            }
        }
        public void InsertNewItemButton_Click(object sender, EventArgs e)
        {
            if (ScheduleChartView.SelectedItem == null)
            {
                return;
            }
            var item = new ScheduleChartItem
            {
                Content         = "New resource",
                GanttChartItems = new List <GanttChartItem>
                {
                    new GanttChartItem {
                        Content = "Task X (New resource)", Start = new DateTime(year, month, 2, 8, 0, 0), Finish = new DateTime(year, month, 5, 16, 0, 0)
                    },
                    new GanttChartItem {
                        Content = "Task Y (New resource)", Start = new DateTime(year, month, 7, 8, 0, 0), Finish = new DateTime(year, month, 8, 16, 0, 0)
                    }
                }
            };

            ScheduleChartView.InsertItem(ScheduleChartView.SelectedIndex, item);
            ScheduleChartView.SelectedItem = item;
            ScheduleChartView.ScrollTo(item);
            ScheduleChartView.ScrollTo(new DateTime(year, month, 1));
        }
        public MainWindow()
        {
            InitializeComponent();

            GanttChartItem task1 = ScheduleChartView.Items[0].GanttChartItems[0];

            task1.Start           = DateTime.Today.Add(TimeSpan.Parse("08:00:00"));
            task1.Finish          = DateTime.Today.Add(TimeSpan.Parse("16:00:00"));
            task1.CompletedFinish = DateTime.Today.Add(TimeSpan.Parse("12:00:00"));

            GanttChartItem task21 = ScheduleChartView.Items[0].GanttChartItems[1];

            task21.Start              = DateTime.Today.AddDays(1).Add(TimeSpan.Parse("12:00:00"));
            task21.Finish             = DateTime.Today.AddDays(2).Add(TimeSpan.Parse("16:00:00"));
            task21.AssignmentsContent = "50%";

            GanttChartItem task22 = ScheduleChartView.Items[1].GanttChartItems[0];

            task22.Start  = DateTime.Today.AddDays(1).Add(TimeSpan.Parse("12:00:00"));
            task22.Finish = DateTime.Today.AddDays(2).Add(TimeSpan.Parse("16:00:00"));

            for (int i = 3; i <= 16; i++)
            {
                ScheduleChartItem item = new ScheduleChartItem();
                for (int j = 1; j <= (i - 1) % 4 + 1; j++)
                {
                    item.GanttChartItems.Add(
                        new GanttChartItem
                    {
                        Content         = "Task " + i + "." + j + " (Resource " + i + ")",
                        Start           = DateTime.Today.AddDays(i + (i - 1) * (j - 1)),
                        Finish          = DateTime.Today.AddDays(i * 1.2 + (i - 1) * (j - 1) + 1),
                        CompletedFinish = DateTime.Today.AddDays(i + (i - 1) * (j - 1)).AddDays((i + j) % 5 == 2 ? 2 : 0)
                    });
                }
                ScheduleChartView.Items.Add(item);
            }

            // You may uncomment the next lines of code to test the component performance:
            // for (int i = 17; i <= 1024; i++)
            // {
            //    ScheduleChartItem item = new ScheduleChartItem();
            //    for (int j = 1; j <= (i - 1) % 4 + 1; j++)
            //    {
            //        item.GanttChartItems.Add(
            //            new GanttChartItem
            //            {
            //                Content = "Task " + i + "." + j + " (Resource " + i + ")",
            //                Start = DateTime.Today.AddDays(i + (i - 1) * (j - 1)),
            //                Finish = DateTime.Today.AddDays(i * 1.2 + (i - 1) * (j - 1) + 1)
            //            });
            //    }
            //    ScheduleChartView.Items.Add(item);
            // }

            // Initialize the control area.
            ScalesComboBox.SelectedIndex   = 0;
            ShowWeekendsCheckBox.IsChecked = true;
        }
        public void SetSelectedItemAsHiddenButton_Click(object sender, EventArgs e)
        {
            ScheduleChartItem item = ScheduleChartView.SelectedItem;

            if (item != null)
            {
                item.IsHidden = true;
            }
        }
        // Control area commands.
        private void AddNewButton_Click(object sender, RoutedEventArgs e)
        {
            ScheduleChartItem item = new ScheduleChartItem {
                Content = "New Resource"
            };

            item.GanttChartItems.Add(new GanttChartItem {
                Content = "New Task", Start = DateTime.Today, Finish = DateTime.Today.AddDays(1)
            });
            ScheduleChartDataGrid.Items.Add(item);
            ScheduleChartDataGrid.SelectedItem = item;
        }
        public MainWindow()
        {
            InitializeComponent();

            ScheduleChartDataGrid.WorkingDayStart     = TimeOfDay.Parse("10:00:00");
            ScheduleChartDataGrid.WorkingDayFinish    = TimeOfDay.Parse("14:00:00");
            ScheduleChartDataGrid.NonworkingIntervals = new ObservableCollection <TimeInterval>(
                new TimeInterval[] { new TimeInterval(DateTime.Today.AddDays(2), DateTime.Today.AddDays(3).Add(TimeSpan.Parse("12:00:00"))) });
            ScheduleChartDataGrid.TimelinePageStart  = DateTime.Today;
            ScheduleChartDataGrid.TimelinePageFinish = DateTime.Today.AddMonths(2);
            ScheduleChartDataGrid.VisibleDayStart    = TimeOfDay.Parse("09:00:00");
            ScheduleChartDataGrid.VisibleDayFinish   = TimeOfDay.Parse("15:00:00");

            GanttChartItem task1 = ScheduleChartDataGrid.Items[0].GanttChartItems[0];

            task1.Start           = DateTime.Today.Add(TimeSpan.Parse("08:00:00"));
            task1.Finish          = DateTime.Today.Add(TimeSpan.Parse("16:00:00"));
            task1.CompletedFinish = DateTime.Today.Add(TimeSpan.Parse("12:00:00"));

            GanttChartItem task21 = ScheduleChartDataGrid.Items[0].GanttChartItems[1];

            task21.Start              = DateTime.Today.AddDays(1).Add(TimeSpan.Parse("12:00:00"));
            task21.Finish             = DateTime.Today.AddDays(2).Add(TimeSpan.Parse("16:00:00"));
            task21.AssignmentsContent = "50%";

            GanttChartItem task22 = ScheduleChartDataGrid.Items[1].GanttChartItems[0];

            task22.Start  = DateTime.Today.AddDays(1).Add(TimeSpan.Parse("12:00:00"));
            task22.Finish = DateTime.Today.AddDays(2).Add(TimeSpan.Parse("16:00:00"));

            for (int i = 3; i <= 16; i++)
            {
                ScheduleChartItem item = new ScheduleChartItem {
                    Content = "Resource " + i
                };
                for (int j = 1; j <= (i - 1) % 4 + 1; j++)
                {
                    item.GanttChartItems.Add(
                        new GanttChartItem
                    {
                        Content         = "Task " + i + "." + j,
                        Start           = DateTime.Today.AddDays((i - 1) * (j - 1)),
                        Finish          = DateTime.Today.AddDays((i - 1) * (j - 1) + 1),
                        CompletedFinish = DateTime.Today.AddDays((i - 1) * (j - 1)).AddDays((i + j) % 5 == 2 ? 2 : 0)
                    });
                }
                ScheduleChartDataGrid.Items.Add(item);
            }
        }
Esempio n. 7
0
        public MainWindow()
        {
            InitializeComponent();

            GanttChartItem task1 = ScheduleChartDataGrid.Items[1].GanttChartItems[0];

            task1.Start           = DateTime.Today.Add(TimeSpan.Parse("08:00:00"));
            task1.Finish          = DateTime.Today.Add(TimeSpan.Parse("16:00:00"));
            task1.CompletedFinish = DateTime.Today.Add(TimeSpan.Parse("12:00:00"));

            GanttChartItem task21 = ScheduleChartDataGrid.Items[1].GanttChartItems[1];

            task21.Start              = DateTime.Today.AddDays(1).Add(TimeSpan.Parse("12:00:00"));
            task21.Finish             = DateTime.Today.AddDays(2).Add(TimeSpan.Parse("16:00:00"));
            task21.AssignmentsContent = "50%";

            GanttChartItem task22 = ScheduleChartDataGrid.Items[2].GanttChartItems[0];

            task22.Start  = DateTime.Today.AddDays(1).Add(TimeSpan.Parse("12:00:00"));
            task22.Finish = DateTime.Today.AddDays(2).Add(TimeSpan.Parse("16:00:00"));

            GanttChartItem task3 = ScheduleChartDataGrid.Items[4].GanttChartItems[0];

            task3.Start  = DateTime.Today.Add(TimeSpan.Parse("08:00:00"));
            task3.Finish = DateTime.Today.Add(TimeSpan.Parse("16:00:00"));

            for (int i = 3; i <= 18; i++)
            {
                ScheduleChartItem item = new ScheduleChartItem {
                    Content = i % 4 == 3 ? "Resource Group " + (char)('A' + 2 + (i - 3) / 4) : "Resource " + i, Indentation = i % 4 == 3 ? 0 : 1
                };
                if (i % 4 != 3)
                {
                    for (int j = 1; j <= (i - 1) % 4 + 1; j++)
                    {
                        item.GanttChartItems.Add(
                            new GanttChartItem
                        {
                            Content         = "Task " + i + "." + j,
                            Start           = DateTime.Today.AddDays(i + (i - 1) * (j - 1)),
                            Finish          = DateTime.Today.AddDays(i * 1.2 + (i - 1) * (j - 1) + 1),
                            CompletedFinish = DateTime.Today.AddDays(i + (i - 1) * (j - 1)).AddDays((i + j) % 5 == 2 ? 2 : 0)
                        });
                    }
                }
                ScheduleChartDataGrid.Items.Add(item);
            }
        }
        private void InsertNewButton_Click(object sender, RoutedEventArgs e)
        {
            ScheduleChartItem selectedItem = ScheduleChartDataGrid.SelectedItem as ScheduleChartItem;

            if (selectedItem == null)
            {
                MessageBox.Show("Cannot insert a new item before selection as the selection is empty; you can either add a new item to the end of the list instead, or select an item first.", "Information", MessageBoxButton.OK);
                return;
            }
            ScheduleChartItem item = new ScheduleChartItem {
                Content = "New Resource"
            };

            item.GanttChartItems.Add(new GanttChartItem {
                Content = "New Task", Start = DateTime.Today, Finish = DateTime.Today.AddDays(1)
            });
            ScheduleChartDataGrid.Items.Insert(ScheduleChartDataGrid.SelectedIndex, item);
            ScheduleChartDataGrid.SelectedItem = item;
        }
        private void ScheduleChartDataGrid_PreviewMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Point controlPosition = e.GetPosition(ScheduleChartDataGrid);
            Point contentPosition = e.GetPosition(ScheduleChartDataGrid.ChartContentElement);

            DateTime          dateTime = ScheduleChartDataGrid.GetDateTime(contentPosition.X);
            ScheduleChartItem itemRow  = ScheduleChartDataGrid.GetItemAt(contentPosition.Y);

            GanttChartItem   item             = null;
            FrameworkElement frameworkElement = e.OriginalSource as FrameworkElement;

            if (frameworkElement != null)
            {
                item = frameworkElement.DataContext as GanttChartItem;
            }

            if (controlPosition.X < ScheduleChartDataGrid.ActualWidth - ScheduleChartDataGrid.GanttChartView.ActualWidth)
            {
                return;
            }
            string message = String.Empty;

            if (controlPosition.Y < ScheduleChartDataGrid.HeaderHeight)
            {
                message = string.Format("You have clicked the chart scale header at date and time {0:g}.", dateTime);
            }
            else if (item != null)
            {
                message = string.Format("You have clicked the task item '{0}' assigned to resource item '{1}' at date and time {2:g}.", item, itemRow, dateTime > item.Finish ? item.Finish : dateTime);
            }
            else if (itemRow != null)
            {
                message = string.Format("You have clicked at date and time {0:g} within the row of item '{1}'.", dateTime, itemRow);
            }
            else
            {
                message = string.Format("You have clicked at date and time {0:g} within an empty area of the chart.", dateTime);
            }

            NotificationsTextBox.AppendText(string.Format("{0}{1}", NotificationsTextBox.Text.Length > 0 ? "\n" : string.Empty, message));
            NotificationsTextBox.ScrollToEnd();
        }
        public MainWindow()
        {
            InitializeComponent();

            GanttChartItem task1 = ScheduleChartDataGrid.Items[0].GanttChartItems[0];

            task1.Start           = DateTime.Today.Add(TimeSpan.Parse("08:00:00"));
            task1.Finish          = DateTime.Today.Add(TimeSpan.Parse("16:00:00"));
            task1.CompletedFinish = DateTime.Today.Add(TimeSpan.Parse("12:00:00"));

            GanttChartItem task21 = ScheduleChartDataGrid.Items[0].GanttChartItems[1];

            task21.Start              = DateTime.Today.AddDays(1).Add(TimeSpan.Parse("12:00:00"));
            task21.Finish             = DateTime.Today.AddDays(2).Add(TimeSpan.Parse("16:00:00"));
            task21.AssignmentsContent = "50%";

            GanttChartItem task22 = ScheduleChartDataGrid.Items[1].GanttChartItems[0];

            task22.Start  = DateTime.Today.AddDays(1).Add(TimeSpan.Parse("12:00:00"));
            task22.Finish = DateTime.Today.AddDays(2).Add(TimeSpan.Parse("16:00:00"));

            for (int i = 3; i <= 16; i++)
            {
                ScheduleChartItem item = new ScheduleChartItem {
                    Content = "Resource " + i
                };
                for (int j = 1; j <= (i - 1) % 4 + 1; j++)
                {
                    item.GanttChartItems.Add(
                        new GanttChartItem
                    {
                        Content         = "Task " + i + "." + j,
                        Start           = DateTime.Today.AddDays(i + (i - 1) * (j - 1)),
                        Finish          = DateTime.Today.AddDays(i * 1.2 + (i - 1) * (j - 1) + 1),
                        CompletedFinish = DateTime.Today.AddDays(i + (i - 1) * (j - 1)).AddDays((i + j) % 5 == 2 ? 2 : 0)
                    });
                }
                ScheduleChartDataGrid.Items.Add(item);
            }

            // You may uncomment the next lines of code to test the component performance:
            // for (int i = 17; i <= 1024; i++)
            // {
            //    ScheduleChartItem item = new ScheduleChartItem { Content = "Resource " + i };
            //    for (int j = 1; j <= (i - 1) % 4 + 1; j++)
            //    {
            //        item.GanttChartItems.Add(
            //            new GanttChartItem
            //            {
            //                Content = "Task " + i + "." + j,
            //                Start = DateTime.Today.AddDays(i + (i - 1) * (j - 1)),
            //                Finish = DateTime.Today.AddDays(i * 1.2 + (i - 1) * (j - 1) + 1)
            //            });
            //    }
            //    ScheduleChartDataGrid.Items.Add(item);
            // }

            // Optionally, define custom schedules for resources, used when scheduling items assigned to those resources.
            // ScheduleChartDataGrid.Items[1].Schedule = new Schedule(
            //     DayOfWeek.Tuesday, DayOfWeek.Saturday, // Working week: between Tuesday and Saturday.
            //     TimeSpan.Parse("07:00:00"), TimeSpan.Parse("15:00:00"), // Working day: between 7 AM and 3 PM.
            //     new TimeInterval[] { // Optionally, generic nonworking intervals.
            //         new TimeInterval(DateTime.Today.AddDays(14), DateTime.Today.AddDays(14).Add(TimeOfDay.MaxValue)), // Holiday: full day.
            //         new TimeInterval(DateTime.Today.AddDays(18), DateTime.Today.AddDays(20).Add(TimeSpan.Parse("12:00:00"))) // Custom time interval off: full and partial day accepted.
            //     },
            //     (date) => { // Optionally, specific nonworking intervals based on date parameter: recurrent breaks and holidays accepted.
            //         if (date.Day % 15 == 0) // First recurrence expression: on decade end days.
            //             return new DayTimeInterval[] {
            //                 new DayTimeInterval(TimeOfDay.MinValue, TimeOfDay.Parse("12:00:00")), // Large interval off: first part of day.
            //                 new DayTimeInterval(TimeOfDay.Parse("12:00:00"), TimeOfDay.Parse("12:30:00")) // Short break: fast lunch time.
            //             };
            //         else if (date.DayOfWeek != DayOfWeek.Monday) // Second recurrence expression: every day except Mondays.
            //             return new DayTimeInterval[] {
            //                 new DayTimeInterval(TimeOfDay.Parse("11:30:00"), TimeOfDay.Parse("12:30:00")) // Break: regular lunch time.
            //             };
            //         return null; // Otherwise use regular timing only.
            //     });

            // Optionally, set AreHierarchyConstraintsEnabled to false to increase performance when you perform hierarchy validation in your application.
            ScheduleChartDataGrid.AreHierarchyConstraintsEnabled = false;

            // Initialize the control area.
            ScalesComboBox.SelectedIndex   = 0;
            ShowWeekendsCheckBox.IsChecked = true;
        }