📄 addpatientinfo.java
字号:
jpCenter.add(jcmbSex);
jpCenter.add(jlblPSex);
jpCenter.add(jEditorPane1);
jpCenter.add(jbtnDelL);
jpCenter.add(jEditorPane2);
jbtnReset.addActionListener(new AddPatientInfo_jbtnReset_actionAdapter(this));
panel1.add(jpCenter, java.awt.BorderLayout.CENTER);
panel1.add(jpNorth, java.awt.BorderLayout.NORTH);
this.getContentPane().add(panel1, java.awt.BorderLayout.CENTER);
this.setResizable(false);
}
public void jbtnReset_actionPerformed(ActionEvent e) {
jtxtPName.setText("");
jtxtPHeight.setText("");
jtxtPWeight.setText("");
leechdomModelb.clear();
}
public void jbtnCancle_actionPerformed(ActionEvent e) {
dispose();
}
public void jlstLeechdom_mouseClicked(MouseEvent e) {
index=jlstLeechdom.getSelectedIndex();
}
public void jbtnAddL_actionPerformed(ActionEvent e) {
if(jlstLeechdom.isSelectionEmpty() == true)
JOptionPane.showMessageDialog(null,"请在可选药品里面选择至少一种药品!","系统提示",JOptionPane.ERROR_MESSAGE);
else
{
selected = leechdomModel.getElementAt(index).toString();
try{
db = new MyDatabase();
rs = db.getResultSet("SELECT * FROM leechdom WHERE name ='" +
selected + "'");
rs.next();
count = rs.getInt("count");
if (count == 0) {
JOptionPane.showMessageDialog(null, "该药品现在正缺,请使用别的药品!",
"系统提示", JOptionPane.ERROR_MESSAGE);
} else {
count =count-1;
Statement stm=db.getStatement();
String url = new String();
url="UPDATE leechdom SET count ='"+count+"'"+"WHERE name='"+selected+"'";
try {
stm.executeUpdate(url);
} catch (SQLException se) {
se.printStackTrace();
}
leechdomModel.removeElementAt(index);
leechdomModelb.addElement(selected);
}
}catch(SQLException se){
se.printStackTrace();
}
}
}
public void jbtnDelL_actionPerformed(ActionEvent e) {
if (jlstLeechdomb.isSelectionEmpty() == true)
JOptionPane.showMessageDialog(null, "请在可选药品里面选择至少一种药品!", "系统提示",
JOptionPane.ERROR_MESSAGE);
else {
selected = leechdomModelb.getElementAt(index).toString();
db = new MyDatabase();
Statement stm = db.getStatement();
String url = new String();
url = "UPDATE leechdom SET count =count+1 WHERE name='"+selected+"'";
try {
stm.executeUpdate(url);
} catch (SQLException se) {
se.printStackTrace();
}
leechdomModelb.removeElementAt(index);
leechdomModel.addElement(selected);
}
}
public void jlstLeechdomb_mouseClicked(MouseEvent e) {
index = jlstLeechdomb.getSelectedIndex();
}
public void jbtnOK_actionPerformed(ActionEvent e) {
if(jtxtPName.getText().equals("") || jtxtPHeight.getText().equals("") || jtxtPWeight.getText().equals("")||leechdomModelb.getSize()==0)
JOptionPane.showMessageDialog(null,"请输入完整的数据!","系统提示",JOptionPane.ERROR_MESSAGE);
else{
String url=new String();
String strValue=new String();
MyDatabase db = new MyDatabase();
Statement stm=db.getStatement();
int num=jlstLeechdomb.getModel().getSize();
leechdom = leechdomModelb.getElementAt(0).toString();
for(int i=1;i<num;i++)
{
leechdom = leechdom+","+leechdomModelb.getElementAt(i).toString();
}
try{
for(int i=0;i<num;i++)
{
leechdomp = leechdomModelb.getElementAt(i).toString();
db = new MyDatabase();
ResultSet rs = db.getResultSet("SELECT * FROM leechdom WHERE name ='"+leechdomp+"'");
rs.next();
price1 = rs.getFloat("price");
price = price+price1;
}
}catch(SQLException se){
se.printStackTrace();
}
birth = jcmbYear.getSelectedItem().toString()+"-"+jcmbMonth.getSelectedItem().toString()+"-"+jcmbDay.getSelectedItem().toString();
url="INSERT INTO patient(name,dname,sex,birth,blood,height,weight,leechdom,price";
strValue="'"+ jtxtPName.getText()+"','"+jtxtDoctorname.getText()+"','"+jcmbSex.getSelectedItem().toString()+"','"+birth+"','"+jcmbXue.getSelectedItem().toString()+"','"+jtxtPHeight.getText()+"','"+jtxtPWeight.getText()+"','"+leechdom+"','"+ price +"'";
url=url+")values("+strValue+")";
try{
stm.executeUpdate(url);
}catch(SQLException se){
se.printStackTrace();
}
JOptionPane.showMessageDialog(null,"添加病人信息成功!","系统提示",JOptionPane.INFORMATION_MESSAGE);
db.close();
dispose();
}
}
public void jbtnSearch_actionPerformed(ActionEvent e) {
if (jtxtSearch.getText().equals("")) {
JOptionPane.showMessageDialog(null, "请输入查询信息");
return;
}
db = new MyDatabase();
lname = jtxtSearch.getText();
rs = db.getResultSet("SELECT name FROM leechdom WHERE name like '%" + lname + "%'");
leechdomModel.clear();
try{
while(rs.next()){
leechdomModel.addElement(rs.getString("name"));
}
}catch(SQLException se){
se.printStackTrace();
}
}
public void jbtnShow_actionPerformed(ActionEvent e) {
leechdomModel.clear();
db = new MyDatabase();
try{
ResultSet rs = db.getResultSet("SELECT * FROM leechdom");
while (rs.next()) {
leechdomModel.addElement(rs.getString("name"));
}
}catch(SQLException se){
se.printStackTrace();
}
db.close();
}
}
class AddPatientInfo_jbtnShow_actionAdapter implements ActionListener {
private AddPatientInfo adaptee;
AddPatientInfo_jbtnShow_actionAdapter(AddPatientInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jbtnShow_actionPerformed(e);
}
}
class AddPatientInfo_jbtnSearch_actionAdapter implements ActionListener {
private AddPatientInfo adaptee;
AddPatientInfo_jbtnSearch_actionAdapter(AddPatientInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jbtnSearch_actionPerformed(e);
}
}
class AddPatientInfo_jbtnOK_actionAdapter implements ActionListener {
private AddPatientInfo adaptee;
AddPatientInfo_jbtnOK_actionAdapter(AddPatientInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jbtnOK_actionPerformed(e);
}
}
class AddPatientInfo_jlstLeechdomb_mouseAdapter extends MouseAdapter {
private AddPatientInfo adaptee;
AddPatientInfo_jlstLeechdomb_mouseAdapter(AddPatientInfo adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.jlstLeechdomb_mouseClicked(e);
}
}
class AddPatientInfo_jlstLeechdom_mouseAdapter extends MouseAdapter {
private AddPatientInfo adaptee;
AddPatientInfo_jlstLeechdom_mouseAdapter(AddPatientInfo adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.jlstLeechdom_mouseClicked(e);
}
}
class AddPatientInfo_jbtnDel_actionAdapter implements ActionListener {
private AddPatientInfo adaptee;
AddPatientInfo_jbtnDel_actionAdapter(AddPatientInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jbtnAddL_actionPerformed(e);
}
}
class AddPatientInfo_jbtnDelL_actionAdapter implements ActionListener {
private AddPatientInfo adaptee;
AddPatientInfo_jbtnDelL_actionAdapter(AddPatientInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jbtnDelL_actionPerformed(e);
}
}
class AddPatientInfo_jbtnCancle_actionAdapter implements ActionListener {
private AddPatientInfo adaptee;
AddPatientInfo_jbtnCancle_actionAdapter(AddPatientInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jbtnCancle_actionPerformed(e);
}
}
class AddPatientInfo_jbtnReset_actionAdapter implements ActionListener {
private AddPatientInfo adaptee;
AddPatientInfo_jbtnReset_actionAdapter(AddPatientInfo adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jbtnReset_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -