⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basenavigator.cs

📁 ComponentArt Web.UI 2006.1252 for asp.net2.0
💻 CS
📖 第 1 页 / 共 5 页
字号:

        this.LoadXml(oDS.GetXml());
      }
      else if(this.DataSource is XmlDocument)
      {
        XmlDocument oXD = (XmlDocument)(this.DataSource);

        this.LoadXml(oXD.OuterXml);
      }
      else
      {
        throw new ArgumentException("DataSource must be a DataSet or XmlDocument.");
      }

      this.ComponentArtFixStructure();
      base.DataBind();
    }

    /// <summary>
    /// GetXml method.
    /// </summary>
    /// <returns>XML string represending the current structure of the data.</returns>
    /// <seealso cref="LoadXml" />
    public string GetXml()
    {
      XmlDocument oXmlDoc = new XmlDocument();
      XmlNode oTopNode = oXmlDoc.CreateElement("SiteMap");

      if(this.nodes != null)
      {
        GetXml(oXmlDoc, oTopNode, this.nodes);
      }

      return oTopNode.OuterXml;
    }
		
    /// <summary>
    /// Select the first selectable node.
    /// </summary>
    public void GoFirst()
    {
      if(!_globalNavigationPossible)
      {
        return;
      }

      // Go first in top group.
      this.selectedNode = nodes[0];
      
      if(this.selectedNode.NavigateUrl != string.Empty)
      {
        this.selectedNode.Navigate();
      }
      else if(this.selectedNode.AutoPostBackOnSelect)
      {
        this.selectedNodePostbackId = this.selectedNode.PostBackID;
      }
      else
      {
        GoNext();
      }
    }

    /// <summary>
    /// Select the first selectable node in the current group.
    /// </summary>
    public void GoFirstInGroup()
    {
      // None are selected or we are in the top group?
      if(this.selectedNode == null || this.selectedNode.parentNode == null)
      {
        GoFirst();
      }
      else
      {
        // Go first in current group.
        this.selectedNode = this.selectedNode.parentNode.nodes[0];
      }

      if(this.selectedNode.NavigateUrl != string.Empty)
      {
        this.selectedNode.Navigate();
      }
      else if(this.selectedNode.AutoPostBackOnSelect)
      {
        this.selectedNodePostbackId = this.selectedNode.PostBackID;
      }
      else
      {
        GoNextInGroup(false);
      }
    }

    /// <summary>
    /// Select the last selectable node.
    /// </summary>
    public void GoLast()
    {
      if(!_globalNavigationPossible)
      {
        return;
      }

      // Go last in top group.
      NavigationNode oNode = nodes[nodes.Count - 1];

      // Go to last descendant.
      while(oNode.nodes != null && oNode.nodes.Count > 0)
      {
        // Go to last child.
        oNode = oNode.nodes[oNode.nodes.Count - 1];
      }

      this.selectedNode = oNode;

      if(oNode.NavigateUrl != string.Empty)
      {
        oNode.Navigate();
      }
      else if(oNode.AutoPostBackOnSelect)
      {
        this.selectedNodePostbackId = this.selectedNode.PostBackID;
      }
      else
      {
        GoPrevious();
      }
    }

    /// <summary>
    /// Select the last selectable node in the current group.
    /// </summary>
    public void GoLastInGroup()
    {
      // None are selected or we are in the top group?
      if(this.selectedNode == null || this.selectedNode.parentNode == null)
      {
        if(nodes != null && nodes.Count > 0)
        {
          this.selectedNode = nodes[nodes.Count - 1];
        }
        else
        {
          return;
        }
      }
      else
      {
        // Go last in current group.
        this.selectedNode = selectedNode.parentNode.nodes[selectedNode.parentNode.nodes.Count - 1];
      }

      if(this.selectedNode.NavigateUrl != string.Empty)
      {
        this.selectedNode.Navigate();
      }
      else if(this.selectedNode.AutoPostBackOnSelect)
      {
        this.selectedNodePostbackId = this.selectedNode.PostBackID;
      }
      else
      {
        GoPreviousInGroup(false);
      }
    }

    /// <summary>
    /// Select the next selectable node.
    /// </summary>
    public void GoNext()
    {
      GoNext(false);
    }
    
    /// <summary>
    /// Select the next selectable node.
    /// </summary>
    /// <param name="bWrap">Whether to wrap to the beginning after reaching the end.</param>
    public void GoNext(bool bWrap)
    {
      NavigationNode oNode = FindNext(this.selectedNode, bWrap, false);

      if(oNode != null)
      {
        this.selectedNode = oNode;

        if(oNode.NavigateUrl != string.Empty)
        {
          oNode.Navigate();
        }
        else
        {
          this.selectedNodePostbackId = this.selectedNode.PostBackID;
        }
      }
    }

    /// <summary>
    /// Select the next selectable node in the current group.
    /// </summary>
    public void GoNextInGroup()
    {
      GoNextInGroup(false);
    }

    /// <summary>
    /// Select the next selectable node in the current group.
    /// </summary>
    /// <param name="bWrap">Whether to wrap to the beginning when we reach the end.</param>
    public void GoNextInGroup(bool bWrap)
    {
      if(this.selectedNode == null)
      {
        return;
      }

      NavigationNode oNode = this.selectedNode.nextSibling;

      while(oNode != null && oNode != this.selectedNode)
      {
        if(oNode.NavigateUrl != string.Empty || oNode.AutoPostBackOnSelect)
        {
          break;
        }

        // Move next
        oNode = oNode.nextSibling;
        
        // Wrap around potentially
        if(oNode == null && bWrap)
        {
          if(selectedNode.parentNode == null)
          {
            oNode = this.nodes[0];
          }
          else
          {
            oNode = selectedNode.parentNode.nodes[0];
          }
        }
      }

      if(oNode != null)
      {
        this.selectedNode = oNode;

        if(oNode.NavigateUrl != string.Empty)
        {
          oNode.Navigate();
        }
        else
        {
          this.selectedNodePostbackId = this.selectedNode.PostBackID;
        }
      }
    }

    /// <summary>
    /// Select the previous selectable node.
    /// </summary>
    public void GoPrevious()
    {
      GoPrevious(false);
    }

    /// <summary>
    /// Select the previous selectable node.
    /// </summary>
    /// <param name="bWrap">Whether to wrap around to the end after we pass the beginning.</param>
    public void GoPrevious(bool bWrap)
    {
      NavigationNode oNode = FindPrevious(this.selectedNode, bWrap);

      if(oNode != null)
      {
        this.selectedNode = oNode;

        if(oNode.NavigateUrl != string.Empty)
        {
          oNode.Navigate();
        }
        else
        {
          this.selectedNodePostbackId = this.selectedNode.PostBackID;
        }
      }
    }

    /// <summary>
    /// Select the previous selectable node in the current group.
    /// </summary>
    public void GoPreviousInGroup()
    {
      GoPreviousInGroup(false);
    }

    /// <summary>
    /// Select the previous selectable node in the current group.
    /// </summary>
    /// <param name="bWrap">Whether to wrap around to the end after we pass the beginning.</param>
    public void GoPreviousInGroup(bool bWrap)
    {
      if(this.selectedNode == null)
      {
        return;
      }

      NavigationNode oNode = this.selectedNode.previousSibling;

      while(oNode != null && oNode != this.selectedNode)
      {
        if(oNode.NavigateUrl != string.Empty || oNode.AutoPostBackOnSelect)
        {
          break;
        }

        // Move previous
        oNode = oNode.previousSibling;
        
        // Wrap around potentially
        if(oNode == null && bWrap)
        {
          if(selectedNode.parentNode == null)
          {
            oNode = this.nodes[this.nodes.Count - 1];
          }
          else
          {
            oNode = selectedNode.parentNode.nodes[selectedNode.parentNode.nodes.Count - 1];
          }
        }
      }

      if(oNode != null)
      {
        this.selectedNode = oNode;

        if(oNode.NavigateUrl != string.Empty)
        {
          oNode.Navigate();
        }
        else
        {
          this.selectedNodePostbackId = this.selectedNode.PostBackID;
        }
      }
    }

    /// <summary>
    /// Load structure from given XmlDocument.
    /// </summary>
    /// <param name="oXmlDoc">XmlDocument to load from</param>
    public void LoadXml(XmlDocument oXmlDoc)
    {
      if(nodes != null)
      {
        nodes.Clear();
      }

      XmlNodeList arRoots = oXmlDoc.DocumentElement.ChildNodes;
					
      // Add roots and process their children recursively
      foreach(XmlNode oNode in arRoots)
      {
        // Only process Xml elements (ignore comments, etc)
        if(oNode.NodeType == XmlNodeType.Element)
        {
          NavigationNode oNewNode = this.AddNode();
          this.LoadXmlNode(oNewNode, oNode);

          this.OnNodeDataBound(oNewNode, oNode);
        }
      }
    }

    /// <summary>
    /// Load structure from given XML string.
    /// </summary>
    /// <param name="sXml">XML string to load from</param>
    public void LoadXml(string sXml)
    {
      if(nodes != null)
      {
        nodes.Clear();
      }

      XmlDocument oXmlDoc = new XmlDocument();
      oXmlDoc.LoadXml(sXml);

      this.LoadXml(oXmlDoc);
    }

    /// <summary>
    /// Raise a postback event.
    /// </summary>
    /// <param name="eventArgument">Postback argument</param>
    public void RaisePostBackEvent(string eventArgument)
    {     
      this.HandlePostback(eventArgument);
    }

    /// <summary>
    /// Force the re-loading and re-binding of custom node templates.
    /// </summary>
    /// <seealso cref="NavigationNode.ServerTemplateId" />
    /// <seealso cref="ServerTemplates" />
    public void ReloadTemplates()
    {
      this.Controls.Clear();
      this.ComponentArtFixStructure();
      this.InstantiateTemplatedNodes(this.nodes);
    }

