/// <summary>
        /// get a list of all the ordered pizzas
        /// </summary>
        /// <returns> List<OrderedPizza> </returns>
        public static List <OrderedPizza> GetAllOrderedPizzas()
        {
            List <OrderedPizza> pizzas = new List <OrderedPizza>();

            if (!File.Exists(filename))
            {
                Utils.CreateEmptyFile(filename);
            }
            using (StreamReader file = new StreamReader(filename))
            {
                string line;

                while ((line = file.ReadLine()) != null)
                {
                    List <String> data    = line.Split(',').ToList();
                    Pizza         pizza   = new Pizza(1, data[0], float.Parse(data[1]), float.Parse(data[2]));
                    OrderedPizza  ordered = new OrderedPizza(1, pizza, Convert.ToInt32(data[3]), bool.Parse(data[4]), bool.Parse(data[5]));
                    pizzas.Add(ordered);
                }
                file.Close();
            }
            return(pizzas);

            throw new NotImplementedException();
        }
Example #2
0
 private void ClearOrderFiles()
 {
     OrderedDrink.ClearFile();
     OrderedPizza.ClearFile();
     Order.ClearFile();
     ClearOrder();
 }
 // methods
 /// <summary>
 /// save pizza to the file
 /// </summary>
 /// <param name="pizza"> pizza object </param>
 /// <param name="quantity"> quantity of the pizza</param>
 /// <param name="isFilled"> is the pizza filled </param>
 /// <param name="isThick"> is the pizza thick</param>
 /// <returns></returns>
 public int AddToFile(Pizza pizza, int quantity, bool isFilled, bool isThick)
 {
     using (StreamWriter sw = File.AppendText(filename))
     {
         sw.WriteLine(string.Join(", ", OrderedPizza.PizzaOrderToCSV(pizza, quantity, isFilled, IsThick)));
         sw.Close();
     }
     return(1);
 }
Example #4
0
        private void ReloadPizzas()
        {
            orderedPizzasLbx.Items.Clear();
            List <OrderedPizza> pizzas = OrderedPizza.GetAllOrderedPizzas();

            foreach (OrderedPizza d in pizzas)
            {
                orderedPizzasLbx.Items.Add(d);
            }
        }
        /// <summary>
        /// Convert the order pizzas to cSV
        /// </summary>
        /// <returns> csv string</returns>
        private string PizzasToCSV()
        {
            string result = "PIZZAS";

            result += Environment.NewLine;
            foreach (OrderedPizza p in pizzas)
            {
                result += OrderedPizza.PizzaOrderToCSV(p.Pizza, p.Quantity, p.IsFilled, p.IsThick);
                result += Environment.NewLine;
            }
            return(result);
        }
        /// <summary>
        /// Get all orders from a file
        /// </summary>
        /// <param name="filename"> the name of the file </param>
        /// <returns></returns>
        public static Shop OrdersFromFile(string filename)
        {
            Shop s = null;

            try
            {
                if (!File.Exists(filename))
                {
                    Utils.CreateEmptyFile(filename);
                }
                using (StreamReader file = new StreamReader(filename))
                {
                    string shopName = file.ReadLine();
                    s = new Shop(shopName);

                    string       line;
                    List <Order> orders = new List <Order>();
                    while ((line = file.ReadLine()) != null)
                    {
                        if (line == "ORDER")
                        {
                            // get base information for the order
                            line = file.ReadLine();
                            List <String> data        = line.Split(',').ToList();
                            bool          IsCancelled = Convert.ToBoolean(data[0]);
                            DateTime      createdAt   = Convert.ToDateTime(data[1]);

                            Customer c = null;
                            if (data.Count == 4)
                            {
                                c = new Customer(1, data[2], data[3]);
                            }
                            else
                            {
                                c = new Customer(1, data[2]);
                            }
                            line = file.ReadLine();
                            if (line == "PIZZAS")
                            {
                                List <OrderedDrink> orderedDrinks = new List <OrderedDrink>();;
                                List <OrderedPizza> orderedPizzas = new List <OrderedPizza>();

                                while ((line = file.ReadLine()) != "DRINKS")
                                {
                                    List <String> pizzas = line.Split(',').ToList();
                                    Pizza         pizza  = new Pizza(1, pizzas[0], float.Parse(pizzas[1]), float.Parse(pizzas[2]));

                                    OrderedPizza p = new OrderedPizza(pizza, Convert.ToInt32(pizzas[3]), Convert.ToBoolean(pizzas[4]), Convert.ToBoolean(pizzas[5]));;
                                    orderedPizzas.Add(p);
                                }

                                while ((line = file.ReadLine()) != "ENDORDER" && line != "")
                                {
                                    List <String> drinks = line.Split(',').ToList();
                                    Drink         drink  = new Drink(1, drinks[0], float.Parse(drinks[1]));
                                    OrderedDrink  d      = new OrderedDrink(drink, Convert.ToInt32(drinks[2]));
                                    orderedDrinks.Add(d);
                                }
                                Order o = new Order(c, IsCancelled, createdAt, orderedPizzas, orderedDrinks, true);
                                orders.Add(o);
                            }
                        }
                    }
                    file.Close();
                    foreach (Order o in orders)
                    {
                        s.AddOrder(o);
                    }
                }
            } catch (Exception)
            {
                if (filename != null)
                {
                    using (File.Create(filename));
                }
            }
            return(s);
        }