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

                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 reputation(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 void getReportOfTeam(GridView report, string team, string season)

        {

            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

            {

                string table_team_stats = season+"_teamstats";

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

                conn = new MySqlConnection(connectionString);

                conn.Open();

                string sql;

                MySqlCommand comm = null;

                MySqlDataReader reader = null;

                MySqlDataAdapter da = null;

                DataTable dt = new DataTable();

                int position = 0;

                //ВЫБИРАЕМ СТРОКУ ИЗ ТАБЛИЦЫ

                sql = "select teams.id as POS, teams.name as TEAM,sum(" + table_team_stats + ".gp) as G,sum(" + table_team_stats + ".w) as W,sum(" + table_team_stats + ".w_ot) as WOT,sum(" + table_team_stats + ".w_so) as WSO,sum(" + table_team_stats + ".l_so) as LSO,sum(" + table_team_stats + ".l_ot) as LOT,sum(" + table_team_stats + ".l) as L,sum(" + table_team_stats + ".gf) as GF, sum(" + table_team_stats + ".ga) as GA,(sum(" + table_team_stats + ".gf)-sum(" + table_team_stats + ".ga)) as GD,((sum(" + table_team_stats + ".w)*(select tournaments.w from tournaments where id = (select conferences.league from conferences inner join divisions on divisions.conference = conferences.id inner join teams on divisions.id=teams.division  inner join " + table_team_stats + " on teams.id = " + table_team_stats + ".team group by conferences.league)))+(sum(" + table_team_stats + ".w_ot)*(select tournaments.w_ot from tournaments where id = (select conferences.league from conferences inner join divisions on divisions.conference = conferences.id inner join teams on divisions.id=teams.division  inner join " + table_team_stats + " on teams.id = " + table_team_stats + ".team group by conferences.league)))+(sum(" + table_team_stats + ".w_so)*(select tournaments.w_so from tournaments where id = (select conferences.league from conferences inner join divisions on divisions.conference = conferences.id inner join teams on divisions.id=teams.division  inner join " + table_team_stats + " on teams.id = " + table_team_stats + ".team group by conferences.league)))+(sum(" + table_team_stats + ".l_so)*(select tournaments.l_so from tournaments where id = (select conferences.league from conferences inner join divisions on divisions.conference = conferences.id inner join teams on divisions.id=teams.division  inner join " + table_team_stats + " on teams.id = " + table_team_stats + ".team group by conferences.league)))+(sum(" + table_team_stats + ".l_ot)*(select tournaments.l_ot from tournaments where id = (select conferences.league from conferences inner join divisions on divisions.conference = conferences.id inner join teams on divisions.id=teams.division  inner join " + table_team_stats + " on teams.id = " + table_team_stats + ".team group by conferences.league)))+(sum(" + table_team_stats + ".l)*(select tournaments.l from tournaments where id = (select conferences.league from conferences inner join divisions on divisions.conference = conferences.id inner join teams on divisions.id=teams.division inner join " + table_team_stats + " on teams.id = " + table_team_stats + ".team group by conferences.league)))) as P FROM " + table_team_stats + " inner join teams on teams.id = " + table_team_stats + ".team group by " + table_team_stats + ".team order by p DESC;";