예제 #1
0
        private void dgvOutput_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var index = e.RowIndex;


            int selectedID = Convert.ToInt32(dgvOutput.Rows[index].Cells[0].Value);


            using (var conn = new OleDbConnection(DatabaseObjects.ConnectionString))
            {
                conn.Open();
                command = new OleDbCommand
                              ("Select p.PassengerID as ID, s.SeatID, p.PassengerName as Name, s.SeatRow, s.SeatColumn, " +
                              "p.PassengerOnWaitingList as OnWaitingList " +
                              "FROM (Passengers p " +
                              "inner join PassengerSeats ps on p.PassengerID = ps.PassengerID) " +
                              "inner join Seats s on s.SeatID = ps.SeatID " +
                              "WHERE p.PassengerID = @PassengerID " +
                              "UNION " +
                              "Select p.PassengerID, null, p.PassengerName, null,null,p.PassengerOnWaitingList " +
                              "FROM Passengers p " +
                              "WHERE p.PassengerOnWaitingList = true AND p.PassengerID = @PassengerID " +
                              "ORDER BY s.SeatRow, s.SeatColumn", conn);
                command.Parameters.Add(new OleDbParameter("PassengerID", selectedID));
                DataTable dt = new DataTable();
                dt.Load(command.ExecuteReader());
                EditDelete form = new EditDelete(dt);
                form.ShowDialog();
                Close();
            }
        }
        private void dgvOutput_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var index      = e.RowIndex;
            int selectedID = Convert.ToInt32(dgvOutput.Rows[index].Cells[0].Value);

            using (var conn = new OleDbConnection(DatabaseObjects.connectionString))
            {
                conn.Open();
                command = new OleDbCommand(@"
                                            SELECT P.PassengerID AS ID, S.SeatID, P.PassengerName AS Name, S.SeatRow, S.SeatColumn, P.PassengerOnWaitingList AS OnWaitingList
                                            FROM (Passengers as P
                                            INNER JOIN  PassengerSeats as PS 
                                            ON PS.PassengerID = P.PassengerID)
                                            INNER JOIN Seats as S
                                            ON S.SeatID = PS.SeatID
                                            WHERE P.PassengerID LIKE @passengerID
                                            UNION
                                            SELECT P.PassengerID, NULL, P.PassengerName, NULL, NULL, P.PassengerOnWaitingList
                                            FROM Passengers as P
                                            WHERE P.PassengerOnWaitingList = TRUE AND P.PassengerID LIKE @passengerID
                                            ORDER BY S.SeatRow, S.SeatColumn", conn);
                command.Parameters.Add(new OleDbParameter("passengerID", selectedID));

                DataTable dt = new DataTable();
                dt.Load(command.ExecuteReader());
                EditDelete form = new EditDelete(dt);
                form.ShowDialog();
                Close();
            }
        }
        private void dgvOutput_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //get the row number that was clicked
            var index = e.RowIndex;

            //get the passengerID from the clicked row and pass it to the command
            int selectedID = Convert.ToInt32(dgvOutput.Rows[index].Cells[0].Value);

            //Select all the passenger information from all three tables that matches
            //the passengerID of the passenger that was clicked
            using (var conn = new OleDbConnection(DatabaseObjects.ConnectionString))
            {
                conn.Open();
                command = new OleDbCommand
                              ("Select p.PassengerID as ID, s.SeatID, p.PassengerName as Name, s.SeatRow, s.SeatColumn, " +
                              "p.PassengerOnWaitingList as OnWaitingList " +
                              "FROM (Passengers p " +
                              "inner join PassengerSeats ps on p.PassengerID = ps.PassengerID) " +
                              "inner join Seats s on s.SeatID = ps.SeatID " +
                              "WHERE p.PassengerID = @PassengerID " +
                              "UNION " +
                              "Select p.PassengerID, null, p.PassengerName, null,null,p.PassengerOnWaitingList " +
                              "FROM Passengers p " +
                              "WHERE p.PassengerOnWaitingList = true AND p.PassengerID = @PassengerID " +
                              "ORDER BY s.SeatRow, s.SeatColumn", conn);
                command.Parameters.Add(new OleDbParameter("PassengerID", selectedID));
                DataTable dt = new DataTable();
                dt.Load(command.ExecuteReader());
                EditDelete form = new EditDelete(dt);
                form.ShowDialog();
                Close();
            }

            //execute command and place results to DataTable and pass it to the EditDelete form
        }