Beispiel #1
0
        // Function for the reverse alphabetical display
        public void RestaurantReverseAlphabeticalStart()
        {
            string cs = @"server=127.0.0.1;userid=dbremoteuser;password=password;database=SampleRestaurantDatabase;port=8889";

            MySqlConnection conn = null;

            try
            {
                //create new lists to store the values
                List <string>  restaurantNames = new List <string>();
                List <decimal> overallRating   = new List <decimal>();

                conn = new MySqlConnection(cs);
                conn.Open();

                //append the returned list from the private methods into these lists
                restaurantNames.AddRange(GetRestaurantNameDESC(conn));
                overallRating.AddRange(GetOverallRatingDESC(conn));

                //reverse the values of the lists to accomodate reverse alphabetical
                restaurantNames.Reverse();
                overallRating.Reverse();

                for (int i = 0; i < 100; i++)
                {
                    decimal rating     = overallRating[i];
                    string  restNumber = (100 - i) + ". ";


                    Console.WriteLine("=============================================" +
                                      "=========================");

                    Console.Write("{0, 5}", restNumber);
                    Console.Write("{0, 5}", restaurantNames[i]);
                    Console.Write("{0, 10}", "Rating: ");
                    Console.WriteLine(DrawStars.DrawStarsStart(rating));


                    if (i == 99)
                    {
                        Console.WriteLine("=============================================" +
                                          "=========================");
                    }
                }

                Console.WriteLine("Please enter return key to go back to menu...");
            }
            catch (MySqlException error)
            {
                Console.WriteLine("Error: {0}", error.ToString());
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
        public static void ShowUnratedStart()
        {
            string cs = @"server=127.0.0.1;userid=dbremoteuser;password=password;database=SampleRestaurantDatabase;port=8889";

            MySqlConnection conn = null;

            try
            {
                conn = new MySqlConnection(cs);
                conn.Open();

                decimal overallRating = 0.00m;

                //create a new list that stores the overall rating
                List <decimal> overallRatingList = new List <decimal>();

                //loops and adds the overall rating to the list
                for (int i = 0; i < 3; i++)
                {
                    string stm = "SELECT OverallRating " +
                                 "FROM RestaurantProfiles " +
                                 "WHERE OverallRating IS NULL OR " +
                                 "OverallRating BETWEEN 0 AND 0.49 " +
                                 "ORDER BY OverallRating ASC";

                    MySqlCommand cmd = new MySqlCommand(stm, conn);

                    MySqlDataReader rdr1 = cmd.ExecuteReader();

                    while (rdr1.Read())
                    {
                        decimal.TryParse(rdr1["OverallRating"].ToString(),
                                         out overallRating);

                        decimal roundedRating = Math.Round(overallRating, 0,
                                                           MidpointRounding.AwayFromZero);

                        overallRatingList.Add(roundedRating);
                    }
                    rdr1.Close(); //close the reader
                }

                //create a new list that stores the names of each restaurant
                List <string> restaurantNameList = new List <string>();

                for (int j = 0; j < 3; j++)
                {
                    //select the restaurant name based on overall rating ASC
                    string stm2 = "SELECT RestaurantName " +
                                  "FROM RestaurantProfiles " +
                                  "WHERE OverallRating IS NULL OR " +
                                  "OverallRating BETWEEN 0 AND 0.49 " +
                                  "ORDER BY OverallRating ASC";

                    MySqlCommand cmd2 = new MySqlCommand(stm2, conn);


                    MySqlDataReader rdr2 = cmd2.ExecuteReader();

                    while (rdr2.Read())
                    {
                        restaurantNameList.Add(rdr2["RestaurantName"].ToString());
                    }
                    rdr2.Close(); //close the reader
                }

                for (int i = 0; i < 3; i++)
                {
                    decimal rating     = overallRatingList[i];
                    string  restNumber = (i + 1) + ". ";


                    Console.WriteLine("=============================================" +
                                      "=========================");

                    Console.Write("{0, 5}", restNumber);
                    Console.Write("{0, 5}", restaurantNameList[i]);
                    Console.Write("{0, 10}", "Rating: ");
                    Console.WriteLine(DrawStars.DrawStarsStart(rating));


                    if (i == 2)
                    {
                        Console.WriteLine("=============================================" +
                                          "=========================");
                    }
                }
                Console.WriteLine("Please enter return key to go back to menu...");
            }
            catch (MySqlException error)
            {
                Console.WriteLine("Error: {0}", error.ToString());
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }