예제 #1
0
 private static Result doEval(object dat, evalBase eval)
 {
     if (eval is evalCALCType)
     {
         return(doCalc(dat, (evalCALCType)eval));
     }
     else if (eval is evalArrayType)
     {
         return(doValue(dat, (evalArrayType)eval));
     }
     else if (eval is evalDateType)
     {
         return(new Result(((evalDateType)eval).val));
     }
     else if (eval is evalNumberType)
     {
         return(new Result(((evalNumberType)eval).val));
     }
     else if (eval is evalStringType)
     {
         return(new Result(((evalStringType)eval).val));
     }
     else if (eval is evalBoolType)
     {
         return(new Result(((evalBoolType)eval).val));
     }
     else if (eval is evalIFType)
     {
         return(doIF(dat, (evalIFType)eval));
     }
     else if (eval is evalValueType)
     {
         return(doValue(dat, (evalValueType)eval));
     }
     else if (eval is evalSFormatType)
     {
         string sval = doFormat(dat, ((evalSFormatType)eval).val);
         return(new Result(sval));
     }
     else
     {
         Result result = new Result(null);
         result.Error = "#Unknown Operation";
         return(result);
     }
 }
예제 #2
0
        private static bool compareLIKE(object dat, evalBase val1, evalBase val2)
        {
            string a = "";
            string b = "";

            try
            {
                a = doEval(dat, val1).Value.ToString();
                b = doEval(dat, val2).Value.ToString();
                Regex rx = new Regex(b);

                return(rx.IsMatch(a));
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Ошибка - при сравнении {0} и {1} в функции compareLIKE", a, b), ex);
            }
        }
예제 #3
0
        private static int compareVals(object dat, evalBase val1, evalBase val2)
        {
            object a = doEval(dat, val1).Value;
            object b = doEval(dat, val2).Value;

            if (a is DateTime && b is DateTime)
            {
                return(DateTime.Compare((DateTime)a, (DateTime)b));
            }
            else if (
                (a is int || a is decimal || a is double || a is Single || a is float) &&
                (b is int || b is decimal || b is double || b is Single || b is float))
            {
                return(Decimal.Compare(Convert.ToDecimal(a), Convert.ToDecimal(b)));
            }
            else if (a is string && b is string)
            {
                return(string.Compare((string)a, (string)b, true));
            }
            throw new Exception(string.Format("Ошибка - при сравнении {0} и {1} в функции comparevals", a, b));
        }
예제 #4
0
        private static Result doCalc(object dat, evalCALCType eval)
        {
            Result   result = new Result(null);
            evalBase a      = eval.Items[0];
            evalBase b      = eval.Items[1];
            Result   r1     = doEval(dat, a);

            if (r1.HasError)
            {
                return(r1);
            }
            Result r2 = doEval(dat, b);

            if (r2.HasError)
            {
                return(r2);
            }
            switch (eval.oper)
            {
            case arOperEnum.add:
                if (r1.TypeValue == TypeEnum.String || r2.TypeValue == TypeEnum.String)
                {
                    result.Value = Convert.ToString(r1.Value) + Convert.ToString(r2.Value);
                }
                else if (r1.TypeValue == TypeEnum.Number && r2.TypeValue == TypeEnum.Number)
                {
                    result.Value = Convert.ToDecimal(r1.Value) + Convert.ToDecimal(r2.Value);
                }
                else if (r1.TypeValue == TypeEnum.Date && r2.TypeValue == TypeEnum.Number)
                {
                    DateTime dt   = Convert.ToDateTime(r1.Value);
                    double   days = Convert.ToDouble(r2.Value);
                    result.Value = dt.AddDays(days);
                }
                else
                {
                    result.Value = null;
                    result.Error = "#ADD:Bad Types";
                }
                break;

            case arOperEnum.sub:
                if (r1.TypeValue == TypeEnum.Number && r2.TypeValue == TypeEnum.Number)
                {
                    result.Value = Convert.ToDecimal(r1.Value) - Convert.ToDecimal(r2.Value);
                }
                else if (r1.TypeValue == TypeEnum.Date && r2.TypeValue == TypeEnum.Number)
                {
                    DateTime dt   = Convert.ToDateTime(r1.Value);
                    double   days = Convert.ToDouble(r2.Value);
                    result.Value = dt.AddDays(-days);
                }
                else
                {
                    result.Value = null;
                    result.Error = "#SUB:Bad Types";
                }
                break;

            case arOperEnum.mul:
                if (r1.TypeValue == TypeEnum.Number && r2.TypeValue == TypeEnum.Number)
                {
                    result.Value = Convert.ToDecimal(r1.Value) * Convert.ToDecimal(r2.Value);
                }
                else
                {
                    result.Value = null;
                    result.Error = "#MUL:Bad Types";
                }
                break;

            case arOperEnum.div:
                if (r1.TypeValue == TypeEnum.Number && r2.TypeValue == TypeEnum.Number &&
                    Convert.ToDecimal(r2.Value) != 0)
                {
                    result.Value = Convert.ToDecimal(r1.Value) * Convert.ToDecimal(r2.Value);
                }
                else
                {
                    result.Value = null;
                    result.Error = "#MUL:Bad Types";
                }
                break;
            }
            return(result);
        }