/*
添加按钮功能
*/
private class AddAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e){
new AddView();
}
}
/*
修改按钮功能
*/
private class ModifyAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e){
int row = table.getSelectedRow();
String id = (String) table.getValueAt(row,0);
String name = (String) table.getValueAt(row,1);
String location = (String) table.getValueAt(row,2);
String baoFei = (String) table.getValueAt(row,3);
String buyTime = (String) table.getValueAt(row,4);
String baoFeiTime = (String) table.getValueAt(row,5);
String record = (String) table.getValueAt(row,6);
// 构造设备对象
Equ equ = new Equ(id,name,location,baoFei,buyTime,baoFeiTime,record);
// 打开修改页面
new ModifyView(equ);
}
}
/*
删除按钮功能
*/
private class DeleteAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e){
int [] rows = table.getSelectedRows();
String[] ids = new String[rows.length];
// 获取选中行设备的ID
for(int i = 0;i < rows.length;i++) {
ids = (String) table.getValueAt(rows,0);
}
System.out.println("选中行的编号为:" + Arrays.toString(ids));
int msg = JOptionPane.showConfirmDialog(null,
"请确认是否删除编号为" + Arrays.toString(ids) + "的设备?",
"确认删除",JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
System.out.println(msg);
if (msg == 0){
for (String id:ids){
SqliteDb.deleteEqu(id);
}
refreshTable(table,SqliteDb.queryAll());
JOptionPane.showMessageDialog(null,"删除完毕");
}
}
}
/*
搜素按钮功能
*/
private class SearchAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e){
java.util.List<Equ> equs = new ArrayList<>();
String temp = searchText.getText(); // 获取输入的内容
// 如果输入的内容为空,全量搜素
if(temp == null || temp.equals("") ){
SqliteDb.queryAll();
}else{
// 否则,根据名字搜素
equs = SqliteDb.queryByName(temp);
}
// 搜素的结果刷新到表格中
refreshTable(table,equs);
// 清空搜素框
searchText.setText("");
}
}
}
|