static char EnterTerminal() { bool isCorrect = true; char insertFlightTerminal; //string tempTerminals = "ABCDEFG"; do { CleanerManager.CheckBorder(); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("Enter flight Terminal [A,B,C,D,E,F or G]: "); Console.ForegroundColor = ConsoleColor.DarkGray; insertFlightTerminal = Console.ReadKey().KeyChar; if (Char.IsLetter(insertFlightTerminal)) { if ("ABCDEFG".Contains(insertFlightTerminal)) { isCorrect = false; } } if (isCorrect) { Console.WriteLine("-Incorrect flight letter terminal. Please repeat"); } } while (isCorrect); return(insertFlightTerminal); }
static int EnteredFlightNumber(List <Flight> FlightList) { bool isEnter = true; int IndexFlightNumber = 0, tempFlightNumber; do { CleanerManager.CheckBorder(); Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("Enter flight number: "); Console.ForegroundColor = ConsoleColor.DarkGray; bool isCorrectValue = int.TryParse(Console.ReadLine(), out tempFlightNumber); if (isCorrectValue) { if (tempFlightNumber == 1) { return(IndexFlightNumber = -1); } IndexFlightNumber = FlightList.FindIndex(x => x.FlightNumber == tempFlightNumber); if (IndexFlightNumber == -1) { Console.WriteLine("Number not find.Please entered correct number or '1' for Quit."); } else { isEnter = false; } } else { Console.WriteLine("The number entered not digit"); } } while (isEnter); return(IndexFlightNumber); }
static int EnterPriceTicket(string ClassTicket) { bool isCorrect = true; int insertFlightPrice; do { CleanerManager.CheckBorder(); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write($"Enter the cost of the ticket {ClassTicket} class [1..999]: "); Console.ForegroundColor = ConsoleColor.Gray; bool isDate = int.TryParse(Console.ReadLine(), out insertFlightPrice); if (isDate && insertFlightPrice > 0 && insertFlightPrice < 1000) { isCorrect = false; } else { Console.WriteLine("Incorrect value price. Please repeat"); } } while (isCorrect); return(insertFlightPrice); }
static int EnterGate() { bool isCorrect = true; int insertFlightGate; do { CleanerManager.CheckBorder(); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("Enter flight Gateway [1..9]: "); Console.ForegroundColor = ConsoleColor.Gray; bool isDate = int.TryParse(Console.ReadLine(), out insertFlightGate); if (isDate && insertFlightGate > 0 && insertFlightGate < 10) { isCorrect = false; } else { Console.WriteLine("Incorrect flight gate. Please repeat"); } } while (isCorrect); return(insertFlightGate); }
static byte EnterStatus() { byte insertFlightStatus = 100; Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine(@"Choise flight status (C)heckin, (G)ate closed, (A)rrived, (D)eparted at, (E)xpected at, De(L)ayed, (I)n flight, (U)nknown, Ca(N)celed: "); Console.ForegroundColor = ConsoleColor.Gray; bool isCorrect = true; do { CleanerManager.CheckBorder(); switch (Console.ReadKey().KeyChar) { case 'c': case 'C': insertFlightStatus = 0; isCorrect = false; break; case 'g': case 'G': insertFlightStatus = 1; isCorrect = false; break; case 'a': case 'A': insertFlightStatus = 2; isCorrect = false; break; case 'd': case 'D': insertFlightStatus = 3; isCorrect = false; break; case 'u': case 'U': insertFlightStatus = 4; isCorrect = false; break; case 'n': case 'N': insertFlightStatus = 5; isCorrect = false; break; case 'e': case 'E': insertFlightStatus = 6; isCorrect = false; break; case 'l': case 'L': insertFlightStatus = 7; isCorrect = false; break; case 'i': case 'I': insertFlightStatus = 8; isCorrect = false; break; default: Console.WriteLine("Incorrect choise. Press 'C','G','A','D','E','L','I','U' or 'N'"); break; } } while (isCorrect); return(insertFlightStatus); }
public bool AddToList(List <Flight> FlightList) { NewFlight newFlight = new NewFlight(); DateTime DateStart = DateTime.Now, DateEnd = DateTime.Now.AddYears(1); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("Select direction flight (A)rrival, (D)eparture"); Console.ForegroundColor = ConsoleColor.DarkGray; bool isCorrect = true; do { switch (Console.ReadKey().KeyChar) { case 'a': case 'A': newFlight.insertFlightDirection = 0; isCorrect = false; break; case 'd': case 'D': newFlight.insertFlightDirection = 1; isCorrect = false; break; default: Console.Write("Press 'A' or 'D'"); break; } } while (isCorrect); Console.WriteLine(); isCorrect = true; do { CleanerManager.CheckBorder(); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("Enter date (format YYYY-MM-DD hh:mm): "); Console.ForegroundColor = ConsoleColor.DarkGray; bool isDate = DateTime.TryParse(Console.ReadLine(), out newFlight.insertFlightDate); if (isDate && newFlight.insertFlightDate > DateStart && newFlight.insertFlightDate < DateEnd) { isCorrect = false; } else { Console.WriteLine("Incorrect date(less than this or more than one year) or format. Please repeat"); } } while (isCorrect); isCorrect = true; do { CleanerManager.CheckBorder(); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("Enter Number flight [100..999]: "); Console.ForegroundColor = ConsoleColor.DarkGray; bool isDate = int.TryParse(Console.ReadLine(), out newFlight.insertFlightNumber); if (isDate && newFlight.insertFlightNumber > 99 && newFlight.insertFlightNumber < 1000) { isCorrect = false; foreach (Flight item in FlightList) { if (item != null && item.FlightNumber == newFlight.insertFlightNumber) { Console.WriteLine("A flight number already exists"); isCorrect = true; } } } else { Console.WriteLine("-Incorrect flight number. Please repeat"); } } while (isCorrect); isCorrect = true; do { CleanerManager.CheckBorder(); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("Enter City: "); Console.ForegroundColor = ConsoleColor.DarkGray; newFlight.insertFlightCity = Console.ReadLine(); if (String.IsNullOrWhiteSpace(newFlight.insertFlightCity)) { Console.WriteLine("Strange empty city.Please repeat"); } else { isCorrect = false; } } while (isCorrect); newFlight.insertFlightTerminal = EnterTerminal(); Console.WriteLine(); newFlight.insertFlightGate = EnterGate(); newFlight.insertFlightStatus = EnterStatus(); Console.WriteLine(); newFlight.insertFlightPriceBusiness = EnterPriceTicket("Business"); Console.WriteLine(); newFlight.insertFlightPriceEconomy = EnterPriceTicket("Economy"); Console.WriteLine(); if (newFlight.insertFlightPriceEconomy > newFlight.insertFlightPriceBusiness) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("WARNING!!! Price Economy large Price business!!!"); Console.ForegroundColor = ConsoleColor.Gray; Thread.Sleep(300); } FlightList.Add(new Flight(newFlight)); LogManager.WriteToLog($"Add new flight number {newFlight.insertFlightNumber}"); return(true); }
public bool EditList(List <Flight> FlightList, int enterFlightNumber = -1) { bool isEdit = false, isCorrect = true, isDate = false; int insertFlightNumber; do { CleanerManager.CheckBorder(); if (enterFlightNumber == -1) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("A flight number you want to modify?: "); Console.ForegroundColor = ConsoleColor.DarkGray; isDate = int.TryParse(Console.ReadLine(), out insertFlightNumber); } else { insertFlightNumber = (int)FlightList[enterFlightNumber].FlightNumber; isDate = true; } if (isDate) { int findFlight = FlightList.FindIndex(x => x.FlightNumber == insertFlightNumber); if (findFlight != -1) { Console.WriteLine("What are we going to modify?(T)erminal,(G)ate,(S)tatus,(P)rice Business/Economy or other for Quit"); switch (Console.ReadKey().KeyChar) { case 't': case 'T': FlightList[findFlight].FlightTerminal = EnterTerminal(); isEdit = true; isCorrect = false; break; case 'g': case 'G': FlightList[findFlight].FlightGate = (byte)EnterGate(); isEdit = true; isCorrect = false; break; case 's': case 'S': FlightList[findFlight].ChangeStatus(EnterStatus()); isEdit = true; isCorrect = false; break; case 'p': case 'P': Console.WriteLine($"Current Business price ticket: {FlightList[findFlight].FlightPriceBussiness:C}"); Console.WriteLine($"Current Economy price ticket: {FlightList[findFlight].FlightPriceEconomy:C}"); FlightList[findFlight].FlightPriceBussiness = (decimal)EnterPriceTicket("Business"); FlightList[findFlight].FlightPriceEconomy = (decimal)EnterPriceTicket("Economy"); isEdit = true; isCorrect = false; break; default: isEdit = false; Console.WriteLine("Editing canceled"); isCorrect = false; break; } } else { Console.WriteLine("Flight number not found."); isCorrect = false; } } else { Console.WriteLine("Incorrect flight number. Re-enter (y/N)"); switch (Console.ReadKey().KeyChar) { case 'y': case 'Y': break; default: isCorrect = false; break; } } } while (isCorrect); return(isEdit); }
public bool DeleteFromList(List <Flight> FlightList, int enterFlightNumber = -1) { bool isDelete = false; bool isCorrect = true; int insertFlightNumber; do { CleanerManager.CheckBorder(); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("A flight number you want to delete?: "); Console.ForegroundColor = ConsoleColor.DarkGray; bool isDate = int.TryParse(Console.ReadLine(), out insertFlightNumber); if (isDate) { int findFlight = FlightList.FindIndex(x => x.FlightNumber == insertFlightNumber); if (findFlight != -1) { Console.WriteLine("We are sure that you want to delete the entry?(y/N)"); switch (Console.ReadKey().KeyChar) { case 'y': case 'Y': FlightList.RemoveAt(findFlight); LogManager.WriteToLog($"Delete flight number {insertFlightNumber}"); isDelete = true; isCorrect = false; break; default: isCorrect = false; break; // } } } else { Console.WriteLine("Flight number not found. Re-enter (y/N)"); switch (Console.ReadKey().KeyChar) { case 'y': case 'Y': break; default: isCorrect = false; break; } } } else { Console.WriteLine("Incorrect flight number. Re-enter (y/N)"); switch (Console.ReadKey().KeyChar) { case 'y': case 'Y': break; default: isCorrect = false; break; } } } while (isCorrect); if (isDelete) { FlightList.TrimExcess(); FlightList.Sort(); } return(isDelete); }
public bool AddToList(List <Flight> FlightList) { NewPassenger newPassenger = new NewPassenger(); DateTime DateStart = DateTime.Now, DateEnd = DateTime.Now.AddYears(-120); Console.WriteLine("The operation is allowed only for flights in condition 'CheckIn' or 'Delayed'"); int IndexFlightNumber = EnteredFlightNumber(FlightList); if (IndexFlightNumber == -1) { return(false); } if (FlightList[IndexFlightNumber].FlightFreePlace == 0) { Console.WriteLine("On this flight there are no free places"); return(false); } if (FlightList[IndexFlightNumber].GetFlightStatus() != "CheckIn" && FlightList[IndexFlightNumber].GetFlightStatus() != "Delayed") { Console.WriteLine("Flight status does not allow additional passengers."); return(false); } int freeCell = FlightList[IndexFlightNumber].PassengersList.FindIndex(x => x == null); bool isCorrect = true; do { CleanerManager.CheckBorder(); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("Enter first name: "); Console.ForegroundColor = ConsoleColor.DarkGray; newPassenger.insertPassengerFirstname = Console.ReadLine(); if (String.IsNullOrWhiteSpace(newPassenger.insertPassengerFirstname)) { Console.WriteLine("Strange empty first name.Please repeat"); } else { isCorrect = false; } } while (isCorrect); isCorrect = true; do { CleanerManager.CheckBorder(); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("Enter last name: "); Console.ForegroundColor = ConsoleColor.DarkGray; newPassenger.insertPassengerLastname = Console.ReadLine(); if (String.IsNullOrWhiteSpace(newPassenger.insertPassengerLastname)) { Console.WriteLine("Strange empty last name.Please repeat"); } else { isCorrect = false; } } while (isCorrect); isCorrect = true; do { CleanerManager.CheckBorder(); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("Enter nationality: "); Console.ForegroundColor = ConsoleColor.DarkGray; newPassenger.insertPassengerNationality = Console.ReadLine(); if (String.IsNullOrWhiteSpace(newPassenger.insertPassengerNationality)) { Console.WriteLine("Strange empty nationality.Please repeat"); } else { isCorrect = false; } } while (isCorrect); isCorrect = true; do { CleanerManager.CheckBorder(); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.Write("Enter passpower: "); Console.ForegroundColor = ConsoleColor.DarkGray; newPassenger.insertPassengerPasspower = Console.ReadLine(); if (String.IsNullOrWhiteSpace(newPassenger.insertPassengerPasspower)) { Console.WriteLine("Strange empty passport.Please repeat"); } else { isCorrect = false; } bool isPassport = true; foreach (char item in newPassenger.insertPassengerPasspower) { if (!char.IsLetterOrDigit(item)) { isPassport = false; } } if (!isPassport) { Console.WriteLine("Incoorect symbol in passport"); isCorrect = true; } } while (isCorrect); isCorrect = true; do { CleanerManager.CheckBorder(); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("Enter birthday date passenger (format YYYY-MM-DD): "); Console.ForegroundColor = ConsoleColor.DarkGray; bool isDate = DateTime.TryParse(Console.ReadLine(), out newPassenger.insertPassengerBirthday); if (isDate && newPassenger.insertPassengerBirthday < DateStart && newPassenger.insertPassengerBirthday > DateEnd) { isCorrect = false; } else { Console.WriteLine("Incorrect date(not yet born or long dead) or format. Please repeat"); } } while (isCorrect); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("Select sex passenger (M)ale, (F)emale"); Console.ForegroundColor = ConsoleColor.DarkGray; isCorrect = true; do { switch (Console.ReadKey().KeyChar) { case 'm': case 'M': newPassenger.insertPassengerSex = 0; isCorrect = false; break; case 'f': case 'F': newPassenger.insertPassengerSex = 1; isCorrect = false; break; default: Console.Write("Press 'M' or 'F'"); break; } } while (isCorrect); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("Select class ticket passenger (B)usiness, (E)conomy"); Console.ForegroundColor = ConsoleColor.DarkGray; isCorrect = true; do { switch (Console.ReadKey().KeyChar) { case 'b': case 'B': newPassenger.insertPassengerTicket = 0; isCorrect = false; break; case 'e': case 'E': newPassenger.insertPassengerTicket = 1; isCorrect = false; break; default: Console.Write("Press 'B' or 'E'"); break; } } while (isCorrect); Console.WriteLine(); newPassenger.priceBussiness = FlightList[IndexFlightNumber].FlightPriceBussiness; newPassenger.priceEconomy = FlightList[IndexFlightNumber].FlightPriceEconomy; if (freeCell != -1) { FlightList[IndexFlightNumber].PassengersList[freeCell] = new Passenger(newPassenger); } else { FlightList[IndexFlightNumber].PassengersList.Add(new Passenger(newPassenger)); } LogManager.WriteToLog($"Add passenger {newPassenger.insertPassengerFirstname} {newPassenger.insertPassengerLastname} into flight {FlightList[IndexFlightNumber].FlightNumber}"); return(true); }
public bool EditList(List <Flight> FlightList, int enterFlightNumber = -1) { Console.WriteLine("The operation is allowed only for flights in condition 'CheckIn' or 'Delayed'"); int IndexFlightNumber = enterFlightNumber; if (enterFlightNumber == -1) { IndexFlightNumber = EnteredFlightNumber(FlightList); } if (IndexFlightNumber == -1) { return(false); } if (FlightList[IndexFlightNumber].GetFlightStatus() != "CheckIn" && FlightList[IndexFlightNumber].GetFlightStatus() != "Delayed") { Console.WriteLine("Flight status does not allow passengers to change"); return(false); } if (enterFlightNumber == -1) { this.PrintList(FlightList, IndexFlightNumber); } if (FlightList[IndexFlightNumber].PassengersList.Count == 0) { Console.WriteLine("On this flight no tickets sold"); return(false); } bool isEnter = true; do { CleanerManager.CheckBorder(); int tempFlightNumber; Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("Enter number passenger for edit parameters: "); Console.ForegroundColor = ConsoleColor.DarkGray; bool isCorrectValue = int.TryParse(Console.ReadLine(), out tempFlightNumber); if (isCorrectValue) { if (tempFlightNumber > 0 && tempFlightNumber <= (FlightList[IndexFlightNumber].PassengersList.Count + 1)) { tempFlightNumber--; Passenger item = FlightList[IndexFlightNumber].PassengersList[tempFlightNumber--]; CleanerManager.CheckBorder(); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine($"Current first name: {item.PassengerFirstname}"); Console.Write("Enter first name or press Enter to skip changes: "); Console.ForegroundColor = ConsoleColor.DarkGray; string insertPassengerFirstname = Console.ReadLine(); if (String.IsNullOrWhiteSpace(insertPassengerFirstname)) { Console.WriteLine("Firstname is skip changes."); } else { item.PassengerFirstname = insertPassengerFirstname; } CleanerManager.CheckBorder(); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine($"Current last name: {item.PassengerLastname}"); Console.Write("Enter last name or press Enter to skip changes:: "); Console.ForegroundColor = ConsoleColor.DarkGray; string insertPassengerLastname = Console.ReadLine(); if (String.IsNullOrWhiteSpace(insertPassengerLastname)) { Console.WriteLine("Firstname is skip changes."); } else { item.PassengerLastname = insertPassengerLastname; } bool isCorrect = true; DateTime DateStart = DateTime.Now, DateEnd = DateTime.Now.AddYears(-120), insertPassengerBirthday; do { CleanerManager.CheckBorder(); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("Enter birthday date passenger (format YYYY-MM-DD) or tomorrow's date to skip changes: "); Console.ForegroundColor = ConsoleColor.DarkGray; bool isDate = DateTime.TryParse(Console.ReadLine(), out insertPassengerBirthday); if (isDate) { if (insertPassengerBirthday < DateStart && insertPassengerBirthday > DateEnd) { item.PassengerBirthday = insertPassengerBirthday; isCorrect = false; } else { Console.WriteLine("Entered date is out of range. Birthday skip changes."); isCorrect = false; } } else { Console.WriteLine("Incorrect date format. Please repeat"); } } while (isCorrect); isEnter = false; } else { Console.WriteLine("Number passenger out of range"); } } else { Console.WriteLine("Number passenger is not digit"); } } while (isEnter); return(true); }
public bool DeleteFromList(List <Flight> FlightList, int enterFlightNumber = -1) { Console.WriteLine("The operation is allowed only for flights in condition 'CheckIn' or 'Delayed'"); int IndexFlightNumber = enterFlightNumber; if (enterFlightNumber == -1) { IndexFlightNumber = EnteredFlightNumber(FlightList); } if (IndexFlightNumber == -1) { return(false); } if (FlightList[IndexFlightNumber].GetFlightStatus() != "CheckIn" && FlightList[IndexFlightNumber].GetFlightStatus() != "Delayed") { Console.WriteLine("Flight status does not allow passengers to remove"); return(false); } if (enterFlightNumber == -1) { this.PrintList(FlightList, IndexFlightNumber); } if (FlightList[IndexFlightNumber].PassengersList.Count == 0) { Console.WriteLine("On this flight no tickets sold"); return(false); } bool isEnter = true; do { CleanerManager.CheckBorder(); int indexPassenger; Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("Enter number passenger for delete: "); Console.ForegroundColor = ConsoleColor.DarkGray; bool isCorrectValue = int.TryParse(Console.ReadLine(), out indexPassenger); if (isCorrectValue) { if (indexPassenger > 0 && indexPassenger <= (FlightList[IndexFlightNumber].PassengersList.Count + 1)) { indexPassenger--; FlightList[IndexFlightNumber].PassengersList.RemoveAt(indexPassenger); LogManager.WriteToLog($"Remove passenger from flight {FlightList[IndexFlightNumber].FlightNumber}"); isEnter = false; FlightList[IndexFlightNumber].PassengersList.TrimExcess(); } else { Console.WriteLine("Number passenger out of range"); } } else { Console.WriteLine("Number passenger is not digit"); } } while (isEnter); return(true); }