This is a migrated thread and some comments may be shown as answers.

Need to include Zoom option in GanttView

0 Answers 124 Views
GanttView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
kanna
Top achievements
Rank 1
kanna asked on 20 Sep 2012, 03:37 PM
Hi,
I am using GanttView for Silverlight and i am using collection to Bind the data(not in MVMM method in online example).
Please let me know how to include the Zoom option to the collection and also i want a suggestion to add the dependency for the below code (binding data to Collection).

Please find my code as below.
Regards,
Kannan

XAML code:
<Grid x:Name="LayoutRoot" Background="White">
       <!--<telerik:RadGanttView Name="xGanttView" HorizontalAlignment="Left" Margin="18,1,0,0" VerticalAlignment="Top" Width="Auto" />-->
       <telerik:RadGanttView x:Name="ganttview"  BorderBrush="#FFD6D4D4" Width="1000"
               BorderThickness="1 0 1 1"
                Grid.Row="1" Margin="0 6 0 0">
           <telerik:RadGanttView.TimeRulerLines>
               <telerik:GroupTickLine>
                   <telerik:TickInterval Interval="OneMonth" FormatString="{}{0:MMMM, yyyy}" />
               </telerik:GroupTickLine>
               <telerik:MajorTickLine>
                   <telerik:TickInterval Interval="OneDay" FormatString="Day {0:dd}" />
               </telerik:MajorTickLine>
 
           </telerik:RadGanttView.TimeRulerLines>
 
 
           <telerik:RadGanttView.Columns>
               <telerik:TreeColumnDefinition MemberBinding="{Binding Title}" Header="" ColumnWidth="5">
                
               </telerik:TreeColumnDefinition>
               <telerik:ColumnDefinition MemberBinding="{Binding Title}" Header="Title" ColumnWidth="120">
                   
               </telerik:ColumnDefinition>
 
               <telerik:ColumnDefinition MemberBinding="{Binding Start,Converter={StaticResource TimeToCustomStringConverter}}"  Header="Start"  ColumnWidth="120">
               </telerik:ColumnDefinition>
               <telerik:ColumnDefinition MemberBinding="{Binding End,Converter={StaticResource TimeToCustomStringConverter}}" Header="End" ColumnWidth="120">
                </telerik:ColumnDefinition>
               <telerik:ColumnDefinition MemberBinding="{Binding Duration,Converter={StaticResource TimeToCustomStringConverter}}" Header="Duration" ColumnWidth="100">
               </telerik:ColumnDefinition>
               <telerik:ColumnDefinition MemberBinding="{Binding Progress}" Header="Progress" ColumnWidth="100">
               </telerik:ColumnDefinition>
               <!--<telerik:ColumnDefinition MemberBinding="{Binding IsMilestone}" Header="IsMilestone" ColumnWidth="100" />-->
           </telerik:RadGanttView.Columns>
         
       </telerik:RadGanttView>
       
   </Grid>
C# code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.GanttView;
using Telerik.Windows.Controls.Scheduling;
using System.Collections.ObjectModel;
using SLGanttChart.WcfRef;
using Telerik.Windows.Controls;
namespace SLGanttChart
{
    public partial class MainPage : UserControl
    {
        public static Collection<WcfRef.ProjectPlan_BO> lstProjectPlan;
        private IRangeGenerator specialSlotsGenerator;
        public static Collection<ProjectPlan> lstProject;
        private readonly static Dictionary<string, Tuple<GanttTask, string>> taskIdToGanttTask = new Dictionary<string, Tuple<GanttTask, string>>();
        private readonly static Dictionary<string, IList<string>> taskToRelation = new Dictionary<string, IList<string>>();
        public MainPage()
        {
            InitializeComponent();
            Random rnd = new Random();
 
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
           
        }
 
        void wcf_GetProjectPlanForDashboardCompleted(object sender, GetProjectPlanForDashboardCompletedEventArgs e)
        {
            lstProjectPlan = e.Result;
            int i=0;
            int j=0;
 
            DateTime minDate=(from lst in lstProjectPlan select lst.PlannedStartDate).Min();
 
            DateTime maxDate=(from lst in lstProjectPlan select lst.PlannedStartDate).Max();
 
            VisibleRange vr = new VisibleRange(minDate, maxDate);
            ganttview.VisibleRange = vr;
 
            var tasks=new ObservableCollection<GanttTask>();
 
            var gt = new GanttTask();
            //gt.UniqueId = "0";
            gt.Title = "Project Name";
            gt.Start = maxDate;
            gt.End = minDate;
            
            Boolean isDependency=false;
            for (i = 0; i < lstProjectPlan.Count-1; i++)
            {
                j = i++;
                if (j <= i)
                {
                    if (lstProjectPlan[i].ExecutableFlag == "DEPN")
                        isDependency = true;
                    else if(lstProjectPlan[j].ExecutableFlag =="DEPN")
                        isDependency=false;
                }
                if (isDependency)
                {
                    var task1 = new GanttTask();
                    var task2 = new GanttTask();
                    //task1.UniqueId = i + lstProjectPlan[i].ExecutableFlag;
                    if (lstProjectPlan[i].ExecutableFlag == "DEPN")
                        task1.Title = lstProjectPlan[i].ActivityName + "*";
                    else
                        task1.Title = lstProjectPlan[i].ActivityName;
 
                    if (lstProjectPlan[i].PlannedStartDate != null)
                        task1.Start = lstProjectPlan[i].PlannedStartDate;
                    else if (lstProjectPlan[i].RevisedStartDate != null)
                        task1.Start = lstProjectPlan[i].RevisedStartDate;
                    else if (lstProjectPlan[i].ActualStartDate != null)
                        task1.Start = lstProjectPlan[i].ActualStartDate;
 
 
                    if (lstProjectPlan[i].PlannedEndDate != null)
                        task1.End = lstProjectPlan[i].PlannedEndDate;
                    else if (lstProjectPlan[i].RevisedEndDate != null)
                        task1.End = lstProjectPlan[i].RevisedEndDate;
                    else if (lstProjectPlan[i].ActualEndDate != null)
                        task1.End = lstProjectPlan[i].ActualEndDate;
 
                    if (lstProjectPlan[i].ExecutableFlag == "MILE")
                        task1.IsMilestone = true;
 
                    task1.Progress = lstProjectPlan[i].Percentage;
 
 
 
 
                    //task2.UniqueId = j + lstProjectPlan[j].ExecutableFlag;
                    task2.Title = lstProjectPlan[j].ActivityName;
 
                    if (lstProjectPlan[j].PlannedStartDate != null)
                        task2.Start = lstProjectPlan[j].PlannedStartDate;
                    else if (lstProjectPlan[j].RevisedStartDate != null)
                        task2.Start = lstProjectPlan[j].RevisedStartDate;
                    else if (lstProjectPlan[j].ActualStartDate != null)
                        task2.Start = lstProjectPlan[j].ActualStartDate;
 
 
                    if (lstProjectPlan[j].PlannedEndDate != null)
                        task2.End = lstProjectPlan[j].PlannedEndDate;
                    else if (lstProjectPlan[j].RevisedEndDate != null)
                        task2.End = lstProjectPlan[j].RevisedEndDate;
                    else if (lstProjectPlan[j].ActualEndDate != null)
                        task2.End = lstProjectPlan[j].ActualEndDate;
 
                    if (lstProjectPlan[j].ExecutableFlag == "MILE")
                        task2.IsMilestone = true;
 
                    task2.Progress = lstProjectPlan[j].Percentage;
 
                    task2.Dependencies.Add(new Dependency() { FromTask = task1 ,Type=RelationType.FinishFinish});
                    gt.Children.Add(task1);
                    gt.Children.Add(task2);
                }
                else
                {
                    var task1 = new GanttTask();
                    //task1.UniqueId = i + lstProjectPlan[i].ExecutableFlag;
                    task1.Title = lstProjectPlan[i].ActivityName;
 
                    if (lstProjectPlan[i].PlannedStartDate != null)
                        task1.Start = lstProjectPlan[i].PlannedStartDate;
                    else if (lstProjectPlan[i].RevisedStartDate != null)
                        task1.Start = lstProjectPlan[i].RevisedStartDate;
                    else if (lstProjectPlan[i].ActualStartDate != null)
                        task1.Start = lstProjectPlan[i].ActualStartDate;
 
 
                    if (lstProjectPlan[i].PlannedEndDate != null)
                        task1.End = lstProjectPlan[i].PlannedEndDate;
                    else if (lstProjectPlan[i].RevisedEndDate != null)
                        task1.End = lstProjectPlan[i].RevisedEndDate;
                    else if (lstProjectPlan[i].ActualEndDate != null)
                        task1.End = lstProjectPlan[i].ActualEndDate;
 
                    if (lstProjectPlan[i].ExecutableFlag == "MILE")
                        task1.IsMilestone = true;
 
                    task1.Progress = lstProjectPlan[i].Percentage;
                    gt.Children.Add(task1);
                }
                 
 
            }
            tasks.Add(gt);
 
            ganttview.TasksSource = tasks;
        }
 
        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
 
