コード例 #1
0
ファイル: WSTreeView.cs プロジェクト: sherryswall/busiblocks
    public object GetSelectedItemBelow(string nodeName, string treeViewType, string treeViewName)
    {
        List <KeyValuePair <string, string> > listItems = new List <KeyValuePair <string, string> >();

        switch (treeViewType)
        {
        case "Category":

            switch (treeViewName)
            {
            case "Doco":
                BusiBlocks.DocoBlock.Category cat = DocoManager.GetCategoryByName(nodeName, true);
                listItems.Add(new KeyValuePair <string, string>(cat.Id, cat.DisplayName));
                IList <BusiBlocks.DocoBlock.Category> docoCategories = DocoManager.GetAllCategoriesBelow(cat.Id);

                foreach (BusiBlocks.DocoBlock.Category item in docoCategories)
                {
                    listItems.Add(new KeyValuePair <string, string>(item.Id, item.DisplayName));
                }
                break;

            case "News":
                BusiBlocks.CommsBlock.News.Category         selectedNews = NewsManager.GetCategoryByName(nodeName, true);
                IList <BusiBlocks.CommsBlock.News.Category> news         = NewsManager.GetCategories(selectedNews.Id, true);

                foreach (BusiBlocks.CommsBlock.News.Category newsItem in news)
                {
                    listItems.Add(new KeyValuePair <string, string>(newsItem.Id, newsItem.Name));
                }
                break;

            default: break;
            }
            break;

        case "Region":
            BusiBlocks.SiteLayer.Region selectedRegion = SiteManager.GetRegionByName(nodeName);
            if (selectedRegion != null)
            {
                listItems.Add(new KeyValuePair <string, string>(selectedRegion.Id, selectedRegion.Name));
                IList <Region> regions = SiteManager.GetAllRegionsBelow(selectedRegion);
                foreach (Region region in regions)
                {
                    listItems.Add(new KeyValuePair <string, string>(region.Id, region.Name));
                }
            }
            break;

        default:
            break;
        }
        return(listItems);
    }
コード例 #2
0
    protected void DeleteCategoryClick(object sender, EventArgs e)
    {
        string categoryName       = string.Empty;
        string categoryId         = popDeleteCategory.ReferrerId;
        string categoryTypeName   = string.Empty;
        string parentCategoryName = string.Empty;
        bool   deleteFailure      = false;

        // Need to figure out if this is a comms block category or a doco block category.
        if (!string.IsNullOrEmpty(categoryId))
        {
            BusiBlocks.CommsBlock.News.Category news = null;
            try
            {
                news = NewsManager.GetCategory(categoryId);
            }
            catch (NewsCategoryNotFoundException) { }
            if (news != null)
            {
                categoryTypeName = news.GetType().Name;
                categoryName     = news.Name;

                // Don't allow the root category to be deleted.
                if (news.ParentCategory == null)
                {
                    ((IFeedback)this.Page.Master).ShowFeedback(
                        BusiBlocksConstants.Blocks.Administration.LongName,
                        news.Name,
                        Feedback.Actions.Error,
                        "Cannot delete the highest level category"
                        );
                    return;
                }

                parentCategoryName = news.ParentCategory.Name;
                IList <BusiBlocks.CommsBlock.News.Item>     newsItems         = NewsManager.GetItems(news, true);
                IList <BusiBlocks.CommsBlock.News.Category> newsSubCategories = NewsManager.GetCategories(news.Id, true);
                // NewsManager.GetCategories returns the root category, so it will always have at least one item
                if (newsSubCategories.Count <= 1 && newsItems.Count == 0)
                {
                    NewsManager.DeleteCategory(news);
                    PopulateTreeView <BusiBlocks.CommsBlock.News.Category>(NewsManager.GetViewableCategories(Page.User.Identity.Name), true, false, string.Empty);
                }
                else
                {
                    deleteFailure = true;
                }
            }
            else
            {
                BusiBlocks.DocoBlock.Category doco = null;
                try
                {
                    doco = DocoManager.GetCategory(categoryId);
                }
                catch (DocoCategoryNotFoundException) { }

                if (doco != null)
                {
                    categoryTypeName   = doco.GetType().Name;
                    categoryName       = doco.DisplayName;
                    parentCategoryName = doco.ParentCategory.DisplayName;

                    IList <Article> docoItems = DocoManager.GetArticles(doco, ArticleStatus.All, true);
                    IList <BusiBlocks.DocoBlock.Category> docoSubCategories = DocoManager.GetAllCategoriesBelow(doco.Id);
                    if (docoSubCategories.Count == 0 && docoItems.Count == 0)
                    {
                        DocoManager.DeleteCategory(doco);
                        this.PopulateTreeView <BusiBlocks.DocoBlock.Category>(DocoManager.GetAllCategories(), true, false, string.Empty);
                    }
                    else
                    {
                        deleteFailure = true;
                    }
                }
            }
            RadTreeView1.DataBind();
        }
        //Displaying feedback.
        if (deleteFailure)
        {
            ((IFeedback)this.Page.Master).ShowFeedback(
                BusiBlocksConstants.Blocks.Administration.LongName,
                categoryTypeName,
                Feedback.Actions.Error,
                ErrorCategoryNotEmpty
                );
            RadTreeView1.FindNodeByText(categoryName).ExpandParentNodes();
            RadTreeView1.FindNodeByText(categoryName).Selected = true;
        }
        else
        {
            ((IFeedback)this.Page.Master).ShowFeedback(
                BusiBlocksConstants.Blocks.Administration.LongName,
                categoryTypeName,
                Feedback.Actions.Deleted,
                categoryName
                );
            RadTreeView1.FindNodeByText(parentCategoryName).ExpandParentNodes();
            RadTreeView1.FindNodeByText(parentCategoryName).Selected = true;
        }
    }