Ejemplo n.º 1
0
 private void FilterFieldValues(PivotGridField field, int[] filterValues,
                                FieldFilterType filterType)
 {
     pivotGridControl1.BeginUpdate();
     try
     {
         field.FilterValues.Clear();
         foreach (object filterValue in filterValues)
         {
             field.FilterValues.Add(filterValue);
         }
     }
     finally
     {
         field.FilterValues.FilterType = filterType;
         pivotGridControl1.EndUpdate();
     }
 }
Ejemplo n.º 2
0
        private FieldFilterType GetFilterType(string text)
        {
            FieldFilterType result = FieldFilterType.ReadOnly;

            switch (text)
            {
            case "All": result = FieldFilterType.All; break;

            case "DateTime": result = FieldFilterType.DateTime; break;

            case "ReadOnly": result = FieldFilterType.ReadOnly; break;

            case "AllowDBNull": result = FieldFilterType.AllowDBNull; break;

            case "Insert": result = FieldFilterType.Insert; break;

            case "Update": result = FieldFilterType.Update; break;

            case "Nullable": result = FieldFilterType.Nullable; break;

            case "!DateTime": result = FieldFilterType.NotDateTime; break;

            case "!ReadOnly": result = FieldFilterType.NotReadOnly; break;

            case "!AllowDBNull": result = FieldFilterType.NotAllowDBNull; break;

            case "!Insert": result = FieldFilterType.NotInsert; break;

            case "!Update": result = FieldFilterType.NotUpdate; break;

            case "!Nullable": result = FieldFilterType.NotNullable; break;

            default: result = FieldFilterType.ReadOnly; break;
            }
            return(result);
        }
Ejemplo n.º 3
0
        private IReadOnlyCollection <ResourceFieldAttribute> Getter <TResource>(Expression <Func <TResource, dynamic> > selector = null, FieldFilterType type = FieldFilterType.None) where TResource : class, IIdentifiable
        {
            IReadOnlyCollection <ResourceFieldAttribute> available;

            if (type == FieldFilterType.Attribute)
            {
                available = GetResourceContext(typeof(TResource)).Attributes;
            }
            else if (type == FieldFilterType.Relationship)
            {
                available = GetResourceContext(typeof(TResource)).Relationships;
            }
            else
            {
                available = GetResourceContext(typeof(TResource)).Fields;
            }

            if (selector == null)
            {
                return(available);
            }

            var targeted = new List <ResourceFieldAttribute>();

            var selectorBody = RemoveConvert(selector.Body);

            if (selectorBody is MemberExpression memberExpression)
            {
                // model => model.Field1
                try
                {
                    targeted.Add(available.Single(f => f.Property.Name == memberExpression.Member.Name));
                    return(targeted);
                }
                catch (InvalidOperationException)
                {
                    ThrowNotExposedError(memberExpression.Member.Name, type);
                }
            }

            if (selectorBody is NewExpression newExpression)
            {
                // model => new { model.Field1, model.Field2 }
                string memberName = null;
                try
                {
                    if (newExpression.Members == null)
                    {
                        return(targeted);
                    }

                    foreach (var member in newExpression.Members)
                    {
                        memberName = member.Name;
                        targeted.Add(available.Single(f => f.Property.Name == memberName));
                    }
                    return(targeted);
                }
                catch (InvalidOperationException)
                {
                    ThrowNotExposedError(memberName, type);
                }
            }

            throw new ArgumentException(
                      $"The expression '{selector}' should select a single property or select multiple properties into an anonymous type. " +
                      "For example: 'article => article.Title' or 'article => new { article.Title, article.PageCount }'.");
        }
Ejemplo n.º 4
0
        private IEnumerable <IResourceField> Getter <T>(Expression <Func <T, dynamic> > selector = null, FieldFilterType type = FieldFilterType.None) where T : IIdentifiable
        {
            IEnumerable <IResourceField> available;

            if (type == FieldFilterType.Attribute)
            {
                available = GetResourceContext(typeof(T)).Attributes;
            }
            else if (type == FieldFilterType.Relationship)
            {
                available = GetResourceContext(typeof(T)).Relationships;
            }
            else
            {
                available = GetResourceContext(typeof(T)).Fields;
            }

            if (selector == null)
            {
                return(available);
            }

            var targeted = new List <IResourceField>();

            if (selector.Body is MemberExpression memberExpression)
            {   // model => model.Field1
                try
                {
                    targeted.Add(available.Single(f => f.ExposedInternalMemberName == memberExpression.Member.Name));
                    return(targeted);
                }
                catch (InvalidOperationException)
                {
                    ThrowNotExposedError(memberExpression.Member.Name, type);
                }
            }


            if (selector.Body is NewExpression newExpression)
            {   // model => new { model.Field1, model.Field2 }
                string memberName = null;
                try
                {
                    if (newExpression.Members == null)
                    {
                        return(targeted);
                    }

                    foreach (var member in newExpression.Members)
                    {
                        memberName = member.Name;
                        targeted.Add(available.Single(f => f.ExposedInternalMemberName == memberName));
                    }
                    return(targeted);
                }
                catch (InvalidOperationException)
                {
                    ThrowNotExposedError(memberName, type);
                }
            }

            throw new ArgumentException($"The expression returned by '{selector}' for '{GetType()}' is of type {selector.Body.GetType()}"
                                        + " and cannot be used to select resource attributes. The type must be a NewExpression.Example: article => new { article.Author };");
        }
Ejemplo n.º 5
0
 private void ThrowNotExposedError(string memberName, FieldFilterType type)
 {
     throw new ArgumentException($"{memberName} is not an json:api exposed {type:g}.");
 }