📄 changecommon.java
字号:
package yd.pethospital.changepasswordcommon;
import java.sql.*;
import java.util.regex.*;
import javax.swing.*;
import yd.pethospital.login.view.Login;
import yd.pethospital.share.SystemShare;
import yd.pethospital.changepassword.view.*;
public class ChangeCommon {
public static PreparedStatement pst; //声明PreparedStatement对象
public static String level,Usercode; //用户级别、用户编号
boolean check = false;
public JFrame frame;
public ChangeCommon(JFrame frame){
this.frame=frame;
if(setDao(check)){
frame.dispose();
}
}
public boolean setDao(boolean check){
try {
SystemShare.SQL="update UserInfo set password=? where usercode="+Login.TCode.getText();
SystemShare.getConnection();
ChangeCommon.pst=SystemShare.pst;
ChangePassword.TOld.setText(Login.TPassword.getText()); //新建密码
if(ChangePassword.TNew.getText().trim().equals("")){
JOptionPane.showMessageDialog(null,"新建密码不允许为空!","修改密码",JOptionPane.ERROR_MESSAGE);
ChangePassword.TNew.requestFocus();
return false;
}
Pattern password=Pattern.compile("[0-9]{6}"); //密码格式
Matcher mpassword=password.matcher(ChangePassword.TNew.getText().trim());
if (!mpassword.matches()){
JOptionPane.showMessageDialog(null,"新建密码不符,重新输入!", "错误对话框",JOptionPane.ERROR_MESSAGE);
ChangePassword.TNew.setText("");
ChangePassword.TNew.requestFocus();
return false;
}
if(ChangePassword.TSure.getText().trim().equals("")){ //确认密码
JOptionPane.showMessageDialog(null,"确认密码不允许为空!","修改密码",JOptionPane.ERROR_MESSAGE);
ChangePassword.TSure.requestFocus();
return false;
}
Pattern passwords=Pattern.compile("[0-9]{6}"); //确认密码格式
Matcher mpasswords=passwords.matcher(ChangePassword.TNew.getText().trim());
if (!mpasswords.matches()){
JOptionPane.showMessageDialog(null,"确认密码不符,重新输入!", "错误对话框",JOptionPane.ERROR_MESSAGE);
ChangePassword.TSure.setText("");
ChangePassword.TSure.requestFocus();
return false;
}
if(!ChangePassword.TNew.getText().trim().equals(ChangePassword.TSure.getText().trim())){ //判断新建密码与确认密码不相符
JOptionPane.showMessageDialog(null,"新建密码与确认密码不相符!","修改密码",JOptionPane.ERROR_MESSAGE);
ChangePassword.TNew.setText("");
ChangePassword.TSure.setText("");
return false;
}
pst.setString(1,ChangePassword.TSure.getText().trim()); //修改密码
pst.executeUpdate(); //更新数据库
SystemShare.changesuccess(); //修改成功
frame.dispose();
this.check=check;
} catch (SQLException e) { //处理异常
SystemShare.changefail();
}
SystemShare.close();
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -