Esempio n. 1
0
        public static IFigures Query(this IFigures figures, out bool sorted, out bool filtered, int stage = 1)
        {
            FigureFilter Filter = figures.Filter;
            FigureSort   Sort   = figures.Sort;

            filtered = (Filter.Terms.Count > 0) ? true : false;
            sorted   = (Sort.Terms.Count > 0) ? true : false;
            return(ResolveQuery(figures, Filter, Sort, stage));
        }
Esempio n. 2
0
        private static IFigures ExecuteQuery(IFigures _figures, FigureFilter filter, FigureSort sort, int stage = 1, IFigure[] appendfigures = null)
        {
            IFigures trell   = _figures;
            IFigures figures = null;
            IFigures view    = _figures.Exposition;

            if (appendfigures == null)
            {
                if (stage > 1)
                {
                    figures = view;
                }
                else if (stage < 0)
                {
                    figures = _figures;
                    view    = _figures.Exposition = (IFigures)_figures.FiguresType.New();
                }
                else
                {
                    figures = trell;
                }
            }

            if (filter != null && filter.Terms.Count > 0)
            {
                filter.Evaluator = filter.GetExpression(stage).Compile();
                view.Query       = filter.Evaluator;

                if (sort != null && sort.Terms.Count > 0)
                {
                    bool isFirst = true;
                    IEnumerable <IFigure>       tsrt = null;
                    IOrderedQueryable <IFigure> ttby = null;
                    if (appendfigures != null)
                    {
                        tsrt = appendfigures.AsEnumerable().Where(filter.Evaluator);
                    }
                    else
                    {
                        tsrt = figures.AsEnumerable().Where(filter.Evaluator);
                    }

                    foreach (SortTerm fcs in sort.Terms)
                    {
                        if (isFirst)
                        {
                            ttby = tsrt.AsQueryable().OrderBy(o => o[fcs.RubricName], fcs.Direction, Comparer <object> .Default);
                        }
                        else
                        {
                            ttby = ttby.ThenBy(o => o[fcs.RubricName], fcs.Direction, Comparer <object> .Default);
                        }
                        isFirst = false;
                    }

                    if (appendfigures != null)
                    {
                        view.Add(ttby.ToArray());
                    }
                    else
                    {
                        view.Clear();
                        view.Add(ttby.ToArray());
                    }
                }
                else
                {
                    if (appendfigures != null)
                    {
                        view.Add(appendfigures.AsQueryable().Where(filter.Evaluator).ToArray());
                    }
                    else
                    {
                        view.Clear();
                        view.Add(figures.AsEnumerable().AsQueryable().Where(filter.Evaluator).ToArray());
                    }
                }
            }
            else if (sort != null && sort.Terms.Count > 0)
            {
                view.Query            = null;
                view.Filter.Evaluator = null;

                bool isFirst = true;
                IOrderedQueryable <IFigure> ttby = null;

                foreach (SortTerm fcs in sort.Terms)
                {
                    if (isFirst)
                    {
                        if (appendfigures != null)
                        {
                            ttby = appendfigures.AsQueryable().OrderBy(o => o[fcs.RubricName], fcs.Direction, Comparer <object> .Default);
                        }
                        else
                        {
                            ttby = figures.AsEnumerable().AsQueryable().OrderBy(o => o[fcs.RubricName], fcs.Direction, Comparer <object> .Default);
                        }
                    }
                    else
                    {
                        ttby = ttby.ThenBy(o => o[fcs.RubricName], fcs.Direction, Comparer <object> .Default);
                    }

                    isFirst = false;
                }

                if (appendfigures != null)
                {
                    view.Add(ttby);
                }
                else
                {
                    view.Add(ttby);
                }
            }
            else
            {
                if (stage < 2)
                {
                    view.Query            = null;
                    view.Filter.Evaluator = null;
                }

                if (appendfigures != null)
                {
                    view.Add(appendfigures);
                }
                else
                {
                    view.Add(figures);
                }
            }

            //  view.PagingDetails.ComputePageCount(view.Count);
            if (stage > 0)
            {
                trell.Exposition = view;
            }
            return(view);
        }