public static void ValidateUndo(GDbTabWrapper <TKey, TValue> tab, string text, DbAttribute attribute)
        {
            try {
                if (tab.List.SelectedItem != null && !tab.ItemsEventsDisabled)
                {
                    TValue tuple = (TValue)tab.List.SelectedItem;
                    ITableCommand <TKey, TValue> command = tab.Table.Commands.Last();

                    if (command is ChangeTupleProperty <TKey, TValue> )
                    {
                        ChangeTupleProperty <TKey, TValue> changeCommand = (ChangeTupleProperty <TKey, TValue>)command;
                        IGenericDbCommand last = tab.GenericDatabase.Commands.Last();

                        if (last != null)
                        {
                            if (last is GenericDbCommand <TKey> )
                            {
                                GenericDbCommand <TKey> nLast = (GenericDbCommand <TKey>)last;

                                if (ReferenceEquals(nLast.Table, tab.Table))
                                {
                                    // The last command of the table is being edited

                                    if (changeCommand.Tuple != tuple || changeCommand.Attribute.Index != attribute.Index)
                                    {
                                        //tab.Table.Commands.Set(tuple, attribute, text);
                                    }
                                    else
                                    {
                                        changeCommand.NewValue = text;
                                        changeCommand.Execute(tab.Table);

                                        if (changeCommand.NewValue.ToString() == changeCommand.OldValue.ToString())
                                        {
                                            nLast.Undo();
                                            tab.GenericDatabase.Commands.RemoveCommands(1);
                                            tab.Table.Commands.RemoveCommands(1);
                                        }

                                        return;
                                    }
                                }
                            }
                        }

                        tab.Table.Commands.Set(tuple, attribute, text);
                    }
                    else
                    {
                        tab.Table.Commands.Set(tuple, attribute, text);
                    }
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }
示例#2
0
        private void _validateUndo(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, string text, DbAttribute attribute)
        {
            try {
                if (tab.List.SelectedItem != null && !tab.ItemsEventsDisabled && _lv.SelectedItem != null)
                {
                    ReadableTuple <TKey> tuple = (ReadableTuple <TKey>)tab.List.SelectedItem;
                    int tupleKey = ((ItemView)_lv.SelectedItem).ID;

                    ITableCommand <TKey, ReadableTuple <TKey> > command = tab.Table.Commands.Last();

                    if (command is ChangeTupleDicoProperty <TKey, ReadableTuple <TKey>, TKey, ReadableTuple <TKey> > )
                    {
                        ChangeTupleDicoProperty <TKey, ReadableTuple <TKey>, TKey, ReadableTuple <TKey> > changeCommand = (ChangeTupleDicoProperty <TKey, ReadableTuple <TKey>, TKey, ReadableTuple <TKey> >)command;
                        IGenericDbCommand last = tab.GenericDatabase.Commands.Last();

                        if (last != null)
                        {
                            if (last is GenericDbCommand <TKey> )
                            {
                                GenericDbCommand <TKey> nLast = (GenericDbCommand <TKey>)last;

                                if (ReferenceEquals(nLast.Table, tab.Table))
                                {
                                    // The last command of the table is being edited

                                    if (changeCommand.Tuple != tuple || tupleKey != (int)(object)changeCommand.DicoKey || changeCommand.Attribute.Index != attribute.Index)
                                    {
                                        //tab.Table.Commands.Set(tuple, attribute, text);
                                    }
                                    else
                                    {
                                        ItemView itemView = ((ItemView)_lv.SelectedItem);

                                        changeCommand.NewValue.SetValue(attribute, text);
                                        changeCommand.Execute(tab.Table);

                                        if (changeCommand.NewValue.CompareWith(changeCommand.InitialValue))
                                        {
                                            nLast.Undo();
                                            tab.GenericDatabase.Commands.RemoveCommands(1);
                                            tab.Table.Commands.RemoveCommands(1);
                                            //changeCommand.InitialValue.Modified = changeCommand.SubModified;
                                            _lv.Dispatch(p => p.SelectedItem = ((RangeObservableCollection <ItemView>)_lv.ItemsSource).FirstOrDefault(q => q.ID == itemView.ID));
                                        }

                                        itemView.VisualUpdate();
                                        return;
                                    }
                                }
                            }
                        }

                        _setSelectedItem(attribute, text);
                    }
                    else
                    {
                        _setSelectedItem(attribute, text);
                    }
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }