/// <summary> /// Called when [execute new task]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param> private static void OnExecuteNewTask(object sender, ExecutedRoutedEventArgs args) { GanttControl gantt = args.Source as GanttControl; int count = gantt.Model.InbuiltTaskCollection.Count; if (count > 0) { /// Creating new Task and adding to the source gantt.Model.InbuiltTaskCollection.Add(new TaskDetails { StartDate = gantt.Model.InbuiltTaskCollection[count - 1].FinishDate, Duration = new TimeSpan(2, 0, 0, 0) }); } else { /// Creating new Task and adding to the source gantt.Model.InbuiltTaskCollection.Add(new TaskDetails() { StartDate = gantt.ActualStartTime.AddDays(14), FinishDate = gantt.ActualStartTime.AddDays(16) }); } /// Type casting the collection for calculating the Task Id var tempCol = new ObservableCollection <IGanttTask>(gantt.Model.InbuiltTaskCollection.Cast <IGanttTask>()); /// Calculating the Task ID after adding a new Item CalculatedTaskId(tempCol, 1); }
/// <summary> /// Called when [execute outdent task]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param> private static void OnExecuteOutdentTask(object sender, ExecutedRoutedEventArgs args) { GanttControl gantt = args.Source as GanttControl; /// The loop has been limitted to one, to perform the out-dent operation on only tge first item in the selected items collection. /// By replacing the condition of loop you can achieve it for all selected items. for (int i = 0; i < 1; i++) { TaskDetails currentTask = gantt.SelectedItems[i] as TaskDetails; /// Getting the parent of the current Task TaskDetails parentTask = gantt.Model.GetParentOfItem(currentTask) as TaskDetails; DateTime parentStart; DateTime parentEnd; if (parentTask == null) { continue; } else { parentStart = parentTask.StartDate; parentEnd = parentTask.FinishDate; /// Getting the parent of the current Task TaskDetails nextLevelParent = gantt.Model.GetParentOfItem(parentTask) as TaskDetails; int currentIndex = parentTask.Child.IndexOf(currentTask); parentTask.Child.Remove(currentTask); while ((parentTask.Child.Count) > currentIndex) { TaskDetails child = parentTask.Child[currentIndex] as TaskDetails; /// Changing the hierarchy to achieve indent parentTask.Child.Remove(child); currentTask.Child.Add(child); } if (nextLevelParent == null) { /// Changing the hierarchy to achieve indent int parentIndex = gantt.Model.InbuiltTaskCollection.IndexOf(parentTask); gantt.Model.InbuiltTaskCollection.Insert(parentIndex + 1, currentTask); } else { /// Changing the hierarchy to achieve indent int parentIndex = nextLevelParent.Child.IndexOf(parentTask); nextLevelParent.Child.Insert(parentIndex + 1, currentTask); } parentTask.StartDate = parentStart; parentTask.FinishDate = parentEnd; } gantt.SelectedItems.Clear(); gantt.SelectedItems.Add(currentTask); } }
protected override object CreateControlsCore() { control = new GanttControl(); foreach (IModelColumn column in Model.Columns) { var ganttColumn = new DevExpress.XtraTreeList.Columns.TreeListColumn(); ganttColumn.Caption = column.Caption; ganttColumn.FieldName = column.PropertyName; ganttColumn.Name = column.PropertyName + "Column"; ganttColumn.Visible = true; ganttColumn.SortIndex = column.SortIndex; control.Columns.Add(ganttColumn); } control.KeyFieldName = nameof(ITask.Id); control.ParentFieldName = nameof(ITask.Parent); control.ChartMappings.TextFieldName = nameof(ITask.Name); control.ChartMappings.StartDateFieldName = nameof(ITask.StartDate); control.ChartMappings.FinishDateFieldName = nameof(ITask.EndDate); control.ChartMappings.ProgressFieldName = nameof(ITask.Progress); control.ChartMappings.PredecessorsFieldName = nameof(ITask.PredecessorTasks); control.AllowTouchGestures = DevExpress.Utils.DefaultBoolean.True; control.OptionsBehavior.ScheduleMode = DevExpress.XtraGantt.Options.ScheduleMode.Auto; control.OptionsCustomization.AllowModifyTasks = DevExpress.Utils.DefaultBoolean.True; control.OptionsCustomization.AllowModifyDependencies = DevExpress.Utils.DefaultBoolean.True; control.OptionsCustomization.AllowModifyProgress = DevExpress.Utils.DefaultBoolean.True; control.SelectionChanged += Control_SelectedIndexChanged; control.FocusedNodeChanged += Control_FocusedNodeChanged; control.MouseDoubleClick += Control_MouseDoubleClick; control.KeyDown += Control_KeyDown; Refresh(); return(control); }
/// <summary> /// Handles the Click event of the ExportBtn control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> void ExportBtn_Click(object sender, System.Windows.RoutedEventArgs e) { RenderTargetBitmap bmp; BitmapEncoder bitmapEncoder; int width; GanttControl Gantt = this.AssociatedObject.TabControl.SelectedContent as GanttControl; //Extract the GanttChart region from GanttControl. ScrollViewer chart = Gantt.FindName <ScrollViewer>("PART_ScheduleViewScrollViewer"); ComboBoxItem item = AssociatedObject.ExpOption.SelectedValue as ComboBoxItem; if (item.Content.ToString() == "Full Region") { //Measure the total size of the Gantt Rendered. Gantt.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); Gantt.Arrange(new Rect(new Size(Gantt.DesiredSize.Width, Gantt.DesiredSize.Height))); bmp = new RenderTargetBitmap( (int)Gantt.DesiredSize.Width, (int)Gantt.DesiredSize.Height, 96, 96, PixelFormats.Default); } else { bmp = new RenderTargetBitmap( (int)Gantt.ActualWidth, (int)Gantt.ActualHeight, 96, 96, PixelFormats.Default); } //Rendering the Chart region of the GanttControl to BitMap bmp.Render(chart); //Getting the size of GanttGrid width = (int)(Gantt.DesiredSize.Width - chart.ActualWidth); //The bitmap will contain the empty space of GanttGrid. To remove that we Cropping the GanttGrid space from image using CroppedBitmap CroppedBitmap crpBmp = new CroppedBitmap(bmp, new Int32Rect(width, 0, (int)chart.ActualWidth, (int)chart.ActualHeight)); bitmapEncoder = new PngBitmapEncoder(); bitmapEncoder.Frames.Add(BitmapFrame.Create(crpBmp)); SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.FileName = "Untitled"; saveFileDialog.DefaultExt = "png"; saveFileDialog.Filter = "PNG Files (*.png)|*.png|Jpeg Files (*.jpg)|*.jpg|Bitmap Files (*.bmp)|*.bmp|All files (*.*)|*.*"; saveFileDialog.FilterIndex = 1; if (saveFileDialog.ShowDialog() == true) { using (Stream stream = saveFileDialog.OpenFile()) { bitmapEncoder.Save(stream); stream.Close(); // Commented this line as facing issue in core project while open the saved image //System.Diagnostics.Process.Start(saveFileDialog.FileName); } } }
/// <summary> /// Called when [execute export to XML]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param> private static void OnExecuteExportToXML(object sender, ExecutedRoutedEventArgs args) { GanttControl gantt = args.Source as GanttControl; if (gantt.ExportToXML()) { MessageBox.Show("Tasks exported successfully.", "XML Import/Export", MessageBoxButton.OK, MessageBoxImage.Information); } }
/// <summary> /// Called when [execute get statistics]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param> private static void OnExecuteGetStatistics(object sender, ExecutedRoutedEventArgs args) { GanttControl gantt = args.Source as GanttControl; ProjectInfo Info = new ProjectInfo(); Info = gantt.GetProjectStatistics(); StatisticsViewModel view = new StatisticsViewModel(Info); StatisticsWindow statisticsView = new StatisticsWindow(view); statisticsView.ShowDialog(); }
public MainWindow() { InitializeComponent(); this.DataContext = new ViewModel(); ganttControl = new GanttControl { ItemsSource = (this.DataContext as ViewModel).TaskDetails, RowHeight = 60 }; ganttControl.Loaded += GanttControl_Loaded; this.Content = ganttControl; }
/// <summary> /// Called when [can execute delete task]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="System.Windows.Input.CanExecuteRoutedEventArgs"/> instance containing the event data.</param> private static void OnCanExecuteDeleteTask(object sender, CanExecuteRoutedEventArgs args) { GanttControl gantt = sender as GanttControl; if (gantt.SelectedItems == null || gantt.SelectedItems.Count <= 0) { args.CanExecute = false; } else { args.CanExecute = true; } }
private void MetroStyleComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { GanttControl gantt = AssociatedObject.Gantt; MetroStyleColor Color = (e.AddedItems[0] as MetroStyleColor); if (gantt != null) { if (gantt.GanttGrid != null) { gantt.GanttGrid.Model.Options.HighlightSelectionBackground = Color.Brush; gantt.GanttGrid.InternalGrid.InvalidateCell(gantt.GanttGrid.Model.SelectedCells); } } }
private void View_ControlsCreated(object sender, EventArgs e) { RibbonForm ribbonForm = Frame.Template as RibbonForm; if (ribbonForm != null && ribbonForm.Ribbon != null) { ribbonControl = ribbonForm.Ribbon; ganttControl = View.Editor?.Control as GanttControl; if (ribbonControl != null && ganttControl != null) { AddGanttPageToRibbon(); } } }
/// <summary> /// Called when [execute insert task]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param> private static void OnExecuteInsertTask(object sender, ExecutedRoutedEventArgs args) { GanttControl gantt = args.Source as GanttControl; TaskDetails selectedTask = gantt.SelectedItems[gantt.SelectedItems.Count - 1] as TaskDetails; /// Getting the parent of selected Item TaskDetails parent = gantt.Model.GetParentOfItem(selectedTask) as TaskDetails; TaskDetails newTask; /// Based on the parent value the task will be added in root collectin or in child collection. if (parent == null) { int count = gantt.Model.InbuiltTaskCollection.Count; int index = gantt.Model.InbuiltTaskCollection.IndexOf(selectedTask); if (index <= -1) { return; } newTask = new TaskDetails { TaskId = count + 1, StartDate = selectedTask.FinishDate, Duration = new TimeSpan(1, 0, 0, 0) }; /// Inserting a new task to the root collection. gantt.Model.InbuiltTaskCollection.Insert(index + 1, newTask); } else { int index = parent.Child.IndexOf(selectedTask as IGanttTask); newTask = new TaskDetails { TaskId = selectedTask.TaskId + 1, StartDate = selectedTask.FinishDate, Duration = new TimeSpan(1, 0, 0, 0) }; /// Inserting a new task to the child collection. parent.Child.Insert(index + 1, newTask); } gantt.SelectedItems.Clear(); gantt.SelectedItems.Add(newTask); /// Type casting the collection for calculating the Task Id var tempCol = new ObservableCollection <IGanttTask>(gantt.Model.InbuiltTaskCollection.Cast <IGanttTask>()); /// Calculating the Task ID after inserting a new Item CalculatedTaskId(tempCol, 1); }
/// <summary> /// Called when [execute delete task]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param> private static void OnExecuteDeleteTask(object sender, ExecutedRoutedEventArgs args) { GanttControl gantt = args.Source as GanttControl; /// This will delete only the first Item of the seleted Item from the source TaskDetails task = gantt.Model.GetParentOfItem(gantt.SelectedItems[0]) as TaskDetails; if (task == null) { gantt.Model.InbuiltTaskCollection.Remove(gantt.SelectedItems[0] as TaskDetails); } else { task.Child.Remove(gantt.SelectedItems[0] as IGanttTask); } gantt.SelectedItems.Clear(); }
void EnableAndDisableButtonVisibility() { GanttControl gantt = AssociatedObject.Gantt; if (gantt.SelectedItems == null || gantt.SelectedItems.Count <= 0) { AssociatedObject.DeleteTask.Background = AssociatedObject.Outdent.Background = AssociatedObject.Indent.Background = AssociatedObject.InsertTask.Background = new SolidColorBrush(Colors.WhiteSmoke); AssociatedObject.DeleteTask.Foreground = AssociatedObject.Outdent.Foreground = AssociatedObject.Indent.Foreground = AssociatedObject.InsertTask.Foreground = new SolidColorBrush(Colors.LightGray); AssociatedObject.DeleteTask.IsHitTestVisible = AssociatedObject.Outdent.IsHitTestVisible = AssociatedObject.Indent.IsHitTestVisible = AssociatedObject.InsertTask.IsHitTestVisible = false; } else { AssociatedObject.DeleteTask.Background = AssociatedObject.Outdent.Background = AssociatedObject.Indent.Background = AssociatedObject.InsertTask.Background = AssociatedObject.NewTask.Background; AssociatedObject.DeleteTask.Foreground = AssociatedObject.Outdent.Foreground = AssociatedObject.Indent.Foreground = AssociatedObject.InsertTask.Foreground = AssociatedObject.NewTask.Foreground; AssociatedObject.DeleteTask.IsHitTestVisible = AssociatedObject.Outdent.IsHitTestVisible = AssociatedObject.Indent.IsHitTestVisible = AssociatedObject.InsertTask.IsHitTestVisible = true; } }
private void DeleteTask_Click(object sender, RoutedEventArgs e) { GanttControl gantt = AssociatedObject.Gantt; /// This will delete only the first Item of the seleted Item from the source TaskDetails task = gantt.Model.GetParentOfItem(gantt.SelectedItems[0]) as TaskDetails; if (task == null) { gantt.Model.InbuiltTaskCollection.Remove(gantt.SelectedItems[0] as TaskDetails); } else { task.Child.Remove(gantt.SelectedItems[0] as IGanttTask); } gantt.SelectedItems.Clear(); }
private void Indent_Click(object sender, RoutedEventArgs e) { GanttControl gantt = AssociatedObject.Gantt; /// The loop has been limitted to one, to perform the intend operation on only the first item in the selected items collection. /// By replacing the condition of loop you can achieve it for all selected items. for (int i = 0; i < 1; i++) { TaskDetails currentTask = gantt.SelectedItems[i] as TaskDetails; /// Getting the parent of the current Task TaskDetails parentTask = gantt.Model.GetParentOfItem(currentTask) as TaskDetails; if (parentTask == null) { int index = gantt.Model.InbuiltTaskCollection.IndexOf(currentTask); if (index < 1) { continue; } /// Changing the hierarchy to achieve indent gantt.Model.InbuiltTaskCollection.Remove(currentTask); gantt.Model.InbuiltTaskCollection[index - 1].Child.Add(currentTask); } else { int currentIndex = parentTask.Child.IndexOf(currentTask); if ((currentIndex - 1) >= 0) { /// Changing the hierarchy to achieve indent parentTask.Child.Remove(currentTask as IGanttTask); parentTask.Child[currentIndex - 1].Child.Add(currentTask); } } gantt.SelectedItems.Clear(); gantt.SelectedItems.Add(currentTask); } }
/// <summary> /// Called when [execute save XML]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param> private static void OnExecuteSaveXML(object sender, ExecutedRoutedEventArgs args) { GanttControl gantt = args.Source as GanttControl; gantt.ExportToXML("../../Data/ProjectData.xml"); }
/// <summary> /// Called when [execute save as XML]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param> private static void OnExecuteSaveAsXML(object sender, ExecutedRoutedEventArgs args) { GanttControl gantt = args.Source as GanttControl; gantt.ExportToXML(); }
/// <summary> /// Called when [execute load XML]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param> private static void OnExecuteLoadXML(object sender, ExecutedRoutedEventArgs args) { GanttControl gantt = args.Source as GanttControl; gantt.ImportFromXML(); }
/// <summary> /// Called when [execute clear all task]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param> private static void OnExecuteClearAllTask(object sender, ExecutedRoutedEventArgs args) { GanttControl gantt = args.Source as GanttControl; gantt.Model.InbuiltTaskCollection.Clear(); }
/// <summary> /// Called when [execute load default view]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param> private static void OnExecuteLoadDefaultView(object sender, ExecutedRoutedEventArgs args) { GanttControl gantt = args.Source as GanttControl; gantt.LoadDefaultTableView(); }