-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAddEmployee.java
More file actions
195 lines (163 loc) · 5.19 KB
/
AddEmployee.java
File metadata and controls
195 lines (163 loc) · 5.19 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
import java.lang.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
import java.util.*;
import java.io.*;
public class AddEmployee extends JFrame implements ActionListener
{
JLabel welcomeLabel, ebackGround, userLabel, passLabel, eNameLabel, phoneLabel, roleLabel, salaryLabel;
JTextField userTF, passTF, phoneTF1, phoneTF2, eNameTF, salaryTF;
JComboBox roleCombo;
JButton autoPassBtn, addBtn, backBtn, logoutBtn;
JPanel panel;
ImageIcon img, limg, lbtnImg;
Font pixelPowerline;
String userId;
public AddEmployee(String userId)
{
super("Add Employee");
limg = new ImageIcon ("library.png");
this.setIconImage (limg.getImage());
this.userId = userId;
this.setSize(600,450);
this.setLocation(300,150);
this.setResizable (false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.userId = userId;
try
{
pixelPowerline = Font.createFont(Font.TRUETYPE_FONT, new File("pixelPowerline.ttf")).deriveFont(15f);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont (Font.createFont(Font.TRUETYPE_FONT, new File ("pixelPowerline.ttf")));
}
catch(IOException | FontFormatException e){}
panel = new JPanel();
panel.setLayout(null);
lbtnImg = new ImageIcon ("rsz_logout.png");
img = new ImageIcon ();
welcomeLabel = new JLabel("Welcome, "+userId);
welcomeLabel.setBounds(410, 40, 400, 30);
welcomeLabel.setFont (pixelPowerline);
panel.add(welcomeLabel);
logoutBtn = new JButton(lbtnImg);
logoutBtn.setBounds(550, 45, 24, 24);
logoutBtn.addActionListener(this);
panel.add(logoutBtn);
userLabel = new JLabel("User ID : ");
userLabel.setBounds(100, 80, 120, 30);
panel.add(userLabel);
userTF = new JTextField();
userTF.setBounds(200, 80, 120, 30);
panel.add(userTF);
passLabel = new JLabel("Password : ");
passLabel.setBounds(100, 130, 120, 30);
panel.add(passLabel);
passTF = new JTextField();
passTF.setBounds(200, 130, 120, 30);
passTF.setEnabled(false);
panel.add(passTF);
autoPassBtn = new JButton("Generate");
autoPassBtn.setBounds(350, 130, 100, 30);
autoPassBtn.addActionListener(this);
panel.add(autoPassBtn);
eNameLabel = new JLabel("Employee Name : ");
eNameLabel.setBounds(100, 180, 120, 30);
panel.add(eNameLabel);
eNameTF = new JTextField();
eNameTF.setBounds(200, 180, 120, 30);
panel.add(eNameTF);
phoneLabel = new JLabel("Phone No. : ");
phoneLabel.setBounds(100, 230, 120, 30);
panel.add(phoneLabel);
phoneTF1 = new JTextField("+880");
phoneTF1.setBounds(200, 230, 35, 30);
phoneTF1.setEnabled(false);
panel.add(phoneTF1);
phoneTF2 = new JTextField();
phoneTF2.setBounds(235, 230, 85, 30);
panel.add(phoneTF2);
roleLabel = new JLabel("Role : ");
roleLabel.setBounds(100, 280, 120, 30);
panel.add(roleLabel);
String []items = {"Manager", "General"};
roleCombo = new JComboBox(items);
roleCombo.setBounds(200, 280, 120, 30);
panel.add(roleCombo);
salaryLabel = new JLabel("Salary : ");
salaryLabel.setBounds(100, 330, 120, 30);
panel.add(salaryLabel);
salaryTF = new JTextField();
salaryTF.setBounds(200, 330, 120, 30);
panel.add(salaryTF);
addBtn = new JButton("Add");
addBtn.setBounds(250, 380, 100, 30);
addBtn.addActionListener(this);
panel.add(addBtn);
backBtn = new JButton ("< Back");
backBtn.setBounds (5,5,100,30);
backBtn.addActionListener (this);
panel.add (backBtn);
ebackGround = new JLabel (img,JLabel.CENTER);
ebackGround.setBounds (0, 0, 600, 400);
panel.add (ebackGround);
this.add(panel);
}
public void actionPerformed(ActionEvent ae)
{
String text = ae.getActionCommand();
if(text.equals(backBtn.getText()))
{
ManageEmployee me = new ManageEmployee(userId);
me.setVisible(true);
this.setVisible(false);
}
else if(text.equals(logoutBtn.getText()))
{
HomeWindow hw = new HomeWindow();
hw.setVisible(true);
this.setVisible(false);
}
else if(text.equals(autoPassBtn.getText()))
{
Random r = new Random();
passTF.setText(r.nextInt(89999999)+10000000+"");
autoPassBtn.setEnabled(false);
}
else if(text.equals(addBtn.getText()))
{
insertIntoDB();
}
else{}
}
public void insertIntoDB()
{
String newId = userTF.getText();
String newPass = passTF.getText();
String eName = eNameTF.getText();
String phnNo = phoneTF1.getText()+phoneTF2.getText();
String role = roleCombo.getSelectedItem().toString();
double salary = Double.parseDouble(salaryTF.getText());
int status = 0;
String query1 = "INSERT INTO Employee VALUES ('"+newId+"','"+eName+"','"+ phnNo+"','"+role+"',"+salary+");";
String query2 = "INSERT INTO Login VALUES ('"+newId+"','"+newPass+"',"+status+");";
System.out.println(query1);
System.out.println(query2);
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/oop1", "root", "");
Statement stm = con.createStatement();
stm.execute(query1);
stm.execute(query2);
stm.close();
con.close();
JOptionPane.showMessageDialog(this, "Success !!!");
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(this, "Oops !!!");
}
}
}