126 lines
3.9 KiB
C#
126 lines
3.9 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using SWS.Commons;
|
||
using SWS.Model;
|
||
|
||
namespace SWS.Commons
|
||
{
|
||
public class TreeHelper
|
||
{
|
||
#region 获取树节点
|
||
|
||
/// <summary>
|
||
/// 获取树节点
|
||
/// </summary>
|
||
public static Model.TreeModel GetTreeModel(TreeModel node, string id)
|
||
{
|
||
// 如果根节点为空,则返回null
|
||
if (node == null) return null;
|
||
// 如果找到当前节点,返回当前节点
|
||
if (node.ID == id) return node;
|
||
//没有子节点就返回null
|
||
if (node.ChildNodes == null) return null;
|
||
// 否则,递归地在子节点中查找
|
||
foreach (var child in node.ChildNodes)
|
||
{
|
||
var result = GetTreeModel(child, id);
|
||
if (result != null)
|
||
{
|
||
return result; // 找到后立即返回
|
||
}
|
||
}
|
||
// 如果在当前树中没有找到,返回null
|
||
return null;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 获取树节点
|
||
/// <summary>
|
||
/// 获取树节点
|
||
/// </summary>
|
||
public static Model.TreeModel GetTreeModel(List<Model.TreeModel> nodes, string id)
|
||
{
|
||
Model.TreeModel node = null;
|
||
foreach (var dto in nodes)
|
||
{
|
||
//获取节点下的图纸
|
||
node = TreeHelper.GetTreeModel(dto, id);
|
||
if (node != null)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
return node;
|
||
}
|
||
#endregion
|
||
|
||
#region 获取树节点
|
||
/// <summary>
|
||
/// 获取树节点
|
||
/// </summary>
|
||
public static Model.TreeModel GetTreeModelByText(List<Model.TreeModel> nodes, string text)
|
||
{
|
||
Model.TreeModel node = null;
|
||
foreach (var dto in nodes)
|
||
{
|
||
//获取节点下的图纸
|
||
node = TreeHelper.GetTreeModelByText(dto, text);
|
||
if (node != null)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
return node;
|
||
}
|
||
public static Model.TreeModel GetTreeModelByText(TreeModel node, string text)
|
||
{
|
||
// 如果根节点为空,则返回null
|
||
if (node == null) return null;
|
||
// 如果找到当前节点,返回当前节点
|
||
if (node.Text == text) return node;
|
||
//没有子节点就返回null
|
||
if (node.ChildNodes == null) return null;
|
||
// 否则,递归地在子节点中查找
|
||
foreach (var child in node.ChildNodes)
|
||
{
|
||
var result = GetTreeModelByText(child, text);
|
||
if (result != null)
|
||
{
|
||
return result; // 找到后立即返回
|
||
}
|
||
}
|
||
// 如果在当前树中没有找到,返回null
|
||
return null;
|
||
}
|
||
#endregion
|
||
|
||
#region 获取树节点所有图纸名
|
||
|
||
/// <summary>
|
||
/// 获取树节点所有图纸名
|
||
/// </summary>
|
||
public static void GetTreeText(Model.TreeModel node)
|
||
{
|
||
// 如果根节点为空,则返回null
|
||
if (node == null) return;
|
||
//没有子节点就返回null
|
||
if (node.ChildNodes == null) return;
|
||
// 否则,递归地在子节点中查找
|
||
foreach (var child in node.ChildNodes)
|
||
{
|
||
GetTreeText(child);
|
||
|
||
}
|
||
if (node.Text.ToLower().EndsWith(".dwg") && !GlobalObject.AllDwgName.Contains(node.Text))
|
||
{ GlobalObject.AllDwgName.Add(node.Text); }
|
||
// 如果在当前树中没有找到,返回null
|
||
return;
|
||
}
|
||
#endregion
|
||
}
|
||
}
|