Exemplo n.º 1
0
        public static void Main()
        {
            List <Employee> employeesList = new List <Employee>(); // Declare a List by using the constructor, from type Employee
            ConsoleKeyInfo  cki;
            string          PressedKey = "";                       //save the user choosen option

            while (true)
            {
                MessageExceptions message  = new MessageExceptions();      // Declare a MessageException by using the constructor
                Employee          employee = new Employee();               // Declare a Employee by using the constructor
                Menus.MainMenuEmployee();                                  //call MainMenuEmployee method from Class Menus
                cki = Console.ReadKey();                                   // Read from Console
                if (cki.Key == ConsoleKey.A)                               // If user press "A" the code in the curly braces start executing
                {
                    cki = Add.Employees(employeesList, employee);          // cki get the otuput value from method AddEmployees in Class Add
                }
                if (cki.Key == ConsoleKey.S)                               // If user press "S" the code in the curly braces start executing
                {
                    PressedKey = Search.Employees(employeesList, message); //pressedkey get the otuput value
                                                                           //from method AddEmployees in Class Add
                }
                if (cki.Key == ConsoleKey.P)                               // If user press "P" the code in the curly braces start executing
                {
                    Print.AllEmployees(employeesList);                     // cki get the otuput value from method PrintAllEmployees in Class Print
                }
                if (cki.Key == ConsoleKey.Q)                               // If user press "P" the code in the curly braces start executing
                {
                    Console.Write("Goodbye!!!");                           // This text appear in the console
                    Environment.Exit(0);                                   // The console is closed
                }
                Console.ReadLine();                                        // use console.readline to stop while looping before the upper code execute
            }
        }
Exemplo n.º 2
0
        public static string Employees(List <Employee> employeesList, MessageExceptions message) //method takes employeesList,
                                                                                                 // message as parameters
        {
            string PressedKey;                                                                   //declare PressedKey as string

            while (true)                                                                         //
            {
                Menus.SubMenuEmployee();                                                         //invoke SubMenuEmployee from Menu class to show the submenu
                PressedKey = Console.ReadLine();                                                 //pressedkey gets value from console
                if (PressedKey == "N")                                                           //if "N" is pressed the code in curly braces executes
                {
                    SearchByName.SearchEmployeeByName(employeesList, message);                   //invoke SearchEmployeeByName method
                    //from classSearchByName with params employeesList message
                }
                if (PressedKey == "PO")                                                //if "PO" is pressed the code in curly braces executes
                {
                    SearchByPosition.SearchEmployeeByPosition(employeesList, message); //invoke SearchEmployeeByPosition method
                    //from SearchByPosition with params employeesList message
                }

                if (PressedKey == "PR")                                              //if "PR" is pressed the code in curly braces executes
                {
                    SearchByProject.SearchEmployeeByProject(employeesList, message); //invoke SearchEmployeeByProject method
                    //from SearchByProject with params employeesList message
                }
                if (PressedKey == "Q")//if "Q" is pressed the code in curly braces executes
                {
                    break;
                }
                Console.ReadLine();// use it to stop while from looping constantly
            }
            return(PressedKey);
        }
Exemplo n.º 3
0
        public static void SearchEmployeeByProject(List <Employee> employeesList,          //method that takes employeesList
                                                   MessageExceptions message)              // message as params
        {
            listWithAllProjects(employeesList);                                            //invoked method which takes employeesList as param
            Console.WriteLine("Enter the name of the Project :");
            string getInputSearch = Console.ReadLine();                                    // Get the project to do a search
            var    projectSearch  = employeesList.Where(s => s.                            //Return list of objects
                                                        Project.Contains(getInputSearch)); //wich have the same project
            int    countEmployeesWithSameProject;
            string foundEmployeeProject;

            processProjectInformation(projectSearch,                                  //invoked method which takes projectSearch
                                      out countEmployeesWithSameProject,              //countEmployeesWithSameProject
                                      out foundEmployeeProject);                      //foundEmployeeProject as params
            if (foundEmployeeProject != null)                                         // Check if it's null to except NullReferenceException
            {
                if (getInputSearch == foundEmployeeProject)                           // Check if this project appear in the company
                {
                    returnedInformation(projectSearch, countEmployeesWithSameProject, //invoked method which takes projectSearch
                                        foundEmployeeProject);                        //countEmployeesWithSameProject
                }                                                                     //foundEmployeeProject as params
                else
                {
                    message.NoSuchProjectMessage();//invoked NoSuchEmployeeMessage method from object message
                }
            }
            else
            {
                message.NoSuchProjectMessage();//invoked NoSuchEmployeeMessage method from object message
            }
        }
