Создание веб-приложения, сочетающего в себе проектирование и создание баз данных, работу со сторонними форматами данных, программирование в NET и веб-разработку, страница 72

            MySqlConnection conn = null;

            try

            {

                //ОБЪЯВЛЕНИЕ

                conn = new MySqlConnection(connectionString);

                conn.Open();

                int id_user = 0;

                int position = 0;

                float[] positionandreputation = null;

                string sql;

                MySqlCommand comm = null;

                MySqlDataReader reader = null;

                //ПРОВЕРЯЕМ, ЕСТЬ ЛИ УЖЕ ТАКОЙ ЮЗЕР

                sql = "SELECT id from auth_user WHERE name='" + UserName + "'";

                comm = new MySqlCommand(sql, conn);

                reader = comm.ExecuteReader();

                while (reader.Read())

                {

                    id_user = Convert.ToInt32(reader["id"].ToString());

                }

                reader.Close();

                sql = "select sum(reputation) as SUM,user from reputation group by user order by SUM DESC";

                comm = new MySqlCommand(sql, conn);

                reader = comm.ExecuteReader();

                while (reader.Read())

                {

                    position++;

                    if (Convert.ToInt32(reader["user"].ToString()) == id_user)

                    {

                        positionandreputation = new float[2];

                        positionandreputation[0] = position;

                        positionandreputation[1] = Convert.ToInt32(reader["SUM"].ToString());

                    }

                }

                reader.Close();

                conn.Close();

                return positionandreputation;

            }

            catch (MySqlException exp)

            {

                conn.Close();

                return null;

            }

        }

        public static float[] getReputationFromTournament(string UserName, string tournament)

        {

            string database = "powerplay";

            string password_db = "admin";

            string user_db = "root";

            string server_db = "localhost";

            connectionString = ("server=" + server_db + "; user id=" + user_db + "; password=" + password_db + "; database=" + database + "");

            MySqlConnection conn = null;

            try

            {

                //ОБЪЯВЛЕНИЕ

                conn = new MySqlConnection(connectionString);

                conn.Open();

                int id_user = 0;

                int tour = 0;

                int position = 0;

                float[] positionandreputation = null;

                string sql;

                MySqlCommand comm = null;

                MySqlDataReader reader = null;

                //ПРОВЕРЯЕМ, ЕСТЬ ЛИ УЖЕ ТАКОЙ ЮЗЕР

                sql = "SELECT id from auth_user WHERE name='" + UserName + "'";

                comm = new MySqlCommand(sql, conn);

                reader = comm.ExecuteReader();

                while (reader.Read())

                {

                    id_user = Convert.ToInt32(reader["id"].ToString());

                }

                reader.Close();

                sql = "SELECT id from tournaments WHERE name='" + tournament + "'";

                comm = new MySqlCommand(sql, conn);

                reader = comm.ExecuteReader();

                while (reader.Read())

                {

                    tour = Convert.ToInt32(reader["id"].ToString());

                }

                reader.Close();

                sql = "select sum(reputation) as SUM,user from reputation inner join seasons on seasons.id = reputation.season inner join tournaments on tournaments.id = seasons.league and tournaments.id = " + tour + " group by user order by SUM DESC";

                comm = new MySqlCommand(sql, conn);