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

📄 bookmanage.java

📁 基于javaSwing的图书馆信息管理系统 使用oracle数据库连接
💻 JAVA
📖 第 1 页 / 共 5 页
字号:

			jTable_book.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mousePressed(java.awt.event.MouseEvent e) {

					String[] value1 = getJTableValue();
					// 选择一条记录时,确定此图书的可借数量和库存数量 是否一样,相同说明此图书可删除
					// if (value1[9].equals(value1[8])
					if (Integer.valueOf(value1[9]) <= Integer
							.valueOf(value1[8])) {
						deleteable = true;
						// System.out.print("此图书可删除--");
					} else {
						deleteable = false;
						// System.out.print("此图书不可删除--");
					}
					// 并保存此书 已借出数量
					borrowedNum = Integer.valueOf(value1[9])
							- Integer.valueOf(value1[8]);
					jTextField_borrowedNum.setText(borrowedNum.toString());
					// System.out.println("此图书已借出数量是" + borrowedNum);

					jTextField_isbn.setText(value1[0]);
					jTextField_author.setText(value1[2]);
					jTextField_book.setText(value1[1]);
					jTextField_unitprice.setText(value1[7]);
					jTextField_stocks.setText(value1[9]);
					jTextField_fine.setText(value1[10]);
					jTextField_copies.setText(value1[8]);
					getJComboBox_publisher().setSelectedItem(value1[5]);
					getJComboBox_category().setSelectedItem(value1[3]);

					if (!value1[11].toString().equals("1")) {
						getJCheckBox_isnew().setSelected(false);
					} else {
						getJCheckBox_isnew().setSelected(true);
					}

				}
			});
		}
		return jTable_book;
	}

	int row = 0;

	private JToolBar jToolBar_control = null;

	private JButton jButton_clear = null;

	private JButton jButton_add = null;

	private JButton jButton_edit = null;

	private JButton jButton_del = null;

	public String[] getJTableValue() {
		row = getJTable_book().getSelectedRow();
		// System.out.println("row " + row);
		int columns = getJTable_book().getColumnCount();
		String[] data = new String[12];
		data[0] = getJTable_book().getValueAt(row, 0).toString();

		Iterator iter = BookOper.query(data[0]).iterator();
		while (iter.hasNext()) {
			Book value = (Book) iter.next();
			data[1] = value.getBook();
			data[2] = value.getAuthor();
			data[3] = value.getCategory();
			data[4] = value.getCategory_id();
			data[5] = value.getPublisher();
			data[6] = value.getPublisher_id();
			data[7] = String.valueOf(value.getUnitprice());
			data[8] = String.valueOf(value.getCopies());
			data[9] = String.valueOf(value.getStocks());
			data[10] = String.valueOf(value.getFine());
			data[11] = value.getIsNew();

		}
		return data;
	}

	// 选择一条借阅者所借的图书时,记录下信息
	// ---用detail值对象更好!!!!
	public Detail getMyTableValue() {
		Detail detail = null;
		row = getJTable_mybook().getSelectedRow();
		// System.out.println("row " + row);
		int columns = getJTable_mybook().getColumnCount();

		// "流水号", "书名","借阅日期", "是否续借", "续借日期", "是否已归还","归还日期", "须交罚金"}
		// ---Object[] data = new Object[columns];
		String detail_id = getJTable_mybook().getValueAt(row, 0).toString();

		Iterator iter = DetailOper.getInfo(3, detail_id).iterator();
		while (iter.hasNext()) {
			detail = (Detail) iter.next();
			// 须交罚金 用 界面显示值.......
			Float fine = Float.valueOf((getJTable_mybook().getValueAt(row,
					columns - 1)).toString());
			detail.setFine(fine);
			/*
			 * //.......好像在绕弯!!!! Detail value = (Detail) iter.next(); String
			 * book = value.getBook(); String isbn = value.getIsbn(); String
			 * borrower_id = value.getBorrower_id(); // String borrower =
			 * value.getBorrower(); String borrower = Login.BORR.getBorrower();
			 * Date borrow_date = value.getBorrow_date(); String isRenew =
			 * value.getIsRenew(); Date renew_date = value.getRenew_date();
			 * String isReturn = value.getIsReturn(); Date return_date =
			 * value.getReturn_date(); // 须交罚金 用 界面显示值....... Float fine =
			 * Float.valueOf((getJTable_mybook().getValueAt(row, columns -
			 * 1)).toString()); detail = new Detail(detail_id, borrower_id,
			 * isbn, borrow_date, isRenew, renew_date, isReturn, return_date,
			 * fine, borrower, book);
			 */
		}

		return detail;
	}

	/**
	 * This method initializes jComboBox_category
	 * 
	 * @return javax.swing.JComboBox
	 */
	private JComboBox getJComboBox_category() {
		if (jComboBox_category == null) {
			jComboBox_category = new JComboBox();
			Iterator ter = new CategoryOper().getInfo().iterator();
			while (ter.hasNext()) {
				Category c = (Category) ter.next();
				String ca = c.getCategory();
				jComboBox_category.addItem(ca);
			}
		}
		return jComboBox_category;
	}

	/**
	 * This method initializes jComboBox_publisher
	 * 
	 * @return javax.swing.JComboBox
	 */
	private JComboBox getJComboBox_publisher() {
		if (jComboBox_publisher == null) {
			jComboBox_publisher = new JComboBox();
			Iterator ter = new PublisherOper().getInfo().iterator();
			while (ter.hasNext()) {
				Publisher c = (Publisher) ter.next();
				String pu = c.getPublisher();
				jComboBox_publisher.addItem(pu);
			}
		}
		return jComboBox_publisher;
	}

	/**
	 * This method initializes jToolBar1
	 * 
	 * @return javax.swing.JToolBar
	 */
	private JToolBar getJToolBar_control() {
		if (jToolBar_control == null) {
			jToolBar_control = new JToolBar();
			jToolBar_control.setFloatable(false);
			jToolBar_control.add(getJButton_clear());
			jToolBar_control.add(getJButton_add());
			jToolBar_control.add(getJButton_edit());
			jToolBar_control.add(getJButton_del());
		}
		return jToolBar_control;
	}

	/**
	 * This method initializes jButton
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJButton_clear() {
		if (jButton_clear == null) {
			jButton_clear = new JButton();
			jButton_clear.setIcon(new ImageIcon("E:/img/standard_094_20.png"));
			jButton_clear.setText("清空");
			jButton_clear
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(java.awt.event.ActionEvent e) {
							getJTextField_book().setText(null);
							getJTextField_isbn().setText(null);
							getJTextField_author().setText(null);
							getJTextField_unitprice().setText(null);
							getJTextField_copies().setText(null);
							getJTextField_stocks().setText(null);
							getJTextField_fine().setText(null);
							getJTextField_borrowedNum().setText(null);

							getJComboBox_publisher().setSelectedIndex(-1);
							getJComboBox_category().setSelectedIndex(-1);

							getJCheckBox_isnew().setSelected(false);
						}
					});
		}
		return jButton_clear;
	}

	/**
	 * This method initializes jButton1
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJButton_add() {
		if (jButton_add == null) {
			jButton_add = new JButton();
			jButton_add.setToolTipText("添加一条新的图书信息");
			jButton_add.setIcon(new ImageIcon("E:/img/standard_159_20.png"));
			jButton_add.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					Book value = getIputText();
					System.out.println(value);
					int ch = JOptionPane.showConfirmDialog(null,
							"你真的要添加该纪录?(自动设置为新书,可借数量设为库存数量)", "添加数据",
							JOptionPane.YES_NO_OPTION);
					if (ch == JOptionPane.YES_OPTION) {
						if (BookOper.add(value)) {
							JOptionPane.showMessageDialog(null, "添加成功");
							search(0);
						} else {
							JOptionPane.showMessageDialog(null, "添加失败!");
						}
					}
				}
			});
		}
		return jButton_add;
	}

	private Book b;

	private JToolBar jToolBar_borrowedNum = null;

	private JLabel jLabel_borrowedNum = null;

	private JTextField jTextField_borrowedNum = null;

	private JPanel jPanel_info = null;

	private JToggleButton jToggleButton_new = null;

	private JLabel jLabel_pagination = null;

	private JButton jButton_borrow = null;

	private JButton jButton_return = null;

	private JButton jButton_renew = null;

	private JTabbedPane jTabbedPane = null;

	private JPanel jPanel_mybook = null;

	private JScrollPane jScrollPane_mybook = null;

	private JPanel jPanel_book = null;

	private JPanel jPanel_info2 = null;

	private JTable jTable_mybook = null;

	private JTextField jTextField_tip = null;

	private Book getIputText() {
		String isbn = getJTextField_isbn().getText().trim();
		String author = getJTextField_author().getText().trim();
		String book = getJTextField_book().getText().trim();

		// 下面的字符串要修改整型或实型
		String unitpriceS = getJTextField_unitprice().getText().trim();
		String copiesS = getJTextField_copies().getText().trim();
		String stocksS = getJTextField_stocks().getText().trim();
		String fineS = getJTextField_fine().getText().trim();

		Float unitprice = 0f;
		Integer copies = 0;
		Integer stocks = 0;
		Float fine = 0f;
		if (!unitpriceS.isEmpty())
			unitprice = Float.valueOf(unitpriceS);
		if (!copiesS.isEmpty())
			copies = Integer.valueOf(copiesS);
		if (!stocksS.isEmpty())
			stocks = Integer.valueOf(stocksS);
		if (!fineS.isEmpty())
			fine = Float.valueOf(fineS);

		// 类型和出版社是复合框
		String category = (String) getJComboBox_category().getSelectedItem();
		String publisher = (String) getJComboBox_publisher().getSelectedItem();

		String category_id = CategoryOper.getId(category);
		String publisher_id = PublisherOper.getId(publisher);
		// System.out.println(category + " " +category_id+ " " +publisher+ " "
		// +publisher_id);
		String isNew = "";
		if (getJCheckBox_isnew().isSelected()) {
			isNew = "1";
		}
		b = new Book(isbn, book, author, category_id, publisher_id, unitprice,
				copies, stocks, fine, isNew, category, publisher);
		return b;
	}

	// 检查编号文本框是否为空,说明是否已选择了一条记录
	// ture 表明通过
	// false表明未选择
	private boolean checkEmpty() {
		String id = getJTextField_isbn().getText().trim();
		if (id.isEmpty()) {
			JOptionPane.showMessageDialog(null, "请选择一条图书记录来进行操作!!");
			return false;
		}
		return true;
	}

	// 不能设置 库存数量 比 已借出数量 小
	private boolean checkStocks() {
		Integer stocks = Integer.valueOf(getJTextField_stocks().getText());
		System.out.println("此图书已借出" + borrowedNum + "本,总库存数量是" + stocks);
		if (borrowedNum > stocks) {
			JOptionPane.showMessageDialog(null, "此图书已借出" + borrowedNum
					+ "本,总库存数量不能小于" + borrowedNum);
			return false;
		}
		return true;
	}

	// 检查借阅人是否还可借书
	// .........
	private boolean checkFree() {
		int free = 0;
		int tmp = 5;
		if (Login.BORR.getIsStudent().equals("1")) {
			free = 5 - Login.BORR.getBorrow_num();
		} else {
			free = 10 - Login.BORR.getBorrow_num();
			tmp = 10;
		}
		if (free <= 0) {
			JOptionPane.showMessageDialog(null, "你已经借满了" + tmp + "本书!!");
			return false;
		}
		return true;
	}

	// 检查借阅人是否有图书已过期
	private boolean checkOutDate() {
		if (outDate) {
			JOptionPane.showMessageDialog(null, "你有图书已过借阅期限,请先还书并交罚金再借书!");
			return false;
		} else {
			return true;
		}
	}

	// 续借过的书归还后,有5天不能再次续借,作为续借缓冲期(供其他有需要的借阅者借阅)
	// 续借过的书 未归还,也不能再借此书
	private boolean checkRenewed() {
		Date activeDate = DetailOper.getActiveDate(getJTextField_isbn()
				.getText().trim(), Login.BORR.getBorrower_id());
		if (activeDate != null) {
			JOptionPane.showMessageDialog(null, "你已续借过此书,5天内不可再借!请于"
					+ activeDate + "后再借此书.");
			return false;
		} else if (DetailOper.isRenewed(getJTextField_isbn().getText().trim(),
				Login.BORR.getBorrower_id(), up)) {
			JOptionPane.showMessageDialog(null, "你已续借了此书,不可再借!");
			return false;
		} else {
			return true;
		}
	}

	/**
	 * This method initializes jButton2
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getJButton_edit() {
		if (jButton_edit == null) {
			jButton_edit = new JButton();
			jButton_edit.setIcon(new ImageIcon("E:/img/standard_138_20.png"));
			jButton_edit.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					// 检查所选书中
					// 库存数量 不比 已借出数量 小
					if (checkEmpty() && checkStocks()) {
						int ch = JOptionPane
								.showConfirmDialog(null, "你真的要修改该纪录?", "修改数据",
										JOptionPane.YES_NO_OPTION);
						if (ch == JOptionPane.YES_OPTION) {
							Book value = getIputText();
							if (BookOper.update(borrowedNum, value)) {
								JOptionPane.showMessageDialog(null, "修改成功");
								search(0);
								// 修改后,还须再刷新可借数
								Integer copies = Integer
										.valueOf(getJTextField_stocks()
												.getText())

⌨️ 快捷键说明

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