Пример #1
0
        public string GetAutomaticMatchingFilterConstraint(out object[] arrFilter, ref Expression <Func <TModel, bool> > expFilterConstraint)
        {
            string resultStr = " 1=1 ";

            arrFilter = null;
            if (this.Parameters.Where != null)
            {
                IList <object> source    = new List <object>();
                int            num       = 0;
                string         filterStr = string.Empty;
                foreach (SearchConstraint searchVo in this.Parameters.Where.Groups)
                {
                    bool flg = false;
                    Expression <Func <TModel, bool> > exp = null;
                    if (searchVo != null && searchVo.Rules.Count > 0)
                    {
                        foreach (ConstraintRule ruleVo in searchVo.Rules)
                        {
                            if (this.getCustomFilterExpression != null)
                            {
                                Expression <Func <TModel, bool> > expVo = this.getCustomFilterExpression(ruleVo);
                                if (expVo != null)
                                {
                                    flg = true;
                                    if (exp == null)
                                    {
                                        exp = expVo;
                                    }
                                    else
                                    {
                                        if (searchVo.GroupOperator.Equals("and", StringComparison.OrdinalIgnoreCase))
                                        {
                                            exp.And(expVo);
                                        }
                                        else
                                        {
                                            exp.Or(expVo);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (flg)
                    {
                        if (expFilterConstraint == null)
                        {
                            expFilterConstraint = exp;
                        }
                        else
                        {
                            if (this.Parameters.Where.GroupOperator.Equals("and", System.StringComparison.OrdinalIgnoreCase))
                            {
                                expFilterConstraint.And(exp);
                            }
                            else
                            {
                                expFilterConstraint.Or(exp);
                            }
                        }
                    }
                    else
                    {
                        if (searchVo != null && searchVo.Rules.Count > 0)
                        {
                            filterStr = filterStr + " AND " + SearchConstraintBinder.GetConstraintByAutomaticFilterConstraint <TModel>(searchVo, ref source, ref num);
                        }
                    }
                }
                resultStr += filterStr;
                arrFilter  = source.ToArray <object>();
            }
            return(resultStr);
        }
Пример #2
0
        public string GetComplexFilterConstraint(out object[] values, ref Expression <Func <TModel, bool> > expFilterConstraint)
        {
            string text = " 1=1 ";

            values = null;
            if (this.provider is IAutomaticMatchingFilterConstraint <TModel> )
            {
                if (this.Parameters.Where != null)
                {
                    System.Collections.Generic.IList <object> source = new System.Collections.Generic.List <object>();
                    int    num   = 0;
                    string text2 = string.Empty;
                    foreach (SearchConstraint current in this.Parameters.Where.Groups)
                    {
                        bool flag = false;
                        Expression <Func <TModel, bool> > expression = null;
                        if (current != null && current.Rules.Count > 0)
                        {
                            foreach (ConstraintRule current2 in current.Rules)
                            {
                                IAutomaticMatchingFilterConstraint <TModel> automaticMatchingFilterConstraint = this.provider as IAutomaticMatchingFilterConstraint <TModel>;
                                Expression <Func <TModel, bool> >           expression2 = automaticMatchingFilterConstraint.CustomFilterExpression(current2);
                                if (expression2 != null)
                                {
                                    flag = true;
                                    if (expression == null)
                                    {
                                        expression = expression2;
                                    }
                                    else
                                    {
                                        if (current.GroupOperator.Equals("and", System.StringComparison.OrdinalIgnoreCase))
                                        {
                                            expression.And(expression2);
                                        }
                                        else
                                        {
                                            expression.Or(expression2);
                                        }
                                    }
                                }
                            }
                        }
                        if (flag)
                        {
                            if (expFilterConstraint == null)
                            {
                                expFilterConstraint = expression;
                            }
                            else
                            {
                                if (this.Parameters.Where.GroupOperator.Equals("and", System.StringComparison.OrdinalIgnoreCase))
                                {
                                    expFilterConstraint.And(expression);
                                }
                                else
                                {
                                    expFilterConstraint.Or(expression);
                                }
                            }
                        }
                        else
                        {
                            if (current != null && current.Rules.Count > 0)
                            {
                                text2 = text2 + " AND " + SearchConstraintBinder.GetConstraintByAutomaticFilterConstraint <TModel>(current, ref source, ref num);
                            }
                        }
                    }
                    text  += text2;
                    values = source.ToArray <object>();
                }
            }
            else
            {
                if (this.provider is ICustomFilterConstraint <TModel> )
                {
                    ICustomFilterConstraint <TModel> service = this.provider as ICustomFilterConstraint <TModel>;
                    expFilterConstraint = SearchConstraintBinder.GetExpression <TModel>(this.Parameters.Where, service);
                }
                else
                {
                    if (this.Parameters.Where != null)
                    {
                        string text2 = SearchConstraintBinder.GetPredicate <TModel>(this.Parameters.Where, out values);
                        if (!string.IsNullOrEmpty(text2) && text2 != "()")
                        {
                            text = text + " AND " + text2;
                        }
                    }
                }
            }
            return(text);
        }