Beispiel #1
0
        private void fStores_Load(object sender, EventArgs e)
        {
            DirectoryInfo directory = new DirectoryInfo(Utils.GetStoresPath());
            QRAdapter     qrAdapter = new QRAdapter();

            var files = directory.GetFiles("*.png");

            Logger.Add(new FileLog());
            Logger.Log("DeliveryApp Started!");
            StoreList.Init();
            foreach (var image in files)
            {
                StoreList.Add(qrAdapter.ReadQR(image.Name));
            }

            dgvStores.DataSource            = StoreList.GetStores().Select(o => new { Id = o.idStore, Name = o.storeName }).ToList();
            dgvStores.Columns["Name"].Width = 220;
        }
Beispiel #2
0
        private void btnSimulate_Click(object sender, EventArgs e)
        {
            Logger.Log("Simulation started.");
            TF.CleanFleet();

            Dictionary <int, int> order_quantity = new Dictionary <int, int>();
            List <Truck>          trucks         = TF.Trucks;
            string simulation_ans = "";

            int  i           = 1;
            bool is_possible = true;

            foreach (var nud in nuds)
            {
                TF.GetTrucks(i, Convert.ToInt32(nud.Value));
                i++;
            }

            foreach (var store in StoreList.GetStores())
            {
                foreach (var product in store.products)
                {
                    if (order_quantity.ContainsKey(product.idProduct))
                    {
                        order_quantity[product.idProduct] += product.quantity;
                    }
                    else
                    {
                        order_quantity.Add(product.idProduct, product.quantity);
                    }
                }
            }

            foreach (var truck in trucks)
            {
                if (order_quantity.ContainsKey(truck.DeliveryProduct.Id))
                {
                    order_quantity[truck.DeliveryProduct.Id] -= truck.Capacity;
                }
            }

            foreach (var product in order_quantity)
            {
                if (product.Value > 0)
                {
                    is_possible     = false;
                    simulation_ans += "missing ";
                }
                else
                {
                    simulation_ans += "remain ";
                }

                simulation_ans += Math.Abs(product.Value).ToString() + " " + ProductList.GetProductById(product.Key).Name + "\n";
            }

            if (is_possible)
            {
                simulation_ans             = "Is possible to deliver the products with this trucks.\n" + simulation_ans;
                btnStartDelivery.Enabled   = true;
                lblSimulationAns.ForeColor = Color.Green;
                Logger.Log("Simulation finished, delivery is possible.");
            }
            else
            {
                simulation_ans             = "Is not possible to deliver the products with this trucks.\n" + simulation_ans;
                btnStartDelivery.Enabled   = false;
                lblSimulationAns.ForeColor = Color.Red;
                Logger.Log("Simulation finished, delivery is NOT possible. Please add more trucks.");
            }

            lblSimulationAns.Text    = simulation_ans;
            lblSimulationAns.Visible = true;
        }