private void BuildColumnToClass() { // Set CMS.Document first foreach (string AllowedClass in AllowedPageTypes.Split(";,|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) { DataClassInfo PageTypeClass = DataClassInfoProvider.GetDataClassInfo(AllowedClass.Trim()); FormInfo PageTypeFormInfo = new FormInfo(PageTypeClass.ClassFormDefinition); foreach (string ColumnName in PageTypeFormInfo.ItemsList.Select(x => ((FormFieldInfo)x).Name.ToLower().Trim('[').Trim(']'))) { if (!ColumnsToDataClass.ContainsKey(ColumnName)) { ColumnsToDataClass.Add(ColumnName, PageTypeClass); } } FormFieldInfo PrimaryKeyField = (FormFieldInfo)PageTypeFormInfo.ItemsList.Where(x => ((FormFieldInfo)x).PrimaryKey).FirstOrDefault(); if (PrimaryKeyField != null) { ClassToPrimaryKeyColumn.Add(AllowedClass.ToLower(), PrimaryKeyField.Name); } } }
public void SetupControl() { // I believe/hope this is how you can pass the extension class CustomUniSelector.ContextResolver.SetNamedSourceData("UIContext", UIContext); CustomUniSelector.ObjectSiteName = ObjectSiteName; CustomUniSelector.DisplayNameFormat = DisplayNameFormat; CustomUniSelector.SelectionMode = (SelectionModeEnum)SelectionMode; if (!string.IsNullOrWhiteSpace(AdditionalColumns) || !string.IsNullOrWhiteSpace(AdditionalSearchColumns)) { BuildColumnToClass(); if (!string.IsNullOrWhiteSpace(AdditionalColumns)) { CustomUniSelector.AdditionalColumns = GetActualAdditionalColumns(); } if (!string.IsNullOrWhiteSpace(AdditionalSearchColumns)) { CustomUniSelector.AdditionalSearchColumns = GetActualAdditionalSearchColumns(); } } //CustomUniSelector.OrderBy = OrderBy; CustomUniSelector.EnabledColumnName = EnabledColumnName; CustomUniSelector.MaxDisplayedTotalItems = MaxDisplayedTotalItems; CustomUniSelector.MaxDisplayedItems = MaxDisplayedItems; CustomUniSelector.ItemsPerPage = ItemsPerPage; CustomUniSelector.FilterControl = FilterControl; CustomUniSelector.UseDefaultNameFilter = UseDefaultNameFilter; string where = ""; // Filter to show items not already selected if (ddlCurrentNodeDirection.SelectedValue == "LeftNode") { where = SqlHelper.AddWhereCondition(where, string.Format("NodeID not in (Select RightNodeID from CMS_Relationship where LeftNodeID = {1} and RelationshipNameID in (Select RelationshipNameID from CMS_RelationshipName where RelationshipName = '{0}'))", RelationshipName, CurrentNodeID)); } else { where = SqlHelper.AddWhereCondition(where, string.Format("NodeID not in (Select LeftNodeID from CMS_Relationship where RightNodeID = {1} and RelationshipNameID in (Select RelationshipNameID from CMS_RelationshipName where RelationshipName = '{0}'))", RelationshipName, CurrentNodeID)); } where = SqlHelper.AddWhereCondition(where, string.Format("NodeID <> {0}", CurrentNodeID)); // Filter for allowed page types if (!string.IsNullOrWhiteSpace(AllowedPageTypes)) { where = SqlHelper.AddWhereCondition(where, string.Format("NodeClassID in (select ClassID from CMS_Class where ClassName in ('{0}'))", string.Join("','", AllowedPageTypes.Split(";| ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) )); } // Filter Where Condition given if (!string.IsNullOrWhiteSpace(WhereCondition)) { where = SqlHelper.AddWhereCondition(where, WhereCondition); } CustomUniSelector.WhereCondition = where; // Pass custom tooltip CustomUniSelector.ToolTipFormat = ToolTipFormat; }
private void SetupControl() { pageTree.LineImagesFolder = "~/CMSModules/RelationshipsExtended/Controls/RelatedCategories_Files"; pageTree.NodeStyle.CssClass = "InputNode"; pageTree.ShowLines = true; // Build a list of the pages var docQuery = new DocumentQuery().OrderBy("NodeLevel, NodeOrder"); foreach (string Path in StartingPathArray) { docQuery.Path(Path, PathTypeEnum.Section); } if (!string.IsNullOrWhiteSpace(RelatedNodeSiteName)) { docQuery.OnSite(RelatedNodeSiteName); } List <CMS.DocumentEngine.TreeNode> Nodes = docQuery.TypedResult.ToList(); // Get existing selected nodes string where = string.Format("NodeClassID in (select ClassID from CMS_Class where ClassName in ('{0}'))", string.Join("','", AllowedPageTypes.Split(";| ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))); // Split off Where condition for if they provide a Where to filter out other items. string AdditionalWhere = where; // Filter to show items not already selected if (ddlCurrentNodeDirection.SelectedValue == "LeftNode") { where = SqlHelper.AddWhereCondition(where, string.Format("({0})", string.Format("NodeID in (Select RightNodeID from CMS_Relationship where LeftNodeID = {1} and RelationshipNameID in (Select RelationshipNameID from CMS_RelationshipName where RelationshipName = '{0}'))", RelationshipName, CurrentNodeID))); } else { where = SqlHelper.AddWhereCondition(where, string.Format("({0})", string.Format("NodeID in (Select LeftNodeID from CMS_Relationship where RightNodeID = {1} and RelationshipNameID in (Select RelationshipNameID from CMS_RelationshipName where RelationshipName = '{0}'))", RelationshipName, CurrentNodeID))); } where = SqlHelper.AddWhereCondition(where, string.Format("NodeID <> {0}", CurrentNodeID)); AlreadySelectedNodes = new DocumentQuery().Where(where).Columns("NodeID").Select(x => x.NodeID).ToList(); // Exclude the current node, can't relate a node to itself. AlreadySelectedNodes.Add(CurrentNodeID); // If the WhereCondition is set, also add any Nodes that match this to "Already selected" so they can't be selected // Filter on the where condition if given FilterSelectableNodes = false; List <int> VisibleNodes = new List <int>(); if (!string.IsNullOrWhiteSpace(WhereCondition)) { AdditionalWhere = SqlHelper.AddWhereCondition(AdditionalWhere, WhereCondition); FilterSelectableNodes = true; SelectableSelectedNodes.AddRange(new DocumentQuery().Where(AdditionalWhere).Columns("NodeID").Select(x => x.NodeID).ToList()); } pageTree.Nodes.Clear(); TreeNode RootNode = new TreeNode("[Tree Root]", "0") { SelectAction = TreeNodeSelectAction.None }; Dictionary <int, TreeNode> NodeIDToTreeNode = new Dictionary <int, TreeNode>(); NodeIDToTreeNode.Add(0, RootNode); // Build the tree for (int i = 0; i < Nodes.Count(); i++) { var Node = Nodes[i]; // Skip Root node if (string.IsNullOrWhiteSpace(Node.NodeName)) { continue; } TreeNode newNode = CreateTreeNode(Node); if (!NodeIDToTreeNode.ContainsKey(Node.NodeID)) { NodeIDToTreeNode.Add(Node.NodeID, newNode); } // Add to the parent if it exists, if it doesn't then add to root. if (NodeIDToTreeNode.ContainsKey(Node.NodeParentID)) { NodeIDToTreeNode[Node.NodeParentID].ChildNodes.Add(newNode); } else { NodeIDToTreeNode[0].ChildNodes.Add(newNode); } } if (RemoveUnselectableChildTrees) { HideUnselectableChildren(RootNode); } // Add root pageTree.Nodes.Add(RootNode); if (SelectionMode == "Checkbox") { btnAdd.Visible = true; } else { btnAdd.Visible = false; pageTree.SelectedNodeChanged += PageTree_SelectedNodeChanged; } }