Пример #1
0
 private void AddCriteriaButton_Click(object sender, EventArgs e)
 {
     if (CriteriaDisplay.SelectedNode != null && DescriptionTextbox.Text != String.Empty)
     {
         CriteriaNode newnode;
         int points;
         if (int.TryParse(this.PointsTextBox.Text, out points))
         {
             newnode = new CriteriaNode(DescriptionTextbox.Text, points);
         }
         else
         {
             newnode = new CriteriaNode(DescriptionTextbox.Text);
         }
         CriteriaDisplay.SelectedNode.Nodes.Add(newnode);
         if (newnode.Parent != null)
         {
             ((CriteriaNode)newnode.Parent).UpdatePoints();
             newnode.Parent.Expand();
         }
         else
         {
             Debug.WriteLine("ERROR: Tried adding a root node to criteria tree.");
         }
     }
 }
 private void AddCriteriaButton_Click(object sender, EventArgs e)
 {
     // parent node
     if (PointsTextBox.TextLength == 0)
     {
         CriteriaNode newnode = new CriteriaNode("Node " + TotalNodes.ToString());
         newnode.Description = this.DescriptionTextbox.Text;
         newnode.Text = newnode.Description;
         newnode.Points = 0;
         ROOTNODE.Nodes.Add(newnode);   // adds to the root node
         TotalNodes++;
         CriteriaDisplay.ExpandAll();
     }
     else
     {
         // root node
         if (CriteriaDisplay.SelectedNode == ROOTNODE)
         {
             CriteriaNode newnode = new CriteriaNode("Node " + TotalNodes.ToString());
             newnode.Description = this.DescriptionTextbox.Text;
             newnode.Points = Convert.ToInt32(this.PointsTextBox.Text);
             newnode.Text = newnode.Description + "(" + newnode.Points + "pts.)";
             ROOTNODE.Nodes.Add(newnode);
             CriteriaTree.AddLast(newnode);
             TotalNodes++;
             CriteriaDisplay.ExpandAll();
         }
         // child node
         else
         {
             CriteriaNode newnode = new CriteriaNode("Node " + TotalNodes.ToString());
             newnode.Description = this.DescriptionTextbox.Text;
             newnode.Points = Convert.ToInt32(this.PointsTextBox.Text);
             newnode.Text = newnode.Description + "(" + newnode.Points + "pts.)";
             CriteriaDisplay.SelectedNode.Nodes.Add(newnode);
             CriteriaDisplay.SelectedNode.ExpandAll();
             TotalNodes++;
             CriteriaDisplay.ExpandAll();
         }
     }
 }
        private void AddCriteriaButton_Click(object sender, EventArgs e)
        {
            // parent node
            if (PointsTextBox.TextLength == 0)
            {
                TreeNode tnode = new TreeNode();
                CriteriaNode newnode = new CriteriaNode("Node " + TotalNodes.ToString());
                newnode.ParentNode = null;
                newnode.Description = this.DescriptionTextbox.Text;
                tnode.Name = newnode.Name;
                tnode.Text = newnode.Description;
                newnode.Points = 0;
                CriteriaDisplay.Nodes.Add(tnode);
                CriteriaTree.AddLast(newnode);
                TotalNodes++;
                newnode.Node = tnode;
                NodeIsSelected = false;
            }
            else
            {
                // root node
                if (CriteriaDisplay.SelectedNode == null)
                {
                    TreeNode tnode = new TreeNode();
                    CriteriaNode newnode = new CriteriaNode("Node " + TotalNodes.ToString());
                    newnode.ParentNode = null;
                    tnode.Name = newnode.Name;
                    newnode.Description = this.DescriptionTextbox.Text;
                    newnode.Points = Convert.ToInt32(this.PointsTextBox.Text);
                    tnode.Text = newnode.Description + "(" + newnode.Points + "pts.)";
                    CriteriaDisplay.Nodes.Add(tnode);
                    CriteriaTree.AddLast(newnode);
                    TotalNodes++;
                    newnode.Node = tnode;
                    NodeIsSelected = false;
                }
                // child node
                else
                {
                    TreeNode tnode = new TreeNode();
                    CriteriaNode newnode = new CriteriaNode("Node " + TotalNodes.ToString());
                    newnode.ParentNode = CriteriaDisplay.SelectedNode;
                    tnode.Name = newnode.Name;
                    newnode.Description = this.DescriptionTextbox.Text;
                    newnode.Points = Convert.ToInt32(this.PointsTextBox.Text);
                    tnode.Text = newnode.Description + "(" + newnode.Points + "pts.)";
                    CriteriaDisplay.SelectedNode.ExpandAll();
                    CriteriaDisplay.SelectedNode.Nodes.Add(tnode);
                    CriteriaDisplay.SelectedNode.ExpandAll();
                    TotalNodes++;
                    newnode.Node = tnode;

                    // this for loop puts the newly created child node at the end of its parent node's list of children
                    for (int i = 0; i < CriteriaTree.Count; i++)
                    {
                        if (CriteriaTree.ElementAt(i).Node == newnode.ParentNode)
                        {
                            CriteriaTree.ElementAt(i).ChildList.AddLast(newnode);
                        }

                    }

                    //for (int j = 0; j < CriteriaDisplay.Nodes.Count; j++)
                    //{

                    //}
                }
               // UpdateCriteriaDisplay();
            }
        }