public override void ProcessOptions(string[] values) { var id = 0; switch (_selectedOption) { case AirlineOptions.ShowPassangers: CurrentAirlineObjects = AirlineObjects.Where(arg => (arg as Passenger) != null).ToArray(); Options = new AirlineOptions[s_general.Length + s_edit.Length]; s_edit.CopyTo(Options, 0); s_general.CopyTo(Options, s_edit.Length); break; case AirlineOptions.SearchPassangers: if (values.Length > 0) { Find(values); } else { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true }); } Options = new AirlineOptions[s_general.Length + s_edit.Length]; s_edit.CopyTo(Options, 0); s_general.CopyTo(Options, s_edit.Length); break; case AirlineOptions.AddAPassanger: if (values.Length > 0) { if (Add(values, new Passenger(), null)) { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "The Passanger has been added successfully", ConsoleColor = ConsoleColor.Green }); } else { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "The Passanger wasn't added", ConsoleColor = ConsoleColor.Red, HasError = true }); } } else { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true }); } CurrentAirlineObjects = AirlineObjects.ToArray(); Options = new AirlineOptions[s_general.Length + s_edit.Length]; s_edit.CopyTo(Options, 0); s_general.CopyTo(Options, s_edit.Length); break; case AirlineOptions.EditThePassanger: if (values.Length > 0) { if (Edit(values)) { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "The Passanger has been edited successfully", ConsoleColor = ConsoleColor.Green }); } } else { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true }); } CurrentAirlineObjects = AirlineObjects.ToArray(); Options = new AirlineOptions[s_general.Length + s_edit.Length]; s_edit.CopyTo(Options, 0); s_general.CopyTo(Options, s_edit.Length); break; case AirlineOptions.DeleteThePassanger: if (values.Length > 0) { var optionsArray = values[0].Split(' '); if ((optionsArray.Length == 3) && (int.TryParse(optionsArray[2], out id)) && (id > 0) && (id < CurrentAirlineObjects.Length + 1)) { if (Delete(CurrentAirlineObjects[id - 1])) { CurrentAirlineObjects = AirlineObjects.ToArray(); OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "Removed Successfully" }); } } } else { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true }); } Options = new AirlineOptions[s_general.Length + s_edit.Length]; s_edit.CopyTo(Options, 0); s_general.CopyTo(Options, s_edit.Length); break; case AirlineOptions.ClearTheConsole: OnDisplayInfoChanged(new AirlineObjectEventArgs { ClearConsole = true }); CurrentAirlineObjects = null; Options = s_general; break; case AirlineOptions.Info: OnDisplayInfoChanged(new AirlineObjectEventArgs { ConsoleColor = ConsoleColor.Yellow, DisplayInfo = "You are inside flight where you can work with passangers and it's info, \n" + "In case if you need to go back to Airline manager, just chose 'Exit or level up' menu item" }); CurrentAirlineObjects = null; Options = s_general; break; case AirlineOptions.ExitOrLevelUp: CurrentAirlineManager = null; CurrentAirlineObjects = null; Options = s_general; Reset(); break; } }
public override void ProcessOptions(string[] values) { var id = 0; switch (_selectedOption) { case AirlineOptions.ShowAllFlights: CurrentAirlineObjects = AirlineObjects.Where(arg => (arg as Flight) != null).ToArray(); if (CurrentAirlineObjects.Length > 0) { Options = new AirlineOptions[s_general.Length + s_edit.Length]; s_edit.CopyTo(Options, 0); s_general.CopyTo(Options, s_edit.Length); } break; case AirlineOptions.ShowArrivals: CurrentAirlineObjects = AirlineObjects.Where(arg => (arg as Flight) != null && ((Flight)arg).Type == FlightType.Arrival).ToArray(); if (CurrentAirlineObjects.Length > 0) { Options = new AirlineOptions[s_general.Length + s_edit.Length]; s_edit.CopyTo(Options, 0); s_general.CopyTo(Options, s_edit.Length); } break; case AirlineOptions.ShowDepartues: CurrentAirlineObjects = AirlineObjects.Where(arg => (arg as Flight) != null && ((Flight)arg).Type == FlightType.Departure).ToArray(); if (CurrentAirlineObjects.Length > 0) { Options = new AirlineOptions[s_general.Length + s_edit.Length]; s_edit.CopyTo(Options, 0); s_general.CopyTo(Options, s_edit.Length); } break; case AirlineOptions.SearchFlights: if (values.Length > 0) { Find(values); } else { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true }); } Options = new AirlineOptions[s_general.Length + s_edit.Length]; s_edit.CopyTo(Options, 0); s_general.CopyTo(Options, s_edit.Length); break; case AirlineOptions.AddAFlight: if (values.Length > 0) { if (Add(values, new Flight(), new Passenger[0])) { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "The Flight has been added successfully", ConsoleColor = ConsoleColor.Green }); } else { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "The Flight wasn't added", ConsoleColor = ConsoleColor.Red, HasError = true }); } } else { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true }); } CurrentAirlineObjects = AirlineObjects.ToArray(); Options = new AirlineOptions[s_general.Length + s_edit.Length]; s_edit.CopyTo(Options, 0); s_general.CopyTo(Options, s_edit.Length); break; case AirlineOptions.EditTheFlight: if (values.Length > 0) { if (Edit(values)) { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "The Flight has been edited successfully", ConsoleColor = ConsoleColor.Green }); } } else { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true }); } CurrentAirlineObjects = AirlineObjects.ToArray(); Options = new AirlineOptions[s_general.Length + s_edit.Length]; s_edit.CopyTo(Options, 0); s_general.CopyTo(Options, s_edit.Length); break; case AirlineOptions.EditPassangersOfTheFlight: if (values.Length > 0) { var optionsArray = values[0].Split(' '); if ((optionsArray.Length == 3) && (int.TryParse(optionsArray[2], out id)) && (id > 0) && (id < CurrentAirlineObjects.Length + 1)) { var flight = CurrentAirlineObjects[id - 1] as Flight; if (flight != null) { IndexOfCurrentAirlineManager = id - 1; CurrentAirlineManager = flight; } } } CurrentAirlineObjects = null; Options = s_general; break; case AirlineOptions.DeleteTheFlight: if (values.Length > 0) { var optionsArray = values[0].Split(' '); if ((optionsArray.Length == 3) && (int.TryParse(optionsArray[2], out id)) && (id > 0) && (id < CurrentAirlineObjects.Length + 1)) { if (Delete(CurrentAirlineObjects[id - 1])) { CurrentAirlineObjects = AirlineObjects.ToArray(); OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "Removed Successfully" }); } } } else { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true }); } Options = new AirlineOptions[s_general.Length + s_edit.Length]; s_edit.CopyTo(Options, 0); s_general.CopyTo(Options, s_edit.Length); break; case AirlineOptions.ClearTheConsole: OnDisplayInfoChanged(new AirlineObjectEventArgs { ClearConsole = true }); CurrentAirlineObjects = null; Options = s_general; break; case AirlineOptions.Info: OnDisplayInfoChanged(new AirlineObjectEventArgs { ConsoleColor = ConsoleColor.Yellow, DisplayInfo = "You are inside Airport manager where you can work with flights and it's info, " + "if you would like to receive an information about passanger and edit it, please go to 'Edit passangers of the flight'.\n" + "In case if you need to exit from Application, just chose 'Exit or level up' menu item" }); CurrentAirlineObjects = null; Options = s_general; break; case AirlineOptions.LoadFromFile: if (values.Length > 0) { try { if (OpenFromFile(values[0])) { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "Loaded successfully", ConsoleColor = ConsoleColor.Green }); CurrentAirlineObjects = AirlineObjects.ToArray(); } else { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "Can't load from file", ConsoleColor = ConsoleColor.Red, HasError = true }); } } catch (Exception ex) { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = $"Couldn't load data from file because of: {ex.Message}", ConsoleColor = ConsoleColor.Red, HasError = true }); } } else { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true }); } break; case AirlineOptions.SaveToFile: if (values.Length > 0) { try { if (SaveToFile(values[0])) { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "Saved successfully", ConsoleColor = ConsoleColor.Green }); } else { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "Can't save to file", ConsoleColor = ConsoleColor.Red, HasError = true }); } } catch (Exception ex) { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = $"Couldn't save data to file because of: {ex.Message}", ConsoleColor = ConsoleColor.Red, HasError = true }); } } else { OnDisplayInfoChanged(new AirlineObjectEventArgs { DisplayInfo = "Empty values provided", ConsoleColor = ConsoleColor.Red, HasError = true }); } break; case AirlineOptions.ExitOrLevelUp: CurrentAirlineManager = null; CurrentAirlineObjects = null; Options = s_general; Reset(); break; } }