⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fhuanshu.java~60~

📁 图书管理 问题描述:图书管理基本业务活动包括对一本书的采编入库、清除库存、借阅和归还等等。将上述业务活动借助于计算机系统完成。
💻 JAVA~60~
字号:
package jxm;

import java.awt.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Vector;
import java.sql.*;
import java.util.Calendar;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class Fhuanshu extends JFrame {
    public Fhuanshu() {
        try {
            jbInit();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date dt = new Date();
            String st = sdf.format(dt);
            jTextField10.setText(st);

        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(null);
        jPanel1.setBorder(BorderFactory.createEtchedBorder());
        jPanel1.setBounds(new Rectangle(23, 7, 431, 66));
        jPanel1.setLayout(null);
        jLabel9.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jLabel9.setText("当前日期");
        jLabel9.setBounds(new Rectangle(26, 381, 59, 31));
        jTextField10.setText("jTextField10");
        jTextField10.setBounds(new Rectangle(89, 385, 133, 27));
        jButton2.setBounds(new Rectangle(236, 383, 68, 29));
        jButton2.setEnabled(false);
        jButton2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jButton2.setText("还书");
        jButton2.addActionListener(new Fhuanshu_jButton2_actionAdapter(this));
        jButton4.setBounds(new Rectangle(314, 383, 64, 28));
        jButton4.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jButton4.setText("清空");
        jScrollPane1.setBounds(new Rectangle(23, 246, 430, 123));
        jButton3.addActionListener(new Fhuanshu_jButton3_actionAdapter(this));
        jButton1.addActionListener(new Fhuanshu_jButton1_actionAdapter(this));
        jLabel7.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jLabel7.setText("图书编号");
        jLabel7.setBounds(new Rectangle(17, 10, 78, 28));
        this.getContentPane().add(jPanel1);
        jTextField3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jTextField3.setText("");
        jTextField3.setBounds(new Rectangle(72, 6, 112, 29));
        jLabel2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jLabel2.setText("借书日期");
        jLabel2.setBounds(new Rectangle(195, 9, 69, 29));
        jTextField4.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jTextField4.setText("");
        jTextField4.setBounds(new Rectangle(254, 10, 146, 27));
        jLabel3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jLabel3.setText("图书名称");
        jLabel3.setBounds(new Rectangle(9, 43, 62, 27));
        jTextField5.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jTextField5.setText("");
        jTextField5.setBounds(new Rectangle(72, 43, 112, 27));
        jLabel4.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jLabel4.setText("应还日期");
        jLabel4.setBounds(new Rectangle(194, 43, 68, 26));
        jTextField6.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jTextField6.setText("");
        jTextField6.setBounds(new Rectangle(254, 44, 145, 27));
        jLabel5.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jLabel5.setText("读者编号");
        jLabel5.setBounds(new Rectangle(9, 82, 60, 24));
        jTextField7.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jTextField7.setText("");
        jTextField7.setBounds(new Rectangle(71, 79, 113, 26));
        jLabel6.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jLabel6.setText("读者名称");
        jLabel6.setBounds(new Rectangle(9, 113, 62, 28));
        jTextField8.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jTextField8.setText("");
        jTextField8.setBounds(new Rectangle(71, 114, 114, 26));
        jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jTextField1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jPanel2.add(jLabel1);
        jPanel2.add(jTextField3);
        jPanel2.add(jLabel3);
        jPanel2.add(jTextField8);
        jPanel2.add(jLabel5);
        jPanel2.add(jLabel6);
        jPanel2.add(jTextField5);
        jPanel2.add(jTextField7);
        jPanel2.add(jLabel2);
        jPanel2.add(jLabel4);
        jPanel2.add(jTextField4);
        jPanel2.add(jTextField6);
        jPanel2.setLayout(null);
        jLabel1.setBounds(new Rectangle(10, 1, 58, 33));
        jButton1.setBounds(new Rectangle(287, 8, 78, 45));
        jButton1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jButton1.setText("确定");
        jButton3.setBounds(new Rectangle(388, 383, 66, 28));
        jButton3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jButton3.setText("退出");
        jPanel2.setBorder(BorderFactory.createEtchedBorder());
        jPanel2.setBounds(new Rectangle(23, 74, 430, 162));
        jLabel1.setText("图书编号");
        jPanel1.add(jButton1);
        jPanel1.add(jTextField1);
        jPanel1.add(jLabel7);
        this.getContentPane().add(jPanel2);
        this.getContentPane().add(jButton2);
        this.getContentPane().add(jButton4);
        this.getContentPane().add(jButton3);
        this.getContentPane().add(jTextField10);
        this.getContentPane().add(jLabel9);
        this.getContentPane().add(jScrollPane1);
        jScrollPane1.getViewport().add(jTable1);
        jTextField1.setText("");
        jTextField1.setBounds(new Rectangle(106, 12, 128, 25));
        df.addColumn("租期");
        df.addColumn("押金");
        df.addColumn("应付租金");
        df.addColumn("找回余额");

    }

    JTextField jTextField1 = new JTextField();
    JPanel jPanel1 = new JPanel();
    JButton jButton1 = new JButton();
    JButton jButton3 = new JButton();
    JPanel jPanel2 = new JPanel();
    JLabel jLabel1 = new JLabel();
    JTextField jTextField3 = new JTextField();
    JLabel jLabel2 = new JLabel();
    JTextField jTextField4 = new JTextField();
    JLabel jLabel3 = new JLabel();
    JTextField jTextField5 = new JTextField();
    JLabel jLabel4 = new JLabel();
    JTextField jTextField6 = new JTextField();
    JLabel jLabel5 = new JLabel();
    JTextField jTextField7 = new JTextField();
    JLabel jLabel6 = new JLabel();
    JTextField jTextField8 = new JTextField();
    JLabel jLabel9 = new JLabel();
    JTextField jTextField10 = new JTextField();
    JButton jButton2 = new JButton();
    JButton jButton4 = new JButton();
    JScrollPane jScrollPane1 = new JScrollPane();
    DefaultTableModel df = new DefaultTableModel();
    JTable jTable1 = new JTable(df);
    public void jButton3_actionPerformed(ActionEvent e) {
        this.dispose();
    }

    public void jButton1_actionPerformed(ActionEvent e) {
        jButton2.setEnabled(true);
        Vector v = new Vector();
        Date d = new Date();
        Calendar cd;
        cd = Calendar.getInstance();
        String str = "select top 1 j.bookid,b.bname,j.userid,d.dname,j.starttime,j.borrowtime,j.yamoney from duze As d inner join jhbook As j on (d.dnum=j.userid) inner join books As b on (j.bookid=b.bnum) where j.bookid='" +
                     jTextField1.getText() +
                     "'and b.bzt='0' and j.endtime is null and j.zumoney is null";
        cons con = new cons();
        ResultSet rs = con.getrs(str);
        try {
            if (rs.next()) {
                jTextField3.setText(rs.getString(1));
                jTextField5.setText(rs.getString(2));
                jTextField7.setText(rs.getString(3));
                jTextField8.setText(rs.getString(4));
                jTextField4.setText(rs.getString(5));
                d = rs.getDate(5); //查询出数据库中的时间
                Date dd = new Date(); //获取当前时间
                cd.setTime(d); //以 D为标准更改日历为当前时间
                cd.add(Calendar.DAY_OF_MONTH, rs.getInt(6)); //当前时间+租期
                d = cd.getTime(); //把处理后的时间也就是应还日期给D
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
                String st = sdf.format(d); //格式化应还日期
                jTextField6.setText(st); //输出显示
                float r = (dd.getTime() - rs.getDate(5).getTime()) / 1000 / 60 /
                          60 / 24; //计算租期
                v.add(String.valueOf(r)); //添加租期
                v.add(rs.getString(7)); //添加押金
                i = r * 2;
                if (r < 1) {
                    i = 2;
                }
                v.add(String.valueOf(i)); //添加租金

                v.add(String.valueOf(rs.getInt(7) - i)); // //添加 余额=押金-租金
                df.addRow(v);
            }
        } catch (SQLException ex1) {
            System.out.println(ex1);
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }

            } catch (Exception ex) {
                System.out.println(ex); //2
            }

        }
    }

    float i;
    JLabel jLabel7 = new JLabel();
    public void jButton2_actionPerformed(ActionEvent e) {
        String str = "update jhbook set endtime='" + jTextField10.getText() +
                     "' ,zumoney=" + i + " where bookid='" +
                     jTextField1.getText() + "'and userid='" +
                     jTextField7.getText() + "' and starttime='" +
                     jTextField4.getText().substring(0, 10) +
                     "' and zumoney is null and endtime is null";
        String str2 = "update books set bzt='1' where bnum='" +
                      jTextField1.getText() + "'";
        String str3 =
                "update bookzt set ymount=ymount+1 ,nmount=nmount-1 where bname='" +
                jTextField5.getText() + "'";
        cons con = new cons();

        System.out.println(str + "\n" + str2 + "\n" + str3);
        if (con.getblcc(str)) {

            if (con.getblcc(str2) && con.getblcc(str3)) {
                JOptionPane.showMessageDialog(this, "资料已记录", "还书成功",
                                              JOptionPane.INFORMATION_MESSAGE);
            }

        } else {
            JOptionPane.showMessageDialog(this, "资料可能已丢失", "还书失败",
                                          JOptionPane.ERROR_MESSAGE);

        }
        this.dispose();
    }


}


class Fhuanshu_jButton2_actionAdapter implements ActionListener {
    private Fhuanshu adaptee;
    Fhuanshu_jButton2_actionAdapter(Fhuanshu adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton2_actionPerformed(e);
    }
}


class Fhuanshu_jButton1_actionAdapter implements ActionListener {
    private Fhuanshu adaptee;
    Fhuanshu_jButton1_actionAdapter(Fhuanshu adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
    }
}


class Fhuanshu_jButton3_actionAdapter implements ActionListener {
    private Fhuanshu adaptee;
    Fhuanshu_jButton3_actionAdapter(Fhuanshu adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton3_actionPerformed(e);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -