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
313package GUI;
import javax.swing.*;
import PDF.InPDF;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import GUI.EmployeePage;
import BUS.HOPDONGLAODONG_BUS;
import BUS.PHONGBAN_BUS;
import DAO.HopDongLaoDongDAO;
import DAO.NhanVienDAO;
import EXCEL.XuatNhapExcel;
public class HopdongPage_Tongquan extends JPanel {
private static final long serialVersionUID = 1L;
private HOPDONGLAODONG_BUS hopdonglaodong_bus = new HOPDONGLAODONG_BUS();
private PHONGBAN_BUS phongban_BUS = new PHONGBAN_BUS();
private NhanVienDAO nhanvien_DAO = new NhanVienDAO();
private HopdongPage_Giahan giaHanPage;
private myTable table;
private String[] columnName = {
"STT", "Mã - Họ tên", "Phòng", "Bắt đầu", "Kết thúc", "Loại hợp đồng", "Lương"
};
private DefaultTableModel model;
private Object[][] data;
public void setData() {
data = hopdonglaodong_bus.getDataObjectToRender();
model = new DefaultTableModel(data, columnName);
table.setModel(model);
}
public HopdongPage_Tongquan() {
init();
setData();
giaHanPage = new HopdongPage_Giahan();
}
public void init() {
setLayout(null);
setBackground(new Color(255, 255, 255));
JPanel panel = new JPanel();
panel.setBackground(Color.WHITE);
panel.setBounds(0, 0, 985, 87);
add(panel);
panel.setLayout(null);
JButton btnGiaHan = new JButton("Gia hạn ");
btnGiaHan.setBounds(61, 5, 145, 25);
btnGiaHan.setFont(new Font("Tahoma", Font.PLAIN, 14));
btnGiaHan.setIcon(new ImageIcon(new ImageIcon(getClass().getResource("/assets/appIcon/icons8-user-24.png"))
.getImage().getScaledInstance(24, 24, Image.SCALE_SMOOTH)));
panel.add(btnGiaHan);
JButton btnHuyHopDong = new JButton("Huỷ hợp đồng");
btnHuyHopDong.setBounds(211, 5, 140, 25);
btnHuyHopDong.setFont(new Font("Tahoma", Font.PLAIN, 14));
btnHuyHopDong.setIcon(new ImageIcon(new ImageIcon(getClass().getResource("/assets/appIcon/icons8-user-24.png")).getImage().getScaledInstance(24, 24, Image.SCALE_SMOOTH)));
panel.add(btnHuyHopDong);
JButton btnImportExcel = new JButton("Nhập Excel");
btnImportExcel.setBounds(61, 41, 107, 25);
btnImportExcel.setFont(new Font("Tahoma", Font.BOLD, 13));
ImageIcon importIcon = new ImageIcon(EmployeePage.class.getResource("/assets/appIcon/icons8-reset-24.png"));
Image importImg = importIcon.getImage().getScaledInstance(24, 24, Image.SCALE_SMOOTH);
btnImportExcel.setIcon(new ImageIcon(importImg));
btnImportExcel.setHorizontalTextPosition(SwingConstants.RIGHT);
btnImportExcel.setVerticalTextPosition(SwingConstants.CENTER);
panel.add(btnImportExcel);
btnImportExcel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser jFileChooser = new JFileChooser();
jFileChooser.setDialogTitle("Chọn file Excel để nhập");
int returnVal = jFileChooser.showOpenDialog(panel);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = jFileChooser.getSelectedFile();
XuatNhapExcel.readExcelToTable(file, table);
}
}
});
ImageIcon searchIcon = new ImageIcon(EmployeePage.class.getResource("/assets/appIcon/icons8-search-24.png"));
ImageIcon resetIcon = new ImageIcon(EmployeePage.class.getResource("/assets/appIcon/icons8-reset-24.png"));
JButton searchButton = new JButton();
searchButton.setBounds(532, 18, 50, 30);
panel.add(searchButton);
searchButton.setIcon(searchIcon);
JTextField searchField = new JTextField();
searchField.setBounds(368, 19, 165, 30);
panel.add(searchField);
JButton resetButton = new JButton();
resetButton.setBounds(447, 83, 45, 30);
panel.add(resetButton);
resetButton.setIcon(resetIcon);
resetButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setData();
}
});
searchButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String searchText = searchField.getText();
data = hopdonglaodong_bus.filterData(searchText);
model.setDataVector(data, columnName);
table.setModel(model);
}
});
//xuất excel
JButton btnExportExcel = new JButton("Xuất Excel");
btnExportExcel.setBounds(209, 41, 103, 25);
btnExportExcel.setFont(new Font("Tahoma", Font.BOLD, 13));
ImageIcon exportIcon = new ImageIcon(EmployeePage.class.getResource("/assets/appIcon/icons8-user-24.png"));
Image exportImg = exportIcon.getImage().getScaledInstance(24, 24, Image.SCALE_SMOOTH);
btnExportExcel.setIcon(new ImageIcon(exportImg));
btnExportExcel.setHorizontalTextPosition(SwingConstants.RIGHT);
btnExportExcel.setVerticalTextPosition(SwingConstants.CENTER);
panel.add(btnExportExcel);
btnExportExcel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser jFileChooser = new JFileChooser();
jFileChooser.setDialogTitle("Lưu file Excel");
int returnVal = jFileChooser.showSaveDialog(panel);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = jFileChooser.getSelectedFile();
String filePath = file.getAbsolutePath();
if (!filePath.endsWith(".xlsx")) {
filePath += ".xlsx";
}
XuatNhapExcel.exportDataToExcel(table, filePath, "Tên Sheet");
JOptionPane.showMessageDialog(panel, "Xuất dữ liệu ra file Excel thành công!");
}
}
});
JButton btnExportPDF = new JButton("Xuất PDF");
btnExportPDF.setBounds(500, 41, 103, 25);
btnExportPDF.setFont(new Font("Tahoma", Font.BOLD, 13));
ImageIcon pdfIcon = new ImageIcon(EmployeePage.class.getResource("/assets/appIcon/icons8-user-24.png"));
Image pdfImg = pdfIcon.getImage().getScaledInstance(24, 24, Image.SCALE_SMOOTH);
btnExportPDF.setIcon(new ImageIcon(pdfImg));
btnExportPDF.setHorizontalTextPosition(SwingConstants.RIGHT);
btnExportPDF.setVerticalTextPosition(SwingConstants.CENTER);
panel.add(btnExportPDF);
btnExportPDF.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Lưu file PDF");
int userSelection = fileChooser.showSaveDialog(panel);
if (userSelection == JFileChooser.APPROVE_OPTION) {
File fileToSave = fileChooser.getSelectedFile();
String filePath = fileToSave.getAbsolutePath();
if (!filePath.toLowerCase().endsWith(".pdf")) {
filePath += ".pdf";
}
InPDF pdfExporter = new InPDF();
pdfExporter.savePDF(table, filePath);
JOptionPane.showMessageDialog(panel, "Xuất dữ liệu ra file PDF thành công!");
}
}
});
panel.add(btnExportPDF);
btnHuyHopDong.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int selectedRow = table.getSelectedRow();
if (selectedRow != -1) {
String maNhanVien = table.getValueAt(selectedRow, 1).toString();
String nhanVien = table.getValueAt(selectedRow, 3).toString();
int result = JOptionPane.showOptionDialog(null,
"Bạn có chắc hủy hợp đồng với nhân viên " + nhanVien + " không?",
"Xác nhận",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null, null, null);
if (result == JOptionPane.YES_OPTION) {
nhanvien_DAO.hiddenNhanVien(maNhanVien);
JOptionPane.showMessageDialog(null, "Huỷ hợp đồng thành công!");
}
} else {
JOptionPane.showMessageDialog(null, "Vui lòng chọn một hợp đồng để huỷ");
}
}
});
JComboBox<String> comboBox = new JComboBox<>();
comboBox.setBounds(400, 6, 100, 22);
comboBox.setEditable(false);
comboBox.setBackground(Color.WHITE);
comboBox.setOpaque(true);
comboBox.addItem("Phòng ban");
for (String i : phongban_BUS.getTenPhongBan()) {
comboBox.addItem(i);
}
panel.add(comboBox);
JComboBox<String> comboBox1 = new JComboBox<>();
comboBox1.setBounds(400, 41, 100, 22);
comboBox1.addItem("Thời hạn hợp đồng");
comboBox1.addItem("1 năm");
comboBox1.addItem("2 năm");
comboBox1.addItem("3 năm");
comboBox1.addItem("4 năm");
comboBox1.addItem("5 năm");
comboBox1.addItem("6 năm");
comboBox1.addItem("7 năm");
panel.add(comboBox1);
JLabel lblLuongTu = new JLabel("Lương từ:");
lblLuongTu.setBounds(627, 9, 62, 17);
lblLuongTu.setFont(new Font("Tahoma", Font.PLAIN, 14));
panel.add(lblLuongTu);
JTextField txtLuongTu = new JTextField();
txtLuongTu.setBounds(694, 7, 96, 20);
txtLuongTu.setColumns(10);
panel.add(txtLuongTu);
JLabel lblDen = new JLabel("đến:");
lblDen.setBounds(795, 9, 28, 17);
lblDen.setFont(new Font("Tahoma", Font.PLAIN, 14));
panel.add(lblDen);
JTextField txtLuongDen = new JTextField();
txtLuongDen.setBounds(828, 7, 96, 20);
txtLuongDen.setColumns(10);
panel.add(txtLuongDen);
btnGiaHan.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Nút Gia hạn được nhấn");
displayGiaHanPage();
}
});
table = new myTable();
table.setRowHeight(30);
table.setFont(new Font("Arial", Font.PLAIN, 12));
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 1) {
int selectedRow = table.getSelectedRow();
if (selectedRow != -1) {
Object[][] selectedData = new Object[1][table.getColumnCount()];
for (int i = 0; i < table.getColumnCount(); i++) {
selectedData[0][i] = table.getValueAt(selectedRow, i);
}
giaHanPage.setData(selectedData);
}
}
}
});
// Add scroll pane containing the table
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBackground(Color.WHITE);
scrollPane.setBounds(0, 98, 985, 510);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
add(scrollPane);
}
private void displayGiaHanPage() {
JFrame frame = new JFrame("Gia hạn hợp đồng");
frame.setContentPane(giaHanPage);
frame.setSize(800, 660);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}