Esempio n. 1
0
        /// <summary>
        /// 删除事件
        /// </summary>
        public void Delete()
        {
            EventTreeNode node = this.SelectedNode as EventTreeNode;

            //如果双击的是事件,删除
            if (node != null)
            {
                if (MessageBox.Show(
                        CommonLanguage.Current.ConfirmDelete
                        + Environment.NewLine + Environment.NewLine + node.Name,
                        CommonLanguage.Current.MessageCaption_Notice,
                        MessageBoxButtons.OKCancel,
                        MessageBoxIcon.Question
                        ) != DialogResult.OK)
                {
                    return;
                }

                int index = this.EventSupport.Events.IndexOf(node.Event);

                this.EventSupport.Events.Remove(node.Event);

                EventSupport.EventUpdate(this);

                node.Remove();

                if (EventChanged != null)
                {
                    Dictionary <int, object> values = new Dictionary <int, object>();
                    values.Add(index, node.Event);
                    EventChanged(new CollectionEditEventArgs(this.EventSupport.Events, values));
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 下移事件
        /// </summary>
        public void Down()
        {
            EventTreeNode node = this.SelectedNode as EventTreeNode;

            if (node == null)
            {
                return;
            }

            EventTreeNode nextNodex = node.NextNode as EventTreeNode;

            if (nextNodex == null)
            {
                return;
            }

            int nodeOldIndex = this.EventSupport.Events.IndexOf(node.Event);

            this.EventSupport.Events.NextTo(node.Event, nextNodex.Event);

            EventSupport.EventUpdate(this);

            //BuildTree();
            this.SwapNode(node, nextNodex);
            this.SelectedNode = node;

            if (EventOrderChanged != null)
            {
                CollectionEditEventArgs[] eventArgs = new CollectionEditEventArgs[1];
                eventArgs[0] = new CollectionEditEventArgs(this.EventSupport.Events, CollectionEditType.Move,
                                                           this.EventSupport.Events.IndexOf(node.Event), nodeOldIndex, node.Event);
                EventOrderChanged(eventArgs);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 编辑事件
        /// </summary>
        public void Edit()
        {
            EventTreeNode node = this.SelectedNode as EventTreeNode;

            //如果选择的不是事件,直接返回
            if (node == null)
            {
                return;
            }

            //保持当前事件对象的副本,用于在编辑事件之后,进行Compare提取差异
            EventBase oldEvent = null;

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

            //FormEventEditor.Event编辑后还是原对象的引用,在原对象基础上修改的
            FormEventEditor formEventSet = new FormEventEditor(node.Event.HostEntity, node.Event);

            formEventSet.FormEntity = node.Event.HostFormEntity;
            formEventSet.EventList  = EventSupport.Events;

            if (formEventSet.ShowDialog() == DialogResult.OK)
            {
                EventSupport.EventUpdate(this);

                //直接重建树
                //如果想根据改变的触发时机来修改当前事件的父节点,涉及到事件的顺序问题
                //因为编辑的事件在移到新的触发时机下面时,不一定是最后一个
                BuildTree();

                //触发事件(如果有)
                if (EventChanged != null)
                {
                    CollectionEditEventArgs args = new CollectionEditEventArgs(this.EventSupport.Events, CollectionEditType.Edit,
                                                                               this.EventSupport.Events.IndexOf(node.Event), node.Event);
                    args.Members.Inject(ObjectCompare.Compare(oldEvent, node.Event));
                    EventChanged(args);
                }
            }
        }
Esempio n. 4
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);
            }
        }