Beispiel #1
0
        public static IEnumerable <T> GetGenealogyTree <T>(GetTreeRequest request) where T : ITreeNode
        {
            // Get the nodes
            var nodes           = new List <T>();
            var rowcount        = 50;
            var lastResultCount = rowcount;
            var callsMade       = 0;

            while (lastResultCount == rowcount)
            {
                var query = Exigo.OData().EnrollerTree
                            .Where(c => c.TopCustomerID == request.TopCustomerID);

                // Filter by level
                var levels = (request.Levels != 0) ? request.Levels : 10;
                query = query
                        .Where(c => c.Level <= levels);

                // Filter by customer types
                var allowableCustomerTypes = new List <int>()
                {
                    (int)CustomerTypes.Associate
                };
                query = query
                        .Where(allowableCustomerTypes.ToOrExpression <EnrollerNode, int>("Customer.CustomerTypeID"));

                // Get the data
                var results = query
                              .OrderBy(c => c.IndentedSort)
                              .Skip(callsMade * rowcount)
                              .Take(rowcount)
                              .Select(c => c)
                              .ToList();

                results.ForEach(c =>
                {
                    var node              = (T)Activator.CreateInstance(typeof(T));
                    node.CustomerID       = c.CustomerID;
                    node.ParentCustomerID = c.EnrollerID;
                    node.Level            = c.Level;
                    node.PlacementID      = 0;
                    node.IndentedSort     = c.IndentedSort;
                    node.ChildNodeCount   = c.ChildCount;

                    nodes.Add(node);
                });

                callsMade++;
                lastResultCount = results.Count;
            }

            return(nodes);
        }
Beispiel #2
0
        private static void PopulateNullPositions <T>(T parentNode, GetTreeRequest request) where T : INestedTreeNode <T>
        {
            if (parentNode.Children.Count() < request.Legs)
            {
                var placementID = 0;
                while (placementID < request.Legs)
                {
                    if (!parentNode.Children.Any(c => c.PlacementID == placementID))
                    {
                        var nullNode = Activator.CreateInstance <T>();
                        if (parentNode.IsOpenPosition)
                        {
                            nullNode = CreateNullPositionTreeNode <T>(parentNode, parentNode.Level + 1, placementID);
                        }
                        else
                        {
                            nullNode = CreateOpenPositionTreeNode <T>(parentNode, parentNode.Level + 1, placementID);
                        }
                        parentNode.Children.Add(nullNode);
                    }

                    placementID++;
                }
            }


            foreach (var child in parentNode.Children)
            {
                if ((child.IsOpenPosition || child.IsNullPosition) && child.Level < request.Levels)
                {
                    var placementID = 0;
                    while (placementID < request.Legs)
                    {
                        var nullNode = CreateNullPositionTreeNode <T>(child, child.Level + 1, placementID);
                        child.Children.Add(nullNode);

                        placementID++;
                    }
                }
            }

            parentNode.Children = parentNode.Children.OrderBy(c => c.PlacementID).ToList();


            if (parentNode.Level + 1 < request.Levels)
            {
                foreach (var child in parentNode.Children)
                {
                    PopulateNullPositions <T>((T)child, request);
                }
            }
        }
Beispiel #3
0
        // Getting tree nodes
        public static IEnumerable <T> GetUniLevelTree <T>(GetTreeRequest request) where T : ITreeNode
        {
            // Get the nodes
            var nodes = new List <T>();

            using (var context = Exigo.Sql())
            {
                string sqlProcedure = string.Format(@"GetUniLevelTree {0},{1},{2},{3},{4}", request.CustomerID, request.TopCustomerID, request.CustomerTypeID, request.Levels, PeriodTypes.Monthly);
                nodes = context.Query <T>(sqlProcedure).ToList();
            }

            return(nodes);
        }
Beispiel #4
0
        public static IEnumerable <T> GetBinaryTree <T>(GetTreeRequest request) where T : ITreeNode
        {
            // Get the nodes
            var nodes           = new List <T>();
            var rowcount        = 50;
            var lastResultCount = rowcount;
            var callsMade       = 0;

            while (lastResultCount == rowcount)
            {
                var query = Exigo.OData().BinaryTree
                            .Where(c => c.TopCustomerID == request.TopCustomerID);

                // Filter by level
                var levels = (request.Levels != 0) ? request.Levels : 10;
                query = query.Where(c => c.Level <= levels);

                // Filter by legs
                if (request.Legs != 0)
                {
                    query = query.Where(c => c.Placement <= request.Legs);
                }

                // Get the data
                var results = query
                              .OrderBy(c => c.IndentedSort)
                              .Skip(callsMade * rowcount)
                              .Take(rowcount)
                              .Select(c => c)
                              .ToList();


                results.ForEach(c =>
                {
                    var node              = (T)Activator.CreateInstance(typeof(T));
                    node.CustomerID       = c.CustomerID;
                    node.ParentCustomerID = c.ParentID;
                    node.Level            = c.Level;
                    node.PlacementID      = c.Placement;
                    node.IndentedSort     = c.IndentedSort;
                    node.ChildNodeCount   = c.ChildCount;

                    nodes.Add(node);
                });

                callsMade++;
                lastResultCount = results.Count;
            }

            return(nodes);
        }
