DataNodeUtil.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:DataNodeUtil
  3. * 作者:xulisong
  4. * 创建时间: 2018/12/10 14:51:29
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using SAGA.Models;
  13. namespace SAGA.GplotRelationComputerManage
  14. {
  15. public class DataNodeUtil
  16. {
  17. public static void BuildNode(DataNode node, List<DataNode> sourceNodes)
  18. {
  19. //从上往下遍历可以控制父节点的范围
  20. var isHandled = node.GetData<bool>();
  21. node.SetData(true);
  22. #region 结束条件
  23. if (string.IsNullOrWhiteSpace(node.Sno))
  24. {
  25. return;
  26. }
  27. if (node.Childrens.Count != 0 ||isHandled)
  28. {
  29. return;
  30. }
  31. #endregion
  32. #region 父子关系整理
  33. var baseNo = node.Sno;
  34. List<DataNode> mainNodes = new List<DataNode>();
  35. List<DataNode> standbyNodes = new List<DataNode>();
  36. foreach (var sourceNode in sourceNodes)
  37. {
  38. if (sourceNode.Sno == baseNo)
  39. {
  40. continue;
  41. }
  42. if (sourceNode.InLineNo == baseNo)
  43. {
  44. sourceNode.Parent = node;
  45. mainNodes.Add(sourceNode);
  46. }
  47. else if(sourceNode.InLineNo1 == baseNo)
  48. {
  49. sourceNode.Parent = node;
  50. standbyNodes.Add(sourceNode);
  51. }
  52. }
  53. node.Childrens.AddRange(mainNodes);
  54. node.Childrens.AddRange(standbyNodes);
  55. #endregion
  56. #region 递归调用
  57. foreach (var nodeChildren in node.Childrens)
  58. {
  59. BuildNode(nodeChildren, sourceNodes);
  60. }
  61. #endregion
  62. }
  63. }
  64. }