示例#1
0
        private void ProcessMissingMapsMultiCurrency(List <ColumnInstantDurationMap> columnMaps)
        {
            if (!this.ContainMultiCurrencies())
            {
                return;
            }

            for (int durIndex = 0; durIndex < this.Columns.Count; durIndex++)
            {
                InstanceReportColumn ircDuration = this.Columns[durIndex];
                if (ircDuration.MyPeriodType != Element.PeriodType.duration)
                {
                    continue;
                }

                if (!string.Equals(ircDuration.CurrencyCode, InstanceUtils.USDCurrencyCode, StringComparison.CurrentCultureIgnoreCase))
                {
                    continue;
                }

                for (int instantIndex = 0; instantIndex < this.Columns.Count; instantIndex++)
                {
                    InstanceReportColumn ircInstant = this.Columns[instantIndex];
                    if ((ircInstant.CurrencyCode.ToLower() == "usd" || String.IsNullOrEmpty(ircInstant.CurrencyCode)) &&
                        ircInstant.MyPeriodType == Element.PeriodType.instant &&
                        ircInstant.MyContextProperty.PeriodStartDate == ircDuration.MyContextProperty.PeriodEndDate)
                    {
                        if (ircDuration.SegmentAndScenarioEquals(ircInstant))
                        {
                            bool found = false;
                            ColumnInstantDurationMap newMap = new ColumnInstantDurationMap(instantIndex, durIndex, ircDuration.ReportingSpan);
                            foreach (ColumnInstantDurationMap map in columnMaps)
                            {
                                if (map.DurationColumnIndex == durIndex && map.InstantColumnIndex == instantIndex)
                                {
                                    found = true;
                                    break;
                                }
                            }

                            if (!found)
                            {
                                columnMaps.Add(newMap);
                            }
                        }
                    }
                }
            }
        }
        public bool ColumnsShouldBeMerged( InstanceReportColumn ircDuration, InstanceReportColumn ircInstant )
        {
            if( !ircDuration.SegmentAndScenarioEquals( ircInstant ) )
                return false;

            if( ircDuration.MCU.contextRef.PeriodType != Element.PeriodType.duration )
                return false;

            if( ircInstant.MCU.contextRef.PeriodType != Element.PeriodType.instant )
                return false;

            //check for end of current duration
            bool isMergeable = false;
            if( ircInstant.MCU.contextRef.PeriodStartDate == ircDuration.MCU.contextRef.PeriodEndDate )
                isMergeable = true;

            //check for beginning of current duration
            if( ircInstant.MCU.contextRef.PeriodStartDate == ircDuration.MCU.contextRef.PeriodStartDate.AddDays( -1 ) ||
                ircInstant.MCU.contextRef.PeriodStartDate == ircDuration.MCU.contextRef.PeriodStartDate )
                isMergeable = true;

            if( !isMergeable )
                return false;

            //continue TopLevelNode check for sgement/scenario
            //Get all of the "labels" that this column uses
            //removed empty entries and the calendar entry - we already matched that
            char[] lineBreak = { '\r', '\n' };
            string[] durationLabelParts = ircDuration.Label.Split( lineBreak );
            string periodString = ircDuration.GetReportingPeriodString();
            List<string> durationLables = new List<string>( durationLabelParts );
            durationLables.RemoveAll(
                ( lbl ) => { return MergedColumnLabelFilter( lbl, periodString ); } );

            string[] instantLabelParts = ircInstant.Label.Split( lineBreak );
            periodString = ircInstant.GetReportingPeriodString();
            List<string> instantLables = new List<string>( instantLabelParts );
            instantLables.RemoveAll(
                ( lbl ) => { return MergedColumnLabelFilter( lbl, periodString ); } );

            int labelDifferences = Math.Abs( instantLables.Count - durationLables.Count );
            if( labelDifferences > 1 )
            {
                //there are too many label differences for us to repair
                return false;
            }

            //Check if one of the columns has a unit label, and the other does not.
            if( labelDifferences == 1 )
            {
                if( durationLables.Count > instantLables.Count )
                {
                    string dLastLabel = durationLables[ durationLables.Count - 1 ];
                    if( dLastLabel.StartsWith( ircDuration.CurrencyCode ) &&
                        dLastLabel.Contains( ircDuration.CurrencySymbol ) )
                    {
                        durationLables.Remove( dLastLabel );
                    }
                }
                else
                {
                    string iLastLabel = instantLables[ instantLables.Count - 1 ];
                    if( iLastLabel.StartsWith( ircInstant.CurrencyCode ) &&
                        iLastLabel.Contains( ircInstant.CurrencySymbol ) )
                    {
                        instantLables.Remove( iLastLabel );
                    }
                }
            }

            //alright - we've done the best we can - let's see if they match
            for( int index = 0; index < instantLables.Count; index++ )
            {
                string instantStr = instantLables[ index ].ToString();
                string durationStr = durationLables[ index ].ToString();

                //converted from durationStr.CompareTo( instantStr ) != 0
                if( durationStr == instantStr )
                    continue;

                return false;
            }

            return true;
        }
