Remove() публичный Метод

public Remove ( Item item ) : void
item Item
Результат void
Пример #1
0
        public void Methods_Control()
        {
            Slider    a = new Slider();
            Button    b = new Button();
            TextBlock c = new TextBlock();

            ItemCollection ic = GetCollection();

            Assert.IsNull(a.Parent, "Slider-Parent-0");

            ic.Add(a);
            Assert.IsNotNull(a.Parent, "Slider-Parent-1");
            Assert.AreSame(Parent, a.Parent, "Slider-Parent-1-Same");
            Assert.AreEqual(1, ic.Count, "Count-1");

            ic.Insert(0, ic);
            Assert.AreEqual(2, ic.Count, "Count-2");

            Assert.IsNull(b.Parent, "Button-Parent-2");
            ic.Insert(0, b);
            Assert.AreSame(Parent, b.Parent, "Button-Parent-3");
            Assert.AreEqual(3, ic.Count, "Count-3");

            Assert.AreEqual(1, ic.IndexOf(ic), "IndexOf");
            Assert.AreEqual(-1, ic.IndexOf(c), "IndexOf-not in collection");

            Assert.IsTrue(ic.IndexOf(a) >= 0, "IndexOf(object)");
            Assert.IsTrue(ic.Contains(a), "Contains(object)");
            Assert.IsFalse(ic.Contains(c), "Contains(moon)");

            ic.Remove(a);
            Assert.IsNull(a.Parent, "Slider-Parent-4");
            Assert.AreEqual(2, ic.Count, "Count-4");

            ic.RemoveAt(0);
            Assert.AreEqual(1, ic.Count, "Count-5");

            ic.Clear();
            Assert.AreEqual(0, ic.Count, "Count-6");

            // try removing an element not in the
            // collection (when we know it has a different
            // parent)
            ItemsControl   parent2 = new ItemsControl();
            ItemCollection ic2     = parent2.Items;

            ic2.Add(a);

            ic.Remove(a);
            Assert.AreEqual(parent2, a.Parent, "Parent-different-collection");
        }
Пример #2
0
        public static void RemoveAll <T>(this Selector selector, Predicate <T> predicate)
        {
            ItemCollection items = selector.Items;
            List <T>       list  = new List <T>(items.Cast <T>().Where(o => predicate(o)));

            list.ForEach(o => items.Remove(o));
        }
Пример #3
0
        private void AddUpdate()
        {
            if (_date.Length == 0 || _name.Length == 0 || _amount.Length == 0)
            {
                return;
            }

            if (_isAddMode == false)
            {
                _selectedItem.DeleteData();
                ItemCollection.Remove(_selectedItem);
            }

            DailyModel newItem = new DailyModel();

            newItem.Type   = _selectedType;
            newItem.Date   = _date;
            newItem.Name   = _name;
            newItem.Amount = int.Parse(_amount.Replace(",", ""));

            ItemCollection.Add(newItem);

            newItem.AddData();

            _lastSearchedStartDayofPeriod = DateTime.MinValue; // In order to update period total amount
            _monthSearched = 0;                                // In order to update monthly total amount
            InitializeList();                                  // In order to update all the IDs
            TextBoxInitialize();
            UpdateText();
        }
Пример #4
0
        public void Methods_Int()
        {
            int a = 5;
            int b = 6;
            int c = 7;

            ItemCollection ic = GetCollection();

            ic.Add(a);
            Assert.AreEqual(1, ic.Count, "Count-1");

            ic.Insert(0, ic);
            Assert.AreEqual(2, ic.Count, "Count-2");

            ic.Insert(0, b);
            Assert.AreEqual(3, ic.Count, "Count-3");

            Assert.AreEqual(1, ic.IndexOf(ic), "IndexOf");
            Assert.AreEqual(-1, ic.IndexOf(c), "IndexOf-not in collection");

            Assert.IsTrue(ic.IndexOf(a) >= 0, "IndexOf(object)");
            Assert.IsTrue(ic.Contains(a), "Contains(object)");
            Assert.IsFalse(ic.Contains(c), "Contains(moon)");

            ic.Remove(a);
            Assert.AreEqual(2, ic.Count, "Count-4");

            ic.RemoveAt(0);
            Assert.AreEqual(1, ic.Count, "Count-5");

            ic.Clear();
            Assert.AreEqual(0, ic.Count, "Count-6");
        }
Пример #5
0
        private void painter_Disconnected(Painter obj)
        {
            PainterClient client = clients.Remove(obj);

            MainCanvas.Dispatcher.BeginInvoke(new Action(() => connectedClientsView.Remove(client.ControlComponent)));
            Log.Debug(String.Format("Client {0} disconnected", obj.RemoteName));
        }
Пример #6
0
 public static void AddComBoxItem(IList <ControlsObject> controls, ComboBox comboBox, object imtemTemplete, bool remove = false, int index = 0)
 {
     if (controls != null && controls.Count > 0)
     {
         Thickness padding;
         if (imtemTemplete != null)
         {
             ComboBoxItem temp = (ComboBoxItem)(imtemTemplete);
             padding = temp.Padding;
         }
         else
         {
             padding = new Thickness();
         }
         ItemCollection collection = comboBox.Items;
         IList <String> list       = CollectionToContents(collection);
         foreach (ControlsObject obj in controls)
         {
             if (!list.Contains(obj.Disname))
             {
                 ComboBoxItem item = new ComboBoxItem();
                 item.Content     = obj.Disname;
                 item.Padding     = padding;
                 item.DataContext = obj;
                 collection.Add(item);
             }
         }
         if (remove)
         {
             collection.Remove(imtemTemplete);
         }
         comboBox.SelectedIndex = index;
     }
 }
Пример #7
0
 public static void RemoveAll(this ItemCollection collection, IList items)
 {
     foreach (var item in items)
     {
         collection.Remove(item);
     }
 }
        public void EventsArgsBufferedTest()
        {
            using (var temp = TempDirectory.Create())
            {
                ItemCollectionChangedEventArgs <DatabaseObject> itemColArgs    = null;
                ItemUpdatedEventArgs <DatabaseObject>           itemUpdateArgs = null;
                var col = new ItemCollection <DatabaseObject>(temp.TempPath);
                col.ItemUpdated           += (e, args) => itemUpdateArgs = args;
                col.ItemCollectionChanged += (e, args) => itemColArgs = args;
                var item = new DatabaseObject();

                col.BeginBufferUpdate();
                col.Add(item);
                col.Update(item);
                col.Update(item);
                col.Remove(item);
                Assert.IsNull(itemColArgs);
                Assert.IsNull(itemUpdateArgs);

                col.EndBufferUpdate();
                Assert.AreEqual(1, itemColArgs.AddedItems.Count);
                Assert.AreEqual(1, itemColArgs.RemovedItems.Count);
                Assert.AreEqual(2, itemUpdateArgs.UpdatedItems.Count);
            }
        }
Пример #9
0
 /// <summary>
 /// 添加不重复的item
 /// </summary>
 /// <param name="texts"></param>
 /// <param name="comboBox"></param>
 /// <param name="imtemTemplete">模板item</param>
 /// <param name="remove">是否移除模板数据</param>
 public static void AddComBoxItem(IList <string> texts, ComboBox comboBox, object imtemTemplete, bool remove = false, int index = 0)
 {
     if (texts != null && texts.Count > 0)
     {
         Thickness padding;
         if (imtemTemplete != null)
         {
             ComboBoxItem temp = (ComboBoxItem)(imtemTemplete);
             padding = temp.Padding;
         }
         else
         {
             padding = new Thickness();
         }
         ItemCollection collection = comboBox.Items;
         IList <String> list       = CollectionToContents(collection);
         foreach (string text in texts)
         {
             if (!list.Contains(text))
             {
                 ComboBoxItem item = new ComboBoxItem();
                 item.Content = text;
                 item.Padding = padding;
                 collection.Add(item);
             }
         }
         if (remove)
         {
             collection.Remove(imtemTemplete);
         }
         comboBox.SelectedIndex = index;
     }
 }
