Skip to content
This repository has been archived by the owner on Dec 17, 2022. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Xarczuz committed May 15, 2019
1 parent 7ac95d2 commit c71eab0
Show file tree
Hide file tree
Showing 25 changed files with 818 additions and 549 deletions.
1 change: 0 additions & 1 deletion .~lock.new.xlsx#

This file was deleted.

1 change: 1 addition & 0 deletions .~lock.test5.xlsx#
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,chjunchi,chjunchi-U45JC,15.05.2019 15:00,file:///home/chjunchi/snap/libreoffice/118/.config/libreoffice/4;
Binary file added er.db
Binary file not shown.
Binary file modified graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified new.db
Binary file not shown.
Binary file modified new.xlsx
Binary file not shown.
Binary file added new2.db
Binary file not shown.
Binary file added sfe.db
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public static void createNewTable() {
String sql4 = "CREATE TABLE IF NOT EXISTS relator (id integer PRIMARY KEY,relator text NOT NULL);";
String sql5 = "CREATE TABLE IF NOT EXISTS relatortorole (id integer PRIMARY KEY, relator text NOT NULL, relatorid integer NOT NULL, role TEXT NOT NULL, roleid INTEGER NOT NULL);";
String sql6 = "CREATE TABLE IF NOT EXISTS hazard (id INTEGER PRIMARY KEY, hazard TEXT NOT NULL, harm TEXT NOT NULL);";
String sql7 = "CREATE TABLE IF NOT EXISTS cause (id INTEGER PRIMARY KEY, cause TEXT NOT NULL, hazardid INTEGER NOT NULL, severity REAL, probability REAL, riskevaluation REAL, risk BIT);";
String sql8 = "CREATE TABLE IF NOT EXISTS mitigation (id INTEGER PRIMARY KEY, mitigation TEXT NOT NULL, hazardid INTEGER NOT NULL);";
String sql7 = "CREATE TABLE IF NOT EXISTS cause (id INTEGER PRIMARY KEY, cause TEXT NOT NULL, mitigation TEXT, hazardid INTEGER NOT NULL, severity REAL, probability REAL, riskevaluation REAL, risk BIT);";
String sql8 = "CREATE TABLE IF NOT EXISTS mishapvictim (id INTEGER PRIMARY KEY, kind TEXT NOT NULL,role TEXT NOT NULL,relator TEXT NOT NULL, kindid INTEGER NOT NULL,roleid INTEGER NOT NULL,relatorid INTEGER NOT NULL);";
try (Connection conn = DriverManager.getConnection(url); Statement stmt = conn.createStatement()) {
// create a new table
stmt.execute(sql1);
Expand Down
107 changes: 75 additions & 32 deletions src/main/java/hazard/HazardAnalysis/DataBase/DataBaseConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import hazard.HazardClasses.Cause;
import hazard.HazardClasses.Hazard;
import hazard.HazardClasses.Kind;
import hazard.HazardClasses.Mitigation;
import hazard.HazardClasses.MishapVictim;
import hazard.HazardClasses.PossibleVictim;
import hazard.HazardClasses.Relator;
import hazard.HazardClasses.Role;
Expand Down Expand Up @@ -170,6 +170,12 @@ public static void exportData(File file) {
headerCellCause = headerCause.createCell(5);
headerCellCause.setCellValue("Risk");
headerCellCause.setCellStyle(headerStyle);
headerCellCause = headerCause.createCell(6);
headerCellCause.setCellValue("Rq.");
headerCellCause.setCellStyle(headerStyle);
headerCellCause = headerCause.createCell(7);
headerCellCause.setCellValue("Mitigation");
headerCellCause.setCellStyle(headerStyle);
Statement stmt2 = conn.createStatement();
String sql2 = "select * from hazard,cause where cause.hazardid=" + rs.getInt("id") + " AND hazard.id="
+ rs.getInt("id") + ";";
Expand All @@ -180,7 +186,6 @@ public static void exportData(File file) {
rowIndex++;
Cell cellCauses = causes.createCell(0);
cellCauses.setCellValue("Cause " + i);
i++;
cellCauses.setCellStyle(style);
cellCauses = causes.createCell(1);
cellCauses.setCellValue(rs2.getString("cause"));
Expand All @@ -206,35 +211,48 @@ public static void exportData(File file) {
}
cellCauses.setCellValue(risk);
cellCauses.setCellStyle(styleRisk);
}
Row headerMitigation = sheet.createRow(rowIndex);
rowIndex++;
Cell headerCellMitigation = headerMitigation.createCell(0);
headerCellMitigation.setCellValue("Rq.");
headerCellMitigation.setCellStyle(headerStyle);
headerCellMitigation = headerMitigation.createCell(1);
headerCellMitigation.setCellValue("Mitigation for H" + (index - 1));
headerCellMitigation.setCellStyle(headerStyle);
Statement stmt4 = conn.createStatement();
String sql4 = "select * from hazard,mitigation where mitigation.hazardid=" + rs.getInt("id")
+ " AND hazard.id=" + rs.getInt("id") + ";";
ResultSet rs4 = stmt4.executeQuery(sql4);
i = 1;
while (rs4.next()) {
Row mitigation = sheet.createRow(rowIndex);
rowIndex++;
Cell cellMitigation = mitigation.createCell(0);
cellMitigation.setCellValue("Mitigation " + i);
cellCauses = causes.createCell(6);
cellCauses.setCellValue("M " + i);
i++;
cellMitigation.setCellStyle(style);
cellMitigation = mitigation.createCell(1);
cellMitigation.setCellValue(rs4.getString("mitigation"));
cellMitigation.setCellStyle(style);
cellCauses.setCellStyle(style);
cellCauses = causes.createCell(7);
cellCauses.setCellValue(rs2.getString("mitigation"));
cellCauses.setCellStyle(style);
}
// Row headerMitigation = sheet.createRow(rowIndex);
// rowIndex++;
// Cell headerCellMitigation = headerMitigation.createCell(0);
// headerCellMitigation.setCellValue("Rq.");
// headerCellMitigation.setCellStyle(headerStyle);
// headerCellMitigation = headerMitigation.createCell(1);
// headerCellMitigation.setCellValue("Mitigation for H" + (index - 1));
// headerCellMitigation.setCellStyle(headerStyle);
// Statement stmt4 = conn.createStatement();
// String sql4 = "select * from hazard,mitigation where mitigation.hazardid=" + rs.getInt("id")
// + " AND hazard.id=" + rs.getInt("id") + ";";
// ResultSet rs4 = stmt4.executeQuery(sql4);
// i = 1;
// while (rs4.next()) {
// Row mitigation = sheet.createRow(rowIndex);
// rowIndex++;
// Cell cellMitigation = mitigation.createCell(0);
// cellMitigation.setCellValue("Mitigation " + i);
// i++;
// cellMitigation.setCellStyle(style);
// cellMitigation = mitigation.createCell(1);
// cellMitigation.setCellValue(rs4.getString("mitigation"));
// cellMitigation.setCellStyle(style);
// }
rowIndex++;
}
sheet.autoSizeColumn(0);
sheet.autoSizeColumn(1);
sheet.autoSizeColumn(2);
sheet.autoSizeColumn(3);
sheet.autoSizeColumn(4);
sheet.autoSizeColumn(5);
sheet.autoSizeColumn(6);
sheet.autoSizeColumn(7);
PrintSetup ps = sheet.getPrintSetup();
ps.setFitWidth((short) 1);
ps.setFitHeight((short) 1);
Expand Down Expand Up @@ -289,13 +307,31 @@ public static void insertHazard(String hazard, String harm) {
}
}

public static void insertMitigation(String mitigation, int hazardID) {
String sql = "INSERT INTO " + "mitigation" + "(mitigation,hazardid) VALUES(?,?)";
public static void insertMishapVictim(int roleID, String role, int kindID, String kind, int relatorID,
String relator) {
try {
String sql = "INSERT INTO mishapvictim (roleid,role,kindid,kind,relator,relatorid) VALUES(?,?,?,?,?,?)";
Connection conn = connect();
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, roleID);
pstmt.setString(2, role);
pstmt.setInt(3, kindID);
pstmt.setString(4, kind);
pstmt.setInt(5, relatorID);
pstmt.setString(6, relator);
pstmt.executeUpdate();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}

public static void insertMitigationToCause(String mitigation, int causeID) {
String sql = "UPDATE cause SET mitigation=? WHERE id = ?";
try {
Connection conn = connect();
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, mitigation);
pstmt.setInt(2, hazardID);
pstmt.setInt(2, causeID);
pstmt.executeUpdate();
} catch (SQLException e) {
System.out.println(e.getMessage());
Expand Down Expand Up @@ -393,8 +429,13 @@ public static <E> void sql(String sql, String table, ObservableList<E> list) {
} else if (table.contentEquals("relatortorole")) {
list.add((E) new Relator(rs.getInt("relatorid"), rs.getString("relator")));
} else if (table.contentEquals("possiblevictim")) {
list.add((E) new PossibleVictim(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4),
rs.getString(5)));
list.add((E) new PossibleVictim(rs.getInt("roleid"), rs.getString("role"),
rs.getInt("kindid"), rs.getString("kind"), rs.getInt("relatorid"),
rs.getString("relator")));
} else if (table.contentEquals("mishapvictim")) {
list.add((E) new MishapVictim(rs.getInt("id"), rs.getInt("roleid"), rs.getString("role"),
rs.getInt("kindid"), rs.getString("kind"), rs.getInt("relatorid"),
rs.getString("relator")));
} else if (table.contentEquals("hazard")) {
Hazard hz = new Hazard(rs.getInt("id"), rs.getString("hazard"), rs.getString("harm"));
list.add((E) hz);
Expand All @@ -404,9 +445,11 @@ public static <E> void sql(String sql, String table, ObservableList<E> list) {
if (d != 0) {
c.setRisk(String.valueOf(rs.getBoolean("risk")));
}
String m = rs.getString("mitigation");
if (m != null) {
c.setMitigation(m);
}
list.add((E) c);
} else if (table.contentEquals("mitigation")) {
list.add((E) new Mitigation(rs.getInt("id"), rs.getString("mitigation"), rs.getInt("hazardid")));
}
}
} catch (SQLException e) {
Expand Down
64 changes: 35 additions & 29 deletions src/main/java/hazard/HazardAnalysis/Steps/Views/MainView.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class MainView {
private ViewStep7 av7;
private ViewStep8 av8;
private ViewStep9 av9;
private ViewStep10 av10;
private Stage pStage;
private int currentStep;
private Text step, description;
Expand All @@ -38,7 +39,7 @@ private Button addEventToGoToPrevStep(Button btnNextStep) {
public void handle(MouseEvent e) {
if (currentStep != 1)
currentStep--;
changeStepTexts();
changeStepTexts(currentStep);
}
};
btnNextStep.addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
Expand Down Expand Up @@ -116,9 +117,9 @@ private Button addNextStepEvent(Button btnNextStep) {
EventHandler<MouseEvent> eventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
if (currentStep != 9)
if (currentStep != 10)
currentStep++;
changeStepTexts();
changeStepTexts(currentStep);
}
};
btnNextStep.addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
Expand Down Expand Up @@ -155,79 +156,77 @@ public VBox addVBox() {
vbox.getChildren().add(title);
Hyperlink options[] = new Hyperlink[] { new Hyperlink("Step 1"), new Hyperlink("Step 2"),
new Hyperlink("Step 3"), new Hyperlink("Step 4"), new Hyperlink("Step 5"), new Hyperlink("Step 6"),
new Hyperlink("Step 7"), new Hyperlink("Step 8"), new Hyperlink("Step 9") };
new Hyperlink("Step 7"), new Hyperlink("Step 8"), new Hyperlink("Step 9"), new Hyperlink("Step 10") };
EventHandler<MouseEvent> eventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
currentStep = 1;
changeStepTexts();
changeStepTexts(1);
}
};
options[0].addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
eventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
currentStep = 2;
changeStepTexts();
changeStepTexts(2);
}
};
options[1].addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
eventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
currentStep = 3;
changeStepTexts();
changeStepTexts(3);
}
};
options[2].addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
eventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
currentStep = 4;
changeStepTexts();
changeStepTexts(4);
}
};
options[3].addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
eventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
currentStep = 5;
changeStepTexts();
changeStepTexts(5);
}
};
options[4].addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
eventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
currentStep = 6;
changeStepTexts();
changeStepTexts(6);
}
};
options[5].addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
eventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
currentStep = 7;
changeStepTexts();
changeStepTexts(7);
}
};
options[6].addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
eventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
currentStep = 8;
changeStepTexts();
changeStepTexts(8);
}
};
options[7].addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
eventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
currentStep = 9;
changeStepTexts();
changeStepTexts(9);
}
};
options[8].addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
eventHandler = new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent e) {
changeStepTexts(10);
}
};
options[9].addEventHandler(MouseEvent.MOUSE_CLICKED, eventHandler);
for (int i = 0; i < options.length; i++) {
VBox.setMargin(options[i], new Insets(0, 0, 0, 8));
vbox.getChildren().add(options[i]);
Expand All @@ -236,7 +235,8 @@ public void handle(MouseEvent e) {
return vbox;
}

private void changeStepTexts() {
private void changeStepTexts(int currentStep) {
this.currentStep = currentStep;
switch (currentStep) {
case 1:
border.setCenter(getAv1().getGridPane());
Expand Down Expand Up @@ -292,6 +292,12 @@ private void changeStepTexts() {
description.setText(getAv9().getStepDescription());
currentStep = 9;
break;
case 10:
border.setCenter(getAv10().getGridPane());
step.setText(getAv10().getStep());
description.setText(getAv10().getStepDescription());
currentStep = 10;
break;
default:
break;
}
Expand All @@ -302,23 +308,18 @@ public ViewStep1 getAv1() {
}

public ViewStep2 getAv2() {
av2.updateTbKind();
return av2;
}

public ViewStep3 getAv3() {
av3.updateTbRole();
return av3;
}

public ViewStep4 getAv4() {
av4.updateTbRole();
return av4;
}

public ViewStep5 getAv5() {
av5.updatePossibleVictimList();
av5.updateHazardList();
return av5;
}

Expand All @@ -338,6 +339,10 @@ public ViewStep9 getAv9() {
return this.av9;
}

public ViewStep10 getAv10() {
return this.av10;
}

private void loadCenterViews() {
this.av2 = new ViewStep2();
this.av3 = new ViewStep3();
Expand All @@ -346,7 +351,8 @@ private void loadCenterViews() {
this.av6 = new ViewStep6();
this.av7 = new ViewStep7();
this.av8 = new ViewStep8();
this.av9 = new ViewStep9(this.pStage);
this.av9 = new ViewStep9();
this.av10 = new ViewStep10(this.pStage);
}

public BorderPane view(Stage primaryStage) {
Expand Down
Loading

0 comments on commit c71eab0

Please sign in to comment.