Beispiel #1
0
        /// <summary>
        /// The ExecuteQuery.
        /// </summary>
        /// <param name="figures">The figures<see cref="IFigures"/>.</param>
        /// <param name="filter">The filter<see cref="FigureFilter"/>.</param>
        /// <param name="sort">The sort<see cref="FigureSort"/>.</param>
        /// <param name="stage">The stage<see cref="int"/>.</param>
        /// <param name="appendfigures">The appendfigures<see cref="IFigure[]"/>.</param>
        /// <returns>The <see cref="IFigures"/>.</returns>
        private static IFigures ExecuteQuery(IFigures figures, FigureFilter filter, FigureSort sort, int stage = 1, IFigure[] appendfigures = null)
        {
            IFigures table    = figures;
            IFigures _figures = null;
            IFigures view     = figures.View;

            if (appendfigures == null)
            {
                if (stage > 1)
                {
                    _figures = view;
                }
                else if (stage < 0)
                {
                    _figures = figures;
                    view     = figures.View;
                    view.Flush();
                }
                else
                {
                    _figures = table;
                }
            }

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

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

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

                    if (appendfigures != null)
                    {
                        view.Add(ioqf.ToArray());
                    }
                    else
                    {
                        view.Flush();
                        view.Add(ioqf.ToArray());
                    }
                }
                else
                {
                    if (appendfigures != null)
                    {
                        view.Add(appendfigures.Where(filter.Evaluator).ToArray());
                    }
                    else
                    {
                        view.Flush();
                        view.Add(figures.Where(filter.Evaluator).ToArray());
                    }
                }
            }
            else if (sort != null && sort.Terms.Count > 0)
            {
                view.QueryFormula     = null;
                view.Filter.Evaluator = null;

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

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

                    isFirst = false;
                }

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

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

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