当前位置:   article > 正文

数据库系统课设--人事管理系统_数据库课设人事管理系统

数据库课设人事管理系统

目录

前言

一,课程设计的目的

二,总体设计

1 系统需求分析

1.1 系统功能分析

1.2 系统功能模块设计(划分)

1.3 与其它系统的关系

1.4 数据流程图

2 数据库设计

2.1 数据库需求分析

2.2 数据库概念结构设计

2.3 数据库逻辑结构设计

2.4 数据库的建立

2.4.1 数据库的建立

2.4.2 初始数据的输入

3 各功能模块的设计与实现

3.1 功能说明

3.2 用户界面设计

3.3 各功能模块的实现

4 系统实现

4.2 加密模块

4.3 登陆模块

4.4 管理模块

4.5 新员工档案录入模块

4.6 人事变更模块

4.7 管理员员工档案查询修改模块

4.8 员工自身信息查询修改模块

4.9 数据库代码

4.10 数据库表结构

5 界面图预览

5.1 登录界面

5.2 管理界面

5.3 新员工档案录入界面

5.4 人事变更界面

5.5 管理员员工档案查询修改界面

5.6 员工自身信息查询修改界面


前言

        2023.7.30,鉴于大家都要数据库代码,所以重新更新了4.9数据库代码部分。

        2023.11.18,鉴于许多人问数据库部分,新增数据库表结构部分4.10数据库表结构

        本博客内容为课设内容,在这里仅提供思路和代码给大家参考,请不要轻易抄袭,最好理解代码并自己实现题目的要求,锻炼自己的编程和逻辑能力。另外,本次的课程设计我是用命令行操作mysql数据库,使用IDEA编写java程序的。

一,课程设计的目的

数据库系统课程设计是为了配合学习数据库系统原理及应用开发而设置的,是计算机科

学与技术、大数据、信息安全、物联网工程、软件工程、智能制造等专业集中实践的教学环

节,是将关系数据库理论知识转化为解决实际问题能力的重要环节。数据库系统课程设计目

的在于加深对关系数据库理论知识的理解,通过使用具体的 DBMS,掌握一种实际的数据

库管理系统并掌握其操作技术,熟练掌握使用数据库前端开发工具(如 VB、C++、Java、

JSP、Delphi、PowerBuilder 等),进一步提高同学们运用数据库技术解决实际问题的能力。

二,总体设计

企业人事管理系统主要用于员工个人资料的录入、职务变动的记录和管理。使用人事管理系统,便于公司领导掌握人员的动向,及时调整人才的分配。

1 系统需求分析

1.1 系统功能分析

人事管理系统主要有以下几项功能要求:

  • 新员工资料的输入。

  • 自动分配员工号,并且设置初始的用户密码。

  • 人事变动的详细记录,包括岗位和部门的调整。

  • 员工信息的查询和修改,包括员工个人信息和密码等。

1.2 系统功能模块设计(划分)

根据系统功能要求,可以将系统分解成几个模块来

分别设计应用程序界面,如图1 所示。

1.3 与其它系统的关系

本系统是公司管理信息系统的基础部分。为其他子系统,如考勤管理系统、工资管理系统和员工培训系统,提供员工的基本信息。同时为其它系统提供了员工登录的密码认证和权限分配功能。

1.4 数据流程图

人事信息管理系统的数据流程如图2 所示,所有数据由人事科管理人员输入。

2 数据库设计

2.1 数据库需求分析

根据数据流程图,可以列出以下数据项和数据结构:

  • 员工信息:员工号、密码、权限、姓名、性别、生日、专业、通讯地址、 电话、email、当前状态、其他。

  • 人事变动:记录号、员工、变动、详细描述。

  • 所需的外部数据支持:

  • 部门设置:部门编号、名称......

2.2 数据库概念结构设计

图3 是本系统所需数据的 E-R 模型图。

2.3 数据库逻辑结构设计

根据系统E—R 图,本系统需要有 2 个数据表分别来存放员工个人信息和人事变动记录。并且需要 1 个外部数据表(部门信息)的支持。同时部分记录字段需要用代码来表示,因此需要 3 个代码表来分别记录教育程度、职务和人事变更的代码。这 6 个数据表的结构如表 1 到表 6 所示。

2.4 数据库的建立

2.4.1 数据库的建立

创建需要一个数据库即可

2.4.2 初始数据的输入

本系统中需要输入的初始数据包括:部门信息、受教育程度代码、职务代码和人事变动代码。受教育程度代码和人事变动代码如表7 到表 8 所示,部门信息代码和职务代码的设置如图4 所示。

图4、部门信息代码和职务代码

3 各功能模块的设计与实现

3.1 功能说明

1、增加新员工

2、人事变动

3、员工信息查询修改

4、加密模块

5、员工登录

3.2 用户界面设计

完成数据库创建和功能说明以后,我们可以进行下一步工作,即设计用户界面。我们把人事信息管理系统的窗体分以下成 6 个主要部分。

1、主窗口的创建

2、增加新员工窗体的创建

3、人事变动窗体的创建

4、员工信息查询修改窗体的创建

5、加密模块的创建

6、登录窗口的创建

3.3 各功能模块的实现

1、增加新员工的实现

2、人事变动的实现

3、员工信息查询修改的实现

4、加密模块的实现

5、员工登录的实现

4 系统实现

4.1 数据库连接模块

  1. import java.sql.*;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. public class DbProcess{
  5. Connection connection = null;
  6. ResultSet rs = null;
  7. //mysql数据库url
  8. String userMySql="root";
  9. String passwordMySql="xxxx";//xxxx表示自己的数据库密码
  10. String urlMySql = "jdbc:mysql://localhost:3306/CourseDesign?user="
  11. +userMySql+"&password="+passwordMySql + "&serverTimezone=UTC&useUnicode=true&characterEncoding=gbk";
  12. //sqlserver数据库url
  13. //String urlSqlServer = "jdbc:sqlserver://localhost:1433;integratedSecurity=true;DatabaseName=InfoDb";
  14. public DbProcess() {
  15. try {
  16. //mysql数据库设置驱动程序类型
  17. Class.forName("com.mysql.cj.jdbc.Driver");
  18. System.out.println("mysql数据库驱动加载成功");
  19. //sqlserver数据库设置驱动程序类型
  20. //Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  21. //System.out.println("sqlserver数据库驱动加载成功");
  22. }
  23. catch(java.lang.ClassNotFoundException e) {
  24. e.printStackTrace();
  25. }
  26. }
  27. public void connect(){
  28. try{
  29. //mysql数据库
  30. connection = DriverManager.getConnection(urlMySql);
  31. //sqlserver数据库
  32. //connection = DriverManager.getConnection(urlSqlServer);
  33. if(connection!=null){
  34. System.out.println("数据库连接成功");
  35. }
  36. }
  37. catch(Exception e){
  38. e.printStackTrace();
  39. }
  40. }
  41. public void disconnect(){
  42. try{
  43. if(connection != null){
  44. connection.close();
  45. connection = null;
  46. System.out.println("数据库断开成功");
  47. }
  48. }
  49. catch(Exception e){
  50. e.printStackTrace();
  51. }
  52. }
  53. public ResultSet executeQuery(String sql) {
  54. try {
  55. System.out.println("executeQuery(). sql = " + sql);
  56. PreparedStatement pstm = connection.prepareStatement(sql);
  57. // 执行查询
  58. rs = pstm.executeQuery();
  59. }
  60. catch(SQLException ex) {
  61. ex.printStackTrace();
  62. }
  63. return rs;
  64. }
  65. //插入
  66. //executeUpdate 的返回值是一个整数,指示受影响的行数(即更新计数)。
  67. //executeUpdate用于执行 INSERT、UPDATE 或 DELETE 语句
  68. //以及 SQL DDL(数据定义语言)语句,例如 CREATE TABLE 和 DROP TABLE。
  69. //执行增、删、改语句的方法
  70. public int executeUpdate(String sql) {
  71. int count = 0;
  72. connect();
  73. try {
  74. Statement stmt = connection.createStatement();
  75. count = stmt.executeUpdate(sql);
  76. }
  77. catch(SQLException ex) {
  78. System.err.println(ex.getMessage());
  79. }
  80. disconnect();
  81. return count;
  82. }
  83. }

4.2 加密模块

  1. import java.math.BigInteger;
  2. public class Md5 {
  3. public static String md5(String str){
  4. BigInteger bStr = new BigInteger(str);
  5. BigInteger B = new BigInteger("654321");
  6. System.out.println("bStr="+bStr);
  7. System.out.println(B.xor(bStr));
  8. return String.valueOf(B.xor(bStr));
  9. }
  10. }

4.3 登陆模块

  1. import javax.swing.*;
  2. import javax.swing.table.DefaultTableModel;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. public class Login extends JFrame implements ActionListener{
  8. // 定义组件
  9. JLabel jLPersonnelManagement = null;//人事管理系统
  10. JLabel jLLoginUser = null;//登录工号
  11. JLabel jLLoginPassword = null;//登录密码
  12. JLabel jLLoginStatus = null;//身份
  13. JTextField jTFLoginUser = null;//用户框
  14. JPasswordField jPFLoginPassword = null;//密码框
  15. JButton jBLogin = null;//登录
  16. JButton jBExit = null;//退出
  17. JComboBox<String> jCBSelectUser = null;//用户选择
  18. JPanel jP1, jP2,jP3,jP4,jP5 = null;
  19. JPanel jP= null;
  20. JScrollPane LoginJScrollPane = null;
  21. private static DbProcess LdbProcess;
  22. private static Manage M;
  23. private static Employee E;
  24. private static Md5 md5;
  25. String SelectUserStr = "管理员";
  26. public Login() {
  27. this.md5 = new Md5();
  28. // 创建标签组件
  29. jLPersonnelManagement = new JLabel("人事管理系统");
  30. jLPersonnelManagement.setFont(new Font("宋体",Font.BOLD,25));
  31. jLLoginUser = new JLabel("工号:");
  32. jLLoginUser.setFont(new Font("宋体",Font.BOLD,15));
  33. jLLoginPassword = new JLabel("密码:");
  34. jLLoginPassword.setFont(new Font("宋体",Font.BOLD,15));
  35. jLLoginStatus = new JLabel("身份:");
  36. jLLoginStatus.setFont(new Font("宋体",Font.BOLD,15));
  37. jTFLoginUser = new JTextField(15);//用户
  38. jPFLoginPassword = new JPasswordField(15);//密码
  39. jBLogin = new JButton("登录");
  40. jBLogin.setFont(new Font("宋体",Font.BOLD,15));
  41. jBExit = new JButton("退出");
  42. jBExit.setFont(new Font("宋体",Font.BOLD,15));
  43. // 设置监听
  44. jBLogin.addActionListener(this);
  45. jBExit.addActionListener(this);
  46. jCBSelectUser = new JComboBox<String>();//查询字段
  47. jCBSelectUser.setFont(new Font("宋体",Font.BOLD,15));
  48. //添加选项
  49. jCBSelectUser.addItem("管理员");
  50. jCBSelectUser.addItem("普通员工");
  51. jCBSelectUser.addItemListener(new ItemListener() {//下拉框事件监听
  52. public void itemStateChanged(ItemEvent event) {
  53. switch (event.getStateChange()) {
  54. case ItemEvent.SELECTED:
  55. SelectUserStr = (String) event.getItem();
  56. System.out.println("选中:" + SelectUserStr);
  57. break;
  58. case ItemEvent.DESELECTED:
  59. System.out.println("取消选中:" + event.getItem());
  60. break;
  61. }
  62. }
  63. });
  64. LoginJScrollPane = new JScrollPane();
  65. jP1 = new JPanel();
  66. jP2 = new JPanel();
  67. jP3 = new JPanel();
  68. jP4 = new JPanel();
  69. jP5 = new JPanel();
  70. jP = new JPanel();
  71. jP1.add(jLPersonnelManagement);
  72. jP1.setLayout(new FlowLayout(FlowLayout.CENTER));
  73. jP1.setPreferredSize(new Dimension(20,85));
  74. jP2.add(jLLoginUser);
  75. jP2.add(jTFLoginUser);
  76. jP2.setLayout(new FlowLayout(FlowLayout.CENTER));
  77. jP2.setPreferredSize(new Dimension(20,85));
  78. jP3.add(jLLoginPassword);
  79. jP3.add(jPFLoginPassword);
  80. jP3.setLayout(new FlowLayout(FlowLayout.CENTER));
  81. jP3.setPreferredSize(new Dimension(20,85));
  82. jP4.add(jLLoginStatus);
  83. jP4.add(jCBSelectUser);
  84. jP4.setLayout(new FlowLayout(FlowLayout.CENTER));
  85. jP4.setPreferredSize(new Dimension(20,85));
  86. jP5.add(jBLogin);
  87. jP5.add(jBExit);
  88. jP5.setLayout(new FlowLayout(FlowLayout.CENTER));
  89. jP5.setPreferredSize(new Dimension(20,85));
  90. jP.setLayout(new GridLayout(5, 1));
  91. jP.add(jP1);
  92. jP.add(jP2);
  93. jP.add(jP3);
  94. jP.add(jP4);
  95. jP.add(jP5);
  96. this.add("North",LoginJScrollPane);
  97. this.add("South",jP);
  98. this.setLayout(new BorderLayout());
  99. this.add(jP,BorderLayout.SOUTH);
  100. this.setTitle("登录界面");
  101. this.setSize(460, 500);
  102. this.setLocation(450, 100);
  103. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  104. this.setVisible(true);
  105. this.setResizable(false);
  106. LdbProcess = new DbProcess();
  107. }
  108. public void actionPerformed(ActionEvent e) {
  109. if(e.getActionCommand().equals("登录")
  110. &&!jTFLoginUser.getText().isEmpty()
  111. &&!String.valueOf(jPFLoginPassword.getPassword()).equals("")){
  112. String sID = jTFLoginUser.getText().trim();
  113. String sPassword = new String(jPFLoginPassword.getPassword());
  114. System.out.println("actionPerformed(). 登录"+sPassword);
  115. loginProcess(sID,sPassword,SelectUserStr);
  116. jPFLoginPassword.setText("");
  117. }else if(e.getActionCommand().equals("退出")) {
  118. System.out.println("actionPerformed(). 退出");
  119. System.exit(0);
  120. }
  121. }
  122. public void loginProcess(String sID, String sPassword,String userStr){
  123. try{
  124. // 建立查询条件
  125. String sql = "select * from staff where ";
  126. sql = sql + "sID";
  127. sql = sql + " = ";
  128. sql = sql + "'" + sID + "';";
  129. System.out.println("queryProcess(). sql = " + sql);
  130. LdbProcess.connect();
  131. ResultSet rs = LdbProcess.executeQuery(sql);
  132. rs.next();
  133. if(rs.getString(14).equals("T")){
  134. if(this.md5.md5(sPassword).equals(rs.getString(2))){
  135. if(rs.getString(3).equals("普通员工")){
  136. if(userStr.equals("普通员工")){
  137. JOptionPane.showMessageDialog(null,
  138. "登录成功!","提示",JOptionPane.INFORMATION_MESSAGE);
  139. this.dispose();
  140. this.E = new Employee(rs);
  141. }else{
  142. JOptionPane.showMessageDialog(null,
  143. "用户身份错误,请重新选择!","错误",JOptionPane.ERROR_MESSAGE);
  144. }
  145. }
  146. if(rs.getString(3).equals("管理员")){
  147. JOptionPane.showMessageDialog(null,
  148. "登录成功!","提示",JOptionPane.INFORMATION_MESSAGE);
  149. this.dispose();
  150. if(userStr.equals("普通员工")){
  151. this.E = new Employee(rs);
  152. }else if(userStr.equals("管理员")){
  153. this.M = new Manage();
  154. }
  155. }
  156. }else{
  157. JOptionPane.showMessageDialog(null,
  158. "用户密码错误,请重新输入!","错误",JOptionPane.ERROR_MESSAGE);
  159. }
  160. }else{
  161. JOptionPane.showMessageDialog(null,
  162. "你已非本公司员工!","错误",JOptionPane.ERROR_MESSAGE);
  163. }
  164. LdbProcess.disconnect();
  165. }catch(SQLException sqle){
  166. System.out.println("sqle = " + sqle);
  167. JOptionPane.showMessageDialog(null,
  168. "你输入的工号不存在,请从新输入!","错误",JOptionPane.ERROR_MESSAGE);
  169. }catch(Exception e){
  170. System.out.println("e = " + e);
  171. JOptionPane.showMessageDialog(null,
  172. "你输入的工号不存在,请从新输入!","错误",JOptionPane.ERROR_MESSAGE);
  173. }
  174. }
  175. }

4.4 管理模块

  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. public class Manage extends JFrame implements ActionListener{
  7. // 定义组件
  8. JButton jBInsert = null;//员工加入
  9. JButton jBChange = null;//人事变更
  10. JButton jBQueryUpdate = null;//查询修改
  11. //JButton jBChangeRecord = null;//变更记录
  12. JPanel jP1, jP2,jP3,jP4 = null;
  13. JPanel jP = null;
  14. JScrollPane ManageJScrollPane = null;
  15. private static DbProcess MdbProcess;
  16. private static PersonnelChange P;
  17. private static NewEmployee N;
  18. private static DatabaseCourseDesign D;
  19. public Manage() {
  20. MdbProcess = new DbProcess();
  21. int pid=100000;
  22. try{
  23. String sql ="select max(pID) from personnel;";
  24. MdbProcess.connect();
  25. ResultSet rs = MdbProcess.executeQuery(sql);
  26. if(rs.next()){
  27. if(pid<=rs.getInt(1)){
  28. pid=rs.getInt(1);
  29. }
  30. System.out.println("pid"+pid);
  31. }
  32. MdbProcess.disconnect();
  33. }catch(SQLException sqle){
  34. System.out.println("sqle = " + sqle);
  35. JOptionPane.showMessageDialog(null,
  36. "空集合","错误",JOptionPane.ERROR_MESSAGE);
  37. }finally {
  38. System.out.println(pid);
  39. this.P = new PersonnelChange(pid+1);
  40. }
  41. // 组件
  42. jBInsert = new JButton("新员工档案的录入");
  43. jBInsert.setFont(new Font("宋体",Font.BOLD,15));
  44. jBChange = new JButton(" 人事变更 ");
  45. jBChange.setFont(new Font("宋体",Font.BOLD,15));
  46. jBQueryUpdate = new JButton("员工档案查询修改");
  47. jBQueryUpdate.setFont(new Font("宋体",Font.BOLD,15));
  48. //jBChangeRecord = new JButton("人事变更记录");
  49. //jBChangeRecord.setFont(new Font("宋体",Font.BOLD,15));
  50. // 设置监听
  51. jBInsert.addActionListener(this);
  52. jBChange.addActionListener(this);
  53. jBQueryUpdate.addActionListener(this);
  54. //jBChangeRecord.addActionListener(this);
  55. ManageJScrollPane = new JScrollPane();
  56. jP1 = new JPanel();
  57. jP2 = new JPanel();
  58. jP3 = new JPanel();
  59. jP4 = new JPanel();
  60. jP = new JPanel();
  61. jP1.add(jBInsert);
  62. jP1.setLayout(new FlowLayout(FlowLayout.CENTER));
  63. jP1.setPreferredSize(new Dimension(250,100));
  64. jP2.add(jBChange);
  65. jP2.setLayout(new FlowLayout(FlowLayout.CENTER));
  66. jP2.setPreferredSize(new Dimension(250,100));
  67. jP3.add(jBQueryUpdate);
  68. jP3.setLayout(new FlowLayout(FlowLayout.CENTER));
  69. jP3.setPreferredSize(new Dimension(250,100));
  70. //jP4.add(jBChangeRecord);
  71. //jP4.setLayout(new FlowLayout(FlowLayout.CENTER));
  72. //jP4.setPreferredSize(new Dimension(250,100));
  73. jP.setLayout(new GridLayout(3, 1));
  74. jP.add(jP1);
  75. jP.add(jP2);
  76. jP.add(jP3);
  77. //jP.add(jP4);
  78. this.add("North", ManageJScrollPane);
  79. this.add("South", jP);
  80. this.setLayout(new BorderLayout());
  81. this.add(jP,BorderLayout.SOUTH);
  82. this.setTitle("管理界面");
  83. this.setSize(350, 400);
  84. this.setLocation(150, 150);
  85. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  86. this.setVisible(true);
  87. this.setResizable(false);
  88. }
  89. public void actionPerformed(ActionEvent e) {
  90. if(e.getActionCommand().equals("新员工档案的录入")){
  91. System.out.println("actionPerformed(). 新员工档案的录入");
  92. int sid=10000;
  93. try{
  94. String sql ="select max(sID) from staff;";
  95. MdbProcess.connect();
  96. ResultSet rs = MdbProcess.executeQuery(sql);
  97. if(rs.next()){
  98. if(sid<=rs.getInt(1)){
  99. sid=rs.getInt(1);
  100. }
  101. System.out.println("sid"+sid);
  102. }
  103. MdbProcess.disconnect();
  104. }catch(SQLException sqle){
  105. System.out.println("sqle = " + sqle);
  106. JOptionPane.showMessageDialog(null,
  107. "空集合","错误",JOptionPane.ERROR_MESSAGE);
  108. }finally {
  109. this.N = new NewEmployee(sid+1,P);
  110. }
  111. }else if(e.getActionCommand().equals(" 人事变更 ")) {
  112. System.out.println("actionPerformed(). 人事变更");
  113. P.PersonnelVector.clear();
  114. P.PersonnelRecordJTable.updateUI();
  115. P.setVisible(true);
  116. }else if(e.getActionCommand().equals("员工档案查询修改")) {
  117. System.out.println("actionPerformed(). 员工档案查询修改");
  118. this.D = new DatabaseCourseDesign();
  119. }
  120. }
  121. }

