示例#1
0
        public static string GetStringValue(this SumFunction sumFunction)
        {
            switch (sumFunction)
            {
            case SumFunction.Sum:
                return("sum");

            case SumFunction.HighSum:
                return("high_sum");

            case SumFunction.LowSum:
                return("low_sum");

            default:
                throw new ArgumentOutOfRangeException(nameof(sumFunction), sumFunction, null);
            }
        }
        private void RadGridView_AutoGeneratingColumn(object sender, Telerik.Windows.Controls.GridViewAutoGeneratingColumnEventArgs e)
        {
            if (e.ItemPropertyInfo.PropertyType == typeof(double) || (e.ItemPropertyInfo.PropertyType == typeof(int) && e.Column.Name != "Round"))
            {
                AggregateFunction af = new SumFunction()
                {
                    Caption = "Sum: "
                };
                if (e.ItemPropertyInfo.Name.Contains("Percent"))
                {
                    af         = new AverageFunction();
                    af.Caption = "Avg: ";
                }
                var info = e.ItemPropertyInfo.Descriptor as System.ComponentModel.PropertyDescriptor;


                var att = info.Attributes.OfType <DisplayFormatAttribute>().FirstOrDefault();

                if (att != null)
                {
                    af.ResultFormatString = "{0:" + att.DataFormatString + "}";
                }


                //if (info.CustomAttributes.Any(c=>c.AttributeType == typeof(DisplayFormatAttribute)))
                //{
                //    string format =info.CustomAttributes.First(f => f.AttributeType == typeof(DisplayFormatAttribute)).NamedArguments.First(f => f.MemberName == "DataFormatString").TypedValue.Value as String;
                //    if (format != null)
                //    {
                //        af.ResultFormatString = format;
                //    }
                //}



                e.Column.AggregateFunctions.Add(af);
            }
        }
示例#3
0
        public static void RegisterAll()
        {
            BreakExpression.Register();
            ContinueExpression.Register();
            ReturnFunctionExpression.Register();
            AbsFunction.Register();
            ExecuteFile.Register();
            PowFunction.Register();
            ProductFunction.Register();
            HelpFunction.Register();
            SqrtFunction.Register();
            SumDeepFunction.Register();
            SumFunction.Register();
            LengthFunction.Register();

            ConsoleObject.Register();
            TrigonometryObject.Register();
            ThisConstant.Register();

            BooleanValue.Register();
            ComplexValue.Register();
            DecimalValue.Register();
            NullValue.Register();
        }
示例#4
0
 protected SumDetectorBase(SumFunction function) : base(function.GetStringValue())
 {
 }
示例#5
0
 public SumDetectorDescriptor(SumFunction function) : base(function.GetStringValue())
 {
 }
示例#6
0
        /// <summary>
        /// Auto generates a table based on the schema of a query
        /// </summary>
        /// <param name="query">The query</param>
        /// <param name="tableTitle">The table title</param>
        /// <param name="excludedColumns">The names of excluded columns</param>
        /// <returns>The table definition created</returns>
        protected virtual TableDefinition AutoGenerateTable
        (
            IQuery query,
            string tableTitle,
            params string[] excludedColumns
        )
        {
            Validate.IsNotNull(query);
            Validate.IsNotNull(excludedColumns);

            var tableDefinition = new TableDefinition
                                  (
                query.Name,
                tableTitle,
                query
                                  );

            foreach (var columnInfo in query.Columns)
            {
                var columnName = columnInfo.Column.Name;

                var isExcluded = excludedColumns.Any
                                 (
                    exclusion => exclusion.Equals(columnName, StringComparison.OrdinalIgnoreCase)
                                 );

                if (false == isExcluded)
                {
                    var valueType       = columnInfo.Column.ValueType;
                    var totalAggregator = default(IAggregateFunction);

                    if (valueType.IsNumericType() && false == valueType.IsEnumAssignable())
                    {
                        totalAggregator = new SumFunction
                                          (
                            new DataBinding
                            (
                                columnName
                            )
                                          );
                    }

                    var columnDefinition = new TableColumnDefinition
                                           (
                        columnName.Spacify(),
                        new DataBinding
                        (
                            DataBindingType.QueryPath,
                            columnName
                        ),
                        totalAggregator
                                           );

                    tableDefinition.StaticColumns.Add
                    (
                        columnDefinition
                    );
                }
            }

            return(tableDefinition);
        }
示例#7
0
        /// <summary>
        /// Generates a table based on the schema of a query with the columns specified
        /// </summary>
        /// <param name="query">The query</param>
        /// <param name="tableTitle">The table title</param>
        /// <param name="columnMappings">The names of columns to map</param>
        /// <returns>The table definition created</returns>
        /// <remarks>
        /// The column mappings are represented as an array of key-value pairs.
        ///
        /// Each pair represents a single query column (key) and the table
        /// column (value) that it maps to.
        /// </remarks>
        protected virtual TableDefinition GenerateTableWith
        (
            IQuery query,
            string tableTitle,
            params KeyValuePair <string, string>[] columnMappings
        )
        {
            Validate.IsNotNull(query);
            Validate.IsNotNull(columnMappings);

            if (columnMappings.Length == 0)
            {
                throw new ArgumentException
                      (
                          "At least one column must be specified to create a table."
                      );
            }

            var tableDefinition = new TableDefinition
                                  (
                query.Name,
                tableTitle,
                query
                                  );

            foreach (var mapping in columnMappings)
            {
                var columnFound = query.HasColumn
                                  (
                    mapping.Key
                                  );

                if (false == columnFound)
                {
                    throw new InvalidOperationException
                          (
                              $"The query does not have a column named '{mapping.Key}'."
                          );
                }

                var columnInfo = query.GetColumn
                                 (
                    mapping.Key
                                 );

                var totalAggregator = default(IAggregateFunction);

                if (columnInfo.Column.ValueType.IsNumeric())
                {
                    totalAggregator = new SumFunction
                                      (
                        new DataBinding
                        (
                            mapping.Key
                        )
                                      );
                }

                var columnDefinition = new TableColumnDefinition
                                       (
                    mapping.Value,
                    new DataBinding
                    (
                        DataBindingType.QueryPath,
                        mapping.Key
                    ),
                    totalAggregator
                                       );

                tableDefinition.StaticColumns.Add
                (
                    columnDefinition
                );
            }

            return(tableDefinition);
        }
        public object Evaluate(SumFunction funcExp, object data, IEnumerable <object> parameters = null)
        {
            var paramValues = _GetParameterValues(funcExp, data, parameters);

            return(((IEnumerable <object>)paramValues[0]).Sum(i => (int)i));
        }
 public string ToSQL(SumFunction funcExp)
 {
     return(_FunctionToSQL(funcExp, "SUM"));
 }
        /// <summary>
        /// Computes the sum of one or more functions. Faster than adding many functions using the + operator overload.
        /// </summary>
        public static Function Sum(params Function[] functions)
        {
            Function result;
            if (!TrySumConstantFunction(functions, out result))
            {
                result = new SumFunction(functions);
            }

            return result;
        }