#endregion

    #region Protected Properties 

    /// <summary>
    /// ID of node to forcefully highlight. This will make it appear as it would when selected.
    /// </summary>
    [Description("ID of node to forcefully highlight.")]
    [Category("Behavior")]
    [DefaultValue("")]
    protected string ForceHighlightedNodeID
    {
      get
      {
        object o = ViewState["ForceHighlightedNodeID"]; 
        return (o == null) ? String.Empty : (string)o; 
      }

      set
      {
        ViewState["ForceHighlightedNodeID"] = value; 
      }
    }

    /// <summary>
    /// The collection of root nodes.
    /// </summary>
    internal NavigationNodeCollection nodes;
		
    /// <summary>
    /// A list of images to preload.
    /// </summary>
    private StringCollection _preloadImages;
    protected StringCollection PreloadImages
    {
      get
      {
        if(_preloadImages == null)
        {
          _preloadImages = new StringCollection();
        }

        return _preloadImages;
      }
    }

    /// <summary>
    /// The selected node.
    /// </summary>
    private NavigationNode _selectedNode;
    internal NavigationNode selectedNode
    {
      get 
      {
        if(_selectedNode == null)
        {
          object o = ViewState["SelectedNodeId"]; 
          if(o != null && this.nodes != null)
          {
            _selectedNode = (NavigationNode) this.FindNodeByPostBackId((string)o, this.nodes);
          }
        }
        
        return _selectedNode;
      }
      set 
      {
        _selectedNode = value;
        ViewState["SelectedNodeId"] = (value == null? null : value.PostBackID);
      }
    }

    private bool _globalNavigationPossible = false;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -