/// <summary> /// Добавить узлы. /// </summary> /// <param name="entities">Сущности.</param> public void NodeAddRange(Hierarchy[] entities) { TreeNode nodeParent; if (entities[0] is Location) { nodeParent = Nodes[0]; } else if (entities[0] is Equipment) { nodeParent = dictNodes[((Equipment)entities[0]).Parent.GetSign()]; } else { return; } var indImage = IconsGetter.GetIndexIcon(entities[0].GetType()); var contextMenuStrip = ContextMenuGetter.GetMenu(entities[0].GetType()); var newNodes = new List <TreeNode>(entities.Length); foreach (var entity in entities) { var newNode = new TreeNode(entity.ToString(), indImage, indImage); newNode.ContextMenuStrip = contextMenuStrip; newNode.Tag = entity.GetSign(); dictNodes.Add(entity.GetSign(), newNode); newNodes.Add(newNode); } nodeParent.Nodes.AddRange(newNodes.ToArray()); SelectedNode = newNodes.First(); Sort(); }
/// <summary> /// Заполнить данными. /// </summary> public void LoadFromContext() { this.SuspendDrawing(); using (var ec = new EntityController()) { var projectNode = new TreeNode("Проект"); projectNode.ContextMenuStrip = ContextMenuGetter.GetMenu(0.GetType()); Nodes.Add(projectNode); foreach (var location in ec.Locations) { var locationSign = location.GetSign(); var nodeLocation = CreateNode(projectNode, locationSign, location.ToString(), ContextMenuGetter.GetMenu(typeof(Location))); foreach (var fireCabinet in location.FireCabinets) { var fireCabinetSign = fireCabinet.GetSign(); var nodeFireCabinet = CreateNode(nodeLocation, fireCabinetSign, fireCabinet.ToString(), ContextMenuGetter.GetMenu(typeof(FireCabinet))); foreach (var extinguisher in fireCabinet.Extinguishers) { var extinguisherSign = extinguisher.GetSign(); CreateNode(nodeFireCabinet, extinguisherSign, extinguisher.ToString(), ContextMenuGetter.GetMenu(typeof(Extinguisher))); } foreach (var hose in fireCabinet.Hoses) { var hoseSign = hose.GetSign(); CreateNode(nodeFireCabinet, hoseSign, hose.ToString(), ContextMenuGetter.GetMenu(typeof(Hose))); } foreach (var hydrant in fireCabinet.Hydrants) { var hydrantSign = hydrant.GetSign(); CreateNode(nodeFireCabinet, hydrantSign, hydrant.ToString(), ContextMenuGetter.GetMenu(typeof(Hydrant))); } } } } Sort(); Nodes[0].Expand(); this.ResumeDrawing(); TreeNode CreateNode(TreeNode parent, EntitySign entitySign, string text, ContextMenuStrip menu = null) { var indImage = IconsGetter.GetIndexIcon(entitySign.Type); var child = new TreeNode(text, indImage, indImage); child.ContextMenuStrip = ContextMenuGetter.GetMenu(entitySign.Type); parent.Nodes.Add(child); child.Tag = entitySign; dictNodes.Add(entitySign, child); return(child); } }