📄 searchdoctorinfo.java~4~
字号:
package cliniquemanager;
import java.awt.BorderLayout;
import java.awt.Frame;
import javax.swing.JDialog;
import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JScrollPane;
import javax.swing.JPopupMenu;
import java.awt.Rectangle;
import javax.swing.JTable;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.table.DefaultTableModel;
import javax.swing.ListSelectionModel;
import java.util.Vector;
import javax.swing.JOptionPane;
import java.sql.ResultSet;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* <p>Title: CliniqueManager</p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: shine</p>
*
* @author robin
* @version 1.0
*/
public class SearchDoctorInfo extends JDialog {
Database db;
ResultSet rs;
DefaultTableModel tableModel;
String sql;
public SearchDoctorInfo(Frame owner, String title, boolean modal) {
super(owner, title, modal);
try {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jbInit();
pack();
} catch (Exception exception) {
exception.printStackTrace();
}
}
public SearchDoctorInfo() {
this(new Frame(), "SearchDoctorInfo", false);
}
private void jbInit() throws Exception {
this.setSize(new Dimension(800, 600));
this.setPreferredSize(new Dimension(800, 600));
this.getContentPane().setLayout(null);
btnAll.setBounds(new Rectangle(382, 479, 104, 29));
btnAll.setText("显示全部");
btnAll.addActionListener(new SearchDoctorInfo_btnAll_actionAdapter(this));
btnExit.setBounds(new Rectangle(506, 479, 104, 29));
btnExit.setText("退出");
btnExit.addActionListener(new SearchDoctorInfo_btnExit_actionAdapter(this));
btnSearch1.setBounds(new Rectangle(128, 479, 104, 29));
btnSearch1.setText("精确查询");
btnSearch1.addActionListener(new
SearchDoctorInfo_btnSearch1_actionAdapter(this));
txtName.setBounds(new Rectangle(100, 417, 163, 26));
txtProfession.setBounds(new Rectangle(492, 417, 185, 26));
lblProdession.setText("医生专业:");
lblProdession.setBounds(new Rectangle(417, 409, 102, 42));
btnSearch2.setBounds(new Rectangle(257, 479, 103, 29));
btnSearch2.setText("模糊查询");
btnSearch2.addActionListener(new
SearchDoctorInfo_btnSearch2_actionAdapter(this));
jLabel1.setText("提示:若知道医生的姓名或专业,则输入后点按钮“精确查询”,若只知道其中的部分,则输入后点按钮“模糊查询”");
jLabel1.setBounds(new Rectangle(0, 0, 667, 40));
this.getContentPane().add(btnSearch1);
this.getContentPane().add(btnExit);
this.getContentPane().add(btnAll);
this.getContentPane().add(lblName);
this.getContentPane().add(txtName);
this.getContentPane().add(tblDoctor);
this.getContentPane().add(btnSearch2);
this.getContentPane().add(lblProdession);
this.getContentPane().add(txtProfession);
this.getContentPane().add(jLabel1);
lblName.setText("医生姓名:");
lblName.setBounds(new Rectangle(15, 414, 74, 30));
sql="select * from doctor";
search(sql);
}
JTable tblDoctor = new JTable();
JLabel lblName = new JLabel();
JLabel lblProdession = new JLabel();
JLabel jLabel1=new JLabel();
JTextField txtProfession = new JTextField();
JTextField txtName = new JTextField();
JButton btnSearch1 = new JButton();
JButton btnExit = new JButton();
JButton btnAll = new JButton();
JScrollPane jsp ;
JButton btnSearch2 = new JButton();
public void search(String sql){
Vector cell;
Vector row=new Vector();
tableModel = new DefaultTableModel();
tableModel = new DefaultTableModel();
db=new Database();
try{
String[] tableHeads = {"用户名","真实姓名", "专业","电话","Email"};
Vector tableHeadName = new Vector();
for (int i = 0; i < tableHeads.length; i++) {
tableHeadName.add(tableHeads[i]);
}
db=new Database();
rs=db.getResultSet(sql);
while(rs.next()){
cell = new Vector();
cell.add(rs.getString("username"));
cell.add(rs.getString("name"));
cell.add(rs.getString("profession"));
cell.add(""+rs.getInt("phone"));
cell.add(rs.getString("email"));
row.add(cell);
}
/*设置表格模型*/
tableModel.setDataVector(row,tableHeadName);
/*表格使用模型*/
tblDoctor = new JTable(tableModel);
//设置行的选择模式,一次只能选择一行
tblDoctor.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jsp=new JScrollPane(tblDoctor);
jsp.setBounds(new Rectangle(8, 5, 766, 395));
this.add(jsp);
db.close();
}catch(Exception e1){
JOptionPane.showMessageDialog(null,e1,"系统提示",JOptionPane.ERROR_MESSAGE);
}
}
public void btnSearch1_actionPerformed(ActionEvent e) {
if (txtName.getText().equals("") && txtProfession.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入查询信息");
return;
}
if(txtName.getText().equals(""))
sql = "select * from manager where profession='" + txtProfession.getText() + "'";
else if(txtProfession.getText().equals(""))
sql = "select * from manager where name='" + txtName.getText() + "'";
else
sql = "select * from manager where name='" + txtName.getText() + "',profession='" + txtProfession.getText() + "'";
search(sql);
txtName.setText("");
txtProfession.setText("");
}
public void btnSearch2_actionPerformed(ActionEvent e) {
if (txtName.getText().equals("") && txtProfession.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入查询信息");
return;
}
if(txtName.getText().equals(""))
sql = "select * from manager where profession like '%" + txtProfession.getText() + "%'";
else if(txtProfession.getText().equals(""))
sql = "select * from manager where name like '%" + txtName.getText() + "%'";
else
sql = "select * from manager where name like '%" + txtName.getText() + "%',profession like '%" + txtProfession.getText() + "%'";
search(sql);
txtName.setText("");
txtProfession.setText("");
}
public void btnAll_actionPerformed(ActionEvent e) {
sql="select * from doctor";
search(sql);
}
public void btnExit_actionPerformed(ActionEvent e) {
this.dispose();
}
}
class SearchDoctorInfo_btnExit_actionAdapter implements ActionListener {
private SearchDoctorInfo adaptee;
SearchDoctorInfo_btnExit_actionAdapter(SearchDoctorInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnExit_actionPerformed(e);
}
}
class SearchDoctorInfo_btnAll_actionAdapter implements ActionListener {
private SearchDoctorInfo adaptee;
SearchDoctorInfo_btnAll_actionAdapter(SearchDoctorInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnAll_actionPerformed(e);
}
}
class SearchDoctorInfo_btnSearch2_actionAdapter implements ActionListener {
private SearchDoctorInfo adaptee;
SearchDoctorInfo_btnSearch2_actionAdapter(SearchDoctorInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnSearch2_actionPerformed(e);
}
}
class SearchDoctorInfo_btnSearch1_actionAdapter implements ActionListener {
private SearchDoctorInfo adaptee;
SearchDoctorInfo_btnSearch1_actionAdapter(SearchDoctorInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnSearch1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -