fazendo os sistemas de clientes e do admin
This commit is contained in:
@@ -537,7 +537,7 @@ private static void procurarClienteAdmin() {
|
||||
}
|
||||
|
||||
if (!encontrado) {
|
||||
System.out.println("❌ Cliente não encontrado.");
|
||||
System.out.println("Cliente não encontrado.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -550,7 +550,7 @@ private static void editarClienteAdmin() {
|
||||
String[] dadosCliente = procurarClientePorId(id);
|
||||
|
||||
if (dadosCliente == null) {
|
||||
System.out.println("❌ Cliente não encontrado!");
|
||||
System.out.println("Cliente não encontrado!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -567,10 +567,10 @@ private static void editarClienteAdmin() {
|
||||
if (!telefoneJaExiste(novoTelefone) || dadosCliente[2].equals(novoTelefone)) {
|
||||
dadosCliente[2] = novoTelefone;
|
||||
} else {
|
||||
System.out.println("❌ Telefone já existe! Mantido o original.");
|
||||
System.out.println("Telefone já existe! Mantido o original.");
|
||||
}
|
||||
} else {
|
||||
System.out.println("❌ Telefone inválido! Mantido o original.");
|
||||
System.out.println("Telefone inválido! Mantido o original.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -579,11 +579,11 @@ private static void editarClienteAdmin() {
|
||||
if (!novoEmail.isEmpty() && verificarEmail(novoEmail)) {
|
||||
dadosCliente[3] = novoEmail;
|
||||
} else if (!novoEmail.isEmpty()) {
|
||||
System.out.println("❌ Email inválido! Mantido o original.");
|
||||
System.out.println("Email inválido! Mantido o original.");
|
||||
}
|
||||
|
||||
atualizarClienteCompleto(dadosCliente);
|
||||
System.out.println("✅ Cliente atualizado com sucesso!");
|
||||
System.out.println("1Cliente atualizado com sucesso!");
|
||||
}
|
||||
|
||||
private static void removerCliente() {
|
||||
@@ -734,7 +734,7 @@ private static void atualizarClienteCompleto(String[] dados) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Separar os dígitos
|
||||
|
||||
int d1 = Character.getNumericValue(nif.charAt(0));
|
||||
int d2 = Character.getNumericValue(nif.charAt(1));
|
||||
int d3 = Character.getNumericValue(nif.charAt(2));
|
||||
@@ -745,7 +745,7 @@ private static void atualizarClienteCompleto(String[] dados) {
|
||||
int d8 = Character.getNumericValue(nif.charAt(7));
|
||||
int d9 = Character.getNumericValue(nif.charAt(8));
|
||||
|
||||
// Cálculo do dígito de controlo
|
||||
|
||||
int produto = (d8 * 2) + (d7 * 3) + (d6 * 4) + (d5 * 5) +
|
||||
(d4 * 6) + (d3 * 7) + (d2 * 8) + (d1 * 9);
|
||||
int resto = produto % 11;
|
||||
@@ -757,7 +757,7 @@ private static void atualizarClienteCompleto(String[] dados) {
|
||||
digitoControlo = 11 - resto;
|
||||
}
|
||||
|
||||
// Verificar se o dígito de controlo está correto
|
||||
|
||||
if (digitoControlo == d9) {
|
||||
return true;
|
||||
} else {
|
||||
@@ -864,7 +864,7 @@ public static void editarDinheiroCliente() {
|
||||
String novoNIF = scanner.nextLine();
|
||||
if (!novoNIF.isEmpty()) nif[indiceEditar] = novoNIF;
|
||||
|
||||
// Reescrever o ficheiro com os dados atualizados
|
||||
|
||||
StringBuilder conteudoAtualizado = new StringBuilder();
|
||||
for (int i = 0; i < nome.length; i++) {
|
||||
conteudoAtualizado.append(nome[i]).append(",")
|
||||
@@ -908,33 +908,33 @@ public static void editarDinheiroCliente() {
|
||||
int indice = random.nextInt(CARACTERES.length());
|
||||
idNum.append(CARACTERES.charAt(indice));
|
||||
}
|
||||
// ver se id já existe
|
||||
|
||||
String idTxt = idNum.toString();
|
||||
if(!idJaExiste(idTxt)){
|
||||
return idTxt;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
private static boolean nifJaExiste(String nif) {
|
||||
private static boolean nifJaExiste (String nif) {
|
||||
String nomeFicheiro = "clientes.txt";
|
||||
|
||||
// 1. Começamos assumindo que NÃO existe
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(nomeFicheiro))) {
|
||||
String linha;
|
||||
while ((linha = reader.readLine()) != null) {
|
||||
String[] campos = linha.split(",");
|
||||
|
||||
// 2. Verificamos se a linha tem dados e se o NIF coincide
|
||||
|
||||
if (campos.length > 0 && campos[0].trim().equals(nif.trim())) {
|
||||
return true; // Encontrou? Retorna imediatamente e fecha o reader
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Opcional: imprimir erro para saber por que a leitura falhou
|
||||
|
||||
System.err.println("Erro ao ler o ficheiro: " + e.getMessage());
|
||||
}
|
||||
|
||||
return false; // Se percorreu tudo e não achou, retorna false
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1020,7 +1020,7 @@ private static boolean nifJaExiste(String nif) {
|
||||
} while (!verificarNIF(nif) || nif.isEmpty());
|
||||
|
||||
String telefone;
|
||||
do {
|
||||
|
||||
System.out.print("║ Introduza telefone (9 dígitos): ");
|
||||
telefone = scanner.nextLine();
|
||||
|
||||
@@ -1031,20 +1031,20 @@ private static boolean nifJaExiste(String nif) {
|
||||
System.out.println("║ Por favor, insira um telefone diferente.");
|
||||
telefone = "";
|
||||
}
|
||||
} while (telefone.isEmpty() || telefone.length() != 9 || !telefone.matches("\\d+"));
|
||||
while (telefone.isEmpty() || telefone.length() != 9 || !telefone.matches("\\d+"));
|
||||
|
||||
String email;
|
||||
do {
|
||||
|
||||
System.out.print("║ Introduza email: ");
|
||||
email = scanner.nextLine();
|
||||
|
||||
if (!verificarEmail(email)) {
|
||||
System.out.println("║ Email inválido! Deve conter @ e .pt ou .com");
|
||||
}
|
||||
} while (!verificarEmail(email));
|
||||
while (!verificarEmail(email));
|
||||
|
||||
double saldo;
|
||||
do {
|
||||
|
||||
System.out.print("║ Introduza saldo (mínimo 60€): ");
|
||||
saldo = scanner.nextDouble();
|
||||
scanner.nextLine(); // limpar buffer
|
||||
@@ -1052,7 +1052,7 @@ private static boolean nifJaExiste(String nif) {
|
||||
if (saldo < 60) {
|
||||
System.out.println("║ Saldo mínimo insuficiente! Mínimo 60€.");
|
||||
}
|
||||
} while (saldo < 60);
|
||||
while (saldo < 60);
|
||||
|
||||
String saldoTxt = Double.toString(saldo);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user