Recently I found that many private messages asked me for source code. Because I changed my computer several times, I searched for it, but I couldn't find it. At that time, I copied all the source codes. You can create the class files by yourself and then copy the code. I marked each file clearly at the head, and mainly used Java swing as the interface. It is recommended that you just learn from the interface. You can comment out the addEventListener event for other components such as buttons. After the interface is successfully run, add the event operation yourself.
Meaning
record
1. System development overview… 1
2. System planning… 1
3. Requirement analysis… 2
3.1 User requirements description… 2
3.1.1 Data requirements… 2
3.1.2 Transaction Requirements… 2
3.2 System requirements description… 2
4. Database logic design… 2
4.1 ER picture… 2
4.2 Data Dictionary… 2
4.3 Relationship Table… 2
5. Database physical design… 2
5.1 Index… 2
5.2 View… 2
5.3 Safety mechanism… 2
6. Application design… 3
6.1 Functional module… 3
6.2 Interface design… 3
6.3 Business Design… 3
7. Test and run… 3
8. Summary… 3
Attached. References… 3
1. System development overview
Project background:
With the advancement of science, some companies are constantly growing and growing, and urgently need a complete set of enterprise wage management systems to help the company's financial management department improve efficiency and realize the systematic, standardized and automated enterprise wage management. More and more human resources investment is also a huge limitation for the growing company, and corporate costs need to be reduced.
Purpose of writing:
1. Have a preliminary understanding and specific application of database technology, and the knowledge of database needs to be applied in detail and systematized.
2. Examine database analysis and creation capabilities and train team unity and cooperation awareness.
The significance of system implementation:
The development of computer technology in the information age brought a revolution to the life and work style of the entire society. The form and connotation of enterprise wage management in the traditional sense are undergoing essential changes. The previous form of salary management of one accounting and one accountant has been replaced by computers and financial software. The intervention of computers and related software has made the wage management of enterprises and institutions scientific, transparent and simplified. Therefore, according to the characteristics of different enterprises and institutions
It is very necessary to develop salary management software that suits you. The guiding ideology of this article is to consider everything for users, the interface is simple and the operation is as simple as possible.
2. System planning
Design tasks:
Task Topic: Employee Salary Management System of Enterprise Chapter (involving: department information, employee information, salary information, allowances, overtime wages, deductions and other entities.)
Requirements analysis (the members of the research team work together to strive for comprehensive and effective requirements analysis!).
Database design (data covers the system's data needs, and the relationship modes all reach 3NF, and you think about performance optimization yourself).
Data integrity (Analyze key data in key tables and formulate your own integrity constraint rules!).
Security (must have basic user and their permissions to control it!).
View (comprehensive consideration of operation convenience, data security, and data logical independence!).
Triggers (Does the triggers be adopted based on your understanding of the application? What are the benefits?).
Stored procedures (make your own judgment on the premise of fully understanding the system's business processing and use them properly!).
Index (reasonable design needs to be made based on the estimation of data volume, application characteristics, etc.).
System functions (as comprehensive as possible based on requirements analysis!).
User interface friendly (consider it from the user's perspective!)
Require:
Grouping: Developed according to the research group, each group has 3 to 4 people, one group leader, role division and task allocation.
Database platform: Oracle, MS SQL Seiver, MySQL.
Development platforms: NET, J2EE, PHP.
Software architecture: B/S, C/S.
Software environment and tools:
Software architecture: C/S.
Development tools: Eclipse, sql sever2008
3. Requirement analysis
3.1 User requirements description
3.1.1 Data Requirements
Employee number
char(8) main code: stanum(staff number)
Employee name varchar(10): staname (staff name)
Employee Gender char(2) Gender can only be for men and women: stasex(staff sex)
Job name varchar(14) 7 Chinese characters less than or equal to
:notp(name of the position)
Job number char(4): dtnum(duty number)
Working years numeric(2,0) Range 1~99: wyear (working year)
Salary level numeric(2,0) Range 1~10: wbk (wage bracket)
Department number char(4)
Department name varchar(14): depname(department number)
Manager employee number: char(8) mgnum
Manager name: varchar(10) mgname
Attendance days numeric(2,0) Range 0~30 atd(attendance day)
Number of overtime days
numeric(2,0) range 0~30 otd(overtime day)
Late days numeric(2,0) Range 0~30 tdd(tardy day)
Basic wage int: bw (basic wage)
Allowance float: allo (allowance)
Deduct money float: whop (withholding of payment)
Bonus float: pm (prize money)
username
char(8) :users_name
Password varchar(10): passwords
Permission numeric(2,0) Range 1~10: aut(authority)
3.1.2 Transaction Requirements
(1) Basic salary setting
(2) Setting of allowances
There is a night shift allowance for overtime people.
(3) Calculate monthly salary
Monthly salary = basic salary + remaining salary (bonus + overtime salary + leave + late arrival + allowance) - deducted funds, the monthly salary is equal to the actual salary = salary should be paid - the personal payment part of the five insurances and one fund - the personal income tax to be paid (wage and salary income
- "Five Insurance and One Fund" - Deduction Number) × Applicable Tax Rate - Quick Calculation of Deduction Number).
(4) Enter employee salary information
Employee salary information is entered by the administrator.
(5) Add employee salary information
Employee information is added by the administrator. Through operations, the administrator inserts an employee information into the database.
(6) Change employee salary information
3.2 System requirements description
System requirements functional framework diagram:
IV. Database logic design
4.1 ER diagram
4.2 Data Dictionary
serial number
Data item name
Data item meaning
type
illustrate
1
stanum
Employee number
char(8)
The most basic definition of judging employees
2
staname
Employee name
varchar(10)
3
stasex
Employee Gender
char(2)
Only enter male and female
4
dtnum
Job number
char(4)
5
wyear
Work experience
numeric(2,0)
6
wbk
Salary Level
numeric(2,0)
Judging employees' wages
What is the basic salary
7
depnum
Department number
char(4)
The most basic definition of the judgment department
8
depname
Department name
varchar(14)
9
mgnum
Manager employee number
char(8)
10
mgname
Manager name
varchar(10)
11
atd
Number of days of attendance
numeric(2,0)
The maximum number of days is 30 days
12
otd
Number of overtime days
numeric(2,0)
The maximum number of days is 30 days
13
tdd
Late days
numeric(2,0)
The maximum number of days is 30 days
14
notp
Job title
varchar(30)
15
bw
Basic salary
int
16
allo
allowance
float
17
whop
Deduct money on behalf of
float
18
pm
bonus
float
19
users_name
username
char(8)
20
passwords
password
varchar(10)
21
aut
Permissions
numeric(2,0)
Range 1~10
4.3 Relationship Table
-
Employee information table: staff(stanum, staname, stasex, dtnum, wyear, wbk) main code: stanum
-
Department information table: department(depnum,depname,mgnum,mgname) Main code: depnum
-
Attendance status table: attendance(stanum,atd,otd,tdd) Main code: stanum
-
Job information table: duty(dtnum,notp) Main code: dtnum
-
Salary calculation table: wage(stanum,bw,allo,whop,pm) Main code: stanum
-
User information table: users(users_name,passwords,aut,stanum) Main code: users_name
5. Database physical design
5.1 Index
5.2 Security mechanism
trigger:
1. Create a trigger for the attendance table (attendence).
insert_att, insertion is not allowed when the number of late days is greater than the number of attendance days.
create trigger att_insert
on attendance for insert
as
begin
if exists(select*from inserted
where
atd<tdd)
Begin
raiseerror('Insertion is not allowed',16,8)
rollback
tran
end
end
2. Create a trigger for the attendance table (attendence).
insert_att, update is not allowed when the number of late days is greater than the number of attendance days.
create trigger att_update
on attendance for update
as
begin
if exists(select*from deleted where
atd<tdd)
Begin
raiseerror('Updated not allowed',16,8)
rollback
tran
end
end
3. For the wage calculation table (wage), create a trigger wage_update. When the deduction is greater than the basic salary, updates are not allowed.
create trigger wage_update
on wage for update
as
begin
if exists(select*from deleted
where
allo<whop)
Begin
raiseerror('Updated not allowed',16,8)
rollback
tran
end
end
Stored procedure:
1.Storing and querying salary list information c_wage_info
2. Store create new user dbo.new_users
3. Store delete_stanum
4. Store create new employees c_new_staff
6. Application Design
6.1 Functional Module
System function implementation flow chart:
- Information input function
(1) Enter basic information about the employee. Including: employee number, name, gender, date of birth, working hours, department, position, title, political appearance, marital status and other basic information.
(2) Enter the employee’s salary information. Including: basic salary, job salary, housing subsidies, allowances, housing provident fund, and pension insurance.
(3) Enter the employee's department information. Including: department number, department name, department head, department number.
2. Data modification and deletion function
1. Modify and delete basic information of employees. When the information of the unit’s personnel changes, such as changes in professional titles, changes in work departments, or transfers from the unit, the system should be able to modify the employee information or delete it.
2. Modify and delete employee salary information. Employee promotion and salary increase and general salary adjustment are common things in enterprises, which requires the system to easily modify employees' wages individually and in batches; if an employee is transferred from the unit, the employee information should be deleted from the employee information table and the corresponding data in his salary information should be deleted.
3. Modify and delete departmental information. When a department is revoked, it should be deleted from the department information bid. When the name of a department changes, all the names of that department in the system should be changed consistently.
3. Payroll management function
(1) Salary calculation
Before calculating wages, the administrator needs to determine the payment of basic wages, the remaining wages and deductions based on the work of each part. According to different professional titles, different parts divide different wage levels. The monthly salary should be paid = basic wage + remaining wages (bonus + overtime salary + leave + lateness + allowance) - deductions, the monthly actual salary is equal to the actual salary = salary should be paid - the part of the individual paid by five insurances and one fund - the personal income tax to be paid (wage and salary income - "five insurances and one fund" - deductions) × applicable tax rate - quick deductions). After calculating the actual salary, the salary is paid to each person's email through email. The system uses bank transfers to employees by generating bank transfers and processing.
(2) Salary Statistical Analysis
After calculating employee wage data, the salary information should be statistically analyzed, such as summary statistics, salary item details, data summary, etc., which are divided into statistical analysis of employee personal wages, department wage statistics, monthly wage statistics analysis, quarterly wage statistics analysis,
Annual salary analysis statistics. The statistical analysis results can display statistical results in the form of bar charts and pie charts. Finally, it is fed back to senior management through reports in a very intuitive and clear manner. At this time, the employee’s personal salary information statistics table and departmental salary information statistics table should be formed in the database.
4. Salary query function
In the client's query module, our employees can query their own salary, but they cannot query other employees' salaries; people at different levels will divide different functions according to their permissions, and people at different levels cannot query over the authority, otherwise they will be prompted beyond the bounds. During the query, the employee login will count the number of people. When the number of people inquiry is greater than the number of people allowed in the system, the system will prevent new users from querying, let new users wait, and avoid the system's rapid response.
5. Report generation and printing
When an employee receives his salary, the system automatically generates a salary slip and sends it to the employee's email address: the personal salary composition, the salary to be paid and the actual salary; the information is automatically updated when the employee receives the salary, and the department's monthly and quarterly reports are automatically formed, and the annual report is for subsequent work needs.
6. System maintenance
When using it, users need to complete the initialization settings: that is, the admission of employee information, position, and salary standards to form a salary system for easier future calculations. The system needs to complete password modification when the user logs in for the first time. When the employee system enters, the number of data users will be automatically recorded, and the user will automatically wait after exceeding the system capacity. When using the salary system, a log is automatically formed every month to facilitate subsequent work and a monthly report is automatically formed at the end of the month. When the system is running, the database administrator can also modify the data.
6.2 Interface design
Employee information function interface: mainly includes employee information function and salary information function.
Employee information query window interface: Business logic is to query based on the employee number of currently logged in employee and display it.
Employee information modification window interface: Employees can modify their username and password.
6.3 Transaction Design
(1) Basic salary setting
(2) Setting of allowances
There is a night shift allowance for overtime people.
(3) Calculate monthly salary
Monthly salary = basic salary + remaining salary (bonus + overtime salary + leave + late arrival + allowance) - deducted funds, the monthly salary is equal to the actual salary = salary should be paid - the personal payment part of the five insurances and one fund - the personal income tax to be paid (wage and salary income
- "Five Insurance and One Fund" - Deduction Number) × Applicable Tax Rate - Quick Calculation of Deduction Number).
(4) Enter employee salary information
Employee salary information is entered by the administrator.
Employee number
Job title
Basic salary
allowance
Deduct money on behalf of
bonus
20180001
Human Resources Department Manager
8000
2000
1000
1500
20180002
Development Department Manager
8000
2000
1000
1500
20180003
Demand Analysis Department Manager
8000
2000
1000
1500
20180004
Canteen Department Manager
8000
2000
1000
1500
20180005
Security Department Manager
8000
2000
1000
1500
20180006
Operations and maintenance department manager
8000
2000
1000
1500
20180007
Marketing Department Manager
8000
2000
1000
1500
20180008
Human Resources Employees
5000
1200
400
1200
20180009
Human Resources Employees
5000
1200
400
1200
20180010
Human Resources Employees
5000
1200
400
1200
20180011
Human Resources Employees
5000
1200
400
1200
20180012
Human Resources Employees
5000
1200
400
1200
20180013
Development Department Employees—C++
7000
3000
1200
1100
20180014
Development Department Employees—C++
7000
3000
1200
1100
20180015
Development Department Employees—C++
7000
3000
1200
1100
20180016
Development Department Employees—Java
6500
3000
1200
1100
(5) Add employee salary information
Employee information is added by the administrator. Through operations, the administrator inserts an additional employee information into the database.
(6) Change employee salary information
For employee salary information, it can only be modified by the administrator, which is a design for database security.
7. Test and run
It introduces the testing situation of the system and provides several test cases.
Optional: Generate large amounts of simulation data and perform performance testing.
8. Summary
Course design experience:
This course design will make me remember it deeply. On the one hand, because due to this epidemic, we cannot return to school and can only do experiments online. On the other hand, I deeply feel the spirit of teamwork. During the course design period, we will discuss what to do in advance before each course setting task. During the process, we kept on voice to communicate and discuss. If there are any problems, we will discuss in time, solve in time, and brainstorm to make the course setting task more efficient. We used one morning to build the database, and the next few times, we conducted interface design, database connection, and modification problems to improve insufficient improvement. Although the course design is online, we still overcome difficulties, actively communicate and solve problems. This teamwork spirit makes us more efficient.
System features:
Our entire database system reaches the 3nf paradigm, meeting the requirements of the system. At the same time, we have established triggers and stored procedures for the operations of some things. When some conditions are not met, we reject the operation of the database, which fully meets the secure design of the database system. In addition, our entire system logic functions are clear, not cumbersome, and easy to get started.
System shortcomings:
Our system still has some shortcomings. When we were conducting the class defense, we also found problems. After the teacher's patient explanation and guidance, we found some problems, such as the database was not indexed, the data query efficiency was low, and so on. Later, after our discussion and modification, the entire system was improved, the index was established, and the problem was solved.
Attached. System implementation source code
// (Login interface)
package wagemanager;
import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class login_windows extends JFrame{
public
void create_login(login_windows l1) {
setTitle("Welcome to use the company's salary management system");
setLayout(null);
this.getContentPane().setBackground(Color.white);
JButton
button1 = new JButton("administrator");
JButton
button2 = new JButton("User");
JButton
button3 = new JButton("Log in");
button3.setEnabled(false);
setSize(500,
400);
setLocation(500,
300);
JTextField
users_name = new JTextField();
JPasswordField
password = new JPasswordField();
users_name.setEnabled(false);
password.setEnabled(false);
JLabel
users = new JLabel("username:");
JLabel
pass = new JLabel("password:");
JLabel
s1 = new JLabel("Luan x");
JLabel
s2 = new JLabel("xxx");
JLabel
s3 = new JLabel("Liu xx");
JLabel
s4 = new JLabel("Zhang xx");
s1.setFont(new
Font (Font.DIALOG, Font.BOLD, 12));
s2.setFont(new
Font (Font.DIALOG, Font.BOLD, 12));
s3.setFont(new
Font (Font.DIALOG, Font.BOLD, 12));
s4.setFont(new
Font (Font.DIALOG, Font.BOLD, 12));
s1.setForeground(Color.white);
s2.setForeground(Color.white);
s3.setForeground(Color.white);
s4.setForeground(Color.white);
users.setForeground(Color.white);
pass.setForeground(Color.white);
ImageIcon
pic = new ImageIcon("e:\\Pictures\\Technology Background.jpg");
JLabel
L2 = new JLabel(pic);
pic.setImage(pic.getImage().getScaledInstance(500,
400,Image.SCALE_DEFAULT));
L2.setBounds(0,
0, pic.getIconWidth(), pic.getIconHeight());
s1.setBounds(375,
310, 60, 20);
s2.setBounds(375,
330, 60, 20);
s3.setBounds(430,
310, 60, 20);
s4.setBounds(430,
330, 60, 20);
users.setBounds(85,
185, 70, 30);
pass.setBounds(85,
230, 70, 30);
users_name.setBounds(155,
180, 230, 30);
password.setBounds(155,
230, 230, 30);
button1.setBounds(100,
100, 100, 30);
button2.setBounds(275,
100, 100, 30);
button3.setBounds(200,
285, 100, 30);
add(users_name);
add(password);
add(button1);//administrator
add(button2);//staff
add(button3);
add(users);
add(pass);
add(s1);
add(s2);
add(s3);
add(s4);
add(L2);
setVisible(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
button2.addActionListener(new
ActionListener() {
public
void actionPerformed(ActionEvent e) {
button3.setEnabled(true);
users_name.setEnabled(true);
password.setEnabled(true);
button3.addActionListener(new
ActionListener() {
@Override
public
void actionPerformed(ActionEvent e) {
String
driverName="";
String
dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=Course Settings";
String
userName="sa";String userPwd="188754752";
try{
Class.forName(driverName);
//("Loading driver successfully!");
}catch(Exception
es){
es.printStackTrace();System.out.println("Loading driver failed!");
}
String
u1 = users_name.getText();
char[]
p1 = password.getPassword();
String
pp = String.valueOf(p1);
String
sta_name = null;
//(u1);
//(p1);
try(Connection
dbConn=DriverManager.getConnection(dbURL,userName,userPwd)){
try(Statement
st = dbConn.createStatement()){
try
(ResultSet rs = st.executeQuery("SELECT users_name,passwords,stanum FROM
users WHERE users_name="+"'"+u1+"'"+"and
passwords="+"'"+pp+"'"+" ")){
//(p1);
while(rs.next())
{
if(rs.getString(1).equals(u1)
&& rs.getString(2).equals(pp)) {
windows
w1 = new windows();
w1.create();
l1.dispose();
sta_name
= rs.getString(3);
w1.get1(sta_name);
//(sta_name);
}
}
// (pp);
}
}
//("Connecting to the database successfully!");
dbConn.close();
}catch(Exception
es){
es.printStackTrace();System.out.print("SQL
ServerConnection failed! ");
}
}
});
}
});
button1.addActionListener(new
ActionListener() {
public
void actionPerformed(ActionEvent e) {
button3.setEnabled(true);
users_name.setEnabled(true);
password.setEnabled(true);
button3.addActionListener(new
ActionListener() {
@Override
public
void actionPerformed(ActionEvent e) {
String
driverName="com. ";
String
dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=Course Settings";
String
userName="sa";String userPwd="188754752";
try{
Class.forName(driverName);
//("Loading driver successfully!");
}catch(Exception
es){
es.printStackTrace();System.out.println("Loading driver failed!");
}
String
u1 = users_name.getText();
char[]
p1 = password.getPassword();
String
pp = String.valueOf(p1);
String
sta_name = null;
//(u1);
//(p1);
try(Connection
dbConn=DriverManager.getConnection(dbURL,userName,userPwd)){
try(Statement
st = dbConn.createStatement()){
try
(ResultSet rs = st.executeQuery("SELECT users_name,passwords,stanum FROM
users WHERE users_name='y0000048' and passwords='1234567890' ")){
//(p1);
while(rs.next())
{
if(rs.getString(1).equals(u1)
&& rs.getString(2).equals(pp)) {
admin
ad = new admin();
ad.create_admin();
l1.dispose();
sta_name
= rs.getString(3);
//ad.get1(sta_name);
//(sta_name);
}
else{
//("11111");
}
}
// (pp);
}
}
//("Connecting to the database successfully!");
dbConn.close();
}catch(Exception
es){
es.printStackTrace();System.out.print("SQL
ServerConnection failed! ");
}
}
});
}
});
}
public
static void main(String[] args) {
login_windows
l1 = new login_windows();
l1.create_login(l1);
}
}
2.Admin.java (admin function interface)package wagemanager;
import java.sql.*;
import java.text.MessageFormat;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.*;
public class admin extends JFrame{
String
stanu = null;
public
void create_admin() {
setTitle("administrator");
JLabel
L1 = new JLabel("manage
Member interface");
L1.setFont(new
Font (Font.DIALOG, Font.BOLD, 25));
L1.setForeground(Color.white);
//().setBackground();
//background
ImageIcon
pic = new ImageIcon("e:\\Pictures\\Technology Background.jpg");
JLabel
L2 = new JLabel(pic);
pic.setImage(pic.getImage().getScaledInstance(500,
400,Image.SCALE_DEFAULT));
L2.setBounds(0,
0, pic.getIconWidth(), pic.getIconHeight());
ImageIcon
wage = new ImageIcon("e:\\picture\\salary.jpg");
wage.setImage(wage.getImage().getScaledInstance(75,
75,Image.SCALE_DEFAULT));
JLabel wage_pic = new JLabel(wage);
wage_pic.setBounds(100,
250, 75, 75);
ImageIcon
sta = new ImageIcon("e:\\Pictures\\Employees.jpg");
sta.setImage(sta.getImage().getScaledInstance(75,
75,Image.SCALE_DEFAULT));
JLabel
sta_pic = new JLabel(sta);
sta_pic.setBounds(100,
150, 75, 75);
JButton
button1 = new JButton("Employee Management");
JButton
button2 = new JButton("Wage Management");
Container
c = getContentPane();
setLayout(null);
button1.setBounds(200,
150, 200, 75);
button2.setBounds(200,
250, 200, 75);
L1.setBounds(145,
50, 275, 75);
add(button1);
add(button2);
add(wage_pic);
add(sta_pic);
add(L1);
add(L2);
setSize(500,
400);
setLocation(500,
300);
setVisible(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
button1.addActionListener(new
ActionListener() {
@Override
public
void actionPerformed(ActionEvent arg0) {
admin_sta
ads1 = new admin_sta();
ads1.create_adsta();
}
});
button2.addActionListener(new
ActionListener() {
@Override
public
void actionPerformed(ActionEvent arg0) {
admin_wage
adw1 = new admin_wage();
adw1.create_adwage();
}
});
}
public
static void main(String[] args) {
admin
a1 = new admin();
a1.create_admin();
}
}
3.Admin_sta.java&&admin_wage.java (Administrator's employee information and employee salary management)package
wagemanager;
import
java.awt.*;
import
java.awt.event.ActionEvent;
import
java.awt.event.ActionListener;
import
java.sql.*;
import
javax.swing.*;
import
javax.swing.table.*;
public class
admin_sta extends JFrame{
public void
create_adsta() {
JFrame
windows2 = new JFrame("Manage employee window");
windows2.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
windows2.setSize(500,
400);
windows2.setLocation(500,
300);
Container
co = windows2.getContentPane();
//
JPanel p = new JPanel();
co.setLayout(null);
ImageIcon
pic = new ImageIcon("e:\\Pictures\\Technology Background.jpg");
JLabel
L2 = new JLabel(pic);
pic.setImage(pic.getImage().getScaledInstance(500,
400,Image.SCALE_DEFAULT));
L2.setBounds(0,
0, pic.getIconWidth(), pic.getIconHeight());
JButton
b1 = new JButton("Query employee information");
JButton
b2 = new JButton("Modify employee information");
JButton
b3 = new JButton("Add employee information");
JButton
b4 = new JButton("Delete employee information");
b1.setBounds(60,
50, 150, 30);
b2.setBounds(260,
50, 150, 30);
b3.setBounds(60,
100, 150, 30);
b4.setBounds(260,
100, 150, 30);
co.add(b1);
co.add(b2);
co.add(b3);
co.add(b4);
co.add(L2);
windows2.setVisible(true);
b1.addActionListener(new ActionListener() {
@Override
public
void actionPerformed(ActionEvent e) {
JFrame
w2 = new JFrame("Query employee information");
w2.setBounds(500,
300, 600, 445);
w2.setLayout(null);
DefaultTableModel
model=new DefaultTableModel();
JTable
table=new JTable(model);
JScrollPane
jsp=new JScrollPane(table);
jsp.setBounds(0,
0, 585, 400);
w2.add(jsp);
String
driverName="";
String
dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=Course Settings";
String
userName="sa";String userPwd="188754752";
try{
Class.forName(driverName);
//("Loading driver successfully!");
}catch(Exception
ea){
ea.printStackTrace();System.out.println("Loading driver failed!");
}
try(Connection
dbConn=DriverManager.getConnection(dbURL,userName,userPwd)){
try(Statement
st = dbConn.createStatement()){
try
(ResultSet rs = st.executeQuery("SELECT * FROM staff")){
ResultSetMetaData
rsmd=rs.getMetaData();
int numb=rsmd.getColumnCount();
for(int i=1;i<=numb;i++){
model.addColumn(rsmd.getColumnName(i));
}
String[] row=new String[numb];
while(rs.next())
{
// Assign each row of data to the array
for(int
i=0;i<numb;i++)
row[i]=rs.getString(i+1);
model.addRow(row);
}
//(bw);
}
}
//("Connecting to the database successfully!");
dbConn.close();
}catch(Exception
ea){
ea.printStackTrace();System.out.print("SQL
ServerConnection failed! ");
}
w2.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
w2.setVisible(true);
}
});
b2.addActionListener(new ActionListener() {
@Override
public
void actionPerformed(ActionEvent e) {
sta_change
stach = new sta_change();
stach.create_stacha();
}
});
b3.addActionListener(new ActionListener() {
@Override
public
void actionPerformed(ActionEvent e) {
sta_add
s1 = new sta_add();
s1.create_sta_add();
}
});
b4.addActionListener(new ActionListener() {
@Override
public
void actionPerformed(ActionEvent e) {
sta_delete
d1 = new sta_delete();
d1.create_stadel();
}
});
}
public
static void main(String[] args) {
admin_sta
ad = new admin_sta();
ad.create_adsta();
}
}
package
wagemanager;
import
java.awt.*;
import
java.awt.event.ActionEvent;
import
java.awt.event.ActionListener;
import
java.sql.*;
import
javax.swing.*;
import
javax.swing.table.*;
public class
admin_wage extends JFrame{
public void
create_adwage() {
setSize(500,
400);
setLocation(500,
300);
setLayout(null);
ImageIcon
pic = new ImageIcon("e:\\Pictures\\Technology Background.jpg");
JLabel
L2 = new JLabel(pic);
pic.setImage(pic.getImage().getScaledInstance(500,
400,Image.SCALE_DEFAULT));
L2.setBounds(0,
0, pic.getIconWidth(), pic.getIconHeight());
JButton
click = new JButton("Inquiry of salary");
JButton
change = new JButton("Modify wages");
click.setBounds(150,
100, 200, 75);
change.setBounds(150,
210, 200, 75);
add(click);
add(change);
add(L2);
setVisible(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
click.addActionListener(new
ActionListener() {
@Override
public
void actionPerformed(ActionEvent e) {
JFrame
w2 = new JFrame("Inquiry of salary");
w2.setBounds(500,
300, 600, 445);
w2.setLayout(null);
DefaultTableModel
model=new DefaultTableModel();
JTable
table=new JTable(model);
JScrollPane
jsp=new JScrollPane(table);
jsp.setBounds(0,
0, 585, 400);
w2.add(jsp);
String
driverName="";
String
dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=Course Settings";
String
userName="sa";String userPwd="188754752";
try{
Class.forName(driverName);
//("Loading driver successfully!");
}catch(Exception
ea){
ea.printStackTrace();System.out.println("Loading driver failed!");
}
try(Connection
dbConn=DriverManager.getConnection(dbURL,userName,userPwd)){
try(Statement
st = dbConn.createStatement()){
try
(ResultSet rs = st.executeQuery("SELECT * FROM wage")){
ResultSetMetaData
rsmd=rs.getMetaData();
int numb=rsmd.getColumnCount();
for(int i=1;i<=numb;i++){
model.addColumn(rsmd.getColumnName(i));
}
String[] row=new String[numb];
while(rs.next())
{
// Assign each row of data to the array
for(int
i=0;i<numb;i++)
row[i]=rs.getString(i+1);
model.addRow(row);
}
//(bw);
}
}
//("Connecting to the database successfully!");
dbConn.close();
}catch(Exception
ea){
ea.printStackTrace();System.out.print("SQL
ServerConnection failed! ");
}
w2.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
w2.setVisible(true);
}
});
change.addActionListener(new
ActionListener() {
@Override
public
void actionPerformed(ActionEvent e) {
JFrame
wch = new JFrame("Modify wages");
wch.setBounds(500,
300, 500, 400);
wch.setLayout(null);
JTextField
t1 = new JTextField(10);
JTextField
t2 = new JTextField(10);
JTextField
t3 = new JTextField(10);
JTextField
t4 = new JTextField(10);
JTextField
t5 = new JTextField(10);
JLabel
lab1 = new JLabel("Employee number:");
JLabel
lab2 = new JLabel("Basic salary:");
JLabel
lab3 = new JLabel("Please:");
JLabel
lab4 = new JLabel("Deducted money:");
JLabel
lab5 = new JLabel("bonus:");
JButton
jb0 = new JButton("Revise");
ImageIcon
pic = new ImageIcon("e:\\Pictures\\Technology Background.jpg");
JLabel L_5 = new JLabel(pic);
pic.setImage(pic.getImage().getScaledInstance(500,
400,Image.SCALE_DEFAULT));
L_5.setBounds(0,
0, pic.getIconWidth(), pic.getIconHeight());
lab1.setForeground(Color.white);
lab2.setForeground(Color.white);
lab3.setForeground(Color.white);
lab4.setForeground(Color.white);
lab5.setForeground(Color.white);
lab1.setBounds(85,
20, 100, 20);
lab2.setBounds(85,
60, 100, 20);
lab3.setBounds(85,
100, 100, 20);
lab4.setBounds(85,
140, 100, 20);
lab5.setBounds(85,
180, 100, 20);
t1.setBounds(140,
20, 200, 20);
t2.setBounds(140,
60, 200, 20);
t3.setBounds(140,
100, 200, 20);
t4.setBounds(140,
140, 200, 20);
t5.setBounds(140,
180, 200, 20);
jb0.setBounds(160,
300, 120, 20);
wch.add(t1);
wch.add(t2);
wch.add(t3);
wch.add(t4);
wch.add(t5);
wch.add(lab1);
wch.add(lab2);
wch.add(lab3);
wch.add(lab4);
wch.add(lab5);
wch.add(jb0);
wch.add(L_5);
wch.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
wch.setVisible(true);
jb0.addActionListener(new
ActionListener() {
@Override
public
void actionPerformed(ActionEvent e) {
try
{
String
driverName = "";// Connect to the database
String
dbURL = "jdbc:sqlserver://localhost:1433;DatabaseName=Course Settings";
String
userName = "sa";
String
userPwd = "188754752";
String
usr = t1.getText();
Class.forName(driverName);
try
{
Connection
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
int
count2 = 0;
int
count3 = 0;
int
count4 = 0;
int
count5 = 0;
if(!t2.getText().trim().equals(""))
{
String
sql3 = "update wage set bw = ?
where stanum="+ usr + "";
PreparedStatement
ps3 = dbConn.prepareStatement(sql3);
ps3.setString(1,
t2.getText());
count2
= ps3.executeUpdate();
}
if(!t3.getText().trim().equals(""))
{
String sql4 = "update wage set
allo = ? where stanum="+ usr + "";
PreparedStatement
ps4 = dbConn.prepareStatement(sql4);
ps4.setString(1,
t3.getText());
count3
= ps4.executeUpdate();
}
if(!t4.getText().trim().equals(""))
{
String
sql5 = "update wage set whop = ?
where stanum="+ usr + "";
PreparedStatement
ps5 = dbConn.prepareStatement(sql5);
ps5.setString(1,
t4.getText());
count4
= ps5.executeUpdate();
}
if(!t5.getText().trim().equals(""))
{
String
sql6 = "update wage set pm = ?
where stanum="+ usr + "";
PreparedStatement
ps6 = dbConn.prepareStatement(sql6);
ps6.setString(1,
t5.getText());
count5
= ps6.executeUpdate();
}
if
(count2 > 0) {
System.out.println("Basic salary modification was successful");
}if(count3
> 0) {
System.out.println("Successful modification of allowance");
}if(count4
>0) {
System.out.println("The deduction is modified successfully");
}if(count5>0)
{
System.out.println("Bonus modification was successful");
}
if(!(count2
> 0||count3 > 0||count4 > 0||count5 > 0)) {
System.out.println("Modification failed");
JOptionPane.showMessageDialog(null,
"Modification failed!",
"mistake",
JOptionPane.ERROR_MESSAGE);
}
dbConn.close();
}
catch (SQLException e1) {
e1.printStackTrace();
//
System.out.println("Loading the driver successfully!");
JOptionPane.showMessageDialog(null,
"Database connection failed!",
"mistake",
JOptionPane.ERROR_MESSAGE);
}
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Loading driver failed!");
JOptionPane.showMessageDialog(null,
"Loading driver failed!",
"mistake",
JOptionPane.ERROR_MESSAGE);
}
}
});
}
});
}
public
static void main(String[] args) {
//
}
}
4.Sta_add&&&sta_change &&stadelete.java (specific implementation of employee functions)package wagemanager;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.sql.*;
public class sta_add extends JFrame{
public
void create_sta_add() {
setSize(500,
400);
setLocation(500,
300);
setLayout(null);
ImageIcon
pic = new ImageIcon("e:\\Pictures\\Technology Background.jpg");
JLabel
L2 = new JLabel(pic);
pic.setImage(pic.getImage().getScaledInstance(500,
400,Image.SCALE_DEFAULT));
L2.setBounds(0,
0, pic.getIconWidth(), pic.getIconHeight());
JTextField
stanum = new JTextField();
JTextField
staname = new JTextField();
JTextField
stasex = new JTextField();
JTextField
dtnum = new JTextField();
JTextField
wyear = new JTextField();
JTextField
wbk = new JTextField();
JTextField
depnum = new JTextField();
JTextField
bw = new JTextField();
JTextField
allo = new JTextField();
JTextField
whop = new JTextField();
JTextField
pm = new JTextField();
JLabel
stanu = new JLabel("staff
Number:");
JLabel
stana = new JLabel("Employee name:");
JLabel
stase = new JLabel("Employee Gender:");
JLabel
dtnu = new JLabel ("Position number:");
JLabel
wyea = new JLabel ("Working age:");
JLabel
wb = new JLabel ("Wage Level:");
JLabel
depnu = new JLabel("department
Number:");
JLabel
bw_1 = new JLabel("Basic salary:");
JLabel
allo_1 = new JLabel("Please:");
JLabel
whop_1 = new JLabel("Deducted money:");
JLabel
pm_1 = new JLabel("bonus:");
JButton
addbtn = new JButton("Add employees");
stanu.setForeground(Color.white);
stana.setForeground(Color.white);
stase.setForeground(Color.white);
dtnu.setForeground(Color.white);
wyea.setForeground(Color.white);
wb.setForeground(Color.white);
depnu.setForeground(Color.white);
bw_1.setForeground(Color.white);
allo_1.setForeground(Color.white);
whop_1.setForeground(Color.white);
pm_1.setForeground(Color.white);
stanu.setBounds(90,
20, 60, 20);
stana.setBounds(90,
45, 60, 20);
stase.setBounds(90,
70, 60, 20);
dtnu.setBounds(90,
95, 60, 20);
wyea.setBounds(90,
120, 60, 20);
wb.setBounds(90,
145, 60, 20);
depnu.setBounds(90,
170, 60, 20);
bw_1.setBounds(90,
195, 60, 20);
allo_1.setBounds(90,
220, 60, 20);
whop_1.setBounds(90,
245, 60, 20);
pm_1.setBounds(90,
270, 60, 20);
stanum.setBounds(150,
20, 220, 20);
staname.setBounds(150,
45, 220, 20);
stasex.setBounds(150,
70, 220, 20);
dtnum.setBounds(150,
95, 220, 20);
wyear.setBounds(150,
120, 220, 20);
wbk.setBounds(150,
145, 220, 20);
depnum.setBounds(150,
170, 220, 20);
bw.setBounds(150,
195, 220, 20);
allo.setBounds(150,
220, 220, 20);
whop.setBounds(150,
245, 220, 20);
pm.setBounds(150,
270, 220, 20);
addbtn.setBounds(190,
300, 90, 30);
add(stanum);
add(staname);
add(stasex);
add(dtnum);
add(wyear);
add(wbk);
add(depnum);
add(stanu);
add(stana);
add(stase);
add(dtnu);
add(wyea);
add(wb);
add(depnu);
add(bw);
add(allo);
add(whop);
add(pm);
add(bw_1);
add(allo_1);
add(whop_1);
add(pm_1);
add(addbtn);
add(L2);
//(x,
y, width, height);
setVisible(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
addbtn.addActionListener(new
ActionListener() {
@Override
public
void actionPerformed(ActionEvent e) {
String
driverName="";
String
dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=Course Settings";
String
userName="sa";String userPwd="188754752";
try{
Class.forName(driverName);
//("Loading driver successfully!");
}catch(Exception
ea){
ea.printStackTrace();System.out.println("Loading driver failed!");
}
try(Connection
dbConn=DriverManager.getConnection(dbURL,userName,userPwd)){
try(PreparedStatement
st = dbConn.prepareStatement("insert into staff
values(?,?,?,?,?,?,?)")){
st.setString(1,
stanum.getText());
st.setString(2,
staname.getText());
st.setString(3,
stasex.getText());
st.setString(4,
dtnum.getText());
st.setString(5,
wyear.getText());
st.setString(6,
wbk.getText());
st.setString(7,
depnum.getText());
st.executeUpdate();
}
try(PreparedStatement
st = dbConn.prepareStatement("insert into wage values(?,?,?,?,?)")){
st.setString(1,
stanum.getText());
st.setString(2,
bw.getText());
st.setString(3,
allo.getText());
st.setString(4,
whop.getText());
st.setString(5,
pm.getText());
st.executeUpdate();
}
//("Connecting to the database successfully!");
dbConn.close();
}catch(Exception
ea){
ea.printStackTrace();System.out.print("SQL
ServerConnection failed! ");
}
}
});
}
}
package wagemanager;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowStateListener;
import java.security.PKCS12Attribute;
import java.sql.*;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
public class sta_change extends JFrame{
public void create_stacha() {
setTitle("Employee Information");
Container
c1 = getContentPane();
setLayout(null);
setSize(500,
400);
setLocation(500,
300);
setVisible(true);
ImageIcon
pic = new ImageIcon("e:\\Pictures\\Technology Background.jpg");
JLabel
L2 = new JLabel(pic);
pic.setImage(pic.getImage().getScaledInstance(500,
400,Image.SCALE_DEFAULT));
L2.setBounds(0,
0, pic.getIconWidth(), pic.getIconHeight());
JButton
button1 = new JButton("Revise");
JTextField
t1 = new JTextField(null);
JTextField
t2 = new JTextField(null);
//JTextField
t3 = new JTextField(20);
//JTextField
t4 = new JTextField(20);
JTextField
t5 = new JTextField(null);
//JTextField
t6 = new JTextField(20);
JTextField
t7 = new JTextField(null);
JTextField
t8 = new JTextField(null);
JLabel
lab1 = new JLabel("Employee number:");
JLabel
lab2 = new JLabel("Employee name:");
//JLabel
lab3 = new JLabel("Employee Gender:");
//JLabel
lab4 = new JLabel("Telephone Name:");
JLabel
lab5 = new JLabel("Position number:");
//JLabel
lab6 = new JLabel("Working age:");
JLabel
lab7 = new JLabel("Wage Level:");
JLabel
lab8 = new JLabel("department
Number:");
lab1.setForeground(Color.white);
lab2.setForeground(Color.white);
lab5.setForeground(Color.white);
lab7.setForeground(Color.white);
lab8.setForeground(Color.white);
lab1.setBounds(85,
20, 200, 20);
lab2.setBounds(85,
60, 200, 20);
//(85,
80, 200, 20);
//(85,
80, 200, 20);
lab5.setBounds(85,
100, 200, 20);
//(85,
170, 200, 20);
lab7.setBounds(85,
140, 200, 20);
lab8.setBounds(85,
180, 200, 20);
button1.setBounds(160,
250, 120, 20);
t1.setBounds(140,
20, 200, 20);
t2.setBounds(140,
60, 200, 20);
//(140,
80, 200, 20);
//(140,
80, 200, 20);
t5.setBounds(140,
100, 200, 20);
//(140,
170, 200, 20);
t7.setBounds(140,
140, 200, 20);
t8.setBounds(140,
180, 200, 20);
c1.add(t1);
c1.add(t2);
//(t3);
//(t4);
c1.add(t5);
//(t6);
c1.add(t7);
c1.add(t8);
c1.add(lab1);
c1.add(lab2);
//(lab3);
//(lab4);
c1.add(lab5);
//(lab6);
c1.add(lab7);
c1.add(lab8);
c1.add(button1);
c1.add(L2);
button1.addActionListener(new
ActionListener() {
@Override
public
void actionPerformed(ActionEvent e) {
try
{
String
driverName = "";// Connect to the database
String
dbURL = "jdbc:sqlserver://localhost:1433;DatabaseName=Course Settings";
String
userName = "sa";
String
userPwd = "188754752";
String
usr = t1.getText();
Class.forName(driverName);
try
{
Connection
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
int
count2 = 0;
int
count4 = 0;
int
count5 = 0;
int
count6 = 0;
if(!t2.getText().trim().equals(""))
{
String
sql2 = "update staff set staname =
? where stanum="+ usr +
"";
PreparedStatement
ps2 = dbConn.prepareStatement(sql2);
ps2.setString(1,
t2.getText());
count2
= ps2.executeUpdate();
}
if(!t5.getText().trim().equals(""))
{
String
sql4 = "update staff set dtnum = ?
where stanum="+ usr + "";
PreparedStatement
ps4 = dbConn.prepareStatement(sql4);
ps4.setString(1,
t5.getText());
count4
= ps4.executeUpdate();
}
if(!t7.getText().trim().equals(""))
{
String
sql5 = "update staff set wbk = ?
where stanum="+ usr + "";
PreparedStatement
ps5 = dbConn.prepareStatement(sql5);
ps5.setString(1,
t7.getText());
count5
= ps5.executeUpdate();
}
if(!t8.getText().trim().equals(""))
{
String
sql6 = "update staff set depnum = ?
where stanum="+ usr + "";
PreparedStatement
ps6 = dbConn.prepareStatement(sql6);
ps6.setString(1,
t8.getText());
count6
= ps6.executeUpdate();
}
if
(count2 > 0) {
System.out.println("Employee name modification successfully");
}
if(count4
> 0) {
System.out.println("The job number is modified successfully");
}
if(count5
> 0) {
System.out.println("Salary level modification was successful");
}
if(count6
> 0) {
System.out.println("Department number modification was successful");
}
if(!(count2
> 0||count4 > 0||count5 > 0||count6 > 0)){
System.out.println("Modification failed");
JOptionPane.showMessageDialog(null,
"Modification failed!",
"mistake",
JOptionPane.ERROR_MESSAGE);
}
dbConn.close();
}
catch (SQLException e1) {
e1.printStackTrace();
//
System.out.println("Loading the driver successfully!");
JOptionPane.showMessageDialog(null,
"Database connection failed!",
"mistake",
JOptionPane.ERROR_MESSAGE);
}
}
catch (Exception ex) {
ex.printStackTrace();
System.out.println("Loading driver failed!");
JOptionPane.showMessageDialog(null,
"Loading driver failed!",
"mistake",
JOptionPane.ERROR_MESSAGE);
}
}
});
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
public
static void main(String[] args) {
sta_change
ss = new sta_change();
ss.create_stacha();
}
}
package wagemanager;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.sql.*;
public class sta_delete extends JFrame{
public
void create_stadel() {
setSize(500,
400);
setLocation(500,
300);
setLayout(null);
ImageIcon
pic = new ImageIcon("e:\\Pictures\\Technology Background.jpg");
JLabel
L2 = new JLabel(pic);
pic.setImage(pic.getImage().getScaledInstance(500,
400,Image.SCALE_DEFAULT));
L2.setBounds(0,
0, pic.getIconWidth(), pic.getIconHeight());
JLabel
dellab = new JLabel("Please enter the employee number you want to delete the employee");
dellab.setFont(new
Font (Font.DIALOG, Font.BOLD, 14));
dellab.setForeground(Color.white);
JButton
delbtn = new JButton("delete");
JTextField
del = new JTextField();
dellab.setBounds(150,
60, 200, 40);
del.setBounds(150,
100, 200, 30);
delbtn.setBounds(200,
180, 100, 30);
add(dellab);
add(del);
add(delbtn);
add(L2);
setVisible(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
delbtn.addActionListener(new
ActionListener() {
@Override
public
void actionPerformed(ActionEvent e) {
String
driverName="";
String
dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=Course Settings";
String
userName="sa";String userPwd="188754752";
try{
Class.forName(driverName);
//("Loading driver successfully!");
}catch(Exception
ea){
ea.printStackTrace();System.out.println("Loading driver failed!");
}
try(Connection
dbConn=DriverManager.getConnection(dbURL,userName,userPwd)){
try(PreparedStatement
st = dbConn.prepareStatement("delete from staff where stanum =
"+()+"")){
st.executeUpdate();
}
//("Connecting to the database successfully!");
try(PreparedStatement
st = dbConn.prepareStatement("delete from wage where stanum =
"+()+"")){
st.executeUpdate();
}
dbConn.close();
}catch(Exception
ea){
ea.printStackTrace();System.out.print("SQL
ServerConnection failed! ");
}
}
});
}
}