Пример #1
0
        /// <summary>
        /// Clear the list.
        /// </summary>
        public void Clear()
        {
            productsCollection.Clear();
            ModificationEventArgs e = new ModificationEventArgs(ModificationEventStatus.successful, this);

            OnCollectionModified(e);
        }
Пример #2
0
        public event CollectionModifiedHandler CollectionModified; //declares event

        /// <summary>
        /// Method that takes in a ModificationEventArgs arguments,
        /// then raises the CollectionModified event.
        /// </summary>
        /// <param name="mea">ModificationEventArgs</param>
        public void OnCollectionModified(ModificationEventArgs mea)
        {
            //if there is no listener then ignore.
            if (CollectionModified != null)
            {
                CollectionModified(this, mea); //raises event
            }
        }
Пример #3
0
 /// <summary>
 /// Inserts into the collection an certain item at a certain index
 /// </summary>
 /// <param name="index">index</param>
 /// <param name="item">Product</param>
 public void Insert(int index, Product item)
 {
     if (!productsCollection.Contains(item))
     {
         productsCollection.Insert(index, item);
         ModificationEventArgs e = new ModificationEventArgs(ModificationEventStatus.successful, this);
         OnCollectionModified(e);
     }
     else
     {
         ModificationEventArgs e = new ModificationEventArgs(ModificationEventStatus.unsuccessful, this);
         OnCollectionModified(e);
     }
 }
Пример #4
0
        /// <summary>
        /// Removes an item from the collection at specified index
        /// </summary>
        /// <param name="index">index</param>
        public void RemoveAt(int index)
        {
            int count = productsCollection.Count;

            productsCollection.RemoveAt(index);
            if (count == productsCollection.Count)
            {
                ModificationEventArgs e = new ModificationEventArgs(ModificationEventStatus.successful, this);
                OnCollectionModified(e);
            }
            else
            {
                ModificationEventArgs e = new ModificationEventArgs(ModificationEventStatus.unsuccessful, this);
                OnCollectionModified(e);
            }
        }
Пример #5
0
 /// <summary>
 /// Removes an item from the productsCollection
 /// </summary>
 /// <param name="item">Product</param>
 /// <returns>true = success or false = failure</returns>
 public bool Remove(Product item)
 {
     if (productsCollection.Contains(item))
     {
         productsCollection.Remove(item);
         ModificationEventArgs e = new ModificationEventArgs(ModificationEventStatus.successful, this);
         OnCollectionModified(e);
         return(true);
     }
     else
     {
         ModificationEventArgs e = new ModificationEventArgs(ModificationEventStatus.unsuccessful, this);
         OnCollectionModified(e);
         return(false);
     }
 }
Пример #6
0
 /// <summary>
 /// Get/set the index property in the collection
 /// </summary>
 /// <param name="index">index</param>
 /// <returns>Product</returns>
 public Product this[int index]
 {
     get
     {
         return(productsCollection[index]);
     }
     set
     {
         if (!productsCollection.Contains(value))
         {
             ModificationEventArgs e = new ModificationEventArgs(ModificationEventStatus.successful, this);
             OnCollectionModified(e);
         }
         else
         {
             productsCollection[index] = value;
         }
     }
 }