            //WCFServiceClient wcf = new WCFServiceClient("BasicHttpBinding_WCFService", "https://qarmtestother.cognizant.com/wcfservice.svc");
            //wcf.GetProjectPlanForDashboardCompleted += new EventHandler<GetProjectPlanForDashboardCompletedEventArgs>(wcf_GetProjectPlanForDashboardCompleted);
            //wcf.GetProjectPlanForDashboardAsync(8347);
 
            //getTasks();
            fillTasks();
         
        }
        public void getTasks()
        {
            var Tasks = new ObservableCollection<GanttTask>();
 
            var d = new DateTime(2012, 3, 1);
 
            for (int i = 0; i < 4; i++)
            {
                var gt = new GanttTask(d.AddDays(14 * i), d.AddDays(14 * i + 14), "Title " + i.ToString());
                
                for (int j = 0; j < gt.Duration.Days; j++)
                {
                    var childGT = new GanttTask();
                    childGT.Start = gt.Start.AddDays(j);
                    childGT.End = childGT.Start.AddHours(23);
                    childGT.Title = "Child " + i.ToString() + "/" + j.ToString();
                    gt.Children.Add(childGT);
                    if (j > 0)
                    {
                        GanttTask prevGt = gt.Children[j - 1] as GanttTask;
                        prevGt.Dependencies.Add(new Dependency() { FromTask = prevGt });
                        gt.Children.Add(prevGt);
                    }
 
                    
 
                }
                 
                Tasks.Add(gt);
            }
 
            ganttview.TasksSource = Tasks;
 
            var majorTickLine = new MajorTickLine();
            majorTickLine.Intervals.Add(new TickInterval { Interval = TimeRulerTickInterval.OneDay });
 
            this.ganttview.TimeRulerLines.Clear();
            this.ganttview.TimeRulerLines.Add(majorTickLine);
 
        }
 
        public void fillTasks()
        {
            lstProject = new Collection<ProjectPlan>();
            ProjectPlan lstPrj = new ProjectPlan();
            lstPrj.Title = "ProjectABC";
            lstPrj.Start = Convert.ToDateTime("12/07/2012");
            lstPrj.End = Convert.ToDateTime("01/10/2012");
            lstPrj.IsDependency = false;
            lstPrj.IsMilestone = false;
            lstPrj.Duration = lstPrj.End.Subtract(lstPrj.Start);
            lstProject.Add(lstPrj);
 
            ProjectPlan lstPrj1 = new ProjectPlan();
            lstPrj1.Title = "Code Drop";
            lstPrj1.Start = Convert.ToDateTime("12/07/2012");
            lstPrj1.End = Convert.ToDateTime("12/07/2012");
            lstPrj1.IsDependency = true;
            lstPrj1.IsMilestone = false;
            lstPrj1.Duration = lstPrj1.End.Subtract(lstPrj1.Start);
            lstProject.Add(lstPrj1);
 
 
 
            ProjectPlan lstPrj2 = new ProjectPlan();
            lstPrj2.Title = "ST Cycle1";
            lstPrj2.Start = Convert.ToDateTime("13/07/2012");
            lstPrj2.End = Convert.ToDateTime("31/08/2012");
            lstPrj2.IsDependency = false;
            lstPrj2.IsMilestone = false;
            lstPrj2.Duration = lstPrj2.End.Subtract(lstPrj2.Start);
            lstProject.Add(lstPrj2);
 
            ProjectPlan lstPrj3 = new ProjectPlan();
            lstPrj3.Title = "ST Cycle2";
            lstPrj3.Start = Convert.ToDateTime("03/09/2012");
            lstPrj3.End = Convert.ToDateTime("29/09/2012");
            lstPrj3.IsDependency = false;
            lstPrj3.IsMilestone = false;
            lstPrj3.Duration = lstPrj3.End.Subtract(lstPrj3.Start);
            lstProject.Add(lstPrj3);
 
 
            ProjectPlan lstPrj4 = new ProjectPlan();
            lstPrj4.Title = "ETOR Report";
            lstPrj4.Start = Convert.ToDateTime("01/10/2012");
            lstPrj4.End = Convert.ToDateTime("29/10/2012");
            lstPrj4.IsDependency = false;
            lstPrj4.IsMilestone = true;
            lstPrj4.Duration = lstPrj4.End.Subtract(lstPrj4.Start);
            lstProject.Add(lstPrj4);
 
 
 
            DateTime dtMax = (from lst in lstProject select lst.Start).Max();
            DateTime dtMin = (from lst in lstProject select lst.End).Min();
 
            //var d = dtMax;
            ganttview.VisibleRange = new VisibleRange(dtMin, dtMax);
            var tasks = new ObservableCollection<GanttTask>();
            var gt = new GanttTask();
            gt.UniqueId = "0";
            gt.Title = lstPrj.Title;
            gt.Start = dtMin;
            gt.End = dtMax;
            gt.Duration = dtMax.Subtract(dtMin);
 
            //gt.Progress=
            //this.SpecialSlotsGenerator = new WeekDaysGenerator();
 
            ganttview.SpecialSlotsGenerator = specialSlotsGenerator;
            int i = 0;
            foreach (ProjectPlan lst in lstProject.Skip(1))
            {
                var childGT = new GanttTask();
                childGT.UniqueId = i.ToString();
                childGT.Start = lst.Start;
                childGT.End = lst.End;
                childGT.Title = lst.Title;
                childGT.Duration = childGT.End.Subtract(childGT.Start);
                childGT.IsMilestone = lst.IsMilestone;
 
                gt.Children.Add(childGT);
                i++;
            }
 
            tasks.Add(gt);
 
 
 
 
            ganttview.TasksSource = tasks;
 
            var majorTickLine = new MajorTickLine();
            majorTickLine.Intervals.Add(new TickInterval { Interval = TimeRulerTickInterval.OneDay });
 
            this.ganttview.TimeRulerLines.Clear();
            this.ganttview.TimeRulerLines.Add(majorTickLine);
         
        }
    }
 
 
    public class ProjectPlan
        {
           public string Title{get;set;}
            public DateTime Start {get;set;}
            public DateTime End { get; set; }
            public double Progress { get; set; }
            public TimeSpan Duration { get; set; }
            public string ExecutableFlag { get; set; }
            public Boolean IsMilestone { get; set; }
            public Boolean IsDependency { get; set; }
        }
 
}
Tags
GanttView
Asked by
kanna
Top achievements
Rank 1
Share this question
or