📄 people.java
字号:
DataBase db=new DataBase();
db.GetResultSet("select * from 人才登记 ");
int cout=0;
try
{
while(db.rs.next())
{
cout++;
if(db.rs.getString(1).equalsIgnoreCase(s))
break;
}
pane.removeAll();
pane.setLayout(new BorderLayout());
pane.add(barPeople,BorderLayout.WEST);
pane.add(panePeople,BorderLayout.CENTER);
getinfo(cout);
pane.setVisible(false);
pane.setVisible(true);
}catch(SQLException e){}
}
}catch(Exception e){}
}
public void mousePressed(MouseEvent parm1)
{
if(parm1.getSource()==lblImage)
{
chooser=new JFileChooser();
JFrame ff=new JFrame();
int result=chooser.showDialog(ff,"文件选择");
File file=chooser.getSelectedFile();
String s=file.toString();
ImageIcon ico=new ImageIcon(s);
lblImage.setIcon(ico);
}
//首条记录
if(parm1.getSource()==lblTool[0])
getinfo(1);
//末条记录
if(parm1.getSource()==lblTool[1])
{
try
{
String s=txtPeople[0].getText().trim();
DataBase db=new DataBase();
db.GetResultSet("select * from 人才登记");
int cout=0;
while(db.rs.next())
{
cout++;
}
getinfo(cout);
db.st.close();
}catch(SQLException e){}
}
//前条记录
if(parm1.getSource()==lblTool[2])
{
try
{
String s=txtPeople[0].getText().trim();
DataBase db=new DataBase();
db.GetResultSet("select * from 人才登记");
int cout=0;
while(db.rs.next())
{
cout++;
if(db.rs.getString(1).trim().equalsIgnoreCase(s)==true)
break;
}
getinfo(cout-1);
db.st.close();
}catch(SQLException e){}
}
//后条记录
if(parm1.getSource()==lblTool[3])
{
try
{
String s=txtPeople[0].getText().trim();
DataBase db=new DataBase();
db.GetResultSet("select * from 人才登记");
int cout=0;
while(db.rs.next())
{
cout++;
if(db.rs.getString(1).trim().equalsIgnoreCase(s)==true)
break;
}
getinfo(cout+1);
}catch(SQLException e){}
}
//新增记录
if(parm1.getSource()==lblTool[4])
{
clear();
}
//保存记录
if(parm1.getSource()==lblTool[5])
{
int flag=1;
int op=JOptionPane.showConfirmDialog(null,"确定要添加这条记录吗?","提示",JOptionPane.YES_NO_OPTION);
if(op==JOptionPane.YES_OPTION)
{
try
{
DataBase db=new DataBase();
db.GetResultSet("select * from 人才登记");
db.rs.moveToInsertRow();
for(int i=0;i<16;i++)
db.rs.updateString(db.rsmd.getColumnName(i+1),txtPeople[i].getText().trim());
for(int i=0;i<4;i++)
db.rs.updateString(db.rsmd.getColumnCount()-4+i,areaPeople[i].getText().trim());
String str=lblImage.getIcon().toString();
db.rs.updateString(db.rsmd.getColumnCount(),str);
db.rs.insertRow();
db.st.close();
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null,"单位编号重复");
txtPeople[0].setText("");
flag=0;
}
if(flag==1)
{
JOptionPane.showMessageDialog(null,"记录添加成功!!!","提示",JOptionPane.WARNING_MESSAGE);
}
}
else
JOptionPane.showMessageDialog(null,"该记录添加失败!!!","警告",JOptionPane.WARNING_MESSAGE);
}
//更新记录
if(parm1.getSource()==lblTool[6])
{
int op=JOptionPane.showConfirmDialog(null,"确定要更新这条记录吗?","提示",JOptionPane.YES_NO_OPTION);
if(op==JOptionPane.YES_OPTION)
{
try
{
String s=txtPeople[0].getText().trim();
DataBase db=new DataBase();
db.GetResultSet("select * from 人才登记 where 编号 = '"+s+"'");
db.rs.next();
for(int i=0;i<16;i++)
db.rs.updateString(db.rsmd.getColumnName(i+1),txtPeople[i].getText().trim());
for(int i=0;i<4;i++)
db.rs.updateString(db.rsmd.getColumnCount()-4+i,areaPeople[i].getText().trim());
String str=lblImage.getIcon().toString();
db.rs.updateString(db.rsmd.getColumnCount(),str);
db.rs.updateRow();
db.st.close();
}catch(Exception e){}
JOptionPane.showMessageDialog(null,"记录已经更新!!!");
}
else
JOptionPane.showMessageDialog(null,"记录更新失败!!!");
}
//删除记录
if(parm1.getSource()==lblTool[7])
{
int op=JOptionPane.showConfirmDialog(null,"确定要删除这条记录吗?","提示",JOptionPane.YES_NO_OPTION);
if(op==JOptionPane.YES_OPTION)
{
try
{
String s=txtPeople[0].getText().trim();
DataBase db=new DataBase();
db.GetResultSet("select * from 人才登记");
db.st.execute("delete from 人才登记 where 编号 = "+"'"+s+"'");
db.st.close();
}catch(Exception e){}
clear();
JOptionPane.showMessageDialog(null,"该记录已经删除!!!","提示",JOptionPane.WARNING_MESSAGE);
}
else
JOptionPane.showMessageDialog(null,"该记录删除失败!!!","警告",JOptionPane.WARNING_MESSAGE);
}
//更多条件
if(parm1.getSource()==lblMore)
{
pane.removeAll();
pane.add(paneTable,BorderLayout.CENTER);
pane.setVisible(false);
pane.setVisible(true);
}
//返回标签
if(parm1.getSource()==lblBack)
{
pane.removeAll();
pane.setLayout(new BorderLayout());
pane.add(barPeople,BorderLayout.WEST);
pane.add(panePeople,BorderLayout.CENTER);
getinfo(1);
pane.setVisible(false);
pane.setVisible(true);
}
}
public void mouseReleased(MouseEvent parm1) {
// TODO: Add your code here
}
public void mouseEntered(MouseEvent parm1)
{
//工具条鼠标进入事件
for(int i=0;i<8;i++)
{
if(parm1.getSource()==lblTool[i])
{
lblTool[i].setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.red));
}
}
if(parm1.getSource()==lblMore)
{
lblMore.setForeground(Color.red);
}
if(parm1.getSource()==lblBack)
{
lblBack.setBorder(BorderFactory.createMatteBorder(0,0,1,0,Color.blue));
}
}
public void mouseExited(MouseEvent parm1)
{
//工具条鼠标离开事件
for(int i=0;i<8;i++)
{
if(parm1.getSource()==lblTool[i])
lblTool[i].setBorder(null);
}
if(parm1.getSource()==lblMore)
{
lblMore.setForeground(Color.blue);
}
if(parm1.getSource()==lblBack)
{
lblBack.setBorder(null);
}
}
public void insertUpdate(DocumentEvent parm1)
{
//简单查询
if(parm1.getDocument()==txtSimple.getDocument())
{
try
{
String s1=choiceSimple.getSelectedItem().trim();
String s2=txtSimple.getText().trim();
DataBase db=new DataBase();
db.GetResultSet("select * from 人才登记 where "+s1+" like "+"'%"+s2+"%'");
db.rs.next();
for(int i=0;i<db.rsmd.getColumnCount()-4;i++)
txtPeople[i].setText(db.rs.getString(i+1));
for(int i=0;i<4;i++)
areaPeople[i].setText(db.rs.getString(db.rsmd.getColumnCount()-4+i));
String s=db.rs.getString(db.rsmd.getColumnCount());
ImageIcon ico=new ImageIcon(s);
lblImage.setIcon(ico);
db.st.close();
}
catch(SQLException e){}
}
//////////一级查询
if(parm1.getDocument()==txtTable[0].getDocument())
{
String s1=choice[0].getSelectedItem().trim();
String s2=txtTable[0].getText().trim();
getmodel("select * from 人才登记 where "+s1+" like"+" '%"+s2+"%'",0);
lockMore.tableOne.setModel(model);
getmodel("select * from 人才登记 where "+s1+" like"+" '%"+s2+"%'",3);
lockMore.tableTwo.setModel(model);
}
//////////二级查询
if(parm1.getDocument()==txtTable[1].getDocument())
{
String s1=choice[0].getSelectedItem().trim();
String s2=txtTable[0].getText().trim();
String s3=choice[1].getSelectedItem().trim();
String s4=choice[2].getSelectedItem().trim();
String s5=txtTable[1].getText();
getmodel("select * from 人才登记 where "+s1+" like"+" '%"+s2+"%' "+s3+" "+s4+" like"+" '%"+s5+"%' ",0);
lockMore.tableOne.setModel(model);
getmodel("select * from 人才登记 where "+s1+" like"+" '%"+s2+"%' "+s3+" "+s4+" like"+" '%"+s5+"%' ",3);
lockMore.tableTwo.setModel(model);
}
}
public void removeUpdate(DocumentEvent parm1)
{
//简单查询
if(parm1.getDocument()==txtSimple.getDocument())
{
try
{
String s1=choiceSimple.getSelectedItem().trim();
String s2=txtSimple.getText().trim();
DataBase db=new DataBase();
db.GetResultSet("select * from 人才登记 where "+s1+" like "+"'%"+s2+"%'");
db.rs.next();
for(int i=0;i<db.rsmd.getColumnCount()-4;i++)
txtPeople[i].setText(db.rs.getString(i+1));
for(int i=0;i<4;i++)
areaPeople[i].setText(db.rs.getString(db.rsmd.getColumnCount()-4+i));
String s=db.rs.getString(db.rsmd.getColumnCount());
ImageIcon ico=new ImageIcon(s);
lblImage.setIcon(ico);
db.st.close();
}
catch(SQLException e){}
}
//////////一级查询
if(parm1.getDocument()==txtTable[0].getDocument())
{
String s1=choice[0].getSelectedItem().trim();
String s2=txtTable[0].getText().trim();
getmodel("select * from 人才登记 where "+s1+" like"+" '%"+s2+"%'",0);
lockMore.tableOne.setModel(model);
getmodel("select * from 人才登记 where "+s1+" like"+" '%"+s2+"%'",3);
lockMore.tableTwo.setModel(model);
}
//////////二级查询
if(parm1.getDocument()==txtTable[1].getDocument())
{
String s1=choice[0].getSelectedItem().trim();
String s2=txtTable[0].getText().trim();
String s3=choice[1].getSelectedItem().trim();
String s4=choice[2].getSelectedItem().trim();
String s5=txtTable[1].getText();
getmodel("select * from 人才登记 where "+s1+" like"+" '%"+s2+"%' "+s3+" "+s4+" like"+" '%"+s5+"%' ",0);
lockMore.tableOne.setModel(model);
getmodel("select * from 人才登记 where "+s1+" like"+" '%"+s2+"%' "+s3+" "+s4+" like"+" '%"+s5+"%' ",3);
lockMore.tableTwo.setModel(model);
}
}
public void changedUpdate(DocumentEvent parm1) {
// TODO: Add your code here
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -