📄 storelacionaction.java
字号:
package librarymanagement.action.dialogAction;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import librarymanagement.dao.StoreLactionDao;
import librarymanagement.dao.common.DbException;
import librarymanagement.view.dialog.StoreLocation;
import librarymanagement.vo.StoreLactionVO;
public class StoreLacionAction implements ActionListener {
/**
* 书籍存放位置设置
*
* @author 陈兵
*/
private StoreLocation store;
private JTable table;
private Vector v;
private StoreLactionDao dao = new StoreLactionDao();
private StoreLactionVO vo;
// 定义一个构造用来获来StoreLocation的一个实例
public StoreLacionAction(StoreLocation store) {
this.store = store;
}
public void actionPerformed(ActionEvent e) {
String name = e.getActionCommand();
if (name.equals("添加")) {
common();
try {
dao.addDateBase(vo);
store.getReading_roomText().setText("");
store.getBookInformationText().setText("");
store.getBookStoreText().setText("");
store.getBookClassText().setText("");
} catch (DbException e1) {
JOptionPane.showConfirmDialog(null, e1.getMessage(), "异常提示",
JOptionPane.YES_OPTION);
}
}
if (name.equals("搜索")) {
if (!((store.getBookStoreText().getText().equals("") && store
.getReading_roomText().equals("")))) {
table = store.createTable();
DefaultTableModel model = (DefaultTableModel) table.getModel();
int rows = model.getRowCount();
for (int i = rows - 1; i >= 0; i--) {
model.removeRow(i);
}
}
try {
if (store.getBookClassText().getText().equals("")
&& store.getBookInformationText().getText().equals("")) {
v = dao.foundDate1(store.getReading_roomText().getText()
.trim(), store.getBookStoreText().getText().trim());
JTable table = store.createTable();
initiaJTableValues(table, v);
}
if (store.getReading_roomText().getText().trim().equals("")
&& store.getBookStoreText().getText().trim().equals("")) {
v = dao.foundDate2(store.getBookClassText().getText()
.trim(), store.getBookInformationText().getText()
.trim());
table = store.createTable();
initiaJTableValues(table, v);
}
} catch (DbException e1) {
JOptionPane.showConfirmDialog(null, e1.getMessage(), "异常提示",
JOptionPane.YES_OPTION);
}
}
if (name.equals("帮助")) {
JOptionPane.showMessageDialog(null,
"当你搜索信息:书籍存放位置和阅览室名称必须同时填上,但此时书籍名称和书籍类型必须为空\n"
+ "或者书籍名称和书籍类型必须同时填上,但此时书籍存放位置和阅览室名称必须为空"
+ "\n这样才能进行正常搜索\n当你进行删除操作:\n注意是删除一个或多个存放位置,而不是书籍!",
"帮助信息", 1);
}
if (name.equals("修改")) {
table = store.createTable();
int row = table.getSelectedRow();
if (row < 0) {
JOptionPane.showMessageDialog(null, "请先搜索出你要修改的信息");
} else {
DefaultTableModel model = (DefaultTableModel) table.getModel();
int rows = model.getRowCount();
for (int i = rows - 1; i >= 0; i--) {
model.removeRow(i);
}
common();
try {
dao.changeDate(vo);
} catch (DbException e1) {
JOptionPane.showConfirmDialog(null, e1.getMessage(),
"异常提示", JOptionPane.YES_OPTION);
}
}
}
if (name.equals("删除")) {
table = store.createTable();
int row = table.getSelectedRow();
if (row < 0) {
JOptionPane.showMessageDialog(null, "请先搜索出你要删除的信息");
} else {
try {
int ch = JOptionPane.showConfirmDialog(null,
"您确认要删除这条记录吗?", "删除提示", JOptionPane.YES_NO_OPTION);
if (ch == JOptionPane.YES_OPTION) {
dao.deleteLocation(table.getValueAt(row, 1).toString());
DefaultTableModel model = (DefaultTableModel) table
.getModel();
int rows = model.getRowCount();
model.removeRow(row);
} else {
return;
}
} catch (DbException e1) {
JOptionPane.showConfirmDialog(null, e1.getMessage(),
"异常提示", JOptionPane.YES_OPTION);
}
}
}
if (name.equals("退出")) {
store.dispose();
}
}
public void foundLocation() {
}
public void initiaJTableValues(JTable table, Vector v) {
table = store.createTable();
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()) {
StoreLactionVO vo = (StoreLactionVO) iter.next();
Object[] data = { vo.getReading_room(), vo.getBookLocation(),
vo.getBookInformation(), vo.getBookClass() };
model.addRow(data);
}
}
public void common() {
vo = new StoreLactionVO();
vo.setReading_room(store.getReading_roomText().getText().toString());
vo.setBookInformation(store.getBookInformationText().getText()
.toString());
vo.setBookLocation(store.getBookStoreText().getText().toString());
vo.setBookClass(store.getBookClassText().getText().toString());
table = store.createTable();
DefaultTableModel model = (DefaultTableModel) table.getModel();
Object[] data = { vo.getReading_room(), vo.getBookLocation(),
vo.getBookInformation(), vo.getBookClass() };
model.addRow(data);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -