/// <summary> /// Add fuel purchase into the collection /// </summary> /// <param name="vehicle">Vehicle to be referenced on this Fuel Purchase</param> /// <param name="cost">Cost of the fuel purchased. Up to 2 decimal points</param> /// <param name="litres">Fuel purchased in litres. Up to 2 decimal points</param> /// <param name="date">Date of purchase of fuel</param> public void Add(Vehicle vehicle, decimal cost, double litres, DateTime date) { int id = FindId(); FuelPurchase fuelPurchase = new FuelPurchase(id, vehicle) { Litres = litres, Cost = cost, Date = date }; List.Add(fuelPurchase); // Prepare SQL query string statement = $"INSERT INTO `fuel_purchases` ( `id`, `vehicle_id`, `litres`, `cost`, `date`)" + $"VALUES (" + $"{fuelPurchase.Id}," + $"{fuelPurchase.VehicleId}," + $"{fuelPurchase.Litres.ToString()}," + $"{fuelPurchase.Cost.ToString()}," + $"'{fuelPurchase.Date.ToString("yyyy-MM-dd")}'" + $")"; // Execute statement if able ExecuteNonQuery(statement); }
/// <summary> /// Delete a fuel purchase /// </summary> /// <param name="fuelPurchase">Fuel purchase to be deleted</param> public void Delete(FuelPurchase fuelPurchase) { List.Remove(fuelPurchase); string statement = $"DELETE FROM `services`" + $"WHERE `id` = {fuelPurchase.Id.ToString()};"; // Execute statement if able ExecuteNonQuery(statement); }
public Vehicle( string manufacturer, string model, int makeYear, string registrationNumber, double tankCapacity, int odometer = 0 ) { Manufacturer = manufacturer; Model = model; MakeYear = makeYear; RegistrationNumber = registrationNumber; TankCapacity = tankCapacity; Odometer = odometer; fuelPurchase = new FuelPurchase(); }
/// <summary> /// Retrieves the most recent fuel purchase /// </summary> /// <param name="vehicle">The vehicle to retrieve the most recent fuel purchase</param> /// <returns>The most recent fuel purchase</returns> public FuelPurchase Recent(Vehicle vehicle) { FuelPurchase RecentFuelPurchase = null; if (List.Count > 0) { // Group Journeys by Vehicle ID. ObservableCollection <FuelPurchase> VehicleFuelPurchases = ByVehicle(vehicle); if (VehicleFuelPurchases.Count > 0) { RecentFuelPurchase = VehicleFuelPurchases[0]; } } return(RecentFuelPurchase); }
/// <summary> /// Edit an existing fuel purchase /// </summary> /// <param name="fuelPurchase">The fuel purchase to be referenced and to be modified</param> /// <param name="cost">Cost of the fuel purchased. Up to 2 decimal points</param> /// <param name="litres">Fuel purchased in litres. Up to 2 decimal points</param> /// <param name="date">Date of purchase of fuel</param> public void Edit(FuelPurchase fuelPurchase, decimal cost, double litres, DateTime date) { var FoundFuelPurchase = List.FirstOrDefault(i => i.Id == fuelPurchase.Id); if (FoundFuelPurchase != null) { FoundFuelPurchase.Cost = cost; FoundFuelPurchase.Litres = litres; FoundFuelPurchase.Date = date; string statement = $"UPDATE `fuel_purchases`" + $"SET " + $"`litres` = {FoundFuelPurchase.Litres.ToString()}, " + $"`cost` = {FoundFuelPurchase.Cost.ToString()}, " + $"`date` = '{FoundFuelPurchase.Date.ToString("yyyy-MM-dd")}'" + $"WHERE `id` = {FoundFuelPurchase.Id.ToString()};"; // Execute statement if able ExecuteNonQuery(statement); } }
private void LvItems_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (lvItems.SelectedItem is FuelPurchase) { if (online) { if (!editMode) { ToggleEditMode(true); } } else { foreach (Control field in fields) { field.IsEnabled = false; } } selected = (FuelPurchase)lvItems.SelectedItem; SetSelectedToFields(); } }