public override TreeNode ToTree()
{
// Define vars
string Name = "Meets All Requirements:";
bool Trim = false;
int i = 0;
HasConditionErrors = false;
// Build the name which will be displayed in the criteria view
switch (this.Type)
{
case ConditionType.Div:
if (SubConditions.Count == 3)
{
// If a div condition has 3 conditions, the last is always a condition value
ConditionValue Cnd = (ConditionValue)SubConditions.Last();
Name = "Conditions Divided Equal to or Greater than " + Cnd.Value;
Trim = true;
}
else
Name = "Divided Value Of:";
break;
case ConditionType.Not:
Name = "Does Not Meet Criteria:";
break;
case ConditionType.Or:
Name = "Meets Any Criteria:";
break;
case ConditionType.Plus:
if (SubConditions.Count == 3)
{
// If a plus condition has 3 conditions, the last is always a condition value
ConditionValue Cnd = (ConditionValue)SubConditions.Last();
Name = "Condtions Equal to or Greater than " + String.Format("{0:N0}", Int32.Parse(Cnd.Value));
Trim = true;
}
else
Name = "The Sum Of:";
break;
}
// Start the TreeNode, and add this condition list in the tag
TreeNode Me = new TreeNode(Name);
Me.Tag = this;
// Add sub conditions to the nodes of this condition's tree node
foreach (Condition C in SubConditions)
{
// Obviously dont add null items
if (C == null)
continue;
// Make sure not to add the last element on a plus conditionlist
if (Trim && C is ConditionValue)
break;
// Convert sub-condition to tree
TreeNode N = C.ToTree();
if (N == null)
continue;
// Nested errors
if (!HasConditionErrors && C is ConditionList)
HasConditionErrors = (C as ConditionList).HasConditionErrors;
// Validation
if (!ValidateParam(i, C.Returns()))
{
N.ForeColor = System.Drawing.Color.Red;
HasConditionErrors = true;
N.ToolTipText = "Invalid Return Type. ";
N.ToolTipText += (C.Returns() == ReturnType.Bool)
? "A criteria value is required"
: "Criteria value must be disabled";
}
else
{
// Always reset this
N.ToolTipText = "";
}
// Add the node
Me.Nodes.Add(N);
i++;
}
return Me;
}