吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 9743|回复: 23
收起左侧

[Java 转载] 【Java】图书管理系统开发

  [复制链接]
夏沫梦影 发表于 2019-6-30 23:47
本帖最后由 夏沫梦影 于 2019-7-1 10:34 编辑

功能介绍:
        图书管理系统会因为图书的数量、种类、提供的操作等不同而具有不同的复杂度。基本信息的维护、图书借阅、归还及查询等操作通常是图书管理系统的基本功能。在规模较大、业务较多的图书馆还需要图书的库存管理、销售管理等更加复杂的功能。


一、开发环境
          操作系统:Windows
          数据库系统:MySql5.0
          编程语言: Java
          开发工具:MyEclipse9.0

二、数据库设计
          采用的数据库类型为MySql,数据库名为“BookDB”,其中包含了3个表,分别是图书信息表book,读者信息表reader,借阅信息表borrow。



三、系统模块设计:
                (1)MainPro包:主要包括了登录程序、系统主程序、图书和读者信息维护程序、图书借阅管理程序,以及图书和读者信息查询程序等。

                (2)PublicModule包:其中包含了一组供MainPro包中各类使用的公共类 。


这里我犯懒了,没用这个。。。

四、公共模块设计

            DbUtil.java:该类用于完成基本的数据库操作,包括加载数据库驱动,创建数据库连接,执行Sql语句等。其中,其构造方法用于加载数据库驱动程序和创建数据库连接(即打开数据库);用于查询记录的方法为executeQuery();用于插入、删除、修改记录的方法为executeUpdate();用于关闭数据的方法为Close()。

[Java] 纯文本查看 复制代码
package PublicModule;
import java.sql.Connection;
import java.sql.DriverManager;
/**
 * 数据库工具类
 * @author Administrator
 *
 */
public class DbUtil {

        private String dbUrl="jdbc:mysql://localhost:3306/bookdb"; // 数据库连接地址
        private String dbUserName="root"; // 用户名
        private String dbPassword="root"; // 密码
        private String jdbcName="com.mysql.jdbc.Driver"; // 驱动名称
    private static Connection con = null;
        /**
         * 获取数据库连接
         * @return
         * @throws Exception
         */
        public Connection getCon() throws Exception{                
                Class.forName(jdbcName);
                Connection con=DriverManager.getConnection(dbUrl,dbUserName,dbPassword);
                return con;
        }
        
        /**
         * 关闭数据库连接
         * @param con
         * @throws Exception
         */
        public void closeCon() throws Exception{
                if(con!=null){
                        con.close();
                }
        }
        public static void main(String[] args) throws Exception {
                DbUtil dbUtil=new DbUtil();
                try {
                        dbUtil.getCon();
                        System.out.println("数据库连接成功");
                } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }finally {
                        dbUtil.closeCon();
                }
        }
}

        DaoFactory.java

[Java] 纯文本查看 复制代码
package PublicModule;

public class DaoFactory {
        public static IUserDao getIUserDaoInsanse() {
                return new UserDaoImpl();
        }
        public static IBookDao getIBookDaoDAOInsanse() {
                return new BookDaoImpl();
        }
}

     User.java

[Java] 纯文本查看 复制代码
package PublicModule;

/**
 * 用户实体
 * @author Administrator
 *
 */
public class User {
        private String username; // 用户名
        private String password; // 密码
        private String rid; //读者编号
        private String btime; //借阅时间
        private String id; //书号
        public User() {
                super();
                // TODO Auto-generated constructor stub
        }
        public User(String rid) {
                super();
                // TODO Auto-generated constructor stub
                this.rid=rid;
        }
        
        public User(String username, String password) {
                super();
                this.username = username;
                this.password = password;
        }
        public User(String id,String rid,String btime) {
                super();
                this.id=id;
                this.rid=rid;
                this.btime=btime;
                // TODO Auto-generated constructor stub
        }
        public String getUserName() {
                return username;
        }
        public void setUserName(String username) {
                this.username = username;
        }
        public String getPassword() {
                return password;
        }
        public void setPassword(String password) {
                this.password = password;
        }
        public String getrid() {
                return rid;
        }
        public void setrid(String rid) {
                this.rid = rid;
        }
        public String getbtime() {
                return btime;
        }
        public void sebtime(String btime) {
                this.btime = btime;
        }
        public String getid() {
                return id;
        }
        public void setid(String id) {
                this.id = id;
        }
        
}

       IUserDao.java

[Java] 纯文本查看 复制代码
package PublicModule;

import java.sql.Connection;
import java.sql.ResultSet;

public interface IUserDao {

        //登录验证
        public User loginAdmin(Connection con,User user) throws Exception;
        public User loginUser(Connection con,User user) throws Exception;
        //存在查询
        public User CheckExist(Connection con,User user) throws Exception;
        //读者信息查询
        public ResultSet Readlist(Connection con,User user)throws Exception;
        //借阅信息查询
        public ResultSet borrowlist(Connection con,User user)throws Exception;
        //添加借书信息
        public int addborrow(Connection con,User user)throws Exception;
        //添加还书时间
        public int updateback(Connection con,User user)throws Exception;
}

      UserDaoImpl.java

[Java] 纯文本查看 复制代码
package PublicModule;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class UserDaoImpl implements IUserDao {

        /**
         * 登录验证
         * @param con
         * @param user
         * @return
         * @throws Exception
         */
        public User loginAdmin(Connection con,User user) throws Exception{
                User resultUser=null;
                String sql="select * from user where username=? and password=? and is_admin='1'";
                PreparedStatement pstmt=con.prepareStatement(sql);
                pstmt.setString(1, user.getUserName());
                pstmt.setString(2, user.getPassword());
                ResultSet rs=pstmt.executeQuery();
                if(rs.next()){
                        resultUser=new User();
                        resultUser.setUserName(rs.getString("username"));
                        resultUser.setPassword(rs.getString("password"));
                }
                return resultUser;
        }
        public User loginUser(Connection con,User user) throws Exception{
                User resultUser=null;
                String sql="select * from user where username=? and password=? and is_admin='0'";
                PreparedStatement pstmt=con.prepareStatement(sql);
                pstmt.setString(1, user.getUserName());
                pstmt.setString(2, user.getPassword());
                ResultSet rs=pstmt.executeQuery();
                if(rs.next()){
                        resultUser=new User();
                        resultUser.setUserName(rs.getString("username"));
                        resultUser.setPassword(rs.getString("password"));
                }
                return resultUser;
        }
        //存在查询
        public User CheckExist(Connection con,User user) throws Exception{
                User resultUser=null;
                String sql="select * from user where username=? ";
                PreparedStatement pstmt=con.prepareStatement(sql);
                pstmt.setString(1, user.getUserName());
                ResultSet rs=pstmt.executeQuery();
                if(rs.next()){
                        resultUser=new User();
                        resultUser.setUserName(rs.getString("username"));
                }
                return resultUser;
        }
        //读者信息查询
        public ResultSet Readlist(Connection con, User user) throws Exception {
                // TODO Auto-generated method stub
                StringBuffer sb=new StringBuffer("select * from reader where 1=1");
                if(user.getrid()!=null){
                        sb.append(" and id='"+user.getrid()+"'");
                }
                PreparedStatement pstmt=con.prepareStatement(sb.toString());
                return pstmt.executeQuery();
        }
        //借阅信息查询
        public ResultSet borrowlist(Connection con, User user) throws Exception {
                // TODO Auto-generated method stub
                StringBuffer sb=new StringBuffer("select * from borrow where 1=1");
                if(user.getrid()!=null){
                        sb.append(" and reader_id='"+user.getrid()+"' and if_back='0' ");
                }
                PreparedStatement pstmt=con.prepareStatement(sb.toString());
                return pstmt.executeQuery();
        }
        //借阅添加
        @Override
        public int addborrow(Connection con, User user) throws Exception {
                // TODO Auto-generated method stub
                String sql="insert into borrow values(null,?,?,?,null,'0')";
                PreparedStatement pstmt=con.prepareStatement(sql);
                pstmt.setString(1, user.getid());
                pstmt.setString(2, user.getrid());
                pstmt.setString(3, user.getbtime());
                return pstmt.executeUpdate();
        }
        //修改已还
        public int updateback(Connection con,User user) throws Exception {
                // TODO Auto-generated method stub
                String sql="update borrow set back_date=?,if_back='1' where book_id=? and reader_id=? ";
                PreparedStatement pstmt=con.prepareStatement(sql);                
                pstmt.setString(1, user.getbtime());
                pstmt.setString(2, user.getid());
                pstmt.setString(3, user.getrid());
                return pstmt.executeUpdate();
        }
}

     Book.java

