Пример #1
0
        static void Main(string[] args)
        {
            string instructions = "\nVad vill du göra?\nAvsluta: [quit]\nSkriv ut: [print]\nLägg till: [add <förnamn> <efternamn> <lön>]";
            string errorMsg     = "Felaktig inmatning!";
            string prompt       = ">";

            EmployeeRegister register = new EmployeeRegister();

            register.AddDummyEmployees();

            Console.WriteLine("Välkommen till personalregistret!");

            bool    exit      = false;
            Command command   = Command.Undefined;
            decimal salary    = 0;
            string  lastName  = "";
            string  firstName = "";

            while (!exit)
            {
                Console.WriteLine(instructions);
                Console.Write(prompt);
                var inputData    = Console.ReadLine();
                var isValidInput = TryGetInput(inputData, out command, out firstName, out lastName, out salary);
                if (isValidInput)
                {
                    if (command == Command.Print)
                    {
                        var employees = register.GetEmployees();
                        foreach (var employee in employees)
                        {
                            Console.WriteLine(string.Format("Namn: {0} {1}  Lön: {2}  kr", employee.FirstName, employee.LastName, employee.Salary.ToString()));
                        }
                    }
                    else if (command == Command.Add)
                    {
                        register.AddEmployee(new Employee(firstName, lastName, salary));
                    }
                    else if (command == Command.Quit)
                    {
                        exit = true;
                    }
                    else
                    {
                        Console.WriteLine(errorMsg);
                    }
                }
                else
                {
                    Console.WriteLine(errorMsg);
                }
            }

            Console.WriteLine("personalregistret avslutas!");
            Console.WriteLine("Hit <return> ...");
            Console.ReadLine();
        }
Пример #2
0
        public void Run()
        {
            EmployeeRegister register = new EmployeeRegister();

            consoleInteraction.ShowWelcome();

            bool exit = false;

            while (!exit)
            {
                consoleInteraction.ShowPrompt();
                var inputData = consoleInteraction.GetUserInputs();

                CommandBase cmd;
                if (TryGetCommand(inputData, out cmd))
                {
                    if (cmd is CommandHelp)
                    {
                        consoleInteraction.ShowRows(CommandItems.GetSyntaxes());
                    }
                    else if (cmd is CommandQuit)
                    {
                        exit = true;
                    }
                    else if (cmd is CommandAdd)
                    {
                        var cmdAdd = cmd as CommandAdd;
                        register.AddEmployee(new Employee(cmdAdd.FirstName, cmdAdd.LastName, cmdAdd.Salary));
                    }
                    else if (cmd is CommandClear)
                    {
                        consoleInteraction.ClearScreen();
                    }
                    else if (cmd is CommandAddMany)
                    {
                        List <Employee> dummys = new List <Employee>()
                        {
                            new Employee("Musse", "Pigg", 25000),
                            new Employee("Kalle", "Anka", 14500.90m),
                            new Employee("Janne", "Långben", 10000.50m),
                        };
                        foreach (var employee in dummys)
                        {
                            register.AddEmployee(employee);
                        }
                    }
                    else if (cmd is CommandPrint)
                    {
                        var employees = register.GetEmployees();
                        foreach (var employee in employees)
                        {
                            consoleInteraction.ShowRows(new string[] { string.Format("Namn: {0} {1}  Lön: {2}  kr", employee.FirstName, employee.LastName, employee.Salary.ToString()) });
                        }
                    }
                    else
                    {
                        consoleInteraction.ShowFaultyInput();
                    }
                }
            }

            consoleInteraction.ShowGoodBye();
        }