Added Cannot delte if the flight path only has 2 points

main
YaFedImYaEatIm 9 years ago
parent fdce7e2f2f
commit 8f5bd3e192

Binary file not shown.

@ -2,6 +2,7 @@ package seng202.group9.Controller;
import javafx.scene.chart.PieChart; import javafx.scene.chart.PieChart;
import javafx.scene.control.Alert;
import seng202.group9.Core.*; import seng202.group9.Core.*;
import java.sql.Connection; import java.sql.Connection;
@ -1160,7 +1161,7 @@ public class Dataset {
flightPathDictionary.put(pathID, newPath); flightPathDictionary.put(pathID, newPath);
flightPaths.add(newPath); flightPaths.add(newPath);
FlightPoint sourcePoint = new FlightPoint(sourceAirport, pathID); FlightPoint sourcePoint = new FlightPoint(sourceAirport, pathID);
FlightPoint destinationPoint = new FlightPoint(sourceAirport, pathID); FlightPoint destinationPoint = new FlightPoint(destAirport, pathID);
try{ try{
addFlightPointToPath(sourcePoint); addFlightPointToPath(sourcePoint);
addFlightPointToPath(destinationPoint); addFlightPointToPath(destinationPoint);
@ -1591,33 +1592,41 @@ public class Dataset {
* @param flightPoint * @param flightPoint
*/ */
public void deleteFlightPoint(FlightPoint flightPoint, FlightPath flightPath){ public void deleteFlightPoint(FlightPoint flightPoint, FlightPath flightPath){
if (flightPath.getFlightPoints().size() > 2){
//drop the tables //drop the tables
Connection c = null; Connection c = null;
Statement stmt = null; Statement stmt = null;
try { try {
Class.forName("org.sqlite.JDBC"); Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db");
String deleteQuery = "DELETE FROM `"+this.name+"_Flight_Points` WHERE `Point_ID` = " + flightPoint.getID() + ";"; String deleteQuery = "DELETE FROM `" + this.name + "_Flight_Points` WHERE `Point_ID` = " + flightPoint.getID() + ";";
stmt = c.createStatement(); stmt = c.createStatement();
stmt.execute(deleteQuery); stmt.execute(deleteQuery);
stmt = c.createStatement(); stmt = c.createStatement();
String updatePointOrderQuery = ""; String updatePointOrderQuery = "";
for (int i = 0; i < flightPath.getFlightPoints().size(); i ++){ for (int i = 0; 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();
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());
System.exit(0); System.exit(0);
} }
flightPath.getFlightPoints().remove(flightPoint); flightPath.getFlightPoints().remove(flightPoint);
flightPointDictionary.remove(flightPoint); flightPointDictionary.remove(flightPoint);
updateFlightPointInfo(flightPath); updateFlightPointInfo(flightPath);
updateFlightPath(flightPath); updateFlightPath(flightPath);
}else{
Alert cannotDelete = new Alert(Alert.AlertType.ERROR);
cannotDelete.setTitle("Flight Path Error");
cannotDelete.setHeaderText("Cannot Delete Flight Point.");
cannotDelete.setContentText("You cannot have less than 2 Points in a Flight Path.");
cannotDelete.showAndWait();
}
} }
/** /**

Loading…
Cancel
Save