/// <summary> /// Read and record the CPF of the position i client and returns true, or returns false if CPF already exists. /// </summary> /// <param name="clientsArray"></param> /// <param name="clientIndex"></param> /// <returns></returns> private static bool ReadAndRecordCPF(string[,] clientsArray, int clientIndex) { string message = "Digite o CPF do Cliente:"; while (true) { string cpf = MenuLib.ReadStringValue(message); if (cpf == "") { return(false); } if (!Verifications.CPFValidation(cpf)) { MenuLib.PrintMessage("\nCPF inválido.\n\n" + "Digite um CPF válido ou pressione qualquer tecla para retornar ao Menu."); } else if (!Verifications.CPFAlreadyExists(clientsArray, cpf)) { MenuLib.PrintMessage("\nCPF já cadastrado no nosso banco de dados.\n\n" + "Pressione qualquer tecla para retornar ao Menu."); Console.ReadKey(); return(false); } else { clientsArray[clientIndex, 0] = cpf; return(true); } } }
/// <summary> /// Reads birth date, only accepts valid format. Keeps asking until valid format. /// </summary> /// <param name="clientsArray"></param> /// <param name="message"></param> /// <returns></returns> public static string ReadBirthDate(string[,] clientsArray, string message) { while (true) { string birthDateString = MenuLib.ReadStringValue(message); if (DateTime.TryParseExact(birthDateString, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime birthDate)) { return(birthDateString); } message = "A data digitada é inválida. Digite uma data no formato \"DD/MM/AAAA\":"; } }
/// <summary> /// Displays a message than reads CPF input. /// If it is found in the clienrsArray, returns the position, /// if not, keeps asking for another valid input, unless user types "" to leave. /// </summary> /// <param name="clientsArray"></param> /// <param name="message"></param> /// <returns></returns> public static int ReadCPF(string[,] clientsArray, string message) { string target = MenuLib.ReadStringValue(message); while (true) { int i = ArrayLib.Find_Ordinary(clientsArray, target, 0); if (i != -1) { return(i); } else { target = MenuLib.ReadStringValue("O CPF digitado não foi encontrado.\n" + "Digite um CPF válido ou tecle ENTER para voltar ao menu principal:"); if (target == "") { return(-1); } } } }
/// <summary> /// Read and record the name of the position i client. /// </summary> /// <param name="clientsArray"></param> /// <param name="clientIndex"></param> /// <param name="message"></param> private static void ReadAndRecordName(string[,] clientsArray, int clientIndex, string message) { clientsArray[clientIndex, 1] = MenuLib.ReadStringValue(message); }