public void Build(Expression expression, AverageFunction ave) { var resolve = new ExpressionResolve(); _builder.SelectField = new List <string>(); resolve.VisitMember(expression).ForEach(x => { var field = string.Empty; switch (ave) { case AverageFunction.MAX: field = " MAX({0})"; break; case AverageFunction.MIN: field = " MIN({0})"; break; case AverageFunction.SUM: field = " SUM({0})"; break; case AverageFunction.AVG: field = " AVG({0})"; break; } _builder.SelectField.Add(string.Format(field, _builder.Adapter.Field(_builder.Table, _builder.TableAliasName, x.FieldName, x.SelectFiledAliasName))); }); }
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); } }