Click here to Skip to main content
15,885,366 members
Articles / Desktop Programming / WPF

MPP Viewer

Rate me:
Please Sign up or sign in to vote.
4.75/5 (13 votes)
15 Jun 2011CPOL3 min read 103.5K   4.1K   41  
MPP Viewer is a simple viewer for Microsoft Project files. I works well with 2000/2003/2007 file formats.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProjectLibrary.Mpp;
using System.Windows;
using System.Windows.Input;

namespace ProjectViewer.ViewModel
{
    public class TaskViewModel : WorkspaceViewModel
    {
        private MppTask _mppTask;
        internal MppTask Task { get { return _mppTask; } private set { _mppTask = value; } }

        public TaskViewModel(MppTask mppTask)
        {
            ChildTasks = new List<TaskViewModel>();
            Resources = new List<ResourceViewModel>();

            CopyToClipboard = new RelayCommand(param => Clipboard.SetText(this.ToString()));

            DisplayName = mppTask.Name;
            _mppTask = mppTask;
        }

        public TaskViewModel(MppTask mppTask, TasksViewModel parent)
            : this(mppTask)
        {
            this.Parent = parent;

            foreach (var task in mppTask.ChildTasks)
            {
                ChildTasks.Add(new TaskViewModel(task, parent));
            }

            foreach (var resource in mppTask.Resources)
            {
                Resources.Add(new ResourceViewModel(resource));
            }


        }

        public ICommand CopyToClipboard { get; private set; }

        public long Id
        {
            get { return _mppTask.Id; }
        }

        public long UniqueId
        {
            get { return _mppTask.UniqueId; }
        }

        public string Name
        {
            get { return _mppTask.Name; }
        }

        public DateTime? StartDate
        {
            get { return _mppTask.StartDate; }
        }

        public DateTime? FinishDate
        {
            get { return _mppTask.FinishDate; }
        }

        public DateTime? ActualStartDate
        {
            get { return _mppTask.ActualStartDate; }
        }

        public DateTime? ActualFinishDate
        {
            get { return _mppTask.ActualFinishDate; }
        }

        public DateTime? ConstraintDate
        {
            get { return _mppTask.ConstraintDate; }
        }

        public TimeSpan Duration
        {
            get { return _mppTask.Duration; }
        }

        public List<ResourceViewModel> _resources;
        public List<ResourceViewModel> Resources
        {
            get { return _resources; }
            private set { _resources = value; }
        }

        public List<TaskViewModel> _childTasks;
        public List<TaskViewModel> ChildTasks
        {
            get { return _childTasks; }
            private set { _childTasks = value; }
        }

        public List<long> PredecessorTaskIds
        {
            get { return _mppTask.PredecessorTaskIds; }
        }

        public string PredecessorTaskIdsString
        {
            get { return String.Join(", ", PredecessorTaskIds); }
        }

        public long ParentTaskId
        {
            get { return _mppTask.ParentTaskId; }
        }

        public string ResourceNames
        {
            get { return _mppTask.ResourceNames; }
        }

        public double PercentageComplete
        {
            get { return _mppTask.PercentageComplete; }
        }

        public MppPriority Priority
        {
            get { return _mppTask.Priority; }
        }

        public string Notes
        {
            get { return _mppTask.Notes; }
        }

        public MppConstraintType ConstraintType
        {
            get { return _mppTask.ConstraintType; }
        }

        public bool InCompletePassedFinishDate
        {
            get
            {
                return
                    _mppTask.FinishDate.HasValue
                    && _mppTask.FinishDate.Value < DateTime.Today
                    && _mppTask.PercentageComplete != 100;
            }
        }

        public override string ToString()
        {
            StringBuilder taskString = new StringBuilder()
            .AppendFormat("Name = {0}", this.Name)
            .AppendLine()
            .AppendFormat("ID = {0}", this.Id)
            .AppendLine()
            .AppendFormat("Parent Task Id = {0}", this.ParentTaskId)
            .AppendLine()
            .AppendFormat("% Complete = {0}", this.PercentageComplete)
            .AppendLine()
            .AppendFormat("Start Date = {0}", this.StartDate)
            .AppendLine()
            .AppendFormat("Finish Date = {0}", this.FinishDate)
            .AppendLine()
            .AppendFormat("Actual Start Date = {0}", this.ActualStartDate)
            .AppendLine()
            .AppendFormat("Actual Finish Date = {0}", this.ActualFinishDate)
            .AppendLine()
            .AppendFormat("Duration = {0}", this.Duration)
            .AppendLine()
            .AppendFormat("Predecessor Task Ids  = {0}", this.PredecessorTaskIdsString)
            .AppendLine()
            .AppendFormat("Notes = {0}", this.Notes)
            .AppendLine()
            .AppendFormat("Priority = {0}", this.Priority)
            .AppendLine()
            .AppendFormat("Unique Id = {0}", this.UniqueId);

            return taskString.ToString();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions