Esempio n. 1
0
        public static bool viewMatchedFlight(string origin, string dest, FlightSeatClass seat,
                                             FlightType type, DateTime dept, DateTime ret)
        {
            int           counter   = 1;
            List <Object> allFlight = FileHandler.GetAllObj(ObjectChoices.Flight);

            foreach (Object obj in allFlight)
            {
                Flight me = (Flight)obj;
                if (me.FlightState == FlightSatus.Scheduled && me.OriginCity.Equals(origin, StringComparison.OrdinalIgnoreCase) &&
                    me.DestinationCity.Equals(dest, StringComparison.OrdinalIgnoreCase) &&
                    me.DepartureDate == dept && me.Type == type)
                {
                    if (type == FlightType.Return && me.ReturnDate != ret)
                    {
                        continue;
                    }
                    if (seat == FlightSeatClass.Buisness && me.BuisnessClassSeat == me.getNumOfBookedSeats(seat))
                    {
                        continue;
                    }
                    if (seat == FlightSeatClass.First && me.FirstClassSeat == me.getNumOfBookedSeats(seat))
                    {
                        continue;
                    }
                    if (seat == FlightSeatClass.Economy && me.EconomyClassSeat == me.getNumOfBookedSeats(seat))
                    {
                        continue;
                    }
                    Console.WriteLine("#" + counter + " : ");
                    Console.WriteLine(me);
                    Console.WriteLine();
                    counter++;
                }
            }
            if (counter == 1)
            {
                Console.WriteLine("No matched flights");
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        public void interact()
        {
            while (true)
            {
                Console.WriteLine(AdminList);
                string     choice = Console.ReadLine();
                DateTime   strt = new DateTime();
                DateTime   end = new DateTime();
                bool       yes = false;
                string     origin, dest, flightType;
                DateTime   dept = new DateTime();
                DateTime   ret = new DateTime();
                string     fare, tp;
                string     firstNum = "", economyNum = "", buisnessNum = "";
                FlightType type     = FlightType.OneWay;
                double     baseFare = 0;
                int        temp;
                string     flightNumber;
                switch (choice)
                {
                case "1":
                    Console.WriteLine("enter the origin city : ");
                    origin = Console.ReadLine();

                    Console.WriteLine("enter the destination city : ");
                    dest = Console.ReadLine();

                    Console.WriteLine("enter the flight type (1 for one way, 2 for return) : ");
                    flightType = Console.ReadLine();
                    if (flightType == "1")
                    {
                        type = FlightType.OneWay;
                    }
                    else if (flightType == "2")
                    {
                        type = FlightType.Return;
                    }
                    else
                    {
                        goto label;
                    }
                    Console.WriteLine("Please, enter the departure date : ");
                    if (!readDate(out dept))
                    {
                        goto label;
                    }

                    if (flightType == "2")
                    {
                        Console.WriteLine("Please, enter the return date : ");
                        if (!readDate(out ret))
                        {
                            if (ret <= dept)
                            {
                                goto label;
                            }
                        }
                    }

                    Console.WriteLine("enter the flight base fare : ");
                    fare = Console.ReadLine();
                    if (double.TryParse(fare, out baseFare))
                    {
                        baseFare = double.Parse(fare);
                    }
                    else
                    {
                        goto label;
                    }

                    Console.WriteLine("please enter the number of seats for the first class : ");
                    firstNum = Console.ReadLine();
                    if (!int.TryParse(firstNum, out temp))
                    {
                        goto label;
                    }

                    Console.WriteLine("please enter the number of seats for the economy class : ");
                    economyNum = Console.ReadLine();
                    if (!int.TryParse(economyNum, out temp))
                    {
                        goto label;
                    }

                    Console.WriteLine("please enter the number of seats for the buisness class : ");
                    buisnessNum = Console.ReadLine();
                    if (!int.TryParse(buisnessNum, out temp))
                    {
                        goto label;
                    }
                    yes = true;
label:
                    if (yes)
                    {
                        Flight neFlight = new Flight(origin, dest, FlightSatus.Scheduled, baseFare,
                                                     int.Parse(firstNum), int.Parse(buisnessNum), int.Parse(economyNum),
                                                     type, dept, ret);
                        FileHandler.Add(ObjectChoices.Flight, neFlight);
                        Console.WriteLine("the flight successfully added");
                    }
                    else
                    {
                        Console.WriteLine("Wrong input for one of the fields");
                    }
                    break;

                case "2":
                    Console.WriteLine("please enter the flight number:");
                    flightNumber = Console.ReadLine();
                    if (SystemHandler.checkInt(flightNumber))
                    {
                        SystemHandler.ViewFlightBooking(int.Parse(flightNumber));
                    }
                    break;

                case "3":
                    SystemHandler.ViewAllFlights();
                    break;

                case "4":
                    Console.WriteLine("please enter the status you want to view\n" +
                                      "(1 for arrived, 2 for cancelled, 3 for scheduled): ");
                    tp = Console.ReadLine();
                    if (SystemHandler.checkInt(tp))
                    {
                        int con = int.Parse(tp);
                        if (con == 1)
                        {
                            SystemHandler.ViewAllFlights(FlightSatus.Arrived);
                        }
                        else if (con == 2)
                        {
                            SystemHandler.ViewAllFlights(FlightSatus.Canclled);
                        }
                        else if (con == 3)
                        {
                            SystemHandler.ViewAllFlights(FlightSatus.Scheduled);
                        }
                        else
                        {
                            Console.WriteLine("wrong input");
                        }
                    }
                    else
                    {
                        Console.WriteLine("wrong input");
                    }
                    break;

                case "5":
                    yes = false;
                    Console.WriteLine("Please enter the start date for the report : ");
                    if (!readDate(out strt))
                    {
                        goto label2;
                    }
                    Console.WriteLine("Please enter the start date for the report : ");
                    if (!readDate(out end))
                    {
                        goto label2;
                    }
                    yes = true;
label2:
                    if (yes)
                    {
                        SystemHandler.ViewStatistics(strt, end);
                    }
                    break;

                case "6":
                    Console.WriteLine("Please, enter the flight number");
                    flightNumber = Console.ReadLine();
                    if (SystemHandler.checkInt(flightNumber))
                    {
                        SystemHandler.ViewFlightBookings(int.Parse(flightNumber), FlightSeatClass.Economy);
                    }
                    else
                    {
                        Console.WriteLine("wrong flight number");
                    }
                    break;

                case "7":
                    Console.WriteLine("Please, enter the flight number");
                    flightNumber = Console.ReadLine();
                    if (SystemHandler.checkInt(flightNumber))
                    {
                        Flight wh = (Flight)FileHandler.Find(ObjectChoices.Flight, flightNumber);
                        if (wh == null)
                        {
                            Console.WriteLine("No such flight exists");
                        }
                        else
                        {
                            Console.WriteLine(wh);
                        }
                    }
                    else
                    {
                        Console.WriteLine("wrong flight number");
                    }
                    break;

                case "8":
                    Console.WriteLine("Please, enter the flight number");
                    flightNumber = Console.ReadLine();
                    if (SystemHandler.checkInt(flightNumber))
                    {
                        Flight me = (Flight)FileHandler.Find(ObjectChoices.Flight, flightNumber);
                        if (me.getNumOfBookedSeats(FlightSeatClass.Buisness) > 0 ||
                            me.getNumOfBookedSeats(FlightSeatClass.First) > 0 ||
                            me.getNumOfBookedSeats(FlightSeatClass.Economy) > 0)
                        {
                            Console.WriteLine("cannot delete the flight\n");
                        }
                        else
                        {
                            FileHandler.Delete(ObjectChoices.Flight, flightNumber);
                            Console.WriteLine("Deleted");
                        }
                    }
                    break;

                case "9":
                    yes = false;
                    Console.WriteLine("Please, enter the start date");
                    if (!readDate(out strt))
                    {
                        goto label3;
                    }
                    Console.WriteLine("Please, enter the end date");
                    if (!readDate(out end))
                    {
                        goto label3;
                    }
                    yes = true;
label3:
                    if (yes)
                    {
                        while (strt <= end)
                        {
                            SystemHandler.OccasionDates.Add(strt);
                            strt = strt.AddDays(1);
                        }
                    }
                    break;

                case "10":
                    Console.WriteLine("Please, enter the flight number");
                    flightNumber = Console.ReadLine();
                    if (SystemHandler.checkInt(flightNumber))
                    {
                        modifyFlightInfo((Flight)FileHandler.Find(ObjectChoices.Flight, flightNumber));
                    }
                    break;

                case "11":
                    foreach (DateTime dt in SystemHandler.OccasionDates)
                    {
                        FileHandler.Add(ObjectChoices.Occasions, dt);
                    }
                    return;

                default:
                    break;
                }
            }
        }