Exemplo n.º 1
0
        private void toolStripButtonRuleUpdate_Click(object sender, EventArgs e)
        {
            DocOpStatement docop = GetSelectedOp() as DocOpStatement;

            if (docop == null)
            {
                return;
            }

            // enumeration|boolean|logical: pick from list
            // string|integer|real: freeform editor

            using (FormConstraint form = new FormConstraint())
            {
                form.DataType = this.m_project.GetDefinition(docop.Reference.EntityRule.Name) as DocType;
                if (form.DataType == null)
                {
                    try
                    {
                        form.ExpressType = (DocExpressType)Enum.Parse(typeof(DocExpressType), docop.Reference.EntityRule.Name);
                    }
                    catch
                    {
                    }
                }

                form.Metric    = docop.Metric;
                form.Operation = docop.Operation;

                if (docop.Value is DocOpLiteral)
                {
                    form.Literal = ((DocOpLiteral)docop.Value).Literal;
                }
                if (form.ShowDialog(this) == DialogResult.OK)
                {
                    docop.Operation = form.Operation;
                    docop.Metric    = form.Metric;

                    if (!(docop.Value is DocOpLiteral))
                    {
                        docop.Value.Delete();
                        docop.Value = new DocOpLiteral();
                    }

                    ((DocOpLiteral)docop.Value).Literal = form.Literal;

                    this.treeViewRules.SelectedNode.Text = docop.ToString(this.Template);
                }
            }
        }
Exemplo n.º 2
0
        public void DoInsert()
        {
            if (this.Template == null)
            {
                return;
            }

            DocModelRule docModelRule = this.Rule;

            if (docModelRule == null)
            {
                return;
            }

            if (!(this.Rule is DocModelRuleEntity))
            {
                return;
            }

            TreeNode tnSelect = this.treeViewRules.SelectedNode;

            DocOpLiteral oplit = new DocOpLiteral();

            oplit.Operation = DocOpCode.LoadString;
            oplit.Literal   = null;

            DocOpStatement op = new DocOpStatement();

            op.Operation = DocOpCode.CompareEqual;
            op.Value     = oplit;

            DocOpReference opref = new DocOpReference();

            opref.Operation  = DocOpCode.NoOperation;            // ldfld...
            opref.EntityRule = this.Rule as DocModelRuleEntity;
            op.Reference     = opref;

            if (tnSelect != null)
            {
                DocOpExpression opSelect = tnSelect.Tag as DocOpExpression;
                if (tnSelect.Tag is DocModelRuleConstraint)
                {
                    opSelect = ((DocModelRuleConstraint)tnSelect.Tag).Expression;
                }


                // convert existing node into new Logical operator

                DocOpLogical opLog = new DocOpLogical();
                opLog.Operation   = DocOpCode.And;
                opLog.ExpressionA = opSelect;
                opLog.ExpressionB = op;

                if (tnSelect.Tag is DocModelRuleConstraint)
                {
                    DocModelRuleConstraint dmr = (DocModelRuleConstraint)tnSelect.Tag;
                    dmr.Expression = opLog;
                }
                else if (tnSelect.Parent != null)
                {
                    DocOpLogical opParent = tnSelect.Parent.Tag as DocOpLogical;
                    if (tnSelect.Parent.Tag is DocModelRuleConstraint)
                    {
                        opParent = ((DocModelRuleConstraint)tnSelect.Parent.Tag).Expression as DocOpLogical;
                    }

                    if (tnSelect.Parent.Nodes[0] == tnSelect)
                    {
                        opParent.ExpressionA = opLog;
                    }
                    else if (tnSelect.Parent.Nodes[1] == tnSelect)
                    {
                        opParent.ExpressionB = opLog;
                    }
                }
                else if (tnSelect.Parent != null && tnSelect.Parent.Nodes[1] == tnSelect)
                {
                    DocOpLogical opParent = (DocOpLogical)tnSelect.Parent.Tag;
                    opParent.ExpressionB = opLog;
                }

                this.LoadRules(op);
            }
            else
            {
                // create new constraint
                DocModelRuleConstraint docCon = new DocModelRuleConstraint();
                docCon.Expression = op;
                docModelRule.Rules.Add(docCon);
                docCon.ParentRule = docModelRule;

                TreeNode tnCon = new TreeNode();
                tnCon.Tag                = docCon;
                tnCon.Text               = op.ToString(this.Template);
                tnCon.ImageIndex         = 3;
                tnCon.SelectedImageIndex = tnCon.ImageIndex;
                this.treeViewRules.Nodes.Add(tnCon);

                this.treeViewRules.SelectedNode = tnCon;
            }
        }
Exemplo n.º 3
0
        public void DoInsert()
        {
            if (this.Template == null)
                return;

            DocModelRule docModelRule = this.Rule;
            if (docModelRule == null)
                return;

            if (!(this.Rule is DocModelRuleEntity))
                return;

            TreeNode tnSelect = this.treeViewRules.SelectedNode;

            DocOpLiteral oplit = new DocOpLiteral();
            oplit.Operation = DocOpCode.LoadString;
            oplit.Literal = null;

            DocOpStatement op = new DocOpStatement();
            op.Operation = DocOpCode.CompareEqual;
            op.Value = oplit;

            DocOpReference opref = new DocOpReference();
            opref.Operation = DocOpCode.NoOperation; // ldfld...
            opref.EntityRule = this.Rule as DocModelRuleEntity;
            op.Reference = opref;

            if (tnSelect != null)
            {
                DocOpExpression opSelect = tnSelect.Tag as DocOpExpression;
                if (tnSelect.Tag is DocModelRuleConstraint)
                {
                    opSelect = ((DocModelRuleConstraint)tnSelect.Tag).Expression;

                }


                // convert existing node into new Logical operator

                DocOpLogical opLog = new DocOpLogical();
                opLog.Operation = DocOpCode.And;
                opLog.ExpressionA = opSelect;
                opLog.ExpressionB = op;

                if (tnSelect.Tag is DocModelRuleConstraint)
                {
                    DocModelRuleConstraint dmr = (DocModelRuleConstraint)tnSelect.Tag;
                    dmr.Expression = opLog;
                }
                else if (tnSelect.Parent != null)
                {
                    DocOpLogical opParent = tnSelect.Parent.Tag as DocOpLogical;
                    if (tnSelect.Parent.Tag is DocModelRuleConstraint)
                    {
                        opParent = ((DocModelRuleConstraint)tnSelect.Parent.Tag).Expression as DocOpLogical;
                    }

                    if (tnSelect.Parent.Nodes[0] == tnSelect)
                    {
                        opParent.ExpressionA = opLog;
                    }
                    else if (tnSelect.Parent.Nodes[1] == tnSelect)
                    {
                        opParent.ExpressionB = opLog;
                    }
                }
                else if (tnSelect.Parent != null && tnSelect.Parent.Nodes[1] == tnSelect)
                {
                    DocOpLogical opParent = (DocOpLogical)tnSelect.Parent.Tag;
                    opParent.ExpressionB = opLog;
                }

                this.LoadRules(op);
            }
            else
            {
                // create new constraint
                DocModelRuleConstraint docCon = new DocModelRuleConstraint();
                docCon.Expression = op;
                docModelRule.Rules.Add(docCon);

                TreeNode tnCon = new TreeNode();
                tnCon.Tag = docCon;
                tnCon.Text = op.ToString(this.Template);
                tnCon.ImageIndex = 3;
                tnCon.SelectedImageIndex = tnCon.ImageIndex;
                this.treeViewRules.Nodes.Add(tnCon);

                this.treeViewRules.SelectedNode = tnCon;
            }

        }