-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddEmployee.java
More file actions
202 lines (161 loc) · 6.62 KB
/
AddEmployee.java
File metadata and controls
202 lines (161 loc) · 6.62 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package employee.management.stystem;
import com.toedter.calendar.JDateChooser;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
public class AddEmployee extends JFrame implements ActionListener {
Random ran = new Random();
int number = ran.nextInt(999999);
JTextField tname, tfname, taddress,tphone, taadhar, temail, tsalary,tdesignation;
JLabel tempid;
JDateChooser tdob;
JButton add,back;
JComboBox Boxeducation;
AddEmployee(){
getContentPane().setBackground(new Color(163,255,188));
JLabel heading = new JLabel("Add Employee Detail");
heading.setBounds(320,30,500,50);
heading.setFont(new Font("serif", Font.BOLD,25));
add(heading);
JLabel name = new JLabel("Name");
name.setBounds(50,150,150,30);
name.setFont(new Font("SAN_SERIF", Font.BOLD,20));
add(name);
tname = new JTextField();
tname.setBounds(200,150,150,30);
tname.setBackground(new Color(177,252,197));
add(tname);
JLabel fname = new JLabel("Father's Name");
fname.setBounds(400,150,150,30);
fname.setFont(new Font("SAN_SERIF", Font.BOLD,20));
add(fname);
tfname = new JTextField();
tfname.setBounds(600,150,150,30);
tfname.setBackground(new Color(177,252,197));
add(tfname);
JLabel dob = new JLabel("Date Of Birth");
dob.setBounds(50,200,150,30);
dob.setFont(new Font("SAN_SERIF", Font.BOLD,20));
add(dob);
tdob = new JDateChooser();
tdob.setBounds(200,200,150,30);
tdob.setBackground(new Color(177,252,197));
add(tdob);
JLabel salary = new JLabel("Salary");
salary.setBounds(400,200,150,30);
salary.setFont(new Font("SAN_SERIF", Font.BOLD,20));
add(salary);
tsalary = new JTextField();
tsalary.setBounds(600,200,150,30);
tsalary.setBackground(new Color(177,252,197));
add(tsalary);
JLabel address = new JLabel("Address");
address.setBounds(50,250,150,30);
address.setFont(new Font("SAN_SERIF", Font.BOLD,20));
add(address);
taddress= new JTextField();
taddress.setBounds(200,250,150,30);
taddress.setBackground(new Color(177,252,197));
add(taddress);
JLabel phone = new JLabel("Phone");
phone.setBounds(400,250,150,30);
phone.setFont(new Font("SAN_SERIF", Font.BOLD,20));
add(phone);
tphone= new JTextField();
tphone.setBounds(600,250,150,30);
tphone.setBackground(new Color(177,252,197));
add(tphone);
JLabel email = new JLabel("Email");
email.setBounds(50,300,150,30);
email.setFont(new Font("SAN_SERIF", Font.BOLD,20));
add(email);
temail= new JTextField();
temail.setBounds(200,300,150,30);
temail.setBackground(new Color(177,252,197));
add(temail);
JLabel education = new JLabel("Higest Education");
education.setBounds(400,300,150,30);
education.setFont(new Font("SAN_SERIF", Font.BOLD,20));
add(education);
String items[] = {"BBA","B.Tech","BCA", "BA", "BSC", "B.COM", "MBA", "MCA", "MA", "MTech", "MSC", "PHD"};
Boxeducation = new JComboBox(items);
Boxeducation.setBackground(new Color(177,252,197));
Boxeducation.setBounds(600,300,150,30);
add(Boxeducation);
JLabel aadhar = new JLabel("Aadhar Number");
aadhar.setBounds(400,350,150,30);
aadhar.setFont(new Font("SAN_SERIF", Font.BOLD,20));
add(aadhar);
taadhar= new JTextField();
taadhar.setBounds(600,350,150,30);
taadhar.setBackground(new Color(177,252,197));
add(taadhar);
JLabel empid = new JLabel("Employee ID");
empid.setBounds(50,400,150,30);
empid.setFont(new Font("SAN_SERIF", Font.BOLD,20));
add(empid);
tempid= new JLabel(""+number);
tempid.setBounds(200,400,150,30);
tempid.setFont(new Font("SAN_SARIF", Font.BOLD,20));
tempid.setForeground(Color.RED);
add(tempid);
JLabel designation = new JLabel("Designation");
designation.setBounds(50,350,150,30);
designation.setFont(new Font("SAN_SERIF", Font.BOLD,20));
add(designation);
tdesignation= new JTextField();
tdesignation.setBounds(200,350,150,30);
tdesignation.setBackground(new Color(177,252,197));
add(tdesignation);
add = new JButton("ADD");
add.setBounds(450,550,150,40);
add.setBackground(Color.black);
add.setForeground(Color.WHITE);
add.addActionListener(this);
add(add);
back = new JButton("BACK");
back.setBounds(250,550,150,40);
back.setBackground(Color.black);
back.setForeground(Color.WHITE);
back.addActionListener(this);
add(back);
setSize(900,700);
setLayout(null);
setLocation(300,50);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == add){
String name = tname.getText();
String fname = tfname.getText();
String dob = ((JTextField) tdob.getDateEditor().getUiComponent()).getText();
String salary = tsalary.getText();
String address = taddress.getText();
String aadhar = taadhar.getText();
String phone = tphone.getText();
String email = temail.getText();
String education = (String) Boxeducation.getSelectedItem();
String designation = tdesignation.getText();
String empID = tempid.getText();
try{
conn c = new conn();
String query = "insert into employee values('"+name+"', '"+fname+"', '"+dob+"', '"+salary+"','"+address+"', '"+phone+"', '"+email+"', '"+education+"', '"+designation+"','"+aadhar+"', '"+empID+"')";
c.statement.executeUpdate(query);
JOptionPane.showMessageDialog(null,"Details added successfully");
setVisible(false);
new Main_class();
}catch (Exception E){
E.printStackTrace();
}
}else {
setVisible(false);
new Main_class();
}
}
public static void main(String[] args) {
new AddEmployee();
}
}