Пример #10
0
        public void Methods_String()
        {
            ItemCollection ic = GetCollection();

            ic.Add("string");
            Assert.AreEqual(1, ic.Count, "Count-1");

            ic.Insert(0, ic);
            Assert.AreEqual(2, ic.Count, "Count-2");

            ic.Insert(0, "another");
            Assert.AreEqual(3, ic.Count, "Count-3");

            Assert.AreEqual(1, ic.IndexOf(ic), "IndexOf");
            Assert.AreEqual(-1, ic.IndexOf("mono"), "IndexOf-not in collection");

            Assert.IsTrue(ic.IndexOf("string") >= 0, "IndexOf(string)");
            Assert.IsTrue(ic.Contains("string"), "Contains(string)");
            Assert.IsFalse(ic.Contains("moon"), "Contains(moon)");

            ic.Remove("string");
            Assert.AreEqual(2, ic.Count, "Count-4");

            ic.RemoveAt(0);
            Assert.AreEqual(1, ic.Count, "Count-5");

            ic.Clear();
            Assert.AreEqual(0, ic.Count, "Count-6");
        }
Пример #11
0
        public void RemoveNull()
        {
            // SL3+ doesn't throw if you try to remove 'null'
            ItemCollection ic = GetCollection();

            ic.Remove(null);
        }
Пример #12
0
        private void AddDBObjectsToTree(List <ObjectDTO> objects, ItemCollection collection)
        {
            collection.Clear();
            foreach (var item in objects)
            {
                var node         = AddDBObjectsToTree(item, collection);
                var childObjects = item.ChildObjects;// bizDatabaseToObject.GetDatabaseChildObjects(item.ObjectCategory, item.Title, Convert.ToInt32(item.ObjectIdentity));
                if (childObjects.Any())
                {
                    AddDBObjectsToTree(childObjects, node.Items);
                    if (item.ObjectCategory == DatabaseObjectCategory.Database || item.ObjectCategory == DatabaseObjectCategory.Schema)
                    {
                        node.IsExpanded = true;
                    }
                }
                else
                {
                    //if (item.ObjectCategory != DatabaseObjectCategory.Archive && item.ObjectCategory != DatabaseObjectCategory.Letter)
                    //{

                    //}
                    if (item.ObjectCategory == DatabaseObjectCategory.Schema || item.ObjectCategory == DatabaseObjectCategory.Database)
                    {
                        collection.Remove(node);
                    }
                }
            }
        }
Пример #13
0
        public void Delete(ItemCollection sender, RoutedPropertyChangedEventArgs <PUComboBoxItem> e)
        {
            var item = e.NewValue as PUComboBoxItem;

            PUMessageBox.ShowDialog($"你点击了“{item.Content}”的删除按钮,但该项目不会立即删除。\n你可以在验证是否允许删除后再手动移除。在此弹窗关闭后,你点击的行项目将会被移除。");
            sender.Remove(item);
        }
Пример #14
0
        public void EventsArgsNonBufferedTest()
        {
            using (var temp = TempDirectory.Create())
            {
                ItemCollectionChangedEventArgs <DatabaseObject> itemColArgs    = null;
                ItemUpdatedEventArgs <DatabaseObject>           itemUpdateArgs = null;
                var col = new ItemCollection <DatabaseObject>(temp.TempPath);
                col.ItemUpdated           += (e, args) => itemUpdateArgs = args;
                col.ItemCollectionChanged += (e, args) => itemColArgs = args;
                var item = new DatabaseObject()
                {
                    Name = "Original"
                };

                col.Add(item);
                Assert.AreEqual(1, itemColArgs.AddedItems.Count);
                Assert.AreEqual(item, itemColArgs.AddedItems[0]);
                Assert.AreEqual(0, itemColArgs.RemovedItems.Count);

                item.Name = "New";
                col.Update(item);
                Assert.AreEqual(1, itemUpdateArgs.UpdatedItems.Count);
                Assert.AreEqual("Original", itemUpdateArgs.UpdatedItems[0].OldData.Name);
                Assert.AreEqual("New", itemUpdateArgs.UpdatedItems[0].NewData.Name);

                col.Remove(item);
                Assert.AreEqual(0, itemColArgs.AddedItems.Count);
                Assert.AreEqual(1, itemColArgs.RemovedItems.Count);
                Assert.AreEqual(item, itemColArgs.RemovedItems[0]);
            }
        }
Пример #15
0
 public void RemoveElement(ViewModelTreeNode node)
 {
     table.RemoveElement(node.Element.ID);
     nodes.Remove(node);
     displayNodes.Remove(node.GuiItem);
     UpdateAll();
 }
