DalProjectTree.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /* ==============================================================================
  2. * 功能描述:沿项目,建筑,楼层树查找
  3. * 创 建 者:Garrett
  4. * 创建日期:2018/8/13 15:16:30
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using SAGA.DotNetUtils;
  12. using SAGA.MBI.Common;
  13. using SAGA.MBI.Gplot;
  14. using SAGA.MBI.Model;
  15. namespace SAGA.MBI.DataArrange
  16. {
  17. /// <summary>
  18. /// DalProjectTree
  19. /// </summary>
  20. public class DalProjectTree
  21. {
  22. /// <summary>
  23. /// 由楼层id获取建筑Id
  24. /// </summary>
  25. /// <param name="id"></param>
  26. /// <returns></returns>
  27. public static string GetBuildingIdByFloor(string id)
  28. {
  29. return GetBuildingByFloor(id)?.Id;
  30. }
  31. /// <summary>
  32. /// 由楼层id获取建筑
  33. /// </summary>
  34. /// <param name="floorId"></param>
  35. /// <returns></returns>
  36. public static MBuilding GetBuildingByFloor(string floorId)
  37. {
  38. TreeNodeItem tree = DalModeFileManange.GetBuildingItemByFloorId(floorId);
  39. MBuilding floorBase = tree?.Item as MBuilding;
  40. return floorBase;
  41. }
  42. /// <summary>
  43. /// 由楼层id,获取当前楼层
  44. /// </summary>
  45. /// <param name="id"></param>
  46. /// <returns></returns>
  47. public static MFloor GetFloorByFloorId(string id)
  48. {
  49. TreeNodeItem tree = DalModeFileManange.GetFloorTreeById(id);
  50. MFloor floor = tree?.Item as MFloor;
  51. return floor;
  52. }
  53. /// <summary>
  54. /// 由楼层id获取楼层的名称
  55. /// </summary>
  56. /// <param name="id"></param>
  57. /// <returns></returns>
  58. public static string GetFloorNameByFloorId(string id)
  59. {
  60. string name = id.IsNullOrEmpty() ? "无法确定楼层" : id;
  61. MFileBase floorBase = GetFloorByFloorId(id);
  62. if (floorBase != null)
  63. name = $"{floorBase}";
  64. return name;
  65. }
  66. /// <summary>
  67. /// 由楼层id获取Floor树节点
  68. /// </summary>
  69. /// <param name="id"></param>
  70. /// <returns></returns>
  71. public static Dictionary<string,string> GetFloorNameAndId()
  72. {
  73. Dictionary<string,string> pair=new Dictionary<string, string>();
  74. TreeNodeItem tree = null;
  75. foreach (TreeNodeItem buildingTree in MBIControl.ProjectTree.Children)
  76. {
  77. foreach (TreeNodeItem floorTree in buildingTree.Children)
  78. {
  79. if (floorTree.Item is MFloor floor)
  80. {
  81. pair.Add(floor.Id,floor.ToString());
  82. }
  83. }
  84. }
  85. return pair;
  86. }
  87. /// <summary>
  88. /// 由楼层id,获取当前楼层的上一层
  89. /// 上一层跟楼层序列号无关,树结构的上一个
  90. /// </summary>
  91. /// <param name="id"></param>
  92. /// <returns></returns>
  93. public static MFloor GetUpperFloor(string id)
  94. {
  95. MFloor floor = null;
  96. TreeNodeItem tree = DalModeFileManange.GetUpperFloorTreeById(id);
  97. if (tree != null)
  98. {
  99. MFileBase floorBase = tree.Item;
  100. floor = floorBase as MFloor;
  101. }
  102. return floor;
  103. }
  104. /// <summary>
  105. /// 当前楼层文件的名称
  106. /// 格式为:"{建筑名称}→{楼层名称}"
  107. /// </summary>
  108. /// <param name="id"></param>
  109. /// <returns></returns>
  110. public static string GetFloorFullName(string id)
  111. {
  112. string name = id;
  113. TreeNodeItem tree = DalModeFileManange.GetFloorTreeById(id);
  114. if (tree != null)
  115. {
  116. MFileBase floorBase = tree.Item;
  117. MFileBase buildingBase = tree.Parent.Item;
  118. name = $"{buildingBase}→{floorBase}";
  119. }
  120. return name;
  121. }
  122. /// <summary>
  123. /// 获取树结点下的楼层
  124. /// </summary>
  125. /// <param name="isContainMissFile">是否包含缺少模型文件的楼层</param>
  126. public static List<MFloor> GetAllFloors(bool isContainMissFile=true)
  127. {
  128. var floors = DalModeFileManange.GetAllFloors(MBIControl.ProjectTree);
  129. return isContainMissFile?floors:floors.Where(t=>!t.IsMissFile).ToList();
  130. }
  131. /// <summary>
  132. /// 获取选择建筑的所有楼层
  133. /// </summary>
  134. /// <param name="isOnlyPermission">仅获取有权限的楼层</param>
  135. /// <returns></returns>
  136. public static List<MFloor> GetSelectedFloors()
  137. {
  138. List<MFloor> floors = new List<MFloor>();
  139. foreach (TreeNodeItem buildingTree in MBIControl.ProjectTree.Children)
  140. {
  141. if (!buildingTree.IsSelected) continue;
  142. if (buildingTree.Item is MBuilding building)
  143. {
  144. foreach (TreeNodeItem floorTree in buildingTree.Children)
  145. {
  146. if (!floorTree.IsSelected) continue;
  147. if (floorTree.Item is MFloor floor)
  148. {
  149. floors.Add(floor);
  150. }
  151. }
  152. }
  153. }
  154. return floors;
  155. }
  156. /// <summary>
  157. /// 获取选择建筑
  158. /// </summary>
  159. /// <param name="isOnlyPermission">仅获取有权限的楼层</param>
  160. /// <returns></returns>
  161. public static MBuilding GetSelectedBuilding()
  162. {
  163. MBuilding building = null;
  164. foreach (TreeNodeItem buildingTree in MBIControl.ProjectTree.Children)
  165. {
  166. if (!buildingTree.IsSelected) continue;
  167. if (buildingTree.Item is MBuilding )
  168. {
  169. building = buildingTree.Item as MBuilding;
  170. }
  171. }
  172. return building;
  173. }
  174. }
  175. }