Esempio n. 1
0
        public ConstraintRule ShiftQueryRule(string fieldName)
        {
            ConstraintRule constraintRule = this.QuerySearch.Rules.Find((ConstraintRule x) => x.Field.Equals(fieldName, System.StringComparison.CurrentCultureIgnoreCase));
            ConstraintRule result;

            if (constraintRule != null)
            {
                this.QuerySearch.Rules.Remove(constraintRule);
                result = constraintRule;
            }
            else
            {
                result = null;
            }
            return(result);
        }
Esempio n. 2
0
        public ConstraintRule ShiftWhereRule(string fieldName)
        {
            List <SearchConstraint> groups = this.Where.Groups;
            ConstraintRule          result;

            foreach (SearchConstraint current in groups)
            {
                ConstraintRule constraintRule = current.Rules.Find((ConstraintRule c) => c.Field.Equals(fieldName));
                if (constraintRule != null)
                {
                    this.Where.Groups.Remove(current);
                    result = constraintRule;
                    return(result);
                }
            }
            result = null;
            return(result);
        }
        public static string GetConstraintByAutomaticFilterConstraint <T>(SearchConstraint group, ref IList <object> values, ref int parameterIndex)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("(");
            List <ConstraintRule> rules = group.Rules;

            if (rules != null && rules.Count > 0)
            {
                System.Reflection.PropertyInfo[] properties = typeof(T).GetProperties();
                int num = 1;
                using (List <ConstraintRule> .Enumerator enumerator = rules.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ConstraintRule rule = enumerator.Current;
                        if (!string.IsNullOrEmpty(rule.Field))
                        {
                            System.Reflection.PropertyInfo propertyInfo = (
                                from p in properties
                                where p.Name.ToLower() == rule.Field.ToLower()
                                select p).FirstOrDefault();
                            if (!(propertyInfo == null))
                            {
                                Type propertyType = propertyInfo.PropertyType;
                                values.Add(rule.GetValue(propertyType));
                                stringBuilder.Append(rule.GetPredicate(parameterIndex));
                                if (num < rules.Count)
                                {
                                    stringBuilder.Append(group.GroupOperator.Equals("and", StringComparison.OrdinalIgnoreCase) ? " AND " : " OR ");
                                }
                                parameterIndex++;
                                num++;
                            }
                        }
                    }
                }
            }
            stringBuilder.Append(")");
            return(stringBuilder.ToString());
        }
Esempio n. 4
0
 public string GetPredicate(int parameterIndex)
 {
     return(string.Format(ConstraintRule.GetOperatorFormatExpression(this.Operator), this.Field, ConstraintRule.GetLinqOperator(this.Operator), parameterIndex));
 }
        private static string GetPredicate <T>(SearchConstraint constraint, IList <object> values, ref int parameterIndex)
        {
            StringBuilder strBuilder = new StringBuilder();
            bool          flg        = !string.IsNullOrEmpty(constraint.GroupOperator) && ((constraint.Groups != null) ? constraint.Groups.Count : 0) + ((constraint.Rules != null) ? constraint.Rules.Count : 0) > 1;

            if (flg)
            {
                strBuilder.Append("(");
            }
            if (constraint.Rules != null && constraint.Rules.Count > 0)
            {
                System.Reflection.PropertyInfo[] properties = typeof(T).GetProperties();
                int num = 1;
                using (List <ConstraintRule> .Enumerator enumerator = constraint.Rules.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ConstraintRule rule = enumerator.Current;
                        if (!string.IsNullOrEmpty(rule.Field))
                        {
                            System.Reflection.PropertyInfo propertyInfo = (
                                from p in properties
                                where p.Name.ToLower() == rule.Field.ToLower()
                                select p).FirstOrDefault();
                            if (!(propertyInfo == null))
                            {
                                Type propertyType = propertyInfo.PropertyType;
                                values.Add((propertyType == typeof(string)) ? rule.GetValue(propertyType).ToString().ToLower() : rule.GetValue(propertyType));
                                strBuilder.Append(rule.GetPredicate(parameterIndex));
                                if (num < constraint.Rules.Count && !string.IsNullOrEmpty(constraint.Rules[num].Field))
                                {
                                    strBuilder.Append(" " + constraint.GroupOperator + " ");
                                }
                                parameterIndex++;
                                num++;
                            }
                        }
                    }
                }
            }
            if (constraint.Groups != null && constraint.Groups.Count > 0)
            {
                int num2 = 0;
                foreach (SearchConstraint current in constraint.Groups)
                {
                    num2++;
                    if (current != null)
                    {
                        if (current.Rules != null && current.Rules.Count > 0)
                        {
                            if (num2 > 1)
                            {
                                strBuilder.Append(" " + constraint.GroupOperator + " ");
                            }
                            strBuilder.Append(GetPredicate <T>(current, values, ref parameterIndex));
                        }
                    }
                }
            }
            if (flg)
            {
                strBuilder.Append(")");
            }
            return(strBuilder.ToString());
        }