Esempio n. 1
0
        protected override bool Compare(decimal x, decimal y)
        {
            var caster = new NumericCaster();
            var z      = caster.Execute(secondOperand);

            return(x % z == y);
        }
Esempio n. 2
0
        protected internal object FormatValue(ColumnType columnType, object value)
        {
            object v = null;

            if (columnType == ColumnType.Numeric)
            {
                v = new NumericCaster().Execute(value);
            }
            else if (columnType == ColumnType.DateTime)
            {
                v = new DateTimeCaster().Execute(value);
            }
            else if (columnType == ColumnType.Boolean)
            {
                v = new ThreeStateBooleanCaster().Execute(value);
            }
            else
            {
                if (value is IConvertible)
                {
                    v = ((IConvertible)value).ToString(CultureInfo.InvariantCulture);
                }
                else
                {
                    v = value.ToString();
                }
            }
            return(v);
        }
Esempio n. 3
0
        protected override bool Apply(object x)
        {
            var caster = new NumericCaster();
            var numX   = caster.Execute(x);

            return(numX % 1 == 0);
        }
Esempio n. 4
0
        public NumericToRound(string digits)
        {
            var caster = new NumericCaster();
            var d      = caster.Execute(digits);

            Digits = Math.Truncate(d) == d?Convert.ToInt32(Math.Truncate(d)) : throw new ArgumentException();
        }
Esempio n. 5
0
        public NumericToClip(string min, string max)
        {
            var caster = new NumericCaster();

            Min = caster.Execute(min);
            Max = caster.Execute(max);
        }
Esempio n. 6
0
        protected override bool ApplyWithReference(object reference, object x)
        {
            var caster = new NumericCaster();
            var numX   = caster.Execute(x);
            var numY   = caster.Execute(reference);

            return(Compare(numX, numY));
        }
Esempio n. 7
0
        protected override bool Apply(object x)
        {
            var builder = new NumericIntervalBuilder(Reference);

            builder.Build();
            var interval = builder.GetInterval();

            var caster = new NumericCaster();
            var numX   = caster.Execute(x);

            return(interval.Contains(numX));
        }
Esempio n. 8
0
        private object EvaluateUncasted(object value)
        {
            if (value as string == "(null)")
            {
                EvaluateNull();
            }

            var caster  = new NumericCaster();
            var numeric = caster.Execute(value);

            return(EvaluateNumeric(numeric));
        }
Esempio n. 9
0
 public object Evaluate(object value)
 {
     if (value == null || DBNull.Value.Equals(value) || value as string == "(empty)" || value as string == "(null)" || value is string && string.IsNullOrEmpty(value as string))
     {
         return(null);
     }
     else
     {
         var caster  = new NumericCaster();
         var numeric = caster.Execute(value);
         return(Truncate(numeric));
     }
 }
Esempio n. 10
0
        protected override bool ApplyWithReference(object reference, object x)
        {
            var builder = new NumericIntervalBuilder(reference);

            builder.Build();
            if (!builder.IsValid())
            {
                throw builder.GetException();
            }
            var interval = builder.GetInterval();

            var caster = new NumericCaster();
            var numX   = caster.Execute(x);

            return(interval.Contains(numX));
        }
Esempio n. 11
0
        private Decimal?CastToNumeric(object obj)
        {
            if (obj == null)
            {
                return(null);
            }

            var caster = new NumericCaster();

            if (caster.IsValid(obj))
            {
                return(caster.Execute(obj));
            }

            throw new ArgumentException();
        }
Esempio n. 12
0
        protected void CheckSettingsFirstRowCell(ColumnRole columnRole, ColumnType columnType, DataColumn dataColumn, object value, string[] messages)
        {
            var columnName = dataColumn.ColumnName;

            if (!DBNull.Value.Equals(value))
            {
                if (columnRole != ColumnRole.Ignore)
                {
                    if (columnType == ColumnType.Numeric && IsNumericField(dataColumn))
                    {
                        return;
                    }

                    var numericCaster = new NumericCaster();
                    if (columnType == ColumnType.Numeric && !(numericCaster.IsValid(value) || BaseComparer.IsValidInterval(value)))
                    {
                        var exception = string.Format(messages[0]
                                                      , columnName, value.ToString());

                        if (numericCaster.IsValid(value.ToString().Replace(",", ".")))
                        {
                            exception += messages[1];
                        }

                        throw new EquivalerException(exception);
                    }

                    if (columnType == ColumnType.DateTime && IsDateTimeField(dataColumn))
                    {
                        return;
                    }

                    if (columnType == ColumnType.DateTime && !BaseComparer.IsValidDateTime(value.ToString()))
                    {
                        throw new EquivalerException(
                                  string.Format(messages[2]
                                                , columnName, value.ToString()));
                    }
                }
            }
        }