-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddEmployee.java
More file actions
183 lines (149 loc) · 6.55 KB
/
AddEmployee.java
File metadata and controls
183 lines (149 loc) · 6.55 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
package employee.management.system;
import java.awt.*;
import javax.swing.*;
import com.toedter.calendar.JDateChooser;
import java.util.*;
import java.awt.event.*;
public class AddEmployee extends JFrame implements ActionListener{
Random ran = new Random();
int number = ran.nextInt(999999);
JTextField tfname, tffname, tfaddress, tfphone, tfaadhar, tfemail, tfsalary, tfdesignation;
JDateChooser dcdob;
JComboBox cbeducation;
JLabel lblempId;
JButton add, back;
AddEmployee() {
getContentPane().setBackground(Color.WHITE);
setLayout(null);
JLabel heading = new JLabel("Add Employee Detail");
heading.setBounds(320, 30, 500, 50);
heading.setFont(new Font("SAN_SERIF", Font.BOLD, 25));
add(heading);
JLabel labelname = new JLabel("Name");
labelname.setBounds(50, 150, 150, 30);
labelname.setFont(new Font("serif", Font.PLAIN, 20));
add(labelname);
tfname = new JTextField();
tfname.setBounds(200, 150, 150, 30);
add(tfname);
JLabel labelfname = new JLabel("Father's Name");
labelfname.setBounds(400, 150, 150, 30);
labelfname.setFont(new Font("serif", Font.PLAIN, 20));
add(labelfname);
tffname = new JTextField();
tffname.setBounds(600, 150, 150, 30);
add(tffname);
JLabel labeldob = new JLabel("Date of Birth");
labeldob.setBounds(50, 200, 150, 30);
labeldob.setFont(new Font("serif", Font.PLAIN, 20));
add(labeldob);
dcdob = new JDateChooser();
dcdob.setBounds(200, 200, 150, 30);
add(dcdob);
JLabel labelsalary = new JLabel("Salary");
labelsalary.setBounds(400, 200, 150, 30);
labelsalary.setFont(new Font("serif", Font.PLAIN, 20));
add(labelsalary);
tfsalary = new JTextField();
tfsalary.setBounds(600, 200, 150, 30);
add(tfsalary);
JLabel labeladdress = new JLabel("Address");
labeladdress.setBounds(50, 250, 150, 30);
labeladdress.setFont(new Font("serif", Font.PLAIN, 20));
add(labeladdress);
tfaddress = new JTextField();
tfaddress.setBounds(200, 250, 150, 30);
add(tfaddress);
JLabel labelphone = new JLabel("Phone");
labelphone.setBounds(400, 250, 150, 30);
labelphone.setFont(new Font("serif", Font.PLAIN, 20));
add(labelphone);
tfphone = new JTextField();
tfphone.setBounds(600, 250, 150, 30);
add(tfphone);
JLabel labelemail = new JLabel("Email");
labelemail.setBounds(50, 300, 150, 30);
labelemail.setFont(new Font("serif", Font.PLAIN, 20));
add(labelemail);
tfemail = new JTextField();
tfemail.setBounds(200, 300, 150, 30);
add(tfemail);
JLabel labeleducation = new JLabel("Higest Education");
labeleducation.setBounds(400, 300, 150, 30);
labeleducation.setFont(new Font("serif", Font.PLAIN, 20));
add(labeleducation);
String courses[] = {"BBA", "BCA", "BA", "BSC", "B.COM", "BTech", "MBA", "MCA", "MA", "MTech", "MSC", "PHD"};
cbeducation = new JComboBox(courses);
cbeducation.setBackground(Color.WHITE);
cbeducation.setBounds(600, 300, 150, 30);
add(cbeducation);
JLabel labeldesignation = new JLabel("Designation");
labeldesignation.setBounds(50, 350, 150, 30);
labeldesignation.setFont(new Font("serif", Font.PLAIN, 20));
add(labeldesignation);
tfdesignation = new JTextField();
tfdesignation.setBounds(200, 350, 150, 30);
add(tfdesignation);
JLabel labelaadhar = new JLabel("Aadhar Number");
labelaadhar.setBounds(400, 350, 150, 30);
labelaadhar.setFont(new Font("serif", Font.PLAIN, 20));
add(labelaadhar);
tfaadhar = new JTextField();
tfaadhar.setBounds(600, 350, 150, 30);
add(tfaadhar);
JLabel labelempId = new JLabel("Employee id");
labelempId.setBounds(50, 400, 150, 30);
labelempId.setFont(new Font("serif", Font.PLAIN, 20));
add(labelempId);
lblempId = new JLabel("" + number);
lblempId.setBounds(200, 400, 150, 30);
lblempId.setFont(new Font("serif", Font.PLAIN, 20));
add(lblempId);
add = new JButton("Add Details");
add.setBounds(250, 550, 150, 40);
add.addActionListener(this);
add.setBackground(Color.BLACK);
add.setForeground(Color.WHITE);
add(add);
back = new JButton("Back");
back.setBounds(450, 550, 150, 40);
back.addActionListener(this);
back.setBackground(Color.BLACK);
back.setForeground(Color.WHITE);
add(back);
setSize(900, 700);
setLocation(300, 50);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == add) {
String name = tfname.getText();
String fname = tffname.getText();
String dob = ((JTextField) dcdob.getDateEditor().getUiComponent()).getText();
String salary = tfsalary.getText();
String address = tfaddress.getText();
String phone = tfphone.getText();
String email = tfemail.getText();
String education = (String) cbeducation.getSelectedItem();
String designation = tfdesignation.getText();
String aadhar = tfaadhar.getText();
String empId = lblempId.getText();
try {
Conn conn = new Conn();
String query = "insert into employee values('"+name+"', '"+fname+"', '"+dob+"', '"+salary+"', '"+address+"', '"+phone+"', '"+email+"', '"+education+"', '"+designation+"', '"+aadhar+"', '"+empId+"')";
conn.s.executeUpdate(query);
JOptionPane.showMessageDialog(null, "Details added successfully");
setVisible(false);
new Home();
} catch (Exception e) {
e.printStackTrace();
}
} else {
setVisible(false);
new Home();
}
}
public static void main(String[] args) {
new AddEmployee();
}
}