//Adding PageElements to ProductOverviewPage object, clears pageElementList each time as this method gets called with each menu update,
 //since a change in the database might have occurred
 static void ProductListDefine()
 {
     ProductOverviewPage.pageElementList.Clear();
     ProductOverviewPage.AddPageElement(0, 30, Convert.ToInt32(DatabaseInterface.CountItems()) + 15, 1, 1, "Product overview");
     ProductOverviewPage.AddPageElement(4, 28, Convert.ToInt32(DatabaseInterface.CountItems()) + 3, 2, 4, "Product list");
     ProductOverviewPage.AddPageElement(7, 28, 2, 2, Convert.ToInt32(DatabaseInterface.CountItems()) + 9, "Remove product - enter product number");
     ProductOverviewPage.AddPageElement(5, 28, 1, 2, Convert.ToInt32(DatabaseInterface.CountItems()) + 14, "<Back");
 }
Beispiel #2
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;
            }
        }