Exemplo n.º 1
0
        private void BuildTree()
        {
            this.SuspendLayout();

            this.Nodes.Clear();

            if (EventSupport == null)
            {
                return;
            }

            foreach (EventTimeAbstract eventTime in EventSupport.EventTimeProvide)
            {
                EventTimeTreeNode timeNode = new EventTimeTreeNode(eventTime);

                //加载该触发时机下的事件
                foreach (EventBase eventBase in EventSupport.Events.GetEventsByTime(eventTime.Code))
                {
                    timeNode.Nodes.Add(new EventTreeNode(eventBase));
                }

                this.Nodes.Add(timeNode);
            }

            this.ExpandAll();

            this.ResumeLayout();
        }
Exemplo n.º 2
0
        protected override void ProcessDragDrop(TreeNode dragNode, TreeNode dropNode)
        {
            CollectionEditEventArgs[] eventArgs = new CollectionEditEventArgs[2];

            EventTreeNode node         = dragNode as EventTreeNode;
            int           nodeOldIndex = this.EventSupport.Events.IndexOf(node.Event);
            EventBase     oldEvent     = null;

            if (EventOrderChanged != null)
            {
                oldEvent = node.Event.Clone() as EventBase;
            }

            #region 如果目标节点是触发时机

            //如果目标节点是触发时机,把拖动的节点放到这个触发时机的最后面
            //需要调用一次EventCollection.Down方法,同步事件序列的顺序
            //并把拖动的事件的触发时机修改为目标节点同样的触发时机
            if (dropNode.GetType().Equals(typeof(EventTimeTreeNode)))
            {
                //直接调用基类方法完成节点移动
                base.MoveNode(dragNode, dropNode);

                //同步触发事件顺序
                //拿到dragNode的前一个节点(如果有),调用一次Down方法

                //改变触发时机
                EventTimeTreeNode eventTimeNode = dragNode.Parent as EventTimeTreeNode;
                node.Event.EventTime = eventTimeNode.EventTime.Code;

                //确保拖动的事件在事件序列中处于当前触发时机中所有事件的最后
                EventTreeNode eventNode = dragNode.PrevNode as EventTreeNode;
                if (eventNode != null)
                {
                    this.EventSupport.Events.NextTo(node.Event, eventNode.Event);
                }
            }

            #endregion

            #region 如果目标节点是事件

            //如果目标节点是事件,把拖动的事件放到这个事件的前面,需调用Up方法同步事件顺序
            //并把拖动的事件的触发时机修改为目标节点同样的触发时机
            else if (dropNode.GetType().Equals(typeof(EventTreeNode)))
            {
                //如果放在拖动节点的同级下一个节点,do nothing
                if (dropNode.NextNode == dragNode)
                {
                    return;
                }

                //移动树节点
                // Remove drag node from parent
                dragNode.Parent.Nodes.Remove(dragNode);
                // Add drag node to drop node
                dropNode.Parent.Nodes.Insert(dropNode.Index + 1, dragNode);

                EventTreeNode prevNode = dragNode.PrevNode as EventTreeNode;

                //改变触发时机
                node.Event.EventTime = prevNode.Event.EventTime;

                //nextNode不可能为null,就是dragNode
                this.EventSupport.Events.NextTo(node.Event, prevNode.Event);
            }

            #endregion

            if (EventOrderChanged != null)
            {
                CollectionEditEventArgs args0 = new CollectionEditEventArgs(this.EventSupport.Events,
                                                                            CollectionEditType.Edit, this.EventSupport.Events.IndexOf(node.Event), node.Event);
                args0.Members.Inject(ObjectCompare.Compare(oldEvent, node.Event));
                eventArgs[0] = args0;

                eventArgs[1] = new CollectionEditEventArgs(this.EventSupport.Events, CollectionEditType.Move,
                                                           this.EventSupport.Events.IndexOf(node.Event), nodeOldIndex, node.Event);

                EventOrderChanged(eventArgs);
            }
        }