// <<<<<<<<<<<<<<<<< EDIT BUTTONS >>>>>>>>>>>>>>>>>>>>>>
        private void btnSave_Click(object sender, EventArgs e)
        {
            Airport local = MatchAirportList((Airport)listBoxAirports.CurrentRow.DataBoundItem);

            if (CheckCity() && CheckCountry() && CheckShort())
            {
                Airport airportNew = new Airport(local.InternId,
                                                 Usefull.UpperCase(textBoxCity.Text),
                                                 Usefull.UpperCase(textBoxCountry.Text),
                                                 tbShortName.Text.ToUpper(),
                                                 Usefull.UpperCase(tbAirportName.Text));

                if (AirportExists(airportNew))
                {
                    local.Name              = Usefull.UpperCase(tbAirportName.Text);
                    local.Country           = Usefull.UpperCase(textBoxCountry.Text);
                    local.City              = Usefull.UpperCase(textBoxCity.Text);
                    local.IATA              = tbShortName.Text.ToUpper();
                    listBoxAirports.Enabled = true;
                    gbEditor.Visible        = false;
                    RefreshList();
                    ClearFields();
                }
            }
        }
        private bool AirportExists(Airport airportNew)
        {
            var result = Airports.Where(a => a.InternId == airportNew.InternId);

            if (result.ToList().Count == 1)//when in edition mode the result will return 1
            {
                return(true);
            }
            else//the result will return 0 because it's a new airport
            {
                var checkName = Airports.Where(a => a.IATA == airportNew.IATA);//this will check for a repeated IATA code
                if (checkName.ToList().Count != 0)
                {
                    MessageBox.Show($"You already have an Airport connection to {Usefull.UpperCase(textBoxCity.Text)}!", "Cannot add Airport!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
                return(true);
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (CheckCity() && CheckCountry() && CheckShort())//checks for empty TBs and returns error if true!
            {
                Airport airportNew = new Airport(NextNumber(),
                                                 Usefull.UpperCase(textBoxCity.Text),
                                                 Usefull.UpperCase(textBoxCountry.Text),
                                                 tbShortName.Text.ToUpper(),
                                                 Usefull.UpperCase(tbAirportName.Text));

                //checks if there is a airport with the same IATA code
                if (AirportExists(airportNew))
                {
                    Airports.Add(airportNew);
                    RefreshList();
                    ClearFields();
                    //not sure if this is correct but cleans the search list
                    BtnClean_Click(sender, e);
                }
            }
        }
Ejemplo n.º 4
0
        //<<<<<<<<<<<<<<<<<<<<<<<<<<< BUTTONS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        private void btnCheckIn_Click(object sender, EventArgs e)
        {
            if (IsEmailValid(tbEmail.Text))
            {
                //variables
                string name      = Usefull.UpperCase(tbName.Text) + " " + Usefull.UpperCase(tbLastName.Text);
                string internId  = MakeId(name);
                string id        = tbIdentification.Text;
                string email     = tbEmail.Text;
                string gender    = GetGender();
                string seat      = cbSeats.Text;
                string seatClass = GetClass();

                //creates a new passenger
                Passenger newPassenger = new Passenger(internId, name, id, email, gender, seat, seatClass);

                //adds the seat to the taken seats in the plane
                toBook.TakenSeats.Add(cbSeats.Text);
                //adds the passenger to the plane
                toBook.Tickets.Add(newPassenger);

                //creates the boarding pass
                FillPDF(newPassenger, toBook);

                MessageBox.Show($"The Boarding Pass for passenger {name} was created.");

                ShowPDF showPDF = new ShowPDF(this, toBook.FlightNumber, newPassenger);
                showPDF.ShowDialog();

                BackToSearch();
            }
            else
            {
                MessageBox.Show("The email provided is invalid.");
            }
        }
        /// <summary>
        /// searches for airports in a list of all world airports with a user inputed city
        /// </summary>
        /// <returns></returns>
        private Task <List <Airport> > GetAirport()
        {
            var result = AllAirports.Where(a => a.City.StartsWith(Usefull.UpperCase(textBoxCity.Text)));

            return(Task.FromResult(result.ToList()));
        }