Esempio n. 1
0
        /// <summary>
        /// Remove a nicotine from the database.
        /// </summary>
        /// <param name="nicotine">The nicotine to remove.</param>
        public void RemoveNicotine(Nicotine nicotine)
        {
            string cmd = $"DELETE FROM {NIC_TABLE_NAME} WHERE {NIC_ID_COL}={nicotine.ID};";

            try {
                WritableDatabase.ExecSQL(cmd);
            } catch (SQLiteAbortException e) {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Remove the flavor from the database.
        /// </summary>
        /// <param name="flavor"></param>
        public void RemoveFlavor(Flavor flavor)
        {
            string cmd = $"DELETE FROM {FLAVOR_TABLE_NAME} WHERE {FLAVOR_ID_COL}={flavor.ID};";

            try {
                WritableDatabase.ExecSQL(cmd);
            } catch (SQLiteAbortException e) {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Update a nicotine in the database.
        /// </summary>
        /// <param name="nicotine">The nicotine to update.</param>
        public void UpdateNicotine(Nicotine nicotine)
        {
            string cmd = $"UPDATE {NIC_TABLE_NAME} SET {NIC_NAME_COL}=\"{nicotine.Name}\", {NIC_VG_COL}={nicotine.VG}, " +
                         $" {NIC_CONC_COL}={nicotine.Concentration} WHERE {NIC_ID_COL}={nicotine.ID};";

            try {
                WritableDatabase.ExecSQL(cmd);
            } catch (SQLiteAbortException e) {
                Console.WriteLine(e.Message);
            }
        }
        /// <summary>
        /// Update a recipe item in its table.
        /// </summary>
        /// <param name="recipeItem">The recipe item to update.</param>
        public void UpdateRecipeItem(RecipeItem recipeItem)
        {
            string cmd = $"UPDATE {RI_TABLE_NAME} SET {RI_FLAVOR_COL}={recipeItem.Flavor.ID}, {RI_PERCENTAGE_COL}={recipeItem.Percentage} " +
                         $"WHERE {RI_ID_COL}={recipeItem.ID};";

            try {
                WritableDatabase.ExecSQL(cmd);
            } catch (SQLiteAbortException e) {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Update an existing flavor in the database.
        /// </summary>
        /// <param name="flavor">The flavor to be updated.</param>
        public void UpdateFlavor(Flavor flavor)
        {
            int    pg  = flavor.PG ? 1 : 0;
            string cmd = $"UPDATE {FLAVOR_TABLE_NAME} SET {FLAVOR_NAME_COL}=\"{flavor.Name}\", {FLAVOR_PG_COL}={pg}, " +
                         $"{FLAVOR_RECPER_COL}={flavor.RecommendedPercentage} WHERE {FLAVOR_ID_COL} = {flavor.ID};";

            try {
                WritableDatabase.ExecSQL(cmd);
            } catch (SQLiteAbortException e) {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Add a new nicotine to the nicotine table.
        /// </summary>
        /// <param name="nicotine">The nicotine to add.</param>
        public void PutNicotine(Nicotine nicotine)
        {
            string cmd = $"INSERT INTO {NIC_TABLE_NAME} ({NIC_NAME_COL}, {NIC_VG_COL}, {NIC_CONC_COL}) " +
                         $"VALUES (\"{nicotine.Name}\", {nicotine.VG}, {nicotine.Concentration});";

            try {
                WritableDatabase.ExecSQL(cmd);
                nicotine.ID = GetLastInsertedID();
            } catch (SQLiteAbortException e) {
                Console.WriteLine(e.Message);
            }
        }
        /// <summary>
        /// Remove a recipe item from the database.
        /// </summary>
        /// <param name="recipeItem">The recipe item to remove.</param>
        public void RemoveRecipeItem(RecipeItem recipeItem)
        {
            string cmd     = $"DELETE FROM {RI_TABLE_NAME} WHERE {RI_ID_COL}={recipeItem.ID};";
            string joinCmd = $"DELETE FROM {RECIPE_RI_TABLE_NAME} WHERE {RECIPE_RI_RI_ID}={recipeItem.ID};";

            try {
                WritableDatabase.ExecSQL(cmd);
                WritableDatabase.ExecSQL(joinCmd);
            } catch (SQLiteAbortException e) {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Add a new flavor to the flavor table.
        /// </summary>
        /// <param name="flavor">The flavor being added.</param>
        public void PutFlavor(Flavor flavor)
        {
            int    pg  = flavor.PG ? 1 : 0;
            string cmd = $"INSERT INTO {FLAVOR_TABLE_NAME} ({FLAVOR_NAME_COL}, {FLAVOR_PG_COL}, {FLAVOR_RECPER_COL}) " +
                         $"VALUES (\"{flavor.Name}\", {pg}, {flavor.RecommendedPercentage});";

            try {
                WritableDatabase.ExecSQL(cmd);
                flavor.ID = GetLastInsertedID();
            } catch (SQLiteAbortException e) {
                Console.WriteLine(e.Message);
            }
        }
        /// <summary>
        /// Add the recipe item to its table.
        /// </summary>
        /// <param name="recipeItem">The recipe item to add.</param>
        public void PutRecipeItem(RecipeItem recipeItem, Recipe owner)
        {
            string cmd = $"INSERT INTO {RI_TABLE_NAME} ({RI_FLAVOR_COL}, {RI_PERCENTAGE_COL}) " +
                         $"VALUES ({recipeItem.Flavor.ID}, {recipeItem.Percentage});";
            string joinCmd = $"INSERT INTO {RECIPE_RI_TABLE_NAME} ({RECIPE_RI_RECIPE_ID}, " +
                             $" {RECIPE_RI_RI_ID}) VALUES ({owner.ID}, {recipeItem.ID});";

            try {
                WritableDatabase.ExecSQL(cmd);
                recipeItem.ID = GetLastInsertedID();
                WritableDatabase.ExecSQL(cmd);
            } catch (SQLiteAbortException e) {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 10
0
        public void EmptyDb(string appId)
        {
            // query to obtain the names of all tables in your database
            ICursor       c      = WritableDatabase.RawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);
            List <String> tables = new List <string>();

            // iterate over the result set, adding every table name to a list
            while (c.MoveToNext())
            {
                tables.Add(c.GetString(0));
            }

            // call DROP TABLE on every table name
            foreach (String table in tables)
            {
                String dropQuery = "DELETE FROM " + table;
                WritableDatabase.ExecSQL(dropQuery);
            }
        }
Esempio n. 11
0
        public long SaveText(IEditable Text, Bundle args)
        {
            long   NoteNumber = 0;
            string date       = DateTime.Now.ToString("dd MMM yyyyг. HH:mm");

            ContentValues    cv       = new ContentValues();
            SpannableFactory a        = new SpannableFactory();
            ISpannable       saveText = a.NewSpannable(Text);



            Java.Lang.Object[] span = saveText.GetSpans(0, saveText.Length(), Java.Lang.Class.FromType(typeof(ImageSpan)));
            if (span != null)
            {
                for (int i = 0; i < span.Length; i++)
                {
                    saveText.RemoveSpan(span[i]);
                }
            }
            if (Build.VERSION.SdkInt >= BuildVersionCodes.N)
            {
                cv.Put(COLUMN_TEXT, Html.ToHtml(saveText, ToHtmlOptions.ParagraphLinesIndividual));
            }
            else
            {
                cv.Put(COLUMN_TEXT, Html.ToHtml(saveText));
            }
            cv.Put(COLUMN_EDITINGTIME, date);
            if (args != null)
            {
                WritableDatabase.Update(TEXTTABLE, cv, "_id == ?", new string[] { args.GetString(Databasehelper.COLUMN_ID) });
                WritableDatabase.ExecSQL("DELETE from " + CONTENTTABLE + " Where _id == " + args.GetString(Databasehelper.COLUMN_ID)); //Delete old image
                NoteNumber = Convert.ToInt32(args.GetString(COLUMN_ID));
            }
            else
            {
                long id = 1;
                cursor = WritableDatabase.RawQuery("Select _id from " + Databasehelper.TEXTTABLE + " ORDER BY _id DESC LIMIT 1", null);
                if (cursor.MoveToFirst())
                {
                    id = cursor.GetLong(cursor.GetColumnIndex("_id"));
                    cursor.Close();
                    id++;
                }
                cv.Put(COLUMN_ID, id);
                WritableDatabase.Insert(TEXTTABLE, null, cv);
                NoteNumber = id;
            }
            Java.Lang.Object[] spans = Text.GetSpans(0, Text.Length(), Java.Lang.Class.FromType(typeof(ImageSpan)));
            //Insert Image in Database
            if (spans != null)
            {
                for (int i = 0; i < spans.Length; i++)
                {
                    int    start = Text.GetSpanStart(spans[i]);
                    int    end   = Text.GetSpanEnd(spans[i]);
                    string source;

                    source = Text.ToString().Substring(start + 1, end - start - 2);


                    SaveBitmapBase(NoteNumber, source, start, end, ((BitmapDrawable)((ImageSpan)spans[i]).Drawable).Bitmap);
                }
            }
            return(NoteNumber);
        }
Esempio n. 12
0
        public void DropTable(string tableName)
        {
            string sql = "drop table if exists " + tableName;

            WritableDatabase.ExecSQL(sql);
        }