You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
3.2 KiB
93 lines
3.2 KiB
3 months ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Web;
|
||
|
using System.Web.Script.Serialization;
|
||
|
using System.Data;
|
||
|
|
||
|
namespace MESWebSite.CommonClass
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Tree数据辅助类
|
||
|
/// </summary>
|
||
|
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<string, object> attributes { get; set; } //节点属性字段
|
||
|
public List<TreeNode> 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<TreeNode>();
|
||
|
return node;
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 递归创建TreeNode集合列表
|
||
|
/// </summary>
|
||
|
/// <param name="dt">DataTable</param>
|
||
|
/// <param name="listNodes">集合列表</param>
|
||
|
/// <param name="pid">节点父id</param>
|
||
|
public void LoadSubNode(DataTable dt, List<TreeNode> 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
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// datagrid数据传输类
|
||
|
/// </summary>
|
||
|
public class DataGridModel
|
||
|
{
|
||
|
public string total;
|
||
|
public List<Dictionary<string, object>> rows;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 数据表转JSON,用于datagrid提供数据
|
||
|
/// </summary>
|
||
|
/// <param name="total">总行数</param>
|
||
|
/// <param name="dt">数据表</param>
|
||
|
/// <returns>JSON字符串</returns>
|
||
|
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);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 数据集转JSON,用于datagrid提供数据
|
||
|
/// </summary>
|
||
|
/// <param name="ds">数据集,表1存total行数,表2存数据</param>
|
||
|
/// <returns>JSON字符串</returns>
|
||
|
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);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|