Example #1
0
        public object Calc(QMathType type, object val1, object val2)
        {
            if (val1 is string || val2 is string)
            {
                return("" + val1 + val2);
            }
            else
            {
                decimal obj1 = GetDecimal(val1);
                decimal obj2 = GetDecimal(val2);

                if (type == QMathType.Plus)
                {
                    return(obj1 + obj2);
                }
                else if (type == QMathType.Minus)
                {
                    return(obj1 - obj2);
                }
                else if (type == QMathType.Multiply)
                {
                    return(obj1 * obj2);
                }
                else // if (type == QExpressionMathType.Devide)
                {
                    return(obj2 == 0M ? 0M : obj1 / obj2);
                }
            }
        }
Example #2
0
        public override string Format(IDbCommand command)
        {
            StringBuilder rez = new StringBuilder();

            for (int i = 0; i < types.Count; i++)
            {
                QMathType type = types[i];
                string    mark = " + ";
                if (type == QMathType.Minus)
                {
                    mark = " - ";
                }
                if (type == QMathType.Multiply)
                {
                    mark = " * ";
                }
                if (type == QMathType.Devide)
                {
                    mark = " / ";
                }
                if (i == 0)
                {
                    rez.Append(Items[i].Format(command));
                }
                rez.AppendFormat("{0}{1}", mark, Items[i + 1].Format(command));
            }
            return(base.Format(command));
        }
Example #3
0
        public override object GetValue(DBItem row)
        {
            object value = null;

            for (int i = 0; i < types.Count; i++)
            {
                QMathType type = types[i];
                object    val1 = (i == 0) ? items[i].GetValue(row) : value;
                object    val2 = items[i + 1].GetValue(row);
                value = Calc(type, val1, val2);
            }
            return(value);
        }