Added Change Path Source and Destination Airports on changing the first or last entry in the flight points
This commit is contained in:
Binary file not shown.
@@ -14,6 +14,7 @@ import javafx.scene.layout.AnchorPane;
|
|||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import seng202.group9.Core.FlightPath;
|
||||||
import seng202.group9.GUI.*;
|
import seng202.group9.GUI.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ public class Dataset {
|
|||||||
//get all Flight Path//
|
//get all Flight Path//
|
||||||
/////////////////////*/
|
/////////////////////*/
|
||||||
stmt = c.createStatement();
|
stmt = c.createStatement();
|
||||||
String queryFlightPath = "SELECT * FROM `"+this.name+"_Flight_Path` ORDER BY `Index_ID` ASC, `Order` ASC";
|
String queryFlightPath = "SELECT * FROM `"+this.name+"_Flight_Path`";
|
||||||
rs = stmt.executeQuery(queryFlightPath);
|
rs = stmt.executeQuery(queryFlightPath);
|
||||||
while ( rs.next() ){
|
while ( rs.next() ){
|
||||||
//FlightPath(int ID, String departureAirport, String arrivalAirport)
|
//FlightPath(int ID, String departureAirport, String arrivalAirport)
|
||||||
@@ -187,7 +187,7 @@ public class Dataset {
|
|||||||
///////////////////////*/
|
///////////////////////*/
|
||||||
for (int i = 0; i < flightPaths.size(); i++){
|
for (int i = 0; i < flightPaths.size(); i++){
|
||||||
stmt = c.createStatement();
|
stmt = c.createStatement();
|
||||||
String queryFlightPoints = "SELECT * FROM `" + this.name + "_Flight_Points` WHERE `Index_ID` = "+flightPaths.get(i).getID() + " ORDER BY `Order` ASC";
|
String queryFlightPoints = "SELECT * FROM `" + this.name + "_Flight_Points` WHERE `Index_ID` = "+flightPaths.get(i).getID() + " ORDER BY `Index_ID` ASC, `Order` ASC";
|
||||||
rs = stmt.executeQuery(queryFlightPoints);
|
rs = stmt.executeQuery(queryFlightPoints);
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
//FlightPoint(String name, int ID, int indexID, String type, String via,
|
//FlightPoint(String name, int ID, int indexID, String type, String via,
|
||||||
@@ -1242,10 +1242,34 @@ public class Dataset {
|
|||||||
String updatePointOrderQuery = "";
|
String updatePointOrderQuery = "";
|
||||||
FlightPath flightPath = flightPathDictionary.get(Integer.valueOf(id));
|
FlightPath flightPath = flightPathDictionary.get(Integer.valueOf(id));
|
||||||
for (int i = index + 1; i < flightPath.getFlightPoints().size(); i ++){
|
for (int i = index + 1; i < flightPath.getFlightPoints().size(); i ++){
|
||||||
updatePointOrderQuery += "UPDATE `"+this.name+"_Flight_Points` SET `Order` = "+i+" WHERE `Point_ID` = "+flightPath.getFlightPoints().get(i).getID()+";";
|
updatePointOrderQuery = "UPDATE `"+this.name+"_Flight_Points` SET `Order` = "+i+" WHERE `Point_ID` = "+flightPath.getFlightPoints().get(i).getID()+";";
|
||||||
}
|
|
||||||
stmt.execute(updatePointOrderQuery);
|
stmt.execute(updatePointOrderQuery);
|
||||||
|
}
|
||||||
stmt.close();
|
stmt.close();
|
||||||
|
//if the index is the first or last we need to update the flight
|
||||||
|
if (index == 0){
|
||||||
|
try {
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String query = "UPDATE `"+this.name+"_Flight_Path` SET `Source_Airport` = \""+flightName+"\" " +
|
||||||
|
"WHERE `Path_ID` = "+flightPath.getID();
|
||||||
|
stmt.execute(query);
|
||||||
|
c.close();
|
||||||
|
} catch ( Exception e ) {
|
||||||
|
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
||||||
|
}
|
||||||
|
flightPath.setDepartureAirport(flightName);
|
||||||
|
}else if (index == flightPath.getFlightPoints().size() - 1){
|
||||||
|
try {
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String query = "UPDATE `"+this.name+"_Flight_Path` SET `Destination_Airport` = \""+flightName+"\" " +
|
||||||
|
"WHERE `Path_ID` = "+flightPath.getID();
|
||||||
|
stmt.execute(query);
|
||||||
|
c.close();
|
||||||
|
} catch ( Exception e ) {
|
||||||
|
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
||||||
|
}
|
||||||
|
flightPath.setArrivalAirport(flightName);
|
||||||
|
}
|
||||||
c.close();
|
c.close();
|
||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
||||||
@@ -1925,6 +1949,7 @@ public class Dataset {
|
|||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
||||||
}
|
}
|
||||||
|
flightPath.setDepartureAirport(flightPoint.getName());
|
||||||
}else if (indexOf == flightPath.getFlightPoints().size() - 1){
|
}else if (indexOf == flightPath.getFlightPoints().size() - 1){
|
||||||
try {
|
try {
|
||||||
stmt = c.createStatement();
|
stmt = c.createStatement();
|
||||||
@@ -1935,6 +1960,7 @@ public class Dataset {
|
|||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
||||||
}
|
}
|
||||||
|
flightPath.setArrivalAirport(flightPoint.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
createDataLinks();
|
createDataLinks();
|
||||||
@@ -1942,11 +1968,12 @@ public class Dataset {
|
|||||||
|
|
||||||
public void moveFlightPoint(FlightPoint flightPoint, int index) throws DataException {
|
public void moveFlightPoint(FlightPoint flightPoint, int index) throws DataException {
|
||||||
//remove and add it to the arraylist first
|
//remove and add it to the arraylist first
|
||||||
FlightPath flightPath = flightPathDictionary.get(flightPoint.getIndexID());
|
System.out.println(flightPoint.getIndex());
|
||||||
|
FlightPath flightPath = flightPathDictionary.get(flightPoint.getIndex());
|
||||||
int curIndex = flightPath.getFlightPoints().indexOf(flightPoint);
|
int curIndex = flightPath.getFlightPoints().indexOf(flightPoint);
|
||||||
flightPath.getFlightPoints().remove(flightPoint);
|
flightPath.getFlightPoints().remove(flightPoint);
|
||||||
int indexToAdd = index;
|
int indexToAdd = index;
|
||||||
if (curIndex > index){
|
if (curIndex < index){
|
||||||
indexToAdd --;
|
indexToAdd --;
|
||||||
}
|
}
|
||||||
flightPath.getFlightPoints().add(indexToAdd, flightPoint);
|
flightPath.getFlightPoints().add(indexToAdd, flightPoint);
|
||||||
@@ -1959,10 +1986,34 @@ public class Dataset {
|
|||||||
stmt = c.createStatement();
|
stmt = c.createStatement();
|
||||||
String updatePointOrderQuery = "";
|
String updatePointOrderQuery = "";
|
||||||
for (int i = index; i < flightPath.getFlightPoints().size(); i ++){
|
for (int i = index; i < flightPath.getFlightPoints().size(); i ++){
|
||||||
updatePointOrderQuery += "UPDATE `"+this.name+"_Flight_Points` SET `Order` = "+i+" WHERE `Point_ID` = "+flightPath.getFlightPoints().get(i).getID()+";";
|
updatePointOrderQuery = "UPDATE `"+this.name+"_Flight_Points` SET `Order` = "+i+" WHERE `Point_ID` = "+flightPath.getFlightPoints().get(i).getID()+";";
|
||||||
}
|
|
||||||
stmt.execute(updatePointOrderQuery);
|
stmt.execute(updatePointOrderQuery);
|
||||||
|
}
|
||||||
stmt.close();
|
stmt.close();
|
||||||
|
|
||||||
|
if (index == 0){
|
||||||
|
try {
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String query = "UPDATE `"+this.name+"_Flight_Path` SET `Source_Airport` = \""+flightPoint.getName().replace("\"", "\"\"")+"\" " +
|
||||||
|
"WHERE `Path_ID` = "+flightPoint.getIndex();
|
||||||
|
stmt.execute(query);
|
||||||
|
c.close();
|
||||||
|
} catch ( Exception e ) {
|
||||||
|
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
||||||
|
}
|
||||||
|
flightPath.setDepartureAirport(flightPoint.getName());
|
||||||
|
}else if (index == flightPath.getFlightPoints().size() - 1){
|
||||||
|
try {
|
||||||
|
stmt = c.createStatement();
|
||||||
|
String query = "UPDATE `"+this.name+"_Flight_Path` SET `Destination_Airport` = \""+flightPoint.getName().replace("\"", "\"\"")+"\" " +
|
||||||
|
"WHERE `Path_ID` = "+flightPoint.getIndex();
|
||||||
|
stmt.execute(query);
|
||||||
|
c.close();
|
||||||
|
} catch ( Exception e ) {
|
||||||
|
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
||||||
|
}
|
||||||
|
flightPath.setArrivalAirport(flightPoint.getName());
|
||||||
|
}
|
||||||
c.close();
|
c.close();
|
||||||
} catch ( Exception e ) {
|
} catch ( Exception e ) {
|
||||||
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
|
||||||
|
|||||||
Reference in New Issue
Block a user