private void btnPerDay_Click(object sender, EventArgs e) { double num; double days; bool Num = double.TryParse(txtJourney.Text, out num); bool Days = double.TryParse(txtDays.Text, out days); if (Num && num >= 0 && Days && days >= 0) { bool serv = Vehicles[cbVehicles.SelectedIndex].ServREQ(num); if (!serv) { Journey journey = new Journey(num); PerDayRental perdayrental = new PerDayRental(days, num); //Order is important here KMserv has to be updated before TotalKM otherwise they would get different results Vehicles[cbVehicles.SelectedIndex].KMServ = Vehicles[cbVehicles.SelectedIndex].AddJourney(journey); Vehicles[cbVehicles.SelectedIndex].TotalKMT = Vehicles[cbVehicles.SelectedIndex].AddJourney(journey); Vehicles[cbVehicles.SelectedIndex].Revenue = Vehicles[cbVehicles.SelectedIndex].AddRevenue(perdayrental); Vehicles[cbVehicles.SelectedIndex].CalcFuelEcon(); rtbReport.Text = Vehicles[cbVehicles.SelectedIndex].PrintToScreen() + "\n\nJourney has been added."; } else { MessageBox.Show("This Vehicle requires a service"); } } else { MessageBox.Show("Please enter a valid number in both fields."); } }
public void TestAddRevenueDayInvalid() { //Arrange days = -1; kmt = -50; PerDayRental perdayrental = new PerDayRental(days, kmt); double expected = 100; var test = new Vehicle(TKMT, TLP, kmserv, fuelecon); //Act double actual = test.AddRevenue(perdayrental); //Assert Assert.AreEqual(expected, actual); }
private void Rent() { int Kilometers; int Litres; int Days; string RentType; bool daysNeeded = int.TryParse(txtDaysRented.Text, out Days); if (isDailyRent) { RentType = "Daily Rate"; } else { RentType = "Distance Rate"; } Vehicle current = Vehicles.ElementAt(cbxChooseCar.SelectedIndex); if (current.NeedService) { MessageBox.Show("This vehicle needs a service and so cannot be rented"); } else if (!int.TryParse(txtKmRent.Text, out Kilometers)) { MessageBox.Show("Kilometers travelled must be a whole number"); } else if (!int.TryParse(txtLitresRent.Text, out Litres)) { MessageBox.Show("Litres used must be a whole number"); } else if (isDailyRent && !daysNeeded) { MessageBox.Show("Days rented must not be blank"); } else { if (isDailyRent) { var Rent = new PerDayRental(Kilometers, Days, Litres); var j = new Journey(Rent.KilometersTravelled); var fp = new FuelPurchase(Rent.LitresUsed); current.AddFuelPurchase(fp); current.AddJourney(j); current.TotalRevenue += Rent.TotalCost; } else { var Rent = new PerKmRental(Kilometers, Litres); var j = new Journey(Rent.KilometersTravelled); var fp = new FuelPurchase(Rent.LitresUsed); current.AddFuelPurchase(fp); current.AddJourney(j); current.TotalRevenue += Rent.TotalCost; } txtDaysRented.Clear(); txtKmRent.Clear(); txtLitresRent.Clear(); MessageBox.Show($"New {RentType} Rental Successfully Saved"); } }