Пример #1
0
        protected virtual string CreateInConditionString(IField field, RelationalOperators op, IValue[] values)
        {
            var valueStrings = new string[values.Length];

            for (var i = 0; i < values.Length; i++)
            {
                valueStrings[i] = ValueConverter.ConvertValueToString(values[i]);
            }

            return(string.Concat(ConditionStringItemPrefix, NameConverter.GenerateFieldString(field), OperatorString(op), "(", string.Join(",", valueStrings), ")", ConditionStringItemPostfix));
        }
Пример #2
0
        protected virtual string CreateConditionString(IField field, RelationalOperators op, object value)
        {
            if ((op & RelationalOperators.In) == RelationalOperators.In)
            {
                return(CreateInConditionString(field, op, value));
            }

            if ((value is IBetweenValue) && (op & RelationalOperators.Between) == RelationalOperators.Between)
            {
                return(CreateBetweenConditionString(field, op, (IBetweenValue)value));
            }

            var valueArray = value as IValueArray;

            if (valueArray != null)
            {
                return(CreateValueArrayConditionString(field, op, valueArray));
            }

            if (value is IEnumerable && !(value is string))
            {
                return(CreateEnumerableConditionString(field, op, value as IEnumerable));
            }

            var fieldName = NameConverter.GenerateFieldString(field);

            var f = value as IField;

            if (f != null)
            {
                return(CreateFieldConditionString(fieldName, op, f));
            }
            var v = value as IValue;

            if (v != null)
            {
                return(CreateFieldConditionString(fieldName, op, v));
            }
            var s = value as string;

            if (s != null)
            {
                return(CreateStringConditionString(fieldName, op, s));
            }
            if (value is DateTime)
            {
                return(CreateDateTimeConditionString(fieldName, op, (DateTime)value));
            }

            double number;

            return(Double.TryParse(value.ToString(), out number) ? CreateNumericConditionString(fieldName, op, value) : string.Concat(ConditionStringItemPrefix, NameConverter.GenerateFieldString(field), OperatorString(op), value.ToString(), ConditionStringItemPostfix));
        }
Пример #3
0
        protected virtual string CreateBetweenConditionString(IField field, RelationalOperators op, IBetweenValue value)
        {
            if (op == RelationalOperators.Between)
            {
                var fieldName = NameConverter.GenerateFieldString(field);
                return(CreateBetweenConditionString(fieldName, value));
            }

            op = (op ^ RelationalOperators.Between);

            if (op == RelationalOperators.AddWildcardSuffix)
            {
                string condString = string.Empty;

                if (!(value.FirstValue is INullValue))
                {
                    condString = CreateConditionString(field, RelationalOperators.Equal | RelationalOperators.GreaterThan, value.FirstValue);
                }

                if (value.SecondValue is INullValue)
                {
                    return(condString);
                }

                if (field.DataType == FieldDataType.DateTime)
                {
                    DateTime d;
                    if (value.SecondValue is IDateTimeValue)
                    {
                        d = ((IDateTimeValue)value.SecondValue).Value;
                    }
                    else
                    {
                        throw new InvalidCastException("IDateTimeValue required");
                    }

                    condString = string.Concat("(", condString, " And ", CreateConditionString(field, RelationalOperators.LessThan, d.Date.AddDays(1)), ")");
                    return(condString);
                }

                if (field.DataType == FieldDataType.Text)
                {
                    string s;
                    if (value.SecondValue is ITextValue)
                    {
                        s = ((ITextValue)value.SecondValue).Value;
                    }
                    else
                    {
                        throw new InvalidCastException("ITextValue required");
                    }

                    if (!string.IsNullOrEmpty(s))
                    {
                        s = s.Substring(0, s.Length - 1) + (char)(s[s.Length - 1] + 1);
                    }

                    condString = string.Concat("(", condString, " And ", CreateConditionString(field, RelationalOperators.LessThan, s), ")");
                    return(condString);
                }
            }

            throw new NotSupportedRelationalOperatorException(op);
        }
Пример #4
0
 protected virtual string CreateFieldConditionString(string fieldName, RelationalOperators op, IField value)
 {
     return(string.Concat(ConditionStringItemPrefix, fieldName, OperatorString(op), NameConverter.GenerateFieldString(value), ConditionStringItemPostfix));
 }
Пример #5
0
 protected virtual string AggregateFieldString(IEnumerable <IField> fields)
 {
     return(fields.Aggregate("", (current, s) => current + (FieldConcatString + NameConverter.GenerateFieldString(s))).Substring(FieldConcatString.Length));
 }