Exemplo n.º 1
0
        private TreeNode MakeNode( XmlNode xNode )
        {
            TreeNode tNode = new TreeNode();

            if ( xNode.Name == "child" )
            {
                // This is a simple child node
                Loc loc = new Loc( xNode );
                tNode.Text = loc.Name;
                // Put location as tag
                tNode.Tag = loc;
            }
            else
            {
                // This is a parent node
                tNode.Text = xNode.Attributes["name"].Value;

                foreach ( XmlNode xChild in xNode.ChildNodes )
                    tNode.Nodes.Add( MakeNode( xChild ) );
            }

            return tNode;
        }
Exemplo n.º 2
0
        private void ButtonAdd_Click(object sender, System.EventArgs e)
        {
            string name = Input.Text;

            if ( name.Length == 0 )
            {
                Status.Text = "The name for the new item cannot be empty";
                return;
            }

            TreeNode pNode = TreeCat.SelectedNode;

            if ( pNode == null )
            {
                if ( TreeCat.Nodes.Count == 0 )
                {
                    // Empty tree, add the first item
                    Loc nLoc = new Loc( name  );
                    TreeNode nNode = new TreeNode( name );
                    Facet = name;
                    nNode.Tag = nLoc;

                    TreeCat.Nodes.Add( nNode );
                    TreeCat.SelectedNode = nNode;

                    IsModified = true;
                    return;
                }

                Status.Text = "Please select a category first";
                return;
            }

            if ( pNode.Tag is Loc )
            {
                if ( ((Loc)pNode.Tag).IsDefined )
                {
                    Status.Text = "You can't add sub-items to a location. Please choose a category instead.";
                    return;
                }
            }

            // Check for duplicates
            if ( IsDuplicate( pNode, name, true ) )
            {
                Status.Text = "An item named " + name + " already exists in the category " + pNode.Text;
                return;
            }

            // Ok we're adding a child. First set parent tag to null
            pNode.Tag = null;

            Loc NewLoc = new Loc( name  );
            TreeNode NewNode = new TreeNode( name );
            NewNode.Tag = NewLoc;

            pNode.Nodes.Add( NewNode );
            TreeCat.SelectedNode = NewNode;

            if ( ( pNode.Nodes.Count > 1 ) && ( pNode.Parent != null ) )
                TreeCat.SelectedNode = pNode;

            IsModified = true;
        }