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

📄 borrow_foundaction.java

📁 一个简单的图书馆的管理系统,该系统主要是针对学校的图书馆而做的
💻 JAVA
字号:
package librarymanagement.action.dialogAction;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.util.Iterator;
import java.util.Vector;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import librarymanagement.dao.Borrow_FoundDao;
import librarymanagement.view.dialog.Borrow_Found;
import librarymanagement.vo.Borrow_FoundVO;

public class Borrow_FoundAction implements ActionListener {

	private Borrow_Found found;
	private Borrow_FoundDao dao = new Borrow_FoundDao();
	private Vector v;
	private JTable table;
	private Borrow_FoundVO vo;
	private JFileChooser fileChooser;

	public Borrow_FoundAction(Borrow_Found found) {
		this.found = found;
	}

	public void actionPerformed(ActionEvent e) {
		String name = e.getActionCommand();
		if (name.equals("查询数据")) {
			if (!(found.getTextReaderID().getText().equals(""))) {
				found.getTextReaderID().setEditable(false);
				table = found.createJTable();
				table.getSelectedRow();
				v = dao.foundInfo(Long.parseLong(found.getTextReaderID()
						.getText()));
				initTable(v, table);
				table.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent e) {
						int ch = e.getClickCount();
						if (ch == 1) {
							int columns = table.getColumnCount();
							int row = table.getSelectedRow();
							String[] data = new String[columns];
							for (int i = 0; i < columns; i++) {
								data[i] = table.getValueAt(row, i).toString();
							}
							initTableUpdate(data);
						}
					}
				});

			} else {
				JOptionPane.showMessageDialog(null, "请输入“读者编号”!!!");
				return;
			}
		}
		if (name.equals("导出数据")) {
			String fileName = null;
			fileChooser = new JFileChooser();
			fileChooser.setCurrentDirectory(new File("."));
			fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
			File file = null;
			if (fileName == null) {
				int result = fileChooser.showSaveDialog(found);
				if (result == JFileChooser.APPROVE_OPTION) {
					file = fileChooser.getSelectedFile();
					fileName = file.getAbsolutePath();
				} else {
					return;
				}
			}

			ExportBorrow_FoundInfo exportAction = new ExportBorrow_FoundInfo();
			String fileNameSave = file.getAbsolutePath() + fileName;
			Vector data = v = dao.foundInfo(Long.parseLong(found
					.getTextReaderID().getText()));// 得到所有员工信息
			v = dao
					.foundInfo(Long
							.parseLong(found.getTextReaderID().getText()));
			exportAction.writeExcelOfFile(fileName, v, null);

			// 记录到数据库中去
//			String content = "导出读者信息信息表 ";
//			JOptionPane.showMessageDialog(null, "已导出到工程目录下,请刷新工程");

		}
		if (name.equals("  重    置 ")) {
			found.getTextReaderID().setEditable(true);
			found.getTextReaderID().setText("");
			found.getTextBackTime().setText("");
			found.getTextBookName().setText("");
			found.getTextBorrowTime().setText("");
			found.getTextReaderName().setText("");
			found.getTextBookID().setText("");
			table = found.createJTable();
			DefaultTableModel model = (DefaultTableModel) table.getModel();
			int rows = model.getRowCount();

			for (int i = rows - 1; i >= 0; i--) {
				model.removeRow(i);
			}
		}
		if (name.equals("  退    出  ")) {
			found.dispose();
		}
	}

	private void initTable(Vector v, JTable table) {

		DefaultTableModel model = (DefaultTableModel) table.getModel();
		int rows = model.getRowCount();
		for (int i = rows - 1; i >= 0; i--) {
			model.removeRow(i);
		}
		Iterator iter = v.iterator();

		while (iter.hasNext()) {
			vo = (Borrow_FoundVO) iter.next();
			found.getTextReaderName().setText(vo.getReader_name().toString());
			found.getTextBookID().setText(vo.getBook_id().toString());
			found.getTextReaderID().setText(String.valueOf(vo.getReader_id()));
			found.getTextBookName().setText(vo.getBook_name().toString());
			found.getTextBackTime().setText(
					vo.getShould_return_date().toString());
			found.getTextBorrowTime().setText(vo.getBorrow_date().toString());
			Object[] data = { new Long(vo.getReader_id()), vo.getReader_name(),
					new Long(vo.getBook_id()), vo.getBook_name(),
					vo.getBorrow_date(), vo.getShould_return_date() };
			model.addRow(data);
		}

	}

	private void initTableUpdate(String[] name) {

		// found.getTextReaderName().setText(name[1]);
		found.getTextBookID().setText(name[2]);
		// found.getTextReaderID().setText(name[0]);
		found.getTextBookName().setText(name[3]);
		found.getTextBackTime().setText(name[5]);
		found.getTextBorrowTime().setText(name[4]);

	}

}

⌨️ 快捷键说明

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