private void LoadThoughtRecord(int id, SQLiteDatabase sqLiteDatabase) { try { string commandText = "SELECT [RecordDate] FROM ThoughtRecord WHERE [ThoughtRecordID] = " + id; Log.Info(TAG, "command text - " + commandText); if (sqLiteDatabase.IsOpen) { Log.Info(TAG, "Database is open, running raw query"); var data = sqLiteDatabase.RawQuery(commandText, null); if (data != null) { Log.Info(TAG, "Found " + data.Count.ToString() + " items" + (data.Count > 1?" found more than 1 item!":"")); if (data.MoveToNext()) { do { var stringDate = Convert.ToDateTime(data.GetString(0)); RecordDateTime = stringDate; ThoughtRecordId = id; Log.Info(TAG, "Retrieved! Date " + RecordDateTime.ToShortDateString() + ", Id " + ThoughtRecordId.ToString()); }while (data.MoveToNext()); } data.Close(); } } } catch (Exception e) { Log.Error(TAG, "Exception - " + e.Message); } }
public override string ConvertToString() { return (RecordDateTime.ToString(DATE_TIME_PATTERN) + RECORD_FIELD_SEPARATORS[0] + Content); }
private void SaveThoughtRecord(SQLiteDatabase sqLiteDatabase) { if (sqLiteDatabase.IsOpen) { Log.Info(TAG, "SaveThoughtRecord: Database is Open"); if (IsNew) { Log.Info(TAG, "SaveThoughtRecord: New record"); try { //string commandText = "INSERT INTO ThoughtRecord([RecordDate]) VALUES (CDateTime(#" + RecordDateTime + "#))"; string commandText = "INSERT INTO ThoughtRecord([RecordDate]) VALUES ('" + RecordDateTime.ToString() + "')"; Log.Info(TAG, "SaveThoughtRecord: Command text is '" + commandText + "'"); ContentValues values = new ContentValues(); values.Put("RecordDate", String.Format("{0:yyyy-MM-dd HH:mm:ss}", RecordDateTime)); var retVal = sqLiteDatabase.Insert("ThoughtRecord", null, values); GlobalData.ThoughtRecordId = retVal; ThoughtRecordId = retVal; Log.Info(TAG, "SaveThoughtRecord: retVal assigned to global thoughtrecordId - " + retVal.ToString()); Log.Info(TAG, "SaveThoughtRecord: Internal ThoughtRecord Id is " + ThoughtRecordId.ToString()); IsNew = false; IsDirty = false; } catch (Exception e) { Log.Error(TAG, "SaveThoughtRecord: Exception - " + e.Message); throw new Exception("Attempt to save Thought Record failed - " + e.Message); } } } }
public override string ToString() { return($"{RecordDateTime.ToString(DateTimeFormat)}, {RecordTemperature:F2}"); }