Esempio n. 1
0
        /// <summary>
        /// Gets the Passengers on a Flight by Flight ID
        /// </summary>
        /// <param name="FlightId"></param>
        /// <returns></returns>
        public List <clsPassenger> GetFlightPassengers(int FlightId)
        {
            try
            {
                DataSet      ds;
                clsPassenger People;

                string sSQL;
                int    iCount = 0;

                // Get the Flight information from the database.
                sSQL = "Select  * FROM Passenger where Passenger_ID IN(Select Passenger_ID FROM Flight_Passenger_Link where Flight_ID =" + FlightId + ")";
                ds   = db.ExecuteSQLStatement(sSQL, ref iCount);
                Passengers.Clear();

                for (int i = 0; i < iCount; i++)
                {
                    People = new clsPassenger();
                    People.Passenger_ID = ((int)ds.Tables[0].Rows[i][0]);
                    People.First_name   = ds.Tables[0].Rows[i][1].ToString();
                    People.Last_name    = ds.Tables[0].Rows[i][2].ToString();
                    People.Seat_Num     = GetTakenSeats((int)ds.Tables[0].Rows[i][0]);
                    Passengers.Add(People);
                }

                return(Passengers);
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "-" + MethodInfo.GetCurrentMethod().Name + "->" + ex.Message);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a list of all of the passengers for a given flight
        /// </summary>
        /// <param name="flightID">The flights id</param>
        /// <returns>List of passenger objects</returns>
        public List <clsPassenger> GetFlightPassengers(String flightID)
        {
            List <clsPassenger> passengers = new List <clsPassenger>();

            try
            {
                DataSet ds   = new DataSet();
                int     iRet = 0;

                ds = clsData.ExecuteSQLStatement(sql.GetAllPassengersForFlight(flightID), ref iRet);

                for (int i = 0; i < iRet; ++i)
                {
                    clsPassenger passenger = new clsPassenger();
                    passenger.PassengerID = Convert.ToInt32(ds.Tables[0].Rows[i][0].ToString());
                    passenger.FirstName   = ds.Tables[0].Rows[i][1].ToString();
                    passenger.LastName    = ds.Tables[0].Rows[i][2].ToString();
                    passenger.SeatNumber  = Convert.ToInt32(ds.Tables[0].Rows[i][3].ToString());
                    passengers.Add(passenger);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }

            return(passengers);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets a passenger object that is in the selected seat of the selected flight
        /// </summary>
        /// <param name="flightID">The flight's ID</param>
        /// <param name="seatNumber">The seat number</param>
        /// <returns></returns>
        public clsPassenger GetPassengerBySeat(String flightID, String seatNumber)
        {
            clsPassenger passenger = new clsPassenger();

            try
            {
                DataSet ds   = new DataSet();
                int     iRet = 0;

                ds = clsData.ExecuteSQLStatement(sql.GetPassengerFromSeat(flightID, seatNumber), ref iRet);

                if (ds.Tables[0].Rows.Count == 0)
                {
                    return(null);
                }

                passenger.PassengerID = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
                passenger.FirstName   = ds.Tables[0].Rows[0][1].ToString();
                passenger.LastName    = ds.Tables[0].Rows[0][2].ToString();
                passenger.SeatNumber  = Convert.ToInt32(seatNumber);
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }

            return(passenger);
        }
Esempio n. 4
0
        /// <summary>
        /// The event handler for the Choose Passenger combo box
        /// </summary>
        /// <param name="sender">The sender object</param>
        /// <param name="e">The event args</param>
        private void cbChoosePassenger_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                cmdChangeSeat.IsEnabled      = true;
                cmdDeletePassenger.IsEnabled = true;

                if (selectedPassenger != null)
                {
                    seats[selectedPassenger.SeatNumber - 1].Background = red;
                }
                selectedPassenger = (clsPassenger)cbChoosePassenger.SelectedItem;
                if (selectedPassenger != null)
                {
                    seats[selectedPassenger.SeatNumber - 1].Background = green;

                    lblPassengersSeatNumber.Content = selectedPassenger.SeatNumber;
                }
            }
            catch (Exception ex)
            {
                HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                            MethodInfo.GetCurrentMethod().Name, ex.Message);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a link between a passenger and a flight
        /// </summary>
        /// <param name="passenger">The passenger object</param>
        /// <param name="flight">The flight object</param>
        /// <param name="seatNumber">The seat assigned to the passenger</param>
        /// <returns>SQL string</returns>
        public String CreateFlightPassengerLink(String flightID, clsPassenger passenger, int seatNumber)
        {
            String sSQL = String.Format("INSERT INTO Flight_Passenger_Link(Flight_ID, Passenger_ID, Seat_Number) " +
                                        "VALUES({0}, {1}, {2})", flightID, passenger.PassengerID, seatNumber);

            return(sSQL);
        }
Esempio n. 6
0
        /// <summary>
        /// Creates a passenger in the database
        /// </summary>
        /// <param name="passenger">The passenger object</param>
        /// <returns>SQL string</returns>
        public String CreatePassenger(clsPassenger passenger)
        {
            String sSQL = String.Format("INSERT INTO Passenger(First_Name, Last_Name) " +
                                        "VALUES('{0}', '{1}')", passenger.FirstName, passenger.LastName);

            return(sSQL);
        }
Esempio n. 7
0
        /// <summary>
        /// Chooses the proper passenger depending on which one was selected.
        /// Highlights the selected passenger in the box and updates the passengerSeat
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CbChoosePassenger_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                cmdDeletePassenger.IsEnabled = true;
                cmdChangeSeat.IsEnabled      = true;

                //cast object into combobox
                ComboBox cbo = (ComboBox)sender;
                //initialize passenger with first passenger in list
                clsPassenger Passenger = (clsPassenger)cbChoosePassenger.Items[0];

                //used to change back the previous label back to red after being selected
                if (prevLabel != null)
                {
                    prevLabel.Background = Brushes.Red;
                }

                //loop through the passenger combo box to find the selected passenger
                for (int i = 0; i < cbChoosePassenger.Items.Count; i++)
                {
                    //Extract the passenger from the cbo
                    if (i == cbo.SelectedIndex)
                    {
                        Passenger = (clsPassenger)cbChoosePassenger.Items[i];
                    }
                }

                //temp string that holds the seatNumber
                string seatString;
                //loops through the active panel and finds the passenger's seat's label
                foreach (var lb in activeSeatCanvas.Children.OfType <System.Windows.Controls.Label>())
                {
                    Label MyLabel = (Label)lb;

                    //appending to find the proper seat
                    if (activeSeatCanvas == c767_Seats)
                    {
                        seatString = "Seat" + Passenger.GetPassengerSeat();
                    }
                    else
                    {
                        seatString = "SeatA" + Passenger.GetPassengerSeat();
                    }

                    //highlighting the selected passenger
                    if (MyLabel.Name == seatString)
                    {
                        prevLabel          = MyLabel;
                        MyLabel.Background = Brushes.Lime;
                        lblPassengersSeatNumber.Content = Passenger.GetPassengerSeat();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Compares two passenger objects to see if they are equivelant
        /// </summary>
        /// <param name="obj">The object to compare to</param>
        /// <returns>True if equivelant otherwise false</returns>
        public override bool Equals(object obj)
        {
            if (obj is clsPassenger)
            {
                clsPassenger other = (clsPassenger)obj;

                return(this.PassengerID == other.PassengerID);
            }
            return(false);
        }
Esempio n. 9
0
        /// <summary>
        /// Sets the Main Window in the add passenger view
        /// </summary>
        /// <param name="passenger"></param>
        public void AddPassenger(clsPassenger passenger)
        {
            try
            {
                addPassenger = passenger;

                addingPassenger = true;

                EnterChangeSeatMode();
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// constructor for the add passenger window
        /// </summary>
        public wndAddPassenger(MainWindow window)
        {
            try
            {
                mainWindow = window;

                InitializeComponent();

                passenger = new clsPassenger();
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// The event handler for the seat labels
        /// </summary>
        /// <param name="sender">The sender object</param>
        /// <param name="e">The event args</param>
        private void lblSeat_Click(object sender, MouseButtonEventArgs e)
        {
            try
            {
                Label seat = (Label)sender;

                if (changeSeat)
                {
                    clsPassenger clickedPassenger = flightLogic.GetPassengerBySeat(currentFlightID, seat.Content.ToString());
                    if (clickedPassenger == null)
                    {
                        if (addingPassenger)
                        {
                            flightLogic.InsertPassenger(currentFlightID, addPassenger);

                            addingPassenger = false;

                            flightLogic.UpdatePassengerSeatNumber(currentFlightID, addPassenger.PassengerID.ToString(), seat.Content.ToString());
                        }
                        else
                        {
                            flightLogic.UpdatePassengerSeatNumber(currentFlightID, selectedPassenger.PassengerID.ToString(), seat.Content.ToString());
                        }

                        ExitChangeSeatMode();

                        selectedPassenger = flightLogic.GetPassengerBySeat(currentFlightID, seat.Content.ToString());

                        RefreshPassengerList();

                        lblSeat_Click(sender, null);
                    }
                }
                else
                {
                    clsPassenger clickedPassenger = flightLogic.GetPassengerBySeat(currentFlightID, seat.Content.ToString());
                    if (clickedPassenger != null)
                    {
                        cbChoosePassenger.SelectedIndex = cbChoosePassenger.Items.IndexOf(clickedPassenger);
                    }
                }
            }
            catch (Exception ex)
            {
                HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                            MethodInfo.GetCurrentMethod().Name, ex.Message);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// The event handler for the Delete Passenger button
        /// </summary>
        /// <param name="sender">The sender object</param>
        /// <param name="e">The event args</param>
        private void cmdDeletePassenger_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                flightLogic.DeletePassenger(currentFlightID, selectedPassenger.PassengerID.ToString());

                selectedPassenger = null;

                RefreshPassengerList();
            }
            catch (Exception ex)
            {
                HandleError(MethodInfo.GetCurrentMethod().DeclaringType.Name,
                            MethodInfo.GetCurrentMethod().Name, ex.Message);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Used to insert a passenger to a flight
        /// </summary>
        /// <param name="passenger">The new passenger</param>
        /// <returns>If the passenger was inserted</returns>
        public bool InsertPassenger(String flightID, clsPassenger passenger)
        {
            try
            {
                clsData.ExecuteNonQuery(sql.CreatePassenger(passenger));

                passenger.PassengerID = Convert.ToInt32(GetPassengerID(passenger.FirstName, passenger.LastName));

                clsData.ExecuteNonQuery(sql.CreateFlightPassengerLink(flightID, passenger, 0));
            }
            catch (Exception ex)
            {
                throw new Exception(MethodInfo.GetCurrentMethod().DeclaringType.Name + "." + MethodInfo.GetCurrentMethod().Name + " -> " + ex.Message);
            }

            return(true);
        }