Пример #1
0
        public static void EvaluateFormula()
        {
            int loopCount = argBoxes.Count;

            if (currentFunction.Arguments.Count == 0)
            {
                loopCount -= 1;
            }
            object[] args = new object[loopCount];
            for (int i = 0; i < loopCount; i++)
            {
                object value = JSEval.Eval(argBoxes[i].TxtInput.Text);
                if (value == null || value.ToString() == "")
                {
                    lblResult.Text = "Formula Result = ";
                    return;
                }
                else
                {
                    args[i] = value;
                }
            }
            dynamic func = currentFunction.BindedFunction;

            lblResult.Text = "Formula Result = " + func(args).ToString();
        }
Пример #2
0
        public static void OnTxtInputTextChange(object sender, EventArgs e)
        {
            TextBox           txt  = sender as TextBox;
            Tuple <int, Type> pair = (Tuple <int, Type>)txt.Tag;

            if (txt.Text == "")      // TEXT BOX EMPTY
            {
                argBoxes[pair.Item1].LblRHS.ForeColor = Color.Gray;
                argBoxes[pair.Item1].LblRHS.Text      = pair.Item2.Name;
            }
            else
            {
                object evaluated = JSEval.Eval(txt.Text);
                if (evaluated.ToString() != "" && (evaluated.GetType().Name == pair.Item2.Name || pair.Item2 == typeof(object)))
                {
                    argBoxes[pair.Item1].LblRHS.ForeColor = Color.Gray;
                    argBoxes[pair.Item1].LblRHS.Text      = evaluated.ToString();
                    EvaluateFormula();
                }
                else
                {
                    argBoxes[pair.Item1].LblRHS.ForeColor = Color.Red;
                    argBoxes[pair.Item1].LblRHS.Text      = "Invalid Input";
                }
            }
        }