using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Script.Serialization; using System.Data; namespace MESWebSite.CommonClass { /// /// Tree数据辅助类 /// public class JEasyUITree { public class TreeNode { public string id { get; set; } //节点的id值 public string text { get; set; } //节点显示的名称 public string state { get; set; } //节点的打开状态 public bool @checked { get; set; } //checked标志 public Dictionary attributes { get; set; } //节点属性字段 public List children { get; set; } //子节点列表 } public TreeNode CreateNode(DataRow r) { TreeNode node = new TreeNode(); node.id = r["id"].ToString(); node.text = r["text"].ToString(); node.children = new List(); return node; } /// /// 递归创建TreeNode集合列表 /// /// DataTable /// 集合列表 /// 节点父id public void LoadSubNode(DataTable dt, List listNodes, string pid = "0") { DataRow[] rows = dt.Select("pid=" + pid.ToString()); foreach (DataRow r in rows) { //生成TreeNode TreeNode node = CreateNode(r); //将节点 加入到 树节点集合 listNodes.Add(node); //递归 为这个新创建的 树节点找 子节点 LoadSubNode(dt, node.children, node.id); } } } public class JEasyUIHelper { /// /// datagrid数据传输类 /// public class DataGridModel { public string total; public List> rows; } /// /// 数据表转JSON,用于datagrid提供数据 /// /// 总行数 /// 数据表 /// JSON字符串 public static string DataTableToJSONdatagrid(int total, DataTable dt) { DataGridModel model = new DataGridModel(); model.total = total.ToString(); model.rows = JSONHelper.DataTableToList(dt); return JSONHelper.ObjectToJSON(model); } /// /// 数据集转JSON,用于datagrid提供数据 /// /// 数据集,表1存total行数,表2存数据 /// JSON字符串 public static string DataSetToJSONdatagrid(DataSet ds) { DataGridModel model = new DataGridModel(); model.total = ds.Tables[0].Rows[0][0].ToString(); model.rows = JSONHelper.DataTableToList(ds.Tables[1]); return JSONHelper.ObjectToJSON(model); } } }