Exemple #1
0
            public void initDB(SQLiteDatabase db)
            {
                db.ExecSQL("DROP TABLE IF EXISTS " + "general");
                db.ExecSQL("DROP TABLE IF EXISTS " + "records");
                db.ExecSQL("create table records ("
                           + "id integer primary key autoincrement,"
                           + "time int,"
                           + "difficulty text" + ");");
                db.ExecSQL("create table general ("
                           + "difficulty text primary key,"
                           + "avgTime int,"
                           + "gamesCount int" + ");");
                ContentValues cv = new ContentValues();

                cv.Put("difficulty", "Easy");
                cv.Put("avgTime", 0);
                cv.Put("gamesCount", 0);
                db.Insert("general", null, cv);
                cv.Clear();
                cv.Put("difficulty", "Normal");
                cv.Put("avgTime", 0);
                cv.Put("gamesCount", 0);
                db.Insert("general", null, cv);
                cv.Clear();
                cv.Put("difficulty", "Hard");
                cv.Put("avgTime", 0);
                cv.Put("gamesCount", 0);
                db.Insert("general", null, cv);
            }
        void InsertValues()
        {
            ContentValues values = new ContentValues();

            values.Put(LocationContentProvider._ID, 1);
            values.Put(LocationContentProvider.NAME, "Brüel & Kjær");
            values.Put(LocationContentProvider.LATITUTDE, 55.816932);
            values.Put(LocationContentProvider.LONGITUDE, 12.532697);
            Android.Net.Uri uri = ContentResolver.Insert(LocationContentProvider.CONTENT_URI, values);
            System.Diagnostics.Debug.WriteLine("Insert: " + uri.ToString());

            values.Clear();

            values.Put(LocationContentProvider._ID, 2);
            values.Put(LocationContentProvider.NAME, "Technical University of Denmark");
            values.Put(LocationContentProvider.LATITUTDE, 55.786323);
            values.Put(LocationContentProvider.LONGITUDE, 12.524135);
            uri = ContentResolver.Insert(LocationContentProvider.CONTENT_URI, values);
            System.Diagnostics.Debug.WriteLine("Insert: " + uri.ToString());
        }
Exemple #3
0
        public static void category_populate(SQLiteDatabase db)
        {
            string[] categorys = { "Comida", "Combustível", "Pedágio", "Manutenção", "Outros" };

            ContentValues category_values = new ContentValues();

            foreach (string s in categorys)
            {
                category_values.Put("registration_date", DateTime.Now.ToString());
                category_values.Put("lastedit_date", DateTime.Now.ToString());
                category_values.Put("name", s);
                db.Insert("category", null, category_values);
                category_values.Clear();
            }

            //TODO

            ContentValues trip_values = new ContentValues();


            trip_values.Put("reward", 1250);
            trip_values.Put("home", "Leme");
            trip_values.Put("destiny", "Araras");
            trip_values.Put("toll_value", 100);
            trip_values.Put("fuell_value", 200);
            trip_values.Put("freight", "Arroz");
            trip_values.Put("registration_date", DateTime.Now.ToString());
            trip_values.Put("lastedit_date", DateTime.Now.ToString());
            trip_values.Put("complete_date", "");
            db.Insert("trip", null, trip_values);
            trip_values.Clear();

            trip_values.Put("reward", 3000);
            trip_values.Put("home", "Campinas");
            trip_values.Put("destiny", "São Paulo");
            trip_values.Put("toll_value", 100);
            trip_values.Put("fuell_value", 200);
            trip_values.Put("freight", "Arroz");
            trip_values.Put("registration_date", DateTime.Now.ToString());
            trip_values.Put("lastedit_date", DateTime.Now.ToString());
            trip_values.Put("complete_date", "");
            db.Insert("trip", null, trip_values);
            trip_values.Clear();

            trip_values.Put("reward", 4000);
            trip_values.Put("home", "Pernambuco");
            trip_values.Put("destiny", "Amapá");
            trip_values.Put("toll_value", 100);
            trip_values.Put("fuell_value", 200);
            trip_values.Put("freight", "Arroz");
            trip_values.Put("registration_date", DateTime.Now.ToString());
            trip_values.Put("lastedit_date", DateTime.Now.ToString());
            trip_values.Put("complete_date", "");
            db.Insert("trip", null, trip_values);
            trip_values.Clear();

            /*
             *
             * values.Put("reward", this.reward);
             * values.Put("home", this.home);
             * values.Put("destiny", this.destiny);
             * values.Put("toll_value", this.toll_value);
             * values.Put("fuell_value", this.fuell_value);
             * values.Put("freight", this.freight);
             * values.Put("registration_date", DateTime.Now.ToString());
             * values.Put("lastedit_date", DateTime.Now.ToString());
             * values.Put("complete_date", 0);
             */
        }
Exemple #4
0
 public static void clear(this ContentValues values)
 {
     values.Clear();
 }
Exemple #5
0
        public void putRecord(long time, String difficulty, Context context)
        {
            dbHelper = new DBHelper(context);
            ContentValues  cv    = new ContentValues();
            SQLiteDatabase db    = dbHelper.WritableDatabase;
            SQLiteCursor   c     = (SQLiteCursor)db.Query("records", null, " difficulty = ?", new String[] { difficulty }, null, null, null);
            int            count = 1;

            if (c.MoveToFirst())
            {
                int idColIndex   = c.GetColumnIndex("id");
                int timeColIndex = c.GetColumnIndex("time");

                int maxDBindex = c.GetInt(idColIndex);
                int maxDBtime  = c.GetInt(timeColIndex);
                count++;
                while (c.MoveToNext())
                {
                    if (c.GetInt(timeColIndex) > maxDBtime)
                    {
                        maxDBtime  = c.GetInt(timeColIndex);
                        maxDBindex = c.GetInt(idColIndex);
                    }
                    count++;
                }
                if (count == 6)
                {
                    if (time < maxDBtime)
                    {
                        db.Delete("records", " id = ?", new String[] { maxDBindex + "" });
                    }
                    else
                    {
                        c.Close();
                        db.Close();
                        return;
                    }
                }
            }
            cv.Put("time", time);
            cv.Put("difficulty", difficulty);
            db.Insert("records", null, cv);
            cv.Clear();

            SQLiteCursor gc = (SQLiteCursor)db.Query("general", null, "difficulty = ?", new String[] { difficulty }, null, null, null);

            gc.MoveToFirst();
            int avgTimeColIndex    = gc.GetColumnIndex("avgTime");
            int gamesCountColIndex = gc.GetColumnIndex("gamesCount");
            int avgTime            = 0;
            int gamesCount         = 0;

            if (gc.MoveToFirst())
            {
                avgTime    = gc.GetInt(avgTimeColIndex);
                gamesCount = gc.GetInt(gamesCountColIndex);
            }
            int newGamesCount = gamesCount + 1;
            int newAvgTime    = (avgTime * gamesCount / newGamesCount) + (int)(time / newGamesCount);

            cv.Put("difficulty", difficulty);
            cv.Put("avgTime", newAvgTime);
            cv.Put("gamesCount", newGamesCount);
            db.Delete("general", " difficulty = ?", new String[] { difficulty });
            db.Insert("general", null, cv);
            db.Close();
            c.Close();
            gc.Close();
        }