/// <summary> /// Splits this product category in two with the new product category inheriting the specified quantity from this /// product. /// </summary> /// <param name="quantity">The quantity of product to be removed from this product and placed into the new /// product</param> /// <returns>Reference to a new product that holds the specified quantity.</returns> public Product Split(int quantity=0) { Product product = new Product(this.Model, this.Price); // if the some of the quantity of this product is being shared with the new product if (quantity > 0) { // Remove the desired quantity from this product this.Quantity -= quantity; // If there wasn't enough in this product category if (this.Quantity < 0) { // Add to the new product whatever quantity is available product.Quantity = quantity + this.Quantity; this.Quantity = 0; // This product category is now empty } else { // Otherwise, split the amount of available quantity in the desired amount product.Quantity = quantity; } } // Reference to a new product return product; }
/// <summary> /// 根据顾客购买的物品计算价格 /// </summary> /// <param name="pros">物品类型</param> /// <returns>总价格</returns> public double GetMoney(Product[] pros) { double money = 0; for (int i = 0; i < pros.Length; i++) { money += pros[i].Price; } return money; }
/// <summary> /// Add the given product to this shelf /// </summary> /// <param name="product">The product to put on this shelf</param> public void Add(Product product) { // If a new product is being added if (!Contains(product.Name)) { // Add to directory supermarket.AddToDirectory(product.Name, this); } inventory.Add(product); }
/// <summary> /// Adds the given product to this inventory if it has a quantity greater than 0. /// </summary> /// <param name="product">The product to store in this inventory.</param> public void Add(Product product) { // Only store product if it has a quantity greater than 0 if (product.Quantity > 0) { // If inventory already has a stack of this product if (items.ContainsKey(product.Name)) { // Combine stacks items[product.Name].Quantity += product.Quantity; } else { // New entry items.Add(product.Name, product); } // Recalculate the new total cost of all items. CalculateTotal(); } }
/// <summary> /// 仓库取货 /// </summary> /// <param name="type">货物类型</param> /// <param name="count">货物数量</param> /// <returns></returns> public Product[] QuPros(string type,int count) { Product[] pros=new Product[count]; for (int i = 0; i < count; i++) { switch (type) { case "Acer":pros[i]=list[0][0]; list[0].RemoveAt(0); break; case "SamSung":pros[i]=list[1][0]; list[1].RemoveAt(0); break; case "JiangYou":pros[i]=list[2][0]; list[2].RemoveAt(0); break; case "Banana":pros[i]=list[3][0]; list[3].RemoveAt(0); break; } } return pros; }