📄 edit_patient.java~54~
字号:
package clinique;
import java.awt.*;
import javax.swing.*;
import java.awt.Rectangle;
import com.borland.dbswing.JdbTable;
import com.borland.dx.sql.dataset.Database;
import com.borland.dx.sql.dataset.QueryDataSet;
import com.borland.dx.sql.dataset.ConnectionDescriptor;
import com.borland.dx.sql.dataset.Load;
import com.borland.dx.sql.dataset.QueryDescriptor;
import com.borland.dx.dataset.Column;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.SQLException;
import java.awt.Font;
import javax.swing.BorderFactory;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class edit_patient extends JPanel {
int n;
String id;
public edit_patient() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setLayout(null);
jScrollPane1.setBounds(new Rectangle(10, 13, 660, 203));
database1.setConnection(new ConnectionDescriptor(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=clinique",
"sa", "", false, "com.microsoft.jdbc.sqlserver.SQLServerDriver"));
jdbTable1.setDataSet(queryDataSet1);
jdbTable1.setEditable(false);
jdbTable1.addMouseListener(new edit_patient_jdbTable1_mouseAdapter(this));
queryDataSet1.setQuery(new QueryDescriptor(database1,
"select * from patient", null, true, Load.ALL));
column1.setColumnName("patient_id");
column1.setDataType(com.borland.dx.dataset.Variant.INT);
column1.setRowId(true);
column1.setTableName("patient");
column1.setWidth(6);
column1.setServerColumnName("patient_id");
column1.setSqlType(4);
column2.setColumnName("name");
column2.setDataType(com.borland.dx.dataset.Variant.STRING);
column2.setPrecision(50);
column2.setTableName("patient");
column2.setWidth(6);
column2.setServerColumnName("name");
column2.setSqlType(1);
column3.setColumnName("birthday");
column3.setDataType(com.borland.dx.dataset.Variant.DATE);
column3.setTableName("patient");
column3.setWidth(6);
column3.setServerColumnName("birthday");
column3.setSqlType(93);
column4.setColumnName("stature");
column4.setDataType(com.borland.dx.dataset.Variant.INT);
column4.setTableName("patient");
column4.setWidth(4);
column4.setServerColumnName("stature");
column4.setSqlType(4);
column5.setColumnName("avoirdupois");
column5.setDataType(com.borland.dx.dataset.Variant.INT);
column5.setTableName("patient");
column5.setWidth(6);
column5.setServerColumnName("AVOIRDUPOIS");
column5.setSqlType(4);
jTname.setBounds(new Rectangle(89, 16, 81, 20));
jComboBox1.setBounds(new Rectangle(263, 18, 81, 20));
jComboBox2.setBounds(new Rectangle(263, 58, 81, 20));
jTstature.setBounds(new Rectangle(89, 96, 81, 20));
jTavo.setBounds(new Rectangle(263, 96, 80, 20));
jLabel1.setText("病人姓名:");
jLabel1.setBounds(new Rectangle(15, 20, 71, 15));
jLabel2.setText("性别:");
jLabel2.setBounds(new Rectangle(212, 22, 42, 15));
jLabel3.setText("出生日期:");
jLabel3.setBounds(new Rectangle(15, 57, 70, 15));
jLabel4.setText("血型:");
jLabel4.setBounds(new Rectangle(213, 61, 42, 15));
jLabel5.setText("身高:");
jLabel5.setBounds(new Rectangle(36, 99, 42, 15));
jLabel6.setText("体重:");
jLabel6.setBounds(new Rectangle(213, 100, 42, 15));
jButton1.setBounds(new Rectangle(396, 373, 86, 23));
jButton1.setText("提交修改");
jButton1.addActionListener(new edit_patient_jButton1_actionAdapter(this));
jButton2.setBounds(new Rectangle(542, 373, 81, 23));
jButton2.setText("取消");
jButton2.addActionListener(new edit_patient_jButton2_actionAdapter(this));
jLabel7.setFont(new java.awt.Font("宋体", Font.BOLD, 15));
jLabel7.setText("病人信息修改");
jLabel7.setBounds(new Rectangle(30, 12, 114, 30));
column6.setColumnName("sex");
column6.setDataType(com.borland.dx.dataset.Variant.STRING);
column6.setPrecision(4);
column6.setTableName("patient");
column6.setWidth(4);
column6.setServerColumnName("SEX");
column6.setSqlType(1);
column7.setColumnName("bloodtype");
column7.setDataType(com.borland.dx.dataset.Variant.STRING);
column7.setPrecision(4);
column7.setTableName("patient");
column7.setWidth(4);
column7.setServerColumnName("BLOODTYPE");
column7.setSqlType(1);
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setBounds(new Rectangle(10, 233, 393, 132));
jPanel1.setLayout(null);
jPanel2.setBorder(BorderFactory.createEtchedBorder());
jPanel2.setBounds(new Rectangle(411, 233, 259, 132));
jPanel2.setLayout(null);
mname.setBounds(new Rectangle(132, 11, 77, 20));
mnumber.setBounds(new Rectangle(132, 38, 77, 20));
pdoctor.setBounds(new Rectangle(132, 96, 77, 20));
jLabel8.setText("所用药品:");
jLabel8.setBounds(new Rectangle(32, 14, 69, 15));
jLabel9.setText("药品数量:");
jLabel9.setBounds(new Rectangle(32, 44, 70, 15));
jLabel10.setText("主治医生:");
jLabel10.setBounds(new Rectangle(32, 101, 71, 15));
jLabel11.setText("药品价格:");
jLabel11.setBounds(new Rectangle(32, 73, 69, 15));
jPanel3.setBorder(BorderFactory.createEtchedBorder());
jPanel3.setBounds(new Rectangle(53, 40, 679, 409));
jPanel3.setLayout(null);
jTextField5.setBounds(new Rectangle(138, 375, 77, 20));
jLabel12.setText("姓名查询:");
jLabel12.setBounds(new Rectangle(50, 379, 72, 15));
jButton3.setBounds(new Rectangle(263, 373, 81, 23));
jButton3.setText("查询");
column8.setColumnName("doctor");
column8.setDataType(com.borland.dx.dataset.Variant.STRING);
column8.setPrecision(50);
column8.setTableName("patient");
column8.setWidth(6);
column8.setServerColumnName("DOCTOR");
column8.setSqlType(1);
column11.setColumnName("date");
column11.setDataType(com.borland.dx.dataset.Variant.DATE);
column11.setTableName("patient");
column11.setWidth(6);
column11.setServerColumnName("DATE");
column11.setSqlType(93);
column9.setColumnName("nenumber");
column9.setDataType(com.borland.dx.dataset.Variant.INT);
column9.setTableName("patient");
column9.setWidth(6);
column9.setServerColumnName("NENUMBER");
column9.setSqlType(4);
column10.setColumnName("medname");
column10.setDataType(com.borland.dx.dataset.Variant.STRING);
column10.setPrecision(50);
column10.setTableName("patient");
column10.setWidth(8);
column10.setServerColumnName("MEDNAME");
column10.setSqlType(1);
birthday.setBounds(new Rectangle(89, 58, 81, 20));
price.setBounds(new Rectangle(132, 67, 76, 20));
column12.setColumnName("price");
column12.setDataType(com.borland.dx.dataset.Variant.BIGDECIMAL);
column12.setPrecision(10);
column12.setScale(2);
column12.setTableName("patient");
column12.setWidth(6);
column12.setServerColumnName("PRICE");
column12.setSqlType(3);
jPanel1.add(jComboBox1);
jPanel1.add(jTstature);
jPanel1.add(jLabel3);
jPanel1.add(jLabel1);
jPanel1.add(jTname);
jPanel1.add(jComboBox2);
jPanel1.add(jLabel4);
jPanel1.add(jLabel6);
jPanel1.add(jLabel2);
jPanel1.add(jLabel5);
jPanel1.add(jTavo);
jPanel1.add(birthday);
this.add(jLabel7);
this.add(jPanel3);
jPanel3.add(jScrollPane1);
jPanel3.add(jButton2);
jPanel3.add(jLabel12);
jPanel3.add(jTextField5);
jPanel3.add(jButton3);
jPanel3.add(jButton1);
jPanel3.add(jPanel2);
jScrollPane1.getViewport().add(jdbTable1);
jPanel2.add(mname);
jPanel2.add(jLabel8);
jPanel2.add(jLabel9);
jPanel2.add(mnumber);
jPanel2.add(jLabel11);
jPanel2.add(jLabel10);
jPanel2.add(price);
jPanel2.add(pdoctor);
jPanel3.add(jPanel1);
jComboBox1.addItem("");
jComboBox1.addItem("男");
jComboBox1.addItem("女");
jComboBox2.addItem("");
jComboBox2.addItem("A");
jComboBox2.addItem("B");
jComboBox2.addItem("O");
jComboBox2.addItem("AB");
queryDataSet1.setColumns(new Column[] {column1, column2, column6,
column3, column7, column4, column5, column8,
column10, column9, column12, column11});
}
JScrollPane jScrollPane1 = new JScrollPane();
JdbTable jdbTable1 = new JdbTable();
Database database1 = new Database();
QueryDataSet queryDataSet1 = new QueryDataSet();
Column column1 = new Column();
Column column2 = new Column();
Column column3 = new Column();
Column column4 = new Column();
Column column5 = new Column();
JTextField jTname = new JTextField();
JComboBox jComboBox1 = new JComboBox();
JComboBox jComboBox2 = new JComboBox();
JTextField jTstature = new JTextField();
JTextField jTavo = new JTextField();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JLabel jLabel7 = new JLabel();
Column column6 = new Column();
Column column7 = new Column();
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JTextField mname = new JTextField();
JTextField mnumber = new JTextField();
JTextField pdoctor = new JTextField();
JLabel jLabel8 = new JLabel();
JLabel jLabel9 = new JLabel();
JLabel jLabel10 = new JLabel();
JLabel jLabel11 = new JLabel();
JPanel jPanel3 = new JPanel();
JTextField jTextField5 = new JTextField();
JLabel jLabel12 = new JLabel();
JButton jButton3 = new JButton();
Column column8 = new Column();
Column column11 = new Column();
Column column9 = new Column();
Column column10 = new Column();
JTextField birthday = new JTextField();
JTextField price = new JTextField();
Column column12 = new Column();
public void jdbTable1_mouseClicked(MouseEvent e) {
n=jdbTable1.getSelectedRow();
id=""+jdbTable1.getValueAt(n,0);
jTname.setText((String)jdbTable1.getValueAt(n,1));
jComboBox1.setSelectedItem((String)jdbTable1.getValueAt(n,2));
birthday.setText(""+jdbTable1.getValueAt(n,3));
jComboBox2.setSelectedItem((String)jdbTable1.getValueAt(n,4));
jTstature.setText(""+jdbTable1.getValueAt(n,5));
jTavo.setText(""+jdbTable1.getValueAt(n,6));
mname.setText((String)jdbTable1.getValueAt(n,8));
mnumber.setText(""+jdbTable1.getValueAt(n,9));
pdoctor.setText((String)jdbTable1.getValueAt(n,7));
price.setText(""+jdbTable1.getValueAt(n,10));
}
public void jButton1_actionPerformed(ActionEvent e) {
edit_patient();
}
private void edit_patient()
{
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
} catch (ClassNotFoundException ce) {
System.out.println(ce);
}
try {
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=clinique";
Connection con = DriverManager.getConnection(url,"sa","");
String sqlStr;
sqlStr="update patient set name=\'"+jTname.getText()+"\',sex=\'"+jComboBox1.getSelectedItem()+"\',birthday=\'"+birthday.getText()+"\',bloodtype=\'"+jComboBox2.getSelectedItem()+"\',stature=\'"+jTstature.getText()+"\',avoirdupois=\'"+jTavo.getText()+"\',doctor=\'"+pdoctor.getText()+"\',medname=\'"+mname.getText()+"\',nenumber=\'"+mnumber.getText()+"\',price=\'"+ price.getText()+"\' where patient_id=\'"+id+"\'";
Statement s = con.createStatement();
s.executeUpdate(sqlStr);
JOptionPane.showMessageDialog(null,"病人信息数据修改成功!");
jTname.setText("");
birthday.setText("");
jComboBox1.setSelectedItem("");
jComboBox2.setSelectedItem("");
jTstature.setText("");
jTavo.setText("");
queryDataSet1.refresh();
mname.setText("");
mnumber.setText("");
price.setText("");
pdoctor.setText("");
s.close();
con.close();
} catch (SQLException ce) {
System.out.println(ce);
}
}
public void jButton2_actionPerformed(ActionEvent e) {
jTname.setText("");
birthday.setText("");
jComboBox1.setSelectedItem("");
jComboBox2.setSelectedItem("");
jTstature.setText("");
jTavo.setText("");
queryDataSet1.refresh();
mname.setText("");
mnumber.setText("");
price.setText("");
pdoctor.setText("");
}
}
class edit_patient_jButton2_actionAdapter implements ActionListener {
private edit_patient adaptee;
edit_patient_jButton2_actionAdapter(edit_patient adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class edit_patient_jdbTable1_mouseAdapter extends MouseAdapter {
private edit_patient adaptee;
edit_patient_jdbTable1_mouseAdapter(edit_patient adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.jdbTable1_mouseClicked(e);
}
}
class edit_patient_jButton1_actionAdapter implements ActionListener {
private edit_patient adaptee;
edit_patient_jButton1_actionAdapter(edit_patient adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -