Example #1
0
        private void _setSelectedItem(DbAttribute attribute, object value)
        {
            var item = (ItemView)_lv.SelectedItem;
            ReadableTuple <int> newValue = new ReadableTuple <int>(item.ID, ServerItemGroupSubAttributes.AttributeList);

            newValue.Copy(item.SubTuple);
            newValue.SetValue(attribute, value);
            newValue.Modified = true;

            _itemGroupsTable.Commands.StoreAndExecute(new ChangeTupleDicoProperty <int, ReadableTuple <int>, int, ReadableTuple <int> >(
                                                          _tab.List.SelectedItem as ReadableTuple <int>, ServerItemGroupAttributes.Table, item.ID, newValue, item.ID));

            item.VisualUpdate();
        }
Example #2
0
        private void _setSelectedItem(int id, object rate, DicoModifs modif)
        {
            if (modif == DicoModifs.Delete)
            {
                var p = (ReadableTuple <int>)_tab.List.SelectedItem;
                _itemGroupsTable.Commands.StoreAndExecute(new ChangeTupleDicoProperty <int, ReadableTuple <int>, int, ReadableTuple <int> >(
                                                              p, ServerItemGroupAttributes.Table, ((ItemView)_lv.SelectedItem).ID));
                return;
            }

            ItemView            selectedItem = null;
            ReadableTuple <int> newValue     = new ReadableTuple <int>(id, ServerItemGroupSubAttributes.AttributeList);

            if (modif != DicoModifs.Add)
            {
                selectedItem = (ItemView)_lv.SelectedItem;
                newValue.Copy(selectedItem.SubTuple);
            }

            newValue.SetValue(ServerItemGroupSubAttributes.Rate, rate);
            newValue.SetValue(ServerItemGroupSubAttributes.Id, id);

            Dictionary <int, ReadableTuple <int> > dico = ((ReadableTuple <int>)_tab.List.SelectedItem).GetRawValue <Dictionary <int, ReadableTuple <int> > >(ServerItemGroupAttributes.Table);

            if (dico.ContainsKey(id))
            {
                if (selectedItem != null)
                {
                    int selectedId = selectedItem.ID;

                    if (selectedId != id)
                    {
                        var coll = ((RangeObservableCollection <ItemView>)_lv.ItemsSource);
                        coll.Remove(coll.FirstOrDefault(p => p.ID == id));
                    }
                }
            }

            if (modif == DicoModifs.Add)
            {
                newValue.Added = true;

                if (dico.ContainsKey(id))
                {
                    ErrorHandler.HandleException("The item ID already exists.");
                    return;
                }

                _itemGroupsTable.Commands.StoreAndExecute(new ChangeTupleDicoProperty <int, ReadableTuple <int>, int, ReadableTuple <int> >(
                                                              _tab.List.SelectedItem as ReadableTuple <int>, ServerItemGroupAttributes.Table, id, newValue, id, _addedItem));
            }
            else if (modif == DicoModifs.Edit)
            {
                newValue.Modified = true;
                int oldId = selectedItem.ID;
                selectedItem.ID = id;

                _itemGroupsTable.Commands.StoreAndExecute(new ChangeTupleDicoProperty <int, ReadableTuple <int>, int, ReadableTuple <int> >(
                                                              _tab.List.SelectedItem as ReadableTuple <int>, ServerItemGroupAttributes.Table, oldId, newValue, id));

                selectedItem.VisualUpdate();
            }

            ((RangeObservableCollection <ItemView>)_lv.ItemsSource).ToList().ForEach(p => p.VisualUpdate());
        }