// Lấy ra và hiển thị các mặt hàng. public void ListItem() { Item_BL item = new Item_BL(); Console.WriteLine(); foreach (var Item in item.GetItems()) { string format = string.Format($"{Item.ItemId,1}. {Item.ItemName,15} {Item.Price,17} {Item.Amount,12} \n"); Console.WriteLine(format); } Console.WriteLine("--------------------------------------------------------------------------------------------"); Console.WriteLine($""); Console.WriteLine("--------------------------------------------------------------------------------------------"); Console.WriteLine("1. Mua hàng."); Console.WriteLine("\n2. Trở về menu chính."); Console.WriteLine("--------------------------------------------------------------------------------------------"); Console.Write("#Chọn : "); int number; while (true) { bool isINT = Int32.TryParse(Console.ReadLine(), out number); if (!isINT) { Console.WriteLine("Giá trị sai vui lòng nhập lại"); Console.Write("#Chọn : "); } else if (number < 0 || number > 2) { Console.WriteLine("Giá trị sai vui lòng nhập lại 1 - 2. "); Console.Write("#Chọn : "); } else { break; } } switch (number) { // case 1: // Shopping ticket = new Shopping (); // ticket.OrderItem(); // break; case 2: ShopInterface shop = new ShopInterface(); shop.Shop(); break; // // } // Console.WriteLine (); } }
public static void Order(Customer c) { string choice1 = ""; OrderBL orderbl = new OrderBL(); Orders o = new Orders(); List <Items> lito = new List <Items>(); CategoryBL cbl = new CategoryBL(); List <Category> lc = new List <Category>(); lc = cbl.GetCategory(); Console.WriteLine("___________________________________________"); Console.WriteLine("|----------- Danh Mục Sản Phẩm -----------|"); Console.WriteLine("|-----------------------------------------|"); foreach (var item in lc) { Console.WriteLine("|" + item.CategoryID + " | " + item.CategoryName); } int choice; do { Console.Write("-chọn: "); choice = Convert.ToInt32(Console.ReadLine()); } while ((choice < 1) || (choice > lc.Count)); Item_BL ibl = new Item_BL(); List <Items> lit = new List <Items>(); lit = ibl.getItemByCategoryId(choice); while (true) { Console.Clear(); Console.WriteLine("___________________________________________________________________________________________________________"); Console.WriteLine("|========================================== Sản Phẩm ======================================================|"); Console.WriteLine("|__________________________________________________________________________________________________________|"); Console.WriteLine("|ID | Tên Sản Phẩm | Giá Sản Phẩm | Số Lượng |"); foreach (var item in lit) { Console.WriteLine("|{0,-3} | {1,-51} | {2,21} VND| {3,-14} ", item.ItemId, item.ItemName, item.ItemPrice, item.ItemAmount); Console.WriteLine("|----------------------------------------------------------------------------------------------------------|"); } Console.Write("1.Chọn ID sản phẩm bạn muốn mua :"); int product; Items io = null; while (true) { product = Validate.InputInt(Console.ReadLine()); int count = 0; foreach (var iteml in lit) { if (product == iteml.ItemId) { count++; } } if (count == 0) { Console.Write("Không có sản phẩm này trong danh mục bạn chọn , mời nhập lại: "); continue; } else { break; } } io = ibl.getItemById(product); int quantity; Console.Write(" Nhập số lượng: "); while (true) { quantity = Validate.InputInt(Console.ReadLine()); if (quantity <= io.ItemAmount) { break; } Console.Write("Số lượng không đúng, mời nhập lại: "); } io.ItemAmount = quantity; int dem = 0; int index = 0; foreach (var item in lito) { if (item.ItemId == product) { dem++; break; } index++; } if (io.ItemAmount != 0 && dem == 0) { lito.Add(io); } else if (dem > 0) { lito[index].ItemAmount += quantity; } while (true) { Console.WriteLine("Bạn có muốn tiếp tục thêm sản phẩm không? (C/K) "); choice1 = Console.ReadLine().ToUpper(); switch (choice1) { case "C": Console.Clear(); break; case "K": Console.Clear(); break; default: continue; } break; } if (choice1 == "C") { Console.Clear(); continue; } else if (choice1 == "K") { Console.Clear(); break; } } // listitem = lito; Console.WriteLine("____________________________________________________________________________________________________"); Console.WriteLine("|-----------------------------------------Đơn Hàng--------------------------------------------------|"); Console.WriteLine("| Tên Sản Phẩm | Số Lượng | Giá Sản Phẩm | Thành Tiền |"); Console.WriteLine("----------------------------------------------------------------------------------------------------"); decimal totalprice = 0; // Console.WriteLine(o.listItems.Count); foreach (var item in lito) { decimal a = 0; a = item.ItemPrice * item.ItemAmount; totalprice += a; Console.WriteLine("|{0,-48}|{1,-14}|{2,15} VND|{3,11} VND|", item.ItemName, item.ItemAmount, pricevalid(item.ItemPrice), a); } Console.WriteLine("_____________________________________________________________________________________________________"); Console.WriteLine("Tổng tiền: {0} VND", pricevalid(totalprice)); while (true) { Console.Write("Bạn có muốn thanh toán đơn hàng? (C/K)?"); choice1 = Console.ReadLine().ToUpper(); switch (choice1) { case "C": break; case "K": Console.Clear(); return; default: continue; } break; } Console.Write("Nhập số tiền khách trả(đồng): "); decimal cusmoney; while (true) { try { cusmoney = Convert.ToDecimal(Console.ReadLine()); if (cusmoney < 0) { Console.Write("Số tiền trả không thể nhỏ hơn 0, mời bạn nhập lại(đồng): "); continue; } else if (cusmoney > 999999999) { Console.Write("Số tiền quá lớn, mời nhập lại(đồng): "); continue; } else if (cusmoney < totalprice) { Console.Write("Số tiền trả không đủ, mời nhập lại(đồng): "); continue; } } catch (System.Exception) { Console.Write("Dữ liệu nhập vào không đúng hoặc số tiền quá lớn, mời bạn nhập lại(đồng): "); continue; } break; } if ((cusmoney - totalprice) > 0) { Console.WriteLine("Tiền trả lại: {0} VND", pricevalid(cusmoney - totalprice)); } Customer_Bl cbl1 = new Customer_Bl(); o.listItems = lito; // Console.WriteLine(o.listItems.ToString()); o.customer = c; o.Status = 1; Console.WriteLine(" Tạo Order " + (orderbl.AddOrder(o) ? "Hoàn tất!" : "Không hoàn tất!") + " Ấn phím bất kì để thoát!"); // listitem = o.listItems; Console.ReadKey(); Console.Clear(); // List<Items> newlit = ibl.GetItemsByOrderId(); }
public void DisplayAllItems(Customers Cus) { Console.Clear(); Console.WriteLine("================================================================================================"); Console.WriteLine("------------------------------------- DANH SÁCH SẢN PHẨM ---------------------------------------"); Console.WriteLine("================================================================================================\n"); Item_BL IBL = new Item_BL(); List <Items> items = IBL.GetAllItems(); table = new ConsoleTable("Mã sản phẩm", "Tên sản phẩm", "Hãng", "Thuộc tính", "Giá sản phẩm"); foreach (Items i in items) { table.AddRow(i.Produce_Code, i.Item_Name, i.Trademark, i.Attribute, U.FormatMoney(i.Item_Price)); } table.Write(Format.Alternative); string[] choice1 = { "Xem chi tiết sản phẩm", "Thêm vào giỏ hàng", "Quay về trang chính" }; int number1 = Product.SubMenu(null, choice1); switch (number1) { case 1: Console.Write("Chọn mã sản phẩm: "); int showdetal = input(Console.ReadLine()); while (IBL.GetItemByProduceCode(showdetal) == null) { string a; Console.WriteLine("Mã sản phẩm không tồn tại!"); Console.Write("Bạn có muốn nhập lại mã sản phẩm không ? (Y/N): "); a = Console.ReadLine().ToUpper(); while (true) { if (a != "Y" && a != "N") { Console.Write("Bạn chỉ được nhập (Y/N): "); a = Console.ReadLine().ToUpper(); continue; } break; } if (a == "Y" || a == "y") { Console.Write("\nChọn mã sản phẩm: "); showdetal = input(Console.ReadLine()); } else { DisplayProduct(Cus); } } DisplayItemDetails(showdetal, Cus); break; case 2: Console.Write("Chọn mã sản phẩm: "); int pc = input(Console.ReadLine()); while (IBL.GetItemByProduceCode(pc) == null) { string a; Console.WriteLine("Mã sản phẩm không tồn tại!"); Console.Write("Bạn có muốn nhập lại mã sản phẩm không ? (Y/N): "); a = Console.ReadLine().ToUpper(); while (true) { if (a != "Y" && a != "N") { Console.Write("Bạn chỉ được nhập (Y/N): "); a = Console.ReadLine().ToUpper(); continue; } break; } if (a == "Y" || a == "y") { Console.Write("\nChọn mã sản phẩm: "); pc = input(Console.ReadLine()); } else { DisplayProduct(Cus); } } Items item = IBL.GetItemByProduceCode(pc); InputQuantity(Cus, item, pc); break; case 3: U.UserMenu(Cus); break; } }
public void DisplayAttribute(Customers Cus) { Console.Clear(); Item_BL IBL = new Item_BL(); User U = new User(); string[] choice = { "Không dây", "Thể thao", "In-Ear", "Gaming", "Earbud", "Trở về danh sách sản phẩm" }; int number = SubMenu("Danh sách sản phẩm theo thuộc tính", choice); List <Items> items = new List <Items>(); string ab = null; switch (number) { case 1: items = IBL.GetItemByAttribute("Không dây"); ab = "Không dây"; break; case 2: items = IBL.GetItemByAttribute("Thể thao"); ab = "Thể thao"; break; case 3: items = IBL.GetItemByAttribute("In-Ear"); ab = "In-Ear"; break; case 4: items = IBL.GetItemByAttribute("Gaming"); ab = "Gaming"; break; case 5: items = IBL.GetItemByAttribute("Earbud"); ab = "Earbud"; break; case 6: DisplayProduct(Cus); break; } Console.Clear(); table = new ConsoleTable("Mã sản phẩm", "Tên sản phẩm", "Hãng", "Thuộc tính", "Giá sản phẩm"); foreach (Items i in items) { table.AddRow(i.Produce_Code, i.Item_Name, i.Trademark, i.Attribute, U.FormatMoney(i.Item_Price)); } table.Write(Format.Alternative); string[] choice1 = { "Xem chi tiết sản phẩm", "Thêm vào giỏ hàng", "Quay về trang chính" }; int number1 = Product.SubMenu(null, choice1); switch (number1) { case 1: Console.Write("Chọn mã sản phẩm: "); int showdetal = input(Console.ReadLine()); while (IBL.GetItemByProduceCodeAndAttribute(showdetal, ab) == null) { string a; Console.WriteLine("Mã sản phẩm không tồn tại!"); Console.Write("Bạn có muốn nhập lại mã sản phẩm không ? (Y/N): "); a = Console.ReadLine().ToUpper(); while (true) { if (a != "Y" && a != "N") { Console.Write("Bạn chỉ được nhập (Y/N): "); a = Console.ReadLine().ToUpper(); continue; } break; } if (a == "Y" || a == "y") { Console.Write("\nChọn mã sản phẩm: "); showdetal = input(Console.ReadLine()); } else { DisplayProduct(Cus); } } DisplayItemDetails(showdetal, Cus); break; case 2: Console.Write("Chọn mã sản phẩm: "); int pc = input(Console.ReadLine()); while (IBL.GetItemByProduceCodeAndAttribute(pc, ab) == null) { string a; Console.WriteLine("Mã sản phẩm không tồn tại!"); Console.Write("Bạn có muốn nhập lại mã sản phẩm không ? (Y/N): "); a = Console.ReadLine().ToUpper(); while (true) { if (a != "Y" && a != "N") { Console.Write("Bạn chỉ được nhập (Y/N): "); a = Console.ReadLine().ToUpper(); continue; } break; } if (a == "Y" || a == "y") { Console.Write("\nChọn mã sản phẩm: "); pc = input(Console.ReadLine()); } else { DisplayProduct(Cus); } } Items item = IBL.GetItemByProduceCodeAndAttribute(pc, ab); InputQuantity(Cus, item, pc); break; case 3: U.UserMenu(Cus); break; } }
public void DisplayTradeMark(Customers Cus) { Console.Clear(); string[] choice = { "Urbanista", "MEE", "RHA AUDIO", "jabees", "SONY", "SOMIC", "Sennheiser", "Audio Technica", "Skullcandy", "Ausdom", "1More", "Trở về danh sách sản phẩm", }; int number = SubMenu("Danh sách sản phẩm theo hãng", choice); Item_BL IBL = new Item_BL(); List <Items> items = new List <Items>(); string trade = null; switch (number) { case 1: items = IBL.GetItemByTradeMark("Urbanista"); trade = "Urbanista"; break; case 2: items = IBL.GetItemByTradeMark("MEE"); trade = "MEE"; break; case 3: items = IBL.GetItemByTradeMark("RHA AUDIO"); trade = "RHA AUDIO"; break; case 4: items = IBL.GetItemByTradeMark("jabees"); trade = "jabees"; break; case 5: items = IBL.GetItemByTradeMark("SONY"); trade = "SONY"; break; case 6: items = IBL.GetItemByTradeMark("SOMIC"); trade = "SOMIC"; break; case 7: items = IBL.GetItemByTradeMark("Sennheiser"); trade = "Sennheiser"; break; case 8: items = IBL.GetItemByTradeMark("Audio Technica"); trade = "Audio Technica"; break; case 9: items = IBL.GetItemByTradeMark("Skullcandy"); trade = "Skullcandy"; break; case 10: items = IBL.GetItemByTradeMark("Ausdom"); trade = "Ausdom"; break; case 11: items = IBL.GetItemByTradeMark("1More"); trade = "1More"; break; case 12: DisplayProduct(Cus); break; } Console.Clear(); table = new ConsoleTable("Mã sản phẩm", "Tên sản phẩm", "Hãng", "Thuộc tính", "Giá sản phẩm"); foreach (Items i in items) { table.AddRow(i.Produce_Code, i.Item_Name, i.Trademark, i.Attribute, U.FormatMoney(i.Item_Price)); } table.Write(Format.Alternative); string[] choice1 = { "Xem chi tiết sản phẩm", "Thêm vào giỏ hàng", "Quay về trang chính" }; int number1 = Product.SubMenu(null, choice1); switch (number1) { case 1: Console.Write("Chọn mã sản phẩm: "); int showdetal = input(Console.ReadLine()); while (IBL.GetItemByProduceCodeAndTradeMark(showdetal, trade) == null) { string a; Console.WriteLine("Mã sản phẩm không tồn tại!"); Console.Write("Bạn có muốn nhập lại mã sản phẩm không ? (Y/N): "); a = Console.ReadLine().ToUpper(); while (true) { if (a != "Y" && a != "N") { Console.Write("Bạn chỉ được nhập (Y/N): "); a = Console.ReadLine().ToUpper(); continue; } break; } if (a == "Y" || a == "y") { Console.Write("\nChọn mã sản phẩm: "); showdetal = input(Console.ReadLine()); } else { DisplayProduct(Cus); } } DisplayItemDetails(showdetal, Cus); break; case 2: Console.Write("Chọn mã sản phẩm: "); int pc = input(Console.ReadLine()); while (IBL.GetItemByProduceCodeAndTradeMark(pc, trade) == null) { string a; Console.WriteLine("Mã sản phẩm không tồn tại!"); Console.Write("Bạn có muốn nhập lại mã sản phẩm không ? (Y/N): "); a = Console.ReadLine().ToUpper(); while (true) { if (a != "Y" && a != "N") { Console.Write("Bạn chỉ được nhập (Y/N): "); a = Console.ReadLine().ToUpper(); continue; } break; } if (a == "Y" || a == "y") { Console.Write("\nChọn mã sản phẩm: "); pc = input(Console.ReadLine()); } else { DisplayProduct(Cus); } } Items item = IBL.GetItemByProduceCodeAndTradeMark(pc, trade); InputQuantity(Cus, item, pc); break; case 3: U.UserMenu(Cus); break; } }
public void DisplayItemDetails(int id, Customers Cus) { Item_BL IBL = new Item_BL(); Items item = IBL.GetItemByProduceCode(id); Console.Clear(); Console.WriteLine("=================================================================================="); Console.WriteLine("-------------------------------- CHI TIẾT SẢN PHẨM -------------------------------\n"); table = new ConsoleTable("Mã sản phẩm", "Tên sản phẩm", "Hãng", "Thuộc tính", "Giá sản phẩm"); table.AddRow(item.Produce_Code, item.Item_Name, item.Trademark, item.Attribute, U.FormatMoney(item.Item_Price)); table.Write(Format.Alternative); Console.WriteLine("Mô tả sản phẩm : {0}\n", item.Item_Description); while (true) { string[] choice = { "Thêm vào giỏ hàng", "Trở về danh sách sản phẩm", "Trở về trang chính" }; int number = SubMenu(null, choice); switch (number) { case 1: InputQuantity(Cus, item, id); break; case 2: DisplayProduct(Cus); break; case 3: if (Cus.User_Name != null && Cus.User_Password != null) { U.UserMenu(Cus); } else { Console.Clear(); Menu m = new Menu(); Product Product = new Product(); string[] choice1 = { "Danh sách sản phẩm", "Xem giỏ hàng", "Đăng nhập", "Thoát" }; int number1 = Product.SubMenu($"Chào mừng đến với cửa hàng", choice1); switch (number1) { case 1: Product.DisplayProduct(Cus); break; case 2: U.DisplayCart(Cus); break; case 3: U.ScreenLogin(); break; case 4: Environment.Exit(0); break; } } break; } } }
public void CreateOrder(Customers Cus, List <Items> ListItems, int total) { Console.Clear(); if (Cus.User_Name == null && Cus.User_Password == null) { Console.Write("Bạn cần đăng nhập để thanh toán!\nBạn có muốn đăng nhập không ? (Y/N): "); string select = Console.ReadLine().ToUpper(); while (true) { if (select != "Y" && select != "N") { Console.Write("Bạn có muốn đăng nhập không? (Y/N): "); select = Console.ReadLine().ToUpper(); continue; } break; } if (select == "Y" || select == "y") { LoginToPay(Cus, ListItems, total); } else { DisplayCart(Cus); } } else { if (File.Exists($"CartOf{Cus.User_Name}.dat")) { List <Items> Items = new List <Items>(); FileStream fs = new FileStream($"CartOf{Cus.User_Name}.dat", FileMode.Open, FileAccess.ReadWrite); BinaryReader br = new BinaryReader(fs); string str = br.ReadString(); Items = JsonConvert.DeserializeObject <List <Items> >(str); fs.Close(); br.Close(); Console.WriteLine("================================================================================================================================"); Console.WriteLine($" Giỏ hàng"); Console.WriteLine("================================================================================================================================\n"); Console.WriteLine("+-------------+-----------------------------------+----------------+------------+-----------------+----------+------------------+"); Console.WriteLine("| {0,-12}| {1,-24}| {2,-10}| {3,-11}| {4,-6} | {5,-9}| {6,-17}|", "Mã sản phẩm", "Tên sản phẩm", "Hãng", "Thuộc tính", "Đơn giá", "Số lượng", "Thành tiền"); Console.WriteLine("+-------------+-----------------------------------+----------------+------------+-----------------+----------+------------------+"); foreach (Items i in Items) { Console.WriteLine("| {0,-7}| {1,-34}| {2,-15}| {3,-11}| {4,-16}| {5,-6}| {6,-16}|", i.Produce_Code, i.Item_Name, i.Trademark, i.Attribute, FormatMoney(i.Item_Price), i.Quantity, FormatMoney(i.Item_Price * i.Quantity)); Console.WriteLine("+-------------+-----------------------------------+----------------+------------+-----------------+----------+------------------+"); } Console.WriteLine("| Tổng tiền | {0,-15} |", FormatMoney(total)); Console.WriteLine("+-------------------------------------------------------------------------------------------------------------------------------+"); } else { Console.WriteLine("Giỏ hàng trống!"); Console.Write("\nNhấn phím bất kỳ để quay lại!"); Console.ReadKey(); UserMenu(Cus); } bool check = true; Order order = new Order(); Order_BL OBL = new Order_BL(); Console.Write("Nhập địa chỉ giao hàng: "); string address_Shipping = Console.ReadLine().Trim(); if (address_Shipping.Length == 0) { order.Address_Shipping = Cus.Cus_Address; } else { order.Address_Shipping = address_Shipping; } Console.WriteLine("Địa chỉ giao hàng: {0}", order.Address_Shipping); order.Order_Date = DateTime.Now; order.Status = "Không thành công"; order.Customer = Cus; Item_BL IBL = new Item_BL(); order.ItemsList = new List <Items>(); order.ItemsList = ListItems; check = OBL.CreateOrder(order); if (check == true) { Console.WriteLine("Đặt hàng thành công!"); while (true) { string[] a = { "Thanh toán", "Hủy đơn hàng" }; int select = Product.SubMenu(null, a); switch (select) { case 1: Pay(Cus, order, total); break; case 2: try { check = OBL.DeleteOrder(order.Order_ID); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } DisplayCart(Cus); break; } } } else { Console.WriteLine("\n Đặt hàng thất bại!\n"); Console.WriteLine("Nhấn phím bất kỳ để quay lại trang chính!"); Console.ReadKey(); UserMenu(Cus); } } }