Ejemplo n.º 1
0
    /// <summary>
    /// Builds category tree from given dataset and returns root node object.
    /// </summary>
    /// <param name="data">Dataset containing categories to be organized as tree.</param>
    private void CreateCategoryTrees(DataSet data)
    {
        generalRoot  = new CategoryNode(CategoriesRoot);
        personalRoot = new CategoryNode(PersonalCategoriesRoot);

        if (!DataHelper.DataSourceIsEmpty(data))
        {
            // Handle custom starting category
            string prefixToRemove = "";
            if (!string.IsNullOrEmpty(StartingCategory) && (StartingCategoryObj != null))
            {
                prefixToRemove = StartingCategoryObj.CategoryIDPath;
            }

            foreach (DataRow dr in data.Tables[0].Rows)
            {
                // Get processed category path
                string idPath = dr["CategoryIDPath"].ToString();

                // Shorten ID path when starting category entered
                if (!string.IsNullOrEmpty(prefixToRemove))
                {
                    idPath = idPath.Replace(prefixToRemove, "");
                }

                // Split path
                string[] idSplits = idPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                int[]    ids      = ValidationHelper.GetIntegers(idSplits, -1);

                // Add categories from path to tree
                foreach (int id in ids)
                {
                    CategoryInfo category = CategoryInfoProvider.GetCategoryInfo(id);

                    if (category != null)
                    {
                        if (category.CategoryIsPersonal)
                        {
                            personalRoot.AddCategory(category);
                        }
                        else
                        {
                            generalRoot.AddCategory(category);
                        }
                    }
                }
            }
        }
    }
    /// <summary>
    /// Builds category tree from given dataset and returns root node object.
    /// </summary>
    /// <param name="data">Dataset containing categories to be organized as tree.</param>
    private void CreateCategoryTrees(DataSet data)
    {
        generalRoot = new CategoryNode(CategoriesRoot);
        personalRoot = new CategoryNode(PersonalCategoriesRoot);

        if (!DataHelper.DataSourceIsEmpty(data))
        {
            // Handle custom starting category
            string prefixToRemove = "";
            if (!string.IsNullOrEmpty(StartingCategory) && (StartingCategoryObj != null))
            {
                prefixToRemove = StartingCategoryObj.CategoryIDPath;
            }

            foreach (DataRow dr in data.Tables[0].Rows)
            {
                // Get processed category path
                string idPath = dr["CategoryIDPath"].ToString();

                // Shorten ID path when starting category entered
                if (!string.IsNullOrEmpty(prefixToRemove))
                {
                    idPath = idPath.Replace(prefixToRemove, "");
                }

                // Split path
                string[] idSplits = idPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                int[] ids = ValidationHelper.GetIntegers(idSplits, -1);

                // Add categories from path to tree
                foreach (int id in ids)
                {
                    CategoryInfo category = CategoryInfoProvider.GetCategoryInfo(id);

                    if (category != null)
                    {
                        if (category.CategoryIsPersonal)
                        {
                            personalRoot.AddCategory(category);
                        }
                        else
                        {
                            generalRoot.AddCategory(category);
                        }
                    }
                }
            }
        }
    }