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

            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();

                string sql;

                int id_ses = 0;

                MySqlCommand comm = null;

                MySqlDataReader reader = null;

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

                sql = "SELECT id FROM seasons WHERE name='"+season+"'";

                comm = new MySqlCommand(sql, conn);

                reader = comm.ExecuteReader();

                while (reader.Read())

                {

                    if (reader["name"].ToString().Equals(season))

                    {

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

                    }

                }

                reader.Close();

                conn.Close();

                return id_ses;

            }

            catch (MySqlException exp)

            {

                conn.Close();

                return 0;

            }

        }

        public static void addRatingPPL(string UserName, int value, int season,int game)

        {

            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();

                string sql;

                int id_user = 0;

                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())

                {

                    if (reader["name"].ToString() == UserName)

                    {

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

                    }

                }

                reader.Close();

                if (id_user != 0)

                {

                    sql = "INSERT INTO ratingppl(user,season,game,rating) VALUES ("+id_user+","+season+","+game+","+value+");";

                    comm = new MySqlCommand(sql, conn);

                    comm.ExecuteNonQuery();

                    conn.Close();

                }

                else

                {

                    conn.Close();

                }

            }

            catch (MySqlException exp)

            {

                conn.Close();

            }

        }

        public static float[] getReputation(string UserName)

        {

            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 + "");