Ejemplo n.º 1
0
        private Shop Seed()
        {
            Shop shop = new Shop();

            shop.AddProduct(new Product {
                Name = "1", Cost = 1.1m
            });
            shop.AddProduct(new Product {
                Name = "2", Cost = 1.4m
            });
            shop.AddProduct(new Product {
                Name = "3", Cost = 1.9m
            });

            Customer a = new Customer {
                Email = "@1"
            };
            Customer b = new Customer {
                Email = "@2"
            };

            shop.MakeOrder(a, new OrderProduct {
                Product = shop.Products[1], Amount = 1
            }
                           , new OrderProduct {
                Product = shop.Products[0], Amount = 4
            });
            shop.MakeOrder(b, new OrderProduct {
                Product = shop.Products[2], Amount = 3
            }
                           , new OrderProduct {
                Product = shop.Products[1], Amount = 2
            }).Status = OrderStatus.Purchased;
            return(shop);
        }
Ejemplo n.º 2
0
Archivo: Test2.cs Proyecto: GoAll5/OOP
        public void TestCanBuyProductForMoney(int money)
        {
            Product product5 = new Product(5, "скумбрия", 1, 35);
            Product product6 = new Product(6, "вода", 2, 30);
            Product product7 = new Product(7, "тыква", 3, 100);
            Product product8 = new Product(8, "дыня", 1, 60);

            List <ProductCount> products = new List <ProductCount>();

            //new ProductCount("скумбрия", 1), new ProductCount("вода", 2),
            //new ProductCount("тыкква", 1), new ProductCount("дыня", 1)
            products.Add(new ProductCount("скумбрия", 1));
            products.Add(new ProductCount("вода", 2));
            products.Add(new ProductCount("тыква", 1));
            products.Add(new ProductCount("дыня", 1));

            Shop shop2 = new Shop(1, "Магазин1", "Кронва");

            shop2.AddProduct(product5);
            shop2.AddProduct(product6);
            shop2.AddProduct(product7);
            shop2.AddProduct(product8);



            List <ProductCount> expected = products;
            List <ProductCount> actual   = shop2.CanBuyProductsForMoney(money);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 3
0
Archivo: Test2.cs Proyecto: GoAll5/OOP
        public void TestBuyBatchProducts1()
        {
            Product product5 = new Product(5, "скумбрия", 1, 35);
            Product product6 = new Product(6, "вода", 2, 30);
            Product product7 = new Product(7, "тыква", 3, 100);
            Product product8 = new Product(8, "дыня", 1, 60);

            List <ProductCount> products = new List <ProductCount>();

            products.Add(new ProductCount("скумбрия", 1));
            products.Add(new ProductCount("вода", 3));
            products.Add(new ProductCount("тыква", 1));
            products.Add(new ProductCount("дыня", 1));

            Shop shop3 = new Shop(1, "Магазин1", "Кронва");

            shop3.AddProduct(product5);
            shop3.AddProduct(product6);
            shop3.AddProduct(product7);
            shop3.AddProduct(product8);

            int expected = 0;
            int actual   = shop3.BuyBatchProducts(products);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 4
0
Archivo: Test2.cs Proyecto: GoAll5/OOP
        public void SetUp()
        {
            Product product1 = new Product(1, "яблоко", 10, 35);
            Product product2 = new Product(2, "груша", 20, 30);
            Product product3 = new Product(3, "лук зеленый", 10, 100);
            Product product4 = new Product(4, "лук репчатый", 33, 60);

            Shop shop1 = new Shop(1, "Магазин1", "Кронва");

            shop1.AddProduct(product1);
            shop1.AddProduct(product2);
            shop1.AddProduct(product3);
            shop1.AddProduct(product4);
        }
Ejemplo n.º 5
0
Archivo: Test2.cs Proyecto: GoAll5/OOP
        public int TestChange(int price, int id)
        {
            Product product1 = new Product(1, "яблоко", 10, 35);
            Product product2 = new Product(2, "груша", 20, 30);
            Product product3 = new Product(3, "лук зеленый", 10, 100);
            Product product4 = new Product(4, "лук репчатый", 33, 60);

            Shop shop1 = new Shop(1, "Магазин1", "Кронва");

            shop1.AddProduct(product1);
            shop1.AddProduct(product2);
            shop1.AddProduct(product3);
            shop1.AddProduct(product4);
            shop1.ChangePrice(id, price);

            return(shop1.ShowPrice(id));
        }
        public void SaveProduct(Product product, Shop shop)
        {
            string parms = new BLimp().TranslateHEtoEN(product.GetParms());

            product.NutritionalValues = new BLimp().GetProductIdNutrition(parms);

            shop.AddProduct(product);
            new BLimp().add_Product(product);
        }
Ejemplo n.º 7
0
Archivo: Test2.cs Proyecto: GoAll5/OOP
        public void TestChange1(int price, int id)
        {
            Product product1 = new Product(1, "яблоко", 10, 35);
            Product product2 = new Product(2, "груша", 20, 30);
            Product product3 = new Product(3, "лук зеленый", 10, 100);
            Product product4 = new Product(4, "лук репчатый", 33, 60);

            Shop shop1 = new Shop(1, "Магазин1", "Кронва");

            shop1.AddProduct(product1);
            shop1.AddProduct(product2);
            shop1.AddProduct(product3);
            shop1.AddProduct(product4);
            shop1.ChangePrice(id, price);
            int?expected = null;
            int actual   = shop1.ShowPrice(id);

            Assert.AreEqual(expected.GetValueOrDefault(), actual);
        }
Ejemplo n.º 8
0
Archivo: Test2.cs Proyecto: GoAll5/OOP
        public void TestFindMinShopBatchOfProduct1()
        {
            Product product5 = new Product(5, "скумбрия", 1, 35);
            Product product6 = new Product(6, "вода", 2, 30);
            Product product7 = new Product(7, "тыква", 3, 100);
            Product product8 = new Product(8, "дыня", 1, 60);

            List <ProductCount> products = new List <ProductCount>();

            products.Add(new ProductCount("скумбрия", 1));
            products.Add(new ProductCount("вода", 1));
            products.Add(new ProductCount("тыква", 1));
            products.Add(new ProductCount("дыня", 1));

            Product product1 = new Product(1, "яблоко", 10, 35);
            Product product2 = new Product(2, "груша", 20, 30);
            Product product3 = new Product(3, "лук зеленый", 10, 100);
            Product product4 = new Product(4, "лук репчатый", 33, 60);

            Shop shop1 = new Shop(1, "Магазин1", "Кронва");

            shop1.AddProduct(product1);
            shop1.AddProduct(product2);
            shop1.AddProduct(product3);
            shop1.AddProduct(product4);

            Shop shop3 = new Shop(2, "Магазин2", "Парфеновская");

            shop3.AddProduct(product5);
            shop3.AddProduct(product6);
            shop3.AddProduct(product7);
            shop3.AddProduct(product8);

            List <Shop> shops = new List <Shop>();

            shops.Add(shop1);
            shops.Add(shop3);

            int expected = shop3.ShowId();
            int actual   = (ChainOfStores.FindMinShopBatchOfProduct(shops, products)).ShowId();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 9
0
 private void Timer_Tick(object sender, EventArgs e)
 {
     if (!ASI.ItemName.Equals("") && !ASI.PicLocation.Equals(""))
     {
         sp.AddProduct(ASI.ItemName, ASI.ItemPriceG, ASI.ItemPriceD, ASI.ItemStock, ASI.HP_Recover, ASI.Mb_Recover, ASI.ItemDescribtion, ASI.PicLocation);
         ASI.clearTB();
         ASI.ClearData();
         ReloadShop();
     }
 }
        static void Main(string[] args)
        {
            var shop = new Shop();

            var fridge = new Fridge("KoelerMan", "X850", 180, "White");

            var microWave = new MicroWave("Philips", "Z50", 100, 950);

            var gsm = new Gsm("Nokia", "Stone of death", 350, true);

            shop.AddProduct(fridge);
            shop.AddProduct(microWave);
            shop.AddProduct(gsm);

            shop.AddProducts(fridge, microWave);

            shop.ShowAllProductDetails();

            Console.ReadLine();
        }
Ejemplo n.º 11
0
            public void Addproduct()
            {
                Display("Name: ");
                string name = Console.ReadLine();

                Display("Description: ");
                string desc = Console.ReadLine();

                Display("Price: ");
                double price = double.Parse(Console.ReadLine());

                Display("Count: ");
                int count = int.Parse(Console.ReadLine());

                Display("id: " + shop.AddProduct(name, desc, price, count));
            }
Ejemplo n.º 12
0
Archivo: Test2.cs Proyecto: GoAll5/OOP
        public void TestCanBuyProductForMoney1000(int money)
        {
            Product product5 = new Product(5, "скумбрия", 1, 35);


            List <ProductCount> products = new List <ProductCount>();

            products.Add(new ProductCount("скумбрия", 1));


            Shop shop2 = new Shop(1, "Магазин1", "Кронва");

            shop2.AddProduct(product5);


            List <ProductCount> expected = products;
            List <ProductCount> actual   = shop2.CanBuyProductsForMoney(money);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 13
0
        private void ShopController(Shop shop)
        {
            Console.WriteLine("1. Добавить продавца");
            Console.WriteLine("2. Удалить продавца");
            Console.WriteLine("3. Добавить товар");
            Console.WriteLine("4. Продать товар");
            Console.WriteLine("5. Посчитать общую сумму всех покупок");
            int answer = int.Parse(Console.ReadLine());

            switch (answer)
            {
            case 1:
            {
                var builder   = new ShopAssistantBuilder();
                var assistant = builder.Build();
                shop.Assistants.Add(assistant);
                break;
            }

            case 2:
            {
                if (shop.Assistants.Count == 0)
                {
                    Console.WriteLine("Работников в этом магазине нет!");
                }
                else
                {
                    var assist = GetShopAssistant(shop);
                    shop.Assistants.Remove(assist);
                }
                break;
            }

            case 3:
            {
                var builder = new ProductBuilder();
                var product = builder.Build();
                shop.AddProduct(product);
                break;
            }

            case 4:
            {
                var assist = GetShopAssistant(shop);
                if (assist == null)
                {
                    return;
                }
                var product = GetProduct(shop);
                if (product == null)
                {
                    return;
                }
                shop.SellProduct(assist, product);
                break;
            }

            case 5:
            {
                Console.WriteLine($"Общая стоимость покупок: {shop.CalculateOverall()}");
                break;
            }
            }
        }
Ejemplo n.º 14
0
        bool ChooseShop(Shop shop)
        {
            string choice = AnyInput("Please choose an option...");

            switch (choice)
            {
            case "1":     // is the shop open?
                Console.Clear();
                if (shop.IsOpen())
                {
                    Console.WriteLine("The shop is opened.");
                }
                else
                {
                    Console.WriteLine("The shop is closed.");
                }
                AnyInput("Press any key to continue...");
                return(true);

            case "2":     // open shop
                Console.Clear();
                shop.Open();
                Console.WriteLine("The shop has just opened.");
                Thread.Sleep(1000);
                return(true);

            case "3":     // close shop
                Console.Clear();
                shop.Close();
                Console.WriteLine("The shop has just closed.");
                Thread.Sleep(1000);
                return(true);

            case "4":     // list the products
                Console.Clear();
                Dictionary <long, int>     quanityOfProduct   = new Dictionary <long, int>();
                Dictionary <long, Product> ProductsDictionary = new Dictionary <long, Product>();
                try
                {
                    foreach (Product product in shop.GetProducts())
                    {
                        long barcode = product.GetBarcode();
                        if (quanityOfProduct.ContainsKey(barcode))
                        {
                            quanityOfProduct[barcode] += +1;
                        }
                        else
                        {
                            quanityOfProduct.Add(barcode, 1);
                            ProductsDictionary.Add(barcode, product);
                        }
                    }
                    foreach (KeyValuePair <long, int> item in quanityOfProduct)
                    {
                        Product product = ProductsDictionary[item.Key];
                        Console.Write(product.ToString());
                        Console.WriteLine(", Quantity: " + item.Value);
                    }
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed.");
                    Thread.Sleep(1000);
                }
                AnyInput("Press any key to continue...");
                return(true);

            case "5":     // find a product by name
                Console.Clear();
                try
                {
                    string  productName = AnyInput("The name of the product: ");
                    Product product     = shop.FindByName(productName);
                    Console.WriteLine(product.ToString());
                    AnyInput("Press any key to continue...");
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed.");
                    Thread.Sleep(1000);
                }
                catch (NoSuchProductException)
                {
                    Console.WriteLine("There is no such product with this name.");
                    Thread.Sleep(1000);
                }
                return(true);

            case "6":     // get the owner of the shop
                Console.Clear();
                Console.WriteLine(shop.GetOwner());
                AnyInput("Press any key to continue...");
                return(true);

            case "7":     // add new product
                try
                {
                    Console.Clear();
                    Console.WriteLine("(1) Add a new foodproduct");
                    Console.WriteLine("(2) Add a new clothing product");
                    while (true)
                    {
                        if (!shop.IsOpen())
                        {
                            throw new ShopIsClosedException();
                        }
                        int    input        = IntInput("Choose an option...");
                        long   barcode      = LongInput("The barcode of the product: ");
                        string name         = AnyInput("The name of the product: ");
                        string manufacturer = AnyInput("The manufacturer of the product: ");
                        if (input == 1)
                        {
                            int         calories    = IntInput("The calorie of the product: ");
                            DateTime    bestBefore  = DateTimeInput("The expiration date of the product: ");
                            FoodProduct foodProduct = new FoodProduct(barcode, name, manufacturer, calories, bestBefore);
                            int         quantity    = IntInput("The quantity of the product: ");
                            int         price       = IntInput("The price of the product: ");
                            shop.AddNewProduct(foodProduct, quantity, price);
                            Console.WriteLine("The new product has added to the shop.");
                            Thread.Sleep(1000);
                            break;
                        }
                        else if (input == 2)
                        {
                            string          material        = AnyInput("The material of the product: ");
                            string          type            = AnyInput("The type of the product: ");
                            ClothingProduct clothingProduct = new ClothingProduct(barcode, name, manufacturer, material, type);
                            int             quantity        = IntInput("The quantity of the product: ");
                            int             price           = IntInput("The price of the product: ");
                            shop.AddNewProduct(clothingProduct, quantity, price);
                            Console.WriteLine("The new product has added to the shop.");
                            Thread.Sleep(1000);
                            break;
                        }
                    }
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed");
                    Thread.Sleep(1000);
                }
                catch (ProductAlreadyExistsException)
                {
                    Console.WriteLine("The product is already exist");
                    Thread.Sleep(1000);
                }
                return(true);

            case "8":     // add existing product
                Console.Clear();
                try
                {
                    if (!shop.IsOpen())
                    {
                        throw new ShopIsClosedException();
                    }
                    long barcode  = LongInput("The barcode of the product: ");
                    int  quantity = IntInput("The quantity: ");
                    shop.AddProduct(barcode, quantity);
                    Console.WriteLine("The product is added to the shop");
                    Thread.Sleep(1000);
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed");
                    Thread.Sleep(1000);
                }
                catch (NoSuchProductException)
                {
                    Console.WriteLine("There is no product with this name");
                    Thread.Sleep(1000);
                }
                return(true);

            case "9":     //Buy a product
                Console.Clear();
                try
                {
                    if (!shop.IsOpen())
                    {
                        throw new ShopIsClosedException();
                    }
                    long    barcode       = LongInput("The barcode of the product: ");
                    Product boughtProduct = shop.BuyProduct(barcode);
                    cart.Add(boughtProduct);
                    prices.Add(shop.GetPrice(boughtProduct.GetBarcode()));
                    Console.WriteLine("The product is bought from the shop");
                    Thread.Sleep(1000);
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed");
                    Thread.Sleep(1000);
                }
                catch (NoSuchProductException)
                {
                    Console.WriteLine("There is no product with this name");
                    Thread.Sleep(1000);
                }
                catch (OutOfStockException)
                {
                    Console.WriteLine("The shop has run out of this product");
                    Thread.Sleep(1000);
                }
                return(true);

            case "10":     // Buy products
                Console.Clear();
                try
                {
                    if (!shop.IsOpen())
                    {
                        throw new ShopIsClosedException();
                    }
                    long           barcode        = LongInput("The barcode of the product: ");
                    int            quantity       = IntInput("The quantity: ");
                    List <Product> boughtProducts = shop.BuyProducts(barcode, quantity);
                    foreach (Product product in boughtProducts)
                    {
                        cart.Add(product);
                        prices.Add(shop.GetPrice(product.GetBarcode()));
                    }
                    Console.WriteLine("The products are bought from the shop");
                    Thread.Sleep(1000);
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed");
                    Thread.Sleep(1000);
                }
                catch (NoSuchProductException)
                {
                    Console.WriteLine("There is no product with this name");
                    Thread.Sleep(1000);
                }
                catch (OutOfStockException)
                {
                    Console.WriteLine("The shop has not enough from this product");
                    Thread.Sleep(1000);
                }
                return(true);

            case "11":     // Get the price
                Console.Clear();
                try
                {
                    long barcode = LongInput("The barcode of the product: ");
                    Console.WriteLine("The price is: " + shop.GetPrice(barcode).ToString());
                    AnyInput("Press any key to continue...");
                }
                catch (ShopIsClosedException)
                {
                    Console.WriteLine("The shop is closed");
                    Thread.Sleep(1000);
                }
                catch (NoSuchProductException)
                {
                    Console.WriteLine("There is no product with this name");
                    Thread.Sleep(1000);
                }
                catch (OutOfStockException)
                {
                    Console.WriteLine("The shop has not enough from this product");
                    Thread.Sleep(1000);
                }
                return(true);

            case "0":
                return(false);

            default:
                return(true);
            }
        }
Ejemplo n.º 15
0
 private void btnAddProduct_Click(object sender, EventArgs e)
 {
     if (String.IsNullOrEmpty(cboBrand.Text))
     {
         MessageBox.Show(Filepath.BrandField);
         cboBrand.Focus();
     }
     else if (String.IsNullOrEmpty(txtModel.Text))
     {
         MessageBox.Show(Filepath.ModelField);
         txtModel.Focus();
     }
     else if (String.IsNullOrEmpty(txtCode.Text))
     {
         MessageBox.Show(Filepath.CodeField);
         txtCode.Focus();
     }
     else if (String.IsNullOrEmpty(txtPrice.Text))
     {
         MessageBox.Show(Filepath.PriceField);
         txtPrice.Focus();
     }
     else if (String.IsNullOrEmpty(txtWarranty.Text))
     {
         MessageBox.Show(Filepath.WarrantyField);
         txtWarranty.Focus();
     }
     else if (String.IsNullOrEmpty(txtPower.Text))
     {
         MessageBox.Show(Filepath.PowerField);
         txtPower.Focus();
     }
     else if (String.IsNullOrEmpty(cboVoltage.Text))
     {
         MessageBox.Show(Filepath.VoltageField);
         cboVoltage.Focus();
     }
     else if (String.IsNullOrEmpty(txtQuantity.Text))
     {
         MessageBox.Show(Filepath.QuantityField);
         txtQuantity.Focus();
     }
     else
     {
         if (!File.Exists(Filepath.productPath))
         {
             var prod = new Product()
             {
                 Brand       = cboBrand.Text,
                 Code        = Convert.ToInt32(txtCode.Text),
                 ModelNo     = txtModel.Text,
                 Price       = Convert.ToInt32(txtPrice.Text),
                 Warranty    = Convert.ToInt32(txtWarranty.Text),
                 Voltage     = cboVoltage.Text,
                 OutputPower = Convert.ToInt64(txtPower.Text),
                 Quantity    = Convert.ToInt32(txtQuantity.Text)
             };
             var result = myShop.AddProduct(prod);
             if (result == true)
             {
                 myShop.ProductSerialize(ref myShop);
                 MessageBox.Show(Filepath.ProductAdded);
                 Reset();
             }
             else
             {
                 MessageBox.Show("Modelno already exists");
                 Reset();
             }
         }
     }
 }