Exemplo n.º 1
0
        /// <summary>
        /// Обработчик события клика мышью.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            SelectedNode = e.Node;
            var sign = e.Node.Tag as EntitySign;

            if (sign == null)
            {
                return;
            }
            MouseClickSign?.Invoke(sign);

            if (e.Button == MouseButtons.Right)
            {
                ContextMenuGetter.GetMenu(sign.Type).Tag = e.Node.Tag;
            }
        }
Exemplo n.º 2
0
        private void treeView_DragDrop(object sender, DragEventArgs e)
        {
            Point targetPoint = PointToClient(new Point(e.X, e.Y));

            TreeNode targetNode  = GetNodeAt(targetPoint);
            TreeNode draggedNode = e.Data.GetData(typeof(TreeNode)) as TreeNode;

            var  targetType  = (targetNode.Tag as EntitySign).Type;
            var  draggedType = (draggedNode.Tag as EntitySign).Type;
            Type draggedTypeParent;

            if (draggedType == typeof(FireCabinet))
            {
                draggedTypeParent = typeof(Location);
            }
            else
            {
                draggedTypeParent = typeof(FireCabinet);
            }

            if (targetType == draggedTypeParent)
            {
                if (e.Effect == DragDropEffects.Move)
                {
                    var sign          = draggedNode.Tag as EntitySign;
                    var signNewParent = targetNode.Tag as EntitySign;
                    using (var ec = new EntityController())
                    {
                        var entity = ec.GetEntity(sign) as Equipment;
                        entity.Parent          = (Hierarchy)ec.GetEntity(signNewParent);
                        entity.Point.Displayed = false;
                        ec.EditEntity(entity);
                        ec.SaveChanges();
                        draggedNode.Text = entity.ToString();
                    }
                    draggedNode.Remove();
                    targetNode.Nodes.Add(draggedNode);
                    MouseClickSign?.Invoke(sign);
                }
                targetNode.Expand();
            }
        }