Exemplo n.º 4
0
        public static void SearchEmployeeByName(List <Employee> employeesList,     //method that takes employeesList
                                                MessageExceptions message)         // message as params
        {
            showListWithNamesOfEmployees(employeesList);                           //invoked method which takes employeesList as param
            Console.WriteLine("Enter the name of employee :");
            string getInputSearch = Console.ReadLine();                            // Get the name to do a search
            var    employeeSearch = employeesList.Where(s => s.Name.               //Return list of objects wich
                                                        Contains(getInputSearch)); //have the same name
            int    countEmployeesWithSameName;
            string foundEmployeeName;

            processEmployeeInformation(employeeSearch,                       // method that takes employeeSearch
                                       out countEmployeesWithSameName,       // countEmployeesWithSameName
                                       out foundEmployeeName);               // foundEmployeeName as params
            if (foundEmployeeName != null)                                   // Check if it's null to except NullReferenceException
            {
                if (getInputSearch == foundEmployeeName)                     // Check if this name of employee appear in the company
                {
                    returnResult(employeeSearch, countEmployeesWithSameName, // invoked method takes employeeSearch
                                 foundEmployeeName);                         //countEmployeesWithSameName, foundEmployeeName as params
                }
                else
                {
                    message.NoSuchEmployeeMessage();//invoked NoSuchEmployeeMessage method from object message
                }
            }
            else
            {
                message.NoSuchEmployeeMessage();//invoked NoSuchEmployeeMessage method from object message
            }
        }
Exemplo n.º 5
0
        public static void SearchEmployeeByPosition(List <Employee> employeesList,   //method takes
                                                    MessageExceptions message)       //employeesList,message as params

        {
            returnlistOfPositions(employeesList);                                             //method which takes employeesList as param
            Console.WriteLine("Enter the position :");
            string getInputSearch = Console.ReadLine();                                       // Get the name to do a search
            var    employeeSearch = employeesList.Where(s =>                                  //Return list of objects
                                                        s.Position.Contains(getInputSearch)); // wich have the same position

            int    countEmployeesWithSamePosition;                                            //declare integer to count how many employees are related to this position
            string foundEmployeePosition;                                                     //declare string which will store the name of the found position in the list

            proccessPositionsInformation(employeeSearch,                                      //method which takes employeeSearch,
                                         out countEmployeesWithSamePosition,                  //countEmployeesWithSamePosition,
                                         out foundEmployeePosition);                          // foundEmployeePosition as params

            if (foundEmployeePosition != null)                                                // Check if searching is not null, to except nullreference exception and retrieve
            {
                if (getInputSearch == foundEmployeePosition)                                  // Check if this name of employee appear in the company
                {
                    returnResults(employeeSearch,                                             //method that takes
                                  countEmployeesWithSamePosition,                             //employeeSearch, countEmployeesWithSamePosition,
                                  foundEmployeePosition);                                     // foundEmployeePosition as params
                }

                else
                {
                    message.NoSuchPositionMessage(); //invoke NoSuchPositionMessage method from message object, instance of
                                                     // class MessageExceptions. This wiil execute if user input is not
                                                     //equal to existing positions in the list
                }
            }
            else
            {
                message.NoSuchPositionMessage(); //invoke NoSuchPositionMessage method from message object, instance of
                                                 // class MessageExceptions. This will execute if user not type anything
            }
        }