示例#1
0
        /// <summary>
        /// Go thorugh each column to determine if the columns should be removed --
        /// if all elements (that have data) in the columns can be found in other reports then consider this a flow thru column and delete it.
        /// For "disclosures", if one element or one dimension member s unique, do remove ANY columns from the disclosure
        /// </summary>
        /// <param name="rh"></param>
        /// <param name="inUseElements"></param>
        /// <param name="inUseSegments"></param>
        private void CleanupColumns(ReportHeader rh, Dictionary <string, int> inUseElements, Dictionary <string, int> inUseSegments)
        {
            string         filePath = Path.Combine(this.currentReportDirectory, rh.XmlFileName);
            InstanceReport report   = InstanceReport.LoadXml(filePath);

            if (report == null)
            {
                return;
            }

            List <InstanceReportColumn> columnsToRemove = new List <InstanceReportColumn>();
            List <InstanceReportRow>    uniqueRows      = report.Rows.FindAll(
                row =>
            {
                if (string.IsNullOrEmpty(row.ElementName))
                {
                    return(false);
                }

                if (row.IsEmpty())
                {
                    return(false);
                }

                if (inUseElements.ContainsKey(row.ElementName))
                {
                    return(false);
                }

                return(true);
            });

            bool hasAnyUniqeRows = uniqueRows.Count > 0;

            for (int c = 0; c < report.Columns.Count; c++)
            {
                InstanceReportColumn col     = report.Columns[c];
                bool columnHasUniqueSegments = false;
                bool columnHasUniqueCells    = ReportUtils.Exists(uniqueRows, row => row.Cells[c].HasData);
                if (!columnHasUniqueCells)                  //this column might need to be removed
                {
                    Dictionary <string, int> colSegments = report.GetUniqueInUseSegments(col);
                    foreach (string key in colSegments.Keys)
                    {
                        if (!inUseSegments.ContainsKey(key))
                        {
                            columnHasUniqueSegments = true;
                            break;
                        }
                    }
                }

                if (!(columnHasUniqueCells || columnHasUniqueSegments))
                {
                    columnsToRemove.Add(col);
                }
            }

            if (columnsToRemove.Count > 0 && columnsToRemove.Count < report.Columns.Count)
            {
                foreach (InstanceReportColumn col in columnsToRemove)
                {
                    col.RemoveSelf(report);
                }

                if (report.Columns.Count > 1)
                {
                    report.PromoteSharedColumnLabelsAfterRemoveFlowThroughColumns();
                }

                report.BuildXMLDocument(filePath, false, false, this.currentFilingSummary);
            }
        }
示例#2
0
        /// <summary>
        /// Go thorugh each column to determine if the columns should be removed --
        /// if all elements (that have data) in the columns can be found in other reports then consider this a flow thru column and delete it.
        /// For "disclosures", if one element or one dimension member s unique, do remove ANY columns from the disclosure
        /// </summary>
        /// <param name="rh"></param>
        /// <param name="allInUseElementsSegments"></param>
        private void CleanupColumns(ReportHeader rh, InstanceReport.ElementSegmentCombinations allInUseElementsSegments)
        {
            string         filePath = Path.Combine(this.currentReportDirectory, rh.XmlFileName);
            InstanceReport report   = InstanceReport.LoadXml(filePath);

            if (report == null)
            {
                return;
            }

            InstanceReportColumn lastSegmentColumn = null;
            bool hasSegmentsOnRows = report.HasSegmentsOnRows();
            List <InstanceReportColumn> columnsToRetain = new List <InstanceReportColumn>();

            foreach (InstanceReportRow row in report.Rows)
            {
                if (hasSegmentsOnRows)
                {
                    if (row.OriginalInstanceReportColumn != null)
                    {
                        lastSegmentColumn = row.OriginalInstanceReportColumn;
                    }
                }

                //we can't test this row
                if (string.IsNullOrEmpty(row.ElementName))
                {
                    continue;
                }

                //we can't test this row
                if (row.IsEmpty())
                {
                    continue;
                }

                for (int c = 0; c < row.Cells.Count; c++)
                {
                    //skip this cell if we already have this column
                    InstanceReportColumn currentColumn = report.Columns[c];
                    if (columnsToRetain.Contains(currentColumn))
                    {
                        continue;
                    }

                    //we only want columns for cells which have data
                    Cell cell = row.Cells[c];
                    if (!cell.HasData)
                    {
                        continue;
                    }

                    //if the element doesn't even exist, we're set - add the column
                    InstanceReportColumn segmentColumn = hasSegmentsOnRows ? lastSegmentColumn : currentColumn;
                    if (!allInUseElementsSegments.ContainsElement(row.ElementName))
                    {
                        columnsToRetain.Add(currentColumn);
                    }
                    else if (segmentColumn != null)
                    {
                        if (segmentColumn.Segments != null && segmentColumn.Segments.Count > 0)
                        {
                            //if the element exists, but maybe its combination with the segments does not
                            StringBuilder sb = new StringBuilder();
                            foreach (string segmentKey in segmentColumn.GetUniqueInUseSegments().Keys)
                            {
                                sb.AppendLine(segmentKey);
                            }

                            if (!allInUseElementsSegments.ContainsElementAndSegments(row.ElementName, sb.ToString()))
                            {
                                columnsToRetain.Add(currentColumn);
                            }
                        }
                    }
                }

                if (columnsToRetain.Count == report.Columns.Count)
                {
                    return;
                }
            }

            if (columnsToRetain.Count == 0 || columnsToRetain.Count == report.Columns.Count)
            {
                return;
            }

            List <InstanceReportColumn> columnsToRemove = report.Columns.FindAll(col => !columnsToRetain.Contains(col));

            foreach (InstanceReportColumn col in columnsToRemove)
            {
                this.currentFilingSummary.TraceInformation("\tProcess Flow-Through: Removing column '" + col.Label + "'");
                col.RemoveSelf(report);
            }

            if (report.Columns.Count > 1)
            {
                report.PromoteSharedColumnLabelsAfterRemoveFlowThroughColumns();
            }

            report.BuildXMLDocument(filePath, false, false, this.currentFilingSummary);
        }