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

📄 returnbook.java

📁 java语言编写的基于sql2000开发的图书馆管理系统
💻 JAVA
字号:
package reception;

import java.awt.GridBagLayout;
import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import java.sql.ResultSet;
import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;

import main.DataBase;

class ReturnBook extends JPanel {

	private static final long serialVersionUID = 1L;
	private JLabel jLabel = null;
	private JTextField member = null;
	private JLabel jLabel1 = null;
	private JTextField isbn = null;
	private JLabel jLabel2 = null;
	private JComboBox conditionOfBook = null;
	private JLabel jLabel3 = null;
	private JComboBox delayornot = null;
	private JButton returnbook = null;
	private JButton fine = null;
	/**
	 * This is the default constructor
	 */
	public ReturnBook() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		jLabel3 = new JLabel();
		jLabel3.setBounds(new Rectangle(35, 254, 110, 26));
		jLabel3.setText("是否延期");
		jLabel2 = new JLabel();
		jLabel2.setBounds(new Rectangle(35, 184, 110, 26));
		jLabel2.setText("书籍状况");
		jLabel1 = new JLabel();
		jLabel1.setBounds(new Rectangle(35, 114, 110, 26));
		jLabel1.setText("isbn");
		jLabel = new JLabel();
		jLabel.setBounds(new Rectangle(35, 44, 110, 26));
		jLabel.setText("会员号");
		this.setSize(582, 398);
		this.setLayout(null);
		this.add(jLabel, null);
		this.add(getMember(), null);
		this.add(jLabel1, null);
		this.add(getIsbn(), null);
		this.add(jLabel2, null);
		this.add(getConditionOfBook(), null);
		this.add(jLabel3, null);
		this.add(getDelayornot(), null);
		this.add(getReturnbook(), null);
		this.add(getFine(), null);
	}

	/**
	 * This method initializes member	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getMember() {
		if (member == null) {
			member = new JTextField();
			member.setBounds(new Rectangle(199, 44, 146, 26));
		}
		return member;
	}

	/**
	 * This method initializes isbn	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getIsbn() {
		if (isbn == null) {
			isbn = new JTextField();
			isbn.setBounds(new Rectangle(199, 114, 146, 26));
		}
		return isbn;
	}

	/**
	 * This method initializes conditionOfBook	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getConditionOfBook() {
		if (conditionOfBook == null) {
			conditionOfBook = new JComboBox();
			conditionOfBook.setBounds(new Rectangle(199, 184, 146, 26));
			conditionOfBook.addItem("正常");
			conditionOfBook.addItem("破损");
			conditionOfBook.addItem("丢失");
		}
		return conditionOfBook;
	}

	/**
	 * This method initializes delayornot	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getDelayornot() {
		if (delayornot == null) {
			delayornot = new JComboBox();
			delayornot.setBounds(new Rectangle(199, 254, 146, 26));
			delayornot.addItem("没有延期");
			delayornot.addItem("延期");
		}
		return delayornot;
	}

	/**
	 * This method initializes returnbook	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getReturnbook() {
		if (returnbook == null) {
			returnbook = new JButton();
			returnbook.setBounds(new Rectangle(35, 324, 110, 26));
			returnbook.setText("还书");
			returnbook.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					//System.out.println("actionPerformed()"); 
					String member=ReturnBook.this.getMember().getText();
					String isbn=ReturnBook.this.getIsbn().getText();
					String condionOfBook=(String)ReturnBook.this.
								getConditionOfBook().getSelectedItem();
					if(condionOfBook.equals("丢失")){
						//库存量不变,耗损加1,删除借书记录
						String sql1="update book set ruined_number=ruined_number+1" +
								" where isbn='"+isbn+"'";
						DataBase.execute(sql1);
						//删除借书记录
						String sql2="delete from member_book where ID_Number='" +member+
								"' and ISBN='"+isbn+"'";
						DataBase.execute(sql2);
						
					}else{
						//库存量加1
						String sql3="update book set remain_number=" +
								"remain_number+1 where isbn='" +isbn+
								"'";
						DataBase.execute(sql3);
						String sql4="delete from member_book where ID_Number='" +member+
								"' and ISBN='"+isbn+"'";
						DataBase.execute(sql4);
					}
					javax.swing.JOptionPane.showMessageDialog(null,"图书馆管理系统\n"+
							"还书成功!!!\n");
					
				}
			});
		}
		return returnbook;
	}

	/**
	 * This method initializes fine	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getFine() {
		if (fine == null) {
			fine = new JButton();
			fine.setBounds(new Rectangle(199, 324, 146, 26));
			fine.setText("开罚单");
			fine.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
				//	String today=ReturnBook.this.getToday();
					String id=ReturnBook.this.getMember().getText();
					int i=0;
					String  tmp=null;
					ResultSet many;
					String sql="select count(*) as many from penalty";
					many=DataBase.executeQuery(sql);
					String penalnum=null;
					try{
						many.next();
						tmp=(String)many.getString("many");
						penalnum=new Integer(new Integer(tmp).intValue()).toString();
					}catch(Exception ee){
						System.out.println(ee);
					}
					if(ReturnBook.this.getConditionOfBook().getSelectedItem().toString().equals("丢失")){
						i++;
						penalnum=new Integer(new Integer(tmp).intValue()+i).toString();
						String sql1="insert into penalty(ID_Number,if_pay,reason," +
								"penal_number)values('" +id+"',0,'"+"丢失"+"','"+penalnum+
								"')";
						//System.out.println(sql1);
						DataBase.execute(sql1);
						javax.swing.JOptionPane.showMessageDialog(null,"图书馆管理系统\n"+
						"丢失罚单,成功\n");
					}
					if(ReturnBook.this.getConditionOfBook().getSelectedItem().toString().equals("破损")){
						i++;
						penalnum=new Integer(new Integer(tmp).intValue()+i).toString();
						String sql1="insert into penalty(ID_Number,if_pay,reason," +
						"penal_number)values('" +id+"',0,'"+"破损"+"','"+penalnum+
						"')";
						//System.out.println(sql1);
						DataBase.execute(sql1);
						javax.swing.JOptionPane.showMessageDialog(null,"图书馆管理系统\n"+
						"破损罚单,成功\n");
					}
					if(ReturnBook.this.getDelayornot().getSelectedItem().toString().equals("延期")){
						i++;
						penalnum=new Integer(new Integer(tmp).intValue()+i).toString();
						String sql1="insert into penalty(ID_Number,if_pay,reason," +
						"penal_number)values('" +id+"',0,'"+"延期"+"','"+penalnum+
						"')";
						//System.out.println(sql1);
						DataBase.execute(sql1);
						javax.swing.JOptionPane.showMessageDialog(null,"图书馆管理系统\n"+
						"延期罚单,成功\n");
					}
					if(ReturnBook.this.getConditionOfBook().getSelectedItem().toString().equals("正常")){
						javax.swing.JOptionPane.showMessageDialog(null,"图书馆管理系统\n"+
						"书籍完好,不需开罚单 \n");
					}
					if(ReturnBook.this.getDelayornot().getSelectedItem().toString().equals("没有延期")){
						javax.swing.JOptionPane.showMessageDialog(null,"图书馆管理系统\n"+
								"没有延期,不需开延期罚单 \n");
					}
				}
			});
		}
		return fine;
	}

	private String getToday(){
		//返回今天的日期,格式20071221
		String today=null;
		String years, months, days;
		int dayOfMonth,  year, month;
		GregorianCalendar calendar = new GregorianCalendar();
		year = calendar.get(Calendar.YEAR);
		month = calendar.get(Calendar.MONTH)+1;
		dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
		// set the corresponding string values for the present date
		years = new Integer(year).toString();
		months = new Integer(month).toString();
		if (month < 10)
			months = "0" + months;
		days = new Integer(dayOfMonth).toString();
		if (dayOfMonth < 10)
			days = "0" + days;
		today=years+months+days;
		return today;
	}
}  //  @jve:decl-index=0:visual-constraint="10,10"

⌨️ 快捷键说明

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