Controllo input e gestione eccezioni opzione 4
This commit is contained in:
@@ -76,16 +76,19 @@ class Cliente {
|
|||||||
bool exit = false;
|
bool exit = false;
|
||||||
int j;
|
int j;
|
||||||
for (int i = 0; i < this.prenotazioni.Length; i++) {
|
for (int i = 0; i < this.prenotazioni.Length; i++) {
|
||||||
|
if (this.prenotazioni[i] != null) {
|
||||||
UUIDs[i] = this.prenotazioni[i].GetUUID();
|
UUIDs[i] = this.prenotazioni[i].GetUUID();
|
||||||
}
|
}
|
||||||
//verifico che lo UUID esista
|
}
|
||||||
|
//trovo a quale prenotazione corrisponde l'UUID selezionato
|
||||||
for (j = 0; j < this.prenotazioni.Length && !exit; j++) {
|
for (j = 0; j < this.prenotazioni.Length && !exit; j++) {
|
||||||
if (UUIDs[j] == p_UUID) {
|
if (UUIDs[j] == p_UUID) {
|
||||||
exit = true;
|
exit = true;
|
||||||
|
j--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.prenotazioni[j] = exit ? null : throw new Exception("Codice prenotazione non trovato");
|
this.prenotazioni[j] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StampaDatiCliente() {
|
public void StampaDatiCliente() {
|
||||||
|
|||||||
@@ -61,8 +61,9 @@ class Prenotazione {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void SetCosto() {
|
public void SetCosto() {
|
||||||
|
//qui andrebbe creata una funzione che calcola il prezzo in base i giorni e a un tariffario per ogni periodo
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
this.costo = Convert.ToString(random.Next());
|
this.costo = Convert.ToString(random.Next(10000));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetNumeroPersone(string p_numeroPersone) {
|
public void SetNumeroPersone(string p_numeroPersone) {
|
||||||
|
|||||||
40
Program.cs
40
Program.cs
@@ -261,17 +261,16 @@ class Program {
|
|||||||
eccezione = false;
|
eccezione = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
clienti[input - 1].InserisciPrenotazione(periodi[scelta], Convert.ToString(giorniPrenotati), Convert.ToString(numeroPersone));
|
clienti[input - 1].InserisciPrenotazione(periodi[scelta - 1], Convert.ToString(giorniPrenotati), Convert.ToString(numeroPersone));
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
Console.WriteLine(e.Message);
|
Console.WriteLine(e.Message);
|
||||||
eccezione = true;
|
eccezione = true;
|
||||||
Pausa();
|
|
||||||
}
|
}
|
||||||
if (!eccezione) {
|
if (!eccezione) {
|
||||||
Console.WriteLine("Prenotazione inserita correttamente.");
|
Console.WriteLine("Prenotazione inserita correttamente.");
|
||||||
Pausa();
|
|
||||||
}
|
}
|
||||||
|
Pausa();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
@@ -286,6 +285,10 @@ class Program {
|
|||||||
case 4:
|
case 4:
|
||||||
do {
|
do {
|
||||||
Console.WriteLine("Cancellare la prenotazione di quale cliente? ");
|
Console.WriteLine("Cancellare la prenotazione di quale cliente? ");
|
||||||
|
for (int i = 0; i < clienti.Length; i++) {
|
||||||
|
Console.WriteLine(i + 1);
|
||||||
|
}
|
||||||
|
Console.Write("Scelta: ");
|
||||||
|
|
||||||
eccezione = false;
|
eccezione = false;
|
||||||
|
|
||||||
@@ -302,14 +305,20 @@ class Program {
|
|||||||
Console.WriteLine("Opzione non valida");
|
Console.WriteLine("Opzione non valida");
|
||||||
Pausa();
|
Pausa();
|
||||||
}
|
}
|
||||||
|
else if (clienti[input - 1] == null) {
|
||||||
|
Console.WriteLine("I dati di questo cliente non sono ancora stati inseriti.");
|
||||||
|
Pausa();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (eccezione || input <= 0 || input > numeroClienti);
|
}
|
||||||
|
while (eccezione || input <= 0 || input > numeroClienti || clienti[input - 1] == null);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
Console.WriteLine("Scegliere una prenotazione:");
|
Console.WriteLine("Scegliere una prenotazione:");
|
||||||
for (int i = 0; i < clienti[input].GetPrenotazioni().Length; i++) {
|
for (int i = 0; i < clienti[input - 1].GetPrenotazioni().Length; i++) {
|
||||||
Console.WriteLine($"{i + 1}. {clienti[input].GetPrenotazioni()[i].GetUUID()}");
|
if (clienti[input - 1].GetPrenotazioni()[i] != null) {
|
||||||
|
Console.WriteLine($"{i + 1}. {clienti[input - 1].GetPrenotazioni()[i].GetUUID()}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Console.Write("Scelta: ");
|
Console.Write("Scelta: ");
|
||||||
|
|
||||||
@@ -324,20 +333,21 @@ class Program {
|
|||||||
Pausa();
|
Pausa();
|
||||||
}
|
}
|
||||||
if (!eccezione) {
|
if (!eccezione) {
|
||||||
if (scelta < 1 || scelta > clienti[input].GetPrenotazioni().Length) {
|
if (scelta < 1 || scelta > clienti[input - 1].GetPrenotazioni().Length) {
|
||||||
|
Console.WriteLine("Opzione non valida");
|
||||||
|
Pausa();
|
||||||
|
}
|
||||||
|
else if (clienti[input - 1].GetPrenotazioni()[scelta - 1] == null) {
|
||||||
Console.WriteLine("Opzione non valida");
|
Console.WriteLine("Opzione non valida");
|
||||||
Pausa();
|
Pausa();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (eccezione || scelta < 1 || scelta > clienti[input].GetPrenotazioni().Length);
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
clienti[input].CancellaPrenotazione(clienti[input].GetPrenotazioni()[scelta - 1].GetUUID());
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
Console.WriteLine(e.Message);
|
|
||||||
}
|
}
|
||||||
|
while (eccezione || scelta < 1 || scelta > clienti[input - 1].GetPrenotazioni().Length || clienti[input - 1].GetPrenotazioni()[scelta - 1] == null);
|
||||||
|
|
||||||
|
clienti[input - 1].CancellaPrenotazione(clienti[input - 1].GetPrenotazioni()[scelta - 1].GetUUID());
|
||||||
|
|
||||||
|
Console.WriteLine("Prenotazione cancellata con successo.");
|
||||||
Pausa();
|
Pausa();
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -13,7 +13,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("agenzia_viaggi")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("agenzia_viaggi")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a880e849e7d4a2978791c0c134799d7ea0c79c90")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5deed24c3015833c03b6882dcd5b9728f2d83e1d")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("agenzia_viaggi")]
|
[assembly: System.Reflection.AssemblyProductAttribute("agenzia_viaggi")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("agenzia_viaggi")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("agenzia_viaggi")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
86d553a2206a24066a2f2a887f4f9259aca91589cd91382116965530ddf5b584
|
11c438e245e0f2a2c0454d8518eaac4d4be227f5a243e5f779c48d80d453d9b8
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user