示例#1
0
 public bool DeleteProduct(string id, double quantity = 0)
 {
     if (quantity < 0)
     {
         return(false);
     }
     if (_list.ContainsKey(id))
     {
         if (quantity == 0)
         {
             _list.Remove(id);
             return(true);
         }
         else
         {
             if (GetProduct(id).ProductQuantity - quantity > 0)
             {
                 GetProduct(id).ProductQuantity           -= quantity;
                 StoreList.GetProduct(id).ProductQuantity += quantity;
             }
             else if (GetProduct(id).ProductQuantity - quantity == 0)
             {
                 //StoreList.GetProduct(id).ProductQuantity += quantity;
                 DeleteProduct(id);
             }
             else
             {
                 return(false);
             }
             return(true);
         }
     }
     return(false);
 }
示例#2
0
        private void Search()
        {
            Console.Write("Enter ProductId to look for: ");
            string id = Console.ReadLine();

            if (StoreList.GetProduct(id) != null)
            {
                Console.WriteLine("{0,-25} {1,-25} {2,-25} {3,-10} {4,-10}", "ID", "Name", "Category", "Price", "Quantity");
                StoreList.GetProduct(id).Print();
            }
            else
            {
                Console.WriteLine("Poduct with Id ({0}) does not exist!", id);
            }
        }
示例#3
0
        public override void AddProduct()
        {
            if (StoreList.isEmpty())
            {
                Console.WriteLine("Store is empty!");
                return;
            }
            Console.WriteLine("Available products");
            StoreList.ViewStoreList(false);
            Console.WriteLine("Products in basket");
            Basket.ViewBasket();
            Console.Write("Enter product ID to add to basket: ");
            string tempID = Console.ReadLine();

            try
            {
                Product temp = StoreList.GetProduct(tempID).Clone();
                if (temp.ProductQuantity == 0)
                {
                    throw new NullReferenceException();
                }
                Console.Write("Enter quantity: ");
                double uquan = Convert.ToDouble(Console.ReadLine());
                if (uquan < 0)
                {
                    throw new FormatException();
                }
                if (temp.ProductQuantity - uquan >= 0)
                {
                    temp.ProductQuantity = uquan;
                    StoreList.GetProduct(tempID).ProductQuantity -= uquan;
                    Basket.Add(temp, uquan);
                    SaveUser();
                }
                else
                {
                    Console.WriteLine("Desired quantity is unavailable!");
                }
            }
            catch (NullReferenceException)
            {
                Console.WriteLine("Product doesn\'t exist!");
            }
            catch (FormatException)
            {
                Console.WriteLine("Wrong value entered!");
            }
        }
示例#4
0
        private void DeleteProductFromStore()
        {
            ViewList();
            Console.Write("Enter ID of product to remove: ");
            string uchoice = Console.ReadLine();
            double quan    = 0;

            if (StoreList.GetProduct(uchoice) != null)
            {
                if (StoreList.GetProduct(uchoice).ProductQuantity != 0)
                {
                    Console.Write("Enter quantity: ");
                    try
                    {
                        quan = Convert.ToDouble(Console.ReadLine());
                        if (quan > StoreList.GetProduct(uchoice).ProductQuantity)
                        {
                            Console.WriteLine("Can\'t remove more than available quantity");
                            throw new FormatException();
                        }
                        if (quan < 0)
                        {
                            throw new FormatException();
                        }
                    }
                    catch (FormatException)
                    {
                        Console.WriteLine("Wrong value entered!");
                        return;
                    }
                }
                if (!StoreList.DeleteProduct(uchoice, quan))
                {
                    Console.WriteLine("Wrong choice!");
                }
            }
            else
            {
                Console.WriteLine("Product does not exist!");
            }
        }
示例#5
0
        public override void AddProduct()
        {
            string id;

            Console.Write("Please enter product ID: ");
            id = Console.ReadLine();
            if (StoreList.GetProduct(id) != null)
            {
                Console.Write("Product already exists, would you like to add by a certain quantity?(Y/N): ");
                string uchoice = Console.ReadLine().ToUpper();
                try
                {
                    if (uchoice == "Y")
                    {
                        while (true)
                        {
                            Console.Write("Enter quantity to increase by: ");
                            double quan = Convert.ToDouble(Console.ReadLine());
                            if (quan < 0)
                            {
                                throw new FormatException();
                            }
                            StoreList.AddProduct(id, quan);
                            break;
                        }
                    }
                    else if (uchoice != "N")
                    {
                        throw new FormatException();
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine("Wrong value entered!");
                }
            }
            else
            {
                StoreList.AddProduct(id);
            }
        }