4.5 新员工档案录入模块

  1. import javax.swing.*;
  2. import javax.swing.table.DefaultTableModel;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. public class NewEmployee extends JFrame implements ActionListener {
  8. // 定义组件
  9. JLabel jLNewEmployee = null;//新员工信息
  10. JLabel jLText = null;//注释
  11. JLabel jLsID = null;//工号
  12. JLabel jLsPassword = null;//密码
  13. JLabel jLsAuthority = null;//权限
  14. JLabel jLsName = null;//姓名
  15. JLabel jLsSex = null;//性别
  16. JLabel jLsBirthday = null;//生日
  17. JLabel jLsDepartment = null;//部门
  18. JLabel jLsJob = null;//职务
  19. JLabel jLsEdu_Level = null;//教育水平
  20. JLabel jLsSpecialty = null;//专业技能
  21. JLabel jLsAddress = null;//住址
  22. JLabel jLsTel = null;//电话
  23. JLabel jLsEmail = null;//邮箱
  24. JLabel jLsState = null;//状态
  25. JLabel jLsRemark = null;//备注
  26. JTextField jTFsID = null;//工号
  27. JTextField jTFsPassword = null;//密码
  28. JTextField jTFsName = null;//姓名
  29. JTextField jTFsSex = null;//性别
  30. JTextField jTFsBirthday = null;//生日
  31. JTextField jTFsSpecialty = null;//专业技能
  32. JTextField jTFsAddress = null;//住址
  33. JTextField jTFsTel = null;//电话
  34. JTextField jTFsEmail = null;//邮箱
  35. JTextField jTFsState = null;//状态
  36. JTextField jTFsRemark = null;//备注
  37. JComboBox<String> jCBAuthority = null;//权限
  38. JComboBox<String> jCBDepartment = null;//部门
  39. JComboBox<String> jCBJob = null;//职务
  40. JComboBox<String> jCBEdu_Level = null;//教育水平
  41. //JComboBox<String> jCBDepartment = null;//部门
  42. String jCBAuthorityStr="普通员工";
  43. String jCBDepartmentStr="0-生产部";
  44. String jCBJobStr="0-员工";
  45. String jCBEdu_LevelStr="0-小学";
  46. JButton jBInsert = null;//返回
  47. //JButton jBDeleteCurrentRecord = null;//删除当前记录
  48. //JButton jBDeleteAllRecords = null;//删除所有记录
  49. //JComboBox jCBSelectQueryField = null;
  50. JPanel jP1, jP2,jP3, jP4, jP5 = null;
  51. JPanel jP = null;
  52. DefaultTableModel studentTableModel = null;
  53. JScrollPane NewEmployeeJScrollPane = null;
  54. private static DbProcess NdbProcess;
  55. private static PersonnelChange P;
  56. private static Md5 md5;
  57. private static int sid;
  58. // 构造函数
  59. public NewEmployee(int id,PersonnelChange P) {
  60. this.md5=new Md5();
  61. this.P=P;
  62. this.sid=id;
  63. // 创建标签组件
  64. jLNewEmployee = new JLabel("新员工信息");
  65. jLNewEmployee.setFont(new Font("宋体",Font.BOLD,25));
  66. jLText = new JLabel("注意:带*的为必填项 ");
  67. jLText.setFont(new Font("宋体",Font.BOLD,15));
  68. jLText.setForeground(Color.red);
  69. jLsID = new JLabel("工号*");
  70. jLsPassword = new JLabel("密码*");
  71. jLsAuthority = new JLabel("权限*");
  72. jLsName = new JLabel("姓名*");
  73. jLsSex = new JLabel("性别*");
  74. jLsBirthday = new JLabel("生日*");
  75. jLsDepartment = new JLabel("部门*");
  76. jLsJob = new JLabel("职务*");
  77. jLsEdu_Level = new JLabel("教育水平*");
  78. jLsSpecialty = new JLabel("专业技能*");
  79. jLsAddress = new JLabel("住址*");
  80. jLsTel = new JLabel("电话*");
  81. jLsEmail = new JLabel("邮箱*");
  82. jLsState = new JLabel("状态*");
  83. jLsRemark = new JLabel("备注");
  84. NdbProcess = new DbProcess();
  85. jTFsID = new JTextField(15);//工号
  86. jTFsID.setEditable(false);
  87. jTFsID.setText(String.valueOf(sid));
  88. jTFsPassword = new JTextField(15);//密码
  89. jTFsPassword.setEditable(false);
  90. jTFsPassword.setText(String.valueOf(sid));
  91. jTFsName = new JTextField(15);//姓名
  92. jTFsSex = new JTextField(15);//性别
  93. jTFsBirthday = new JTextField(15);//生日
  94. jTFsSpecialty = new JTextField(15);//专业技能
  95. jTFsAddress = new JTextField(15);//住址
  96. jTFsTel = new JTextField(15);//电话
  97. jTFsEmail = new JTextField(15);//邮箱
  98. jTFsState = new JTextField(15);//状态
  99. jTFsState.setEditable(false);
  100. jTFsState.setText("T");
  101. jTFsRemark = new JTextField(15);//备注
  102. jBInsert = new JButton("录入新员工");
  103. jBInsert.setFont(new Font("宋体",Font.BOLD,20));
  104. // 设置监听
  105. jBInsert.addActionListener(this);
  106. jCBAuthority = new JComboBox<String>();//权限
  107. //jCBAuthority.set
  108. jCBAuthority.addItem("普通员工");//添加选项
  109. jCBAuthority.addItem("管理员");
  110. jCBDepartment = new JComboBox<String>();//部门
  111. jCBDepartment.addItem("0-生产部");
  112. jCBDepartment.addItem("1-运营部");
  113. jCBDepartment.addItem("2-行政部");
  114. jCBDepartment.addItem("3-人事部");
  115. jCBJob = new JComboBox<String>();//职务
  116. jCBJob.addItem("0-员工");
  117. jCBJob.addItem("1-组长");
  118. jCBJob.addItem("2-主任");
  119. jCBJob.addItem("3-经理");
  120. jCBEdu_Level = new JComboBox<String>();//教育水平
  121. jCBEdu_Level.addItem("0-小学");
  122. jCBEdu_Level.addItem("1-初中");
  123. jCBEdu_Level.addItem("2-高中");
  124. jCBEdu_Level.addItem("3-职高");
  125. jCBEdu_Level.addItem("4-大本");
  126. jCBEdu_Level.addItem("5-大专");
  127. jCBEdu_Level.addItem("6-硕士");
  128. jCBEdu_Level.addItem("7-博士");
  129. jCBEdu_Level.addItem("8-博士后");
  130. jCBAuthority.addItemListener(new ItemListener() {//查询下拉框事件监听
  131. public void itemStateChanged(ItemEvent event) {
  132. switch (event.getStateChange()) {
  133. case ItemEvent.SELECTED:
  134. jCBAuthorityStr = (String) event.getItem();
  135. System.out.println("选中:" + jCBAuthorityStr);
  136. break;
  137. case ItemEvent.DESELECTED:
  138. System.out.println("取消选中:" + event.getItem());
  139. break;
  140. }
  141. }
  142. });
  143. jCBDepartment.addItemListener(new ItemListener() {//查询下拉框事件监听
  144. public void itemStateChanged(ItemEvent event) {
  145. switch (event.getStateChange()) {
  146. case ItemEvent.SELECTED:
  147. jCBDepartmentStr = (String) event.getItem();
  148. System.out.println("选中:" + jCBDepartmentStr);
  149. break;
  150. case ItemEvent.DESELECTED:
  151. System.out.println("取消选中:" + event.getItem());
  152. break;
  153. }
  154. }
  155. });
  156. jCBJob.addItemListener(new ItemListener() {//查询下拉框事件监听
  157. public void itemStateChanged(ItemEvent event) {
  158. switch (event.getStateChange()) {
  159. case ItemEvent.SELECTED:
  160. jCBJobStr = (String) event.getItem();
  161. System.out.println("选中:" + jCBJobStr);
  162. break;
  163. case ItemEvent.DESELECTED:
  164. System.out.println("取消选中:" + event.getItem());
  165. break;
  166. }
  167. }
  168. });
  169. jCBEdu_Level.addItemListener(new ItemListener() {//查询下拉框事件监听
  170. public void itemStateChanged(ItemEvent event) {
  171. switch (event.getStateChange()) {
  172. case ItemEvent.SELECTED:
  173. jCBEdu_LevelStr = (String) event.getItem();
  174. System.out.println("选中:" + jCBEdu_LevelStr);
  175. break;
  176. case ItemEvent.DESELECTED:
  177. System.out.println("取消选中:" + event.getItem());
  178. break;
  179. }
  180. }
  181. });
  182. //studentTableModel = new DefaultTableModel(tableTitle, 15);
  183. NewEmployeeJScrollPane = new JScrollPane();
  184. jP1 = new JPanel();
  185. jP2 = new JPanel();
  186. jP3 = new JPanel();
  187. jP4 = new JPanel();
  188. jP5 = new JPanel();
  189. jP = new JPanel();
  190. //jP1.add(NewEmployeeJScrollPane);
  191. jP1.add(jLNewEmployee);
  192. jP1.setLayout(new FlowLayout(FlowLayout.CENTER));
  193. jP1.setPreferredSize(new Dimension(250,80));
  194. jP2.add(jLsID);
  195. jP2.add(jTFsID);
  196. jP2.add(jLsPassword);
  197. jP2.add(jTFsPassword);
  198. jP2.add(jLsAuthority);
  199. jP2.add(jCBAuthority);
  200. jP2.add(jLsDepartment);
  201. jP2.add(jCBDepartment);
  202. jP2.add(jLsJob);
  203. jP2.add(jCBJob);
  204. jP2.add(jLsEdu_Level);
  205. jP2.add(jCBEdu_Level);
  206. jP2.setLayout(new FlowLayout(FlowLayout.CENTER));
  207. jP2.setPreferredSize(new Dimension(250,80));
  208. jP3.add(jLsName);
  209. jP3.add(jTFsName);
  210. jP3.add(jLsSex);
  211. jP3.add(jTFsSex);
  212. jP3.add(jLsBirthday);
  213. jP3.add(jTFsBirthday);
  214. jP3.add(jLsSpecialty);
  215. jP3.add(jTFsSpecialty);
  216. jP3.setLayout(new FlowLayout(FlowLayout.CENTER));
  217. jP3.setPreferredSize(new Dimension(250,80));
  218. jP4.add(jLsAddress);
  219. jP4.add(jTFsAddress);
  220. jP4.add(jLsTel);
  221. jP4.add(jTFsTel);
  222. jP4.add(jLsEmail);
  223. jP4.add(jTFsEmail);
  224. jP4.add(jLsState);
  225. jP4.add(jTFsState);
  226. jP4.add(jLsRemark);
  227. jP4.add(jTFsRemark);
  228. jP4.setLayout(new FlowLayout(FlowLayout.CENTER));
  229. jP4.setPreferredSize(new Dimension(250,80));
  230. //jP5.setLayout(new BorderLayout());
  231. jP5.add(jLText);
  232. jP5.add(jBInsert);
  233. jP5.setLayout(new FlowLayout(FlowLayout.CENTER));
  234. jP5.setPreferredSize(new Dimension(250,80));
  235. jP.setLayout(new GridLayout(5, 1));
  236. jP.add(jP1);
  237. jP.add(jP2);
  238. jP.add(jP3);
  239. jP.add(jP4);
  240. jP.add(jP5);
  241. this.add("North", NewEmployeeJScrollPane);
  242. this.add("South", jP);
  243. this.setLayout(new BorderLayout());
  244. this.add(jP,BorderLayout.SOUTH);
  245. this.setTitle("新员工档案的录入");
  246. this.setSize(970, 450);
  247. this.setLocation(200, 150);
  248. this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  249. this.setVisible(true);
  250. this.setResizable(false);
  251. }
  252. public void actionPerformed(ActionEvent e) {
  253. if(e.getActionCommand().equals("录入新员工")
  254. && !jTFsPassword.getText().isEmpty()
  255. && !jTFsName.getText().isEmpty()
  256. && !jTFsSex.getText().isEmpty()
  257. && !jTFsBirthday.getText().isEmpty()
  258. && !jTFsSpecialty.getText().isEmpty()
  259. && !jTFsAddress.getText().isEmpty()
  260. && !jTFsTel.getText().isEmpty()
  261. && !jTFsEmail.getText().isEmpty()
  262. && !jTFsState.getText().isEmpty()){
  263. System.out.println("actionPerformed(). 录入新员工");
  264. insertProcess();
  265. sid++;
  266. jTFsID.setText(String.valueOf(sid));
  267. jTFsPassword.setText(String.valueOf(sid));
  268. jTFsName.setText("");
  269. jTFsSex.setText("");
  270. jTFsBirthday.setText("");
  271. jTFsSpecialty.setText("");
  272. jTFsAddress.setText("");
  273. jTFsTel.setText("");
  274. jTFsEmail.setText("");
  275. jTFsRemark.setText("");
  276. }
  277. }
  278. public void insertProcess(){
  279. String sID = jTFsID.getText().trim();
  280. String sPassword = this.md5.md5(jTFsPassword.getText().trim());
  281. String sAuthority = jCBAuthorityStr;
  282. String sName = jTFsName.getText().trim();
  283. String sSex = jTFsSex.getText().trim();
  284. String sBirthday = jTFsBirthday.getText().trim();
  285. String sDepartment = "";
  286. String sJob = "";
  287. String sEdu_Level = "";
  288. String sSpecialty = jTFsSpecialty.getText().trim();
  289. String sAddress = jTFsAddress.getText().trim();
  290. String sTel = jTFsTel.getText().trim();
  291. String sEmail = jTFsEmail.getText().trim();
  292. String sState = jTFsState.getText().trim();
  293. String sRemark = jTFsRemark.getText().trim();
  294. if(jCBDepartmentStr.equals("0-生产部")){
  295. sDepartment="生产部";
  296. }else if(jCBDepartmentStr.equals("1-运营部")){
  297. sDepartment="运营部";
  298. }
  299. else if(jCBDepartmentStr.equals("2-行政部")){
  300. sDepartment="行政部";
  301. }
  302. else if(jCBDepartmentStr.equals("3-人事部")){
  303. sDepartment="人事部";
  304. }
  305. if(jCBJobStr.equals("0-员工")){
  306. sJob="员工";
  307. }else if(jCBJobStr.equals("1-组长")){
  308. sJob="组长";
  309. }else if(jCBJobStr.equals("2-主任")){
  310. sJob="主任";
  311. }else if(jCBJobStr.equals("3-经理")){
  312. sJob="经理";
  313. }
  314. if(jCBEdu_LevelStr.equals("0-小学")){
  315. sEdu_Level="小学";
  316. }else if(jCBEdu_LevelStr.equals("1-初中")){
  317. sEdu_Level="初中";
  318. }else if(jCBEdu_LevelStr.equals("2-高中")){
  319. sEdu_Level="高中";
  320. }else if(jCBEdu_LevelStr.equals("3-职高")){
  321. sEdu_Level="职高";
  322. }else if(jCBEdu_LevelStr.equals("4-大本")){
  323. sEdu_Level="大本";
  324. }else if(jCBEdu_LevelStr.equals("5-大专")){
  325. sEdu_Level="大专";
  326. }else if(jCBEdu_LevelStr.equals("6-硕士")){
  327. sEdu_Level="硕士";
  328. }else if(jCBEdu_LevelStr.equals("7-博士")){
  329. sEdu_Level="博士";
  330. }else if(jCBEdu_LevelStr.equals("8-博士后")){
  331. sEdu_Level="博士后";
  332. }
  333. // 建立更新条件
  334. String sql = "insert into staff values('";
  335. sql = sql + sID + "','";
  336. sql = sql + sPassword + "','";
  337. sql = sql + sAuthority + "','";
  338. sql = sql + sName + "','";
  339. sql = sql + sSex + "','";
  340. sql = sql + sBirthday + "','";
  341. sql = sql + sDepartment + "','";
  342. sql = sql + sJob + "','";
  343. sql = sql + sEdu_Level + "','";
  344. sql = sql + sSpecialty + "','";
  345. sql = sql + sAddress + "','";
  346. sql = sql + sTel + "','";
  347. sql = sql + sEmail + "','";
  348. sql = sql + sState + "','";
  349. sql = sql + sRemark + "');";
  350. System.out.println("updateProcess(). sql = " + sql);
  351. try{
  352. if (NdbProcess.executeUpdate(sql) < 1) {
  353. System.out.println("updateProcess(). update database failed.");
  354. }else{
  355. //String sql = "insert into staff values('";
  356. JOptionPane.showMessageDialog(null,
  357. "录入新员工成功!","提示",JOptionPane.INFORMATION_MESSAGE);
  358. int pid=100000;
  359. try{
  360. sql ="select max(pID) from personnel;";
  361. System.out.println("queryProcess(). sql = " + sql);
  362. NdbProcess.connect();
  363. ResultSet rs = NdbProcess.executeQuery(sql);
  364. if(rs.next()){
  365. if(pid<=rs.getInt(1)){
  366. pid=rs.getInt(1);
  367. System.out.println("pid"+pid);
  368. }
  369. }
  370. NdbProcess.disconnect();
  371. }catch(SQLException sqle){
  372. System.out.println("sqle = " + sqle);
  373. JOptionPane.showMessageDialog(null,
  374. "空集合","错误",JOptionPane.ERROR_MESSAGE);
  375. }finally {
  376. System.out.println(pid);
  377. sql = "insert into personnel values('";
  378. sql = sql + (pid+1) + "','";
  379. sql = sql + sID + "','";
  380. sql = sql + "0" + "','";
  381. sql = sql + "新员工录入" + "');";
  382. if (NdbProcess.executeUpdate(sql) < 1) {
  383. System.out.println("updateProcess(). update database failed.");
  384. }else{
  385. P.jTFChangeID.setText(String.valueOf(pid+2));
  386. //this.P.setVisible(true);
  387. JOptionPane.showMessageDialog(null,
  388. "人事变动成功!","提示",JOptionPane.INFORMATION_MESSAGE);
  389. }
  390. }
  391. }
  392. }catch(Exception e){
  393. System.out.println("e = " + e);
  394. JOptionPane.showMessageDialog(null,
  395. "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);
  396. }
  397. }
  398. }

4.6 人事变更模块

  1. import javax.swing.*;
  2. import javax.swing.table.DefaultTableModel;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.util.Vector;
  8. class PersonnelChange extends JFrame implements ActionListener {
  9. // 定义组件
  10. JLabel jLPersonnelRecord = null;//人事变更记录表
  11. JLabel jLSelectQueryField = null;//选择查询字段
  12. JLabel jLText2 = null;//注释1
  13. JLabel jLText1 = null;//注释2
  14. JLabel jLEqual1 = null;//=
  15. JLabel jLEqual2 = null;//=
  16. JLabel jLChangeID = null;//变更编号
  17. JLabel jLsID = null;//需要进行变更的员工工号
  18. JLabel jLSelectChangeCode = null;//代码
  19. JLabel jLAfter;//变之后的内容
  20. JLabel jLChangeDescription = null;//详细描述
  21. JTextField jTFQueryField = null;//查询字段
  22. JTextField jTFChangeID = null;//变更编号
  23. JTextField jTFsID = null;//需要进行变更的员工工号
  24. JTextField jTFChangeDescription = null;//详细描述
  25. JButton jBQuery = null;//查询
  26. JButton jBQueryAll = null;//查询所有记录
  27. JButton jBChange = null;//变更
  28. //JButton jBDeleteCurrentRecord = null;//删除当前记录
  29. //JButton jBDeleteAllRecords = null;//删除所有记录
  30. //JComboBox jCBSelectQueryField = null;
  31. JComboBox<String> jCBSelectQueryField = null;//查询字段
  32. JComboBox<String> jCBChangeCode = null;//代码
  33. JComboBox<String> jCBJob = null;//职务
  34. JPanel jP1, jP2,jP3,jP4,jP5,jP6,jP7,jP8,jP9,jP10 = null;
  35. JPanel jPTop, jPBottom = null;
  36. DefaultTableModel studentTableModel = null;
  37. JTable PersonnelRecordJTable = null;
  38. JScrollPane PersonnelRecordJScrollPane = null;
  39. Vector PersonnelVector = null;
  40. Vector titleVector = null;
  41. private static DbProcess PdbProcess;
  42. private static int pid;
  43. String SelectQueryFieldStr = "记录编号";
  44. String SelectChangeCodeStr = "1-职务变动";
  45. String jCBJobStr="0-员工";
  46. // 构造函数
  47. public PersonnelChange(int pid) {
  48. this.pid=pid;
  49. // 创建标签组件
  50. jLPersonnelRecord = new JLabel("人事变更记录表");
  51. jLText1 = new JLabel("注意:带*的为必填项,进行职务变动需要选择变动后的职务,辞退不需要处理");
  52. jLText1.setFont(new Font("宋体",Font.BOLD,15));
  53. jLText1.setForeground(Color.red);
  54. jLText2 = new JLabel("变更代码含义:0(新员工加入),1(职务变动),2(辞退)");
  55. jLText2.setFont(new Font("宋体",Font.BOLD,15));
  56. jLText2.setForeground(Color.red);
  57. jLSelectQueryField = new JLabel("选择查询字段");
  58. jLSelectQueryField.setFont(new Font("宋体",Font.BOLD,15));
  59. jLEqual1 = new JLabel(" = ");
  60. jLEqual1.setFont(new Font("宋体",Font.BOLD,15));
  61. jLEqual2 = new JLabel(" = ");
  62. jLEqual2.setFont(new Font("宋体",Font.BOLD,15));
  63. jLChangeID = new JLabel("记录编号*:");
  64. jLChangeID.setFont(new Font("宋体",Font.BOLD,15));
  65. jLsID = new JLabel("需要进行变更的员工工号*:");
  66. jLsID.setFont(new Font("宋体",Font.BOLD,15));
  67. jLSelectChangeCode = new JLabel("需要变更的代码*");
  68. jLSelectChangeCode.setFont(new Font("宋体",Font.BOLD,15));
  69. jLAfter = new JLabel("改变后的职务:");
  70. jLAfter.setFont(new Font("宋体",Font.BOLD,15));
  71. jLChangeDescription = new JLabel("详细描述*:");
  72. jLChangeDescription.setFont(new Font("宋体",Font.BOLD,15));
  73. jTFQueryField = new JTextField(15);//查询字段
  74. jTFChangeID = new JTextField(15);
  75. jTFChangeID.setEditable(false);
  76. jTFChangeID.setText(String.valueOf(pid));
  77. jTFsID = new JTextField(15);//需要进行变更的员工工号
  78. jTFChangeDescription = new JTextField(25);
  79. jBQuery = new JButton("查询");
  80. jBQueryAll = new JButton("查询所有记录");
  81. jBChange = new JButton("变更");
  82. jBChange.setFont(new Font("宋体",Font.BOLD,20));
  83. // 设置监听
  84. jBQuery.addActionListener(this);
  85. jBQueryAll.addActionListener(this);
  86. jBChange.addActionListener(this);
  87. jCBSelectQueryField = new JComboBox<String>();//查询字段
  88. jCBSelectQueryField.addItem("记录编号");//添加选项
  89. jCBSelectQueryField.addItem("员工工号");
  90. jCBSelectQueryField.addItem("变更代码");
  91. jCBChangeCode = new JComboBox<String>();//变更代码
  92. jCBChangeCode.addItem("1-职务变动");
  93. jCBChangeCode.addItem("2-辞退");
  94. jCBJob = new JComboBox<String>();//职务
  95. jCBJob.addItem("0-员工");
  96. jCBJob.addItem("1-组长");
  97. jCBJob.addItem("2-主任");
  98. jCBJob.addItem("3-经理");
  99. jCBSelectQueryField.addItemListener(new ItemListener() {//查询下拉框事件监听
  100. public void itemStateChanged(ItemEvent event) {
  101. switch (event.getStateChange()) {
  102. case ItemEvent.SELECTED:
  103. SelectQueryFieldStr = (String) event.getItem();
  104. System.out.println("选中:" + SelectQueryFieldStr);
  105. break;
  106. case ItemEvent.DESELECTED:
  107. System.out.println("取消选中:" + event.getItem());
  108. break;
  109. }
  110. }
  111. });
  112. jCBChangeCode.addItemListener(new ItemListener() {//变更代码下拉框事件监听
  113. public void itemStateChanged(ItemEvent event) {
  114. switch (event.getStateChange()) {
  115. case ItemEvent.SELECTED:
  116. SelectChangeCodeStr = (String) event.getItem();
  117. System.out.println("选中:" + SelectChangeCodeStr);
  118. break;
  119. case ItemEvent.DESELECTED:
  120. System.out.println("取消选中:" + event.getItem());
  121. break;
  122. }
  123. }
  124. });
  125. jCBJob.addItemListener(new ItemListener() {//职务下拉框事件监听
  126. public void itemStateChanged(ItemEvent event) {
  127. switch (event.getStateChange()) {
  128. case ItemEvent.SELECTED:
  129. jCBJobStr = (String) event.getItem();
  130. System.out.println("选中:" + jCBJobStr);
  131. break;
  132. case ItemEvent.DESELECTED:
  133. System.out.println("取消选中:" + event.getItem());
  134. break;
  135. }
  136. }
  137. });
  138. PersonnelVector = new Vector();
  139. titleVector = new Vector();
  140. // 定义表头
  141. titleVector.add("记录编号");
  142. titleVector.add("变更代码");
  143. titleVector.add("员工工号");
  144. titleVector.add("员工姓名");
  145. titleVector.add("员工职务");
  146. titleVector.add("员工状态");
  147. titleVector.add("详细记录");
  148. //studentTableModel = new DefaultTableModel(tableTitle, 15);
  149. PersonnelRecordJTable = new JTable(PersonnelVector, titleVector);
  150. PersonnelRecordJTable.setPreferredScrollableViewportSize(new Dimension(660,240));
  151. PersonnelRecordJScrollPane = new JScrollPane(PersonnelRecordJTable);
  152. //分别设置水平和垂直滚动条自动出现
  153. PersonnelRecordJScrollPane.setHorizontalScrollBarPolicy(
  154. JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  155. PersonnelRecordJScrollPane.setVerticalScrollBarPolicy(
  156. JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
  157. //为表格添加监听器
  158. PersonnelRecordJTable.addMouseListener(new MouseAdapter()
  159. {
  160. public void mouseClicked(MouseEvent e)
  161. {
  162. int row = ((JTable) e.getSource()).rowAtPoint(e.getPoint()); // 获得行位置
  163. System.out.println("mouseClicked(). row = " + row);
  164. }
  165. });
  166. jP1 = new JPanel();
  167. jP2 = new JPanel();
  168. jP3 = new JPanel();
  169. jP4 = new JPanel();
  170. jP5 = new JPanel();
  171. jP6 = new JPanel();
  172. jP7 = new JPanel();
  173. jP8 = new JPanel();
  174. jP9 = new JPanel();
  175. jP10 = new JPanel();
  176. jPTop = new JPanel();
  177. jPBottom = new JPanel();
  178. jP1.add(jLPersonnelRecord,BorderLayout.NORTH);
  179. jP2.add(PersonnelRecordJScrollPane);
  180. jP10.add(jLText2);
  181. jP10.setLayout(new FlowLayout(FlowLayout.CENTER));
  182. jP10.setPreferredSize(new Dimension(20,20));
  183. jP3.add(jLSelectQueryField);
  184. jP3.add(jCBSelectQueryField);
  185. jP3.add(jLEqual1);
  186. jP3.add(jTFQueryField);
  187. jP3.add(jBQuery);
  188. jP3.add(jBQueryAll);
  189. jP3.setLayout(new FlowLayout(FlowLayout.CENTER));
  190. jP3.setPreferredSize(new Dimension(20,20));
  191. jP4.add(jLChangeID);
  192. jP4.add(jTFChangeID);
  193. jP4.setLayout(new FlowLayout(FlowLayout.CENTER));
  194. jP4.setPreferredSize(new Dimension(20,20));
  195. jP5.add(jLsID);
  196. jP5.add(jTFsID);
  197. jP5.setLayout(new FlowLayout(FlowLayout.CENTER));
  198. jP5.setPreferredSize(new Dimension(20,20));
  199. jP6.add(jLSelectChangeCode);
  200. jP6.add(jCBChangeCode);
  201. jP6.add(jLAfter);
  202. jP6.add(jCBJob);
  203. jP6.setLayout(new FlowLayout(FlowLayout.CENTER));
  204. jP6.setPreferredSize(new Dimension(20,20));
  205. jP7.add(jLChangeDescription);
  206. jP7.add(jTFChangeDescription);
  207. jP7.setLayout(new FlowLayout(FlowLayout.CENTER));
  208. jP7.setPreferredSize(new Dimension(20,20));
  209. jP8.add(jBChange);
  210. jP8.setLayout(new FlowLayout(FlowLayout.CENTER));
  211. jP8.setPreferredSize(new Dimension(20,20));
  212. jP9.add(jLText1);
  213. //jP9.add(jLText2);
  214. jP9.setLayout(new FlowLayout(FlowLayout.CENTER));
  215. jP9.setPreferredSize(new Dimension(20,20));
  216. jPTop.add(jP1);
  217. jPTop.add(jP2);
  218. jPBottom.setLayout(new GridLayout(8, 1));
  219. jPBottom.add(jP10);
  220. jPBottom.add(jP3);
  221. jPBottom.add(jP4);
  222. jPBottom.add(jP5);
  223. jPBottom.add(jP6);
  224. jPBottom.add(jP7);
  225. jPBottom.add(jP8);
  226. jPBottom.add(jP9);
  227. this.add("North", jPTop);
  228. this.add("South", jPBottom);
  229. this.setLayout(new GridLayout(2, 1));
  230. this.setTitle("人事变更");
  231. this.setSize(700, 700);
  232. this.setLocation(300, 10);
  233. this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  234. this.setVisible(false);
  235. this.setResizable(false);
  236. PdbProcess = new DbProcess();
  237. }
  238. @Override
  239. public void actionPerformed(ActionEvent e) {
  240. if(e.getActionCommand().equals("查询")
  241. && !jTFQueryField.getText().isEmpty()){
  242. System.out.println("actionPerformed(). 查询");
  243. String sQueryField = jTFQueryField.getText().trim();
  244. queryProcess(sQueryField);
  245. jTFQueryField.setText("");
  246. }else if(e.getActionCommand().equals("查询所有记录")) {
  247. System.out.println("actionPerformed(). 查询所有记录");
  248. queryAllProcess();
  249. }else if(e.getActionCommand().equals("变更")
  250. && !jTFsID.getText().isEmpty()
  251. && !jTFChangeDescription.getText().isEmpty()){
  252. int sid=10001;
  253. try{
  254. String sql ="select max(sID) from staff;";
  255. PdbProcess.connect();
  256. ResultSet rs = PdbProcess.executeQuery(sql);
  257. if(rs.next()){
  258. if(sid<=rs.getInt(1))
  259. sid=rs.getInt(1);
  260. System.out.println("sid"+sid);
  261. }
  262. PdbProcess.disconnect();
  263. }catch(SQLException sqle){
  264. System.out.println("sqle = " + sqle);
  265. JOptionPane.showMessageDialog(null,
  266. "空集合","错误",JOptionPane.ERROR_MESSAGE);
  267. }finally {
  268. if(sid<Integer.parseInt(jTFsID.getText().trim())||10000>=Integer.parseInt(jTFsID.getText().trim())){
  269. JOptionPane.showMessageDialog(null,
  270. "员工工号不存在","错误",JOptionPane.ERROR_MESSAGE);
  271. }else{
  272. int pid=100000;
  273. try{
  274. String sql ="select max(pID) from personnel;";
  275. PdbProcess.connect();
  276. ResultSet rs = PdbProcess.executeQuery(sql);
  277. if(rs.next()){
  278. if(pid<=rs.getInt(1)){
  279. pid=rs.getInt(1);
  280. }
  281. System.out.println("pid"+pid);
  282. }
  283. PdbProcess.disconnect();
  284. }catch(SQLException sqle){
  285. System.out.println("sqle = " + sqle);
  286. JOptionPane.showMessageDialog(null,
  287. "空集合","错误",JOptionPane.ERROR_MESSAGE);
  288. }finally {
  289. try{
  290. String sql ="select sState from staff where sID = '"+jTFsID.getText().trim()+"';";
  291. PdbProcess.connect();
  292. ResultSet rs = PdbProcess.executeQuery(sql);
  293. rs.next();
  294. if(rs.getString("sState").equals("T")){
  295. if(SelectChangeCodeStr.equals("1-职务变动")){
  296. System.out.println("actionPerformed(). 职务变动");
  297. ChangeProcess(0);
  298. pid++;
  299. System.out.println("pid="+pid);
  300. jTFChangeID.setText(String.valueOf(pid+1));
  301. jTFsID.setText("");
  302. jTFChangeDescription.setText("");
  303. }
  304. if(SelectChangeCodeStr.equals("2-辞退")){
  305. System.out.println("actionPerformed(). 辞退");
  306. ChangeProcess(1);
  307. pid++;
  308. System.out.println("pid="+pid);
  309. jTFChangeID.setText(String.valueOf(pid+1));
  310. jTFsID.setText("");
  311. jTFChangeDescription.setText("");
  312. }
  313. }else{
  314. JOptionPane.showMessageDialog(null,
  315. "该员工已被辞退,无法变更!","错误",JOptionPane.ERROR_MESSAGE);
  316. }
  317. PdbProcess.disconnect();
  318. }catch(SQLException sqle){
  319. JOptionPane.showMessageDialog(null,
  320. "该员工已被辞退,无法变更!","错误",JOptionPane.ERROR_MESSAGE);
  321. }
  322. }
  323. }
  324. }
  325. }
  326. }
  327. public void queryProcess(String sQueryField)
  328. {
  329. try{
  330. // 建立查询条件
  331. String sql = "select pID,pChange,personnel.sID,sName,sJob,sState,pDescription from personnel,staff where ";
  332. String queryFieldStr = jCBSelectQueryFieldTransfer(SelectQueryFieldStr);
  333. sql = sql + queryFieldStr;
  334. sql = sql + " = ";
  335. sql = sql + "'" + sQueryField + "'";
  336. sql = sql + "and personnel.sID = staff.sID ;";
  337. System.out.println("queryProcess(). sql = " + sql);
  338. PdbProcess.connect();
  339. ResultSet rs = PdbProcess.executeQuery(sql);
  340. // 将查询获得的记录数据,转换成适合生成JTable的数据形式
  341. PersonnelVector.clear();
  342. while(rs.next()){
  343. Vector v = new Vector();
  344. v.add(rs.getString("pID"));
  345. v.add(rs.getString("pChange"));
  346. v.add(rs.getString("sID"));
  347. v.add(rs.getString("sName"));
  348. v.add(rs.getString("sJob"));
  349. v.add(rs.getString("sState"));
  350. v.add(rs.getString("pDescription"));
  351. PersonnelVector.add(v);
  352. }
  353. PersonnelRecordJTable.updateUI();
  354. PdbProcess.disconnect();
  355. }catch(SQLException sqle){
  356. System.out.println("sqle = " + sqle);
  357. JOptionPane.showMessageDialog(null,
  358. "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);
  359. }catch(Exception e){
  360. System.out.println("e = " + e);
  361. JOptionPane.showMessageDialog(null,
  362. "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);
  363. }
  364. }
  365. public void queryAllProcess()
  366. {
  367. try{
  368. // 建立查询条件
  369. String sql = "select pID,pChange,personnel.sID,sName,sJob,sState,pDescription from personnel,staff where ";
  370. //String queryFieldStr = jCBSelectQueryFieldTransfer(SelectQueryFieldStr);
  371. sql = sql + "personnel.sID = staff.sID order by pID asc;";
  372. System.out.println("queryAllProcess(). sql = " + sql);
  373. PdbProcess.connect();
  374. ResultSet rs = PdbProcess.executeQuery(sql);
  375. // 将查询获得的记录数据,转换成适合生成JTable的数据形式
  376. PersonnelVector.clear();
  377. while(rs.next()){
  378. Vector v = new Vector();
  379. v.add(rs.getString("pID"));
  380. v.add(rs.getString("pChange"));
  381. v.add(rs.getString("sID"));
  382. v.add(rs.getString("sName"));
  383. v.add(rs.getString("sJob"));
  384. v.add(rs.getString("sState"));
  385. v.add(rs.getString("pDescription"));
  386. PersonnelVector.add(v);
  387. }
  388. PersonnelRecordJTable.updateUI();
  389. PdbProcess.disconnect();
  390. }catch(SQLException sqle){
  391. System.out.println("sqle = " + sqle);
  392. JOptionPane.showMessageDialog(null,
  393. "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);
  394. }
  395. }
  396. public void ChangeProcess(int code)
  397. {
  398. String pID = jTFChangeID.getText().trim();
  399. String sID = jTFsID.getText().trim();
  400. String pChange="";
  401. String sJob="";
  402. String pDescription = jTFChangeDescription.getText().trim();
  403. if(jCBJobStr.equals("0-员工")){
  404. sJob="员工";
  405. }else if(jCBJobStr.equals("1-组长")){
  406. sJob="组长";
  407. }else if(jCBJobStr.equals("2-主任")){
  408. sJob="主任";
  409. }else if(jCBJobStr.equals("3-经理")){
  410. sJob="经理";
  411. }
  412. String sql="";
  413. if(code==0){
  414. pChange="1";
  415. sql = "update staff set sJob = '";
  416. sql = sql + sJob+"'";
  417. sql = sql + " WHERE sID = '"+sID+"';";
  418. }
  419. if(code==1){
  420. pChange="2";
  421. sql = "update staff set sState = 'F' WHERE sID = '"+sID+"';";
  422. }
  423. try{
  424. if (PdbProcess.executeUpdate(sql) < 1) {
  425. System.out.println("insertProcess(). update database failed.");
  426. }
  427. }catch(Exception e){
  428. System.out.println("e = " + e);
  429. JOptionPane.showMessageDialog(null,
  430. "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);
  431. }finally {
  432. // 建立插入条件
  433. sql = "insert into personnel values('";
  434. sql = sql + pID + "','";
  435. sql = sql + sID + "','";
  436. sql = sql + pChange + "','";
  437. sql = sql + pDescription + "');";
  438. System.out.println("insertProcess(). sql = " + sql);
  439. try{
  440. if (PdbProcess.executeUpdate(sql) < 1) {
  441. System.out.println("insertProcess(). insert database failed.");
  442. }else{
  443. JOptionPane.showMessageDialog(null,
  444. "变更成功!","提示",JOptionPane.INFORMATION_MESSAGE);
  445. }
  446. }catch(Exception e){
  447. System.out.println("e = " + e);
  448. JOptionPane.showMessageDialog(null,
  449. "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);
  450. }
  451. queryAllProcess();
  452. }
  453. }
  454. public String jCBSelectQueryFieldTransfer(String InputStr)
  455. {
  456. String outputStr = "";
  457. System.out.println("jCBSelectQueryFieldTransfer(). InputStr = " + InputStr);
  458. if(InputStr.equals("记录编号")){
  459. outputStr = "pID";
  460. }else if(InputStr.equals("员工工号")){
  461. outputStr = "personnel.sID";
  462. }else if(InputStr.equals("变更代码")){
  463. outputStr = "pChange";
  464. }
  465. System.out.println("jCBSelectQueryFieldTransfer(). outputStr = " + outputStr);
  466. return outputStr;
  467. }
  468. }

4.7 管理员员工档案查询修改模块

  1. import javax.swing.*;
  2. import javax.swing.table.DefaultTableModel;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.util.Vector;
  8. class DatabaseCourseDesign extends JFrame implements ActionListener {
  9. // 定义组件
  10. JLabel jLStaff = null;//员工信息表
  11. JLabel jLText = null;//注释
  12. JLabel jLSelectQueryField = null;//选择查询字段
  13. JLabel jLEqual = null;//=
  14. JLabel jLsID = null;//工号
  15. //JLabel jLsPassword = null;//密码
  16. JLabel jLsAuthority = null;//权限
  17. JLabel jLsName = null;//姓名
  18. JLabel jLsSex = null;//性别
  19. JLabel jLsBirthday = null;//生日
  20. JLabel jLsDepartment = null;//部门
  21. JLabel jLsJob = null;//职务
  22. JLabel jLsEdu_Level = null;//教育水平
  23. JLabel jLsSpecialty = null;//专业技能
  24. JLabel jLsAddress = null;//住址
  25. JLabel jLsTel = null;//电话
  26. JLabel jLsEmail = null;//邮箱
  27. JLabel jLsState = null;//状态
  28. JLabel jLsRemark = null;//备注
  29. JTextField jTFQueryField = null;//查询字段
  30. JTextField jTFsID = null;//工号
  31. //JTextField jTFsPassword = null;//密码
  32. JTextField jTFsJob =null;//职务
  33. JTextField jTFsName = null;//姓名
  34. JTextField jTFsSex = null;//性别
  35. JTextField jTFsBirthday = null;//生日
  36. JTextField jTFsSpecialty = null;//专业技能
  37. JTextField jTFsAddress = null;//住址
  38. JTextField jTFsTel = null;//电话
  39. JTextField jTFsEmail = null;//邮箱
  40. JTextField jTFsState = null;//状态
  41. JTextField jTFsRemark = null;//备注
  42. JButton jBQuery = null;//查询
  43. JButton jBQueryAll = null;//查询所有记录
  44. JButton jBUpdate = null;//更新
  45. JButton jBReset = null;//重置密码
  46. JComboBox<String> jCBSelectQueryField = null;//查询字段
  47. JComboBox<String> jCBAuthority = null;//权限
  48. JComboBox<String> jCBDepartment = null;//部门
  49. //JComboBox<String> jCBJob = null;//职务
  50. JComboBox<String> jCBEdu_Level = null;//教育水平
  51. JPanel jP1, jP2,jP3,jP4,jP5,jP6,jP7 = null;
  52. JPanel jPTop, jPBottom = null;
  53. DefaultTableModel studentTableModel = null;
  54. JTable staffJTable = null;
  55. JScrollPane staffJScrollPane = null;
  56. Vector staffVector = null;
  57. Vector titleVector = null;
  58. private static DbProcess dbProcess;
  59. private static Md5 md5;
  60. String SelectQueryFieldStr = "工号";
  61. String jCBAuthorityStr="普通员工";
  62. String jCBDepartmentStr="0-生产部";
  63. String jCBJobStr="0-员工";
  64. String jCBEdu_LevelStr="0-小学";
  65. // 构造函数
  66. public DatabaseCourseDesign() {
  67. this.md5 = new Md5();
  68. // 创建标签组件
  69. jLStaff = new JLabel("员工信息表");
  70. jLText = new JLabel("注意:带*的为必填项 ");
  71. jLText.setFont(new Font("宋体",Font.BOLD,15));
  72. jLText.setForeground(Color.red);
  73. jLSelectQueryField = new JLabel("选择查询字段");
  74. jLEqual = new JLabel(" = ");
  75. jLsID = new JLabel("工号*");
  76. //jLsPassword = new JLabel("密码*");
  77. jLsAuthority = new JLabel("权限*");
  78. jLsName = new JLabel("姓名*");
  79. jLsSex = new JLabel("性别*");
  80. jLsBirthday = new JLabel("生日*");
  81. jLsDepartment = new JLabel("部门*");
  82. jLsJob = new JLabel("职务*");
  83. jLsEdu_Level = new JLabel("教育水平*");
  84. jLsSpecialty = new JLabel("专业技能*");
  85. jLsAddress = new JLabel("住址*");
  86. jLsTel = new JLabel("电话*");
  87. jLsEmail = new JLabel("邮箱*");
  88. jLsState = new JLabel("状态*");
  89. jLsRemark = new JLabel("备注");
  90. jTFQueryField = new JTextField(15);//查询字段
  91. jTFsID = new JTextField(15);//工号
  92. jTFsID.setEditable(false);
  93. //jTFsPassword = new JTextField(15);//密码
  94. jTFsJob = new JTextField(15);//职务
  95. jTFsJob.setEditable(false);
  96. jTFsName = new JTextField(15);//姓名
  97. jTFsSex = new JTextField(15);//性别
  98. jTFsBirthday = new JTextField(15);//生日
  99. jTFsSpecialty = new JTextField(15);//专业技能
  100. jTFsAddress = new JTextField(15);//住址
  101. jTFsTel = new JTextField(15);//电话
  102. jTFsEmail = new JTextField(15);//邮箱
  103. jTFsState = new JTextField(15);//状态
  104. jTFsState.setEditable(false);
  105. jTFsRemark = new JTextField(15);//备注
  106. jBQuery = new JButton("查询");
  107. jBQueryAll = new JButton("查询所有记录");
  108. jBUpdate = new JButton("更新员工信息");
  109. jBUpdate.setFont(new Font("宋体",Font.BOLD,20));
  110. jBReset = new JButton("重置用户密码");
  111. jBReset.setFont(new Font("宋体",Font.BOLD,20));
  112. //jBBack = new JButton("返回");
  113. //jBDeleteCurrentRecord = new JButton("删除当前记录");
  114. //jBDeleteAllRecords = new JButton("删除所有记录");
  115. // 设置监听
  116. jBQuery.addActionListener(this);
  117. jBQueryAll.addActionListener(this);
  118. jBUpdate.addActionListener(this);
  119. jBReset.addActionListener(this);
  120. //jBDeleteCurrentRecord.addActionListener(this);
  121. //jBDeleteAllRecords.addActionListener(this);
  122. jCBSelectQueryField = new JComboBox<String>();//查询字段
  123. jCBSelectQueryField.addItem("工号");//添加选项
  124. jCBSelectQueryField.addItem("权限");
  125. jCBSelectQueryField.addItem("姓名");
  126. jCBSelectQueryField.addItem("性别");
  127. jCBSelectQueryField.addItem("生日");
  128. jCBSelectQueryField.addItem("部门");
  129. jCBSelectQueryField.addItem("职务");
  130. jCBSelectQueryField.addItem("教育水平");
  131. jCBSelectQueryField.addItem("专业技能");
  132. jCBSelectQueryField.addItem("状态");
  133. jCBAuthority = new JComboBox<String>();//权限
  134. //jCBAuthority.set
  135. jCBAuthority.addItem("普通员工");//添加选项
  136. jCBAuthority.addItem("管理员");
  137. jCBDepartment = new JComboBox<String>();//部门
  138. jCBDepartment.addItem("0-生产部");
  139. jCBDepartment.addItem("1-运营部");
  140. jCBDepartment.addItem("2-行政部");
  141. jCBDepartment.addItem("3-人事部");
  142. /*jCBJob = new JComboBox<String>();//职务
  143. jCBJob.addItem("员工");
  144. jCBJob.addItem("组长");
  145. jCBJob.addItem("主任");
  146. jCBJob.addItem("经理");*/
  147. jCBEdu_Level = new JComboBox<String>();//教育水平
  148. jCBEdu_Level.addItem("0-小学");
  149. jCBEdu_Level.addItem("1-初中");
  150. jCBEdu_Level.addItem("2-高中");
  151. jCBEdu_Level.addItem("3-职高");
  152. jCBEdu_Level.addItem("4-大本");
  153. jCBEdu_Level.addItem("5-大专");
  154. jCBEdu_Level.addItem("6-硕士");
  155. jCBEdu_Level.addItem("7-博士");
  156. jCBEdu_Level.addItem("8-博士后");
  157. jCBSelectQueryField.addItemListener(new ItemListener() {//下拉框事件监听
  158. public void itemStateChanged(ItemEvent event) {
  159. switch (event.getStateChange()) {
  160. case ItemEvent.SELECTED:
  161. SelectQueryFieldStr = (String) event.getItem();
  162. System.out.println("选中:" + SelectQueryFieldStr);
  163. break;
  164. case ItemEvent.DESELECTED:
  165. System.out.println("取消选中:" + event.getItem());
  166. break;
  167. }
  168. }
  169. });
  170. jCBAuthority.addItemListener(new ItemListener() {//查询下拉框事件监听
  171. public void itemStateChanged(ItemEvent event) {
  172. switch (event.getStateChange()) {
  173. case ItemEvent.SELECTED:
  174. jCBAuthorityStr = (String) event.getItem();
  175. System.out.println("选中:" + jCBAuthorityStr);
  176. break;
  177. case ItemEvent.DESELECTED:
  178. System.out.println("取消选中:" + event.getItem());
  179. break;
  180. }
  181. }
  182. });
  183. jCBDepartment.addItemListener(new ItemListener() {//查询下拉框事件监听
  184. public void itemStateChanged(ItemEvent event) {
  185. switch (event.getStateChange()) {
  186. case ItemEvent.SELECTED:
  187. jCBDepartmentStr = (String) event.getItem();
  188. System.out.println("选中:" + jCBDepartmentStr);
  189. break;
  190. case ItemEvent.DESELECTED:
  191. System.out.println("取消选中:" + event.getItem());
  192. break;
  193. }
  194. }
  195. });
  196. /*jCBJob.addItemListener(new ItemListener() {//查询下拉框事件监听
  197. public void itemStateChanged(ItemEvent event) {
  198. switch (event.getStateChange()) {
  199. case ItemEvent.SELECTED:
  200. jCBJobStr = (String) event.getItem();
  201. System.out.println("选中:" + jCBJobStr);
  202. break;
  203. case ItemEvent.DESELECTED:
  204. System.out.println("取消选中:" + event.getItem());
  205. break;
  206. }
  207. }
  208. });*/
  209. jCBEdu_Level.addItemListener(new ItemListener() {//查询下拉框事件监听
  210. public void itemStateChanged(ItemEvent event) {
  211. switch (event.getStateChange()) {
  212. case ItemEvent.SELECTED:
  213. jCBEdu_LevelStr = (String) event.getItem();
  214. System.out.println("选中:" + jCBEdu_LevelStr);
  215. break;
  216. case ItemEvent.DESELECTED:
  217. System.out.println("取消选中:" + event.getItem());
  218. break;
  219. }
  220. }
  221. });
  222. staffVector = new Vector();
  223. titleVector = new Vector();
  224. // 定义表头
  225. titleVector.add("工号");
  226. //titleVector.add("密码");
  227. titleVector.add("权限");
  228. titleVector.add("姓名");
  229. titleVector.add("性别");
  230. titleVector.add("生日");
  231. titleVector.add("部门");
  232. titleVector.add("职务");
  233. titleVector.add("教育水平");
  234. titleVector.add("专业技能");
  235. titleVector.add("住址");
  236. titleVector.add("电话");
  237. titleVector.add("邮箱");
  238. titleVector.add("状态");
  239. titleVector.add("备注");
  240. //studentTableModel = new DefaultTableModel(tableTitle, 15);
  241. staffJTable = new JTable(staffVector, titleVector);
  242. staffJTable.setPreferredScrollableViewportSize(new Dimension(910,220));
  243. staffJScrollPane = new JScrollPane(staffJTable);
  244. //分别设置水平和垂直滚动条自动出现
  245. staffJScrollPane.setHorizontalScrollBarPolicy(
  246. JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  247. staffJScrollPane.setVerticalScrollBarPolicy(
  248. JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
  249. //为表格添加监听器
  250. staffJTable.addMouseListener(new MouseAdapter()
  251. {
  252. public void mouseClicked(MouseEvent e)
  253. {
  254. int row = ((JTable) e.getSource()).rowAtPoint(e.getPoint()); // 获得行位置
  255. System.out.println("mouseClicked(). row = " + row);
  256. Vector v = new Vector();
  257. v = (Vector) staffVector.get(row);
  258. jTFsID.setText((String) v.get(0));// 工号
  259. //jTFsPassword.setText((String) v.get(1));// 密码
  260. if(String.valueOf(v.get(1)).equals("普通员工")){
  261. jCBAuthority.setSelectedIndex(0);
  262. }else if (String.valueOf(v.get(1)).equals("管理员")){
  263. jCBAuthority.setSelectedIndex(1);
  264. }
  265. jTFsName.setText((String) v.get(2));// 姓名
  266. jTFsSex.setText((String) v.get(3));// 性别
  267. jTFsBirthday.setText((String) v.get(4));// 生日
  268. //jCBDepartmentStr=((String) v.get(6));// 部门
  269. if(String.valueOf(v.get(5)).equals("生产部")){
  270. jCBDepartment.setSelectedIndex(0);
  271. }else if (String.valueOf(v.get(5)).equals("运营部")){
  272. jCBDepartment.setSelectedIndex(1);
  273. }else if (String.valueOf(v.get(5)).equals("行政部")){
  274. jCBDepartment.setSelectedIndex(2);
  275. }else if (String.valueOf(v.get(5)).equals("人事部")){
  276. jCBDepartment.setSelectedIndex(3);
  277. }
  278. jTFsJob.setText((String) v.get(6));// 职务
  279. /*if(String.valueOf(v.get(7)).equals("员工")){
  280. jCBJob.setSelectedIndex(0);
  281. }else if (String.valueOf(v.get(7)).equals("组长")){
  282. jCBJob.setSelectedIndex(1);
  283. }else if (String.valueOf(v.get(7)).equals("主任")){
  284. jCBJob.setSelectedIndex(2);
  285. }else if (String.valueOf(v.get(7)).equals("经理")){
  286. jCBJob.setSelectedIndex(3);
  287. }*/
  288. //jTFsEdu_Level.setText((String) v.get(8));// 教育水平
  289. if(String.valueOf(v.get(7)).equals("小学")){
  290. jCBEdu_Level.setSelectedIndex(0);
  291. }else if (String.valueOf(v.get(7)).equals("初中")){
  292. jCBEdu_Level.setSelectedIndex(1);
  293. }else if (String.valueOf(v.get(7)).equals("高中")){
  294. jCBEdu_Level.setSelectedIndex(2);
  295. }else if (String.valueOf(v.get(7)).equals("职高")){
  296. jCBEdu_Level.setSelectedIndex(3);
  297. }else if (String.valueOf(v.get(7)).equals("大本")){
  298. jCBEdu_Level.setSelectedIndex(4);
  299. }else if (String.valueOf(v.get(7)).equals("大专")){
  300. jCBEdu_Level.setSelectedIndex(5);
  301. }else if (String.valueOf(v.get(7)).equals("硕士")){
  302. jCBEdu_Level.setSelectedIndex(6);
  303. }else if (String.valueOf(v.get(7)).equals("博士")){
  304. jCBEdu_Level.setSelectedIndex(7);
  305. }else if (String.valueOf(v.get(7)).equals("博士后")){
  306. jCBEdu_Level.setSelectedIndex(7);
  307. }
  308. jTFsSpecialty.setText((String) v.get(8));// 专业技能
  309. jTFsAddress.setText((String) v.get(9));// 住址
  310. jTFsTel.setText((String) v.get(10));// 电话
  311. jTFsEmail.setText((String) v.get(11));// 邮箱
  312. jTFsState.setText((String) v.get(12));//状态
  313. jTFsRemark.setText((String) v.get(13));// 备注
  314. }
  315. });
  316. jP1 = new JPanel();
  317. jP2 = new JPanel();
  318. jP3 = new JPanel();
  319. jP4 = new JPanel();
  320. jP5 = new JPanel();
  321. jP6 = new JPanel();
  322. jP7 = new JPanel();
  323. jPTop = new JPanel();
  324. jPBottom = new JPanel();
  325. jP1.add(jLStaff,BorderLayout.NORTH);
  326. jP2.add(staffJScrollPane);
  327. jP3.add(jLSelectQueryField);
  328. jP3.add(jCBSelectQueryField);
  329. jP3.add(jLEqual);
  330. jP3.add(jTFQueryField);
  331. jP3.add(jBQuery);
  332. jP3.add(jBQueryAll);
  333. jP3.setLayout(new FlowLayout(FlowLayout.CENTER));
  334. jP3.setPreferredSize(new Dimension(20,20));
  335. jP4.add(jLsID);
  336. jP4.add(jTFsID);
  337. //jP4.add(jLsPassword);
  338. //jP4.add(jTFsPassword);
  339. jP4.add(jLsAuthority);
  340. jP4.add(jCBAuthority);
  341. jP4.add(jLsDepartment);
  342. jP4.add(jCBDepartment);
  343. //jP4.add(jLsJob);
  344. //jP4.add(jCBJob);
  345. jP4.add(jLsEdu_Level);
  346. jP4.add(jCBEdu_Level);
  347. jP4.setLayout(new FlowLayout(FlowLayout.CENTER));
  348. jP4.setPreferredSize(new Dimension(20,20));
  349. jP5.add(jLsName);
  350. jP5.add(jTFsName);
  351. jP5.add(jLsSex);
  352. jP5.add(jTFsSex);
  353. jP5.add(jLsJob);
  354. jP5.add(jTFsJob);
  355. jP5.add(jLsBirthday);
  356. jP5.add(jTFsBirthday);
  357. jP5.add(jLsSpecialty);
  358. jP5.add(jTFsSpecialty);
  359. jP5.setLayout(new FlowLayout(FlowLayout.CENTER));
  360. jP5.setPreferredSize(new Dimension(20,20));
  361. jP6.add(jLsAddress);
  362. jP6.add(jTFsAddress);
  363. jP6.add(jLsTel);
  364. jP6.add(jTFsTel);
  365. jP6.add(jLsEmail);
  366. jP6.add(jTFsEmail);
  367. jP6.add(jLsState);
  368. jP6.add(jTFsState);
  369. jP6.add(jLsRemark);
  370. jP6.add(jTFsRemark);
  371. jP6.setLayout(new FlowLayout(FlowLayout.CENTER));
  372. jP6.setPreferredSize(new Dimension(20,20));
  373. jP7.add(jLText);
  374. jP7.add(jBUpdate);
  375. jP7.add(jBReset);
  376. jP7.setLayout(new FlowLayout(FlowLayout.CENTER));
  377. jP7.setPreferredSize(new Dimension(20,20));
  378. jPTop.add(jP1);
  379. jPTop.add(jP2);
  380. jPBottom.setLayout(new GridLayout(5, 1));
  381. jPBottom.add(jP3);
  382. jPBottom.add(jP4);
  383. jPBottom.add(jP5);
  384. jPBottom.add(jP6);
  385. jPBottom.add(jP7);
  386. this.add("North", jPTop);
  387. this.add("South", jPBottom);
  388. this.setLayout(new GridLayout(2, 1));
  389. this.setTitle("员工档案查询修改");
  390. this.setSize(970, 650);
  391. this.setLocation(200, 10);
  392. this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  393. this.setVisible(true);
  394. this.setResizable(false);
  395. dbProcess = new DbProcess();
  396. }
  397. @Override
  398. public void actionPerformed(ActionEvent e) {
  399. if(e.getActionCommand().equals("查询")
  400. && !jTFQueryField.getText().isEmpty()){
  401. System.out.println("actionPerformed(). 查询");
  402. String sQueryField = jTFQueryField.getText().trim();
  403. jTFsID.setText("");
  404. //jTFsPassword.setText("");
  405. //jTFsAuthority.setText("");
  406. jTFsName.setText("");
  407. jTFsSex.setText("");
  408. jTFsBirthday.setText("");
  409. //jTFsDepartment.setText("");
  410. //jTFsJob.setText("");
  411. //jTFsEdu_Level.setText("");
  412. jTFsSpecialty.setText("");
  413. jTFsAddress.setText("");
  414. jTFsTel.setText("");
  415. jTFsEmail.setText("");
  416. jTFsState.setText("");
  417. jTFsRemark.setText("");
  418. queryProcess(sQueryField);
  419. jTFQueryField.setText("");
  420. }else if(e.getActionCommand().equals("查询所有记录")) {
  421. System.out.println("actionPerformed(). 查询所有记录");
  422. queryAllProcess();
  423. } else if(e.getActionCommand().equals("重置用户密码")
  424. && !jTFsID.getText().isEmpty()
  425. && !jTFsName.getText().isEmpty()
  426. && !jTFsSex.getText().isEmpty()
  427. && !jTFsJob.getText().isEmpty()
  428. && !jTFsBirthday.getText().isEmpty()
  429. && !jTFsSpecialty.getText().isEmpty()
  430. && !jTFsAddress.getText().isEmpty()
  431. && !jTFsTel.getText().isEmpty()
  432. && !jTFsEmail.getText().isEmpty()
  433. && !jTFsState.getText().isEmpty()){
  434. System.out.println("actionPerformed(). 重置用户密码");
  435. ResetProcess();
  436. }else if(e.getActionCommand().equals("更新员工信息")
  437. && !jTFsID.getText().isEmpty()
  438. && !jTFsName.getText().isEmpty()
  439. && !jTFsSex.getText().isEmpty()
  440. && !jTFsJob.getText().isEmpty()
  441. && !jTFsBirthday.getText().isEmpty()
  442. && !jTFsSpecialty.getText().isEmpty()
  443. && !jTFsAddress.getText().isEmpty()
  444. && !jTFsTel.getText().isEmpty()
  445. && !jTFsEmail.getText().isEmpty()
  446. && !jTFsState.getText().isEmpty()){
  447. try{
  448. String sql ="select sState from staff where sID = '"+jTFsID.getText().trim()+"';";
  449. dbProcess.connect();
  450. ResultSet rs = dbProcess.executeQuery(sql);
  451. rs.next();
  452. if(rs.getString("sState").equals("T")){
  453. System.out.println("actionPerformed(). 更新");
  454. updateProcess();
  455. }else {
  456. JOptionPane.showMessageDialog(null,
  457. "该员工已被辞退,无法更新!","错误",JOptionPane.ERROR_MESSAGE);
  458. }
  459. dbProcess.disconnect();
  460. }catch(SQLException sqle){
  461. System.out.println("sqle = " + sqle);
  462. JOptionPane.showMessageDialog(null,
  463. "该员工已被辞退,无法更新!","错误",JOptionPane.ERROR_MESSAGE);
  464. }
  465. }/*else if(e.getActionCommand().equals(" 返回 ")){
  466. System.out.println("actionPerformed(). 返回");
  467. }*//*else if(e.getActionCommand().equals("删除所有记录")){
  468. System.out.println("actionPerformed(). 删除所有记录");
  469. deleteAllRecordsProcess();
  470. }*/
  471. }
  472. public static void main(String[] args) {
  473. // TODO Auto-generated method stub
  474. Login L = new Login();
  475. //Manage M = new Manage();
  476. //NewEmployee N = new NewEmployee();
  477. //Employee N = new Employee();
  478. //PersonnelChange P = new PersonnelChange();
  479. //DatabaseCourseDesign getcon = new DatabaseCourseDesign();
  480. }
  481. public void queryProcess(String sQueryField)
  482. {
  483. try{
  484. // 建立查询条件
  485. String sql = "select * from staff where ";
  486. String queryFieldStr = jCBSelectQueryFieldTransfer(SelectQueryFieldStr);
  487. /*if(queryFieldStr.equals("sAge")){//int sAge.
  488. sql = sql + queryFieldStr;
  489. sql = sql + " = " + sQueryField;
  490. }else{*/
  491. sql = sql + queryFieldStr;
  492. sql = sql + " = ";
  493. sql = sql + "'" + sQueryField + "';";
  494. //}
  495. System.out.println("queryProcess(). sql = " + sql);
  496. dbProcess.connect();
  497. ResultSet rs = dbProcess.executeQuery(sql);
  498. // 将查询获得的记录数据,转换成适合生成JTable的数据形式
  499. staffVector.clear();
  500. while(rs.next()){
  501. Vector v = new Vector();
  502. v.add(rs.getString("sID"));
  503. //v.add(rs.getString("sPassword"));
  504. v.add(rs.getString("sAuthority"));
  505. v.add(rs.getString("sName"));
  506. v.add(rs.getString("sSex"));
  507. v.add(rs.getString("sBirthday"));
  508. v.add(rs.getString("sDepartment"));
  509. v.add(rs.getString("sJob"));
  510. v.add(rs.getString("sEdu_Level"));
  511. v.add(rs.getString("sSpecialty"));
  512. v.add(rs.getString("sAddress"));
  513. v.add(rs.getString("sTel"));
  514. v.add(rs.getString("sEmail"));
  515. v.add(rs.getString("sState"));
  516. v.add(rs.getString("sRemark"));
  517. staffVector.add(v);
  518. }
  519. staffJTable.updateUI();
  520. dbProcess.disconnect();
  521. }catch(SQLException sqle){
  522. System.out.println("sqle = " + sqle);
  523. JOptionPane.showMessageDialog(null,
  524. "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);
  525. }catch(Exception e){
  526. System.out.println("e = " + e);
  527. JOptionPane.showMessageDialog(null,
  528. "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);
  529. }
  530. }
  531. public void queryAllProcess()
  532. {
  533. try{
  534. // 建立查询条件
  535. String sql = "select * from staff;";
  536. System.out.println("queryAllProcess(). sql = " + sql);
  537. dbProcess.connect();
  538. ResultSet rs = dbProcess.executeQuery(sql);
  539. // 将查询获得的记录数据,转换成适合生成JTable的数据形式
  540. staffVector.clear();
  541. while(rs.next()){
  542. Vector v = new Vector();
  543. v.add(rs.getString("sID"));
  544. //v.add(rs.getString("sPassword"));
  545. v.add(rs.getString("sAuthority"));
  546. v.add(rs.getString("sName"));
  547. v.add(rs.getString("sSex"));
  548. v.add(rs.getString("sBirthday"));
  549. v.add(rs.getString("sDepartment"));
  550. v.add(rs.getString("sJob"));
  551. v.add(rs.getString("sEdu_Level"));
  552. v.add(rs.getString("sSpecialty"));
  553. v.add(rs.getString("sAddress"));
  554. v.add(rs.getString("sTel"));
  555. v.add(rs.getString("sEmail"));
  556. v.add(rs.getString("sState"));
  557. v.add(rs.getString("sRemark"));
  558. staffVector.add(v);
  559. }
  560. staffJTable.updateUI();
  561. dbProcess.disconnect();
  562. }catch(SQLException sqle){
  563. System.out.println("sqle = " + sqle);
  564. JOptionPane.showMessageDialog(null,
  565. "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);
  566. }
  567. }
  568. public void updateProcess()
  569. {
  570. String sID = jTFsID.getText().trim();
  571. //String sPassword = jTFsPassword.getText().trim();
  572. String sAuthority = jCBAuthorityStr;
  573. String sName = jTFsName.getText().trim();
  574. String sSex = jTFsSex.getText().trim();
  575. String sBirthday = jTFsBirthday.getText().trim();
  576. String sDepartment = "";
  577. String sJob = jTFsJob.getText().trim();
  578. String sEdu_Level = "";
  579. String sSpecialty = jTFsSpecialty.getText().trim();
  580. String sAddress = jTFsAddress.getText().trim();
  581. String sTel = jTFsTel.getText().trim();
  582. String sEmail = jTFsEmail.getText().trim();
  583. String sState = jTFsState.getText().trim();
  584. String sRemark = jTFsRemark.getText().trim();
  585. if(jCBDepartmentStr.equals("0-生产部")){
  586. sDepartment="生产部";
  587. }else if(jCBDepartmentStr.equals("1-运营部")){
  588. sDepartment="运营部";
  589. }
  590. else if(jCBDepartmentStr.equals("2-行政部")){
  591. sDepartment="行政部";
  592. }
  593. else if(jCBDepartmentStr.equals("3-人事部")){
  594. sDepartment="人事部";
  595. }
  596. /*
  597. if(jCBJobStr.equals("0-员工")){
  598. sJob="员工";
  599. }else if(jCBJobStr.equals("1-组长")){
  600. sJob="组长";
  601. }else if(jCBJobStr.equals("2-主任")){
  602. sJob="主任";
  603. }else if(jCBJobStr.equals("3-经理")){
  604. sJob="经理";
  605. }*/
  606. if(jCBEdu_LevelStr.equals("0-小学")){
  607. sEdu_Level="小学";
  608. }else if(jCBEdu_LevelStr.equals("1-初中")){
  609. sEdu_Level="初中";
  610. }else if(jCBEdu_LevelStr.equals("2-高中")){
  611. sEdu_Level="高中";
  612. }else if(jCBEdu_LevelStr.equals("3-职高")){
  613. sEdu_Level="职高";
  614. }else if(jCBEdu_LevelStr.equals("4-大本")){
  615. sEdu_Level="大本";
  616. }else if(jCBEdu_LevelStr.equals("5-大专")){
  617. sEdu_Level="大专";
  618. }else if(jCBEdu_LevelStr.equals("6-硕士")){
  619. sEdu_Level="硕士";
  620. }else if(jCBEdu_LevelStr.equals("7-博士")){
  621. sEdu_Level="博士";
  622. }else if(jCBEdu_LevelStr.equals("8-博士后")){
  623. sEdu_Level="博士后";
  624. }
  625. // 建立更新条件
  626. String sql = "update staff set sAuthority = '";
  627. //sql = sql + sPassword + "', sAuthority = '";
  628. sql = sql + sAuthority + "', sName = '";
  629. sql = sql + sName + "', sSex = '";
  630. sql = sql + sSex + "', sBirthday = '";
  631. sql = sql + sBirthday + "', sDepartment = '";
  632. sql = sql + sDepartment + "', sJob = '";
  633. sql = sql + sJob + "', sEdu_Level = '";
  634. sql = sql + sEdu_Level + "', sSpecialty = '";
  635. sql = sql + sSpecialty + "', sAddress = '";
  636. sql = sql + sAddress + "', sTel = '";
  637. sql = sql + sTel + "', sEmail = '";
  638. sql = sql + sEmail + "', sState = '";
  639. sql = sql + sState + "', sRemark = '";
  640. sql = sql + sRemark + "'";
  641. sql = sql + " WHERE sID = '" + sID + "';";
  642. System.out.println("updateProcess(). sql = " + sql);
  643. try{
  644. if (dbProcess.executeUpdate(sql) < 1) {
  645. System.out.println("updateProcess(). update database failed.");
  646. }else{
  647. JOptionPane.showMessageDialog(null,
  648. "更新成功","提示",JOptionPane.INFORMATION_MESSAGE);
  649. }
  650. }catch(Exception e){
  651. System.out.println("e = " + e);
  652. JOptionPane.showMessageDialog(null,
  653. "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);
  654. }
  655. queryAllProcess();
  656. }
  657. public void ResetProcess(){
  658. String sPassword=this.md5.md5(jTFsID.getText().trim());
  659. String sql = "update staff set sPassword = '";
  660. sql = sql + sPassword + "'";
  661. sql = sql + " WHERE sID = '" + jTFsID.getText().trim() + "';";
  662. System.out.println("updateProcess(). sql = " + sql);
  663. try{
  664. if (dbProcess.executeUpdate(sql) < 1) {
  665. System.out.println("updateProcess(). Reset database failed.");
  666. }else{
  667. JOptionPane.showMessageDialog(null,
  668. "重置密码成功","提示",JOptionPane.INFORMATION_MESSAGE);
  669. }
  670. }catch(Exception e){
  671. System.out.println("e = " + e);
  672. JOptionPane.showMessageDialog(null,
  673. "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);
  674. }
  675. }
  676. public String jCBSelectQueryFieldTransfer(String InputStr)
  677. {
  678. String outputStr = "";
  679. System.out.println("jCBSelectQueryFieldTransfer(). InputStr = " + InputStr);
  680. if(InputStr.equals("工号")){
  681. outputStr = "sID";
  682. }else if(InputStr.equals("权限")){
  683. outputStr = "sAuthority";
  684. }else if(InputStr.equals("姓名")){
  685. outputStr = "sName";
  686. }else if(InputStr.equals("性别")){
  687. outputStr = "sSex";
  688. }else if(InputStr.equals("生日")){
  689. outputStr = "sBirthday";
  690. }else if(InputStr.equals("部门")){
  691. outputStr = "sDepartment";
  692. }else if(InputStr.equals("职务")){
  693. outputStr = "sJob";
  694. }else if(InputStr.equals("教育水平")){
  695. outputStr = "sEdu_Level";
  696. }else if(InputStr.equals("专业技能")){
  697. outputStr = "sSpecialty";
  698. }else if(InputStr.equals("状态")){
  699. outputStr = "sState";
  700. }
  701. System.out.println("jCBSelectQueryFieldTransfer(). outputStr = " + outputStr);
  702. return outputStr;
  703. }
  704. }

4.8 员工自身信息查询修改模块

  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. public class Employee extends JFrame implements ActionListener {
  7. // 定义组件
  8. JLabel jLEmployee = null;//员工信息
  9. JLabel jLText = null;//注释
  10. JLabel jLsID = null;//工号
  11. JLabel jLsPassword1 = null;//密码1
  12. JLabel jLsPassword2 = null;//密码2
  13. JLabel jLsAuthority = null;//权限
  14. JLabel jLsName = null;//姓名
  15. JLabel jLsSex = null;//性别
  16. JLabel jLsBirthday = null;//生日
  17. JLabel jLsDepartment = null;//部门
  18. JLabel jLsJob = null;//职务
  19. JLabel jLsEdu_Level = null;//教育水平
  20. JLabel jLsSpecialty = null;//专业技能
  21. JLabel jLsAddress = null;//住址
  22. JLabel jLsTel = null;//电话
  23. JLabel jLsEmail = null;//邮箱
  24. JLabel jLsState = null;//状态
  25. JLabel jLsRemark = null;//备注
  26. JTextField jTFsID = null;//工号
  27. JPasswordField jPFsPassword1 = null;//密码1
  28. JPasswordField jPFsPassword2 = null;//密码2
  29. JTextField jTFsAuthority = null;//权限
  30. JTextField jTFsName = null;//姓名
  31. JTextField jTFsSex = null;//性别
  32. JTextField jTFsBirthday = null;//生日
  33. JTextField jTFsDepartment = null;//部门
  34. JTextField jTFsJob = null;//职务
  35. JTextField jTFsEdu_Level = null;//教育水平
  36. JTextField jTFsSpecialty = null;//专业技能
  37. JTextField jTFsAddress = null;//住址
  38. JTextField jTFsTel = null;//电话
  39. JTextField jTFsEmail = null;//邮箱
  40. JTextField jTFsState = null;//状态
  41. JTextField jTFsRemark = null;//备注
  42. JButton jBUpdateInfo = null;//更新信息
  43. JButton jBUpdatePwd = null;//修改密码
  44. //JComboBox jCBSelectQueryField = null;
  45. JPanel jP1, jP2,jP3, jP4, jP5,jP6 = null;
  46. JPanel jP = null;
  47. JScrollPane EmployeeJScrollPane = null;
  48. private static DbProcess EdbProcess;
  49. private static Md5 md5;
  50. // 构造函数
  51. public Employee(ResultSet rs) {
  52. this.md5=new Md5();
  53. // 创建标签组件
  54. try {
  55. jLEmployee = new JLabel("员工信息");
  56. jLEmployee.setFont(new Font("宋体",Font.BOLD,25));
  57. jLText = new JLabel("注意:更新信息需要填写上方所有带*的内容,修改密码只需要输入两次新密码即可!");
  58. jLText.setFont(new Font("宋体",Font.BOLD,15));
  59. jLText.setForeground(Color.red);
  60. jLsID = new JLabel("工号*");
  61. jLsPassword1 = new JLabel("新密码*");
  62. jLsPassword2 = new JLabel("确认新密码*");
  63. jLsAuthority = new JLabel("权限*");
  64. jLsName = new JLabel("姓名*");
  65. jLsSex = new JLabel("性别*");
  66. jLsBirthday = new JLabel("生日*");
  67. jLsDepartment = new JLabel("部门*");
  68. jLsJob = new JLabel("职务*");
  69. jLsEdu_Level = new JLabel("教育水平*");
  70. jLsSpecialty = new JLabel("专业技能*");
  71. jLsAddress = new JLabel("住址*");
  72. jLsTel = new JLabel("电话*");
  73. jLsEmail = new JLabel("邮箱*");
  74. jLsState = new JLabel("状态*");
  75. jLsRemark = new JLabel("备注");
  76. EdbProcess = new DbProcess();
  77. jTFsID = new JTextField(15);//工号
  78. jTFsID.setEditable(false);
  79. jTFsID.setText(rs.getString(1));
  80. jPFsPassword1 = new JPasswordField(15);//密码
  81. //jTFsPassword1.setText(rs.getString(2));
  82. jPFsPassword2 = new JPasswordField(15);//密码
  83. //jTFsPassword2.setText(rs.getString(2));
  84. jTFsAuthority = new JTextField(15);//权限
  85. jTFsAuthority.setEditable(false);
  86. jTFsAuthority.setText(rs.getString(3));
  87. jTFsName = new JTextField(15);//姓名
  88. jTFsName.setEditable(false);
  89. jTFsName.setText(rs.getString(4));
  90. jTFsSex = new JTextField(15);//性别
  91. jTFsSex.setEditable(false);
  92. jTFsSex.setText(rs.getString(5));
  93. jTFsBirthday = new JTextField(15);//生日
  94. jTFsBirthday.setEditable(false);
  95. jTFsBirthday.setText(rs.getString(6));
  96. jTFsDepartment = new JTextField(15);//部门
  97. jTFsDepartment.setEditable(false);
  98. jTFsDepartment.setText(rs.getString(7));
  99. jTFsJob = new JTextField(15);//职务
  100. jTFsJob.setEditable(false);
  101. jTFsJob.setText(rs.getString(8));
  102. jTFsEdu_Level = new JTextField(15);//教育水平
  103. jTFsEdu_Level.setEditable(false);
  104. jTFsEdu_Level.setText(rs.getString(9));
  105. jTFsSpecialty = new JTextField(15);//专业技能
  106. jTFsSpecialty.setText(rs.getString(10));
  107. jTFsAddress = new JTextField(15);//住址
  108. jTFsAddress.setText(rs.getString(11));
  109. jTFsTel = new JTextField(15);//电话
  110. jTFsTel.setText(rs.getString(12));
  111. jTFsEmail = new JTextField(15);//邮箱
  112. jTFsEmail.setText(rs.getString(13));
  113. jTFsState = new JTextField(15);//状态
  114. jTFsState.setEditable(false);
  115. jTFsState.setText(rs.getString(14));
  116. jTFsRemark = new JTextField(15);//备注
  117. jTFsRemark.setEditable(false);
  118. jTFsRemark.setText(rs.getString(15));
  119. jBUpdateInfo = new JButton("更新信息");
  120. jBUpdateInfo.setFont(new Font("宋体",Font.BOLD,20));
  121. jBUpdatePwd = new JButton("修改密码");
  122. jBUpdatePwd.setFont(new Font("宋体",Font.BOLD,20));
  123. // 设置监听
  124. jBUpdateInfo.addActionListener(this);
  125. jBUpdatePwd.addActionListener(this);
  126. //studentTableModel = new DefaultTableModel(tableTitle, 15);
  127. EmployeeJScrollPane = new JScrollPane();
  128. jP1 = new JPanel();
  129. jP2 = new JPanel();
  130. jP3 = new JPanel();
  131. jP4 = new JPanel();
  132. jP5 = new JPanel();
  133. jP6 = new JPanel();
  134. jP = new JPanel();
  135. //jP1.add(NewEmployeeJScrollPane);
  136. jP1.add(jLEmployee);
  137. jP1.setLayout(new FlowLayout(FlowLayout.CENTER));
  138. jP1.setPreferredSize(new Dimension(250,80));
  139. jP2.add(jLsID);
  140. jP2.add(jTFsID);
  141. jP2.add(jLsAuthority);
  142. jP2.add(jTFsAuthority);
  143. jP2.add(jLsName);
  144. jP2.add(jTFsName);
  145. jP2.add(jLsSex);
  146. jP2.add(jTFsSex);
  147. jP2.setLayout(new FlowLayout(FlowLayout.CENTER));
  148. jP2.setPreferredSize(new Dimension(250,80));
  149. jP3.add(jLsBirthday);
  150. jP3.add(jTFsBirthday);
  151. jP3.add(jLsDepartment);
  152. jP3.add(jTFsDepartment);
  153. jP3.add(jLsJob);
  154. jP3.add(jTFsJob);
  155. jP3.add(jLsEdu_Level);
  156. jP3.add(jTFsEdu_Level);
  157. jP3.add(jLsSpecialty);
  158. jP3.add(jTFsSpecialty);
  159. jP3.setLayout(new FlowLayout(FlowLayout.CENTER));
  160. jP3.setPreferredSize(new Dimension(250,80));
  161. jP4.add(jLsAddress);
  162. jP4.add(jTFsAddress);
  163. jP4.add(jLsTel);
  164. jP4.add(jTFsTel);
  165. jP4.add(jLsEmail);
  166. jP4.add(jTFsEmail);
  167. jP4.add(jLsState);
  168. jP4.add(jTFsState);
  169. jP4.add(jLsRemark);
  170. jP4.add(jTFsRemark);
  171. jP4.setLayout(new FlowLayout(FlowLayout.CENTER));
  172. jP4.setPreferredSize(new Dimension(250,80));
  173. jP5.add(jLText);
  174. jP5.add(jBUpdateInfo);
  175. jP5.setLayout(new FlowLayout(FlowLayout.CENTER));
  176. jP5.setPreferredSize(new Dimension(250,80));
  177. jP6.add(jLsPassword1);
  178. jP6.add(jPFsPassword1);
  179. jP6.add(jLsPassword2);
  180. jP6.add(jPFsPassword2);
  181. jP6.add(jBUpdatePwd);
  182. jP6.setLayout(new FlowLayout(FlowLayout.CENTER));
  183. jP6.setPreferredSize(new Dimension(250,80));
  184. jP.setLayout(new GridLayout(6, 1));
  185. jP.add(jP1);
  186. jP.add(jP2);
  187. jP.add(jP3);
  188. jP.add(jP4);
  189. jP.add(jP5);
  190. jP.add(jP6);
  191. this.add("North", EmployeeJScrollPane);
  192. this.add("South", jP);
  193. this.setLayout(new BorderLayout());
  194. this.add(jP,BorderLayout.SOUTH);
  195. this.setTitle("员工信息查询修改");
  196. this.setSize(970, 450);
  197. this.setLocation(200, 150);
  198. this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  199. this.setVisible(true);
  200. this.setResizable(false);
  201. }catch (SQLException sqle){
  202. System.out.println("sqle = " + sqle);
  203. JOptionPane.showMessageDialog(null,
  204. "你输入的工号不存在,请从新输入!","错误",JOptionPane.ERROR_MESSAGE);
  205. }
  206. }
  207. public void actionPerformed(ActionEvent e) {
  208. if(e.getActionCommand().equals("更新信息")
  209. && !jTFsSpecialty.getText().isEmpty()
  210. && !jTFsAddress.getText().isEmpty()
  211. && !jTFsTel.getText().isEmpty()
  212. && !jTFsEmail.getText().isEmpty()){
  213. System.out.println("actionPerformed(). 更新");
  214. updateProcess();
  215. }else if(e.getActionCommand().equals("修改密码")
  216. &&!String.valueOf(jPFsPassword1.getPassword()).equals("")
  217. &&!String.valueOf(jPFsPassword2.getPassword()).equals("")){
  218. String sPassword1 = new String(jPFsPassword1.getPassword());
  219. String sPassword2 = new String(jPFsPassword2.getPassword());
  220. if(sPassword1.equals(sPassword2)){
  221. changePwdProcess(this.md5.md5(sPassword1));
  222. }else{
  223. System.out.println("两次密码不一致");
  224. JOptionPane.showMessageDialog(null,
  225. "两次密码不一致,请确认后再输入!","提示",JOptionPane.INFORMATION_MESSAGE);
  226. }
  227. jPFsPassword1.setText("");
  228. jPFsPassword2.setText("");
  229. }
  230. }
  231. public void updateProcess(){
  232. String sID = jTFsID.getText().trim();
  233. //String sPassword = jPFsPassword1.getText().trim();
  234. String sSpecialty = jTFsSpecialty.getText().trim();
  235. String sAddress = jTFsAddress.getText().trim();
  236. String sTel = jTFsTel.getText().trim();
  237. String sEmail = jTFsEmail.getText().trim();
  238. // 建立更新条件
  239. String sql = "update staff set sSpecialty = '";
  240. //sql = sql + sPassword + "', sSpecialty = '";
  241. sql = sql + sSpecialty + "', sAddress = '";
  242. sql = sql + sAddress + "', sTel = '";
  243. sql = sql + sTel + "', sEmail = '";
  244. sql = sql + sEmail + "'";
  245. sql = sql + " WHERE sID = '" + sID + "';";
  246. System.out.println("updateProcess(). sql = " + sql);
  247. try{
  248. if (EdbProcess.executeUpdate(sql) < 1) {
  249. System.out.println("updateProcess(). update database failed.");
  250. }else{
  251. JOptionPane.showMessageDialog(null,
  252. "更新成功!","提示",JOptionPane.INFORMATION_MESSAGE);
  253. }
  254. }catch(Exception e){
  255. System.out.println("e = " + e);
  256. JOptionPane.showMessageDialog(null,
  257. "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);
  258. }
  259. }
  260. public void changePwdProcess(String sPassword){
  261. String sql = "update staff set sPassword = '";
  262. sql = sql + sPassword + "'";
  263. sql = sql + " WHERE sID = '" + jTFsID.getText().trim() + "';";
  264. System.out.println("changePwdProcess(). sql = " + sql);
  265. try{
  266. if (EdbProcess.executeUpdate(sql) < 1) {
  267. System.out.println("changePwdProcess(). update database failed.");
  268. }else{
  269. JOptionPane.showMessageDialog(null,
  270. "修改密码成功!","提示",JOptionPane.INFORMATION_MESSAGE);
  271. }
  272. }catch(Exception e){
  273. System.out.println("e = " + e);
  274. JOptionPane.showMessageDialog(null,
  275. "数据操作错误","错误",JOptionPane.ERROR_MESSAGE);
  276. }
  277. }
  278. }

4.9 数据库代码

如果下面的代码运行不了的,可以直接参考4.10建好相应的表,然后执行insert语句就行了,再有问题我是真没办法了。

  1. /*
  2. Navicat Premium Data Transfer
  3. Source Server : test
  4. Source Server Type : MySQL
  5. Source Server Version : 80030
  6. Source Host : localhost:3306
  7. Source Schema : coursedesign
  8. Target Server Type : MySQL
  9. Target Server Version : 80030
  10. File Encoding : 65001
  11. Date: 31/07/2023 18:00:09
  12. */
  13. SET NAMES utf8mb4;
  14. SET FOREIGN_KEY_CHECKS = 0;
  15. -- ----------------------------
  16. -- Table structure for changecode
  17. -- ----------------------------
  18. DROP TABLE IF EXISTS `changecode`;
  19. CREATE TABLE `changecode` (
  20. `cCode` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  21. `cDescription` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  22. PRIMARY KEY (`cCode`) USING BTREE
  23. ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
  24. -- ----------------------------
  25. -- Records of changecode
  26. -- ----------------------------
  27. INSERT INTO `changecode` VALUES ('0', '新员工加入');
  28. INSERT INTO `changecode` VALUES ('1', '职务变动');
  29. INSERT INTO `changecode` VALUES ('2', '辞退');
  30. -- ----------------------------
  31. -- Table structure for department
  32. -- ----------------------------
  33. DROP TABLE IF EXISTS `department`;
  34. CREATE TABLE `department` (
  35. `dID` varchar(10) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  36. `dName` varchar(16) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  37. `sID` varchar(15) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  38. `dIntro` varchar(20) CHARACTER SET gbk COLLATE gbk_chinese_ci NULL DEFAULT NULL,
  39. PRIMARY KEY (`dID`) USING BTREE,
  40. INDEX `sID`(`sID`) USING BTREE,
  41. CONSTRAINT `department_ibfk_1` FOREIGN KEY (`sID`) REFERENCES `staff` (`sID`) ON DELETE CASCADE ON UPDATE CASCADE
  42. ) ENGINE = InnoDB CHARACTER SET = gbk COLLATE = gbk_chinese_ci ROW_FORMAT = Dynamic;
  43. -- ----------------------------
  44. -- Records of department
  45. -- ----------------------------
  46. INSERT INTO `department` VALUES ('0', '生产部', '10004', '生产管理');
  47. INSERT INTO `department` VALUES ('1', '运营部', '10003', '运营管理');
  48. INSERT INTO `department` VALUES ('2', '行政部', '10002', '行政管理');
  49. INSERT INTO `department` VALUES ('3', '人事部', '10001', '人事管理');
  50. -- ----------------------------
  51. -- Table structure for edu
  52. -- ----------------------------
  53. DROP TABLE IF EXISTS `edu`;
  54. CREATE TABLE `edu` (
  55. `eCode` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  56. `eDescription` varchar(6) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  57. PRIMARY KEY (`eCode`) USING BTREE
  58. ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
  59. -- ----------------------------
  60. -- Records of edu
  61. -- ----------------------------
  62. INSERT INTO `edu` VALUES ('0', '小学');
  63. INSERT INTO `edu` VALUES ('1', '初中');
  64. INSERT INTO `edu` VALUES ('2', '高中');
  65. INSERT INTO `edu` VALUES ('3', '职高');
  66. INSERT INTO `edu` VALUES ('4', '大本');
  67. INSERT INTO `edu` VALUES ('5', '大专');
  68. INSERT INTO `edu` VALUES ('6', '硕士');
  69. INSERT INTO `edu` VALUES ('7', '博士');
  70. INSERT INTO `edu` VALUES ('8', '博士后');
  71. -- ----------------------------
  72. -- Table structure for job
  73. -- ----------------------------
  74. DROP TABLE IF EXISTS `job`;
  75. CREATE TABLE `job` (
  76. `jCode` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  77. `jDescription` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  78. PRIMARY KEY (`jCode`) USING BTREE
  79. ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
  80. -- ----------------------------
  81. -- Records of job
  82. -- ----------------------------
  83. INSERT INTO `job` VALUES ('0', '员工');
  84. INSERT INTO `job` VALUES ('1', '组长');
  85. INSERT INTO `job` VALUES ('2', '主任');
  86. INSERT INTO `job` VALUES ('3', '经理');
  87. -- ----------------------------
  88. -- Table structure for personnel
  89. -- ----------------------------
  90. DROP TABLE IF EXISTS `personnel`;
  91. CREATE TABLE `personnel` (
  92. `pID` varchar(15) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  93. `sID` varchar(15) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  94. `pChange` varchar(1) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  95. `pDescription` varchar(20) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  96. PRIMARY KEY (`pID`) USING BTREE,
  97. INDEX `sID`(`sID`) USING BTREE,
  98. CONSTRAINT `personnel_ibfk_1` FOREIGN KEY (`sID`) REFERENCES `staff` (`sID`) ON DELETE CASCADE ON UPDATE CASCADE
  99. ) ENGINE = InnoDB CHARACTER SET = gbk COLLATE = gbk_chinese_ci ROW_FORMAT = Dynamic;
  100. -- ----------------------------
  101. -- Records of personnel
  102. -- ----------------------------
  103. INSERT INTO `personnel` VALUES ('100001', '10001', '0', '新员工录入');
  104. INSERT INTO `personnel` VALUES ('100002', '10002', '0', '新员工录入');
  105. INSERT INTO `personnel` VALUES ('100003', '10003', '0', '新员工录入');
  106. INSERT INTO `personnel` VALUES ('100004', '10004', '0', '新员工录入');
  107. INSERT INTO `personnel` VALUES ('100005', '10005', '0', '新员工录入');
  108. INSERT INTO `personnel` VALUES ('100006', '10005', '1', '表现好');
  109. INSERT INTO `personnel` VALUES ('100007', '10006', '0', '新员工录入');
  110. INSERT INTO `personnel` VALUES ('100008', '10006', '1', '表现好');
  111. INSERT INTO `personnel` VALUES ('100009', '10005', '2', '表现差');
  112. -- ----------------------------
  113. -- Table structure for staff
  114. -- ----------------------------
  115. DROP TABLE IF EXISTS `staff`;
  116. CREATE TABLE `staff` (
  117. `sID` varchar(15) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  118. `sPassword` varchar(20) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  119. `sAuthority` varchar(8) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  120. `sName` varchar(20) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  121. `sSex` varchar(2) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  122. `sBirthday` varchar(8) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  123. `sDepartment` varchar(10) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  124. `sJob` varchar(16) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  125. `sEdu_Level` varchar(6) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  126. `sSpecialty` varchar(20) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  127. `sAddress` varchar(40) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  128. `sTel` varchar(11) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  129. `sEmail` varchar(20) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  130. `sState` varchar(1) CHARACTER SET gbk COLLATE gbk_chinese_ci NOT NULL,
  131. `sRemark` varchar(20) CHARACTER SET gbk COLLATE gbk_chinese_ci NULL DEFAULT NULL,
  132. PRIMARY KEY (`sID`) USING BTREE
  133. ) ENGINE = InnoDB CHARACTER SET = gbk COLLATE = gbk_chinese_ci ROW_FORMAT = Dynamic;
  134. -- ----------------------------
  135. -- Records of staff
  136. -- ----------------------------
  137. INSERT INTO `staff` VALUES ('10001', '646368', '管理员', 'wx', '男', '20202020', '人事部', '经理', '大本', 'java', '湖南省', '13366668888', 'w@x', 'T', '');
  138. INSERT INTO `staff` VALUES ('10002', '646371', '普通员工', 'sd', '男', '20202020', '行政部', '经理', '大本', 'c语言', '湖南省', '15566668888', 's@d', 'T', '');
  139. INSERT INTO `staff` VALUES ('10003', '646370', '普通员工', 'nj', '男', '20202020', '运营部', '经理', '大本', 'javaspring', '湖南省', '15577778888', 'n@j', 'T', '');
  140. INSERT INTO `staff` VALUES ('10004', '646373', '普通员工', 'cq', '男', '20202020', '生产部', '经理', '大本', 'c++', '广东省', '16699998888', 'c@q', 'T', '');
  141. INSERT INTO `staff` VALUES ('10005', '646372', '普通员工', '张三', '女', '20202020', '生产部', '主任', '初中', 'java', '广东省', '1555', '张@s', 'F', '');
  142. INSERT INTO `staff` VALUES ('10006', '646375', '普通员工', '李四', '男', '20192019', '生产部', '组长', '大本', '汇编语言', '广东省', '13355556666', '李@四', 'T', '');
  143. SET FOREIGN_KEY_CHECKS = 1;

4.10 数据库表结构

(1)员工信息表staff

(2)人事变更记录表personnel

(3)部门信息表department

(4)教育水平表edu

(5)职务表job

(6)人事变更代码表changecode

5 界面图预览

5.1 登录界面

5.2 管理界面

5.3 新员工档案录入界面

5.4 人事变更界面

5.5 管理员员工档案查询修改界面

5.6 员工自身信息查询修改界面

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/486700
推荐阅读
相关标签
  

闽ICP备14008679号