コード例 #1
0
        public List <Product> FindProduct(Product product, Location location)
        {
            WareHouse      ClosestWarehouse = FindClosestWareHouse(WareHouse);
            List <Product> ReturnList       = new List <Product>()
            {
                new Product()
                {
                    ID = -1, Name = "Apple", Quantity = 25, Location = new Location()
                    {
                        Area = 1, Country = "Russia", Municipality = "esbjerg"
                    }
                }
                , new Product()
                {
                    ID = -2, Name = "Apple", Quantity = 6, Location = new Location()
                    {
                        Area = 2, Country = "Denmark", Municipality = "esbjerg"
                    }
                }
                , new Product()
                {
                    ID = -3, Name = "Apple", Quantity = 25, Location = new Location()
                    {
                        Area = 3, Country = "Russia", Municipality = "esbjerg"
                    }
                },
            };

            return(new List <Product>());
        }
コード例 #2
0
        private void AddProductToWareHouse(Product product, WareHouse warehouse)
        {
            warehouse.ProductList.Add(product);
            Location location = new Location();

            location.Country      = warehouse.country;
            location.Municipality = warehouse.municipality;
            product.Location      = location;
        }
コード例 #3
0
        private List <WareHouse> FindClosestWareHouses(List <WareHouse> noneCheckedWareHouses, Location location)
        {
            //Contry First Then municipality
            List <WareHouse> CountryChecked = noneCheckedWareHouses.FindAll(x => x.country == location.Country);

            if (CountryChecked.Count == 0)
            {
                // if there are no warehouses in the Country is there no reason to send back a emty list and no reason to check Municipality
                List <WareHouse> LW = new List <WareHouse>();
                LW.AddRange(noneCheckedWareHouses);
                return(LW);
            }
            List <WareHouse> MunicipalityChecked = CountryChecked.FindAll(x => x.municipality == location.Municipality);

            if (MunicipalityChecked.Count == 0)
            {
                MunicipalityChecked.AddRange(CountryChecked);
            }
            return(MunicipalityChecked);
        }
コード例 #4
0
        public List <Product> ProductList  = new List <Product>();   // List Af Product som Kunen vil købe
        public void Start()
        {
            Console.WriteLine("Stating");
            TestRun();
            Console.WriteLine(WareHouses.Count);
            while (true)
            {
                Console.WriteLine("" +
                                  "1 = AddWareHouse\n" +
                                  "2 = Clear Console\n" +
                                  "3 = FindClosestWareHouse\n" +
                                  "4 = AddProduct\n" +
                                  "5 = Get List Of Products\n" +
                                  "6 = AddProduct to warehouse\n" +
                                  "");
                string Text = Console.ReadLine();
                switch (Text)
                {
                case "1":         //AddWareHouse
                    Console.WriteLine("You Hae Chossen Add WareHouse");
                    Console.WriteLine("What County");
                    string County = Console.ReadLine();
                    Console.WriteLine("What Municipality");
                    string Municipality = Console.ReadLine();
                    int    ID           = WareHouses.Count + 1;
                    AddWareHouse(ID, County, Municipality);
                    break;

                case "2":
                    Console.Clear();
                    break;

                case "3":
                    Console.WriteLine("use Call Nun To Select With product you want");
                    TestFunktionShowProducktList();
                    int  productNun      = -1;
                    bool productNunCheck = false;
                    while (productNunCheck == false)
                    {
                        if (Int32.TryParse(Console.ReadLine(), out productNun))
                        {
                            productNunCheck = true;
                        }
                        else
                        {
                            Console.WriteLine("String could not be parsed. Plz use numbers");
                        }
                    }
                    Console.WriteLine("How Many");
                    int  amount      = -1;
                    bool amountCheck = false;
                    while (amountCheck == false)
                    {
                        if (Int32.TryParse(Console.ReadLine(), out amount))
                        {
                            amountCheck = true;
                        }
                        else
                        {
                            Console.WriteLine("String could not be parsed. Plz use numbers");
                        }
                    }
                    Product productLookingFor = new Product();
                    productLookingFor.ID       = ProductList[productNun].ID;
                    productLookingFor.Name     = ProductList[productNun].Name;
                    productLookingFor.Quantity = amount;
                    Console.WriteLine("\nWere From");
                    Location location = new Location()
                    {
                    };
                    Console.WriteLine("what Country");
                    location.Country = Console.ReadLine();
                    Console.WriteLine("what Municipality");
                    location.Municipality      = Console.ReadLine();
                    productLookingFor.Location = location;
                    List <Product> PL = FindProduct(productLookingFor);
                    foreach (var p in PL)
                    {
                        Console.WriteLine(p.Location.Country + " Name = " + p.Name + " Price = " + p.Price + " Quantity = " + p.Quantity);
                    }
                    break;

                    #region .           4 = AddProduct
                case "4":
                    Console.WriteLine("What Is its Name");
                    string Name = Console.ReadLine();
                    Console.WriteLine("How Many");
                    int  Quantity   = -1;
                    bool ValueCheck = false;
                    while (ValueCheck == false)
                    {
                        if (Int32.TryParse(Console.ReadLine(), out Quantity))
                        {
                            ValueCheck = true;
                        }
                        else
                        {
                            Console.WriteLine("String could not be parsed. Plz use numbers");
                        }
                    }

                    Console.WriteLine("At What Price");
                    ValueCheck = false;
                    int Price = -1;
                    while (ValueCheck == false)
                    {
                        if (Int32.TryParse(Console.ReadLine(), out Price))
                        {
                            ValueCheck = true;
                        }
                        else
                        {
                            Console.WriteLine("String could not be parsed. Plz use numbers");
                        }
                    }

                    Console.WriteLine("Adding new Produck To List");
                    AddProduct(ProductList.Count + 1, "Tomato", Price, Quantity);
                    break;

                    #endregion
                    #region .           5 = Get List Of Products
                case "5":
                    TestFunktionShowProducktList();
                    break;

                    #endregion
                    #region .           6 = AddProduct to warehouse
                case "6":
                    Console.WriteLine("use Call Nun To Select With product you want to use");
                    TestFunktionShowProducktList();
                    int  productID      = -1;
                    bool productIDCheck = false;
                    while (productIDCheck == false)
                    {
                        if (Int32.TryParse(Console.ReadLine(), out productID))
                        {
                            productIDCheck = true;
                        }
                        else
                        {
                            Console.WriteLine("String could not be parsed. Plz use numbers");
                        }
                    }

                    Console.WriteLine("use Call Nun To Select With WareHouse you want to use");
                    TestFunktionShowWareHouseList();
                    int  warHouseID      = -1;
                    bool warHouseIDCheck = false;
                    while (warHouseIDCheck == false)
                    {
                        if (Int32.TryParse(Console.ReadLine(), out warHouseID))
                        {
                            warHouseIDCheck = true;
                        }
                        else
                        {
                            Console.WriteLine("String could not be parsed. Plz use numbers");
                        }
                    }
                    if (ProductList[productID] != null && WareHouses[warHouseID] != null)
                    {
                        AddProductToWareHouse(ProductList[productID], WareHouses[warHouseID]);
                    }
                    break;

                    #endregion
                default:
                    break;
                }
                Console.WriteLine(Text);
            }
        }