Пример #16
0
        public void DeleteSelectedNode(ItemCollection collection, SQLTreeItem itemToDelete)
        {
            foreach (SQLTreeItem i in collection)
            {
                if (i.Items.Count > 0)
                {
                    if (i == itemToDelete)
                    {
                        collection.Remove(i);
                        break;
                    }

                    int index = i.Items.IndexOf(itemToDelete);
                    if (index > -1)
                    {
                        i.Items.RemoveAt(index);
                        break;
                    }
                    else
                    {
                        DeleteSelectedNode(i.Items, itemToDelete);
                    }
                }
            }
        }
Пример #17
0
        public TextTabViewModel(params FileData[] defaultDatas)
        {
            var dataArray       = defaultDatas.Length != 0 ? defaultDatas : new[] { FileData.DefaultData, FileData.DefaultData };
            var dropFileCommand = new DelegateCommand <MarkdownViewModel>((model) => ItemCollection.Remove(model));

            ItemCollection  = new ObservableCollection <MarkdownViewModel>(dataArray.Select(data => new MarkdownViewModel(data)).ToArray());
            ItemCollections = ItemCollection;
        }
Пример #18
0
        public void CannotRemoveMoreThanWhatWeHave()
        {
            var collection = new ItemCollection {Item(quantity:5)};
            Assert.That(collection.Remove(Item(quantity:6)), Is.False);

            Assert.That(collection.Count, Is.EqualTo(1));
            Assert.That(collection.ItemCount, Is.EqualTo(5));
        }
Пример #19
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if ("Act".IsRequest())
        {
            switch ("Act".RequestStr().ToUpper())
            {
            case "ATTR":
                //
                ItemCollection Items = BLOB.Attr("ItemID".RequestStr());

                try
                {
                    Items.Remove("安定性");
                    Items.Remove("烧失量");
                    Items.Remove("胶砂流动度");
                    Items.Remove("三氧化硫含量");
                    Items.Remove("氯离子含量");
                    Items.Remove("碱含量");
                    Items.Remove("游离氧化钙含量");
                    Items.Add(new Item()
                    {
                        ItemName = "用量", BindField = "YLL", StandardBindField = ""
                    });
                }
                catch { }
                Response.Write(JsonConvert.SerializeObject(Items));
                Response.End();
                break;

            case "CHART":
                Chart();
                break;
            }
        }
    }
Пример #20
0
        public static void RemoveItems <T>(this Selector selector, IEnumerable <T> elements)
        {
            ItemCollection items = selector.Items;

            foreach (T item in elements)
            {
                items.Remove(item);
            }
        }
Пример #21
0
        public void Delete(ItemCollection sender, RoutedPropertyChangedEventArgs <PUComboBoxItem> e)
        {
            var item = e.NewValue as PUComboBoxItem;

            if (PUMessageBox.ShowConfirm("确定要删除该选项吗?") == true)
            {
                sender.Remove(item);
            }
        }
Пример #22
0
        private TreeViewItem GetTreeViewItemFromAddress(ItemCollection items, string address, double priority)
        {
            var    split            = address.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            var    name             = split[0];
            string remainingAddress = address.Substring(address.IndexOf('/', 1));

            foreach (var item in items)
            {
                if (item is TreeViewItem)
                {
                    if (((TreeViewItem)item).Name == name)
                    {
                        if (split.Count() > 1)
                        {
                            return(GetTreeViewItemFromAddress(((TreeViewItem)item).Items, remainingAddress, priority));
                        }
                        else
                        {
                            //adjust this entry to its right position (because it didn't happen already):
                            ((TreeViewItem)item).Tag = priority;
                            items.Remove(item);
                            int i = 0;
                            while (i < items.Count && (double)((TreeViewItem)items[i]).Tag > priority)
                            {
                                i++;
                            }
                            items.Insert(i, item);

                            return((TreeViewItem)item);
                        }
                    }
                }
            }
            TreeViewItem newItem = new TreeViewItem();

            newItem.Name   = name;
            newItem.Header = name;  //temporary header
            newItem.Tag    = priority;

            //search the right position (based on the priorities):
            int pos = 0;

            while (pos < items.Count && (double)((TreeViewItem)items[pos]).Tag > priority)
            {
                pos++;
            }
            items.Insert(pos, newItem);

            if (split.Count() > 1)
            {
                return(GetTreeViewItemFromAddress(newItem.Items, remainingAddress, priority));
            }
            else
            {
                return(newItem);
            }
        }