[Java] 纯文本查看 复制代码
package PublicModule;

public class Book {
        private String id; //图书编号
        private String bookname; //图书名称
        private String booktype; //图书类型
        private String author; //作者
        private String translator; //译者
        private String publisher; //出版社
        private String publishe_time; //出版时间
        private String price; //价格
        private String stock; //库存
        private String readname;//读者姓名
        private String readtype;//读者类型
        private String sex;//性别
        private String max_num;//最大借阅数量
        private String days_num;//最大节约天数
        //注册用户
        private String username; // 用户名
        private String password; // 密码
        private String is_admin; //权限
        private String rid;//读者编号
        
        
        public Book() {
                super();
                // TODO Auto-generated constructor stub
        }
        public Book(String username,String readname,String readtype,String sex,String max_num,String days_num) {
                super();
                // TODO Auto-generated constructor stub
                this.username=username;
                this.readname=readname;
                this.readtype=readtype;
                this.sex=sex;
                this.max_num=max_num;
                this.days_num=days_num;
        }
        public Book(String username,String password) {
                super();
                // TODO Auto-generated constructor stub
                this.username=username;
                this.password=password;
        }
        public Book(String username,String password,String is_admin) {
                super();
                // TODO Auto-generated constructor stub
                this.username=username;
                this.password=password;
                this.is_admin=is_admin;
        }

        public Book(String id) {
                super();
        this.id=id;
        }
        public Book(String bookname, String author, String publisher,String publishe_time) {
                super();
                this.bookname=bookname;
                this.author=author;
                this.publisher=publisher;
                this.publishe_time=publishe_time;
        }
        
        public Book(String id,String bookname,String booktype,String author,String translator,String publisher,String publishe_time,String price,String stock) {
                super();
                this.id=id;
                this.bookname=bookname;
                this.booktype=booktype;
                this.author=author;
                this.translator=translator;
                this.publisher=publisher;
                this.publishe_time=publishe_time;
                this.price=price;
                this.stock=stock;        
        }
        
        public String getid() {
                return id;
        }
        public void setid(String id) {
                this.id = id;
        }
        public String getbookname() {
                return bookname;
        }
        public void setbookname(String bookname) {
                this.bookname = bookname;
        }
        public String getbooktype(){
                return booktype;
        }
        public void setbooktype(String booktype) {
                this.booktype = booktype;
        }
        public String getauthor() {
                return author;
        }
        public void setauthor(String author) {
                this.author = author;
        }
        public String gettranslator() {
                return translator;
        }
        public void settranslator(String translator) {
                this.translator = translator;
        }
        public String getpublisher() {
                return publisher;
        }
        public void setpublisher(String publisher) {
                this.publisher = publisher;
        }
        public String getpublishe_time() {
                return publishe_time;
        }
        public void setpublishe_time(String publishe_time) {
                this.publishe_time = publishe_time;
        }
        public String getprice() {
                return price;
        }
        public void setprice(String price) {
                this.price = price;
        }
        public String getstock() {
                return stock;
        }
        public void setstock(String stock) {
                this.stock = stock;
        }
        public String getusername() {
                return username;
        }
        public void setusername(String username) {
                this.username = username;
        }
        public String getpassword() {
                return password;
        }
        public void setpassword(String password) {
                this.password = password;
        }
        public String getis_admin() {
                return is_admin;
        }
        public void setis_admin(String is_admin) {
                this.is_admin = is_admin;
        }
        
        public String getreadname() {
                return readname;
        }
        public void setreadname(String readname) {
                this.readname = readname;
        }
        public String getreadtype() {
                return readtype;
        }
        public void setreadtype(String readtype) {
                this.readtype = readtype;
        }
        public String getsex() {
                return sex;
        }
        public void setsex(String sex) {
                this.sex = sex;
        }
        public String getmax_num() {
                return max_num;
        }
        public void setmax_num(String max_num) {
                this.max_num = max_num;
        }
        public String getdays_num() {
                return days_num;
        }
        public void setdays_num(String days_num) {
                this.days_num = days_num;
        }
        public String getrid() {
                return rid;
        }
        public void setrid(String rid) {
                this.rid = rid;
        }


}

     IBookDao.java

[Java] 纯文本查看 复制代码
package PublicModule;

import java.sql.Connection;
import java.sql.ResultSet;

public interface IBookDao {
        //图书添加
        public int add(Connection con,Book book)throws Exception;

        //按图书编号图书所有信息查询
        public ResultSet list(Connection con,Book book)throws Exception;
        
        //图书信息删除
        public int delete(Connection con,String id)throws Exception;
        
        //图书信息修改
        public int update(Connection con,Book book)throws Exception;
        
        //注册用户
        public int RegistUser(Connection con,Book book)throws Exception;
        //修改密码
        public int updatePassword(Connection con,Book book)throws Exception;
        //按条件查询所有图书
        public ResultSet list1(Connection con,Book book)throws Exception;
        //添加读者
        public int AddReader(Connection con,Book book)throws Exception;
}

          IBookDao.java

[Java] 纯文本查看 复制代码
package PublicModule;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class BookDaoImpl implements IBookDao {
        //图书添加
        @Override
        public int add(Connection con, Book book) throws Exception {
                // TODO Auto-generated method stub
                String sql="insert into book values(?,?,?,?,?,?,?,?,?)";
                PreparedStatement pstmt=con.prepareStatement(sql);
                pstmt.setString(1, book.getid());
                pstmt.setString(2, book.getbookname());
                pstmt.setString(3, book.getbooktype());
                pstmt.setString(4, book.getauthor());
                pstmt.setString(5, book.gettranslator());
                pstmt.setString(6, book.getpublisher());
                pstmt.setString(7, book.getpublishe_time());
                pstmt.setString(8, book.getprice());
                pstmt.setString(9, book.getstock());
                return pstmt.executeUpdate();
        }

        //注册用户
        public int RegistUser(Connection con, Book book) throws Exception {
                // TODO Auto-generated method stub
                String sql="insert into user values(null,?,?,?)";
                PreparedStatement pstmt=con.prepareStatement(sql);
                pstmt.setString(1, book.getusername());
                pstmt.setString(2, book.getpassword());
                pstmt.setString(3, book.getis_admin());
                return pstmt.executeUpdate();
        }
        //添加读者信息
        public int AddReader(Connection con, Book book) throws Exception {
                // TODO Auto-generated method stub
                String sql="insert into reader values(?,?,?,?,?,?)";
                PreparedStatement pstmt=con.prepareStatement(sql);
                pstmt.setString(1, book.getusername());
                pstmt.setString(2, book.getreadname());
                pstmt.setString(3, book.getreadtype());
                pstmt.setString(4, book.getsex());
                pstmt.setString(5, book.getmax_num());
                pstmt.setString(6, book.getdays_num());
                return pstmt.executeUpdate();
        }
        
        
        //修改密码
        public int updatePassword(Connection con, Book book) throws Exception {
                // TODO Auto-generated method stub
                String sql="update user set password=? where username=?";
                PreparedStatement pstmt=con.prepareStatement(sql);
                pstmt.setString(1, book.getpassword());
                pstmt.setString(2, book.getusername());
                return pstmt.executeUpdate();
        }
        //图书信息查询(所有)
        @Override
        public ResultSet list(Connection con, Book book) throws Exception {
                // TODO Auto-generated method stub
                StringBuffer sb=new StringBuffer("select * from book  where 1=1");
                if(book.getid()!=null){
                        sb.append(" and id='"+book.getid()+"'");
                }
                PreparedStatement pstmt=con.prepareStatement(sb.toString());
                return pstmt.executeQuery();
        }        
        //按条件查询所有图书信息
        public ResultSet list1(Connection con, Book book) throws Exception {
                // TODO Auto-generated method stub
                StringBuffer sb=new StringBuffer("select * from book where 1=1");
                if(book.getbookname()!=null){
                        sb.append(" and bookname like '"+book.getbookname()+"'");
                }
                if(book.getauthor()!=null){
                        sb.append(" and author like '"+book.getauthor()+"'");
                }
                if(book.getpublisher()!=null){
                        sb.append(" and publisher = '"+book.getpublisher()+"'");
                }
                if(book.getpublishe_time()!=null){
                        sb.append(" and publish_time = '"+book.getpublishe_time()+"'");
                }
                PreparedStatement pstmt=con.prepareStatement(sb.toString());
                return pstmt.executeQuery();
        }
        //图书信息删除
        @Override
        public int delete(Connection con, String id) throws Exception {
                // TODO Auto-generated method stub
                String sql="delete from book where id=?";
                PreparedStatement pstmt=con.prepareStatement(sql);
                pstmt.setString(1, id);
                return pstmt.executeUpdate();
        }
        //图书信息修改
        @Override
        public int update(Connection con, Book book) throws Exception {
                // TODO Auto-generated method stub
                String sql="update book set bookname=?,booktype=?,author=?,translator=?,publisher=?,publish_time=?,price=?,stock=? where id=? ";
                PreparedStatement pstmt=con.prepareStatement(sql);
                pstmt.setString(1, book.getbookname());
                pstmt.setString(2, book.getbooktype());
                pstmt.setString(3, book.getauthor());
                pstmt.setString(4, book.gettranslator());
                pstmt.setString(5, book.getpublisher());
                pstmt.setString(6, book.getpublishe_time());
                pstmt.setString(7, book.getprice());
                pstmt.setString(8, book.getstock());
                pstmt.setString(9, book.getid());
                return pstmt.executeUpdate();
        }

}

五、主模块设计
     Login.java登录模块用于实现用户登录功能,也是进入系统的入口。进行系统登录时,需要输入用户名和密码,系统会查询数据库中的user表,验证用户名和密码是否正确。


注册按钮相关代码:

[Java] 纯文本查看 复制代码
private void jLabel4MouseClicked(java.awt.event.MouseEvent evt) {
                // TODO add your handling code here:
                new Regist().setVisible(true);
                dispose();
        }

登录按钮相关代码:

[Java] 纯文本查看 复制代码
private DbUtil dbUtil = new DbUtil();
        private void BtnLoginActionPerformed(java.awt.event.ActionEvent evt) {
                // TODO add your handling code here:
                String username=txtname.getText();
                String password=String.valueOf(txtpass.getPassword());
                Uname=txtname.getText();
                User user=new User(username, password);
                Connection con=null;
                try {
                        con=dbUtil.getCon();
                        User currentAdmin = DaoFactory.getIUserDaoInsanse().loginAdmin(con, user);//userDao.login(con, user);
                        User currentUser = DaoFactory.getIUserDaoInsanse().loginUser(con, user);//userDao.login(con, user);
                        if (username.length()!=0 && password.length()!=0) {
                                if(rdbtnAdmin.isSelected() ) {
                                        if(currentAdmin!= null){
                                                new ShowMain().setVisible(true);
                                                dispose();
                                                }
                                                else{
                                                        JOptionPane.showMessageDialog(null, "账户或密码错误!", "提示", JOptionPane.ERROR_MESSAGE);
                                                }                                        
                                }
                                if(rdbtnUser.isSelected()) {
                                        if(currentUser!=null){
                                                dispose();
                                                ShowMain USER=new ShowMain();
                                                USER.jMenu1.setVisible(false);
                                                USER.jMenu2.setVisible(false);
                                                USER.setVisible(true);
                                                }
                                                else{
                                                        JOptionPane.showMessageDialog(null, "账户或密码错误!", "提示", JOptionPane.ERROR_MESSAGE);
                                                }        
                                }
                                if(!rdbtnAdmin.isSelected()&&!rdbtnUser.isSelected()){
                                        JOptionPane.showMessageDialog(null, "权限未选择!", "提示", JOptionPane.ERROR_MESSAGE);
                                }
                        } else {
                                JOptionPane.showMessageDialog(null, "账户或密码不能为空!", "提示", JOptionPane.ERROR_MESSAGE);
                        }
                } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        JOptionPane.showMessageDialog(null, "登陆失败!", "提示", JOptionPane.ERROR_MESSAGE);
                }finally{
                        try {
                                dbUtil.closeCon();
                        } catch (Exception e) {
                                e.printStackTrace();
                        }
                }

        }
        
        public void resetValueActionPerformed(ActionEvent evt) {
                txtname.setText("");
                txtpass.setText("");
        }

窗口初始化:

[Java] 纯文本查看 复制代码
/** Creates new form Login */
        public Login() {
                initComponents();
                addRdbtn();
                int width = Toolkit.getDefaultToolkit().getScreenSize().width;
                int height = Toolkit.getDefaultToolkit().getScreenSize().height;
                // 定义窗体的宽高
                int windowsWedth = 400;
                int windowsHeight = 300;
                this.setBounds((width - windowsWedth) / 2,
                                (height - windowsHeight) / 2, windowsWedth, windowsHeight);
        }

        public void addRdbtn() {

                ButtonGroup grout = new ButtonGroup();//创建一个组 把两个对象合并为组
                grout.add(rdbtnAdmin);
                grout.add(rdbtnUser);
                rdbtnAdmin.setContentAreaFilled(false);//设置组件透明
                rdbtnUser.setContentAreaFilled(false);

        }

注册窗体:

          这里可以注册用户及录入读者信息。


注册按钮相关代码:

