예제 #1
0
        /// <summary>
        /// Update a price of a product.
        ///   The price of the product will be update to new price that user enters.
        /// </summary>
        /// <param name="numberOfCatalogues">The number of catalogues created.</param>
        private static void UpdatePrice(ref int numberOfCatalogues)
        {
            if (numberOfCatalogues == 0)
            {
                Console.WriteLine("No catalogues exist. Please create a catalogue first.");
                return;
            }

            ProductCatalogue cata = SelectCatalogue(numberOfCatalogues);

            // Show all products in the catalogue and products in it.
            ShowProductNamesAndPrice(cata);
            if (cata.NumberOfProducts == 0)
            {
                return;
            }

            int index = SelectProduct(cata.NumberOfProducts);
            //show a product that a user selected
            ProductData data = cata.GetProduct(index - 1);

            Console.Write("You have selected {0}.", data.ProductName);
            Console.WriteLine("The current retail price is {0:c2}.", data.RetailPrice);
            //update the price
            data.RetailPrice = InputHelper.GetPositiveDoubleFromUser("Please enter the new price: ");

            Console.WriteLine();
        }
예제 #2
0
        /// <summary>
        /// Select catalogue.
        ///     User selects existing catalogues.
        /// </summary>
        /// <param name="numberOfCatalogues">The number of catalogues created.</param>
        /// <returns>ProductCatalogue object.</returns>
        private static ProductCatalogue SelectCatalogue(int numberOfCatalogues)
        {
            ShowAllCatalogueNames(numberOfCatalogues);

            int index = InputHelper.GetIntFromUser(
                "Please choose the catalogues: ", MIN_INDEX_NUM, numberOfCatalogues);
            ProductCatalogue ret = Catalogues[index - 1];

            return(ret);
        }
예제 #3
0
 /// <summary>
 /// Show all products in the catalog.
 /// </summary>
 /// <param name="cata">Product catalog.</param>
 private static void ShowProductNamesAndPrice(ProductCatalogue cata)
 {
     if (cata == null || cata.NumberOfProducts == 0)
     {
         Console.WriteLine("No products exist.");
         return;
     }
     for (int i = 0; i < cata.NumberOfProducts; i++)
     {
         ProductData data = cata.GetProduct(i);
         //product number starts from 1, thus "+1"
         Console.WriteLine("{0}. {1}: {2:c2}", (i + 1), data.ProductName, data.RetailPrice);
     }
 }
예제 #4
0
        /// <summary>
        /// Create a new catalogue.
        ///     If the number of catalogue is as same as MAX_NUM_CATALOGUES, the method shows an error message.
        /// </summary>
        /// <param name="numberOfCatalogues">The number of catalogues created.</param>
        private static void CreateCatalogue(ref int numberOfCatalogues)
        {
            //check existance of any catalogues
            if (numberOfCatalogues == MAX_NUM_CATALOGUES)
            {
                Console.WriteLine("Catalogue list is full.");
                return;
            }
            string           name = InputHelper.GetStringFromUser("Please enter a new catalogue name: ");
            ProductCatalogue cata = new ProductCatalogue(name);

            Catalogues[numberOfCatalogues] = cata;
            numberOfCatalogues++;
        }
예제 #5
0
        /// <summary>
        /// Show average price per catalogue.
        ///     Price is not displayed if there are no products.
        /// </summary>
        /// <param name="numberOfCatalogues">The number of catalogues created.</param>
        private static void ShowAvgPricePerCatalogue(int numberOfCatalogues)
        {
            if (numberOfCatalogues == 0)
            {
                Console.WriteLine("No catalogues exist. Please create a catalogue first.");
                return;
            }

            //loop to show all catalogues' average price
            for (int i = 0; i < numberOfCatalogues; i++)
            {
                ProductCatalogue cata = Catalogues[i];
                Console.Write("You have {0} products in {1}. ", cata.NumberOfProducts, cata.CatalogueName);
                if (cata.NumberOfProducts > 0)
                {
                    double avgPrice = cata.GetAvgPrice();
                    Console.WriteLine("The average retail price is: {0:c2}.", avgPrice);
                }
                else
                {
                    Console.WriteLine("");
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Add product and its price.
        ///   The method ask to enter a product name and its price respectively,
        ///   then stores them in a catalogue previously selected by the user.
        /// </summary>
        /// <param name="numberOfCatalogues">The number of catalogues created.</param>
        private static void AddProductAndPrice(ref int numberOfCatalogues)
        {
            if (numberOfCatalogues == 0)
            {
                Console.WriteLine("No catalogues exist. Please create a catalogue first.");
                return;
            }
            ProductCatalogue cata = SelectCatalogue(numberOfCatalogues);

            Console.WriteLine("You have chosen {0}.", cata.CatalogueName);

            //Check the number of products in the catalogue.
            if (cata.NumberOfProducts == ProductCatalogue.MAX_NUM_PRODUCTS)
            {
                Console.WriteLine("Cannot add a product. The catalog is full. ");
                return;
            }

            string name  = InputHelper.GetStringFromUser("Enter the name of a new product in your catalogue: ");
            double price = InputHelper.GetPositiveDoubleFromUser(string.Format("Enter the retail price of {0}: ", name));

            cata.InsertProduct(new ProductData(name, price));
            Console.WriteLine();
        }