Esempio n. 1
0
        public static void AddNewRating(PizzaRating pizzaRating)
        {
            StreamWriter streamWriter = new StreamWriter("pizzaRatings.txt", true);

            streamWriter.WriteLine(pizzaRating.Pizza + ", " + pizzaRating.Rating.ToString());
            streamWriter.Close();
        }
Esempio n. 2
0
        public static List <PizzaRating> GetRatings()
        {
            List <PizzaRating> ratings = new List <PizzaRating>();

            StreamReader streamReader = new StreamReader("pizzaRatings.txt");

            while (true)
            {
                string line = streamReader.ReadLine();
                if (line != null)
                {
                    PizzaRating pizzaRating = new PizzaRating()
                    {
                        Pizza  = line.Split(',')[0].Trim(),
                        Rating = Convert.ToDecimal(line.Split(',')[1].Trim()),
                    };
                    ratings.Add(pizzaRating);
                }
                else
                {
                    break;
                }
            }
            streamReader.Close();

            return(ratings);
        }
 private void btnAddRating_Click(object sender, EventArgs e)
 {
     if (cboPizza.SelectedItem != null)
     {
         PizzaRating pizzaRating = new PizzaRating()
         {
             Pizza  = cboPizza.SelectedItem.ToString(),
             Rating = numRating.Value
         };
         PizzaRatingService.AddNewRating(pizzaRating);
         ratingsDataGridView.DataSource = null;
         ratingsDataGridView.DataSource = PizzaRatingService.GetRatings();
         ratingsDataGridView.Refresh();
         MessageBox.Show("Rating is successfully added.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     else
     {
         MessageBox.Show("Pizza is not selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }