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

📄 frmaddbook.java

📁 在管理员表中初始插入数据 usn: admin, pwd: 21232F297A57A5A743894A0E4A801FC3 初始用户账号/密码: admin (密码为 md5 加密) SRC
💻 JAVA
字号:
import java.awt.*;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.text.JTextComponent;

import java.sql.ResultSet;
import java.sql.*;

public class FrmAddBook extends JDialog {
    JLabel jLabel1 = new JLabel();
    JTextField jTextField1 = new JTextField();
    JLabel jLabel2 = new JLabel();
    JTextField jTextField2 = new JTextField();
    JLabel jLabel3 = new JLabel();
    JLabel jLabel4 = new JLabel();
    JTextField jTextField3 = new JTextField();
    JLabel jLabel5 = new JLabel();
    JTextField jTextField4 = new JTextField();
    JLabel jLabel6 = new JLabel();
    JComboBox jComboBox1 = new JComboBox();
    JLabel jLabel7 = new JLabel();
    JComboBox jComboBox2 = new JComboBox();
    JButton jButton1 = new JButton();
    JLabel jLabel8 = new JLabel();
    JTextField jTextField5 = new JTextField();
    JLabel jLabel9 = new JLabel();
    JTextField jTextField6 = new JTextField();
    JLabel jLabel10 = new JLabel();
    JTextArea jTextArea1 = new JTextArea();
    Border border1 = BorderFactory.createLineBorder(Color.white, 2);
    TitledBorder titledBorder1 = new TitledBorder("");
    JButton jButton2 = new JButton();
    JButton jButton3 = new JButton();
    JLabel jLabel11 = new JLabel();
    JTextField jTextField7 = new JTextField();
    JLabel jLabel12 = new JLabel();
    JTextField jTextField8 = new JTextField();
    JLabel jLabel13 = new JLabel();

