Exemple #1
0
        public bool Remove()
        {
            SQLiteDatabase sqlDatabase = null;

            try
            {
                Globals dbHelp = new Globals();
                dbHelp.OpenDatabase();
                sqlDatabase = dbHelp.GetSQLiteDatabase();
                if (sqlDatabase != null && sqlDatabase.IsOpen)
                {
                    Log.Info(TAG, "Remove: Attempting to Remove Medication with ID - " + ID.ToString());
                    var sql = @"DELETE FROM [Medication] WHERE ID = " + ID.ToString();
                    sqlDatabase.ExecSQL(sql);
                    Log.Info(TAG, "Remove: Removed Medication with ID " + ID.ToString());
                    if (MedicationSpread != null && MedicationSpread.Count > 0)
                    {
                        foreach (var spread in MedicationSpread)
                        {
                            Log.Info(TAG, "Remove: Removing Spread with ID - " + spread.ID.ToString());
                            spread.Remove();
                        }
                        if (PrescriptionType != null)
                        {
                            Log.Info(TAG, "Remove: Removing Prescription Type with ID - " + PrescriptionType.ID.ToString());
                            PrescriptionType.Remove();
                            PrescriptionType = new Prescription();
                        }
                        sqlDatabase.Close();
                        return(true);
                    }
                }
                Log.Error(TAG, "Remove: SQLite database is null or was not open - remove failed");
                return(false);
            }
            catch (Exception e)
            {
                Log.Error(TAG, "Remove: Exception - " + e.Message);
                if (sqlDatabase != null && sqlDatabase.IsOpen)
                {
                    sqlDatabase.Close();
                }
                return(false);
            }
        }