Ejemplo n.º 1
0
        public static bool Add(Account a, Order o)
        {
            o.OrderTable   = new Table();
            o.OrderAccount = new Account();
            int tableid;

            Console.WriteLine("|| id table  ||      table name     ||     table status     ||");
            foreach (var item in tbl.display())
            {
                if (item.Status == 0)
                {
                    string stt = "empty";
                    Console.WriteLine("||{0,10}||{1,20}||{2,20}||", item.Table_Id, item.TableName, stt);
                }
                else if (item.Status == 1)
                {
                    string stt = "has some one";
                    Console.WriteLine("||{0,10}||{1,20}||{2,20}||", item.Table_Id, item.TableName, stt);
                }
            }
            while (true)
            {
                Console.WriteLine("Input table Id: ");
                tableid = Convert.ToInt32(Console.ReadLine());
                while (tableid == 0 || tableid > 36)
                {
                    Console.Write("Pre-enter: ");
                    try
                    {
                        tableid = Convert.ToInt32(Console.ReadLine());
                    }
                    catch (Exception)
                    {
                        // Console.WriteLine("error"+ e);
                        // Console.Clear();
                        Console.Write("");
                    }
                }
                var result = tbl.CheckTableById(tableid);

                if (result == true)
                {
                    t = (tbl.GetTableById(tableid));

                    break;
                }

                else
                {
                    Console.WriteLine("Cant find this table or table is not empty!!!");
                    continue;
                }
            }
            o.OrderTable.Table_Id     = tableid;
            o.OrderAccount.Account_Id = a.Account_Id;



            Console.WriteLine("|| item id  ||      Item name     ||     item price     ||");
            foreach (var item in itbl.display())
            {
                Console.WriteLine("||{0,10}||{1,20}||{2,20}||", item.ItemId, item.ItemName, item.ItemPrice);
            }

            while (true)
            {
                Console.WriteLine(" Input Item Id: ");
                int itemid;
                while (!int.TryParse(Console.ReadLine(), out itemid) && itemid < 100 && itemid > 0)
                {
                    Console.WriteLine("Invalid entry. Please enter a number.");
                }

                Console.WriteLine("Input quantity item: ");
                int quantity = Convert.ToInt32(Console.ReadLine());
                while (quantity <= 0 || quantity > 100)
                {
                    Console.WriteLine("Dont try to test my system :)!!");
                    Console.Write("Pre-enter: ");
                    try
                    {
                        quantity = Convert.ToInt32(Console.ReadLine());
                    }
                    catch (Exception)
                    {
                        // Console.WriteLine("error"+ e);
                        // Console.Clear();
                        Console.Write("");
                    }
                    //  obl.AddItemToOrder(itemid, quantity, o);
                }
                obl.AddItemToOrder(itemid, quantity, o);
                //it = itbl.GetItemById(itemid);
                Console.WriteLine("Do you want to continue Add Item? ");
                string choice2 = Console.ReadLine();
                if (choice2 == "Y" || choice2 == "y")
                {
                    continue;
                }
                else if (choice2 == "N" || choice2 == "n")
                {
                    break;
                }
            }
            Console.WriteLine("Do you want to create order: ");
            char choice3 = Convert.ToChar(Console.ReadLine());

            switch (choice3)
            {
            case 'y':
                Console.WriteLine("Create Order: " + (obl.CreateOrder(o) ? "completed!" : "not complete!"));
                o.ItemsList.Clear();
                Console.WriteLine("Order ID: " + o.OrderId);

                Console.WriteLine("Order Date: " + o.OrderDate);

                foreach (var item in o.ItemsList)
                {
                    Console.WriteLine("Item Name: " + item.ItemName + "  -  " + "Quantity: " + item.Amount + " pecie");
                }
                Console.WriteLine("Order By: " + a.StaffName);
                Console.Write("Press any key to back the menu: ");
                Console.ReadKey();
                break;

            case 'Y':
                Console.WriteLine("Create Order: " + (obl.CreateOrder(o) ? "completed!" : "not complete!"));
                foreach (var item in o.ItemsList)
                {
                    Console.WriteLine("Item Name: " + item.ItemName + "  -  " + "Quantity: " + item.Amount + " pecie");
                }
                Console.WriteLine("Order By: " + a.StaffName);
                Console.Write("Press any key to back the menu: ");
                Console.ReadKey();
                break;

            case 'n':
                Console.Write("Press any key to back the menu: ");
                Console.ReadKey();
                break;

            case 'N':
                Console.Write("Press any key to back the menu: ");
                Console.ReadKey();
                break;

            default:
                Console.Write("Press any key to back the menu: ");
                Console.ReadKey();
                break;
            }
            return(true);
        }