/// <summary> /// Creates a list of unique columns based on their segments and scenarios. /// </summary> /// <returns></returns> private List <InstanceReportColumn> GetSegmentScenarioColumnsForSegmentProcessing() { //#1 - this will be our X axis - a set of unique segments and scenarios // It will be our "master" list of columns for the equity report List <InstanceReportColumn> uniqueSegmentScenarioColumns = new List <InstanceReportColumn>(); for (int c = 0; c < this.Columns.Count; c++) { InstanceReportColumn column = this.Columns[c]; bool exists = ReportUtils.Exists(uniqueSegmentScenarioColumns, tmp => { if (!tmp.SegmentAndScenarioEquals(column)) { return(false); } //if( !tmp.CurrencyEquals( column ) ) // return false; return(true); }); if (!exists) { //create a clone so that we can digest this data without affecting other references InstanceReportColumn newColumn = (InstanceReportColumn)column.Clone(); uniqueSegmentScenarioColumns.Add(newColumn); } } return(uniqueSegmentScenarioColumns); }
private bool ProcessMultiCurrencyMaps(List <ColumnInstantDurationMap> columnMaps) { this.SynchronizeGrid(); //let's put this way to the right int maxColumnId = this.Columns.Count + 5; //first, convert the duration index to the duration ID //also, lookup and store the instant columns Dictionary <int, List <InstanceReportColumn> > durIdToInstantCols = new Dictionary <int, List <InstanceReportColumn> >(); foreach (ColumnInstantDurationMap colMap in columnMaps) { int durID = this.Columns[colMap.DurationColumnIndex].Id; if (!durIdToInstantCols.ContainsKey(durID)) { durIdToInstantCols[durID] = new List <InstanceReportColumn>(); } durIdToInstantCols[durID].Add(this.Columns[colMap.InstantColumnIndex]); } //now we get a set of duration IDs in reverse so that we can work "from right to left" List <int> durationIDs = new List <int>(durIdToInstantCols.Keys); durationIDs.Sort(); durationIDs.Reverse(); bool reprocessMerge = false; foreach (int durID in durationIDs) { InstanceReportColumn durationColumn = this.Columns.Find(col => col.Id == durID); if (!string.IsNullOrEmpty(durationColumn.CurrencyCode)) { continue; } List <InstanceReportColumn> instantColumns = durIdToInstantCols[durID]; if (instantColumns.Count < 2) { continue; } List <string> currencies = new List <string>(); foreach (InstanceReportColumn iCol in instantColumns) { if (string.IsNullOrEmpty(iCol.CurrencyCode)) { continue; } if (!currencies.Contains(iCol.CurrencyCode)) { currencies.Add(iCol.CurrencyCode); } } if (currencies.Count < 2) { continue; } //set this flag so that we know that the mapping needs to be run again. reprocessMerge = true; //alphabetical order... currencies.Sort(); //...USD first if (currencies.Contains(InstanceUtils.USDCurrencyCode)) { currencies.Remove(InstanceUtils.USDCurrencyCode); currencies.Insert(0, InstanceUtils.USDCurrencyCode); } int newLabelId = 0; durationColumn.Labels.ForEach(ll => newLabelId = Math.Max(newLabelId, ll.Id)); int durationIndex = this.Columns.IndexOf(durationColumn); int insertIndex = durationIndex; //create the clones first... InstanceReportColumn original = null; foreach (string currency in currencies) { insertIndex++; //keep moving this up - we do not want duplicated IDs maxColumnId++; InstanceReportColumn clone = (InstanceReportColumn)durationColumn.Clone(); clone.Id = maxColumnId; clone.CurrencyCode = currency; clone.CurrencySymbol = ReportBuilder.GetISOCurrencySymbol(currency); //we will have to clean up at the end - make sure this column sticks somehow if (string.Equals(clone.CurrencyCode, durationColumn.CurrencyCode)) { //if the currency code matches, this is preferred - always store it original = clone; } else { //we will have to clean up at the end - if no column has been selected yet, pick the first //later, if the currency code matches, we'll replace `original` with that if (original == null) { original = clone; } clone.IsPseudoColumn = true; } if (string.IsNullOrEmpty(clone.CurrencySymbol)) { clone.Labels.Add(new LabelLine(newLabelId, clone.CurrencyCode)); } else { clone.Labels.Add(new LabelLine(newLabelId, clone.CurrencyCode + " (" + clone.CurrencySymbol + ")")); } this.Columns.Insert(insertIndex, clone); foreach (InstanceReportRow row in this.Rows) { Cell c = (Cell)row.Cells[durationIndex].Clone(); c.Id = maxColumnId; row.Cells.Insert(insertIndex, c); } } original.IsPseudoColumn = false; //...then remove the original this.RemoveColumn(durationIndex); } if (reprocessMerge) { this.SynchronizeGrid(); } return(reprocessMerge); }