コード例 #1
0
    /// <summary>
    /// Creates node.
    /// </summary>
    /// <param name="uniNode">Node to create</param>
    protected TreeNode CreateNode(UniTreeNode uniNode)
    {
        var data = (DataRow)uniNode.ItemData;

        if (data == null)
        {
            return(null);
        }

        TreeNode node = new TreeNode();

        // Get data
        int childNodesCount = 0;

        if (!String.IsNullOrEmpty(ProviderObject.ChildCountColumn))
        {
            childNodesCount = ValidationHelper.GetInteger(data[ProviderObject.ChildCountColumn], 0);
        }

        // Node ID
        int nodeId = 0;

        if (!String.IsNullOrEmpty(ProviderObject.IDColumn))
        {
            nodeId = ValidationHelper.GetInteger(data[ProviderObject.IDColumn], 0);
        }

        // Node value
        string nodeValue = String.Empty;

        if (!String.IsNullOrEmpty(ProviderObject.ValueColumn))
        {
            nodeValue = nodeId.ToString();
        }

        string objectType = String.Empty;

        if (!String.IsNullOrEmpty(ProviderObject.ObjectTypeColumn))
        {
            objectType = ValidationHelper.GetString(data[ProviderObject.ObjectTypeColumn], "");

            // Add object type to value
            nodeValue += "_" + objectType;
        }

        // Caption
        string displayName = String.Empty;

        if (!String.IsNullOrEmpty(ProviderObject.CaptionColumn))
        {
            displayName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ValidationHelper.GetString(data[ProviderObject.CaptionColumn], "")));
        }

        // Display name, if caption is empty (or non existent)
        if (!String.IsNullOrEmpty(ProviderObject.DisplayNameColumn) && String.IsNullOrEmpty(displayName))
        {
            displayName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ValidationHelper.GetString(data[ProviderObject.DisplayNameColumn], "")));
        }

        // Path
        string nodePath = String.Empty;

        if (!String.IsNullOrEmpty(ProviderObject.PathColumn))
        {
            nodePath = HTMLHelper.HTMLEncode(ValidationHelper.GetString(data[ProviderObject.PathColumn], "")).ToLowerCSafe();
        }

        // Parent ID
        int parentId = 0;

        if (!String.IsNullOrEmpty(ProviderObject.ParentIDColumn))
        {
            parentId = ValidationHelper.GetInteger(data[ProviderObject.ParentIDColumn], 0);
        }

        // Parameter
        string parameter = String.Empty;

        if (!String.IsNullOrEmpty(ProviderObject.ParameterColumn))
        {
            parameter = HTMLHelper.HTMLEncode(ValidationHelper.GetString(data[ProviderObject.ParameterColumn], "")).ToLowerCSafe();
        }

        int nodeLevel = 0;

        if (!String.IsNullOrEmpty(ProviderObject.LevelColumn))
        {
            nodeLevel = ValidationHelper.GetInteger(data[ProviderObject.LevelColumn], 0);
        }

        // Set navigation URL to current page
        node.NavigateUrl = RequestContext.CurrentURL + "#";

        // Set value
        node.Value = nodeValue;

        // Get tree icon
        var treeIcon = GetNodeIconMarkup(uniNode, data);

        // Set text
        string text;

        string selectedItem      = ValidationHelper.GetString(SelectedItem, "");
        string selectPathLowered = SelectPath.ToLowerCSafe();

        if (nodeValue.EqualsCSafe(selectedItem, true) || ((selectPathLowered == nodePath) && String.IsNullOrEmpty(selectedItem)))
        {
            text = ReplaceMacros(SelectedNodeTemplate, nodeId, childNodesCount, displayName, treeIcon, parentId, objectType, parameter);
        }
        else
        {
            text = ReplaceMacros(NodeTemplate, nodeId, childNodesCount, displayName, treeIcon, parentId, objectType, parameter);
        }

        if (UsePostBack)
        {
            text = "<span onclick=\"" + ControlsHelper.GetPostBackEventReference(this, nodeValue + ";" + nodePath) + "\">" + text + "</span>";
        }

        node.Text = text;

        // Set populate node automatically
        if (childNodesCount != 0)
        {
            node.PopulateOnDemand = true;
        }

        // Expand tree
        if (ExpandAll)
        {
            node.Expanded = true;
        }
        else if (CollapseAll)
        {
            node.Expanded = false;
        }
        else
        {
            // Handle expand path
            if (!nodePath.EndsWith("/", StringComparison.OrdinalIgnoreCase))
            {
                nodePath += "/";
            }

            string expandPathLowered = ExpandPath.ToLowerCSafe();

            if (selectPathLowered.StartsWithCSafe(nodePath) && (selectPathLowered != nodePath))
            {
                node.Expanded = true;
            }
            else if ((expandPathLowered.StartsWithCSafe(nodePath)))
            {
                node.Expanded = true;
            }
            else
            // Path expanded by user
            if (selectedPath.StartsWithCSafe(nodePath) && (selectedPath != nodePath))
            {
                node.Expanded = true;
            }
            // Expand all roots for multiple roots tree
            else if ((parentId == 0) && MultipleRoots)
            {
                node.Expanded = true;
            }
            else
            {
                node.Expanded = false;
            }
        }

        // Expand level
        if ((ExpandLevel != 0) && !CollapseAll)
        {
            node.Expanded = nodeLevel <= ExpandLevel;
        }

        return(node);
    }
コード例 #2
0
ファイル: UniTree.ascx.cs プロジェクト: tvelzy/RadstackMedia
    /// <summary>
    /// Creates node.
    /// </summary>
    /// <param name="uniNode">Node to create</param>
    protected TreeNode CreateNode(UniTreeNode uniNode)
    {
        DataRow dr = (DataRow)uniNode.ItemData;

        if (dr != null)
        {
            TreeNode node = new TreeNode();

            // Get data
            int childNodesCount = 0;
            if (!string.IsNullOrEmpty(ProviderObject.ChildCountColumn))
            {
                childNodesCount = ValidationHelper.GetInteger(dr[ProviderObject.ChildCountColumn], 0);
            }

            // Node ID
            int nodeID = 0;
            if (!string.IsNullOrEmpty(ProviderObject.IDColumn))
            {
                nodeID = ValidationHelper.GetInteger(dr[ProviderObject.IDColumn], 0);
            }

            // Node value
            string nodeValue = string.Empty;
            if (!string.IsNullOrEmpty(ProviderObject.ValueColumn))
            {
                nodeValue = nodeID.ToString();
            }

            string objectType = string.Empty;
            if (!string.IsNullOrEmpty(ProviderObject.ObjectTypeColumn))
            {
                objectType = ValidationHelper.GetString(dr[ProviderObject.ObjectTypeColumn], "");

                // Add object type to value
                nodeValue += "_" + objectType;
            }

            // Display name
            string displayName = string.Empty;
            if (!string.IsNullOrEmpty(ProviderObject.DisplayNameColumn))
            {
                displayName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ValidationHelper.GetString(dr[ProviderObject.DisplayNameColumn], "")));
            }

            // Path
            string nodePath = string.Empty;
            if (!string.IsNullOrEmpty(ProviderObject.PathColumn))
            {
                nodePath = HTMLHelper.HTMLEncode(ValidationHelper.GetString(dr[ProviderObject.PathColumn], "")).ToLowerCSafe();
            }

            // Parent ID
            int parentID = 0;
            if (!string.IsNullOrEmpty(ProviderObject.ParentIDColumn))
            {
                parentID = ValidationHelper.GetInteger(dr[ProviderObject.ParentIDColumn], 0);
            }

            // Parameter
            string parameter = string.Empty;
            if (!string.IsNullOrEmpty(ProviderObject.ParameterColumn))
            {
                parameter = HTMLHelper.HTMLEncode(ValidationHelper.GetString(dr[ProviderObject.ParameterColumn], "")).ToLowerCSafe();
            }

            int nodeLevel = 0;
            if (!String.IsNullOrEmpty(ProviderObject.LevelColumn))
            {
                nodeLevel = ValidationHelper.GetInteger(dr[ProviderObject.LevelColumn], 0);
            }

            node.NavigateUrl = URLRewriter.CurrentURL + "#";

            // Set value
            node.Value = nodeValue;

            // Get image html tag
            string imgPath = string.Empty;

            if (!string.IsNullOrEmpty(ProviderObject.ImageColumn))
            {
                imgPath = ResolveUrl(ValidationHelper.GetString(dr[ProviderObject.ImageColumn], ""));
            }

            if (string.IsNullOrEmpty(imgPath))
            {
                imgPath = ResolveUrl(DefaultImagePath);
            }

            if (OnGetImage != null)
            {
                imgPath = ResolveUrl(OnGetImage(uniNode));
            }

            string imgTag = string.Empty;
            if (!string.IsNullOrEmpty(imgPath))
            {
                imgTag = "<img class=\"TreeItemImage\" alt=\"" + ResHelper.LocalizeString(displayName) + "\" src=\"" + HTMLHelper.HTMLEncode(imgPath) + "\"/>";
            }

            // Set text
            string text = null;

            string selectedItem      = ValidationHelper.GetString(SelectedItem, "");
            string selectPathLowered = SelectPath.ToLowerCSafe();

            if (nodeValue.EqualsCSafe(selectedItem, true) || ((selectPathLowered == nodePath) && string.IsNullOrEmpty(selectedItem)))
            {
                text = ReplaceMacros(SelectedNodeTemplate, nodeID, childNodesCount, displayName, imgTag, parentID, objectType, parameter);
            }
            else
            {
                text = ReplaceMacros(NodeTemplate, nodeID, childNodesCount, displayName, imgTag, parentID, objectType, parameter);
            }

            if (UsePostBack)
            {
                text = "<span onclick=\"" + ControlsHelper.GetPostBackEventReference(this, nodeValue + ";" + nodePath) + "\">" + text + "</span>";
            }

            node.Text = text;

            // Set populate node automatically
            if (childNodesCount != 0)
            {
                node.PopulateOnDemand = true;
            }

            // Expand tree
            if (ExpandAll)
            {
                node.Expanded = true;
            }
            else if (CollapseAll)
            {
                node.Expanded = false;
            }
            else
            {
                // Handle expand path
                if (!nodePath.EndsWith("/"))
                {
                    nodePath += "/";
                }

                string expandPathLowered = ExpandPath.ToLowerCSafe();
                // SelectPath property
                if (selectPathLowered.StartsWithCSafe(nodePath) && (selectPathLowered != nodePath))
                {
                    node.Expanded = true;
                }
                // ExpandPath property
                else if ((expandPathLowered.StartsWithCSafe(nodePath)))
                {
                    node.Expanded = true;
                }
                // Path expanded by user
                else if (selectedPath.StartsWithCSafe(nodePath) && (selectedPath != nodePath))
                {
                    node.Expanded = true;
                }
                else
                {
                    node.Expanded = false;
                }
            }

            // Expand level
            if ((ExpandLevel != 0) && !CollapseAll)
            {
                node.Expanded = nodeLevel <= ExpandLevel;
            }

            return(node);
        }
        return(null);
    }