📄 srchmanagerinfo.java
字号:
package cliniquemanager;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import com.borland.dx.sql.dataset.Database;
import com.borland.dx.sql.dataset.QueryDataSet;
import com.borland.dx.sql.dataset.ConnectionDescriptor;
import javax.swing.JScrollPane;
import com.borland.dbswing.JdbTable;
import com.borland.dx.sql.dataset.Load;
import com.borland.dx.sql.dataset.QueryDescriptor;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Font;
import javax.swing.JOptionPane;
import java.awt.Rectangle;
import javax.swing.JEditorPane;
import javax.swing.border.TitledBorder;
import java.awt.SystemColor;
import java.awt.Color;
import java.awt.Dimension;
/**
* <p>Title: CliniqueManager</p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: shine</p>
*
* @author robin
* @version 1.0
*/
public class SrchManagerInfo extends JPanel {
BorderLayout borderLayout1 = new BorderLayout();
Database database1 = new Database();
JScrollPane jScrollPane1 = new JScrollPane();
//jdbtable用于显示数据
JdbTable dbtblManager = new JdbTable();
JButton btnExit = new JButton();
JButton btnAll = new JButton();
JButton btnSearch2 = new JButton();
JButton btnSearch1 = new JButton();
JLabel lblName = new JLabel();
JTextField txtName = new JTextField();
QueryDataSet rsSearchManager = new QueryDataSet();
JLabel lblTip = new JLabel();
JLabel lblTop = new JLabel();
String sql;
//sql语句,用于查询
String tsql="select username as '用户名',name as '真实姓名',phone as '电话',email as '邮箱' from manager ";
JEditorPane edtPButton = new JEditorPane();
TitledBorder titledBorder1 = new TitledBorder("基本操作");
TitledBorder titledBorder2 = new TitledBorder("管理员信息");
JEditorPane edtPInfo = new JEditorPane();
TitledBorder titledBorder3 = new TitledBorder("查询条件");
JEditorPane edtPTip = new JEditorPane();
TitledBorder titledBorder4 = new TitledBorder("提示信息");
public SrchManagerInfo() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setSize(new Dimension(1000, 600));
this.setLayout(null);
database1.setConnection(new ConnectionDescriptor(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Clinique",
"sa", "", false, "com.microsoft.jdbc.sqlserver.SQLServerDriver"));
btnExit.setBounds(new Rectangle(673, 479, 100, 30));
btnExit.setText("关闭");
btnExit.addActionListener(new SrchManagerInfo_btnExit_actionAdapter(this));
btnAll.setBounds(new Rectangle(526, 479, 100, 30));
btnAll.setText("全部显示");
btnAll.addActionListener(new SrchManagerInfo_btnAll_actionAdapter(this));
btnSearch2.setBounds(new Rectangle(382, 479, 100, 30));
btnSearch2.setText("模糊查找");
btnSearch2.addActionListener(new
SrchManagerInfo_btnSearch2_actionAdapter(this));
btnSearch1.setBounds(new Rectangle(234, 479, 100, 30));
btnSearch1.setText("精确查找");
btnSearch1.addActionListener(new
SrchManagerInfo_btnSearch1_actionAdapter(this));
lblName.setText("管理员姓名:");
lblName.setBounds(new Rectangle(55, 410, 72, 15));
search(tsql);
lblTip.setBorder(null);
lblTip.setToolTipText("");
lblTip.setText("若知道管理员的姓名,则输入后点按钮“精确查询”,若只知道姓名中的部分,则输入后点按钮“模糊查询”");
lblTip.setBounds(new Rectangle(55, 544, 612, 38));
lblTop.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
lblTop.setText("管理员信息查询");
lblTop.setBounds(new Rectangle(430, 0, 140, 24));
rsSearchManager.setReadOnly(true);
rsSearchManager.setEditable(false);
txtName.setBounds(new Rectangle(148, 405, 187, 28));
jScrollPane1.setBorder(titledBorder2);
jScrollPane1.setBounds(new Rectangle(30, 30, 940, 350));
dbtblManager.setEditable(false);
edtPButton.setBackground(SystemColor.control);
edtPButton.setEnabled(false);
edtPButton.setBorder(titledBorder1);
edtPButton.setEditable(false);
edtPButton.setBounds(new Rectangle(30, 456, 940, 69));
edtPInfo.setBackground(SystemColor.control);
edtPInfo.setEnabled(false);
edtPInfo.setBorder(titledBorder3);
edtPInfo.setCaretColor(Color.white);
edtPInfo.setEditable(false);
edtPInfo.setBounds(new Rectangle(30, 379, 940, 78));
edtPTip.setBackground(SystemColor.control);
edtPTip.setEnabled(false);
edtPTip.setBorder(titledBorder4);
edtPTip.setEditable(false);
edtPTip.setBounds(new Rectangle(30, 524, 940, 71));
this.add(lblTop);
this.add(jScrollPane1, java.awt.BorderLayout.CENTER);
this.add(lblName);
this.add(txtName);
this.add(edtPInfo);
this.add(btnAll);
this.add(btnSearch1);
this.add(btnSearch2);
this.add(btnExit);
this.add(edtPButton);
this.add(lblTip);
this.add(edtPTip);
jScrollPane1.getViewport().add(dbtblManager);
}
//查询函数
public void search(String sql){
rsSearchManager.closeStatement();
rsSearchManager.setQuery(new QueryDescriptor(database1,
sql, null, true,
Load.ALL));
dbtblManager.setDataSet(rsSearchManager);
rsSearchManager.refresh();
}
//精确查询
public void btnSearch1_actionPerformed(ActionEvent e) {
//判断是否输入了查询信息,若未输入则给出提示信息,否则按照查询条件查询
if(txtName.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"请输入查询信息!");
return;
}
sql=tsql + "where name='" + txtName.getText() + "'";
search(sql);
txtName.setText("");
}
//模糊查询
public void btnSearch2_actionPerformed(ActionEvent e) {
//判断是否输入了查询信息,若未输入则给出提示信息,否则按照查询条件查询
if(txtName.getText().equals(""))
{
JOptionPane.showMessageDialog(null, "请输入查询信息!");
return;
}
sql=tsql + " where name like '%" + txtName.getText() + "%'";
search(sql);
txtName.setText("");
}
//全部显示医生的信息
public void btnAll_actionPerformed(ActionEvent e) {
search(tsql);
}
//关闭按钮
public void btnExit_actionPerformed(ActionEvent e) {
this.setVisible(false);
}
}
class SrchManagerInfo_btnExit_actionAdapter implements ActionListener {
private SrchManagerInfo adaptee;
SrchManagerInfo_btnExit_actionAdapter(SrchManagerInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnExit_actionPerformed(e);
}
}
class SrchManagerInfo_btnAll_actionAdapter implements ActionListener {
private SrchManagerInfo adaptee;
SrchManagerInfo_btnAll_actionAdapter(SrchManagerInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnAll_actionPerformed(e);
}
}
class SrchManagerInfo_btnSearch2_actionAdapter implements ActionListener {
private SrchManagerInfo adaptee;
SrchManagerInfo_btnSearch2_actionAdapter(SrchManagerInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnSearch2_actionPerformed(e);
}
}
class SrchManagerInfo_btnSearch1_actionAdapter implements ActionListener {
private SrchManagerInfo adaptee;
SrchManagerInfo_btnSearch1_actionAdapter(SrchManagerInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnSearch1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -