Exemplo n.º 1
0
        public RecordInfo getRecordsInfo(String difficulty, Context context)
        {
            dbHelper = new DBHelper(context);
            SQLiteDatabase db = dbHelper.WritableDatabase;
            SQLiteCursor   gc = (SQLiteCursor)db.Query("general", null, "difficulty = ?", new String[] { difficulty }, null, null, null);
            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);
            }
            RecordInfo   result = new RecordInfo(avgTime, gamesCount, new Java.Lang.String(difficulty));
            SQLiteCursor c      = (SQLiteCursor)db.Query("records", null, " difficulty = ?", new String[] { difficulty }, null, null, null);

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

                result.addRecord(c.GetInt(timeColIndex));
                while (c.MoveToNext())
                {
                    result.addRecord(c.GetInt(timeColIndex));
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public SQLiteCursor pobierz()
        {
            SQLiteDatabase db     = this.WritableDatabase;
            SQLiteCursor   kursor = (SQLiteCursor)db.RawQuery("SELECT * FROM " + database_table + " ORDER BY PUNKTY DESC", null);// + "ORDER BY 3 DESC", null);

            return(kursor);
        }
Exemplo n.º 3
0
        public Settings GetByName(SettingName settingname)
        {
            String[] projection =
            {
                FeedEntry.Id,
                FeedEntry.COLUMN_NAME_NAME,
                FeedEntry.COLUMN_NAME_VAL_1,
                FeedEntry.COLUMN_NAME_VAL_2,
                FeedEntry.COLUMN_NAME_VAL_3,
                FeedEntry.COLUMN_NAME_VAL_4,
                FeedEntry.COLUMN_NAME_VAL_5,
            };
            String selection = FeedEntry.COLUMN_NAME_NAME + " = ?";

            String[]     selectionArgs = { settingname.ToString() };
            String       sortOrder     = FeedEntry.COLUMN_NAME_NAME + " DESC";
            SQLiteCursor cursor        = (SQLiteCursor)db.Query(
                FeedEntry.TABLE_NAME,                     // The table to query
                projection,                               // The columns to return
                selection,                                // The columns for the WHERE clause
                selectionArgs,                            // The values for the WHERE clause
                null,                                     // don't group the rows
                null,                                     // don't filter by row groups
                sortOrder                                 // The sort order
                );

            cursor.MoveToFirst();
            Settings result = null;

            if (cursor.Count > 0)
            {
                result       = new Settings();
                result.Id    = cursor.GetLong(cursor.GetColumnIndexOrThrow(FeedEntry.Id));
                result.Name  = (SettingName)Enum.Parse(typeof(SettingName), cursor.GetString(cursor.GetColumnIndexOrThrow(FeedEntry.COLUMN_NAME_NAME)));
                result.Val_1 = cursor.GetString(cursor.GetColumnIndexOrThrow(FeedEntry.COLUMN_NAME_VAL_1));
                result.Val_2 = cursor.GetString(cursor.GetColumnIndexOrThrow(FeedEntry.COLUMN_NAME_VAL_2));
                result.Val_3 = cursor.GetString(cursor.GetColumnIndexOrThrow(FeedEntry.COLUMN_NAME_VAL_3));
                result.Val_4 = cursor.GetString(cursor.GetColumnIndexOrThrow(FeedEntry.COLUMN_NAME_VAL_4));
                result.Val_5 = cursor.GetString(cursor.GetColumnIndexOrThrow(FeedEntry.COLUMN_NAME_VAL_5));
                cursor.Close();
            }
            return(result);
        }
Exemplo n.º 4
0
        public void pokazwyniki()
        {
            SQLiteCursor kursor = db.pobierz();

            if (kursor.Count > 0)
            {
                Toast.MakeText(this, "coś jest", ToastLength.Long).Show();
                StringBuffer buff = new StringBuffer();
                int          i    = 1;
                while (kursor.MoveToNext())

                {
                    buff.Append(i + "  " + kursor.GetString(1) + "       " + kursor.GetString(2) + "\n");
                    ++i;
                }
                listWyniki.Add(buff.ToString());
                PokazWiadomosc("Wynik", buff.ToString());
            }
            else
            {
                PokazWiadomosc("Brak", "NIe udało sie");
            }
        }
Exemplo n.º 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();
        }