// Thêm giỏ hàng public void Add(Cart cart) { listcart.Listcart.Add(cart); string fullpath = $@"{path}\{filename}"; ReadorWriteFile <ListCart> .WriteData(fullpath, listcart); }
public ListCart ReadFile() { string fullpath = $@"{path}\{filename}"; ReadorWriteFile <ListCart> .ReadData(fullpath, ref listcart); return(listcart); }
// 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); }
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(); } }