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

📄 add_patient.java

📁 在个一个诊所系统,实现数据的查询和删除等的操作.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    JLabel jLabel4 = new JLabel();
    JLabel jLabel5 = new JLabel();
    JLabel jLabel6 = new JLabel();
    JButton jBorder = new JButton();
    JButton jBexit = new JButton();
    JComboBox jComboBox1 = new JComboBox();
    JComboBox jComboBox2 = new JComboBox();
    Column column5 = new Column();
    Column column6 = new Column();
    JLabel jLabel7 = new JLabel();
    Column column7 = new Column();
    Column column8 = new Column();
    JPanel jPanel1 = new JPanel();
    JPanel jPanel2 = new JPanel();
    JLabel jLabel8 = new JLabel();
    JLabel jLabel9 = new JLabel();
    JLabel jLabel10 = new JLabel();
    JLabel jLabel11 = new JLabel();
    JTextField mname = new JTextField();
    JTextField mnumber = new JTextField();
    JTextField pdoctor = new JTextField();
    JPanel jPanel3 = new JPanel();
    Column column11 = new Column();
    Column column12 = new Column();
    Column column13 = new Column();
    JTextField cyear = new JTextField();
    JTextField cmonth = new JTextField();
    JTextField cday = new JTextField();
    JLabel jLabel12 = new JLabel();
    JLabel jLabel13 = new JLabel();
    JLabel jLabel14 = new JLabel();
    JTextField price = new JTextField();
    JLabel jLabel18 = new JLabel();
    JLabel jLabel19 = new JLabel();
    JLabel jLabel20 = new JLabel();
    Column column9 = new Column();
    public void jButton1_actionPerformed(ActionEvent e) {
        if(jTpname.getText().length()==0)
        {
            JOptionPane.showMessageDialog(null,"请输入病人的姓名!");
            jTpname.requestFocus();
        }
        else if(jComboBox1.getSelectedItem().equals(""))
        {
            JOptionPane.showMessageDialog(null,"请选择病人的性别!");
            jComboBox1.requestFocus();
        }
        else if(cyear.getText().length()==0)
        {
            JOptionPane.showMessageDialog(null,"请输入病人的出生年!");
            cyear.requestFocus();
        }
        else if(number(cyear.getText())==false)
        {
            JOptionPane.showMessageDialog(null,"你输入病人的出生年不是有效数字!");
            cyear.setText("");
            cyear.requestFocus();
        }
        else if(Integer.parseInt(cyear.getText())<1900 || Integer.parseInt(cyear.getText())>2200)
        {
            JOptionPane.showMessageDialog(null,"你输入病人的出生年份有误,请重新输入!");
            cyear.setText("");
            cyear.requestFocus();
        }
        else if(cmonth.getText().length()==0)
        {
            JOptionPane.showMessageDialog(null,"请输入病人的出生月!");
            cmonth.requestFocus();
        }
        else if(number(cmonth.getText())==false)
        {
            JOptionPane.showMessageDialog(null,"你输入病人的出生月不是有效数字!");
            cmonth.requestFocus();
        }
        else if(Integer.parseInt(cmonth.getText())<1 || Integer.parseInt(cmonth.getText())>12)
        {
            JOptionPane.showMessageDialog(null,"你输入病人的出生月份有误,请重新输入!");
            cmonth.setText("");
            cmonth.requestFocus();
        }
        else if(cday.getText().length()==0)
        {
            JOptionPane.showMessageDialog(null,"请输入病人的出生日!");
            cday.requestFocus();
        }
        else if(number(cday.getText())==false)
        {
            JOptionPane.showMessageDialog(null,"你输入病人的出生日不是有效数字!");
            cday.requestFocus();
        }
        else if(Integer.parseInt(cday.getText())<1 || Integer.parseInt(cday.getText())>31)
        {
            JOptionPane.showMessageDialog(null,"你输入病人的出生日有误,请重新输入!");
            cday.setText("");
            cday.requestFocus();
        }
        else if(jComboBox2.getSelectedItem().equals(""))
        {
            JOptionPane.showMessageDialog(null,"请选择病人的血型!");
            jComboBox2.requestFocus();
        }
        else if(jTpstature.getText().length()==0)
        {
            JOptionPane.showMessageDialog(null,"请输入病人的身高!");
            jTpstature.requestFocus();
        }
        else if(number(jTpstature.getText())==false)
        {
            JOptionPane.showMessageDialog(null,"你输入的病人身高不是有效数字!");
            jTpstature.setText("");
            jTpstature.requestFocus();
        }
        else if(jTpavo.getText().length()==0)
        {
            JOptionPane.showMessageDialog(null,"请输入病人的体重!");
            jTpavo.requestFocus();
        }
        else if(number(jTpavo.getText())==false)
        {
            JOptionPane.showMessageDialog(null,"你输入的病人体重不是有效数字!");
            jTpavo.setText("");
            jTpavo.requestFocus();
        }
        else if(mname.getText().length()==0)
        {
            JOptionPane.showMessageDialog(null,"请输入病人所用的药品的名称!");
            mname.requestFocus();
        }
        else if(mnumber.getText().length()==0)
        {
            JOptionPane.showMessageDialog(null,"请输入病人所用的药品的数量!");
            mnumber.requestFocus();
        }
        else if(number(mnumber.getText())==false)
        {
            JOptionPane.showMessageDialog(null,"你输入的病人所用药品数量不是有效数字!");
            mnumber.setText("");
            mnumber.requestFocus();
        }
        else if(price.getText().length()==0)
        {
            JOptionPane.showMessageDialog(null,"请输入病人所用的药品的价格!");
            price.requestFocus();
        }
        /*else if(!price.getText().equals(""))
                {
                        try
                        {
                                Float.parseFloat(price.getText());
                        }
                        catch(NumberFormatException n)
                        {
                                price.setText("");
                                price.requestFocus();
                                JOptionPane.showMessageDialog(this,"你输入的病人所用药品单价不是有效数字!");
                        }
			}*/
        else if(pdoctor.getText().length()==0)
        {
            JOptionPane.showMessageDialog(null,"请输入病人的主治医生的名字!");
            pdoctor.requestFocus();
        }

        else
        {
            addpatient();
        }
    }

    private boolean number(String s)
            {
                    String Phostr=s;
                    for(int i=0;i<Phostr.length();i++)
                    {
                            char ch=Phostr.charAt(i);
                            if(ch<'0'||ch>'9')
                            return false;
                    }
                    return true;
	}
    private void addpatient()
    {
        String pbirthday;

        pbirthday=cyear.getText()+"-"+cmonth.getText()+"-"+cday.getText();

        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;
     String sql;
     sqlStr="insert into patient(name,sex,birthday,bloodtype,stature,avoirdupois,medname,nenumber,doctor,price) values(\'"+jTpname.getText()+"\',\'"+jComboBox1.getSelectedItem()+"\',\'"+pbirthday+"\',\'"+jComboBox2.getSelectedItem()+"\',\'"+jTpstature.getText()+"\',\'"+jTpavo.getText()+"\',\'"+mname.getText()+"\',\'"+mnumber.getText()+"\',\'"+pdoctor.getText()+"\',\'"+price.getText()+"\')";
     Statement s = con.createStatement();
     s.executeUpdate(sqlStr);
     JOptionPane.showMessageDialog(null,"病人信息添加成功!");
     sql="insert into reckoning(patientname,medicine,price,number,doctor) values(\'"+jTpname.getText()+"\',\'"+mname.getText()+"\',\'"+price.getText()+"\',\'"+mnumber.getText()+"\',\'"+pdoctor.getText()+"\')";
     s.executeUpdate(sql);
     JOptionPane.showMessageDialog(null,"病人相应帐单信息添加成功!");
     jTpname.setText("");
     jComboBox1.setSelectedItem("");
     cyear.setText("");
     cmonth.setText("");
     cday.setText("");
     jComboBox2.setSelectedItem("");
     jTpstature.setText("");
     jTpavo.setText("");
     mname.setText("");
     price.setText("");
     mnumber.setText("");
     pdoctor.setText("");

     queryDataSet1.refresh();
     s.close();
     con.close();
 } catch (SQLException ce) {
     System.out.println(ce);
 }
    }

    public void jBexit_actionPerformed(ActionEvent e) {
        jTpname.setText("");
        jComboBox1.setSelectedItem("");
        cyear.setText("");
        cmonth.setText("");
        cday.setText("");
        jComboBox2.setSelectedItem("");
        jTpstature.setText("");
        jTpavo.setText("");
        mname.setText("");
        price.setText("");
        mnumber.setText("");
     pdoctor.setText("");
    }


}


class add_patient_jBexit_actionAdapter implements ActionListener {
    private add_patient adaptee;
    add_patient_jBexit_actionAdapter(add_patient adaptee) {
        this.adaptee = adaptee;
    }

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


class add_patient_jButton1_actionAdapter implements ActionListener {
    private add_patient adaptee;
    add_patient_jButton1_actionAdapter(add_patient adaptee) {
        this.adaptee = adaptee;
    }

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

⌨️ 快捷键说明

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