internal void FillImageCategoriesTree(IDictionary <string, IList <string> > categories, List <string> imageNames, ICollection <string> currentLevelChildren)
        {
            List <string> nextLevelChildren = new List <string>(currentLevelChildren);

            if (ParentCategory != null && ParentCategory.ParentCategory == null)
            {
                nextLevelChildren = new List <string>(categories.Keys);
            }
            nextLevelChildren.Remove(Name);

            List <string> nextLevelImageTreeNodes = new List <string>(imageNames);
            Dictionary <string, List <string> > childCategoriesImageNames = new Dictionary <string, List <string> >();

            foreach (string imageName in imageNames)
            {
                images.Add(new ImagePreviewObject(Owner, imageName));
                foreach (string categoryName in nextLevelChildren)
                {
                    if (categoryName != Name)
                    {
                        if (!childCategoriesImageNames.ContainsKey(categoryName))
                        {
                            childCategoriesImageNames.Add(categoryName, new List <string>());
                        }
                        if (categories[categoryName].Contains(imageName))
                        {
                            childCategoriesImageNames[categoryName].Add(imageName);
                            nextLevelImageTreeNodes.Remove(imageName);
                        }
                    }
                }
            }

            foreach (string childCategoryName in childCategoriesImageNames.Keys)
            {
                if (childCategoriesImageNames[childCategoryName].Count == 1)
                {
                    if (!nextLevelImageTreeNodes.Contains(childCategoriesImageNames[childCategoryName][0]))
                    {
                        nextLevelImageTreeNodes.Add(childCategoriesImageNames[childCategoryName][0]);
                    }
                }
                else if (childCategoriesImageNames[childCategoryName].Count > 1)
                {
                    ImagesGroupNode childCategory = new ImagesGroupNode(Owner, this, childCategoryName);
                    ChildCategories.Add(childCategory);
                    childCategory.FillImageCategoriesTree(categories, childCategoriesImageNames[childCategoryName], nextLevelChildren);
                }
            }
            foreach (string nextLevelImageTreeNode in nextLevelImageTreeNodes)
            {
                ImageNode imageTreeNode = new ImageNode(Owner, nextLevelImageTreeNode);
                ChildCategories.Add(imageTreeNode);
            }
        }
예제 #2
0
 public virtual void AddChildCategory(Category category)
 {
     if (category == null)
     {
         throw new ArgumentException("Can't add a null Category as child.");
     }
     // Remove from old parent category
     if (category.ParentCategory != null)
     {
         category.ParentCategory.ChildCategories.Remove(category);
     }
     // Set parent in child
     category.ParentCategory = this;
     // Set child in parent
     ChildCategories.Add(category);
 }
예제 #3
0
 public void AddChild(Category category) => ChildCategories.Add(category);
예제 #4
0
파일: Product.cs 프로젝트: zaieda/InRetail
 private void AddChildCategory(Category category)
 {
     ChildCategories.Add(category);
 }
 public virtual void AddChild(Category child)
 {
     ChildCategories.Add(child);
     child.ParentCategory = this;
 }