void BuildOneLevel(StringBuilder text, XmlNode parent) { string strName = ""; string strCount = ""; string strUrl = ""; bool bSelected = false; bool bClosed = true; if (this.GetNodeData != null) { GetNodeDataEventArgs e = new GetNodeDataEventArgs(); e.Node = parent; this.GetNodeData(this, e); strName = e.Name; strCount = e.Count; strUrl = e.Url; bSelected = e.Seletected; bClosed = e.Closed; } else { strName = DomUtil.GetAttr(parent, "name"); strUrl = DomUtil.GetAttr(parent, "url"); } if (string.IsNullOrEmpty(strName) == false) { List <string> li_classes = new List <string>();; if (bClosed == true) { li_classes.Add("closed"); } string strLiClass = ""; if (li_classes.Count > 0) { strLiClass = " class='" + StringUtil.MakePathList(li_classes, " ") + "' "; } text.Append("<li" + strLiClass + ">"); List <string> text_classes = new List <string>(); if (bSelected == true) { text_classes.Add("selected"); } { // text_classes.Add("name"); string strTextClass = ""; if (text_classes.Count > 0) { strTextClass = " class='" + StringUtil.MakePathList(text_classes, " ") + "' "; } if (this.EventMode == true) { string strValueID = this.m_value.ClientID; string strButtonID = this.m_button.ClientID; // text.Append("<a " + strTextClass + " data-url='"+HttpUtility.HtmlAttributeEncode(strUrl)+"' href='#' onclick='javascript:$(\"input[id="+strValueID+"]\").val($(this).data(\"url\"));$(\"#"+strButtonID+"\").trigger(\"click\");'>" + HttpUtility.HtmlEncode(strName) + "</a>"); text.Append("<a " + strTextClass + " data-url='" + HttpUtility.HtmlAttributeEncode(strUrl) + "' href='#' onclick='$(\"#" + strValueID + "\").val($(this).data(\"url\"));$(\"#" + strButtonID + "\").trigger(\"click\");'>" + HttpUtility.HtmlEncode(strName) + "</a>"); // text.Append("<a " + strTextClass + " data-name='" + HttpUtility.HtmlAttributeEncode("test name") + "' href='#' onclick='javascript:OnTreeClick(this);'>" + HttpUtility.HtmlEncode(strName) + "</a>"); } else { if (string.IsNullOrEmpty(strUrl) == false) { text.Append("<a " + strTextClass + " href='" + strUrl + "'>" + HttpUtility.HtmlEncode(strName) + "</a>"); } else { text.Append("<span " + strTextClass + ">" + HttpUtility.HtmlEncode(strName) + "</span>"); } } /* * if (string.IsNullOrEmpty(strCount) == false) * text.Append("<span class='count'>"+HttpUtility.HtmlEncode(strCount)+"</span>"); * */ } if (string.IsNullOrEmpty(strCount) == false) { text_classes.Remove("name"); text_classes.Add("count"); string strTextClass = ""; if (text_classes.Count > 0) { strTextClass = " class='" + StringUtil.MakePathList(text_classes, " ") + "' "; } text.Append("<span " + strTextClass + ">" + HttpUtility.HtmlEncode(strCount) + "</span>"); } } StringBuilder inner_text = new StringBuilder(4095); foreach (XmlNode node in parent.ChildNodes) { BuildOneLevel(inner_text, node); } if (inner_text.Length > 0) { text.Append("<ul>"); text.Append(inner_text); text.Append("</ul>"); } if (string.IsNullOrEmpty(strName) == false) { text.Append("</li>"); } }
protected void TreeView1_GetNodeData(object sender, GetNodeDataEventArgs e) { /* if (e.Node == e.Node.OwnerDocument.DocumentElement) return; * */ if (e.Node.Name[0] == '_') return; string strName = DomUtil.GetAttr(e.Node, "name"); if (string.IsNullOrEmpty(strName) == true) return; bool bCommand = true; string strCommand = DomUtil.GetAttr(e.Node, "command"); if (string.IsNullOrEmpty(strCommand) == false && strCommand[0] == '~') bCommand = false; /// string strSideBarFileName = Path.GetFileName(this.SideBarControl1.CfgFile).ToLower(); string strDataFile = Path.GetFileName(this.TreeView1.XmlFileName).ToLower(); string strNodePath = CacheBuilder.MakeNodePath(e.Node); string strCount = ""; if (bCommand == true) { strCount = app.GetBrowseNodeCount(strDataFile, strNodePath); if (string.IsNullOrEmpty(strCount) == true && app.CacheBuilder != null) { long lCount = app.CacheBuilder.GetCountByNodePath(strDataFile, strNodePath, false); if (lCount == -1) strCount = "?"; else strCount = lCount.ToString(); app.SetBrowseNodeCount(strDataFile, strNodePath, strCount); } } if (string.IsNullOrEmpty(strCount) == false) { // e.Name = strName + " (" + strCount + ")"; e.Name = strName; e.Count = strCount; } else e.Name = strName; if (strNodePath == this.SelectingNodePath) { e.Seletected = true; /* // 如果有更适合的标题文字 if (string.IsNullOrEmpty(this.SelectedNodeCaption) == false) e.Name = this.SelectedNodeCaption; * */ } // TODO: 是否可以给每个节点都显示包含记录的数字? 为了提高速度,是否可以用一个hashtable来存储这个数字对照关系? string strSideBarParam = ""; if (string.IsNullOrEmpty(strSideBarFileName) == false) strSideBarParam = "&sidebar=" + HttpUtility.UrlEncode(strSideBarFileName); string strFormatParam = ""; if (string.IsNullOrEmpty(this.BrowseSearchResultControl1.CurrentFormat) == false) strFormatParam = "&format=" + HttpUtility.UrlEncode(this.BrowseSearchResultControl1.CurrentFormat); else if (string.IsNullOrEmpty(this.BrowseSearchResultControl1.FormatName) == false) strFormatParam = "&format=" + HttpUtility.UrlEncode(this.BrowseSearchResultControl1.FormatName); e.Url = "./browse.aspx?datafile="+HttpUtility.UrlEncode(strDataFile)+ strSideBarParam + "&node=" + strNodePath + strFormatParam; if (e.Node == e.Node.OwnerDocument.DocumentElement || IsParentPath(strNodePath, this.SelectingNodePath) == true) e.Closed = false; }
protected void TreeView1_GetNodeData(object sender, GetNodeDataEventArgs e) { if (e.Node.Name[0] == '_') return; if (m_nodes == null) { // 首次初始化 m_nodes = GetParentNodes(e.Node.OwnerDocument.DocumentElement, this.TreeView1.SelectedNodePath); } string strName = DomUtil.GetAttr(e.Node, "name"); if (string.IsNullOrEmpty(strName) == true) return; string strDate = DomUtil.GetAttr(e.Node, "date"); // string strDataFile = Path.GetFileName(this.TreeView1.XmlFileName).ToLower(); e.Name = strName; if (strDate == this.TreeView1.SelectedNodePath) { e.Seletected = true; } /* string strDateParam = ""; if (string.IsNullOrEmpty(strDate) == false) strDateParam = "&date=" + HttpUtility.UrlEncode(strDate); e.Url = "./statischart.aspx?" + strDateParam; * */ e.Url = strDate; // if (e.Node == e.Node.OwnerDocument.DocumentElement) if (this.m_nodes != null && this.m_nodes.Count > 0) { if (this.m_nodes.IndexOf(e.Node) != -1) e.Closed = false; } else e.Closed = false; }
void BuildOneLevel(StringBuilder text, XmlNode parent) { string strName = ""; string strCount = ""; string strUrl = ""; bool bSelected = false; bool bClosed = true; if (this.GetNodeData != null) { GetNodeDataEventArgs e = new GetNodeDataEventArgs(); e.Node = parent; this.GetNodeData(this, e); strName = e.Name; strCount = e.Count; strUrl = e.Url; bSelected = e.Seletected; bClosed = e.Closed; } else { strName = DomUtil.GetAttr(parent, "name"); strUrl = DomUtil.GetAttr(parent, "url"); } if (string.IsNullOrEmpty(strName) == false) { List<string> li_classes = new List<string>(); ; if (bClosed == true) li_classes.Add("closed"); string strLiClass = ""; if (li_classes.Count > 0) strLiClass = " class='" + StringUtil.MakePathList(li_classes, " ") + "' "; text.Append("<li" + strLiClass + ">"); List<string> text_classes = new List<string>(); if (bSelected == true) text_classes.Add("selected"); { // text_classes.Add("name"); string strTextClass = ""; if (text_classes.Count > 0) strTextClass = " class='" + StringUtil.MakePathList(text_classes, " ") + "' "; if (this.EventMode == true) { string strValueID = this.m_value.ClientID; string strButtonID = this.m_button.ClientID; // text.Append("<a " + strTextClass + " data-url='"+HttpUtility.HtmlAttributeEncode(strUrl)+"' href='#' onclick='javascript:$(\"input[id="+strValueID+"]\").val($(this).data(\"url\"));$(\"#"+strButtonID+"\").trigger(\"click\");'>" + HttpUtility.HtmlEncode(strName) + "</a>"); text.Append("<a " + strTextClass + " data-url='" + HttpUtility.HtmlAttributeEncode(strUrl) + "' href='#' onclick='$(\"#" + strValueID + "\").val($(this).data(\"url\"));$(\"#" + strButtonID + "\").trigger(\"click\");'>" + HttpUtility.HtmlEncode(strName) + "</a>"); // text.Append("<a " + strTextClass + " data-name='" + HttpUtility.HtmlAttributeEncode("test name") + "' href='#' onclick='javascript:OnTreeClick(this);'>" + HttpUtility.HtmlEncode(strName) + "</a>"); } else { if (string.IsNullOrEmpty(strUrl) == false) text.Append("<a " + strTextClass + " href='" + strUrl + "'>" + HttpUtility.HtmlEncode(strName) + "</a>"); else text.Append("<span " + strTextClass + ">" + HttpUtility.HtmlEncode(strName) + "</span>"); } /* if (string.IsNullOrEmpty(strCount) == false) text.Append("<span class='count'>"+HttpUtility.HtmlEncode(strCount)+"</span>"); * */ } if (string.IsNullOrEmpty(strCount) == false) { text_classes.Remove("name"); text_classes.Add("count"); string strTextClass = ""; if (text_classes.Count > 0) strTextClass = " class='" + StringUtil.MakePathList(text_classes, " ") + "' "; text.Append("<span " + strTextClass + ">" + HttpUtility.HtmlEncode(strCount) + "</span>"); } } StringBuilder inner_text = new StringBuilder(4095); foreach (XmlNode node in parent.ChildNodes) { BuildOneLevel(inner_text, node); } if (inner_text.Length > 0) { text.Append("<ul>"); text.Append(inner_text); text.Append("</ul>"); } if (string.IsNullOrEmpty(strName) == false) { text.Append("</li>"); } }