示例#3
0
        private void InstantValues()
        {
            List <InstanceReportRow> instantRows = this.Rows.FindAll(row => row.PeriodType == "instant");

            if (instantRows.Count == 0)
            {
                return;
            }

            for (int c = 0; c < this.Columns.Count; c++)
            {
                InstanceReportColumn curColumn = this.Columns[c];

                DateTime?curDate = null;
                if (curColumn.MyPeriodType == Element.PeriodType.instant)
                {
                    curDate = curColumn.MyContextProperty.PeriodStartDate;
                }

                for (int c2 = c + 1; c2 < this.Columns.Count; c2++)
                {
                    InstanceReportColumn nextColumn = this.Columns[c2];
                    if (!curColumn.SegmentAndScenarioEquals(nextColumn))
                    {
                        break;
                    }

                    bool curHasCurrency = !string.IsNullOrEmpty(curColumn.CurrencyCode);
                    if (curHasCurrency)
                    {
                        bool nextHasCurrency = !string.IsNullOrEmpty(nextColumn.CurrencyCode);
                        if (nextHasCurrency)
                        {
                            if (!string.Equals(curColumn.CurrencyCode, nextColumn.CurrencyCode))
                            {
                                continue;
                            }
                        }
                    }

                    DateTime?nextDate = null;
                    if (nextColumn.MyPeriodType == Element.PeriodType.instant)
                    {
                        nextDate = nextColumn.MyContextProperty.PeriodStartDate;
                    }

                    foreach (InstanceReportRow row in instantRows)
                    {
                        DateTime?leftDate, rightDate;
                        if (curDate.HasValue)
                        {
                            leftDate = curDate;
                        }
                        else
                        {
                            if (row.IsBeginningBalance)
                            {
                                leftDate = curColumn.MyContextProperty.PeriodStartDate;
                            }
                            else
                            {
                                leftDate = curColumn.MyContextProperty.PeriodEndDate;
                            }
                        }

                        if (nextDate.HasValue)
                        {
                            rightDate = nextDate;
                        }
                        else
                        {
                            if (row.IsBeginningBalance)
                            {
                                rightDate = nextColumn.MyContextProperty.PeriodStartDate;
                            }
                            else
                            {
                                rightDate = nextColumn.MyContextProperty.PeriodEndDate;
                            }
                        }

                        if (DateTime.Equals(leftDate, rightDate))
                        {
                            bool canShareData = row.Cells[c].HasData ^ row.Cells[c2].HasData;
                            if (canShareData)
                            {
                                if (!row.Cells[c].HasData)
                                {
                                    row.Cells[c].AddData(row.Cells[c2]);
                                }
                                else
                                {
                                    row.Cells[c2].AddData(row.Cells[c]);
                                }
                            }
                        }
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// Consider calling <see>report</see>.<see cref="InstanceReport.SortColumns"/> first.  Merges 1) non-monetary units and 2) monetary units of the same currency and 3) merges them under the same calendar/segments if possible.
        /// </summary>
        /// <param name="report">The report whose columns will be merged.</param>
        /// <returns>True on success, false on fail.</returns>
        private static bool MergeColumns(InstanceReport report)
        {
            if (report == null)
            {
                return(false);
            }

            bool hasMergedColumns = false;

            for (int c = 0; c < report.Columns.Count - 1; c++)
            {
                InstanceReportColumn curColumn  = report.Columns[c];
                InstanceReportColumn nextColumn = report.Columns[c + 1];
                if (!curColumn.ReportingPeriodEquals(nextColumn) ||
                    !curColumn.SegmentAndScenarioEquals(nextColumn))
                {
                    continue;
                }

                bool curHasCurrency = !string.IsNullOrEmpty(curColumn.CurrencyCode);
                if (curHasCurrency)
                {
                    bool nextHasCurrency = !string.IsNullOrEmpty(nextColumn.CurrencyCode);
                    if (nextHasCurrency)
                    {
                        if (!string.Equals(curColumn.CurrencyCode, nextColumn.CurrencyCode))
                        {
                            continue;
                        }
                    }
                }

                bool columnValuesAreUnique = true;
                foreach (InstanceReportRow row in report.Rows)
                {
                    if (row.Cells[c].HasData && row.Cells[c + 1].HasData)
                    {
                        columnValuesAreUnique = false;
                        break;
                    }
                }

                if (columnValuesAreUnique)
                {
                    //since we have unique columns, merge them and remove the column + cells
                    hasMergedColumns = true;
                    foreach (InstanceReportRow row in report.Rows)
                    {
                        if (!row.Cells[c].HasData && row.Cells[c + 1].HasData)
                        {
                            row.Cells[c].AddData(row.Cells[c + 1]);
                        }
                    }

                    //please don't move this up ;-)
                    report.RemoveColumn(c + 1);
                    c--;

                    curColumn.Units.AddRange(nextColumn.Units);
                    if (string.IsNullOrEmpty(curColumn.CurrencyCode) && !string.IsNullOrEmpty(nextColumn.CurrencyCode))
                    {
                        curColumn.CurrencyCode   = nextColumn.CurrencyCode;
                        curColumn.CurrencySymbol = nextColumn.CurrencySymbol;

                        curColumn.MCU.CurrencyCode   = nextColumn.MCU.CurrencyCode;
                        curColumn.MCU.CurrencySymbol = nextColumn.MCU.CurrencySymbol;

                        //this is probably the currency label - since we didn't have a currency, we didn't have the label
                        //copy the reference to this label over
                        LabelLine last = nextColumn.Labels[nextColumn.Labels.Count - 1];
                        last.Id = curColumn.Labels.Count;
                        curColumn.Labels.Add(last);
                    }
                }
            }

            return(hasMergedColumns);
        }
示例#5
0
        public bool ColumnsShouldBeMerged(InstanceReportColumn ircDuration, InstanceReportColumn ircInstant)
        {
            if (!ircDuration.SegmentAndScenarioEquals(ircInstant))
            {
                return(false);
            }

            if (ircDuration.MCU.contextRef.PeriodType != Element.PeriodType.duration)
            {
                return(false);
            }

            if (ircInstant.MCU.contextRef.PeriodType != Element.PeriodType.instant)
            {
                return(false);
            }


            //check for end of current duration
            bool isMergeable = false;

            if (ircInstant.MCU.contextRef.PeriodStartDate == ircDuration.MCU.contextRef.PeriodEndDate)
            {
                isMergeable = true;
            }

            //check for beginning of current duration
            if (ircInstant.MCU.contextRef.PeriodStartDate == ircDuration.MCU.contextRef.PeriodStartDate.AddDays(-1) ||
                ircInstant.MCU.contextRef.PeriodStartDate == ircDuration.MCU.contextRef.PeriodStartDate)
            {
                isMergeable = true;
            }


            if (!isMergeable)
            {
                return(false);
            }

            //continue TopLevelNode check for sgement/scenario
            //Get all of the "labels" that this column uses
            //removed empty entries and the calendar entry - we already matched that
            char[]        lineBreak          = { '\r', '\n' };
            string[]      durationLabelParts = ircDuration.Label.Split(lineBreak);
            string        periodString       = ircDuration.GetReportingPeriodString();
            List <string> durationLables     = new List <string>(durationLabelParts);

            durationLables.RemoveAll(
                (lbl) => { return(MergedColumnLabelFilter(lbl, periodString)); });


            string[] instantLabelParts = ircInstant.Label.Split(lineBreak);
            periodString = ircInstant.GetReportingPeriodString();
            List <string> instantLables = new List <string>(instantLabelParts);

            instantLables.RemoveAll(
                (lbl) => { return(MergedColumnLabelFilter(lbl, periodString)); });


            int labelDifferences = Math.Abs(instantLables.Count - durationLables.Count);

            if (labelDifferences > 1)
            {
                //there are too many label differences for us to repair
                return(false);
            }

            //Check if one of the columns has a unit label, and the other does not.
            if (labelDifferences == 1)
            {
                if (durationLables.Count > instantLables.Count)
                {
                    string dLastLabel = durationLables[durationLables.Count - 1];
                    if (dLastLabel.StartsWith(ircDuration.CurrencyCode) &&
                        dLastLabel.Contains(ircDuration.CurrencySymbol))
                    {
                        durationLables.Remove(dLastLabel);
                    }
                }
                else
                {
                    string iLastLabel = instantLables[instantLables.Count - 1];
                    if (iLastLabel.StartsWith(ircInstant.CurrencyCode) &&
                        iLastLabel.Contains(ircInstant.CurrencySymbol))
                    {
                        instantLables.Remove(iLastLabel);
                    }
                }
            }

            //alright - we've done the best we can - let's see if they match
            for (int index = 0; index < instantLables.Count; index++)
            {
                string instantStr  = instantLables[index].ToString();
                string durationStr = durationLables[index].ToString();

                //converted from durationStr.CompareTo( instantStr ) != 0
                if (durationStr == instantStr)
                {
                    continue;
                }

                return(false);
            }

            return(true);
        }