Esempio n. 1
0
 /// <summary>
 /// Creates a deep copy of the structured query.
 /// </summary>
 /// <returns></returns>
 public StructuredQuery DeepCopy()
 {
     using (Profiler.Measure("StructureQuery.DeepCopy"))
     {
         StructuredQuery deepCopy = (StructuredQuery)serializer.DeepClone(this);
         return(deepCopy);
     }
 }
        public void Test_FieldTypes(string fieldTypeAlias, string calc, string equalTo, Type databaseType, Type cellDataType)
        {
            // Define type
            EntityType type = new EntityType();

            // Define calculated field
            Field field = Entity.Create(new EntityRef(fieldTypeAlias)).As <Field>();

            field.IsCalculatedField = true;
            field.FieldCalculation  = calc;
            type.Fields.Add(field);

            type.Save();

            // Create instance
            Resource inst = Entity.Create(type.Id).As <Resource>();

            inst.Name = "Name1";
            inst.Save();

            // Define structured query
            var sq = new SQ.StructuredQuery();

            sq.RootEntity = new SQ.ResourceEntity(new EntityRef(type.Id));
            var column = new SQ.SelectColumn();

            column.Expression = new SQ.ResourceDataColumn(sq.RootEntity, new EntityRef(field.Id));
            sq.SelectColumns.Add(column);

            // Run report
            var settings    = new SQ.QuerySettings();
            var queryResult = Factory.QueryRunner.ExecuteQuery(sq, settings);

            // Check results
            Assert.That(queryResult.Columns[0].ColumnType, Is.TypeOf(databaseType));
            var    row  = queryResult.DataTable.Rows[0];
            object data = row[0];

            Assert.That(data, Is.InstanceOf(cellDataType));

            if (equalTo == "*")
            {
                Assert.That(data.ToString(), Is.Not.Null.And.Not.Empty);
            }
            else
            {
                Assert.That(data.ToString(), Is.EqualTo(equalTo));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a shallow copy of the structured query.
        /// </summary>
        /// <returns></returns>
        public StructuredQuery ShallowCopy()
        {
            var queryCopy = new StructuredQuery();

            queryCopy.RootEntity = RootEntity;
            queryCopy.SelectColumns.AddRange(SelectColumns);
            queryCopy.Conditions.AddRange(Conditions);
            queryCopy.OrderBy.AddRange(OrderBy);
            queryCopy.Distinct                 = Distinct;
            queryCopy.TimeZoneName             = TimeZoneName;
            queryCopy.Report                   = Report;
            queryCopy.InvalidReportInformation = InvalidReportInformation;

            return(queryCopy);
        }
        /// <summary>
        /// Aggregated columns for report.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <param name="query">The query.</param>
        /// <returns>List{ReportAggregateField}.</returns>
        internal static List <ReportAggregateField> AggregatedColumnsForReport(Report report, StructuredQuery query)
        {
            var converter = Factory.Current.Resolve <IReportToQueryPartsConverter>( );

            return((from column in report.ReportColumns
                    from rollup in column.ColumnRollup
                    where converter.IsValidExpression(column.ColumnExpression)
                    select new ReportAggregateField
            {
                ReportColumnId = column.Id == 0 ? Guid.Empty : query.SelectColumns.First(sc => sc.EntityId == column.Id).ColumnId,
                ReportColumnEntityId = column.Id,
                AggregateMethod = AggregateMethodFromEntityEnum(rollup.RollupMethod),
                ShowGrandTotals = report.RollupGrandTotals ?? false,
                ShowSubTotals = report.RollupSubTotals ?? false,
                ShowRowCounts = report.RollupRowCounts ?? false,
                ShowRowLabels = report.RollupRowLabels ?? false,
                ShowOptionLabel = report.RollupOptionLabels ?? false,
                IncludedCount = column.Id == 0
            }).ToList());
        }
        /// <summary>
        /// Grouped columns for report.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <param name="query">The query.</param>
        /// <returns>List{ReportAggregateField}.</returns>
        internal static List <ReportGroupField> GroupedColumnsForReport(Report report, StructuredQuery query)
        {
            var converter = Factory.Current.Resolve <IReportToQueryPartsConverter>( );

            return((from column in report.ReportColumns
                    from columnGrouping in column.ColumnGrouping
                    orderby columnGrouping.GroupingPriority
                    where converter.IsValidExpression(column.ColumnExpression)
                    select new ReportGroupField
            {
                ReportColumnId = query.SelectColumns.First(sc => sc.EntityId == column.Id).ColumnId,
                ReportColumnEntityId = column.Id,
                GroupMethod = GroupingMethodFromEntityEnum(columnGrouping.GroupingMethod),
                ShowGrandTotals = report.RollupGrandTotals ?? false,
                ShowSubTotals = report.RollupSubTotals ?? false,
                ShowRowCounts = report.RollupRowCounts ?? false,
                ShowRowLabels = report.RollupRowLabels ?? false,
                ShowOptionLabel = report.RollupOptionLabels ?? false,
                Collapsed = columnGrouping.GroupingCollapsed ?? false
            }).ToList());
        }
Esempio n. 6
0
 public ClientAggregate(Report report, StructuredQuery query)
 {
     GroupedColumns    = ClientAggregateHelper.GroupedColumnsForReport(report, query);
     AggregatedColumns = ClientAggregateHelper.AggregatedColumnsForReport(report, query);
 }
        public void Test_InvalidateWhen_ReferencedDataChanged()
        {
            EntityType type = null;
            Field      field;
            Resource   inst;

            try
            {
                // Define type
                type = new EntityType();

                // Define calculated field
                field = Entity.Create(new EntityRef("core:stringField")).As <Field>();
                field.IsCalculatedField = true;
                field.FieldCalculation  = "'Value '+Description";
                type.Fields.Add(field);
                type.Save();

                // Create instance
                inst             = Entity.Create(type.Id).As <Resource>();
                inst.Name        = "Name1";
                inst.Description = "One";
                inst.Save();

                // Define structured query
                var sq = new SQ.StructuredQuery();
                sq.RootEntity = new SQ.ResourceEntity(new EntityRef(type.Id));
                var column = new SQ.SelectColumn();
                column.Expression = new SQ.ResourceDataColumn(sq.RootEntity, new EntityRef(field.Id));
                sq.SelectColumns.Add(column);

                // Run report
                var settings    = new SQ.QuerySettings();
                var queryResult = Factory.QueryRunner.ExecuteQuery(sq, settings);

                // Check results
                var    row  = queryResult.DataTable.Rows[0];
                object data = row[0];
                Assert.That(data, Is.EqualTo("Value One"));

                // Modify data
                inst.Description = "Two";
                inst.Save();

                // Rerun report
                queryResult = Factory.QueryRunner.ExecuteQuery(sq, settings);

                // Recheck results
                row  = queryResult.DataTable.Rows[0];
                data = row[0];
                Assert.That(data, Is.EqualTo("Value Two"));
            }
            finally
            {
                if (type != null)
                {
                    type.Delete();
                }
                // Using RunWithTransaction causes this test to fail
            }
        }