Exemplo n.º 1
0
 public static void RemoveThoughtRecord()
 {
     try
     {
         Log.Info(TAG, "RemoveThoughtRecord: ThoughtRecordId - " + ThoughtRecordId.ToString());
         if (ThoughtRecordId > 0)
         {
             Log.Info(TAG, "RemoveThoughtRecord: Id > 0, proceeding to remove");
             var dbHelp = new Globals();
             dbHelp.OpenDatabase();
             ThoughtRecordItem.RemoveThisThoughtRecord(dbHelp.GetSQLiteDatabase());
             dbHelp.CloseDatabase();
             Log.Info(TAG, "RemoveThoughtRecord: Reset ThoughtRecordItem");
             ThoughtRecordId   = 0;
             ThoughtRecordItem = new ThoughtRecord(); //empty one for next use
         }
         if (ThoughtRecordId == 0)
         {
             Log.Info(TAG, "RemoveThoughtRecord: Skipped Removal, ID is zero!");
         }
     }
     catch (System.Exception e)
     {
         Log.Error(TAG, "RemoveThoughtRecord: Error removing Thought Record with ID " + ThoughtRecordId.ToString() + " - " + e.Message);
     }
 }
Exemplo n.º 2
0
        public static void SetupDataFields()
        {
            try
            {
                ThoughtRecordId                = 0;
                ThoughtRecordItem              = new ThoughtRecord();
                SituationItem                  = new Situation();
                MoodItems                      = new List <Mood>();
                MoodListItems                  = new List <MoodList>();
                AutomaticThoughtsItems         = new List <AutomaticThoughts>();
                EvidenceForHotThoughtItems     = new List <EvidenceForHotThought>();
                EvidenceAgainstHotThoughtItems = new List <EvidenceAgainstHotThought>();
                AlternativeThoughtsItems       = new List <AlternativeThoughts>();
                RerateMoodsItems               = new List <RerateMood>();
                ThoughtRecordsItems            = new List <ThoughtRecord>();

                Log.Info(TAG, "Exiting SetupDataFields with ThoughtRecordId = " + ThoughtRecordId.ToString());
            }
            catch (System.Exception e)
            {
                Log.Error(TAG, "SetupDataFields: Error occurred initialising default data objects - " + e.Message);
            }
        }
Exemplo n.º 3
0
        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);
                    }
                }
            }
        }