Ejemplo n.º 1
0
        public GoalViewModel(Goal goal, GoalData goalData, ProjectData projectData, TaskData taskData)
        {
            if (goal == null)
            {
                throw new ArgumentNullException("goal");
            }

            if (goalData == null)
            {
                throw new ArgumentNullException("goalData");
            }

            if (projectData == null)
            {
                throw new ArgumentNullException("projectData");
            }

            if (taskData == null)
            {
                throw new ArgumentNullException("taskData");
            }

            _goal                = goal;
            _goalData            = goalData;
            _projectData         = projectData;
            _taskData            = taskData;
            _statusOptions       = AppInfo.Instance.StatusList;
            _selectedStatus      = _statusOptions.FirstOrDefault(s => s.StatusID == this.StatusId);
            _categoryOptions     = AppInfo.Instance.CategoryList;
            _selectedCategory    = _categoryOptions.FirstOrDefault(c => c.CategoryID == this.CategoryId);
            _isSaved             = true;
            _statusDescription   = _statusOptions.FirstOrDefault(s => s.StatusID == this.StatusId).Description;
            _categoryDescription = _categoryOptions.FirstOrDefault(c => c.CategoryID == this.CategoryId).Description;
            List <Project> childProjects = _goalData.GetChildProjects(_goal.GoalId);

            foreach (Project childProject in childProjects)
            {
                _childProjectVMs.Add(new ProjectViewModel(childProject, projectData, taskData));
            }

            _originalStatusId = StatusId;

            // Subscribe for notifications of when a new project is saved.
            _projectData.ProjectAdded   += this.OnProjectAdded;
            _projectData.ProjectUpdated += this.OnProjectUpdated;
            _projectData.ProjectDeleted += this.OnProjectDeleted;

            base.DisplayName  = Properties.Resources.Edit_Goal_DisplayName;
            base.DisplayImage = "pack://application:,,,/TaskConqueror;Component/Assets/Images/goal.png";
        }
        public override FlowDocument Build()
        {
            FlowDocument flowDocument = new FlowDocument();

            flowDocument.Blocks.Add(FlowDocumentHelper.BuildTitle(Title));

            Paragraph criteriaPara = new Paragraph();
            Span      titleSpan    = new Span();

            titleSpan.Inlines.Add("Title: ");
            titleSpan.FontWeight = FontWeights.Bold;
            Span titleValueSpan = new Span();

            titleValueSpan.Inlines.Add(SelectedGoal.Title);
            Span dateTitleSpan = new Span();

            dateTitleSpan.Inlines.Add("     Date Created: ");
            dateTitleSpan.FontWeight = FontWeights.Bold;
            Span dateValueSpan = new Span();

            dateValueSpan.Inlines.Add(SelectedGoal.CreatedDate.ToShortDateString());
            criteriaPara.Inlines.Add(titleSpan);
            criteriaPara.Inlines.Add(titleValueSpan);
            criteriaPara.Inlines.Add(dateTitleSpan);
            criteriaPara.Inlines.Add(dateValueSpan);
            flowDocument.Blocks.Add(criteriaPara);

            Dictionary <string, Tuple <string, string> > columnDefinitions = new Dictionary <string, Tuple <string, string> >()
            {
                { "Title", new Tuple <string, string>("Project Title", null) },
                { "StatusDescription", new Tuple <string, string>("Status", null) },
                { "EstimatedCost", new Tuple <string, string>("Estimated Cost", "0:C") },
                { "CreatedDate", new Tuple <string, string>("Date Created", null) },
                { "CompletedDate", new Tuple <string, string>("Date Completed", null) }
            };

            using (ProjectData pData = new ProjectData())
            {
                using (TaskData tData = new TaskData())
                {
                    using (GoalData gData = new GoalData())
                    {
                        List <Project>          childProjects = gData.GetChildProjects(SelectedGoal.GoalId);
                        List <ProjectViewModel> rowData       = new List <ProjectViewModel>();
                        foreach (Project project in childProjects)
                        {
                            rowData.Add(new ProjectViewModel(project, pData, tData));
                        }

                        flowDocument.Blocks.Add(FlowDocumentHelper.BuildTable <ProjectViewModel>(columnDefinitions, rowData));

                        foreach (ProjectViewModel projectVm in rowData)
                        {
                            projectVm.Dispose();
                        }
                    }
                }
            }

            return(flowDocument);
        }