javaFx 图书管理系统,采用 jfoenix-8.0.4 开源框架,使用 MaterialDesighn 风格
前一阵子使用javafx开发了医院管理系统,整体感觉还不错,主要是能用css样式文件进行美化。
我的GitHub ,欢迎大家start,项目地址:
https://github.com/alimjan02/javaFx-jfoenix-8.0.4-MaterialDesighn
这次发现了一个好东西 jfoenix-8.0.4 开源框架 ,是基于javafx改变的一个框架,是使用了Android设计的 MaterialDesighn 风格,控件很漂亮。最近上的数据库课程需要写一个数据库应用系统,就用它试了一下,整体感觉很棒,下面看看效果吧
- 登录界面
首先是登录界面,使用JFXTextField作为输入框,点击得到focus以后的效果很不错,登录使用了多线程,因为按钮有自己的动画效果,当用户身份查询查询匹配数据库信息时要等待,这样导致有些动画效果不流畅,因此多线程完美解决了这一点。
记住密码功能使用了文件存储。
登录过程中还有进度条。
2.读者界面
3.管理员界面
源代码:
1.主类
1 package sample; 2 3 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader; 4 import javafx.application.Application; 5 import javafx.fxml.FXMLLoader; 6 import javafx.fxml.LoadException; 7 import javafx.scene.Parent; 8 import javafx.scene.Scene; 9 import javafx.scene.control.Label; 10 import javafx.scene.image.Image; 11 import javafx.scene.layout.StackPane; 12 import javafx.stage.Stage; 13 import javafx.stage.StageStyle; 14 15 public class Main extends Application { 16 17 private Stage mainStage; 18 19 @Override 20 public void start(Stage primaryStage) throws Exception{ 21 mainStage = primaryStage; 22 mainStage.setResizable(false); 23 //设置窗口的图标. 24 mainStage.getIcons().add(new Image( 25 Main.class.getResourceAsStream("logo.png"))); 26 FXMLLoader loader = new FXMLLoader(getClass().getResource("sample.fxml")); 27 Parent root = loader.load(); 28 primaryStage.setTitle("图书管理系统"); 29 Controller controller = loader.getController(); 30 controller.setApp(this); 31 Scene scene = new Scene(root, 700, 460); 32 scene.getStylesheets().add(Main.class.getResource("main.css").toExternalForm()); 33 primaryStage.setScene(scene); 34 primaryStage.show(); 35 } 36 37 public void gotoMainUi(String userId) { 38 try { 39 FXMLLoader loader = new FXMLLoader(getClass().getResource("main_ui.fxml")); 40 Parent root = loader.load(); 41 mainStage.setTitle("图书管理系统"); 42 MainUiController controller = loader.getController(); 43 controller.setApp(this); 44 controller.setMyName(userId); 45 Scene scene = new Scene(root, 700, 500); 46 scene.getStylesheets().add(Main.class.getResource("main.css").toExternalForm()); 47 mainStage.setScene(scene); 48 mainStage.show(); 49 } catch (Exception e) { 50 System.out.println(e.getMessage()); 51 } 52 53 } 54 55 public void gotoReaderUi(String id) { 56 try { 57 FXMLLoader loader = new FXMLLoader(getClass().getResource("reader_ui.fxml")); 58 Parent root = loader.load(); 59 mainStage.setTitle("图书管理系统"); 60 ReaderUi controller = loader.getController(); 61 controller.setApp(this); 62 controller.setUserInfo(id); 63 Scene scene = new Scene(root, 700, 460); 64 scene.getStylesheets().add(Main.class.getResource("main.css").toExternalForm()); 65 mainStage.setScene(scene); 66 mainStage.show(); 67 } catch (Exception e) { 68 System.out.println(e.getMessage()+e.toString()); 69 } 70 71 } 72 73 public void closeWindow() { 74 mainStage.close(); 75 } 76 77 public void hideWindow(){ mainStage.hide();} 78 79 public void showWindow(){ mainStage.show();} 80 81 82 public static void main(String[] args) { 83 launch(args); 84 } 85 86 public void gotoLoginUi() { 87 try { 88 FXMLLoader loader = new FXMLLoader(getClass().getResource("sample.fxml")); 89 Parent root = loader.load(); 90 mainStage.setTitle("图书管理系统"); 91 Controller controller = loader.getController(); 92 controller.setApp(this); 93 Scene scene = new Scene(root, 700, 460); 94 scene.getStylesheets().add(Main.class.getResource("main.css").toExternalForm()); 95 mainStage.setScene(scene); 96 mainStage.show(); 97 } catch (Exception e) { 98 System.out.println(e.toString()); 99 } 100 101 } 102 }
2.登陆界面controller
1 package sample; 2 3 import Util.DataBaseUtil; 4 import Util.FileUtil; 5 import com.jfoenix.controls.*; 6 import com.jfoenix.validation.RequiredFieldValidator; 7 import javafx.application.Platform; 8 import javafx.concurrent.Task; 9 import javafx.fxml.FXML; 10 import javafx.fxml.FXMLLoader; 11 import javafx.fxml.Initializable; 12 import javafx.scene.Parent; 13 import javafx.scene.Scene; 14 import javafx.scene.control.Alert; 15 import javafx.scene.control.ToggleGroup; 16 import javafx.stage.Stage; 17 18 import java.awt.*; 19 import java.io.IOException; 20 import java.net.URL; 21 import java.util.Arrays; 22 import java.util.ResourceBundle; 23 import java.util.concurrent.TimeUnit; 24 import java.util.logging.Handler; 25 import java.util.regex.Pattern; 26 27 import static java.lang.Thread.sleep; 28 29 public class Controller implements Initializable { 30 31 @FXML 32 public ToggleGroup identity; 33 34 private Main myApp; 35 36 @FXML 37 private JFXCheckBox rememberInfo; 38 39 @FXML 40 private JFXProgressBar prgs_login; 41 42 @FXML 43 private JFXButton btn_start; 44 45 @FXML 46 private JFXTextField tf_user; 47 48 @FXML 49 private JFXPasswordField tf_passWord; 50 51 @FXML 52 private JFXRadioButton rb_duzhe; 53 54 @FXML 55 private JFXRadioButton rb_gzry; 56 57 JFXDialog dialog = new JFXDialog(); 58 59 private Thread thread; 60 61 public void setApp(Main myApp) { 62 this.myApp = myApp; 63 } 64 65 @Override 66 public void initialize(URL location, ResourceBundle resources) { 67 68 rememberInfo.setSelected(true); 69 70 RequiredFieldValidator validator = new RequiredFieldValidator(); 71 validator.setMessage("请输入用户名..."); 72 tf_user.getValidators().add(validator); 73 tf_user.focusedProperty().addListener((o,oldVal,newVal)->{ 74 if(!newVal) tf_user.validate(); 75 }); 76 77 RequiredFieldValidator validator2 = new RequiredFieldValidator(); 78 validator2.setMessage("请输入密码..."); 79 tf_passWord.getValidators().add(validator2); 80 tf_passWord.focusedProperty().addListener((o,oldVal,newVal)->{ 81 if(!newVal) tf_passWord.validate(); 82 }); 83 84 rb_duzhe.setSelected(true); 85 // lb_Title.setIcon(new ImageIcon(LogOnFrm.class.getResource("/images/logo.png"))); 86 // dialog.setContent(new Label("Content")); 87 // btn_start.setOnAction((action)->dialog.show()); 88 prgs_login.setVisible(false); 89 String str = FileUtil.getUserAndPass(); 90 Pattern p = Pattern.compile("[#]+"); 91 String[] result = p.split(str); 92 if (result.length >= 1) { 93 tf_user.setText(result[0]); 94 } 95 if (result.length >= 2) { 96 tf_passWord.setText(result[1]); 97 } 98 99 } 100 101 /** 102 * 登录按钮点击事件 103 */ 104 @FXML 105 public void onStart() { 106 System.out.println("ok"); 107 prgs_login.setVisible(true); 108 //创建线程登录 109 myProgress myProgress = new myProgress(prgs_login); 110 thread = new Thread(myProgress); 111 thread.setPriority(Thread.MAX_PRIORITY); 112 thread.start(); 113 114 if (rememberInfo.isSelected()) { 115 FileUtil.setUserAndPass(tf_user.getText(), tf_passWord.getText()); 116 }else{ 117 FileUtil.setUserAndPass(tf_user.getText(), ""); 118 } 119 120 //登录界面控件不可见 121 setDisable(true); 122 123 124 // prgs_login.setVisible(false); 125 } 126 127 /** 128 * 登录期间------组件的控制-----登录界面控件不可见 129 */ 130 public void setDisable(Boolean bool) { 131 btn_start.setDisable(bool); 132 tf_user.setDisable(bool); 133 tf_passWord.setDisable(bool); 134 rememberInfo.setDisable(bool); 135 } 136 137 138 /** 139 * 检查并登录 140 */ 141 private void doCheckUser() { 142 if (identity.getSelectedToggle() == rb_duzhe) { 143 if (DataBaseUtil.checkReader(tf_user.getText().trim(),tf_passWord.getText())) { 144 myApp.gotoReaderUi(tf_user.getText()); 145 } else { 146 setDisable(false); 147 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 148 alert.setAlertType(Alert.AlertType.ERROR); 149 alert.setTitle("登录失败!"); 150 alert.show(); 151 } 152 } else if (identity.getSelectedToggle() == rb_gzry) { 153 if (DataBaseUtil.checkUser(tf_user.getText().trim(),tf_passWord.getText())) { 154 myApp.gotoMainUi(tf_user.getText()); 155 } else { 156 setDisable(false); 157 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 158 alert.setAlertType(Alert.AlertType.ERROR); 159 alert.setTitle("登录失败!"); 160 alert.show(); 161 } 162 } 163 } 164 165 /** 166 * 忘记密码 167 */ 168 @FXML 169 public void forgotPass() { 170 myApp.hideWindow(); 171 Stage myStage=new Stage(); 172 myStage.setResizable(false); 173 FXMLLoader loader = new FXMLLoader(getClass().getResource("forgotPass.fxml")); 174 Parent root = null; 175 try { 176 root = loader.load(); 177 } catch (IOException e) { 178 e.printStackTrace(); 179 } 180 ForgotPass con = loader.getController(); 181 con.setMyApp(myApp); 182 con.setController(myStage); 183 myStage.setTitle("忘记密码"); 184 Scene scene = new Scene(root, 500, 400); 185 scene.getStylesheets().add(Main.class.getResource("main.css").toExternalForm()); 186 myStage.setScene(scene); 187 myStage.show(); 188 189 } 190 191 192 /** 193 * 登录界面--点击登录按钮后---启用新的线程检查用户身份是否正确 194 */ 195 class myProgress implements Runnable { 196 197 private JFXProgressBar prgs_login; 198 199 myProgress(JFXProgressBar prgs_login) { 200 this.prgs_login = prgs_login; 201 } 202 203 @Override 204 public void run() { 205 try { 206 207 for (int i = 0; i <= 100; i++) { 208 prgs_login.setProgress(i); 209 210 } 211 sleep(100); 212 //更新JavaFX的主线程的代码放在此处 213 Platform.runLater(Controller.this::doCheckUser); 214 215 } catch (Exception ignored) { 216 217 } 218 } 219 } 220 221 222 }
3.登陆界面fxml
1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <?import com.jfoenix.controls.JFXButton?> 4 <?import com.jfoenix.controls.JFXCheckBox?> 5 <?import com.jfoenix.controls.JFXPasswordField?> 6 <?import com.jfoenix.controls.JFXProgressBar?> 7 <?import com.jfoenix.controls.JFXRadioButton?> 8 <?import com.jfoenix.controls.JFXTextField?> 9 <?import javafx.scene.control.Hyperlink?> 10 <?import javafx.scene.control.Label?> 11 <?import javafx.scene.control.Separator?> 12 <?import javafx.scene.control.ToggleGroup?> 13 <?import javafx.scene.layout.AnchorPane?> 14 <?import javafx.scene.text.Font?> 15 16 <AnchorPane id="AnchorPane" fx:id="anchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="485.0" prefWidth="722.0" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller"> 17 <children> 18 <Label layoutX="296.0" layoutY="175.0" text="登录界面" textFill="GOLD"> 19 <font> 20 <Font name="System Bold Italic" size="29.0" /> 21 </font> 22 </Label> 23 <JFXButton fx:id="btn_start" buttonType="RAISED" layoutX="561.0" layoutY="317.0" mnemonicParsing="false" onAction="#onStart" prefHeight="23.0" prefWidth="73.0" text="登录" /> 24 <JFXTextField fx:id="tf_user" focusColor="DEEPSKYBLUE" layoutX="383.0" layoutY="267.0" promptText="请输入用户名..." style="-fx-background-color: #808080;" /> 25 <Label layoutX="329.0" layoutY="271.0" text="用户名" textFill="DARKORANGE"> 26 <font> 27 <Font name="System Bold" size="15.0" /> 28 </font></Label> 29 <Label layoutX="330.0" layoutY="318.0" text="密 码" textFill="DARKORANGE"> 30 <font> 31 <Font name="System Bold" size="15.0" /> 32 </font></Label> 33 <JFXPasswordField fx:id="tf_passWord" focusColor="DEEPSKYBLUE" layoutX="383.0" layoutY="317.0" promptText="请输入密码..." style="-fx-background-color: #808080;" /> 34 <JFXProgressBar fx:id="prgs_login" layoutY="460.0" prefHeight="10.0" prefWidth="722.0" progress="0.0" /> 35 <Label layoutX="77.0" layoutY="120.0" prefHeight="55.0" prefWidth="219.0" text="图书管理系统" textFill="DEEPSKYBLUE"> 36 <font> 37 <Font name="System Bold Italic" size="33.0" /> 38 </font> 39 </Label> 40 <JFXCheckBox fx:id="rememberInfo" layoutX="561.0" layoutY="272.0" mnemonicParsing="false" selected="true" text="记住密码" textFill="WHITE" /> 41 <Separator layoutX="322.0" layoutY="363.0" prefHeight="4.0" prefWidth="344.0" /> 42 <Hyperlink layoutX="564.0" layoutY="374.0" onAction="#forgotPass" prefHeight="21.0" prefWidth="80.0" text=" 忘记密码 ?" textFill="WHITE" /> 43 <JFXRadioButton fx:id="rb_duzhe" layoutX="383.0" layoutY="239.0" mnemonicParsing="false" prefHeight="15.0" prefWidth="66.0" text="读者" textFill="#00e5ff"> 44 <toggleGroup> 45 <ToggleGroup fx:id="identity" /> 46 </toggleGroup> 47 </JFXRadioButton> 48 <JFXRadioButton fx:id="rb_gzry" layoutX="457.0" layoutY="239.0" mnemonicParsing="false" prefHeight="15.0" prefWidth="66.0" text="工作人员" textFill="#00e5ff" toggleGroup="$identity" /> 49 </children> 50 </AnchorPane>
效果如下:
4.读者界面controller
1 package sample; 2 3 import Util.DataBaseUtil; 4 import Util.DateUtils; 5 import com.jfoenix.controls.JFXButton; 6 import com.jfoenix.controls.JFXTextField; 7 import com.jfoenix.validation.RequiredFieldValidator; 8 import javafx.beans.property.DoubleProperty; 9 import javafx.beans.property.SimpleBooleanProperty; 10 import javafx.beans.property.SimpleDoubleProperty; 11 import javafx.beans.value.ObservableValue; 12 import javafx.collections.ObservableList; 13 import javafx.event.ActionEvent; 14 import javafx.event.EventHandler; 15 import javafx.fxml.FXML; 16 import javafx.fxml.Initializable; 17 import javafx.geometry.Insets; 18 import javafx.scene.control.*; 19 import javafx.scene.control.cell.PropertyValueFactory; 20 import javafx.scene.input.KeyCode; 21 import javafx.scene.input.KeyEvent; 22 import javafx.scene.input.MouseEvent; 23 import javafx.scene.layout.StackPane; 24 import javafx.stage.Stage; 25 import javafx.util.Callback; 26 import sample.entity.Book; 27 import sample.entity.Borrow; 28 import sample.entity.Reader; 29 import sample.entity.borrow_record; 30 31 import java.math.BigDecimal; 32 import java.net.URL; 33 import java.text.SimpleDateFormat; 34 import java.util.Date; 35 import java.util.ResourceBundle; 36 37 public class ReaderUi implements Initializable { 38 39 private Reader user; 40 41 @FXML 42 private JFXTextField tf_reader_search;//搜索框 43 @FXML 44 private JFXButton btn_search;//搜索按钮 45 @FXML 46 private JFXTextField tf_search_bookId;//要借图书id 47 @FXML 48 private JFXTextField tf_search_bookName;//要借图书名称 49 @FXML 50 private JFXButton btn_search_confirmBook;//确认借书 51 @FXML 52 private JFXButton btn_search_confirmBorrow;//确认借书 53 54 @FXML 55 private TableView tbv_search_Result;// 56 @FXML 57 private TableColumn tb_column_book_id; 58 @FXML 59 private TableColumn tb_column_book_name; 60 @FXML 61 private TableColumn tb_column_book_type; 62 @FXML 63 private TableColumn tb_column_book_author; 64 @FXML 65 private TableColumn tb_column_book_translator; 66 @FXML 67 private TableColumn tb_column_book_publisher; 68 @FXML 69 private TableColumn tb_column_book_publishTime; 70 @FXML 71 private TableColumn tb_column_book_price; 72 73 74 //用户信息 75 @FXML 76 private JFXTextField tf_userInfo_readerId; 77 @FXML 78 private JFXTextField tf_userInfo_readerName; 79 @FXML 80 private JFXTextField tf_userInfo_readerType; 81 @FXML 82 private JFXTextField tf_userInfo_readerSex; 83 @FXML 84 private JFXTextField tf_userInfo_readerMaxNumbers; 85 @FXML 86 private JFXTextField tf_userInfo_readerMaxDays; 87 @FXML 88 private JFXTextField tf_userInfo_readerForfeit; 89 90 @FXML 91 private TableView tbv_userInfo_borrowRecord; 92 @FXML 93 private TableColumn tb_column_userInfo_bookId; 94 @FXML 95 private TableColumn tb_column_userInfo_bookName; 96 @FXML 97 private TableColumn tb_column_userInfo_backDate; 98 @FXML 99 private TableColumn tb_column_userInfo_reBorrow; 100 101 @FXML 102 private Label lb_search_resultNumber; 103 @FXML 104 private Label lb_welcome; 105 @FXML 106 private Label lb_js_reader_jieshu_date; 107 @FXML 108 private Label lb_js_reader_huanshu_date; 109 110 @FXML 111 private JFXTextField tf_userInfo_jiaoKuan; 112 113 private Main myApp; 114 115 public void setApp(Main myApp) { 116 this.myApp = myApp; 117 } 118 119 @Override 120 public void initialize(URL location, ResourceBundle resources) { 121 122 tf_reader_search.setOnKeyPressed(this::tf_reader_search_keyEvent); 123 tf_search_bookId.setOnKeyPressed(this::tf_search_book_keyEvent); 124 125 //所有书目列表初始化 126 tb_column_book_id.setCellValueFactory(new PropertyValueFactory("Id")); 127 tb_column_book_name.setCellValueFactory(new PropertyValueFactory("name")); 128 tb_column_book_type.setCellValueFactory(new PropertyValueFactory("type")); 129 tb_column_book_author.setCellValueFactory(new PropertyValueFactory("author")); 130 tb_column_book_translator.setCellValueFactory(new PropertyValueFactory("translator")); 131 tb_column_book_publisher.setCellValueFactory(new PropertyValueFactory("publisher")); 132 tb_column_book_publishTime.setCellValueFactory(new PropertyValueFactory("publishTime")); 133 tb_column_book_price.setCellValueFactory(new PropertyValueFactory("price")); 134 135 RequiredFieldValidator validator = new RequiredFieldValidator(); 136 validator.setMessage("请输入..."); 137 tf_search_bookId.getValidators().add(validator); 138 tf_search_bookId.getValidators().add(validator); 139 tf_search_bookId.focusedProperty().addListener((o,oldVal,newVal)->{ 140 if(!newVal) tf_search_bookId.validate(); 141 }); 142 143 } 144 145 146 //Define the button cell 147 private class ButtonCell extends TableCell<borrow_record, Boolean> { 148 final Button cellButton = new Button("续借"); 149 150 ButtonCell(){ 151 cellButton.setOnAction(t -> { 152 // do something when button clicked 153 tbv_userInfo_borrowRecord.getSelectionModel().select(getTableRow().getIndex()); 154 ObservableList<borrow_record> userbb = tbv_userInfo_borrowRecord.getItems(); 155 System.out.println("图书ID-->"+userbb.get(getTableRow().getIndex()).getBookId()+userbb.get(getTableRow().getIndex()).getBookName()); 156 String bookId = userbb.get(getTableRow().getIndex()).getBookId(); 157 String backDate = userbb.get(getTableRow().getIndex()).getBackDate(); 158 userBorrowBookXuJie(bookId,backDate); 159 }); 160 } 161 162 //Display button if the row is not empty 163 @Override 164 protected void updateItem(Boolean t, boolean empty) { 165 super.updateItem(t, empty); 166 if(!empty){ 167 setGraphic(cellButton); 168 } 169 } 170 } 171 172 private void userBorrowBookXuJie(String bookId, String backDate) { 173 String bDate = DateUtils.getAfterDay(backDate, user.getDays_num()); 174 if (user.getForfeit() > 0) { 175 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 176 alert.setAlertType(Alert.AlertType.INFORMATION); 177 alert.setContentText("有超期数目欠款,续借失败!"); 178 alert.setTitle("续借失败!"); 179 alert.show(); 180 } else { 181 boolean isok = DataBaseUtil.reBorrow(user.getId(),bookId,bDate); 182 if (isok) { 183 getBorrowedRecordings(user.getId()); 184 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 185 alert.setAlertType(Alert.AlertType.INFORMATION); 186 alert.setContentText("续借成功,应还日期为:" + bDate); 187 alert.setTitle("续借成功!"); 188 alert.show(); 189 } 190 } 191 192 } 193 194 /** 195 * 退出登录 196 */ 197 @FXML 198 public void hbrlink_goto_login() { 199 myApp.gotoLoginUi(); 200 } 201 202 /** 203 * 确认图书 204 * @param keyEvent 205 */ 206 private void tf_search_book_keyEvent(KeyEvent keyEvent) { 207 if (keyEvent.getCode().equals(KeyCode.ENTER)) { 208 Book book = DataBaseUtil.getBook(tf_search_bookId.getText()); 209 if (book != null) { 210 tf_search_bookName.setText(book.getName()); 211 } 212 } 213 } 214 215 @FXML 216 public void tf_search_book() { 217 if (!tf_search_bookId.getText().equals("")) { 218 Book book = DataBaseUtil.getBook(tf_search_bookId.getText()); 219 if (book != null) { 220 tf_search_bookName.setText(book.getName()); 221 } 222 } else { 223 tf_search_bookId.validate(); 224 } 225 } 226 227 /** 228 * 搜索图书---监听回车 229 * @param keyEvent 230 */ 231 private void tf_reader_search_keyEvent(KeyEvent keyEvent) { 232 if (keyEvent.getCode().equals(KeyCode.ENTER)) { 233 ObservableList<Book> books = DataBaseUtil.getAllLikesBooks(tf_reader_search.getText()); 234 if (books != null) { 235 tbv_search_Result.setItems(books); 236 lb_search_resultNumber.setText(tbv_search_Result.getItems().size()+" 条记录"); 237 } 238 } 239 } 240 241 /** 242 * 搜索图书 243 */ 244 @FXML 245 private void tf_reader_search() { 246 ObservableList<Book> books = DataBaseUtil.getAllLikesBooks(tf_reader_search.getText()); 247 if (books != null) { 248 tbv_search_Result.setItems(books); 249 lb_search_resultNumber.setText(tbv_search_Result.getItems().size()+" 条记录"); 250 } 251 } 252 253 /** 254 * 设置用户信息 255 * @param id 256 */ 257 public void setUserInfo(String id) { 258 Reader reader = DataBaseUtil.getReader(id); 259 if (reader != null) { 260 user = reader; 261 tf_userInfo_readerId.setText(reader.getId()); 262 tf_userInfo_readerName.setText(reader.getName()); 263 tf_userInfo_readerType.setText(reader.getType()); 264 tf_userInfo_readerSex.setText(reader.getSex()); 265 tf_userInfo_readerMaxNumbers.setText(reader.getMax_num()+""); 266 tf_userInfo_readerMaxDays.setText(reader.getDays_num()+""); 267 tf_userInfo_readerForfeit.setText(reader.getForfeit() + ""); 268 269 lb_welcome.setText(reader.getName()+" ,您好!"); 270 271 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式 272 //初始化当前时间 273 lb_js_reader_jieshu_date.setText(df.format(new Date())); 274 lb_js_reader_huanshu_date.setText(DateUtils.getAfterDay(lb_js_reader_jieshu_date.getText(), user.getDays_num())); 275 276 getBorrowedRecordings(id); 277 } 278 } 279 280 /** 281 * 获取全部借阅记录 282 */ 283 public void getBorrowedRecordings(String id) { 284 tb_column_userInfo_bookId.setCellValueFactory(new PropertyValueFactory("bookId")); 285 tb_column_userInfo_bookName.setCellValueFactory(new PropertyValueFactory("bookName")); 286 tb_column_userInfo_backDate.setCellValueFactory(new PropertyValueFactory("backDate")); 287 // tb_column_userInfo_reBorrow.setCellValueFactory(new PropertyValueFactory("isBack")); 288 289 tb_column_userInfo_reBorrow.setCellValueFactory((Callback<TableColumn.CellDataFeatures<borrow_record, Boolean>, ObservableValue<Boolean>>) p -> new SimpleBooleanProperty(p.getValue() != null)); 290 tb_column_userInfo_reBorrow.setCellFactory((Callback<TableColumn<borrow_record, Boolean>, TableCell<borrow_record, Boolean>>) p -> new ButtonCell()); 291 //tbv_userInfo_borrowRecord.getColumns().add(tb_column_userInfo_reBorrow); 292 293 ObservableList<borrow_record> borrows = DataBaseUtil.getBorrowRecord(id); 294 if (borrows != null) { 295 tbv_userInfo_borrowRecord.setItems(borrows); 296 } 297 } 298 299 public void borrow_book() { 300 if (!tf_search_bookId.getText().trim().equals("")) { 301 boolean isBorrow = DataBaseUtil.addNewBorrow(tf_search_bookId.getText(), user.getId(), lb_js_reader_jieshu_date.getText(), lb_js_reader_huanshu_date.getText(), 0); 302 if (isBorrow) { 303 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 304 alert.setAlertType(Alert.AlertType.INFORMATION); 305 alert.setContentText("借书成功!"); 306 alert.setTitle("借书成功!"); 307 alert.show(); 308 getBorrowedRecordings(user.getId()); 309 tf_search_bookId.setText(""); 310 tf_search_bookName.setText(""); 311 } else { 312 Alert alert = new Alert(Alert.AlertType.ERROR); 313 alert.setAlertType(Alert.AlertType.ERROR); 314 alert.setContentText("借书失败!"); 315 alert.setTitle("借书失败!"); 316 alert.show(); 317 } 318 } else { 319 tf_search_bookId.validate(); 320 } 321 } 322 323 public void jiaokuan() { 324 if (user.getForfeit() > 0) { 325 if (!tf_userInfo_jiaoKuan.getText().trim().equals("")) { 326 double jiaokuanFirst = user.getForfeit() - Double.parseDouble(tf_userInfo_jiaoKuan.getText().trim()); 327 BigDecimal bg = new BigDecimal(jiaokuanFirst); 328 double jiaokuan = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 329 boolean isok; 330 if (jiaokuan < 0) { 331 isok = DataBaseUtil.jiaokuan(user.getId(), 0); 332 if (isok) { 333 Alert alert = new Alert(Alert.AlertType.ERROR); 334 alert.setAlertType(Alert.AlertType.ERROR); 335 alert.setContentText("支付成功!找零为 " + Math.abs(jiaokuan) + "¥"); 336 alert.setTitle("提示!"); 337 alert.show(); 338 } else { 339 Alert alert = new Alert(Alert.AlertType.ERROR); 340 alert.setAlertType(Alert.AlertType.ERROR); 341 alert.setContentText("系统错误,支付失败!"); 342 alert.setTitle("提示!"); 343 alert.show(); 344 } 345 }else{ 346 isok = DataBaseUtil.jiaokuan(user.getId(), Math.abs(jiaokuan)); 347 if (isok) { 348 Alert alert = new Alert(Alert.AlertType.ERROR); 349 alert.setAlertType(Alert.AlertType.ERROR); 350 alert.setContentText("支付成功!还需交款: " + Math.abs(jiaokuan) + "¥"); 351 alert.setTitle("提示!"); 352 alert.show(); 353 } else { 354 Alert alert = new Alert(Alert.AlertType.ERROR); 355 alert.setAlertType(Alert.AlertType.ERROR); 356 alert.setContentText("系统错误,支付失败!"); 357 alert.setTitle("提示!"); 358 alert.show(); 359 } 360 } 361 setUserInfo(user.getId()); 362 tf_userInfo_jiaoKuan.setText(""); 363 } else { 364 Alert alert = new Alert(Alert.AlertType.ERROR); 365 alert.setAlertType(Alert.AlertType.ERROR); 366 alert.setContentText("请输入交款金额!"); 367 alert.setTitle("提示!"); 368 alert.show(); 369 } 370 } else { 371 Alert alert = new Alert(Alert.AlertType.ERROR); 372 alert.setAlertType(Alert.AlertType.ERROR); 373 alert.setContentText("无超期欠款,无需支付!"); 374 alert.setTitle("提示!"); 375 alert.show(); 376 tf_userInfo_jiaoKuan.setText(""); 377 } 378 } 379 380 381 }
5.读者界面fxml
1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <?import com.jfoenix.controls.JFXButton?> 4 <?import com.jfoenix.controls.JFXTabPane?> 5 <?import com.jfoenix.controls.JFXTextField?> 6 <?import javafx.scene.control.Hyperlink?> 7 <?import javafx.scene.control.Label?> 8 <?import javafx.scene.control.Separator?> 9 <?import javafx.scene.control.Tab?> 10 <?import javafx.scene.control.TableColumn?> 11 <?import javafx.scene.control.TableView?> 12 <?import javafx.scene.layout.AnchorPane?> 13 <?import javafx.scene.text.Font?> 14 15 <AnchorPane prefHeight="498.0" prefWidth="700.0" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.ReaderUi"> 16 <Label layoutX="314.0" layoutY="36.0" text="读者界面" textFill="GOLD"> 17 <font> 18 <Font name="System Bold Italic" size="18.0" /> 19 </font> 20 </Label> 21 22 <JFXTabPane layoutX="14.0" layoutY="88.0" prefHeight="385.0" prefWidth="669.0" tabClosingPolicy="UNAVAILABLE"> 23 <Tab text="查询"> 24 <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="577.0"> 25 <JFXButton fx:id="btn_search_confirmBook" layoutX="553.0" layoutY="235.0" mnemonicParsing="false" onAction="#tf_search_book" text="确认图书" /> 26 <JFXTextField fx:id="tf_reader_search" alignment="CENTER" focusColor="DEEPSKYBLUE" layoutX="58.0" layoutY="39.0" prefHeight="23.0" prefWidth="481.0" promptText="搜索书名/作者/出版社/类别" style="-fx-background-color: #808080;" /> 27 <JFXButton fx:id="btn_search" layoutX="549.0" layoutY="39.0" mnemonicParsing="false" onAction="#tf_reader_search" prefHeight="23.0" prefWidth="72.0" text="搜索" /> 28 <TableView fx:id="tbv_search_Result" layoutX="23.0" layoutY="93.0" prefHeight="124.0" prefWidth="624.0"> 29 <columns> 30 <TableColumn fx:id="tb_column_book_id" prefWidth="63.99998474121094" text="图书ID" /> 31 <TableColumn fx:id="tb_column_book_name" prefWidth="100.0" text="图书名称" /> 32 <TableColumn fx:id="tb_column_book_type" prefWidth="78.0" text="图书类别" /> 33 <TableColumn fx:id="tb_column_book_author" prefWidth="55.0" text="作者" /> 34 <TableColumn fx:id="tb_column_book_translator" prefWidth="62.0" text="译者" /> 35 <TableColumn fx:id="tb_column_book_publisher" prefWidth="98.0" text="出版社" /> 36 <TableColumn fx:id="tb_column_book_publishTime" prefWidth="95.0" text="出版时间" /> 37 <TableColumn fx:id="tb_column_book_price" prefWidth="69.0" text="价格" /> 38 </columns> 39 </TableView> 40 <Label layoutX="77.0" layoutY="237.0" text="图书ID" textFill="#2196f3"> 41 <font> 42 <Font name="System Bold Italic" size="15.0" /> 43 </font> 44 </Label> 45 <JFXTextField fx:id="tf_search_bookId" focusColor="DEEPSKYBLUE" layoutX="134.0" layoutY="235.0" prefHeight="23.0" prefWidth="185.0" style="-fx-background-color: #F5F5F5;" /> 46 <JFXTextField fx:id="tf_search_bookName" editable="false" focusColor="DEEPSKYBLUE" layoutX="391.0" layoutY="235.0" style="-fx-background-color: #F5F5F5;" /> 47 <Label layoutX="335.0" layoutY="239.0" text="图书名称" textFill="WHITE" /> 48 <JFXButton fx:id="btn_search_confirmBorrow" layoutX="549.0" layoutY="292.0" mnemonicParsing="false" onAction="#borrow_book" prefHeight="23.0" prefWidth="72.0" text="确认借书" /> 49 <Label layoutX="62.0" layoutY="76.0" text="总共:" textFill="#f8f8f8" /> 50 <Label fx:id="lb_search_resultNumber" layoutX="101.0" layoutY="76.0" text="0 条记录" textFill="WHITE" /> 51 <Label layoutX="84.0" layoutY="294.0" text="借书日期" textFill="#d84315" /> 52 <Label layoutX="342.0" layoutY="294.0" text="应还日期" textFill="#d84315" /> 53 <Label fx:id="lb_js_reader_jieshu_date" alignment="CENTER" layoutX="155.0" layoutY="294.0" prefHeight="15.0" prefWidth="95.0"> 54 <font> 55 <Font name="System Bold" size="13.0" /> 56 </font></Label> 57 <Label fx:id="lb_js_reader_huanshu_date" alignment="CENTER" layoutX="421.0" layoutY="294.0" prefHeight="15.0" prefWidth="92.0"> 58 <font> 59 <Font name="System Bold" size="13.0" /> 60 </font></Label> 61 </AnchorPane> 62 </Tab> 63 <Tab text="个人信息"> 64 <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="577.0"> 65 <children> 66 <Label layoutX="60.0" layoutY="53.0" text="用户ID" textFill="#2196f3"> 67 <font> 68 <Font name="System Bold Italic" size="15.0" /> 69 </font> 70 </Label> 71 <Label layoutX="71.0" layoutY="98.0" text="姓名" textFill="#03a9f4"> 72 <font> 73 <Font name="System Bold Italic" size="12.0" /> 74 </font></Label> 75 <Label layoutX="71.0" layoutY="127.0" text="身份" textFill="#03a9f4"> 76 <font> 77 <Font name="System Bold" size="12.0" /> 78 </font></Label> 79 <Label layoutX="71.0" layoutY="159.0" text="性别" textFill="#03a9f4"> 80 <font> 81 <Font name="System Bold" size="12.0" /> 82 </font></Label> 83 <Label layoutX="59.0" layoutY="208.0" text="可借数量" /> 84 <Label layoutX="59.0" layoutY="238.0" text="可借天数" /> 85 <JFXTextField fx:id="tf_userInfo_readerId" alignment="CENTER" editable="false" focusColor="DEEPSKYBLUE" layoutX="118.0" layoutY="51.0" style="-fx-background-color: #808080;" unFocusColor="#bfbbbb" /> 86 <JFXTextField fx:id="tf_userInfo_readerName" alignment="CENTER" editable="false" focusColor="DEEPSKYBLUE" layoutX="118.0" layoutY="94.0" style="-fx-background-color: #F5F5F5;" unFocusColor="#bfbbbb" /> 87 <JFXTextField fx:id="tf_userInfo_readerType" alignment="CENTER" editable="false" focusColor="DEEPSKYBLUE" layoutX="118.0" layoutY="123.0" style="-fx-background-color: #F5F5F5;" unFocusColor="#bfbbbb" /> 88 <JFXTextField fx:id="tf_userInfo_readerSex" alignment="CENTER" editable="false" focusColor="DEEPSKYBLUE" layoutX="118.0" layoutY="155.0" style="-fx-background-color: #F5F5F5;" unFocusColor="#bfbbbb" /> 89 <JFXTextField fx:id="tf_userInfo_readerMaxNumbers" alignment="CENTER" editable="false" focusColor="DEEPSKYBLUE" layoutX="118.0" layoutY="204.0" /> 90 <JFXTextField fx:id="tf_userInfo_readerMaxDays" alignment="CENTER" editable="false" focusColor="DEEPSKYBLUE" layoutX="118.0" layoutY="234.0" /> 91 <Separator layoutX="294.0" layoutY="51.0" prefHeight="3.0" prefWidth="360.0" /> 92 <Label layoutX="449.0" layoutY="27.0" text="借阅记录" textFill="WHITE" /> 93 <TableView fx:id="tbv_userInfo_borrowRecord" layoutX="307.0" layoutY="70.0" prefHeight="200.0" prefWidth="332.0"> 94 <columns> 95 <TableColumn fx:id="tb_column_userInfo_bookId" prefWidth="57.0" text="图书ID" /> 96 <TableColumn fx:id="tb_column_userInfo_bookName" prefWidth="136.0" text="图书名称" /> 97 <TableColumn fx:id="tb_column_userInfo_backDate" prefWidth="75.0" text="到期时间" /> 98 <TableColumn fx:id="tb_column_userInfo_reBorrow" minWidth="0.0" prefWidth="63.0" text="续借" /> 99 </columns> 100 </TableView> 101 <Label layoutX="59.0" layoutY="277.0" text="罚款金额" textFill="#eb0f0f" /> 102 <JFXTextField fx:id="tf_userInfo_readerForfeit" alignment="CENTER" editable="false" focusColor="#eb0707" layoutX="118.0" layoutY="273.0" /> 103 <JFXButton layoutX="224.0" layoutY="308.0" mnemonicParsing="false" onAction="#jiaokuan" text="提交" /> 104 <JFXTextField fx:id="tf_userInfo_jiaoKuan" focusColor="DEEPSKYBLUE" layoutX="118.0" layoutY="308.0" prefHeight="23.0" prefWidth="102.0" /> 105 </children></AnchorPane> 106 </Tab> 107 </JFXTabPane> 108 <Label fx:id="lb_welcome" layoutX="39.0" layoutY="72.0" text="xxx ,您好!" textFill="DARKORANGE" /> 109 <Hyperlink alignment="CENTER" contentDisplay="CENTER" layoutX="630.0" layoutY="61.0" onAction="#hbrlink_goto_login" prefHeight="21.0" prefWidth="53.0" text=" 退出 " textAlignment="CENTER" underline="true" /> 110 </AnchorPane>
效果如下:
6.工作人员controller
1 package sample; 2 3 import Util.Constant; 4 import Util.DataBaseUtil; 5 import Util.DateUtils; 6 import com.jfoenix.controls.*; 7 8 import com.jfoenix.controls.cells.editors.TextFieldEditorBuilder; 9 import com.jfoenix.controls.cells.editors.base.GenericEditableTreeTableCell; 10 import com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject; 11 import com.jfoenix.validation.RequiredFieldValidator; 12 13 import javafx.beans.binding.Bindings; 14 import javafx.beans.property.SimpleStringProperty; 15 import javafx.beans.property.StringProperty; 16 import javafx.collections.FXCollections; 17 import javafx.collections.ObservableList; 18 import javafx.fxml.FXML; 19 import javafx.fxml.Initializable; 20 import javafx.scene.control.*; 21 22 import javafx.scene.control.cell.PropertyValueFactory; 23 import javafx.scene.image.Image; 24 import javafx.scene.image.ImageView; 25 import javafx.scene.input.KeyCode; 26 import javafx.scene.input.KeyEvent; 27 import javafx.scene.layout.AnchorPane; 28 import sample.entity.*; 29 30 import java.net.URL; 31 import java.text.SimpleDateFormat; 32 import java.util.ArrayList; 33 import java.util.Date; 34 import java.util.ResourceBundle; 35 36 public class MainUiController implements Initializable { 37 38 39 private Main myApp; 40 41 private String myName=""; 42 43 @FXML 44 private AnchorPane treeview_test; 45 46 //所有书目显示列表信息 47 @FXML 48 private TableView tbv_book;//数目列表 49 @FXML 50 private TableColumn tb_column_book_id; 51 @FXML 52 private TableColumn tb_column_book_name; 53 @FXML 54 private TableColumn tb_column_book_type; 55 @FXML 56 private TableColumn tb_column_book_author; 57 @FXML 58 private TableColumn tb_column_book_translator; 59 @FXML 60 private TableColumn tb_column_book_publisher; 61 @FXML 62 private TableColumn tb_column_book_publishTime; 63 @FXML 64 private TableColumn tb_column_book_price; 65 66 //所有读者显示列表信息 67 @FXML 68 private TableView tbv_reader;//读者列表 69 @FXML 70 private TableColumn tb_column_reader_id; 71 @FXML 72 private TableColumn tb_column_reader_name; 73 @FXML 74 private TableColumn tb_column_reader_type; 75 @FXML 76 private TableColumn tb_column_reader_sex; 77 @FXML 78 private TableColumn tb_column_reader_numbers; 79 @FXML 80 private TableColumn tb_column_reader_days; 81 @FXML 82 private TableColumn tb_column_reader_forfeit; 83 @FXML 84 private TableColumn tb_column_reader_borrowed_books; 85 86 87 //所有借阅记录显示列表 88 @FXML 89 private TableView tbv_borrow;//借阅列表 90 @FXML 91 private TableColumn tb_column_borrow_id; 92 @FXML 93 private TableColumn tb_column_borrow_bookId; 94 @FXML 95 private TableColumn tb_column_borrow_readerId; 96 @FXML 97 private TableColumn tb_column_borrow_borrowDate; 98 @FXML 99 private TableColumn tb_column_borrow_backDate; 100 @FXML 101 private TableColumn tb_column_borrow_isBack; 102 103 104 //借书---图书信息 105 @FXML 106 private JFXTextField tf_js_book_id;//图书编号 107 @FXML 108 private JFXTextField tf_js_book_name;//图书名称 109 @FXML 110 private JFXTextField tf_js_book_publisher;//出版社 111 @FXML 112 private JFXTextField tf_js_book_publish_time;//出版时间 113 114 //借书---读者信息 115 @FXML 116 private JFXTextField tf_js_reader_id;//读者编号 117 @FXML 118 private JFXTextField tf_js_reader_name;//读者名称 119 @FXML 120 private JFXTextField tf_js_reader_type;//读者类别 121 @FXML 122 private JFXTextField tf_js_reader_sex;//性别 123 124 //借书---button 125 @FXML 126 private JFXButton btn_jieshu_confirm;//确认按钮 127 @FXML 128 private JFXButton btn_jieshu_clear;//清楚按钮 129 130 //借书---label---日期 131 @FXML 132 private Label lb_js_reader_jieshu_date;//借书时间 133 @FXML 134 private Label lb_js_reader_huanshu_date;//还书时间 135 136 137 //还书---表格信息 138 @FXML 139 private TableView tbv_huanshu_record; 140 @FXML 141 private TableColumn tb_column_huanshu_bookId; 142 @FXML 143 private TableColumn tb_column_huanshu_bookName; 144 @FXML 145 private TableColumn tb_column_huanshu_borrowDate; 146 @FXML 147 private TableColumn tb_column_huanshu_backDate; 148 149 //还书----读者信息 150 @FXML 151 private JFXTextField tf_hs_reader_id; 152 @FXML 153 private JFXTextField tf_hs_reader_name; 154 @FXML 155 private JFXTextField tf_hs_reader_type; 156 @FXML 157 private JFXTextField tf_hs_reader_sex; 158 159 //还书----图书信息 160 @FXML 161 private JFXTextField tf_hs_book_id; 162 @FXML 163 private JFXTextField tf_hs_book_name; 164 165 166 //图书维护---添加 167 @FXML 168 private JFXTextField tf_ts_add_book_id;//图书编号 169 @FXML 170 private JFXTextField tf_ts_add_book_name;//图书名称 171 @FXML 172 private JFXComboBox cb_ts_add_book_type;//图书类别 173 @FXML 174 private JFXTextField tf_ts_add_book_author;//作者 175 @FXML 176 private JFXTextField tf_ts_add_book_translator;//译者 177 @FXML 178 private JFXTextField tf_ts_add_book_publisher;//出版社 179 @FXML 180 private JFXDatePicker dp_ts_add_book_publish_time;//出版时间 181 @FXML 182 private JFXTextField tf_ts_add_book_price;//图书价格 183 @FXML 184 private JFXTextField tf_ts_add_book_stock;//库存容量 185 186 @FXML 187 private JFXButton btn_ts_add_book_add;//确认添加按钮 188 @FXML 189 private JFXButton btn_ts_add_book_clear;//清楚按钮 190 191 192 //图书维护----修改 193 @FXML 194 private JFXTextField tf_ts_alter_book_search_id;//搜索图书编号 195 @FXML 196 private JFXTextField tf_ts_alter_book_id;//图书编号 197 @FXML 198 private JFXTextField tf_ts_alter_book_name;//图书名称 199 @FXML 200 private JFXComboBox cb_ts_alter_book_type;//图书类别 201 @FXML 202 private JFXTextField tf_ts_alter_book_author;//作者 203 @FXML 204 private JFXTextField tf_ts_alter_book_translator;//译者 205 @FXML 206 private JFXTextField tf_ts_alter_book_publisher;//出版社 207 @FXML 208 private JFXDatePicker tp_ts_alter_book_publish_time;//出版时间 209 @FXML 210 private JFXTextField tf_ts_alter_book_price;//图书价格 211 @FXML 212 private JFXTextField tf_ts_alter_book_stock;//库存容量 213 214 @FXML 215 private JFXButton btn_ts_alter_book_alterBtn;//确认修改按钮 216 @FXML 217 private JFXButton btn_ts_alter_book_clearBtn;//清楚按钮 218 @FXML 219 private JFXButton btn_ts_alter_book_searchBtn;//查询按钮 220 221 222 //图书维护----删除 223 @FXML 224 private JFXTextField tf_ts_delete_book_search_id;//搜索图书编号 225 @FXML 226 private JFXTextField tf_ts_delete_book_id;//图书编号 227 @FXML 228 private JFXTextField tf_ts_delete_book_name;//图书名称 229 @FXML 230 private JFXComboBox cb_ts_delete_book_type;//图书类别 231 @FXML 232 private JFXTextField tf_ts_delete_book_author;//作者 233 @FXML 234 private JFXTextField tf_ts_delete_book_translator;//译者 235 @FXML 236 private JFXTextField tf_ts_delete_book_publisher;//出版社 237 @FXML 238 private JFXTextField tf_ts_delete_book_publish_time;//出版时间 239 @FXML 240 private JFXTextField tf_ts_delete_book_price;//图书价格 241 @FXML 242 private JFXTextField tf_ts_delete_book_stock;//库存容量 243 244 @FXML 245 private JFXButton btn_ts_delete_book_deleteBtn;//确认修改按钮 246 @FXML 247 private JFXButton btn_ts_delete_book_clearBtn;//清楚按钮 248 @FXML 249 private JFXButton btn_ts_delete_book_searchBtn;//查询按钮 250 251 252 253 //读者维护---添加 254 @FXML 255 private JFXTextField tf_rd_add_reader_id;//读者编号 256 @FXML 257 private JFXTextField tf_rd_add_reader_name;//读者名称 258 @FXML 259 private JFXComboBox cb_rd_add_reader_type;//读者类别 260 @FXML 261 private JFXComboBox cb_rd_add_reader_sex;//性别 262 @FXML 263 private JFXTextField tf_rd_add_reader_numbers;//可借数量 264 @FXML 265 private JFXTextField tf_rd_add_reader_days;//可借天数 266 267 @FXML 268 private JFXButton btn_rd_add_reader_addBtn;//确认添加按钮 269 @FXML 270 private JFXButton btn_rd_add_reader_clearBtn;//清楚按钮 271 272 273 //读者维护----修改 274 @FXML 275 private JFXTextField tf_rd_alter_reader_search_id;//搜索读者编号 276 @FXML 277 private JFXTextField tf_rd_alter_reader_id;//读者编号 278 @FXML 279 private JFXTextField tf_rd_alter_reader_name;//读者名称 280 @FXML 281 private JFXComboBox cb_rd_alter_reader_type;//读者类别 282 @FXML 283 private JFXComboBox cb_rd_alter_reader_sex;//性别 284 @FXML 285 private JFXTextField tf_rd_alter_reader_numbers;//可借数量 286 @FXML 287 private JFXTextField tf_rd_alter_reader_days;//可借天数 288 @FXML 289 private JFXToggleButton tgBtn_rd_alter_reader_password_reset;//初始化密码 290 291 @FXML 292 private JFXButton btn_rd_alter_reader_alterBtn;//确认修改按钮 293 @FXML 294 private JFXButton btn_rd_alter_reader_clearBtn;//清楚按钮 295 296 297 //读者维护----删除 298 @FXML 299 private JFXTextField tf_rd_delete_reader_search_id;//搜索读者编号 300 @FXML 301 private JFXTextField tf_rd_delete_reader_id;//读者编号 302 @FXML 303 private JFXTextField tf_rd_delete_reader_name;//读者名称 304 @FXML 305 private JFXComboBox cb_rd_delete_reader_type;//读者类别 306 @FXML 307 private JFXComboBox cb_rd_delete_reader_sex;//性别 308 @FXML 309 private JFXTextField tf_rd_delete_reader_numbers;//可借数量 310 @FXML 311 private JFXTextField tf_rd_delete_reader_days;//可借天数 312 313 @FXML 314 private JFXButton btn_rd_delete_reader_deleteBtn;//确认删除按钮 315 @FXML 316 private JFXButton btn_rd_delete_reader_clearBtn;//清楚按钮 317 @FXML 318 private JFXButton btn_rd_delete_reader_searchBtn;//查询按钮 319 320 @FXML 321 private Label lb_welcome;//工作人员欢迎 322 323 @FXML 324 private ImageView imageview; 325 326 327 /** 328 * 主类传递进来,方便界面管理 329 * @param myApp 330 */ 331 public void setApp(Main myApp) { 332 this.myApp = myApp; 333 } 334 335 /** 336 * 设置欢迎语句 337 * @param myName 338 */ 339 public void setMyName(String myName) { 340 this.myName = myName; 341 User user = DataBaseUtil.getUser(myName); 342 if (user != null) { 343 lb_welcome.setText(user.getName()+" ,老师您好!"); 344 } 345 } 346 347 @Override 348 public void initialize(URL location, ResourceBundle resources) { 349 350 // Image img=new Image(this.getClass().getResourceAsStream("logo.png")); 351 // imageview.setImage(img); 352 353 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式 354 //初始化当前时间 355 lb_js_reader_jieshu_date.setText(df.format(new Date())); 356 357 RequiredFieldValidator validator_tf_js_book_id = new RequiredFieldValidator(); 358 validator_tf_js_book_id.setMessage("请输入图书编号..."); 359 tf_js_book_id.getValidators().add(validator_tf_js_book_id); 360 tf_js_book_id.focusedProperty().addListener((o,oldVal,newVal)->{ 361 if(!newVal) tf_js_book_id.validate(); 362 }); 363 364 365 RequiredFieldValidator validator_tf_js_reader_id = new RequiredFieldValidator(); 366 validator_tf_js_reader_id.setMessage("请输入读者编号..."); 367 tf_js_reader_id.getValidators().add(validator_tf_js_reader_id); 368 tf_js_reader_id.focusedProperty().addListener((o,oldVal,newVal)->{ 369 if(!newVal) tf_js_reader_id.validate(); 370 }); 371 372 RequiredFieldValidator validator_tf_reqireInput = new RequiredFieldValidator(); 373 validator_tf_reqireInput.setMessage("请输入..."); 374 375 tf_hs_reader_id.getValidators().add(validator_tf_reqireInput); 376 tf_hs_reader_id.focusedProperty().addListener((o,oldVal,newVal)->{ 377 if(!newVal) tf_hs_reader_id.validate(); 378 }); 379 380 tf_hs_book_id.getValidators().add(validator_tf_reqireInput); 381 tf_hs_book_id.focusedProperty().addListener((o,oldVal,newVal)->{ 382 if(!newVal) tf_hs_book_id.validate(); 383 }); 384 385 //添加键盘监听 386 tf_js_book_id.setOnKeyPressed(this::tf_js_book_id_keyEvent); 387 tf_js_reader_id.setOnKeyPressed(this::tf_js_reader_id_keyEvent); 388 tf_hs_reader_id.setOnKeyPressed(this::tf_hs_reader_id_keyEvent); 389 tf_hs_book_id.setOnKeyPressed(this::tf_hs_book_id_keyEvent); 390 391 //图书维护---初始化 392 initBookAddUi(); 393 394 //读者维护---初始化 395 initReaderAddUi(); 396 397 // initBooksUi(); 398 399 //所有书目列表初始化 400 tb_column_book_id.setCellValueFactory(new PropertyValueFactory("Id")); 401 tb_column_book_name.setCellValueFactory(new PropertyValueFactory("name")); 402 tb_column_book_type.setCellValueFactory(new PropertyValueFactory("type")); 403 tb_column_book_author.setCellValueFactory(new PropertyValueFactory("author")); 404 tb_column_book_translator.setCellValueFactory(new PropertyValueFactory("translator")); 405 tb_column_book_publisher.setCellValueFactory(new PropertyValueFactory("publisher")); 406 tb_column_book_publishTime.setCellValueFactory(new PropertyValueFactory("publishTime")); 407 tb_column_book_price.setCellValueFactory(new PropertyValueFactory("price")); 408 409 tb_column_reader_id.setCellValueFactory(new PropertyValueFactory("id")); 410 tb_column_reader_name.setCellValueFactory(new PropertyValueFactory("name")); 411 tb_column_reader_type.setCellValueFactory(new PropertyValueFactory("type")); 412 tb_column_reader_sex.setCellValueFactory(new PropertyValueFactory("sex")); 413 tb_column_reader_numbers.setCellValueFactory(new PropertyValueFactory("max_num")); 414 tb_column_reader_days.setCellValueFactory(new PropertyValueFactory("days_num")); 415 tb_column_reader_forfeit.setCellValueFactory(new PropertyValueFactory("forfeit")); 416 // tb_column_reader_borrowed_books.setCellValueFactory(new PropertyValueFactory("borrowed_books")); 417 418 tb_column_borrow_id.setCellValueFactory(new PropertyValueFactory("id")); 419 tb_column_borrow_bookId.setCellValueFactory(new PropertyValueFactory("bookId")); 420 tb_column_borrow_readerId.setCellValueFactory(new PropertyValueFactory("readerId")); 421 tb_column_borrow_borrowDate.setCellValueFactory(new PropertyValueFactory("borrowDate")); 422 tb_column_borrow_backDate.setCellValueFactory(new PropertyValueFactory("backDate")); 423 tb_column_borrow_isBack.setCellValueFactory(new PropertyValueFactory("isBack")); 424 425 tb_column_huanshu_bookId.setCellValueFactory(new PropertyValueFactory("bookId")); 426 tb_column_huanshu_bookName.setCellValueFactory(new PropertyValueFactory("bookName")); 427 tb_column_huanshu_borrowDate.setCellValueFactory(new PropertyValueFactory("borrowDate")); 428 tb_column_huanshu_backDate.setCellValueFactory(new PropertyValueFactory("backDate")); 429 430 } 431 432 433 /** 434 * 退出登录 435 */ 436 @FXML 437 public void hbrlink_goto_login() { 438 myApp.gotoLoginUi(); 439 } 440 441 442 /** 443 * *********************************************借书模块-------开始************************************************ 444 */ 445 446 /** 447 * 监听----借书--button--确认 448 */ 449 @FXML 450 public void js_confirm_start() { 451 if (!tf_js_book_name.getText().equals("") && !tf_js_reader_name.getText().equals("")) { 452 boolean isBorrow = DataBaseUtil.addNewBorrow(tf_js_book_id.getText(), tf_js_reader_id.getText(), lb_js_reader_jieshu_date.getText(), lb_js_reader_huanshu_date.getText(), 0); 453 if (isBorrow) { 454 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 455 alert.setAlertType(Alert.AlertType.INFORMATION); 456 alert.setContentText("借书成功!"); 457 alert.setTitle("借书成功!"); 458 alert.show(); 459 tf_js_book_id.setText(""); 460 tf_js_reader_id.setText(""); 461 clear_js_book(); 462 clear_js_reader(); 463 } 464 } else { 465 tf_js_book_id.setText(""); 466 tf_js_reader_id.setText(""); 467 clear_js_book(); 468 clear_js_reader(); 469 tf_js_book_id.validate(); 470 tf_js_reader_id.validate(); 471 } 472 } 473 474 /** 475 * 监听----借书--书--id--输入回车 476 * @param keyEvent 477 */ 478 public void tf_js_book_id_keyEvent(KeyEvent keyEvent) { 479 if (keyEvent.getCode().equals(KeyCode.ENTER)) { 480 Book book = DataBaseUtil.getBook(tf_js_book_id.getText()); 481 if (book != null) { 482 // tf_js_book_id.setText(book.getId()); 483 tf_js_book_name.setText(book.getName()); 484 tf_js_book_publisher.setText(book.getPublisher()); 485 tf_js_book_publish_time.setText(book.getPublishTime().toString()); 486 } else { 487 clear_js_book(); 488 } 489 490 } 491 } 492 493 /** 494 * 监听----借书--读者--id--输入回车 495 * @param keyEvent 496 */ 497 public void tf_js_reader_id_keyEvent(KeyEvent keyEvent) { 498 if (keyEvent.getCode().equals(KeyCode.ENTER)) { 499 Reader reader = DataBaseUtil.getReader(tf_js_reader_id.getText()); 500 if (reader != null) { 501 // tf_js_reader_id.setText(reader.getId()); 502 tf_js_reader_name.setText(reader.getName()); 503 tf_js_reader_type.setText(reader.getType()); 504 tf_js_reader_sex.setText(reader.getSex()); 505 lb_js_reader_huanshu_date.setText(DateUtils.getAfterDay(lb_js_reader_jieshu_date.getText(), reader.getDays_num())); 506 } else { 507 clear_js_reader(); 508 } 509 510 } 511 } 512 513 /** 514 * 监听----借书--button--清楚 515 */ 516 @FXML 517 public void js_clear_start() { 518 tf_js_book_id.setText(""); 519 tf_js_reader_id.setText(""); 520 clear_js_book(); 521 clear_js_reader(); 522 } 523 524 /** 525 * 清楚---借书 526 */ 527 public void clear_js_book() { 528 // tf_js_book_id.setText(null); 529 tf_js_book_name.setText(""); 530 tf_js_book_publisher.setText(""); 531 tf_js_book_publish_time.setText(""); 532 } 533 534 /** 535 * 清楚---借书 536 */ 537 public void clear_js_reader() { 538 // tf_js_reader_id.setText(null); 539 tf_js_reader_name.setText(""); 540 tf_js_reader_type.setText(""); 541 tf_js_reader_sex.setText(""); 542 lb_js_reader_huanshu_date.setText(""); 543 } 544 545 /** 546 * *********************************************还书模块-------开始************************************************ 547 */ 548 549 /** 550 * 还书模块---监听---读者id 551 * @param keyEvent 552 */ 553 private void tf_hs_reader_id_keyEvent(KeyEvent keyEvent) { 554 if (keyEvent.getCode().equals(KeyCode.ENTER)) { 555 Reader reader = DataBaseUtil.getReader(tf_hs_reader_id.getText()); 556 //如果不为空,则进行 557 if (reader != null) { 558 tf_hs_reader_name.setText(reader.getName()); 559 tf_hs_reader_type.setText(reader.getType()); 560 tf_hs_reader_sex.setText(reader.getSex()); 561 getReaderBorrowRecord(reader.getId()); 562 } else { 563 clear_hs_reader(); 564 } 565 } 566 } 567 568 /** 569 * 还书模块---用于还书成功后刷新 570 */ 571 private void tf_hs_reader_id_keyEvent() { 572 Reader reader = DataBaseUtil.getReader(tf_hs_reader_id.getText()); 573 //如果不为空,则进行 574 if (reader != null) { 575 tf_hs_reader_name.setText(reader.getName()); 576 tf_hs_reader_type.setText(reader.getType()); 577 tf_hs_reader_sex.setText(reader.getSex()); 578 getReaderBorrowRecord(reader.getId()); 579 } else { 580 clear_hs_reader(); 581 } 582 } 583 584 /** 585 * 清楚---还书 586 */ 587 @FXML 588 public void clear_hs_reader() { 589 tf_hs_reader_id.setText(null); 590 tf_hs_reader_name.setText(""); 591 tf_hs_reader_type.setText(""); 592 tf_hs_reader_sex.setText(""); 593 tf_hs_book_id.setText(""); 594 tf_hs_book_name.setText(""); 595 //先清理原来表格记录 596 int size = tbv_huanshu_record.getItems().size(); 597 for (int i = 0; i < size; i++) { 598 tbv_huanshu_record.getItems().remove(0); 599 } 600 } 601 602 public void getReaderBorrowRecord(String id) { 603 ObservableList<borrow_record> borrows = DataBaseUtil.getBorrowRecord(id); 604 if (borrows != null) { 605 tbv_huanshu_record.setItems(borrows); 606 }else { 607 608 } 609 } 610 611 /** 612 * 还书模块---监听---读者id 613 * @param keyEvent 614 */ 615 private void tf_hs_book_id_keyEvent(KeyEvent keyEvent) { 616 if (keyEvent.getCode().equals(KeyCode.ENTER)) { 617 Book book = DataBaseUtil.getBook(tf_hs_book_id.getText()); 618 //如果不为空,则进行 619 if (book != null) { 620 tf_hs_book_name.setText(book.getName()); 621 } else { 622 tf_hs_book_name.setText(""); 623 } 624 } 625 } 626 627 /** 628 * 点击还书按钮----进行还书 629 */ 630 @FXML 631 private void huanshu_start() { 632 if (!tf_hs_reader_name.getText().trim().equals("")) { 633 if (!tf_hs_book_id.getText().trim().equals("")) { 634 double isok = DataBaseUtil.backBook(tf_hs_reader_id.getText().trim(),tf_hs_book_id.getText().trim()); 635 if (isok != -1) { 636 tf_hs_reader_id_keyEvent(); 637 tf_hs_book_id.setText(""); 638 tf_hs_book_name.setText(""); 639 System.out.println("huanshu ok"); 640 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 641 alert.setAlertType(Alert.AlertType.INFORMATION); 642 alert.setContentText("还书成功! 超期罚款为 : " + isok); 643 alert.setTitle("还书成功!"); 644 alert.show(); 645 } else { 646 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 647 alert.setAlertType(Alert.AlertType.ERROR); 648 alert.setContentText("还书失败!"); 649 alert.setTitle("还书失败!"); 650 alert.show(); 651 } 652 } else { 653 tf_hs_book_id.validate(); 654 } 655 } else { 656 tf_hs_reader_id.validate(); 657 } 658 } 659 660 661 /** 662 * *********************************************图书维护模块-------开始************************************************ 663 */ 664 665 /** 666 * 初始化--图书维护模块 667 */ 668 public void initBookAddUi() { 669 for (int i = 0; i < Constant.BOOK_TYPES.length; i++) { 670 cb_ts_add_book_type.getItems().addAll(Constant.BOOK_TYPES[i]); 671 } 672 673 RequiredFieldValidator validator_ts_book_add = new RequiredFieldValidator(); 674 validator_ts_book_add.setMessage("请输入..."); 675 tf_ts_add_book_id.getValidators().add(validator_ts_book_add); 676 tf_ts_add_book_id.focusedProperty().addListener((o,oldVal,newVal)->{ 677 if(!newVal) tf_ts_add_book_id.validate(); 678 }); 679 680 tf_ts_add_book_name.getValidators().add(validator_ts_book_add); 681 tf_ts_add_book_name.focusedProperty().addListener((o,oldVal,newVal)->{ 682 if(!newVal) tf_ts_add_book_name.validate(); 683 }); 684 685 tf_ts_add_book_author.getValidators().add(validator_ts_book_add); 686 tf_ts_add_book_author.focusedProperty().addListener((o,oldVal,newVal)->{ 687 if(!newVal) tf_ts_add_book_author.validate(); 688 }); 689 690 tf_ts_add_book_translator.getValidators().add(validator_ts_book_add); 691 tf_ts_add_book_translator.focusedProperty().addListener((o,oldVal,newVal)->{ 692 if(!newVal) tf_ts_add_book_translator.validate(); 693 }); 694 695 tf_ts_add_book_publisher.getValidators().add(validator_ts_book_add); 696 tf_ts_add_book_publisher.focusedProperty().addListener((o,oldVal,newVal)->{ 697 if(!newVal) tf_ts_add_book_publisher.validate(); 698 }); 699 700 tf_ts_add_book_price.getValidators().add(validator_ts_book_add); 701 tf_ts_add_book_price.focusedProperty().addListener((o,oldVal,newVal)->{ 702 if(!newVal) tf_ts_add_book_price.validate(); 703 }); 704 705 tf_ts_add_book_stock.getValidators().add(validator_ts_book_add); 706 tf_ts_add_book_stock.focusedProperty().addListener((o,oldVal,newVal)->{ 707 if(!newVal) tf_ts_add_book_stock.validate(); 708 }); 709 710 cb_ts_add_book_type.getSelectionModel().selectFirst(); 711 712 //////*****////// 713 tf_ts_alter_book_search_id.getValidators().add(validator_ts_book_add); 714 tf_ts_alter_book_search_id.focusedProperty().addListener((o,oldVal,newVal)->{ 715 if(!newVal) tf_ts_alter_book_search_id.validate(); 716 }); 717 718 tf_ts_delete_book_search_id.getValidators().add(validator_ts_book_add); 719 tf_ts_delete_book_search_id.focusedProperty().addListener((o,oldVal,newVal)->{ 720 if(!newVal) tf_ts_delete_book_search_id.validate(); 721 }); 722 723 } 724 725 /** 726 * 图书信息维护界面-----添加 727 * 添加按钮点击事件 728 */ 729 @FXML 730 public void ts_book_add() { 731 System.out.println("info====> "+tf_ts_add_book_id.getText() + tf_ts_add_book_name.getText()+tf_ts_add_book_author.getText()+tf_ts_add_book_translator.getText()+tf_ts_add_book_publisher.getText()+ 732 tf_ts_add_book_price.getText()+tf_ts_add_book_stock.getText()+cb_ts_add_book_type.getSelectionModel().getSelectedItem().toString()+dp_ts_add_book_publish_time.getEditor().getText()); 733 if (!tf_ts_add_book_id.getText().equals("") && !tf_ts_add_book_name.getText().equals("") && !tf_ts_add_book_author.getText().equals("") && !tf_ts_add_book_translator.getText().equals("") && !tf_ts_add_book_publisher.getText().equals("") && 734 !tf_ts_add_book_price.getText().equals("") && !tf_ts_add_book_stock.getText().equals("") && !cb_ts_add_book_type.getSelectionModel().getSelectedItem().toString().equals("") && !dp_ts_add_book_publish_time.getEditor().getText().equals("")) { 735 Book book = new Book(); 736 book.setId(tf_ts_add_book_id.getText()); 737 book.setName(tf_ts_add_book_name.getText()); 738 book.setType(cb_ts_add_book_type.getSelectionModel().getSelectedItem().toString()); 739 book.setAuthor(tf_ts_add_book_author.getText()); 740 book.setTranslator(tf_ts_add_book_translator.getText()); 741 book.setPublisher(tf_ts_add_book_publisher.getText()); 742 book.setPublishTime(dp_ts_add_book_publish_time.getEditor().getText()); 743 book.setStock(Integer.parseInt(tf_ts_add_book_stock.getText())); 744 book.setPrice(Double.parseDouble(tf_ts_add_book_price.getText())); 745 Boolean isok = DataBaseUtil.addNewBook(book); 746 if (isok) { 747 System.out.println("add ok"); 748 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 749 alert.setAlertType(Alert.AlertType.INFORMATION); 750 alert.setContentText("添加成功!"); 751 alert.setTitle("添加成功!"); 752 alert.show(); 753 ts_book_add_clear(); 754 } else { 755 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 756 alert.setAlertType(Alert.AlertType.ERROR); 757 alert.setContentText("添加失败!"); 758 alert.setTitle("添加失败!"); 759 alert.show(); 760 } 761 } else { 762 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 763 alert.setAlertType(Alert.AlertType.ERROR); 764 alert.setContentText("信息不完整!"); 765 alert.setTitle("添加错误!"); 766 alert.show(); 767 } 768 } 769 770 /** 771 * 图书信息维护界面-----添加 772 * 清楚按钮点击事件 773 */ 774 @FXML 775 private void ts_book_add_clear() { 776 tf_ts_add_book_id.setText(""); 777 tf_ts_add_book_name.setText(""); 778 // cb_ts_add_book_type.getSelectionModel().clearSelection(); 779 tf_ts_add_book_author.setText(""); 780 tf_ts_add_book_translator.setText(""); 781 tf_ts_add_book_publisher.setText(""); 782 dp_ts_add_book_publish_time.getEditor().setText(""); 783 tf_ts_add_book_stock.setText(""); 784 tf_ts_add_book_price.setText(""); 785 } 786 787 /** 788 * 图书维护---修改---查询图书 789 */ 790 @FXML 791 public void ts_book_alter_search() { 792 if (!tf_ts_alter_book_search_id.getText().equals("")) { 793 Book book = DataBaseUtil.getBook(tf_ts_alter_book_search_id.getText().trim()); 794 if (book != null) { 795 tf_ts_alter_book_id.setText(book.getId()); 796 tf_ts_alter_book_name.setText(book.getName()); 797 cb_ts_alter_book_type.getEditor().setText(book.getType()); 798 tf_ts_alter_book_author.setText(book.getAuthor()); 799 tf_ts_alter_book_translator.setText(book.getTranslator()); 800 tf_ts_alter_book_publisher.setText(book.getPublisher()); 801 tp_ts_alter_book_publish_time.getEditor().setText(book.getPublishTime()); 802 tf_ts_alter_book_price.setText("" + book.getPrice()); 803 tf_ts_alter_book_stock.setText("" + book.getStock()); 804 } else { 805 tf_ts_alter_book_search_id.setText(""); 806 tf_ts_alter_book_search_id.validate(); 807 } 808 } 809 } 810 811 /** 812 * 图书维护---修改 813 */ 814 @FXML 815 public void ts_book_alter_start() { 816 if (!tf_ts_alter_book_id.getText().equals("") && !tf_ts_alter_book_name.getText().equals("") && !tf_ts_alter_book_author.getText().equals("") && !tf_ts_alter_book_translator.getText().equals("") && !tf_ts_alter_book_publisher.getText().equals("") && 817 !tf_ts_alter_book_price.getText().equals("") && !tf_ts_alter_book_stock.getText().equals("") && !cb_ts_alter_book_type.getSelectionModel().getSelectedItem().toString().equals("") && !tp_ts_alter_book_publish_time.getEditor().getText().equals("")) { 818 Book book = new Book(); 819 book.setId(tf_ts_alter_book_id.getText()); 820 book.setName(tf_ts_alter_book_name.getText()); 821 book.setType(cb_ts_alter_book_type.getEditor().getText()); 822 book.setAuthor(tf_ts_alter_book_author.getText()); 823 book.setTranslator(tf_ts_alter_book_translator.getText()); 824 book.setPublisher(tf_ts_alter_book_publisher.getText()); 825 book.setPublishTime(tp_ts_alter_book_publish_time.getEditor().getText()); 826 book.setStock(Integer.parseInt(tf_ts_alter_book_stock.getText())); 827 book.setPrice(Double.parseDouble(tf_ts_alter_book_price.getText())); 828 Boolean isok = DataBaseUtil.alterBook(book); 829 if (isok) { 830 System.out.println("alter ok"); 831 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 832 alert.setAlertType(Alert.AlertType.INFORMATION); 833 alert.setContentText("修改成功!"); 834 alert.setTitle("修改成功!"); 835 alert.show(); 836 ts_book_alter_clear(); 837 } else { 838 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 839 alert.setAlertType(Alert.AlertType.ERROR); 840 alert.setContentText("修改失败!"); 841 alert.setTitle("修改失败!"); 842 alert.show(); 843 } 844 } else { 845 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 846 alert.setAlertType(Alert.AlertType.ERROR); 847 alert.setContentText("信息不完整!"); 848 alert.setTitle("修改错误!"); 849 alert.show(); 850 } 851 } 852 853 /** 854 * 图书信息维护界面-----修改 855 * 清楚按钮点击事件 856 */ 857 @FXML 858 private void ts_book_alter_clear() { 859 tf_ts_alter_book_id.setText(""); 860 tf_ts_alter_book_name.setText(""); 861 // cb_ts_alter_book_type.getSelectionModel().clearSelection(); 862 tf_ts_alter_book_author.setText(""); 863 tf_ts_alter_book_translator.setText(""); 864 tf_ts_alter_book_publisher.setText(""); 865 tp_ts_alter_book_publish_time.getEditor().setText(""); 866 tf_ts_alter_book_stock.setText(""); 867 tf_ts_alter_book_price.setText(""); 868 } 869 870 871 /** 872 * 图书维护---删除---查询图书 873 */ 874 @FXML 875 public void ts_book_delete_search() { 876 if (!tf_ts_delete_book_search_id.getText().equals("")) { 877 Book book = DataBaseUtil.getBook(tf_ts_delete_book_search_id.getText().trim()); 878 if (book != null) { 879 tf_ts_delete_book_id.setText(book.getId()); 880 tf_ts_delete_book_name.setText(book.getName()); 881 cb_ts_delete_book_type.getEditor().setText(book.getType()); 882 tf_ts_delete_book_author.setText(book.getAuthor()); 883 tf_ts_delete_book_translator.setText(book.getTranslator()); 884 tf_ts_delete_book_publisher.setText(book.getPublisher()); 885 tf_ts_delete_book_publish_time.setText(book.getPublishTime()); 886 tf_ts_delete_book_price.setText("" + book.getPrice()); 887 tf_ts_delete_book_stock.setText("" + book.getStock()); 888 } else { 889 tf_ts_delete_book_search_id.setText(""); 890 tf_ts_delete_book_search_id.validate(); 891 } 892 } 893 894 } 895 896 /** 897 * 图书维护---删除--按钮 898 */ 899 @FXML 900 public void ts_book_delete() { 901 if (!tf_ts_delete_book_id.getText().equals("")) { 902 Book book = new Book(); 903 book.setId(tf_ts_delete_book_id.getText()); 904 book.setName(tf_ts_delete_book_name.getText()); 905 book.setType(cb_ts_delete_book_type.getEditor().getText()); 906 book.setAuthor(tf_ts_delete_book_author.getText()); 907 book.setTranslator(tf_ts_delete_book_translator.getText()); 908 book.setPublisher(tf_ts_delete_book_publisher.getText()); 909 book.setPublishTime(tf_ts_delete_book_publish_time.getText()); 910 book.setStock(Integer.parseInt(tf_ts_delete_book_stock.getText())); 911 book.setPrice(Double.parseDouble(tf_ts_delete_book_price.getText())); 912 913 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 914 alert.setAlertType(Alert.AlertType.CONFIRMATION); 915 alert.setContentText("确认删除?"); 916 alert.setTitle("确认删除!"); 917 alert.showAndWait(); 918 ButtonType type = alert.getResult(); 919 System.out.println("type="+type.getText()); 920 if (type == ButtonType.OK) { 921 Boolean isok = DataBaseUtil.deleteBook(book); 922 if (isok) { 923 System.out.println("delete ok"); 924 Alert alert1 = new Alert(Alert.AlertType.CONFIRMATION); 925 alert1.setAlertType(Alert.AlertType.INFORMATION); 926 alert1.setContentText("删除成功!"); 927 alert1.setTitle("删除成功!"); 928 alert1.show(); 929 ts_book_delete_clear(); 930 } else { 931 Alert alert2 = new Alert(Alert.AlertType.CONFIRMATION); 932 alert2.setAlertType(Alert.AlertType.ERROR); 933 alert2.setContentText("删除失败!"); 934 alert2.setTitle("删除失败!"); 935 alert2.show(); 936 } 937 } 938 939 } else { 940 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 941 alert.setAlertType(Alert.AlertType.ERROR); 942 alert.setContentText("信息不完整!"); 943 alert.setTitle("删除错误!"); 944 alert.show(); 945 } 946 } 947 948 /** 949 * 图书信息维护界面-----删除 950 * 清楚按钮点击事件 951 */ 952 @FXML 953 private void ts_book_delete_clear() { 954 tf_ts_delete_book_id.setText(""); 955 tf_ts_delete_book_name.setText(""); 956 cb_ts_delete_book_type.getEditor().setText(""); 957 tf_ts_delete_book_author.setText(""); 958 tf_ts_delete_book_translator.setText(""); 959 tf_ts_delete_book_publisher.setText(""); 960 tf_ts_delete_book_publish_time.setText(""); 961 tf_ts_delete_book_stock.setText(""); 962 tf_ts_delete_book_price.setText(""); 963 } 964 965 /** 966 * *********************************************图书维护模块-------结束************************************************ 967 */ 968 969 970 /** 971 * *********************************************读者维护模块-------开始************************************************ 972 */ 973 974 /** 975 * 读者维护模块初始化 976 */ 977 private void initReaderAddUi() { 978 979 for (int i = 0; i < Constant.READER_YTPES.length; i++) { 980 cb_rd_add_reader_type.getItems().addAll(Constant.READER_YTPES[i]); 981 cb_rd_alter_reader_type.getItems().addAll(Constant.READER_YTPES[i]); 982 cb_rd_delete_reader_type.getItems().addAll(Constant.READER_YTPES[i]); 983 } 984 cb_rd_add_reader_type.getSelectionModel().selectFirst(); 985 cb_rd_alter_reader_type.getSelectionModel().selectFirst(); 986 cb_rd_delete_reader_type.getSelectionModel().selectFirst(); 987 988 for (int i = 0; i < Constant.SEX.length; i++) { 989 cb_rd_add_reader_sex.getItems().addAll(Constant.SEX[i]); 990 cb_rd_alter_reader_sex.getItems().addAll(Constant.SEX[i]); 991 cb_rd_delete_reader_sex.getItems().addAll(Constant.SEX[i]); 992 } 993 cb_rd_add_reader_sex.getSelectionModel().selectFirst(); 994 cb_rd_alter_reader_sex.getSelectionModel().selectFirst(); 995 cb_rd_delete_reader_sex.getSelectionModel().selectFirst(); 996 997 RequiredFieldValidator validator_ts_book_add = new RequiredFieldValidator(); 998 validator_ts_book_add.setMessage("请输入..."); 999 tf_rd_alter_reader_search_id.getValidators().add(validator_ts_book_add); 1000 tf_rd_alter_reader_search_id.focusedProperty().addListener((o,oldVal,newVal)->{ 1001 if(!newVal) tf_rd_alter_reader_search_id.validate(); 1002 }); 1003 1004 tf_rd_delete_reader_search_id.getValidators().add(validator_ts_book_add); 1005 tf_rd_delete_reader_search_id.focusedProperty().addListener((o,oldVal,newVal)->{ 1006 if(!newVal) tf_rd_delete_reader_search_id.validate(); 1007 }); 1008 1009 } 1010 1011 /** 1012 * 添加新的读者 1013 */ 1014 @FXML 1015 public void add_new_reader() { 1016 if (!tf_rd_add_reader_id.getText().equals("") && !tf_rd_add_reader_name.getText().equals("") && !tf_rd_add_reader_numbers.getText().equals("") && !tf_rd_add_reader_days.getText().equals("") && 1017 !cb_rd_add_reader_type.getSelectionModel().getSelectedItem().toString().equals("") && !cb_rd_add_reader_sex.getSelectionModel().getSelectedItem().toString().equals("")) { 1018 Reader reader = new Reader(); 1019 reader.setId(tf_rd_add_reader_id.getText()); 1020 reader.setName(tf_rd_add_reader_name.getText()); 1021 reader.setPassword("123456");//默认密码 1022 reader.setType(cb_rd_add_reader_type.getSelectionModel().getSelectedItem().toString()); 1023 reader.setSex(cb_rd_add_reader_sex.getSelectionModel().getSelectedItem().toString()); 1024 reader.setMax_num(Integer.parseInt(tf_rd_add_reader_numbers.getText())); 1025 reader.setDays_num(Integer.parseInt(tf_rd_add_reader_days.getText())); 1026 reader.setForfeit(0); 1027 1028 Boolean isok = DataBaseUtil.addNewReader(reader); 1029 if (isok) { 1030 System.out.println("add ok"); 1031 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 1032 alert.setAlertType(Alert.AlertType.INFORMATION); 1033 alert.setContentText("添加成功!"); 1034 alert.setTitle("添加成功!"); 1035 alert.show(); 1036 rd_reader_add_clear(); 1037 } else { 1038 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 1039 alert.setAlertType(Alert.AlertType.ERROR); 1040 alert.setContentText("添加失败!"); 1041 alert.setTitle("添加失败!"); 1042 alert.show(); 1043 } 1044 } else { 1045 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 1046 alert.setAlertType(Alert.AlertType.ERROR); 1047 alert.setContentText("信息不完整!"); 1048 alert.setTitle("添加错误!"); 1049 alert.show(); 1050 } 1051 } 1052 1053 /** 1054 * 读者信息维护界面-----添加 1055 * 清楚按钮点击事件 1056 */ 1057 @FXML 1058 private void rd_reader_add_clear() { 1059 tf_rd_add_reader_id.setText(""); 1060 tf_rd_add_reader_name.setText(""); 1061 tf_rd_add_reader_numbers.setText(""); 1062 tf_rd_add_reader_days.setText(""); 1063 } 1064 1065 /** 1066 * 修改读者 1067 */ 1068 @FXML 1069 public void alter_rd_reader() { 1070 if (!tf_rd_alter_reader_id.getText().equals("") && !tf_rd_alter_reader_name.getText().equals("") && !tf_rd_alter_reader_numbers.getText().equals("") && !tf_rd_alter_reader_days.getText().equals("") && 1071 !cb_rd_alter_reader_type.getSelectionModel().getSelectedItem().toString().equals("") && !cb_rd_alter_reader_sex.getSelectionModel().getSelectedItem().toString().equals("")) { 1072 Reader reader = new Reader(); 1073 reader.setId(tf_rd_alter_reader_id.getText()); 1074 reader.setName(tf_rd_alter_reader_name.getText()); 1075 if (tgBtn_rd_alter_reader_password_reset.isPressed()) { 1076 reader.setPassword("123456");//默认密码 1077 } else { 1078 reader.setPassword(rd_reader_alter_password);//原密码 1079 } 1080 reader.setType(cb_rd_alter_reader_type.getSelectionModel().getSelectedItem().toString()); 1081 reader.setSex(cb_rd_alter_reader_sex.getSelectionModel().getSelectedItem().toString()); 1082 reader.setMax_num(Integer.parseInt(tf_rd_alter_reader_numbers.getText())); 1083 reader.setDays_num(Integer.parseInt(tf_rd_alter_reader_days.getText())); 1084 reader.setForfeit(0); 1085 1086 Boolean isok = DataBaseUtil.alterReader(reader); 1087 if (isok) { 1088 System.out.println("add ok"); 1089 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 1090 alert.setAlertType(Alert.AlertType.INFORMATION); 1091 alert.setContentText("修改成功!"); 1092 alert.setTitle("修改成功!"); 1093 alert.show(); 1094 rd_reader_alter_clear(); 1095 } else { 1096 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 1097 alert.setAlertType(Alert.AlertType.ERROR); 1098 alert.setContentText("修改失败!"); 1099 alert.setTitle("修改失败!"); 1100 alert.show(); 1101 } 1102 } else { 1103 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 1104 alert.setAlertType(Alert.AlertType.ERROR); 1105 alert.setContentText("信息不完整!"); 1106 alert.setTitle("修改错误!"); 1107 alert.show(); 1108 } 1109 } 1110 1111 private String rd_reader_alter_password = "123456"; 1112 1113 /** 1114 * 读者维护---修改---查询读者 1115 */ 1116 @FXML 1117 public void rd_reader_alter_search() { 1118 if (!tf_rd_alter_reader_search_id.getText().equals("")) { 1119 Reader reader = DataBaseUtil.getReader(tf_rd_alter_reader_search_id.getText().trim()); 1120 if (reader != null) { 1121 tf_rd_alter_reader_id.setText(reader.getId()); 1122 tf_rd_alter_reader_name.setText(reader.getName()); 1123 if (reader.getType().equals("教师")) { 1124 cb_rd_alter_reader_type.getSelectionModel().selectFirst(); 1125 } else if (reader.getType().equals("学生")) { 1126 cb_rd_alter_reader_type.getSelectionModel().select(1); 1127 } else { 1128 cb_rd_alter_reader_type.getSelectionModel().select(2); 1129 } 1130 if (reader.getSex().equals("男")) { 1131 cb_rd_alter_reader_sex.getSelectionModel().selectFirst(); 1132 } else { 1133 cb_rd_alter_reader_sex.getSelectionModel().select(1); 1134 } 1135 rd_reader_alter_password = reader.getPassword(); 1136 tf_rd_alter_reader_numbers.setText(reader.getMax_num()+""); 1137 tf_rd_alter_reader_days.setText(reader.getDays_num()+""); 1138 } else { 1139 tf_rd_alter_reader_search_id.setText(""); 1140 tf_rd_alter_reader_search_id.validate(); 1141 } 1142 } 1143 1144 } 1145 1146 /** 1147 * 读者信息维护界面-----修改 1148 * 清楚按钮点击事件 1149 */ 1150 @FXML 1151 private void rd_reader_alter_clear() { 1152 tf_rd_alter_reader_id.setText(""); 1153 tf_rd_alter_reader_name.setText(""); 1154 tf_rd_alter_reader_numbers.setText(""); 1155 tf_rd_alter_reader_days.setText(""); 1156 } 1157 1158 1159 /** 1160 * 读者维护---删除---读者查询 1161 */ 1162 @FXML 1163 public void rd_reader_delete_search() { 1164 if (!tf_rd_delete_reader_search_id.getText().equals("")) { 1165 Reader reader = DataBaseUtil.getReader(tf_rd_delete_reader_search_id.getText().trim()); 1166 if (reader != null) { 1167 tf_rd_delete_reader_id.setText(reader.getId()); 1168 tf_rd_delete_reader_name.setText(reader.getName()); 1169 if (reader.getType().equals("教师")) { 1170 cb_rd_delete_reader_type.getSelectionModel().selectFirst(); 1171 } else if (reader.getType().equals("学生")) { 1172 cb_rd_delete_reader_type.getSelectionModel().select(1); 1173 } else { 1174 cb_rd_delete_reader_type.getSelectionModel().select(2); 1175 } 1176 if (reader.getSex().equals("男")) { 1177 cb_rd_delete_reader_sex.getSelectionModel().selectFirst(); 1178 } else { 1179 cb_rd_delete_reader_sex.getSelectionModel().select(1); 1180 } 1181 tf_rd_delete_reader_numbers.setText(reader.getMax_num()+""); 1182 tf_rd_delete_reader_days.setText(reader.getDays_num()+""); 1183 } else { 1184 tf_rd_delete_reader_search_id.setText(""); 1185 tf_rd_delete_reader_search_id.validate(); 1186 } 1187 } 1188 1189 } 1190 1191 /** 1192 * 删除读者 1193 */ 1194 @FXML 1195 public void delete_rd_reader() { 1196 if (!tf_rd_delete_reader_id.getText().equals("")) { 1197 1198 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 1199 alert.setAlertType(Alert.AlertType.CONFIRMATION); 1200 alert.setContentText("确认删除?"); 1201 alert.setTitle("确认删除!"); 1202 alert.showAndWait(); 1203 ButtonType type = alert.getResult(); 1204 System.out.println("type="+type.getText()); 1205 if (type == ButtonType.OK) { 1206 Boolean isok = DataBaseUtil.deleteReader(tf_rd_delete_reader_id.getText()); 1207 if (isok) { 1208 System.out.println("add ok"); 1209 Alert alert1 = new Alert(Alert.AlertType.CONFIRMATION); 1210 alert1.setAlertType(Alert.AlertType.INFORMATION); 1211 alert1.setContentText("删除成功!"); 1212 alert1.setTitle("删除成功!"); 1213 alert1.show(); 1214 rd_reader_delete_clear(); 1215 } else { 1216 Alert alert2 = new Alert(Alert.AlertType.CONFIRMATION); 1217 alert2.setAlertType(Alert.AlertType.ERROR); 1218 alert2.setContentText("删除失败!"); 1219 alert2.setTitle("删除失败!"); 1220 alert2.show(); 1221 } 1222 } 1223 } else { 1224 Alert alert = new Alert(Alert.AlertType.CONFIRMATION); 1225 alert.setAlertType(Alert.AlertType.ERROR); 1226 alert.setContentText("信息不完整!"); 1227 alert.setTitle("删除错误!"); 1228 alert.show(); 1229 } 1230 } 1231 1232 /** 1233 * 读者信息维护界面-----删除 1234 * 清楚按钮点击事件 1235 */ 1236 @FXML 1237 private void rd_reader_delete_clear() { 1238 tf_rd_delete_reader_id.setText(""); 1239 tf_rd_delete_reader_name.setText(""); 1240 tf_rd_delete_reader_numbers.setText(""); 1241 tf_rd_delete_reader_days.setText(""); 1242 } 1243 1244 1245 /** 1246 * *********************************************读者维护模块-------结束************************************************ 1247 */ 1248 1249 1250 /** 1251 * *********************************************所有图书、读者、借阅显示模块-------开始************************************************ 1252 */ 1253 1254 /** 1255 * 获取全部书目,并显示 1256 */ 1257 @FXML 1258 public void getAllBooks() { 1259 ObservableList<Book> books = DataBaseUtil.getAllBooks(); 1260 if (books != null) { 1261 tbv_book.setItems(books); 1262 } else { 1263 // tbv_book.setAccessibleText("无记录"); 1264 } 1265 1266 } 1267 1268 /** 1269 * 获取全部书目,并显示 1270 */ 1271 @FXML 1272 public void getAllReaders() { 1273 ObservableList<Reader> readers = DataBaseUtil.getAllReaders(); 1274 if (readers != null) { 1275 tbv_reader.setItems(readers); 1276 }else { 1277 // tbv_reader.setAccessibleText("无记录"); 1278 } 1279 } 1280 1281 /** 1282 * 获取全部借阅记录 1283 */ 1284 public void getAllBorrowedRecordings() { 1285 ObservableList<Borrow> borrows = DataBaseUtil.getAllBorrowRecord(); 1286 if (borrows != null) { 1287 tbv_borrow.setItems(borrows); 1288 }else { 1289 // tbv_borrow.setAccessibleText("无记录"); 1290 } 1291 } 1292 1293 /** 1294 * *********************************************所有图书、读者、借阅显示模块-------结束************************************************ 1295 */ 1296 1297 }
7.工作人员fxml
1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <?import com.jfoenix.controls.JFXButton?> 4 <?import com.jfoenix.controls.JFXComboBox?> 5 <?import com.jfoenix.controls.JFXDatePicker?> 6 <?import com.jfoenix.controls.JFXTabPane?> 7 <?import com.jfoenix.controls.JFXTextField?> 8 <?import com.jfoenix.controls.JFXToggleButton?> 9 <?import javafx.scene.control.Hyperlink?> 10 <?import javafx.scene.control.Label?> 11 <?import javafx.scene.control.ScrollPane?> 12 <?import javafx.scene.control.Separator?> 13 <?import javafx.scene.control.Tab?> 14 <?import javafx.scene.control.TableColumn?> 15 <?import javafx.scene.control.TableView?> 16 <?import javafx.scene.image.ImageView?> 17 <?import javafx.scene.layout.AnchorPane?> 18 <?import javafx.scene.text.Font?> 19 20 <AnchorPane prefHeight="500.0" prefWidth="700.0" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.MainUiController"> 21 <children> 22 <JFXTabPane layoutX="20.0" layoutY="60.0" prefHeight="415.0" prefWidth="660.0" tabClosingPolicy="UNAVAILABLE"> 23 <tabs> 24 <Tab text="借书"> 25 <content> 26 <ScrollPane layoutX="120.0" layoutY="128.0" prefHeight="200.0" prefWidth="200.0"> 27 <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="380.0" prefWidth="645.0"> 28 <children> 29 <Label layoutX="314.0" layoutY="36.0" text="借书"> 30 <font> 31 <Font name="System Bold Italic" size="18.0" /> 32 </font> 33 </Label> 34 <Label layoutX="57.0" layoutY="130.0" text="图书编号" textFill="#2196f3"> 35 <font> 36 <Font name="System Bold Italic" size="15.0" /> 37 </font></Label> 38 <JFXTextField fx:id="tf_js_book_id" alignment="CENTER" focusColor="DEEPSKYBLUE" layoutX="120.0" layoutY="128.0" /> 39 <Label layoutX="375.0" layoutY="130.0" text="读者编号" textFill="#2196f3"> 40 <font> 41 <Font name="System Bold Italic" size="15.0" /> 42 </font></Label> 43 <Label layoutX="381.0" layoutY="182.0" text="读者姓名" textFill="DARKORANGE" /> 44 <JFXTextField fx:id="tf_js_reader_id" alignment="CENTER" focusColor="DEEPSKYBLUE" layoutX="437.0" layoutY="128.0" /> 45 <JFXTextField fx:id="tf_js_reader_name" alignment="CENTER" editable="false" layoutX="437.0" layoutY="174.0" /> 46 <Separator layoutX="63.0" layoutY="112.0" prefWidth="220.0" /> 47 <Label layoutX="158.0" layoutY="81.0" text="图书信息" /> 48 <Label layoutX="464.0" layoutY="81.0" text="读者信息" /> 49 <Separator layoutX="378.0" layoutY="111.0" prefWidth="220.0" /> 50 <Label layoutX="63.0" layoutY="178.0" text="图书名称" textFill="DARKORANGE" /> 51 <Label layoutX="69.0" layoutY="225.0" text="出版社" textFill="DARKORANGE" /> 52 <Label layoutX="63.0" layoutY="271.0" text="出版时间" textFill="DARKORANGE" /> 53 <Label layoutX="381.0" layoutY="225.0" text="读者类别" textFill="DARKORANGE" /> 54 <Label layoutX="381.0" layoutY="271.0" text="读者性别" textFill="DARKORANGE" /> 55 <JFXTextField fx:id="tf_js_book_name" alignment="CENTER" editable="false" layoutX="120.0" layoutY="174.0" /> 56 <JFXTextField fx:id="tf_js_book_publisher" alignment="CENTER" editable="false" layoutX="120.0" layoutY="221.0" /> 57 <JFXTextField fx:id="tf_js_reader_type" alignment="CENTER" editable="false" layoutX="437.0" layoutY="221.0" /> 58 <JFXTextField fx:id="tf_js_book_publish_time" alignment="CENTER" editable="false" layoutX="120.0" layoutY="267.0" /> 59 <JFXTextField fx:id="tf_js_reader_sex" alignment="CENTER" editable="false" layoutX="437.0" layoutY="267.0" /> 60 <JFXButton fx:id="btn_jieshu_confirm" layoutX="267.0" layoutY="340.0" mnemonicParsing="false" onAction="#js_confirm_start" prefHeight="23.0" prefWidth="59.0" text="确认" /> 61 <JFXButton fx:id="btn_jieshu_clear" layoutX="332.0" layoutY="340.0" mnemonicParsing="false" onAction="#js_clear_start" prefHeight="23.0" prefWidth="63.0" text="清楚" /> 62 <Label layoutX="57.0" layoutY="308.0" text="借书日期" textFill="#304ffe"> 63 <font> 64 <Font name="System Bold Italic" size="15.0" /> 65 </font> 66 </Label> 67 <Label layoutX="375.0" layoutY="308.0" text="还书日期" textFill="#304ffe"> 68 <font> 69 <Font name="System Bold Italic" size="15.0" /> 70 </font> 71 </Label> 72 <Label fx:id="lb_js_reader_jieshu_date" alignment="CENTER" contentDisplay="CENTER" layoutX="127.0" layoutY="311.0" prefHeight="15.0" prefWidth="134.0" text="Label" /> 73 <Label fx:id="lb_js_reader_huanshu_date" alignment="CENTER" contentDisplay="CENTER" layoutX="452.0" layoutY="311.0" prefHeight="15.0" prefWidth="125.0" /> 74 <ImageView fx:id="imageview" fitHeight="40.0" fitWidth="47.0" layoutX="194.0" layoutY="-85.0" pickOnBounds="true" preserveRatio="true" /> 75 76 </children> 77 </AnchorPane> 78 </ScrollPane> 79 </content> 80 </Tab> 81 <Tab text="还书"> 82 <content> 83 <ScrollPane layoutX="120.0" layoutY="128.0" prefHeight="200.0" prefWidth="200.0"> 84 <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="379.0" prefWidth="655.0"> 85 <children> 86 <Label layoutX="314.0" layoutY="35.0" text="还书"> 87 <font> 88 <Font name="System Bold Italic" size="18.0" /> 89 </font> 90 </Label> 91 <Label layoutX="69.0" layoutY="310.0" text="图书编号" textFill="#2196f3"> 92 <font> 93 <Font name="System Bold Italic" size="15.0" /> 94 </font></Label> 95 <JFXTextField fx:id="tf_hs_book_id" alignment="CENTER" focusColor="DEEPSKYBLUE" layoutX="131.0" layoutY="309.0" /> 96 <Label layoutX="69.0" layoutY="133.0" text="读者编号" textFill="#2196f3"> 97 <font> 98 <Font name="System Bold Italic" size="15.0" /> 99 </font></Label> 100 <Label layoutX="76.0" layoutY="169.0" text="读者姓名" textFill="DARKORANGE" /> 101 <JFXTextField fx:id="tf_hs_reader_id" alignment="CENTER" focusColor="DEEPSKYBLUE" layoutX="131.0" layoutY="129.0" /> 102 <JFXTextField fx:id="tf_hs_reader_name" alignment="CENTER" editable="false" layoutX="132.0" layoutY="161.0" /> 103 <Separator layoutX="63.0" layoutY="112.0" prefWidth="220.0" /> 104 <Label layoutX="158.0" layoutY="81.0" text="读者信息" /> 105 <Label layoutX="464.0" layoutY="81.0" text="借书信息" /> 106 <Separator layoutX="335.0" layoutY="112.0" prefHeight="3.0" prefWidth="300.0" /> 107 <Label layoutX="285.0" layoutY="312.0" text="图书名称" textFill="DARKORANGE" /> 108 <Label layoutX="76.0" layoutY="197.0" text="读者类别" textFill="DARKORANGE" /> 109 <Label layoutX="76.0" layoutY="228.0" text="读者性别" textFill="DARKORANGE" /> 110 <JFXTextField fx:id="tf_hs_book_name" alignment="CENTER" editable="false" layoutX="342.0" layoutY="308.0" /> 111 <JFXTextField fx:id="tf_hs_reader_type" alignment="CENTER" editable="false" layoutX="132.0" layoutY="193.0" /> 112 <JFXTextField fx:id="tf_hs_reader_sex" alignment="CENTER" editable="false" layoutX="132.0" layoutY="224.0" /> 113 <JFXButton layoutX="267.0" layoutY="352.0" mnemonicParsing="false" onAction="#huanshu_start" prefHeight="23.0" prefWidth="59.0" text="确认" /> 114 <JFXButton layoutX="332.0" layoutY="352.0" mnemonicParsing="false" onAction="#clear_hs_reader" prefHeight="23.0" prefWidth="63.0" text="清楚" /> 115 <TableView fx:id="tbv_huanshu_record" layoutX="345.0" layoutY="124.0" prefHeight="127.0" prefWidth="284.0"> 116 <columns> 117 <TableColumn fx:id="tb_column_huanshu_bookId" prefWidth="54.0" text="图书Id" /> 118 <TableColumn fx:id="tb_column_huanshu_bookName" prefWidth="81.0" text="图书名称" /> 119 <TableColumn fx:id="tb_column_huanshu_borrowDate" prefWidth="73.0" text="借出时间" /> 120 <TableColumn fx:id="tb_column_huanshu_backDate" prefWidth="74.0" text="到期时间" /> 121 </columns> 122 </TableView> 123 <Label layoutX="158.0" layoutY="271.0" text="图书信息" /> 124 <Separator layoutX="68.0" layoutY="296.0" prefHeight="3.0" prefWidth="567.0" /> 125 </children> 126 </AnchorPane> 127 </ScrollPane> 128 </content> 129 </Tab> 130 <Tab text="图书信息维护"> 131 <ScrollPane layoutX="120.0" layoutY="128.0" prefHeight="200.0" prefWidth="200.0"> 132 <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="378.0" prefWidth="656.0"> 133 <children> 134 <Label layoutX="278.0" layoutY="25.0" text="图书信息维护"> 135 <font> 136 <Font name="System Bold Italic" size="18.0" /> 137 </font> 138 </Label> 139 <JFXTabPane layoutX="37.0" layoutY="63.0" prefHeight="301.0" prefWidth="577.0" style="-fx-border-color: #4CAF50; -fx-background-color: #EEEEEE;" tabClosingPolicy="UNAVAILABLE"> 140 <Tab text="添加"> 141 <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="656.0"> 142 <Label layoutX="53.0" layoutY="39.0" text="图书编号" textFill="#2196f3"> 143 <font> 144 <Font name="System Bold Italic" size="15.0" /> 145 </font></Label> 146 <Label layoutX="344.0" layoutY="39.0" text="图书名称" textFill="#2196f3"> 147 <font> 148 <Font name="System Bold Italic" size="15.0" /> 149 </font></Label> 150 <Label layoutX="53.0" layoutY="83.0" text="图书类别" /> 151 <Label layoutX="65.0" layoutY="125.0" text="译者" /> 152 <Label layoutX="53.0" layoutY="165.0" text="出版时间" /> 153 <Label layoutX="356.0" layoutY="83.0" text="作者" /> 154 <Label layoutX="350.0" layoutY="125.0" text="出版社" /> 155 <Label layoutX="356.0" layoutY="165.0" text="价格" /> 156 <Label layoutX="53.0" layoutY="209.0" text="库存容量" /> 157 <JFXButton fx:id="btn_ts_add_book_add" layoutX="392.0" layoutY="235.0" mnemonicParsing="false" onAction="#ts_book_add" prefHeight="23.0" prefWidth="69.0" text="添加" /> 158 <JFXButton fx:id="btn_ts_add_book_clear" layoutX="473.0" layoutY="235.0" mnemonicParsing="false" onAction="#ts_book_add_clear" prefHeight="23.0" prefWidth="69.0" text="清楚" /> 159 <JFXTextField fx:id="tf_ts_add_book_id" alignment="CENTER" focusColor="DEEPSKYBLUE" layoutX="112.0" layoutY="35.0" /> 160 <JFXTextField fx:id="tf_ts_add_book_translator" alignment="CENTER" focusColor="DEEPSKYBLUE" layoutX="112.0" layoutY="121.0" /> 161 <JFXTextField fx:id="tf_ts_add_book_stock" alignment="CENTER" focusColor="DEEPSKYBLUE" layoutX="112.0" layoutY="207.0" /> 162 <JFXTextField fx:id="tf_ts_add_book_name" alignment="CENTER" focusColor="DEEPSKYBLUE" layoutX="404.0" layoutY="35.0" /> 163 <JFXTextField fx:id="tf_ts_add_book_author" alignment="CENTER" focusColor="DEEPSKYBLUE" layoutX="404.0" layoutY="79.0" /> 164 <JFXTextField fx:id="tf_ts_add_book_publisher" alignment="CENTER" focusColor="DEEPSKYBLUE" layoutX="404.0" layoutY="121.0" /> 165 <JFXTextField fx:id="tf_ts_add_book_price" alignment="CENTER" focusColor="DEEPSKYBLUE" layoutX="404.0" layoutY="161.0" /> 166 <JFXComboBox fx:id="cb_ts_add_book_type" focusColor="DEEPSKYBLUE" layoutX="111.0" layoutY="79.0" prefWidth="150.0" promptText="请选择类别..." /> 167 <JFXDatePicker fx:id="dp_ts_add_book_publish_time" defaultColor="DEEPSKYBLUE" layoutX="112.0" layoutY="161.0" prefHeight="23.0" prefWidth="156.0" /> 168 </AnchorPane> 169 </Tab> 170 <Tab text="修改"> 171 <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="656.0"> 172 <Label layoutX="53.0" layoutY="70.0" text="图书编号" /> 173 <Label layoutX="344.0" layoutY="70.0" text="图书名称" /> 174 <Label layoutX="53.0" layoutY="112.0" text="图书类别" /> 175 <Label layoutX="56.0" layoutY="147.0" text="译 者" /> 176 <Label layoutX="53.0" layoutY="181.0" text="出版时间" /> 177 <Label layoutX="356.0" layoutY="112.0" text="作者" /> 178 <Label layoutX="350.0" layoutY="147.0" text="出版社" /> 179 <Label layoutX="356.0" layoutY="181.0" text="价格" /> 180 <Label layoutX="53.0" layoutY="216.0" text="库存容量" /> 181 <JFXButton fx:id="btn_ts_alter_book_alterBtn" layoutX="392.0" layoutY="235.0" mnemonicParsing="false" onAction="#ts_book_alter_start" prefHeight="23.0" prefWidth="69.0" text="修改" /> 182 <JFXButton fx:id="btn_ts_alter_book_clearBtn" layoutX="473.0" layoutY="235.0" mnemonicParsing="false" onAction="#ts_book_alter_clear" prefHeight="23.0" prefWidth="69.0" text="清楚" /> 183 <JFXTextField fx:id="tf_ts_alter_book_id" editable="false" layoutX="112.0" layoutY="66.0" /> 184 <JFXTextField fx:id="tf_ts_alter_book_translator" layoutX="112.0" layoutY="143.0" /> 185 <JFXTextField fx:id="tf_ts_alter_book_stock" layoutX="112.0" layoutY="214.0" /> 186 <JFXTextField fx:id="tf_ts_alter_book_name" layoutX="404.0" layoutY="66.0" /> 187 <JFXTextField fx:id="tf_ts_alter_book_author" layoutX="404.0" layoutY="108.0" /> 188 <JFXTextField fx:id="tf_ts_alter_book_publisher" layoutX="404.0" layoutY="143.0" /> 189 <JFXTextField fx:id="tf_ts_alter_book_price" layoutX="404.0" layoutY="177.0" /> 190 <JFXComboBox fx:id="cb_ts_alter_book_type" editable="true" layoutX="111.0" layoutY="108.0" prefWidth="150.0" /> 191 <JFXDatePicker fx:id="tp_ts_alter_book_publish_time" layoutX="113.0" layoutY="177.0" prefHeight="23.0" prefWidth="156.0" /> 192 <Label layoutX="43.0" layoutY="27.0" text="图书编号" textFill="#2196f3"> 193 <font> 194 <Font name="System Bold Italic" size="17.0" /> 195 </font> 196 </Label> 197 <JFXTextField fx:id="tf_ts_alter_book_search_id" layoutX="113.0" layoutY="27.0" prefHeight="23.0" prefWidth="343.0" /> 198 <JFXButton fx:id="btn_ts_alter_book_searchBtn" layoutX="465.0" layoutY="27.0" mnemonicParsing="false" onAction="#ts_book_alter_search" prefHeight="23.0" prefWidth="85.0" text="查询" /> 199 </AnchorPane> 200 </Tab> 201 <Tab text="删除"> 202 <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="656.0"> 203 <Label layoutX="53.0" layoutY="70.0" text="图书编号" /> 204 <Label layoutX="344.0" layoutY="70.0" text="图书名称" /> 205 <Label layoutX="53.0" layoutY="112.0" text="图书类别" /> 206 <Label layoutX="56.0" layoutY="147.0" text="译 者" /> 207 <Label layoutX="53.0" layoutY="181.0" text="出版时间" /> 208 <Label layoutX="356.0" layoutY="112.0" text="作者" /> 209 <Label layoutX="350.0" layoutY="147.0" text="出版社" /> 210 <Label layoutX="356.0" layoutY="181.0" text="价格" /> 211 <Label layoutX="53.0" layoutY="216.0" text="库存容量" /> 212 <JFXButton fx:id="btn_ts_delete_book_deleteBtn" layoutX="392.0" layoutY="235.0" mnemonicParsing="false" onAction="#ts_book_delete" prefHeight="23.0" prefWidth="69.0" text="删除" /> 213 <JFXButton fx:id="btn_ts_delete_book_clearBtn" layoutX="473.0" layoutY="235.0" mnemonicParsing="false" onAction="#ts_book_delete_clear" prefHeight="23.0" prefWidth="69.0" text="清楚" /> 214 <JFXTextField fx:id="tf_ts_delete_book_id" editable="false" layoutX="112.0" layoutY="66.0" /> 215 <JFXTextField fx:id="tf_ts_delete_book_translator" editable="false" layoutX="112.0" layoutY="143.0" /> 216 <JFXTextField fx:id="tf_ts_delete_book_stock" editable="false" layoutX="112.0" layoutY="214.0" /> 217 <JFXTextField fx:id="tf_ts_delete_book_name" editable="false" layoutX="404.0" layoutY="66.0" /> 218 <JFXTextField fx:id="tf_ts_delete_book_author" editable="false" layoutX="404.0" layoutY="108.0" /> 219 <JFXTextField fx:id="tf_ts_delete_book_publisher" editable="false" layoutX="404.0" layoutY="143.0" /> 220 <JFXTextField fx:id="tf_ts_delete_book_price" editable="false" layoutX="404.0" layoutY="177.0" /> 221 <JFXComboBox fx:id="cb_ts_delete_book_type" editable="true" layoutX="111.0" layoutY="108.0" prefWidth="150.0" /> 222 <JFXTextField fx:id="tf_ts_delete_book_publish_time" editable="false" layoutX="112.0" layoutY="177.0" /> 223 <Label layoutX="43.0" layoutY="27.0" text="图书编号" textFill="#2196f3"> 224 <font> 225 <Font name="System Bold Italic" size="17.0" /> 226 </font> 227 </Label> 228 <JFXTextField fx:id="tf_ts_delete_book_search_id" layoutX="113.0" layoutY="27.0" prefHeight="23.0" prefWidth="343.0" /> 229 <JFXButton fx:id="btn_ts_delete_book_searchBtn" layoutX="465.0" layoutY="27.0" mnemonicParsing="false" onAction="#ts_book_delete_search" prefHeight="23.0" prefWidth="85.0" text="查询" /> 230 </AnchorPane> 231 </Tab> 232 <Tab text="图书类别"> 233 <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="656.0"> 234 235 </AnchorPane> 236 </Tab> 237 </JFXTabPane> 238 </children> 239 </AnchorPane> 240 </ScrollPane> 241 242 </Tab> 243 <Tab text="读者信息维护"> 244 <ScrollPane layoutX="120.0" layoutY="128.0" prefHeight="200.0" prefWidth="200.0"> 245 <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="377.0" prefWidth="658.0"> 246 <children> 247 <Label layoutX="275.0" layoutY="27.0" text="读者信息维护"> 248 <font> 249 <Font name="System Bold Italic" size="18.0" /> 250 </font> 251 </Label> 252 <JFXTabPane layoutX="37.0" layoutY="63.0" prefHeight="302.0" prefWidth="577.0" style="-fx-background-color: #EEEEEE; -fx-border-color: #4CAF50;" tabClosingPolicy="UNAVAILABLE"> 253 <Tab text="添加"> 254 <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="577.0"> 255 <Label layoutX="53.0" layoutY="39.0" text="读者编号" /> 256 <Label layoutX="344.0" layoutY="39.0" text="读者姓名" /> 257 <Label layoutX="53.0" layoutY="83.0" text="读者类别" /> 258 <Label layoutX="53.0" layoutY="128.0" text="可借数量" /> 259 <Label layoutX="356.0" layoutY="83.0" text="性别" /> 260 <Label layoutX="344.0" layoutY="128.0" text="可借天数" /> 261 <JFXTextField fx:id="tf_rd_add_reader_id" layoutX="117.0" layoutY="35.0" /> 262 <JFXTextField fx:id="tf_rd_add_reader_numbers" layoutX="117.0" layoutY="124.0" /> 263 <JFXTextField fx:id="tf_rd_add_reader_name" layoutX="406.0" layoutY="35.0" /> 264 <JFXTextField fx:id="tf_rd_add_reader_days" layoutX="406.0" layoutY="124.0" /> 265 <JFXComboBox fx:id="cb_rd_add_reader_type" layoutX="116.0" layoutY="79.0" prefWidth="150.0" /> 266 <JFXComboBox fx:id="cb_rd_add_reader_sex" layoutX="405.0" layoutY="79.0" prefWidth="150.0" /> 267 <JFXButton fx:id="btn_rd_add_reader_addBtn" layoutX="392.0" layoutY="235.0" mnemonicParsing="false" onAction="#add_new_reader" prefHeight="23.0" prefWidth="69.0" text="添加" /> 268 <JFXButton fx:id="btn_rd_add_reader_clearBtn" layoutX="473.0" layoutY="235.0" mnemonicParsing="false" onAction="#rd_reader_add_clear" prefHeight="23.0" prefWidth="69.0" text="清楚" /> 269 </AnchorPane> 270 </Tab> 271 <Tab text="修改"> 272 <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="656.0"> 273 <Label layoutX="53.0" layoutY="78.0" text="读者编号" /> 274 <Label layoutX="344.0" layoutY="78.0" text="读者姓名" /> 275 <Label layoutX="53.0" layoutY="122.0" text="读者类别" /> 276 <Label layoutX="53.0" layoutY="167.0" text="可借数量" /> 277 <Label layoutX="356.0" layoutY="122.0" text="性别" /> 278 <Label layoutX="344.0" layoutY="167.0" text="可借天数" /> 279 <JFXTextField fx:id="tf_rd_alter_reader_id" editable="false" layoutX="117.0" layoutY="74.0" /> 280 <JFXTextField fx:id="tf_rd_alter_reader_numbers" layoutX="117.0" layoutY="163.0" /> 281 <JFXTextField fx:id="tf_rd_alter_reader_name" layoutX="406.0" layoutY="74.0" /> 282 <JFXTextField fx:id="tf_rd_alter_reader_days" layoutX="406.0" layoutY="163.0" /> 283 <JFXComboBox fx:id="cb_rd_alter_reader_type" layoutX="116.0" layoutY="118.0" prefWidth="150.0" /> 284 <JFXComboBox fx:id="cb_rd_alter_reader_sex" layoutX="405.0" layoutY="118.0" prefWidth="150.0" /> 285 <JFXButton fx:id="btn_rd_alter_reader_alterBtn" layoutX="392.0" layoutY="235.0" mnemonicParsing="false" onAction="#alter_rd_reader" prefHeight="23.0" prefWidth="69.0" text="修改" /> 286 <JFXButton fx:id="btn_rd_alter_reader_clearBtn" layoutX="473.0" layoutY="235.0" mnemonicParsing="false" onAction="#rd_reader_alter_clear" prefHeight="23.0" prefWidth="69.0" text="清楚" /> 287 <Label layoutX="41.0" layoutY="35.0" text="读者编号" textFill="#2196f3"> 288 <font> 289 <Font name="System Bold Italic" size="18.0" /> 290 </font> 291 </Label> 292 <JFXTextField fx:id="tf_rd_alter_reader_search_id" layoutX="118.0" layoutY="36.0" prefHeight="23.0" prefWidth="350.0" /> 293 <JFXButton layoutX="474.0" layoutY="36.0" mnemonicParsing="false" onAction="#rd_reader_alter_search" prefHeight="23.0" prefWidth="79.0" text="查询" /> 294 <JFXToggleButton fx:id="tgBtn_rd_alter_reader_password_reset" layoutX="118.0" layoutY="196.0" mnemonicParsing="false" prefHeight="56.0" prefWidth="149.0" text="初始化密码" /> 295 <Label layoutX="53.0" layoutY="218.0" text="密码设置" /> 296 </AnchorPane> 297 </Tab> 298 <Tab text="删除"> 299 <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="656.0"> 300 <Label layoutX="53.0" layoutY="78.0" text="读者编号" /> 301 <Label layoutX="344.0" layoutY="78.0" text="读者姓名" /> 302 <Label layoutX="53.0" layoutY="122.0" text="读者类别" /> 303 <Label layoutX="53.0" layoutY="167.0" text="可借数量" /> 304 <Label layoutX="356.0" layoutY="122.0" text="性别" /> 305 <Label layoutX="344.0" layoutY="167.0" text="可借天数" /> 306 <JFXTextField fx:id="tf_rd_delete_reader_id" editable="false" layoutX="117.0" layoutY="74.0" /> 307 <JFXTextField fx:id="tf_rd_delete_reader_numbers" editable="false" layoutX="117.0" layoutY="163.0" /> 308 <JFXTextField fx:id="tf_rd_delete_reader_name" editable="false" layoutX="406.0" layoutY="74.0" /> 309 <JFXTextField fx:id="tf_rd_delete_reader_days" editable="false" layoutX="406.0" layoutY="163.0" /> 310 <JFXComboBox fx:id="cb_rd_delete_reader_type" layoutX="116.0" layoutY="118.0" prefWidth="150.0" /> 311 <JFXComboBox fx:id="cb_rd_delete_reader_sex" layoutX="405.0" layoutY="118.0" prefWidth="150.0" /> 312 <JFXButton fx:id="btn_rd_delete_reader_deleteBtn" layoutX="392.0" layoutY="235.0" mnemonicParsing="false" onAction="#delete_rd_reader" prefHeight="23.0" prefWidth="69.0" text="删除" /> 313 <JFXButton fx:id="btn_rd_delete_reader_clearBtn" layoutX="473.0" layoutY="235.0" mnemonicParsing="false" onAction="#rd_reader_delete_clear" prefHeight="23.0" prefWidth="69.0" text="清楚" /> 314 <Label layoutX="41.0" layoutY="35.0" text="读者编号" textFill="#2196f3"> 315 <font> 316 <Font name="System Bold Italic" size="18.0" /> 317 </font> 318 </Label> 319 <JFXTextField fx:id="tf_rd_delete_reader_search_id" layoutX="118.0" layoutY="36.0" prefHeight="23.0" prefWidth="350.0" /> 320 <JFXButton fx:id="btn_rd_delete_reader_searchBtn" layoutX="474.0" layoutY="36.0" mnemonicParsing="false" onAction="#rd_reader_delete_search" prefHeight="23.0" prefWidth="79.0" text="查询" /> 321 </AnchorPane> 322 </Tab> 323 </JFXTabPane> 324 </children> 325 </AnchorPane> 326 </ScrollPane> 327 </Tab> 328 <Tab text="所有书目"> 329 <AnchorPane fx:id="treeview_test" minHeight="0.0" minWidth="0.0" prefHeight="377.0" prefWidth="658.0"> 330 <children> 331 <TableView fx:id="tbv_book" layoutX="14.0" layoutY="45.0" prefHeight="320.0" prefWidth="635.0"> 332 <columns> 333 <TableColumn fx:id="tb_column_book_id" prefWidth="75.0" text="图书ID" /> 334 <TableColumn fx:id="tb_column_book_name" prefWidth="89.0" text="图书名称" /> 335 <TableColumn fx:id="tb_column_book_type" prefWidth="69.0" text="图书类别" /> 336 <TableColumn fx:id="tb_column_book_author" prefWidth="64.0" text="作者" /> 337 <TableColumn fx:id="tb_column_book_translator" prefWidth="69.0" text="译者" /> 338 <TableColumn fx:id="tb_column_book_publisher" prefWidth="92.0" text="出版社" /> 339 <TableColumn fx:id="tb_column_book_publishTime" prefWidth="84.0" text="出版时间" /> 340 <TableColumn fx:id="tb_column_book_price" prefWidth="71.0" text="价格" /> 341 </columns> 342 </TableView> 343 <JFXButton layoutX="581.0" layoutY="14.0" mnemonicParsing="false" onAction="#getAllBooks" prefHeight="23.0" prefWidth="65.0" text="刷新" /> 344 </children> 345 </AnchorPane> 346 </Tab> 347 <Tab text="所有读者"> 348 <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="377.0" prefWidth="658.0"> 349 <children> 350 <TableView fx:id="tbv_reader" layoutX="14.0" layoutY="45.0" prefHeight="320.0" prefWidth="635.0"> 351 <columns> 352 <TableColumn fx:id="tb_column_reader_id" prefWidth="75.0" text="读者ID" /> 353 <TableColumn fx:id="tb_column_reader_name" prefWidth="75.0" text="读者名称" /> 354 <TableColumn fx:id="tb_column_reader_type" prefWidth="75.0" text="读者类别" /> 355 <TableColumn fx:id="tb_column_reader_sex" prefWidth="75.0" text="读者性别" /> 356 <TableColumn fx:id="tb_column_reader_numbers" prefWidth="75.0" text="可借数量" /> 357 <TableColumn fx:id="tb_column_reader_days" prefWidth="75.0" text="可借天数" /> 358 <TableColumn fx:id="tb_column_reader_forfeit" prefWidth="75.0" text="罚款金额" /> 359 <TableColumn fx:id="tb_column_reader_borrowed_books" prefWidth="75.0" text="已借数量" /> 360 </columns> 361 </TableView> 362 <JFXButton layoutX="581.0" layoutY="14.0" mnemonicParsing="false" onAction="#getAllReaders" prefHeight="23.0" prefWidth="65.0" text="刷新" /> 363 </children> 364 </AnchorPane> 365 </Tab> 366 <Tab text="所有借阅记录"> 367 <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="377.0" prefWidth="658.0"> 368 <children> 369 <TableView fx:id="tbv_borrow" layoutX="14.0" layoutY="45.0" prefHeight="320.0" prefWidth="635.0"> 370 <columns> 371 <TableColumn fx:id="tb_column_borrow_id" prefWidth="78.0" text="借阅流水号" /> 372 <TableColumn fx:id="tb_column_borrow_bookId" prefWidth="153.0" text="图书" /> 373 <TableColumn fx:id="tb_column_borrow_readerId" prefWidth="149.0" text="读者" /> 374 <TableColumn fx:id="tb_column_borrow_borrowDate" prefWidth="94.0" text="借出时间" /> 375 <TableColumn fx:id="tb_column_borrow_backDate" prefWidth="92.0" text="到期时间" /> 376 <TableColumn fx:id="tb_column_borrow_isBack" prefWidth="68.0" text="是否归还" /> 377 </columns> 378 </TableView> 379 <JFXButton layoutX="581.0" layoutY="14.0" mnemonicParsing="false" onAction="#getAllBorrowedRecordings" prefHeight="23.0" prefWidth="65.0" text="刷新" /> 380 </children> 381 </AnchorPane> 382 </Tab> 383 </tabs> 384 </JFXTabPane> 385 <Label layoutX="272.0" layoutY="14.0" text="图书管理系统" textFill="GOLD"> 386 <font> 387 <Font name="System Bold Italic" size="26.0" /> 388 </font> 389 </Label> 390 <Label fx:id="lb_welcome" layoutX="28.0" layoutY="40.0" text="xx,老师您好!" textFill="DARKORANGE" /> 391 <Hyperlink layoutX="633.0" layoutY="37.0" onAction="#hbrlink_goto_login" text="退出" /> 392 </children> 393 </AnchorPane>
效果如下:
8.util包----工具类
- constant常量类
package Util; public class Constant { //图书类别 public static final String[] BOOK_TYPES = new String[]{"科技类", "文学类", "杂志", "其他"}; //读者类别 public static final String[] READER_YTPES = new String[]{"教师", "学生", "职工"}; //性别 public static final String[] SEX = new String[]{"男", "女"}; }
- DataUtils 时间计算类------计算出指定日期过多少天以后的日期,适用于计算到期时间
package Util; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.SimpleTimeZone; public class DateUtils { public static String getAfterDay(String date, int day) { SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd"); Date a = null; try { a = parser.parse(date); Calendar calendar = Calendar.getInstance(); calendar.setTime(a); calendar.add(Calendar.DATE, day); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); return simpleDateFormat.format(calendar.getTime()); } catch (ParseException e) { e.printStackTrace(); } return null; } }
- FileUtil-----文件类-----适用于记住密码等
package Util; import java.io.*; import java.util.Arrays; import java.util.Scanner; public class FileUtil { public static void setUserAndPass(String User, String Pass) { PrintWriter outputStream = null; try { outputStream = new PrintWriter(new FileOutputStream("user_pass.txt")); outputStream.println(User+"#"+Pass); outputStream.flush(); } catch (FileNotFoundException e) { e.printStackTrace(); } } public static String getUserAndPass( ) { Scanner scan = null; try { scan = new Scanner(new FileInputStream("user_pass.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); } return scan.nextLine(); } }
- DataBaseUtil-----数据库查询类-----所有的数据库查询代码均在这个类里面,方便维护
1 package Util; 2 3 import javafx.collections.FXCollections; 4 import javafx.collections.ObservableList; 5 import sample.entity.*; 6 7 import java.math.BigDecimal; 8 import java.sql.*; 9 import java.text.SimpleDateFormat; 10 import java.util.ArrayList; 11 import java.util.Date; 12 import java.util.HashMap; 13 14 15 public class DataBaseUtil { 16 17 18 /** 19 * 读者登陆检查 20 * @param account 21 * @param password 22 * @return 23 */ 24 public static boolean checkReader(String account, String password) { 25 boolean checkbool = false; 26 try { 27 Connection con = null; //定义一个MYSQL链接对象 28 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 29 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 30 Statement stmt; //创建声明 31 stmt = con.createStatement(); 32 33 String password_fromDb; 34 String selectSql = "select pass from Reader where Id='"+account+"'"; 35 ResultSet selectRes = stmt.executeQuery(selectSql); 36 if (selectRes.next()) { 37 password_fromDb = selectRes.getString("pass"); 38 if (password_fromDb.equals(password)) { 39 checkbool = true; 40 } 41 } 42 con.close(); 43 } catch (Exception e) { 44 System.out.print("读者登陆检查---checkReader----MYSQL ERROR:" + e.getMessage()); 45 } 46 return checkbool; 47 } 48 49 /** 50 * 管理员登陆检查 51 * @param account 52 * @param password 53 * @return 54 */ 55 public static boolean checkUser(String account, String password) { 56 boolean checkbool = false; 57 try { 58 Connection con = null; //定义一个MYSQL链接对象 59 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 60 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 61 Statement stmt; //创建声明 62 stmt = con.createStatement(); 63 64 String password_fromDb; 65 String selectSql = "SELECT pass FROM user where Id='"+account+"'"; 66 ResultSet selectRes = stmt.executeQuery(selectSql); 67 if (selectRes.next()) { 68 password_fromDb = selectRes.getString("pass"); 69 if (password_fromDb.equals(password)) { 70 checkbool = true; 71 } 72 } 73 con.close(); 74 } catch (Exception e) { 75 System.out.print("管理员登陆检查----checkUser----MYSQL ERROR:" + e.getMessage()); 76 } 77 return checkbool; 78 } 79 80 /** 81 * 获取book 82 * @param id 83 * @return 84 */ 85 public static Book getBook(String id) { 86 Book book = null; 87 try { 88 Connection con = null; //定义一个MYSQL链接对象 89 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 90 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 91 Statement stmt; //创建声明 92 stmt = con.createStatement(); 93 94 String selectSql = "SELECT * FROM book where Id='"+id+"'"; 95 ResultSet selectRes = stmt.executeQuery(selectSql); 96 if (selectRes.next()) { 97 book = new Book(); 98 book.setId(selectRes.getString("Id")); 99 book.setName(selectRes.getString("name")); 100 book.setType(selectRes.getString("type")); 101 book.setAuthor(selectRes.getString("author")); 102 book.setTranslator(selectRes.getString("translator")); 103 book.setPublisher(selectRes.getString("publisher")); 104 book.setPublishTime(selectRes.getDate("publish_time").toString()); 105 book.setStock(selectRes.getInt("stock")); 106 book.setPrice(selectRes.getDouble("price")); 107 } 108 con.close(); 109 return book; 110 } catch (Exception e) { 111 System.out.print("book获取检查----getBook----MYSQL ERROR:" + e.getMessage()); 112 } 113 return book; 114 } 115 116 /** 117 * 获取单个读者信息 118 * @param id 119 * @return 120 */ 121 public static Reader getReader(String id) { 122 Reader reader = null; 123 try { 124 Connection con = null; //定义一个MYSQL链接对象 125 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 126 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 127 Statement stmt; //创建声明 128 stmt = con.createStatement(); 129 130 String selectSql = "SELECT * FROM reader where Id='"+id+"'"; 131 ResultSet selectRes = stmt.executeQuery(selectSql); 132 if (selectRes.next()) { 133 reader = new Reader(); 134 reader.setId(selectRes.getString("Id")); 135 reader.setName(selectRes.getString("name")); 136 reader.setPassword(selectRes.getString("pass")); 137 reader.setType(selectRes.getString("type")); 138 reader.setSex(selectRes.getString("sex")); 139 reader.setMax_num(selectRes.getInt("max_num")); 140 reader.setDays_num(selectRes.getInt("days_num")); 141 reader.setForfeit(selectRes.getDouble("forfeit")); 142 } 143 con.close(); 144 return reader; 145 } catch (Exception e) { 146 System.out.print("reader获取检查----getReader----MYSQL ERROR:" + e.getMessage()); 147 } 148 return reader; 149 } 150 151 /** 152 * 添加新的借阅记录 153 * @param bookId 154 * @param readerId 155 * @param jieshu_date 156 * @param huanshu_date 157 * @param isBack 158 * @return 159 */ 160 public static boolean addNewBorrow(String bookId, String readerId, String jieshu_date, String huanshu_date, int isBack) { 161 try { 162 Connection con = null; //定义一个MYSQL链接对象 163 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 164 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 165 Statement stmt; //创建声明 166 stmt = con.createStatement(); 167 168 String updateSql = "insert into borrow (book_id,reader_id,borrow_date,back_date,is_back) values ('"+bookId+"','"+readerId+"','"+jieshu_date+"','"+huanshu_date+"','"+isBack+"')"; 169 int selectRes = stmt.executeUpdate(updateSql); 170 if (selectRes != 0) { 171 return true; 172 } 173 con.close(); 174 } catch (Exception e) { 175 System.out.print("addBorrow检查----addNewBorrow----MYSQL ERROR:" + e.getMessage()); 176 } 177 return false; 178 179 } 180 181 /** 182 * 183 * 添加新书 184 * @param book 185 * @return 186 */ 187 public static boolean addNewBook(Book book) { 188 try { 189 Connection con = null; //定义一个MYSQL链接对象 190 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 191 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 192 Statement stmt; //创建声明 193 stmt = con.createStatement(); 194 195 String updateSql = "insert into book (Id,name,type,author,translator,publisher,publish_time,stock,price) values ('" + book.getId() + "','" + book.getName() + "','" + book.getType() + "','" + book.getAuthor() + "','" + book.getTranslator()+ "','" + book.getPublisher()+ "','" + book.getPublishTime()+ "','" + book.getStock()+ "','" + book.getPrice() + "')"; 196 int selectRes = stmt.executeUpdate(updateSql); 197 if (selectRes != 0) { 198 return true; 199 } 200 con.close(); 201 } catch (Exception e) { 202 System.out.print("addBook检查----addNewBook----MYSQL ERROR:" + e.getMessage()); 203 } 204 return false; 205 206 } 207 208 /** 209 * 修改单个书 210 * @param book 211 * @return 212 */ 213 public static Boolean alterBook(Book book) { 214 try { 215 Connection con = null; //定义一个MYSQL链接对象 216 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 217 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 218 Statement stmt; //创建声明 219 stmt = con.createStatement(); 220 221 String updateSql = "update book set name='" + book.getName() + "',type='" + book.getType() + "',author='" + book.getAuthor() + "',translator='" + book.getTranslator() + "',publisher='" + book.getPublisher() + "',publish_time='" + book.getPublishTime() + "',stock=" + book.getStock() + ",price=" + book.getPrice() + " where Id =" + book.getId() + ""; 222 System.out.println(updateSql); 223 int selectRes = stmt.executeUpdate(updateSql); 224 if (selectRes != 0) { 225 return true; 226 } 227 con.close(); 228 } catch (Exception e) { 229 System.out.print("alterBook检查----alterBook----MYSQL ERROR:" + e.getMessage()); 230 } 231 return false; 232 } 233 234 /** 235 * 删除单个书 236 * @param book 237 * @return 238 */ 239 public static Boolean deleteBook(Book book) { 240 try { 241 Connection con = null; //定义一个MYSQL链接对象 242 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 243 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 244 Statement stmt; //创建声明 245 stmt = con.createStatement(); 246 247 String updateSql = "delete from book where Id='"+book.getId()+"'"; 248 System.out.println(updateSql); 249 int selectRes = stmt.executeUpdate(updateSql); 250 if (selectRes != 0) { 251 return true; 252 } 253 con.close(); 254 } catch (Exception e) { 255 System.out.print("deleteBook检查----deleteBook----MYSQL ERROR:" + e.getMessage()); 256 } 257 return false; 258 } 259 260 /** 261 * 添加新的读者 262 * @param reader 263 * @return 264 */ 265 public static Boolean addNewReader(Reader reader) { 266 try { 267 Connection con = null; //定义一个MYSQL链接对象 268 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 269 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 270 Statement stmt; //创建声明 271 stmt = con.createStatement(); 272 273 String updateSql = "insert into reader (Id,name,pass,type,sex,max_num,days_num,forfeit) values ('" + reader.getId() + "','" + reader.getName() + "','" + reader.getPassword() + "','"+ reader.getType()+"','" + reader.getSex() + "','" + reader.getMax_num()+ "','" + reader.getDays_num()+ "','" + reader.getForfeit()+ "')"; 274 System.out.println(updateSql); 275 int selectRes = stmt.executeUpdate(updateSql); 276 if (selectRes != 0) { 277 return true; 278 } 279 con.close(); 280 } catch (Exception e) { 281 System.out.print("addReader检查----addNewReader----MYSQL ERROR:" + e.getMessage()); 282 } 283 return false; 284 } 285 286 /** 287 * 修改单个书 288 * @param reader 289 * @return 290 */ 291 public static Boolean alterReader(Reader reader) { 292 try { 293 Connection con = null; //定义一个MYSQL链接对象 294 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 295 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 296 Statement stmt; //创建声明 297 stmt = con.createStatement(); 298 299 String updateSql = "update reader set name='" + reader.getName() +"',pass='"+reader.getPassword()+ "',type='" + reader.getType() + "',sex='" + reader.getSex() + "',max_num=" + reader.getMax_num() + ",days_num=" + reader.getDays_num() + ",forfeit=" + reader.getForfeit() + " where Id =" + reader.getId() + ""; 300 System.out.println(updateSql); 301 int selectRes = stmt.executeUpdate(updateSql); 302 if (selectRes != 0) { 303 return true; 304 } 305 con.close(); 306 } catch (Exception e) { 307 System.out.print("alterReader检查----alterReader----MYSQL ERROR:" + e.getMessage()); 308 } 309 return false; 310 } 311 312 /** 313 * 删除读者 314 * @param Id 315 * @return 316 */ 317 public static Boolean deleteReader(String Id) { 318 try { 319 Connection con = null; //定义一个MYSQL链接对象 320 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 321 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 322 Statement stmt; //创建声明 323 stmt = con.createStatement(); 324 325 String updateSql = "delete from reader where Id='"+Id+"'"; 326 System.out.println(updateSql); 327 int selectRes = stmt.executeUpdate(updateSql); 328 if (selectRes != 0) { 329 return true; 330 } 331 con.close(); 332 } catch (Exception e) { 333 System.out.print("deleteReader检查----deleteReader----MYSQL ERROR:" + e.getMessage()); 334 } 335 return false; 336 337 } 338 339 /** 340 * 获取用户---管理员 341 * @param myName 342 * @return 343 */ 344 public static User getUser(String myName) { 345 User user = null; 346 try { 347 Connection con = null; //定义一个MYSQL链接对象 348 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 349 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 350 Statement stmt; //创建声明 351 stmt = con.createStatement(); 352 353 String selectSql = "SELECT * FROM user where Id='"+myName+"'"; 354 ResultSet selectRes = stmt.executeQuery(selectSql); 355 if (selectRes.next()) { 356 user = new User(); 357 user.setId(selectRes.getString("Id")); 358 user.setName(selectRes.getString("name")); 359 user.setEmail(selectRes.getString("email")); 360 user.setIsAdmin(selectRes.getInt("is_admin")); 361 } 362 con.close(); 363 return user; 364 } catch (Exception e) { 365 System.out.print("user获取检查----getUser----MYSQL ERROR:" + e.getMessage()); 366 } 367 return user; 368 369 } 370 371 /** 372 * 获取所有图书信息 373 * @return 374 */ 375 public static ObservableList<Book> getAllBooks() { 376 final ObservableList<Book> books = FXCollections.observableArrayList(); 377 try { 378 Connection con = null; //定义一个MYSQL链接对象 379 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 380 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 381 Statement stmt; //创建声明 382 stmt = con.createStatement(); 383 384 Book book = null; 385 String selectSql = "SELECT * FROM book"; 386 ResultSet selectRes = stmt.executeQuery(selectSql); 387 while (selectRes.next()) { 388 book = new Book(); 389 book.setId(selectRes.getString("Id")); 390 book.setName(selectRes.getString("name")); 391 book.setType(selectRes.getString("type")); 392 book.setAuthor(selectRes.getString("author")); 393 book.setTranslator(selectRes.getString("translator")); 394 book.setPublisher(selectRes.getString("publisher")); 395 book.setPublishTime(selectRes.getDate("publish_time").toString()); 396 book.setStock(selectRes.getInt("stock")); 397 book.setPrice(selectRes.getDouble("price")); 398 399 books.add(book); 400 } 401 con.close(); 402 return books; 403 } catch (Exception e) { 404 System.out.print("books获取检查----getAllBooks----MYSQL ERROR:" + e.getMessage()); 405 } 406 return books; 407 } 408 409 /** 410 * 获取所有读者信息 411 * @return 412 */ 413 public static ObservableList<Reader> getAllReaders() { 414 final ObservableList<Reader> readers = FXCollections.observableArrayList(); 415 try { 416 Connection con = null; //定义一个MYSQL链接对象 417 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 418 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 419 Statement stmt; //创建声明 420 stmt = con.createStatement(); 421 422 Reader reader = null; 423 String selectSql = "SELECT * FROM reader"; 424 ResultSet selectRes = stmt.executeQuery(selectSql); 425 while (selectRes.next()) { 426 reader = new Reader(); 427 reader.setId(selectRes.getString("Id")); 428 reader.setName(selectRes.getString("name")); 429 reader.setPassword(selectRes.getString("pass")); 430 reader.setType(selectRes.getString("type")); 431 reader.setSex(selectRes.getString("sex")); 432 reader.setMax_num(selectRes.getInt("max_num")); 433 reader.setDays_num(selectRes.getInt("days_num")); 434 reader.setForfeit(selectRes.getDouble("forfeit")); 435 readers.add(reader); 436 } 437 con.close(); 438 return readers; 439 } catch (Exception e) { 440 System.out.print("getAllReader获取检查----getAllReader----MYSQL ERROR:" + e.getMessage()); 441 } 442 return readers; 443 } 444 445 /** 446 * 获取所有借阅记录 447 * @return 448 */ 449 public static ObservableList<Borrow> getAllBorrowRecord() { 450 final ObservableList<Borrow> borrows = FXCollections.observableArrayList(); 451 try { 452 Connection con = null; //定义一个MYSQL链接对象 453 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 454 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 455 Statement stmt; //创建声明 456 stmt = con.createStatement(); 457 458 Borrow borrow = null; 459 String selectSql = "SELECT * FROM borrow"; 460 ResultSet selectRes = stmt.executeQuery(selectSql); 461 while (selectRes.next()) { 462 borrow = new Borrow(); 463 borrow.setId(selectRes.getString("Id")); 464 borrow.setBookId(selectRes.getString("book_id")+" ("+getBook(selectRes.getString("book_id")).getName()+")"); 465 borrow.setReaderId(selectRes.getString("reader_id")+" ("+getReader(selectRes.getString("reader_id")).getName()+")"); 466 borrow.setBorrowDate(selectRes.getString("borrow_date")); 467 borrow.setBackDate(selectRes.getString("back_date")); 468 borrow.setIsBack(selectRes.getInt("is_back")); 469 borrows.add(borrow); 470 } 471 con.close(); 472 return borrows; 473 } catch (Exception e) { 474 System.out.print("getAllBorrowRecord获取检查----getAllBorrowRecord----MYSQL ERROR:" + e.getMessage()); 475 } 476 return borrows; 477 } 478 479 /** 480 * 获取指定用户的借阅记录 481 * @param id 482 * @return 483 */ 484 public static ObservableList<borrow_record> getBorrowRecord(String id) { 485 final ObservableList<borrow_record> borrows = FXCollections.observableArrayList(); 486 try { 487 Connection con = null; //定义一个MYSQL链接对象 488 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 489 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 490 Statement stmt; //创建声明 491 stmt = con.createStatement(); 492 493 borrow_record borrow = null; 494 String selectSql = "SELECT * FROM borrow where reader_id='"+id+"' and is_back=0"; 495 ResultSet selectRes = stmt.executeQuery(selectSql); 496 while (selectRes.next()) { 497 borrow = new borrow_record(); 498 borrow.setBookId(selectRes.getString("book_id")); 499 borrow.setBookName(getBook(selectRes.getString("book_id")).getName()); 500 borrow.setBorrowDate(selectRes.getString("borrow_date")); 501 borrow.setBackDate(selectRes.getString("back_date")); 502 borrows.add(borrow); 503 } 504 con.close(); 505 return borrows; 506 } catch (Exception e) { 507 System.out.print("getBorrowRecord获取检查----getBorrowRecord----MYSQL ERROR:" + e.getMessage()); 508 } 509 return borrows; 510 } 511 512 public static double backBook(String redaerId, String bookId) { 513 try { 514 Connection con = null; //定义一个MYSQL链接对象 515 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 516 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 517 Statement stmt,stmt1,stmt2; //创建声明 518 stmt = con.createStatement(); 519 stmt1 = con.createStatement(); 520 stmt2 = con.createStatement(); 521 522 //先找到需要还的书籍,计算是否超出应还日期 523 String selectSql = "select back_date from borrow where reader_id ='" + redaerId + "' and book_id='"+bookId+"' and is_back=0"; 524 ResultSet selectResult = stmt1.executeQuery(selectSql); 525 526 String updateSql = "update borrow set is_back=1 where reader_id ='" + redaerId + "' and book_id='"+bookId+"' and is_back=0"; 527 System.out.println(updateSql); 528 int updateRes = stmt.executeUpdate(updateSql); 529 if (updateRes != 0) { 530 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式 531 String todayStr = format.format(new Date());//今天 532 Date today = format.parse(todayStr); 533 534 double allForfeit = 0; 535 536 while (selectResult.next()) { 537 String back_date_str = selectResult.getString("back_date"); 538 //计算超期天数,按照一天0.2元的方式罚款 539 Date back_date = format.parse(back_date_str); 540 int day = (int) ((today.getTime() - back_date.getTime()) / (1000*3600*24)); 541 if (day > 0) { 542 double forfeit = day * 0.2; 543 allForfeit += forfeit; 544 System.out.println("超期书目:" + getBook(bookId).getName() + " 超期天数=" + day + " 罚款金额=" + forfeit); 545 } 546 } 547 BigDecimal bg = new BigDecimal(allForfeit); 548 double myAllForfeit = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); 549 System.out.println("总的罚款金额:" + myAllForfeit); 550 String upSql = "update reader set forfeit=forfeit+"+myAllForfeit+" where Id='"+redaerId+"'"; 551 int rs = stmt2.executeUpdate(upSql); 552 if (rs != 0) { 553 return myAllForfeit; 554 } else { 555 return -1; 556 } 557 // return true; 558 } 559 con.close(); 560 } catch (Exception e) { 561 System.out.print("backBook检查----backBook----MYSQL ERROR:" + e.getMessage()); 562 } 563 return -1; 564 } 565 566 public static ObservableList<Book> getAllLikesBooks(String bookName) { 567 final ObservableList<Book> books = FXCollections.observableArrayList(); 568 try { 569 Connection con = null; //定义一个MYSQL链接对象 570 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 571 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 572 Statement stmt; //创建声明 573 stmt = con.createStatement(); 574 575 Book book = null; 576 String selectSql = "SELECT * FROM book where name like '%"+bookName+"%' or author like'%"+bookName+"%' or publisher like '%"+bookName+"%' or type like '%"+bookName+"%'"; 577 ResultSet selectRes = stmt.executeQuery(selectSql); 578 while (selectRes.next()) { 579 book = new Book(); 580 book.setId(selectRes.getString("Id")); 581 book.setName(selectRes.getString("name")); 582 book.setType(selectRes.getString("type")); 583 book.setAuthor(selectRes.getString("author")); 584 book.setTranslator(selectRes.getString("translator")); 585 book.setPublisher(selectRes.getString("publisher")); 586 book.setPublishTime(selectRes.getDate("publish_time").toString()); 587 book.setStock(selectRes.getInt("stock")); 588 book.setPrice(selectRes.getDouble("price")); 589 590 books.add(book); 591 } 592 con.close(); 593 return books; 594 } catch (Exception e) { 595 System.out.print("books获取检查----getSearchedBooks----MYSQL ERROR:" + e.getMessage()); 596 } 597 return books; 598 } 599 600 public static boolean reBorrow(String id, String bookId, String bDate) { 601 try { 602 Connection con = null; //定义一个MYSQL链接对象 603 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 604 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 605 Statement stmt; //创建声明 606 stmt = con.createStatement(); 607 608 String updateSql = "update borrow set back_date ='"+bDate+"' where book_id='"+bookId+"' and reader_id='"+id+"' and is_back=0"; 609 int selectRes = stmt.executeUpdate(updateSql); 610 if (selectRes != 0) { 611 return true; 612 } 613 con.close(); 614 } catch (Exception e) { 615 System.out.print("reBorrow检查----reBorrow----MYSQL ERROR:" + e.getMessage()); 616 } 617 return false; 618 } 619 620 public static boolean jiaokuan(String id, double jiaokuan) { 621 try { 622 Connection con = null; //定义一个MYSQL链接对象 623 Class.forName("com.mysql.jdbc.Driver").newInstance();//MYSQL驱动 624 con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/tushuguanli_database_test", "root", "root"); //链接本地MYSQL 625 Statement stmt; //创建声明 626 stmt = con.createStatement(); 627 628 String updateSql = "update reader set forfeit ='" + jiaokuan + "' where Id='" + id + "'"; 629 int selectRes = stmt.executeUpdate(updateSql); 630 if (selectRes != 0) { 631 return true; 632 } 633 con.close(); 634 } catch (Exception e) { 635 System.out.print("jiaokuan检查----jiaokuan----MYSQL ERROR:" + e.getMessage()); 636 } 637 return false; 638 } 639 }
8.entity包----实体类
- Book
1 package sample.entity; 2 3 import java.util.Date; 4 5 public class Book { 6 private String Id; 7 private String name; 8 private String type; 9 private String author; 10 private String translator; 11 private String publisher; 12 private String publishTime; 13 private int stock; 14 private double price; 15 16 17 public Book(String id, String name, String type, String author, String translator, String publisher, String publishTime, int stock, double price) { 18 this.Id = id; 19 this.name = name; 20 this.type = type; 21 this.author = author; 22 this.translator = translator; 23 this.publisher = publisher; 24 this.publishTime = publishTime; 25 this.stock = stock; 26 this.price = price; 27 } 28 29 public Book() { 30 31 } 32 33 public String getId() { 34 return Id; 35 } 36 37 public void setId(String id) { 38 Id = id; 39 } 40 41 public String getName() { 42 return name; 43 } 44 45 public void setName(String name) { 46 this.name = name; 47 } 48 49 public String getType() { 50 return type; 51 } 52 53 public void setType(String type) { 54 this.type = type; 55 } 56 57 public String getAuthor() { 58 return author; 59 } 60 61 public void setAuthor(String author) { 62 this.author = author; 63 } 64 65 public String getTranslator() { 66 return translator; 67 } 68 69 public void setTranslator(String translator) { 70 this.translator = translator; 71 } 72 73 public String getPublisher() { 74 return publisher; 75 } 76 77 public void setPublisher(String publisher) { 78 this.publisher = publisher; 79 } 80 81 public String getPublishTime() { 82 return publishTime; 83 } 84 85 public void setPublishTime(String publishTime) { 86 this.publishTime = publishTime; 87 } 88 89 public int getStock() { 90 return stock; 91 } 92 93 public void setStock(int stock) { 94 this.stock = stock; 95 } 96 97 public double getPrice() { 98 return price; 99 } 100 101 public void setPrice(double price) { 102 this.price = price; 103 } 104 }
- Borrow
1 package sample.entity; 2 3 public class Borrow { 4 private String id; 5 private String bookId; 6 private String readerId; 7 private String borrowDate; 8 private String backDate; 9 private int isBack; 10 11 public Borrow(String id, String bookId, String readerId, String borrowDate, String backDate, int isBack) { 12 this.id = id; 13 this.bookId = bookId; 14 this.readerId = readerId; 15 this.borrowDate = borrowDate; 16 this.backDate = backDate; 17 this.isBack = isBack; 18 } 19 20 public Borrow() { 21 22 } 23 24 public String getId() { 25 return id; 26 } 27 28 public void setId(String id) { 29 this.id = id; 30 } 31 32 public String getBookId() { 33 return bookId; 34 } 35 36 public void setBookId(String bookId) { 37 this.bookId = bookId; 38 } 39 40 public String getReaderId() { 41 return readerId; 42 } 43 44 public void setReaderId(String readerId) { 45 this.readerId = readerId; 46 } 47 48 public String getBorrowDate() { 49 return borrowDate; 50 } 51 52 public void setBorrowDate(String borrowDate) { 53 this.borrowDate = borrowDate; 54 } 55 56 public String getBackDate() { 57 return backDate; 58 } 59 60 public void setBackDate(String backDate) { 61 this.backDate = backDate; 62 } 63 64 public int getIsBack() { 65 return isBack; 66 } 67 68 public void setIsBack(int isBack) { 69 this.isBack = isBack; 70 } 71 }
- borrow_record
1 package sample.entity; 2 3 public class borrow_record { 4 private String bookId; 5 private String bookName; 6 private String borrowDate; 7 private String backDate; 8 9 public borrow_record(String bookId, String bookName, String borrowDate, String backDate, int isBack) { 10 this.bookId = bookId; 11 this.bookName = bookName; 12 this.borrowDate = borrowDate; 13 this.backDate = backDate; 14 } 15 16 public borrow_record() { 17 18 } 19 20 public String getBookId() { 21 return bookId; 22 } 23 24 public void setBookId(String bookId) { 25 this.bookId = bookId; 26 } 27 28 public String getBookName() { 29 return bookName; 30 } 31 32 public void setBookName(String bookName) { 33 this.bookName = bookName; 34 } 35 36 public String getBorrowDate() { 37 return borrowDate; 38 } 39 40 public void setBorrowDate(String borrowDate) { 41 this.borrowDate = borrowDate; 42 } 43 44 public String getBackDate() { 45 return backDate; 46 } 47 48 public void setBackDate(String backDate) { 49 this.backDate = backDate; 50 } 51 52 }
- Reader
1 package sample.entity; 2 3 public class Reader { 4 private String id; 5 private String name; 6 private String password; 7 private String type; 8 private String sex; 9 private int max_num; 10 private int days_num; 11 private double forfeit; 12 13 public Reader(String id, String name, String type, String sex, int max_num, int days_num, double forfeit) { 14 this.id = id; 15 this.name = name; 16 this.type = type; 17 this.sex = sex; 18 this.max_num = max_num; 19 this.days_num = days_num; 20 this.forfeit = forfeit; 21 } 22 23 public Reader() { 24 25 } 26 27 28 public String getId() { 29 return id; 30 } 31 32 public void setId(String id) { 33 this.id = id; 34 } 35 36 public String getName() { 37 return name; 38 } 39 40 public void setName(String name) { 41 this.name = name; 42 } 43 44 public String getType() { 45 return type; 46 } 47 48 public void setType(String type) { 49 this.type = type; 50 } 51 52 public String getSex() { 53 return sex; 54 } 55 56 public void setSex(String sex) { 57 this.sex = sex; 58 } 59 60 public int getMax_num() { 61 return max_num; 62 } 63 64 public void setMax_num(int max_num) { 65 this.max_num = max_num; 66 } 67 68 public int getDays_num() { 69 return days_num; 70 } 71 72 public void setDays_num(int days_num) { 73 this.days_num = days_num; 74 } 75 76 public double getForfeit() { 77 return forfeit; 78 } 79 80 public void setForfeit(double forfeit) { 81 this.forfeit = forfeit; 82 } 83 84 public String getPassword() { 85 return password; 86 } 87 88 public void setPassword(String password) { 89 this.password = password; 90 } 91 }
- User
1 package sample.entity; 2 3 public class User { 4 private String id; 5 private String name; 6 private String email; 7 private int isAdmin; 8 9 public String getId() { 10 return id; 11 } 12 13 public void setId(String id) { 14 this.id = id; 15 } 16 17 public String getName() { 18 return name; 19 } 20 21 public void setName(String name) { 22 this.name = name; 23 } 24 25 public String getEmail() { 26 return email; 27 } 28 29 public void setEmail(String email) { 30 this.email = email; 31 } 32 33 public int getIsAdmin() { 34 return isAdmin; 35 } 36 37 public void setIsAdmin(int isAdmin) { 38 this.isAdmin = isAdmin; 39 } 40 }
通过测试暂时还没有找到明显的bug,希望大家留言提出意见!