private void buttonCreate_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Passenger passenger = new Passenger();
         Seat seat = new Seat();
         passenger.getUserName = textBoxName.Text;
         passenger.getUserAge = textBoxAge.Text;
         seat.seatID = listBoxSeat.SelectedItem.ToString();
         
         SaveXML.SaveData(passenger, seat.seatID, "passengers.xml");
         MessageBox.Show("You have submitted your name to the flight.");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemple #2
0
 public SeatReservation Reserve(string row, int seatNumber, Passenger passenger)
 {
     return(new SeatReservation(this, row, seatNumber, passenger));
 }
Exemple #3
0
        //add passenger
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //passenger and seat objects
            passenger = new Passenger();
            seat      = new Seat();

            //see what seat column was selected (A, B, C, or D)
            var checkedButton = Controls.OfType <RadioButton>()
                                .FirstOrDefault(r => r.Checked);

            //validate input. Valid name, seat row and selection of seat column is required
            if (!passenger.IsValidPassenger(txtName.Text) || cmbSeatRow.SelectedIndex == -1 ||
                checkedButton == null)
            {
                MessageBox.Show("Please enter valid name and seat", "Invalid Input", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            //check if plane is full. If it is, place passenger on waitig list
            if (seat.IsPlaneFull())
            {
                var msg = MessageBox.Show("The plane is full. Add passenger on waiting list?", "Plane Full",
                                          MessageBoxButtons.YesNo, MessageBoxIcon.Information);

                if (msg == DialogResult.No)
                {
                    return;
                }

                using (var conn = new OleDbConnection(DatabaseObjects.ConnectionString))
                {
                    conn.Open();
                    command = new OleDbCommand("INSERT INTO Passengers (PassengerName, PassengerOnWaitingList) " +
                                               "VALUES (@passengerName, true)", conn);
                    command.Parameters.Add(new OleDbParameter("PassengerName", txtName.Text));
                    command.ExecuteNonQuery();

                    command = new OleDbCommand("INSERT INTO PassengerSeats (PassengerID, SeatID) " +
                                               "SELECT MAX(PassengerID), 0 from Passengers", conn);
                    command.ExecuteNonQuery();

                    MessageBox.Show("Passenger " + txtName.Text + " was added to the waiting list",
                                    "Waiting List", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                return;
            }

            //check if seat is taken. If it is, exit so the user can select a different seat
            if (seat.IsSeatAlreadyTaken(cmbSeatRow.SelectedItem.ToString(), checkedButton.Text))
            {
                MessageBox.Show("The seat is already taken. Please select different seat",
                                "Seat Taken", MessageBoxButtons.OK, MessageBoxIcon.Information);

                return;
            }

            //if everything is OK add passenger and seat to database along with the assigned seat
            //Insert new passenger to Passengers db.
            //Update seat to Taken in Seats db.
            //Insert Passenger and Seat ID in PassengerSeats db
            using (var conn = new OleDbConnection(DatabaseObjects.ConnectionString))
            {
                conn.Open();
                command = new OleDbCommand("INSERT INTO Passengers (PassengerName) " +
                                           "VALUES (@passengerName)", conn);
                command.Parameters.Add(new OleDbParameter("PassengerName", txtName.Text));
                command.ExecuteNonQuery();

                command = new OleDbCommand("UPDATE Seats SET IsTaken = true WHERE " +
                                           "SeatRow = @SeatRow AND SeatColumn = @SeatColumn", conn);
                command.Parameters.Add(new OleDbParameter("SeatRow", cmbSeatRow.Text));
                command.Parameters.Add(new OleDbParameter("SeatColumn", checkedButton.Text));
                command.ExecuteNonQuery();

                command = new OleDbCommand("INSERT INTO PassengerSeats (SeatID, PassengerID) " +
                                           "Select Seats.SeatID, (SELECT MAX(PassengerID) FROM Passengers) " +
                                           "FROM Seats WHERE Seats.SeatRow = @SeatRow AND Seats.SeatColumn = @SeatColumn",
                                           conn);
                command.Parameters.Add(new OleDbParameter("SeatRow", cmbSeatRow.Text));
                command.Parameters.Add(new OleDbParameter("SeatColumn", checkedButton.Text));
                command.ExecuteNonQuery();

                MessageBox.Show("Passenger has been added",
                                "Added Passenger", MessageBoxButtons.OK, MessageBoxIcon.Information);

                PopulateAirplane();
            }
        }
 public void AddNameToManifest(Passenger passenger)
 {
     passengerList.Add(passenger);
 }
Exemple #5
0
        public static Passenger GenerateRandomPassenger()
        {
            string    firstName;
            string    lastName;
            DateTime  birthday = new DateTime();
            Passenger passenger;

            string[] firstMaleName = new string[] { "Keiran", "Danny", "Xander", "Jessy", "Tonny" };
            string[] lastMaleName  = new string[] { "Lee", "Darko", "Corvus", "James", "Ribas" };

            string[] firstFemaleName = new string[] { "Asa", "Jayden", "Peta", "July", "Summer" };
            string[] lastFemaleName  = new string[] { "Akira", "Jones", "Jensen", "May", "Frost" };

            string[] nationality = new string[] { "Japanese", "Espaniol", "Englishman", "Gringo", "Italian" };

            Gender passengerGender = (Gender)rndValue(2);

            if ((byte)passengerGender == 0)
            {
                firstName = firstMaleName[rndValue(firstMaleName.Length)];
                lastName  = lastMaleName[rndValue(lastMaleName.Length)];
            }
            else
            {
                firstName = firstFemaleName[rndValue(firstFemaleName.Length)];
                lastName  = lastFemaleName[rndValue(lastFemaleName.Length)];
            }

            passenger = new Passenger
            {
                FirstName         = firstName,
                LastName          = lastName,
                Nationality       = nationality[rndValue(nationality.Length)],
                PassportPassenger = RandomPassport.GetRandomPassport(),
                Birthday          = birthday,
                PassengerGender   = passengerGender
            };

            //Date of birth filling
            int yearRnd  = rndValue(1950, 2010);
            int monthRnd = rndValue(1, 13);
            int dayRnd   = 0;

            if (monthRnd == 1 || monthRnd == 3 || monthRnd == 5 ||
                monthRnd == 7 || monthRnd == 8 || monthRnd == 10 || monthRnd == 12)
            {
                dayRnd = rndValue(1, 32);
            }
            else if (monthRnd == 4 || monthRnd == 6 || monthRnd == 9 || monthRnd == 11)
            {
                dayRnd = rndValue(1, 31);
            }
            else if (monthRnd == 2)
            {
                if (!DateTime.IsLeapYear(yearRnd))
                {
                    dayRnd = rndValue(1, 29);
                }
                else
                {
                    dayRnd = rndValue(1, 30);
                }
            }
            passenger.Birthday = new DateTime(yearRnd, monthRnd, dayRnd);

            return(passenger);
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            passenger = new Passenger();
            seat      = new Seat();
            var checkedButton = gbRadios.Controls.OfType <RadioButton>().FirstOrDefault(r => r.Checked);

            if (!passenger.IsValidPassenger(txtName.Text) || cmbSeatRow.SelectedIndex == -1 || checkedButton == null)
            {
                MessageBox.Show("Please Enter Valid Name and Seat", "Invalid Input", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            if (seat.IsPlaneFull())
            {
                var msg = MessageBox.Show("Plane is Full.\r\nAdd Passenger on waiting list?",
                                          "Plane is Full", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (msg == DialogResult.No)
                {
                    return;
                }
                else
                {
                    using (var conn = new OleDbConnection(DatabaseObjects.connectionString))
                    {
                        conn.Open();
                        command = new OleDbCommand("INSERT INTO Passengers (PassengerName, PassengerOnWaitingList)" +
                                                   " Values (@passengerName,true)", conn);
                        command.Parameters.Add(new OleDbParameter("passengerName", txtName.Text));
                        command.ExecuteNonQuery();

                        command = new OleDbCommand("INSERT INTO PassengerSeats (PassengerID, SeatID)" + "" +
                                                   "SELECT MAX(PassengerID),0 FROM Passengers", conn);
                        command.ExecuteNonQuery();

                        MessageBox.Show($"Passenger {txtName.Text} was added to the waiting list",
                                        "Waiting List", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    return;
                }
            }

            if (seat.IsSeatAlreadyTaken(cmbSeatRow.SelectedItem.ToString(), checkedButton.Text))
            {
                MessageBox.Show($"The seat is already taken. Please select different seat.",
                                "Seat Taken", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            using (var conn = new OleDbConnection(DatabaseObjects.connectionString))
            {
                conn.Open();
                command = new OleDbCommand("INSERT INTO Passengers (PassengerName)" +
                                           " Values (@passengerName)", conn);
                command.Parameters.Add(new OleDbParameter("passengerName", txtName.Text));
                command.ExecuteNonQuery();

                command = new OleDbCommand("UPDATE Seats SET IsTaken = true WHERE SeatRow = @seatRow AND SeatColumn = @seatColumn", conn);
                command.Parameters.Add(new OleDbParameter("seatRow", cmbSeatRow.Text));
                command.Parameters.Add(new OleDbParameter("seatColumn", checkedButton.Text));
                command.ExecuteNonQuery();

                command = new OleDbCommand("INSERT INTO PassengerSeats (SeatID,PassengerID) " +
                                           "SELECT Seats.SeatID, (SELECT MAX(PassengerID) FROM Passengers) " +
                                           "FROM Seats WHERE Seats.SeatRow = @seatRow AND Seats.SeatColumn = @seatColumn"
                                           , conn);
                command.Parameters.Add(new OleDbParameter("seatRow", cmbSeatRow.Text));
                command.Parameters.Add(new OleDbParameter("seatColumn", checkedButton.Text));
                command.ExecuteNonQuery();

                MessageBox.Show($"Passenger has been added.",
                                "Seat Taken", MessageBoxButtons.OK, MessageBoxIcon.Information);

                PopulateAirplane();
            }
        }