    FrmMain parent;
    public FrmAddBook(Frame owner, String title, boolean modal) {
        super(owner, title, modal);
    	Gload.checkLogin(this);
        this.parent = (FrmMain)owner;
        try {
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            jbInit();
            this.initSelect();
            this.setBounds((Gload.de.width - 450)/2, (Gload.de.height-490)/2, 450, 490);
            this.setResizable(false);
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    public FrmAddBook() {
        this(new Frame(), "FrmAddBook", false);
    }

    private void jbInit() throws Exception {
        this.getContentPane().setLayout(null);
        jLabel1.setToolTipText("");
        jLabel1.setText("书名:");
        jLabel1.setBounds(new Rectangle(8, 9, 48, 16));
        jTextField1.setBounds(new Rectangle(55, 6, 368, 21));
        jLabel2.setText("作者:");
        jLabel2.setBounds(new Rectangle(7, 34, 48, 23));
        jTextField2.setBounds(new Rectangle(56, 35, 368, 22));
        jLabel3.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
        jLabel3.setForeground(Color.red);
        jLabel3.setText("*");
        jLabel3.setBounds(new Rectangle(431, 7, 20, 22));
        jLabel4.setText("出版号:");
        jLabel4.setBounds(new Rectangle(8, 151, 45, 27));
        jTextField3.setBounds(new Rectangle(58, 154, 364, 22));
        jLabel5.setText("价格:");
        jLabel5.setBounds(new Rectangle(9, 68, 35, 18));
        jTextField4.setText("1.00");
        jTextField4.setBounds(new Rectangle(57, 65, 366, 23));
        jLabel6.setText("分类:");
        jLabel6.setBounds(new Rectangle(8, 97, 33, 20));
        jComboBox1.setBounds(new Rectangle(58, 97, 367, 21));
        jLabel7.setText("出版社:");
        jLabel7.setBounds(new Rectangle(8, 129, 42, 19));
        jComboBox2.setBounds(new Rectangle(58, 125, 275, 23));
        jButton1.setBounds(new Rectangle(339, 126, 85, 22));
        jButton1.setText("添 加");
        jButton1.addActionListener(new FrmAddBook_jButton1_actionAdapter(this));
        jLabel8.setText("出版日期:");
        jLabel8.setBounds(new Rectangle(6, 184, 57, 20));
        jTextField5.setBounds(new Rectangle(58, 184, 70, 22));
        jLabel9.setText("数量:");
        jLabel9.setBounds(new Rectangle(11, 210, 40, 22));
        jTextField6.setText("1");
        jTextField6.setBounds(new Rectangle(58, 211, 69, 21));
        jLabel10.setText("简介:");
        jLabel10.setBounds(new Rectangle(11, 242, 40, 16));
        jTextArea1.setBorder(titledBorder1);
        jTextArea1.setText("好书!");
        jTextArea1.setBounds(new Rectangle(58, 238, 366, 181));
        jButton2.setBounds(new Rectangle(240, 428, 87, 26));
        jButton2.setText("入 库");
        jButton2.addActionListener(new FrmAddBook_jButton2_actionAdapter(this));
        jButton3.setBounds(new Rectangle(338, 428, 84, 26));
        jButton3.setText("取 消");
        jButton3.addActionListener(new FrmAddBook_jButton3_actionAdapter(this));
        jLabel11.setText("年");
        jLabel11.setBounds(new Rectangle(136, 185, 30, 21));
        jTextField7.setBounds(new Rectangle(153, 183, 75, 22));
        jLabel12.setText("月");
        jLabel12.setBounds(new Rectangle(236, 184, 30, 21));
        jTextField8.setBounds(new Rectangle(253, 184, 50, 21));
        jLabel13.setText("日");
        jLabel13.setBounds(new Rectangle(317, 185, 28, 22));
        this.getContentPane().add(jLabel1, null);
        this.getContentPane().add(jTextField1);
        this.getContentPane().add(jTextField2);
        this.getContentPane().add(jLabel2);
        this.getContentPane().add(jLabel3);
        this.getContentPane().add(jComboBox1);
        this.getContentPane().add(jLabel5);
        this.getContentPane().add(jTextField4);
        this.getContentPane().add(jLabel6);
        this.getContentPane().add(jTextField3);
        this.getContentPane().add(jLabel7);
        this.getContentPane().add(jComboBox2);
        this.getContentPane().add(jButton1);
        this.getContentPane().add(jLabel4);
        this.getContentPane().add(jTextField5);
        this.getContentPane().add(jLabel8);
        this.getContentPane().add(jTextField6);
        this.getContentPane().add(jLabel9);
        this.getContentPane().add(jTextArea1);
        this.getContentPane().add(jLabel10);
        this.getContentPane().add(jButton3);
        this.getContentPane().add(jButton2);
        this.getContentPane().add(jLabel11);
        this.getContentPane().add(jTextField7);
        this.getContentPane().add(jLabel12);
        this.getContentPane().add(jTextField8);
        this.getContentPane().add(jLabel13);
    }

    private void initSelect() {
        ResultSet rs = Conn.query("select count(id) as s from 类别");
        try {
            rs.next();
            int i = rs.getInt("s");
            if (i == 0) {
                Gload.MSG(this, "没有任何类别,请先在类别管理中添加图书类别");
                rs.close();
                this.dispose();
            }
        } catch (SQLException ex1) {
            ex1.printStackTrace();
        }

        rs = Conn.query("select distinct 类名 from 类别");
        try {
            while (rs.next()) {
                jComboBox1.addItem(rs.getString("类名"));
            }
            rs.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        rs = Conn.query("select distinct 出版社 from 出版社");
        try {
            while (rs.next()) {
                jComboBox2.addItem(rs.getString("出版社"));
            }
            rs.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }

    }

    public void jButton1_actionPerformed(ActionEvent e) {
        //System.out.println("点击添加出版社");
        String s2 = JOptionPane.showInputDialog(this, "请输入出版社名", "管理系统", 0);
        if (s2 == null || s2.equals("")) return;
        jComboBox2.addItem(s2.trim());
        jComboBox2.setSelectedIndex(jComboBox2.getItemCount() - 1);
    }

    public void jButton3_actionPerformed(ActionEvent e) {
        this.dispose();
    }

    public void jButton2_actionPerformed(ActionEvent e) {
        //入库
        String title = Gload.getText(this.jTextField1).trim();
        if (title.equals("")) {
            Gload.MSG(this, "书名是必填项,请填写!");
            return;
        }
        String author = Gload.getText(this.jTextField2).trim();
        String price = Gload.getText(this.jTextField4).trim();
        if (price.equals("")) price = "0.0";
        if (!Gload.checkNumber(price)) {
            Gload.MSG(this, "价格不正确!");
            return;
        }
        String publish = this.jComboBox2.getSelectedItem().toString();
        String BookClass = this.jComboBox1.getSelectedItem().toString();
        String pubID = Gload.getText(this.jTextField3);
        String year = Gload.getText(this.jTextField5);
        String month = Gload.getText(this.jTextField7);
        String day = Gload.getText(this.jTextField8);

        boolean flag = true;
        if (year.equals("") && month.equals("") && day.equals("")) {
            flag = false;
        } else if (Gload.checkNumber(year) && Gload.checkNumber(month) && Gload.checkNumber(day)) {
        	try {
        		Date.parse(year + "/" + month + "/" + day);
        	} catch (Exception e1) {
        		Gload.MSG(this, "出版日期不正确!");
        		return;
        	}
        } else {
            Gload.MSG(this, "出版日期不正确");
            return;
        }
        String sum = Gload.getText(this.jTextField6);
        try {
            if (!sum.equals("")) {
                int tmp = Integer.parseInt(sum);
                if (tmp < 1) {
                    Gload.MSG(this, "图书数量不正确");
                    return;
                }
            } else sum = "1";
        } catch (Exception e2) {
            Gload.MSG(this, "图书数量不正确");
            return;
        }
        String content = Gload.getText(this.jTextArea1);
        String s1, s2;
        int k = 0, t = 0;
        s1 = "select count(id) as s from 出版社 where 出版社.出版社='" + publish + "'";
        ResultSet rs = Conn.query(s1);
        try {
            rs.next();
            k = rs.getInt("s");
            rs.close();
        } catch (SQLException ex) { ex.printStackTrace(); }
        if (k == 0) {
            s1 = "insert into 出版社(出版社) values('" + publish + "')";
            Conn.exec(s1);
        }
        rs = Conn.query("select id from 出版社 where 出版社='" + publish + "'");
        try {
            rs.next();
            k = rs.getInt("id");
            rs.close();
        } catch (SQLException ex1) { ex1.printStackTrace(); }
        rs = Conn.query("select id from 类别 where 类名 = '" + BookClass + "'");
        try {
            rs.next();
            t = rs.getInt("id");
            rs.close();
        } catch (SQLException ex2) { ex2.printStackTrace(); }
        s1 = "insert into  图书信息(书名, 作者, 出版号, 出版社ID, 类别ID, 数量, 简介, 价格";
        s2 = ") values('" + title + "', '" + author + "', '" + pubID + "', " + k + ", " + t + ", " + sum + ", '" + content + "', " + price;
        if (flag) {
            s1 = s1 + ", 出版日期";
            s2 = s2 + ", '" + year + "-" + month + "-" + day + "'";
        }
        Conn.exec(s1 + s2 + ")");
        rs = Conn.query("select @@identity as id");
        try {
            rs.next();
            k = Integer.parseInt(rs.getString("id"));
            rs.close();
            Conn.exec("insert into 图书状态(书号,总数,库存,借出,报废) values(" + k + ", " + sum + ", " + sum + ", 0, 0)");
            Conn.exec("insert into 运行记录(操作,书号,备注) values('入库', " + k + ", '数量:" + sum + "')");
        } catch (SQLException ex3) {
            ex3.printStackTrace();
        }
        Gload.MSG(this, "插入成功");
        this.parent.initBook();
        this.dispose();
    }
}


class FrmAddBook_jButton2_actionAdapter implements ActionListener {
    private FrmAddBook adaptee;
    FrmAddBook_jButton2_actionAdapter(FrmAddBook adaptee) {
        this.adaptee = adaptee;
    }

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


class FrmAddBook_jButton3_actionAdapter implements ActionListener {
    private FrmAddBook adaptee;
    FrmAddBook_jButton3_actionAdapter(FrmAddBook adaptee) {
        this.adaptee = adaptee;
    }

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


class FrmAddBook_jButton1_actionAdapter implements ActionListener {
    private FrmAddBook adaptee;
    FrmAddBook_jButton1_actionAdapter(FrmAddBook adaptee) {
        this.adaptee = adaptee;
    }

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

⌨️ 快捷键说明

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