[Java] 纯文本查看 复制代码
private DbUtil dbUtil = new DbUtil();
        private DbUtil dbUtil1 = new DbUtil();
        private DbUtil dbUtil2 = new DbUtil();
        private DbUtil dbUtil3 = new DbUtil();
        private void btnRegistActionPerformed(java.awt.event.ActionEvent evt) {
                // TODO add your handling code here:
                //注册账号
                String username = txtname.getText();
                String password = String.valueOf(this.txtpass.getPassword());
                String is_admin = "";
                String readname=Readname.getText();
                String readtype="";
                String sex="";
                String max_num="";
                String days_num="";
                if (rdbtnAdmin.isSelected()) {
                        is_admin = "1";
                }
                if (rdbtnUser.isSelected()) {
                        is_admin = "0";
                }
                if(rdbtnmale.isSelected()){
                        sex="male";
                }
                if(rdbtnfemale.isSelected()){
                        sex="female";
                }
                if(rdbtnmember.isSelected()){
                        readtype="member";
                        max_num="5";
                        days_num="5";
                }
                if(rdbtvip.isSelected()){
                        readtype="vip";
                        max_num="10";
                        days_num="30";
                }
                
                User user = new User(username, password);
                Book book1 = new Book(username, readname, readtype, sex, max_num, days_num);
                Connection con = null;
                Connection con2 = null;
                Connection con3 = null;
                if (username.length() != 0 && password.length() != 0 && readname.length() != 0 && readtype.length() != 0 && sex.length() != 0) {
                        try {
                                con = dbUtil.getCon();
                                User CheckExist = DaoFactory.getIUserDaoInsanse().CheckExist(
                                                con, user);//userDao.login(con, user);
                                if (CheckExist != null) {
                                        JOptionPane.showMessageDialog(null, "该用户已存在!", "提示",
                                                        JOptionPane.ERROR_MESSAGE);
                                        return;
                                } else {
                                        if (rdbtnAdmin.isSelected()) {
                                                Book book = new Book(username, password, is_admin);
                                                Connection con1 = null;
                                                try {
                                                        con1 = dbUtil1.getCon();
                                                        int addNum = DaoFactory.getIBookDaoDAOInsanse()
                                                                        .RegistUser(con1, book);//bookDao.add(con, book);
                                                        if (addNum == 1) {
                                                                JOptionPane.showMessageDialog(null, "管理员注册成功!",
                                                                                "提示", JOptionPane.INFORMATION_MESSAGE);
                                                        } else {
                                                                JOptionPane.showMessageDialog(null, "管理员注册失败!",
                                                                                "提示", JOptionPane.ERROR_MESSAGE);
                                                        }
                                                } catch (Exception e2) {
                                                        e2.printStackTrace();
                                                        JOptionPane.showMessageDialog(null, "注册失败!", "提示",
                                                                        JOptionPane.ERROR_MESSAGE);
                                                } finally {
                                                        try {
                                                                dbUtil1.closeCon();
                                                        } catch (Exception e2) {
                                                                // TODO Auto-generated catch block
                                                                e2.printStackTrace();
                                                        }
                                                }
                                                //添加读者信息
                                                if (rdbtnmember.isSelected()) {                
                                                        try {
                                                                con2 = dbUtil2.getCon();
                                                                int addNum = DaoFactory.getIBookDaoDAOInsanse().AddReader(con2, book1);//bookDao.add(con, book);
                                                                if (addNum == 1) {
                                                                        JOptionPane.showMessageDialog(null, "读者添加成功!", "提示",
                                                                                        JOptionPane.INFORMATION_MESSAGE);
                                                                        dispose();
                                                                        new Login().setVisible(true);
                                                                } else {
                                                                        JOptionPane.showMessageDialog(null, "读者添加失败!", "提示",
                                                                                        JOptionPane.ERROR_MESSAGE);
                                                                }
                                                        } catch (Exception e2) {
                                                                e2.printStackTrace();
                                                                JOptionPane.showMessageDialog(null, "读者添加失败!", "提示",
                                                                                JOptionPane.ERROR_MESSAGE);
                                                                dispose();
                                                        } finally {
                                                                try {
                                                                        dbUtil2.closeCon();
                                                                } catch (Exception e2) {
                                                                        // TODO Auto-generated catch block
                                                                        e2.printStackTrace();
                                                                }
                                                        }
                                                }                                
                                                if (rdbtvip.isSelected()) {
                                                        try {
                                                                con3 = dbUtil3.getCon();
                                                                int addNum = DaoFactory.getIBookDaoDAOInsanse().AddReader(con3, book1);//bookDao.add(con, book);
                                                                if (addNum == 1) {
                                                                        JOptionPane.showMessageDialog(null, "读者添加成功!", "提示",
                                                                                        JOptionPane.INFORMATION_MESSAGE);
                                                                        dispose();
                                                                        new Login().setVisible(true);
                                                                } else {
                                                                        JOptionPane.showMessageDialog(null, "读者添加失败!", "提示",
                                                                                        JOptionPane.ERROR_MESSAGE);                        
                                                                }
                                                        } catch (Exception e2) {
                                                                e2.printStackTrace();
                                                                JOptionPane.showMessageDialog(null, "读者添加失败!", "提示",
                                                                                JOptionPane.ERROR_MESSAGE);
                                                        } finally {
                                                                try {
                                                                        dbUtil3.closeCon();
                                                                } catch (Exception e2) {
                                                                        // TODO Auto-generated catch block
                                                                        e2.printStackTrace();
                                                                }
                                                        }
                                                }
                                        }
                                        if (rdbtnUser.isSelected()) {
                                                Book book = new Book(username, password, is_admin);
                                                Connection con1 = null;
                                                try {
                                                        con1 = dbUtil1.getCon();
                                                        int addNum = DaoFactory.getIBookDaoDAOInsanse()
                                                                        .RegistUser(con1, book);//bookDao.add(con, book);
                                                        if (addNum == 1) {
                                                                JOptionPane.showMessageDialog(null, "用户注册成功!",
                                                                                "提示", JOptionPane.INFORMATION_MESSAGE);
                                                        } else {
                                                                JOptionPane.showMessageDialog(null, "用户注册失败!",
                                                                                "提示", JOptionPane.ERROR_MESSAGE);
                                                        }
                                                } catch (Exception e2) {
                                                        e2.printStackTrace();
                                                        JOptionPane.showMessageDialog(null, "注册失败!", "提示",
                                                                        JOptionPane.ERROR_MESSAGE);
                                                } finally {
                                                        try {
                                                                dbUtil1.closeCon();
                                                        } catch (Exception e2) {
                                                                // TODO Auto-generated catch block
                                                                e2.printStackTrace();
                                                        }
                                                }
                                                //添加读者信息
                                                if (rdbtnmember.isSelected()) {                
                                                        try {
                                                                con2 = dbUtil2.getCon();
                                                                int addNum = DaoFactory.getIBookDaoDAOInsanse().AddReader(con2, book1);//bookDao.add(con, book);
                                                                if (addNum == 1) {
                                                                        JOptionPane.showMessageDialog(null, "读者添加成功!", "提示",
                                                                                        JOptionPane.INFORMATION_MESSAGE);
                                                                        dispose();
                                                                        new Login().setVisible(true);
                                                                } else {
                                                                        JOptionPane.showMessageDialog(null, "读者添加失败!", "提示",
                                                                                        JOptionPane.ERROR_MESSAGE);
                                                                }
                                                        } catch (Exception e2) {
                                                                e2.printStackTrace();
                                                                JOptionPane.showMessageDialog(null, "读者添加失败!", "提示",
                                                                                JOptionPane.ERROR_MESSAGE);
                                                        } finally {
                                                                try {
                                                                        dbUtil2.closeCon();
                                                                } catch (Exception e2) {
                                                                        // TODO Auto-generated catch block
                                                                        e2.printStackTrace();
                                                                }
                                                        }
                                                }                                
                                                if (rdbtvip.isSelected()) {
                                                        try {
                                                                con3 = dbUtil3.getCon();
                                                                int addNum = DaoFactory.getIBookDaoDAOInsanse().AddReader(con3, book1);//bookDao.add(con, book);
                                                                if (addNum == 1) {
                                                                        JOptionPane.showMessageDialog(null, "读者添加成功!", "提示",
                                                                                        JOptionPane.INFORMATION_MESSAGE);
                                                                        dispose();
                                                                        new Login().setVisible(true);
                                                                } else {
                                                                        JOptionPane.showMessageDialog(null, "读者添加失败!", "提示",
                                                                                        JOptionPane.ERROR_MESSAGE);
                                                                }
                                                        } catch (Exception e2) {
                                                                e2.printStackTrace();
                                                                JOptionPane.showMessageDialog(null, "读者添加失败!", "提示",
                                                                                JOptionPane.ERROR_MESSAGE);
                                                        } finally {
                                                                try {
                                                                        dbUtil3.closeCon();
                                                                } catch (Exception e2) {
                                                                        // TODO Auto-generated catch block
                                                                        e2.printStackTrace();
                                                                }
                                                        }
                                                }
                                        }
                                        if (!rdbtnAdmin.isSelected() && !rdbtnUser.isSelected()) {
                                                JOptionPane.showMessageDialog(null, "权限未选择!", "提示",
                                                                JOptionPane.ERROR_MESSAGE);
                                        }
                                }
                        } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                                JOptionPane.showMessageDialog(null, "注册失败");
                        } finally {
                                try {
                                        dbUtil.closeCon();
                                } catch (Exception e) {
                                        e.printStackTrace();
                                }
                        }
                } else {
                        JOptionPane.showMessageDialog(null, "请输入完整", "提示",
                                        JOptionPane.ERROR_MESSAGE);
                        return;
                }
                
        }

初始化窗体:

[Java] 纯文本查看 复制代码
/** Creates new form Regist */
        public Regist() {
                initComponents();
                buttonGroup1.add(rdbtnAdmin);//创建一个组 把两个对象合并为组
                buttonGroup1.add(rdbtnUser);
                rdbtnAdmin.setContentAreaFilled(false);//设置组件透明
                rdbtnUser.setContentAreaFilled(false);
                buttonGroup2.add(rdbtnfemale);
                buttonGroup2.add(rdbtnmale);
                rdbtnfemale.setContentAreaFilled(false);//设置组件透明
                rdbtnmale.setContentAreaFilled(false);
                buttonGroup3.add(rdbtnmember);
                buttonGroup3.add(rdbtvip);
                rdbtnmember.setContentAreaFilled(false);//设置组件透明
                rdbtvip.setContentAreaFilled(false);
                int width = Toolkit.getDefaultToolkit().getScreenSize().width;
                int height = Toolkit.getDefaultToolkit().getScreenSize().height;
                // 定义窗体的宽高
                int windowsWedth = 420;
                int windowsHeight = 320;
                this.setBounds((width - windowsWedth) / 2,
                                (height - windowsHeight) / 2, windowsWedth, windowsHeight);
        }

ShowMain.java:

          成功登录系统后即进入系统的主界面。需要注意的是,系统会根据登录的用户类型(普通用户和管理员),决定“系统维护”和“借阅管理”菜单是否可用。


初始化窗体:

[Java] 纯文本查看 复制代码
/** Creates new form ShowMain */
        public ShowMain() {
                initComponents();
                int width = Toolkit.getDefaultToolkit().getScreenSize().width;
                int height = Toolkit.getDefaultToolkit().getScreenSize().height;
                // 定义窗体的宽高
                int windowsWedth = 800;
                int windowsHeight = 600;
                this.setBounds((width - windowsWedth) / 2,
                                (height - windowsHeight) / 2, windowsWedth, windowsHeight);
        }

基础维护----添加图书:

            该模块用于输入图书信息。其设计要点主要有:① 为确保图书编号的唯一性,图书编号不能重复;② 当出版时间、定价、库存数量无效时,可通过捕捉异常来处理;③ 正常输入并保存记录后,要给出提示信息;④ 输入并保存一个记录后,应清空文本框,让用户能够继续输入下一个记录。

           ReaderAdd.java  ReaderUpdate.java ReaderDelete.java ReaderQuery.java
           读者信息的录入、修改、删除和查询模块与图书相关模块在功能和设计上完全类似 。



初始化窗体:

[Java] 纯文本查看 复制代码
/** Creates new form BookAdd */
        public BookAdd() {
                initComponents();
                int width = Toolkit.getDefaultToolkit().getScreenSize().width;
                int height = Toolkit.getDefaultToolkit().getScreenSize().height;
                // 定义窗体的宽高
                int windowsWedth = 600;
                int windowsHeight = 300;
                this.setBounds((width - windowsWedth) / 2,
                                (height - windowsHeight) / 2, windowsWedth, windowsHeight);
        }

保存,取消及初始化:

[Java] 纯文本查看 复制代码
        private DbUtil dbUtil = new DbUtil();
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
                // TODO add your handling code here:
                String id = ID.getText();
                String bookname = Bookname.getText();
                String booktype = (String) Booktype.getSelectedItem();
                String author = Author.getText();
                String translator = Translator.getText();
                String publisher = Publisher.getText();
                String publishe_time = Publish_time.getText();
                String price = Price.getText();
                String stock = Stock.getText();
                if (id.length() == 0) {
                        JOptionPane.showMessageDialog(null, "图书编号不能为空!", "提示",
                                        JOptionPane.ERROR_MESSAGE);
                        return;
                }
                Book book = new Book(id, bookname, booktype, author, translator,
                                publisher, publishe_time, price, stock);
                Connection con = null;
                try {
                        con = dbUtil.getCon();
                        int addNum = DaoFactory.getIBookDaoDAOInsanse().add(con, book);//bookDao.add(con, book);
                        if (addNum == 1) {
                                JOptionPane.showMessageDialog(null, "图书添加成功!", "提示",
                                                JOptionPane.INFORMATION_MESSAGE);
                                resetValue();
                        } else {
                                JOptionPane.showMessageDialog(null, "图书添加失败!", "提示",
                                                JOptionPane.ERROR_MESSAGE);
                        }
                } catch (Exception e2) {
                        e2.printStackTrace();
                        JOptionPane.showMessageDialog(null, "图书添加失败!", "提示",
                                        JOptionPane.ERROR_MESSAGE);
                } finally {
                        try {
                                dbUtil.closeCon();
                        } catch (Exception e2) {
                                // TODO Auto-generated catch block
                                e2.printStackTrace();
                        }
                }
        }

        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
                // TODO add your handling code here:
                dispose();
        }

        private void resetValue() {
                ID.setText("");
                Bookname.setText("");
                Author.setText("");
                Translator.setText("");
                Publisher.setText("");
                Publish_time.setText("");
                Price.setText("");
                Stock.setText("");
                if (Booktype.getItemCount() > 0) {
                        Booktype.setSelectedItem(0);
                }
        }

基础维护----删除图书:

             该模块用于根据图书编号删除所选图书。执行删除操作时,用户应首先在“图书编号”编辑框中输入要删除的图书编号,然后单击“查询”按钮,调出该图书的相关信息,供用户进行确认。如果确认无误,即可单击“删除”按钮删除所选图书。


初始化:

[Java] 纯文本查看 复制代码
/** Creates new form BookDelete */
        public BookDelete() {
                initComponents();
                int width = Toolkit.getDefaultToolkit().getScreenSize().width;
                int height = Toolkit.getDefaultToolkit().getScreenSize().height;
                // 定义窗体的宽高
                int windowsWedth = 600;
                int windowsHeight = 320;
                this.setBounds((width - windowsWedth) / 2,
                                (height - windowsHeight) / 2, windowsWedth, windowsHeight);
        }

查询:

[Java] 纯文本查看 复制代码
private DbUtil dbUtil = new DbUtil();
        private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
                // TODO add your handling code here:
                String id = this.id1.getText();
                Book book = new Book(id);
                Connection con = null;
                if (id.length() != 0) {
                        try {
                                con = dbUtil.getCon();
                                ResultSet rs = DaoFactory.getIBookDaoDAOInsanse().list(con,
                                                book);//bookDao.list(con, book);
                                while (rs.next()) {
                                        ID.setText(rs.getString("id"));
                                        Bookname.setText(rs.getString("bookname"));
                                        Booktype.setSelectedItem(rs.getString("booktype"));
                                        Author.setText(rs.getString("author"));
                                        Translator.setText(rs.getString("translator"));
                                        Publisher.setText(rs.getString("publisher"));
                                        Publish_time.setText(rs.getString("publish_time"));
                                        Price.setText(rs.getString("price"));
                                        Stock.setText(rs.getString("stock"));
                                        ID.setEnabled(false);
                                }
                        } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        } finally {
                                try {
                                        dbUtil.closeCon();
                                } catch (Exception e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }
                        }
                } else {
                        JOptionPane.showMessageDialog(null, "请输入要查询的图书编号!", "提示",
                                        JOptionPane.ERROR_MESSAGE);
                }
        }

