Exemple #1
0
        /// <summary>
        /// 递归解析组,即将Searcher对象中的条件,按照他们的组别进行里外层的组划分,好为条件添加括号来判定他们的执行顺序
        /// </summary>
        /// <param name="searcher">需要解析的查询对象</param>
        /// <param name="mainGroup">用于返回排好层级的条件组,并填充好各级的条件对象</param>
        /// <param name="sortColumnList">用于返回所有需要排序的字段</param>
        protected void ParseGroup(Searcher searcher, ConditionGroup mainGroup, List <SearchColumn> sortColumnList)
        {
            if (searcher == null)
            {
                return;
            }

            IList <SearchColumn>         conditionColumnList  = searcher.ConditionColumnList;
            IList <Searcher>             relationSearcherList = searcher.RelationSearcherList;
            IEnumerable <ConditionGroup> mainSubGroupList     = mainGroup.SubGroup;
            IList <Condition>            mainConditionList    = mainGroup.ConditionCollection;
            ConditionGroup    rootGroup     = null;
            IList <Condition> conditionList = null;

            foreach (SearchColumn column in conditionColumnList)
            {
                if (column.SortOrder != SortOrder.None)
                {
                    sortColumnList.Add(column);
                }

                if (column.ConditionCollection.Count == 0)
                {
                    continue;
                }

                conditionList = column.ConditionCollection;

                foreach (Condition condition in conditionList)
                {
                    if (condition.Group == null)
                    {
                        mainConditionList.Add(condition);
                        continue;
                    }

                    rootGroup = this.GetRootGroup(condition.Group);

                    if (!mainGroup.GroupId.Equals(rootGroup.GroupId) && !mainSubGroupList.Contains(rootGroup))
                    {
                        mainGroup.AddSubGroup(rootGroup);
                    }
                }
            }

            if (rootGroup == null)
            {
                rootGroup = mainGroup;
            }

            foreach (Searcher relationSearcher in relationSearcherList)
            {
                this.ParseGroup(relationSearcher, rootGroup, sortColumnList);
            }
        }
Exemple #2
0
        private static ConditionGroup AddCondition(ConditionRelation relation, ICondition condition1, ICondition condition2, params ICondition[] conditions)
        {
            ConditionGroup    newGroup      = new ConditionGroup();
            List <ICondition> conditionList = new List <ICondition>();

            conditionList.Add(condition1);
            conditionList.Add(condition2);

            if (conditions != null)
            {
                conditionList.AddRange(conditions);
            }

            Condition      paramCondition = null;
            ConditionGroup conditionGroup = null;
            int            groupIndex     = 1;
            int            conditionIndex = 1;

            foreach (ICondition con in conditionList)
            {
                if (con is ConditionGroup)
                {
                    conditionGroup               = (ConditionGroup)con;
                    conditionGroup.GroupIndex    = groupIndex;
                    conditionGroup.GroupRelation = relation;
                    newGroup.AddSubGroup(conditionGroup);
                    groupIndex++;
                }
                else if (con is Condition)
                {
                    paramCondition          = (Condition)con;
                    paramCondition.Index    = conditionIndex;
                    paramCondition.Group    = newGroup;
                    paramCondition.Relation = relation;
                    conditionIndex++;
                }
            }

            return(newGroup);
        }
Exemple #3
0
        /// <summary>
        /// 递归解析组,即将Searcher对象中的条件,按照他们的组别进行里外层的组划分,好为条件添加括号来判定他们的执行顺序
        /// </summary>
        /// <param name="searcher">需要解析的查询对象</param>
        /// <param name="mainGroup">用于返回排好层级的条件组,并填充好各级的条件对象</param>
        /// <param name="sortColumnList">用于返回所有需要排序的字段</param>
        protected void ParseGroup(Searcher searcher, ConditionGroup mainGroup, List<SearchColumn> sortColumnList)
        {
            if (searcher == null)
            {
                return;
            }

            IList<SearchColumn> conditionColumnList = searcher.ConditionColumnList;
            IList<Searcher> relationSearcherList = searcher.RelationSearcherList;
            IEnumerable<ConditionGroup> mainSubGroupList = mainGroup.SubGroup;
            IList<Condition> mainConditionList = mainGroup.ConditionCollection;
            ConditionGroup rootGroup = null;
            IList<Condition> conditionList = null;

            foreach (SearchColumn column in conditionColumnList)
            {
                if (column.SortOrder != SortOrder.None)
                {
                    sortColumnList.Add(column);
                }

                if (column.ConditionCollection.Count == 0)
                {
                    continue;
                }

                conditionList = column.ConditionCollection;

                foreach (Condition condition in conditionList)
                {
                    if (condition.Group == null)
                    {
                        mainConditionList.Add(condition);
                        continue;
                    }

                    rootGroup = this.GetRootGroup(condition.Group);

                    if (!mainGroup.GroupId.Equals(rootGroup.GroupId) && !mainSubGroupList.Contains(rootGroup))
                    {
                        mainGroup.AddSubGroup(rootGroup);
                    }
                }
            }

            if(rootGroup == null)
            {
                rootGroup = mainGroup;
            }

            foreach (Searcher relationSearcher in relationSearcherList)
            {
                this.ParseGroup(relationSearcher, rootGroup, sortColumnList);
            }
        }