Beispiel #1
0
 public MainMenu(MasterItem i_MasterItem)
 {
     RootItem = i_MasterItem;
 }
Beispiel #2
0
        private void PrintItems(MasterItem i_MasterItem, bool i_IsThisMainMenu)
        {
            StringBuilder menuListOfItemString = new StringBuilder();
            int index = 1;

            menuListOfItemString.AppendLine(i_MasterItem.ItemName);
            menuListOfItemString.AppendFormat("====================== {0}{1}", Environment.NewLine, Environment.NewLine);
            foreach (MenuItem item in i_MasterItem.MenuItemsList)
            {
                menuListOfItemString.AppendLine(index.ToString() + ") " + item.ItemName);
                index++;
            }

            menuListOfItemString.AppendFormat("Press 0 to {0} menu {1}", i_IsThisMainMenu ? "exit" : "back", Environment.NewLine);
            Console.WriteLine(menuListOfItemString.ToString());
        }
Beispiel #3
0
        /// <summary>
        /// Recursive method that displays the menu and its sub menus
        /// </summary>
        /// <param name="i_MasterItem">The Menu item paramater</param>
        /// <param name="i_IsThisMainMenu">Boolean that determines whether display Main menu or sub-menu</param>
        private void ShowMenu(MasterItem i_MasterItem, bool i_IsThisMainMenu)
        {
            int userInput = 0;

            while (true)
            {
                Console.Clear();
                PrintItems(i_MasterItem, i_IsThisMainMenu);
                userInput = GetUserInput(m_RootItem.MenuItemsList.Count);
                if (userInput == 0)
                {
                    return;
                }

                MasterItem masterItem = i_MasterItem.MenuItemsList[userInput - 1] as MasterItem;

                if (masterItem != null)
                {
                    ShowMenu(masterItem, false);
                }
                else
                {
                    Console.Clear();
                    LeafItem leafItem = i_MasterItem.MenuItemsList[userInput - 1] as LeafItem;
                    leafItem.RunMethod();
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey();
                }
            }
        }