commit e7eb4a6663e683beb7f3c5fcd22cfcffd5a039bc Author: unknown Date: Sun Jun 14 13:43:10 2020 +0200 Projekt LSR diff --git a/Projekt-LSR/.classpath b/Projekt-LSR/.classpath new file mode 100644 index 0000000..4fd8998 --- /dev/null +++ b/Projekt-LSR/.classpath @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/Projekt-LSR/.project b/Projekt-LSR/.project new file mode 100644 index 0000000..e3047a6 --- /dev/null +++ b/Projekt-LSR/.project @@ -0,0 +1,23 @@ + + + Projekt-LSR + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.xtext.ui.shared.xtextBuilder + + + + + + org.eclipse.xtext.ui.shared.xtextNature + org.eclipse.jdt.core.javanature + + diff --git a/Projekt-LSR/.settings/org.eclipse.jdt.core.prefs b/Projekt-LSR/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..ef28d2b --- /dev/null +++ b/Projekt-LSR/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=13 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=13 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=13 diff --git a/Projekt-LSR/bin/application/ApplicationController.class b/Projekt-LSR/bin/application/ApplicationController.class new file mode 100644 index 0000000..1852a9f Binary files /dev/null and b/Projekt-LSR/bin/application/ApplicationController.class differ diff --git a/Projekt-LSR/bin/application/CreditsController.class b/Projekt-LSR/bin/application/CreditsController.class new file mode 100644 index 0000000..a2acf9c Binary files /dev/null and b/Projekt-LSR/bin/application/CreditsController.class differ diff --git a/Projekt-LSR/bin/application/Main.class b/Projekt-LSR/bin/application/Main.class new file mode 100644 index 0000000..4121cd5 Binary files /dev/null and b/Projekt-LSR/bin/application/Main.class differ diff --git a/Projekt-LSR/bin/application/Movie.class b/Projekt-LSR/bin/application/Movie.class new file mode 100644 index 0000000..710d1c3 Binary files /dev/null and b/Projekt-LSR/bin/application/Movie.class differ diff --git a/Projekt-LSR/bin/application/Opinion.class b/Projekt-LSR/bin/application/Opinion.class new file mode 100644 index 0000000..64f14eb Binary files /dev/null and b/Projekt-LSR/bin/application/Opinion.class differ diff --git a/Projekt-LSR/bin/application/OpinionController.class b/Projekt-LSR/bin/application/OpinionController.class new file mode 100644 index 0000000..5d322e3 Binary files /dev/null and b/Projekt-LSR/bin/application/OpinionController.class differ diff --git a/Projekt-LSR/bin/application/addOpinionView.fxml b/Projekt-LSR/bin/application/addOpinionView.fxml new file mode 100644 index 0000000..2b15809 --- /dev/null +++ b/Projekt-LSR/bin/application/addOpinionView.fxml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Projekt-LSR/bin/application/ocena_dlugi.fcl b/Projekt-LSR/bin/application/ocena_dlugi.fcl new file mode 100644 index 0000000..7dca2d7 --- /dev/null +++ b/Projekt-LSR/bin/application/ocena_dlugi.fcl @@ -0,0 +1,37 @@ +FUNCTION_BLOCK ocena_dlugosc + +VAR_INPUT + dlugosc: REAL; +END_VAR + +VAR_OUTPUT + ocena : REAL; +END_VAR + +FUZZIFY dlugosc + TERM krotki := (40, 1) (80,0); + TERM sredni := (60, 0) (90, 1) (120,1) (150,0); + TERM dlugi := (130, 0) (170,1); +END_FUZZIFY + + +DEFUZZIFY ocena + TERM slaby := (5,1) (11,0); + TERM srednia := (9,0) (15,1) (21,0); + TERM dobry := (19,0) (25,1); + METHOD : COG; + DEFAULT := 0; +END_DEFUZZIFY + +RULEBLOCK No1 + AND : MIN; + ACT : MIN; + ACCU : MAX; + RULE 1 : IF dlugosc is dlugi THEN ocena IS dobry; + RULE 2 : IF dlugosc is sredni THEN ocena IS srednia; + RULE 3 : IF dlugosc IS krotki THEN ocena IS slaby; + +END_RULEBLOCK + +END_FUNCTION_BLOCK + diff --git a/Projekt-LSR/bin/application/ocena_duzo_glosow.fcl b/Projekt-LSR/bin/application/ocena_duzo_glosow.fcl new file mode 100644 index 0000000..f36ff0b --- /dev/null +++ b/Projekt-LSR/bin/application/ocena_duzo_glosow.fcl @@ -0,0 +1,35 @@ +FUNCTION_BLOCK ocena + +VAR_INPUT + glosy : REAL; +END_VAR + +VAR_OUTPUT + ocena : REAL; +END_VAR + +FUZZIFY glosy + TERM malo := (1000,1) (2500,0); + TERM srednio := (2000, 0) (3500, 1) (4500,1) (6000,0) ; + TERM duzo := (5500, 0) (6500,1); +END_FUZZIFY + +DEFUZZIFY ocena + TERM slaby := (5,1) (11,0); + TERM srednia := (9,0) (15,1) (21,0); + TERM dobry := (19,0) (25,1); + METHOD : COG; + DEFAULT := 0; +END_DEFUZZIFY + +RULEBLOCK No1 + AND : MIN; + ACT : MIN; + ACCU : MAX; + RULE 7 : IF glosy IS duzo THEN ocena IS dobry; + RULE 8 : IF glosy IS srednio THEN ocena IS srednia; + RULE 9 : IF glosy IS malo THEN ocena IS slaby; +END_RULEBLOCK + +END_FUNCTION_BLOCK + diff --git a/Projekt-LSR/bin/application/ocena_krotki.fcl b/Projekt-LSR/bin/application/ocena_krotki.fcl new file mode 100644 index 0000000..e999bd6 --- /dev/null +++ b/Projekt-LSR/bin/application/ocena_krotki.fcl @@ -0,0 +1,37 @@ +FUNCTION_BLOCK ocena_dlugosc + +VAR_INPUT + dlugosc: REAL; +END_VAR + +VAR_OUTPUT + ocena : REAL; +END_VAR + +FUZZIFY dlugosc + TERM krotki := (40, 1) (80,0); + TERM sredni := (60, 0) (90, 1) (120,1) (150,0); + TERM dlugi := (130, 0) (170,1); +END_FUZZIFY + + +DEFUZZIFY ocena + TERM slaby := (5,1) (11,0); + TERM srednia := (9,0) (15,1) (21,0); + TERM dobry := (19,0) (25,1); + METHOD : COG; + DEFAULT := 0; +END_DEFUZZIFY + +RULEBLOCK No1 + AND : MIN; + ACT : MIN; + ACCU : MAX; + RULE 1 : IF dlugosc is krotki THEN ocena IS dobry; + RULE 2 : IF dlugosc is sredni THEN ocena IS srednia; + RULE 3 : IF dlugosc IS dlugi THEN ocena IS slaby; + +END_RULEBLOCK + +END_FUNCTION_BLOCK + diff --git a/Projekt-LSR/bin/application/ocena_malo_glosow.fcl b/Projekt-LSR/bin/application/ocena_malo_glosow.fcl new file mode 100644 index 0000000..c1267b7 --- /dev/null +++ b/Projekt-LSR/bin/application/ocena_malo_glosow.fcl @@ -0,0 +1,35 @@ +FUNCTION_BLOCK ocena + +VAR_INPUT + glosy : REAL; +END_VAR + +VAR_OUTPUT + ocena : REAL; +END_VAR + +FUZZIFY glosy + TERM malo := (1000,1) (2500,0); + TERM srednio := (2000, 0) (3500, 1) (4500,1) (6000,0) ; + TERM duzo := (5500, 0) (6500,1); +END_FUZZIFY + +DEFUZZIFY ocena + TERM slaby := (5,1) (11,0); + TERM srednia := (9,0) (15,1) (21,0); + TERM dobry := (19,0) (25,1); + METHOD : COG; + DEFAULT := 0; +END_DEFUZZIFY + +RULEBLOCK No1 + AND : MIN; + ACT : MIN; + ACCU : MAX; + RULE 7 : IF glosy IS malo THEN ocena IS dobry; + RULE 8 : IF glosy IS srednio THEN ocena IS srednia; + RULE 9 : IF glosy IS duzo THEN ocena IS slaby; +END_RULEBLOCK + +END_FUNCTION_BLOCK + diff --git a/Projekt-LSR/bin/application/ocena_niska_ocena.fcl b/Projekt-LSR/bin/application/ocena_niska_ocena.fcl new file mode 100644 index 0000000..d85a1e8 --- /dev/null +++ b/Projekt-LSR/bin/application/ocena_niska_ocena.fcl @@ -0,0 +1,37 @@ +FUNCTION_BLOCK ocena_sr + +VAR_INPUT + sr_ocena : REAL; +END_VAR + +VAR_OUTPUT + ocena : REAL; +END_VAR + +FUZZIFY sr_ocena + TERM niska := (3,1) (5,0); + TERM srednia := (4, 0) (5, 1) (6,1) (7,0) ; + TERM wysoka := (6, 0) (8,1); +END_FUZZIFY + +DEFUZZIFY ocena + TERM slaby := (5,1) (11,0); + TERM srednia := (9,0) (15,1) (21,0); + TERM dobry := (19,0) (25,1); + METHOD : COG; + DEFAULT := 0; +END_DEFUZZIFY + +RULEBLOCK No1 + AND : MIN; + ACT : MIN; + ACCU : MAX; + RULE 7 : IF sr_ocena IS wysoka THEN ocena IS slaby; + RULE 8 : IF sr_ocena IS srednia THEN ocena IS srednia; + RULE 9 : IF sr_ocena IS niska THEN ocena IS dobry; +END_RULEBLOCK + +END_FUNCTION_BLOCK + + + diff --git a/Projekt-LSR/bin/application/ocena_nowy.fcl b/Projekt-LSR/bin/application/ocena_nowy.fcl new file mode 100644 index 0000000..f8094db --- /dev/null +++ b/Projekt-LSR/bin/application/ocena_nowy.fcl @@ -0,0 +1,35 @@ +FUNCTION_BLOCK ocena + +VAR_INPUT + rok : REAL; +END_VAR + +VAR_OUTPUT + ocena : REAL; +END_VAR + +FUZZIFY rok + TERM stary := (1990, 1) (1997,0); + TERM sredni := (1995, 0) (2000, 1) (2005,1) (2010,0) ; + TERM nowy := (2007,0) (2015,1); +END_FUZZIFY + +DEFUZZIFY ocena + TERM slaby := (5,1) (11,0); + TERM srednia := (9,0) (15,1) (21,0); + TERM dobry := (19,0) (25,1); + METHOD : COG; + DEFAULT := 0; +END_DEFUZZIFY + +RULEBLOCK No1 + AND : MIN; + ACT : MIN; + ACCU : MAX; + RULE 4 : IF rok IS nowy THEN ocena IS dobry; + RULE 5 : IF rok IS sredni THEN ocena IS srednia; + RULE 6 : IF rok IS stary THEN ocena IS slaby; +END_RULEBLOCK + +END_FUNCTION_BLOCK + diff --git a/Projekt-LSR/bin/application/ocena_sredni.fcl b/Projekt-LSR/bin/application/ocena_sredni.fcl new file mode 100644 index 0000000..cf6a841 --- /dev/null +++ b/Projekt-LSR/bin/application/ocena_sredni.fcl @@ -0,0 +1,37 @@ +FUNCTION_BLOCK ocena_dlugosc + +VAR_INPUT + dlugosc: REAL; +END_VAR + +VAR_OUTPUT + ocena : REAL; +END_VAR + +FUZZIFY dlugosc + TERM krotki := (40, 1) (80,0); + TERM sredni := (60, 0) (90, 1) (120,1) (150,0); + TERM dlugi := (130, 0) (170,1); +END_FUZZIFY + + +DEFUZZIFY ocena + TERM slaby := (5,1) (11,0); + TERM srednia := (9,0) (15,1) (21,0); + TERM dobry := (19,0) (25,1); + METHOD : COG; + DEFAULT := 0; +END_DEFUZZIFY + +RULEBLOCK No1 + AND : MIN; + ACT : MIN; + ACCU : MAX; + RULE 1 : IF dlugosc is krotki THEN ocena IS slaby; + RULE 2 : IF dlugosc is sredni THEN ocena IS dobry; + RULE 3 : IF dlugosc IS dlugi THEN ocena IS slaby; + +END_RULEBLOCK + +END_FUNCTION_BLOCK + diff --git a/Projekt-LSR/bin/application/ocena_srednia_ocena.fcl b/Projekt-LSR/bin/application/ocena_srednia_ocena.fcl new file mode 100644 index 0000000..9508619 --- /dev/null +++ b/Projekt-LSR/bin/application/ocena_srednia_ocena.fcl @@ -0,0 +1,37 @@ +FUNCTION_BLOCK ocena_sr + +VAR_INPUT + sr_ocena : REAL; +END_VAR + +VAR_OUTPUT + ocena : REAL; +END_VAR + +FUZZIFY sr_ocena + TERM niska := (3,1) (5,0); + TERM srednia := (4, 0) (5, 1) (6,1) (7,0) ; + TERM wysoka := (6, 0) (8,1); +END_FUZZIFY + +DEFUZZIFY ocena + TERM slaby := (5,1) (11,0); + TERM srednia := (9,0) (15,1) (21,0); + TERM dobry := (19,0) (25,1); + METHOD : COG; + DEFAULT := 0; +END_DEFUZZIFY + +RULEBLOCK No1 + AND : MIN; + ACT : MIN; + ACCU : MAX; + RULE 7 : IF sr_ocena IS wysoka THEN ocena IS slaby; + RULE 8 : IF sr_ocena IS srednia THEN ocena IS dobry; + RULE 9 : IF sr_ocena IS niska THEN ocena IS slaby; +END_RULEBLOCK + +END_FUNCTION_BLOCK + + + diff --git a/Projekt-LSR/bin/application/ocena_srednio_glosow.fcl b/Projekt-LSR/bin/application/ocena_srednio_glosow.fcl new file mode 100644 index 0000000..4aa7517 --- /dev/null +++ b/Projekt-LSR/bin/application/ocena_srednio_glosow.fcl @@ -0,0 +1,35 @@ +FUNCTION_BLOCK ocena + +VAR_INPUT + glosy : REAL; +END_VAR + +VAR_OUTPUT + ocena : REAL; +END_VAR + +FUZZIFY glosy + TERM malo := (1000,1) (2500,0); + TERM srednio := (2000, 0) (3500, 1) (4500,1) (6000,0) ; + TERM duzo := (5500, 0) (6500,1); +END_FUZZIFY + +DEFUZZIFY ocena + TERM slaby := (5,1) (11,0); + TERM srednia := (9,0) (15,1) (21,0); + TERM dobry := (19,0) (25,1); + METHOD : COG; + DEFAULT := 0; +END_DEFUZZIFY + +RULEBLOCK No1 + AND : MIN; + ACT : MIN; + ACCU : MAX; + RULE 7 : IF glosy IS malo THEN ocena IS slaby; + RULE 8 : IF glosy IS srednio THEN ocena IS dobry; + RULE 9 : IF glosy IS duzo THEN ocena IS slaby; +END_RULEBLOCK + +END_FUNCTION_BLOCK + diff --git a/Projekt-LSR/bin/application/ocena_srednio_stary.fcl b/Projekt-LSR/bin/application/ocena_srednio_stary.fcl new file mode 100644 index 0000000..edd1e8e --- /dev/null +++ b/Projekt-LSR/bin/application/ocena_srednio_stary.fcl @@ -0,0 +1,35 @@ +FUNCTION_BLOCK ocena + +VAR_INPUT + rok : REAL; +END_VAR + +VAR_OUTPUT + ocena : REAL; +END_VAR + +FUZZIFY rok + TERM stary := (1990, 1) (1997,0); + TERM sredni := (1995, 0) (2000, 1) (2005,1) (2010,0) ; + TERM nowy := (2007,0) (2015,1); +END_FUZZIFY + +DEFUZZIFY ocena + TERM slaby := (5,1) (11,0); + TERM srednia := (9,0) (15,1) (21,0); + TERM dobry := (19,0) (25,1); + METHOD : COG; + DEFAULT := 0; +END_DEFUZZIFY + +RULEBLOCK No1 + AND : MIN; + ACT : MIN; + ACCU : MAX; + RULE 4 : IF rok IS nowy THEN ocena IS slaby; + RULE 5 : IF rok IS sredni THEN ocena IS dobry; + RULE 6 : IF rok IS stary THEN ocena IS slaby; +END_RULEBLOCK + +END_FUNCTION_BLOCK + diff --git a/Projekt-LSR/bin/application/ocena_stary.fcl b/Projekt-LSR/bin/application/ocena_stary.fcl new file mode 100644 index 0000000..e3c612e --- /dev/null +++ b/Projekt-LSR/bin/application/ocena_stary.fcl @@ -0,0 +1,35 @@ +FUNCTION_BLOCK ocena + +VAR_INPUT + rok : REAL; +END_VAR + +VAR_OUTPUT + ocena : REAL; +END_VAR + +FUZZIFY rok + TERM stary := (1990, 1) (1997,0); + TERM sredni := (1995, 0) (2000, 1) (2005,1) (2010,0) ; + TERM nowy := (2007,0) (2015,1); +END_FUZZIFY + +DEFUZZIFY ocena + TERM slaby := (5,1) (11,0); + TERM srednia := (9,0) (15,1) (21,0); + TERM dobry := (19,0) (25,1); + METHOD : COG; + DEFAULT := 0; +END_DEFUZZIFY + +RULEBLOCK No1 + AND : MIN; + ACT : MIN; + ACCU : MAX; + RULE 4 : IF rok IS nowy THEN ocena IS slaby; + RULE 5 : IF rok IS sredni THEN ocena IS srednia; + RULE 6 : IF rok IS stary THEN ocena IS dobry; +END_RULEBLOCK + +END_FUNCTION_BLOCK + diff --git a/Projekt-LSR/bin/application/ocena_wysoka_ocena.fcl b/Projekt-LSR/bin/application/ocena_wysoka_ocena.fcl new file mode 100644 index 0000000..023e880 --- /dev/null +++ b/Projekt-LSR/bin/application/ocena_wysoka_ocena.fcl @@ -0,0 +1,37 @@ +FUNCTION_BLOCK ocena_sr + +VAR_INPUT + sr_ocena : REAL; +END_VAR + +VAR_OUTPUT + ocena : REAL; +END_VAR + +FUZZIFY sr_ocena + TERM niska := (3,1) (5,0); + TERM srednia := (4, 0) (5, 1) (6,1) (7,0) ; + TERM wysoka := (6, 0) (8,1); +END_FUZZIFY + +DEFUZZIFY ocena + TERM slaby := (5,1) (11,0); + TERM srednia := (9,0) (15,1) (21,0); + TERM dobry := (19,0) (25,1); + METHOD : COG; + DEFAULT := 0; +END_DEFUZZIFY + +RULEBLOCK No1 + AND : MIN; + ACT : MIN; + ACCU : MAX; + RULE 7 : IF sr_ocena IS wysoka THEN ocena IS dobry; + RULE 8 : IF sr_ocena IS srednia THEN ocena IS srednia; + RULE 9 : IF sr_ocena IS niska THEN ocena IS slaby; +END_RULEBLOCK + +END_FUNCTION_BLOCK + + + diff --git a/Projekt-LSR/build.fxbuild b/Projekt-LSR/build.fxbuild new file mode 100644 index 0000000..353069a --- /dev/null +++ b/Projekt-LSR/build.fxbuild @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/Projekt-LSR/src/application/ApplicationController.java b/Projekt-LSR/src/application/ApplicationController.java new file mode 100644 index 0000000..e28f795 --- /dev/null +++ b/Projekt-LSR/src/application/ApplicationController.java @@ -0,0 +1,606 @@ +package application; + +import java.io.IOException; +import java.net.URL; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.ResourceBundle; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.ChoiceBox; +import javafx.scene.control.TabPane; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableView; +import javafx.scene.control.TextField; +import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.input.MouseButton; +import javafx.scene.input.MouseEvent; +import javafx.stage.Stage; + +public class ApplicationController implements Initializable { + +//variables + private ObservableList observableList; + private List values; + private String url = "jdbc:postgresql://localhost:5432/fcl"; + private String user = "postgres"; + private String password = "postgres"; + Connection connection; + + @FXML + private TabPane tabPane; + +//FXML app tab + @FXML + private ChoiceBox typeChoiceBox; + @FXML + private ChoiceBox productionChoiceBox; + @FXML + private ChoiceBox durationChoiceBox; + @FXML + private ChoiceBox userRatingChoiceBox; + @FXML + private ChoiceBox numberOfVotesChoiceBox; + + @FXML + private TableView queryResultTableView; + @FXML + private TableColumn titleColumn; + @FXML + private TableColumn> typesColumn; + @FXML + private TableColumn productionYearColumn; + @FXML + private TableColumn durationColumn; + @FXML + private TableColumn ratingColumn; + @FXML + private TableColumn numberOfVotesColumn; + @FXML + private TableColumn bestMatchingColumn; + +//FXML findingMovieTab + @FXML + private TextField queryFindingTabTextField; + @FXML + private TableView queryResultFindingTabTableView; + @FXML + private TableColumn titleFindingTabColumn; + @FXML + private TableColumn> typesFindingTabColumn; + @FXML + private TableColumn productionYearFindingTabColumn; + @FXML + private TableColumn durationFindingTabColumn; + @FXML + private TableColumn ratingFindingTabColumn; + @FXML + private TableColumn numberOfVotesFindingTabColumn; + +//FXML opinionTab + @FXML + private TextField opinionTabTitleTextField; + @FXML + private TextField opinionTabRatingTextField; + @FXML + private TextField opinionTabVotesTextField; + @FXML + public TableView opinionsTableView; + @FXML + private TableColumn emailOpinionsTabColumn; + @FXML + private TableColumn dateOpinionsTabColumn; + @FXML + private TableColumn opinionOpinionsTabColumn; + @FXML + private TableColumn ratingOpinionsTabColumn; + @FXML + private TableColumn nickOpinionsTabColumn; + + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + initializeChoiceBoxes(); + initializeTables(); + + queryResultTableView.setOnMouseClicked((MouseEvent e) -> { + Movie selectedMovie = queryResultTableView.getSelectionModel().getSelectedItem(); + if (e.getButton() == MouseButton.PRIMARY && e.getClickCount() == 2 && selectedMovie != null) { + tabPane.getSelectionModel().select(2); + insertSelectedMovie(selectedMovie.getTitle(), selectedMovie.getRating(), selectedMovie.getNumberOfVotes()); + updateTableView(selectedMovie.getTitle()); + } + }); + + queryResultFindingTabTableView.setOnMouseClicked((MouseEvent e) -> { + Movie selectedMovie = queryResultFindingTabTableView.getSelectionModel().getSelectedItem(); + if (e.getButton() == MouseButton.PRIMARY && e.getClickCount() == 2 && selectedMovie != null) { + tabPane.getSelectionModel().select(2); + insertSelectedMovie(selectedMovie.getTitle(), selectedMovie.getRating(), selectedMovie.getNumberOfVotes()); + updateTableView(selectedMovie.getTitle()); + } + }); + } + + private void insertSelectedMovie(String title, Double rating, int numberOfVotes) { + opinionTabTitleTextField.setEditable(true); + opinionTabRatingTextField.setEditable(true); + opinionTabVotesTextField.setEditable(true); + + opinionTabTitleTextField.setText(title); + opinionTabRatingTextField.setText(String.valueOf(rating)); + opinionTabVotesTextField.setText(String.valueOf(numberOfVotes)); + + opinionTabTitleTextField.setEditable(false); + opinionTabRatingTextField.setEditable(false); + opinionTabVotesTextField.setEditable(false); + } + + private void initializeChoiceBoxes() { + initializeTypeChoiceBox(); + initializeProductionChoiceBox(); + initializeDurationChoiceBox(); + initializeUserRatingChoiceBox(); + initializeNumberOfVotesChoiceBox(); + } + + private void initializeTypeChoiceBox() { + this.values = new ArrayList<>(); + this.values.add(" "); + this.values.add("comedy"); + this.values.add("drama"); + this.values.add("crime"); + this.values.add("fantasy"); + this.values.add("horror"); + this.values.add("romance"); + this.values.add("adventure"); + this.values.add("animation"); + this.values.add("history"); + this.values.add("sci-fi"); + this.values.add("sport"); + this.values.add("thriller"); + this.values.add("biography"); + this.values.add("documentary"); + this.values.add("musical"); + this.observableList = FXCollections.observableArrayList(); + this.observableList.addAll(values); + typeChoiceBox.setItems(observableList); + typeChoiceBox.setValue(values.get(0)); + } + + private void initializeProductionChoiceBox() { + this.values = new ArrayList<>(); + this.values.add(" "); + this.values.add("Stary film"); + this.values.add("Sredni film"); + this.values.add("Nowy film"); + this.observableList = FXCollections.observableArrayList(); + this.observableList.addAll(values); + productionChoiceBox.setItems(observableList); + productionChoiceBox.setValue(values.get(0)); + } + + private void initializeDurationChoiceBox() { + this.values = new ArrayList<>(); + this.values.add(" "); + this.values.add("Krotkiej dlugosci film"); + this.values.add("Sredniej dlugosci film"); + this.values.add("Dlugiej dlugosci film"); + this.observableList = FXCollections.observableArrayList(); + this.observableList.addAll(values); + durationChoiceBox.setItems(observableList); + durationChoiceBox.setValue(values.get(0)); + } + + private void initializeUserRatingChoiceBox() { + this.values = new ArrayList<>(); + this.values.add(" "); + this.values.add("Slaby film"); + this.values.add("Przecietny film"); + this.values.add("Dobry film"); + this.observableList = FXCollections.observableArrayList(); + this.observableList.addAll(values); + userRatingChoiceBox.setItems(observableList); + userRatingChoiceBox.setValue(values.get(0)); + } + + private void initializeNumberOfVotesChoiceBox() { + this.values = new ArrayList<>(); + this.values.add(" "); + this.values.add("Mala ilosc glosow"); + this.values.add("Srednia ilosc glosow"); + this.values.add("Duza ilosc glosow"); + this.observableList = FXCollections.observableArrayList(); + this.observableList.addAll(values); + numberOfVotesChoiceBox.setItems(observableList); + numberOfVotesChoiceBox.setValue(values.get(0)); + } + + private void initializeTables() { +//app Tab Table + titleColumn.setCellValueFactory(new PropertyValueFactory<>("title")); + typesColumn.setCellValueFactory(new PropertyValueFactory<>("types")); + productionYearColumn.setCellValueFactory(new PropertyValueFactory<>("productionYear")); + durationColumn.setCellValueFactory(new PropertyValueFactory<>("duration")); + ratingColumn.setCellValueFactory(new PropertyValueFactory<>("rating")); + numberOfVotesColumn.setCellValueFactory(new PropertyValueFactory<>("numberOfVotes")); + bestMatchingColumn.setCellValueFactory(new PropertyValueFactory<>("bestMatching")); +//find Movie Tab Table + titleFindingTabColumn.setCellValueFactory(new PropertyValueFactory<>("title")); + typesFindingTabColumn.setCellValueFactory(new PropertyValueFactory<>("types")); + productionYearFindingTabColumn.setCellValueFactory(new PropertyValueFactory<>("productionYear")); + durationFindingTabColumn.setCellValueFactory(new PropertyValueFactory<>("duration")); + ratingFindingTabColumn.setCellValueFactory(new PropertyValueFactory<>("rating")); + numberOfVotesFindingTabColumn.setCellValueFactory(new PropertyValueFactory<>("numberOfVotes")); +//opinions Tab Table + emailOpinionsTabColumn.setCellValueFactory(new PropertyValueFactory<>("email")); + dateOpinionsTabColumn.setCellValueFactory(new PropertyValueFactory<>("date")); + opinionOpinionsTabColumn.setCellValueFactory(new PropertyValueFactory<>("opinion")); + ratingOpinionsTabColumn.setCellValueFactory(new PropertyValueFactory<>("rating")); + nickOpinionsTabColumn.setCellValueFactory(new PropertyValueFactory<>("nick")); + } + + @FXML + private void creditsButtonAction() { + try { + FXMLLoader loader = new FXMLLoader(this.getClass().getResource("creditsView.fxml")); + Parent root = (Parent) loader.load(); + Stage stage = new Stage(); + stage.setTitle("Credits"); + stage.setScene(new Scene(root)); + stage.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @FXML + private void findMoviesButtonAction() { + + String genre = typeChoiceBox.getSelectionModel().getSelectedItem(); + String production = productionChoiceBox.getSelectionModel().getSelectedItem(); + String duration = durationChoiceBox.getSelectionModel().getSelectedItem(); + String userRating = userRatingChoiceBox.getSelectionModel().getSelectedItem(); + String numberOfVotes = numberOfVotesChoiceBox.getSelectionModel().getSelectedItem(); + + ObservableList data = FXCollections.observableArrayList(); + + try { + connection = DriverManager.getConnection(url, user, password); + if (connection != null) { + Statement statement = connection.createStatement(); + String query = "SELECT * FROM title_join"; +//kategoria + if (!(genre == " ")) { + query += " WHERE \"genres\" LIKE '%" + genre + "%'"; + } +//rok produkcji + if (production.equals("Nowy film")) { + query += " AND CAST(\"startyear\" AS INT) > '2000'"; + } else if (production.equals("Sredni film")) { + query += " AND CAST(\"startyear\" AS INT) > '1980' AND CAST(\"startyear\" AS INT) < '2020'"; + } else if (production.equals("Stary film")) { + query += " AND CAST(\"startyear\" AS INT) < '2000'"; + } +//dlugosc filmu + if (duration.equals("Dlugiej dlugosci film")) { + query += " AND CAST(\"runtimeminutes\" AS INT) > '120'"; + } else if (duration.equals("Sredniej dlugosci film")) { + query += " AND CAST(\"runtimeminutes\" AS INT) > '50' AND CAST(\"runtimeminutes\" AS INT) < '150'"; + } else if (duration.equals("Krotkiej dlugosci film")) { + query += " AND CAST(\"runtimeminutes\" AS INT) < '100'"; + } +//ocena uzytkownikow + if (userRating.equals("Dobry film")) { + query += " AND \"averagerating\" > '5'"; + } else if (userRating.equals("Przecietny film")) { + query += " AND \"averagerating\" > '2' AND \"averagerating\" < '8'"; + } else if (userRating.equals("Slaby film")) { + query += " AND \"averagerating\" < '5'"; + } +//ilosc glosow uzytkownikow + if (numberOfVotes.equals("Duza ilosc glosow")) { + query += " AND \"numvotes\" > '150'"; + } else if (numberOfVotes.equals("Srednia ilosc glosow")) { + query += " AND \"numvotes\" < '200' AND \"numvotes\" > '50'"; + } else if (numberOfVotes.equals("Mala ilosc glosow")) { + query += " AND \"numvotes\" < '100'"; + } +//gdyby brakowalo jakiegos pola dopasowuje zapytanie + query = query.replaceFirst("title_join AND", "title_join WHERE"); + + + ResultSet queryResult = statement.executeQuery(query); + while (queryResult.next()) { + Movie m = new Movie(); + m.setTitle(queryResult.getString(2)); + m.setProductionYear(queryResult.getInt(3)); + m.setDuration(queryResult.getInt(4)); + String s = queryResult.getString(5); + ArrayList genres = new ArrayList(Arrays.asList(s.split(","))); + m.setTypes(genres); + m.setRating(queryResult.getDouble(6)); + m.setNumberOfVotes(queryResult.getInt(7)); + m.setBestMatching(1.0); + data.add(m); + } + } else { + Alert alert = new Alert(AlertType.INFORMATION); + alert.setTitle("Information Dialog"); + alert.setHeaderText(null); + alert.setContentText("Blad polaczenia z baza danych"); + alert.showAndWait(); + } + } catch (SQLException e) { + e.printStackTrace(); + } + + if(!(production.equals(" ") && duration.equals(" ") && userRating.equals(" ") && numberOfVotes.equals(" "))){ + for (Movie m : data) { + m.setBestMatching(calculateBestMatching(m.getProductionYear(), m.getDuration(), m.getRating(), m.getNumberOfVotes())); + } + } + + if (data.size() == 0) { + Alert alert = new Alert(AlertType.INFORMATION); + alert.setTitle("Information Dialog"); + alert.setHeaderText(null); + alert.setContentText("W bazie nie znajduja sie filmy pasujace do podanego zapytania."); + alert.showAndWait(); + } + queryResultTableView.setItems(data); + } + + private double calculateBestMatching(int productionYear, int movieDuration, double rating, int votes) { + String production = productionChoiceBox.getSelectionModel().getSelectedItem(); + String duration = durationChoiceBox.getSelectionModel().getSelectedItem(); + String userRating = userRatingChoiceBox.getSelectionModel().getSelectedItem(); + String numberOfVotes = numberOfVotesChoiceBox.getSelectionModel().getSelectedItem(); + + double matching = 0.0; + +//rok produkcji + if (!production.equals(" ")) { + if (production.equals("Nowy film")) { + matching = fp(2010, 2015, 2015, productionYear); + } else if (production.equals("Sredni film")) { + matching = fpCenter(1995, 2003, 2007, 2015, productionYear); + } else if (production.equals("Stary film")) { + matching = fp(1980, 1980, 2000, productionYear); + } + } +//dlugosc filmu + if (!duration.equals(" ")) { + if (matching != 0) { + if (duration.equals("Dlugiej dlugosci film")) { + matching = (fp(120, 180, 180, movieDuration) + matching) / 2; + } else if (duration.equals("Sredniej dlugosci film")) { + matching = (fpCenter(50, 90, 110, 150, movieDuration) + matching) / 2; + } else if (duration.equals("Krotkiej dlugosci film")) { + matching = (fp(30, 30, 90, movieDuration) + matching) / 2; + } + } else { + if (duration.equals("Dlugiej dlugosci film")) { + matching = fp(120, 180, 180, movieDuration); + } else if (duration.equals("Sredniej dlugosci film")) { + matching = fpCenter(50, 90, 110, 150, movieDuration); + } else if (duration.equals("Krotkiej dlugosci film")) { + matching = fp(30, 30, 90, movieDuration); + } + } + } +//ocena uzytkownikow + if (!userRating.equals(" ")) { + if (matching != 0) { + if (userRating.equals("Dobry film")) { + matching = (fp(5.0, 7.5, 7.5, rating) + matching) / 2; + } else if (userRating.equals("Przecietny film")) { + matching = (fpCenter(2.5, 4, 6, 7.5, rating) + matching) / 2; + } else if (userRating.equals("Slaby film")) { + matching = (fp(2.5, 2.5, 5.0, rating) + matching) / 2; + } + } else { + if (userRating.equals("Dobry film")) { + matching = fp(5.0, 7.5, 7.5, rating); + } else if (userRating.equals("Przecietny film")) { + matching = fpCenter(2.5, 4, 6, 7.5, rating); + } else if (userRating.equals("Slaby film")) { + matching = fp(2.5, 2.5, 5.0, rating); + } + } + } +//ilosc glosow uzytkownikow + if (!numberOfVotes.equals(" ")) { + if (matching != 0) { + if (numberOfVotes.equals("Duza ilosc glosow")) { + matching = (fp(150, 250, 250, votes) + matching) / 2; + } else if (numberOfVotes.equals("Srednia ilosc glosow")) { + matching = (fpCenter(75, 100, 150, 175, votes) + matching) / 2; + } else if (numberOfVotes.equals("Mala ilosc glosow")) { + matching = (fp(50, 50, 100, votes) + matching) / 2; + } + } else { + if (numberOfVotes.equals("Duza ilosc glosow")) { + matching = fp(150, 250, 250, votes); + } else if (numberOfVotes.equals("Srednia ilosc glosow")) { + matching = fpCenter(75, 100, 150, 175, votes); + } else if (numberOfVotes.equals("Mala ilosc glosow")) { + matching = fp(50, 50, 100, votes); + } + } + } + return matching; + } + + double fp(double a, double b, double c, double x) { + double y = -1; + if (a == b) { + if (x <= a) { + return 1; + } else if (x > a && x < c) { + y = (0 - 1) / (c - a) * (x - a) + 1; + return y; + } else { + return 0; + } + } else if (b == c) { + if (x <= a) { + return 0; + } else if (x > a && x < c) { + y = (1 - 0) / (c - a) * (x - a); + return y; + } else { + return 1; + } + } + return y; + } + + double fpCenter(double a, double b, double c, double d, double x) { + double y = -1; + + if (x <= a || x >= d) { + return 0; + } else if (x >= b && x <=c) { + return 1; + } else if (x > a && x < b) { + y = (1 - 0) / (b - a) * (x - a); + return y; + } else { + y = (0 - 1) / (d - c) * (x - c) + 1; + return y; + } + } + + @FXML + void queryFindingTabButtonAction() { + if (!queryFindingTabTextField.getText().isEmpty()) { + + ObservableList data = FXCollections.observableArrayList(); + + try { + connection = DriverManager.getConnection(url, user, password); + if (connection != null) { + Statement statement = connection.createStatement(); + String query = "SELECT * FROM title_join WHERE \"originaltitle\" LIKE '%" + + queryFindingTabTextField.getText() + "%'"; + ResultSet queryResult = statement.executeQuery(query); + while (queryResult.next()) { + Movie m = new Movie(); + m.setTitle(queryResult.getString(2)); + m.setProductionYear(queryResult.getInt(3)); + m.setDuration(queryResult.getInt(4)); + String s = queryResult.getString(5); + ArrayList genres = new ArrayList(Arrays.asList(s.split(","))); + m.setTypes(genres); + m.setRating(queryResult.getDouble(6)); + m.setNumberOfVotes(queryResult.getInt(7)); + data.add(m); + } + } else { + Alert alert = new Alert(AlertType.INFORMATION); + alert.setTitle("Information Dialog"); + alert.setHeaderText(null); + alert.setContentText("Blad polaczenia z baza danych"); + alert.showAndWait(); + } + } catch (SQLException e) { + e.printStackTrace(); + } + queryResultFindingTabTableView.setItems(data); + } else { + Alert alert = new Alert(AlertType.INFORMATION); + alert.setTitle("Information Dialog"); + alert.setHeaderText(null); + alert.setContentText("Wpisz tytul lub jego fragment"); + alert.showAndWait(); + } + } + + @FXML + void addOpinionButtonAction() { + if(!opinionTabTitleTextField.getText().equals("")) { + try { + FXMLLoader loader = new FXMLLoader(this.getClass().getResource("addOpinionView.fxml")); + Parent root = (Parent) loader.load(); + Stage stage = new Stage(); + stage.setTitle("Add new opinion"); + stage.setScene(new Scene(root)); + stage.show(); + SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy"); + Date date = new Date(); + TextField textField = (TextField) root.lookup("#addOpinionTitleTextField"); + textField.setText(opinionTabTitleTextField.getText()); + textField.setEditable(false); + textField = (TextField) root.lookup("#addOpinionDateTextField"); + textField.setText(formatter.format(date)); + textField.setEditable(false); + + } catch (IOException e) { + e.printStackTrace(); + } + }else { + Alert alert = new Alert(AlertType.INFORMATION); + alert.setTitle("Information Dialog"); + alert.setHeaderText(null); + alert.setContentText("Nie mozna dodac opinii bez wybranego filmu"); + alert.showAndWait(); + } + } + + public void updateTableView(String title){ + + ObservableList data = FXCollections.observableArrayList(); + + try { + connection = DriverManager.getConnection(url, user, password); + if (connection != null) { + Statement statement = connection.createStatement(); + String query = "SELECT * FROM movie_opinions WHERE \"originaltitle\" = '" + title + "'"; + ResultSet queryResult = statement.executeQuery(query); + while (queryResult.next()) { + Opinion o = new Opinion(); + o.setTitle(queryResult.getString(2)); + o.setEmail(queryResult.getString(3)); + o.setOpinionDate(queryResult.getString(4)); + o.setOpinion(queryResult.getString(5)); + o.setRating(queryResult.getInt(6)); + o.setNick(queryResult.getString(7)); + data.add(o); + } + } else { + Alert alert = new Alert(AlertType.INFORMATION); + alert.setTitle("Information Dialog"); + alert.setHeaderText(null); + alert.setContentText("Blad polaczenia z baza danych"); + alert.showAndWait(); + } + } catch (SQLException e) { + e.printStackTrace(); + } + opinionsTableView.setItems(data); + } + + @FXML + void refreshButtonAction() { + if(!opinionTabTitleTextField.getText().equals("")) { + updateTableView(opinionTabTitleTextField.getText()); + } + } +} \ No newline at end of file diff --git a/Projekt-LSR/src/application/CreditsController.java b/Projekt-LSR/src/application/CreditsController.java new file mode 100644 index 0000000..68c7c29 --- /dev/null +++ b/Projekt-LSR/src/application/CreditsController.java @@ -0,0 +1,3 @@ +package application; + +public class CreditsController {} diff --git a/Projekt-LSR/src/application/Main.java b/Projekt-LSR/src/application/Main.java new file mode 100644 index 0000000..7d930ca --- /dev/null +++ b/Projekt-LSR/src/application/Main.java @@ -0,0 +1,29 @@ +package application; + +import java.io.IOException; +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.stage.Stage; +import javafx.scene.Scene; +import javafx.scene.layout.AnchorPane; + +public class Main extends Application { + + public static void main(String[] args) {launch(args);} + + @Override + public void start(Stage stage) throws IOException { + try { + FXMLLoader loader = new FXMLLoader(this.getClass().getResource("applicationView.fxml")); + AnchorPane root = loader.load(); + Scene scene = new Scene(root); + stage.setResizable(false); + stage.setTitle("Projekt LSR"); + stage.setScene(scene); + stage.show(); + } catch (IOException e) { + System.out.println(e); + } + } + +} diff --git a/Projekt-LSR/src/application/Movie.java b/Projekt-LSR/src/application/Movie.java new file mode 100644 index 0000000..a94476c --- /dev/null +++ b/Projekt-LSR/src/application/Movie.java @@ -0,0 +1,81 @@ +package application; + +import java.util.ArrayList; + +public class Movie { + private String title; + private ArrayListtypes; + private int productionYear; + private int duration; + private double rating; + private int numberOfVotes; + private double bestMatching; + + public Movie() {} + public Movie(String title, ArrayListtypes, int productionYear, int duration, double rating, int numberOfVotes) { + this.title = title; + this.types = types; + this.productionYear = productionYear; + this.duration = duration; + this.rating = rating; + this.numberOfVotes = numberOfVotes; + this.bestMatching = -1.0; + } + public Movie(String title, ArrayListtypes, int productionYear, int duration, double rating, int numberOfVotes, double bestMatching) { + this.title = title; + this.types = types; + this.productionYear = productionYear; + this.duration = duration; + this.rating = rating; + this.numberOfVotes = numberOfVotes; + this.bestMatching = bestMatching; + } + + public String getTitle() { + return title; + } + public void setTitle(String title) { + this.title = title; + } + + public ArrayList getTypes() { + return types; + } + public void setTypes(ArrayList types) { + this.types = types; + } + + public int getProductionYear() { + return productionYear; + } + public void setProductionYear(int productionYear) { + this.productionYear = productionYear; + } + + public int getDuration() { + return duration; + } + public void setDuration(int duration) { + this.duration = duration; + } + + public double getRating() { + return rating; + } + public void setRating(double rating) { + this.rating = rating; + } + + public int getNumberOfVotes() { + return numberOfVotes; + } + public void setNumberOfVotes(int numberOfVotes) { + this.numberOfVotes = numberOfVotes; + } + public double getBestMatching() { + return bestMatching; + } + public void setBestMatching(double d) { + this.bestMatching = d; + } +} \ No newline at end of file diff --git a/Projekt-LSR/src/application/Opinion.java b/Projekt-LSR/src/application/Opinion.java new file mode 100644 index 0000000..ddb9d49 --- /dev/null +++ b/Projekt-LSR/src/application/Opinion.java @@ -0,0 +1,63 @@ +package application; + +public class Opinion { + private String title; + private String email; + private String date; + private String opinion; + private int rating; + private String nick; + + public Opinion() {} + public Opinion(String title, String email, String date, String opinion, int rating, String nick) { + this.title = title; + this.email = email; + this.date = date; + this.opinion = opinion; + this.rating = rating; + this.nick = nick; + } + + public String getTitle() { + return title; + } + public void setTitle(String title) { + this.title = title; + } + + public String getNick() { + return nick; + } + public void setNick(String nick) { + this.nick = nick; + } + + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } + + public String getDate() { + return date; + } + public void setOpinionDate(String date) { + this.date = date; + } + + public int getRating() { + return rating; + } + public void setRating(int rating) { + this.rating = rating; + } + + public String getOpinion() { + return opinion; + } + public void setOpinion(String opinion) { + this.opinion = opinion; + } + +} \ No newline at end of file diff --git a/Projekt-LSR/src/application/OpinionController.java b/Projekt-LSR/src/application/OpinionController.java new file mode 100644 index 0000000..c90e8fa --- /dev/null +++ b/Projekt-LSR/src/application/OpinionController.java @@ -0,0 +1,128 @@ +package application; + +import java.net.URL; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.ResourceBundle; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.Alert; +import javafx.scene.control.Button; +import javafx.scene.control.ChoiceBox; +import javafx.scene.control.TextArea; +import javafx.scene.control.TextField; +import javafx.scene.control.Alert.AlertType; +import javafx.stage.Stage; + +public class OpinionController implements Initializable { + + private ObservableList observableList; + private String url = "jdbc:postgresql://localhost:5432/fcl"; + private String user = "postgres"; + private String password = "postgres"; + Connection connection; + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + List values = new ArrayList(); + values.add("10"); + values.add("9"); + values.add("8"); + values.add("7"); + values.add("6"); + values.add("5"); + values.add("5"); + values.add("4"); + values.add("3"); + values.add("2"); + values.add("1"); + this.observableList = FXCollections.observableArrayList(); + this.observableList.addAll(values); + ratingChoiceBox.setItems(observableList); + ratingChoiceBox.setValue(values.get(0)); + } + + @FXML + private TextField addOpinionTitleTextField; + + @FXML + private TextField addOpinionNickTextField; + + @FXML + private TextField addOpinionEMailTextField; + + @FXML + private TextField addOpinionDateTextField; + + @FXML + private TextArea addOpinionTextArea; + + @FXML + private ChoiceBox ratingChoiceBox; + + @FXML + private Button closeButton; + + @FXML + void confirmOpinionButtonAction() { + Opinion opinion = new Opinion(); + String patternString = "[^@]+@[^\\.]+\\..+"; + + Pattern pattern = Pattern.compile(patternString); + + Matcher matcher = pattern.matcher(addOpinionEMailTextField.getText()); + boolean matches = matcher.matches(); + + if(!(addOpinionTitleTextField.getText().equals("") || matches == false || addOpinionDateTextField.getText().equals("") || + addOpinionTextArea.getText().equals("") || addOpinionNickTextField.getText().equals(""))) { + + opinion.setTitle(addOpinionTitleTextField.getText()); + opinion.setEmail(addOpinionEMailTextField.getText()); + opinion.setOpinionDate(addOpinionDateTextField.getText()); + opinion.setOpinion(addOpinionTextArea.getText()); + opinion.setRating(Integer.valueOf(ratingChoiceBox.getSelectionModel().getSelectedItem())); + opinion.setNick(addOpinionNickTextField.getText()); + + insertOpinion(opinion); + + Stage stage = (Stage) closeButton.getScene().getWindow(); + stage.close(); + }else { + Alert alert = new Alert(AlertType.INFORMATION); + alert.setTitle("Information Dialog"); + alert.setHeaderText(null); + alert.setContentText("Nie mozna dodac opinii do podanego filmu bez wymaganych danych"); + alert.showAndWait(); + } + } + + private void insertOpinion(Opinion opinion) { + String query = "INSERT INTO movie_opinions(tconst, originaltitle, email, date, opinion, rating, nick) " + + "VALUES(?,?,?,?,?,?,?)"; + try ( + Connection conn = DriverManager.getConnection(url, user, password); + PreparedStatement statement = conn.prepareStatement(query);) { + statement.setString(1, "1"); + statement.setString(2, opinion.getTitle()); + statement.setString(3, opinion.getEmail()); + statement.setString(4, opinion.getDate()); + statement.setString(5, opinion.getOpinion()); + statement.setInt(6, opinion.getRating()); + statement.setString(7, opinion.getNick()); + + statement.addBatch(); + statement.executeBatch(); + } catch (SQLException ex) { + System.out.println(ex.getMessage()); + } + } +} \ No newline at end of file diff --git a/Projekt-LSR/src/application/addOpinionView.fxml b/Projekt-LSR/src/application/addOpinionView.fxml new file mode 100644 index 0000000..2b15809 --- /dev/null +++ b/Projekt-LSR/src/application/addOpinionView.fxml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Raport końcowy.docx b/Raport końcowy.docx new file mode 100644 index 0000000..806ec41 Binary files /dev/null and b/Raport końcowy.docx differ