181 lines
8.5 KiB
C#
181 lines
8.5 KiB
C#
namespace Rubrica_Miglioria;
|
|
|
|
class Program {
|
|
static void Main(string[] args) {
|
|
Console.Clear();
|
|
const int DIMENSIONE_RUBRICA = 100;
|
|
int scelta = 0;
|
|
string nome = "";
|
|
string numeroditelefono, tipologia;
|
|
bool check = false;
|
|
bool check2 = false;
|
|
bool check3 = false;
|
|
int contatore = 0;
|
|
string nomeesatto;
|
|
string nomeapprossimato;
|
|
string messaggio;
|
|
string[] nomi = new string[DIMENSIONE_RUBRICA];
|
|
string[] numeriditelefono = new string[DIMENSIONE_RUBRICA];
|
|
Voce singolavoce = null;
|
|
Voce[] vocidellarubrica = new Voce[DIMENSIONE_RUBRICA];
|
|
Rubrica rubrica = null;
|
|
do {
|
|
Console.WriteLine("1)Aggiungi nuova voce in rubrica");
|
|
Console.WriteLine("2)Ricerca esatta per nome");
|
|
Console.WriteLine("3)Ricerca approsimata per nome");
|
|
Console.WriteLine("4)Stampa completa rubrice");
|
|
Console.WriteLine("5)Esci");
|
|
scelta = Convert.ToInt32(Console.ReadLine());
|
|
switch (scelta) {
|
|
case 1:
|
|
if (contatore > DIMENSIONE_RUBRICA - 1) {
|
|
Console.WriteLine($"Limite di {DIMENSIONE_RUBRICA} voci nella rubrica raggiunta");
|
|
}
|
|
else {
|
|
do {
|
|
check2 = false;
|
|
Console.WriteLine("Inserisci il nome della voce che andrà nella rubrica telefonica");
|
|
nome = Console.ReadLine().ToLower();
|
|
nomi[contatore] = nome;
|
|
tipologia = "nome";
|
|
check2 = VerificaCorrettezza(nome, tipologia);
|
|
check3 = VerificaDoppione(nome, nomi, contatore);
|
|
if (nome.Length > 40) {
|
|
Console.WriteLine("il nome non può essere lungo più di 40 caratteri");
|
|
}
|
|
if (check2 == true) {
|
|
Console.WriteLine("il nome non può contenere dei numeri");
|
|
}
|
|
if (check3 == true) {
|
|
Console.WriteLine("Questo nome esiste già nelle rubrica");
|
|
}
|
|
}
|
|
while (nome.Length > 40 || check2 == true || check3 == true);
|
|
do {
|
|
check2 = false;
|
|
Console.WriteLine("Inserisci il numero di telefono della voce che andrà nella rubrica telefonica");
|
|
numeroditelefono = Console.ReadLine();
|
|
numeroditelefono = numeroditelefono.ToLower();
|
|
numeriditelefono[contatore] = numeroditelefono;
|
|
tipologia = "numero di telefono";
|
|
check2 = VerificaCorrettezza(numeroditelefono, tipologia);
|
|
check3 = VerificaDoppione(numeroditelefono, numeriditelefono, contatore);
|
|
if (numeroditelefono.Length > 20) {
|
|
Console.WriteLine("il numero di telefono non può essere lungo più di 20 caratteri");
|
|
}
|
|
if (check2 == true) {
|
|
Console.WriteLine("il numero di telefono deve contenere solo numeri");
|
|
}
|
|
if (check3 == true) {
|
|
Console.WriteLine("Questo numero di telefono esiste già nelle rubrica");
|
|
}
|
|
}
|
|
while (numeroditelefono.Length > 20 || check2 == true || check3 == true);
|
|
singolavoce = new Voce(nome, numeroditelefono);
|
|
vocidellarubrica[contatore] = singolavoce;
|
|
rubrica = new Rubrica(vocidellarubrica);
|
|
contatore++;
|
|
check = true;
|
|
}
|
|
break;
|
|
case 2:
|
|
if (check == false) {
|
|
Console.WriteLine("devi prima aggiungere una voce in rubrica");
|
|
}
|
|
else {
|
|
do {
|
|
check2 = false;
|
|
Console.WriteLine("Inserisci il nome esatto che stai cercando");
|
|
nomeesatto = Console.ReadLine();
|
|
nomeesatto = nomeesatto.ToLower();
|
|
tipologia = "nome";
|
|
check2 = VerificaCorrettezza(nome, tipologia);
|
|
if (nomeesatto.Length > 40) {
|
|
Console.WriteLine("il nome non può essere lungo più di 40 caratteri");
|
|
}
|
|
if (check2 == true) {
|
|
Console.WriteLine("il nome non può contenere dei numeri");
|
|
}
|
|
}
|
|
while (nomeesatto.Length > 40 || check2 == true);
|
|
messaggio = rubrica.EsistenzaNomeEsatto(nomeesatto, contatore);
|
|
Console.WriteLine(messaggio);
|
|
}
|
|
break;
|
|
case 3:
|
|
if (check == false) {
|
|
Console.WriteLine("devi prima aggiungere una voce in rubrica");
|
|
}
|
|
else {
|
|
do {
|
|
check2 = false;
|
|
Console.WriteLine("Inserisci il nome approsimato che stai cercando");
|
|
nomeapprossimato = Console.ReadLine();
|
|
nomeapprossimato = nomeapprossimato.ToLower();
|
|
tipologia = "nome";
|
|
check2 = VerificaCorrettezza(nome, tipologia);
|
|
if (nomeapprossimato.Length > 40) {
|
|
Console.WriteLine("il nome non può essere lungo più di 40 caratteri");
|
|
}
|
|
if (check2 == true) {
|
|
Console.WriteLine("il nome non può contenere dei numeri");
|
|
}
|
|
}
|
|
while (nomeapprossimato.Length > 40 || check2 == true);
|
|
rubrica.EsistenzaNomeApprosimato(nomeapprossimato, contatore);
|
|
}
|
|
break;
|
|
case 4:
|
|
if (check == false) {
|
|
Console.WriteLine("devi prima aggiungere una voce in rubrica");
|
|
}
|
|
else {
|
|
rubrica.StampaRubricaCompleta(contatore);
|
|
}
|
|
break;
|
|
case 5:
|
|
break;
|
|
default:
|
|
Console.WriteLine("Questa scelta non esiste");
|
|
break;
|
|
}
|
|
}
|
|
while (scelta != 5);
|
|
Console.WriteLine("Chiusura effettuta con successo");
|
|
}
|
|
static bool VerificaDoppione(string p_stringa, string[] p_stringhe, int p_contatore) {
|
|
bool check = false;
|
|
if (p_contatore != 0) {
|
|
for (int i = 0; i < p_contatore; i++) {
|
|
if (p_stringhe[i] == p_stringa) {
|
|
check = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return check;
|
|
}
|
|
static bool VerificaCorrettezza(string p_stringa, string p_tipologia) {
|
|
bool check = false;
|
|
string corretezzanome = "1234567890";
|
|
string corretezzanumeroditelefono = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZàèéìòùÀÈÉÌÒÙáéíóúÁÉÍÓÚâêîôûÂÊÎÔÛäëïöüÄËÏÖÜãõñÃÕÑçÇß¡¿€£¥¢¤!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ \r\n";
|
|
if (p_tipologia == "nome") {
|
|
for (int i = 0; i < p_stringa.Length; i++) {
|
|
if (corretezzanome.Contains(p_stringa[i])) {
|
|
check = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (p_tipologia == "numero di telefono") {
|
|
for (int i = 0; i < p_stringa.Length; i++) {
|
|
if (corretezzanumeroditelefono.Contains(p_stringa[i])) {
|
|
check = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return check;
|
|
}
|
|
}
|