Exemplo n.º 1
0
        /// <summary>
        /// Determines if an object is a child of another object.
        /// </summary>
        /// <param name="parentObject">The parent object.</param>
        /// <param name="childObject">The chld object.</param>
        /// <returns>True of the child object is an descendant of the parent object.</returns>
        public static bool IsChildObject(MarketData.ObjectRow parentObject, MarketData.ObjectRow childObject)
        {
            // If the parent is the same as the child, they are related.
            if (parentObject.ObjectId == childObject.ObjectId)
            {
                return(true);
            }

            // Recurse through the hierarhy testing to see if the child is part of the famly tree of the parent object.
            foreach (MarketData.ObjectTreeRow objectTreeRow in parentObject.GetObjectTreeRowsByObjectObjectTreeParentId())
            {
                if (IsChildObject(objectTreeRow.ObjectRowByObjectObjectTreeChildId, childObject))
                {
                    return(true);
                }
            }

            // At this point, the child is not part of the parent hierarchy.
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines if a given blotter is visible on the current document.
        /// </summary>
        /// <param name="parentRow">The current object in the recursive search.</param>
        /// <param name="blotterId">The blotter id to be found.</param>
        /// <returns>true if the blotter is part of the tree structure.</returns>
        public static bool IsDescendant(MarketData.ObjectRow parentRow, MarketData.ObjectRow childRow)
        {
            // Don't attempt to search if there is no starting point.
            if (parentRow != null)
            {
                // If the parent is the same as the child, then the original records are related.
                if (parentRow == childRow)
                {
                    return(true);
                }

                // Recursively search each of the children of the current node.
                foreach (MarketData.ObjectTreeRow objectTreeRow in parentRow.GetObjectTreeRowsByObjectObjectTreeParentId())
                {
                    if (IsDescendant(objectTreeRow.ObjectRowByObjectObjectTreeChildId, childRow))
                    {
                        return(true);
                    }
                }
            }

            // At this point, there were no children found on this tree that matched the blotter id.
            return(false);
        }