📄 changeprotectget.java
字号:
package yd.pethospital.protectcommom;
import java.sql.*;
import java.util.regex.*;
import javax.swing.*;
import yd.pethospital.protectregister.view.*;
import yd.pethospital.share.SystemShare;
public class ChangeProtectGet {
static PreparedStatement pst; //声明PreparedStatement对象
boolean check = false;
public JFrame frame; //用于错误时返回原窗体
public ChangeProtectGet(JFrame frame){
this.frame=frame;
if(setDao(check)){
frame.dispose();
}
}
public static void GetText(){
ChangeProtect.TNum.setText((String)ProtectRegister.BTCK.getValueAt(ProtectRegister.BTCK.getSelectedRow(), 0)); //获得所选中的表格的内容 编号
ChangeProtect.TDate.setText((String)ProtectRegister.BTCK.getValueAt(ProtectRegister.BTCK.getSelectedRow(), 1)); //接种日期
ChangeProtect.TMedicine.setText((String)ProtectRegister.BTCK.getValueAt(ProtectRegister.BTCK.getSelectedRow(), 2)); //药物
ChangeProtect.TAccount.setText((String)ProtectRegister.BTCK.getValueAt(ProtectRegister.BTCK.getSelectedRow(), 3)); //数量
ChangeProtect.TMan.setText((String)ProtectRegister.BTCK.getValueAt(ProtectRegister.BTCK.getSelectedRow(), 4)); //诊断人
}
public boolean setDao(boolean check){
try {
SystemShare.SQL="update EpidemicInfo set inoculatedate=?,bacterincode=?,usingamount=?,inoculateman=? where petcode="+ChangeProtect.TNum.getText();
SystemShare.getConnection();
ChangeProtectGet.pst=SystemShare.pst;
if(ChangeProtect.TDate.getText().trim().equals("")){ //日期为空处理
JOptionPane.showMessageDialog(null,"接种日期不允许为空!","防疫诊断",JOptionPane.ERROR_MESSAGE);
ChangeProtect.TDate.requestFocus();
return false;
}
//日期格式处理
Pattern birth=Pattern.compile("(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29) ");
Matcher mbirth=birth.matcher(ChangeProtect.TDate.getText());
if (!mbirth.matches()){
JOptionPane.showMessageDialog(null,"接种日期格式不符,重新输入!", "错误对话框",JOptionPane.ERROR_MESSAGE);
ChangeProtect.TDate.setText("");
ChangeProtect.TDate.requestFocus();
return false;
}
if(ChangeProtect.TMedicine.getText().trim().equals("")){ //疫苗为空处理
JOptionPane.showMessageDialog(null,"药物编号不允许为空!","防疫诊断",JOptionPane.ERROR_MESSAGE);
ChangeProtect.TMedicine.requestFocus();
return false;
}
if(ChangeProtect.TAccount.getText().trim().equals("")){ //数量为空处理
JOptionPane.showMessageDialog(null,"数量不允许为空!","防疫诊断",JOptionPane.ERROR_MESSAGE);
ChangeProtect.TAccount.requestFocus();
return false;
}
if(ChangeProtect.TMan.getText().trim().equals("")){ //诊断人为空处理
JOptionPane.showMessageDialog(null,"大夫不允许为空!","防疫诊断",JOptionPane.ERROR_MESSAGE);
ChangeProtect.TMan.requestFocus();
return false;
}
pst.setString(1,ChangeProtect.TDate.getText().trim()); //更新接种日期
pst.setString(2,ChangeProtect.TMedicine.getText().trim()); //更新疫苗
pst.setString(3,ChangeProtect.TAccount.getText().trim()); //更新数量
pst.setString(4,ChangeProtect.TMan.getText().trim()); //更新诊断人
pst.executeUpdate(); //更新数据库
//修改成功
SystemShare.changesuccess();
frame.dispose();
new ProtectRegister();
this.check=check;
} catch (SQLException e) {
SystemShare.changefail();
}
SystemShare.close();
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -