Exemple #1
0
 public void AddProductToProductStoragePass()
 {
     Product p = new Product("Testprodukt", 1, "Testdescription", 1.0f, new BoxSize(1, 1, 1), true);
     ProductStorage ps = new ProductStorage();
     ps.AddNewProduct(p);
     Assert.AreEqual(ps.ProductCount(), 1);
 }
        public void Add(Product product)
        {
            if (ProductsById.ContainsKey (product.Id)) {
                var oldProduct = ProductsById [product.Id];
                ProductsById [oldProduct.Id] = product;
                ProductsByTitle [oldProduct.Title][oldProduct.Id] = product;
                ProductsByPrice [oldProduct.Price][oldProduct.Id] = product;
                ProductsByTitlePrice [oldProduct.Title][oldProduct.Price] [oldProduct.Id] = product;
                ProductsBySupplierPrice [oldProduct.Supplier][oldProduct.Price] [oldProduct.Id] = product;
                return;
            }

            if( !ProductsByPrice.ContainsKey(product.Price)) {
                ProductsByPrice [product.Price] = new OrderedDictionary<int, Product> ();
            }
            if (!ProductsByTitlePrice.ContainsKey (product.Title)) {
                ProductsByTitle [product.Title] = new OrderedDictionary<int, Product> ();
                ProductsByTitlePrice [product.Title] = new OrderedDictionary<float, OrderedDictionary<int, Product>> ();
            }
            if( !ProductsByTitlePrice [product.Title].ContainsKey(product.Price) ){
                ProductsByTitlePrice [product.Title] [product.Price] = new OrderedDictionary<int, Product> ();
            }
            if (!ProductsBySupplierPrice.ContainsKey (product.Supplier)) {
                ProductsBySupplierPrice [product.Supplier] = new OrderedDictionary<float, OrderedDictionary<int, Product>> ();
            }
            if( !ProductsBySupplierPrice [product.Supplier].ContainsKey(product.Price) ){
                ProductsBySupplierPrice [product.Supplier] [product.Price] = new OrderedDictionary<int, Product> ();
            }

            ProductsById [product.Id] = product;
            ProductsByTitle [product.Title] [product.Id] = product;
            ProductsByPrice [product.Price] [product.Id] = product;
            ProductsByTitlePrice [product.Title] [product.Price][product.Id] = product;
            ProductsBySupplierPrice [product.Supplier] [product.Price][product.Id] = product;
        }
Exemple #3
0
 public void RemoveProductFromStoragePass()
 {
     Product p = new Product("Testprodukt", 1, "Testdescription", 1.0, new BoxSize(1, 1, 1), true);
     ProductStorage ps = new ProductStorage();
     ps.AddNewProduct(p);
     ps.RemoveProductID(1);
     Assert.AreEqual(ps.ProductCount(), 0);
 }
Exemple #4
0
        public void SortProductsByNamePass()
        {
            ProductStorage ps = new ProductStorage();
            Product p1 = new Product("Testprodukt", 1, "Testdescription", 1.0f, new BoxSize(1, 1, 1), true);
            Product p2 = new Product("ABC produkt", 1, "Testdescription", 1.0f, new BoxSize(1, 1, 1), true);
            ps.AddNewProduct(p1);
            ps.AddNewProduct(p2);

            List<Product> sortedlist = ps.ProductsSortedByName();
            Assert.AreEqual(sortedlist[0].ProductName, "ABC produkt");
        }
Exemple #5
0
        public Class1()
        {
            products = new Product[30];
              for (int i = 0; i < 30; i++)
                  products[i] = new Product();

              //设置分类,0表示食物,1表示学习用品
              for (int i = 0; i < 30; i++)
                  if (i < 16)
                      products[i].type = 0;
                  else
                      products[i].type = 1;

              //一个一个地赋值,名称和价格
              products[0].name = "康师傅红烧牛肉面"; products[0].price = 3.50F; products[0].labelnum = 6920152414019;
              products[1].name = "可口可乐罐装"; products[1].price = 2.0F; products[1].labelnum = 6920476664183;
              products[2].name = "蒙牛特仑苏牛奶"; products[2].price = 4.70F; products[2].labelnum = 6923644266066;
              products[3].name = "德芙黑巧克力43克"; products[3].price = 6.80F; products[3].labelnum = 6914973600041;
              products[4].name = "农夫山泉矿泉水1.5L"; products[4].price = 2.50F; products[4].labelnum = 6921168520015;
              products[5].name = "金锣肉颗粒多"; products[5].price = 14.0F; products[5].labelnum = 6927462214186;
              products[6].name = "达利园蛋黄派"; products[6].price = 9.0F; products[6].labelnum = 6911988006783;
              products[7].name = "娃哈哈八宝粥"; products[7].price = 3.50F; products[7].labelnum = 6902083880781;
              products[8].name = "娃哈哈AD钙奶 220*4瓶"; products[8].price = 7.0F; products[8].labelnum = 6902083881085;
              products[9].name = "好吃点香脆腰果饼干"; products[9].price = 2.90F; products[9].labelnum = 6911988009777;
              products[10].name = "金丝猴奶糖 118克袋装"; products[10].price = 5.90F; products[10].labelnum = 6921681167564;
              products[11].name = "雀巢脆脆鲨威化饼干"; products[11].price = 23.0F; products[11].labelnum = 6917878131504;
              products[12].name = "康师傅绿茶550ml装"; products[12].price = 2.60F; products[12].labelnum = 6920459905166;
              products[13].name = "黄山毛尖"; products[13].price = 33.89F; products[13].labelnum = 6931386400129;
              products[14].name = "雀巢咖啡罐装"; products[14].price = 4.00F; products[14].labelnum = 6917878027333;
              products[15].name = "清扬男士去屑洗发露"; products[15].price = 22.0F; products[15].labelnum = 6902088113112;
              products[16].name = "天堂雨伞"; products[16].price = 25.0F; products[16].labelnum = 6912003033111;
              products[17].name = "黑人牙膏90克"; products[17].price = 200F; products[17].labelnum = 4891338005692;
              products[18].name = "富光新太空杯800ml"; products[18].price = 39.0F; products[18].labelnum = 6921899998084;
              products[19].name = "小闹钟"; products[19].price = 25.0F; products[19].labelnum = 6941326932009;
              products[20].name = "微波饭盒"; products[20].price = 3.20F; products[20].labelnum = 6930622800020;
              products[21].name = "双飞燕鼠标"; products[21].price = 60.0F; products[21].labelnum = 6949336011332;
              products[22].name = "科学计算器"; products[22].price = 6.40F; products[22].labelnum = 6921734917102;
              products[23].name = "英雄蓝色墨水"; products[23].price = 3.50F; products[23].labelnum = 6940328702320;
              products[24].name = "真彩中性笔芯20根"; products[24].price = 16.0F; products[24].labelnum = 6945091706056;
              products[25].name = "《高等数学导论(下)》,中国科学技术大学出版社"; products[25].price = 37.50F; products[25].labelnum = 9787312029851;
              products[26].name = "笔记本"; products[26].price = 6.60F; products[26].labelnum = 6925550576024;
              products[27].name = "得力订书机"; products[27].price = 13F; products[27].labelnum = 6921734903259;
              products[28].name = "led小台灯"; products[28].price = 33F; products[28].labelnum = 6939020420603;
              products[29].name = "心相印纸面巾"; products[29].price = 5.20F; products[29].labelnum = 6903244984102;
        }
Exemple #6
0
 public void NewProduct()
 {
     //Add a product
     Console.WriteLine("Time to create an object. Please enter the following information.");
     Console.Write("ProductName:");
     string name = Console.ReadLine();
     Console.Write("ProductID:");
     int id = Int32.Parse(Console.ReadLine());
     Console.Write("Price:");
     int price = Int32.Parse(Console.ReadLine());
     //...
     Product product = new Product();
     product.ProductName = name;
     product.ProductID = id;
     product.ProductDescription = "Generic product description.";
     product.Price = price;
     //...
     storage.AddNewProduct(product);
 }
Exemple #7
0
        static void Main(string[] args)
        {
            // 1. create product with details
            Product p1 = new Product(123, "Banana", 3.0, 2.0);

            // 2. buy 100 units
            p1.RenewalStockLevel(100);
            p1.printProduct();

            // 3. sell to user and display accumulated profit
            string input;
            bool success;
            int quantity;

            do
            {
                Console.Write("buy / exit: ");
                input = Console.ReadLine();

                if (input.Equals("buy"))
                {
                    Console.Write("Enter the number of products to buy: ");
                    quantity = int.Parse(Console.ReadLine());

                    success = p1.Sell(quantity);

                    if (success)
                    {
                        Console.WriteLine("Thank you for your purchase\n");
                        p1.printProfit();
                    }
                    else
                        Console.WriteLine("We do not have that many in stock!\n");
                }
            }
            while (input.Equals("buy"));
        }
Exemple #8
0
        static void Main(string[] args)
        {
            ProductStorage storage = new ProductStorage();
            // Add a product
            do
            {
                Console.WriteLine("Time to create an object. Please enter the following information.");
                Console.Write("ProductName:");
                string name = Console.ReadLine();
                Console.Write("ProductID:");
                int id = Int32.Parse(Console.ReadLine());

                Product product = new Product();
                product.ProductName = name;
                product.ProductID = id;
                product.ProductDescription = "Generic product description";

                storage.AddNewProduct(product);
                Console.WriteLine("Product added.");
                Console.WriteLine("Press ESC to quit");
            }
            while (Console.ReadKey().Key != ConsoleKey.Escape);

            Console.WriteLine("Thank you Sir or Madame!");

            Console.Write("Enter ProductID to remove:");
            int ID = Int32.Parse(Console.ReadLine());
            storage.RemoveProductID(ID);

            var prodlist = storage.ProductsSortedByName();
            foreach (var item in prodlist)
            {
                Console.WriteLine(item.ProductName);
            }
            while (Console.ReadKey().Key != ConsoleKey.Escape);
        }
 public void AddNewProduct(Product p)
 {
     productdb.Add(p);
 }
        public void Remove(Product product)
        {
            ProductsById.Remove (product.Id);

            ProductsByTitle [product.Title].Remove(product.Id);
            if (0 == ProductsByTitle [product.Title].Count) {
                ProductsByTitle.Remove(product.Title);
            }

            ProductsByPrice [product.Price].Remove(product.Id);
            if (0 == ProductsByPrice [product.Price].Count) {
                ProductsByPrice.Remove(product.Price);
            }

            ProductsByTitlePrice [product.Title][product.Price].Remove(product.Id);
            if (0 == ProductsByTitlePrice [product.Title][product.Price].Count) {
                ProductsByTitlePrice[product.Title].Remove(product.Price);
            }
            if (0 == ProductsByTitlePrice [product.Title].Count) {
                ProductsByTitlePrice.Remove(product.Title);
            }

            ProductsBySupplierPrice [product.Supplier][product.Price].Remove(product.Id);
            if (0 == ProductsBySupplierPrice [product.Supplier][product.Price].Count) {
                ProductsBySupplierPrice[product.Supplier].Remove(product.Price);
            }
            if (0 == ProductsBySupplierPrice [product.Supplier].Count) {
                ProductsBySupplierPrice.Remove(product.Supplier);
            }
        }