⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 srchpatientinfo.java

📁 医疗管理系统
💻 JAVA
字号:
package cliniquemanager;

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.Dimension;
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;


/**
 * <p>Title: CliniqueManager</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: shine</p>
 *
 * @author robin
 * @version 1.0
 */
public class SrchPatientInfo extends JPanel {
    Database database1 = new Database();
    JScrollPane jScrollPane1 = new JScrollPane();
    //jdbtable用于显示数据
    JdbTable dbtblPatient = 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 rsSearchPatient = new QueryDataSet();
    JLabel lblTip = new JLabel();
    JLabel lblTop = new JLabel();
    String sql;
    //sql语句,用于查询
    String tsql="select ptnt_id as '编号', name as '姓名',dname as '主治医生',sex as '性别',blood as '血型', birth as '生日',height as '身高',weight as'体重',leechdom as '所用药品' from patient ";
    JLabel lblDocName = new JLabel();
    JTextField txtDocName = new JTextField();
    TitledBorder titledBorder1 = new TitledBorder("基本操作");
    TitledBorder titledBorder2 = new TitledBorder("病人信息");
    JEditorPane edtPInfo = new JEditorPane();
    TitledBorder titledBorder3 = new TitledBorder("查询条件");
    JEditorPane edtPTip = new JEditorPane();
    TitledBorder titledBorder4 = new TitledBorder("提示信息");
    JEditorPane edtPButton = new JEditorPane();
    public SrchPatientInfo() {
        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.setText("关闭");
        btnExit.addActionListener(new SrchPatientInfo_btnExit_actionAdapter(this));
        btnAll.setText("全部显示");
        btnAll.addActionListener(new SrchPatientInfo_btnAll_actionAdapter(this));
        btnSearch2.setText("模糊查找");
        btnSearch2.addActionListener(new
                                     SrchPatientInfo_btnSearch2_actionAdapter(this));
        btnSearch1.setText("精确查找");
        btnSearch1.addActionListener(new
                                     SrchPatientInfo_btnSearch1_actionAdapter(this));
        lblName.setToolTipText("");
        lblName.setText("病人姓名:");
        search(tsql);
        lblTip.setToolTipText("");
        lblTip.setText("若知道病人姓名或主治医生,则输入后点按钮“精确查询”,若只知道其中的部分,则输入后点按钮“模糊查询”");
        lblTop.setFont(new java.awt.Font("宋体", Font.PLAIN, 20));
        lblTop.setText("病人信息查询");

        lblDocName.setText("主治医生:");
        rsSearchPatient.setReadOnly(true);
        dbtblPatient.setEditable(false);
        jScrollPane1.setBorder(titledBorder2);
        edtPButton.setBackground(SystemColor.control);
        edtPButton.setEnabled(false);
        edtPButton.setBorder(titledBorder1);
        edtPButton.setEditable(false);
        edtPInfo.setBackground(SystemColor.control);
        edtPInfo.setEnabled(false);
        edtPInfo.setBorder(titledBorder3);
        edtPInfo.setEditable(false);
        edtPTip.setBackground(SystemColor.control);
        edtPTip.setEnabled(false);
        edtPTip.setBorder(titledBorder4);
        edtPTip.setEditable(false);
        btnExit.setBounds(new Rectangle(673, 479, 100, 30));
        btnAll.setBounds(new Rectangle(526, 479, 100, 30));
        btnSearch2.setBounds(new Rectangle(382, 479, 100, 30));
        btnSearch1.setBounds(new Rectangle(234, 479, 100, 30));
        lblName.setBounds(new Rectangle(55, 410, 72, 15));
        lblTip.setBounds(new Rectangle(55, 544, 612, 38));
        lblTop.setBounds(new Rectangle(430, 0, 140, 24));
        txtName.setBounds(new Rectangle(148, 405, 187, 28));
        jScrollPane1.setBounds(new Rectangle(30, 30, 940, 350));
        edtPButton.setBounds(new Rectangle(30, 456, 940, 69));
        edtPInfo.setBounds(new Rectangle(30, 379, 940, 78));
        edtPTip.setBounds(new Rectangle(30, 524, 940, 71));
        lblDocName.setBounds(new Rectangle(514, 410, 86, 15));
        txtDocName.setBounds(new Rectangle(618, 405, 187, 28));

        this.add(jScrollPane1, null);
        jScrollPane1.getViewport().add(dbtblPatient);
        this.add(lblTip, null);
        this.add(lblTop, null);
        this.add(txtName, null);
        this.add(btnSearch1, null);
        this.add(btnSearch2);
        this.add(btnAll);
        this.add(btnExit);
        this.add(lblName);
        this.add(lblDocName);
        this.add(txtDocName);
        this.add(edtPInfo);
        this.add(edtPTip);
        this.add(edtPButton);
    }


	//查询函数
    public void search(String sql){
       rsSearchPatient.closeStatement();
       rsSearchPatient.setQuery(new QueryDescriptor(database1,
               sql, null, true,
               Load.ALL));
       dbtblPatient.setDataSet(rsSearchPatient);
       rsSearchPatient.refresh();
    }


	//精确查询
    public void btnSearch1_actionPerformed(ActionEvent e) {
    	//判断是否输入了查询信息,若未输入则给出提示信息,否则按照查询条件查询
        if (txtName.getText().equals("") && txtDocName.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "请输入查询信息");
            return;
        }
        if(txtName.getText().equals("")) {
            sql = tsql + "where dname='" + txtDocName.getText() + "'";
        } else if(txtDocName.getText().equals(""))
            sql = tsql + "where name='" + txtName.getText() + "'";
        else {
            sql = tsql + "where name='" + txtName.getText() + "'and dname='" + txtDocName.getText() + "'";
        }
        search(sql);	//调用查询函数
        txtName.setText("");
        txtDocName.setText("");
    }


	//模糊查询
    public void btnSearch2_actionPerformed(ActionEvent e) {
    	//判断是否输入了查询信息,若未输入则给出提示信息,否则按照查询条件查询
        if (txtName.getText().equals("") && txtDocName.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "请输入查询信息");
            return;
        }
        if(txtName.getText().equals("")) {
            sql = tsql + "where dname like '%" + txtDocName.getText() + "%'";
        }
        else if(txtDocName.getText().equals(""))
            sql = tsql + "where name like '%" + txtName.getText() + "%'";
        else {
            sql = tsql + "where name like '%" + txtName.getText() + "%' and dname like '%" + txtDocName.getText()+ "%'";
        }
        search(sql);	//调用查询函数
        txtName.setText("");
        txtDocName.setText("");
    }


	//全部显示医生的信息
    public void btnAll_actionPerformed(ActionEvent e) {
        search(tsql);
    }


	//关闭按钮
    public void btnExit_actionPerformed(ActionEvent e) {
        this.setVisible(false);
    }

}


class SrchPatientInfo_btnExit_actionAdapter implements ActionListener {
    private SrchPatientInfo adaptee;
    SrchPatientInfo_btnExit_actionAdapter(SrchPatientInfo adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btnExit_actionPerformed(e);
    }
}


class SrchPatientInfo_btnAll_actionAdapter implements ActionListener {
    private SrchPatientInfo adaptee;
    SrchPatientInfo_btnAll_actionAdapter(SrchPatientInfo adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btnAll_actionPerformed(e);
    }
}


class SrchPatientInfo_btnSearch2_actionAdapter implements ActionListener {
    private SrchPatientInfo adaptee;
    SrchPatientInfo_btnSearch2_actionAdapter(SrchPatientInfo adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btnSearch2_actionPerformed(e);
    }
}


class SrchPatientInfo_btnSearch1_actionAdapter implements ActionListener {
    private SrchPatientInfo adaptee;
    SrchPatientInfo_btnSearch1_actionAdapter(SrchPatientInfo adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btnSearch1_actionPerformed(e);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -