📄 fee.java
字号:
//费用管理
package src;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.table.*;
import javax.swing.table.DefaultTableColumnModel;
public class fee extends JFrame implements ActionListener{
private JTable table;
private String[] columnNames={"科室","床号","病人姓名","病历号","记账号","押金","花费金额","所剩金额","需交押金"};
private JPanel jp3,jp,jp31,jp32;
private int flag=1;
private JTextField name,number,leftFee;
private JButton jb2,jb3,check,in,stop;
public fee(){
super("费用管理");
setLocation(210,140);
setSize(650,400);
setResizable(false);
//modify title image
ImageIcon title=new ImageIcon("images/pill.gif");
setIconImage(title.getImage());
//add table
JPanel jp0=new JPanel();
jp0.add(new JLabel(new ImageIcon("images/head2.gif")));
add("North",jp0);
JPanel jp_down=new JPanel(new BorderLayout());
conectTab.dtm=new DefaultTableModel(columnNames,18);
table=new JTable(conectTab.dtm);
new conectTab("费用管理");
JScrollPane scrollPane = new JScrollPane(table);
add("Center",scrollPane);
//add research panel
jp=new JPanel(new GridLayout(1,3));
JPanel jp1=new JPanel(new GridLayout(3,1));
jp1.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("科室"),
BorderFactory.createEmptyBorder(1,1,1,1)));
JPanel jp01=new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel jp03=new JPanel(new FlowLayout(FlowLayout.LEFT));
String[] KeShi={"Office51","Office52","Office53","Office54","Office55"};
JComboBox jcbb=new JComboBox(KeShi);
jp01.add(new JLabel("请选择科室")); jp01.add(jcbb); jp1.add(jp01);
jp03.add(new JLabel("日期"));jp1.add(jp03);
JPanel jp12=new JPanel();
String[] years={"1960","1961","1962","1963","1964","1965","1966","1967","1968","1969","1970","1971","1972","1973","1974","1975"
,"1976","1978","1979","1980","1981","1982","1983","1984","1985","1986","1987","1988","1989"
,"1990","1991","1992","1993","1994","1995","1996","1997","1998","1999","2000","2001","2002","2003","2004","2005","2006","2007","2008"};
JPanel jp121=new JPanel(new FlowLayout(FlowLayout.CENTER));
jp12.add("Center",jp121);
JComboBox year=new JComboBox(years);
jp121.add(year);
jp121.add(new JLabel("年"));
String[] months={"1","2","3","4","5","6","7","8","9","10","11","12"};
JComboBox month=new JComboBox(months);
jp121.add(month);
jp121.add(new JLabel("月"));
String[] days={"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16",
"17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"};
JComboBox day=new JComboBox(days);
jp121.add(day);
jp121.add(new JLabel("日"));
jp1.add(jp12);
jp.add(jp1);
JPanel jp21=new JPanel(new FlowLayout(FlowLayout.CENTER));
JPanel jp22=new JPanel(new FlowLayout(FlowLayout.CENTER));
JPanel jp23=new JPanel(new FlowLayout(FlowLayout.CENTER));
JPanel jp2=new JPanel(new GridLayout(3,1));
jp2.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("处理"),
BorderFactory.createEmptyBorder(1,1,1,1)));
check=new JButton("费 用 核 算");
jp21.add(check);
jp2.add(jp21);
stop=new JButton("当日停医嘱查询");
jp22.add(stop);
jp2.add(jp22);
in=new JButton("一次性收费录入");
jp23.add(in);
jp2.add(jp23);
jp.add(jp2);
jp3=new JPanel(new GridLayout(3,1));
jp3.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("查询"),
BorderFactory.createEmptyBorder(1,1,1,1)));
jp31=new JPanel();
String[] finding={"请选择查询种类","病人姓名","病历号"};
final JComboBox jcbb1=new JComboBox(finding);
jcbb1.addActionListener(this);
jp31.add(jcbb1);
jp32=new JPanel(new CardLayout());
JPanel card0=new JPanel(new GridLayout(2,1));
JPanel card1=new JPanel(new GridLayout(2,1));
JPanel card2=new JPanel(new GridLayout(2,1));
JPanel card3=new JPanel(new GridLayout(2,1));
card0.add(new JLabel(""));
card1.add(new JLabel("请输入查询姓名"));name=new JTextField(10);card1.add(name);
card2.add(new JLabel("请输入病历号"));number=new JTextField(10);card2.add(number);
card3.add(new JLabel("请输入查询所剩押金"));leftFee=new JTextField(10);card3.add(leftFee);
jp32.add(card0,"请选择查询种类");
jp32.add(card1,"病人姓名");
jp32.add(card2,"病历号");
//jp32.add(card3,"所剩押金");
jp3.add(jp31);jp3.add(jp32);
JPanel jp33=new JPanel();
jb3=new JButton("查询");
jb3.addMouseListener(
new MouseAdapter()
{
public void mouseClicked(MouseEvent EX) {
//++++++++++++++++++++++++++++++++++++++++++++++
int rowcount = conectTab.dtm.getRowCount() - 1;
if (rowcount >4) {
for (int i = rowcount; i >= 0; i--) {
conectTab.dtm.removeRow(i); // 删除Jtable中的所有行
}
conectTab.dtm.setRowCount(0); // 将Jtable中的行数设为零
}
//++++++++++++++++++++++++++++++++++++++++++++++
System.out.println("Good idea!!!");
Object SelectName=jcbb1.getSelectedItem();
String selectNamecontent=SelectName.toString();
if(selectNamecontent.equals("请选择查询种类"))
{
System.out.println("什么也不做");
return;
}
else if(selectNamecontent.equals("病人姓名"))
{
if(name.getText().equals(""))
{
JOptionPane.showMessageDialog(Doctor.frame," 请输入病人姓名!","注意",JOptionPane.ERROR_MESSAGE);
return;
}
String sickName=name.getText().trim();
String SQL="select officeNo,bedNo,sickName,sick.medicalNo,accountNo,hand,cost,leave,need from foregift,sick,room where sick.medicalNo=foregift.medicalNo and sick.roomNo=room.roomNo and sick.sickName='"+sickName+"'";
databaseSearch(SQL,9);
System.out.println(name.getText());
return;
}else if(selectNamecontent.equals("病历号"))
{
if(number.getText().equals(""))
{
JOptionPane.showMessageDialog(Doctor.frame," 请输入病历号!","注意",JOptionPane.ERROR_MESSAGE);
return;
}
String sickCaseID=number.getText().trim();
System.out.println("sickCaseID"+sickCaseID);
String SQL="select officeNo,bedNo,sickName,sick.medicalNo,accountNo,hand,cost,leave,need from foregift,sick,room where sick.medicalNo=foregift.medicalNo and sick.roomNo=room.roomNo and foregift.medicalNo='"+sickCaseID+"'";
databaseSearch(SQL,9);
System.out.println(number.getText());
return;
}
}
}
);
jp33.add(jb3);
jp3.add("Center",jp33);
jp.add(jp3);
add("South",jp);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
CardLayout cl = (CardLayout)(jp32.getLayout());
JComboBox find= (JComboBox)e.getSource();
String findType = (String)find.getSelectedItem();
cl.show(jp32,findType);
}
private void databaseSearch(String SQL,int num)
{
Connection conn=null;
ResultSet rs=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(Exception e){
System.out.println("Not Found Driver!!!");
}
try{
conn=DriverManager.getConnection("jdbc:odbc:Hospital","","");
Statement stmt=conn.createStatement();
rs=stmt.executeQuery(SQL);
int i=0;
String[] data = new String[num];
while(rs.next())
{
i++;
for (int j = 1; j <= num; j++) {
data[j - 1] = rs.getString(j); // 取出数据库中的数组装载到数组中
}
conectTab.dtm.addRow(data); // 在Jtable中显示取出的数据
}
if(i==0)
{
JOptionPane.showMessageDialog(Doctor.frame, " 您查找的内容不存在!",
"注意", JOptionPane.INFORMATION_MESSAGE);
}
conn.close();
}catch(SQLException e){
System.out.println("Link Error");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -