开发团队:206和207
时间:2012年4月8日
数据库配置:sqlserver2000
创建数据库SalaryManagement 在其下创建数据表logindata、
创建数据表Employee
创建数据表January
创建数据表February
创建数据表March
创建数据库April
创建数据表May
创建数据表June
创建数据表July
创建数据表August
创建数据表September
创建数据表October
创建数据表November
创建数据表December
开发工具JDK1.6.21和eclipse,数据库驱动jdbc配置和导入省略。
程序代码如下
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class Login extends JFrame{
private JLabel lbTitle, lbUser, lbPwd;
private JButton btnLogon,btnOK, btnExit;
private Boolean lean=null;
JTextField tfUser = new JTextField(15);
JPasswordField tfPwd = new JPasswordField(15);
JRadioButton radiobutton1=new JRadioButton("教师登陆");
JRadioButton radiobutton2=new JRadioButton("管理登陆");
ButtonGroup buttongroup=new ButtonGroup();
String username=tfUser.getText();
String password=new String(tfPwd.getPassword());
public Login(){
try{init();}catch(Exception e3){
e3.printStackTrace();
}
}
public void init() {
this.setTitle("登陆界面");
this.setBounds(450, 300, 400, 300);
JPanel p = new JPanel(new BorderLayout());
p.setBounds(0, 0, 500, 400);
JPanel p1 = new JPanel(new FlowLayout());
JPanel p2 = new JPanel(new GridLayout(2,1));
JPanel p21 = new JPanel(new FlowLayout());
JPanel p22 = new JPanel(new FlowLayout());
JPanel p3 = new JPanel(new FlowLayout());
buttongroup.add(radiobutton1);
buttongroup.add(radiobutton2);
this.lbUser = new JLabel(" 用户名:");
this.lbPwd = new JLabel("密 码:");
this.tfUser = new JTextField(15);
this.tfPwd = new JPasswordField(15);
this.tfPwd.setEchoChar('*');
this.btnLogon=new JButton("注册");
this.btnOK = new JButton(" 登录");
this.btnExit = new JButton("退出");
this.btnLogon.addActionListener(new ActionMonitor());
this.btnOK.addActionListener(new ActionMonitor());
this.btnExit.addActionListener(new ActionMonitor());
p1.add(radiobutton1);
p1.add(radiobutton2);
p21.add(this.lbUser);
p21.add(this.tfUser);
p22.add(this.lbPwd);
p22.add(this.tfPwd);
p3.add(btnLogon);
p3.add(this.btnOK);
p3.add(this.btnExit);
p2.add(p21);
p2.add(p22);
p.add(p1, BorderLayout.NORTH);
p.add(p2, BorderLayout.CENTER);
p.add(p3, BorderLayout.SOUTH);
p.setVisible(true);
this.add(p);
this.pack();
this.setVisible(true);
this.addWindowListener(new WindowMonitor());
}
class WindowMonitor extends WindowAdapter {
public void windowClosing(WindowEvent e) {
setVisible(false);
System.exit(0);
}
}
class ActionMonitor implements ActionListener {
public void actionPerformed(ActionEvent e) {
try{
if(e.getSource()==btnOK){
if(radiobutton2.isSelected()){
ManageUser user1= new ManageUser();
user1.setName(tfUser.getText());
user1.setPassword(new String(tfPwd.getPassword()));
ManageCheck ar1 = new ManageCheck(user1);
if(ar1.check()){
new ManagementFrame().setVisible(true);
}else{
JOptionPane.showMessageDialog(null,"账号或密码错误警告",JFrame.EXIT_ON_CLOSE);
tfUser.setText("");
tfPwd.setText("");
}
}else if(radiobutton1.isSelected()){
User user= new User();
user.setUserName(tfUser.getText());
user.setPassWord(new String(tfPwd.getPassword()));
ActionCheck ar = new ActionCheck(user);
if(ar.check()){
new TeacherFrame().setVisible(true);
}else{
JOptionPane.showMessageDialog(null,"账号或密码错误警告",JFrame.EXIT_ON_CLOSE);
tfUser.setText("");
tfPwd.setText("");
}
}
}
else if(e.getSource() == btnExit) {
setVisible(false);
System.exit(0);
}
else if(e.getSource()==btnLogon){
new LogonFrame().setVisible(true);
}
}
catch(Exception e2){
e2.printStackTrace();
}
}
}
public static void main(String[] args){
Login frame=new Login();
Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize =frame.getSize();
if(frameSize.height>screenSize.height)
frameSize.height=screenSize.height;
if(frameSize.width>screenSize.width)
frameSize.width=screenSize.width;
frame.setLocation((screenSize.width-frameSize.width)/2,(screenSize.height-frameSize.height)/2);
frame.setVisible(true);
}
}
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
public class LogonFrame extends JFrame {
Connection con;
Statement st;
JLabel jLabel1=new JLabel("职工工号");
JLabel jLabel2=new JLabel("登陆密码");
JLabel jLabel3=new JLabel("职工姓别");
JLabel jLabel4=new JLabel("职工性名");
JLabel jLabel5=new JLabel("职工年龄");
JLabel jLabel6=new JLabel("所属院系");
JLabel jLabel7=new JLabel("家庭住址");
JLabel jLabel8=new JLabel("联系电话");
JTextField jTextField1=new JTextField();
JPasswordField jTextField2=new JPasswordField();
JTextField jTextField3=new JTextField();
JTextField jTextField4=new JTextField();
JTextField jTextField5=new JTextField();
JTextField jTextField6=new JTextField();
JTextField jTextField7=new JTextField();
JRadioButton jRadioButton1=new JRadioButton("男");
JRadioButton jRadioButton2=new JRadioButton("女");
ButtonGroup buttonGroup1=new ButtonGroup();
JButton jButton1=new JButton("注册");
JButton jButton2=new JButton("取消");
public LogonFrame()
{
try{
bInit();
}
catch(Exception exception){
exception.printStackTrace();
}
}
private void bInit() throws Exception
{
con=DB.getConn();
st=con.createStatement();
this.setTitle("注册界面");
this.setLayout(null);
this.setSize(450, 450);
this.setLocationRelativeTo(null);
jLabel1.setBounds(new Rectangle(21,17,,24));
jLabel2.setBounds(new Rectangle(21,51,53,22));
jLabel3.setBounds(new Rectangle(21,86,61,27));
jLabel4.setBounds(new Rectangle(21,122,59,25));
jLabel5.setBounds(new Rectangle(21,168,54,24));
jLabel6.setBounds(new Rectangle(21,205,54,24));
jLabel7.setBounds(new Rectangle(21,245,54,24));
jLabel8.setBounds(new Rectangle(21,285,54,25));
jTextField1.setBounds(new Rectangle(102,10,100,30));
jTextField2.setBounds(new Rectangle(102,49,200,30));
jTextField3.setBounds(new Rectangle(102,117,100,33));
jTextField4.setBounds(new Rectangle(102,163,100,29));
jTextField5.setBounds(new Rectangle(102,200,200,29));
jTextField6.setBounds(new Rectangle(102,240,200,29));
jTextField7.setBounds(new Rectangle(102,280,200,29));
jRadioButton1.setBounds(new Rectangle(102,83,65,30));
jRadioButton2.setBounds(new Rectangle(190,85,85,30));
jButton1.setBounds(new Rectangle(130,320,60,32));
jButton2.setBounds(new Rectangle(200,320,60,32));
jRadioButton1.setSelected(true);
jButton1.addActionListener(new ActionMonitor());
jButton2.addActionListener(new ActionMonitor());
this.add(jLabel1);
this.add(jTextField1);
this.add(jLabel2);
this.add(jTextField2);
this.add(jLabel3);
buttonGroup1.add(jRadioButton1);
buttonGroup1.add(jRadioButton2);
this.add(jRadioButton1);
this.add(jRadioButton2);
this.add(jLabel4);
this.add(jTextField3);
this.add(jLabel5);
this.add(jTextField4);
this.add(jLabel6);
this.add(jTextField5);
this.add(jLabel7);
this.add(jTextField6);
this.add(jLabel8);
this.add(jTextField7);
this.add(jButton1);
this.add(jButton2);
}
class ActionMonitor implements ActionListener{
public void actionPerformed(ActionEvent e)
{
String EmployeeID=jTextField1.getText();
String EmployeePassword=new String(jTextField2.getPassword());
String EmployeeSex="";
if(jRadioButton1.isSelected())
EmployeeSex+="男";
if(jRadioButton2.isSelected())
EmployeeSex+="女";
String EmployeeName=jTextField3.getText();
String EmployeeIge=jTextField4.getText();
String EmployeeCollege=jTextField5.getText();
String EmployeeAddress=jTextField6.getText();
String EmployeeTell=jTextField7.getText();
try{
if(e.getSource()==jButton1){
if(EmployeeID.equals("")|EmployeePassword.equals("")|EmployeeName.equals("")|EmployeeIge.equals("")|EmployeeCollege.equals("")|EmployeeAddress.equals("")|EmployeeTell.equals("")){
JOptionPane.showMessageDialog(null,"内容不允许为空警告",JFrame.EXIT_ON_CLOSE);
}else {
st.execute("set dateformat ymd");
st.executeUpdate("insert into Employee values('"+EmployeeID+"','"+EmployeePassword+"','"+EmployeeName+"','"+EmployeeSex+"','"+EmployeeIge+"','"+EmployeeCollege+"','"+EmployeeAddress+"','"+EmployeeTell+"')");
JOptionPane.showMessageDialog(null,"职工添加成功!提示",JFrame.EXIT_ON_CLOSE);
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
}
}else if(e.getSource()==jButton2){
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jTextField7.setText("");
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(null,"职工添加失败!提示",JFrame.EXIT_ON_CLOSE);
ex.printStackTrace();
}
}
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ManagementFrame extends JFrame implements ActionListener
{
JPanel contentPane;
JLayeredPane contentPane1;
JMenuBar jMenuBar1=new JMenuBar();
JMenu jMenu0=new JMenu("系统");
JMenuItem jMenuItem0=new JMenuItem("退出");
JMenuItem jMenuItem10=new JMenuItem("主界面");
JMenu jMenu1=new JMenu("职工管理");
JMenuItem jMenuItem1=new JMenuItem("添加职工");
JMenuItem jMenuItem2=new JMenuItem("修改职工");
JMenuItem jMenuItem3=new JMenuItem("删除职工");
JMenu jMenu2=new JMenu("工资管理");
JMenuItem jMenuItem4=new JMenuItem("添加工资");
JMenuItem jMenuItem5=new JMenuItem("修改工资");
JMenuItem jMenuItem8=new JMenuItem("工资查询");
JMenu jMenu3=new JMenu("职工查询");
JMenuItem jMenuItem6=new JMenuItem("按工号查询");
JMenuItem jMenuItem7=new JMenuItem("按姓名查询");
JMenu jMenu4=new JMenu("帮助");
JMenuItem jMenuItem9=new JMenuItem("互动");
public ManagementFrame()
{
try{
setDefaultCloseOperation(EXIT_ON_CLOSE);
Init();
}
catch(Exception exception){
exception.printStackTrace();
}
}
private void Init() throws Exception
{
setContentPane(new Layeredpane());
setSize(new Layeredpane().getWidth(),new Layeredpane().getHeight());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("教师工资管理小系统");
setLocationRelativeTo(null);
jMenuItem0.addActionListener(this);
jMenuItem1.addActionListener(this);
jMenuItem2.addActionListener(this);
jMenuItem3.addActionListener(this);
jMenuItem4.addActionListener(this);
jMenuItem5.addActionListener(this);
jMenuItem6.addActionListener(this);
jMenuItem7.addActionListener(this);
jMenuItem8.addActionListener(this);
jMenuItem9.addActionListener(this);
jMenuItem10.addActionListener(this);
setJMenuBar(jMenuBar1);
jMenuBar1.add(jMenu0);
jMenuBar1.add(jMenu1);
jMenuBar1.add(jMenu2);
jMenuBar1.add(jMenu3);
jMenuBar1.add(jMenu4);
jMenu0.add(jMenuItem10);
jMenu0.add(jMenuItem0);
jMenu1.add(jMenuItem1);
jMenu1.add(jMenuItem2);
jMenu1.add(jMenuItem3);
jMenu2.add(jMenuItem4);
jMenu2.add(jMenuItem5);
jMenu2.add(jMenuItem8);
jMenu3.add(jMenuItem6);
jMenu3.add(jMenuItem7);
jMenu4.add(jMenuItem9);
}
public void actionPerformed(ActionEvent actionEvent)
{
if(actionEvent.getSource()==jMenuItem0)
{
System.exit(0);
}
if(actionEvent.getSource()==jMenuItem1)
{
AddEmployee addemployee=new AddEmployee();
this.remove(this.getContentPane());
this.setContentPane(addemployee);
this.setVisible(true);
}
if(actionEvent.getSource()==jMenuItem2)
{
ModifyEmployee ModifyEmp=new ModifyEmployee();
this.remove(this.getContentPane());
this.setContentPane(ModifyEmp);
this.setVisible(true);
}
if(actionEvent.getSource()==jMenuItem3)
{
DeleteEmployee DeleteEmp=new DeleteEmployee();
this.remove(this.getContentPane());
this.setContentPane(DeleteEmp);
this.setVisible(true);
}
if(actionEvent.getSource()==jMenuItem4)
{
AddSalary AddSal=new AddSalary();
this.remove(this.getContentPane());
this.setContentPane(AddSal);
this.setVisible(true);
}
if(actionEvent.getSource()==jMenuItem5)
{
ModifySalary ModifySal=new ModifySalary();
this.remove(this.getContentPane());
this.setContentPane(ModifySal);
this.setVisible(true);
}
if(actionEvent.getSource()==jMenuItem8)
{
SalaryInquire SalaryInq=new SalaryInquire();
this.remove(this.getContentPane());
this.setContentPane(SalaryInq);
this.setVisible(true);
}
if(actionEvent.getSource()==jMenuItem6)
{
InquireOnGH OnGH=new InquireOnGH();
this.remove(this.getContentPane());
this.setContentPane(OnGH);
this.setVisible(true);
}
if(actionEvent.getSource()==jMenuItem7)
{
InquireOnName OnName=new InquireOnName();
this.remove(this.getContentPane());
this.setContentPane(OnName);
this.setVisible(true);
}
if(actionEvent.getSource()==jMenuItem9)
{
EmployeeHelp EmployeeH=new EmployeeHelp();
this.remove(this.getContentPane());
this.setContentPane(EmployeeH);
this.setVisible(true);
}
if(actionEvent.getSource()==jMenuItem10){
Layeredpane layeredpane=new Layeredpane();
this.remove(this.getContentPane());
this.setContentPane(layeredpane);
this.setVisible(true);
}
}
}
import java.awt.*;
import java.awt.event.*;
import java.beans.Statement;
import java.sql.Connection;
import javax.swing.*;
public class TeacherFrame extends JFrame implements ActionListener
{
Connection conn;
Statement stmt;
JPanel contentPane;
JLayeredPane contentPane1;
JMenuBar jMenuBar1=new JMenuBar();
JMenu jMenu0=new JMenu("系统");
JMenuItem jMenuItem0=new JMenuItem("退出");
JMenuItem jMenuItem1=new JMenuItem("主界面");
JMenu jMenu1=new JMenu("工资管理");
JMenuItem jMenuItem2=new JMenuItem("工资查询");
JMenu jMenu2=new JMenu("职工查询");
JMenuItem jMenuItem4=new JMenuItem("按工号查询");
JMenuItem jMenuItem5=new JMenuItem("按姓名查询");
JMenu jMenu3=new JMenu("帮助");
JMenuItem jMenuItem6=new JMenuItem("互动");
JMenu jMenu4=new JMenu("密码设置");
JMenuItem jMenuItem7=new JMenuItem("增加密码");
JMenuItem jMenuItem8=new JMenuItem("修改密码");
public TeacherFrame()
{
try{
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
}
catch(Exception exception){
exception.printStackTrace();
}
}
private void jbInit() throws Exception
{
setContentPane(new Layeredpane());
setSize(new Layeredpane().getWidth(),new Layeredpane().getHeight());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("教师工资管理小系统");
setLocationRelativeTo(null);
jMenuItem0.addActionListener(this);
jMenuItem1.addActionListener(this);
jMenuItem2.addActionListener(this);
jMenuItem4.addActionListener(this);
jMenuItem5.addActionListener(this);
jMenuItem6.addActionListener(this);
setJMenuBar(jMenuBar1);
jMenuBar1.add(jMenu0);
jMenuBar1.add(jMenu1);
jMenuBar1.add(jMenu2);
jMenuBar1.add(jMenu4);
jMenuBar1.add(jMenu3);
jMenu0.add(jMenuItem1);
jMenu0.add(jMenuItem0);
jMenu1.add(jMenuItem2);
jMenu2.add(jMenuItem4);
jMenu2.add(jMenuItem5);
jMenu3.add(jMenuItem6);
jMenu4.add(jMenuItem7);
jMenu4.add(jMenuItem8);
}
public void actionPerformed(ActionEvent actionEvent)
{
if(actionEvent.getSource()==jMenuItem0)
{
System.exit(0);
}
if(actionEvent.getSource()==jMenuItem1)
{
Layeredpane layeredpane=new Layeredpane();
this.remove(this.getContentPane());
this.setContentPane(layeredpane);
this.setVisible(true);
}
if(actionEvent.getSource()==jMenuItem2)
{
SalaryInquire SalaryInq=new SalaryInquire();
this.remove(this.getContentPane());
this.setContentPane(SalaryInq);
this.setVisible(true);
}
if(actionEvent.getSource()==jMenuItem4)
{
InquireOnGH OnGH=new InquireOnGH();
this.remove(this.getContentPane());
this.setContentPane(OnGH);
this.setVisible(true);
}
if(actionEvent.getSource()==jMenuItem5)
{
InquireOnName OnName=new InquireOnName();
this.remove(this.getContentPane());
this.setContentPane(OnName);
this.setVisible(true);
}
if(actionEvent.getSource()==jMenuItem6)
{
EmployeeHelp EmployeeH=new EmployeeHelp();
this.remove(this.getContentPane());
this.setContentPane(EmployeeH);
this.setVisible(true);
}
if(actionEvent.getSource()==jMenuItem7)
{
}
if(actionEvent.getSource()==jMenuItem8)
{
}
}
}
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class ActionCheck {
private User user;
ActionCheck(User user) {
this.user = user;
}
public boolean check() {
boolean isAdmin = false;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "";
try {
conn = DB.getConn();
sql = "select * from Employee where employeeid=? and password=?";
pstmt = DB.getPstmt(conn, sql);
pstmt.setString(1, user.getUserName());
pstmt.setString(2, user.getPassWord());
rs = DB.getRs(pstmt);
if (rs.next()) {
isAdmin = true;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DB.close(rs);
DB.close(pstmt);
DB.close(conn);
}
return isAdmin;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
public class AddEmployee extends JPanel implements ActionListener
{
Connection con;
Statement st;
JButton jButton1=new JButton("确定");
JLabel jLabel1=new JLabel("职工工号");
JLabel jLabel2=new JLabel("职工姓名");
JLabel jLabel3=new JLabel("职工性别");
JLabel jLabel4=new JLabel("职工年龄");
JLabel jLabel5=new JLabel("所属院系");
JLabel jLabel6=new JLabel("家庭住址");
JLabel jLabel7=new JLabel("联系电话");
JTextField jTextField1=new JTextField();
JTextField jTextField2=new JTextField();
JTextField jTextField3=new JTextField();
JTextField jTextField4=new JTextField();
JTextField jTextField5=new JTextField();
JTextField jTextField6=new JTextField();
JRadioButton jRadioButton1=new JRadioButton("男");
JRadioButton jRadioButton2=new JRadioButton("女");
ButtonGroup buttonGroup1=new ButtonGroup();
public AddEmployee()
{
try{
jbInit();
}
catch(Exception exception){
exception.printStackTrace();
}
}
private void jbInit() throws Exception
{
con=DB.getConn();
st=con.createStatement();
this.setLayout(null);
jLabel1.setBounds(new Rectangle(21,17,,24));
jLabel2.setBounds(new Rectangle(21,51,53,22));
jLabel3.setBounds(new Rectangle(21,86,61,27));
jLabel4.setBounds(new Rectangle(21,122,59,25));
jLabel5.setBounds(new Rectangle(21,168,54,24));
jLabel6.setBounds(new Rectangle(21,205,54,24));
jLabel7.setBounds(new Rectangle(21,245,54,24));
jTextField1.setBounds(new Rectangle(102,10,200,30));
jTextField2.setBounds(new Rectangle(102,49,200,30));
jTextField3.setBounds(new Rectangle(102,117,80,33));
jTextField4.setBounds(new Rectangle(102,163,200,29));
jTextField5.setBounds(new Rectangle(102,200,200,29));
jTextField6.setBounds(new Rectangle(102,240,200,29));
jRadioButton1.setBounds(new Rectangle(102,83,65,30));
jRadioButton2.setBounds(new Rectangle(190,85,85,30));
jButton1.setBounds(new Rectangle(130,280,150,32));
jRadioButton1.setSelected(true);
jButton1.addActionListener(this);
this.add(jLabel1);
this.add(jTextField1);
this.add(jLabel2);
this.add(jTextField2);
this.add(jLabel3);
buttonGroup1.add(jRadioButton1);
buttonGroup1.add(jRadioButton2);
this.add(jRadioButton1);
this.add(jRadioButton2);
this.add(jLabel4);
this.add(jTextField3);
this.add(jLabel5);
this.add(jTextField4);
this.add(jLabel6);
this.add(jTextField5);
this.add(jLabel7);
this.add(jTextField6);
this.add(jButton1);
}
public void actionPerformed(ActionEvent e){
String EmployeeID=jTextField1.getText();
String EmployeeName=jTextField2.getText();
String EmployeeSex="";
if(jRadioButton1.isSelected())
EmployeeSex+="男";
if(jRadioButton2.isSelected())
EmployeeSex+="女";
String EmployeeAge=jTextField3.getText();
String EmployeeCollege=jTextField4.getText();
String EmployeeAddress=jTextField5.getText();
String EmployeePhone=jTextField6.getText();
try{
st.execute("set dateformat ymd");
st.executeUpdate("insert into Employee values('"+EmployeeID+"','"+""+"','"+EmployeeName+"','"+EmployeeSex+"','"+EmployeeAge+"','"+EmployeeCollege+"','"+EmployeeAddress+"','"+EmployeePhone+"')");
JOptionPane.showMessageDialog(this,"职工添加成功!");
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"职工添加失败!");
ex.printStackTrace();
}
}
}
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
public class AddSalary extends JPanel implements ActionListener
{
Connection con;
Statement st;
String month=null;
JLabel jLabel1=new JLabel("职工工号");
JLabel jLabel2=new JLabel("职工工资");
JLabel jLabel3=new JLabel("增加月份");
JTextField jTextField1=new JTextField();
JTextField jTextField2=new JTextField();
JRadioButton jradiobutton1=new JRadioButton("一");
JRadioButton jradiobutton2=new JRadioButton("二");
JRadioButton jradiobutton3=new JRadioButton("三");
JRadioButton jradiobutton4=new JRadioButton("四");
JRadioButton jradiobutton5=new JRadioButton("五");
JRadioButton jradiobutton6=new JRadioButton("六");
JRadioButton jradiobutton7=new JRadioButton("七");
JRadioButton jradiobutton8=new JRadioButton("八");
JRadioButton jradiobutton9=new JRadioButton("九");
JRadioButton jradiobutton10=new JRadioButton("十");
JRadioButton jradiobutton11=new JRadioButton("十一");
JRadioButton jradiobutton12=new JRadioButton("十二");
JButton jButton1=new JButton("添加工资");
ButtonGroup buttongroup=new ButtonGroup();
String EmployeeID=jTextField1.getText();
String EmployeeSalary=jTextField2.getText();
public AddSalary()
{
try{
jbInit();
}
catch(Exception exception){
exception.printStackTrace();
}
}
private void jbInit() throws Exception
{
con=DB.getConn();
st=con.createStatement();
this.setLayout(null);
buttongroup.add(jradiobutton1);
buttongroup.add(jradiobutton2);
buttongroup.add(jradiobutton3);
buttongroup.add(jradiobutton4);
buttongroup.add(jradiobutton5);
buttongroup.add(jradiobutton6);
buttongroup.add(jradiobutton7);
buttongroup.add(jradiobutton8);
buttongroup.add(jradiobutton9);
buttongroup.add(jradiobutton10);
buttongroup.add(jradiobutton11);
buttongroup.add(jradiobutton12);
jLabel1.setBounds(new Rectangle(21,17,,24));
jLabel2.setBounds(new Rectangle(21,63,53,22));
jradiobutton1.setBounds(new Rectangle(21,138,40,20));
jradiobutton2.setBounds(new Rectangle(,138,40,20));
jradiobutton3.setBounds(new Rectangle(107,138,40,20));
jradiobutton4.setBounds(new Rectangle(150,138,40,20));
jradiobutton5.setBounds(new Rectangle(193,138,40,20));
jradiobutton6.setBounds(new Rectangle(236,138,40,20));
jradiobutton7.setBounds(new Rectangle(21,160,40,20));
jradiobutton8.setBounds(new Rectangle(,160,40,20));
jradiobutton9.setBounds(new Rectangle(107,160,40,20));
jradiobutton10.setBounds(new Rectangle(150,160,40,20));
jradiobutton11.setBounds(new Rectangle(193,160,55,20));
jradiobutton12.setBounds(new Rectangle(250,160,55,20));
jLabel3.setBounds(21,105,,24);
jTextField1.setBounds(new Rectangle(102,10,120,30));
jTextField2.setBounds(new Rectangle(102,60,120,30));
jButton1.setBounds(new Rectangle(102,200,100,32));
jButton1.addActionListener(this);
this.add(jradiobutton1);
this.add(jradiobutton2);
this.add(jradiobutton3);
this.add(jradiobutton4);
this.add(jradiobutton5);
this.add(jradiobutton6);
this.add(jradiobutton7);
this.add(jradiobutton8);
this.add(jradiobutton9);
this.add(jradiobutton10);
this.add(jradiobutton11);
this.add(jradiobutton12);
this.add(jLabel1);
this.add(jTextField1);
this.add(jLabel2);
this.add(jTextField2);
this.add(jLabel3);
this.add(jButton1);
}
public void actionPerformed(ActionEvent e)
{
String EmployeeID=jTextField1.getText();
String EmployeeSalary=jTextField2.getText();
if(EmployeeID.equals("")|EmployeeSalary.equals("")){
JOptionPane.showMessageDialog(this, "内容不允许为空");
}else{
try{
if(jradiobutton1.isSelected())
month="insert into January(employeeid,January) values('"+EmployeeID+"','"+EmployeeSalary+"')";
else if(jradiobutton2.isSelected())
month="insert into February(employeeid,February) values('"+EmployeeID+"','"+EmployeeSalary+"')";
else if(jradiobutton3.isSelected())
month="insert into March(employeeid,March) values('"+EmployeeID+"','"+EmployeeSalary+"')";
else if(jradiobutton4.isSelected())
month="insert into April(employeeid,April) values('"+EmployeeID+"','"+EmployeeSalary+"')";
else if(jradiobutton5.isSelected())
month="insert into May(employeeid,May) values('"+EmployeeID+"','"+EmployeeSalary+"')";
else if(jradiobutton6.isSelected())
month="insert into June(employeeid,June) values('"+EmployeeID+"','"+EmployeeSalary+"')";
else if(jradiobutton7.isSelected())
month="Julyinsert into July(employeeid,July) values('"+EmployeeID+"','"+EmployeeSalary+"')";
else if(jradiobutton8.isSelected())
month="Augustinsert into August(employeeid,August) values('"+EmployeeID+"','"+EmployeeSalary+"')";
else if(jradiobutton9.isSelected())
month="insert into September(employeeid,September) values('"+EmployeeID+"','"+EmployeeSalary+"')";
else if(jradiobutton10.isSelected())
month="insert into October(employeeid,October) values('"+EmployeeID+"','"+EmployeeSalary+"')";
else if(jradiobutton11.isSelected())
month="insert into November(employeeid,November) values('"+EmployeeID+"','"+EmployeeSalary+"')";
else if(jradiobutton12.isSelected())
month="insert into December(employeeid,December) values('"+EmployeeID+"','"+EmployeeSalary+"')";
st.executeUpdate(month);
JOptionPane.showMessageDialog(this,"工资添加成功!");
jTextField1.setText("");
jTextField2.setText("");
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资添加失败!");
ex.printStackTrace();
}
}
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DB {
public static Connection getConn() {
Connection conn = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:SalaryManagement", "sa", "youpassword");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public static Statement getStmt(Connection conn) {
Statement stmt = null;
try {
stmt = conn.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
return stmt;
}
public static PreparedStatement getPstmt(Connection conn, String sql) {
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return pstmt;
}
public static ResultSet getRs(PreparedStatement pstmt) {
ResultSet rs = null;
try {
rs = pstmt.executeQuery();
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
public static ResultSet getRs(Statement stmt, String sql) {
ResultSet rs = null;
try {
rs = stmt.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
public static void close(Connection conn) {
try {
if (conn != null)
conn.close();
conn = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void close(Statement stmt) {
try {
if (stmt != null)
stmt.close();
stmt = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void close(PreparedStatement pstmt) {
try {
if (pstmt != null)
pstmt.close();
pstmt = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void close(ResultSet rs) {
try {
if (rs != null)
rs.close();
rs = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
}
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
public class DeleteEmployee extends JPanel implements ActionListener
{
Connection con;
Statement st;
JLabel jLabel1=new JLabel("请输入待删除的职工的编号");
JTextField jTextField1=new JTextField();
JButton jButton1=new JButton("删除");
public DeleteEmployee()
{
try{
jbInit();
}
catch(Exception exception){
exception.printStackTrace();
}
}
private void jbInit() throws Exception
{
con=DB.getConn();
st=con.createStatement();
this.setLayout(null);
jLabel1.setFont(new java.awt.Font("黑体",Font.BOLD,14));
jLabel1.setBounds(new Rectangle(70,20,200,30));
jTextField1.setBounds(new Rectangle(70,80,207,41));
jButton1.setBounds(new Rectangle(70,175,205,36));
jButton1.addActionListener(this);
this.add(jLabel1);
this.add(jTextField1);
this.add(jButton1);
}
public void actionPerformed(ActionEvent e)
{
String EmployeeID=jTextField1.getText();
if(JOptionPane.showConfirmDialog(this,"确认要删除吗?")==JOptionPane.YES_OPTION)
{
try{
st.executeUpdate("delete from Employee where employeeid='"+EmployeeID+"'");
JOptionPane.showMessageDialog(this,"职工删除操作,执行成功!");
jTextField1.setText("");
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"职工删除操作,执行失败!");
}
}
}
}
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
public class EmployeeHelp extends JPanel
{
JLabel jLabel1=new JLabel("有问题,请你联系作者:");
JLabel jLabel4=new JLabel("曹长君");
JLabel jLabel2=new JLabel("QQ:29590985");
JLabel jLabel3=new JLabel("邮箱:****************");
public EmployeeHelp()
{
try{
jbInit();
}
catch(Exception exception){
exception.printStackTrace();
}
}
private void jbInit() throws Exception
{
this.setLayout(null);
jLabel1.setFont(new java.awt.Font("楷体",Font.BOLD,20));
jLabel1.setBounds(new Rectangle(50,50,300,30));
jLabel4.setFont(new java.awt.Font("楷体",Font.BOLD,20));
jLabel4.setBounds(new Rectangle(50,90,150,30));
jLabel2.setFont(new java.awt.Font("楷体",Font.BOLD,20));
jLabel2.setBounds(new Rectangle(50,140,300,30));
jLabel3.setFont(new java.awt.Font("楷体",Font.BOLD,20));
jLabel3.setBounds(new Rectangle(50,180,300,30));
this.add(jLabel1);
this.add(jLabel2);
this.add(jLabel3);
this.add(jLabel4);
}
}
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
public class InquireOnGH extends JPanel implements ActionListener
{
Connection con;
Statement st;
JLabel jLabel1=new JLabel("请输入职工的编号:");
JTextField jTextField1=new JTextField();
JButton jButton1=new JButton("查找");
JTextArea jTextArea1=new JTextArea();
public InquireOnGH()
{
try{
jbInit();
}
catch(Exception exception){
exception.printStackTrace();
}
}
private void jbInit() throws Exception
{
con=DB.getConn();
st=con.createStatement();
this.setLayout(null);
jLabel1.setFont(new java.awt.Font("黑体",Font.BOLD,16));
jLabel1.setBounds(new Rectangle(46,4,222,32));
jTextField1.setBounds(new Rectangle(47,37,247,31));
jButton1.setBounds(new Rectangle(47,86,247,30));
jTextArea1.setBounds(new Rectangle(24,130,305,130));
jButton1.addActionListener(this);
this.add(jLabel1);
this.add(jTextField1);
this.add(jTextArea1);
this.add(jButton1);
}
public void actionPerformed(ActionEvent e)
{
String EmployeeID=jTextField1.getText();
jTextArea1.setText("");
try{
ResultSet rs=st.executeQuery("select * from Employee where employeeid='"+EmployeeID+"'");
if(rs.next())
{
jTextArea1.setText("职工编号:"+rs.getString("employeeid")+"\\n"+"职工姓名:"+rs.getString("employeename")+"\\n"+"职工性别:"+rs.getString("employeesex")+"\\n"+"职工年龄:"+rs.getString("employeeige")+"\\n"+"所属院系:"+rs.getString("employeecollege")+"\\n"+"家庭住址:"+rs.getString("employeeaddress")+"\\n"+"联系电话:"+rs.getString("employeetell")+"\\n");
}
else
{
JOptionPane.showMessageDialog(this,"没有这个工号的职工!");
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"职工查询失败!");
}
}
}
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
public class InquireOnName extends JPanel implements ActionListener
{
Connection con;
Statement st;
JLabel jLabel1=new JLabel("请输入职工的姓名:");
JTextField jTextField1=new JTextField();
JButton jButton1=new JButton("查找");
JTextArea jTextArea1=new JTextArea();
public InquireOnName()
{
try{
jbInit();
}
catch(Exception exception){
exception.printStackTrace();
}
}
private void jbInit() throws Exception
{
con=DB.getConn();
st=con.createStatement();
this.setLayout(null);
jLabel1.setFont(new java.awt.Font("黑体",Font.BOLD,16));
jLabel1.setBounds(new Rectangle(46,4,222,32));
jTextField1.setBounds(new Rectangle(47,37,247,31));
jButton1.setBounds(new Rectangle(47,86,247,30));
jTextArea1.setBounds(new Rectangle(24,130,305,130));
jButton1.addActionListener(this);
this.add(jLabel1);
this.add(jTextField1);
this.add(jTextArea1);
this.add(jButton1);
}
public void actionPerformed(ActionEvent e)
{
String EmployeeName=jTextField1.getText();
jTextArea1.setText("");
try{
ResultSet rs=st.executeQuery("select * from Employee where employeename='"+EmployeeName+"'");
if(rs.next())
{
jTextArea1.setText("职工编号:"+rs.getString("employeeid")+"\\n"+"职工姓名:"+rs.getString("employeename")+"\\n"+"职工性别:"+rs.getString("employeesex")+"\\n"+"职工年龄:"+rs.getString("employeeige")+"\\n"+"所属院系:"+rs.getString("employeecollege")+"\\n"+"家庭住址:"+rs.getString("employeeaddress")+"\\n"+"联系电话:"+rs.getString("employeetell")+"\\n");
}
else
{
JOptionPane.showMessageDialog(this,"没有这个工号的职工!");
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"职工查询失败!");
}
}
}
import java.awt.*;
import javax.swing.*;
public class Layeredpane extends JPanel{
private ImageIcon background;
public Layeredpane(){
JLabel label=new JLabel(background);
label.setBounds(0,0,background.getIconWidth(),background.getIconHeight());
setLayout(null);
add(label,new Integer(Integer.MIN_VALUE));
setSize(background.getIconWidth(),background.getIconHeight());
setVisible(true);
}
}
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class ManageCheck {
private ManageUser user;
ManageCheck(ManageUser user) {
this.user = user;
}
public boolean check() {
boolean isAdmin = false;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "";
try {
conn = DB.getConn();
sql = "select * from logindata where username=? and password=?";
pstmt = DB.getPstmt(conn, sql);
pstmt.setString(1, user.getName());
pstmt.setString(2, user.getPassword());
rs = DB.getRs(pstmt);
if (rs.next()) {
isAdmin = true;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DB.close(rs);
DB.close(pstmt);
DB.close(conn);
}
return isAdmin;
}
public ManageUser getUser() {
return user;
}
public void setUser(ManageUser user) {
this.user = user;
}
}
public class ManageUser {
private int id;
private String username;
private String password;
public String getName() {
return username;
}
public void setName(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
public class ModifyEmployee extends JPanel implements ActionListener
{
Connection con;
Statement st;
JLabel jLabel1=new JLabel("请输入职工的编号:");
JTextField jTextField1=new JTextField();
JButton jButton1=new JButton("查找该职工");
JLabel jLabel2=new JLabel("职工编号:");
JTextField jTextField2=new JTextField();
JLabel jLabel3=new JLabel("职工姓名:");
JTextField jTextField3=new JTextField();
JLabel jLabel4=new JLabel("职工性别:");
JTextField jTextField4=new JTextField();
JLabel jLabel5=new JLabel("职工年龄:");
JTextField jTextField5=new JTextField();
JLabel jLabel6=new JLabel("家庭住址:");
JTextField jTextField6=new JTextField();
JLabel jLabel7=new JLabel("联系电话:");
JTextField jTextField7=new JTextField();
JButton jButton2=new JButton("修改职工信息");
public ModifyEmployee()
{
try{
jbInit();
}
catch(Exception exception){
exception.printStackTrace();
}
}
private void jbInit() throws Exception
{
con=DB.getConn();
st=con.createStatement();
this.setLayout(null);
jLabel1.setFont(new java.awt.Font("楷体",Font.BOLD,14));
jLabel1.setBounds(new Rectangle(40,15,140,30));
jTextField1.setBounds(new Rectangle(185,15,120,30));
jButton1.setBounds(new Rectangle(110,55,150,30));
jLabel2.setFont(new java.awt.Font("楷体",Font.BOLD,14));
jLabel2.setBounds(new Rectangle(20,105,80,30));
jTextField2.setBounds(new Rectangle(100,105,80,30));
jLabel3.setFont(new java.awt.Font("楷体",Font.BOLD,14));
jLabel3.setBounds(new Rectangle(190,105,80,30));
jTextField3.setBounds(new Rectangle(270,105,80,30));
jLabel4.setFont(new java.awt.Font("楷体",Font.BOLD,14));
jLabel4.setBounds(new Rectangle(20,145,80,30));
jTextField4.setBounds(new Rectangle(100,145,80,30));
jLabel5.setFont(new java.awt.Font("楷体",Font.BOLD,14));
jLabel5.setBounds(new Rectangle(190,145,80,30));
jTextField5.setBounds(new Rectangle(270,145,80,30));
jLabel6.setFont(new java.awt.Font("楷体",Font.BOLD,14));
jLabel6.setBounds(new Rectangle(20,185,80,30));
jTextField6.setBounds(new Rectangle(100,185,80,30));
jLabel7.setFont(new java.awt.Font("楷体",Font.BOLD,14));
jLabel7.setBounds(new Rectangle(190,185,80,30));
jTextField7.setBounds(new Rectangle(270,185,80,30));
jButton2.setBounds(new Rectangle(120,240,150,30));
jButton1.addActionListener(this);
jButton2.addActionListener(this);
this.add(jLabel1);
this.add(jTextField1);
this.add(jButton1);
this.add(jLabel2);
this.add(jTextField2);
jTextField2.setEditable(false);
this.add(jLabel3);
this.add(jTextField3);
this.add(jLabel4);
this.add(jTextField4);
this.add(jLabel5);
this.add(jTextField5);
this.add(jLabel6);
this.add(jTextField6);
this.add(jLabel7);
this.add(jTextField7);
this.add(jButton2);
}
public void actionPerformed(ActionEvent actionevent)
{
if(actionevent.getSource()==jButton1)
{
try{
ResultSet rs=st.executeQuery("select * from Employee where employeeid='"+jTextField1.getText()+"'");
if(rs.next())
{
jTextField2.setText(rs.getString("employeeid"));
jTextField3.setText(rs.getString("employeename"));
jTextField4.setText(rs.getString("employeesex"));
jTextField5.setText(rs.getString("employeeige"));
jTextField6.setText(rs.getString("employeeaddress"));
jTextField7.setText(rs.getString("employeetell"));
}
else
{
JOptionPane.showMessageDialog(this,"没有这个工号的职工!");
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"职工信息修改失败!");
}
}
if(actionevent.getSource()==jButton2)
{
try{
st.executeUpdate("update Employee set employeename='"+jTextField3.getText()+"' where eimployeeid='"+jTextField2.getText()+"'");
st.executeUpdate("update Employee set employeesex='"+jTextField4.getText()+"' where eimployeeid='"+jTextField2.getText()+"'");
st.executeUpdate("update Employee set employeeige='"+jTextField5.getText()+"' where eimployeeid='"+jTextField2.getText()+"'");
st.executeUpdate("update Employee set employeeaddress='"+jTextField6.getText()+"' where eimployeeid='"+jTextField2.getText()+"'");
st.executeUpdate("update Employee set employeetell='"+jTextField7.getText()+"' where eimployeeid='"+jTextField2.getText()+"'");
JOptionPane.showMessageDialog(this,"职工信息修改成功!");
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"职工信息修改失败!");
ex.printStackTrace();
}
}
}
}
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
public class ModifySalary extends JPanel implements ActionListener
{
Connection con;
Statement st;
JLabel jLabel1=new JLabel("职工编号:");
JTextField jTextField1=new JTextField();
JButton jButton1=new JButton("查找该职工");
JLabel jLabel2=new JLabel("职工编号:");
JTextField jTextField2=new JTextField();
JLabel jLabel3=new JLabel("职工工资:");
JTextField jTextField3=new JTextField();
JButton jButton2=new JButton("修改工资");
JLabel jLabel4=new JLabel("请选月份:");
JRadioButton jradiobutton1=new JRadioButton("一");
JRadioButton jradiobutton2=new JRadioButton("二");
JRadioButton jradiobutton3=new JRadioButton("三");
JRadioButton jradiobutton4=new JRadioButton("四");
JRadioButton jradiobutton5=new JRadioButton("五");
JRadioButton jradiobutton6=new JRadioButton("六");
JRadioButton jradiobutton7=new JRadioButton("七");
JRadioButton jradiobutton8=new JRadioButton("八");
JRadioButton jradiobutton9=new JRadioButton("九");
JRadioButton jradiobutton10=new JRadioButton("十");
JRadioButton jradiobutton11=new JRadioButton("十一");
JRadioButton jradiobutton12=new JRadioButton("十二");
ButtonGroup buttongroup=new ButtonGroup();
public ModifySalary()
{
try{
jbInit();
}
catch(Exception exception){
exception.printStackTrace();
}
}
private void jbInit() throws Exception
{
con=DB.getConn();
st=con.createStatement();
this.setLayout(null);
buttongroup.add(jradiobutton1);
buttongroup.add(jradiobutton2);
buttongroup.add(jradiobutton3);
buttongroup.add(jradiobutton4);
buttongroup.add(jradiobutton5);
buttongroup.add(jradiobutton6);
buttongroup.add(jradiobutton7);
buttongroup.add(jradiobutton8);
buttongroup.add(jradiobutton9);
buttongroup.add(jradiobutton10);
buttongroup.add(jradiobutton11);
buttongroup.add(jradiobutton12);
jLabel1.setFont(new java.awt.Font("楷体",Font.BOLD,14));
jLabel1.setBounds(new Rectangle(20,25,80,30));
jTextField1.setBounds(new Rectangle(105,25,80,30));
jButton1.setBounds(new Rectangle(20,300,100,30));
jLabel2.setFont(new java.awt.Font("楷体",Font.BOLD,14));
jLabel2.setBounds(new Rectangle(20,140,80,30));
jTextField2.setBounds(new Rectangle(100,140,80,30));
jLabel3.setFont(new java.awt.Font("楷体",Font.BOLD,14));
jLabel3.setBounds(new Rectangle(20,185,80,30));
jTextField3.setBounds(new Rectangle(100,185,80,30));
jButton2.setBounds(new Rectangle(140,300,100,30));
jLabel4.setFont(new java.awt.Font("楷体",Font.BOLD,14));
jLabel4.setBounds(new Rectangle(20,80,80,30));
jradiobutton1.setBounds(new Rectangle(102,80,40,20));
jradiobutton2.setBounds(new Rectangle(144,80,40,20));
jradiobutton3.setBounds(new Rectangle(186,80,40,20));
jradiobutton4.setBounds(new Rectangle(228,80,40,20));
jradiobutton5.setBounds(new Rectangle(270,80,40,20));
jradiobutton6.setBounds(new Rectangle(312,80,40,20));
jradiobutton7.setBounds(new Rectangle(102,104,40,20));
jradiobutton8.setBounds(new Rectangle(144,104,40,20));
jradiobutton9.setBounds(new Rectangle(186,104,40,20));
jradiobutton10.setBounds(new Rectangle(228,104,40,20));
jradiobutton11.setBounds(new Rectangle(270,104,55,20));
jradiobutton12.setBounds(new Rectangle(327,104,55,20));
jButton1.addActionListener(this);
jButton2.addActionListener(this);
this.add(jradiobutton1);
this.add(jradiobutton2);
this.add(jradiobutton3);
this.add(jradiobutton4);
this.add(jradiobutton5);
this.add(jradiobutton6);
this.add(jradiobutton7);
this.add(jradiobutton8);
this.add(jradiobutton9);
this.add(jradiobutton10);
this.add(jradiobutton11);
this.add(jradiobutton12);
this.add(jLabel1);
this.add(jTextField1);
this.add(jButton1);
this.add(jLabel2);
this.add(jTextField2);
jTextField2.setEditable(false);
this.add(jLabel3);
this.add(jTextField3);
this.add(jLabel4);
this.add(jButton2);
}
public void actionPerformed(ActionEvent actionevent)
{
if(jradiobutton1.isSelected()){
String EmployeeID=jTextField1.getText();
if(actionevent.getSource()==jButton1)
{
try{
ResultSet rs=st.executeQuery("select * from January where employeeid='"+EmployeeID+"'");
if(rs.next())
{
jTextField2.setText(rs.getString("employeeid"));
jTextField3.setText(rs.getString("January"));
}
else
{
JOptionPane.showMessageDialog(this,"没有这个工号的职工!");
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
}
}
if(actionevent.getSource()==jButton2)
{
try{
st.executeUpdate("update January set January='"+jTextField3.getText()+"' where employeeid='"+jTextField2.getText()+"'");
JOptionPane.showMessageDialog(this,"工资修改成功!");
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
ex.printStackTrace();
}
}
}
else if(jradiobutton2.isSelected()){
String EmployeeID=jTextField1.getText();
if(actionevent.getSource()==jButton1)
{
try{
ResultSet rs=st.executeQuery("select * from February where employeeid='"+EmployeeID+"'");
if(rs.next())
{
jTextField2.setText(rs.getString("employeeid"));
jTextField3.setText(rs.getString("February"));
}
else
{
JOptionPane.showMessageDialog(this,"没有这个工号的职工!");
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
}
}
if(actionevent.getSource()==jButton2)
{
try{
st.executeUpdate("update February set February='"+jTextField3.getText()+"' where employeeid='"+jTextField2.getText()+"'");
JOptionPane.showMessageDialog(this,"工资修改成功!");
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
ex.printStackTrace();
}
}
}
else if(jradiobutton3.isSelected()){
String EmployeeID=jTextField1.getText();
if(actionevent.getSource()==jButton1)
{
try{
ResultSet rs=st.executeQuery("select * from March where employeeid='"+EmployeeID+"'");
if(rs.next())
{
jTextField2.setText(rs.getString("employeeid"));
jTextField3.setText(rs.getString("March"));
}
else
{
JOptionPane.showMessageDialog(this,"没有这个工号的职工!");
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
}
}
if(actionevent.getSource()==jButton2)
{
try{
st.executeUpdate("update March set March='"+jTextField3.getText()+"' where employeeid='"+jTextField2.getText()+"'");
JOptionPane.showMessageDialog(this,"工资修改成功!");
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
ex.printStackTrace();
}
}
}
else if(jradiobutton4.isSelected()){
String EmployeeID=jTextField1.getText();
if(actionevent.getSource()==jButton1)
{
try{
ResultSet rs=st.executeQuery("select * from April where employeeid='"+EmployeeID+"'");
if(rs.next())
{
jTextField2.setText(rs.getString("employeeid"));
jTextField3.setText(rs.getString("April"));
}
else
{
JOptionPane.showMessageDialog(this,"没有这个工号的职工!");
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
}
}
if(actionevent.getSource()==jButton2)
{
try{
st.executeUpdate("update April set April='"+jTextField3.getText()+"' where employeeid='"+jTextField2.getText()+"'");
JOptionPane.showMessageDialog(this,"工资修改成功!");
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
ex.printStackTrace();
}
}
}
else if(jradiobutton5.isSelected()){
String EmployeeID=jTextField1.getText();
if(actionevent.getSource()==jButton1)
{
try{
ResultSet rs=st.executeQuery("select * from May where employeeid='"+EmployeeID+"'");
if(rs.next())
{
jTextField2.setText(rs.getString("employeeid"));
jTextField3.setText(rs.getString("May"));
}
else
{
JOptionPane.showMessageDialog(this,"没有这个工号的职工!");
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
}
}
if(actionevent.getSource()==jButton2)
{
try{
st.executeUpdate("update May set May='"+jTextField3.getText()+"' where employeeid='"+jTextField2.getText()+"'");
JOptionPane.showMessageDialog(this,"工资修改成功!");
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
ex.printStackTrace();
}
}
}
else if(jradiobutton6.isSelected()){
String EmployeeID=jTextField1.getText();
if(actionevent.getSource()==jButton1)
{
try{
ResultSet rs=st.executeQuery("select * from June where employeeid='"+EmployeeID+"'");
if(rs.next())
{
jTextField2.setText(rs.getString("employeeid"));
jTextField3.setText(rs.getString("June"));
}
else
{
JOptionPane.showMessageDialog(this,"没有这个工号的职工!");
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
}
}
if(actionevent.getSource()==jButton2)
{
try{
st.executeUpdate("update June set June='"+jTextField3.getText()+"' where employeeid='"+jTextField2.getText()+"'");
JOptionPane.showMessageDialog(this,"工资修改成功!");
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
ex.printStackTrace();
}
}
}
else if(jradiobutton7.isSelected()){
String EmployeeID=jTextField1.getText();
if(actionevent.getSource()==jButton1)
{
try{
ResultSet rs=st.executeQuery("select * from July where employeeid='"+EmployeeID+"'");
if(rs.next())
{
jTextField2.setText(rs.getString("employeeid"));
jTextField3.setText(rs.getString("July"));
}
else
{
JOptionPane.showMessageDialog(this,"没有这个工号的职工!");
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
}
}
if(actionevent.getSource()==jButton2)
{
try{
st.executeUpdate("update July set July='"+jTextField3.getText()+"' where employeeid='"+jTextField2.getText()+"'");
JOptionPane.showMessageDialog(this,"工资修改成功!");
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
ex.printStackTrace();
}
}
}
else if(jradiobutton8.isSelected()){
String EmployeeID=jTextField1.getText();
if(actionevent.getSource()==jButton1)
{
try{
ResultSet rs=st.executeQuery("select * from August where employeeid='"+EmployeeID+"'");
if(rs.next())
{
jTextField2.setText(rs.getString("employeeid"));
jTextField3.setText(rs.getString("August"));
}
else
{
JOptionPane.showMessageDialog(this,"没有这个工号的职工!");
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
}
}
if(actionevent.getSource()==jButton2)
{
try{
st.executeUpdate("update August set August='"+jTextField3.getText()+"' where employeeid='"+jTextField2.getText()+"'");
JOptionPane.showMessageDialog(this,"工资修改成功!");
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
ex.printStackTrace();
}
}
}
else if(jradiobutton9.isSelected()){
String EmployeeID=jTextField1.getText();
if(actionevent.getSource()==jButton1)
{
try{
ResultSet rs=st.executeQuery("select * from September where employeeid='"+EmployeeID+"'");
if(rs.next())
{
jTextField2.setText(rs.getString("employeeid"));
jTextField3.setText(rs.getString("September"));
}
else
{
JOptionPane.showMessageDialog(this,"没有这个工号的职工!");
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
}
}
if(actionevent.getSource()==jButton2)
{
try{
st.executeUpdate("update September set September='"+jTextField3.getText()+"' where employeeid='"+jTextField2.getText()+"'");
JOptionPane.showMessageDialog(this,"工资修改成功!");
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
ex.printStackTrace();
}
}
}
else if(jradiobutton10.isSelected()){
String EmployeeID=jTextField1.getText();
if(actionevent.getSource()==jButton1)
{
try{
ResultSet rs=st.executeQuery("select * from October where employeeid='"+EmployeeID+"'");
if(rs.next())
{
jTextField2.setText(rs.getString("employeeid"));
jTextField3.setText(rs.getString("October"));
}
else
{
JOptionPane.showMessageDialog(this,"没有这个工号的职工!");
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
}
}
if(actionevent.getSource()==jButton2)
{
try{
st.executeUpdate("update October set October='"+jTextField3.getText()+"' where employeeid='"+jTextField2.getText()+"'");
JOptionPane.showMessageDialog(this,"工资修改成功!");
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
ex.printStackTrace();
}
}
}
else if(jradiobutton11.isSelected()){
String EmployeeID=jTextField1.getText();
if(actionevent.getSource()==jButton1)
{
try{
ResultSet rs=st.executeQuery("select * from November where employeeid='"+EmployeeID+"'");
if(rs.next())
{
jTextField2.setText(rs.getString("employeeid"));
jTextField3.setText(rs.getString("November"));
}
else
{
JOptionPane.showMessageDialog(this,"没有这个工号的职工!");
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
}
}
if(actionevent.getSource()==jButton2)
{
try{
st.executeUpdate("update November set November='"+jTextField3.getText()+"' where employeeid='"+jTextField2.getText()+"'");
JOptionPane.showMessageDialog(this,"工资修改成功!");
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
ex.printStackTrace();
}
}
}
else if(jradiobutton12.isSelected()){
String EmployeeID=jTextField1.getText();
if(actionevent.getSource()==jButton1)
{
try{
ResultSet rs=st.executeQuery("select * from December where employeeid='"+EmployeeID+"'");
if(rs.next())
{
jTextField2.setText(rs.getString("employeeid"));
jTextField3.setText(rs.getString("December"));
}
else
{
JOptionPane.showMessageDialog(this,"没有这个工号的职工!");
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
}
}
if(actionevent.getSource()==jButton2)
{
try{
st.executeUpdate("update December set December='"+jTextField3.getText()+"' where employeeid='"+jTextField2.getText()+"'");
JOptionPane.showMessageDialog(this,"工资修改成功!");
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,"工资修改失败!");
ex.printStackTrace();
}
}
}
}
}
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
public class SalaryInquire extends JPanel implements ActionListener
{
Connection con;
Statement st;
String month1=null;
String month2=null;
String month3=null;
JLabel jLabel1=new JLabel("请输入要查询的职工的编号:");
JTextField jTextField1=new JTextField();
JLabel jLabel2=new JLabel("请选择要查询的月份:");
JRadioButton jradiobutton1=new JRadioButton("一");
JRadioButton jradiobutton2=new JRadioButton("二");
JRadioButton jradiobutton3=new JRadioButton("三");
JRadioButton jradiobutton4=new JRadioButton("四");
JRadioButton jradiobutton5=new JRadioButton("五");
JRadioButton jradiobutton6=new JRadioButton("六");
JRadioButton jradiobutton7=new JRadioButton("七");
JRadioButton jradiobutton8=new JRadioButton("八");
JRadioButton jradiobutton9=new JRadioButton("九");
JRadioButton jradiobutton10=new JRadioButton("十");
JRadioButton jradiobutton11=new JRadioButton("十一");
JRadioButton jradiobutton12=new JRadioButton("十二");
JButton jButton1=new JButton("工资查询");
ButtonGroup buttongroup=new ButtonGroup();
JTextArea jTextArea1=new JTextArea();
String EmployeeID=jTextField1.getText();
public SalaryInquire()
{
try{
jbInit();
}
catch(Exception exception){
exception.printStackTrace();
}
}
private void jbInit() throws Exception
{
con=DB.getConn();
st=con.createStatement();
this.setLayout(null);
buttongroup.add(jradiobutton1);
buttongroup.add(jradiobutton2);
buttongroup.add(jradiobutton3);
buttongroup.add(jradiobutton4);
buttongroup.add(jradiobutton5);
buttongroup.add(jradiobutton6);
buttongroup.add(jradiobutton7);
buttongroup.add(jradiobutton8);
buttongroup.add(jradiobutton9);
buttongroup.add(jradiobutton10);
buttongroup.add(jradiobutton11);
buttongroup.add(jradiobutton12);
jLabel1.setFont(new java.awt.Font("黑体",Font.BOLD,16));
jLabel1.setBounds(new Rectangle(46,4,222,32));
jLabel2.setFont(new java.awt.Font("黑体",Font.BOLD,16));
jLabel2.setBounds(new Rectangle(46,72,222,16));
jTextField1.setBounds(new Rectangle(47,37,247,31));
jradiobutton1.setBounds(new Rectangle(46,92,40,20));
jradiobutton2.setBounds(new Rectangle(90,92,40,20));
jradiobutton3.setBounds(new Rectangle(134,92,40,20));
jradiobutton4.setBounds(new Rectangle(178,92,40,20));
jradiobutton5.setBounds(new Rectangle(222,92,40,20));
jradiobutton6.setBounds(new Rectangle(266,92,40,20));
jradiobutton7.setBounds(new Rectangle(46,118,40,20));
jradiobutton8.setBounds(new Rectangle(90,118,40,20));
jradiobutton9.setBounds(new Rectangle(134,118,40,20));
jradiobutton10.setBounds(new Rectangle(178,118,40,20));
jradiobutton11.setBounds(new Rectangle(222,118,55,20));
jradiobutton12.setBounds(new Rectangle(280,118,55,20));
jButton1.setBounds(new Rectangle(47,150,247,30));
jTextArea1.setBounds(new Rectangle(24,185,305,109));
jButton1.addActionListener(this);
this.add(jradiobutton1);
this.add(jradiobutton2);
this.add(jradiobutton3);
this.add(jradiobutton4);
this.add(jradiobutton5);
this.add(jradiobutton6);
this.add(jradiobutton7);
this.add(jradiobutton8);
this.add(jradiobutton9);
this.add(jradiobutton10);
this.add(jradiobutton11);
this.add(jradiobutton12);
this.add(jLabel1);
this.add(jTextField1);
this.add(jLabel2);
this.add(jTextArea1);
this.add(jButton1);
}
public void actionPerformed(ActionEvent e)
{
String EmployeeID=jTextField1.getText();
if(jradiobutton1.isSelected()){
try{
ResultSet rs=st.executeQuery("select * from January where employeeid='"+EmployeeID+"'");
if(rs.next()){
jTextArea1.setText("职工编号:"+rs.getString("employeeid")+"\\n"+"所查月份:"+"一月"+"\\n"+"职工工资:"+rs.getString("January")+"\\n");
}else{
JOptionPane.showMessageDialog(this,"工资不存在!");
}
}
catch(Exception ex){
ex.printStackTrace();
JOptionPane.showMessageDialog(this,"工资查询失败!");
}
}
else if(jradiobutton2.isSelected()){
try{
ResultSet rs=st.executeQuery("select * from February where employeeid='"+EmployeeID+"'");
if(rs.next()){
jTextArea1.setText("职工编号:"+rs.getString("employeeid")+"\\n"+"所查月份:"+"二月"+"\\n"+"职工工资:"+rs.getString("February")+"\\n");
}else{
JOptionPane.showMessageDialog(this,"工资不存在!");
}
}
catch(Exception ex){
ex.printStackTrace();
JOptionPane.showMessageDialog(this,"工资查询失败!");
}
}
else if(jradiobutton3.isSelected()){
try{
ResultSet rs=st.executeQuery("select * from March where employeeid='"+EmployeeID+"'");
if(rs.next()){
jTextArea1.setText("职工编号:"+rs.getString("employeeid")+"\\n"+"所查月份:"+"三月"+"\\n"+"职工工资:"+rs.getString("March")+"\\n");
}else{
JOptionPane.showMessageDialog(this,"工资不存在!");
}
}
catch(Exception ex){
ex.printStackTrace();
JOptionPane.showMessageDialog(this,"工资查询失败!");
}
}
else if(jradiobutton4.isSelected()){
try{
ResultSet rs=st.executeQuery("select * from April where employeeid='"+EmployeeID+"'");
if(rs.next()){
jTextArea1.setText("职工编号:"+rs.getString("employeeid")+"\\n"+"所查月份:"+"四月"+"\\n"+"职工工资:"+rs.getString("April")+"\\n");
}else{
JOptionPane.showMessageDialog(this,"工资不存在!");
}
}
catch(Exception ex){
ex.printStackTrace();
JOptionPane.showMessageDialog(this,"工资查询失败!");
}
}
else if(jradiobutton5.isSelected()){
try{
ResultSet rs=st.executeQuery("select * from May where employeeid='"+EmployeeID+"'");
if(rs.next()){
jTextArea1.setText("职工编号:"+rs.getString("employeeid")+"\\n"+"所查月份:"+"五月"+"\\n"+"职工工资:"+rs.getString("May")+"\\n");
}else{
JOptionPane.showMessageDialog(this,"工资不存在!");
}
}
catch(Exception ex){
ex.printStackTrace();
JOptionPane.showMessageDialog(this,"工资查询失败!");
}
}
else if(jradiobutton6.isSelected()){
try{
ResultSet rs=st.executeQuery("select * from June where employeeid='"+EmployeeID+"'");
if(rs.next()){
jTextArea1.setText("职工编号:"+rs.getString("employeeid")+"\\n"+"所查月份:"+"六月"+"\\n"+"职工工资:"+rs.getString("June")+"\\n");
}else{
JOptionPane.showMessageDialog(this,"工资不存在!");
}
}
catch(Exception ex){
ex.printStackTrace();
JOptionPane.showMessageDialog(this,"工资查询失败!");
}
}
else if(jradiobutton7.isSelected()){
try{
ResultSet rs=st.executeQuery("select * from July where employeeid='"+EmployeeID+"'");
if(rs.next()){
jTextArea1.setText("职工编号:"+rs.getString("employeeid")+"\\n"+"所查月份:"+"七月"+"\\n"+"职工工资:"+rs.getString("July")+"\\n");
}else{
JOptionPane.showMessageDialog(this,"工资不存在!");
}
}
catch(Exception ex){
ex.printStackTrace();
JOptionPane.showMessageDialog(this,"工资查询失败!");
}
}
else if(jradiobutton8.isSelected()){
try{
ResultSet rs=st.executeQuery("select * from August where employeeid='"+EmployeeID+"'");
if(rs.next()){
jTextArea1.setText("职工编号:"+rs.getString("employeeid")+"\\n"+"所查月份:"+"八月"+"\\n"+"职工工资:"+rs.getString("August")+"\\n");
}else{
JOptionPane.showMessageDialog(this,"工资不存在!");
}
}
catch(Exception ex){
ex.printStackTrace();
JOptionPane.showMessageDialog(this,"工资查询失败!");
}
}
else if(jradiobutton9.isSelected()){
try{
ResultSet rs=st.executeQuery("select * from September where employeeid='"+EmployeeID+"'");
if(rs.next()){
jTextArea1.setText("职工编号:"+rs.getString("employeeid")+"\\n"+"所查月份:"+"九月"+"\\n"+"职工工资:"+rs.getString("September")+"\\n");
}else{
JOptionPane.showMessageDialog(this,"工资不存在!");
}
}
catch(Exception ex){
ex.printStackTrace();
JOptionPane.showMessageDialog(this,"工资查询失败!");
}
}
else if(jradiobutton10.isSelected()){
try{
ResultSet rs=st.executeQuery("select * from October where employeeid='"+EmployeeID+"'");
if(rs.next()){
jTextArea1.setText("职工编号:"+rs.getString("employeeid")+"\\n"+"所查月份:"+"十月"+"\\n"+"职工工资:"+rs.getString("October")+"\\n");
}else{
JOptionPane.showMessageDialog(this,"工资不存在!");
}
}
catch(Exception ex){
ex.printStackTrace();
JOptionPane.showMessageDialog(this,"工资查询失败!");
}
}
else if(jradiobutton11.isSelected()){
try{
ResultSet rs=st.executeQuery("select * from November where employeeid='"+EmployeeID+"'");
if(rs.next()){
jTextArea1.setText("职工编号:"+rs.getString("employeeid")+"\\n"+"所查月份:"+"十一月"+"\\n"+"职工工资:"+rs.getString("November")+"\\n");
}else{
JOptionPane.showMessageDialog(this,"工资不存在!");
}
}
catch(Exception ex){
ex.printStackTrace();
JOptionPane.showMessageDialog(this,"工资查询失败!");
}
}
else if(jradiobutton12.isSelected()){
try{
ResultSet rs=st.executeQuery("select * from December where employeeid='"+EmployeeID+"'");
if(rs.next()){
jTextArea1.setText("职工编号:"+rs.getString("employeeid")+"\\n"+"所查月份:"+"十二月"+"\\n"+"职工工资:"+rs.getString("December")+"\\n");
}else{
JOptionPane.showMessageDialog(this,"工资不存在!");
}
}
catch(Exception ex){
ex.printStackTrace();
JOptionPane.showMessageDialog(this,"工资查询失败!");
}
}
}
}
public class User {
private int id;
private String username;
private String password;
public String getUserName() {
return username;
}
public void setUserName(String username) {
this.username = username;
}
public String getPassWord() {
return password;
}
public void setPassWord(String password) {
this.password = password;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
运行图示