コード例 #1
0
        private void btn_confirm_Click(object sender, EventArgs e)
        {
            double liters = 0;
            double cost   = 0;

            if (check_full.Checked)
            {
                liters = 100 - current.Fuel;
                cost   = Math.Round(liters * currentprice);
                if (current.NetIncome < cost)
                {
                    MessageBox.Show("To make it full, you need $ " + cost + ". You only have $ " + current.NetIncome + ".");
                }
                else
                {
                    double change = current.Add_Fuel(currentprice, cost, current);
                    MessageBox.Show("The tank is full. You have spent $ " + cost.ToString() + ".");
                    this.Close();
                }
            }
            else
            {
                string c = cbo_payment.SelectedItem.ToString();
                c    = c.Replace("$ ", "");
                cost = Convert.ToDouble(c);
                if (current.NetIncome < cost)
                {
                    double cc = cost - current.NetIncome;
                    MessageBox.Show("You only have $ " + current.NetIncome + ". To purchase $ " + cost + ", you need $ " + cc + " more.");
                }
                else
                {
                    double change = current.Add_Fuel(currentprice, cost, current);
                    if (change != 0)
                    {
                        MessageBox.Show("The tank is full and the change is $ " + change.ToString());
                        this.Close();
                    }
                    else
                    {
                        liters = cost / currentprice;
                        liters = Math.Round(liters, 2);
                        MessageBox.Show("You have added " + liters + " liter of fuel.\nCurrent fuel level is " + current.Fuel.ToString() + "%.");
                        this.Close();
                    }
                }
            }
        }
コード例 #2
0
        private void Nt_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (nt.Trip_Created)
            {
                currentTrip = nt.Current_Trip;

                // check if the fuel is empty  >> if then take $100 from current net income, and add fuel ($ 20)
                if (currentTM.Fuel - currentTrip.Fuel <= 0)
                {
                    currentTM.NetIncome -= 100.00;
                    // create random price for the fuel
                    Random rnd          = new Random();
                    int    random       = rnd.Next(15, 45);
                    string price        = "1." + random.ToString();
                    double random_price = Convert.ToDouble(price);
                    MessageBox.Show("You have called a recharging service. You have spent $100(Service fee) and $50(Fuel charge).\nPrice for Fuel was :  $ " + price + " / liter");
                    currentTM.TaxiMeter_Renew(currentTM, currentTrip);
                    currentTM.Add_Fuel(random_price, 50.00, currentTM);
                    TaxiMeter_Reload(currentTM);
                }
                else
                {
                    // add current trip to the current taxi meter
                    currentTM.TaxiMeter_Renew(currentTM, currentTrip);
                    TaxiMeter_Reload(currentTM);
                }
            }
            nt = null;
        }