删除及初始化:

[Java] 纯文本查看 复制代码
private DbUtil dbUtil1 = new DbUtil();
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
                // TODO add your handling code here:
                String id = this.id1.getText();
                if (id.length() == 0) {
                        JOptionPane.showMessageDialog(null, "请先查询!", "提示",
                                        JOptionPane.ERROR_MESSAGE);
                        return;
                }
                int n = JOptionPane.showConfirmDialog(null, "确定要删除这本图书的信息嘛?", "标题",
                                JOptionPane.YES_NO_OPTION);
                if (n == 0) {
                        Connection con = null;
                        try {
                                con = dbUtil1.getCon();
                                int deleteNum = DaoFactory.getIBookDaoDAOInsanse().delete(con,
                                                id);//bookDao.delete(con, id);
                                if (deleteNum == 1) {
                                        JOptionPane.showMessageDialog(null, "删除成功!", "提示",
                                                        JOptionPane.INFORMATION_MESSAGE);
                                        this.resetValue();
                                } else {
                                        JOptionPane.showMessageDialog(null, "删除失败!", "提示",
                                                        JOptionPane.ERROR_MESSAGE);
                                }
                        } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                                JOptionPane.showMessageDialog(null, "删除失败!", "提示",
                                                JOptionPane.ERROR_MESSAGE);
                        } finally {
                                try {
                                        dbUtil1.closeCon();
                                } catch (Exception e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }
                        }
                }
        }

        private void resetValue() {
                ID.setText("");
                Bookname.setText("");
                Author.setText("");
                Translator.setText("");
                Publisher.setText("");
                Publish_time.setText("");
                Price.setText("");
                Stock.setText("");
                if (Booktype.getItemCount() > 0) {
                        Booktype.setSelectedItem(0);
                }
        }

基础维护----修改图书:

             该模块用来修改图书信息。使用该功能模块时,用户应首先在“图书编号”编辑框中输入要修改图书的图书编号,然后单击“查询”按钮,将所选图书的其他数据显示出来,接下来就可以对这些数据进行修改了。


初始化:

[Java] 纯文本查看 复制代码
public class BookUpdate extends javax.swing.JFrame {

        /** Creates new form BookUpdate */
        public BookUpdate() {
                initComponents();
                int width = Toolkit.getDefaultToolkit().getScreenSize().width;
                int height = Toolkit.getDefaultToolkit().getScreenSize().height;
                // 定义窗体的宽高
                int windowsWedth = 600;
                int windowsHeight = 320;
                this.setBounds((width - windowsWedth) / 2,
                                (height - windowsHeight) / 2, windowsWedth, windowsHeight);
        }

查询:

[Java] 纯文本查看 复制代码
private DbUtil dbUtil = new DbUtil();
        private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
                // TODO add your handling code here:
                String id = this.id1.getText();
                Book book = new Book(id);
                Connection con = null;
                if (id.length() != 0) {
                        try {
                                con = dbUtil.getCon();
                                ResultSet rs = DaoFactory.getIBookDaoDAOInsanse().list(con,
                                                book);//bookDao.list(con, book);
                                while (rs.next()) {
                                        ID.setText(rs.getString("id"));
                                        Bookname.setText(rs.getString("bookname"));
                                        Booktype.setSelectedItem(rs.getString("booktype"));
                                        Author.setText(rs.getString("author"));
                                        Translator.setText(rs.getString("translator"));
                                        Publisher.setText(rs.getString("publisher"));
                                        Publish_time.setText(rs.getString("publish_time"));
                                        Price.setText(rs.getString("price"));
                                        Stock.setText(rs.getString("stock"));
                                        ID.setEnabled(false);
                                }
                        } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        } finally {
                                try {
                                        dbUtil.closeCon();
                                } catch (Exception e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }
                        }
                } else {
                        JOptionPane.showMessageDialog(null, "请输入要查询的图书编号!", "提示",
                                        JOptionPane.ERROR_MESSAGE);
                }
        }

修改及初始化:

[Java] 纯文本查看 复制代码
private DbUtil dbUtil1 = new DbUtil();
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
                // TODO add your handling code here:
                String id = this.id1.getText();
                String bookname = Bookname.getText();
                String booktype = (String) Booktype.getSelectedItem();
                String author = Author.getText();
                String translator = Translator.getText();
                String publisher = Publisher.getText();
                String publishe_time = Publish_time.getText();
                String price = Price.getText();
                String stock = Stock.getText();
                Book book = new Book(id, bookname, booktype, author, translator,
                                publisher, publishe_time, price, stock);
                Connection con1 = null;
                if (id.length() == 0) {
                        JOptionPane.showMessageDialog(null, "请先查询!", "提示",
                                        JOptionPane.ERROR_MESSAGE);
                        return;
                }
                try {
                        con1 = dbUtil1.getCon();
                        int addNum = DaoFactory.getIBookDaoDAOInsanse().update(con1, book);//bookDao.add(con, book);
                        if (addNum == 1) {
                                JOptionPane.showMessageDialog(null, "图书信息修改成功!", "提示",
                                                JOptionPane.INFORMATION_MESSAGE);
                                resetValue();
                        } else {
                                JOptionPane.showMessageDialog(null, "图书信息修改失败!", "提示",
                                                JOptionPane.ERROR_MESSAGE);
                        }
                } catch (Exception e2) {
                        e2.printStackTrace();
                        JOptionPane.showMessageDialog(null, "图书信息修改失败!", "提示",
                                        JOptionPane.ERROR_MESSAGE);
                } finally {
                        try {
                                dbUtil1.closeCon();
                        } catch (Exception e2) {
                                // TODO Auto-generated catch block
                                e2.printStackTrace();
                        }
                }
        }

        private void resetValue() {
                ID.setText("");
                Bookname.setText("");
                Author.setText("");
                Translator.setText("");
                Publisher.setText("");
                Publish_time.setText("");
                Price.setText("");
                Stock.setText("");
                if (Booktype.getItemCount() != 0) {
                        Booktype.setSelectedItem(0);
                }
        }

借阅管理----借阅图书:

             该模块用于执行借书操作。用户应首先输入图书编号和读者编号,然后做如下几个判断:① 所选图书是否存在,是否有库存;② 读者是否借过此书且未归还;③ 读者当前已借且未归还的图书是否超出了允许其最大可借数。如果上述条件都满足,“借出”按钮才有效,单击之可由程序填写借*屏蔽的关键字*录 。


初始化:

[Java] 纯文本查看 复制代码
/** Creates new form Borrow */
        public Borrow() {
                initComponents();
                int width = Toolkit.getDefaultToolkit().getScreenSize().width;
                int height = Toolkit.getDefaultToolkit().getScreenSize().height;
                // 定义窗体的宽高
                int windowsWedth = 600;
                int windowsHeight = 500;
                this.setBounds((width - windowsWedth) / 2,
                                (height - windowsHeight) / 2, windowsWedth, windowsHeight);
        }

查询:

