A recursive processing JSON tree node help class __js

Source: Internet
Author: User

Using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.Hosting;
using System.Security.Permissions;
using System.Text;
using Clientcontrol;

<summary>
Summary description of Exttree
</summary>
public class Exttree
{
private string _xmlpath;
private static Exttree exttree = null;
public static Exttree Current
{
Get
{
if (Exttree = null)
Exttree = new Exttree ();

return exttree;
}
}

DataTable Dttree = new DataTable ();

private string Logidid = String. Empty;
private string SessionID = String. Empty;

Private Exttree ()
{
Initxmlpath ();
Getallnodes ();
}

private void Initxmlpath ()
{
String Xmlpath = "~/app_data/tree.xml";
_xmlpath = Hostingenvironment.mappath (Xmlpath);
FileIOPermission Permission = new FileIOPermission (Fileiopermissionaccess.write, _xmlpath);
Permission. Demand ();
}

Private DataTable Getallnodes ()
{
Ds. READXML (_xmlpath);
Dttree = Mainclientcontrol.instance (). Gettree (This.logidid, This.sessionid);
return dttree;
}

Private DataTable Getallnodes (String parentid)
{
DataTable dt = Getallnodes ();
DataTable dt = Dttree;
DataTable _dt = dt. Clone ();

datarow[] DRS = dt. Select ("ParentID = '" + parentid.) ToString () + "'");
if (DRS). Length > 0)
//{
foreach (DataRow Dr in Drs)
//    {
_dt. ImportRow (DR);
//    }
//}
foreach (DataRow dr in Dt. Rows)
{
if (dr["ParentID"]. ToString () = = ParentID. ToString ())
_dt. Rows.Add (Dr. ItemArray);
}
return _DT;
}

public string Createexttreejson (String logidid,string SessionID)
{
This.logidid = Logidid;
This.sessionid = SessionID;
Getallnodes ();
StringBuilder sb = new StringBuilder ();
Createexttreenode (SB);
String s= sb. ToString ();
Return S.replace ("{", "},{");
}
/*
* EXT Tree JSON Data part Properties Description:
* Text: The node file to display
* ID: This doesn't have to be explained.
* HREF: Link address
* Hreftarget: Link Target frame name
* Children: Sub-node format: [{Node 1},{Node 2} ...]
* Leaf: Whether the current node is a leaf node. If False, this node has child nodes.
* Otherwise true, this node is in a child-free node
* */
private void Createexttreenode (StringBuilder sb)
{
DataTable dt = Getallnodes ("0");
if (dt. Rows.Count > 0)
{
Sb. Append ("[");
foreach (DataRow dr in Dt. Rows)
{
Sb. Append ("{");
Sb. Append ("text:" + dr["title"]. ToString () + "',");
if (This.logidid = = "9999")
{
Sb. Append ("Checked:false,");
}
Sb. Append ("ID: ' node" + dr["id"]. ToString () + "',");
Sb. Append ("ID:" + dr["id"]. ToString () + "',");
Sb. Append ("href:" + dr["url"]. ToString () + "',");
Sb. Append ("Hreftarget: ' Main '");
Addchildrennode (Getallnodes (dr["id"). ToString ()), SB);
Sb. Append ("}");
}
}

Sb. Append ("]");
}

private void Addchildrennode (DataTable dt,stringbuilder SB)
{
if (dt. Rows.Count > 0)
{
Sb. Append (", leaf:false,children:[");
foreach (DataRow dr in Dt. Rows)
{
Sb. Append ("{");
Sb. Append ("text:" + dr["title"]. ToString () + "',");
if (This.logidid = = "9999")
{
Sb. Append ("Checked:false,");
}
Sb. Append ("ID: ' node" + dr["id"]. ToString () + "',");
Sb. Append ("ID:" + dr["id"]. ToString () + "',");
Sb. Append ("href:" + dr["url"]. ToString () + "',");
Sb. Append ("Hreftarget: ' Main '");
Addchildrennode (Getallnodes (dr["id"). ToString ()), SB);
Sb. Append ("}");
}

Sb. Append ("]");
}
Else
Sb. Append (", leaf:true");
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.