📄 addpay.java
字号:
label_28.setBounds(265, 470, 81, 15);
frame.getContentPane().add(label_28);
final JLabel label_29 = new JLabel();
label_29.setText("代扣电费:");
label_29.setBounds(265, 500, 81, 15);
frame.getContentPane().add(label_29);
final JLabel label_30 = new JLabel();
label_30.setText("代扣水费:");
label_30.setBounds(265, 530, 81, 15);
frame.getContentPane().add(label_30);
final JLabel label_31 = new JLabel();
label_31.setText("其他扣款:");
label_31.setBounds(265, 560, 81, 15);
frame.getContentPane().add(label_31);
final JLabel label_32 = new JLabel();
label_32.setText("年份:");
label_32.setBounds(45, 110, 60, 15);
frame.getContentPane().add(label_32);
final JLabel label_33 = new JLabel();
label_33.setText("月份:");
label_33.setBounds(268, 110, 60, 15);
frame.getContentPane().add(label_33);
textField_16 = new JTextField();
textField_16.setBounds(130, 555, 113, 21);
frame.getContentPane().add(textField_16);
textField_17 = new JTextField();
textField_17.setBounds(340, 167, 114, 21);
frame.getContentPane().add(textField_17);
textField_18 = new JTextField();
textField_18.setBounds(340, 197, 113, 21);
frame.getContentPane().add(textField_18);
textField_19 = new JTextField();
textField_19.setBounds(340, 227, 113, 21);
frame.getContentPane().add(textField_19);
textField_20 = new JTextField();
textField_20.setBounds(340, 257, 113, 21);
frame.getContentPane().add(textField_20);
textField_21 = new JTextField();
textField_21.setBounds(340, 287, 113, 21);
frame.getContentPane().add(textField_21);
textField_22 = new JTextField();
textField_22.setBounds(340, 317, 113, 21);
frame.getContentPane().add(textField_22);
textField_23 = new JTextField();
textField_23.setBounds(340, 347, 113, 21);
frame.getContentPane().add(textField_23);
textField_24 = new JTextField();
textField_24.setBounds(340, 377, 113, 21);
frame.getContentPane().add(textField_24);
textField_25 = new JTextField();
textField_25.setBounds(340, 407, 113, 21);
frame.getContentPane().add(textField_25);
textField_26 = new JTextField();
textField_26.setBounds(340, 437, 113, 21);
frame.getContentPane().add(textField_26);
textField_27 = new JTextField();
textField_27.setBounds(340, 467, 113, 21);
frame.getContentPane().add(textField_27);
textField_28 = new JTextField();
textField_28.setBounds(340, 497, 113, 21);
frame.getContentPane().add(textField_28);
textField_29 = new JTextField();
textField_29.setBounds(340, 527, 113, 21);
frame.getContentPane().add(textField_29);
textField_30 = new JTextField();
textField_30.setBounds(340, 557, 113, 21);
frame.getContentPane().add(textField_30);
textField_31 = new JTextField();
textField_31.setBounds(130, 105, 114, 21);
frame.getContentPane().add(textField_31);
textField_32 = new JTextField();
textField_32.setBounds(339, 107, 114, 21);
frame.getContentPane().add(textField_32);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String employeeid=textField_1.getText();
String BasePay=textField_2.getText();
String HoldAllowance=textField_3.getText();
String RetirementPension=textField_4.getText();
String OtherPay=textField_5.getText();
String MonthliveSubsidy=textField_6.getText();
String GoernmentAllowance=textField_7.getText();
String SanitationFee=textField_8.getText();
String LiveSubsidy=textField_9.getText();
String MissmealFee=textField_10.getText();
String SuburbSubsidy=textField_11.getText();
String CoalAllowance=textField_12.getText();
String Pension=textField_13.getText();
String ReissuePay=textField_14.getText();
String GraduateSubsidy=textField_15.getText();
String DirectorSubsidy=textField_16.getText();
String OtherEarning=textField_17.getText();
String EndowmentInsurance=textField_18.getText();
String AccmulationFund=textField_19.getText();
String HospitalizationInsurance=textField_20.getText();
String WithdrawInsurance=textField_21.getText();
String IdlennessInsurance=textField_22.getText();
String LabourunionFee=textField_23.getText();
String HousingHire=textField_24.getText();
String WithdrawHire=textField_25.getText();
String CampusBroadband=textField_26.getText();
String EradeducthaveLine=textField_27.getText();
String EraductElectricityFee=textField_28.getText();
String EraductwaterFee=textField_29.getText();
String OtherEraduct=textField_30.getText();
String Year=textField_31.getText();
String Month=textField_32.getText();
String Sequence=employeeid+Year+Month;
Float TotalSalsary=Float.valueOf(BasePay).floatValue()+Float.valueOf(HoldAllowance).floatValue()+
Float.valueOf(RetirementPension).floatValue()+Float.valueOf(OtherPay).floatValue()+Float.valueOf(MonthliveSubsidy).floatValue()
+Float.valueOf(GoernmentAllowance).floatValue()+Float.valueOf(SanitationFee).floatValue()+Float.valueOf(LiveSubsidy).floatValue()
+Float.valueOf(MissmealFee).floatValue()+Float.valueOf(SuburbSubsidy).floatValue()+Float.valueOf(CoalAllowance).floatValue()
+Float.valueOf(Pension).floatValue()+Float.valueOf(ReissuePay).floatValue()+Float.valueOf(GraduateSubsidy).floatValue()
+Float.valueOf(DirectorSubsidy).floatValue()+Float.valueOf(OtherEarning).floatValue()+Float.valueOf(EndowmentInsurance).floatValue()
+Float.valueOf(AccmulationFund).floatValue()+Float.valueOf(HospitalizationInsurance).floatValue()+Float.valueOf(WithdrawInsurance).floatValue()
+Float.valueOf(IdlennessInsurance).floatValue()-Float.valueOf(LabourunionFee).floatValue()-Float.valueOf(HousingHire).floatValue()
-Float.valueOf(WithdrawHire).floatValue()-Float.valueOf(CampusBroadband).floatValue()-Float.valueOf(EradeducthaveLine).floatValue()
-Float.valueOf(EraductElectricityFee).floatValue()-Float.valueOf(EraductwaterFee).floatValue()-Float.valueOf(OtherEraduct).floatValue();
try{
Connection con=getConnection();
Statement stmt=con.createStatement();
java.util.Random r = new java.util.Random();
String random = "";
for (int i=0;i<8;i++){
random += Integer.toString(r.nextInt(36) ,36);
}
textField.setText(random);
String sql = "insert into employpay(id,employeeid,BasePay,HoldAllowance," +
"RetirementPension,OtherPay,MonthliveSubsidy,GoernmentAllowance," +
"SanitationFee,LiveSubsidy,MissmealFee," +
"SuburbSubsidy,CoalAllowance,Pension,ReissuePay,GraduateSubsidy," +
"DirectorSubsidy,OtherEarning,EndowmentInsurance,AccmulationFund," +
"HospitalizationInsurance,WithdrawInsurance,IdlennessInsurance," +
"LabourunionFee,HousingHire,WithdrawHire,CampusBroadband," +
"EradeducthaveLine,EraductElectricityFee,EraductwaterFee," +
"OtherEraduct,Year,Month,TotalSalsary,Sequence)" +
" values( '"+random+"','"+employeeid+"','"+BasePay+"','"+HoldAllowance+"'," +
"'"+RetirementPension+"','"+OtherPay+"','"+MonthliveSubsidy+"'," +
"'"+GoernmentAllowance+"','"+SanitationFee+"','"+LiveSubsidy+"','"+MissmealFee+"'," +
"'"+SuburbSubsidy+"','"+CoalAllowance+"','"+Pension+"' ," +
"'"+ReissuePay+"','"+GraduateSubsidy+"','"+DirectorSubsidy+"','"+OtherEarning+"'," +
"'"+EndowmentInsurance+"','"+AccmulationFund+"','"+HospitalizationInsurance+"','"+WithdrawInsurance+"'," +
"'"+IdlennessInsurance+"','"+LabourunionFee+"','"+HousingHire+"','"+WithdrawHire+"'," +
"'"+CampusBroadband+"','"+EradeducthaveLine+"','"+EraductElectricityFee+"','"+EraductwaterFee+"'," +
"'"+OtherEraduct+"','"+Year+"','"+Month+"','"+TotalSalsary+"' ,'"+Sequence+"' )";
stmt.executeUpdate(sql);
stmt.close();
con.close();
Object[] options={"是(y)","否(n)","取消",};
String str1=new String("提示!数据已写入!");
JOptionPane.showOptionDialog(null,str1,"提示窗口",JOptionPane.DEFAULT_OPTION,JOptionPane.WARNING_MESSAGE,null,options,options[0]);
}
catch(java.lang.ClassNotFoundException e){
System.err.print(" ClassNotFoundException: ");
System.err.println(e.getMessage());
}
catch(SQLException ex){
System.err.println(" SQLException: "+ex.getMessage());
}
catch(Exception e) {
e.printStackTrace();
}
}});
button.setText("添加");
button.setBounds(147, 618, 99, 23);
frame.getContentPane().add(button);
final JButton button_1 = new JButton();
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
frame.dispose();
}
});
button_1.setText("取消");
button_1.setBounds(339, 618, 99, 23);
frame.getContentPane().add(button_1);
final JButton button_2 = new JButton();
button_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String employeeid=textField_1.getText();
String year=textField_31.getText();
String month=textField_32.getText();
try{
if(employeeid.equals("")||year.equals("")||month.equals(""))
{
Object[] options={"是(y)","否(n)","取消",};
String str1=new String("警告!员工号,年份或月份为空,请重新输入!");
JOptionPane.showOptionDialog(null,str1,"警告窗口",JOptionPane.DEFAULT_OPTION,JOptionPane.WARNING_MESSAGE,null,options,options[0]);
}
else{
Connection con=getConnection();
Statement stmt=con.createStatement();
String query="select * from employpay where employeeid='"+employeeid+"' ";
ResultSet rs=stmt.executeQuery(query);
if(rs.next()){
String e=rs.getString("employeeid");
String y=rs.getString("employeeid");
String m=rs.getString("employeeid");
if(e.equals(employeeid)&&y.equals(year)&&m.equals(month)){
Object[] options={"是(y)","否(n)","取消",};
String str1=new String("警告!此条信息已存在,请重新输入!");
JOptionPane.showOptionDialog(null,str1,"警告窗口",JOptionPane.DEFAULT_OPTION,JOptionPane.WARNING_MESSAGE,null,options,options[0]);
textField_1.setText(null);
textField_31.setText(null);
textField_32.setText(null);
}
else{
Object[] options={"是(y)","否(n)","取消",};
String str1=new String("连接数据库失败!");
JOptionPane.showOptionDialog(null,str1,"警告窗口",JOptionPane.DEFAULT_OPTION,JOptionPane.WARNING_MESSAGE,null,options,options[0]);
}
}
else{
Object[] options={"是(y)","否(n)","取消",};
String str1=new String("提示!此信息不存在,可以添加!");
JOptionPane.showOptionDialog(null,str1,"警告窗口",JOptionPane.DEFAULT_OPTION,JOptionPane.WARNING_MESSAGE,null,options,options[0]);
textField.setText(null);
textField_2.setText(null);
textField_3.setText(null);
textField_4.setText(null);
textField_5.setText(null);
textField_6.setText(null);
textField_7.setText(null);
textField_8.setText(null);
textField_9.setText(null);
textField_10.setText(null);
textField_11.setText(null);
textField_12.setText(null);
textField_13.setText(null);
textField_14.setText(null);
textField_15.setText(null);
textField_16.setText(null);
textField_17.setText(null);
textField_18.setText(null);
textField_19.setText(null);
textField_20.setText(null);
textField_21.setText(null);
textField_22.setText(null);
textField_23.setText(null);
textField_24.setText(null);
textField_25.setText(null);
textField_26.setText(null);
textField_27.setText(null);
textField_28.setText(null);
textField_29.setText(null);
textField_30.setText(null);
}
rs.close();
stmt.close();
con.close();
}
}
catch(java.lang.ClassNotFoundException e){
System.err.print(" ClassNotFoundException: ");
System.err.println(e.getMessage());
}
catch(SQLException ex){
System.err.println(" SQLException: "+ex.getMessage());
}
catch(Exception e) {
e.printStackTrace();
}
}});
button_2.setText("查询");
button_2.setBounds(339, 76, 70, 23);
frame.getContentPane().add(button_2);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -