コード例 #1
0
        private static void TopTenRestaurants()
        {
            //Initiates a MySQL connection and executes a MySQL command to search for two columns in a table, where a join is included to obtain reference data from another table
            DataTable dt = new DataTable();

            _ = new Database(Program.cs);
            using (MySqlCommand cmd = new MySqlCommand("select rp.restaurantname,avg(rr.reviewscore) as average from restaurantprofiles rp join restaurantreviews rr on rp.id = rr.restaurantid where rr.reviewscore >= 70 group by rp.restaurantname desc limit 10", Database.con))
            {
                MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                da.Fill(dt);
                MySqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    if (!string.IsNullOrWhiteSpace(reader["average"].ToString()))
                    {
                        Console.Write(reader["restaurantname"].ToString() + " ");
                        BarGraphs.DrawGraph(reader["average"].ToString());
                        Console.Write(" Average: " + reader["average"].ToString() + "%");
                        Console.WriteLine();
                    }
                    else
                    {
                        Console.Write(reader["restaurantname"].ToString() + " ");
                        BarGraphs.DrawGraph(reader["average"].ToString());
                        Console.Write("Average: N/A");
                        Console.WriteLine();
                    }
                }
                Database.con.Close();
            }
        }
コード例 #2
0
        private static void DinnerSpinner()
        {
            //Initiates a MySQL connection and executes a MySQL command to search for two columns in a table, where a specific row is equal to the given value
            DataTable dt = new DataTable();

            _ = new Database(Program.cs);
            using (MySqlCommand cmd = new MySqlCommand("select rp.restaurantname,avg(rr.reviewscore) as average from restaurantprofiles rp join restaurantreviews rr on rp.id = rr.restaurantid group by rp.restaurantname order by rand() limit 1", Database.con))
            {
                MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                da.Fill(dt);
                MySqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    if (!string.IsNullOrWhiteSpace(reader["average"].ToString()))
                    {
                        Console.Write(reader["restaurantname"].ToString() + " ");
                        BarGraphs.DrawGraph(reader["average"].ToString());
                        Console.Write(" Average: " + reader["average"].ToString() + "%");
                        Console.WriteLine();
                    }
                    else
                    {
                        Console.Write(reader["restaurantname"].ToString() + " ");
                        BarGraphs.DrawGraph(reader["average"].ToString());
                        Console.Write("Average: N/A");
                        Console.WriteLine();
                    }
                }
                Database.con.Close();
            }
        }