java swing mysql实现的员工工资管理系统项目
下载链接https://download.csdn.net/download/RONNIE_Zz/12675313
项目功能
随着经济的发展,企业正向着大型化、规模化发展,而对于大中型企业,员工、职称等跟工资管理有关的信息随之急剧增加。在这种情况下单靠人工来处理员工的工资不但显得力不从心,而且极容易出错。如何设计一个小型企业工资的数据库管理系统,由计算机代替人工执行一系列诸如增加新员工,删除旧员工,工资查询,统计等操作。这样就使办公人员可以轻松快捷地完成工资管理的任务。实现工资的集中管理。
功能:可供财务人员对本单位的人员以及工资进行增加、删除、修改、查询,对人事的管理及工资发放中的应发工资合计等项目由系统自动进行计算;同时系统还可对人事及工资管理情况进行多角度查询
每个子功能介绍
基础功能:登录与增查删改
可以选择登录方式:员工或者管理员(账密默认为admin,123456)
查询分为员工查询和管理员查询,员工只可以根据自己的信息查询,不具备修改的能力,管理员有多种查询功能,在各个模块之间进行操作时,下面有实时的信息显示
管理员具有添加员工,部门等,以及可以添加管理员的功能,修改员工信息,部门信息,设定工资信息。
进阶功能与特色功能:遍历信息与统计
访问数据库,遍历信息,生成表格。根据选择分析并统计数据
关键代码
java swing mysql实现的员工工资管理系统项目源码
登录界面,判断使用权限,输出对应的内容
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jComboBox1 = new javax.swing.JComboBox();
username = new javax.swing.JTextField();
jPasswordField1 = new javax.swing.JPasswordField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("登录界面");
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "管理员", "员工" }));
jComboBox1.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
// TODO Auto-generated method stub
if(e.getStateChange() == ItemEvent.SELECTED){
if("员工".equals(e.getItem())){
jButton1.setText("查询工资");
jLabel2.hide();
username.hide();
jPasswordField1.hide();
jLabel3.hide();
jPasswordField1.hide();
}else{
jButton1.setText("登录");
jLabel2.show();
username.show();
jPasswordField1.show();
jLabel3.show();
jPasswordField1.show();
}
}
}
});
//username.setText("quan");
jLabel1.setText("身份:");
jLabel2.setText("用户名:");
jLabel3.setText("密码:");
jButton1.setText("登录");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("退出");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jLabel4.setForeground(new java.awt.Color(255, 0, 0));
jLabel4.setText("注:员工可以匿名登录");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(80, 80, 80)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1)
.addComponent(jLabel3)
.addComponent(jLabel2))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(username, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jComboBox1, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addComponent(jLabel4))))
.addGroup(layout.createSequentialGroup()
.addGap(110, 110, 110)
.addComponent(jButton1)
.addGap(39, 39, 39)
.addComponent(jButton2)))
.addContainerGap(54, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(65, 65, 65)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(username, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap(102, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
status = (String) jComboBox1.getSelectedItem();
name = username.getText();
String password = jPasswordField1.getText();
if(status.equals("管理员")){
if(name.equals("")){
JOptionPane.showMessageDialog(null, "用户名不能为空!!");
}else if(password.equals("")){
JOptionPane.showMessageDialog(null,"密码不能为空!!");
}else{
String sql = "select username from userlist where status = '"+ status +"' and username = '"+ name +"' and password = '"+ password +"'";
//String sql = "select * from userlist";
System.out.println(sql);
DBConn db = new DBConn();
if (db.Check(sql) != 0){
new MainFrame().setVisible(true);
this.hide();
}else {
JOptionPane.showMessageDialog(null, "用户名与密码不对!!");
}
}
}else{
new SalarySearch().setVisible(true);
}
}//GEN-LAST:event_jButton1ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
int selection = JOptionPane.showConfirmDialog(this,
"是否退出?", "退出提示", JOptionPane.OK_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE);
if (selection == JOptionPane.OK_OPTION) {
System.exit(0);
}
}//GEN-LAST:event_jButton2ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Login().setVisible(true);
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
}
数据库使用代码,建立对应的数据库文件
/*
Navicat MySQL Data Transfer
Source Server : localhost
Source Server Version : 50523
Source Host : localhost:3306
Source Database : salarydb
Target Server Type : MYSQL
Target Server Version : 50523
File Encoding : 65001
Date: 2013-07-03 20:47:40
*/
SET FOREIGN_KEY_CHECKS=0;
– Table structure for department
DROP TABLE IF EXISTS department
;
CREATE TABLE department
(ID
varchar(20) COLLATE utf8_unicode_ci NOT NULL,Name
varchar(25) COLLATE utf8_unicode_ci NOT NULL,Director
varchar(25) COLLATE utf8_unicode_ci NOT NULL,Number
int(16) NOT NULL,
PRIMARY KEY (ID
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
– Records of department
INSERT INTO department
VALUES (‘ks001’, ‘经理室’, ‘赢政’, ‘10’);
INSERT INTO department
VALUES (‘ks002’, ‘财务室’, ‘刘邦’, ‘6’);
INSERT INTO department
VALUES (‘ks003’, ‘军机部’, ‘李鸿章’, ‘6’);
INSERT INTO department
VALUES (‘ks004’, ‘外交部’, ‘张仪’, ‘8’);
INSERT INTO department
VALUES (‘ks005’, ‘技术科’, ‘朱元璋’, ‘10’);
INSERT INTO department
VALUES (‘ks006’, ‘董事会’, ‘李世民’, ‘10’);
– Table structure for employee
DROP TABLE IF EXISTS employee
;
CREATE TABLE employee
(ID
varchar(10) COLLATE utf8_unicode_ci NOT NULL,name
varchar(25) COLLATE utf8_unicode_ci NOT NULL,sex
char(2) COLLATE utf8_unicode_ci NOT NULL,age
int(6) NOT NULL,department
varchar(50) COLLATE utf8_unicode_ci NOT NULL,position
varchar(25) COLLATE utf8_unicode_ci NOT NULL,phone
varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL,time
datetime DEFAULT NULL,address
varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (ID
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
– Records of employee
INSERT INTO employee
VALUES (‘0001’, ‘赢政’, ‘男’, ‘37’, ‘经理室’, ‘经理’, ‘10086’, ‘0201-01-01 00:00:00’, ‘咸阳’);
INSERT INTO employee
VALUES (‘0002’, ‘刘邦’, ‘男’, ‘40’, ‘技术科’, ‘技术长’, ‘10087910’, ‘2001-05-06 00:00:00’, ‘长安’);
INSERT INTO employee
VALUES (‘0003’, ‘武则天’, ‘女’, ‘30’, ‘财务室’, ‘经理’, ‘10088’, ‘1999-08-07 00:00:00’, ‘长安’);
INSERT INTO employee
VALUES (‘0004’, ‘刘秀’, ‘男’, ‘46’, ‘军机部’, ‘副部长’, ‘123548788’, ‘2013-05-07 00:00:00’, ‘桂林’);
INSERT INTO employee
VALUES (‘0005’, ‘西施’, ‘女’, ‘23’, ‘财务室’, ‘会计’, ‘10089’, ‘2001-02-03 00:00:00’, ‘越国’);
INSERT INTO employee
VALUES (‘0006’, ‘李清照’, ‘女’, ‘25’, ‘财务室’, ‘出纳’, ‘125478’, ‘2012-03-04 00:00:00’, ‘宋国’);
INSERT INTO employee
VALUES (‘0007’, ‘杨玉环’, ‘女’, ‘29’, ‘财务室’, ‘会计’, ‘125478’, ‘2010-02-04 00:00:00’, ‘长安’);
INSERT INTO employee
VALUES (‘0008’, ‘孙权’, ‘男’, ‘35’, ‘外交部’, ‘部长’, ‘150478’, ‘2005-05-04 00:00:00’, ‘江东’);
INSERT INTO employee
VALUES (‘0009’, ‘李世民’, ‘男’, ‘54’, ‘董事会’, ‘会长’, ‘100865’, ‘1998-05-08 00:00:00’, ‘西安’);
INSERT INTO employee
VALUES (‘0010’, ‘项羽’, ‘男’, ‘40’, ‘经理室’, ‘副经理’, ‘1008670’, ‘2000-02-05 00:00:00’, ‘彭城’);
INSERT INTO employee
VALUES (‘0011’, ‘李鸿章’, ‘男’, ‘52’, ‘军机部’, ‘部长’, ‘1008699’, ‘2001-05-08 00:00:00’, ‘北京’);
INSERT INTO employee
VALUES (‘0012’, ‘张仪’, ‘男’, ‘44’, ‘外交部’, ‘部长’, ‘10089’, ‘2002-02-04 00:00:00’, ‘魏国’);
INSERT INTO employee
VALUES (‘0013’, ‘朱元璋’, ‘男’, ‘35’, ‘技术科’, ‘部长’, ‘100896’, ‘2013-05-07 00:00:00’, ‘南京’);
INSERT INTO employee
VALUES (‘0014’, ‘貂蝉’, ‘女’, ‘25’, ‘经理室’, ‘助理’, ‘10086972’, ‘2005-05-04 00:00:00’, ‘洛阳’);
INSERT INTO employee
VALUES (‘0015’, ‘李渊’, ‘男’, ‘55’, ‘董事会’, ‘董事’, ‘25897’, ‘2001-02-05 00:00:00’, ‘长安’);
– Table structure for salary
DROP TABLE IF EXISTS salary
;
CREATE TABLE salary
(salaryID
int(4) NOT NULL AUTO_INCREMENT,ID
varchar(10) COLLATE utf8_unicode_ci NOT NULL,name
varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL,basepay
int(10) DEFAULT NULL,welfare
int(10) DEFAULT NULL,reward
int(10) DEFAULT NULL,insurance
int(10) DEFAULT NULL,funds
int(10) DEFAULT NULL,month
varchar(25) COLLATE utf8_unicode_ci NOT NULL,remark
varchar(25) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (salaryID
,ID
)
) ENGINE=InnoDB AUTO_INCREMENT=42 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
– Records of salary
INSERT INTO salary
VALUES (‘1’, ‘0001’, ‘赢政’, ‘3000’, ‘100’, ‘100’, ‘100’, ‘500’, ‘1月’, ‘未结算’);
INSERT INTO salary
VALUES (‘13’, ‘0002’, ‘刘邦’, ‘3000’, ‘200’, ‘100’, ‘100’, ‘400’, ‘1月’, ‘未结算’);
INSERT INTO salary
VALUES (‘15’, ‘0003’, ‘武则天’, ‘2500’, ‘100’, ‘200’, ‘100’, ‘300’, ‘1月’, ‘未结算’);
INSERT INTO salary
VALUES (‘16’, ‘0004’, ‘刘秀’, ‘2900’, ‘100’, ‘150’, ‘250’, ‘200’, ‘1月’, ‘未结算’);
INSERT INTO salary
VALUES (‘17’, ‘0005’, ‘西施’, ‘2800’, ‘100’, ‘100’, ‘100’, ‘300’, ‘1月’, ‘未结算’);
INSERT INTO salary
VALUES (‘18’, ‘0006’, ‘李清照’, ‘2700’, ‘120’, ‘150’, ‘100’, ‘300’, ‘1月’, ‘未结算’);
INSERT INTO salary
VALUES (‘19’, ‘0007’, ‘杨玉环’, ‘2680’, ‘200’, ‘150’, ‘100’, ‘300’, ‘1月’, ‘未结算’);
INSERT INTO salary
VALUES (‘20’, ‘0008’, ‘孙权’, ‘2900’, ‘100’, ‘200’, ‘100’, ‘500’, ‘1月’, ‘未结算’);
INSERT INTO salary
VALUES (‘21’, ‘0009’, ‘李世民’, ‘2870’, ‘200’, ‘100’, ‘100’, ‘300’, ‘1月’, ‘未结算’);
INSERT INTO salary
VALUES (‘22’, ‘0010’, ‘项羽’, ‘2600’, ‘200’, ‘100’, ‘100’, ‘300’, ‘1月’, ‘未结算’);
INSERT INTO salary
VALUES (‘23’, ‘0011’, ‘李鸿章’, ‘2800’, ‘200’, ‘100’, ‘100’, ‘300’, ‘1月’, ‘未结算’);
INSERT INTO salary
VALUES (‘24’, ‘0012’, ‘张仪’, ‘2900’, ‘200’, ‘150’, ‘100’, ‘500’, ‘1月’, ‘未结算’);
INSERT INTO salary
VALUES (‘25’, ‘0013’, ‘朱元璋’, ‘2600’, ‘250’, ‘200’, ‘100’, ‘400’, ‘1月’, ‘未结算’);
INSERT INTO salary
VALUES (‘26’, ‘0001’, ‘赢政’, ‘3000’, ‘100’, ‘200’, ‘100’, ‘300’, ‘2月’, ‘未结算’);
INSERT INTO salary
VALUES (‘27’, ‘0001’, ‘赢政’, ‘3000’, ‘250’, ‘200’, ‘100’, ‘400’, ‘3月’, ‘未结算’);
INSERT INTO salary
VALUES (‘28’, ‘0002’, ‘刘邦’, ‘3000’, ‘250’, ‘150’, ‘100’, ‘400’, ‘2月’, ‘未结算’);
INSERT INTO salary
VALUES (‘29’, ‘0002’, ‘刘邦’, ‘3000’, ‘300’, ‘150’, ‘100’, ‘500’, ‘3月’, ‘未结算’);
INSERT INTO salary
VALUES (‘30’, ‘0003’, ‘武则天’, ‘2900’, ‘200’, ‘150’, ‘100’, ‘300’, ‘2月’, ‘未结算’);
INSERT INTO salary
VALUES (‘31’, ‘0003’, ‘武则天’, ‘2800’, ‘250’, ‘120’, ‘100’, ‘500’, ‘3月’, ‘未结算’);
INSERT INTO salary
VALUES (‘33’, ‘0004’, ‘刘秀’, ‘2580’, ‘500’, ‘200’, ‘100’, ‘300’, ‘2月’, ‘未结算’);
INSERT INTO salary
VALUES (‘35’, ‘0004’, ‘刘秀’, ‘2900’, ‘200’, ‘150’, ‘100’, ‘300’, ‘3月’, ‘未结算’);
INSERT INTO salary
VALUES (‘37’, ‘0005’, ‘西施’, ‘2900’, ‘200’, ‘100’, ‘100’, ‘300’, ‘2月’, ‘未结算’);
INSERT INTO salary
VALUES (‘39’, ‘0005’, ‘西施’, ‘2800’, ‘200’, ‘150’, ‘100’, ‘300’, ‘3月’, ‘未结算’);
INSERT INTO salary
VALUES (‘40’, ‘0006’, ‘李清照’, ‘2900’, ‘200’, ‘100’, ‘100’, ‘300’, ‘2月’, ‘未结算’);
INSERT INTO salary
VALUES (‘41’, ‘0006’, ‘李清照’, ‘2900’, ‘200’, ‘100’, ‘100’, ‘300’, ‘3月’, ‘未结算’);
– Table structure for userlist
DROP TABLE IF EXISTS userlist
;
CREATE TABLE userlist
(status
varchar(20) COLLATE utf8_unicode_ci NOT NULL,username
varchar(20) COLLATE utf8_unicode_ci NOT NULL,password
varchar(20) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (username
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
– Records of userlist
INSERT INTO userlist
VALUES (‘管理员’, ‘admin’, ‘123456’);
INSERT INTO userlist
VALUES (‘管理员’, ‘quan’, ‘1’);
INSERT INTO userlist
VALUES (‘管理员’, ‘wufeng’, ‘123456’);
– Table structure for view_salary
DROP TABLE IF EXISTS view_salary
;
CREATE TABLE view_salary
(ID
int(10) NOT NULL AUTO_INCREMENT,工号
varchar(10) COLLATE utf8_unicode_ci NOT NULL,姓名
varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL,部门
varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL,职位
varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL,总工资
int(10) DEFAULT NULL,月份
varchar(10) COLLATE utf8_unicode_ci NOT NULL,备注
varchar(10) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (ID
)
) ENGINE=InnoDB AUTO_INCREMENT=42 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
– Records of view_salary
INSERT INTO view_salary
VALUES (‘1’, ‘0001’, ‘赢政’, ‘经理室’, ‘经理’, ‘2600’, ‘1月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘9’, ‘0002’, ‘刘邦’, ‘技术室’, ‘技术长’, ‘2800’, ‘1月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘11’, ‘0003’, ‘武则天’, ‘财务室’, ‘经理’, ‘2400’, ‘1月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘12’, ‘0004’, ‘刘秀’, ‘军机部’, ‘大王’, ‘2700’, ‘1月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘13’, ‘0005’, ‘西施’, ‘财务室’, ‘会计’, ‘2600’, ‘1月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘14’, ‘0006’, ‘李清照’, ‘财务室’, ‘出纳’, ‘2570’, ‘1月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘15’, ‘0007’, ‘杨玉环’, ‘财务室’, ‘会计’, ‘2630’, ‘1月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘16’, ‘0008’, ‘孙权’, ‘外交部’, ‘部长’, ‘2600’, ‘1月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘17’, ‘0009’, ‘李世民’, ‘董事会’, ‘会长’, ‘2770’, ‘1月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘18’, ‘0010’, ‘项羽’, ‘经理室’, ‘副经理’, ‘2500’, ‘1月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘19’, ‘0011’, ‘李鸿章’, ‘军机部’, ‘部长’, ‘2700’, ‘1月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘20’, ‘0012’, ‘张仪’, ‘外交部’, ‘部长’, ‘2650’, ‘1月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘21’, ‘0013’, ‘朱元璋’, ‘技术科’, ‘部长’, ‘2550’, ‘1月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘22’, ‘0001’, ‘赢政’, ‘经理室’, ‘经理’, ‘2900’, ‘2月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘23’, ‘0001’, ‘赢政’, ‘经理室’, ‘经理’, ‘2950’, ‘3月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘24’, ‘0002’, ‘刘邦’, ‘技术室’, ‘技术长’, ‘2900’, ‘2月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘25’, ‘0002’, ‘刘邦’, ‘技术室’, ‘技术长’, ‘2850’, ‘3月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘26’, ‘0003’, ‘武则天’, ‘财务室’, ‘经理’, ‘2850’, ‘2月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘27’, ‘0003’, ‘武则天’, ‘财务室’, ‘经理’, ‘2570’, ‘3月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘35’, ‘0004’, ‘刘秀’, ‘军机部’, ‘副部长’, ‘2850’, ‘3月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘36’, ‘0004’, ‘刘秀’, ‘军机部’, ‘副部长’, ‘2750’, ‘2月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘37’, ‘0005’, ‘西施’, ‘财务室’, ‘会计’, ‘2800’, ‘2月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘39’, ‘0005’, ‘西施’, ‘财务室’, ‘会计’, ‘2750’, ‘3月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘40’, ‘0006’, ‘李清照’, ‘财务室’, ‘出纳’, ‘2800’, ‘2月’, ‘未结算’);
INSERT INTO view_salary
VALUES (‘41’, ‘0006’, ‘李清照’, ‘财务室’, ‘出纳’, ‘2800’, ‘3月’, ‘未结算’);
特色遍历功能
/*
To change this template, choose Tools | Templates
and open the template in the editor.
*/
/*
SalaryShow.java
Created on 2013-6-24, 9:28:40
*/
package code;
import java.awt.Toolkit;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
/**
*
@author Administrator
*/
public class SalaryShow extends javax.swing.JFrame {/** Creates new form SalaryShow */
private Toolkit tk = Toolkit.getDefaultToolkit();
int x = tk.getScreenSize().width / 2 - 250;
int y = tk.getScreenSize().height / 2 - 250;
DefaultTableModel dtm = null;
public SalaryShow() {
initTable();
initComponents();
setLocation(x,y);
}private void initTable(){
String head[] = {“工号”,“姓名”,“部门”,“职位”,“总工资”,“月份”,“备注”};
Object obj[][] = new Object[0][0];
dtm = new DefaultTableModel(obj,head);
String sql = “select distinct 工号,姓名,部门,职位,总工资,月份,备注 from view_salary”;
try{
DBConn db = new DBConn();
Vector v;
ResultSet rs = db.Search(sql);
while (rs.next()) {
v = new Vector();
v.add(rs.getString(1));
v.add(rs.getString(2));
v.add(rs.getString(3));
v.add(rs.getString(4));
v.add(rs.getString(5));
v.add(rs.getString(6));
v.add(rs.getString(7));
dtm.addRow(v);
}
db.close();
} catch (SQLException ex) {
System.out.println(ex);
}
}/** This method is called from within the constructor to
/**
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new SalaryShow().setVisible(true);
}
});
}
*/// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JTable jTable1;
private javax.swing.JLabel title;
// End of variables declaration//GEN-END:variables@param args the command line arguments
initialize the form.
WARNING: Do NOT modify this code. The content of this method is
always regenerated by the Form Editor.
*/
@SuppressWarnings(“unchecked”)
// //GEN-BEGIN:initComponents
private void initComponents() {title = new javax.swing.JLabel();
jSeparator1 = new javax.swing.JSeparator();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle(“员工工资一览表”);title.setText(“员工工资一览表”);
jTable1.setModel(dtm);
jScrollPane1.setViewportView(jTable1);javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(209, 209, 209)
.addComponent(title))
.addGroup(layout.createSequentialGroup()
.addGap(105, 105, 105)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 323, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(27, 27, 27)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 467, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(24, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(title, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 303, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(39, Short.MAX_VALUE))
);pack();
}// //GEN-END:initComponents
}
统计功能
/*
To change this template, choose Tools | Templates
and open the template in the editor.
*/
/*
Statistics.java
Created on 2013-6-23, 14:14:39
*/
package code;
import java.awt.Toolkit;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/**
*
@author Administrator
*/
public class Statistics extends javax.swing.JFrame {/** Creates new form Statistics */
private Toolkit tk = Toolkit.getDefaultToolkit();
int x = tk.getScreenSize().width / 2 - 180;
int y = tk.getScreenSize().height / 2 - 180;DefaultComboBoxModel dcm;
String[] head = {“部门”, “负责人”, “总人数”, “总工资”};
Object[][] obj = new Object[0][0];
DefaultTableModel dtm = new DefaultTableModel(obj, head);public Statistics() {
initComboBox();
initComponents();
setTitle(“信息统计”);
setLocation(x,y);
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
}///初始化下拉列表
private void initComboBox(){
Vector v = new Vector();
DBConn db = new DBConn();
try{
ResultSet rs = db.Search(“select distinct name from department”);
while(rs.next()){
v.addElement(rs.getString(“name”)); //添加到向量尾部,大小加1
}
dcm = new DefaultComboBoxModel(v);
}catch(SQLException ex){
ex.printStackTrace();
}finally{
db.close();
}
}private void initTable(String sql){
try {
// String[] head = {“部门”, “负责人”, “总人数”, “总工资”};
// Object[][] obj = new Object[0][0];
dtm = new DefaultTableModel(obj, head);
Vector v;
DBConn db = new DBConn();
ResultSet rs = db.Search(sql);
while (rs.next()) {
v = new Vector();
v.add(rs.getString(1));
v.add(rs.getString(2));
v.add(rs.getString(3));
v.add(rs.getString(4));
dtm.addRow(v);
jTable1.setModel(dtm);
}
db.close();
} catch (SQLException ex) {
ex.printStackTrace();
}}
/** This method is called from within the constructor to
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
String name = (String) jname.getSelectedItem();
int index = jseason.getSelectedIndex();
String sql = null;
if(index == 1){
sql = “select 部门,director,number,sum(总工资) from view_salary,department where " +
“department.name=部门 and 月份 in (‘1月’,‘2月’,‘3月’) and 部门=’”+ name +”’ group by 部门,director,number ";
System.out.println(sql);
}else if(index == 2){
sql = “select 部门,director,number,sum(总工资) from view_salary,department where " +
“department.name=部门 and 月份 in (‘4月’,‘5月’,‘6月’) and 部门=’”+ name +”’ group by 部门,director,number ";
System.out.println(sql);
}else if(index == 3){
sql = “select 部门,director,number,sum(总工资) from view_salary,department where " +
“department.name=部门 and 月份 in (‘7月’,‘8月’,‘9月’) and 部门=’”+ name +”’ group by 部门,director,number ";
System.out.println(sql);
}else if(index == 4){
sql = “select 部门,director,number,sum(总工资) from view_salary,department where " +
“department.name=部门 and 月份 in (‘10月’,‘11月’,‘12月’) and 部门=’”+ name +”’ group by 部门,director,number ";
System.out.println(sql);
}else{
JOptionPane.showMessageDialog(null, “请选择季度”);
}
initTable(sql);
}//GEN-LAST:event_jButton1ActionPerformed/**
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Statistics().setVisible(true);
}
});
}
*/
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JTable jTable1;
private javax.swing.JComboBox jname;
private javax.swing.JComboBox jseason;
// End of variables declaration//GEN-END:variables@param args the command line arguments
initialize the form.
WARNING: Do NOT modify this code. The content of this method is
always regenerated by the Form Editor.
*/
@SuppressWarnings(“unchecked”)
// //GEN-BEGIN:initComponents
private void initComponents() {jname = new javax.swing.JComboBox();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jSeparator1 = new javax.swing.JSeparator();
jseason = new javax.swing.JComboBox();
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jname.setModel(dcm);
jLabel1.setText(“部门名称:”);
jLabel2.setText(“季度:”);
jseason.setModel(new javax.swing.DefaultComboBoxModel(new String[] { “–请选择季度–”, “第一季度”, “第二季度”, “第三季度”, “第四季度” }));
jButton1.setText(“查询”);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});jTable1.setModel(dtm);
jScrollPane1.setViewportView(jTable1);javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(44, 44, 44)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(28, 28, 28)
.addComponent(jseason, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(39, 39, 39)
.addComponent(jButton1))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jname, 0, 190, Short.MAX_VALUE)
.addGap(189, 189, 189))))
.addGroup(layout.createSequentialGroup()
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 399, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 378, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(56, 56, 56)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jseason, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(jButton1))
.addGap(20, 20, 20)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(50, Short.MAX_VALUE))
);pack();
}// //GEN-END:initComponents
}
结果截图