private void CallOnEditButtonClickEvent()
        {
            if (this.dataGridView.SelectedRows.Count != 1)
            {
                return;
            }

            if (this.OnEdit != null)
            {
                object value = dataGridView.SelectedRows[0].DataBoundItem;
                object oldValue;

                if (OnEdit(value, new CollectionEditorEventArgs(_bindingSource), out oldValue))
                {
                    CollectionEditEventArgs collectionEditEventArgs = new CollectionEditEventArgs(this._bindingSource, CollectionEditType.Edit, _bindingSource.IndexOf(value),
                                                                                                  value);
                    collectionEditEventArgs.Members.Add(ObjectCompare.Compare(oldValue, value));

                    if (this.SupportCancel)
                    {
                        AddUndoUnit(collectionEditEventArgs);
                    }

                    if (this.OnEdited != null)
                    {
                        OnEdited(this, collectionEditEventArgs);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method is inherited from the IComparer interface. It compares the two objects passed using a case insensitive comparison.
        /// </summary>
        /// <param name="x">First object to be compared</param>
        /// <param name="y">Second object to be compared</param>
        /// <returns>The result of the comparison. "0" if equal, negative if 'x' is less than 'y' and positive if 'x' is greater than 'y'</returns>
        public int Compare(object x, object y)
        {
            int          compareResult;
            ListViewItem listviewX, listviewY;

            // Cast the objects to be compared to ListViewItem objects
            listviewX = (ListViewItem)x;
            listviewY = (ListViewItem)y;

            // Compare the two items
            compareResult = ObjectCompare.Compare(listviewX.SubItems[ColumnToSort].Text, listviewY.SubItems[ColumnToSort].Text);

            return(CompareResult(compareResult));
        }
Exemplo n.º 3
0
        private void Edit()
        {
            if (dataGridViewEvent.SelectedRows.Count != 1)
            {
                return;
            }

            EventBase even  = this.dataGridViewEvent.SelectedRows[0].DataBoundItem as EventBase;
            int       index = this.EventList.IndexOf(even);

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

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

            //这里暂时还能用using,因为窗体释放时,会把事件的编辑面板也释放掉,要另外处理这个问题
            //using (FormEventEditor formEventSet = new FormEventEditor(this._entity, even))
            //{
            formEventSet.FormEntity = this.FormEntity;
            formEventSet.EventList  = this.EventList;

            if (formEventSet.ShowDialog() == DialogResult.OK)
            {
                //CheckWarning
                IWarningable warningable = formEventSet.Event as IWarningable;
                if (warningable != null)
                {
                    warningable.CheckWarning();
                }

                _eventBindingList.ResetItem(index);

                EventUpdate();

                if (this.OnEdited != null)
                {
                    CollectionEditEventArgs args = new CollectionEditEventArgs(this.EventList,
                                                                               CollectionEditType.Edit, index, formEventSet.Event);
                    args.Members.Inject(ObjectCompare.Compare(oldEvent, formEventSet.Event));
                    OnEdited(this, args);
                }
            }
            //}
        }
Exemplo n.º 4
0
            public override int Compare(TaskMgrListItem x, TaskMgrListItem y)
            {
                int compareResult = 0;

                compareResult = string.Compare(x.SubItems[SortColumn].Text, y.SubItems[SortColumn].Text);
                if (compareResult == 0)
                {
                    compareResult = ObjectCompare.Compare(x.PID, y.PID);
                }
                if (Order == SortOrder.Ascending)
                {
                    return(compareResult);
                }
                else if (Order == SortOrder.Descending)
                {
                    return(-compareResult);
                }
                return(compareResult);
            }
Exemplo n.º 5
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);
                }
            }
        }
Exemplo n.º 6
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);
            }
        }