コード例 #1
0
ファイル: Situation.cs プロジェクト: Spanyardie/MindYourMood
        public string toString()
        {
            string ret = "";

            ret  = "What: " + What.Trim() + "\r\n";
            ret += "Who: " + Who.Trim() + "\r\n";
            ret += "Where: " + Where.Trim() + "\r\n";
            ret += "When: " + When.Trim();

            return(ret);
        }
コード例 #2
0
ファイル: Situation.cs プロジェクト: Spanyardie/MindYourMood
        public void Save(SQLiteDatabase sqLiteDatabase)
        {
            if (sqLiteDatabase.IsOpen)
            {
                if (IsNew)
                {
                    try
                    {
                        ContentValues values = new ContentValues();
                        values.Put("ThoughtRecordID", ThoughtRecordId);
                        string what = What.Trim().Replace("'", "''").Replace("\"", "\"\"");
                        values.Put("What", what);
                        string when = When.Trim().Replace("'", "''").Replace("\"", "\"\"");
                        values.Put("[When]", when);
                        string where = Where.Trim().Replace("'", "''").Replace("\"", "\"\"");
                        values.Put("[Where]", where);
                        string who = Who.Trim().Replace("'", "''").Replace("\"", "\"\"");
                        values.Put("Who", who);

                        SituationId = (int)sqLiteDatabase.Insert("Situation", null, values);

                        IsNew   = false;
                        IsDirty = false;
                    }
                    catch (Exception newE)
                    {
                        throw new Exception("Unable to Save Situation to database - " + newE.Message);
                    }
                }

                if (IsDirty)
                {
                    try
                    {
                        ContentValues values = new ContentValues();
                        values.Put("[ThoughtRecordID]", ThoughtRecordId);
                        values.Put("Who", Who.Trim().Replace("'", "''").Replace("\"", "\"\""));
                        values.Put("What", What.Trim().Replace("'", "''").Replace("\"", "\"\""));
                        values.Put("When", When.Trim().Replace("'", "''").Replace("\"", "\"\""));
                        values.Put("Where", Where.Trim().Replace("'", "''").Replace("\"", "\"\""));
                        string whereClause = "SituationID = " + SituationId;
                        sqLiteDatabase.Update("Situation", values, whereClause, null);

                        IsDirty = false;
                    }
                    catch (Exception dirtyE)
                    {
                        throw new Exception("Unable to Update Situation in the database - " + dirtyE.Message);
                    }
                }
            }
        }