Controllo input e gestione eccezioni fino all'opzione 1
This commit is contained in:
parent
f9184fea2c
commit
ec1388ecb1
174
Program.cs
174
Program.cs
@ -4,25 +4,37 @@ namespace agenzia_viaggi;
|
||||
|
||||
class Program {
|
||||
static void Main(string[] args) {
|
||||
int scelta = 0;
|
||||
Console.Clear();
|
||||
int scelta = 3;
|
||||
bool eccezione;
|
||||
|
||||
do {
|
||||
Console.WriteLine("Scegliere un'opzione:");
|
||||
Console.WriteLine("1. Demo");
|
||||
Console.WriteLine("2. Esecuzione standard");
|
||||
Console.WriteLine("0. Esci");
|
||||
Console.Write("Scelta: ");
|
||||
|
||||
eccezione = false;
|
||||
|
||||
try {
|
||||
scelta = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
catch (FormatException) {
|
||||
Console.WriteLine("Opzione non valida");
|
||||
eccezione = true;
|
||||
Pausa();
|
||||
}
|
||||
if (!eccezione) {
|
||||
switch (scelta) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
Console.Clear();
|
||||
Demo();
|
||||
break;
|
||||
case 2:
|
||||
Console.Clear();
|
||||
Menu();
|
||||
break;
|
||||
default:
|
||||
@ -31,7 +43,8 @@ class Program {
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (scelta != 0);
|
||||
}
|
||||
while (eccezione || scelta < 0 || scelta > 2);
|
||||
}
|
||||
|
||||
static void Pausa() {
|
||||
@ -54,24 +67,31 @@ class Program {
|
||||
|
||||
static void Menu() {
|
||||
int numeroClienti = 0, scelta = 0, input = 0;
|
||||
bool eccezione;
|
||||
|
||||
do {
|
||||
Console.Write("Quanti clienti considerare? ");
|
||||
|
||||
eccezione = false;
|
||||
try {
|
||||
numeroClienti = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
catch (FormatException) {
|
||||
Console.WriteLine("Numero non valido");
|
||||
eccezione = true;
|
||||
Pausa();
|
||||
}
|
||||
if (!eccezione) {
|
||||
if (numeroClienti <= 0) {
|
||||
Console.WriteLine("Errore: non è possibile considerare meno di un cliente.");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
while (numeroClienti <= 0);
|
||||
}
|
||||
while (eccezione || numeroClienti <= 0);
|
||||
|
||||
Cliente[] clienti = new Cliente[numeroClienti];
|
||||
|
||||
do {
|
||||
Console.WriteLine("Scegliere un'opzione:");
|
||||
Console.WriteLine("1. Inserire i dati dei clienti");
|
||||
@ -81,34 +101,55 @@ class Program {
|
||||
Console.WriteLine("5. Mostra tutte le prenotazioni");
|
||||
Console.WriteLine("0. Esci");
|
||||
Console.Write("Scelta: ");
|
||||
|
||||
eccezione = false;
|
||||
|
||||
try {
|
||||
scelta = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
catch (FormatException) {
|
||||
Console.WriteLine("Opzione non valida");
|
||||
eccezione = true;
|
||||
Pausa();
|
||||
}
|
||||
|
||||
if (!eccezione) {
|
||||
switch (scelta) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
do {
|
||||
Console.WriteLine("Inserire i dati di quale cliente? ");
|
||||
for (int i = 0; i < clienti.Length; i++) {
|
||||
Console.WriteLine(i + 1);
|
||||
}
|
||||
Console.Write("Scelta: ");
|
||||
|
||||
eccezione = false;
|
||||
|
||||
try {
|
||||
input = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
catch (FormatException) {
|
||||
Console.WriteLine("Opzione non valida");
|
||||
eccezione = true;
|
||||
Pausa();
|
||||
}
|
||||
if (!eccezione) {
|
||||
if (input <= 0 || input > numeroClienti) {
|
||||
Console.WriteLine("Opzione non valida");
|
||||
Pausa();
|
||||
}
|
||||
else if (clienti[input - 1] != null) {
|
||||
Console.WriteLine("Errore: i dati di questo cliente sono già stati inseriti.");
|
||||
Pausa();
|
||||
}
|
||||
while (input <= 0 || input > numeroClienti);
|
||||
}
|
||||
}
|
||||
while (eccezione || input <= 0 || input > numeroClienti || clienti[input - 1] != null);
|
||||
|
||||
clienti[input] = CreaCliente();
|
||||
clienti[input - 1] = CreaCliente();
|
||||
Console.WriteLine("Cliente inserito con successo");
|
||||
|
||||
Pausa();
|
||||
break;
|
||||
@ -117,20 +158,31 @@ class Program {
|
||||
int giorniPrenotati = 0, numeroPersone = 0;
|
||||
do {
|
||||
Console.WriteLine("Inserire la prenotazione di quale cliente? ");
|
||||
for (int i = 0; i < clienti.Length; i++) {
|
||||
Console.WriteLine(i + 1);
|
||||
}
|
||||
Console.Write("Scelta: ");
|
||||
|
||||
eccezione = false;
|
||||
|
||||
try {
|
||||
input = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
catch (FormatException) {
|
||||
Console.WriteLine("Opzione non valida");
|
||||
eccezione = true;
|
||||
Pausa();
|
||||
}
|
||||
if (!eccezione) {
|
||||
if (input <= 0 || input > numeroClienti) {
|
||||
Console.WriteLine("Opzione non valida");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
while (input <= 0 || input > numeroClienti);
|
||||
}
|
||||
while (eccezione || input <= 0 || input > numeroClienti);
|
||||
|
||||
scelta = 5;
|
||||
do {
|
||||
Console.WriteLine("Quale periodo dell'anno scegliere?");
|
||||
Console.WriteLine("1. Primavera");
|
||||
@ -138,49 +190,72 @@ class Program {
|
||||
Console.WriteLine("3. Autunno");
|
||||
Console.WriteLine("4. Inverno");
|
||||
Console.Write("Scelta: ");
|
||||
|
||||
eccezione = false;
|
||||
|
||||
try {
|
||||
scelta = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
catch (FormatException) {
|
||||
Console.WriteLine("Opzione non valida");
|
||||
eccezione = true;
|
||||
Pausa();
|
||||
}
|
||||
if (!eccezione) {
|
||||
if (scelta < 1 || scelta > 4) {
|
||||
|
||||
Console.WriteLine("Opzione non valida");
|
||||
Pausa();
|
||||
}
|
||||
} while (scelta < 1 || scelta > 4);
|
||||
}
|
||||
} while (eccezione || scelta < 1 || scelta > 4);
|
||||
|
||||
do {
|
||||
Console.Write("Per quanti giorni prenotare? ");
|
||||
|
||||
eccezione = false;
|
||||
|
||||
try {
|
||||
giorniPrenotati = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
catch (FormatException) {
|
||||
Console.WriteLine("Numero non valido");
|
||||
eccezione = true;
|
||||
Pausa();
|
||||
}
|
||||
if (!eccezione) {
|
||||
if (giorniPrenotati <= 0) {
|
||||
Console.WriteLine("Errore: impossibile prenotare per meno di un giorno.");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
while (giorniPrenotati <= 0);
|
||||
}
|
||||
while (eccezione || giorniPrenotati <= 0);
|
||||
|
||||
do {
|
||||
Console.Write("Per quante persone prenotare? ");
|
||||
|
||||
eccezione = false;
|
||||
|
||||
try {
|
||||
numeroPersone = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
catch (FormatException) {
|
||||
Console.WriteLine("Numero non valido");
|
||||
eccezione = true;
|
||||
Pausa();
|
||||
}
|
||||
if (!eccezione) {
|
||||
if (numeroPersone <= 0) {
|
||||
Console.WriteLine("Errore: impossibile prenotare per meno di una persona.");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
}
|
||||
while (numeroPersone <= 0);
|
||||
|
||||
clienti[input].InserisciPrenotazione(periodi[scelta], Convert.ToString(giorniPrenotati), Convert.ToString(numeroPersone));
|
||||
clienti[input - 1].InserisciPrenotazione(periodi[scelta], Convert.ToString(giorniPrenotati), Convert.ToString(numeroPersone));
|
||||
|
||||
Console.WriteLine("Prenotazione inserita correttamente.");
|
||||
|
||||
Pausa();
|
||||
break;
|
||||
@ -192,9 +267,66 @@ class Program {
|
||||
Pausa();
|
||||
break;
|
||||
case 4:
|
||||
do {
|
||||
Console.WriteLine("Cancellare la prenotazione di quale cliente? ");
|
||||
|
||||
eccezione = false;
|
||||
|
||||
try {
|
||||
input = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
catch (FormatException) {
|
||||
Console.WriteLine("Opzione non valida");
|
||||
eccezione = true;
|
||||
Pausa();
|
||||
}
|
||||
if (!eccezione) {
|
||||
if (input <= 0 || input > numeroClienti) {
|
||||
Console.WriteLine("Opzione non valida");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
}
|
||||
while (eccezione || input <= 0 || input > numeroClienti);
|
||||
|
||||
do {
|
||||
Console.WriteLine("Scegliere una prenotazione:");
|
||||
for (int i = 0; i < clienti[input].GetPrenotazioni().Length; i++) {
|
||||
Console.WriteLine($"{i + 1}. {clienti[input].GetPrenotazioni()[i].GetUUID()}");
|
||||
}
|
||||
Console.Write("Scelta: ");
|
||||
|
||||
eccezione = false;
|
||||
|
||||
try {
|
||||
scelta = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
catch (FormatException) {
|
||||
Console.WriteLine("Opzione non valida");
|
||||
eccezione = true;
|
||||
Pausa();
|
||||
}
|
||||
if (!eccezione) {
|
||||
if (scelta < 1 || scelta > clienti[input].GetPrenotazioni().Length) {
|
||||
Console.WriteLine("Opzione non valida");
|
||||
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);
|
||||
}
|
||||
Pausa();
|
||||
break;
|
||||
case 5:
|
||||
for (int i = 0; i < clienti.Length; i++) {
|
||||
clienti[i].StampaPrenotazioni();
|
||||
}
|
||||
Pausa();
|
||||
break;
|
||||
default:
|
||||
@ -203,13 +335,15 @@ class Program {
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (scelta != 0);
|
||||
}
|
||||
while (eccezione || scelta != 0);
|
||||
}
|
||||
|
||||
static Cliente CreaCliente() {
|
||||
string nome, cognome, codiceFiscale;
|
||||
int eta = 0, prenotazioni = 0;
|
||||
const int MAX_PRENOTAZIONI = 10;
|
||||
bool eccezione;
|
||||
|
||||
do {
|
||||
Console.Write("Inserire il nome: ");
|
||||
@ -243,29 +377,40 @@ class Program {
|
||||
|
||||
do {
|
||||
Console.Write("Inserire l'età: ");
|
||||
|
||||
eccezione = false;
|
||||
|
||||
try {
|
||||
eta = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
catch (FormatException) {
|
||||
Console.WriteLine("Età non valida");
|
||||
eccezione = true;
|
||||
Pausa();
|
||||
}
|
||||
if (!eccezione) {
|
||||
if (eta <= 0) {
|
||||
Console.WriteLine("Errore: non è possibile inserire un'età inferiore a 1");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
while (eta <= 0);
|
||||
}
|
||||
while (eccezione || eta <= 0);
|
||||
|
||||
do {
|
||||
Console.Write("Inserire il numero di prenotazioni: ");
|
||||
|
||||
eccezione = false;
|
||||
|
||||
try {
|
||||
prenotazioni = Convert.ToInt32(Console.ReadLine());
|
||||
}
|
||||
catch (FormatException) {
|
||||
Console.WriteLine("Età non valida");
|
||||
Console.WriteLine("Numero non valido");
|
||||
eccezione = true;
|
||||
Pausa();
|
||||
}
|
||||
if (!eccezione) {
|
||||
if (prenotazioni <= 0) {
|
||||
Console.WriteLine("Errore: non è possibile inserire un numero di prenotazioni inferiore a 1");
|
||||
Pausa();
|
||||
@ -275,7 +420,8 @@ class Program {
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
while (prenotazioni <= 0 && prenotazioni > MAX_PRENOTAZIONI);
|
||||
}
|
||||
while (eccezione || prenotazioni <= 0 || prenotazioni > MAX_PRENOTAZIONI);
|
||||
|
||||
return new Cliente(nome, cognome, codiceFiscale, Convert.ToString(eta), prenotazioni);
|
||||
|
||||
|
||||
BIN
bin/Debug/net9.0/agenzia_viaggi
Executable file
BIN
bin/Debug/net9.0/agenzia_viaggi
Executable file
Binary file not shown.
23
bin/Debug/net9.0/agenzia_viaggi.deps.json
Normal file
23
bin/Debug/net9.0/agenzia_viaggi.deps.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"runtimeTarget": {
|
||||
"name": ".NETCoreApp,Version=v9.0",
|
||||
"signature": ""
|
||||
},
|
||||
"compilationOptions": {},
|
||||
"targets": {
|
||||
".NETCoreApp,Version=v9.0": {
|
||||
"agenzia_viaggi/1.0.0": {
|
||||
"runtime": {
|
||||
"agenzia_viaggi.dll": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"agenzia_viaggi/1.0.0": {
|
||||
"type": "project",
|
||||
"serviceable": false,
|
||||
"sha512": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
bin/Debug/net9.0/agenzia_viaggi.dll
Normal file
BIN
bin/Debug/net9.0/agenzia_viaggi.dll
Normal file
Binary file not shown.
BIN
bin/Debug/net9.0/agenzia_viaggi.pdb
Normal file
BIN
bin/Debug/net9.0/agenzia_viaggi.pdb
Normal file
Binary file not shown.
12
bin/Debug/net9.0/agenzia_viaggi.runtimeconfig.json
Normal file
12
bin/Debug/net9.0/agenzia_viaggi.runtimeconfig.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"tfm": "net9.0",
|
||||
"framework": {
|
||||
"name": "Microsoft.NETCore.App",
|
||||
"version": "9.0.0"
|
||||
},
|
||||
"configProperties": {
|
||||
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -13,10 +13,10 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("agenzia_viaggi")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8e5f3e33fbcd48695682ec39aee4bd41978d057c")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f9184fea2c9646a9d311a20814a0ffb94d3afd4a")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("agenzia_viaggi")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("agenzia_viaggi")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
// Generated by the MSBuild WriteCodeFragment class.
|
||||
// Generato dalla classe WriteCodeFragment di MSBuild.
|
||||
|
||||
|
||||
@ -1 +1 @@
|
||||
f8f6f674141003bac93fe918afe7713f0e7b7f4d36c5021a8ac1373fecaeff14
|
||||
1bc455adbb990f51be8b7d12aa7c0f4dcc419f5750faa87eb217db2284f5c44c
|
||||
|
||||
@ -0,0 +1 @@
|
||||
272511a537020fef9d5058812d4bcfb6bb307ad5010489099043c9b34fa5a981
|
||||
14
obj/Debug/net9.0/agenzia_viaggi.csproj.FileListAbsolute.txt
Normal file
14
obj/Debug/net9.0/agenzia_viaggi.csproj.FileListAbsolute.txt
Normal file
@ -0,0 +1,14 @@
|
||||
/home/Verde/git/agenzia_viaggi/bin/Debug/net9.0/agenzia_viaggi
|
||||
/home/Verde/git/agenzia_viaggi/bin/Debug/net9.0/agenzia_viaggi.deps.json
|
||||
/home/Verde/git/agenzia_viaggi/bin/Debug/net9.0/agenzia_viaggi.runtimeconfig.json
|
||||
/home/Verde/git/agenzia_viaggi/bin/Debug/net9.0/agenzia_viaggi.dll
|
||||
/home/Verde/git/agenzia_viaggi/bin/Debug/net9.0/agenzia_viaggi.pdb
|
||||
/home/Verde/git/agenzia_viaggi/obj/Debug/net9.0/agenzia_viaggi.GeneratedMSBuildEditorConfig.editorconfig
|
||||
/home/Verde/git/agenzia_viaggi/obj/Debug/net9.0/agenzia_viaggi.AssemblyInfoInputs.cache
|
||||
/home/Verde/git/agenzia_viaggi/obj/Debug/net9.0/agenzia_viaggi.AssemblyInfo.cs
|
||||
/home/Verde/git/agenzia_viaggi/obj/Debug/net9.0/agenzia_viaggi.csproj.CoreCompileInputs.cache
|
||||
/home/Verde/git/agenzia_viaggi/obj/Debug/net9.0/agenzia_viaggi.dll
|
||||
/home/Verde/git/agenzia_viaggi/obj/Debug/net9.0/refint/agenzia_viaggi.dll
|
||||
/home/Verde/git/agenzia_viaggi/obj/Debug/net9.0/agenzia_viaggi.pdb
|
||||
/home/Verde/git/agenzia_viaggi/obj/Debug/net9.0/agenzia_viaggi.genruntimeconfig.cache
|
||||
/home/Verde/git/agenzia_viaggi/obj/Debug/net9.0/ref/agenzia_viaggi.dll
|
||||
BIN
obj/Debug/net9.0/agenzia_viaggi.dll
Normal file
BIN
obj/Debug/net9.0/agenzia_viaggi.dll
Normal file
Binary file not shown.
1
obj/Debug/net9.0/agenzia_viaggi.genruntimeconfig.cache
Normal file
1
obj/Debug/net9.0/agenzia_viaggi.genruntimeconfig.cache
Normal file
@ -0,0 +1 @@
|
||||
106d84dc00dd80da38f44a5ee46bdbd9b6bee51edd940c49f882de68d9ebdfc6
|
||||
BIN
obj/Debug/net9.0/agenzia_viaggi.pdb
Normal file
BIN
obj/Debug/net9.0/agenzia_viaggi.pdb
Normal file
Binary file not shown.
BIN
obj/Debug/net9.0/apphost
Executable file
BIN
obj/Debug/net9.0/apphost
Executable file
Binary file not shown.
BIN
obj/Debug/net9.0/ref/agenzia_viaggi.dll
Normal file
BIN
obj/Debug/net9.0/ref/agenzia_viaggi.dll
Normal file
Binary file not shown.
BIN
obj/Debug/net9.0/refint/agenzia_viaggi.dll
Normal file
BIN
obj/Debug/net9.0/refint/agenzia_viaggi.dll
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user