protected void DeleteRegionClick(object sender, EventArgs e) { string regionID = popDeleteRegion.ReferrerId; Region region = SiteManager.GetRegionById(regionID); Region parentRegion = region.ParentRegion; string regionName = region.Name; string regionTypeName = region.GetType().Name; IList <Site> sites = SiteManager.GetAllSitesByRegion(region, true); if (sites.Count == 0) { SiteManager.DeleteRegion(region); ((IFeedback)this.Page.Master).ShowFeedback( BusiBlocksConstants.Blocks.Administration.LongName, regionTypeName, Feedback.Actions.Deleted, regionName ); PopulateTreeView <Region>(SiteManager.GetAllRegions(), true, false, string.Empty); RadTreeView1.DataBind(); RadTreeView1.FindNodeByText(parentRegion.Name).Selected = true; } else { ((IFeedback)this.Page.Master).ShowFeedback( BusiBlocksConstants.Blocks.Administration.LongName, region.GetType().Name, Feedback.Actions.Error, ErrorRegionNotEmpty ); } }
protected void AddRegionClick(object sender, EventArgs e) { Region newRegion = new Region(); newRegion.Name = popAddRegion.Value; newRegion.ParentRegion = SiteManager.GetRegionById(popAddRegion.ReferrerId); IList <RegionType> regionTypes = SiteManager.GetAllRegionTypes(); RegionType regionType = regionTypes.Last(); newRegion.RegionType = regionType; if (!SiteManager.IsRegionUnique(newRegion)) { ((IFeedback)this.Page.Master).SetError(GetType(), "The region is not unique within its parent region"); return; } SiteManager.CreateRegion(newRegion); PopulateTreeView <Region>(SiteManager.GetAllRegions(), true, false, string.Empty); RadTreeView1.DataBind(); RadTreeView1.FindNodeByText(newRegion.Name).ExpandParentNodes(); RadTreeView1.FindNodeByText(newRegion.ParentRegion.Name).Selected = true; ((IFeedback)this.Page.Master).ShowFeedback( BusiBlocksConstants.Blocks.Administration.LongName, newRegion.GetType().Name, Feedback.Actions.Created, newRegion.Name ); }
protected void AddSiteClick(object sender, EventArgs e) { string regionId = popAddSite.ReferrerId; string siteName = popAddSite.Value; // If this site name already exists, then error if (SiteManager.GetSiteByName(siteName) != null) { ((IFeedback)Page.Master).ShowFeedback(Feedback.Actions.Error, "Site " + siteName + " already exists"); } else { Region region = SiteManager.GetRegionById(regionId); Site site = new Site(); site.Name = siteName; site.Region = region; site.SiteType = SiteManager.GetAllSiteTypes().First(); SiteManager.CreateSite(site); this.PopulateTreeView <Region>(SiteManager.GetAllRegions(), true, false, string.Empty); RadTreeView1.DataBind(); RadTreeView1.FindNodeByText(region.Name).ExpandParentNodes(); RadTreeView1.FindNodeByText(region.Name).Selected = true; ((IFeedback)this.Page.Master).ShowFeedback( BusiBlocksConstants.Blocks.Administration.LongName, site.GetType().Name, Feedback.Actions.Created, site.Name ); } }
private void AddNodes <T>(T node, bool isAdmin, bool showNodeItems, IList <T> userAdminList, string personId) { var t = typeof(T); var nodes = from items in userAdminList select items; if (t.FullName.Contains("Region")) { Region r = node as Region; IList <Region> userRegionList = userAdminList as IList <Region>; if (r.ParentRegion != null) { if (RadTreeView1.FindNodeByText(r.ParentRegion.Name) != null) { AddSubNode(r, isAdmin, showNodeItems, userRegionList, personId); } else { IList <Region> regions = new List <Region>(); foreach (var item in nodes) { regions.Add(item as Region); } if (regions.Contains(r.ParentRegion))//if sub node's parent not add parent nodes first!. { AddParentNode(r.ParentRegion, isAdmin, showNodeItems, userRegionList, personId); } //add the node again after adding parent nodes. AddSubNode(r, isAdmin, showNodeItems, userRegionList, personId); } } } }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="nodeType"></param> /// <param name="isAdmin"></param> /// <param name="showNodeItems"></param> /// <param name="userAdminList"></param> protected void AddParentNode <T>(T nodeType, bool isAdmin, bool showNodeItems, IList <T> userAdminList, string personId) { var tempNodeType = typeof(T); string nodeText = ""; string nodeID; var t = nodeType; List <T> temp = new List <T>(); // todo the following code is dodgey. The check for a parent needs to be handled better. switch (tempNodeType.Name) { case "Category": if (tempNodeType.FullName.Contains("News")) { if ((nodeType as BusiBlocks.CommsBlock.News.Category).ParentCategory == null) { return; } nodeText = (nodeType as BusiBlocks.CommsBlock.News.Category).ParentCategory.Name; BusiBlocks.CommsBlock.News.Category x = NewsManager.GetCategoryByName(nodeText, true); t = (T)Convert.ChangeType(x, typeof(T)); } else if (tempNodeType.FullName.Contains("Doco")) { if ((nodeType as BusiBlocks.DocoBlock.Category).ParentCategory == null) { return; } nodeText = (nodeType as BusiBlocks.DocoBlock.Category).ParentCategory.DisplayName; nodeID = (nodeType as BusiBlocks.DocoBlock.Category).ParentCategory.Id; BusiBlocks.DocoBlock.Category x = DocoManager.GetCategory(nodeID); t = (T)Convert.ChangeType(x, typeof(T)); } break; case "Region": nodeText = (nodeType as Region).ParentRegion.Name; break; default: break; } if (RadTreeView1.FindNodeByText(nodeText) != null) { AddSubNode(nodeType, isAdmin, showNodeItems, userAdminList, personId); } else { //Add the parent node that does not have a parent node to a list. temp.Add(nodeType); AddParentNode(t, isAdmin, showNodeItems, userAdminList, personId); foreach (T item in temp) { AddSubNode(item, isAdmin, showNodeItems, userAdminList, personId); } } }
protected void AddCategoryClick(object sender, EventArgs e) { string categoryName = popAddCategory.Value; string categoryId = popAddCategory.ReferrerId; string categoryTypeName = string.Empty; // 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); categoryTypeName = news.GetType().Name; } catch (NewsCategoryNotFoundException) { } if (news != null) { BusiBlocks.CommsBlock.News.Category childCategory = NewsManager.CreateCategory(categoryName); childCategory.ParentCategory = news; NewsManager.UpdateCategory(childCategory); this.PopulateTreeView <BusiBlocks.CommsBlock.News.Category>(NewsManager.GetAllCategories(), true, false, string.Empty); } else { BusiBlocks.DocoBlock.Category doco = null; try { doco = DocoManager.GetCategory(categoryId); categoryTypeName = doco.GetType().Name; } catch (DocoCategoryNotFoundException) { } if (doco != null) { BusiBlocks.DocoBlock.Category childDocoCategory = DocoManager.CreateCategory(categoryName); childDocoCategory.ParentCategory = doco; DocoManager.UpdateCategory(childDocoCategory); this.PopulateTreeView <BusiBlocks.DocoBlock.Category>(DocoManager.GetAllCategories(), true, false, string.Empty); } } RadTreeView1.DataBind(); RadTreeView1.FindNodeByText(categoryName).ExpandParentNodes(); RadTreeView1.FindNodeByText(categoryName).Selected = true; ((IFeedback)this.Page.Master).ShowFeedback( BusiBlocksConstants.Blocks.Administration.LongName, categoryTypeName, Feedback.Actions.Created, categoryName ); } }
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; } }
protected void CreateCategoryNode <T>(T category, bool isAdmin) { var tempNode = typeof(T); string nodeName = string.Empty; string nodeId = string.Empty; string nodeParentName = string.Empty; string nodeParentId = string.Empty; string createLink = string.Empty; string createLinkText = string.Empty; bool hasAccess = false; var tempCategory = category; string createLinkStyle = string.Empty; if (tempNode.FullName.Contains("News")) { nodeName = (category as BusiBlocks.CommsBlock.News.Category).Name; nodeId = (category as BusiBlocks.CommsBlock.News.Category).Id; if ((category as BusiBlocks.CommsBlock.News.Category).ParentCategory != null) { nodeParentName = (category as BusiBlocks.CommsBlock.News.Category).ParentCategory.Name; nodeParentId = (category as BusiBlocks.CommsBlock.News.Category).ParentCategory.Id; } BusiBlocks.CommsBlock.News.Category x = NewsManager.GetCategoryByName(nodeName, true); tempCategory = (T)Convert.ChangeType(x, typeof(T)); createLink = Navigation.Communication_NewsCategoryNewItem(x).GetAbsoluteClientUrl(false); } else if (tempNode.FullName.Contains("Doco")) { nodeName = (category as BusiBlocks.DocoBlock.Category).DisplayName; nodeId = (category as BusiBlocks.DocoBlock.Category).Id; if ((category as BusiBlocks.DocoBlock.Category).ParentCategory != null) { nodeParentName = (category as BusiBlocks.DocoBlock.Category).ParentCategory.DisplayName; nodeParentId = (category as BusiBlocks.DocoBlock.Category).ParentCategory.Id; } BusiBlocks.DocoBlock.Category x = DocoManager.GetCategory(nodeId); tempCategory = (T)Convert.ChangeType(x, typeof(T)); createLink = Navigation.Doco_NewArticle(nodeId).GetAbsoluteClientUrl(false); } if (RadTreeView1.FindNodeByText(nodeName) == null) { RadTreeNode node = new RadTreeNode(nodeName, nodeId); string itemCount = string.Empty; //create node icons and links for new item. if (CategoryType == "News") { node.ImageUrl = "../app_themes/default/icons/commCat.gif"; var cat = NewsManager.GetCategory(nodeId); var newsItems = NewsManager.GetItems(cat, false); itemCount = NewsManager.CountItems(newsItems, Page.User.Identity.Name).ToString(); createLinkText = "Announcement"; createLinkStyle = "newAnnounce"; createLink = Navigation.Communication_NewsNewItem(NewsManager.GetCategory((category as BusiBlocks.CommsBlock.News.Category).Id)).GetAbsoluteClientUrl(false); } else if (CategoryType == "Doco") { node.ImageUrl = "../App_Themes/Default/icons/folder.png"; itemCount = DocoManager.CountItems(nodeId, Page.User.Identity.Name, Utilities.GetUserName(Page.User.Identity.Name)).ToString(); createLinkStyle = "newDoc"; createLinkText = "Document"; } Panel p = new Panel(); p.ID = "pnlNode"; p.CssClass = "tvNode"; Label lblName = new Label(); lblName.ID = "lblDivNodeName"; lblName.Text = nodeName + " (" + itemCount + ") "; Label lblContextMenu = new Label(); lblContextMenu.ID = "lblContextMenu"; lblContextMenu.CssClass = nodeId + "_tvContext hideElement"; //if user can edit then no need to check for contribute. hasAccess = SecurityHelper.CheckWriteAccess(Page.User.Identity.Name, nodeId); nodeName = "\'" + Utilities.EscapeSpecialCharacters(nodeName) + "\'"; if (isAdmin) { string url = tempNode.FullName.Contains("News") ? Navigation.Communication_NewsCategoryEditItem(nodeId).GetClientUrl(this, false) : Navigation.Admin_DocoDetails(nodeId).GetClientUrl(this, false); lblContextMenu.Text = "<a href=" + url + " class='edit'>Edit</a> "; string ParentCatId = string.Empty; //if all categories are listed as one node i.e. as list then the root is always null.(caters for any node with null parent) if (nodeParentId != string.Empty) { ParentCatId = nodeParentId; } lblContextMenu.Text += "<a href=# class='deleteitem' onclick=\"showDeleteCategoryPopup('Category','" + nodeId + "'," + nodeName + ",'','Delete');\">Delete</a> " +//delete link "<a href=# class='addCategory' onclick=\"showAddCategoryPopup('Category','" + nodeId + "',''," + nodeName + ",'Add');\">Add Category</a>"; } else { if (hasAccess) { lblContextMenu.Text = "<a href='" + createLink + "' class='" + createLinkStyle + "'>Create " + createLinkText + "</a>"; } } p.Controls.Add(lblName); p.Controls.Add(lblContextMenu); node.Controls.Add(p); RadTreeNode tNode = RadTreeView1.FindNode(x => x.Text.Contains(nodeParentName)); if (tNode == null) { RadTreeView1.Nodes.Add(node); } else if (nodeParentId != string.Empty) { if (tNode != null) { RadTreeView1.FindNodeByText(nodeParentName).Nodes.Add(node); } } else { RadTreeView1.Nodes.Add(node); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string nt = ""; try { nt = Session["NodeText"].ToString(); } catch { nt = "Admin Users"; } try { RadTreeView1.Nodes.FindNodeByText(nt).Selected = true; RadTreeView1.Nodes.FindNodeByText(nt).Expanded = true; } catch { } try { if (Session["user"] != null) { if (Session["AdminUserName"] != null) { lblwelcome.Text = "Welcome : " + Session["AdminUserName"].ToString(); } if (Session["AdminType"].ToString() == "President") { try { RadTreeView1.Nodes.FindNodeByText("Admin Users").Visible = false; RadTreeView1.Nodes.FindNodeByText("RI Presidents").Visible = false; RadTreeView1.Nodes.FindNodeByText("RI Awards").Visible = false; RadTreeView1.Nodes.FindNodeByText("Abbreviations").Visible = false; RadTreeView1.Nodes.FindNodeByText("Glossary").Visible = false; RadTreeView1.Nodes.FindNodeByText("Manage District No.").Visible = false; RadTreeView1.Nodes.FindNodeByText("RI & DG").Visible = false; RadTreeView1.Nodes.FindNodeByText("DGs & PDGs").Visible = false; RadTreeView1.Nodes.FindNodeByText("Roll of Honour").Visible = false; RadTreeView1.Nodes.FindNodeByText("Rotaract Clubs").Visible = false; RadTreeView1.Nodes.FindNodeByText("Interact Clubs").Visible = false; RadTreeView1.Nodes.FindNodeByText("District Awards").Visible = false; RadTreeView1.Nodes.FindNodeByText("Upcoming Events").Visible = false; RadTreeView1.Nodes.FindNodeByText("Manage Dollor Rate").Visible = false; RadTreeView1.Nodes.FindNodeByText("BOD Members").Visible = false; RadTreeView1.Nodes.FindNodeByText("BOD Position").Visible = false; RadTreeView1.Nodes.FindNodeByText("District Officers").Visible = false; RadTreeView1.Nodes.FindNodeByText("Change Admin Password").Visible = false; // Disabled / Visibility False for Child Nodes RadTreeNode node1 = RadTreeView1.FindNodeByText("Manage Members"); foreach (RadTreeNode childNode in node1.Nodes) { if (childNode.Text == "View Members") { childNode.Visible = false; } } RadTreeNode node2 = RadTreeView1.FindNodeByText("Manage Clubs"); foreach (RadTreeNode childNode in node2.Nodes) { if (childNode.Text == "View Clubs") { childNode.Visible = false; } } } catch { } } } else { Response.Redirect("Default.aspx"); } } catch { } } }