예제 #1
0
 public static ProductAdministrator GetInstance()
 {
     if (_ProductAdministrator == null)
     {
         _ProductAdministrator = new ProductAdministrator();
     }
     return(_ProductAdministrator);
 }
예제 #2
0
        public static void Execute()
        {
            ProductAdministratorExcecuter excecuter = new ProductAdministratorExcecuter(listProductTest);

            ProductAdministrator productAdministrator = ProductAdministrator.GetInstance();

            Console.WriteLine("==============================================================================");
            Console.WriteLine("-->Add a new product.");
            Product newProduct = new Product(Category.Book, "123", "Naruto (3-in-1 Edition) Vol. 1: Includes vols. 1, 2 & 3 ", 1462, 16.7676);
            bool    isSuccess  = productAdministrator.AddProduct(newProduct);

            if (isSuccess)
            {
                Console.WriteLine("---->The {0} have just added in the store.", newProduct.Name);
                excecuter.ShowItemsWithTag();
            }
            else
            {
                Console.WriteLine("---->The {0} have just added in the store.", newProduct.Name);
            }
            Console.WriteLine("---------------------------------------------------------------------------");
            string itemId = "bookO2";

            Console.WriteLine("-->Find a product what has id is " + itemId);
            Product foundProduct = productAdministrator.FindById(itemId, true);

            if (foundProduct != null)
            {
                Console.WriteLine("---->The infomation of the product has just found " + foundProduct.ToString());
            }
            else
            {
                Console.WriteLine("----> The {0} is not found.", itemId);
            }
            Console.WriteLine("---------------------------------------------------------------------------");
            string keyword = "java";

            Console.WriteLine("-->Find products what names include \"{0}\" word", keyword);
            List <Product> foundProducts = productAdministrator.FindByName(keyword, true);

            if (foundProducts == null)
            {
                Console.WriteLine("---->Not found anything with the \"{0}\" keyword.", foundProduct.ToString());
            }
            else
            {
                ShowAList(foundProducts);
            }

            Console.WriteLine("---------------------------------------------------------------------------");
            string delete_id = "123";

            Console.WriteLine("--> Delete a product with id is  \"{0}\" ", delete_id);
            isSuccess = productAdministrator.Delete(delete_id);
            if (isSuccess)
            {
                Console.WriteLine("----> Deleting the product has Id is \"{0}\" successful", delete_id);
            }
            else
            {
                Console.WriteLine("----> Deleting the product has Id is \"{0}\" unsuccessful", delete_id);
            }
            Console.WriteLine("==============================================================================");
            Console.WriteLine("商品の値段の合計: {0} 商品の値段の平均: {1} ", excecuter.TotalPrice, excecuter.PriceAverage);
            Console.WriteLine("---------------------------------------------------------------------------");
            Console.WriteLine("商品の利益率の最大: {0} 商品の利益率の最小: {1} 商品の利益率の平均: {2} ", excecuter.MaximumOfProfitRate, excecuter.MinimumOfProfitRate, excecuter.AverageOfProfitRate);
            Console.WriteLine("---------------------------------------------------------------------------");
            Console.WriteLine("利益の合計: {0} 利益の最大: {1} 利益の最小 {2} 利益の平均: {3} ", excecuter.Profit, excecuter.MaximumOfProfit, excecuter.MinimumOfProfit, excecuter.AverageOfProfit);
            Console.WriteLine("---------------------------------------------------------------------------");
            Console.WriteLine("-->Display all information of all of products");
            excecuter.ShowProducts();
            Console.WriteLine("---------------------------------------------------------------------------");
            Console.WriteLine("-->Display all information of all of products with tags");
            excecuter.ShowItemsWithTag();
        }
예제 #3
0
 public ProductAdministratorExcecuter(List <Product> list)
 {
     productAdministrator = ProductAdministrator.GetInstance();
     productAdministrator.AddProducts(list);
 }