internal static string GetTagReplacementValue(Match match, IList <DataElement> dataSet, int depth) { Logger logger = LogManager.GetLogger("Generator"); string name = match.Groups["name"].Value; Index rowIndex = string.IsNullOrEmpty(match.Groups["row"].Value) ? new Index(0) : new Index(match.Groups["row"].Value); Index columnIndex = string.IsNullOrEmpty(match.Groups["column"].Value) ? new Index(0) : new Index(match.Groups["column"].Value); string format = match.Groups["format"].Value; DataElement targetElement = dataSet.FirstOrDefault(e => e.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (targetElement != null) { object replacementValue = targetElement.Column(columnIndex)[rowIndex]; if (replacementValue != null) { if (replacementValue is string && ((string)replacementValue).IndexOf('#') >= 0) { replacementValue = ParseAndReplace((string)replacementValue, dataSet, ++depth); } if (!string.IsNullOrEmpty(format)) { return(string.Format("{0:" + format.TrimStart('{'), replacementValue)); } return(replacementValue.ToString()); } else { logger.Debug("Element {0} contains no data", name); return("#" + match.Value + "#"); } } logger.Debug("Unable to find data element {0}", name); return("#" + match.Value + "#"); }
public override void ApplyToData(DataElement data) { Dictionary <int, object> dataToSort = new Dictionary <int, object>(); int columnNo = data.Columns.IndexOf(data.Column(Index)); for (int i = 0; i < data.Rows.Count; i++) { dataToSort.Add(i, data.Rows[i].Data[columnNo]); } DataElement temp = data.Clone(); data.Rows.Clear(); foreach (Column column in data.Columns) { column.Data.Clear(); } List <KeyValuePair <int, object> > sortedData; if (SortOrder == Commands.SortOrder.Ascending) { sortedData = dataToSort.OrderBy(k => k.Value).ToList(); } else { sortedData = dataToSort.OrderByDescending(k => k.Value).ToList(); } foreach (KeyValuePair <int, object> kvp in sortedData) { data.Rows.Add(temp.Rows[kvp.Key]); } data.Normalize(); }
public void ColumnByNameThrowsArgumentExceptionWhenNoRowHeaders() { DataElement da = Helpers.CreateTestDataElement(); da.HasColumnHeaders = false; da.HasRowHeaders = false; var column = da.Column("Column 2"); }
public void ColumnByNameReturnsColumn() { DataElement da = Helpers.CreateTestDataElement(); var column = da.Column("Column 2"); Assert.AreEqual("client 1", column.Data[0]); Assert.AreEqual("client 2", column.Data[1]); }
public void ApplyToDataFormatsAllValues() { DataElement da = Helpers.CreateTestDataElement(); ShapeElementBase element = (ShapeElementBase)(ShapeElementBaseTest.Create()); element.RowIndexes.Clear(); element.RowIndexes.Add(new Index(0)); element.RowIndexes.Add(new Index(1)); element.ColumnIndexes.Clear(); element.ColumnIndexes.Add(new Index(0)); FormatCommand cmd = new FormatCommand(); cmd.TargetElement = element; cmd.FormatString = "0.0000"; cmd.ApplyToData(da); Assert.AreEqual("1.0000", da.Row(0).Data[0]); Assert.AreEqual("5.0500", da.Row(1).Data[0]); Assert.AreEqual("1.0000", da.Column(0).Data[0]); Assert.AreEqual("5.0500", da.Column(0).Data[1]); }
public override void ApplyToData(DataElement data) { if (Index.IsAll) { for (int i = 0; i < data.Columns.Count; i++) { var column = data.Columns[i]; ApplyToColumn(data, column); } } else { var column = data.Column(Index); ApplyToColumn(data, column); } }
public override void ApplyToData(DataElement data) { if (string.IsNullOrEmpty(FormatString)) { return; } if (Index == null) { for (int columnIndex = 0; columnIndex < data.Columns.Count; columnIndex++) { FormatColumn(data, columnIndex); } } else { Column column = data.Column(Index); int columnIndex = data.Columns.IndexOf(column); FormatColumn(data, columnIndex); } }
public void ColumnByNameThrowsIndexExceptionWhenIndexInvalid() { DataElement da = Helpers.CreateTestDataElement(); var column = da.Column("My Column 2"); }