コード例 #1
0
        private string ParseOption(AirlineOptions flightOption)
        {
            var option = flightOption.ToString();

            option = string.Concat(option.Select(c => char.IsUpper(c) ? " " + c.ToString().ToLower() : c.ToString())).TrimStart();
            option = char.ToUpper(option[0]) + option.Substring(1);
            return(option);
        }
コード例 #2
0
        /// <summary>
        /// Processes and prepare functioanlity depending on the options received
        /// </summary>
        /// <param name="option">Received option</param>
        public void SelectOptions(string option)
        {
            int optionId = 0;

            CurrentAirlineManager = this;
            if ((int.TryParse(option, out optionId)) && (optionId > 0) && (optionId < Options.Count + 1))
            {
                //var AirlineOption = Options[optionId - 1];
                _selectedOption = Options[optionId - 1];
                MultipleOption  = MultipleOptions.Contains(_selectedOption);
                NeedOption      = !NoNeedOptions.Contains(_selectedOption);
                OnDisplayInfoChanged(new AirlineObjectEventArgs {
                    DisplayInfo = ParseOption(_selectedOption), ClearConsoleLine = true, ConsoleColor = ConsoleColor.DarkYellow
                });
                if (EditableOptions.Contains(_selectedOption))
                {
                    OnDisplayInfoChanged(new AirlineObjectEventArgs
                    {
                        DisplayInfo = "Use the column names, " +
                                      "then please use eq - equals/gt - greater than/lt - lower than for applying the values like 'FlightNumber eq RG24'\n" +
                                      "For editing the airlineObject you should put ID filed on first place like 'ID eq 1'\n" +
                                      "For deleting the airlineObject it's enough to provide just id like '1'\n",
                        ConsoleColor = ConsoleColor.Blue
                    });
                }
                if (IsServiceOptionNow)
                {
                    OnDisplayInfoChanged(new AirlineObjectEventArgs {
                        DisplayInfo = "Please type path to file below :"
                    });
                }
            }
            else
            {
                OnDisplayInfoChanged(new AirlineObjectEventArgs {
                    HasError = true, ConsoleColor = ConsoleColor.Red, DisplayInfo = "WRONG OPTION!!!!"
                });
                CurrentAirlineObjects = null;
                _selectedOption       = AirlineOptions.NULL;
            }
        }
コード例 #3
0
        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;
            }
        }
コード例 #4
0
 /// <summary>
 /// Resets the default values
 /// </summary>
 public virtual void Reset()
 {
     NeedOption      = false;
     MultipleOption  = false;
     _selectedOption = AirlineOptions.NULL;
 }
コード例 #5
0
        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;
            }
        }