浏览代码

Added updateMovie

toomanysugar 4 年之前
父节点
当前提交
e6b7e534c9

二进制
out/production/JavaFxApplication/com/moviesdb/Controller.class


+ 12 - 2
out/production/JavaFxApplication/com/moviesdb/test2.fxml

@@ -133,9 +133,9 @@
                   <Label layoutX="822.0" layoutY="19.0" text="Button" textFill="#9f9f9f" AnchorPane.rightAnchor="22.0" AnchorPane.topAnchor="19.0" />
                </children>
             </AnchorPane>
-        <AnchorPane fx:id="detailsPane" maxWidth="0.0" minWidth="0.0" prefWidth="0.0" style="-fx-background-color: #212121;" SplitPane.resizableWithParent="false">
+        <AnchorPane fx:id="detailsPane" maxWidth="0.0" minWidth="0.0" prefHeight="550.0" prefWidth="318.0" style="-fx-background-color: #212121;" SplitPane.resizableWithParent="false">
           <children>
-            <Label alignment="CENTER" font="$x1" layoutX="14.0" layoutY="14.0" style="&#10;" text="Details" textAlignment="CENTER" textFill="$x2" wrapText="false" />
+            <Label alignment="CENTER" font="$x1" layoutX="14.0" layoutY="14.0" style="&#10;" text="Details" textAlignment="CENTER" textFill="#9f9f9f" wrapText="false" />
                   <AnchorPane fx:id="detailsPicPane" layoutX="14.0" layoutY="41.0" prefHeight="222.0" AnchorPane.bottomAnchor="287.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="9.0" AnchorPane.topAnchor="41.0" />
                   <Label fx:id="detailsNameLabel" layoutX="14.0" layoutY="265.0" text="Info" textFill="#9f9f9f">
                      <font>
@@ -143,6 +143,16 @@
                      </font>
                   </Label>
                   <TextFlow fx:id="detailsContent" layoutX="14.0" layoutY="287.0" prefHeight="255.0" prefWidth="277.0" />
+                  <Label fx:id="deleteMovieButton" layoutX="-14.0" layoutY="528.0" text="Delete" textFill="#9f9f9f" AnchorPane.bottomAnchor="14.0" AnchorPane.rightAnchor="14.0">
+                     <font>
+                        <Font size="16.0" />
+                     </font>
+                  </Label>
+                  <Label fx:id="editMovieButton" layoutX="212.0" layoutY="534.0" text="Edit" textFill="#9f9f9f" AnchorPane.bottomAnchor="14.0" AnchorPane.rightAnchor="71.0">
+                     <font>
+                        <Font size="16.0" />
+                     </font>
+                  </Label>
 
 
           </children>

+ 59 - 1
src/com/moviesdb/DataBaseConnector.java

@@ -153,7 +153,6 @@ public class DataBaseConnector {
             Statement statement = conn.createStatement();
             String req;
 
-            String commandString;
             String intoPart = "";
             String valPart = "";
 
@@ -218,6 +217,65 @@ public class DataBaseConnector {
         }
     }
 
+    public void updateMovie(Movie oldMovie, Movie newMovie) {
+        try {
+            Statement statement = conn.createStatement();
+            String req;
+
+            String intoPart = "";
+
+            if (!oldMovie.name().equals(newMovie.name())) {
+                intoPart += " `name` = '" + newMovie.name() + "',";
+            }
+
+            if (!oldMovie.genre().equals(newMovie.genre())) {
+                intoPart += " `genre` = '" + newMovie.genre() + "',";
+            }
+
+            if (!oldMovie.description().equals(newMovie.description())) {
+                intoPart += " `description` = '" + newMovie.description() + "',";
+            }
+
+            if (!oldMovie.duration().equals(newMovie.duration())) {
+                intoPart += " `duration` = '" + newMovie.duration() + "',";
+            }
+
+            if (!oldMovie.rating().equals(newMovie.rating())) {
+                intoPart += " `user_rating` = '" + newMovie.rating() + "',";
+            }
+
+            if (!oldMovie.year().equals(newMovie.year())) {
+                intoPart += " `year` = '" + newMovie.year() + "',";
+            }
+
+            if (!oldMovie.studio().equals(newMovie.studio())) {
+                intoPart += " `studio` = '" + newMovie.studio() + "',";
+            }
+
+            if (!oldMovie.director().equals(newMovie.director())) {
+                intoPart += " `director` = '" + newMovie.director() + "',";
+            }
+
+            if (!oldMovie.getImageLink().equals(newMovie.getImageLink())) {
+                intoPart += " `image_link` = '" + newMovie.getImageLink() + "',";
+            }
+
+            if (intoPart.charAt(intoPart.length() - 1) == ',')
+                intoPart = intoPart.substring(0, intoPart.length() - 1);
+
+            //сборка текста запроса
+
+            req = "UPDATE Movies SET" + intoPart;
+            req += " WHERE (`id` = '" + oldMovie.id() + "');";
+
+
+            //выполнение запроса
+            statement.execute(req);
+        } catch (SQLException ex) {
+            ex.printStackTrace();
+        }
+    }
+
     public boolean granted(String grantName){
         return connRights.contains(grantName);
     }