private void handleThisEnvelopeNode(EnvelopeNode envNode)
        {
            int envelopeID = envNode.EnvelopeID;

            foreach (var item in DBquery.getSubEnvelopeBalances(envelopeID))
            {
                AENode node = new AENode(item.ID, envelopeID, item.Name, item.SubBalance);
                node.ImageId = (int)NodeImage.Bank;
                envNode.Nodes.Add(node);
            }
        }
        private bool updateBalanceRecurse(BaseNode pNode, int accountID, int envelopeID, decimal newAmount)
        {
            switch (pNode.NodeType)
            {
            case MyNodes.Root:
            case MyNodes.AccountType:
            case MyNodes.EnvelopeGroup:
                foreach (BaseNode child in pNode.Nodes)
                {
                    if (updateBalanceRecurse(child, accountID, envelopeID, newAmount))
                    {
                        return(true);
                    }
                }
                break;

            case MyNodes.Account:
                AccountNode aNode = pNode as AccountNode;
                if (aNode.AccountID == accountID)
                {
                    if (envelopeID == SpclEnvelope.NULL)
                    {
                        aNode.setBalance(newAmount);
                        return(true);
                    }
                    else
                    {
                        foreach (BaseNode child in pNode.Nodes)
                        {
                            if (updateBalanceRecurse(child, accountID, envelopeID, newAmount))
                            {
                                return(true);
                            }
                        }

                        // If we get here the AENode was not found so handle this Account Node.
                        bool open = aNode.Expanded;

                        aNode.Nodes.Clear();
                        this.handleThisAccountNode(aNode);

                        aNode.Expanded = open;
                        return(true);
                    }
                }
                break;

            case MyNodes.Envelope:
                EnvelopeNode eNode = pNode as EnvelopeNode;
                if (eNode.EnvelopeID == envelopeID)
                {
                    if (accountID == SpclAccount.NULL)
                    {
                        eNode.setBalance(newAmount);
                        return(true);
                    }
                    else
                    {
                        foreach (BaseNode child in pNode.Nodes)
                        {
                            if (updateBalanceRecurse(child, accountID, envelopeID, newAmount))
                            {
                                return(true);
                            }
                        }

                        // If we get here the AENode was not found so handle this Account Node.
                        bool open = eNode.Expanded;

                        eNode.Nodes.Clear();
                        this.handleThisEnvelopeNode(eNode);

                        eNode.Expanded = open;
                        return(true);
                    }
                }
                break;

            case MyNodes.AENode:
                AENode aeNode = pNode as AENode;
                if (aeNode.EnvelopeID == envelopeID && aeNode.AccountID == accountID)
                {
                    if (newAmount == 0.00m)
                    {
                        // If we get here delete this node because it is zero balance.
                        // To do that in a simple way just return false and the previous iteration
                        // will think we didn't find the aeNode and do a update of all the aeNode.
                        // which will be the same as deleting it here.
                        return(false);
                    }
                    else
                    {
                        aeNode.setBalance(newAmount);
                    }

                    return(true);
                }
                break;
            }
            return(false);
        }