示例#1
0
        private void LoadOpExpression(TreeNode tn, DocOp op)
        {
            if (op == null)
            {
                return;
            }

            if (tn.Tag == null)
            {
                tn.Tag = op;
            }
            tn.Text               = op.ToString(this.Template);
            tn.ImageIndex         = 3;
            tn.SelectedImageIndex = tn.ImageIndex;

            if (op is DocOpLogical)
            {
                DocOpLogical oplog = (DocOpLogical)op;
                tn.ImageIndex         = 4;
                tn.SelectedImageIndex = tn.ImageIndex;

                TreeNode tnA = new TreeNode();
                LoadOpExpression(tnA, oplog.ExpressionA);
                tn.Nodes.Add(tnA);

                TreeNode tnB = new TreeNode();
                LoadOpExpression(tnB, oplog.ExpressionB);
                tn.Nodes.Add(tnB);
            }
        }
示例#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;
            }
        }
示例#3
0
        private void toolStripButtonRuleRemove_Click(object sender, EventArgs e)
        {
            TreeNode tn = this.treeViewRules.SelectedNode;

            if (tn == null)
            {
                return;
            }

            if (tn.Tag is DocModelRuleConstraint)
            {
                DocModelRuleConstraint docConstraint = (DocModelRuleConstraint)tn.Tag;
                docConstraint.Delete();
                this.RemoveRuleConstraint(this.Template.Rules, docConstraint);
                this.LoadRules(null);
            }
            else if (tn.Tag is DocOp)
            {
                // dissolve parent Logical operator, move other statement into parent

                DocOp op = (DocOp)tn.Tag;

                TreeNode     tnParent = tn.Parent;
                DocOpLogical oplog    = tnParent.Tag as DocOpLogical;
                if (tnParent.Tag is DocModelRuleConstraint)
                {
                    DocModelRuleConstraint dmr = (DocModelRuleConstraint)tnParent.Tag;
                    oplog = dmr.Expression as DocOpLogical;
                }

                TreeNode tnGrand = tnParent.Parent;

                DocOpExpression opOther = null;
                if (oplog.ExpressionA == op)
                {
                    opOther           = oplog.ExpressionB;
                    oplog.ExpressionB = null;                     // prevent deletion
                }
                else if (oplog.ExpressionB == op)
                {
                    opOther           = oplog.ExpressionA;
                    oplog.ExpressionA = null;                     // prevent deletion
                }

                if (tnParent.Tag is DocModelRuleConstraint)
                {
                    DocModelRuleConstraint dmr = (DocModelRuleConstraint)tnParent.Tag;
                    dmr.Expression = opOther;
                }
                else if (tnGrand != null)
                {
                    DocOpLogical opGrand = tnGrand.Tag as DocOpLogical;
                    if (tnGrand.Tag is DocModelRuleConstraint)
                    {
                        DocModelRuleConstraint dmr = (DocModelRuleConstraint)tnGrand.Tag;
                        opGrand = dmr.Expression as DocOpLogical;
                    }

                    if (opGrand.ExpressionA == oplog)
                    {
                        opGrand.ExpressionA = opOther;
                    }
                    else if (opGrand.ExpressionB == oplog)
                    {
                        opGrand.ExpressionB = opOther;
                    }
                }

                oplog.Delete();
                op.Delete();
                this.LoadRules(opOther);
            }
        }
示例#4
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;
            }

        }