Beispiel #5
0
        private static IEnumerable <T> GetChildren <T>(T parentNode, IEnumerable <T> nodes, GetTreeRequest request) where T : INestedTreeNode <T>
        {
            var parentNodeChildren = new List <T>();
            var currentLevel       = parentNode.Level + 1;


            foreach (var node in nodes)
            {
                // Is this a child?
                var isChild =
                    node.Level == currentLevel &&
                    node.ParentCustomerID == parentNode.CustomerID;

                if (isChild)
                {
                    node.ParentNodeID = parentNode.NodeID;
                    node.Children.AddRange(GetChildren(node, nodes.Where(c => c.Level > node.Level), request));
                    parentNodeChildren.Add(node);
                }
            }


            // Insert open position nodes if applicable
            if (request.IncludeOpenPositions && request.Legs > 0 && currentLevel < request.Levels && parentNodeChildren.Count < request.Legs)
            {
                var placementID = 0;
                while (placementID < request.Legs)
                {
                    if (!parentNodeChildren.Any(c => c.PlacementID == placementID))
                    {
                        // Create an empty node
                        parentNodeChildren.Add((T)CreateOpenPositionTreeNode <T>(parentNode, currentLevel, placementID));
                    }

                    placementID++;
                }
            }


            return(parentNodeChildren.OrderBy(c => c.PlacementID));
        }
Beispiel #6
0
        public static IEnumerable <T> OrganizeNestedTreeNodes <T>(IEnumerable <T> nodes, GetTreeRequest request) where T : INestedTreeNode <T>
        {
            var topNode = nodes.FirstOrDefault();

            if (topNode == null)
            {
                yield return(topNode);
            }

            topNode.Children.AddRange(GetChildren <T>(topNode, nodes.Where(c => c.Level > topNode.Level), request).OrderBy(c => c.PlacementID));

            // Populate null positions if applicable
            if (request.IncludeNullPositions)
            {
                PopulateNullPositions <T>(topNode, request);
            }

            yield return(topNode);
        }
Beispiel #7
0
        public static IEnumerable <T> GetBinaryTree <T>(GetTreeRequest request) where T : ITreeNode
        {
            // Get the nodes
            var nodes           = new List <T>();
            var rowcount        = 50;
            var lastResultCount = rowcount;
            var callsMade       = 0;

            while (lastResultCount == rowcount)
            {
                //var query = Exigo.OData().BinaryTree
                //    .Where(c => c.TopCustomerID == request.TopCustomerID);

                //// Filter by level
                //var levels = (request.Levels != 0) ? request.Levels : 15;
                //query = query.Where(c => c.Level <= levels);

                //// Filter by legs
                //if (request.Legs != 0)
                //{
                //    query = query.Where(c => c.Placement <= request.Legs);
                //}

                //// Get the data
                //var results = query
                //    .OrderBy(c => c.IndentedSort)
                //    .Skip(callsMade * rowcount)
                //    .Take(rowcount)
                //    .Select(c => c)
                //    .ToList();


                //results.ForEach(c =>
                //{
                //    var node = (T)Activator.CreateInstance(typeof(T));
                //    node.CustomerID = c.CustomerID;
                //    node.ParentCustomerID = c.ParentID;
                //    node.Level = c.Level;
                //    node.PlacementID = c.Placement;
                //    node.IndentedSort = c.IndentedSort;
                //    node.ChildNodeCount = c.ChildCount;

                //    nodes.Add(node);
                //});
                var levels    = (request.Levels != 0) ? request.Levels : 15;
                var skip      = callsMade * rowcount;
                var take      = rowcount;
                var placement = request.Legs != 0 ? request.Legs : (int?)null;

                using (SqlConnection context = Exigo.Sql())
                {
                    context.Open();
                    SqlCommand cmd = new SqlCommand("dbo.GetBinaryTree", context);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@topcustomerid", request.TopCustomerID));
                    cmd.Parameters.Add(new SqlParameter("@level", levels));
                    cmd.Parameters.Add(new SqlParameter("@skip", skip));
                    cmd.Parameters.Add(new SqlParameter("@take", take));
                    cmd.Parameters.Add(new SqlParameter("@placement", placement));


                    using (SqlDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            var node = (T)Activator.CreateInstance(typeof(T));
                            node.CustomerID       = (int)rdr["DownLines"];
                            node.ParentCustomerID = (int)rdr["ParentID"];
                            node.Level            = (int)rdr["Level"];
                            node.PlacementID      = (int)rdr["Placement"];
                            node.IndentedSort     = (int)rdr["IndentedSort"];
                            node.ChildNodeCount   = (int)rdr["ChildCount"];

                            nodes.Add(node);
                        }
                    }

                    callsMade++;
                    lastResultCount = nodes.Count;
                }
            }

            return(nodes);
        }