圖書館管理系統


圖書館管理系統

  1. 未完成部分:
  • [ ] 申請延期
  • [ ] 查看詳情
  • [ ] 個人簽名
  1. 個人覺得有意義的部分

    • “記住密碼”功能
    • 講展示tip變成一個獨立的工具類
    • 使用TreeTable,其歸檔作用用在這里十分合適
  2. 學到的東西

    • RandomAcessFile 就是C的文件指針,超好用,可以同時讀寫還可以跳,除了無法實現刪除,定位修改什么的都十分容易
    • JavaFx的定位系統Point2D
    • JavaFX的控件TreeTable,DatePicker
  3. 部分展示

    • 頭像顯示不正常,因為資源的路徑沒辦法正確編譯進去




  4. 數據存儲部分

    • 數據文件並未加密
    • signedAdmin 存放注冊管理員相關

  • signedUser 存放注冊用戶相關

  • Books 存放所有書籍

  1. 數據存儲部分代碼

    • 用戶存書 User.saveBooks 查看整個文件
    • 用戶取書和驗證是一起進行的,為了減少讀寫文件的次數,所以這里不貼出,感興趣可以看源文件Store.isSigned
    public void saveBooks(){
        File file = new File(fileName);
        try {
            PrintWriter out = new PrintWriter(fileName+".bak");
            Scanner in = new Scanner(file);
            while(in.hasNextLine()){
                String line = in.nextLine();
                ArrayList<String> each = new ArrayList<>();
                each.addAll(Arrays.asList(line.split(" ")));
                if (each.get(0).equals(name)){
                    if (each.indexOf("<Books>")==-1){
                        out.print(line+" ");
                    }else {
                        for (int i = 0; i < each.indexOf("<Books>"); i++) {
                            out.print(each.get(i) + " ");
                        }
                    }
                    out.print("<Books> ");
                    hadBooks.forEach(i -> out.print(i+" "));
                    out.println("</Books>");
                }else out.println(line);
            }
            in.close();
            out.close();
            Files.delete(Paths.get(fileName));
            new File(fileName+".bak").renameTo(file);
        } catch (IOException e) {
            System.out.println("文件寫入出錯");
            e.printStackTrace();
        }
    }
    static void saveBooks() {
        try {
            PrintWriter in = new PrintWriter("Books");
            //in.append(each); Attention:FileWriter.append不是追加內容,是流操作
            Controller.showAll.forEach(in::println);
            in.close();
        } catch (IOException e) {
            System.out.println("文件寫入出錯");
            e.printStackTrace();
        }
    }
    static ArrayList<Book> importBooks() {
        addedBooks = new ArrayList<>();
        ArrayList<Book> allBooks = new ArrayList<>();
        if(!Paths.get("Books").toFile().exists()) {
            return allBooks;
        }
        try {
            Files.readAllLines(Paths.get("Books")).stream().map(line -> {
                String[] each = line.split(",");
                return new Book(each[0], each[1], each[2], parseInt(each[3]));
            }).forEach(allBooks::add);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return allBooks;
    }

Git鏈接:https://github.com/dongmingchao/LibrarySystem
最好clone下來感受,或者在github上有jar包,細節比較多


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM