/// <summary>
        /// this is click event for delete fuel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonForDeleteFuel_Clicked(object sender, RoutedEventArgs e)
        {
            Button       deleteFuelPurchase = (Button)sender;
            FuelPurchase f = deleteFuelPurchase.CommandParameter as FuelPurchase;

            deleteFuelPurchases(f);
            Vehicle relatedVehicle = CarList.vehicles.Find(v => v.Id == f.VId);

            FuelPurchasesViewForHistory.ItemsSource = CarList.fuelPurchases.FindAll(fuel => fuel.VId == relatedVehicle.Id);
            FuelPurchasesViewForHistory.Items.Refresh();
        }
        /// <summary>
        /// this is a method to show details for specific vehicle
        /// </summary>
        /// <returns></returns>
        public string printDetails()
        {
            List <Service> vehicleServices = CarList.services != null && CarList.services.Count > 0 ? CarList.services.FindAll(s => s.vehicleID == this.Id) : new List <Service>();
            Service        latestService   = vehicleServices != null && vehicleServices.Count > 0 ? Service.getLatestService(vehicleServices) : null;
            //double kmSinceLastService = latestService != null ? (this.VehicleOdometer - latestService.ServiceOdometer) : 0;
            double  kmSinceLastService = vehicleServices != null ? this.VehicleOdometer - vehicleServices.Last(v => v.vehicleID == Id).ServiceOdometer : 0;
            Journey relatedJourneys    = CarList.journeys.Find(j => j.vehicleID == Id);

            bool   requiresService     = vehicleServices != null && vehicleServices.Count > 0 ? Service.requiresService(vehicleServices) : false;
            string requiresServiceText = requiresService ? "Yes" : "No";

            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"Vehicle: {this.CarManufacture} {this.CarModel} {this.CarYear}");
            sb.AppendLine($"Registration No: {this.RegistrationID}");
            double distanceTravelled = this.getTotalDistanceTravelled();

            if (distanceTravelled > 0)
            {
                sb.AppendLine($"Distance Travelled: {distanceTravelled} km");
            }
            else
            {
                sb.AppendLine($"This vehicle never used before for journeys");
            }

            int serviceCount = this.serviceCount;

            if (serviceCount > 0)
            {
                sb.AppendLine($"Total Services: {this.serviceCount}");
            }
            else
            {
                sb.AppendLine($"Total Services: no record");
            }
            sb.AppendLine($"Car Revenue: {this.TotalRentalCost.ToString("C")}");
            sb.AppendLine($"KM Since last service: {kmSinceLastService} km");
            double fuelEconomy = FuelPurchase.getFuelEconomy(this.Id);

            if (fuelEconomy > 0)
            {
                sb.AppendLine($"Fuel Economy: {fuelEconomy} km/L");
            }
            else
            {
                sb.AppendLine($"Fuel Economy: not available yet");
            }
            sb.AppendLine($"Requires service: {requiresServiceText}");

            return(sb.ToString());
        }
Exemplo n.º 3
0
        /// <summary>
        /// this is a click event for add fuel purchases
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddFuelPurchasesButton_Clicked(object sender, RoutedEventArgs e)
        {
            double FuelQuantity = double.Parse(TextBoxFuelQuantity.Text);
            double FuelPrice    = double.Parse(TextBoxFuelPrice.Text);

            FuelPurchase fuelPurchase = new FuelPurchase(FuelQuantity, FuelPrice);

            fuelPurchase.VId = VehicleId;

            CarList.fuelPurchases.Add(fuelPurchase);
            FuelPurchase.SaveFuelPurchases(CarList.fuelPurchases);
            Close();
        }
 /// <summary>
 /// this is a bool for unit test
 /// to check if the delete button is working or not
 /// </summary>
 /// <param name="f"></param>
 /// <returns></returns>
 public static bool deleteFuelPurchases(FuelPurchase f)
 {
     return(CarList.fuelPurchases.Remove(f));
 }