public static void MenuFuncionarios(Employee activeuser) { int menuOption; EmployeeList employeeList = new EmployeeList(); do { employeeList.LerFicheiro(); Console.WriteLine("************SUPERMERCADO BINHAS ONTE***************"); Console.WriteLine("** **"); Console.WriteLine("** Bem-vindo/a! **"); Console.WriteLine("** **"); Console.WriteLine("**\t" + DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm") + "\t\t**"); Console.WriteLine("**************************************************\n"); Console.WriteLine("1- Registar Funcionario"); Console.WriteLine("2- Remover Funcionario\n"); Console.WriteLine("3- Editar Funcionario\n"); Console.WriteLine("--------------------------------------------------"); Console.WriteLine("0- Sair"); while (int.TryParse(Console.ReadLine(), out menuOption) == false) { Console.WriteLine("Opçao errada"); } Console.Clear(); switch (menuOption) { case 0: Console.WriteLine("0"); break; case 1: Console.WriteLine("**TECLA 0 - PARA SAIR OU CANCELAR**\n"); Console.WriteLine(employeeList.ToString()); Console.WriteLine("ID: {0}\n", employeeList.employeeList.Count + 1); string id = Operator.AtribuirIDEmpregado(employeeList); Console.WriteLine("Introduza o Nome\n"); string name = Console.ReadLine(); if (name == "0") { employeeList.ClearList(); break; } Console.WriteLine("Introduza a Password\n"); string password = Console.ReadLine(); if (password == "0") { employeeList.ClearList(); break; } Console.WriteLine("Qual o Cargo? \n"); Console.WriteLine("Para Gerente prima '0'\n"); Console.WriteLine("Para Repositor prima '1'\n"); Console.WriteLine("Para Caixa prima '2'\n"); bool result = Enum.TryParse(Console.ReadLine(), out EmployeeRole employeeRole) && Enum.IsDefined(typeof(EmployeeRole), employeeRole); while (!result) { Console.WriteLine("Valor incorrecto, tente novamente"); result = Enum.TryParse(Console.ReadLine(), out employeeRole) && Enum.IsDefined(typeof(EmployeeRole), employeeRole); } employeeList.NewEmployee(id, name, password, employeeRole); employeeList.GravarParaFicheiro(); Console.WriteLine(employeeList.ToString()); employeeList.ClearList(); break; case 2: Console.WriteLine("**TECLA 0 - PARA SAIR OU CANCELAR**\n"); Console.WriteLine(employeeList.ToString()); Console.WriteLine("Introduza o ID a remover\n"); string idARemover = Console.ReadLine(); if (idARemover == "0") { employeeList.ClearList(); break; } employeeList.RemoveEmployee(idARemover); Console.WriteLine(employeeList.ToString()); employeeList.GravarParaFicheiro(); employeeList.ClearList(); break; case 3: Console.WriteLine("**TECLA 0 - PARA SAIR OU CANCELAR**\n"); Console.WriteLine(employeeList.ToString()); Console.WriteLine("Introduza o ID do funcionário a editar\n"); string newId = Console.ReadLine(); if (newId == "0") { employeeList.ClearList(); break; } Console.WriteLine("**O QUE DESEJA ALTERAR? \n 1: Nome | 2: password | 3: Função**\n"); int opcaoAlterarFunc = -1; while (int.TryParse(Console.ReadLine(), out opcaoAlterarFunc) == false) { Console.WriteLine("Opçao errada"); } Console.Clear(); switch (opcaoAlterarFunc) { case 0: Console.WriteLine("0"); break; case 1: Console.WriteLine("Introduza o novo nome\n"); string newName = Console.ReadLine(); employeeList.FindEmployee(newId).Name = newName; break; case 2: Console.WriteLine("Introduza a nova password\n"); string newPassword = Console.ReadLine(); employeeList.FindEmployee(newId).Password = newPassword; break; case 3: Console.WriteLine("Introduza a nova função\n"); Console.WriteLine("Para Gerente prima '0'\n"); Console.WriteLine("Para Repositor prima '1'\n"); Console.WriteLine("Para Caixa prima '2'\n"); bool result2 = Enum.TryParse(Console.ReadLine(), out EmployeeRole newEmployeeRole) && Enum.IsDefined(typeof(EmployeeRole), newEmployeeRole); while (!result2) { Console.WriteLine("Valor incorrecto, tente novamente"); result = Enum.TryParse(Console.ReadLine(), out newEmployeeRole) && Enum.IsDefined(typeof(EmployeeRole), newEmployeeRole); } employeeList.FindEmployee(newId).EmployeeRole = newEmployeeRole; break; default: Console.WriteLine("Opção Invalida"); break; } Console.WriteLine(employeeList.ToString()); employeeList.GravarParaFicheiro(); employeeList.ClearList(); Console.WriteLine(employeeList.ToString()); break; default: Console.WriteLine("Escolheu uma opção inválida"); break; } Console.ReadKey(); Console.Clear(); } while (menuOption != 0); }
public static void MostrarMenu(Employee activeuser) { int menuOption; EmployeeList employeeList = new EmployeeList(); do { employeeList.LerFicheiro(); Console.WriteLine("************SUPERMERCADO BINHAS ONTE***************"); Console.WriteLine("** **"); Console.WriteLine("** Bem-vindo/a! **"); Console.WriteLine("** **"); Console.WriteLine("**\t" + DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm") + "\t\t**"); Console.WriteLine("**************************************************\n"); Console.WriteLine("1- Entrar"); //Console.WriteLine("2- Recuperar a password\n"); : A desenvolver Console.WriteLine("--------------------------------------------------"); Console.WriteLine("0- Sair"); while (int.TryParse(Console.ReadLine(), out menuOption) == false) { Console.WriteLine("Opçao errada"); } Console.Clear(); switch (menuOption) { case 0: break; case 1: bool successfull = false; while (!successfull) { Console.WriteLine("Introduza o seu ID"); string id = Console.ReadLine(); Console.WriteLine("Introduza a sua password"); string password = null; while (true) { var key = System.Console.ReadKey(true); if (key.Key == ConsoleKey.Enter) { Console.WriteLine("\n"); break; } else if (key.Key == ConsoleKey.Backspace) { password = password.Remove(password.Length - 1); Console.Write("\b \b"); } else { password += key.KeyChar; Console.Write("*"); } } successfull = employeeList.ValidateEntry(id, password); activeuser = employeeList.FindEmployee(id); } MostrarPrincipal(activeuser); break; case 2: Console.WriteLine("2"); break; default: Console.WriteLine("Escolheu uma opção inválida"); break; } Console.ReadKey(); Console.Clear(); } while (menuOption != 0); }