public static string AtribuirIDEmpregado(EmployeeList el)
        {
            string   id;
            Employee lastEmployee = el.employeeList[el.employeeList.Count - 1];

            id = (int.Parse(lastEmployee.Id) + 1).ToString();
            return(id);
        }
 public static void UpdatePosicaoListaEmpregados(EmployeeList el) // Desnecessario
 {
     for (int i = 0; i < el.employeeList.Count; i++)
     {
         if (int.Parse(el.employeeList[i].Id) != (i + 1))
         {
             el.employeeList[i].Id = (i + 1).ToString();
         }
     }
 }
Exemple #3
0
        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);
        }
Exemple #4
0
        public static void MostrarPrincipal(Employee activeuser) //Menu principal
        {
            int menuOption2;

            EmployeeList employeelist = new EmployeeList();
            InvoiceList  invoiceList  = new InvoiceList();

            do
            {
                employeelist.LerFicheiro();
                invoiceList = GravadorFaturas.ReadInvoiceList();
                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- Vendas\n");
                Console.WriteLine("2- Stock\n");
                Console.WriteLine("3- Funcionarios\n");
                Console.WriteLine("4- Listagem de Faturas\n");
                //Console.WriteLine("5- Remover Faturas\n"); Legalmente nao se pode remover faturas, apenas inserimos aqui esta opçao para remover faturas teste
                Console.WriteLine("--------------------------------------------------");
                Console.WriteLine("0- Sair");

                while (int.TryParse(Console.ReadLine(), out menuOption2) == false)
                {
                    Console.WriteLine("Opçao errada");
                }

                Console.Clear();

                switch (menuOption2)
                {
                case 0:
                    break;

                case 1:
                    if (activeuser.EmployeeRole.Equals(EmployeeRole.Repositor))
                    {
                        Console.WriteLine("Lamento, não tem permissão para esta opção!");
                        break;
                    }
                    Invoice newInvoice = (MenuVendas(activeuser, invoiceList));
                    if (newInvoice.InvoiceProducts.Count > 0)
                    {
                        invoiceList.AddInvoice(newInvoice);
                        GravadorFaturas.SaveInvoiceList(invoiceList);
                    }

                    break;

                case 2:
                    if (activeuser.EmployeeRole.Equals(EmployeeRole.Caixa))
                    {
                        Console.WriteLine("Lamento, não tem permissão para esta opção!");
                        break;
                    }
                    MenuStock(activeuser);
                    break;

                case 3:
                    if (activeuser.EmployeeRole.Equals(EmployeeRole.Gerente))
                    {
                        MenuFuncionarios(activeuser);
                        break;
                    }
                    Console.WriteLine("Lamento, não tem permissão para esta opção!");
                    break;

                case 4:
                    Table.PrintLine();
                    Table.PrintRow("LISTAGEM DE FATURAS");
                    Table.PrintLine();
                    invoiceList.ToString();

                    //invoiceList.ListInvoiceList(invoiceList);
                    break;

                case 5:
                /*
                 * invoiceList.ListInvoiceList(invoiceList);
                 * invoiceList.RemoveInvoiceFromList(invoiceList);
                 * GravadorFaturas.SaveInvoiceList(invoiceList);
                 * break;
                 */
                default:
                    Console.WriteLine("Escolheu uma opção inválida");
                    break;
                }
                Console.ReadKey();
                Console.Clear();
            } while (menuOption2 != 0);
        }
Exemple #5
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);
        }