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

📄 frmdelete.java

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

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;

public class FrmDelete extends JDialog {
	private int slcID = -1;
	
	FrmMain parent;
    public FrmDelete(Frame owner, String title, boolean modal) {
        super(owner, title, modal);
    	Gload.checkLogin(this);
        this.parent = (FrmMain)owner;
        try {
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            jbInit();
            this.setBounds((Gload.de.width - 430)/2, (Gload.de.height-300)/2, 400, 300);
            this.setResizable(false);

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

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

    private void jbInit() throws Exception {
        this.getContentPane().setLayout(null);
        jLabel1.setText("书号:");
        jLabel1.setBounds(new Rectangle(4, 5, 46, 31));
        jButton1.setBounds(new Rectangle(296, 9, 85, 26));
        jButton1.setText("查 看");
        jButton1.addActionListener(new FrmDelete_jButton1_actionAdapter(this));
        jButton2.setBounds(new Rectangle(296, 43, 85, 24));
        jButton2.setEnabled(false);
        jButton2.setText("报销此书");
        jButton2.addActionListener(new FrmDelete_jButton2_actionAdapter(this));
        jButton3.setBounds(new Rectangle(297, 72, 86, 25));
        jButton3.setText("取 消");
        jButton3.addActionListener(new FrmDelete_jButton3_actionAdapter(this));
        jLabel3.setForeground(Color.red);
        jLabel3.setText("注: 如果此书有多本,每次删除只删除一本书");
        jLabel3.setBounds(new Rectangle(9, 243, 323, 23));
        this.getContentPane().add(jLabel1);
        txt.setBorder(titledBorder1);
        txt.setText("");
        txt.setBounds(new Rectangle(7, 40, 280, 202));
        txt.setEditable(false);
        txt.setBackground(this.getContentPane().getBackground());
        this.getContentPane().add(jTextField1);
        this.getContentPane().add(txt);
        this.getContentPane().add(jButton1);
        this.getContentPane().add(jButton2);
        this.getContentPane().add(jButton3);
        this.getContentPane().add(jLabel3);
        jTextField1.setBounds(new Rectangle(35, 10, 252, 22));
    }

    JLabel jLabel1 = new JLabel();
    JTextField jTextField1 = new JTextField();
    JTextArea txt = new JTextArea();
    TitledBorder titledBorder1 = new TitledBorder("图书信息");
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JButton jButton3 = new JButton();
    JLabel jLabel3 = new JLabel();
    public void jButton3_actionPerformed(ActionEvent e) {
        this.dispose();
    }

    public void jButton1_actionPerformed(ActionEvent e) {
    	this.txt.setText("");
        String tmp = Gload.getText(this.jTextField1);
        if (tmp.equals("")) {
        	Gload.MSG(this, "请输入书号");
        	return;
        }
        try {
        	this.slcID = Integer.parseInt(tmp);
        } catch(Exception ex) {
        	Gload.MSG(this, "书号不正确");
        	return;
        }
        ResultSet rs = Conn.query("select count(id) as c from 图书信息 where id=" + tmp);
        try {
        	rs.next();
        	int i = rs.getInt("c");
        	if (i == 0) {
        		Gload.MSG(this, "不存在书号为 " + tmp + " 的图书");
        		rs.close();
        		return;
        	}
			rs.close();
		} catch (SQLException e1) {
			e1.printStackTrace();
		}

		this.txt.setText(Conn.getBookInfo(tmp));
		this.jButton2.setEnabled(true);
    }

    public void jButton2_actionPerformed(ActionEvent e) {
        //点击报销
        this.jButton2.setEnabled(false);
        if (Gload.NO == Gload.Confirm(this, "确认报销该图书吗?")) {
        	return;
        }
        ResultSet rs = Conn.query("select id from 图书信息 where 数量>1 and id=" + this.slcID);
        boolean flag = false;
        try {
        	flag = rs.next();
			rs.close();
		} catch (SQLException e1) {
			e1.printStackTrace();
		}
		if (flag) {
	        String tmp;
	        if (Gload.YES == Gload.Confirm(this, "该图书报销前正处于 借出 状态吗?\n请仔细选择,不能选错!", "确定图书目前状态")) {
	        	tmp = "借出";
	        	String bid = JOptionPane.showInputDialog(this, "请输入读者号!", "管理系统", 0);
	        	if (bid == null || bid.equals(""))
	        		return;
	        	try {
	        		Integer.parseInt(bid);
	        	} catch(Exception e1) {
	        		Gload.MSG(this, "读者号不正确");
	        		return;
	        	}
	        	rs = Conn.query("select id from 借书 where 书号=" + slcID + " and 读者号=" + bid);
	        	try {
	        		if (!rs.next()) {
	        			Gload.MSG(this, "该读者没有借此书!");
	        			rs.close();
	        			return;
	        		}
	    			rs.close();
	    			Conn.exec("delete from 借书 where 书号=" + slcID + " and 读者号=" + bid);
	    		} catch (SQLException e1) {
	    			e1.printStackTrace();
	    		}
	        } else
	        	tmp = "库存";
			Conn.exec("update 图书信息 set 数量=数量-1 where id=" + this.slcID);
			Conn.exec("update 图书状态 set 报废=报废+1, " + tmp + "=" + tmp + "-1 where 书号=" + this.slcID);
		} else {
			Conn.exec("delete from 图书信息 where id=" + this.slcID);
			Conn.exec("delete from 图书状态 where 书号=" + this.slcID);
		}
		Conn.exec("insert into 运行记录(书号, 操作, 备注) values(" + this.slcID + ", '报销', '单本')");
		Gload.MSG(this, "报销成功");
		parent.initBook();
    }
}

class FrmDelete_jButton2_actionAdapter implements ActionListener {
    private FrmDelete adaptee;
    FrmDelete_jButton2_actionAdapter(FrmDelete adaptee) {
        this.adaptee = adaptee;
    }

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


class FrmDelete_jButton1_actionAdapter implements ActionListener {
    private FrmDelete adaptee;
    FrmDelete_jButton1_actionAdapter(FrmDelete adaptee) {
        this.adaptee = adaptee;
    }

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


class FrmDelete_jButton3_actionAdapter implements ActionListener {
    private FrmDelete adaptee;
    FrmDelete_jButton3_actionAdapter(FrmDelete adaptee) {
        this.adaptee = adaptee;
    }

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

⌨️ 快捷键说明

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