From 8f5bd3e192222adf35a14e9d2789cdfd0dfc37bc Mon Sep 17 00:00:00 2001 From: YaFedImYaEatIm Date: Sat, 1 Oct 2016 18:37:09 +1300 Subject: [PATCH] Added Cannot delte if the flight path only has 2 points --- res/userdb.db | Bin 8387584 -> 8387584 bytes .../seng202/group9/Controller/Dataset.java | 59 ++++++++++-------- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/res/userdb.db b/res/userdb.db index 23bc7f6702b9c9e186376e96acf47995bbe3e527..ada920437f82cf5d6466b69c2dcb9310c362dd0f 100644 GIT binary patch delta 798 zcmY+>$xl;390%~3H-)}FUxiv8h@jS$MMV(Yz=c{w3JOROzSISb?Lm`RY*< zL(l#R29n;4H_pb8=oK{K#KCYNUT_|UL?`)7=C@vEVr5lLXm5+;%)8=xJ!CKq5B-C%Utd`WGyYHK_vy_xRpL<(YX1UGrd%U_aELTK2WS7*X zBb`pfRJqEOi*juyE~mZ+JhoU63(6Fxm>2Wu(L|s$9qMux)Afmflm3znED#QnPZSWF zi9%uvQA89ITZwJNb|OUVAa)YFh~2~tL@Uuov=bMJ z4kAW$5|@ZBqMHEGL&S;8#1-NyagFFD`iOqwI*}j-h$L}?7$k;>Vd5rnix?qp6L*Na z#3*r(xKE4`DdGX~ka$EqCY}&aiD$%f;sxL906! Xi&d_Q;N-x+dDB{3n2E;6Gavo{+i&#o delta 659 zcmXBRyHC?$6vpx2uWz9U6sfgT1QiuTyrT#TBGe*sQ9z3D1w}waKoJG%{ZbN>M@CHu zo&6IGLpQ@_oDGAMivzRi(75Q^IDCdDIp-P9S=tFBTP3S%C(esT(IhU2W^qxph*l91mqb*wiOZs0 zToE0jQ*?=LaaCLsJ)&3iiR+?Y#KeHOAqK^eKn#l!aZ}t9qvEz06XRk++!2%Fu9y<{ z#I%?Zv*NyZAm+qFF)tp8$6`S&iX{;jPsCI4OgtAa#7pr?ycTc7+cgs2aK4LUHq5eV xb-x>*=c~KwS@CqbsfCr%W;e-j;)`3KT$~%N^4qKX-LMn1|8sn)&XGjw(?46#-<|*f diff --git a/src/main/java/seng202/group9/Controller/Dataset.java b/src/main/java/seng202/group9/Controller/Dataset.java index c677a15..8217b2c 100644 --- a/src/main/java/seng202/group9/Controller/Dataset.java +++ b/src/main/java/seng202/group9/Controller/Dataset.java @@ -2,6 +2,7 @@ package seng202.group9.Controller; import javafx.scene.chart.PieChart; +import javafx.scene.control.Alert; import seng202.group9.Core.*; import java.sql.Connection; @@ -1160,7 +1161,7 @@ public class Dataset { flightPathDictionary.put(pathID, newPath); flightPaths.add(newPath); FlightPoint sourcePoint = new FlightPoint(sourceAirport, pathID); - FlightPoint destinationPoint = new FlightPoint(sourceAirport, pathID); + FlightPoint destinationPoint = new FlightPoint(destAirport, pathID); try{ addFlightPointToPath(sourcePoint); addFlightPointToPath(destinationPoint); @@ -1591,33 +1592,41 @@ public class Dataset { * @param flightPoint */ public void deleteFlightPoint(FlightPoint flightPoint, FlightPath flightPath){ - //drop the tables - Connection c = null; - Statement stmt = null; - try { - Class.forName("org.sqlite.JDBC"); - c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); - String deleteQuery = "DELETE FROM `"+this.name+"_Flight_Points` WHERE `Point_ID` = " + flightPoint.getID() + ";"; - stmt = c.createStatement(); - stmt.execute(deleteQuery); + if (flightPath.getFlightPoints().size() > 2){ + //drop the tables + Connection c = null; + Statement stmt = null; + try { + Class.forName("org.sqlite.JDBC"); + c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db"); + String deleteQuery = "DELETE FROM `" + this.name + "_Flight_Points` WHERE `Point_ID` = " + flightPoint.getID() + ";"; + stmt = c.createStatement(); + stmt.execute(deleteQuery); - stmt = c.createStatement(); - String updatePointOrderQuery = ""; - 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()+";"; - stmt.execute(updatePointOrderQuery); - } - stmt.close(); + stmt = c.createStatement(); + String updatePointOrderQuery = ""; + 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() + ";"; + stmt.execute(updatePointOrderQuery); + } + stmt.close(); - c.close(); - } catch ( Exception e ) { - System.err.println( e.getClass().getName() + ": " + e.getMessage() ); - System.exit(0); + c.close(); + } catch (Exception e) { + System.err.println(e.getClass().getName() + ": " + e.getMessage()); + System.exit(0); + } + flightPath.getFlightPoints().remove(flightPoint); + flightPointDictionary.remove(flightPoint); + updateFlightPointInfo(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(); } - flightPath.getFlightPoints().remove(flightPoint); - flightPointDictionary.remove(flightPoint); - updateFlightPointInfo(flightPath); - updateFlightPath(flightPath); } /**