Beispiel #1
0
        public void addWithNum(tbl_Product item, int no)
        {
            Cart c   = new Cart(item, no);
            int  num = getID(item);

            if (this.arrCart.Count == 0)
            {
                this.arrCart.Add(c);
                this.amounts += no;
                this.cost    += c.cost;
            }
            else
            {
                if (num < 0)
                {
                    this.arrCart.Add(c);
                    this.amounts += no;
                    this.cost    += c.cost;
                }
                else
                {
                    c.amounts++;
                    this.arrCart[num] = c;
                    this.amounts     += no;
                    this.cost        += c.cost;
                }
            }
        }
Beispiel #2
0
 public Cart(Cart oldCart)
 {
     if (oldCart != null)
     {
         this.item    = oldCart.item;
         this.amounts = oldCart.amounts;
         this.cost    = oldCart.cost;
     }
 }
Beispiel #3
0
        public void remove(tbl_Product item, int no)
        {
            int  num  = getID(item);
            Cart cart = (Cart)this.arrCart[num];

            this.amounts -= no;
            this.cost    -= cart.cost * no;
            this.arrCart.RemoveAt(num);
        }
Beispiel #4
0
 public Cart(tbl_Product item, int num)
 {
     this.amounts += num;
     if (item.discount > 0)
     {
         this.cost = item.discount;
     }
     else
     {
         this.cost = item.price;
     }
     this.item = item;
 }
Beispiel #5
0
        public int getID(tbl_Product p)
        {
            int num = -1;

            if (this.arrCart.Count != 0)
            {
                for (int i = 0; i < this.arrCart.Count; i++)
                {
                    Cart item = (Cart)this.arrCart[i];
                    if (item.item.id == p.id)
                    {
                        num = i;
                        break;
                    }
                }
            }
            return(num);
        }
Beispiel #6
0
 public Cart()
 {
     this.item    = null;
     this.amounts = 0;
     this.cost    = 0;
 }