85 lines
2.5 KiB
C#
85 lines
2.5 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using SWS.CAD.Models;
|
||
|
||
namespace SWS.CAD.Helper
|
||
{
|
||
public class TreeHelper
|
||
{
|
||
#region 获取树节点
|
||
|
||
/// <summary>
|
||
/// 获取树节点
|
||
/// </summary>
|
||
public static 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 TreeModel GetTreeModel(List<TreeModel> nodes, string id)
|
||
{
|
||
TreeModel node = null;
|
||
foreach (var dto in GlobalObject.objectTypeTree)
|
||
{
|
||
//获取节点下的图纸
|
||
node = TreeHelper.GetTreeModel(dto, id);
|
||
if (node != null)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
return node;
|
||
}
|
||
#endregion
|
||
|
||
#region 获取树节点所有图纸名
|
||
|
||
/// <summary>
|
||
/// 获取树节点所有图纸名
|
||
/// </summary>
|
||
public static void GetTreeText(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
|
||
}
|
||
}
|