2025-09-04 18:28:02 +08:00

86 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SWS.Commons;
using SWS.Model;
namespace SWS.CAD.Helper
{
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 GlobalObject.objectTypeTree)
{
//获取节点下的图纸
node = TreeHelper.GetTreeModel(dto, id);
if (node != null)
{
break;
}
}
return node;
}
#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
}
}