Ejemplo n.º 1
0
        public bool LoadMedicationSpread()
        {
            SQLiteDatabase sqlDatabase = null;

            try
            {
                var      sql    = @"SELECT [Dosage], [FoodRelevance] FROM [MedicationSpread] WHERE [ID] = ? AND [MedicationID] = ?";
                string[] values = new string[]
                {
                    ID.ToString(),
                         MedicationID.ToString()
                };
                Globals dbHelp = new Globals();
                dbHelp.OpenDatabase();
                sqlDatabase = dbHelp.GetSQLiteDatabase();
                if (sqlDatabase != null)
                {
                    if (sqlDatabase.IsOpen)
                    {
                        ICursor medicationItem = sqlDatabase.RawQuery(sql, values);
                        if (medicationItem.Count > 0)
                        {
                            medicationItem.MoveToFirst();
                            MedicationTakeTime = new MedicationTime();
                            MedicationTakeTime.LoadMedicationTime(ID);
                            MedicationTakeReminder = new MedicationReminder();
                            MedicationTakeReminder.LoadMedicationTime(ID);
                            if (!MedicationTakeReminder.IsSet)
                            {
                                MedicationTakeReminder = null;
                            }
                            Dosage        = medicationItem.GetInt(medicationItem.GetColumnIndex("Dosage"));
                            FoodRelevance = (ConstantsAndTypes.MEDICATION_FOOD)medicationItem.GetInt(medicationItem.GetColumnIndex("FoodRelevance"));
                        }
                        else
                        {
                            dbHelp.CloseDatabase();
                            return(false);
                        }
                    }
                    dbHelp.CloseDatabase();
                }
                return(true);
            }
            catch (Exception e)
            {
                Log.Error(TAG, "LoadMedicationSpread: Exception - " + e.Message);
                if (sqlDatabase != null && sqlDatabase.IsOpen)
                {
                    sqlDatabase.Close();
                }
                return(false);
            }
        }
Ejemplo n.º 2
0
        public bool Save(int medicationSpreadID)
        {
            SQLiteDatabase sqlDatabase = null;

            try
            {
                Globals dbHelp = new Globals();
                dbHelp.OpenDatabase();
                sqlDatabase = dbHelp.GetSQLiteDatabase();
                if (sqlDatabase != null)
                {
                    if (sqlDatabase.IsOpen)
                    {
                        if (IsNew)
                        {
                            Log.Info(TAG, "Save: New Reminder to Save for Spread with ID - " + medicationSpreadID.ToString());
                            ContentValues values = new ContentValues();
                            values.Put("MedicationSpreadID", medicationSpreadID);
                            values.Put("MedicationDay", (int)MedicationDay);
                            values.Put("MedicationTime", string.Format("{0:HH:mm:ss}", MedicationTime));
                            Log.Info(TAG, "Save: Saved Medication Day - " + StringHelper.DayStringForConstant(MedicationDay) + ", Medication Time - " + MedicationTime.ToShortTimeString());

                            ID = (int)sqlDatabase.Insert("MedicationReminder", null, values);
                            Log.Info(TAG, "Save: Reminder saved with new ID - " + ID.ToString());
                            IsNew   = false;
                            IsDirty = false;
                            IsSet   = true;
                            Log.Info(TAG, "Save: IsNew - FALSE, IsDirty - FALSE");
                        }
                        if (IsDirty)
                        {
                            Log.Info(TAG, "Save: Updating existing Reminder, ID - " + ID.ToString());
                            ContentValues values = new ContentValues();
                            values.Put("MedicationSpreadID", medicationSpreadID);
                            values.Put("MedicationDay", (int)MedicationDay);
                            values.Put("MedicationTime", string.Format("{0:HH:mm:ss}", MedicationTime));
                            Log.Info(TAG, "Save: Stored Medication Day - " + StringHelper.DayStringForConstant(MedicationDay) + ", Medication Time - " + MedicationTime.ToShortTimeString());
                            string whereClause = "ID = ?";
                            sqlDatabase.Update("MedicationReminder", values, whereClause, new string[] { ID.ToString() });
                            IsDirty = false;
                            Log.Info(TAG, "Save: Updated, IsDirty - FALSE");
                        }
                        sqlDatabase.Close();
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception e)
            {
                Log.Error(TAG, "Save: Exception - " + e.Message);
                return(false);
            }
        }