public bool IsAsPreviouslyReported(XmlDocument membersXDoc, out int index) { index = -1; if (membersXDoc == null) { return(false); } if (this.Segments == null || this.Segments.Count == 0) { return(false); } int i = 0; foreach (Segment seg in this.Segments) { if (ColumnRowRequirement.IsSegmentPreviouslyReported(seg, membersXDoc)) { index = i; return(true); } i++; } return(false); }
public void GenerateEmbedLabel(ColumnRowRequirement embedRequirements, bool showDefault) { this.Labels.Clear(); string calendarLabel = null; if (embedRequirements.HasSelectionType(CommandIterator.SelectionType.Period)) { CommandIterator cmdI = Array.Find(embedRequirements.EmbedCommands, cmd => cmd.Selection == CommandIterator.SelectionType.Period); if (cmdI != null) { calendarLabel = embedRequirements.GetLabel(cmdI, false); } } string[] labels = embedRequirements.GetLabels(this.HasMultiCurrency, showDefault); for (int i = 0; i < labels.Length; i++) { if (calendarLabel != null) { if (string.Equals(labels[i], calendarLabel)) { this.Labels.Add(new LabelLine(i, labels[i], "Calendar")); continue; } } this.Labels.Add(new LabelLine(i, labels[i])); } }
//TODO make private public static CommandIterator.SelectionType GetIntersection(ColumnRowRequirement leftCol, ColumnRowRequirement rightCol) { if (leftCol == null || rightCol == null) { return(CommandIterator.SelectionType.None); } CommandIterator.SelectionType leftSelection = leftCol.GetSelections(); CommandIterator.SelectionType rightSelection = rightCol.GetSelections(); CommandIterator.SelectionType intersection = leftSelection & rightSelection; return(intersection); }
public bool IsDimensionMatch(ColumnRowRequirement columnRowRequirement) { foreach (Segment mySeg in this.Segments) { bool dimensionExists = ReportUtils.Exists(columnRowRequirement.Segments, iSeg => string.Equals(mySeg.DimensionInfo.dimensionId, iSeg.DimensionInfo.dimensionId)); if (!dimensionExists) { return(false); } } return(true); }
private bool FindColumn( InstanceReportColumn col, ColumnRowRequirement netCell ) { if( netCell.Period != null ) { CalendarPeriod colCalendar = col.GetCalendarPeriod(); if( netCell.Period.PeriodType == colCalendar.PeriodType ) { if( !CalendarPeriod.Equals( colCalendar, netCell.Period ) ) return false; } else { CalendarPeriod cpDuration = null; CalendarPeriod cpInstant = null; if( colCalendar.PeriodType == Element.PeriodType.instant ) { cpDuration = netCell.Period; cpInstant = colCalendar; } else { cpDuration = colCalendar; cpInstant = netCell.Period; } if( netCell.ElementRow != null && netCell.ElementRow.IsBeginningBalance ) { if( !DateTime.Equals( cpInstant.StartDate.AddDays(1), cpDuration.StartDate ) ) return false; } else { if( !DateTime.Equals( cpInstant.StartDate, cpDuration.EndDate ) ) return false; } } } if( netCell.Unit != null ) { string colCC = GetColumnCurrencyCode( col ); string unitCC = netCell.UnitCode; bool unitsMatch = colCC == unitCC; if( !unitsMatch ) return false; } if( netCell.Segments != null ) { foreach( Segment seg in netCell.Segments ) { bool found = false; foreach( Segment cSeg in col.Segments ) { if( cSeg.DimensionInfo.dimensionId == seg.DimensionInfo.dimensionId ) { if( cSeg.DimensionInfo.Id == seg.DimensionInfo.Id ) { found = true; break; } else { return false; } } } if( !found && !seg.IsDefaultForEntity ) return false; } } return true; }
private List<InstanceReportRow> FindBaseRows( ColumnRowRequirement netCell, List<InstanceReportRow> rows ) { //here we make the assumption that the only items on our rows are elements... List<InstanceReportRow> foundRows = rows.FindAll( row => { if( string.IsNullOrEmpty( netCell.ElementKey ) ) return true; if( !string.Equals( netCell.ElementKey, row.ElementKey ) ) return false; if( netCell.ElementRow.IsBeginningBalance && !row.IsBeginningBalance ) return false; if( netCell.ElementRow.IsEndingBalance && !row.IsEndingBalance ) return false; return true; } ); return foundRows; }
private List<InstanceReportColumn> FindBaseColumns( ColumnRowRequirement netCell, List<InstanceReportColumn> columns ) { List<InstanceReportColumn> foundColumns = columns.FindAll( col => FindColumn( col, netCell ) ); return foundColumns; }
private static ColumnRowRequirement BuildNetCell( params ColumnRowRequirement[] requirements ) { ColumnRowRequirement netCell = new ColumnRowRequirement(); Dictionary<string, int> segments = new Dictionary<string, int>(); foreach( ColumnRowRequirement req in requirements ) { if( string.IsNullOrEmpty( netCell.ElementKey ) ) netCell.ElementRow = req.ElementRow; if( netCell.Period == null ) netCell.Period = req.Period; foreach( Segment s in req.Segments ) { if( !ReportUtils.Exists( netCell.Segments, seg => Segment.Equals( seg, s ) ) ) netCell.Segments.Add( s ); } if( netCell.Unit == null ) netCell.Unit = req.Unit; } return netCell; }
public void PopulateEmbeddedReport( InstanceReport baseReport, CommandIterator[] columnIterators, CommandIterator[] rowIterators, ITraceMessenger messenger ) { this.IsMultiCurrency = baseReport.IsMultiCurrency; foreach( InstanceReportColumn col in this.Columns ) { col.GenerateEmbedLabel(); } foreach( InstanceReportRow row in this.Rows ) { row.Cells.Clear(); row.GenerateEmbedLabel(); for( int c = 0; c < this.Columns.Count; c++ ) row.Cells.Add( new Cell() ); } ColumnRowRequirement[,] netCells = new ColumnRowRequirement[ this.Rows.Count, this.Columns.Count ]; for( int r = 0; r < this.Rows.Count; r++ ) { for( int c = 0; c < this.Columns.Count; c++ ) { netCells[ r, c ] = BuildNetCell( this.Rows[ r ].EmbedRequirements, this.Columns[ c ].EmbedRequirements ); } } for( int r = 0; r < this.Rows.Count; r++ ) { for( int c = 0; c < this.Columns.Count; c++ ) { List<InstanceReportColumn> baseColumns = FindBaseColumns( netCells[ r, c ], baseReport.Columns ); if( baseColumns.Count == 0 ) continue; List<InstanceReportRow> baseRows = FindBaseRows( netCells[ r, c ], baseReport.Rows ); if( baseRows.Count == 0 ) continue; bool found = false; foreach( InstanceReportColumn col in baseColumns ) { foreach( InstanceReportRow row in baseRows ) { //CEE: By moving this up, we are using the "strict" logic //Strict: Instead of seeking to the first populated cell // the netCell is expected to point to 1 and only 1 cell //found = true; Cell bCell = row.Cells.Find( cell => cell.Id == col.Id ); if( bCell != null && bCell.HasData ) { Cell clone = (Cell)bCell.Clone(); clone.ShowCurrencySymbol = false; if( !this.IsEquityReport && this.IsMultiCurrency && row.IsMonetary ) { clone.CurrencyCode = col.CurrencyCode; clone.CurrencySymbol = col.CurrencySymbol; clone.IsMonetary = true; } this.Rows[ r ].Cells.RemoveAt( c ); this.Rows[ r ].Cells.Insert( c, clone ); //CEE: By moving this down, we are using the "loose" logic //Loose: Instead of expecting the netCell to point to // 1 and only 1 cell, we seek to the first populated cell found = true; break; } } if( found ) break; } } } //clean up columns this.RemoveEmptyColumns(); if( this.Columns.Count == 0 ) return; //clean up rows this.RemoveEmptyRows(); this.MergeCurrencyDifferences(); this.CheckAndScrubCurrencies(); this.ApplyCustomUnitsEmbedded(); //apply grouped and unitcell this.ApplyRowStyles( rowIterators, messenger ); if( !this.IsEquityReport ) { this.PromoteDefaultMemberGroups(); this.RemoveDefaultMemberHeaders(); } this.RelabelDefaultTotalRow(); this.ApplyUnitCell(); //how many unique periods are on these columns? //if 1, remove the label this.RemoveSingularPeriod(); //if a unit occurs on all columns... // remove it from the columns so it can't get promoted as "shared" // save it so it can be added last string currencyLabel = this.RemoveSharedCurrency(); //if a label occurs on all columns, shift it to the header this.PromoteSharedLabels(); //if there is a shared currency label, add it last if( !string.IsNullOrEmpty( currencyLabel ) ) this.ReportName += Environment.NewLine + currencyLabel; //copy over the footnotes this.PromoteFootnotes( baseReport ); this.SynchronizeGrid(); this.ProcessColumnHeaders(); }
public void GenerateEmbedLabel( ColumnRowRequirement embedRequirements, bool showDefault ) { this.Labels.Clear(); string calendarLabel = null; if( embedRequirements.HasSelectionType( CommandIterator.SelectionType.Period ) ) { CommandIterator cmdI = Array.Find( embedRequirements.EmbedCommands, cmd => cmd.Selection == CommandIterator.SelectionType.Period ); if( cmdI != null ) calendarLabel = embedRequirements.GetLabel( cmdI, false ); } string[] labels = embedRequirements.GetLabels( this.HasMultiCurrency, showDefault ); for( int i = 0; i < labels.Length; i++ ) { if( calendarLabel != null ) { if( string.Equals( labels[ i ], calendarLabel ) ) { this.Labels.Add( new LabelLine( i, labels[ i ], "Calendar" ) ); continue; } } this.Labels.Add( new LabelLine( i, labels[ i ] ) ); } }
public static bool AreSameExceptCurrency(ColumnRowRequirement thisRow, ColumnRowRequirement nextRow) { if (thisRow.ElementKey != nextRow.ElementKey) { return(false); } if (thisRow.PeriodLabel != nextRow.PeriodLabel) { return(false); } bool nextIsEmpty = nextRow.Segments == null || nextRow.Segments.Count == 0; if (thisRow.Segments == null || thisRow.Segments.Count == 0) { if (nextIsEmpty) { return(true); } else { return(false); } } else if (nextIsEmpty) { return(false); } if (thisRow.Segments.Count != nextRow.Segments.Count) { return(false); } foreach (Segment iSeg in thisRow.Segments) { bool found = ReportUtils.Exists(nextRow.Segments, oSeg => { if (iSeg.DimensionInfo.dimensionId != oSeg.DimensionInfo.dimensionId) { return(false); } if (iSeg.DimensionInfo.Id != oSeg.DimensionInfo.Id) { return(false); } return(true); }); if (!found) { return(false); } } return(true); }
public CommandIterator.SelectionType GetIntersection(ColumnRowRequirement rightCol) { return(GetIntersection(this, rightCol)); }
public bool IsDimensionMatch( ColumnRowRequirement columnRowRequirement ) { foreach( Segment mySeg in this.Segments ) { bool dimensionExists = ReportUtils.Exists( columnRowRequirement.Segments, iSeg => string.Equals( mySeg.DimensionInfo.dimensionId, iSeg.DimensionInfo.dimensionId ) ); if( !dimensionExists ) return false; } return true; }
public CommandIterator.SelectionType GetIntersection( ColumnRowRequirement rightCol ) { return GetIntersection( this, rightCol ); }
//TODO make private public static CommandIterator.SelectionType GetIntersection( ColumnRowRequirement leftCol, ColumnRowRequirement rightCol ) { if( leftCol == null || rightCol == null) return CommandIterator.SelectionType.None; CommandIterator.SelectionType leftSelection = leftCol.GetSelections(); CommandIterator.SelectionType rightSelection = rightCol.GetSelections(); CommandIterator.SelectionType intersection = leftSelection & rightSelection; return intersection; }
public static bool AreSameExceptCurrency( ColumnRowRequirement thisRow, ColumnRowRequirement nextRow ) { if( thisRow.ElementKey != nextRow.ElementKey ) return false; if( thisRow.PeriodLabel != nextRow.PeriodLabel ) return false; bool nextIsEmpty = nextRow.Segments == null || nextRow.Segments.Count == 0; if( thisRow.Segments == null || thisRow.Segments.Count == 0 ) { if( nextIsEmpty ) return true; else return false; } else if( nextIsEmpty ) { return false; } if( thisRow.Segments.Count != nextRow.Segments.Count ) return false; foreach( Segment iSeg in thisRow.Segments ) { bool found = ReportUtils.Exists( nextRow.Segments, oSeg => { if( iSeg.DimensionInfo.dimensionId != oSeg.DimensionInfo.dimensionId ) return false; if( iSeg.DimensionInfo.Id != oSeg.DimensionInfo.Id ) return false; return true; } ); if( !found ) return false; } return true; }
public void GenerateEmbedLabel(ColumnRowRequirement embedRequirements) { this.GenerateEmbedLabel(embedRequirements, false); }
private void ProcessIteratorsHierarchically(LinkedListNode <CommandIterator> iterator, Stack <CommandIterator> iteratorHierarchy, ITraceMessenger messenger) { if (iterator == null) { this.selectionCount++; Dictionary <CommandIterator.IteratorType, List <CommandIterator> > itrs = new Dictionary <CommandIterator.IteratorType, List <CommandIterator> >(); itrs[CommandIterator.IteratorType.Column] = new List <CommandIterator>(); itrs[CommandIterator.IteratorType.Row] = new List <CommandIterator>(); Dictionary <CommandIterator.IteratorType, ColumnRowRequirement> reqs = new Dictionary <CommandIterator.IteratorType, ColumnRowRequirement>(); reqs[CommandIterator.IteratorType.Column] = new ColumnRowRequirement(); reqs[CommandIterator.IteratorType.Row] = new ColumnRowRequirement(); List <CommandIterator> iterators = new List <CommandIterator>(iteratorHierarchy); iterators.Reverse(); foreach (CommandIterator iMember in iterators) { itrs[iMember.Type].Add(iMember); switch (iMember.Selection) { case CommandIterator.SelectionType.Axis: reqs[iMember.Type].Segments.Add((Segment)iMember.TempCurrentMemberValue); break; case CommandIterator.SelectionType.Element: reqs[iMember.Type].ElementRow = (InstanceReportRow)iMember.TempCurrentMemberValue; break; case CommandIterator.SelectionType.Period: reqs[iMember.Type].Period = (CalendarPeriod)iMember.TempCurrentMemberValue; break; case CommandIterator.SelectionType.Unit: reqs[iMember.Type].Unit = (EmbeddedUnitWrapper)iMember.TempCurrentMemberValue; break; } } //if either the rows or columns are missing, this intersection cannot be created - skip it. if (itrs[CommandIterator.IteratorType.Column].Count == 0 || itrs[CommandIterator.IteratorType.Row].Count == 0) { return; } //write the column { ColumnRowRequirement colReqs = reqs[CommandIterator.IteratorType.Column]; colReqs.EmbedCommands = itrs[CommandIterator.IteratorType.Column].ToArray(); bool areSame = false; //Check if the previous column matches this one - this only works because column iterators are first if (this.InstanceReport.Columns.Count > 0) { InstanceReportColumn prevCol = this.InstanceReport.Columns[this.InstanceReport.Columns.Count - 1]; areSame = ColumnRowRequirement.AreSameExceptCurrency(prevCol.EmbedRequirements, colReqs); if (areSame) { //the previous check doesn't check currency - check it here areSame = string.Equals(prevCol.EmbedRequirements.UnitCode, colReqs.UnitCode); } } //If they are the same, skip the new one - we don't want or need duplicates if (!areSame) { InstanceReportColumn col = new InstanceReportColumn(); col.EmbedRequirements = colReqs; col.HasMultiCurrency = this.hasMultiCurrency; if (col.EmbedRequirements.HasSelectionType(CommandIterator.SelectionType.Period)) { col.MCU = new MergedContextUnitsWrapper(); col.MCU.CurrencyCode = string.Empty; col.MCU.CurrencySymbol = string.Empty; col.MCU.contextRef = new ContextProperty(); if (col.EmbedRequirements.Period.PeriodType == Element.PeriodType.instant) { col.MCU.contextRef.PeriodType = Element.PeriodType.instant; col.MCU.contextRef.PeriodStartDate = col.EmbedRequirements.Period.StartDate; } else if (col.EmbedRequirements.Period.PeriodType == Element.PeriodType.duration) { col.MCU.contextRef.PeriodType = Element.PeriodType.duration; col.MCU.contextRef.PeriodStartDate = col.EmbedRequirements.Period.StartDate; col.MCU.contextRef.PeriodEndDate = col.EmbedRequirements.Period.EndDate; } } this.InstanceReport.Columns.Add(col); } } //write the row { ColumnRowRequirement rowReqs = reqs[CommandIterator.IteratorType.Row]; rowReqs.EmbedCommands = itrs[CommandIterator.IteratorType.Row].ToArray(); bool areSame = false; //Check if ANY of the previous rows matches this one... if (this.InstanceReport.Rows.Count > 0) { foreach (InstanceReportRow prevRow in this.InstanceReport.Rows) { areSame = ColumnRowRequirement.AreSameExceptCurrency(prevRow.EmbedRequirements, rowReqs); if (areSame) { //the previous check doesn't check currency - check it here areSame = string.Equals(prevRow.EmbedRequirements.UnitCode, rowReqs.UnitCode); } //let `areSame` fall through, and this row will not get picked up if (areSame) { break; } } } //If they are the same, skip the new one - we don't want or need duplicates if (!areSame) { InstanceReportRow row = new InstanceReportRow(); row.EmbedRequirements = rowReqs; row.HasMultiCurrency = this.hasMultiCurrency; if (row.EmbedRequirements.ElementRow != null) { row.EmbedRequirements.ElementRow.ApplyDataTo(row); } this.InstanceReport.Rows.Add(row); } } } else if (iterator.Value.Selection == CommandIterator.SelectionType.Separator) { iteratorHierarchy.Push(iterator.Value); ProcessIteratorsHierarchically(iterator.Next, iteratorHierarchy, messenger); iteratorHierarchy.Pop(); } else { bool hasDefaultMember; Dictionary <string, object> memberValues = this.GetSelectionMembers(iteratorHierarchy, iterator.Value, out hasDefaultMember); if (memberValues.Count == 0) { if (messenger != null) { messenger.TraceWarning("Warning: The selection of the following command, '" + iterator.Value.SelectionString + "', did not match any values available on this report:" + Environment.NewLine + iterator.Value.ToString()); } return; } switch (iterator.Value.Selection) { case CommandIterator.SelectionType.Axis: if (!hasDefaultMember) { iterator.Value.Style = CommandIterator.StyleType.Compact; } break; case CommandIterator.SelectionType.Unit: if (memberValues.Count > 1) { if (memberValues.ContainsKey(string.Empty) && memberValues.Count == 2) { this.hasMultiCurrency = false; } else { this.hasMultiCurrency = true; } } break; } int valuesFound = 0; foreach (KeyValuePair <string, object> member in memberValues) { if (string.Equals(iterator.Value.Filter, "*") || string.Equals(iterator.Value.Filter, member.Key, StringComparison.CurrentCultureIgnoreCase)) { valuesFound++; iteratorHierarchy.Push(iterator.Value); iterator.Value.TempCurrentMemberKey = member.Key; iterator.Value.TempCurrentMemberValue = member.Value; ProcessIteratorsHierarchically(iterator.Next, iteratorHierarchy, messenger); iterator.Value.TempCurrentMemberKey = null; iterator.Value.TempCurrentMemberValue = null; iteratorHierarchy.Pop(); } } if (valuesFound == 0) { if (messenger != null) { messenger.TraceWarning("Warning: The filter '" + iterator.Value.Filter + "' of following embed command did not match any values available on this report:" + Environment.NewLine + iterator.Value.ToString()); } } } }
public void GenerateEmbedLabel( ColumnRowRequirement embedRequirements ) { this.GenerateEmbedLabel( embedRequirements, false ); }