private static ReportDataDefinition PackReportResponse(QueryResult results) { DataTable table = results.DataTable; var data = new ReportDataDefinition( ); ResultColumn idCol = results.Columns.FirstOrDefault(c => c.RequestColumn.ColumnName == "_Id"); data.ReportTitle = "Query"; data.ReportStyle = "Simple"; data.Columns = new List <ReportColumn>( results.Columns.Select(c => new ReportColumn { Title = !string.IsNullOrEmpty(c.DisplayName) ? c.DisplayName : c.RequestColumn.ColumnName, DataType = c.ColumnType.GetDisplayName( ) })); data.ReportDataRows = new List <ReportData>( table.Rows.OfType <DataRow>( ).Select(r => new ReportData { Id = idCol != null ? ( long )r[idCol.RequestColumn.ColumnName] : 99, LineItems = new List <ReportDataItem>(table.Columns.OfType <DataColumn>( ) .Select(c => new ReportDataItem { Value = r[c.ColumnName].ToString( ) })) })); return(data); }
internal void PopulateArray(DataTable metaData) { BindToColumns(metaData); ResultColumn column = null; if (metaData.DefaultView.Count > 0) { IEnumerator enumerator = metaData.DefaultView.GetEnumerator(); while (enumerator.MoveNext()) { DataRowView rowView = enumerator.Current as DataRowView; if (plugin != null) { column = this.dbRoot.ClassFactory.CreateResultColumn() as ResultColumn; } else { column = new PluginResultColumn(null); } column.dbRoot = this.dbRoot; column.ResultColumns = this; column.Row = rowView.Row; this._array.Add(column); } } }
private IEnumerable <List <EmailOwnerRecipientData> > TokenRecipients(List <EmailTemplateRecipientEntity> tokenRecipients) { if (!template.SendDifferentMessages) { return(new[] { tokenRecipients.SelectMany(tr => { ResultColumn owner = dicTokenColumn.GetOrThrow(tr.Token.Token); List <EmailOwnerData> groups = currentRows.Select(r => (EmailOwnerData)r[owner]).Distinct().ToList(); if (groups.Count == 1 && groups[0]?.Email == null) { return new List <EmailOwnerRecipientData>(); } return groups.Where(g => g.Email.HasText()).Select(g => new EmailOwnerRecipientData(g) { Kind = tr.Kind }).ToList(); }).ToList() }); } else { return(CrossProduct(tokenRecipients, 0)); } }
public override IEnumerable <object> GetFilteredRows(TemplateParameters p, FilterOperation?operation, string stringValue) { if (operation == null) { var column = p.Columns[ParsedToken.QueryToken]; var filtered = p.Rows.Where(r => ToBool(r[column])).ToList(); return(filtered); } else { var type = this.Type; object val = FilterValueConverter.Parse(stringValue, type, operation.Value.IsList()); Expression value = Expression.Constant(val, type); ResultColumn col = p.Columns[ParsedToken.QueryToken]; var expression = Signum.Utilities.ExpressionTrees.Linq.Expr((ResultRow rr) => rr[col]); Expression newBody = QueryUtils.GetCompareExpression(operation.Value, Expression.Convert(expression.Body, type), value, inMemory: true); var lambda = Expression.Lambda <Func <ResultRow, bool> >(newBody, expression.Parameters).Compile(); var filtered = p.Rows.Where(lambda).ToList(); return(filtered); } }
/// <summary> /// Clone a list of result columns, performing mapping of original select column to current select column. /// See notes in MutateResultToMatchCurrentQuery. /// </summary> private static List <ResultColumn> MutateColumnList(List <ResultColumn> columnList, List <SelectColumn> originalRequestColumns, List <SelectColumn> currentRequestColumns) { if (columnList == null) { return(null); } List <ResultColumn> result = new List <ResultColumn>(columnList.Count); foreach (ResultColumn resultColumn in columnList) { ResultColumn cloneColumn = resultColumn.ShallowClone( ); // Faster than setting up a dictionary when there are so few columns int index = -1; if (cloneColumn.RequestColumn != null) { index = originalRequestColumns.FindIndex(column => column.ColumnId == cloneColumn.RequestColumn.ColumnId); } if (index != -1) { cloneColumn.RequestColumn = currentRequestColumns [index]; } result.Add(cloneColumn); } return(result); }
public static List <ResultColumn> ToResultColumns(this IList <DataColumn> dataColumns) { var result = new List <ResultColumn>(); foreach (var dc in dataColumns) { var r = new ResultColumn(); r.AllowDBNull = dc.AllowDBNull; r.AutoIncrement = dc.AutoIncrement; r.AutoIncrementSeed = dc.AutoIncrementSeed; r.AutoIncrementStep = dc.AutoIncrementStep; r.Caption = dc.Caption; //r.ColumnMapping = dc.ColumnMapping r.ColumnName = dc.ColumnName; r.DataType = dc.DataType.ToString(); //r.DateTimeMode = dc.DateTimeMode; //r.DefaultValue = r.DesignMode = dc.DesignMode; r.Expression = dc.Expression; r.MaxLength = dc.MaxLength; r.Namespace = dc.Namespace; r.Ordinal = dc.Ordinal; r.Prefix = dc.Prefix; //r.Site = dc.Site r.ReadOnly = dc.ReadOnly; r.Unique = dc.Unique; result.Add(r); } return(result); }
/// <summary> /// Get the structure view column indexes. /// </summary> /// <param name="result">The query result.</param> /// <returns>The structure view column indexes.</returns> private static List <StructureViewColumInfo> GetStructureViewColumns(QueryResult result) { var structureViewColumnIndexes = new List <StructureViewColumInfo>(); for (int i = 0; i < result.Columns.Count; i++) { ResultColumn resultColumn = result.Columns[i]; if (resultColumn.RequestColumn == null) { continue; } if (resultColumn.RequestColumn.Expression is StructureViewExpression) { // Column returns an encoded structure view path structureViewColumnIndexes.Add(new StructureViewColumInfo(i, false)); } else if (resultColumn.RequestColumn.Expression is AggregateExpression) { var aggregateExpression = resultColumn.RequestColumn.Expression as AggregateExpression; if (aggregateExpression.Expression is StructureViewExpression && aggregateExpression.AggregateMethod == AggregateMethod.List) { // Column returns xml containing encoded structure view path. Yuck ! structureViewColumnIndexes.Add(new StructureViewColumInfo(i, true)); } } } return(structureViewColumnIndexes); }
public List <PredictorCodification> GenerateCodifications(ResultColumn rc, PredictorColumnBase column) { return(rc.Values.Cast <object>().NotNull().Distinct().Select(v => new PredictorCodification(column) { IsValue = v }).ToList()); }
/// <summary> /// Determines whether the result column should use a resource condition. /// </summary> /// <param name="resultColumn">The result column.</param> /// <returns></returns> private bool IsResourceCondition(ResultColumn resultColumn) { if (resultColumn == null) { return(false); } return(resultColumn.IsRelatedResource || _reportResult.IsResultColumnEntityNameColumn(resultColumn)); }
private static ResultColumn[] BuildResultColumns(DAE.Schema.IRowType rowType) { ResultColumn[] result = new ResultColumn[rowType.Columns.Count]; for (int i = 0; i < rowType.Columns.Count; i++) { result[i] = new ResultColumn(rowType.Columns[i].Name); } return(result); }
public void Edit(ResultColumn obj) { if (this._currentType == obj.GetType()) { return; } BindGrid(obj.GlobalProperties); this._currentType = obj.GetType(); }
private static void ResultsFromList(ListValue list, StringBuilder results) { ResultColumn[] resultColumns = new ResultColumn[] { new ResultColumn("Elements") }; for (int index = 0; index < list.Count(); index++) { resultColumns[0].Add(list.GetValue(index).ToString()); } BuildResults(resultColumns, results); }
/// <summary> /// Adds the content row_ string. /// </summary> /// <param name="tr">The tr.</param> /// <param name="col">The col.</param> /// <param name="cellValue">The cell value.</param> private static void AddContentRow_String(TableRow tr, ResultColumn col, object cellValue) { TableCell tc; string cellText = GetFormattedCellValue(cellValue, col.ColumnType, col.RequestColumn.Expression is AggregateExpression); tc = new TableCell(new Paragraph(new Run( new DocumentFormat.OpenXml.Wordprocessing.Text(cellText)))); tr.Append(tc); }
DataTemplate CreateDataTemplate(ResultColumn c) { Binding b = new Binding("[{0}]".FormatWith(c.Index)) { Mode = BindingMode.OneTime }; DataTemplate dt = Settings.GetFormatter(c.Column)(b); return(dt); }
public virtual List <PredictorCodification> GenerateCodifications(ResultColumn rc, PredictorColumnBase column) { var distinctStrings = rc.Values.Cast <string>().NotNull().Distinct(); var allWords = distinctStrings.SelectMany(str => SplitWords(str)).Distinct(StringComparer.CurrentCultureIgnoreCase).ToList(); return(allWords.Select(v => new PredictorCodification(column) { IsValue = v }).ToList()); }
/// <summary> /// Deletes the given part order. The part order should not be used in nestings. /// </summary> /// <param name="id">The identifier.</param> /// <returns>true if deleted</returns> public bool DeletePartOrder(string id) { if (!ResultColumn.SelectItem(id)) { ResultColumn.ClearSearch(); return(false); } Toolbar.Delete(); ResultColumn.ClearSearch(); return(true); }
/// <summary> /// Deletes the given nesting template. /// </summary> /// <param name="id">The identifier.</param> /// <returns>true if successful</returns> public bool DeleteNestingTemplate(string id) { if (!ResultColumn.SelectItem(id)) { ResultColumn.ClearSearch(); return(false); } Toolbar.Delete(); ResultColumn.ClearSearch(); return(true); }
public TabularResultContentSet(ResultConfig resultConfig, List <ResultSpecificationField> resultFields, IDataReader reader) : base() { Reader = reader; Meta = new ResultMetaData() { Columns = ResultColumn.Map(resultFields, SourceColumnType.GetColumnTypes(reader)) }; Data = new ResultData() { DataCollection = Iterator.ToList() }; RequestId = resultConfig.RequestId; }
/// <summary> /// Deletes the given material. /// </summary> /// <param name="id">The identifier.</param> /// <returns>true if successful</returns> public bool DeleteMaterial(string id) { if (!ResultColumn.SelectItem(id)) { ResultColumn.ClearSearch(); return(false); } Toolbar.Delete(); (( TcMainTabControl )Parent).WaitForTabOverlayDisappear(); ResultColumn.ClearSearch(); return(true); }
public List <PredictorCodification> GenerateCodifications(ResultColumn rc, PredictorColumnBase column) { var values = rc.Values.Cast <object>().NotNull().Select(a => Convert.ToSingle(a)).ToList(); return(new List <PredictorCodification> { new PredictorCodification(column) { Average = values.Count == 0 ? 0 : values.Average(), StdDev = values.Count == 0 ? 1 : values.StdDev(), Min = values.Count == 0 ? 0 : values.Min(), Max = values.Count == 0 ? 1 : values.Max(), } }); }
/// <summary> /// Adds the content row_ non string. /// </summary> /// <param name="tr">The tr.</param> /// <param name="col">The col.</param> /// <param name="cellValue">The cell value.</param> private static void AddContentRow_NonString(TableRow tr, ResultColumn col, object cellValue) { TableCell tc; //if data types are Numeric or datetime type, the cell alignment set to right justified ParagraphProperties paragraphProperties = new ParagraphProperties( ); Justification justification = new Justification { Val = JustificationValues.Right }; paragraphProperties.Append(justification); string cellText = GetFormattedCellValue(cellValue, col.ColumnType); tc = new TableCell(new Paragraph(paragraphProperties, new Run( new DocumentFormat.OpenXml.Wordprocessing.Text(cellText)))); tr.Append(tc); }
/// </structural_toolkit_2015> /// <structural_toolkit_2015> /// <summary> /// Build document body for result document /// </summary> /// <param name="calculationParameters">Code calculation parameters</param> /// <param name="element">Revit element for which result document is built</param> /// <param name="document">Active Revit document</param> /// <returns>DocumentBody object</returns> public override DocumentBody BuildResultDocumentBody(Autodesk.Revit.DB.ExtensibleStorage.Entity calculationParameters, Element element, Autodesk.Revit.DB.Document document) { Autodesk.Revit.DB.CodeChecking.Storage.StorageService service = Autodesk.Revit.DB.CodeChecking.Storage.StorageService.GetStorageService(); Autodesk.Revit.DB.CodeChecking.Storage.StorageDocument storageDocument = service.GetStorageDocument(document); Guid activePackageId = storageDocument.CalculationParamsManager.CalculationParams.GetInputResultPackageId(Server.ID); Autodesk.Revit.DB.CodeChecking.Storage.ResultStatus status = storageDocument.ResultsManager.GetResultStatus(element, activePackageId, Server.ID); DocumentBody body = new DocumentBody(); if (!status.IsError()) { // create body object // get results schema for the current element string schemaName = calculationParameters.Schema.SchemaName; switch (schemaName) { case "ResultBeam": ResultLinearElement resultBeam = new ResultBeam(); resultBeam.SetProperties(calculationParameters); WriteResultsToNoteForLinearElements(body, resultBeam, document, ElementType.Beam); break; case "ResultColumn": ResultLinearElement resultColumn = new ResultColumn(); resultColumn.SetProperties(calculationParameters); WriteResultsToNoteForLinearElements(body, resultColumn, document, ElementType.Column); break; case "ResultFloor": ResultSurfaceElement resultFloor = new ResultSurfaceElement(); resultFloor.SetProperties(calculationParameters); WriteResultsToNoteForSurfaceElements(body, resultFloor, document, element, ElementType.Floor); break; case "ResultWall": ResultSurfaceElement resultWall = new ResultSurfaceElement(); resultWall.SetProperties(calculationParameters); WriteResultsToNoteForSurfaceElements(body, resultWall, document, element, ElementType.Wall); break; } } return(body); }
IEnumerable <EmailAddressEmbedded> GetFrom() { if (template.From != null) { if (template.From.Token != null) { ResultColumn owner = dicTokenColumn.GetOrThrow(template.From.Token.Token); if (!template.SendDifferentMessages) { yield return(new EmailAddressEmbedded(currentRows.Select(r => (EmailOwnerData)r[owner] !).Distinct().SingleEx())); } else { var groups = currentRows.GroupBy(r => (EmailOwnerData)r[owner] !); if (groups.Count() == 1 && groups.Single().Key?.Owner == null) { yield break; } else { foreach (var gr in groups) { var old = currentRows; currentRows = gr; yield return(new EmailAddressEmbedded(gr.Key)); currentRows = old; } } } } else { yield return(new EmailAddressEmbedded(new EmailOwnerData { CultureInfo = null, Email = template.From.EmailAddress !, DisplayName = template.From.DisplayName, }));
private IEnumerable <List <EmailOwnerRecipientData> > CrossProduct(List <EmailTemplateRecipientEntity> tokenRecipients, int pos) { if (tokenRecipients.Count == pos) { yield return(new List <EmailOwnerRecipientData>()); } else { EmailTemplateRecipientEntity tr = tokenRecipients[pos]; ResultColumn owner = dicTokenColumn.GetOrThrow(tr.Token.Token); var groups = currentRows.GroupBy(r => (EmailOwnerData)r[owner]).ToList(); if (groups.Count == 1 && groups[0].Key?.Email == null) { yield return(new List <EmailOwnerRecipientData>()); } else { foreach (var gr in groups) { var rec = new EmailOwnerRecipientData(gr.Key) { Kind = tr.Kind }; var old = currentRows; currentRows = gr; foreach (var list in CrossProduct(tokenRecipients, pos + 1)) { var result = list.ToList(); result.Insert(0, rec); yield return(result); } currentRows = old; } } } }
internal TemplateCells GetTemplateCell(ResultColumn c) { if (c.Column.Type.UnNullify() == typeof(DateTime) && c.Column.Format == "d") { return(TemplateCells.Date); } if (c.Column.Type.UnNullify() == typeof(decimal)) { switch (c.Column.Unit) { case "€": return(TemplateCells.DecimalEuro); case "$": return(TemplateCells.DecimalDollar); case "£": return(TemplateCells.DecimalPound); case "¥": return(TemplateCells.DecimalYuan); } } return(GetTemplateCell(c.Column.Type)); }
public static object?DistinctSingle(this IEnumerable <ResultRow> rows, ResultColumn column) { return(rows.Select(r => r[column]).Distinct(SemiStructuralEqualityComparer.Comparer).SingleEx( () => "No values for column {0}".FormatWith(column.Column.Token.FullKey()), () => "Multiple values for column {0}".FormatWith(column.Column.Token.FullKey()))); }
public static IEnumerable <IEnumerable <ResultRow> > GroupByColumn(this IEnumerable <ResultRow> rows, ResultColumn keyColumn) { var groups = rows.GroupBy(r => r[keyColumn], TemplateUtils.SemiStructuralEqualityComparer.Comparer).ToList(); if (groups.Count == 1 && groups[0].Key == null) { return(Enumerable.Empty <IEnumerable <ResultRow> >()); } return(groups); }
/// <summary> /// Converts the data table from one format to another format. /// </summary> /// <param name="queryResult">The query result.</param> /// <param name="sourceQuery">The source query.</param> /// <param name="reportObject">The report object.</param> /// <returns>An in-memory copy of the converted data table.</returns> public static DbDataTable ConvertTo(QueryResult queryResult, StructuredQuery sourceQuery, ReportObject reportObject) { DbDataTable dbTable = null; DataTable dataTable = queryResult.DataTable; if (queryResult.DataTable != null) { var columns = new List <DbDataColumn>( ); // Convert the columns var columnDictionary = new Dictionary <DataColumn, SelectColumn>( ); for (int i = 0; i < queryResult.Columns.Count; i++) { ResultColumn resultColumn = queryResult.Columns[i]; DataColumn dataColumn = queryResult.DataTable.Columns[i]; var dbColumn = new DbDataColumn( ); SelectColumn selectColumn = null; // Check for a column id property if (dataColumn.ExtendedProperties.ContainsKey("ColumnId")) { var columnId = ( Guid )dataColumn.ExtendedProperties["ColumnId"]; selectColumn = sourceQuery.SelectColumns.FirstOrDefault(c => c.ColumnId == columnId); if (!columnDictionary.ContainsKey(dataColumn)) { columnDictionary.Add(dataColumn, selectColumn); } } // Have not found the column yet fallback to using the ordinal if (selectColumn == null) { selectColumn = sourceQuery.SelectColumns[dataColumn.Ordinal]; } // Determine column type if (resultColumn.ColumnType != null) { if (dataColumn.ExtendedProperties.ContainsKey("DisplayPattern") && !string.IsNullOrEmpty(( string )dataColumn.ExtendedProperties["DisplayPattern"])) { dbColumn.Type = new AutoIncrementType( ); } else { dbColumn.Type = resultColumn.ColumnType; } } else { dbColumn.Type = GetColumnDatabaseType(sourceQuery, selectColumn); if (dbColumn.Type is UnknownType) { dbColumn.Type = DatabaseType.ConvertFromType(dataColumn.DataType); } } dbColumn.Id = selectColumn.ColumnId; dbColumn.Name = string.IsNullOrEmpty(selectColumn.DisplayName) ? selectColumn.ColumnName : selectColumn.DisplayName; dbColumn.ColumnName = selectColumn.ColumnName; dbColumn.IsHidden = selectColumn.IsHidden; columns.Add(dbColumn); } var rows = new List <DbDataRow>( ); // Convert the rows foreach (DataRow dataRow in dataTable.Rows) { var row = new DbDataRow( ); // Convert each field foreach (DataColumn dataColumn in dataTable.Columns) { object obj = dataRow[dataColumn]; if (!Convert.IsDBNull(obj)) { row.FieldsByOrdinal[dataColumn.Ordinal] = new DbDataField(DatabaseTypeHelper.ConvertToString(columns[dataColumn.Ordinal].Type, dataRow[dataColumn])); } else { row.FieldsByOrdinal[dataColumn.Ordinal] = new DbDataField(null); } } rows.Add(row); } dbTable = new DbDataTable { TableName = dataTable.TableName, Columns = columns, Rows = rows }; if (dataTable.ExtendedProperties.ContainsKey("Id")) { dbTable.Id = ( Guid )dataTable.ExtendedProperties["Id"]; } if (dataTable.ExtendedProperties.ContainsKey("Name")) { dbTable.Name = ( string )dataTable.ExtendedProperties["Name"]; } } else if (queryResult.AggregateDataTable != null) { var columns = new List <DbDataColumn>( ); // Convert the columns for (int i = 0; i < queryResult.AggregateColumns.Count; i++) { ResultColumn resultColumn = queryResult.AggregateColumns[i]; DataColumn dataColumn = queryResult.AggregateDataTable.Columns[i]; var dbColumn = new DbDataColumn( ); SelectColumn selectColumn = null; // Check for a column id property if (dataColumn.ExtendedProperties.ContainsKey("ColumnId")) { var columnId = ( Guid )dataColumn.ExtendedProperties["ColumnId"]; selectColumn = sourceQuery.SelectColumns.FirstOrDefault(c => c.ColumnId == columnId); } // Have not found the column yet fallback to using the ordinal if (selectColumn == null) { selectColumn = sourceQuery.SelectColumns[dataColumn.Ordinal]; } // Determine column type if (resultColumn.ColumnType != null) { if (dataColumn.ExtendedProperties.ContainsKey("DisplayPattern") && !string.IsNullOrEmpty(( string )dataColumn.ExtendedProperties["DisplayPattern"])) { dbColumn.Type = new AutoIncrementType( ); } else { dbColumn.Type = resultColumn.ColumnType; } } else { dbColumn.Type = GetColumnDatabaseType(sourceQuery, selectColumn); if (dbColumn.Type is UnknownType) { dbColumn.Type = DatabaseType.ConvertFromType(dataColumn.DataType); } } dbColumn.Id = selectColumn.ColumnId; dbColumn.Name = string.IsNullOrEmpty(selectColumn.DisplayName) ? selectColumn.ColumnName : selectColumn.DisplayName; dbColumn.ColumnName = resultColumn.AggregateColumn.AggregateMethod == AggregateMethod.List ? selectColumn.ColumnName : resultColumn.AggregateColumn.AggregateMethod.ToString( ); dbColumn.IsHidden = selectColumn.IsHidden; columns.Add(dbColumn); } var rows = new List <DbDataRow>( ); // Convert the rows foreach (DataRow dataRow in dataTable.Rows) { var row = new DbDataRow( ); // Convert each field foreach (DataColumn dataColumn in dataTable.Columns) { object obj = dataRow[dataColumn]; if (!Convert.IsDBNull(obj)) { row.FieldsByOrdinal[dataColumn.Ordinal] = new DbDataField(DatabaseTypeHelper.ConvertToString(columns[dataColumn.Ordinal].Type, dataRow[dataColumn])); } else { row.FieldsByOrdinal[dataColumn.Ordinal] = new DbDataField(null); } } rows.Add(row); } dbTable = new DbDataTable { TableName = dataTable.TableName, Columns = columns, Rows = rows }; if (dataTable.ExtendedProperties.ContainsKey("Id")) { dbTable.Id = ( Guid )dataTable.ExtendedProperties["Id"]; } if (dataTable.ExtendedProperties.ContainsKey("Name")) { dbTable.Name = ( string )dataTable.ExtendedProperties["Name"]; } } return(dbTable); }
public static DbDataTable ConvertTo(QueryResult queryResult, List <ResultColumn> queryResultColumns, DataTable dataTable, DataTable aggregateDataTable, StructuredQuery sourceQuery, ClientAggregate clientAggregate, ReportObject reportObject) { var columns = new List <DbDataColumn>( ); var databaseTypeDictionary = new Dictionary <Guid, DatabaseType>( ); for (int i = 0; i < queryResultColumns.Count; i++) { queryResult.Columns[i] = queryResultColumns[i]; ResultColumn resultColumn = queryResultColumns[i]; DataColumn dataColumn = dataTable.Columns[i]; var dbColumn = new DbDataColumn( ); SelectColumn selectColumn = null; Guid columnId = Guid.Empty; // Check for a column id property if (dataColumn.ExtendedProperties.ContainsKey("ColumnId")) { columnId = ( Guid )dataColumn.ExtendedProperties["ColumnId"]; selectColumn = sourceQuery.SelectColumns.FirstOrDefault(c => c.ColumnId == columnId); if (!databaseTypeDictionary.ContainsKey(columnId)) { databaseTypeDictionary.Add(columnId, resultColumn.ColumnType); } } // Have not found the column yet fallback to using the ordinal if (selectColumn == null) { selectColumn = sourceQuery.SelectColumns[dataColumn.Ordinal]; } //if current column in groupedcolumn, same as columntype //otherwise, use string type bool existAggregatedColumn = clientAggregate.AggregatedColumns.Any(gc => gc.ReportColumnId == columnId); if (existAggregatedColumn) { dbColumn.Type = new StringType( ); } else { // Determine column type if (resultColumn.ColumnType != null) { if (dataColumn.ExtendedProperties.ContainsKey("DisplayPattern") && !string.IsNullOrEmpty(( string )dataColumn.ExtendedProperties["DisplayPattern"])) { dbColumn.Type = new AutoIncrementType( ); } else { dbColumn.Type = resultColumn.ColumnType; } } else { dbColumn.Type = GetColumnDatabaseType(sourceQuery, selectColumn); if (dbColumn.Type is UnknownType) { dbColumn.Type = DatabaseType.ConvertFromType(dataColumn.DataType); } } } dbColumn.Id = selectColumn.ColumnId; dbColumn.Name = string.IsNullOrEmpty(selectColumn.DisplayName) ? selectColumn.ColumnName : selectColumn.DisplayName; dbColumn.ColumnName = selectColumn.ColumnName; dbColumn.IsHidden = selectColumn.IsHidden; columns.Add(dbColumn); } var rows = new List <DbDataRow>( ); // Convert the rows int rowIndex = 0; foreach (DataRow aggregateDataRow in aggregateDataTable.Rows) { bool isGrandTotalRow = rowIndex == (aggregateDataTable.Rows.Count - 1); rowIndex++; var row = new DbDataRow( ); // Convert each field foreach (DataColumn dataColumn in dataTable.Columns) { Guid columnId = Guid.Empty; DatabaseType databaseType = DatabaseType.StringType; DatabaseType selectColumnType = DatabaseType.StringType; // Check for a column id property if (dataColumn.ExtendedProperties.ContainsKey("ColumnId")) { columnId = ( Guid )dataColumn.ExtendedProperties["ColumnId"]; SelectColumn selectColumn = sourceQuery.SelectColumns.FirstOrDefault(c => c.ColumnId == columnId); databaseType = databaseTypeDictionary.ContainsKey(columnId) ? databaseTypeDictionary[columnId] : DatabaseType.StringType; var expression = selectColumn.Expression as EntityExpression; if (expression != null) { selectColumnType = GetSelectColumnCastType(expression, databaseType); } } bool existGroupedColumn = clientAggregate.GroupedColumns != null && clientAggregate.GroupedColumns.Any(gc => gc.ReportColumnId == columnId); bool existAggregatedColumn = clientAggregate.AggregatedColumns.Any(gc => gc.ReportColumnId == columnId); //not existing in GroupedColumn or AggregatedColumn if (!existGroupedColumn && !existAggregatedColumn) { row.FieldsByOrdinal[dataColumn.Ordinal] = new DbDataField(null); } else if (existGroupedColumn) { List <DataColumn> aggregatedDataColumns = GetAggregatedDataColumns(aggregateDataTable.Columns, columnId); DataColumn aggregatedDataColumn = aggregatedDataColumns.Count > 0 ? aggregatedDataColumns[0] : null; object obj = aggregateDataRow[aggregatedDataColumn]; if (!Convert.IsDBNull(obj)) { string displayPattern = null; if (dataColumn.ExtendedProperties.ContainsKey("DisplayPattern")) { displayPattern = ( string )dataColumn.ExtendedProperties["DisplayPattern"]; } string additionStringformating = GetAddtionalFormatString(columnId, reportObject); string cellValue = DatabaseTypeHelper.ConvertToString(columns[dataColumn.Ordinal].Type, aggregateDataRow[aggregatedDataColumn], displayPattern); if (!string.IsNullOrEmpty(additionStringformating)) { cellValue = string.Format(additionStringformating, aggregateDataRow[aggregatedDataColumn]); } row.FieldsByOrdinal[dataColumn.Ordinal] = new DbDataField(cellValue); } else { row.FieldsByOrdinal[dataColumn.Ordinal] = new DbDataField(null); } } else if (existAggregatedColumn) { List <DataColumn> aggregatedDataColumns = GetAggregatedDataColumns(aggregateDataTable.Columns, columnId); var aggregatedValues = new List <string>( ); foreach (DataColumn aggregatedDataColumn in aggregatedDataColumns) { string columnName = aggregatedDataColumn.ColumnName; columnName = columnName.Split(' ')[0]; int groupedColumnCount = clientAggregate.GroupedColumns != null ? clientAggregate.GroupedColumns.Count : 0; int columnIndex = aggregateDataTable.Columns.IndexOf(aggregatedDataColumn); int aggregateColumnIndex = columnIndex - groupedColumnCount; ReportAggregateField reportAggregateField = clientAggregate.AggregatedColumns[aggregateColumnIndex]; AggregateMethod aggregateMethod = reportAggregateField.AggregateMethod; if (clientAggregate.AggregatedColumns[aggregateColumnIndex] != null) { if (aggregateMethod == AggregateMethod.Count || aggregateMethod == AggregateMethod.CountUniqueItems || aggregateMethod == AggregateMethod.CountUniqueNotBlanks || aggregateMethod == AggregateMethod.CountWithValues) { databaseType = DatabaseType.Int32Type; } } string displayPattern = DatabaseTypeHelper.GetDisplayFormatString(databaseType); string additionStringformating = GetAddtionalFormatString(columnId, reportObject); bool doFormat = !(aggregateMethod == AggregateMethod.Count || aggregateMethod == AggregateMethod.CountUniqueItems || aggregateMethod == AggregateMethod.CountUniqueNotBlanks || aggregateMethod == AggregateMethod.CountWithValues); if (string.IsNullOrEmpty(additionStringformating)) { if (doFormat) { if (selectColumnType is CurrencyType) { //displayPattern = "{0:c3}"; } else if (selectColumnType is DecimalType) { displayPattern = "{0:N3}"; } } } else { displayPattern = additionStringformating; } string aggregateValue = string.Empty; if (doFormat) { if (selectColumnType is DateTimeType) // convert to local time { DateTime tempDate; if (DateTime.TryParse(aggregateDataRow[aggregatedDataColumn].ToString( ), out tempDate)) { tempDate = TimeZoneHelper.ConvertToLocalTime(tempDate, sourceQuery.TimeZoneName); aggregateValue = string.Format(displayPattern, tempDate); } } else { aggregateValue = string.Format(displayPattern, aggregateDataRow[aggregatedDataColumn]); } } else { aggregateValue = aggregateDataRow[aggregatedDataColumn].ToString( ); } if (selectColumnType is ChoiceRelationshipType && (aggregateMethod == AggregateMethod.Max || aggregateMethod == AggregateMethod.Min)) { aggregateValue = UpdateChoiceFieldXmlValue(aggregateValue); } if (doFormat && selectColumnType is CurrencyType && !aggregateValue.StartsWith("$")) { aggregateValue = string.Format("{0:c2}", aggregateDataRow[aggregatedDataColumn]); } if (columnName == "Count") { columnName = "Count"; } else if (columnName == "CountWithValues") { columnName = "Count with values"; } else if (columnName == "CountUniqueItems") { columnName = "Count unique"; } if (reportAggregateField != null && ((isGrandTotalRow && reportAggregateField.ShowGrandTotals) || (!isGrandTotalRow && reportAggregateField.ShowSubTotals))) { aggregatedValues.Add(string.Format("{0}: {1}", columnName, aggregateValue)); } } row.FieldsByOrdinal[dataColumn.Ordinal] = new DbDataField(string.Join("\r", aggregatedValues)); } else { row.FieldsByOrdinal[dataColumn.Ordinal] = new DbDataField(null); } } rows.Add(row); } var dbTable = new DbDataTable { TableName = dataTable.TableName, Columns = columns, Rows = rows }; if (dataTable.ExtendedProperties.ContainsKey("Id")) { dbTable.Id = ( Guid )dataTable.ExtendedProperties["Id"]; } if (dataTable.ExtendedProperties.ContainsKey("Name")) { dbTable.Name = ( string )dataTable.ExtendedProperties["Name"]; } return(dbTable); }
private void BeforeNodeSelected(TreeNode node) { if (node != null) { if (node.Tag == null) { return; } NodeData data = node.Tag as NodeData; MetaObject obj = null; if (data.Type != NodeType.ESMETADATAENGINE) { obj = data.Meta as MetaObject; } if (data != null) { switch (data.Type) { case NodeType.COLUMNS: this.EditNiceNames(data.Meta as Columns); break; case NodeType.DATABASES: this.EditNiceNames(data.Meta as Databases); break; case NodeType.TABLES: case NodeType.SUBTABLES: this.EditNiceNames(data.Meta as Tables); break; case NodeType.VIEWS: case NodeType.SUBVIEWS: this.EditNiceNames(data.Meta as Views); break; case NodeType.FOREIGNKEYS: case NodeType.INDIRECTFOREIGNKEYS: this.EditNiceNames(data.Meta as ForeignKeys); break; case NodeType.PARAMETERS: this.EditNiceNames(data.Meta as Parameters); break; case NodeType.RESULTCOLUMNS: this.EditNiceNames(data.Meta as ResultColumns); break; case NodeType.INDEXES: this.EditNiceNames(data.Meta as Indexes); break; case NodeType.PROCEDURES: this.EditNiceNames(data.Meta as Procedures); break; case NodeType.DOMAINS: this.EditNiceNames(data.Meta as Domains); break; default: this.Grid.DataSource = null; break; } switch (data.Type) { case NodeType.DATABASE: { Database o = obj as Database; metadataProperties.DisplayDatabaseProperties(o, node); this.EditSingle(o, o.Alias); } break; case NodeType.COLUMN: { Column o = obj as Column; metadataProperties.DisplayColumnProperties(o, node); this.EditSingle(o, o.Alias); } break; case NodeType.TABLE: { Table o = obj as Table; metadataProperties.DisplayTableProperties(o, node); this.EditSingle(o, o.Alias); } break; case NodeType.VIEW: { EntitySpaces.MetadataEngine.View o = obj as EntitySpaces.MetadataEngine.View; metadataProperties.DisplayViewProperties(o, node); this.EditSingle(o, o.Alias); } break; case NodeType.PARAMETER: { Parameter o = obj as Parameter; metadataProperties.DisplayParameterProperties(o, node); this.EditSingle(o, o.Alias); } break; case NodeType.RESULTCOLUMN: { ResultColumn o = obj as ResultColumn; metadataProperties.DisplayResultColumnProperties(o, node); this.EditSingle(o, o.Alias); } break; case NodeType.FOREIGNKEY: { ForeignKey o = obj as ForeignKey; metadataProperties.DisplayForeignKeyProperties(o, node); this.EditSingle(o, o.Alias); } break; case NodeType.INDEX: { Index o = obj as Index; metadataProperties.DisplayIndexProperties(o, node); this.EditSingle(o, o.Alias); } break; case NodeType.PROCEDURE: { Procedure o = obj as Procedure; metadataProperties.DisplayProcedureProperties(o, node); this.EditSingle(o, o.Alias); } break; case NodeType.DOMAIN: { Domain o = obj as Domain; metadataProperties.DisplayDomainProperties(o, node); this.EditSingle(o, o.Alias); } break; default: metadataProperties.Clear(); break; } } } }
DataTemplate CreateDataTemplate(ResultColumn c) { Binding b = new Binding("[{0}]".FormatWith(c.Index)) { Mode = BindingMode.OneTime }; DataTemplate dt = Settings.GetFormatter(c.Column)(b); return dt; }