-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployeeController.java
More file actions
389 lines (326 loc) · 15.6 KB
/
Copy pathEmployeeController.java
File metadata and controls
389 lines (326 loc) · 15.6 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
package controller;
import model.*;
import view.*;
import controller.NadraDBController;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
public class EmployeeController {
String user;
private EmployeeModel model;
private EmployeeView view;
private NadraDBModel NDM;
private NadraDBView NDV;
private JFrame loginFrame;
private JFrame passwordChangeFrame;
private JFrame Menuframe;
NadraDBController nadraController;
// Constructor
public EmployeeController(EmployeeModel model, EmployeeView view,NadraDBModel nd,NadraDBView nv) {
this.model = model;
this.view = view;
NDM=nd;
NDV=nv;
nadraController = new NadraDBController(NDM,NDV);
}
// Load employee data
public void loadEmployeeData() {
model.loadEmployeeData();
}
public void showMenu() {
String customerFile = "C:\\Users\\city\\Desktop\\java\\LESCO_MVC\\src\\resources\\CustomerInfo.txt";
String billingFile = "C:\\Users\\city\\Desktop\\java\\LESCO_MVC\\src\\resources\\BillingInfo.txt";
String nadraDBFile = "C:\\Users\\city\\Desktop\\java\\LESCO_MVC\\src\\resources\\NadraDB.txt";
String tariffTaxFile = "C:\\Users\\city\\Desktop\\java\\LESCO_MVC\\src\\resources\\TariffTaxInfo.txt";
// Resize the icon to fit better with the text
ImageIcon icon = new ImageIcon(new ImageIcon("C:\\Users\\city\\Desktop\\java\\LESCO_MVC\\src\\icons\\Network-Control-Panel-icon.png")
.getImage().getScaledInstance(50, 50, Image.SCALE_SMOOTH));
// Create the JLabel with text and icon, center-align the icon
JLabel empMenu = new JLabel("Employee Menu", icon, JLabel.CENTER);
// Set font for a more prominent title
empMenu.setFont(new Font("Arial", Font.BOLD, 20));
empMenu.setForeground(Color.DARK_GRAY); // Prominent dark text color
// Set bounds for positioning the label at the top center
empMenu.setBounds(125, 10, 250, 80); // Adjust width and height as necessary
// Create buttons with their respective bounds
JButton ChangePass = createStyledButton("Change Password");
ChangePass.setBounds(80, 120, 150, 35);
JButton viewBill = createStyledButton("View Bills");
viewBill.setBounds(230, 120, 150, 35);
viewBill.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Customer model = new Customer(customerFile);
CustomerView view2 = new CustomerView();
CustomerController controller = new CustomerController(model, view2);
}
});
JButton ViewCNIC = createStyledButton("Show Customers CNIC Dates");
ViewCNIC.setBounds(80, 170, 300, 35);
JButton Billreports = createStyledButton("Bill Reports");
Billreports.setBounds(80, 220, 300, 35);
Billreports.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
List<BillingInfo> billingInfos = BillingInfo.loadBillingData(billingFile);
BillingView view=new BillingView();
BillingController billingController = new BillingController(billingInfos,view,billingFile);
}
});
JButton taxtarriff = createStyledButton("Update Tax Tariff");
taxtarriff.setBounds(80, 270, 300, 35);
taxtarriff.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
TaxTariffInfo model2 = new TaxTariffInfo(tariffTaxFile);
TaxTariffView view3 = new TaxTariffView();
new TaxTariffController(model2, view3);
}
});
JButton cancel = createStyledButton("Cancel");
cancel.setBounds(300, 350, 100, 35);
// Create the menu frame
Menuframe = new JFrame("Employee Control");
Menuframe.setLayout(null);
// Add components to the frame
Menuframe.add(empMenu); // Add the label with icon and text at the top center
Menuframe.add(ChangePass);
Menuframe.add(viewBill);
Menuframe.add(ViewCNIC);
Menuframe.add(Billreports);
Menuframe.add(taxtarriff);
Menuframe.add(cancel);
// Configure the frame
Menuframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Menuframe.setSize(500, 500); // Increase size to fit all buttons comfortably
Menuframe.setLocationRelativeTo(null); // Center the frame on the screen
Menuframe.setVisible(true);
cancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Menuframe.dispose();
}
});
ChangePass.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
createPasswordChangeFrame();
}
});
ViewCNIC.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
nadraController.showExpiries();
}
});
}
// Create the employee login frame with enhanced style
public void createLoginFrame() {
loginFrame = new JFrame("Employee Login");
loginFrame.setSize(420, 420);
loginFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
loginFrame.getContentPane().setBackground(Color.white);
loginFrame.setLayout(null);
// Add username and password fields
JLabel usernameLabel = createStyledLabel("Username: ");
usernameLabel.setForeground(Color.gray);
usernameLabel.setBounds(50, 100, 85, 25);
JTextField usernameField = createStyledTextField();
usernameField.setBounds(125, 100, 200, 25);
JLabel passwordLabel = createStyledLabel("Password: ");
passwordLabel.setForeground(Color.gray);
passwordLabel.setBounds(50, 150, 85, 25);
JPasswordField passwordField = createStyledPasswordField();
passwordField.setBounds(125, 150, 200, 25);
// Add 'Show Password' checkbox
JCheckBox showPasswordCheckBox = new JCheckBox("Show Password");
showPasswordCheckBox.setBounds(125, 180, 200, 25);
showPasswordCheckBox.setBackground(Color.white);
// Add login and cancel buttons
JButton cancelButton = createStyledButton("Cancel");
JButton loginButton = createStyledButton("Login");
loginButton.setBounds(150, 230, 100, 35);
cancelButton.setBounds(150, 280, 100, 35);
// Add components to the frame
loginFrame.setLocationRelativeTo(null);
loginFrame.add(usernameLabel);
loginFrame.add(usernameField);
loginFrame.add(passwordLabel);
loginFrame.add(passwordField);
loginFrame.add(showPasswordCheckBox);
loginFrame.add(new JLabel()); // Empty label for spacing
loginFrame.add(loginButton);
loginFrame.add(cancelButton);
// Add action listener to show password checkbox
showPasswordCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (showPasswordCheckBox.isSelected()) {
passwordField.setEchoChar((char) 0); // Show password
} else {
passwordField.setEchoChar('•'); // Hide password
}
}
});
// Add action listener to login button
loginButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String username = usernameField.getText();
String password = new String(passwordField.getPassword());
if (username.isEmpty() || password.isEmpty()) {
JOptionPane.showMessageDialog(loginFrame, "Please fill in all fields!", "Error", JOptionPane.ERROR_MESSAGE);
} else if (model.validateEmployee(username, password)) {
user = username;
view.showLoginSuccess();
showMenu();
loginFrame.dispose(); // Close login frame
} else {
view.showLoginFailure();
}
}
});
// Add action listener to cancel button
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
loginFrame.dispose();
}
});
// Set login frame icon and visibility
loginFrame.setIconImage(new ImageIcon("C:\\Users\\city\\Desktop\\java\\LESCO_MVC\\src\\icons\\Preppy-icon.png").getImage());
loginFrame.setVisible(true);
}
// Create the password change frame with enhanced style
public void createPasswordChangeFrame() {
passwordChangeFrame = new JFrame("Password Change");
passwordChangeFrame.setSize(420, 420);
passwordChangeFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
passwordChangeFrame.setLayout(null);
passwordChangeFrame.setLocationRelativeTo(null);
passwordChangeFrame.getContentPane().setBackground(Color.white);
// Add current password and new password fields
JLabel currentPasswordLabel = createStyledLabel("Current Password: ");
currentPasswordLabel.setBounds(50, 100, 250, 25);
JPasswordField currentPasswordField = createStyledPasswordField();
currentPasswordField.setBounds(200, 100, 150, 25); // Adjusted field position
JLabel newPasswordLabel = createStyledLabel("New Password: ");
newPasswordLabel.setBounds(50, 170, 250, 25);
JPasswordField newPasswordField = createStyledPasswordField();
newPasswordField.setBounds(200, 170, 150, 25); // Adjusted field position
// Add 'Show Password' checkboxes for both fields
JCheckBox showCurrentPasswordCheckBox = new JCheckBox("Show Current Password");
showCurrentPasswordCheckBox.setBounds(200, 130, 180, 25); // Adjusted checkbox position
showCurrentPasswordCheckBox.setBackground(Color.white);
JCheckBox showNewPasswordCheckBox = new JCheckBox("Show New Password");
showNewPasswordCheckBox.setBounds(200, 200, 150, 25); // Adjusted checkbox position
showNewPasswordCheckBox.setBackground(Color.white);
// Add change password and cancel buttons
JButton changePasswordButton = createStyledButton("Change Password");
changePasswordButton.setBounds(140, 250, 145, 35);
JButton cancelButton = createStyledButton("Cancel");
cancelButton.setBounds(165, 300, 100, 35);
// Add components to the frame
passwordChangeFrame.add(currentPasswordLabel);
passwordChangeFrame.add(currentPasswordField);
passwordChangeFrame.add(newPasswordLabel);
passwordChangeFrame.add(newPasswordField);
passwordChangeFrame.add(showCurrentPasswordCheckBox);
passwordChangeFrame.add(showNewPasswordCheckBox);
passwordChangeFrame.add(changePasswordButton);
passwordChangeFrame.add(cancelButton);
// Add action listeners to the 'Show Password' checkboxes
showCurrentPasswordCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (showCurrentPasswordCheckBox.isSelected()) {
currentPasswordField.setEchoChar((char) 0); // Show current password
} else {
currentPasswordField.setEchoChar('•'); // Hide current password
}
}
});
showNewPasswordCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (showNewPasswordCheckBox.isSelected()) {
newPasswordField.setEchoChar((char) 0); // Show new password
} else {
newPasswordField.setEchoChar('•'); // Hide new password
}
}
});
// Add action listener to change password button
changePasswordButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String currentPassword = new String(currentPasswordField.getPassword());
String newPassword = new String(newPasswordField.getPassword());
if (currentPassword.isEmpty() || newPassword.isEmpty()) {
JOptionPane.showMessageDialog(passwordChangeFrame, "Please fill in all fields!", "Error", JOptionPane.ERROR_MESSAGE);
} else if (model.changePassword(user, currentPassword, newPassword)) {
view.showPasswordChangeSuccess(user);
passwordChangeFrame.dispose(); // Close the password change frame after successful password change
} else {
view.showPasswordChangeFailure();
}
}
});
// Add action listener to cancel button
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
passwordChangeFrame.dispose();
}
});
passwordChangeFrame.setVisible(true);
}
// Method to create a styled JLabel
private JLabel createStyledLabel(String text) {
JLabel label = new JLabel(text);
label.setForeground(Color.gray); // Text color
label.setFont(new Font("Arial", Font.BOLD, 14));
return label;
}
// Method to create a styled JTextField
private JTextField createStyledTextField() {
JTextField textField = new JTextField();
textField.setFont(new Font("Arial", Font.PLAIN, 14));
textField.setForeground(Color.black);
textField.setBackground(new Color(211, 211, 211));
textField.setBorder(BorderFactory.createLineBorder(new Color(90, 98, 118), 1));
return textField;
}
// Method to create a styled JPasswordField
private JPasswordField createStyledPasswordField() {
JPasswordField passwordField = new JPasswordField();
passwordField.setFont(new Font("Arial", Font.PLAIN, 14));
passwordField.setForeground(Color.black);
passwordField.setBackground(new Color(211, 211, 211));
passwordField.setBorder(BorderFactory.createLineBorder(new Color(90, 98, 118), 1));
return passwordField;
}
// Method to create a styled JButton
private JButton createStyledButton(String text) {
JButton button = new JButton(text);
button.setFont(new Font("Arial", Font.BOLD, 14));
button.setForeground(Color.WHITE);
button.setBackground(new Color(60, 180, 75)); // Green background
button.setFocusPainted(false); // Remove default button focus
button.setBorder(BorderFactory.createLineBorder(Color.WHITE, 2));
// Add hover effect
button.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseEntered(java.awt.event.MouseEvent evt) {
button.setBackground(new Color(0, 150, 136)); // Hover color
}
@Override
public void mouseExited(java.awt.event.MouseEvent evt) {
button.setBackground(new Color(60, 180, 75)); // Original color
}
});
return button;
}
}