/// <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); }