[Java] 纯文本查看 复制代码
private DbUtil dbUtil = new DbUtil();
        private DbUtil dbUtil1 = new DbUtil();
        private DbUtil dbUtil2 = new DbUtil();
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
                // TODO add your handling code here:
                String id = this.ID.getText();
                String rid = this.RID.getText();
                int a = 0;
                int count = 0;
                brnum.setText(String.valueOf(count));
                Book book = new Book(id);
                User user = new User(rid);
                Connection con = null;
                Connection con1 = null;
                Connection con2 = null;
                //图书信息
                if (id.length() != 0) {
                        try {
                                con = dbUtil.getCon();
                                ResultSet rs = DaoFactory.getIBookDaoDAOInsanse().list(con,
                                                book);//bookDao.list(con, book);
                                while (rs.next()) {
                                        Bookname.setText(rs.getString("bookname"));
                                        Author.setText(rs.getString("author"));
                                        Publisher.setText(rs.getString("publisher"));
                                        Publish_time.setText(rs.getString("publish_time"));
                                        Price.setText(rs.getString("price"));
                                        Stock.setText(rs.getString("stock"));
                                }
                        } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        } finally {
                                try {
                                        dbUtil.closeCon();
                                } catch (Exception e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }
                        }
                } else {
                        JOptionPane.showMessageDialog(null, "请输入要查询的图书编号!", "提示",
                                        JOptionPane.ERROR_MESSAGE);
                }
                //读者信息
                if (rid.length() != 0) {
                        try {
                                con1 = dbUtil1.getCon();
                                ResultSet rs = DaoFactory.getIUserDaoInsanse().Readlist(con1,
                                                user);
                                while (rs.next()) {
                                        Readname.setText(rs.getString("readename"));
                                        Readtype.setText(rs.getString("readetype"));
                                        Max_num.setText(rs.getString("max_num"));
                                        Days_num.setText(rs.getString("days_num"));
                                        a = Integer.parseInt(rs.getString("max_num"));
                                }
                        } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        } finally {
                                try {
                                        dbUtil1.closeCon();
                                } catch (Exception e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }
                        }
                        //借阅数量
                        try {
                                con2 = dbUtil2.getCon();
                                ResultSet rs = DaoFactory.getIUserDaoInsanse().borrowlist(con2,
                                                user);
                                while (rs.next()) {
                                        count = rs.getRow();
                                        brnum.setText(String.valueOf(count));
                                }
                        } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        } finally {
                                try {
                                        dbUtil2.closeCon();
                                } catch (Exception e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }
                        }
                } else {
                        JOptionPane.showMessageDialog(null, "请输入要查询的读者编号!", "提示",
                                        JOptionPane.ERROR_MESSAGE);
                }

                if (a > count) {
                        ifbr.setText("是");
                } else {
                        ifbr.setText("否");
                }
                Formatter fmt = new Formatter();
                Calendar cal = Calendar.getInstance();
                fmt = new Formatter();
                fmt.format("%tc", cal);
                System.out.println(fmt);

                // 中国时间格式
                Date d = new Date();
                SimpleDateFormat simpDate;
                simpDate = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
                // simpDate = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
                shijian.setText(simpDate.format(d));
        }

借出:

[Java] 纯文本查看 复制代码
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
                // TODO add your handling code here:
                Formatter fmt = new Formatter();
                Calendar cal = Calendar.getInstance();
                fmt = new Formatter();
                fmt.format("%tc", cal);
                System.out.println(fmt);

                // 中国时间格式
                Date d = new Date();
                SimpleDateFormat simpDate;
                simpDate = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
                // simpDate = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
                DbUtil dbUtil = new DbUtil();
                String id = this.ID.getText();
                String rid = this.RID.getText();
                String btime=(simpDate.format(d));
                User user=new User(id, rid, btime);
                Connection con = null;
                try {
                        con = dbUtil.getCon();
                        int addNum = DaoFactory.getIUserDaoInsanse().addborrow(con, user);
                        if (addNum == 1) {
                                JOptionPane.showMessageDialog(null, "图书借出成功!", "提示",
                                                JOptionPane.INFORMATION_MESSAGE);
                        } else {
                                JOptionPane.showMessageDialog(null, "图书借出失败!", "提示",
                                                JOptionPane.ERROR_MESSAGE);
                        }
                } catch (Exception e2) {
                        e2.printStackTrace();
                        JOptionPane.showMessageDialog(null, "图书借出失败!", "提示",
                                        JOptionPane.ERROR_MESSAGE);
                } finally {
                        try {
                                dbUtil.closeCon();
                        } catch (Exception e2) {
                                // TODO Auto-generated catch block
                                e2.printStackTrace();
                        }
                }
        }


借阅管理----还回图书:

             该模块用于完成还书操作,此时只需判断该读者是否曾经借过此书且未归还就可以了 。


初始化:

[Java] 纯文本查看 复制代码
/** Creates new form Back */
        public Back() {
                initComponents();
                int width = Toolkit.getDefaultToolkit().getScreenSize().width;
                int height = Toolkit.getDefaultToolkit().getScreenSize().height;
                // 定义窗体的宽高
                int windowsWedth = 600;
                int windowsHeight = 400;
                this.setBounds((width - windowsWedth) / 2,
                                (height - windowsHeight) / 2, windowsWedth, windowsHeight);
        }

查询:

[Java] 纯文本查看 复制代码
private DbUtil dbUtil = new DbUtil();
        private DbUtil dbUtil1 = new DbUtil();
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
                // TODO add your handling code here:
                String id = this.ID.getText();
                String rid = this.RID.getText();
                Book book = new Book(id);
                User user = new User(rid);
                Connection con = null;
                Connection con1 = null;
                if (id.length() != 0) {
                        try {
                                con = dbUtil.getCon();
                                ResultSet rs = DaoFactory.getIBookDaoDAOInsanse().list(con,
                                                book);//bookDao.list(con, book);
                                while (rs.next()) {
                                        Bookname.setText(rs.getString("bookname"));
                                        Author.setText(rs.getString("author"));
                                        Publisher.setText(rs.getString("publisher"));
                                        Publish_time.setText(rs.getString("publish_time"));
                                        Price.setText(rs.getString("price"));
                                        Stock.setText(rs.getString("stock"));
                                }
                        } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        } finally {
                                try {
                                        dbUtil.closeCon();
                                } catch (Exception e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }
                        }
                } else {
                        JOptionPane.showMessageDialog(null, "请输入要查询的图书编号!", "提示",
                                        JOptionPane.ERROR_MESSAGE);
                }
                if (rid.length() != 0) {
                        try {
                                con1 = dbUtil.getCon();
                                ResultSet rs = DaoFactory.getIUserDaoInsanse().Readlist(con1,
                                                user);
                                while (rs.next()) {
                                        Readname.setText(rs.getString("readename"));
                                        Readtype.setText(rs.getString("readetype"));
                                        Max_num.setText(rs.getString("max_num"));
                                        Days_num.setText(rs.getString("days_num"));
                                }
                        } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        } finally {
                                try {
                                        dbUtil1.closeCon();
                                } catch (Exception e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }
                        }
                } else {
                        JOptionPane.showMessageDialog(null, "请输入要查询的读者编号!", "提示",
                                        JOptionPane.ERROR_MESSAGE);
                }
                Formatter fmt = new Formatter();
                Calendar cal = Calendar.getInstance();
                fmt = new Formatter();
                fmt.format("%tc", cal);
                System.out.println(fmt);

                // 中国时间格式
                Date d = new Date();
                SimpleDateFormat simpDate;
                simpDate = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
                // simpDate = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
                shijian.setText(simpDate.format(d));
        }

还回:

