Check out my new blog at https://shibumiware.blogspot.com

Monday, June 02, 2008

mpFx - Reading & Displaying Project Server Data in a WinForms Application

I continue to work the mpFx project when I have a few minutes down time.   This weekend I implemented simple functionality to read a project from Project Server and render it in a WinForms form.  Here is what a simple project with dependencies and a summary task looks like:

image

Here is what it looks like in Microsoft Project:

image

You really should check out the project management data control and Gantt chart controls from DlhSoft.  I am using them in the mpFx test harness and so far I am really impressed.

Here is the code that renders the project information:

   1: private void LoadProject()
   2: {
   3:     toolStripProgressBar.Visible = true;
   4:  
   5:     ProjectDataSet.TaskDataTable tasks = _ProjectDataSet.Task;
   6:     ProjectDataSet.DependencyDataTable dependencies = _ProjectDataSet.Dependency;
   7:  
   8:     ganttChartView.StartMember = "Start";
   9:     ganttChartView.WorkMember = "Work";
  10:     ganttChartView.CompletedWorkMember = "CompletedWork";
  11:     ganttChartView.PredecessorsMember = "Predecessors";
  12:     ganttChartView.ResourcesMember = "Resources";
  13:     ganttChartView.GanttImageIndexMember = "IconIndex";
  14:     ganttChartView.PlannedStartMember = "PlannedStart";
  15:     ganttChartView.PlannedWorkMember = "PlannedWork";
  16:     ganttChartView.PlannedCompletedWorkMember = "PlannedCompletedWork";
  17:     ganttChartView.IndentLevelMember = "IndentLevel";
  18:     ganttChartView.BarTextMember = "Description";
  19:     ganttChartView.PredecessorsMember = "Predecessors";
  20:  
  21:     ganttChartView.ShowDependencies = true;
  22:  
  23:     int id = 1;
  24:  
  25:     DateTime earliestDate = DateTime.Now.AddYears(2000);
  26:  
  27:     foreach (ProjectDataSet.TaskRow task in tasks)
  28:     {
 
I wouldn't normally do the following conditionals, but for demo purposes it is what I intended
 
  29:         if (!task.IsTASK_NAMENull() && !task.IsTASK_START_DATENull() && !task.IsTASK_FINISH_DATENull())
  30:         {
  31:             DlhTask dlhTask = new DlhTask();
  32:  
  33:             dlhTask.ID = id++;
  34:             dlhTask.Guid = task.TASK_UID;
  35:             dlhTask.Name = task.IsTASK_NAMENull() ? string.Empty : task.TASK_NAME;
  36:             dlhTask.Start = task.TASK_START_DATE;
  37:  
  38:             if (dlhTask.Start < earliestDate)
  39:             {
  40:                 earliestDate = dlhTask.Start;
  41:             }
  42:  
  43:             dlhTask.Finish = task.TASK_FINISH_DATE;
  44:  
  45:             dlhTask.IndentLevel = task.TASK_OUTLINE_LEVEL;
  46:  
  47:             _tasks.Add(dlhTask);
  48:         }
  49:     }
  50:  
  51:     foreach (ProjectDataSet.DependencyRow dependency in dependencies.Rows)
  52:     {
  53:         foreach (DlhTask task in _tasks)
  54:         {
  55:             if (task.Guid == dependency.LINK_PRED_UID)
  56:             {
  57:                 // This task is a predecessor to task dependency.LINK_SUCC_UID
  58:  
  59:                 DlhTask taskWithPredecessor = FindTaskByGuid(dependency.LINK_SUCC_UID);
  60:  
  61:                 if (taskWithPredecessor != null)
  62:                 {
  63:                     if (string.IsNullOrEmpty(taskWithPredecessor.Predecessors))
  64:                     {
  65:                         taskWithPredecessor.Predecessors = task.ID.ToString();
  66:                     }
  67:                     else
  68:                     {
  69:                         taskWithPredecessor.Predecessors = string.Format("{0},{1}", taskWithPredecessor.Predecessors, task.ID);
  70:                     }
  71:                 }
  72:             }
  73:         }
  74:     }
  75:  
  76:     ganttChartView.ScaleType = ScaleType.Months;
  77:     ganttChartView.InitialDate = earliestDate.AddDays(-2);
  78:     ganttChartView.DataSource = _tasks;
  79:  
  80:     toolStripProgressBar.Visible = false;
  81: }

 

Pretty slick..and very easy.  

No comments :

Disclaimer

Content on this site is provided "AS IS" with no warranties and confers no rights. Additionally, all content on this site is my own personal opinion and does not represent my employer's view in any way.