java课程设计(人事管理系统).doc

上传人:jian****018 文档编号:9339686 上传时间:2020-04-04 格式:DOC 页数:35 大小:388KB
返回 下载 相关 举报
java课程设计(人事管理系统).doc_第1页
第1页 / 共35页
java课程设计(人事管理系统).doc_第2页
第2页 / 共35页
java课程设计(人事管理系统).doc_第3页
第3页 / 共35页
点击查看更多>>
资源描述
人事管理系统一.系统需求分析:2(1)系统的功能设计2(2)系统功能结构2(3)数据库设计2二.功能模块开发3(1)查询人员信息界面3(2)添加员工界面3(3)修改员工信息界面4(4)删除员工界面5(5)员工考核界面5(6)员工考核历史记录界面6三.各个类说明6四.程序代码9(1)Manager9(2)CardEmploy11(3)SelEmploy12(4)AddEmploy14(5)ReviseEmploy16iUpdDialog18(6)DelEmploy21(7)AllEmploy22(8)Examine23(9)History27(10)EmployModel28(11)AppraisalModel30(12)SqlHelper33一.系统需求分析:(1) 系统的功能设计i 员工信息管理:员工信息管理包括对员工基本信息和情况进行查询、添加、删除和修改及部门管理ii 员工考核管理:包括对员工的考核情况进行操作,还可以对历史考核情况进行浏览(2) 系统功能结构人事管理的系统结构功能结构如图所示:(3) 数据库设计员工基本表(Employinfo)名称字段名称数据类型主键非空工号Empnovarchar(10)YesYes姓名Enamevarchar(10)No yes性别Sexvarchar(4)No yes出生年月BirthdayDatetimeNo Yes部门DeptNoChar(10)No Yes职务EjobChar(20)No Yes工资SalfloatNo Yes员工考核表(Appraisal)名称字段名称数据类型主键非空工号Empnovarchar(10)yesyes考核Consequencevarchar(10)noyes变更日期RegDatedatetimeNo Yes 考核历史记录(History)名称字段名称数据类型主键非空流水号JourNoIntYesyes工号Empnovarchar(10)noyes姓名Enamevarchar(10)No Yes 上次考核OldInfovarchar(10)No Yes 本次考核NewInfovarchar(10)No Yes 变更日期RegDatedatetimeNo Yes 二. 功能模块开发(1) 查询人员信息界面 实例一个SelEmploy类,当点击“查询”时调用EmployModel类的queryEmploy方法实现查询(2) 添加员工界面 实例一个AddEmploy类当点击“添加”时调用EmployModel类的updEmploy方法实现添加功能(3) 修改员工信息界面实例一个ReviseEmploy类当点击“修改”时,先调用UpdDialo弹跳出一个修改信息对话框,信息修改完毕后,调用EmployModel类的updEmploy方法实现修改功能(4) 删除员工界面实例一个DelEmploy类当点击“删除”时调用EmployModel类的updEmploy方法实现删除功能(5) 员工考核界面实例一个Examine类当点击“确认”时调用AppraisalModel类的updAppraisal方法来完成考核功能(6) 员工考核历史记录界面实例一个History类当点击时调用AppraisalModel类的updAppraisal方法来完成考核功能三. 各个类说明类之间的关系图:1. Manager类Manager类的一个实例,从而生成了人事管理系统的界面,用JSplitPane类将整个界面分为左右两个部分。其中左侧实现了人事管理系统的功能树,采用JTree类构建,同时实现了TreeSelectionListener接口,定义了该接口所必须实现的valueChanged(TreeSelectionEvent e)方法,JSplitPane右边加入卡片布局CardEmploy类。当JTree的TreeSelectionEvent事件发生时,调用CardEmploy的c.show方法 切换不同卡片,实现不同的管理界面。2. CardEmploy类CardEmploy为卡片布局类的面板,主要功能是添加各个界面的卡片,当JTree的TreeSelectionEvent事件发生时。切换不同的卡片3. EmployModel、AppraisalModel类这两个类继承了AbstractTableModel,主要实现的功能是,存放调用sqlhelper类得到的数据。可以通过调用sqlhelper实现 增 删 查 改 功能4. SqlHelper类主要就是连接数据库的一些基础操作是,方便代码修改,重复使用5. SelEmploy这个类继承Panel,为“查询员工”的界面。实现了Actionlistener 接口,当ActionEvent 事件发生时,调用EmployModel类的queryEmploy方法实现查询6. AddEmploy、ReviseEmploy、DelEmploy类这些类继承Pane,分别为“添加员工信息”“修改员工信息”“删除员工信息”的界面, 这些类实现了Actionlistener 接口,当ActionEvent 事件发生时,调用EmployModel类的updEmploy方法实现添加、查询、删除、功能7. Examine类这个类继承Panel,为“考核员工”界面。这个类实现了Actionlistener 接口,当ActionEvent 事件发生时,(1)先通过调用AppraisalModel的queryAppraisal获取上次考核成绩,(2)修改Appraisal表的考核成绩(3)再把上次考核成绩跟本次考核成绩加到History表中8. History这个类主要是把History表中的信息显示到界面上。四. 程序代码(1) Managerpackage com.Manager;import java.awt.*;import javax.swing.*;import javax.swing.event.TreeSelectionEvent;import javax.swing.event.TreeSelectionListener;import javax.swing.tree.*;import java.awt.event.*;public class Manager extends JFrame implements TreeSelectionListener JPanel jp;JSplitPane js;JScrollPane jsp;JTree tree;DefaultMutableTreeNode root, t1, t2, t1_1, t1_2, t1_3, t1_4, t1_5, t2_1,t2_2;CardEmploy ae;EmployModel em;public static void main(String args) Manager manager = new Manager();public Manager() / 给树的各个结点赋值root = new DefaultMutableTreeNode(人事管理系统);t1 = new DefaultMutableTreeNode(基本信息管理);t1_1 = new DefaultMutableTreeNode(查询员工);t1_2 = new DefaultMutableTreeNode(添加员工);t1_3 = new DefaultMutableTreeNode(修改员工信息);t1_4 = new DefaultMutableTreeNode(删除员工资料);t1_5 = new DefaultMutableTreeNode(查询全体员工);t2 = new DefaultMutableTreeNode(人员考核管理);t2_1 = new DefaultMutableTreeNode(人员考核);t2_2 = new DefaultMutableTreeNode(考核历史查询);t1.add(t1_1);t1.add(t1_2);t1.add(t1_3);t1.add(t1_4);t1.add(t1_5);t2.add(t2_1);t2.add(t2_2);root.add(t1);root.add(t2);tree = new JTree(root);/ 对树进行监听tree.addTreeSelectionListener(this);/ 实例化CardEmploy面板 并加到jsplitpane的边ae = new CardEmploy();js = new JSplitPane();js.setLeftComponent(tree);js.setRightComponent(ae);this.getContentPane().add(js);this.setTitle(人事管理系统);this.setVisible(true);this.setSize(600, 500);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);public void valueChanged(TreeSelectionEvent e) / 获取点击结点名称DefaultMutableTreeNode dpath = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();/ 通过点击不同结点切换不同界面if (dpath.equals(t1_1) ae.c.show(ae, 1); else if (dpath.equals(t1_2) ae.c.show(ae, 2); else if (dpath.equals(t1_3) ae.c.show(ae, 3); else if (dpath.equals(t1_4) ae.c.show(ae, 4); else if (dpath.equals(t1_5) ae.c.show(ae, 5); else if (dpath.equals(t2_1) ae.c.show(ae, 6); else if (dpath.equals(t2_2) ae.c.show(ae, 7);(2) CardEmploy/* * 用卡片布局设置各个界面 */package com.Manager;import javax.swing.*;import java.awt.*;public class CardEmploy extends PanelCardLayout c; /查询表SelEmploy selE;/添加表AddEmploy addE; /修改员工信息表 ReviseEmploy revE; /删除员工表格 DelEmploy delE; /所有员工信息 AllEmploy allE; /员工考核表 Examine exaE; /历史记录界面 History His; public CardEmploy() /查询员工表 selE = new SelEmploy();/添加员工表addE = new AddEmploy(); /修改员工信息 revE = new ReviseEmploy(); /删除员工表格 delE = new DelEmploy(); /所有员工信息 allE =new AllEmploy(); /员工考核表 exaE = new Examine(); /历史记录界面 His = new History(); JPanel jp = new JPanel(); /定义cardemploy面板 为卡片布局 /把各个面板加入到C的卡片布局中 c = new CardLayout(); this.setLayout(c); this.add(selE,1); this.add(addE,2); this.add(revE,3); this.add(delE,4); this.add(allE,5); this.add(exaE,6); this.add(His,7); (3) SelEmploy/* * SelEmploy 类 设置查询员工界面 */package com.Manager;import java.awt.*;import javax.swing.*;import java.awt.event.*;public class SelEmploy extends Panel implements ActionListener EmployModel em;JLabel jl;JTextField jtf;JButton jb;JTable jt;JScrollPane jsp;JPanel jp1;public SelEmploy() / 北部jp1 = new JPanel();jl = new JLabel(输入员工号:);jtf = new JTextField(20);jb = new JButton(查询);/ 对查询按钮监听jb.addActionListener(this);jp1.add(jl);jp1.add(jtf);jp1.add(jb);/ 中部em = new EmployModel();String paras = 1 ;em.queryEmploy(select * from Employinfo where 1 = ?, paras);jt = new JTable(em);jsp = new JScrollPane(jt);this.setLayout(new BorderLayout();this.add(jp1, BorderLayout.NORTH);this.add(jsp, BorderLayout.CENTER);public void actionPerformed(ActionEvent e) if (e.getSource() = jb) String name = this.jtf.getText().trim();String sql = select * from Employinfo where Empno = ?;String paras = name ;em = new EmployModel();em.queryEmploy(sql, paras);/ 查找成功更新表jt.setModel(em);(4) AddEmploypackage com.Manager;import java.awt.*;import javax.swing.*;import java.awt.event.*;public class AddEmploy extends Panel implements ActionListener JLabel jl, jl1, jl2, jl3, jl4, jl5, jl6, jl7;JButton jb1, jb2;JTextField jtf1, jtf2, jtf3, jtf4, jtf5, jtf6, jtf7;JPanel jp1, jp2, jp3, jp4;EmployModel em;public AddEmploy() jl1 = new JLabel(工号:);jl2 = new JLabel(姓名:);jl3 = new JLabel(性别:);jl4 = new JLabel(出生年月:);jl5 = new JLabel(部门:);jl6 = new JLabel(职位:);jl7 = new JLabel(工资:);jtf1 = new JTextField(20);jtf2 = new JTextField(20);jtf3 = new JTextField(20);jtf4 = new JTextField(20);jtf5 = new JTextField(20);jtf6 = new JTextField(20);jtf7 = new JTextField(20);jb1 = new JButton(添加);jb2 = new JButton(取消);/ 监听添加 取消按钮jb1.addActionListener(this);jb2.addActionListener(this);jp1 = new JPanel(new GridLayout(7, 1);jp2 = new JPanel(new GridLayout(7, 1);jp3 = new JPanel();jp1.add(jl1);jp1.add(jl2);jp1.add(jl3);jp1.add(jl4);jp1.add(jl5);jp1.add(jl6);jp1.add(jl7);jp2.add(jtf1);jp2.add(jtf2);jp2.add(jtf3);jp2.add(jtf4);jp2.add(jtf5);jp2.add(jtf6);jp2.add(jtf7);jp3.add(jb1);jp3.add(jb2);jp4 = new JPanel(new BorderLayout();jp4.add(jp1, BorderLayout.WEST);jp4.add(jp2, BorderLayout.EAST);jp4.setSize(300, 300);this.setLayout(new FlowLayout();this.add(jp4);this.add(jp3);public void actionPerformed(ActionEvent e) if (e.getSource() = jb1) / 调用EmployModel 里的updEmploy 方法,实现对表格的添加String sql = insert into Employinfo values(?,?,?,?,?,?,?);String paras = jtf1.getText(), jtf2.getText(), jtf3.getText(),jtf4.getText(), jtf5.getText(), jtf6.getText(),jtf7.getText() ;em = new EmployModel();if (em.updEmploy(sql, paras) / 当添加新员工成功时,则弹出”添加成功“的对话框JOptionPane.showMessageDialog(this, 添加成功); else if (!em.updEmploy(sql, paras) JOptionPane.showMessageDialog(this, 添加失败);/ 当新员工加入成功后,要把新加入员工的工号加到考核表AppraisalModel temp = new AppraisalModel();String sql1 = insert into Appraisal(Empno) values(?);String paras1 = jtf1.getText() ;temp.updAppraisal(sql1, paras1);else if(e.getSource() = jb2)jtf1.setText();jtf2.setText();jtf3.setText();jtf4.setText();jtf5.setText();jtf6.setText();jtf7.setText();(5) ReviseEmploypackage com.Manager;/* * 修改员工界面 */import java.awt.*;import java.awt.event.*;import javax.swing.*;public class ReviseEmploy extends Panel implements ActionListener JTable jt;JScrollPane jsp;JButton jb1, jb2;JPanel jp1,jp2;EmployModel em; JLabel jl1;public ReviseEmploy() jl1 = new JLabel(修改员工信息,JLabel.CENTER);jl1.setFont(new Font(宋体, Font.BOLD, 28);jp2 = new JPanel();jp2.add(jl1);em = new EmployModel();String paras = 1 ;em.queryEmploy(select * from Employinfo where 1 = ?, paras);jt = new JTable(em);jsp = new JScrollPane(jt);jb1 = new JButton(修改);jb2 = new JButton(刷新);/ 对两个按钮进行监听jb1.addActionListener(this);jb2.addActionListener(this);this.setLayout(new BorderLayout();jp1 = new JPanel();jp1.add(jb1);jp1.add(jb2);this.add(jp2,BorderLayout.NORTH);this.add(jsp, BorderLayout.CENTER);this.add(jp1, BorderLayout.SOUTH);public void actionPerformed(ActionEvent e) if (e.getSource() = jb1) int rowNum = this.jt.getSelectedRow();if (rowNum = -1) JOptionPane.showMessageDialog(this, 请选择一行);return;/ 弹出修改对话框new UpdDialog(em, rowNum); else if (e.getSource() = jb2) / 刷新修改界面中的表格em = new EmployModel();String paras1 = 1 ;em.queryEmploy(select * from Employinfo where 1 = ?, paras1);jt.setModel(em);i UpdDialogpackage com.Manager;/* * 弹出修改界面 */import javax.swing.*;import java.awt.*;import java.awt.event.*;public class UpdDialog extends JDialog implements ActionListener JLabel jl1, jl2, jl3, jl4, jl5, jl6, jl7;JButton jb1, jb2;JTextField jtf1, jtf2, jtf3, jtf4, jtf5, jtf6, jtf7;JPanel jp1, jp2, jp3;public UpdDialog(EmployModel em, int rowNums) jl1 = new JLabel(工号:);jl2 = new JLabel(姓名:);jl3 = new JLabel(性别:);jl4 = new JLabel(出生年月:);jl5 = new JLabel(部门:);jl6 = new JLabel(职位:);jl7 = new JLabel(工资:);jtf1 = new JTextField(20);jtf2 = new JTextField(30);jtf3 = new JTextField(30);jtf4 = new JTextField(30);jtf5 = new JTextField(30);jtf6 = new JTextField(30);jtf7 = new JTextField(30);/ 初始化jtextfield数据jtf1.setText(String) em.getValueAt(rowNums, 0);jtf1.setEditable(false);jtf2.setText(String) em.getValueAt(rowNums, 1);jtf3.setText(String) em.getValueAt(rowNums, 2);jtf4.setText(String) em.getValueAt(rowNums, 3);jtf5.setText(String) em.getValueAt(rowNums, 4);jtf6.setText(String) em.getValueAt(rowNums, 5);jtf7.setText(String) em.getValueAt(rowNums, 6);jb1 = new JButton(修改);jb2 = new JButton(取消);/ 对两个按钮监听jb1.addActionListener(this);jb2.addActionListener(this);jp1 = new JPanel();jp2 = new JPanel();jp3 = new JPanel();/ 设置布局jp1.setLayout(new GridLayout(7, 1);jp2.setLayout(new GridLayout(7, 1);/ 添加组件jp1.add(jl1);jp1.add(jl2);jp1.add(jl3);jp1.add(jl4);jp1.add(jl5);jp1.add(jl6);jp1.add(jl7);jp2.add(jtf1);jp2.add(jtf2);jp2.add(jtf3);jp2.add(jtf4);jp2.add(jtf5);jp2.add(jtf6);jp2.add(jtf7);jp3.add(jb1);jp3.add(jb2);this.add(jp1, BorderLayout.WEST);this.add(jp2, BorderLayout.CENTER);this.add(jp3, BorderLayout.SOUTH);this.setSize(300, 250);this.setVisible(true);this.setLocation(200, 200);this.addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) dispose(););public void actionPerformed(ActionEvent e) if (e.getSource() = jb1) / 修改员工信息的 sql 语句,paras 为待注入的值String sql = update Employinfo set + Ename = ?,Sex = ?,Birthday = ?, DeptNo = ?, Ejob = ? ,Sal=? where Empno = ?;String paras = jtf2.getText(), jtf3.getText(), jtf4.getText(),jtf5.getText(), jtf6.getText(), jtf7.getText(),jtf1.getText() ;EmployModel temp = new EmployModel();/ 如果修改语句运行成功 则弹出“修改成功”对话框if (temp.updEmploy(sql, paras) JOptionPane.showMessageDialog(this, 修改成功);this.dispose(); else if (e.getSource() = jb2) / 关闭对话框this.dispose();(6) DelEmploy/* * 删除员工 */package com.Manager;import javax.swing.*;import java.awt.*;import java.awt.event.*;public class DelEmploy extends Panel implements ActionListener JTable jt;JScrollPane jsp;JButton jb1, jb2;JPanel jp1, jp2;JLabel jl1;EmployModel em;public DelEmploy() / 北部jl1 = new JLabel(删除员工, JLabel.CENTER);jl1.setFont(new Font(黑体, Font.BOLD, 30);jp2 = new JPanel();jp2.add(jl1);/ 中部em = new EmployModel();String paras = 1 ;em.queryEmploy(select * from Employinfo where 1 = ?, paras);jt = new JTable(em);jsp = new JScrollPane(jt);/ 南部jp1 = new JPanel();jb1 = new JButton(删除);jb2 = new JButton(取消);jb1.addActionListener(this);jp1.add(jb1);jp1.add(jb2);this.setLayout(new BorderLayout();this.add(jp2, BorderLayout.NORTH);this.add(jsp, BorderLayout.CENTER);this.add(jp1, BorderLayout.SOUTH);public void actionPerformed(ActionEvent e) if (e.getSource() = jb1) / 返回用户点中的行int rowNum = this.jt.getSelectedRow();if (rowNum = -1) JOptionPane.showMessageDialog(this, 请选择一行);return;/ 得到学生编号String Empno = (String) em.getValueAt(rowNum, 0);/ 删除记录的sql语句String sql = delete from Employinfo where Empno = ?;String paras = Empno ;EmployModel temp = new EmployModel();temp.updEmploy(sql, paras);/ 删除员工成功后,更新员工表em = new EmployModel();String paras1 = 1 ;em.queryEmploy(select * from Employinfo where 1 = ?, paras1);jt.setModel(em);(7) AllEmploy/* * 遍历所有员工 */package com.Manager;import java.awt.*;import javax.swing.*;public class AllEmploy extends PanelEmployModel em;JTable jt;JScrollPane jsp; JLabel jl1; JPanel jp;public AllEmploy()/北部jp = new JPanel();jl1 = new JLabel(全体员工,JLabel.CENTER);jl1.setFont(new Font(黑体, Font.BOLD, 30); jp.add(jl1); /中部em = new EmployModel();String paras =1;em.queryEmploy(select * from Employinfo where 1 = ?, paras);jt = new JTable(em);jsp = new JScrollPane(jt);this.setLayout(new BorderLayout(); this.add(jp,BorderLayout.NORTH);this.add(jsp,BorderLayout.CENTER);(8) Examine/* * 员工考核界面 */package com.Manager;import java.awt.*;import java.awt.event.*;import java.sql.ResultSet;import java.util.Vector;import java.sql.*;import javax.swing.*;public class Examine extends Panel implements ActionListener JLabel jl1, jl2, jl3, jl4;JTable jt;JScrollPane jsp;JTextField jtf1, jtf2;Choice ch;JButton jb1, jb2;JPanel jp1, jp2, jp3, jp4;AppraisalModel am;SqlHelper sqh;public Examine() / 北部 为标题文字jp4 = new JPanel();jl1 = new JLabel(员工考核, JLabel.CENTER);jl1.setFont(new Font(黑体, Font.BOLD, 30);jp4.add(jl1);/ 中部am = new AppraisalModel();am.queryAppraisal(select E.Empno,E.Ename,A.Consequence,A.RegDate from + Employinfo as E,Appraisal as A where E.Empno=A.Empno);jt = new JTable(am);jsp = new JScrollPane(jt);/ 监听jtable 点击表格时获取点击的行数 并通过鼠标点击事件给 jtf1,jtf2 赋值jt.addMouseListener(new MouseAdapter() public void mouseClicked(MouseEvent e) int rowNum = jt.getSelectedRow();jtf1.setText(String) am.getValueAt(rowNum, 0);jtf2.setText(String) am.getValueAt(rowNum, 1););jl2 = new JLabel(工号:);jl3 = new JLabel(姓名:);jl4 = new JLabel(考核);jtf1 = new JTextField(10);jtf2 = new JTextField(10);jtf1.setEditable(false);jtf2.setEditable(false);/ 实例单选框组件,并赋值ch = new Choice();ch.add(未考核);ch.add(不合格);ch.add(合格);ch.add(优秀);jp1 = new JPanel();jp1.add(jl2);jp1.add(jtf1);jp1.add(jl3);jp1.add(jtf2);jp1.add(jl4);jp1.add(ch);jp2 = new JPanel(new BorderLayout();jp2.add(jsp, BorderLayout.CENTER);jp2.add(jp1, BorderLayout.SOUTH);/ 南部jb1 = new JButton(确认);jb2 = new JButton(刷新);jp3 = new JPanel();jb1.addActionListener(this);jb2.addActionListener(this);jp3.add(jb1);jp3.add(jb2);this.setLayout(new BorderLayout();this.add(jp4, BorderLayout.NORTH);this.add(jp2, BorderLayout.CENTER);this.add(jp3, BorderLayout.SOUTH);public void actionPerformed(ActionEvent e) if (e.getSource() = jb1) String Empno = jtf1.getText();String Ename = jtf2.getText();String Consequence = ch.getSelectedItem();/ 先获取上次考核记录String sql = select Consequence from Appraisal where Empno =?;String paras = Empno ;String OldInfo = ;try sqh = new SqlHelper();ResultSet rs = sqh.queryExecute(sql, paras);rs.next();OldInfo = rs.getString(1); catch (Exception e1) e1.printStackTrace(); finally sqh.close();/ 对考核表进行修改 修改考核记录的sql语句String sql1 = update Appraisal set Consequence = ? where Empno =?;String paras1 = Consequence, Empno ;AppraisalModel temp = new AppraisalModel();if (temp.updAppraisal(sql1, paras1) JOptionPane.showMessageDialog(this, 考核成功);/ 再把上次考核记录以及本次操作记录 插入到 history表中String sql2 = insert into History(Empno,Ename,OldInfo,NewInfo) values(?,?,?,?);String paras2 = Empno, Ename, OldInfo, Consequence ;AppraisalModel temp1 = new AppraisalModel();temp1.updAppraisal(sql2, paras2); else if (e.g
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 大学资料


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!