public CriteriaOperatorCollection GetCollection(CriteriaOperator oper)
        {
            Type t    = oper.GetType();
            var  prop = t.GetProperty("Operands");

            if (prop != null)
            {
                return(prop.GetValue(oper, null) as CriteriaOperatorCollection);
            }
            return(new CriteriaOperatorCollection());
        }
示例#2
0
        private string CreateWhereClauseCriteriaOperator(CriteriaOperator oprator)
        {
            var whereClause = string.Empty;

            if (oprator.GetType() == typeof(FunctionOperator))
            {
                whereClause = CreateWhereClauseFunctionOperator((FunctionOperator)oprator);
            }
            else
            {
                whereClause = CreateWhereClauseBinaryOperator((BinaryOperator)oprator);
            }
            return(whereClause);
        }
示例#3
0
        private static object GetMetadata(CriteriaOperator @operator)
        {
            var type = @operator.GetType();
            var info = type.GetMember(@operator.ToString());

            if ((info != null) && (info.Length > 0))
            {
                var attrs = info[0].GetCustomAttributes(typeof(CriteriaOperatorMetadataAttribute), false);
                if ((attrs != null) && (attrs.Length > 0))
                {
                    return(attrs[0]);
                }
            }

            return(null);
        }
示例#4
0
        private string CreateWhereClauseComplexOperator(CriteriaOperator criteria)
        {
            var whereClause = string.Empty;

            if (criteria.GetType() == typeof(GroupOperator))
            {
                var operands = ((GroupOperator)criteria).Operands;

                var operatorType = ((GroupOperator)criteria).OperatorType;

                whereClause += CreateWhereClauseGroupOperator((GroupOperator)criteria, operands, operatorType);
            }

            else
            {
                whereClause += CreateWhereClauseCriteriaOperator(criteria);
            }
            return(whereClause);
        }
        private static Condition GetCondition(CriteriaOperator criter)
        {
            if (criter is null)
            {
                return(null);
            }
            switch (criter?.GetType().Name)
            {
            case nameof(BinaryOperator): return(Binary(criter as BinaryOperator));

            case nameof(FunctionOperator): return(Function(criter as FunctionOperator));

            case nameof(BetweenOperator): return(Between(criter as BetweenOperator));

            case nameof(UnaryOperator): return(Unary(criter as UnaryOperator));

            case nameof(InOperator): return(In(criter as InOperator));

            default:
                throw new FilterException(string.Format(Resource.UnsupportedOperatorError, criter?.GetType().Name, "condition"));
            }
        }
示例#6
0
        public static void SetFilter(this GridView gv, CriteriaOperator item)
        {
            var Criteria = gv.GetCriteria() == null ? new List<CriteriaOperator>() : gv.GetCriteria().ToList();
            gv.ClearColumnsFilter();

            if (Criteria.Count == 0)
                Criteria.Add(item);
            else
            {
                switch (item.GetType().Name)
                {
                    case "GroupOperator":
                        {
                            var grpi = item as GroupOperator;
                            var itms = grpi.Operands.ToArray();

                            var grps = Criteria.OfType<GroupOperator>()
                                .Where(g =>
                                    g.Operands.Count() == itms.Count() &&
                                    g.Operands.All(i => itms.Any(o => i.IsNamed(o)))
                                )
                                .ToArray();

                            Criteria.RemoveAll(o => grps.Contains(o));
                            Criteria.Add(item);
                        }
                        break;
                    case "InOperator":
                        {
                            var inoi = item as InOperator;
                            Criteria.RemoveAll(o => o.IsNamed(inoi.LeftOperand));
                            Criteria.Add(item);
                        }
                        break;
                    case "BinaryOperator":
                        {
                            var bini = item as BinaryOperator;
                            Criteria.RemoveAll(o => o.IsNamed(bini.LeftOperand));
                            Criteria.Add(item);
                        }
                        break;
                }
            }

            gv.ActiveFilterCriteria = new GroupOperator(Criteria.ToArray());
            gv.ApplyColumnsFilter();
            gv.MoveFirst();
        }
示例#7
0
        public static bool IsNamed(this CriteriaOperator co, CriteriaOperator LeftOperand)
        {
            string pn = null;

            switch (LeftOperand.GetType().Name)
            {
                case "OperandProperty":
                    pn = (LeftOperand as OperandProperty).PropertyName;
                    break;
                case "InOperator":
                    if ((co as InOperator).LeftOperand is OperandProperty)
                        pn = ((co as InOperator).LeftOperand as OperandProperty).PropertyName;
                    break;
                case "BinaryOperator":
                    if ((co as BinaryOperator).LeftOperand is OperandProperty)
                        pn = ((co as BinaryOperator).LeftOperand as OperandProperty).PropertyName;
                    break;
            }

            if (pn == null)
                return false;

            switch (co.GetType().Name)
            {
                case "InOperator":
                    if ((co as InOperator).LeftOperand is OperandProperty)
                        return ((co as InOperator).LeftOperand as OperandProperty).PropertyName == pn;
                    else return false;
                case "BinaryOperator":
                    if ((co as BinaryOperator).LeftOperand is OperandProperty)
                        return ((co as BinaryOperator).LeftOperand as OperandProperty).PropertyName == pn;
                    else return false;
                default:
                    return false;
            }
        }