Example #1
0
 public Product[] GetProducts()
 {
     Product[] tmp = new Product[Count];
     for (int i = 0; i < Count; i++)
         tmp[i] = Products[i];
     return tmp;
 }
Example #2
0
 public IEnumerator GetEnumerator()
 {
     Product[] tmp = new Product[Count];
     for (int i =0; i < Count; i++)
         tmp[i] = Products[i];
     return tmp.GetEnumerator();
 }
Example #3
0
 /// <summary>
 /// add a new Product to the list
 /// </summary>
 /// <param name="newPdt"></param>
 public void Add(Product newPdt)
 {
     if (Count < Products.Length) {
         Products[Count++] = newPdt;
     }
     else {
         // expand the list
         ExpandArray();
         Add(newPdt);
     }
 }
Example #4
0
 public int IndexOf(Product pdt)
 {
     int ret = -1;
     bool found = false;
     int c = 0;
     while (!found && c < Count) {
         if (pdt.Equals(Products[c++])) {
             found = true;
             ret = c-1;
         }
     }
     return ret;
 }
Example #5
0
        private void button_Add_Click(object sender, RoutedEventArgs e)
        {
            if (NameTB.Text.Any() && AmountTB.Text.Any() && InfoTB.Text.Any()) {
                Product p =  new Product(NameTB.Text, int.Parse(AmountTB.Text));
                p.ProductInfo = InfoTB.Text;
                Inv.Add(p);
            }
            else if (NameTB.Text.Any() && AmountTB.Text.Any()) {
                Inv.Add(new Product(NameTB.Text, int.Parse(AmountTB.Text)));
            }
            else if (NameTB.Text.Any()) {
                Inv.Add(new Product(NameTB.Text));
            }
            else {

            }
            button_Clear_Click(null, null);
            UpdateList();
        }
Example #6
0
 public Product Remove(int index)
 {
     if (index < Count && index > -1) {
         Product[] tmp = new Product[Products.Length];
         int i = 0;
         for (; i < index; i++)
             tmp[i] = Products[i];
         //Console.WriteLine(i);//DEBUG
         Product ret = Products[i++];
         for (; i < Products.Length; i++)
             tmp[i - 1] = Products[i];
         Products = tmp;
         Count--;
         return ret;
     }
     else if (index  == -1) {
         return null;
     }
     else {
         throw new System.IndexOutOfRangeException();
     }
 }
Example #7
0
 /// <summary>
 /// Expands the Array with a countstan amount of 10
 /// </summary>
 private void ExpandArray()
 {
     Product[] tmp = new Product[Products.Length + 10];
     for (int i = 0; i < Products.Length; i++) {
         tmp[i] = Products[i];	//filling tmp with products
     }
     Products = tmp;
 }
Example #8
0
 /// <summary>
 /// will add and expand the array
 /// </summary>
 /// <param name="index"></param>
 /// <param name="newPdt"></param>
 public void SetProduct(int index, Product newPdt)
 {
     if (index < Count) {
         Product[] tmp = Count  < Products.Length ? new Product[Products.Length] : new Product[Products.Length + 1];
         int i = 0;
         for( ; i < index; i++)
             tmp[i] = Products[i];		//Pre - Filling
         tmp[i++]= newPdt;				//adding
         for (; i < tmp.Length; i++)
             tmp[i] = Products[i - 1];   //Post filling
         Products = tmp;
         Count++;
     }
     else
         throw new System.IndexOutOfRangeException();
 }
Example #9
0
 public Product Remove(Product pdt)
 {
     return Remove(IndexOf(pdt));
 }