Esempio n. 1
0
        //public static SqlConnection SqlConnection = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=\"E:\\The CyberSec Lounge\\Discord Bot\\Data\\TCL_Database.mdf\";Integrated Security=True");

        // Needs a null value checking

        /*
         * internal static BumpGameUser[] GetLastBumpGameWinners()
         * {
         *  SqlCommand getLastBumpGameWinners = new SqlCommand("SELECT TOP 3 * FROM bumpGameUsers ORDER BY Last_Bump DESC;", SqlConnection);
         *  SqlDataReader reader = getLastBumpGameWinners.ExecuteReader();
         *  reader.Read();
         *  BumpGameUser[] users = new BumpGameUser[3];
         *  users.SetValue(new BumpGameUser() { ID = reader.GetInt64(0), Name = reader.GetString(1), FirstBump = reader.GetDateTime(2), LastBump = reader.GetDateTime(3), Points = reader.GetInt32(4) }, 0);
         *  reader.Read();
         *  users.SetValue(new BumpGameUser() { ID = reader.GetInt64(0), Name = reader.GetString(1), FirstBump = reader.GetDateTime(2), LastBump = reader.GetDateTime(3), Points = reader.GetInt32(4) }, 1);
         *  reader.Read();
         *  users.SetValue(new BumpGameUser() { ID = reader.GetInt64(0), Name = reader.GetString(1), FirstBump = reader.GetDateTime(2), LastBump = reader.GetDateTime(3), Points = reader.GetInt32(4) }, 2);
         *  reader.Close();
         *  return users;
         * }
         */

        // Needs a null value checking
        internal static BumpGameUser[] GetLastBumps()
        {
            BumpGameUser[] users        = new BumpGameUser[3];
            int            indexCounter = 0;

            SqlCommand    getLastBumps    = new SqlCommand("SELECT TOP 3 * FROM Bumps ORDER BY Bump_Time DESC", SqlConnection);
            SqlDataReader lastBumpsReader = getLastBumps.ExecuteReader();

            lastBumpsReader.Read();
            users.SetValue(new BumpGameUser()
            {
                ID = lastBumpsReader.GetInt64(1)
            }, 0);
            lastBumpsReader.Read();
            users.SetValue(new BumpGameUser()
            {
                ID = lastBumpsReader.GetInt64(1)
            }, 1);
            lastBumpsReader.Read();
            users.SetValue(new BumpGameUser()
            {
                ID = lastBumpsReader.GetInt64(1)
            }, 2);

            lastBumpsReader.Close();

            foreach (BumpGameUser user in users)
            {
                users.SetValue(GetUser((ulong)user.ID), indexCounter);
                indexCounter++;
            }
            return(users);
        }
Esempio n. 2
0
        internal static BumpGameUser[] GetAllUsers()
        {
            SqlCommand rowCountCommand = new SqlCommand("SELECT COUNT(*) FROM bumpGameUsers;", SqlConnection);
            int        rowCount        = (int)rowCountCommand.ExecuteScalar();

            SqlCommand    getUsers   = new SqlCommand("SELECT * FROM bumpGameUsers ORDER BY Points DESC;", SqlConnection);
            SqlDataReader dataReader = getUsers.ExecuteReader();

            if (rowCount > 0)
            {
                BumpGameUser[] users = new BumpGameUser[rowCount];

                for (int row = 0; row <= rowCount - 1; row++)
                {
                    dataReader.Read();
                    users.SetValue(new BumpGameUser()
                    {
                        ID = dataReader.GetInt64(0), Name = dataReader.GetString(1), FirstBump = dataReader.GetDateTime(2), LastBump = dataReader.GetDateTime(3), Points = dataReader.GetInt32(4)
                    }, row);
                }
                dataReader.Close();
                return(users);
            }

            else
            {
                dataReader.Close();
                return(null);
            }
        }
Esempio n. 3
0
        internal static BumpGameUser[] GetTopUsers(int amount)
        {
            SqlCommand countUsers = new SqlCommand("SELECT COUNT(*) FROM(SELECT TOP(@amount) * FROM bumpGameUsers ORDER BY Points DESC) AS result;", SqlConnection);

            countUsers.Parameters.AddWithValue("@amount", amount);
            int rowCount = (int)countUsers.ExecuteScalar();

            SqlCommand getUsers = new SqlCommand("SELECT TOP (@amount) * FROM bumpGameUsers ORDER BY Points DESC;", SqlConnection);

            getUsers.Parameters.AddWithValue("@amount", amount);
            SqlDataReader dataReader = getUsers.ExecuteReader();

            if (rowCount > 0)
            {
                BumpGameUser[] users = new BumpGameUser[rowCount];

                for (int row = 0; row <= rowCount - 1; row++)
                {
                    dataReader.Read();
                    users.SetValue(new BumpGameUser()
                    {
                        ID = dataReader.GetInt64(0), Name = dataReader.GetString(1), FirstBump = dataReader.GetDateTime(2), LastBump = dataReader.GetDateTime(3), Points = dataReader.GetInt32(4)
                    }, row);
                }
                dataReader.Close();
                return(users);
            }

            else
            {
                dataReader.Close();
                return(null);
            }
        }