private void PerformExportWork() { _fileWriter = new MyFileWriter(); try { System.Diagnostics.Debug.WriteLine("Getting Start Information"); string startPoint = tripRepository_.GetStartPointFromTrip(SelectedTripId); System.Threading.Thread.Sleep(300); var recordList = JourneyRepository_.GetExportDataSet(SelectedTripId); System.Diagnostics.Debug.WriteLine(String.Format("There are {0} records in the list", recordList.Count())); _fileWriter.WriteLine(ExportingTripRecord.GetHeader()); foreach (var record in recordList) { record.StartPoint = startPoint; _fileWriter.WriteLine(record.GetAsString()); startPoint = record.EndPoint; System.Threading.Thread.Sleep(50); } System.Threading.Thread.Sleep(1 * 1000); RunOnUiThread(() => { Toast.MakeText(this, "Export Completed", ToastLength.Long).Show(); }); } catch (Exception) { RunOnUiThread(() => { Toast.MakeText(this, "Export Completed", ToastLength.Long).Show(); }); } finally { _progressDialog.Dismiss(); } }
public IEnumerable <ExportingTripRecord> GetExportDataSet(int Id) { List <ExportingTripRecord> list = new List <ExportingTripRecord>(); try { string SQLString = GetCompleteRecordsFromTrip(Id); connection = new SqliteConnection("Data Source=" + GetPathToDatabase()); connection.Open(); using (var c = connection.CreateCommand()) { c.CommandText = SQLString; var reader = c.ExecuteReader(); while (reader.Read()) { DateTime x; DateTime y; if (reader.IsDBNull((3))) { x = DateTime.MinValue; } else { x = DateTime.ParseExact(reader.GetString(3), "yyyy-M-d H:m:s.FFF", CultureInfo.InvariantCulture, DateTimeStyles.None); } if (reader.IsDBNull((4))) { y = DateTime.MinValue; } else { y = DateTime.ParseExact(reader.GetString(4), "yyyy-M-d H:m:s.FFF", CultureInfo.InvariantCulture, DateTimeStyles.None); } ExportingTripRecord record = new ExportingTripRecord() { JourneyStarted = x, JourneyEnded = y, Distance = !reader.IsDBNull(5) ? reader.GetDouble(5) : 0.0, EndPoint = !reader.IsDBNull(6) ? reader.GetString(6) : string.Empty, Notes = !reader.IsDBNull(7) ? reader.GetString(7): string.Empty, Amount = !reader.IsDBNull(8) ? reader.GetString(8) : string.Empty, CostPerUnit = !reader.IsDBNull(9) ? reader.GetString(9) : string.Empty, TotalCost = !reader.IsDBNull(10) ? reader.GetString(10) : string.Empty, DriverName = !reader.IsDBNull(12) ? reader.GetString(12) : string.Empty }; list.Add(record); } reader.Close(); } connection.Close(); connection.Dispose(); connection = null; return(list.AsEnumerable()); } catch (Exception ex) { return(new List <ExportingTripRecord>().AsEnumerable()); } }