private void LoadAutomaticThoughts(int id, SQLiteDatabase sqLiteDatabase) { try { AutomaticThoughts autoThought = new AutomaticThoughts(); string commandText = "SELECT [AutomaticThoughtsID], [Thought], [HotThought] FROM AutomaticThoughts WHERE [ThoughtRecordID] = " + id; if (sqLiteDatabase.IsOpen) { var data = sqLiteDatabase.RawQuery(commandText, null); if (data != null) { if (data.MoveToNext()) { do { autoThought = new AutomaticThoughts(); autoThought.AutomaticThoughtsId = data.GetInt(0); autoThought.ThoughtRecordId = id; autoThought.Thought = data.GetString(1).Trim(); autoThought.IsHotThought = Convert.ToBoolean(data.GetShort(2)); autoThought.IsNew = false; autoThought.IsDirty = false; AutomaticThoughtsList.Add(autoThought); }while (data.MoveToNext()); } } data.Close(); } } catch (Exception e) { throw new Exception("Load of Automatic Thoughts failed - " + e.Message); } }
public void AddAutomaticThought(AutomaticThoughts newAutomaticThought) { try { if (newAutomaticThought != null) { AutomaticThoughtsList.Add(newAutomaticThought); IsDirty = true; } } catch (Exception e) { throw new Exception("Attempt to add Automatic Thought failed - " + e.Message); } }
private void ClearAutomaticThoughts(SQLiteDatabase sqLiteDatabase) { try { if (AutomaticThoughtsList.Count > 0) { foreach (var automaticThought in AutomaticThoughtsList) { if (!automaticThought.IsNew) { automaticThought.Remove(sqLiteDatabase); } } AutomaticThoughtsList.Clear(); } } catch (Exception e) { throw new Exception("Attempt to clear Automatic Thoughts failed - " + e.Message); } }
public void RemoveAutomaticThought(AutomaticThoughts automaticThought, SQLiteDatabase sqlDatabase) { try { //caller will have to warn User that any EvidenceForHotThought and EvidenceAgainstHotThought based on this will also be removed if (automaticThought != null) { //find and remove any EvidenceForHotThought with this ID foreach (var evidenceForHotThought in EvidenceForHotThoughtList) { if (evidenceForHotThought.AutomaticThoughtsId == automaticThought.AutomaticThoughtsId) { EvidenceForHotThoughtList.Remove(evidenceForHotThought); evidenceForHotThought.Remove(sqlDatabase); break; } } //find and remove any EvidenceAgainstHotThought with this ID foreach (var evidenceAgainstHotThought in EvidenceAgainstHotThoughtList) { if (evidenceAgainstHotThought.AutomaticThoughtsId == automaticThought.AutomaticThoughtsId) { EvidenceAgainstHotThoughtList.Remove(evidenceAgainstHotThought); evidenceAgainstHotThought.Remove(sqlDatabase); break; } } automaticThought.Remove(sqlDatabase); AutomaticThoughtsList.Remove(automaticThought); } } catch (Exception e) { throw new Exception("Attempt to remove Automatic Thought failed - " + e.Message); } }