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

📄 basenavigator.cs

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

#endregion

    #region Protected Methods 

    protected abstract NavigationNode AddNode();
    
    protected abstract NavigationNode NewNode();

    protected void LoadClientData(string sData)
    {
      try
      {
        if (sData != string.Empty)
        {
          this.nodes.Clear();
          
          sData = HttpUtility.UrlDecode(sData, Encoding.Default);

          // make it xml-safe
          sData = sData.Replace("&", "#$cAmp@*");

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

          XmlNode oRootNode = oXmlDoc.DocumentElement;

          if (oRootNode != null && oRootNode.ChildNodes.Count > 0)
          {
            this.LoadClientXmlNodes(oRootNode.ChildNodes, -1, this.nodes);

            // fix up pointers
            this.ComponentArtFixStructure();
          }
        }
      }
      catch (Exception ex)
      {
        throw new Exception("Error loading client data: " + ex);
      }
    }

    protected void LoadClientProperties(string sData)
    {
      try
      {
        if (sData != string.Empty)
        {
          sData = HttpUtility.UrlDecode(sData, Encoding.Default);

          // make it xml-safe
          sData = sData.Replace("&", "#$cAmp@*");

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

          XmlNode oRootNode = oXmlDoc.DocumentElement;

          if (oRootNode != null)
          {
            if (oRootNode.ChildNodes.Count > 0)
            {
              this.LoadClientXmlProperties(oRootNode.ChildNodes, this.Properties);
            }
          }
        }
      }
      catch(Exception ex)
      {
        throw new Exception("Error loading client properties: " + ex);
      }
    }

    protected NavigationNode LoadClientXmlNode(XmlNodeList arClientNodes, XmlNodeList arXmlMembers)
    {
      NavigationNode oNode = NewNode();

      // postback ID
      if (arXmlMembers[0].FirstChild != null)
      {
        oNode.PostBackID = arXmlMembers[0].FirstChild.InnerText;
      }

      // are there properties on this node?
      if (arXmlMembers[3].FirstChild.ChildNodes.Count > 0)
      {
        XmlNodeList arProperties = arXmlMembers[3].FirstChild.ChildNodes;

        this.LoadClientXmlNodeProperties(arProperties, oNode);
      }

      if (arXmlMembers[2].FirstChild.ChildNodes.Count > 0)
      {
        // load children!
        LoadClientXmlNodes(arClientNodes, arXmlMembers[2].FirstChild.ChildNodes, oNode.nodes);
      }

      return oNode;
    }

    protected void LoadClientXmlNodes(XmlNodeList arClientNodes, int iParentIndex, NavigationNodeCollection arNodes)
    {
      string sParentIndex = iParentIndex.ToString();

      foreach(XmlNode oNode in arClientNodes)
      {
        if(oNode.ChildNodes.Count > 0)
        {
          XmlNodeList arElements = oNode.FirstChild.ChildNodes;

          if(arElements[1].InnerText == sParentIndex)
          {
            NavigationNode oNavNode = LoadClientXmlNode(arClientNodes, arElements);
            arNodes.Add(oNavNode);
          }
        }
      }
    }

    protected void LoadClientXmlNodes(XmlNodeList arClientNodes, XmlNodeList arChildIndices, NavigationNodeCollection arNodes)
    {
      foreach(XmlNode oIndex in arChildIndices)
      {
        if(oIndex.InnerText.Length > 0)
        {
          int iIndex = int.Parse(oIndex.InnerText);

          NavigationNode oChildNode = LoadClientXmlNode(arClientNodes, arClientNodes[iIndex].FirstChild.ChildNodes);
          arNodes.Add(oChildNode);
        }
      }
    }

    protected void LoadClientXmlNodeProperties(XmlNodeList arXmlProperties, NavigationNode oNode)
    {
      foreach(XmlNode arProperty in arXmlProperties)
      {
        string sPropertyName = arProperty.FirstChild.FirstChild.InnerText;
        if (Utils.CanParseAsInt(sPropertyName))
        {
          sPropertyName = this.PropertyIndex[sPropertyName].ToString();
        }

        string sPropertyValue = (arProperty.FirstChild.ChildNodes.Count > 1) ? arProperty.FirstChild.LastChild.InnerText : ""; // handle undefined values

        sPropertyValue = sPropertyValue.Replace("#$cAmp@*", "&");

        oNode.Properties[oNode.GetAttributeVarName(sPropertyName)] = sPropertyValue;
      }
    }

    protected void LoadClientXmlProperties(XmlNodeList arXmlProperties, System.Web.UI.AttributeCollection arProperties)
    {
      foreach(XmlNode arProperty in arXmlProperties)
      {
        string sPropertyName = arProperty.FirstChild.FirstChild.InnerText;
        string sPropertyValue = (arProperty.FirstChild.ChildNodes.Count > 1) ? arProperty.FirstChild.LastChild.InnerText : ""; // handle undefined values

        sPropertyValue = sPropertyValue.Replace("#$cAmp@*", "&");

        arProperties[sPropertyName] = sPropertyValue;
      }
    }
    
    private Hashtable _propertyIndex;
    internal virtual Hashtable PropertyIndex
    {
      get
      {
        if (_propertyIndex == null)
        {
          _propertyIndex = new Hashtable();
        }
        return _propertyIndex;
      }
    }

    private System.Web.UI.AttributeCollection _properties;
    internal System.Web.UI.AttributeCollection Properties
    {
      get
      {
        if(_properties == null)
        {
          StateBag oBag = new StateBag(true);
          _properties = new System.Web.UI.AttributeCollection(oBag);
        }

        return _properties;
      }
      set
      {
        _properties = value;
      }
    }

    protected override void ComponentArtRender(HtmlTextWriter output)
    {
      // last chance to fix structure before render
      ComponentArtFixStructure();

      // figure out which node is current, if any
      if(this.selectedNode == null)
      {
        this.UpdateSelectedNode();
      }

      if (this.MultiPageId != null && this.MultiPageId != "")
      {
        // First try to find the corresponding MultiPage nearby (maybe within a user control we're both in)
        Control multiPage = Utils.FindControl(this, this.MultiPageId);
        
        if (multiPage is MultiPage)
          this._multiPageId = multiPage.ClientID; // resolve the MultiPageId
        else
          throw new Exception("Target MultiPage control (" + this.MultiPageId + ") not found on the page.");
      }
    }

    internal string ConvertUrl(string sUrl)
    {
      return Utils.ConvertUrl(Context, this.BaseUrl, sUrl);	
    }

    internal string ConvertImageUrl(string sImageUrl)
    {
      return Utils.ConvertUrl(Context, this.ImagesBaseUrl, sImageUrl);	
    }

    protected override void CreateChildControls()
    {
      if(this.ServerTemplates.Count > 0 && this.nodes != null)
      {
        this.Controls.Clear();
        this.ComponentArtFixStructure();
        this.InstantiateTemplatedNodes(this.nodes);
      }
    }

    /// <summary>
    /// Find the selectable node following the given one in the structure.
    /// </summary>
    /// <param name="oStart">Node to start from.</param>
    /// <param name="bWrap">Whether to wrap when the end is reached.</param>
    /// <param name="bNoDeeper">Whether to not go deeper in the structure when looking.</param>
    /// <returns>The found node.</returns>
    private NavigationNode FindNext(NavigationNode oStart, bool bWrap, bool bNoDeeper)
    {
      if(!_globalNavigationPossible)
      {
        return null;
      }

      // None are selected?
      if(oStart == null)
      {
        return FindNext(this.nodes[0], bWrap, false);
      }
      else if(oStart.nodes != null && oStart.nodes.Count > 0 && !bNoDeeper) // Do we have children?
      {
        oStart = oStart.nodes[0];
      }
      else if(oStart.nextSibling != null) // Do we have siblings?
      {
        oStart = oStart.nextSibling;
      }
      else if(oStart.parentNode != null) // Do we have a parent?
      {
        oStart = oStart.parentNode;
        return FindNext(oStart, bWrap, true);
      }
      else if(bWrap) // Do we wrap around?
      {
        oStart = nodes[0];
      }
      else
      {
        return null;
      }

      // does the found node qualify?
      if(oStart.NavigateUrl != string.Empty || oStart.AutoPostBackOnSelect)
      {
        return oStart;
      }
      else if(oStart != this.selectedNode)
      {
        return FindNext(oStart, bWrap, false);
      }
      else
      {
        return null;
      }
    }

    private NavigationNode FindNodeById(string sNodeID, NavigationNodeCollection arNodes)
    {
      foreach(NavigationNode oNode in arNodes)
      {
        if(oNode.ID == sNodeID)
        {
          return oNode;
        }
				
        if(oNode.nodes != null)
        {
          NavigationNode oFoundBelow = FindNodeById(sNodeID, oNode.nodes);

          if(oFoundBelow != null)
          {
            return oFoundBelow;
          }
        }
      }

      return null;
    }

    /// <summary>
    /// Find the node with the given ID.
    /// </summary>
    /// <param name="sNodeID">The ID to search for.</param>
    /// <returns>The found node or null.</returns>
    protected NavigationNode FindNodeById(string sNodeID)
    {
      if(this.nodes != null)
      {
        return FindNodeById(sNodeID, this.nodes);
      }
      else
      {
        return null;
      }
    }
	 
    protected NavigationNode FindNodeByPostBackId(string sPostBackID, NavigationNodeCollection arNodes)
    {
      if(arNodes == null)
      {
        return null;
      }

      foreach(NavigationNode oNode in arNodes)
      {
        if(oNode.PostBackID == sPostBackID)
        {
          return oNode;
        }
				
        if(oNode.nodes != null)
        {
          NavigationNode oFoundBelow = FindNodeByPostBackId(sPostBackID, oNode.nodes);

          if(oFoundBelow != null)
          {
            return oFoundBelow;
          }
        }
      }

      return null;
    }

    /// <summary>
    /// Find the selectable node preceding the given one in the structure.
    /// </summary>
    /// <param name="oStart">Node to start from.</param>
    /// <param name="bWrap">Whether to wrap when the beginning is reached.</param>
    /// <returns>The found node.</returns>
    private NavigationNode FindPrevious(NavigationNode oStart, bool bWrap)
    {
      if(!_globalNavigationPossible)
      {
        return null;
      }

      // None are selected?
      if(oStart == null)
      {
        return FindNext(this.nodes[0], bWrap, false);
      }
      else if(oStart.previousSibling != null) // Do we have siblings?
      {
        oStart = oStart.previousSibling;

        // Does the new selected node have children?
        while(oStart.nodes != null && oStart.nodes.Count > 0)
        {
          oStart = oStart.nodes[oStart.nodes.Count - 1];
        }
      }
      else if(oStart.parentNode != null) // Do we have a parent?
      {
        oStart = oStart.parentNode;
      }
      else if(bWrap) // Do we wrap around?
      {
        oStart = nodes[nodes.Count - 1];
        while(oStart.nodes != null && oStart.nodes.Count > 0)
        {
          oStart = oStart.nodes[oStart.nodes.Count - 1];
        }
      }
      else
      {
        return null;
      }

      // does the found node qualify?
      if(oStart.NavigateUrl != string.Empty || oStart.AutoPostBackOnSelect)
      {
        return oStart;
      }
      else
      {
        return FindPrevious(oStart, bWrap);
      }
    }

    internal NavigationCustomTemplate FindTemplateById(string sTemplateId)
    {
      foreach(NavigationCustomTemplate oTemplate in ServerTemplates)
      {
        if(oTemplate.ID == sTemplateId)
        {
          return oTemplate;
        }
      }
      
      return null;
    }

    /// <summary>
    /// This function is used to resolve the various references and unique IDs that ensure
    /// a sound tree structure.
    /// </summary>
    protected virtual void ComponentArtFixStructure()
    {
      FixStructureStep(null, this.nodes, 0);
    }

    private int FixStructureStep (
      NavigationNode oParent,
      NavigationNodeCollection arNodes,
      int counter )
    {
      if(arNodes == null)
      {
        return counter;
      }

      NavigationNode oPreviousNode = null;

      foreach(NavigationNode oNode in arNodes)
      {
        if(oNode.ID == null || oNode.ID == string.Empty)
        {
          oNode.PostBackID = String.Format("p{0:X}", counter);
        }
        else
        {
          oNode.PostBackID = "p_" + oNode.ID;
        }
			
        // set parent pointer
        oNode.parentNode = oParent;

        // set navigator
        oNode.navigator = this;

        // do we have a navigable?
        if(!_globalNavigationPossible &&
          (oNode.NavigateUrl != string.Empty || oNode.AutoPostBackOnSelect))
        {
          _globalNavigationPossible = true;
        }
        
        // Deprecate TemplateId, and use ServerTemplateId instead
        if (oNode.Properties["TemplateId"] != null)
        {
          if (oNode.Properties["ServerTemplateId"] == null)
          {
            oNode.Properties["ServerTemplateId"] = oNode.Properties["TemplateId"];
          }
          oNode.Properties.Remove("TemplateId");
        }

⌨️ 快捷键说明

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