123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- /* ==============================================================================
- * 功能描述:沿项目,建筑,楼层树查找
- * 创 建 者:Garrett
- * 创建日期:2018/8/13 15:16:30
- * ==============================================================================*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using SAGA.DotNetUtils;
- using SAGA.MBI.Common;
- using SAGA.MBI.Gplot;
- using SAGA.MBI.Model;
- namespace SAGA.MBI.DataArrange
- {
- /// <summary>
- /// DalProjectTree
- /// </summary>
- public class DalProjectTree
- {
- /// <summary>
- /// 由楼层id获取建筑Id
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public static string GetBuildingIdByFloor(string id)
- {
- return GetBuildingByFloor(id)?.Id;
- }
- /// <summary>
- /// 由楼层id获取建筑
- /// </summary>
- /// <param name="floorId"></param>
- /// <returns></returns>
- public static MBuilding GetBuildingByFloor(string floorId)
- {
- TreeNodeItem tree = DalModeFileManange.GetBuildingItemByFloorId(floorId);
- MBuilding floorBase = tree?.Item as MBuilding;
- return floorBase;
- }
- /// <summary>
- /// 由楼层id,获取当前楼层
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public static MFloor GetFloorByFloorId(string id)
- {
- TreeNodeItem tree = DalModeFileManange.GetFloorTreeById(id);
- MFloor floor = tree?.Item as MFloor;
- return floor;
- }
- /// <summary>
- /// 由楼层id获取楼层的名称
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public static string GetFloorNameByFloorId(string id)
- {
- string name = id.IsNullOrEmpty() ? "无法确定楼层" : id;
- MFileBase floorBase = GetFloorByFloorId(id);
- if (floorBase != null)
- name = $"{floorBase}";
- return name;
- }
- /// <summary>
- /// 由楼层id获取Floor树节点
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public static Dictionary<string,string> GetFloorNameAndId()
- {
- Dictionary<string,string> pair=new Dictionary<string, string>();
- TreeNodeItem tree = null;
- foreach (TreeNodeItem buildingTree in MBIControl.ProjectTree.Children)
- {
- foreach (TreeNodeItem floorTree in buildingTree.Children)
- {
- if (floorTree.Item is MFloor floor)
- {
- pair.Add(floor.Id,floor.ToString());
- }
- }
- }
- return pair;
- }
- /// <summary>
- /// 由楼层id,获取当前楼层的上一层
- /// 上一层跟楼层序列号无关,树结构的上一个
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public static MFloor GetUpperFloor(string id)
- {
- MFloor floor = null;
- TreeNodeItem tree = DalModeFileManange.GetUpperFloorTreeById(id);
- if (tree != null)
- {
- MFileBase floorBase = tree.Item;
- floor = floorBase as MFloor;
- }
- return floor;
- }
- /// <summary>
- /// 当前楼层文件的名称
- /// 格式为:"{建筑名称}→{楼层名称}"
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public static string GetFloorFullName(string id)
- {
- string name = id;
- TreeNodeItem tree = DalModeFileManange.GetFloorTreeById(id);
- if (tree != null)
- {
- MFileBase floorBase = tree.Item;
- MFileBase buildingBase = tree.Parent.Item;
- name = $"{buildingBase}→{floorBase}";
- }
- return name;
- }
- /// <summary>
- /// 获取树结点下的楼层
- /// </summary>
- /// <param name="isContainMissFile">是否包含缺少模型文件的楼层</param>
- public static List<MFloor> GetAllFloors(bool isContainMissFile=true)
- {
- var floors = DalModeFileManange.GetAllFloors(MBIControl.ProjectTree);
- return isContainMissFile?floors:floors.Where(t=>!t.IsMissFile).ToList();
- }
- /// <summary>
- /// 获取选择建筑的所有楼层
- /// </summary>
- /// <param name="isOnlyPermission">仅获取有权限的楼层</param>
- /// <returns></returns>
- public static List<MFloor> GetSelectedFloors()
- {
- List<MFloor> floors = new List<MFloor>();
- foreach (TreeNodeItem buildingTree in MBIControl.ProjectTree.Children)
- {
- if (!buildingTree.IsSelected) continue;
- if (buildingTree.Item is MBuilding building)
- {
- foreach (TreeNodeItem floorTree in buildingTree.Children)
- {
- if (!floorTree.IsSelected) continue;
- if (floorTree.Item is MFloor floor)
- {
- floors.Add(floor);
- }
- }
- }
- }
- return floors;
- }
- /// <summary>
- /// 获取选择建筑
- /// </summary>
- /// <param name="isOnlyPermission">仅获取有权限的楼层</param>
- /// <returns></returns>
- public static MBuilding GetSelectedBuilding()
- {
- MBuilding building = null;
- foreach (TreeNodeItem buildingTree in MBIControl.ProjectTree.Children)
- {
- if (!buildingTree.IsSelected) continue;
- if (buildingTree.Item is MBuilding )
- {
- building = buildingTree.Item as MBuilding;
- }
- }
- return building;
- }
- }
- }
|