Ejemplo n.º 1
0
        //Method for controlling the individual function of each PageElement
        public void PageElementFunction()
        {
            switch (function)
            {
            case 1:
                //Text input field

                //Clears current line
                Console.WriteLine(new string(' ', lineWidth));
                //Makes console cursor visible
                Console.CursorVisible = true;
                //Reads input
                stringInputToDatabase = LimitCharacterAmount(20);
                //Makes console cursor invisible
                Console.CursorVisible = false;
                //Goes back to menu
                Page.Menu(Page.ProductRegistrationPage);
                break;

            case 2:
                //Numeric input field

                Console.WriteLine(new string(' ', lineWidth));
                Console.SetCursorPosition(StartX + 1, StartY + 2);
                Console.CursorVisible = true;

                //Variables for parsing string to int
                int    parsed;
                string str;

                //do-while loop for tryparse until succes
                do
                {
                    Console.SetCursorPosition(StartX + 1, StartY + 2);
                    Console.WriteLine(new string(' ', lineWidth));
                    str = LimitCharacterAmount(7);
                } while (int.TryParse(str, out parsed) == false);

                //Saves parsed output
                intInputToDatabase = parsed;

                Console.CursorVisible = false;
                Page.Menu(Page.ProductRegistrationPage);
                break;

            case 3:
                //Go to ProductRegistrationPage
                Console.Clear();
                Page.Menu(Page.ProductRegistrationPage);
                break;

            case 4:
                //Go to ProductOverviewPage
                Console.CursorVisible = false;
                Console.Clear();
                Console.SetCursorPosition(StartX + 1, StartY + 3);
                Page.PrintAllProducts();
                Page.Menu(Page.ProductOverviewPage);
                break;

            case 5:
                //Go to MenuPage
                Console.Clear();
                Page.Menu(Page.MenuPage);
                break;

            case 6:
                //Exit application
                Environment.Exit(0);
                break;

            case 7:
                //Delete product from product number

                //Product number input
                Console.CursorVisible = true;
                string productNo = LimitCharacterAmount(20);
                Console.CursorVisible = false;

                Console.SetCursorPosition(StartX - 1, StartY + 9);

                //Removes specified product from database if possible
                Item product = new Item(productNo);
                product.RemoveFromDB();

                if (productRemoved)
                {
                    //Updates page if a product was cleared from the database
                    Console.Clear();
                    Console.SetCursorPosition(StartX + 1, StartY - 3 - Convert.ToInt32(DatabaseInterface.CountItems()));
                    Page.PrintAllProducts();
                }
                else
                {
                    //Clears product numberinput line
                    Console.SetCursorPosition(StartX + 1, StartY + 2);
                    Console.WriteLine(new string(' ', lineWidth));
                }
                Page.Menu(Page.ProductOverviewPage);
                break;

            case 8:
                //Registers new product if inputs are not empty
                if (!string.IsNullOrEmpty(Page.ProductRegistrationPage.pageElementList[2].stringInputToDatabase) &&
                    !string.IsNullOrEmpty(Page.ProductRegistrationPage.pageElementList[1].stringInputToDatabase) &&
                    !string.IsNullOrEmpty(Page.ProductRegistrationPage.pageElementList[4].stringInputToDatabase))
                {
                    new Item(Page.ProductRegistrationPage.pageElementList[2].stringInputToDatabase,
                             Page.ProductRegistrationPage.pageElementList[1].stringInputToDatabase,
                             Page.ProductRegistrationPage.pageElementList[3].intInputToDatabase,
                             Page.ProductRegistrationPage.pageElementList[4].stringInputToDatabase);
                }

                //Clears product value input lines
                for (int i = 1; i < 5; i++)
                {
                    Console.SetCursorPosition(Page.ProductRegistrationPage.pageElementList[i].StartX + 1, Page.ProductRegistrationPage.pageElementList[i].StartY + 2);
                    Console.WriteLine(new string(' ', lineWidth));
                }

                Page.Menu(Page.ProductRegistrationPage);
                break;
            }
        }