public Add_Child_Aggregation ( Item_Aggregation_Related_Aggregations Child_Aggregation ) : void | ||
Child_Aggregation | Item_Aggregation_Related_Aggregations | New child aggregation |
return | void |
/// <summary> Adds the child information to the item aggregation object from the datatable extracted from the database </summary> /// <param name="AggrInfo">Partially built item aggregation object</param> /// <param name="ChildInfo">Datatable from database calls with child item aggregation information ( either SobekCM_Get_Item_Aggregation or SobekCM_Get_All_Groups )</param> private static void add_children(Complete_Item_Aggregation AggrInfo, DataTable ChildInfo) { if (ChildInfo.Rows.Count == 0) return; string childTypes = String.Empty; // Build a dictionary of nodes while building this tree Dictionary<string, Item_Aggregation_Related_Aggregations> nodes = new Dictionary<string, Item_Aggregation_Related_Aggregations>(ChildInfo.Rows.Count); // Step through each row of children foreach (DataRow thisRow in ChildInfo.Rows) { // pull some of the basic data out int hierarchyLevel = Convert.ToInt16(thisRow[5]); string code = thisRow[0].ToString().ToLower(); string parentCode = thisRow[1].ToString().ToLower(); // If this does not already exist, create it if (!nodes.ContainsKey(code)) { // Create the object Item_Aggregation_Related_Aggregations childObject = new Item_Aggregation_Related_Aggregations(code, thisRow[2].ToString(), thisRow[4].ToString(), Convert.ToBoolean(thisRow[6]), Convert.ToBoolean(thisRow[7])); // Add this object to the node dictionary nodes.Add(code, childObject); // If this is not ALL, no need to add the full hierarchy if ((AggrInfo.Code == "all") || (hierarchyLevel == -1)) { // Check for parent in the node list if ((parentCode.Length > 0) && (AggrInfo.Code != parentCode) && (nodes.ContainsKey(parentCode))) { nodes[parentCode].Add_Child_Aggregation(childObject); } } // If this is the first hierarchy, add to the main item aggregation object if (hierarchyLevel == -1) { AggrInfo.Add_Child_Aggregation(childObject); // If this is active and not hidden, check the type and save to list if ((!childObject.Hidden) && (childObject.Active)) { if (childTypes.Length == 0) childTypes = childObject.Type + "s"; else if (childTypes != childObject.Type) childTypes = "SubCollections"; } } } } // Save the type for the child collections AggrInfo.Child_Types = childTypes; }