Exemple #1
0
        private void btnShowPassengers_Click(object sender, EventArgs e)
        {
            //display all passenger in lookup form
            frmPassengerLookup form = new frmPassengerLookup("view");

            form.ShowDialog();

            //must open it in viewOnly mode
        }
Exemple #2
0
        private void btnDeletePessenger_Click(object sender, EventArgs e)
        {
            //enter name and validate it
            var name = txtName.Text.Trim();

            if (name == "")
            {
                MessageBox.Show("Please enter passenger's name", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //if valid input, create passenger that matches the name of passenger to be deleted
            // search for passenger to delete
            var passenger = new Passenger(name);

            foundPassengers = passenger.GetPassengersByName(name);

            //check if no passenger is found
            if (foundPassengers.Count() == 0)
            {
                MessageBox.Show("Passenger " + name + " does not exist", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //if passenger exists, open lookup form and display name there
            frmPassengerLookup form = new frmPassengerLookup("delete");

            form.ShowDialog();

            //if user canceleed operation we just return; otherwise we procced to delete passanger
            if (form.isOperationCancelled)
            {
                return;
            }

            //assign the passenger object to be deleted and populate the text boxes with the details
            passenger       = form.passenger;
            txtName.Text    = passenger.Name;
            mtbSeatRow.Text = passenger.SeatRow.ToString();
            mtbSeatCol.Text = passenger.SeatColumn;

            //ask user to confirm deletion
            var msg = MessageBox.Show("Delete Passenger?", "Delete",
                                      MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

            //if deletes is true
            if (msg == DialogResult.Yes)
            {
                //delete passenger from list
                passenger.RemovePassenger(passenger);

                //check if anyone is on waitng list and move the first passenger from wait list
                if (passenger.NumberOfSeatedPassengers() == 39 && passenger.NumberOfWaitingPassengers() > 0)
                {
                    var index = passengers.FindIndex(p => p.IsOnWaitingList == true);

                    passengers[index].SeatRow    = Convert.ToInt32(mtbSeatRow.Text);
                    passengers[index].SeatColumn = mtbSeatCol.Text;

                    //remove that passenger from the waiting list
                    passengers[index].IsOnWaitingList = false;

                    //display massege that we are removed passenger from the lsit
                    MessageBox.Show("Passenger " + txtName.Text + " was removed from the list" + Environment.NewLine +
                                    passengers[index].Name + " was moved from the waiting list to seat " +
                                    mtbSeatRow.Text + mtbSeatCol.Text, "Passengers Removed/Moved", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                //clear form and upade the seating chart
                ClearForm();
                PopulateAirplane();
            }
        }