Пример #23
0
        private void Delete()
        {
            if (currentTreeViewItem.HasItems)
            {
                CommonFunction.NotifySelection("当前记录有子结点,不能被删除");
                return;
            }

            Action action = () =>
            {
                if (this.CurrentOrderEntity.FBEntityState == FBEntityState.Added)
                {
                    OrderEntity orderEntity = this.EntityList.FirstOrDefault(item => { return(object.Equals(item, this.currentOrderEntity)); });
                    if (orderEntity != null)
                    {
                        this.EntityList.Remove(orderEntity);
                    }
                    else
                    {
                        FBEntity     fbEntity = this.CurrentOrderEntity.FBEntity;
                        T_FB_SUBJECT subject  = fbEntity.Entity as T_FB_SUBJECT;
                        this.dictTreeViewItem[subject.T_FB_SUBJECTTYPE].DeleteFBEntity(fbEntity);
                    }
                    this.CurrentOrderEntity = null;
                }
                else
                {
                    this.CurrentOrderEntity.FBEntityState = FBEntityState.Deleted;
                }

                Type           type  = this.currentTreeViewItem.Parent.GetType();
                PropertyInfo   p     = type.GetProperty("Items");
                ItemCollection items = (ItemCollection)p.GetValue(this.currentTreeViewItem.Parent, null);

                //beyond
                TreeViewItem tempcurrentTreeViewItem = currentTreeViewItem.Parent as TreeViewItem;

                items.Remove(this.currentTreeViewItem);

                //beyond this.currentTreeViewItem
                if (items.Count > 0)
                {
                    this.currentTreeViewItem = items[0] as TreeViewItem;
                }
                else
                {
                    this.currentTreeViewItem = tempcurrentTreeViewItem;
                }

                this.CurrentOrderEntity = currentTreeViewItem.DataContext as OrderEntity;

                //  this.CurrentEditForm.Save();
            };

            CommonFunction.AskDelete(string.Empty, action);
        }
Пример #24
0
        public void RemoveItem(string key)
        {
            _dataRepoItems.Delete(key);
            SampleItem existing = _sampleItems.SingleOrDefault(i => i.Name == key);

            if (existing != null)
            {
                _sampleItems.Remove(existing);
            }
        }
Пример #25
0
 public static void RemoveRange <T>(this ItemCollection collection, IEnumerable <T> items)
 {
     if (items != null)
     {
         for (int index = items.Count() - 1; index >= 0; index--)
         {
             collection.Remove(items.ElementAt(index));
         }
     }
 }
Пример #26
0
        private static bool RegisterMenu(MenuPath path, ItemCollection items, object header, ICommand command, string iconPath)
        {
            while (true)
            {
                if (path.Next == null)
                {
                    if (header is string s)
                    {
                        header = new Localize {
                            Id = s
                        };
                    }

                    var m = new MenuItem {
                        Name       = path.Name,
                        Header     = header,
                        Command    = command,
                        Background = Brushes.Transparent,
                        Icon       = new IconView
                        {
                            Height = 25,
                            Path   = iconPath
                        }
                    };

                    var old = items.Cast <MenuItem>().FirstOrDefault(menu => menu.Name == path.Name);
                    if (old != null)
                    {
                        items.Remove(old);
                        while (old.HasItems)
                        {
                            var item = old.Items[0];
                            old.Items.Remove(item);
                            m.Items.Add(item);
                        }
                    }

                    items.Add(m);
                    return(true);
                }

                var child = items.Cast <MenuItem>().FirstOrDefault(menu => menu.Name == path.Name);

                if (child == null)
                {
                    child = new MenuItem {
                        Name = path.Name
                    };
                    items.Add(child);
                }
                path  = path.Next;
                items = child.Items;
            }
        }
