Пример #1
0
        // Thêm giỏ hàng
        public void Add(Cart cart)
        {
            listcart.Listcart.Add(cart);
            string fullpath = $@"{path}\{filename}";

            ReadorWriteFile <ListCart> .WriteData(fullpath, listcart);
        }
Пример #2
0
        public ListCart ReadFile()
        {
            string fullpath = $@"{path}\{filename}";

            ReadorWriteFile <ListCart> .ReadData(fullpath, ref listcart);

            return(listcart);
        }
Пример #3
0
// In bills
        public void PrintBill(Cart cart)
        {
            string billname = $"{DateTime.Now.ToString("ddMMyyyyhhmm")}_table_{cart.CartId}";

            ReadorWriteFile <Cart> .WriteData($@"{path}\{billname}", cart);

            string fulllink = $@"{path}\{filename}";

            ReadorWriteFile <ListCart> .WriteData(fulllink, listcart);
        }
Пример #4
0
        private static void UpdateCart()
        {
            Console.Clear();
            try
            {
                Console.WriteLine("Enter id of cart you want to add: ");
                int  id    = int.Parse(Console.ReadLine());
                Cart _cart = admin.Check(id);

                if (_cart != null)
                {
                    Console.WriteLine("Enter product's name: ");
                    string name = Console.ReadLine();
                    int    pos  = admin.Checkpro(id, name);
                    if (_cart.Status == 1 && pos == -1)
                    {
                        do
                        {
                            Console.WriteLine("Enter Price:");
                            int price = (int)uint.Parse(Console.ReadLine());
                            Console.WriteLine("Enter Count:");
                            int     count   = (int)uint.Parse(Console.ReadLine());
                            Product product = new Product()
                            {
                                name  = name,
                                price = price,
                                count = count,
                            };
                            _cart.products.Add(product);
                            int ind = admin.listcart.Listcart.IndexOf(_cart);
                            admin.listcart.Listcart[ind].products = _cart.products;
                            Console.Clear();
                            Console.WriteLine(_cart.ToString());
                            Console.WriteLine("Successfully");
                            Console.Write("Do you want to add more? y/n:  ");
                        } while (Console.ReadLine().ToLower() == "y");
                    }
                    else if (_cart.Status == 1 && pos != -1)
                    {
                        Console.WriteLine("This item already exists!! Enter the amount to add: ");
                        int count = (int)uint.Parse(Console.ReadLine());
                        _cart.products[pos].count += count;
                        string fulllink = $@"{path}\{filename}";
                        ReadorWriteFile <ListCart> .WriteData(fulllink, admin.listcart);

                        Console.WriteLine("Succesfully");
                    }
                    else
                    {
                        Console.WriteLine(_cart.ToString());
                        Console.WriteLine("This table has already been paid or cancel!");
                    }
                }
                else
                {
                    Console.WriteLine("Not found!");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"{e.GetType()}, {e.Message}");
                UpdateCart();
            }
        }