Example #1
0
 public void DeleteOrder(int?id)
 {
     Assert.True(OBL.DeleteOrder(id));
 }
Example #2
0
        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);
                }
            }
        }