[Java] 纯文本查看 复制代码
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
                // TODO add your handling code here:
                Formatter fmt = new Formatter();
                Calendar cal = Calendar.getInstance();
                fmt = new Formatter();
                fmt.format("%tc", cal);
                System.out.println(fmt);

                // 中国时间格式
                Date d = new Date();
                SimpleDateFormat simpDate;
                simpDate = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
                // simpDate = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
                DbUtil dbUtil = new DbUtil();
                String id = this.ID.getText();
                String rid = this.RID.getText();
                String btime=(simpDate.format(d));
                User user=new User(id, rid, btime);
                Connection con = null;
                try {
                        con = dbUtil.getCon();
                        int addNum = DaoFactory.getIUserDaoInsanse().updateback(con, user);
                        if (addNum == 1) {
                                JOptionPane.showMessageDialog(null, "图书还回成功!", "提示",
                                                JOptionPane.INFORMATION_MESSAGE);
                        } else {
                                JOptionPane.showMessageDialog(null, "图书还回失败!", "提示",
                                                JOptionPane.ERROR_MESSAGE);
                        }
                } catch (Exception e2) {
                        e2.printStackTrace();
                        JOptionPane.showMessageDialog(null, "图书还回失败!", "提示",
                                        JOptionPane.ERROR_MESSAGE);
                } finally {
                        try {
                                dbUtil.closeCon();
                        } catch (Exception e2) {
                                // TODO Auto-generated catch block
                                e2.printStackTrace();
                        }
                }
        }

查询管理----图书查询:

             该模块用于根据图书名称、作者、出版社、出版时间等信息进行图书查询。这四个条件之间的关系为逻辑与关系。如果在某个编辑框中不输入内容,则忽略该条件。如果在四个编辑框中均不输入任何内容,表示显示全部图书信息。


初始化:

[Java] 纯文本查看 复制代码
/** Creates new form BookQuery */
        public BookQuery() {
                initComponents();
                int width = Toolkit.getDefaultToolkit().getScreenSize().width;
                int height = Toolkit.getDefaultToolkit().getScreenSize().height;
                // 定义窗体的宽高
                int windowsWedth = 700;
                int windowsHeight = 500;
                this.setBounds((width - windowsWedth) / 2,
                                (height - windowsHeight) / 2, windowsWedth, windowsHeight);
        }

查询:

[Java] 纯文本查看 复制代码
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
                // TODO add your handling code here:
                String bookname = this.Bookname.getText();
                String author = this.Author.getText();
                String publisher = this.Publisher.getText();
                String publishe_time = this.Publish_time.getText();
                Book book = new Book(bookname, author, publisher, publishe_time);
                fillTable(book);
        }

        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
                // TODO add your handling code here:
                dispose();
        }
        private DbUtil dbUtil = new DbUtil();
        private void fillTable(Book book) {
                DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
                dtm.setRowCount(0);
                Connection con = null;
                try {
                        con = dbUtil.getCon();
                        ResultSet rs = DaoFactory.getIBookDaoDAOInsanse().list(con, book);//bookDao.list(con, book);
                        while (rs.next()) {
                                Vector v = new Vector();
                                v.add(rs.getString("id"));
                                v.add(rs.getString("bookname"));
                                v.add(rs.getString("booktype"));
                                v.add(rs.getString("author"));
                                v.add(rs.getString("translator"));
                                v.add(rs.getString("publisher"));
                                v.add(rs.getString("publish_time"));
                                v.add(rs.getString("price"));
                                v.add(rs.getString("stock"));
                                dtm.addRow(v);
                        }
                } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } finally {
                        try {
                                dbUtil.closeCon();
                        } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                }
        }

系统管理----修改密码:

             该模块用来更该当前用户的密码 。


初始化:

[Java] 纯文本查看 复制代码
/** Creates new form UpdatePassword */
        public UpdatePassword() {
                initComponents();
                int width = Toolkit.getDefaultToolkit().getScreenSize().width;
                int height = Toolkit.getDefaultToolkit().getScreenSize().height;
                // 定义窗体的宽高
                int windowsWedth = 400;
                int windowsHeight = 300;
                this.setBounds((width - windowsWedth) / 2,
                                (height - windowsHeight) / 2, windowsWedth, windowsHeight);
        }

按钮:

[Java] 纯文本查看 复制代码
private DbUtil dbUtil = new DbUtil();
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
                // TODO add your handling code here:
                String username=Login.Uname;
                String password=String.valueOf(Password.getPassword());
                if(password.length()==0)
                {
                        JOptionPane.showMessageDialog(null, "密码不能为空!", "提示", JOptionPane.ERROR_MESSAGE);
                }
                else
                {
                        if(password.equals(String.valueOf(Password1.getPassword())))
                        {
                                Book book=new Book(username, password);
                                Connection con1=null;
                                try{
                                        con1=dbUtil.getCon();
                                        int addNum=DaoFactory.getIBookDaoDAOInsanse().updatePassword(con1, book);//bookDao.add(con, book);
                                        if(addNum==1){
                                                JOptionPane.showMessageDialog(null, "修改密码成功!", "提示", JOptionPane.INFORMATION_MESSAGE);        
                                                dispose();
                                        }else{
                                                JOptionPane.showMessageDialog(null, "修改密码失败!", "提示", JOptionPane.ERROR_MESSAGE);
                                        }
                                }catch(Exception e2){
                                        e2.printStackTrace();
                                        JOptionPane.showMessageDialog(null, "修改密码失败!", "提示", JOptionPane.ERROR_MESSAGE);
                                }finally{
                                        try {
                                                dbUtil.closeCon();
                                        } catch (Exception e2) {
                                                // TODO Auto-generated catch block
                                                e2.printStackTrace();
                                        }
                                }
                        }
                        else{
                                JOptionPane.showMessageDialog(null, "两次输入密码不一致!", "提示", JOptionPane.ERROR_MESSAGE);
                        }
                }
        }

图书管理系统.zip

1.02 MB, 下载次数: 339, 下载积分: 吾爱币 -1 CB

免费评分

参与人数 8吾爱币 +8 热心值 +5 收起 理由
wangjiu321 + 1 + 1 <font style="vertical-align: inherit;"><font style=
快乐heni + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
0一叶之秋0 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
pppoe + 1 + 1 我很赞同!
barry91 + 1 + 1 真的非常有用了!一级棒
eredef1368 + 1 + 1 用心讨论,共获提升!
北城南笙丶 + 1 + 1 谢谢@Thanks!
百花凋零 + 1 java开发的图书管理系统?

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

l99650 发表于 2019-7-1 00:10
本帖最后由 l99650 于 2019-7-7 02:19 编辑

dell

点评

帮你解下码: 下载链接: 蓝奏:https://www.lanzous.com/i4scx8f 度盘:https://pan.baidu.com/s/1f20Os-6zn32w5kyW3rTI2w+提取码:+52p  发表于 2019-7-7 02:14
%CF%C2%D4%D8%C1%B4%BD%D3%A3%BA%0D%0A%C0%B6%D7%E0%A3%BAhttps%3A%2F%2Fwww.lanzous.com%2Fi4scx8f%0D%0A%B6%C8%C5%CC%A3%BAhttps%3A%2F%2Fpan.baidu.com%2Fs%2F1f20Os-6zn32w5kyW3rTI2w+%CC%E1%C8%A1%C2%EB%3A+52p   发表于 2019-7-1 00:18

免费评分

参与人数 1吾爱币 +3 热心值 +1 收起 理由
夏沫梦影 + 3 + 1 谢谢@Thanks!

查看全部评分

 楼主| 夏沫梦影 发表于 2019-11-13 15:24
legend000 发表于 2019-6-30 23:54
冷孤幽 发表于 2019-6-30 23:58
你想表达什么,全都是乱码
shaojie418 发表于 2019-7-1 00:01
你来错地方了,这是地球。
Vvvvvoid 发表于 2019-7-1 00:01
什么玩意
919359733 发表于 2019-7-1 00:05
大佬都是用乱码交流的
小爱同学. 发表于 2019-7-1 00:12
这是哪国语言?
追逐太阳 发表于 2019-7-1 08:02
乱码了,什么情况
wangxuefeng 发表于 2019-7-1 10:38
java写前台好low啊
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-27 10:03

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表