示例#1
0
        private void btnOrder_Click(object sender, EventArgs e)
        {
            List <StoreProduct> products = new List <StoreProduct>();

            foreach (DataGridViewRow row in dgvProducts.Rows)
            {
                if (Convert.ToInt32(row.Cells["Quantity"].Value) > 0)
                {
                    int id       = Convert.ToInt32(row.Cells["Id"].Value);
                    int quantity = Convert.ToInt32(row.Cells["Quantity"].Value);

                    StoreProduct prod = new StoreProduct(ProductList.GetProductById(id), quantity);
                    products.Add(prod);

                    Logger.Log(String.Format("Store requested {0} of product {1}", quantity, prod.name));
                }
            }

            current_store.products = products;
            qrAdapter.CreateQR(current_store);
            this.Close();
        }
示例#2
0
 public SodaTruck()
 {
     this.DeliveryProduct = ProductList.GetProductById(ProductList.GetSodaId());
     this.Capacity        = 120;
 }
示例#3
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;
        }