private void button1_Click(object sender, EventArgs e)
        {
            string s = textBox2.Text;

            switch (s)
            {
            case "<":
                Exp = new RelationalOp(Exp1.GetExp(), Exp2.GetExp(), 1);
                break;

            case "<=":
                Exp = new RelationalOp(Exp1.GetExp(), Exp2.GetExp(), 2);
                break;

            case "==":
                Exp = new RelationalOp(Exp1.GetExp(), Exp2.GetExp(), 3);
                break;

            case "!=":
                Exp = new RelationalOp(Exp1.GetExp(), Exp2.GetExp(), 4);
                break;

            case ">":
                Exp = new RelationalOp(Exp1.GetExp(), Exp2.GetExp(), 5);
                break;

            case ">=":
                Exp = new RelationalOp(Exp1.GetExp(), Exp2.GetExp(), 6);
                break;

            default:    //any other case will be Exp1 < Exp2
                Exp = new RelationalOp(Exp1.GetExp(), Exp2.GetExp(), 1);
                break;
            }
        }
Exemple #2
0
 public RelExpr(ITerm t1, RelationalOp oper, ITerm t2) : base(t1, oper.ToString(), t2) => op = oper;
 public RelationalExpression(Expression left, RelationalOp op, Expression right)
 {
     Left  = left;
     Op    = op;
     Right = right;
 }
        private void btnSave_Click(object sender, EventArgs e)
        {
            this.DialogResult         = DialogResult.OK;
            expression.QuestionTitle  = tbQuestionTitle.Text;
            expression.Hint           = tbSuggestions.Text;
            expression.SkipEvaluation = chkBxSkipEval.Checked;

            expression.FallbackAction = null;
            if (cbxFallbackActionNode.SelectedItem != null)
            {
                var id   = (cbxFallbackActionNode.SelectedItem as ILinkInfo)._id;
                var type = (LinkType)((KeyValuePair <string, int>)cbxFallbackActionType.SelectedItem).Value;
                expression.FallbackAction = new ActionLink {
                    LinkId = id, Type = type
                };
            }

            expression.ForwardAction = null;
            if (cbxForwardActionNode.SelectedItem != null)
            {
                var id   = (cbxForwardActionNode.SelectedItem as ILinkInfo)._id;
                var type = (LinkType)((KeyValuePair <string, int>)cbxForwardActionType.SelectedItem).Value;
                expression.ForwardAction = new ActionLink {
                    LinkId = id, Type = type
                };
            }

            expression.ExpressionTree = new ExpressionTree {
                Nodes = new List <IExpEval>()
            };
            var dt = ((KeyValuePair <string, Type>)cbxDataType.SelectedItem).Value;  //Data type

            foreach (DataGridViewRow row in dataGridViewActionItems.Rows)
            {
                var op   = row.Cells[0].Value;           //Operation
                var rVal = row.Cells[1].Value as string; //String data
                var with = row.Cells[2].Value;           //Logical with
                if (!string.IsNullOrWhiteSpace(rVal) && op != null && with != null)
                {
                    IExpEval curRes     = null;
                    object   parsedRVal = Convert((Type)dt, rVal);
                    if (parsedRVal != null)
                    {
                        if (op is RelationalOpType)
                        {
                            curRes = new RelationalOp {
                                With = (LogicalOpType)with, RVal = parsedRVal, ROp = (RelationalOpType)op
                            };
                        }
                        else if (op is ArithmeticOpType)
                        {
                            curRes = new ArithmeticOp {
                                With = (LogicalOpType)with, RVal = parsedRVal, AOp = (ArithmeticOpType)op
                            };
                        }
                    }

                    if (curRes != null)
                    {
                        expression.ExpressionTree.Nodes.Add(curRes);
                    }
                }
            }
        }