Exemple #1
0
 public bool SaveTripDescription(TripDecorator trip)
 {
     var didSave = false;
     using (var db = _dbHelper.WritableDatabase)
     {
         var countCursor = db.RawQuery("SELECT COUNT(*) AS kount FROM " + VehicleTripDescriptionTable.TABLE_NAME + " WHERE vehicle=? AND description=?;", new[] {trip.Vehicle, trip.Description});
         countCursor.MoveToFirst();
         var colIndex = countCursor.GetColumnIndexOrThrow("kount");
         var rowCount = countCursor.GetInt(colIndex);
         if (rowCount == 0)
         {
             var x = new VehicleTripDescription(trip);
             try
             {
                 db.InsertOrThrow(VehicleTripDescriptionTable.TABLE_NAME, null, x.ToContentValues());
                 didSave = true;
                 Log.Debug(TAG, "Added the description " + trip.Description + " for the vehicle " + trip.Vehicle + ".");
             }
             catch (Exception ex)
             {
                 Log.Error(TAG, ex.ToString());
                 didSave = false;
             }
         }
         else
         {
             Log.Debug(TAG, "There already is a description " + trip.Description + " for the vehicle " + trip.Vehicle);
         }
         countCursor.Close();
     }
     return didSave;
 }
 public VehicleTripDescription(TripDecorator trip)
     : this()
 {
     Vehicle = trip.Vehicle;
     Description = trip.Description;
 }
Exemple #3
0
        /// <summary>
        ///   Save a trip to the database, and save the trip description as well.
        /// </summary>
        /// <param name="trip"> </param>
        /// <returns> </returns>
        public bool Save(TripDecorator trip)
        {
            Toast toast;
            var didSave = false;
            if (trip.IsValid())
            {
                Log.Verbose(TAG, "The trip was valid - saving to the database.");

                using (var db = _dbHelper.WritableDatabase)
                {
                    try
                    {
                        db.InsertOrThrow(TripTable.TABLE_NAME, null, trip.ToContentValues());
                        didSave = true;
                        Log.Verbose(TAG, "Saved a new trip to the database.");
                        SaveTripDescription(trip);
                        toast = Toast.MakeText(_context, "Saved your trip.", ToastLength.Short);
                    }
                    catch (Exception ex)
                    {
                        Log.Error(TAG, ex.ToString());
                        toast = Toast.MakeText(_context, "There was an error trying to save your trip. Sorry.", ToastLength.Long);
                    }
                }
            }
            else
            {
                Log.Debug(TAG, "The trip is not valid.");
                toast = Toast.MakeText(_context, "There seems to be something wrong with your data. You should fix it.",
                                       ToastLength.Long);
            }
            toast.Show();
            return didSave;
        }