Beispiel #1
0
 private void _visualUpdate(object sender, ITableCommand <int, ReadableTuple <int> > command)
 {
     if (_lv != null && _lv.ItemsSource != null)
     {
         _lv.Dispatch(p => ((RangeObservableCollection <ReadableTuple <int> >)_lv.ItemsSource).Update());
     }
 }
Beispiel #2
0
        public GenericDbCommand(AbstractDb <TKey> db)
        {
            _displayName = db.DbSource.DisplayName;
            Table        = db.Table;

            _command      = Table.Commands.Current;
            _commandsList = Table.Commands;
        }
        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);
            }
        }
Beispiel #4
0
        private void _commands_PreviewCommandRedo(object sender, ITableCommand <TKey, TValue> command)
        {
            RangeObservableCollection <TValue> coll = SearchEngine.Collection;

            if (coll != null)
            {
                SearchEngine.Collection.Disable();
            }

            _listView.Disable();
        }
Beispiel #5
0
        private void _commands_CommandRedo(object sender, ITableCommand <TKey, TValue> command)
        {
            _listView.UpdateAndEnable();

            RangeObservableCollection <TValue> coll = SearchEngine.Collection;

            if (coll != null)
            {
                SearchEngine.Collection.UpdateAndEnable();
            }
        }
Beispiel #6
0
        public virtual string CommandText(ITableCommand command)
        {
            if (command == null)
            {
                return(string.Empty);
            }
            var querySql = string.Format("{0}{1}{2}{3}", command.CommandText_Select, command.CommandText_From,
                                         command.CommandText_Where,
                                         this.GetOrderBy(command.CommandText_OrderBy_Asc,
                                                         command.CommandText_OrderBy_Desc));

            if (StringHelper.IsNullOrEmptyOrBlankString(command.CommandText_Page))
            {
                return(querySql);
            }
            else
            {
                var countSql = string.Format("select count(1) {0} {1} ", command.CommandText_From,
                                             command.CommandText_Where);
                return(string.Format("{0}{1} ; {2}", querySql, command.CommandText_Page, countSql));
            }
        }
Beispiel #7
0
        public override void StoreAndExecute(ITableCommand <TKey, ReadableTuple <TKey> > command)
        {
            var cmd1 = command as ChangeTupleProperty <TKey, ReadableTuple <TKey> >;

            if (cmd1 != null)
            {
                for (int i = 0; i < _tables.Count; i++)
                {
                    if (_tables[i].ContainsKey(command.Key))
                    {
                        _tables[i].Commands.StoreAndExecute(command);
                        return;
                    }
                }

                return;
            }

            var cmd2 = command as DeleteTuple <TKey, ReadableTuple <TKey> >;

            if (cmd2 != null)
            {
                for (int i = 0; i < _tables.Count; i++)
                {
                    if (_tables[i].ContainsKey(command.Key))
                    {
                        _tables[i].Commands.StoreAndExecute(command);
                        //return; Removes in all tables
                    }
                }

                return;
            }

            throw new NotImplementedException();
        }
Beispiel #8
0
 private void _commandChanged(object sender, ITableCommand <int, ReadableTuple <int> > command)
 {
     _commandChanged2(null, null);
 }
Beispiel #9
0
 public override void Store(ITableCommand <TKey, ReadableTuple <TKey> > command)
 {
     throw new NotImplementedException();
 }
 public TableQueryFrom(IDataManager dataManager, ITableCommand command)
 {
     this.DataManager = dataManager;
     this.Command     = command;
 }
Beispiel #11
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);
            }
        }
Beispiel #12
0
 public TableQueryOrderBy(IDataManager dataManager, ITableCommand command)
     : base(dataManager, command)
 {
     this.DataManager = dataManager;
     this.Command     = command;
 }