// Update public bool FinishTrip(double counterEnd, double counterEndDecimal) { bool success = false; Debug.WriteLine("TMVM: Finishing trip..."); if (counterEndDecimal <= 0) { counterEndDecimal = 0; } string counterString = counterEnd + "." + counterEndDecimal; double counter = Convert.ToDouble(counterString, CultureInfo.InvariantCulture); counter = Math.Round(counter, 1); if (counter > currentTrip.CounterStart) { counterEnd = Math.Round(counter, 1); currentTrip.CounterEnd = counter; tripManager.Update(currentTrip); currentTrip = null; success = true; } else { // Give error f**k.ShowErrorDialog("Message-WrongAmount"); } return(success); }
// Add public void AddNewTrip(int carId, double counterStart, double counterStartDecimal) { Debug.WriteLine("TMVM: Add new trip..."); TripViewModel tripViewModel = new TripViewModel(); // Get Car ID and add that to the trip tripViewModel.CarId = carId; if (counterStartDecimal <= 0) { counterStartDecimal = 0; } string counterString = counterStart + "." + counterStartDecimal; double counter = Convert.ToDouble(counterString, CultureInfo.InvariantCulture); counter = Math.Round(counter, 1); tripViewModel.CounterStart = counter; tripManager.Add(tripViewModel); this._Trips.Add(tripViewModel); this._SelectedIndex = this._Trips.IndexOf(tripViewModel); tripViewModel.PropertyChanged += Trip_OnNotifyPropertyChanged; // Update Total distance Debug.WriteLine("Trip ID: " + tripViewModel.TripId); Debug.WriteLine("GrandTotalDistance: " + this.TotalDistance.ToString()); }
// Delete all trips public void DeleteAll() { try { foreach (TripViewModel trip in _Trips) { tripManager.Delete(trip); } _Trips.Clear(); currentTrip = null; Debug.WriteLine("TMVM: Deleted all trips!"); } catch { Debug.WriteLine("TMVM: Coudn't delete all trips :("); } }
public void GetTrips(int carId) { tripManager = new TripManager(carId); _SelectedIndex = -1; _Trips.Clear(); foreach (var trip in tripManager.Trips) { var newTrip = new TripViewModel(trip); newTrip.PropertyChanged += Trip_OnNotifyPropertyChanged; // Check whether the End-Distance has been filled in. If not, don't add it to the list, but add is as current car if (newTrip.CounterEnd != 0) { _Trips.Add(newTrip); } else { currentTrip = newTrip; } } }
// Delete single trip from list public bool Delete(TripViewModel tripToDelete) { bool success = false; Debug.WriteLine("TMVM: Delete single Trip - Starting attempt"); try { this.tripManager.Delete(tripToDelete); this._Trips.Remove(tripToDelete); this._SelectedIndex = -1; Debug.WriteLine("TMVM: Delete single Trip - Successful"); success = true; } catch (Exception ex) { Debug.WriteLine("TMVM: Delete single Trip - Failed"); Debug.WriteLine("Error: " + ex); } return(success); }