protected string BuildReviewersAndApprovers(int id)
        {
            StringBuilder result = new StringBuilder();

            EntityDTO dto = entityData.GetOneEntity(id);
            dto.ExtractProperties();

            List<string> reviewersBasis = RemoveBelongsToOrg(dto.GetPropertyList("Reviewers"));
            List<string> approversBasis = RemoveBelongsToOrg(dto.GetPropertyList("Approvers"));

            List<EntityDTO> reviewers = entityData.GetReviewersAndApprovers(id);

            if (reviewersBasis.Count > 0)
            {
                HtmlTable t = new HtmlTable(2, 0, "grid", new int[] { 30, 70 });
                t.AddHeader(GlobalStringResource.Reviewers, 2);

                t.AddHeader(GlobalStringResource.Name);
                t.AddHeader(GlobalStringResource.Position);
                foreach (string item in reviewersBasis)
                {
                    EntityDTO rev = reviewers.Find(x => x.Name == item.Trim());
                    CreateMainTable(t, rev);
                }
                result.Append(t.EndHtmlTable());
            }

            if (approversBasis.Count > 0)
            {
                HtmlTable t = new HtmlTable(2, 0, "grid", new int[] { 30, 70 });
                t.AddHeader(GlobalStringResource.Approvers, 2);

                t.AddHeader(GlobalStringResource.Name);
                t.AddHeader(GlobalStringResource.Position);
                foreach (string item in approversBasis)
                {
                    EntityDTO appr = reviewers.Find(x => x.Name == item.Trim());
                    CreateMainTable(t, appr);
                }
                result.Append(t.EndHtmlTable());
            }

            return result.ToString();
        }
        protected virtual string BuildChangeHistory(int id)
        {
            string result = string.Empty;
            EntityData entityData = new EntityData();

            List<EntityDTO> changeHistory = entityData.GetChangeHistory(id);
            ChangeHistoryComparer comparer = new ChangeHistoryComparer();
            changeHistory.Sort(comparer);
            if (changeHistory.Count > 0)
            {
                HtmlTable t = new HtmlTable(4, 0, "grid");
                //t.AddHeader(GlobalStringResource.ChangeHistory, 4);

                t.AddHeader(GlobalStringResource.Version);
                t.AddHeader(GlobalStringResource.Date);
                t.AddHeader(GlobalStringResource.ReasonforChange);
                t.AddHeader(GlobalStringResource.AuthorOnly);

                foreach (EntityDTO related in changeHistory)
                {
                    related.ExtractProperties();
                    t.AddCell(related.RenderHTML(GlobalStringResource.Version, RenderOption.Span));
                    t.AddCell(related.RenderHTML(GlobalStringResource.Date, RenderOption.Span));
                    t.AddCell(related.RenderHTML(GlobalStringResource.ReasonforChange, RenderOption.Span));

                    List<EntityDTO> users = entityData.GetRelatedPersons(related.ID);

                    StringBuilder userLinks = new StringBuilder();
                    if (users.Count > 0)
                    {
                        foreach (EntityDTO user in users)
                        {
                            userLinks.Append(user.RenderAsPopupLink());
                            userLinks.Append(GlobalStringResource.BreakTag);
                        }
                    }

                    t.AddCell(userLinks.ToString());
                }
                result = t.EndHtmlTable();
            }

            return result;
        }
        protected override string BuildAcronyms(int id)
        {
            string result = string.Empty;
            List<EntityDTO> acronyms = entityData.GetAcronyms(id);
            if (acronyms.Count > 0)
            {
                HtmlTable t = new HtmlTable(2, 0, "grid", new int[] { 5, 95 } );
                //t.AddHeader(GlobalStringResource.Acronyms, 2);

                t.AddHeader(GlobalStringResource.Acronyms);
                t.AddHeader(GlobalStringResource.Description);

                foreach (EntityDTO related in acronyms)
                {
                    related.ExtractProperties();

                    t.AddCell(related.RenderAsPopupLink());
                    t.AddCell(
                        related.RenderHTML(
                        GlobalStringResource.AbbreviationDescription,
                        RenderOption.Break));
                }
                result = t.EndHtmlTable();
            }

            return result;
        }
        protected override string BuildSubProcessRelation(int id)
        {
            string result = string.Empty;
            List<EntityDTO> relatedSubProcess = entityData.GetRelatedSubProcess(id);
            if (relatedSubProcess.Count > 0)
            {
                HtmlTable t = new HtmlTable(4, 0, "grid", new int[] { 20,55,15,10 } );
                //t.AddHeader(GlobalStringResource.SubProcessRelation, 4);
                t.AddHeader(GlobalStringResource.SubProcessDiagram);
                t.AddHeader(GlobalStringResource.SubProcessOverview);
                t.AddHeader(GlobalStringResource.SubProcessOwner);
                t.AddHeader(GlobalStringResource.Authors);

                foreach (EntityDTO related in relatedSubProcess)
                {
                    related.ExtractProperties();
                    t.AddCell(related.RenderAsLink());
                    t.AddCell(related.RenderHTML(GlobalStringResource.Description, RenderOption.Paragraph));
                    t.AddCell(related.RenderHTML(GlobalStringResource.DocumentOwners, RenderOption.Break));
                    t.AddCell(related.RenderHTML(GlobalStringResource.Authors,
                        RenderOption.Break));
                }
                result = t.EndHtmlTable();
            }
            return result;
        }
        protected override string BuildProcessRelation(int id)
        {
            string result = string.Empty;
            List<EntityDTO> relatedProcess = entityData.GetRelatedProcess(id);
            if (relatedProcess.Count > 0)
            {
                HtmlTable t = new HtmlTable(3, 0, "grid", new int[] { 10, 45, 45 });
                //t.AddHeader(GlobalStringResource.ProcessRelation, 3);
                t.AddHeader(GlobalStringResource.ReferenceNumber);
                t.AddHeader(GlobalStringResource.Name);
                t.AddHeader(GlobalStringResource.Relationship);
                foreach (EntityDTO related in relatedProcess)
                {
                    related.ExtractProperties();

                    EntityDTO actual = entityData.GetActualRelatedProcess(related.ID);
                    if (actual != null)
                    {
                        actual.ExtractProperties();

                        /*
                         * gets the actual diagram
                         * displays plain text if the diagram does not exist
                         */
                        EntityDTO diag = entityData.GetOneEntityByReferenceNumberAndClass(related.RenderHTML(
                            GlobalStringResource.ReferenceNumber, RenderOption.None), 1);
                        if (diag != null)
                        {
                            t.AddCell(diag.RenderAsLink(related.RenderHTML(GlobalStringResource.ReferenceNumber, RenderOption.None), diag.ID, RenderOption.None));
                        }
                        else
                        {
                            t.AddCell(related.RenderHTML(GlobalStringResource.ReferenceNumber, RenderOption.None));
                        }
                    }
                    else
                    {
                        //Display plain text
                        t.AddCell(related.RenderHTML(GlobalStringResource.ReferenceNumber, RenderOption.None));
                    }
                    t.AddCell(related.RenderHTML(GlobalStringResource.Process, RenderOption.None));
                    t.AddCell(related.RenderHTML(GlobalStringResource.Relationship, RenderOption.None));
                }
                result = t.EndHtmlTable();
            }
            return result;
        }
        protected override string BuildSubProcessRelation(int id)
        {
            string result = string.Empty;
            //TODO: Add sorting to the items
            List<EntityDTO> relatedSubProcess = entityData.GetSubProcessDependencies(id);

            if (relatedSubProcess.Count > 0)
            {
                HtmlTable t = new HtmlTable(4, 0, "grid");
                //t.AddHeader(GlobalStringResource.SubProcessDependencies, 4);

                t.AddHeader(GlobalStringResource.PrecedingSucceeding);
                t.AddHeader(GlobalStringResource.FromSubProcess);
                t.AddHeader(GlobalStringResource.ToSubProcess);
                t.AddHeader(GlobalStringResource.IntegrationObjectives);

                foreach (EntityDTO related in relatedSubProcess)
                {
                    related.ExtractProperties();
                    string linkFrom = RenderLink(related, GlobalStringResource.FromSubProcess);
                    string linkTo = RenderLink(related, GlobalStringResource.ToSubProcess);

                    t.AddCell(related.RenderHTML(GlobalStringResource.EventType, RenderOption.Break));
                    t.AddCell(linkFrom);
                    t.AddCell(linkTo);
                    t.AddCell(related.RenderHTML(GlobalStringResource.SubProcessObjective, RenderOption.Break));
                }
                result = t.EndHtmlTable();
            }

            return result;
        }
        private string BuildParentProcessDescription(int id)
        {
            HtmlTable t = new HtmlTable(2, 0, "grid");
            EntityDTO parentDto = entityData.GetParentDiagram(id);

            if(parentDto != null)
            {
                parentDto.ExtractProperties();

                //t.AddHeader(GlobalStringResource.Process, 2);

                t.AddHeader(GlobalStringResource.ProcessName);
                t.AddHeader(GlobalStringResource.Description);

                t.AddCell(parentDto.RenderAsLink());
                t.AddCell(parentDto.RenderHTML(GlobalStringResource.ProcessDescription, RenderOption.Paragraph));
            }

            return t.EndHtmlTable();
        }
        private string BuildStrategicAgenda(int id)
        {
            string result = string.Empty;
            List<EntityDTO> agendas = data.GetAllStrategicAgenda(id);

            if (agendas.Count > 0)
            {
                HtmlTable t = new HtmlTable(2, 1, "grid", new int[] { 50, 50 });
                t.AddHeader("Strategic Agenda");
                t.AddHeader("Description");

                foreach (EntityDTO agenda in agendas)
                {
                    agenda.ExtractProperties();
                    t.AddCell(agenda.Name);
                    t.AddCell(agenda.RenderHTML(GlobalStringResource.Description, ADB.SA.Reports.Entities.Enums.RenderOption.None));
                }
                result = t.EndHtmlTable();
            }

            return result;
        }
        protected override string BuildBusinessMapping(int id)
        {
            string result = string.Empty;
            List<EntityDTO> sections = entityData.GetSections(id);
            if (sections.Count > 0)
            {
                HtmlTable t = new HtmlTable(2, 0, "grid", new int[] { 10, 90 } );
                //t.AddHeader(GlobalStringResource.BusinessProcessandBusinessRuleMapping, 2);

                t.AddHeader(GlobalStringResource.SectionName);
                t.AddHeader(GlobalStringResource.SectionDescription);

                foreach (EntityDTO related in sections)
                {
                    related.ExtractProperties();

                    t.AddCell(MappingToolUrlHelper.GenerateValidSectionLinkMarkup(related.Name));
                    t.AddCell(related.RenderHTML(GlobalStringResource.Description, RenderOption.None).ToUpper());
                }
                result = t.EndHtmlTable();
            }
            return result;
        }
        private string BuildOperationalGoals(int id)
        {
            string result = string.Empty;
            List<EntityDTO> goals = data.GetAllOperationalGoals(id);

            if (goals.Count > 0)
            {
                HtmlTable t = new HtmlTable(2, 1, "grid", new int[] { 50, 50 });
                t.AddHeader("Operational Goals");
                t.AddHeader("Description");

                foreach (EntityDTO g in goals)
                {
                    g.ExtractProperties();
                    t.AddCell(g.Name);
                    t.AddCell(g.RenderHTML(GlobalStringResource.Description, ADB.SA.Reports.Entities.Enums.RenderOption.None));
                }
                result = t.EndHtmlTable();
            }

            return result;
        }
        private string BuildResultFrameworkLevel(int id)
        {
            string result = string.Empty;
            List<EntityDTO> results = data.GetAllResultFrameworkLevel(id);

            if (results.Count > 0)
            {
                HtmlTable t = new HtmlTable(2, 1, "grid", new int[] { 50, 50 });
                t.AddHeader("Result Framework Level");
                t.AddHeader("Description");

                foreach (EntityDTO r in results)
                {
                    r.ExtractProperties();
                    t.AddCell(r.Name);
                    t.AddCell(r.RenderHTML(GlobalStringResource.Description, ADB.SA.Reports.Entities.Enums.RenderOption.None));
                }
                result = t.EndHtmlTable();
            }

            return result;
        }
        private string BuilddriversOfChange(int id)
        {
            string result = string.Empty;
            List<EntityDTO> drivers = data.GetAllDriversOfChange(id);

            if (drivers.Count > 0)
            {
                HtmlTable t = new HtmlTable(2, 1, "grid", new int[] { 50, 50 });
                t.AddHeader("Drivers of Change");
                t.AddHeader("Description");

                foreach (EntityDTO d in drivers)
                {
                    d.ExtractProperties();
                    t.AddCell(d.Name);
                    t.AddCell(d.RenderHTML(GlobalStringResource.Description, ADB.SA.Reports.Entities.Enums.RenderOption.None));
                }
                result = t.EndHtmlTable();
            }

            return result;
        }
        private string BuildDevelopingPartnerCountries(int id)
        {
            string result = string.Empty;
            List<EntityDTO> dpcs = data.GetAllDevelopingPartnerCountries(id);

            if (dpcs.Count > 0)
            {
                HtmlTable t = new HtmlTable(2, 1, "grid", new int[] { 50, 50 });
                t.AddHeader("Developing Partner Countries");
                t.AddHeader("Description");

                foreach (EntityDTO dpc in dpcs)
                {
                    dpc.ExtractProperties();
                    t.AddCell(dpc.Name);
                    t.AddCell(dpc.RenderHTML(GlobalStringResource.Description, ADB.SA.Reports.Entities.Enums.RenderOption.None));
                }
                result = t.EndHtmlTable();
            }

            return result;
        }
        private string BuildCorporateValues(int id)
        {
            string result = string.Empty;
            List<EntityDTO> values = data.GetAllCorporateValues(id);

            if (values.Count > 0)
            {
                HtmlTable t = new HtmlTable(2, 1, "grid", new int[] { 50, 50 });
                t.AddHeader("Corporate Values");
                t.AddHeader("Description");

                foreach (EntityDTO v in values)
                {
                    v.ExtractProperties();
                    t.AddCell(v.Name);
                    t.AddCell(v.RenderHTML(GlobalStringResource.Description, ADB.SA.Reports.Entities.Enums.RenderOption.None));
                }
                result = t.EndHtmlTable();
            }

            return result;
        }
        protected override string BuildDiagramDescription(EntityDTO dto)
        {
            HtmlTable t = new HtmlTable(2, 0, "grid", new int[]{ 15,85 });
            dto.ExtractProperties();

            //t.AddHeader(GlobalStringResource.SubProcessDescription, 2);

            t.AddHeader("&emsp;", 2);

            t.AddCell(GlobalStringResource.Objective);
            t.AddCell(dto.RenderHTML(GlobalStringResource.Description, RenderOption.Paragraph));

            t.AddCell(GlobalStringResource.DocumentOwners);
            t.AddCell(dto.RenderHTML(GlobalStringResource.DocumentOwners, RenderOption.Break));

            t.AddCell(GlobalStringResource.FrameworkReference);
            t.AddCell(dto.RenderHTML(GlobalStringResource.FrameworkReference, RenderOption.Break));

            t.AddCell(GlobalStringResource.InternalReference);
            t.AddCell(dto.RenderHTML(GlobalStringResource.InternalReference, RenderOption.Break));

            return t.EndHtmlTable();
        }
        protected override string BuildDiagramDescription(EntityDTO dto)
        {
            HtmlTable t = new HtmlTable(2, 0, "grid", new int[] { 15, 85 });

            t.AddHeader("&emsp;", 2);

            t.AddCell(GlobalStringResource.ProcessName);
            t.AddCell(dto.Name);

            t.AddCell(GlobalStringResource.Description);
            t.AddCell(dto.RenderHTML(GlobalStringResource.ProcessDescription, RenderOption.Paragraph));

            t.AddCell(GlobalStringResource.Purpose);
            t.AddCell(dto.RenderHTML(GlobalStringResource.Description, RenderOption.Paragraph));

            t.AddCell(GlobalStringResource.Objective);
            t.AddCell(dto.RenderHTML(GlobalStringResource.ProcessObjective, RenderOption.Paragraph));

            t.AddCell(GlobalStringResource.Strategy);
            t.AddCell(dto.RenderHTML(GlobalStringResource.Strategy, RenderOption.Paragraph));

            t.AddCell(GlobalStringResource.DocumentOwners);
            t.AddCell(dto.RenderHTML(GlobalStringResource.DocumentOwners, RenderOption.Break));

            return t.EndHtmlTable();
        }
        protected override string BuildModuleRelationship(int id)
        {
            string result = string.Empty;
            List<EntityDTO> applications = entityData.GetModuleRelationship(id);
            if (applications.Count > 0)
            {
                HtmlTable t = new HtmlTable(2, 0, "grid");
                //t.AddHeader(GlobalStringResource.ApplicationRelationship);

                t.AddHeader("Module");
                t.AddHeader("Description");

                foreach (EntityDTO related in applications)
                {
                    related.ExtractProperties();
                    t.AddCell(related.Name);
                    t.AddCell(related.RenderHTML("Description", RenderOption.Paragraph));
                }
                result = t.EndHtmlTable();
            }
            return result;
        }
        protected override string BuildFrameworkReference(int id)
        {
            string result = string.Empty;
            List<EntityDTO> frameworks = entityData.GetFrameworkReference(id);
            if (frameworks.Count > 0)
            {
                HtmlTable t = new HtmlTable(3, 0, "grid");
                //t.AddHeader(GlobalStringResource.FrameworkReference, 3);

                t.AddHeader(GlobalStringResource.Framework);
                t.AddHeader(GlobalStringResource.FrameworkIndexID);
                t.AddHeader(GlobalStringResource.Description);

                foreach (EntityDTO related in frameworks)
                {
                    related.ExtractProperties();

                    t.AddCell(related.Name);
                    t.AddCell(related.RenderHTML(GlobalStringResource.FrameworkIndexID, RenderOption.Paragraph));
                    t.AddCell(related.RenderHTML(GlobalStringResource.FrameworkDescription, RenderOption.Paragraph));
                }
                result = t.EndHtmlTable();
            }

            return result;
        }
        private string BuildActivityOverview(int id)
        {
            EntityDTO parent = entityData.GetOneEntity(id);

            List<EntityDTO> activities = entityData.GetActivityOverview(id);
            string result = string.Empty;
            if (activities.Count > 0)
            {
                int[] widths = new int[] { 20,10,30,10,10,10,10 };
                HtmlTable t = new HtmlTable(7, 0, "grid", widths);
                //t.AddHeader(GlobalStringResource.ActivityOverview, 7);

                t.AddHeader(GlobalStringResource.Activity);
                t.AddHeader(GlobalStringResource.User);
                t.AddHeader(GlobalStringResource.TriggerInput);
                t.AddHeader(GlobalStringResource.Output);
                t.AddHeader(GlobalStringResource.KeyDocuments);
                t.AddHeader(GlobalStringResource.SystemsInformation);
                t.AddHeader(GlobalStringResource.Memo);

                foreach (EntityDTO activity in activities)
                {
                    activity.ExtractProperties();

                    List<EntityDTO> users = entityData.GetRelatedUsers(activity.ID);
                    StringBuilder userLinks = new StringBuilder();
                    if (users.Count > 0)
                    {
                        foreach (EntityDTO user in users)
                        {
                            userLinks.Append(user.RenderAsPopupLink());
                            userLinks.Append(GlobalStringResource.BreakTag);
                        }
                    }

                    bool isCtl = false;

                    if (parent != null)
                    {
                        isCtl = parent.IsCTL;
                    }

                    t.AddCell(activity.RenderAsPopupLink(isCtl));
                    t.AddCell(userLinks.ToString());
                    t.AddCell(activity.RenderHTML(GlobalStringResource.TriggerInput, RenderOption.Break));
                    t.AddCell(activity.RenderHTML(GlobalStringResource.Output, RenderOption.Break));
                    t.AddCell(activity.RenderHTML(GlobalStringResource.KeyDocuments, RenderOption.Break));
                    t.AddCell(activity.RenderHTML(GlobalStringResource.SystemsInformation, RenderOption.Break));
                    t.AddCell(activity.RenderHTML(GlobalStringResource.Memo, RenderOption.Break));
                }
                result = t.EndHtmlTable();
            }

            return result;
        }
        protected override string BuildInternalReference(int id)
        {
            string result = string.Empty;

            List<EntityDTO> references = entityData.GetInternalReference(id);

            if (references.Count > 0)
            {
                HtmlTable t = new HtmlTable(3, 0, "grid", new int[] { 20,40,40 });

                //t.AddHeader(GlobalStringResource.InternalReference, 3);

                t.AddHeader(GlobalStringResource.DocumentType);
                t.AddHeader(GlobalStringResource.Title);
                t.AddHeader(GlobalStringResource.DocumentReferenceNumber);

                foreach (EntityDTO related in references)
                {
                    related.ExtractProperties();

                    t.AddCell(related.RenderHTML(GlobalStringResource.ReferenceType, RenderOption.Paragraph));
                    t.AddCell(related.RenderHTML(GlobalStringResource.Description, RenderOption.Paragraph));
                    t.AddCell(related.Name);
                }
                result = t.EndHtmlTable();
            }

            return result;
        }
        private void CreateMainTable(HtmlTable t, EntityDTO dto)
        {
            if (dto != null)
            {
                dto.ExtractProperties();

                string personName = dto.RenderHTML(GlobalStringResource.Assignedto, RenderOption.None);
                if (!string.IsNullOrEmpty(personName))
                {
                    EntityDTO relatedPerson = entityData.GetOneEntityByNameAndType(personName, 663);
                    if (relatedPerson != null)
                    {
                        relatedPerson.ExtractProperties();
                        personName = relatedPerson.RenderAsPopupLink();
                    }
                }
                t.AddCell(personName);
                t.AddCell(dto.RenderAsPopupLink());
            }
        }
        protected virtual string BuildRolesAndResponsibilities(int id)
        {
            string result = string.Empty;
            EntityData entityData = new EntityData();
            List<EntityDTO> rolesAndResponsibilities = entityData.GetRolesAndResponsibilities(id);

            if (rolesAndResponsibilities.Count > 0)
            {
                HtmlTable t = new HtmlTable(2, 0, "grid", new int[] { 20, 80 } );

                t.AddHeader(GlobalStringResource.Role);
                t.AddHeader(GlobalStringResource.Responsibilities);

                foreach (EntityDTO dto in rolesAndResponsibilities)
                {
                    dto.ExtractProperties();
                    EntityDTO descriptionDto = entityData.GetRolesDescription(dto.ID);
                    string description = string.Empty;
                    if (descriptionDto != null)
                    {
                        descriptionDto.ExtractProperties();
                        description = descriptionDto.RenderHTML(GlobalStringResource.Description,
                            RenderOption.Break);
                    }
                    t.AddCell(dto.RenderHTML(GlobalStringResource.Role, RenderOption.None));//(Resources.Role, RenderOption.Paragraph));
                    t.AddCell(description);
                }
                result = t.EndHtmlTable();
            }

            return result;
        }