做课程设计遇到一个问题。做的是工资管理系统。我想实现 如果已经输入一个月的工资,如果再输这个月的,就会提示“该月工资已经录入,不能重复录入”,代码已经写了,没有报错,但就是实现不了,求大佬帮忙解答
/**
* 工资信息修改事件处理
* @param arg0
*/
private void salaryUpdateActionEvent(ActionEvent arg0) {
String GH1=s_numTxt.getText();
Double 基本工资=Double.parseDouble(JBGZTxt_1.getText());
Double 福利补贴=Double.parseDouble(FLBTTxt_1.getText());
Double 奖励工资=Double.parseDouble(JLGZTxt_1.getText());
Double 失业保险=Double.parseDouble(SYBXTxt_1.getText());
Double 住房公积金=Double.parseDouble(ZFGJJTxt_1.getText());
Double 个税=Double.parseDouble(GSTxt_1.getText());
String 工资发放时间=SJTxt_1.getText();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
/*if(DoubleUtil.isEmpty(基本工资)){
JOptionPane.showMessageDialog(null, "请选择要修改的记录");
return;
}*/
Salary salary=new Salary(GH1,基本工资, 福利补贴,奖励工资,失业保险,住房公积金,个税,工资发放时间);
Connection con=null;
try {
con=jdbc.getCon();
PreparedStatement sf = con.prepareStatement("select * from 工资 where 工号= ?");
sf.setString(1, salary.get工号());
ResultSet rf = sf.executeQuery();
//如果salary表中有记录
while (rf.next()) {
Date edate = rf.getDate("时间");
//获取已录入年月
String year1 = sdf.format(edate).substring(0, 4);
String month1 = sdf.format(edate).substring(5, 7);
// 获取输入年月
String Year = salary.get工资发放时间().substring(0, 4);
String Month = salary.get工资发放时间().substring(5, 7); if (year1.equals(Year) && month1.equals(Month)) {
JOptionPane.showMessageDialog(null, "该月工资已录入,不能重复录入");
break;
}
}
int modifyNum=salaryDao.update(con,salary);
if(modifyNum!=0) {
JOptionPane.showMessageDialog(null,"修改成功");
this.resetValue();
this.fillTable(new Salary());
}else {
JOptionPane.showMessageDialog(null,"修改失败");
}
}catch(Exception arg) {
arg.printStackTrace();
JOptionPane.showMessageDialog(null, "修改失败");
}finally {
try {
jdbc.closeCon(con);
}catch(Exception arg) {
arg.printStackTrace();
}
}
}
/**
* 工资信息修改事件处理
* @param arg0
*/
private void salaryUpdateActionEvent(ActionEvent arg0) {
String GH1=s_numTxt.getText();
Double 基本工资=Double.parseDouble(JBGZTxt_1.getText());
Double 福利补贴=Double.parseDouble(FLBTTxt_1.getText());
Double 奖励工资=Double.parseDouble(JLGZTxt_1.getText());
Double 失业保险=Double.parseDouble(SYBXTxt_1.getText());
Double 住房公积金=Double.parseDouble(ZFGJJTxt_1.getText());
Double 个税=Double.parseDouble(GSTxt_1.getText());
String 工资发放时间=SJTxt_1.getText();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
/*if(DoubleUtil.isEmpty(基本工资)){
JOptionPane.showMessageDialog(null, "请选择要修改的记录");
return;
}*/
Salary salary=new Salary(GH1,基本工资, 福利补贴,奖励工资,失业保险,住房公积金,个税,工资发放时间);
Connection con=null;
try {
con=jdbc.getCon();
PreparedStatement sf = con.prepareStatement("select * from 工资 where 工号= ?");
sf.setString(1, salary.get工号());
ResultSet rf = sf.executeQuery();
//如果salary表中有记录
while (rf.next()) {
Date edate = rf.getDate("时间");
//获取已录入年月
String year1 = sdf.format(edate).substring(0, 4);
String month1 = sdf.format(edate).substring(5, 7);
// 获取输入年月
String Year = salary.get工资发放时间().substring(0, 4);
String Month = salary.get工资发放时间().substring(5, 7); if (year1.equals(Year) && month1.equals(Month)) {
JOptionPane.showMessageDialog(null, "该月工资已录入,不能重复录入");
break;
}
}
int modifyNum=salaryDao.update(con,salary);
if(modifyNum!=0) {
JOptionPane.showMessageDialog(null,"修改成功");
this.resetValue();
this.fillTable(new Salary());
}else {
JOptionPane.showMessageDialog(null,"修改失败");
}
}catch(Exception arg) {
arg.printStackTrace();
JOptionPane.showMessageDialog(null, "修改失败");
}finally {
try {
jdbc.closeCon(con);
}catch(Exception arg) {
arg.printStackTrace();
}
}
}
String YearMonth = salary.get工资发放时间()
Date edate = rf.getDate("时间");
String yearMonth1 = sdf1.format(edate);
把YearMonth 和yearMonth1 打印出来看看。