图书馆管理系统

图书馆管理系统

  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包,细节比较多

posted @ 2017-12-09 20:37  三组组长-董明超  阅读(444)  评论(8编辑  收藏  举报