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

📄 patientinfomation.java

📁 这是Java数据库系统项目开发实践源代码,所有代码经过测试
💻 JAVA
字号:
package hospitalinfomationsystem;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import com.borland.jbcl.layout.*;import com.borland.dx.sql.dataset.*;import com.borland.dbswing.*;import com.borland.dx.dataset.*;import java.sql.*;import java.io.*;public class PatientInfomation extends JFrame{  String[] job={"","工程师","技师","电焊工"};  String[] diploma={"","本科","大专","高中","初中","小学"};  XYLayout xYLayout1 = new XYLayout();  JLabel person = new JLabel();  JLabel IDLabel = new JLabel();  JTextField IDField = new JTextField();  JLabel jLabel1 = new JLabel();  JLabel jLabel2 = new JLabel();  JLabel jLabel3 = new JLabel();  JTextField jTextField2 = new JTextField();  String[] sex={"","男","女"};  JComboBox jComboBox1 = new JComboBox(sex);  JTextField jTextField1 = new JTextField();  JLabel jLabel4 = new JLabel();  JComboBox jComboBox2 = new JComboBox(job);  JLabel jLabel5 = new JLabel();  JComboBox jComboBox3 = new JComboBox(diploma);  JLabel jLabel6 = new JLabel();  JTextField jTextField3 = new JTextField();  JButton addButton = new JButton();  JButton jButton2 = new JButton();  Database database1 = new Database();  JButton deleteButton = new JButton();  JButton alterButton = new JButton();  public PatientInfomation() {    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    }  }  private void jbInit() throws Exception {    person.setFont(new java.awt.Font("Dialog", 0, 17));    person.setText("学 生 情 况 表 ");    this.getContentPane().setLayout(xYLayout1);    IDLabel.setText("学号 ");    //IDField.setText("");    jLabel1.setText("性别");    jLabel2.setText("姓名");    jLabel3.setText("出生日期");    jTextField2.setText("");    jTextField1.setText("");    jLabel4.setText("系别");    jLabel5.setText("学生类别");    jLabel6.setText("备注");    jTextField3.setText("");    this.getContentPane().setBackground(new Color(250, 250, 220));    addButton.setText("添加");    addButton.addActionListener(new PatientInfomation_addButton_actionAdapter(this));    jButton2.setText("取消");    jButton2.addActionListener(new PatientInfomation_jButton2_actionAdapter(this));    database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:odbc:patient", "", "", false, "sun.jdbc.odbc.JdbcOdbcDriver"));    deleteButton.setText("删除");    deleteButton.addActionListener(new PatientInfomation_deleteButton_actionAdapter(this));    alterButton.setText("更新");    alterButton.addActionListener(new PatientInfomation_alterButton_actionAdapter(this));    this.getContentPane().add(person, new XYConstraints(128, 26, 122, 32));    this.getContentPane().add(IDLabel,   new XYConstraints(33, 60, 36, 24));    this.getContentPane().add(IDField,   new XYConstraints(72, 60, 66, 24));    this.getContentPane().add(jLabel1,  new XYConstraints(186, 63, 43, 22));    this.getContentPane().add(jLabel2,       new XYConstraints(33, 95, -1, 25));    this.getContentPane().add(jLabel3,       new XYConstraints(186, 92, 46, 32));    this.getContentPane().add(jTextField2,   new XYConstraints(72, 97, 88, 25));    this.getContentPane().add(jComboBox1,    new XYConstraints(238, 58, 68, 24));    this.getContentPane().add(jTextField1,      new XYConstraints(238, 95, 88, 25));    this.getContentPane().add(jLabel4,      new XYConstraints(33, 140, 36, 24));    this.getContentPane().add(jComboBox2,     new XYConstraints(72, 142, 88, 25));    this.getContentPane().add(jLabel5,   new XYConstraints(186, 142, 47, 26));    this.getContentPane().add(jComboBox3,     new XYConstraints(238, 138, 88, 25));    this.getContentPane().add(jLabel6,   new XYConstraints(33, 188, 37, 24));    this.getContentPane().add(jTextField3,  new XYConstraints(74, 185, 256, 29));    this.getContentPane().add(jButton2,      new XYConstraints(266, 254, 63, 24));    this.getContentPane().add(addButton,    new XYConstraints(27, 254, 63, 24));    this.getContentPane().add(deleteButton,    new XYConstraints(105, 253, 63, 24));    this.getContentPane().add(alterButton, new XYConstraints(184, 255, 63, 24));    this.setVisible(true);    this.setSize(400,350);    this.setLocation(100,100);  }//获得工号 文本框中的内容public String getIDFieldText(){  return IDField.getText();  } //设置工号文本框中的内容public void setIDFieldText(String idText) {   //IDField是这个文本框的名字    IDField.setText(idText);  }  public String getSex(){    int no=jComboBox1.getSelectedIndex();    Object text=jComboBox1.getItemAt(no);    String sex=text.toString();    return sex;}  public String getName(){return jTextField2.getText();}  public String getBirthDate(){return jTextField1.getText();}  public String getJob(){return (jComboBox2.getItemAt(jComboBox1.getSelectedIndex())).toString();}  public String getDiploma(){return (jComboBox3.getItemAt(jComboBox1.getSelectedIndex())).toString();}  public String getBeizhu(){return jTextField3.getText();}  void jButton2_actionPerformed(ActionEvent e) {    this.setVisible(false);  }  void addButton_actionPerformed(ActionEvent e) {    String id = this.getIDFieldText();    String name = this.getName();    String sex = this.getSex();    String job = this.getJob();    String birthday = this.getBirthDate();    String remark = this.getBeizhu();    String diploma = this.getDiploma();    int no;    if (id.length() != 0) {      no = Integer.parseInt(id);    }    else {      JOptionPane.showMessageDialog(this, "you must enter student ID!!");      no = 0;    }    if (no == 0)      JOptionPane.showMessageDialog(this, "you must enter student ID");    else {      try {          PreparedStatement addInfo = database1.createPreparedStatement(              "INSERT INTO student_info"              + "(ID,name,sex,birthday,diploma,polity,job,post,branch,marry,np,address,tel,email,mobile,ID_card,school,speciality,grad_time,bank,bank_ID,work_time,relegation,rel_time,record,study,fruit,honour,memo)"              +              "  VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");          addInfo.setInt(1, no);          addInfo.setString(2, name);          addInfo.setString(3, sex);          addInfo.setString(4, birthday);          addInfo.setString(5, diploma);          addInfo.setString(6, null);          addInfo.setString(7, job);          addInfo.setString(8, null);          addInfo.setString(9, null);          addInfo.setString(10, null);          addInfo.setString(11, null);          addInfo.setString(12, null);          addInfo.setString(13, null);          addInfo.setString(14, null);          addInfo.setString(15, null);          addInfo.setString(16, null);          addInfo.setString(17, null);          addInfo.setString(18, null);          addInfo.setString(19, null);          addInfo.setString(20, null);          addInfo.setString(21, null);          addInfo.setString(22, null);          addInfo.setString(23, null);          addInfo.setString(24, null);          addInfo.setString(25, null);          addInfo.setString(26, null);          addInfo.setString(27, null);          addInfo.setString(28, null);          addInfo.setString(29, remark);          addInfo.execute();addInfo.close();      }        catch (SQLException err) {          err.printStackTrace();        }        this.setVisible(false);        JOptionPane.showMessageDialog(null, "you have add student infomation");    }  }  void deleteButton_actionPerformed(ActionEvent e) {      String patient = IDField.getText();      if (patient.length() != 0) {    int number = Integer.parseInt(patient);    try {      PreparedStatement deleteInfo = database1.createPreparedStatement(          "DELETE FROM student_info WHERE ID=" + number);      deleteInfo.execute();      deleteInfo.close();      JOptionPane.showMessageDialog(this, "you have delete this infoamtion!");    }    catch (SQLException sql) {      sql.printStackTrace();    }  }  else {    JOptionPane.showMessageDialog(this, "please enter infoamtion!");  }  }  void alterButton_actionPerformed(ActionEvent e) {    String name1="";    String sex1="";    String job1="";    String birthday1="";    String remark1="";    String diploma1="";    String id=this.getIDFieldText();    String name=this.getName();    String sex=this.getSex();    String job=this.getJob();    String birthday=this.getBirthDate();    String remark=this.getBeizhu();    String diploma=this.getDiploma();    int number=0;    if(id!=null)    {      try{number=Integer.parseInt(id);}      catch(NumberFormatException nfe){number=0;}     }    else{JOptionPane.showMessageDialog(this,"you must enter stuent ID!!");number=0; }    if(number==0)JOptionPane.showMessageDialog(this,"you must enter student ID");    else{    try{      PreparedStatement alterInfo = database1.createPreparedStatement(          "SELECT name,sex,birthday,diploma,job,memo FROM student_info WHERE ID='"+number+"'");      ResultSet rs=alterInfo.executeQuery();      if(name!=null) name1=name;      else name1=rs.getString(1);      if(sex!=null) sex1=sex;      else sex1=rs.getString(2);      if(birthday!=null)birthday1=birthday;        else birthday1=rs.getString(3);      if(diploma!=null)diploma1=diploma;        else diploma1=rs.getString(4);      if(job!=null)job1=job;        else job1=rs.getString(5);      if(remark!=null)remark1=remark;        else remark1=rs.getString(6);       rs.close();       alterInfo.close();}     catch(SQLException sql){sql.printStackTrace();}     try{      PreparedStatement alter=database1.createPreparedStatement("UPDATE student_info SET name=?,sex=?,birthday=?,diploma=?,job=?,memo=? WHERE ID=?");      alter.setString(1,name1);      alter.setString(2,sex1);      alter.setString(3,birthday1);      alter.setString(4,diploma1);      alter.setString(5,job1);      alter.setString(6,remark1);      alter.setInt(7,number);      alter.execute();      alter.close();    }    catch (SQLException err) {       err.printStackTrace();     }     this.setVisible(false);      JOptionPane.showMessageDialog(null,"you have alter student infomation");    }  }  }class PatientInfomation_jButton2_actionAdapter implements java.awt.event.ActionListener {  PatientInfomation adaptee;  PatientInfomation_jButton2_actionAdapter(PatientInfomation adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.jButton2_actionPerformed(e);  }}class PatientInfomation_addButton_actionAdapter implements java.awt.event.ActionListener {  PatientInfomation adaptee;  PatientInfomation_addButton_actionAdapter(PatientInfomation adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.addButton_actionPerformed(e);  }}class PatientInfomation_deleteButton_actionAdapter implements java.awt.event.ActionListener {  PatientInfomation adaptee;  PatientInfomation_deleteButton_actionAdapter(PatientInfomation adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.deleteButton_actionPerformed(e);  }}class PatientInfomation_alterButton_actionAdapter implements java.awt.event.ActionListener {  PatientInfomation adaptee;  PatientInfomation_alterButton_actionAdapter(PatientInfomation adaptee) {    this.adaptee = adaptee;  }  public void actionPerformed(ActionEvent e) {    adaptee.alterButton_actionPerformed(e);  }}

⌨️ 快捷键说明

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