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); } }
private void toolStripButtonRuleRef_Click(object sender, EventArgs e) { DocOp op = this.GetSelectedOp(); if (op is DocOpStatement) { DocOpStatement statement = (DocOpStatement)op; if (this.Rule is DocModelRuleAttribute) { DocOpParameter param = new DocOpParameter(); param.Operation = DocOpCode.LoadArgument; param.AttributeRule = (DocModelRuleAttribute)this.Rule; statement.Value = param; } else if (this.Rule is DocModelRuleEntity) { DocOpReference opref = new DocOpReference(); opref.Operation = DocOpCode.LoadField; opref.EntityRule = (DocModelRuleEntity)this.Rule; statement.Value = opref; } this.treeViewRules.SelectedNode.Text = op.ToString(this.Template); } }
private void SetSelectedRuleOperator(DocOpCode opcode) { TreeNode tn = this.treeViewRules.SelectedNode; DocOp docop = this.GetSelectedOp(); docop.Operation = opcode; tn.Text = docop.ToString(this.Template); this.treeViewRules_AfterSelect(this.treeViewRules, new TreeViewEventArgs(this.treeViewRules.SelectedNode)); }
private void treeViewRules_AfterSelect(object sender, TreeViewEventArgs e) { TreeNode tn = this.treeViewRules.SelectedNode; DocOp op = this.GetSelectedOp(); if (this.Template == null) { foreach (ToolStripItem tsi in this.toolStripConceptRule.Items) { tsi.Enabled = false; if (tsi is ToolStripButton) { ((ToolStripButton)tsi).Checked = false; } } return; } this.toolStripButtonRuleInsert.Enabled = (this.Rule is DocModelRuleEntity); this.toolStripButtonRuleRemove.Enabled = (tn != null); this.toolStripButtonRuleUpdate.Enabled = (op is DocOpStatement); this.toolStripButtonRuleRef.Enabled = (op is DocOpStatement && this.Rule != null); this.toolStripButtonRuleAnd.Enabled = (op is DocOpLogical); this.toolStripButtonRuleOr.Enabled = (op is DocOpLogical); this.toolStripButtonRuleXor.Enabled = (op is DocOpLogical); this.toolStripButtonRuleCeq.Enabled = (op is DocOpStatement); this.toolStripButtonRuleCne.Enabled = (op is DocOpStatement); this.toolStripButtonRuleCle.Enabled = (op is DocOpStatement); this.toolStripButtonRuleClt.Enabled = (op is DocOpStatement); this.toolStripButtonRuleCge.Enabled = (op is DocOpStatement); this.toolStripButtonRuleCgt.Enabled = (op is DocOpStatement); this.toolStripButtonRuleIncludes.Enabled = (op is DocOpStatement); this.toolStripButtonRuleAnd.Checked = (op != null && op.Operation == DocOpCode.And); this.toolStripButtonRuleOr.Checked = (op != null && op.Operation == DocOpCode.Or); this.toolStripButtonRuleXor.Checked = (op != null && op.Operation == DocOpCode.Xor); this.toolStripButtonRuleCeq.Checked = (op != null && op.Operation == DocOpCode.CompareEqual); this.toolStripButtonRuleCne.Checked = (op != null && op.Operation == DocOpCode.CompareNotEqual); this.toolStripButtonRuleCle.Checked = (op != null && op.Operation == DocOpCode.CompareLessThanOrEqual); this.toolStripButtonRuleClt.Checked = (op != null && op.Operation == DocOpCode.CompareLessThan); this.toolStripButtonRuleCge.Checked = (op != null && op.Operation == DocOpCode.CompareGreaterThanOrEqual); this.toolStripButtonRuleCgt.Checked = (op != null && op.Operation == DocOpCode.CompareGreaterThan); this.toolStripButtonRuleIncludes.Checked = (op != null && op.Operation == DocOpCode.IsIncluded); }
private DocOp GetSelectedOp() { TreeNode tn = this.treeViewRules.SelectedNode; if (tn == null) { return(null); } DocOp docop = tn.Tag as DocOp; if (tn.Tag is DocModelRuleConstraint) { DocModelRuleConstraint dmr = (DocModelRuleConstraint)tn.Tag; docop = dmr.Expression; } return(docop); }
private void LoadRules(DocOp selection) { this.treeViewRules.BeginUpdate(); this.treeViewRules.Nodes.Clear(); if (this.m_template != null) { this.LoadRules(this.Template.Rules, null); this.treeViewRules.ExpandAll(); this.treeViewRules_AfterSelect(this.treeViewRules, new TreeViewEventArgs(null)); foreach (TreeNode tn in this.treeViewRules.Nodes) { SelectRule(tn, selection); } } this.treeViewRules.EndUpdate(); // select nothing such that color is displayed for validation this.treeViewRules.SelectedNode = null; }
private void SelectRule(TreeNode tn, DocOp selection) { if (tn.Tag == selection) { this.treeViewRules.SelectedNode = tn; return; } else if (tn.Tag is DocModelRuleConstraint) { DocModelRuleConstraint dmc = (DocModelRuleConstraint)tn.Tag; if (dmc.Expression == selection) { this.treeViewRules.SelectedNode = tn; } } foreach (TreeNode ts in tn.Nodes) { SelectRule(ts, selection); } }
private void ValidateNode(TreeNode tn) { if (this.m_instance != null) { DocOp docOp = null; if (tn.Tag is DocModelRuleConstraint) { DocModelRuleConstraint con = (DocModelRuleConstraint)tn.Tag; docOp = con.Expression; } else if (tn.Tag is DocOp) { docOp = (DocOp)tn.Tag; } if (docOp != null) { Hashtable hashtable = new Hashtable(); object oresult = docOp.Eval(this.m_instance, hashtable, this.m_template, null, null); // if hashtable contains a value, that means that entire population must be tested to determine uniqueness if (hashtable.Count > 0 && this.m_population != null) { // must evalulate all for uniqueness foreach (object other in this.m_population) { if (other == this.m_instance) // first instance will pass; following duplicate instances will fail { break; } // returning false means there's a duplicate (not unique). object otherresult = docOp.Eval(other, hashtable, this.m_template, null, null); if (otherresult is bool && !(bool)otherresult) { oresult = false; break; } } } if (oresult == null) { tn.BackColor = Color.Yellow; } else if (oresult is bool && (bool)oresult) { tn.BackColor = Color.Lime; } else if (oresult is bool && !(bool)oresult) { tn.BackColor = Color.Red; } } } else { tn.BackColor = Color.Empty; } // recurse foreach (TreeNode sub in tn.Nodes) { ValidateNode(sub); } }
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); } }
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); } }
private object TraceOperation(DocTemplateDefinition template, DocOp op, StringBuilder sb, SEntity ent, List<SEntity> population, int level) { System.Collections.Hashtable hashtable = new System.Collections.Hashtable(); object result = op.Eval(ent, hashtable, template, null, null); if (hashtable.Count > 0) { // must evaluate all for uniqueness foreach (object other in population) { if (other == ent) // first instance will pass; following duplicate instances will fail break; // returning false means there's a duplicate (not unique). object otherresult = op.Eval(other, hashtable, template, null, null); if (otherresult is bool && !(bool)otherresult) { result = false; break; } } } if (result is bool && !((bool)result)) { for (int i = 0; i < level; i++ ) { sb.Append(" "); } sb.AppendLine(op.ToString(template) + "<br/>"); } // recurse if (op is DocOpLogical) { DocOpLogical oplog = (DocOpLogical)op; TraceOperation(template, oplog.ExpressionA, sb, ent, population, level + 1); TraceOperation(template, oplog.ExpressionB, sb, ent, population, level + 1); } return result; }