Пример #27
0
        public void RemoveFromLocalRemoveFromParent()
        {
            var global = new ItemCollection();
            var local = new ItemCollection(global);

            local.Add(Item());
            local.Remove(Item());

            Assert.That(local, Is.Empty);
            Assert.That(global, Is.Empty);
        }
Пример #28
0
 private void DeleteObjectInTree(ItemCollection nodes, GameObject item)
 {
     foreach (TreeViewItem node in nodes)
     {
         if (node.DataContext == item)
         {
             nodes.Remove(node);
             break;
         }
         DeleteObjectInTree(node.Items, item);
     }
 }
Пример #29
0
        public IItem Buy(string itemName)
        {
            // try to find it
            var item = items.FirstOrDefault(i => i.Name == itemName);

            // if found, remove from inventory
            if (item != null)
            {
                items.Remove(item);
            }

            return(item);
        }
Пример #30
0
        public void RemoveMenuItem(object parentMenu, object menuItem)
        {
            ItemCollection itemCollection = null;

            if (parentMenu is RadContextMenu)
            {
                itemCollection = (parentMenu as RadContextMenu).Items;
            }
            else if (parentMenu is RadMenuItem)
            {
                itemCollection = (parentMenu as RadMenuItem).Items;
            }
            itemCollection.Remove(menuItem);
        }
Пример #31
0
        /// <summary>
        /// Move selected item down.
        /// </summary>
        public void MoveDownSelectedItem()
        {
            Object         obj   = this.SelectedItem;
            ItemCollection items = this.ControlItems;
            int            index = items.IndexOf(obj);

            ++index;
            if (index < items.Count)
            {
                items.Remove(obj);
                items.Insert(index, obj);
                this.SelectedItem = obj;
            }
        }
Пример #32
0
 public void Execute(HiveTask item, HiveTask parentItem)
 {
     if (parentItem == null)
     {
         hiveTasks.Remove(item);
     }
     else
     {
         var experiment = parentItem.ItemTask.Item as Experiment;
         if (experiment != null)
         {
             experiment.Optimizers.Remove(((OptimizerTask)item.ItemTask).Item);
         }
     }
 }
        public void FullNameCorrectWhenAdded()
        {
            Enterprise enterprise = new Enterprise {name = "Company"};
            ItemCollection<Area> areas = new ItemCollection<Area>(enterprise);

            Area area1 = new Area {name = "Area 1"};

            Assert.That(area1.FullName, Is.EqualTo("Area 1"));

            areas.Add(area1);

            Assert.That(areas.Count, Is.EqualTo(1));
            Assert.That(area1.FullName, Is.EqualTo("Company.Area 1"));

            areas.Remove(area1);
            Assert.That(areas.Count, Is.EqualTo(0));
            Assert.That(area1.FullName, Is.EqualTo("Area 1"));
        }
Пример #34
0
        public void RemoveItemOfSameType()
        {
            var collection = new ItemCollection {Item(quantity:5), Item(quantity:3)};
            collection.Remove(Item(quantity:4));

            Assert.That(collection.Count, Is.EqualTo(1));
            Assert.That(collection.ItemCount, Is.EqualTo(4));
        }
Пример #35
0
        public void RemoveItem()
        {
            var item = Item();
            var collection = new ItemCollection {item};
            collection.Remove(item);

            Assert.That(collection, Is.Empty);
        }
Пример #36
0
        public void RemoveMultipleItems()
        {
            var collection = new ItemCollection();
            collection.Add(_itemFactory.Build(ItemCode.LightFrigate, 10));
            collection.Remove(_itemFactory.Build(ItemCode.LightFrigate, 5));

            Assert.That(collection.Count, Is.EqualTo(1));
            Assert.That(collection.ItemCount, Is.EqualTo(5));
        }
Пример #37
0
        public void CanRemoveItemThatDoesNotExist()
        {
            var collection = new ItemCollection();
            collection.Add(_itemFactory.Build(ItemCode.LightFrigate, 10));

            bool canRemove = collection.Remove(_itemFactory.Build(ItemCode.MiningLaser, 1));
            Assert.That(canRemove, Is.False);

            canRemove = collection.Remove(_itemFactory.Build(ItemCode.LightFrigate, 20));
            Assert.That(canRemove, Is.False);

            Assert.That(collection.Contains(ItemCode.LightFrigate, 10));
        }