Ejemplo n.º 1
0
        //<<Menu dialog section:>>
        //
        private void MenuDialog_GenerateNew2DArray()
        {
            Console.Clear();
            Console.WriteLine("\tGenerating new 2D array: \n\nPlease enter number of rows (1 - 1000):");
            int customNumberOfRows = SortUtil.ValidateInputNumberForIntValue(Console.ReadLine(), 1, 1000);

            Console.WriteLine("Please enter number of columns (1 - 1000):");
            int customNumberOfColumns = SortUtil.ValidateInputNumberForIntValue(Console.ReadLine(), 1, 1000);

            current2DArray = SortUtil.Generate2DArray(customNumberOfRows, customNumberOfColumns);
            Console.WriteLine("New 2D array was generated. \nTo continue, please press any key...");
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method will check user selection for Asc\Desc  sorting type
        /// </summary>
        private void CheckForAscDescSelection()
        {
            //read sorting sub menu selection and define Asc\Desc sort mode
            int userSelectionSubMenu = SortUtil.ValidateInputNumberForIntValue(Console.ReadLine(), 1, 2);

            if (userSelectionSubMenu == 1)
            {
                isAscSorting = true;
            }
            else
            {
                isAscSorting = false;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Mathod which is representing the main menu;
        /// </summary>
        public void ShowMenu()
        {
            //objects and fields init:
            bool isExit = false;

            current2DArray = SortUtil.Generate2DArray(10, 10);

            //Menu:
            while (!isExit)
            {
                //Menu generator:
                Console.Clear();
                int sorterListMenuItemCounter = menuNumberConst;

                //TODO: create array of string and print
                Console.WriteLine(
                    "\t\tChoose your actions:\n" +
                    "(1) - Generate new custom 2D array\n" +
                    "(2) - Import array from DB\n" +
                    "(3) - Print 2D array\n\n" +
                    "(4) - Sort simultaneously with all sorters"
                    );

                //generating dynamic menu, according to incoming List of sorters
                foreach (ISorter sorter in sorterList)
                {
                    Console.WriteLine("({0}) - {1}", sorterListMenuItemCounter, sorter);
                    sorterListMenuItemCounter++;
                }

                //Display last step - exit
                Console.WriteLine("({0}) - Exit", sorterList.Count + menuNumberConst);

                //Reading user selection and parse for correct value:
                userSelectionMainMenu = SortUtil.ValidateInputNumberForIntValue(Console.ReadLine(), 1, sorterList.Count + menuNumberConst);

                //User selection 1-3 handler:
                switch (userSelectionMainMenu)
                {
                case 1:
                    MenuDialog_GenerateNew2DArray();
                    break;

                case 2:
                    current2DArray = sqlConnectionUtil.Get2DArrayFromDB();
                    Console.Clear();
                    Console.WriteLine("Array was readed from DB, please press any key...");
                    Console.ReadKey();
                    break;

                case 3:
                    Console.Clear();
                    Console.WriteLine("Please see below printed 2D array:\n\n");
                    SortUtil.Print2DArrayToConsole(current2DArray);
                    Console.WriteLine("To continue, please press any key...");
                    Console.ReadKey();
                    break;

                case 4:
                    MenuDialog_SortingMenuHandler(true);
                    break;

                default:
                    break;
                }

                //sub menu (for list of sorters) selection, in case of user selected sorting methods:
                if (Enumerable.Range(menuNumberConst, sorterList.Count).Contains(userSelectionMainMenu))
                {
                    MenuDialog_SortingMenuHandler(false);
                }

                //exit logic
                else if (userSelectionMainMenu == sorterList.Count + menuNumberConst)
                {
                    isExit = true;
                }
            }
        }