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

📄 frminfo.java

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

import javax.swing.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.*;

public class FrmInfo extends JDialog {
    JPanel panel1 = new JPanel();
    JLabel 书名 = new JLabel();
    JTextField jTextField1 = new JTextField();
    JTextField jTextField2 = new JTextField();
    JTextField jTextField3 = new JTextField();
    JTextField jTextField4 = new JTextField();
    JTextField jTextField6 = new JTextField();
    JTextField jTextField8 = new JTextField();
    JTextField jTextField9 = new JTextField();
    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();
    JLabel jLabel4 = new JLabel();
    JLabel jLabel5 = new JLabel();
    JLabel jLabel6 = new JLabel();
    JTextArea jTextArea1 = new JTextArea();
    JLabel jLabel7 = new JLabel();
    JLabel jLabel8 = new JLabel();
    JLabel jLabel9 = new JLabel();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JComboBox jComboBox1 = new JComboBox();
    JComboBox jComboBox2 = new JComboBox();
    JButton jButton4 = new JButton();
    FrmMain parent;
    
    
    public FrmInfo(Frame owner, String title, boolean modal) {
        super(owner, title, modal);
    	Gload.checkLogin(this);
        this.parent = (FrmMain)owner;
        try {
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        this.setBounds((Gload.de.width - 430)/2, (Gload.de.height-300)/2, 350, 425);
        this.setResizable(false);
        String cls = "", pubs = "";
        if (Gload.slcID != -1) {
            ResultSet rs = Conn.query("select 书名, 出版号, 作者, 价格, 简介,出版社,出版日期,数量,类名 from 类别,图书信息,出版社 where 类别.id=图书信息.类别ID AND 出版社ID=出版社.id and 图书信息.id=" +
                                      Gload.slcID);
            try {
                if (rs.next()) {
                    this.jTextField1.setText(rs.getString("书名").trim());
                    this.jTextField3.setText(rs.getString("出版号").trim());
                    this.jTextField2.setText(rs.getString("作者").trim());
                    this.jTextField6.setText(rs.getString("价格"));
                    this.jTextArea1.setText(rs.getString("简介").trim());
                    pubs = rs.getString("出版社").trim();
                    Date d = rs.getDate("出版日期");
                    if (d != null)
                        this.jTextField8.setText(d.toString());
                    this.jTextField4.setText(rs.getString("数量"));
                    cls = rs.getString("类名").trim();
                    this.jTextField9.setText(1 + "");
                    rs.close();
                }
            } catch (SQLException ex) {
                System.out.println(ex.getMessage());
            }
            this.jComboBox1.addItem(cls);
            rs = Conn.query("select distinct 类名 from 类别");
            try {
                String tmp;
                while (rs.next()) {
                    tmp = rs.getString("类名");
                    if (!tmp.equals(cls))
                        this.jComboBox1.addItem(tmp);
                }
                rs.close();
            } catch (SQLException ex1) {
                ex1.printStackTrace();
            }
            this.jComboBox2.addItem(pubs);
            rs = Conn.query("select distinct 出版社 from 出版社");
            try {
                String tmp2;
                int i = 0;
                while (rs.next()) {
                    tmp2 = rs.getString("出版社");
                    if (!tmp2.equals(pubs))
                        this.jComboBox2.addItem(tmp2);
                }
                rs.close();
            } catch (SQLException ex1) {
                ex1.printStackTrace();
            }

        }
    }

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

    private void jbInit() throws Exception {
        panel1.setLayout(null);
        this.getContentPane().setLayout(null);
        书名.setToolTipText("");
        书名.setText("书 名");
        书名.setBounds(new Rectangle(13, 5, 42, 23));
        this.getContentPane().setBackground(SystemColor.controlHighlight);
        jTextField1.setText("");
        jTextField1.setBounds(new Rectangle(63, 7, 253, 19));
        jLabel1.setToolTipText("");
        jLabel1.setText("作 者");
        jLabel1.setBounds(new Rectangle(13, 32, 45, 25));
        jTextField2.setBounds(new Rectangle(62, 35, 254, 21));
        jLabel2.setText("出版号");
        jLabel2.setBounds(new Rectangle(10, 64, 46, 19));
        jTextField3.setBounds(new Rectangle(61, 67, 256, 19));
        jLabel3.setText("数 量");
        jLabel3.setBounds(new Rectangle(11, 92, 51, 24));
        jTextField4.setBounds(new Rectangle(62, 98, 74, 19));
        jLabel4.setText("分 类");
        jLabel4.setBounds(new Rectangle(12, 123, 51, 20));
        jLabel5.setText("价格");
        jLabel5.setBounds(new Rectangle(13, 158, 50, 24));
        jTextField6.setBounds(new Rectangle(61, 160, 77, 21));
        jLabel6.setText("简 介");
        jLabel6.setBounds(new Rectangle(12, 199, 46, 21));
        jTextArea1.setBorder(BorderFactory.createEtchedBorder());
        jTextArea1.setBounds(new Rectangle(63, 192, 259, 56));
        jLabel7.setText("出版社");
        jLabel7.setBounds(new Rectangle(12, 263, 60, 21));
        jLabel8.setText("出版日期");
        jLabel8.setBounds(new Rectangle(10, 297, 60, 21));
        jTextField8.setBounds(new Rectangle(62, 297, 260, 24));
        jLabel9.setText("编号");
        jLabel9.setBounds(new Rectangle(16, 334, 55, 18));
        jTextField9.setBounds(new Rectangle(62, 333, 85, 20));
        jTextField9.setEditable(false);
        jButton1.setBounds(new Rectangle(144, 358, 83, 27));
        jButton1.setText("修 改");
        jButton1.addActionListener(new FrmInfo_jButton1_actionAdapter(this));
        jButton2.setBounds(new Rectangle(241, 359, 79, 26));
        jButton2.setText("取 消");
        jButton2.addActionListener(new FrmInfo_jButton2_actionAdapter(this));
        jComboBox1.setBorder(BorderFactory.createEtchedBorder());
        jComboBox1.setBounds(new Rectangle(61, 125, 258, 23));
        jComboBox2.setBorder(BorderFactory.createEtchedBorder());
        jComboBox2.setBounds(new Rectangle(63, 260, 173, 24));
        jButton4.setBounds(new Rectangle(241, 259, 75, 23));
        jButton4.setText("其它");
        jButton4.addActionListener(new FrmInfo_jButton4_actionAdapter(this));
        this.getContentPane().add(panel1, null);
        this.getContentPane().add(书名);
        this.getContentPane().add(jTextField1);
        this.getContentPane().add(jTextField2);
        this.getContentPane().add(jLabel1);
        this.getContentPane().add(jLabel2);
        this.getContentPane().add(jTextField3);
        this.getContentPane().add(jLabel3);
        this.getContentPane().add(jTextField4);
        this.getContentPane().add(jLabel4);
        this.getContentPane().add(jLabel5);
        this.getContentPane().add(jTextField6);
        this.getContentPane().add(jTextArea1);
        this.getContentPane().add(jLabel7);
        this.getContentPane().add(jLabel8);
        this.getContentPane().add(jTextField8);
        this.getContentPane().add(jLabel9);
        this.getContentPane().add(jTextField9);
        this.getContentPane().add(jLabel6);
        this.getContentPane().add(jComboBox1);
        this.getContentPane().add(jComboBox2);
        this.getContentPane().add(jButton4);
        this.getContentPane().add(jButton1);
        this.getContentPane().add(jButton2);
        panel1.setBounds(new Rectangle(0, 263, 1, 1));
    }

    public void jButton2_actionPerformed(ActionEvent e) {
        this.dispose();
    }
    
    public void jButton4_actionPerformed(ActionEvent e) {
    	String s2 = JOptionPane.showInputDialog(this, "请输入出版社名", "管理系统", 0);
        if (s2 == null || s2.equals("")) return;
        jComboBox2.addItem(s2.trim());
        jComboBox2.setSelectedIndex(jComboBox2.getItemCount() - 1);
    }

    public void jButton1_actionPerformed(ActionEvent e) {
        //点击修改
    	String ti = Gload.getText(this.jTextField1).trim();
    	if (ti == null || ti.equals("")) {
    		Gload.MSG(this, "请填写书名");
    		return;
    	}
    	String au = Gload.getText(this.jTextField2).trim();
    	String price = Gload.getText(this.jTextField6).trim();
    	if (price.equals("")) price = "0.0";
        if (!Gload.checkNumber(price)) {
            Gload.MSG(this, "价格不正确!");
            return;
        }
    	String pubs = this.jComboBox2.getSelectedItem().toString();
    	String pid = Gload.getText(this.jTextField3).trim();
    	String cls = this.jComboBox1.getSelectedItem().toString();
    	String pDate = Gload.getText(this.jTextField8).trim();
    	try {
    		if (!pDate.equals(""))
    			Date.parse(pDate.replaceAll("-", "/"));
    	} catch (Exception e1) {
    		Gload.MSG(this, "出版日期不正确!");
    		return;
    	}
    	//System.out.println(Gload.getText(this.jTextField9));
    	String content = Gload.getText(this.jTextArea1).trim();
    	String sum = Gload.getText(this.jTextField4).trim();
        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 sql;
        String s1, s2;
        int k = 0, t = 0;
        sql = "select count(id) as s from 出版社 where 出版社.出版社='" + pubs + "'";
        ResultSet rs = Conn.query(sql);
        try {
            rs.next();
            k = rs.getInt("s");
            rs.close();
        } catch (SQLException ex) { ex.printStackTrace(); }
        if (k == 0) {
            sql = "insert into 出版社(出版社) values('" + pubs + "')";
            Conn.exec(sql);
        }
        rs = Conn.query("select id from 出版社 where 出版社='" + pubs + "'");
        try {
            rs.next();
            k = rs.getInt("id");
            rs.close();
        } catch (SQLException ex1) { ex1.printStackTrace(); }
        rs = Conn.query("select id from 类别 where 类名 = '" + cls + "'");
        try {
            rs.next();
            t = rs.getInt("id");
            rs.close();
        } catch (SQLException ex2) { ex2.printStackTrace(); }
        sql = "UPDATE 图书信息 SET 书名='" + ti + "', 作者='" + au + "', 出版号='" + pid + "', 数量=" + sum + ", 价格=" + price + ", 出版日期='" + pDate + "', 简介='" + content + "', 类别ID=" + k + ", 出版社ID=" + k + " WHERE id=" + Gload.slcID;
        Conn.exec(sql);
        Conn.exec("UPDATE 图书状态 SET 库存=" + sum + "-借出 where 书号=" + Gload.slcID);
        Gload.MSG(this, "修改成功");
        this.parent.initBook();
        this.dispose();
    }

    public static void main(String[] ar) {
    	try {
    		System.out.println(Date.parse("2005-6-31".replaceAll("-", "/")));
    		System.out.println(Date.parse("6/31/2005"));
    	} catch(Exception e) {
    		;
    	}
    }
}


class FrmInfo_jButton1_actionAdapter implements ActionListener {
    private FrmInfo adaptee;
    FrmInfo_jButton1_actionAdapter(FrmInfo adaptee) {
        this.adaptee = adaptee;
    }

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


class FrmInfo_jButton4_actionAdapter implements ActionListener {
    private FrmInfo adaptee;
    FrmInfo_jButton4_actionAdapter(FrmInfo adaptee) {
        this.adaptee = adaptee;
    }

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


class FrmInfo_jButton2_actionAdapter implements ActionListener {
    private FrmInfo adaptee;
    FrmInfo_jButton2_actionAdapter(FrmInfo adaptee) {
        this.adaptee = adaptee;
    }

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

⌨️ 快捷键说明

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