Пример #1
0
        //Compare flights
        public int CompareTo(object obj)
        {
            FlightDetails temp = obj as FlightDetails;

            return(this.flight.Time.CompareTo(temp.flight.Time));
        }
Пример #2
0
        //Triggers on form submit checks all input fields and validates them. If all correct inputs the details in the DB for that flights.
        private void btnAddFlightDetails_Click(object sender, EventArgs e)
        {
            string validacija         = "";
            var    destinationCountry = "";

            //Validation of destination country
            if (comboBoxCountries.Visible)
            {
                if (comboBoxCountries.Text == "")
                {
                    lblErrorDestinationCountry.Visible = true;
                    lblErrorDestinationCountry.Text    = "You have to choose the destination country!";
                }
                else
                {
                    lblErrorDestinationCountry.Visible = false;
                    destinationCountry = comboBoxCountries.Text;
                    validacija         = validacija + "1";
                }
            }
            else if (textBoxNewCountry.Visible)
            {
                if (textBoxNewCountry.Text == "")
                {
                    lblErrorDestinationCountry.Visible = true;
                    lblErrorDestinationCountry.Text    = "You can't leave the destination country field empty!";
                }
                else if (textBoxNewCountry.Text[0].ToString() != textBoxNewCountry.Text[0].ToString().ToUpper())
                {
                    lblErrorDestinationCountry.Visible = true;
                    lblErrorDestinationCountry.Text    = "The destination country can't have a lowercase letter as its first letter!";
                }
                else
                {
                    destinationCountry = textBoxNewCountry.Text;
                    lblErrorDestinationCountry.Visible = false;
                    validacija = validacija + "1";
                }
            }
            //Validation of hour duration
            if (numericUpDownHours.Value < 0)
            {
                lblErrorHours.Visible = true;
                lblErrorHours.Text    = "Hours can't be less then 1!";
            }
            else if (numericUpDownHours.Value == 0 && numericUpDownMinutes.Value <= 0)
            {
                lblErrorHours.Visible = true;
                lblErrorHours.Text    = "Hours can't be zero!";
            }
            else
            {
                lblErrorHours.Visible = false;
                validacija            = validacija + "2";
            }
            //Validation of minute duration
            if (numericUpDownMinutes.Value < 0)
            {
                lblErrorMinutes.Visible = true;
                lblErrorMinutes.Text    = "Minutes can't be less then 1!";
            }
            else if (numericUpDownHours.Value <= 0 && numericUpDownMinutes.Value == 0)
            {
                lblErrorMinutes.Visible = true;
                lblErrorMinutes.Text    = "Minutes can't be zero!";
            }
            else if (numericUpDownMinutes.Value > 59)
            {
                lblErrorMinutes.Visible = true;
                lblErrorMinutes.Text    = "Minutes can't bigger than 59!";
            }
            else
            {
                lblErrorMinutes.Visible = false;
                validacija = validacija + "3";
            }
            //Validation of flight price
            if (numericUpDownPrice.Value == 0)
            {
                lblErrorFlightPrice.Visible = true;
                lblErrorFlightPrice.Text    = "Price can't be zero!";
            }
            else if (numericUpDownPrice.Value < 0)
            {
                lblErrorFlightPrice.Visible = true;
                lblErrorFlightPrice.Text    = "Price can't be negative!";
            }
            else
            {
                lblErrorFlightPrice.Visible = false;
                validacija = validacija + "4";
            }
            //Validation of passanger number
            if (numericUpDownNumOfPassangers.Value == 0 || numericUpDownNumOfPassangers.Value < 0)
            {
                lblErrorNumOfPassangers.Visible = true;
                lblErrorNumOfPassangers.Text    = "Passangers can't be less then 1!";
            }
            else
            {
                lblErrorNumOfPassangers.Visible = false;
                validacija = validacija + "5";
            }
            if (validacija == "12345")
            {
                string originCountry = String.Concat(lblCountryOfOrigin.Text.Where(c => !Char.IsWhiteSpace(c)));
                originCountry = originCountry.Substring(14);
                int           flightId      = Convert.ToInt32(lblFlightId.Text.Substring(11));
                FlightDetails flightDetails = new FlightDetails
                {
                    originCountry      = originCountry,
                    flightId           = flightId,
                    destinationCountry = destinationCountry,
                    flightDuration     = numericUpDownHours.Value + ":" + numericUpDownMinutes.Value,
                    flightPrice        = numericUpDownPrice.Value,
                    numberOfPassangers = Convert.ToInt32(numericUpDownNumOfPassangers.Value)
                };
                fR.UpdateFlightInDBWithTheDetails(flightDetails);
                panelAddDetails.Visible = false;
            }
            else
            {
                btnAddFlightDetails.Text = "Error, try again..";
            }
        }
Пример #3
0
        //Method to split data into lists
        private void AddToLists <T>(List <T> data, List <FlightDetails> listToAddTo)
        {
            foreach (T f in data)
            {
                string t             = "",
                       date          = "",
                       airlineCode   = "",
                       town          = "",
                       flightCode    = "";
                Flights typeOfFlight = f as Flights;

                if (typeOfFlight.Cancelled == false && typeOfFlight.ProgressPercentage == 100)
                {
                    if (f.GetType() == typeof(ArrivalFlights))
                    {
                        ArrivalFlights arrival = f as ArrivalFlights;
                        t           = arrival.ArrivalTime.Time;
                        date        = arrival.ArrivalTime.Date;
                        airlineCode = arrival.AirlineCode;
                        town        = SplitTownName(arrival.Origin.City);
                        flightCode  = arrival.FlightID;
                    }
                    else if (f.GetType() == typeof(DepartureFlights))
                    {
                        DepartureFlights departure = f as DepartureFlights;
                        t           = departure.DepartureTime.Time;
                        date        = departure.DepartureTime.Date;
                        airlineCode = departure.AirlineCode;
                        town        = SplitTownName(departure.Destination.City);
                        flightCode  = departure.FlightID;
                    }
                }
                else if (typeOfFlight.Cancelled == true || typeOfFlight.ProgressPercentage == -1)
                {
                    if (f.GetType() == typeof(ArrivalFlights))
                    {
                        ArrivalFlights arrival = f as ArrivalFlights;
                        t           = arrival.EstimatedArrivalTime.Time;
                        date        = arrival.EstimatedArrivalTime.Date;
                        airlineCode = arrival.AirlineCode;
                        town        = SplitTownName(arrival.Origin.City);
                        flightCode  = arrival.FlightID;
                    }
                    else if (f.GetType() == typeof(DepartureFlights))
                    {
                        DepartureFlights departure = f as DepartureFlights;
                        t           = departure.EstimatedDepartureTime.Time;
                        date        = departure.EstimatedDepartureTime.Date;
                        airlineCode = departure.AirlineCode;
                        town        = SplitTownName(departure.Destination.City);
                        flightCode  = departure.FlightID;
                    }
                }

                if (t != "" && town != "" && flightCode != "" && date != "")
                {
                    Flight        flight = new Flight(t, date, airlineCode + flightCode, town);
                    FlightDetails detail = new FlightDetails(flight);
                    listToAddTo.Add(detail);
                }
                else
                {
                    continue;
                }
            }
        }