Example #1
0
 private void ContextMenuStrip_Reservations_Opening(object sender, CancelEventArgs e)
 {
     if (listView_Reservations.SelectedItems.Count == 0)
     {
         e.Cancel = true;
     }
     else
     {
         // dont open context menu if the boarding pass is already issued.
         BoardingPass boardingPass = BoardingPasses[listView_Reservations.SelectedItems[0].Index];
         if (boardingPass.Issued)
         {
             e.Cancel = true;
         }
     }
 }
Example #2
0
        private void IssueBoardingPassToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bool discount = false;

            if (listView_Reservations.SelectedItems.Count > 0)
            {
label1:

                BoardingPass boardingPass = BoardingPasses[listView_Reservations.SelectedItems[0].Index];

                List <Seat> seats = boardingPass.Flight.Seats.FindAll(x => x.Class == boardingPass.Class && x.PassengerID == 0);

                if (seats.Count == 0)
                {
                    MessageBox.Show("The flight is now full. This passenger will be rebooked on the next available flight.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    Flight f = new Flight();
                    foreach (var flight in Database.GetFlights().FindAll(x => x.ID != boardingPass.FlightID && x.EndDestination.ToString() == boardingPass.Flight.EndDestination.ToString()))
                    {
                        f = flight;
                        break;
                    }
                    if (f.ID != 0)
                    {
                        discount = true;
                        boardingPass.FlightID = f.ID;
                        boardingPass.SeatID   = 0;
                        goto label1;
                    }
                    else
                    {
                        MessageBox.Show("Failed to reschedule, please manually reschedule passenger.");
                        return;
                    }
                }

                SeatingPreference preference = (SeatingPreference)comboBox_Preference.SelectedIndex;
                Seat selectedSeat            = null;
Begin:
                // find a passengers seat.
                foreach (var seat in seats)
                {
                    string seatColumn = Regex.Replace(seat.SeatNumber, "[^A-Z]", "");
                    if (seat.PassengerID == 0 && preference == SeatingPreference.Window && (seatColumn == "A" || seatColumn == "J"))
                    {
                        selectedSeat = seat;
                        break;
                    }
                    else if (seat.PassengerID == 0 && preference == SeatingPreference.Isle && (seatColumn == "C" || seatColumn == "D" || seatColumn == "G" || seatColumn == "H"))
                    {
                        selectedSeat = seat;
                        break;
                    }
                    else if (seat.PassengerID == 0 && preference == SeatingPreference.Middle && (seatColumn == "B" || seatColumn == "E" || seatColumn == "F" || seatColumn == "I"))
                    {
                        selectedSeat = seat;
                        break;
                    }
                    else if (seat.PassengerID == 0 && preference == SeatingPreference.None)
                    {
                        selectedSeat = seat;
                        break;
                    }
                }
                if (selectedSeat == null) // seating preference could not be fufiled.
                {
                    if (MessageBox.Show("The seating preference for this passenger cannot be fulfilled. Would you like to put passenger in any seat? ", "Cant Issue Seat", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        preference = SeatingPreference.None;
                        goto Begin;
                    }
                    else
                    {
                        return;
                    }
                }

                boardingPass.SeatID = selectedSeat.ID;
                boardingPass.Issued = true;

                int seatPrice = 0;
                if (boardingPass.Class == "First Class")
                {
                    seatPrice = 300;
                }
                else if (boardingPass.Class == "Business Class")
                {
                    seatPrice = 200;
                }
                Passenger.Cost += (boardingPass.Flight.Price + seatPrice);

                if (discount)
                {
                    Passenger.Cost -= ((boardingPass.Flight.Price + seatPrice) * (decimal)0.10);
                }

                textBox_Cost.Text = Passenger.Cost.ToString();
                BoardingPasses[listView_Reservations.SelectedItems[0].Index] = boardingPass;
                IssuedBoardingPasses.Add(boardingPass);
                LoadFormData();
            }
        }