2025-08-15 16:34:31 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2025-09-04 18:28:02 +08:00
|
|
|
|
using SWS.Commons;
|
|
|
|
|
using SWS.Model;
|
2025-08-15 16:34:31 +08:00
|
|
|
|
|
|
|
|
|
namespace SWS.CAD.Helper
|
|
|
|
|
{
|
|
|
|
|
public class TreeHelper
|
|
|
|
|
{
|
|
|
|
|
#region 获取树节点
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取树节点
|
|
|
|
|
/// </summary>
|
2025-09-04 18:28:02 +08:00
|
|
|
|
public static Model.TreeModel GetTreeModel(TreeModel node, string id)
|
2025-08-15 16:34:31 +08:00
|
|
|
|
{
|
|
|
|
|
// 如果根节点为空,则返回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>
|
2025-09-04 18:28:02 +08:00
|
|
|
|
public static Model.TreeModel GetTreeModel(List<Model.TreeModel> nodes, string id)
|
2025-08-15 16:34:31 +08:00
|
|
|
|
{
|
2025-09-04 18:28:02 +08:00
|
|
|
|
Model.TreeModel node = null;
|
2025-08-15 16:34:31 +08:00
|
|
|
|
foreach (var dto in GlobalObject.objectTypeTree)
|
|
|
|
|
{
|
|
|
|
|
//获取节点下的图纸
|
|
|
|
|
node = TreeHelper.GetTreeModel(dto, id);
|
|
|
|
|
if (node != null)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 获取树节点所有图纸名
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取树节点所有图纸名
|
|
|
|
|
/// </summary>
|
2025-09-04 18:28:02 +08:00
|
|
|
|
public static void GetTreeText(Model.TreeModel node)
|
2025-08-15 16:34:31 +08:00
|
|
|
|
{
|
|
|
|
|
// 如果根节点为空,则返回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
|
|
|
|
|
}
|
|
|
|
|
}
|