diff --git a/database/db_qlcb (1).sql b/database/db_qlcb (1).sql
new file mode 100644
index 0000000..397a6a0
--- /dev/null
+++ b/database/db_qlcb (1).sql
@@ -0,0 +1,280 @@
+-- phpMyAdmin SQL Dump
+-- version 5.2.0
+-- https://www.phpmyadmin.net/
+--
+-- Máy chủ: 127.0.0.1
+-- Thời gian đã tạo: Th6 26, 2022 lúc 05:17 PM
+-- Phiên bản máy phục vụ: 10.4.24-MariaDB
+-- Phiên bản PHP: 8.1.6
+
+SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
+START TRANSACTION;
+SET time_zone = "+00:00";
+
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8mb4 */;
+
+--
+-- Cơ sở dữ liệu: `db_qlcb`
+--
+
+-- --------------------------------------------------------
+
+--
+-- Cấu trúc bảng cho bảng `tbl_canbo`
+--
+
+CREATE TABLE `tbl_canbo` (
+ `macb` int(11) NOT NULL,
+ `tencb` varchar(50) COLLATE utf8mb4_vietnamese_ci NOT NULL,
+ `namsinh` int(11) NOT NULL,
+ `gioitinh` varchar(10) COLLATE utf8mb4_vietnamese_ci NOT NULL,
+ `diachi` varchar(100) COLLATE utf8mb4_vietnamese_ci NOT NULL,
+ `manghe` int(11) NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_vietnamese_ci;
+
+--
+-- Đang đổ dữ liệu cho bảng `tbl_canbo`
+--
+
+INSERT INTO `tbl_canbo` (`macb`, `tencb`, `namsinh`, `gioitinh`, `diachi`, `manghe`) VALUES
+(72, 'Đỗ Ngọc Đức', 2001, 'Nam', 'Hà Nam', 0),
+(81, 'Trần Duy Khương', 2001, 'Nam', 'Hải Dương', 1),
+(82, 'Trần Văn Công', 1998, 'Nữ', 'Hải Phòng', 1),
+(83, 'Trần Thị Minh', 2006, 'Nữ', 'Hải Nam', 1),
+(84, 'Trần Thành ', 1995, 'Nam', 'Quảng Bình', 3),
+(85, 'Lê Thị Thơm', 2004, 'Nữ', 'Hà Giang', 3),
+(86, 'Nguyễn Tiến Long', 1997, 'Nam', 'Nghệ An', 3),
+(87, 'Trịnh Văn Sơn', 1995, 'Nam', 'Thanh Hóa', 2),
+(88, 'Đỗ Ngọc Đức', 2001, 'Nam', 'Hà Nam', 2),
+(89, 'Trần Tiến Công', 1997, 'Nam', 'Cà Mau', 1),
+(90, 'Lương Văn Sơn', 1997, 'Nam', 'Quảng Ninh', 2),
+(91, 'Phạm Thế Hùng', 2009, 'Nam', 'Ninh Bình', 3),
+(92, 'Nguyễn Văn Dương', 2001, 'Nam', 'Hà Nam', 2),
+(93, 'Hoàng Trịnh Trọng', 2000, 'Nam', 'Thanh Hóa', 1);
+
+-- --------------------------------------------------------
+
+--
+-- Cấu trúc bảng cho bảng `tbl_congnhan`
+--
+
+CREATE TABLE `tbl_congnhan` (
+ `macn` int(11) NOT NULL,
+ `bac` int(10) NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_vietnamese_ci;
+
+--
+-- Đang đổ dữ liệu cho bảng `tbl_congnhan`
+--
+
+INSERT INTO `tbl_congnhan` (`macn`, `bac`) VALUES
+(81, 9),
+(82, 6),
+(83, 10),
+(89, 9),
+(93, 7);
+
+-- --------------------------------------------------------
+
+--
+-- Cấu trúc bảng cho bảng `tbl_kysu`
+--
+
+CREATE TABLE `tbl_kysu` (
+ `maks` int(11) NOT NULL,
+ `nganhdt` varchar(100) COLLATE utf8mb4_vietnamese_ci NOT NULL,
+ `loaibang` varchar(100) COLLATE utf8mb4_vietnamese_ci NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_vietnamese_ci;
+
+--
+-- Đang đổ dữ liệu cho bảng `tbl_kysu`
+--
+
+INSERT INTO `tbl_kysu` (`maks`, `nganhdt`, `loaibang`) VALUES
+(87, 'CNTT', 'Giỏi'),
+(88, 'Tự động hóa', 'Giỏi'),
+(90, 'Cơ điện tử', 'Khá'),
+(92, 'CNTT', 'Giỏi');
+
+-- --------------------------------------------------------
+
+--
+-- Cấu trúc bảng cho bảng `tbl_nghe`
+--
+
+CREATE TABLE `tbl_nghe` (
+ `manghe` int(11) NOT NULL,
+ `tennghe` varchar(100) COLLATE utf8mb4_vietnamese_ci NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_vietnamese_ci;
+
+--
+-- Đang đổ dữ liệu cho bảng `tbl_nghe`
+--
+
+INSERT INTO `tbl_nghe` (`manghe`, `tennghe`) VALUES
+(0, 'Quản trị viên'),
+(1, 'Công Nhân'),
+(2, 'Kỹ Sư'),
+(3, 'Nhân Viên');
+
+-- --------------------------------------------------------
+
+--
+-- Cấu trúc bảng cho bảng `tbl_nhanvien`
+--
+
+CREATE TABLE `tbl_nhanvien` (
+ `manv` int(11) NOT NULL,
+ `congviec` varchar(100) COLLATE utf8mb4_vietnamese_ci NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_vietnamese_ci;
+
+--
+-- Đang đổ dữ liệu cho bảng `tbl_nhanvien`
+--
+
+INSERT INTO `tbl_nhanvien` (`manv`, `congviec`) VALUES
+(84, 'Phục vụ'),
+(85, 'Phụ bếp'),
+(86, 'Đầu bếp'),
+(91, 'Quản lý');
+
+-- --------------------------------------------------------
+
+--
+-- Cấu trúc bảng cho bảng `tbl_taikhoan`
+--
+
+CREATE TABLE `tbl_taikhoan` (
+ `id` int(11) NOT NULL,
+ `username` varchar(30) COLLATE utf8mb4_vietnamese_ci NOT NULL,
+ `password` varchar(100) COLLATE utf8mb4_vietnamese_ci NOT NULL,
+ `macb` int(11) NOT NULL,
+ `quyen` int(3) NOT NULL,
+ `trangthai` text COLLATE utf8mb4_vietnamese_ci NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_vietnamese_ci;
+
+--
+-- Đang đổ dữ liệu cho bảng `tbl_taikhoan`
+--
+
+INSERT INTO `tbl_taikhoan` (`id`, `username`, `password`, `macb`, `quyen`, `trangthai`) VALUES
+(12, 'ducdn', 'admin@123', 72, 0, 'Đang hoạt động'),
+(14, 'tranduykhuong', '76797943', 81, 1, 'Đang hoạt động'),
+(15, 'tranvancong', '5742266', 82, 1, 'Đang hoạt động'),
+(16, 'tranthiminh', '40446294', 83, 0, 'Vô hiệu hóa'),
+(17, 'tranthanh', '3926818', 84, 0, 'Đang hoạt động'),
+(18, 'lethithom', '41433794', 85, 1, 'Đang hoạt động'),
+(19, 'nguyentienlong', 'long2001@', 86, 0, 'Đang hoạt động'),
+(21, 'dongocduc', '11405031', 88, 1, 'Đang hoạt động'),
+(22, 'trantiencong', '64423393', 89, 1, 'Đang hoạt động'),
+(23, 'luongvanson', 'son2001@', 90, 1, 'Đang hoạt động'),
+(24, 'phamthehung', '80902513', 91, 1, 'Đang hoạt động'),
+(25, 'nguyenvanduong', '14878199', 92, 1, 'Đang hoạt động'),
+(26, 'hoangtrinhtrong', '64539800', 93, 0, 'Đang hoạt động');
+
+--
+-- Chỉ mục cho các bảng đã đổ
+--
+
+--
+-- Chỉ mục cho bảng `tbl_canbo`
+--
+ALTER TABLE `tbl_canbo`
+ ADD PRIMARY KEY (`macb`),
+ ADD KEY `fk_nghe` (`manghe`);
+
+--
+-- Chỉ mục cho bảng `tbl_congnhan`
+--
+ALTER TABLE `tbl_congnhan`
+ ADD PRIMARY KEY (`macn`);
+
+--
+-- Chỉ mục cho bảng `tbl_kysu`
+--
+ALTER TABLE `tbl_kysu`
+ ADD PRIMARY KEY (`maks`);
+
+--
+-- Chỉ mục cho bảng `tbl_nghe`
+--
+ALTER TABLE `tbl_nghe`
+ ADD PRIMARY KEY (`manghe`);
+
+--
+-- Chỉ mục cho bảng `tbl_nhanvien`
+--
+ALTER TABLE `tbl_nhanvien`
+ ADD PRIMARY KEY (`manv`);
+
+--
+-- Chỉ mục cho bảng `tbl_taikhoan`
+--
+ALTER TABLE `tbl_taikhoan`
+ ADD PRIMARY KEY (`id`),
+ ADD KEY `fk_tk` (`macb`);
+
+--
+-- AUTO_INCREMENT cho các bảng đã đổ
+--
+
+--
+-- AUTO_INCREMENT cho bảng `tbl_canbo`
+--
+ALTER TABLE `tbl_canbo`
+ MODIFY `macb` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=94;
+
+--
+-- AUTO_INCREMENT cho bảng `tbl_nghe`
+--
+ALTER TABLE `tbl_nghe`
+ MODIFY `manghe` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
+
+--
+-- AUTO_INCREMENT cho bảng `tbl_taikhoan`
+--
+ALTER TABLE `tbl_taikhoan`
+ MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=27;
+
+--
+-- Các ràng buộc cho các bảng đã đổ
+--
+
+--
+-- Các ràng buộc cho bảng `tbl_canbo`
+--
+ALTER TABLE `tbl_canbo`
+ ADD CONSTRAINT `fk_nghe` FOREIGN KEY (`manghe`) REFERENCES `tbl_nghe` (`manghe`) ON DELETE CASCADE ON UPDATE CASCADE;
+
+--
+-- Các ràng buộc cho bảng `tbl_congnhan`
+--
+ALTER TABLE `tbl_congnhan`
+ ADD CONSTRAINT `fk_macn` FOREIGN KEY (`macn`) REFERENCES `tbl_canbo` (`macb`) ON DELETE CASCADE ON UPDATE CASCADE;
+
+--
+-- Các ràng buộc cho bảng `tbl_kysu`
+--
+ALTER TABLE `tbl_kysu`
+ ADD CONSTRAINT `fk_maks` FOREIGN KEY (`maks`) REFERENCES `tbl_canbo` (`macb`) ON DELETE CASCADE ON UPDATE CASCADE;
+
+--
+-- Các ràng buộc cho bảng `tbl_nhanvien`
+--
+ALTER TABLE `tbl_nhanvien`
+ ADD CONSTRAINT `fk_manv` FOREIGN KEY (`manv`) REFERENCES `tbl_canbo` (`macb`) ON DELETE CASCADE ON UPDATE CASCADE;
+
+--
+-- Các ràng buộc cho bảng `tbl_taikhoan`
+--
+ALTER TABLE `tbl_taikhoan`
+ ADD CONSTRAINT `fk_tk` FOREIGN KEY (`macb`) REFERENCES `tbl_canbo` (`macb`) ON DELETE CASCADE ON UPDATE CASCADE;
+COMMIT;
+
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
diff --git a/jaexel/employee.xls b/jaexel/employee.xls
new file mode 100644
index 0000000..8e237b0
Binary files /dev/null and b/jaexel/employee.xls differ
diff --git a/jaexel/engineer.xls b/jaexel/engineer.xls
new file mode 100644
index 0000000..9bf4cd5
Binary files /dev/null and b/jaexel/engineer.xls differ
diff --git a/jaexel/worker.xls b/jaexel/worker.xls
new file mode 100644
index 0000000..f66fa7f
Binary files /dev/null and b/jaexel/worker.xls differ
diff --git a/pom.xml b/pom.xml
index 7c7198c..0e38a53 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,5 +21,23 @@
AbsoluteLayout
RELEASE126
+
+
+ org.apache.poi
+ poi
+ 3.17
+
+
+
+ org.apache.poi
+ poi-ooxml
+ 3.17
+
+
+
+ commons-codec
+ commons-codec
+ 1.14
+
\ No newline at end of file
diff --git a/src/main/java/com/mycompany/qlcb/dao/CanBoDao.java b/src/main/java/com/mycompany/qlcb/dao/CanBoDao.java
index 8387577..a0f5eaa 100644
--- a/src/main/java/com/mycompany/qlcb/dao/CanBoDao.java
+++ b/src/main/java/com/mycompany/qlcb/dao/CanBoDao.java
@@ -5,6 +5,7 @@
import com.mycompany.qlcb.model.Congnhan;
import com.mycompany.qlcb.model.Kysu;
import com.mycompany.qlcb.model.Nhanvien;
+import com.mycompany.qlcb.model.TaiKhoan;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -19,8 +20,7 @@ public boolean insertCB(Canbo cb, int manghe) throws SQLException, Exception {
+ "values(?, ?, ?, ?, ?)";
try (
- Connection con = DatabaseHelper.openConnection();
- PreparedStatement pstmt = con.prepareStatement(sql);) {
+ Connection con = DatabaseHelper.openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
pstmt.setString(1, cb.getTencb());
pstmt.setInt(2, cb.getNamsinh());
pstmt.setString(3, cb.getGioitinh());
@@ -36,9 +36,8 @@ public int getLastIdCB() throws SQLException, Exception {
String sql = "SELECT macb FROM tbl_canbo ORDER BY macb DESC LIMIT 1;";
try (
- Connection con = DatabaseHelper.openConnection();
- PreparedStatement pstmt = con.prepareStatement(sql);) {
- try (ResultSet rs = pstmt.executeQuery();) {
+ Connection con = DatabaseHelper.openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
+ try ( ResultSet rs = pstmt.executeQuery();) {
if (rs.next()) {
return rs.getInt("macb");
}
@@ -55,8 +54,7 @@ public boolean insertTable(String table, int macb, String filed1, String filed2)
String sql = "Insert into " + table + " values (?,?, ?)";
try (
- Connection con = DatabaseHelper.openConnection();
- PreparedStatement pstmt = con.prepareStatement(sql);) {
+ Connection con = DatabaseHelper.openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
pstmt.setInt(1, macb);
pstmt.setString(2, filed1);
pstmt.setString(3, filed2);
@@ -67,8 +65,7 @@ public boolean insertTable(String table, int macb, String filed1, String filed2)
String sql = "Insert into " + table + " values (?,?)";
try (
- Connection con = DatabaseHelper.openConnection();
- PreparedStatement pstmt = con.prepareStatement(sql);) {
+ Connection con = DatabaseHelper.openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
pstmt.setInt(1, macb);
if (table.equalsIgnoreCase("tbl_congnhan")) {
pstmt.setInt(2, Integer.parseInt(filed1));
@@ -80,25 +77,60 @@ public boolean insertTable(String table, int macb, String filed1, String filed2)
}
}
-
-
- //Thêm tài khoản
+
+ //Thêm tài khoản cào bản tài khoản
public boolean insertTaiKhoan(String username, String password, int macb, int quyen) throws SQLException, Exception {
- String sql = "Insert into tbl_taikhoan(username, password, macb, quyen) values (?,?,?,?)";
+ String sql = "Insert into tbl_taikhoan(username, password, macb, quyen, trangthai) values (?,?,?,?,?)";
try (
- Connection con = DatabaseHelper.openConnection();
- PreparedStatement pstmt = con.prepareStatement(sql);) {
+ Connection con = DatabaseHelper.openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
pstmt.setString(1, username);
pstmt.setString(2, password);
- pstmt.setInt(3, macb);
- pstmt.setInt(4, quyen);
-
+ pstmt.setInt(3, macb);
+ pstmt.setInt(4, quyen);
+ String status = "Đang hoạt động";
+ pstmt.setString(5, status);
+
return pstmt.executeUpdate() > 0;
+ }
+ }
+ // Lấy thông tin tài khoản
+ public ArrayList getInfoAccount() throws SQLException, Exception {
+ String sql = "SELECT * FROM tbl_taikhoan";
+ try (
+ Connection con = DatabaseHelper.openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
+ try ( ResultSet rs = pstmt.executeQuery();) {
+ ArrayList listtk = new ArrayList();
+ while (rs.next()) {
+ TaiKhoan tk = new TaiKhoan();
+ tk.setMacb(rs.getInt("macb"));
+ tk.setUsername(rs.getString("username"));
+ tk.setQuyen(rs.getInt("quyen"));
+ tk.setTrangthai(rs.getString("trangthai"));
+ listtk.add(tk);
+ }
+ return listtk;
}
+
+ }
}
-
- // Cập nhật thông tin
+ // Cập nhật thông tin tài khoản
+ public boolean update(TaiKhoan tk) throws SQLException, Exception {
+
+ String sql = "update tbl_taikhoan set quyen = ?, trangthai = ? where macb = ?";
+
+ try (
+ Connection con = DatabaseHelper.openConnection();
+ PreparedStatement pstmt = con.prepareStatement(sql);)
+ {
+ pstmt.setInt(1, tk.getQuyen());
+ pstmt.setString(2, tk.getTrangthai());
+ pstmt.setInt(3, tk.getMacb());
+ return pstmt.executeUpdate() > 0;
+ }
+ }
+
+ // Cập nhật thông tin
public void update(String table, Canbo cb, String filed1, String filed2) throws SQLException, Exception {
if (table.equalsIgnoreCase("tbl_kysu")) {
String sql = "update tbl_canbo, " + table + " set tencb = ?, "
@@ -107,8 +139,7 @@ public void update(String table, Canbo cb, String filed1, String filed2) throws
+ "and macb = ?";
try (
- Connection con = DatabaseHelper.openConnection();
- PreparedStatement pstmt = con.prepareStatement(sql);) {
+ Connection con = DatabaseHelper.openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
pstmt.setString(1, cb.getTencb());
pstmt.setInt(2, cb.getNamsinh());
pstmt.setString(3, cb.getGioitinh());
@@ -132,8 +163,7 @@ public void update(String table, Canbo cb, String filed1, String filed2) throws
}
try (
- Connection con = DatabaseHelper.openConnection();
- PreparedStatement pstmt = con.prepareStatement(sql);) {
+ Connection con = DatabaseHelper.openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
pstmt.setString(1, cb.getTencb());
pstmt.setInt(2, cb.getNamsinh());
pstmt.setString(3, cb.getGioitinh());
@@ -151,8 +181,7 @@ public boolean delete(String table, String ma, int macb) throws SQLException, Ex
+ table + " on tbl_canbo.macb = " + table + "." + ma + " where tbl_canbo.macb = ?;";
try (
- Connection con = DatabaseHelper.openConnection();
- PreparedStatement pstmt = con.prepareStatement(sql);) {
+ Connection con = DatabaseHelper.openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
pstmt.setInt(1, macb);
return pstmt.executeUpdate() > 0;
}
@@ -163,9 +192,8 @@ public ArrayList getAllCanBo() throws SQLException, Exception {
String sql = "select * from tbl_canbo inner join tbl_nghe on tbl_canbo.manghe = tbl_nghe.manghe";
try (
- Connection con = DatabaseHelper.openConnection();
- PreparedStatement pstmt = con.prepareStatement(sql);) {
- try (ResultSet rs = pstmt.executeQuery();) {
+ Connection con = DatabaseHelper.openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
+ try ( ResultSet rs = pstmt.executeQuery();) {
ArrayList listcb = new ArrayList();
while (rs.next()) {
Canbo cb = new Canbo();
@@ -182,68 +210,81 @@ public ArrayList getAllCanBo() throws SQLException, Exception {
}
}
}
-
+
+ public int[] getNumber() throws SQLException, Exception {
+ String sql = "SELECT count(macb) as 'soluong' FROM tbl_canbo group by manghe";
+ int[] arr = new int[5];
+ try (
+ Connection con = DatabaseHelper.openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
+ try ( ResultSet rs = pstmt.executeQuery();) {
+ int i = 0;
+ while (rs.next()) {
+ arr[i] = rs.getInt("soluong");
+ i++;
+ }
+
+ }
+ return arr;
+ }
+ }
+
public Congnhan getDetailCn(int macb) throws SQLException, Exception {
String sql = "SELECT * FROM tbl_canbo inner join tbl_congnhan on macb = macn where macb = " + macb;
Congnhan cn;
try (
- Connection con = DatabaseHelper.openConnection();
- PreparedStatement pstmt = con.prepareStatement(sql);) {
- try (ResultSet rs = pstmt.executeQuery();) {
+ Connection con = DatabaseHelper.openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
+ try ( ResultSet rs = pstmt.executeQuery();) {
if (rs.next()) {
CongNhanDao dao = new CongNhanDao();
cn = dao.getDetailCongNhan(macb);
return cn;
}
-
+
}
}
return null;
}
-
- public Kysu getDetailKs(int macb) throws SQLException, Exception {
+
+ public Kysu getDetailKs(int macb) throws SQLException, Exception {
String sql = "SELECT * FROM tbl_canbo inner join tbl_kysu on macb = maks where macb = " + macb;
Kysu ks;
try (
- Connection con = DatabaseHelper.openConnection();
- PreparedStatement pstmt = con.prepareStatement(sql);) {
- try (ResultSet rs = pstmt.executeQuery();) {
+ Connection con = DatabaseHelper.openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
+ try ( ResultSet rs = pstmt.executeQuery();) {
if (rs.next()) {
KySuDao dao = new KySuDao();
ks = dao.getDetailKySu(macb);
return ks;
}
-
+
}
}
return null;
}
-
- public Nhanvien getDetailcb(int macb) throws SQLException, Exception {
+
+ public Nhanvien getDetailcb(int macb) throws SQLException, Exception {
String sql = "SELECT * FROM tbl_canbo inner join tbl_nhacbien on macb = macb where macb = " + macb;
Nhanvien cb;
try (
- Connection con = DatabaseHelper.openConnection();
- PreparedStatement pstmt = con.prepareStatement(sql);) {
- try (ResultSet rs = pstmt.executeQuery();) {
+ Connection con = DatabaseHelper.openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
+ try ( ResultSet rs = pstmt.executeQuery();) {
if (rs.next()) {
NhanVienDao dao = new NhanVienDao();
cb = dao.getDetailNhanVien(macb);
return cb;
}
-
+
}
}
return null;
}
-
+
public int getManghe(int macb) throws SQLException, Exception {
String sql = "select manghe from tbl_canbo where macb = " + macb;
int manghe;
try (
- Connection con = DatabaseHelper.openConnection();
- PreparedStatement pstmt = con.prepareStatement(sql);) {
- try (ResultSet rs = pstmt.executeQuery();) {
+ Connection con = DatabaseHelper.openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
+ try ( ResultSet rs = pstmt.executeQuery();) {
if (rs.next()) {
manghe = rs.getInt("manghe");
return manghe;
@@ -253,69 +294,65 @@ public int getManghe(int macb) throws SQLException, Exception {
}
return -1;
}
+
// Lấy ra thông tin ngu?i dùng
public Canbo getDataND(int maCB) throws SQLException, Exception {
String sql = "SELECT * FROM tbl_canbo where macb = " + String.valueOf(maCB);
try (
- Connection con = DatabaseHelper.openConnection();
- PreparedStatement pstmt = con.prepareStatement(sql);) {
- try (ResultSet rs = pstmt.executeQuery();) {
+ Connection con = DatabaseHelper.openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
+ try ( ResultSet rs = pstmt.executeQuery();) {
if (rs.next()) {
- Canbo cb = new Canbo();
+ Canbo cb = new Canbo();
cb.setMacb(maCB);
- cb.setTencb(rs.getString("tencb"));
+ cb.setTencb(rs.getString("tencb"));
cb.setNamsinh(rs.getInt("namsinh"));
cb.setGioitinh(rs.getString("gioitinh"));
cb.setDiachi(rs.getString("diachi"));
- return cb;
+ return cb;
}
}
}
return null;
}
+
//update cán bộ
- public boolean update(String pw, int macb) throws SQLException, Exception {
-
+ public boolean chagePassword(String pw, int macb) throws SQLException, Exception {
+
String sql = "update tbl_taikhoan SET password = ?"
- + "where tbl_taikhoan.macb = ?";
-
+ + "where tbl_taikhoan.macb = ?";
+
try (
- Connection con = DatabaseHelper.openConnection();
- PreparedStatement pstmt = con.prepareStatement(sql);)
- {
- pstmt.setString(1, pw);
+ Connection con = DatabaseHelper.openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
+ pstmt.setString(1, pw);
pstmt.setInt(2, macb);
return pstmt.executeUpdate() > 0;
}
}
+
//check password
public boolean checkPw(String pw, int macb) throws SQLException, Exception {
-
+
String sql = "select password form tbl_taikhoan where password = ? AND macb=?";
-
+
try (
- Connection con = DatabaseHelper.openConnection();
- PreparedStatement pstmt = con.prepareStatement(sql);)
- {
- pstmt.setString(1, pw);
+ Connection con = DatabaseHelper.openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
+ pstmt.setString(1, pw);
pstmt.setInt(2, macb);
return true;
}
}
-
+
// cập nhật thông tin cơ bản ở panel người dùng
public boolean update_general(Canbo cb) throws SQLException, Exception {
-
+
String sql = "update tbl_canbo set tencb = ?, namsinh = ?, gioitinh = ?, diachi = ?"
- + "where tbl_canbo.macb = ?";
-
+ + "where tbl_canbo.macb = ?";
+
try (
- Connection con = DatabaseHelper.openConnection();
- PreparedStatement pstmt = con.prepareStatement(sql);)
- {
+ Connection con = DatabaseHelper.openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
pstmt.setString(1, cb.getTencb());
pstmt.setInt(2, cb.getNamsinh());
pstmt.setString(3, cb.getGioitinh());
@@ -324,4 +361,5 @@ public boolean update_general(Canbo cb) throws SQLException, Exception {
return pstmt.executeUpdate() > 0;
}
}
+
}
diff --git a/src/main/java/com/mycompany/qlcb/dao/CongNhanDao.java b/src/main/java/com/mycompany/qlcb/dao/CongNhanDao.java
index 59c931b..86eb221 100644
--- a/src/main/java/com/mycompany/qlcb/dao/CongNhanDao.java
+++ b/src/main/java/com/mycompany/qlcb/dao/CongNhanDao.java
@@ -40,7 +40,7 @@ public ArrayList findCongnhan(String info) throws SQLException, Except
String sql = "select * from tbl_canbo cb inner join "
+ "tbl_congnhan cn on cb.macb = cn.macn "
+ "where tencb like" + info + " or namsinh like" + info + " or gioitinh like " + info
- + " or diachi like " + info + "or bac like " + info;
+ + " or diachi like " + info + "or bac like " + info + " or macb like " + info;
try
(
diff --git a/src/main/java/com/mycompany/qlcb/dao/KySuDao.java b/src/main/java/com/mycompany/qlcb/dao/KySuDao.java
index 83b0261..c150ad1 100644
--- a/src/main/java/com/mycompany/qlcb/dao/KySuDao.java
+++ b/src/main/java/com/mycompany/qlcb/dao/KySuDao.java
@@ -50,7 +50,8 @@ public ArrayList findKysu(String info) throws SQLException, Exception {
String sql = "select * from tbl_canbo cb inner join "
+ "tbl_kysu ks on cb.macb = ks.maks "
+ "where tencb like" + info + " or namsinh like" + info + " or gioitinh like " + info
- + " or diachi like " + info + "or nganhdt like " + info + " or loaibang like " + info;
+ + " or diachi like " + info + "or nganhdt like " + info + " or loaibang like " + info +
+ " or macb like " + info;
try
(
diff --git a/src/main/java/com/mycompany/qlcb/dao/NguoiDungDao.java b/src/main/java/com/mycompany/qlcb/dao/NguoiDungDao.java
index e0cec15..fa20913 100644
--- a/src/main/java/com/mycompany/qlcb/dao/NguoiDungDao.java
+++ b/src/main/java/com/mycompany/qlcb/dao/NguoiDungDao.java
@@ -1,48 +1,49 @@
package com.mycompany.qlcb.dao;
import static com.mycompany.qlcb.helpers.DatabaseHelper.openConnection;
+import com.mycompany.qlcb.helpers.MessageDialogHelper;
import com.mycompany.qlcb.model.NguoiDung;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
-
public class NguoiDungDao {
+
public NguoiDung checkLogin(String tenDangNhap, String matKhau) throws Exception {
- String sql = "Select username, password,macb, quyen from tbl_taikhoan where username = ? and password = ?";
- try
- (
- Connection con = openConnection();
- PreparedStatement pstmt = con.prepareStatement(sql);
- )
- {
+ String sql = "Select username, password,macb, quyen, trangthai from tbl_taikhoan where username = ? and password = ?";
+ try (
+ Connection con = openConnection(); PreparedStatement pstmt = con.prepareStatement(sql);) {
pstmt.setString(1, tenDangNhap);
pstmt.setString(2, matKhau);
- try(ResultSet rs = pstmt.executeQuery();) {
+ try ( ResultSet rs = pstmt.executeQuery();) {
if (rs.next()) {
- NguoiDung nd = new NguoiDung();
- nd.setTenDangNhap(tenDangNhap);
- nd.setMaCB(rs.getInt("macb"));
- int quyen = rs.getInt("quyen");
- if(quyen == 0){
- nd.setVaiTro("Quản trị viên");
- }
- if(quyen == 1){
- nd.setVaiTro("Công nhân");
- }
- if(quyen == 2){
- nd.setVaiTro("Kỹ sư");
+ if (rs.getString("trangthai").equals("Đang hoạt động")) {
+ NguoiDung nd = new NguoiDung();
+ nd.setTenDangNhap(tenDangNhap);
+ nd.setMaCB(rs.getInt("macb"));
+ int quyen = rs.getInt("quyen");
+ if (quyen == 0) {
+ nd.setVaiTro("Quản trị viên");
+ }
+ if (quyen == 1) {
+ nd.setVaiTro("Công nhân");
+ }
+ if (quyen == 2) {
+ nd.setVaiTro("Kỹ sư");
+ }
+ if (quyen == 3) {
+ nd.setVaiTro("Nhân viên");
+ }
+ return nd;
+ } else {
+ return new NguoiDung();
}
- if(quyen == 2){
- nd.setVaiTro("Nhân viên");
- }
- return nd;
-
+
}
}
}
-
+
return null;
- }
-
+ }
+
}
diff --git a/src/main/java/com/mycompany/qlcb/dao/NhanVienDao.java b/src/main/java/com/mycompany/qlcb/dao/NhanVienDao.java
index 402a7b7..20395d1 100644
--- a/src/main/java/com/mycompany/qlcb/dao/NhanVienDao.java
+++ b/src/main/java/com/mycompany/qlcb/dao/NhanVienDao.java
@@ -47,7 +47,7 @@ public ArrayList findNhanVien(String info) throws SQLException, Except
String sql = "select * from tbl_canbo cb inner join "
+ "tbl_nhanvien nv on cb.macb = nv.manv "
+ "where tencb like" + info + " or namsinh like" + info + " or gioitinh like " + info
- + " or diachi like " + info + "or congviec like " + info;
+ + " or diachi like " + info + "or congviec like " + info + " or macb like " + info;
try
(
diff --git a/src/main/java/com/mycompany/qlcb/filehelpers/ExportBase.java b/src/main/java/com/mycompany/qlcb/filehelpers/ExportBase.java
new file mode 100644
index 0000000..f663626
--- /dev/null
+++ b/src/main/java/com/mycompany/qlcb/filehelpers/ExportBase.java
@@ -0,0 +1,265 @@
+
+package com.mycompany.qlcb.filehelpers;
+
+import com.mycompany.qlcb.model.Congnhan;
+import com.mycompany.qlcb.model.Kysu;
+import com.mycompany.qlcb.model.Nhanvien;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.poi.hssf.usermodel.HSSFCellStyle;
+import org.apache.poi.hssf.usermodel.HSSFFont;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.Row;
+
+
+public class ExportBase {
+
+ private static HSSFCellStyle createStyleForTitle(HSSFWorkbook workbook) {
+ HSSFFont font = workbook.createFont();
+ font.setBold(true);
+ HSSFCellStyle style = workbook.createCellStyle();
+ style.setFont(font);
+ return style;
+ }
+
+ /**
+ *
+ * @param list
+ * @throws IOException
+ */
+ public static void NhanVienExport(List list) throws IOException {
+
+ HSSFWorkbook workbook = new HSSFWorkbook();
+ HSSFSheet sheet = workbook.createSheet("Employees sheet");
+
+
+ int rownum = 0;
+ Cell cell;
+ Row row;
+ //
+ HSSFCellStyle style = createStyleForTitle(workbook);
+
+ row = sheet.createRow(rownum);
+
+ // EmpNo
+ cell = row.createCell(0, CellType.STRING);
+ cell.setCellValue("Mã NV");
+ cell.setCellStyle(style);
+ // EmpName
+ cell = row.createCell(1, CellType.STRING);
+ cell.setCellValue("Tên NV");
+ cell.setCellStyle(style);
+
+ cell = row.createCell(2, CellType.NUMERIC);
+ cell.setCellValue("Năm sinh");
+ cell.setCellStyle(style);
+
+ // Salary
+ cell = row.createCell(3, CellType.STRING);
+ cell.setCellValue("Giới tính");
+ cell.setCellStyle(style);
+ // Grade
+ cell = row.createCell(4, CellType.STRING);
+ cell.setCellValue("Địa chỉ");
+ cell.setCellStyle(style);
+ // Bonus
+ cell = row.createCell(5, CellType.STRING);
+ cell.setCellValue("Công việc");
+ cell.setCellStyle(style);
+
+ // Data
+ for (Nhanvien emp : list) {
+ rownum++;
+ row = sheet.createRow(rownum);
+
+ // EmpNo (A)
+ cell = row.createCell(0, CellType.STRING);
+ cell.setCellValue(emp.getMacb());
+ // EmpName (B)
+ cell = row.createCell(1, CellType.STRING);
+ cell.setCellValue(emp.getTencb());
+
+ cell = row.createCell(2, CellType.NUMERIC);
+ cell.setCellValue(emp.getNamsinh());
+
+ cell = row.createCell(3, CellType.STRING);
+ cell.setCellValue(emp.getGioitinh());
+ // Grade (D)
+ cell = row.createCell(4, CellType.STRING);
+ cell.setCellValue(emp.getDiachi());
+
+ cell = row.createCell(5, CellType.STRING);
+ cell.setCellValue(emp.getCongviec());
+
+
+ }
+ File file = new File("D:/employee.xls");
+ file.getParentFile().mkdirs();
+
+ FileOutputStream outFile = new FileOutputStream(file);
+ workbook.write(outFile);
+ System.out.println("Created file: " + file.getAbsolutePath());
+
+ }
+
+ public static void KySuExport(List list) throws IOException {
+
+ HSSFWorkbook workbook = new HSSFWorkbook();
+ HSSFSheet sheet = workbook.createSheet("Employees sheet");
+
+
+ int rownum = 0;
+ Cell cell;
+ Row row;
+ //
+ HSSFCellStyle style = createStyleForTitle(workbook);
+
+ row = sheet.createRow(rownum);
+
+ // EmpNo
+ cell = row.createCell(0, CellType.STRING);
+ cell.setCellValue("Mã NV");
+ cell.setCellStyle(style);
+ // EmpName
+ cell = row.createCell(1, CellType.STRING);
+ cell.setCellValue("Tên NV");
+ cell.setCellStyle(style);
+
+ cell = row.createCell(2, CellType.NUMERIC);
+ cell.setCellValue("Năm sinh");
+ cell.setCellStyle(style);
+
+ // Salary
+ cell = row.createCell(3, CellType.STRING);
+ cell.setCellValue("Giới tính");
+ cell.setCellStyle(style);
+ // Grade
+ cell = row.createCell(4, CellType.STRING);
+ cell.setCellValue("Địa chỉ");
+ cell.setCellStyle(style);
+ // Bonus
+ cell = row.createCell(5, CellType.STRING);
+ cell.setCellValue("Ngành đào tạo");
+ cell.setCellStyle(style);
+
+ cell = row.createCell(5, CellType.STRING);
+ cell.setCellValue("Loại bằng");
+ cell.setCellStyle(style);
+
+ // Data
+ for (Kysu emp : list) {
+ rownum++;
+ row = sheet.createRow(rownum);
+
+ // EmpNo (A)
+ cell = row.createCell(0, CellType.STRING);
+ cell.setCellValue(emp.getMacb());
+ // EmpName (B)
+ cell = row.createCell(1, CellType.STRING);
+ cell.setCellValue(emp.getTencb());
+
+ cell = row.createCell(2, CellType.NUMERIC);
+ cell.setCellValue(emp.getNamsinh());
+
+ cell = row.createCell(3, CellType.STRING);
+ cell.setCellValue(emp.getGioitinh());
+ // Grade (D)
+ cell = row.createCell(4, CellType.STRING);
+ cell.setCellValue(emp.getDiachi());
+
+ cell = row.createCell(5, CellType.STRING);
+ cell.setCellValue(emp.getNganhdt());
+
+ cell = row.createCell(5, CellType.STRING);
+ cell.setCellValue(emp.getLoaibang());
+
+ }
+ File file = new File("D:/engineer.xls");
+ file.getParentFile().mkdirs();
+
+ FileOutputStream outFile = new FileOutputStream(file);
+ workbook.write(outFile);
+ System.out.println("Created file: " + file.getAbsolutePath());
+
+ }
+ public static void WorkerExport(List list) throws IOException {
+
+ HSSFWorkbook workbook = new HSSFWorkbook();
+ HSSFSheet sheet = workbook.createSheet("Employees sheet");
+
+
+ int rownum = 0;
+ Cell cell;
+ Row row;
+ //
+ HSSFCellStyle style = createStyleForTitle(workbook);
+
+ row = sheet.createRow(rownum);
+
+ // EmpNo
+ cell = row.createCell(0, CellType.STRING);
+ cell.setCellValue("Mã NV");
+ cell.setCellStyle(style);
+ // EmpName
+ cell = row.createCell(1, CellType.STRING);
+ cell.setCellValue("Tên NV");
+ cell.setCellStyle(style);
+
+ cell = row.createCell(2, CellType.NUMERIC);
+ cell.setCellValue("Năm sinh");
+ cell.setCellStyle(style);
+
+ // Salary
+ cell = row.createCell(3, CellType.STRING);
+ cell.setCellValue("Giới tính");
+ cell.setCellStyle(style);
+ // Grade
+ cell = row.createCell(4, CellType.STRING);
+ cell.setCellValue("Địa chỉ");
+ cell.setCellStyle(style);
+ // Bonus
+ cell = row.createCell(5, CellType.STRING);
+ cell.setCellValue("Bậc");
+ cell.setCellStyle(style);
+
+ // Data
+ for (Congnhan emp : list) {
+ rownum++;
+ row = sheet.createRow(rownum);
+
+ // EmpNo (A)
+ cell = row.createCell(0, CellType.STRING);
+ cell.setCellValue(emp.getMacb());
+ // EmpName (B)
+ cell = row.createCell(1, CellType.STRING);
+ cell.setCellValue(emp.getTencb());
+
+ cell = row.createCell(2, CellType.NUMERIC);
+ cell.setCellValue(emp.getNamsinh());
+
+ cell = row.createCell(3, CellType.STRING);
+ cell.setCellValue(emp.getGioitinh());
+ // Grade (D)
+ cell = row.createCell(4, CellType.STRING);
+ cell.setCellValue(emp.getDiachi());
+
+ cell = row.createCell(5, CellType.STRING);
+ cell.setCellValue(emp.getBac());
+
+ }
+ File file = new File("D:/worker.xls");
+ file.getParentFile().mkdirs();
+
+ FileOutputStream outFile = new FileOutputStream(file);
+ workbook.write(outFile);
+ System.out.println("Created file: " + file.getAbsolutePath());
+
+ }
+
+}
diff --git a/src/main/java/com/mycompany/qlcb/filehelpers/ExportKySu.java b/src/main/java/com/mycompany/qlcb/filehelpers/ExportKySu.java
new file mode 100644
index 0000000..9f16f27
--- /dev/null
+++ b/src/main/java/com/mycompany/qlcb/filehelpers/ExportKySu.java
@@ -0,0 +1,112 @@
+
+package com.mycompany.qlcb.filehelpers;
+
+import com.mycompany.qlcb.model.Kysu;
+import com.mycompany.qlcb.model.Kysu;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.poi.hssf.usermodel.HSSFCellStyle;
+import org.apache.poi.hssf.usermodel.HSSFFont;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.Row;
+
+
+public class ExportKySu {
+
+ private static HSSFCellStyle createStyleForTitle(HSSFWorkbook workbook) {
+ HSSFFont font = workbook.createFont();
+ font.setBold(true);
+ HSSFCellStyle style = workbook.createCellStyle();
+ style.setFont(font);
+ return style;
+ }
+
+ /**
+ *
+ * @param list
+ * @throws IOException
+ */
+ public void Export(List list) throws IOException {
+
+ HSSFWorkbook workbook = new HSSFWorkbook();
+ HSSFSheet sheet = workbook.createSheet("Employees sheet");
+
+
+ int rownum = 0;
+ Cell cell;
+ Row row;
+ //
+ HSSFCellStyle style = createStyleForTitle(workbook);
+
+ row = sheet.createRow(rownum);
+
+ // EmpNo
+ cell = row.createCell(0, CellType.STRING);
+ cell.setCellValue("Mã NV");
+ cell.setCellStyle(style);
+ // EmpName
+ cell = row.createCell(1, CellType.STRING);
+ cell.setCellValue("Tên NV");
+ cell.setCellStyle(style);
+
+ cell = row.createCell(2, CellType.NUMERIC);
+ cell.setCellValue("Năm sinh");
+ cell.setCellStyle(style);
+
+ // Salary
+ cell = row.createCell(3, CellType.STRING);
+ cell.setCellValue("Giới tính");
+ cell.setCellStyle(style);
+ // Grade
+ cell = row.createCell(4, CellType.STRING);
+ cell.setCellValue("Địa chỉ");
+ cell.setCellStyle(style);
+ // Bonus
+ cell = row.createCell(5, CellType.STRING);
+ cell.setCellValue("Công việc");
+ cell.setCellStyle(style);
+
+ // Data
+ for (Kysu emp : list) {
+ rownum++;
+ row = sheet.createRow(rownum);
+
+ // EmpNo (A)
+ cell = row.createCell(0, CellType.STRING);
+ cell.setCellValue(emp.getMacb());
+ // EmpName (B)
+ cell = row.createCell(1, CellType.STRING);
+ cell.setCellValue(emp.getTencb());
+
+ cell = row.createCell(2, CellType.NUMERIC);
+ cell.setCellValue(emp.getNamsinh());
+
+ cell = row.createCell(3, CellType.STRING);
+ cell.setCellValue(emp.getGioitinh());
+ // Grade (D)
+ cell = row.createCell(4, CellType.STRING);
+ cell.setCellValue(emp.getDiachi());
+
+ cell = row.createCell(5, CellType.STRING);
+ cell.setCellValue(emp.getNganhdt());
+
+
+ }
+ File file = new File("D:/employee.xls");
+ file.getParentFile().mkdirs();
+
+ FileOutputStream outFile = new FileOutputStream(file);
+ workbook.write(outFile);
+ System.out.println("Created file: " + file.getAbsolutePath());
+
+ }
+
+
+
+}
diff --git a/src/main/java/com/mycompany/qlcb/model/NguoiDung.java b/src/main/java/com/mycompany/qlcb/model/NguoiDung.java
index 45f5862..ea9a4c4 100644
--- a/src/main/java/com/mycompany/qlcb/model/NguoiDung.java
+++ b/src/main/java/com/mycompany/qlcb/model/NguoiDung.java
@@ -6,6 +6,9 @@ public class NguoiDung {
private int macb;
public NguoiDung() {
+ tenDangNhap = "";
+ matKhau = "";
+ vaiTro = "";
}
public NguoiDung(String tenDangNhap, String matKhau,int macb, String vaiTro) {
diff --git a/src/main/java/com/mycompany/qlcb/model/TaiKhoan.java b/src/main/java/com/mycompany/qlcb/model/TaiKhoan.java
new file mode 100644
index 0000000..7fcc662
--- /dev/null
+++ b/src/main/java/com/mycompany/qlcb/model/TaiKhoan.java
@@ -0,0 +1,59 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
+ */
+package com.mycompany.qlcb.model;
+
+/**
+ *
+ * @author Duc
+ */
+public class TaiKhoan {
+ private int macb, quyen;
+ private String username, trangthai;
+
+ public int getMacb() {
+ return macb;
+ }
+
+ public void setMacb(int macb) {
+ this.macb = macb;
+ }
+
+ public int getQuyen() {
+ return quyen;
+ }
+
+ public void setQuyen(int quyen) {
+ this.quyen = quyen;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getTrangthai() {
+ return trangthai;
+ }
+
+ public void setTrangthai(String trangthai) {
+ this.trangthai = trangthai;
+ }
+
+ public TaiKhoan(int macb, int quyen, String username, String trangthai) {
+ this.macb = macb;
+ this.quyen = quyen;
+ this.username = username;
+ this.trangthai = trangthai;
+ }
+
+ public TaiKhoan() {
+ }
+
+
+
+}
diff --git a/src/main/java/com/mycompany/qlcb/ui/AccountManagementPanel.form b/src/main/java/com/mycompany/qlcb/ui/AccountManagementPanel.form
new file mode 100644
index 0000000..c78fa81
--- /dev/null
+++ b/src/main/java/com/mycompany/qlcb/ui/AccountManagementPanel.form
@@ -0,0 +1,225 @@
+
+
+
diff --git a/src/main/java/com/mycompany/qlcb/ui/AccountManagementPanel.java b/src/main/java/com/mycompany/qlcb/ui/AccountManagementPanel.java
new file mode 100644
index 0000000..3b300d2
--- /dev/null
+++ b/src/main/java/com/mycompany/qlcb/ui/AccountManagementPanel.java
@@ -0,0 +1,328 @@
+/*
+ * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
+ * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JPanel.java to edit this template
+ */
+package com.mycompany.qlcb.ui;
+
+import com.mycompany.qlcb.dao.CanBoDao;
+import com.mycompany.qlcb.dao.NhanVienDao;
+import com.mycompany.qlcb.helpers.DataValidator;
+import com.mycompany.qlcb.helpers.MessageDialogHelper;
+import com.mycompany.qlcb.model.Canbo;
+import com.mycompany.qlcb.model.Nhanvien;
+import com.mycompany.qlcb.model.TaiKhoan;
+import java.util.ArrayList;
+import javax.swing.JOptionPane;
+import javax.swing.table.DefaultTableModel;
+
+/**
+ *
+ * @author Duc
+ */
+public class AccountManagementPanel extends javax.swing.JPanel {
+
+ private MainForm parentForm;
+ private DefaultTableModel tblModel;
+
+ public AccountManagementPanel() {
+ initComponents();
+ initTable();
+ loadDataToTable();
+ }
+
+ private void initTable() {
+ tblModel = new DefaultTableModel();
+ tblModel.setColumnIdentifiers(new String[] {"Mã CB","Tên đăng nhập","Quyền", "Trạng thái"});
+ tbAccount.setModel(tblModel);
+ }
+
+ public void loadDataToTable() {
+ try {
+ CanBoDao dao = new CanBoDao();
+ ArrayList list = dao.getInfoAccount();
+ tblModel.setRowCount(0);
+
+ for (TaiKhoan it:list) {
+ String cv = null;
+ if (it.getQuyen() == 0) cv = "Quản trị viên";
+ else if (it.getQuyen() == 1) cv = "User thường";
+
+ tblModel.addRow(new Object[] {
+ it.getMacb(),it.getUsername(), cv, it.getTrangthai()
+ });
+ }
+ tblModel.fireTableDataChanged();
+
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ MessageDialogHelper.showErrorDialog(parentForm, e.getMessage(), "Lỗi");
+ }
+ }
+ @SuppressWarnings("unchecked")
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ jScrollPane1 = new javax.swing.JScrollPane();
+ tbAccount = new javax.swing.JTable();
+ jLabel1 = new javax.swing.JLabel();
+ jLabel2 = new javax.swing.JLabel();
+ txtId = new javax.swing.JTextField();
+ txtUsername = new javax.swing.JTextField();
+ jLabel3 = new javax.swing.JLabel();
+ jLabel4 = new javax.swing.JLabel();
+ jButton1 = new javax.swing.JButton();
+ jLabel5 = new javax.swing.JLabel();
+ tblReload = new javax.swing.JButton();
+ cbRule = new javax.swing.JComboBox<>();
+ cbStatus = new javax.swing.JComboBox<>();
+
+ tbAccount.setModel(new javax.swing.table.DefaultTableModel(
+ new Object [][] {
+ {null, null, null, null},
+ {null, null, null, null},
+ {null, null, null, null},
+ {null, null, null, null}
+ },
+ new String [] {
+ "Title 1", "Title 2", "Title 3", "Title 4"
+ }
+ ));
+ tbAccount.addMouseListener(new java.awt.event.MouseAdapter() {
+ public void mouseClicked(java.awt.event.MouseEvent evt) {
+ tbAccountMouseClicked(evt);
+ }
+ });
+ jScrollPane1.setViewportView(tbAccount);
+
+ jLabel1.setFont(new java.awt.Font("Segoe UI", 1, 16)); // NOI18N
+ jLabel1.setForeground(new java.awt.Color(255, 51, 51));
+ jLabel1.setText("QUẢN LÝ TÀI KHOẢN NGƯỜI DÙNG");
+
+ jLabel2.setText("ID:");
+
+ txtUsername.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ txtUsernameActionPerformed(evt);
+ }
+ });
+
+ jLabel3.setText("Username");
+
+ jLabel4.setText("Quyền");
+
+ jButton1.setBackground(new java.awt.Color(0, 204, 255));
+ jButton1.setForeground(new java.awt.Color(255, 0, 51));
+ jButton1.setText("Cập nhật");
+ jButton1.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ jButton1ActionPerformed(evt);
+ }
+ });
+
+ jLabel5.setText("Trạng thái");
+
+ tblReload.setText("Reload");
+ tblReload.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ tblReloadActionPerformed(evt);
+ }
+ });
+
+ cbRule.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Quản trị viên", "User thường" }));
+ cbRule.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ cbRuleActionPerformed(evt);
+ }
+ });
+
+ cbStatus.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Đang hoạt động", "Vô hiệu hóa" }));
+ cbStatus.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ cbStatusActionPerformed(evt);
+ }
+ });
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+ this.setLayout(layout);
+ layout.setHorizontalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(15, 15, 15)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 341, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(0, 0, Short.MAX_VALUE))
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE)
+ .addGap(27, 27, 27)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(jLabel3)
+ .addComponent(jLabel2)
+ .addComponent(jLabel4))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+ .addComponent(txtUsername, javax.swing.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)
+ .addComponent(txtId)))
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jLabel5)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(11, 11, 11)
+ .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addComponent(tblReload, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGroup(layout.createSequentialGroup()
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+ .addComponent(cbRule, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(cbStatus, 0, 144, Short.MAX_VALUE))))))
+ .addContainerGap())))
+ );
+ layout.setVerticalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addGap(23, 23, 23)
+ .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
+ .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jLabel2))
+ .addGap(20, 20, 20)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGap(15, 15, 15)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel4)
+ .addComponent(cbRule, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel5)
+ .addComponent(cbStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jButton1)
+ .addComponent(tblReload)))
+ .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 368, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addContainerGap(23, Short.MAX_VALUE))
+ );
+ }// //GEN-END:initComponents
+
+ private void txtUsernameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtUsernameActionPerformed
+ // TODO add your handling code here:
+ }//GEN-LAST:event_txtUsernameActionPerformed
+
+ private void tbAccountMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbAccountMouseClicked
+ try {
+ // Lấy ra dong được click
+ int row = tbAccount.getSelectedRow();
+ if (row >= 0) {
+ txtId.setText(String.valueOf(tbAccount.getValueAt(row, 0)));
+ txtUsername.setText((String)tbAccount.getValueAt(row, 1));
+ if ((String)tbAccount.getValueAt(row, 2) == "Quản trị viên") {
+ cbRule.setSelectedIndex(0);
+ }
+ else if ((String)tbAccount.getValueAt(row, 2) == "User thường") {
+ cbRule.setSelectedIndex(1);
+ }
+
+
+ if ((String)tbAccount.getValueAt(row, 3) == "Đang hoạt động") {
+ System.out.println("alo 1");
+ cbStatus.setSelectedIndex(0);
+ }
+ else if ((String)tbAccount.getValueAt(row, 3) == "Vô hiệu hóa")
+ {
+ System.out.println("alo2");
+ cbStatus.setSelectedIndex(1);
+ }
+ }
+ } catch (Exception e) {
+ MessageDialogHelper.showErrorDialog(parentForm, e.getMessage(), "Lỗi");
+ }
+ }//GEN-LAST:event_tbAccountMouseClicked
+
+ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
+ StringBuilder sb = new StringBuilder();
+ DataValidator.validateEmpty(txtId, sb, "Mã cán bộ không được để trống!!");
+ DataValidator.validateEmpty(txtUsername, sb, "Tên đăng nhập không được bỏ trống!!");
+
+ // Nếu có lỗi
+ if (sb.length() > 0) {
+ MessageDialogHelper.showErrorDialog(parentForm, sb.toString(), "Lỗi");
+ return;
+ }
+
+ if (MessageDialogHelper.showConfirmDialog(parentForm, "Bạn có muốn cập nhật sinh tài khoản?",
+ "Xác nhận") == JOptionPane.NO_OPTION) {
+ return;
+ }
+ try {
+ // Lấy dữ liệu từ trên form xuống
+ TaiKhoan tk = new TaiKhoan();
+ tk.setMacb(Integer.parseInt(txtId.getText()));
+ int quyen = 0;
+ if (rule.equalsIgnoreCase("Admin")) quyen = 0;
+ else if (rule.equalsIgnoreCase("User thường")) quyen = 1;
+
+
+
+ tk.setTrangthai(status);
+
+ CanBoDao dao = new CanBoDao();
+
+
+ if (dao.update(tk))
+ {
+ loadDataToTable();
+ MessageDialogHelper.showMessageDialog(parentForm, "Tài khoản đã được cập nhật thành công!!",
+ "Thông báo");
+ }
+ else {
+ MessageDialogHelper.showConfirmDialog(parentForm,
+ "Tài khoản không được cập nhật do lỗi", "Cảnh báo");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ MessageDialogHelper.showErrorDialog(parentForm, e.getMessage(), "Lỗi");
+ }
+ }//GEN-LAST:event_jButton1ActionPerformed
+
+ private void tblReloadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tblReloadActionPerformed
+ loadDataToTable();
+ }//GEN-LAST:event_tblReloadActionPerformed
+
+ String rule = "";
+ private void cbRuleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbRuleActionPerformed
+ String txt = (String)cbRule.getSelectedItem();
+ rule = txt;
+ }//GEN-LAST:event_cbRuleActionPerformed
+
+ String status = "";
+ private void cbStatusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbStatusActionPerformed
+ String txt = (String)cbStatus.getSelectedItem();
+ status = txt;
+ }//GEN-LAST:event_cbStatusActionPerformed
+
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JComboBox cbRule;
+ private javax.swing.JComboBox cbStatus;
+ private javax.swing.JButton jButton1;
+ private javax.swing.JLabel jLabel1;
+ private javax.swing.JLabel jLabel2;
+ private javax.swing.JLabel jLabel3;
+ private javax.swing.JLabel jLabel4;
+ private javax.swing.JLabel jLabel5;
+ private javax.swing.JScrollPane jScrollPane1;
+ private javax.swing.JTable tbAccount;
+ private javax.swing.JButton tblReload;
+ private javax.swing.JTextField txtId;
+ private javax.swing.JTextField txtUsername;
+ // End of variables declaration//GEN-END:variables
+}
diff --git a/src/main/java/com/mycompany/qlcb/ui/EmployeeManagementPanel.form b/src/main/java/com/mycompany/qlcb/ui/EmployeeManagementPanel.form
index 6a5702d..c6e69c9 100644
--- a/src/main/java/com/mycompany/qlcb/ui/EmployeeManagementPanel.form
+++ b/src/main/java/com/mycompany/qlcb/ui/EmployeeManagementPanel.form
@@ -28,165 +28,212 @@
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
+
-
+
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
@@ -244,8 +291,6 @@
-
-
@@ -407,6 +452,9 @@
+
+
+
@@ -475,5 +523,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/com/mycompany/qlcb/ui/EmployeeManagementPanel.java b/src/main/java/com/mycompany/qlcb/ui/EmployeeManagementPanel.java
index d1a0c2a..0826a5b 100644
--- a/src/main/java/com/mycompany/qlcb/ui/EmployeeManagementPanel.java
+++ b/src/main/java/com/mycompany/qlcb/ui/EmployeeManagementPanel.java
@@ -4,6 +4,7 @@
import com.mycompany.qlcb.dao.NhanVienDao;
import com.mycompany.qlcb.helpers.DataValidator;
import com.mycompany.qlcb.helpers.MessageDialogHelper;
+import com.mycompany.qlcb.filehelpers.ExportBase;
import com.mycompany.qlcb.helpers.VNCharacterUtils;
import com.mycompany.qlcb.model.Nhanvien;
import java.util.ArrayList;
@@ -12,16 +13,16 @@
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
-
+import org.apache.poi.ss.formula.functions.Count;
public class EmployeeManagementPanel extends javax.swing.JPanel {
-
+
private MainForm parentForm;
private DefaultTableModel tblModel;
ArrayList list;
String fieldSort = "tencb";
String sortType = "ASC";
-
+
public EmployeeManagementPanel() {
initComponents();
rdNam.setSelected(true);
@@ -31,26 +32,25 @@ public EmployeeManagementPanel() {
}
private void initTable() {
- tblModel = new DefaultTableModel();
- tblModel.setColumnIdentifiers(new String[] {"Mã NV","Họ tên","Năm sinh", "Giới tính",
- "Địa chỉ", "Công việc"});
- tblEmployee.setModel(tblModel);
+ tblModel = new DefaultTableModel();
+ tblModel.setColumnIdentifiers(new String[]{"Mã NV", "Họ tên", "Năm sinh", "Giới tính",
+ "Địa chỉ", "Công việc"});
+ tblEmployee.setModel(tblModel);
}
-
+
private void loadDataToTable() {
try {
NhanVienDao dao = new NhanVienDao();
ArrayList list = dao.getAllNhanVien(null, "");
tblModel.setRowCount(0);
- for (Nhanvien it:list) {
- tblModel.addRow(new Object[] {
- it.getMacb(),it.getTencb(), it.getNamsinh(), it.getGioitinh(),
+ for (Nhanvien it : list) {
+ tblModel.addRow(new Object[]{
+ it.getMacb(), it.getTencb(), it.getNamsinh(), it.getGioitinh(),
it.getDiachi(), it.getCongviec()
});
}
tblModel.fireTableDataChanged();
- }
- catch (Exception e) {
+ } catch (Exception e) {
e.printStackTrace();
MessageDialogHelper.showErrorDialog(parentForm, e.getMessage(), "Lỗi");
}
@@ -72,7 +72,6 @@ private void initComponents() {
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
txtName = new javax.swing.JTextField();
- jSeparator2 = new javax.swing.JSeparator();
txtNamSinh = new javax.swing.JTextField();
txtAddress = new javax.swing.JTextField();
rdNam = new javax.swing.JRadioButton();
@@ -94,6 +93,9 @@ private void initComponents() {
cbField = new javax.swing.JComboBox<>();
cbSort = new javax.swing.JComboBox<>();
btnSort = new javax.swing.JButton();
+ jButton1 = new javax.swing.JButton();
+ btnExport = new javax.swing.JButton();
+ jLabel7 = new javax.swing.JLabel();
jLabel1.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
jLabel1.setText("QUẢN LÝ NHÂN VIÊN");
@@ -240,156 +242,202 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});
+ jButton1.setText("Reset mật khẩu");
+ jButton1.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ jButton1ActionPerformed(evt);
+ }
+ });
+
+ btnExport.setText("Xuất file");
+ btnExport.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ btnExportActionPerformed(evt);
+ }
+ });
+
+ jLabel7.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
+ jLabel7.setText("Sắp xếp");
+
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
+ .addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
- .addGap(12, 12, 12)
- .addComponent(jLabel2)
- .addGap(83, 83, 83)
- .addComponent(txtName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addGap(12, 12, 12)
- .addComponent(jLabel3)
- .addGap(66, 66, 66)
- .addComponent(txtNamSinh, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addGap(12, 12, 12)
- .addComponent(jLabel5)
- .addGap(84, 84, 84)
- .addComponent(txtAddress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addGap(12, 12, 12)
- .addComponent(jLabel8)
- .addGap(65, 65, 65)
- .addComponent(txtJob, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .addComponent(jLabel4)
+ .addGap(36, 36, 36)
+ .addComponent(rdNam)
+ .addGap(26, 26, 26)
+ .addComponent(rdNu))
.addGroup(layout.createSequentialGroup()
- .addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jSeparator1)
- .addComponent(jSeparator2)
- .addComponent(jSeparator3)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)))
- .addGroup(layout.createSequentialGroup()
- .addGap(12, 12, 12)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel1)
.addGroup(layout.createSequentialGroup()
- .addComponent(jLabel4)
- .addGap(73, 73, 73)
- .addComponent(rdNam)
- .addGap(79, 79, 79)
- .addComponent(rdNu)))
- .addGap(0, 362, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jLabel6)
- .addGap(28, 28, 28)
- .addComponent(txtSearch)
+ .addComponent(jLabel2)
+ .addGap(46, 46, 46)
+ .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(24, 24, 24)
+ .addComponent(jLabel6))
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jLabel3)
+ .addGap(29, 29, 29)
+ .addComponent(txtNamSinh, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(26, 26, 26)
+ .addComponent(jLabel7)))
.addGap(18, 18, 18)
- .addComponent(btnSeach)))
- .addContainerGap())
- .addGroup(layout.createSequentialGroup()
- .addGap(139, 139, 139)
- .addComponent(btnNew)
- .addGap(50, 50, 50)
- .addComponent(btnSave)
- .addGap(58, 58, 58)
- .addComponent(btnUpdate)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 75, Short.MAX_VALUE)
- .addComponent(btnDelete)
- .addGap(21, 21, 21))
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addComponent(cbField, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addComponent(cbSort, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
+ .addComponent(btnSeach)
+ .addComponent(btnSort, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))))
+ .addGap(0, 55, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(cbField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addComponent(cbSort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(btnSort)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(23, 23, 23)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jLabel1)
+ .addGap(0, 0, Short.MAX_VALUE))))
+ .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
+ .addComponent(txtMaNghe, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(0, 0, Short.MAX_VALUE))
+ .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(24, 24, 24)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(btnNew, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(18, 18, 18)
+ .addComponent(btnSave, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(26, 26, 26)
+ .addComponent(btnUpdate))
+ .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 340, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(18, 18, 18)
+ .addComponent(btnDelete, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .addGroup(layout.createSequentialGroup()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(jLabel5)
+ .addComponent(jLabel8))
+ .addGap(27, 27, 27)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(txtJob, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE))))
+ .addGap(26, 26, 26))
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addContainerGap()
+ .addComponent(txtmanv, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(67, 67, 67)))
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 485, Short.MAX_VALUE)
+ .addComponent(btnExport, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
+ .addComponent(txtMaNghe, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addGap(18, 18, 18)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(16, 16, 16)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(10, 10, 10)
- .addComponent(jLabel2))
- .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel3)
- .addComponent(txtNamSinh, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(12, 12, 12)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(btnSeach, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
- .addGap(1, 1, 1)
- .addComponent(jLabel4))
- .addComponent(rdNam)
- .addComponent(rdNu))
- .addGap(9, 9, 9)
+ .addGap(4, 4, 4)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(jLabel2)
+ .addComponent(jLabel6))))
+ .addGap(6, 6, 6)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
- .addGap(10, 10, 10)
- .addComponent(jLabel5))
- .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(13, 13, 13)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(txtNamSinh, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(4, 4, 4)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(jLabel3)
+ .addComponent(jLabel7))))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(rdNam)
+ .addComponent(rdNu)))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(4, 4, 4)
+ .addComponent(jLabel5))
+ .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGap(13, 13, 13)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(4, 4, 4)
+ .addComponent(jLabel8))
+ .addComponent(txtJob, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGap(22, 22, 22)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(btnNew)
+ .addComponent(btnSave)
+ .addComponent(btnUpdate))
+ .addGap(18, 18, 18)
+ .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jButton1)
+ .addComponent(btnDelete))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 134, Short.MAX_VALUE)
+ .addComponent(txtmanv, 0, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(25, 25, 25))
.addGroup(layout.createSequentialGroup()
- .addGap(10, 10, 10)
- .addComponent(jLabel8))
- .addComponent(txtJob, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(13, 13, 13)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(btnSave)
- .addComponent(btnNew))
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(btnUpdate)
- .addComponent(btnDelete)))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(5, 5, 5)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(btnSeach, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel6)))
- .addGap(18, 18, 18)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(cbField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(cbSort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(btnSort))
- .addContainerGap())
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(cbField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(cbSort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(btnSort)
+ .addGap(0, 0, Short.MAX_VALUE)))
+ .addGap(18, 18, 18)
+ .addComponent(btnExport)
+ .addContainerGap())))
);
+
+ txtMaNghe.getAccessibleContext().setAccessibleName("");
}// //GEN-END:initComponents
private void txtNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNameActionPerformed
-
+
}//GEN-LAST:event_txtNameActionPerformed
private void txtNamSinhActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNamSinhActionPerformed
-
+
}//GEN-LAST:event_txtNamSinhActionPerformed
private void txtAddressActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtAddressActionPerformed
-
+
}//GEN-LAST:event_txtAddressActionPerformed
private void txtJobActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtJobActionPerformed
-
+
}//GEN-LAST:event_txtJobActionPerformed
private void btnNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewActionPerformed
@@ -400,8 +448,7 @@ private void btnNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:
rdNam.setSelected(true);
rdNu.setSelected(false);
}//GEN-LAST:event_btnNewActionPerformed
-
-
+
// Sự kiện save
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
StringBuilder sb = new StringBuilder();
@@ -409,60 +456,53 @@ private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST
DataValidator.validateEmpty(txtNamSinh, sb, "Năm sinh không được bỏ trống!!");
DataValidator.validateEmpty(txtAddress, sb, "Địa chỉ không được bỏ trống!");
DataValidator.validateEmpty(txtJob, sb, "Công việc không được bỏ trống!!");
-
+
// Nếu có lỗi
if (sb.length() > 0) {
MessageDialogHelper.showErrorDialog(parentForm, sb.toString(), "Lỗi");
return;
}
-
-
+
try {
// Lấy dữ liệu từ trên form xuống
Nhanvien nv = new Nhanvien();
nv.setTencb(txtName.getText());
nv.setNamsinh(Integer.parseInt(txtNamSinh.getText()));
- nv.setGioitinh(rdNam.isSelected()?"Nam":"Nữ");
+ nv.setGioitinh(rdNam.isSelected() ? "Nam" : "Nữ");
nv.setCongviec(txtJob.getText());
nv.setDiachi(txtAddress.getText());
int manghe = Integer.parseInt(txtMaNghe.getText());
CanBoDao dao = new CanBoDao();
-
-
- if (dao.insertCB(nv, manghe))
- {
+
+ if (dao.insertCB(nv, manghe)) {
MessageDialogHelper.showMessageDialog(parentForm, "Công nhân đã được thêm thành công!!",
- "Thông báo");
- }
- else {
- MessageDialogHelper.showConfirmDialog(parentForm,
+ "Thông báo");
+ } else {
+ MessageDialogHelper.showConfirmDialog(parentForm,
"Công nhân không được lưu do lỗi", "Cảnh báo");
}
-
-
+
// Lấy ra mã cán bộ cuối cùng trong bảng để chèn vào bảng Công nhân
-
if (dao.getLastIdCB() != -1) {
int macb = dao.getLastIdCB();
-
+
// Chèn vào bảng Công nhân
dao.insertTable("tbl_nhanvien", macb, txtJob.getText(), "");
SatisticManagementPanel sasPanel = new SatisticManagementPanel();
sasPanel.loadDataToTable1();
-
+
//tao tai khoan tu dong
String tk = VNCharacterUtils.removeAccent(txtName.getText()).replace(" ", "").toLowerCase();
System.out.print(tk);
Random rand = new Random();
String mk = String.valueOf(rand.nextInt(100000000));
- if(dao.insertTaiKhoan(tk, mk, macb, Integer.valueOf(txtMaNghe.getText()))){
- MessageDialogHelper.showMessageDialog(parentForm, "Tạo tài khoản thành công!\nTài khoản: "+tk+"\nMật khẩu: "+mk,
- "Thông báo");
+ if (dao.insertTaiKhoan(tk, mk, macb, Integer.valueOf(txtMaNghe.getText()))) {
+ MessageDialogHelper.showMessageDialog(parentForm, "Tạo tài khoản thành công!\nTài khoản: " + tk + "\nMật khẩu: " + mk,
+ "Thông báo");
}
loadDataToTable();
}
-
-
+
} catch (Exception e) {
e.printStackTrace();
MessageDialogHelper.showErrorDialog(parentForm, e.getMessage(), "Lỗi");
@@ -475,14 +515,14 @@ private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR
DataValidator.validateEmpty(txtNamSinh, sb, "Năm sinh không được bỏ trống!!");
DataValidator.validateEmpty(txtAddress, sb, "Địa chỉ không được bỏ trống!");
DataValidator.validateEmpty(txtJob, sb, "Công việc không được bỏ trống!!");
-
+
// Nếu có lỗi
if (sb.length() > 0) {
MessageDialogHelper.showErrorDialog(parentForm, sb.toString(), "Lỗi");
return;
}
-
- if (MessageDialogHelper.showConfirmDialog(parentForm, "Bạn có muốn cập nhật sinh viên không?",
+
+ if (MessageDialogHelper.showConfirmDialog(parentForm, "Bạn có muốn cập nhật sinh viên không?",
"Xác nhận") == JOptionPane.NO_OPTION) {
return;
}
@@ -491,21 +531,18 @@ private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR
Nhanvien nv = new Nhanvien();
nv.setTencb(txtName.getText());
nv.setNamsinh(Integer.parseInt(txtNamSinh.getText()));
- nv.setGioitinh(rdNam.isSelected()?"Nam":"Nữ");
+ nv.setGioitinh(rdNam.isSelected() ? "Nam" : "Nữ");
nv.setCongviec(txtJob.getText());
nv.setDiachi(txtAddress.getText());
nv.setMacb(Integer.parseInt(txtmanv.getText()));
NhanVienDao dao = new NhanVienDao();
-
-
- if (dao.update(nv))
- {
+
+ if (dao.update(nv)) {
loadDataToTable();
MessageDialogHelper.showMessageDialog(parentForm, "Công nhân đã được cập nhật thành công!!",
- "Thông báo");
- }
- else {
- MessageDialogHelper.showConfirmDialog(parentForm,
+ "Thông báo");
+ } else {
+ MessageDialogHelper.showConfirmDialog(parentForm,
"Công nhân không được cập nhật do lỗi", "Cảnh báo");
}
} catch (Exception e) {
@@ -520,18 +557,18 @@ private void tblEmployeeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST
int row = tblEmployee.getSelectedRow();
if (row >= 0) {
txtmanv.setText(String.valueOf(tblModel.getValueAt(row, 0)));
- txtName.setText((String)tblModel.getValueAt(row, 1));
+ txtName.setText((String) tblModel.getValueAt(row, 1));
txtNamSinh.setText(String.valueOf(tblModel.getValueAt(row, 2)));
- String gender = (String)tblModel.getValueAt(row, 3);
+ String gender = (String) tblModel.getValueAt(row, 3);
if (gender.equalsIgnoreCase("Nam")) {
rdNam.setSelected(true);
rdNu.setSelected(false);
+ } else {
+ rdNu.setSelected(true);
+ rdNam.setSelected(false);
}
- else {
- rdNu.setSelected(true); rdNam.setSelected(false);
- }
- txtAddress.setText((String)tblModel.getValueAt(row, 4));
- txtJob.setText((String)tblModel.getValueAt(row, 5));
+ txtAddress.setText((String) tblModel.getValueAt(row, 4));
+ txtJob.setText((String) tblModel.getValueAt(row, 5));
}
} catch (Exception e) {
MessageDialogHelper.showErrorDialog(parentForm, e.getMessage(), "Lỗi");
@@ -544,14 +581,14 @@ private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR
DataValidator.validateEmpty(txtNamSinh, sb, "Năm sinh không được bỏ trống!!");
DataValidator.validateEmpty(txtAddress, sb, "Địa chỉ không được bỏ trống!");
DataValidator.validateEmpty(txtJob, sb, "Công việc không được bỏ trống!!");
-
+
// Nếu có lỗi
if (sb.length() > 0) {
MessageDialogHelper.showErrorDialog(parentForm, sb.toString(), "Lỗi");
return;
}
-
- if (MessageDialogHelper.showConfirmDialog(parentForm, "Bạn có muốn cập nhật sinh viên không?",
+
+ if (MessageDialogHelper.showConfirmDialog(parentForm, "Bạn có muốn cập nhật sinh viên không?",
"Xác nhận") == JOptionPane.NO_OPTION) {
return;
}
@@ -559,17 +596,13 @@ private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR
// Lấy dữ liệu từ trên form xuống
CanBoDao dao = new CanBoDao();
int manv = Integer.parseInt(txtmanv.getText());
-
-
-
- if (dao.delete("tbl_nhanvien", "manv",manv))
- {
+
+ if (dao.delete("tbl_nhanvien", "manv", manv)) {
MessageDialogHelper.showMessageDialog(parentForm, "Công nhân đã được xóa thành công!!",
- "Thông báo");
+ "Thông báo");
loadDataToTable();
- }
- else {
- MessageDialogHelper.showConfirmDialog(parentForm,
+ } else {
+ MessageDialogHelper.showConfirmDialog(parentForm,
"Công nhân không được xóa do lỗi", "Cảnh báo");
}
} catch (Exception e) {
@@ -582,55 +615,95 @@ private void btnSeachActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
try {
NhanVienDao dao = new NhanVienDao();
String info = txtSearch.getText();
- info = "'%" + info + "%'";
- ArrayList list = dao.findNhanVien(info);
- tblModel.setRowCount(0);
- for (Nhanvien it:list) {
- tblModel.addRow(new Object[] {
- it.getMacb(),it.getTencb(), it.getNamsinh(), it.getGioitinh(),
- it.getDiachi(), it.getCongviec()
- });
+ if (info.length() == 0) {
+ MessageDialogHelper.showErrorDialog(parentForm, "Thông tin tìm kiếm không được bỏ trống!!", "Lỗi");
+ } else {
+ info = "'%" + info + "%'";
+ ArrayList list = dao.findNhanVien(info);
+ tblModel.setRowCount(0);
+ for (Nhanvien it : list) {
+ tblModel.addRow(new Object[]{
+ it.getMacb(), it.getTencb(), it.getNamsinh(), it.getGioitinh(),
+ it.getDiachi(), it.getCongviec()
+ });
+ }
+ tblModel.fireTableDataChanged();
}
- tblModel.fireTableDataChanged();
- }
- catch (Exception e) {
+ } catch (Exception e) {
e.printStackTrace();
MessageDialogHelper.showErrorDialog(parentForm, e.getMessage(), "Lỗi");
}
}//GEN-LAST:event_btnSeachActionPerformed
private void cbFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbFieldActionPerformed
- String txt = (String)cbField.getSelectedItem();
+ String txt = (String) cbField.getSelectedItem();
fieldSort = txt;
}//GEN-LAST:event_cbFieldActionPerformed
private void cbSortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbSortActionPerformed
- String type = (String)cbSort.getSelectedItem();
+ String type = (String) cbSort.getSelectedItem();
sortType = type;
}//GEN-LAST:event_cbSortActionPerformed
private void btnSortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSortActionPerformed
NhanVienDao dao = new NhanVienDao();
ArrayList listt;
+ tblModel.setRowCount(0);
try {
listt = dao.sortEmployee(fieldSort, sortType);
- for (Nhanvien it:listt) {
- tblModel.addRow(new Object[] {
- it.getMacb(),it.getTencb(), it.getNamsinh(), it.getGioitinh(),
+ for (Nhanvien it : listt) {
+ tblModel.addRow(new Object[]{
+ it.getMacb(), it.getTencb(), it.getNamsinh(), it.getGioitinh(),
it.getDiachi(), it.getCongviec()
});
}
tblModel.fireTableDataChanged();
tblEmployee.setModel(tblModel);
- tblModel.setRowCount(0);
+
} catch (Exception ex) {
Logger.getLogger(EngineerManagementPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_btnSortActionPerformed
+ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
+ int manv = Integer.parseInt(txtmanv.getText());
+ Random rand = new Random();
+ String mk = String.valueOf(rand.nextInt(100000000));
+ CanBoDao dao = new CanBoDao();
+ try {
+ System.out.println("alo dmm1");
+ if (dao.chagePassword(mk, manv)) {
+
+ System.out.println("alo dmm2");
+ MessageDialogHelper.showMessageDialog(parentForm, "Reset mật khẩu thành công!!\nMật khẩu mới: " + mk, "Thông báo");
+ }
+
+ } catch (Exception ex) {
+ MessageDialogHelper.showErrorDialog(parentForm, ex.getMessage(), "Lỗi");
+ }
+ }//GEN-LAST:event_jButton1ActionPerformed
+
+ private void btnExportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportActionPerformed
+ try {
+ NhanVienDao dao = new NhanVienDao();
+ ArrayList list = dao.getAllNhanVien(null, "");
+
+ if (list.size() > 0) {
+ ExportBase export = new ExportBase();
+ export.NhanVienExport(list);
+
+ MessageDialogHelper.showMessageDialog(parentForm, "Xuất file thành công", "Thông báo");
+ }
+
+ } catch (Exception ex) {
+ MessageDialogHelper.showErrorDialog(parentForm, ex.getMessage(), "Lỗi");
+ }
+ }//GEN-LAST:event_btnExportActionPerformed
+
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnDelete;
+ private javax.swing.JButton btnExport;
private javax.swing.JButton btnNew;
private javax.swing.JButton btnSave;
private javax.swing.JButton btnSeach;
@@ -639,16 +712,17 @@ private void btnSortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST
private javax.swing.JComboBox cbField;
private javax.swing.JComboBox cbSort;
private javax.swing.ButtonGroup genderGroup;
+ private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
+ private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
- private javax.swing.JSeparator jSeparator2;
private javax.swing.JSeparator jSeparator3;
private javax.swing.JSeparator jSeparator4;
private javax.swing.JSeparator jSeparator5;
@@ -665,4 +739,5 @@ private void btnSortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST
private javax.swing.JTextField txtSearch;
private javax.swing.JTextField txtmanv;
// End of variables declaration//GEN-END:variables
+
}
diff --git a/src/main/java/com/mycompany/qlcb/ui/EngineerManagementPanel.form b/src/main/java/com/mycompany/qlcb/ui/EngineerManagementPanel.form
index c4c39fc..20f42ba 100644
--- a/src/main/java/com/mycompany/qlcb/ui/EngineerManagementPanel.form
+++ b/src/main/java/com/mycompany/qlcb/ui/EngineerManagementPanel.form
@@ -21,119 +21,111 @@
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -141,81 +133,100 @@
-
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
@@ -255,8 +266,6 @@
-
-
@@ -380,6 +389,9 @@
+
+
+
@@ -456,6 +468,7 @@
+
@@ -480,14 +493,12 @@
-
-
-
+
@@ -534,5 +545,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/com/mycompany/qlcb/ui/EngineerManagementPanel.java b/src/main/java/com/mycompany/qlcb/ui/EngineerManagementPanel.java
index 93c0a7b..698ab44 100644
--- a/src/main/java/com/mycompany/qlcb/ui/EngineerManagementPanel.java
+++ b/src/main/java/com/mycompany/qlcb/ui/EngineerManagementPanel.java
@@ -2,6 +2,7 @@
import com.mycompany.qlcb.dao.CanBoDao;
import com.mycompany.qlcb.dao.KySuDao;
+import com.mycompany.qlcb.filehelpers.ExportBase;
import com.mycompany.qlcb.helpers.DataValidator;
import com.mycompany.qlcb.helpers.MessageDialogHelper;
import com.mycompany.qlcb.helpers.VNCharacterUtils;
@@ -13,14 +14,14 @@
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
-
public class EngineerManagementPanel extends javax.swing.JPanel {
+
private MainForm parentForm;
private DefaultTableModel tblModel;
ArrayList list;
String fieldSort = "";
String sortType = "ASC";
-
+
public EngineerManagementPanel() {
initComponents();
rdNam.setSelected(true);
@@ -28,34 +29,32 @@ public EngineerManagementPanel() {
initTable();
loadDataToTable();
}
-
+
private void initTable() {
- tblModel = new DefaultTableModel();
- tblModel.setColumnIdentifiers(new String[] {"Mã KS","Họ tên","Năm sinh", "Giới tính",
- "Địa chỉ", "Ngành đào tạo", "Loại bằng"});
- tblEngineer.setModel(tblModel);
+ tblModel = new DefaultTableModel();
+ tblModel.setColumnIdentifiers(new String[]{"Mã KS", "Họ tên", "Năm sinh", "Giới tính",
+ "Địa chỉ", "Ngành đào tạo", "Loại bằng"});
+ tblEngineer.setModel(tblModel);
}
-
+
private void loadDataToTable() {
try {
KySuDao dao = new KySuDao();
list = dao.getAllKysu(null, "");
tblModel.setRowCount(0);
- for (Kysu it:list) {
- tblModel.addRow(new Object[] {
- it.getMacb(),it.getTencb(), it.getNamsinh(), it.getGioitinh(),
+ for (Kysu it : list) {
+ tblModel.addRow(new Object[]{
+ it.getMacb(), it.getTencb(), it.getNamsinh(), it.getGioitinh(),
it.getDiachi(), it.getNganhdt(), it.getLoaibang()
});
}
tblModel.fireTableDataChanged();
- }
- catch (Exception e) {
+ } catch (Exception e) {
e.printStackTrace();
MessageDialogHelper.showErrorDialog(parentForm, e.getMessage(), "Lỗi");
}
}
-
@SuppressWarnings("unchecked")
// //GEN-BEGIN:initComponents
private void initComponents() {
@@ -66,7 +65,6 @@ private void initComponents() {
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
- jSeparator2 = new javax.swing.JSeparator();
txtAddress = new javax.swing.JTextField();
rdNam = new javax.swing.JRadioButton();
rdNu = new javax.swing.JRadioButton();
@@ -88,11 +86,13 @@ private void initComponents() {
txtname = new javax.swing.JTextField();
txtSearch = new javax.swing.JTextField();
btnSearch = new javax.swing.JButton();
- jSeparator4 = new javax.swing.JSeparator();
jLabel6 = new javax.swing.JLabel();
cbField = new javax.swing.JComboBox<>();
cbSort = new javax.swing.JComboBox<>();
btnSort = new javax.swing.JButton();
+ jButton1 = new javax.swing.JButton();
+ btnExport = new javax.swing.JButton();
+ jLabel9 = new javax.swing.JLabel();
jLabel1.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
jLabel1.setText("QUẢN LÝ KỸ SƯ");
@@ -170,6 +170,7 @@ public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
+ tblEngineer.setMinimumSize(new java.awt.Dimension(1000, 64));
tblEngineer.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tblEngineerMouseClicked(evt);
@@ -214,6 +215,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
jLabel16.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
jLabel16.setText("Họ tên");
+ txtmaks.setEditable(false);
txtmaks.setAlignmentX(0.0F);
txtmaks.setAlignmentY(0.0F);
@@ -232,7 +234,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
});
jLabel6.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
- jLabel6.setText("Thông tin tìm kiếm");
+ jLabel6.setText("Sắp xếp");
cbField.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Họ tên", "Năm sinh", "Giới tính", "Ngành đào tạo", "Loại bằng" }));
cbField.addActionListener(new java.awt.event.ActionListener() {
@@ -255,167 +257,185 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});
+ jButton1.setText("Reset mật khẩu");
+ jButton1.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ jButton1ActionPerformed(evt);
+ }
+ });
+
+ btnExport.setText("Xuất file");
+ btnExport.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ btnExportActionPerformed(evt);
+ }
+ });
+
+ jLabel9.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
+ jLabel9.setText("Thông tin tìm kiếm");
+
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(txtmaks, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
+ .addGap(126, 126, 126))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(12, 12, 12)
- .addComponent(jLabel1))
- .addGroup(layout.createSequentialGroup()
- .addGap(20, 20, 20)
- .addComponent(jLabel4)
- .addGap(67, 67, 67)
- .addComponent(rdNam)
- .addGap(79, 79, 79)
- .addComponent(rdNu)))
- .addGap(0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
+ .addComponent(txtMaNghe, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(btnExport, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGroup(layout.createSequentialGroup()
+ .addGap(21, 21, 21)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
- .addComponent(jLabel5)
- .addGap(78, 78, 78)
- .addComponent(txtAddress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel3)
- .addGap(60, 60, 60)
- .addComponent(txtNamSinh, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .addComponent(btnAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addComponent(btnSave, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(21, 21, 21)
+ .addComponent(btnUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 380, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
- .addComponent(jLabel16)
- .addGap(77, 77, 77)
- .addComponent(txtname, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel7)
.addGap(24, 24, 24)
- .addComponent(txtField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
- .addGap(12, 12, 12))
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jSeparator1)
- .addContainerGap())
- .addGroup(layout.createSequentialGroup()
- .addGap(20, 20, 20)
- .addComponent(jLabel8)
- .addGap(58, 58, 58)
- .addComponent(txtDegree, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addContainerGap())
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel6)
- .addGap(28, 28, 28)
- .addComponent(txtSearch)
- .addGap(18, 18, 18)
- .addComponent(btnSearch))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jScrollPane1)
+ .addComponent(txtField, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
- .addGap(8, 8, 8)
- .addComponent(txtMaNghe, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(cbField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(cbSort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(btnSort)))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(txtmaks, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addContainerGap())
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jSeparator2)
- .addContainerGap())
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jSeparator3)
+ .addComponent(jLabel8)
+ .addGap(58, 58, 58)
+ .addComponent(txtDegree, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addComponent(jLabel1)
+ .addGroup(layout.createSequentialGroup()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jLabel3)
+ .addGap(60, 60, 60)
+ .addComponent(txtNamSinh, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jLabel16)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(txtname, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGroup(layout.createSequentialGroup()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(jLabel5)
+ .addComponent(jLabel4))
+ .addGap(67, 67, 67)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(rdNam)
+ .addGap(38, 38, 38)
+ .addComponent(rdNu))
+ .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)))))
+ .addGap(20, 20, 20)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(cbField, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addComponent(cbSort, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(13, 13, 13)
+ .addComponent(btnSort, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jLabel9)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 238, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addComponent(btnSearch)))))
+ .addGap(0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
- .addGap(0, 124, Short.MAX_VALUE)
- .addComponent(btnAdd)
- .addGap(109, 109, 109)
- .addComponent(btnSave)
- .addGap(81, 81, 81)
- .addComponent(btnUpdate)
- .addGap(92, 92, 92)
- .addComponent(btnDelete)))
+ .addGap(408, 408, 408)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jLabel6)
+ .addGap(0, 0, Short.MAX_VALUE))
+ .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 607, Short.MAX_VALUE))))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jSeparator4)
+ .addGap(21, 21, 21)
+ .addComponent(jSeparator1)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
+ .addComponent(txtmaks, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(17, 17, 17)
+ .addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel16)
- .addComponent(txtname, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(10, 10, 10)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel3)
- .addComponent(txtNamSinh, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(10, 10, 10)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel4)
- .addComponent(rdNam)
- .addComponent(rdNu))
- .addGap(5, 5, 5)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
- .addGap(10, 10, 10)
- .addComponent(jLabel5))
- .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(10, 10, 10)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(10, 10, 10)
- .addComponent(jLabel7))
- .addComponent(txtField, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(20, 20, 20)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel8)
- .addComponent(txtDegree, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 4, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(1, 1, 1)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(txtname, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(btnSearch))
+ .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING))))
.addGap(13, 13, 13)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(btnSave)
- .addComponent(btnAdd)
- .addComponent(btnUpdate)
- .addComponent(btnDelete))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(txtSearch)
- .addComponent(btnSearch, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addComponent(jLabel6))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(txtmaks, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(btnSort)
- .addComponent(cbSort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(cbField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(txtMaNghe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap(21, Short.MAX_VALUE))
+ .addComponent(txtNamSinh, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jLabel3)
+ .addComponent(jLabel6))
+ .addGroup(layout.createSequentialGroup()
+ .addGap(1, 1, 1)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(cbField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(cbSort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addComponent(btnSort))))
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
+ .addGroup(layout.createSequentialGroup()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(9, 9, 9)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(rdNam)
+ .addComponent(jLabel4)))
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(rdNu)))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jLabel5))
+ .addGap(18, 18, 18)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(txtField, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jLabel7))
+ .addGap(13, 13, 13)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(txtDegree, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jLabel8))
+ .addGap(24, 24, 24)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(btnAdd)
+ .addComponent(btnSave))
+ .addComponent(btnUpdate))
+ .addGap(13, 13, 13)
+ .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jButton1)
+ .addComponent(btnDelete))
+ .addGap(64, 64, 64)
+ .addComponent(txtMaNghe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addContainerGap(26, Short.MAX_VALUE))
+ .addGroup(layout.createSequentialGroup()
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(btnExport)
+ .addGap(17, 17, 17))))
);
}// //GEN-END:initComponents
@@ -424,7 +444,7 @@ private void txtAddressActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
}//GEN-LAST:event_txtAddressActionPerformed
private void txtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtFieldActionPerformed
-
+
}//GEN-LAST:event_txtFieldActionPerformed
private void txtDegreeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDegreeActionPerformed
@@ -458,35 +478,31 @@ private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST
MessageDialogHelper.showErrorDialog(parentForm, sb.toString(), "Lỗi");
return;
}
-
-
+
try {
// Lấy dữ liệu từ trên form xuống
Kysu ks = new Kysu();
ks.setTencb(txtname.getText());
ks.setNamsinh(Integer.parseInt(txtNamSinh.getText()));
- ks.setGioitinh(rdNam.isSelected()?"Nam":"Nữ");
+ ks.setGioitinh(rdNam.isSelected() ? "Nam" : "Nữ");
ks.setLoaibang(txtField.getText());
ks.setDiachi(txtAddress.getText());
ks.setNganhdt(txtField.getText());
-
+
int manghe = Integer.parseInt(txtMaNghe.getText());
CanBoDao dao = new CanBoDao();
- if (dao.insertCB(ks, manghe))
- {
+ if (dao.insertCB(ks, manghe)) {
MessageDialogHelper.showMessageDialog(parentForm, "Kỹ sư đã được thêm thành công!!",
- "Thông báo");
- }
- else {
- MessageDialogHelper.showConfirmDialog(parentForm,
+ "Thông báo");
+ } else {
+ MessageDialogHelper.showConfirmDialog(parentForm,
"Kỹ sư không được lưu do lỗi", "Cảnh báo");
}
-
+
// Lấy ra mã cán bộ cuối cùng trong bảng để chèn vào bảng nhân viên
-
if (dao.getLastIdCB() != -1) {
int macb = dao.getLastIdCB();
-
+
// Chèn vào bảng nhân viên
dao.insertTable("tbl_kysu", macb, txtField.getText(), txtDegree.getText());
//tao tai khoan tu dong
@@ -494,9 +510,9 @@ private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST
System.out.print(tk);
Random rand = new Random();
String mk = String.valueOf(rand.nextInt(100000000));
- if(dao.insertTaiKhoan(tk, mk, macb, Integer.valueOf(txtMaNghe.getText()))){
- MessageDialogHelper.showMessageDialog(parentForm, "Tạo tài khoản thành công!\nTài khoản: "+tk+"\nMật khẩu: "+mk,
- "Thông báo");
+ if (dao.insertTaiKhoan(tk, mk, macb, Integer.valueOf(txtMaNghe.getText()))) {
+ MessageDialogHelper.showMessageDialog(parentForm, "Tạo tài khoản thành công!\nTài khoản: " + tk + "\nMật khẩu: " + mk,
+ "Thông báo");
}
loadDataToTable();
}
@@ -515,22 +531,22 @@ private void txtnameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST
}//GEN-LAST:event_txtnameActionPerformed
private void tblEngineerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblEngineerMouseClicked
- try {
+ try {
// Lấy ra dong được click
int row = tblEngineer.getSelectedRow();
if (row >= 0) {
txtmaks.setText((String.valueOf(tblModel.getValueAt(row, 0))));
- txtname.setText((String)tblModel.getValueAt(row, 1));
+ txtname.setText((String) tblModel.getValueAt(row, 1));
txtNamSinh.setText(String.valueOf(tblModel.getValueAt(row, 2)));
- String gender = (String)tblModel.getValueAt(row, 3);
+ String gender = (String) tblModel.getValueAt(row, 3);
if (gender.equalsIgnoreCase("Nam")) {
rdNam.setSelected(true);
rdNu.setSelected(false);
+ } else {
+ rdNu.setSelected(true);
+ rdNam.setSelected(false);
}
- else {
- rdNu.setSelected(true); rdNam.setSelected(false);
- }
- txtAddress.setText((String)tblModel.getValueAt(row, 4));
+ txtAddress.setText((String) tblModel.getValueAt(row, 4));
txtField.setText(String.valueOf(tblModel.getValueAt(row, 5)));
txtDegree.setText(String.valueOf(tblModel.getValueAt(row, 6)));
}
@@ -540,19 +556,19 @@ private void tblEngineerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST
}//GEN-LAST:event_tblEngineerMouseClicked
private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdateActionPerformed
- StringBuilder sb = new StringBuilder();
+ StringBuilder sb = new StringBuilder();
DataValidator.validateEmpty(txtname, sb, "Tên nhân viên không được để trống!!");
DataValidator.validateEmpty(txtNamSinh, sb, "Năm sinh không được bỏ trống!!");
DataValidator.validateEmpty(txtAddress, sb, "Địa chỉ không được bỏ trống!");
DataValidator.validateEmpty(txtField, sb, "Trường làm việc không được bỏ trống!!");
-
+
// Nếu có lỗi
if (sb.length() > 0) {
MessageDialogHelper.showErrorDialog(parentForm, sb.toString(), "Lỗi");
return;
}
-
- if (MessageDialogHelper.showConfirmDialog(parentForm, "Bạn có muốn cập nhật sinh viên không?",
+
+ if (MessageDialogHelper.showConfirmDialog(parentForm, "Bạn có muốn cập nhật sinh viên không?",
"Xác nhận") == JOptionPane.NO_OPTION) {
return;
}
@@ -561,29 +577,26 @@ private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR
Kysu ks = new Kysu();
ks.setTencb(txtname.getText());
ks.setNamsinh(Integer.parseInt(txtNamSinh.getText()));
- ks.setGioitinh(rdNam.isSelected()?"Nam":"Nữ");
+ ks.setGioitinh(rdNam.isSelected() ? "Nam" : "Nữ");
ks.setNganhdt(txtField.getText());
ks.setLoaibang(txtDegree.getText());
ks.setDiachi(txtAddress.getText());
ks.setMacb(Integer.parseInt(txtmaks.getText()));
KySuDao dao = new KySuDao();
-
-
- if (dao.update(ks))
- {
+
+ if (dao.update(ks)) {
loadDataToTable();
MessageDialogHelper.showMessageDialog(parentForm, "Kỹ sư đã được cập nhật thành công!!",
- "Thông báo");
- }
- else {
- MessageDialogHelper.showConfirmDialog(parentForm,
+ "Thông báo");
+ } else {
+ MessageDialogHelper.showConfirmDialog(parentForm,
"Kỹ sư không được cập nhật do lỗi", "Cảnh báo");
}
} catch (Exception e) {
e.printStackTrace();
MessageDialogHelper.showErrorDialog(parentForm, e.getMessage(), "Lỗi");
}
-
+
}//GEN-LAST:event_btnUpdateActionPerformed
private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
@@ -598,8 +611,8 @@ private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR
MessageDialogHelper.showErrorDialog(parentForm, sb.toString(), "Lỗi");
return;
}
-
- if (MessageDialogHelper.showConfirmDialog(parentForm, "Bạn có muốn xóa kỹ sư không?",
+
+ if (MessageDialogHelper.showConfirmDialog(parentForm, "Bạn có muốn xóa kỹ sư không?",
"Xác nhận") == JOptionPane.NO_OPTION) {
return;
}
@@ -607,17 +620,13 @@ private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR
// Lấy dữ liệu từ trên form xuống
CanBoDao dao = new CanBoDao();
int maks = Integer.parseInt(txtmaks.getText());
-
-
-
- if (dao.delete("tbl_kysu", "maks",maks))
- {
+
+ if (dao.delete("tbl_kysu", "maks", maks)) {
loadDataToTable();
MessageDialogHelper.showMessageDialog(parentForm, "Kỹ sư đã được xóa thành công!!",
- "Thông báo");
- }
- else {
- MessageDialogHelper.showConfirmDialog(parentForm,
+ "Thông báo");
+ } else {
+ MessageDialogHelper.showConfirmDialog(parentForm,
"Kỹ sư không được xóa do lỗi", "Cảnh báo");
}
} catch (Exception e) {
@@ -630,31 +639,36 @@ private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR
try {
KySuDao dao = new KySuDao();
String info = txtSearch.getText();
- info = "'%" + info + "%'";
- ArrayList list = dao.findKysu(info);
- tblModel.setRowCount(0);
- for (Kysu it:list) {
- tblModel.addRow(new Object[] {
- it.getMacb(),it.getTencb(), it.getNamsinh(), it.getGioitinh(),
- it.getDiachi(), it.getNganhdt(), it.getLoaibang()
- });
+
+ if (info.length() == 0) {
+ MessageDialogHelper.showErrorDialog(parentForm, "Thông tin tìm kiếm không được bỏ trống!!", "Lỗi");
+ } else {
+ info = "'%" + info + "%'";
+ ArrayList list = dao.findKysu(info);
+ tblModel.setRowCount(0);
+ for (Kysu it : list) {
+ tblModel.addRow(new Object[]{
+ it.getMacb(), it.getTencb(), it.getNamsinh(), it.getGioitinh(),
+ it.getDiachi(), it.getNganhdt(), it.getLoaibang()
+ });
+ }
+ tblModel.fireTableDataChanged();
}
- tblModel.fireTableDataChanged();
- }
- catch (Exception e) {
+
+ } catch (Exception e) {
e.printStackTrace();
MessageDialogHelper.showErrorDialog(parentForm, e.getMessage(), "Lỗi");
}
}//GEN-LAST:event_btnSearchActionPerformed
private void cbFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbFieldActionPerformed
- String txt = (String)cbField.getSelectedItem();
+ String txt = (String) cbField.getSelectedItem();
fieldSort = txt;
}//GEN-LAST:event_cbFieldActionPerformed
private void cbSortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbSortActionPerformed
- String type = (String)cbSort.getSelectedItem();
- sortType = type;
+ String type = (String) cbSort.getSelectedItem();
+ sortType = type;
}//GEN-LAST:event_cbSortActionPerformed
private void btnSortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSortActionPerformed
@@ -663,9 +677,9 @@ private void btnSortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST
tblModel.setRowCount(0);
try {
listt = dao.sortEngineer(fieldSort, sortType);
- for (Kysu it:listt) {
- tblModel.addRow(new Object[] {
- it.getMacb(),it.getTencb(), it.getNamsinh(), it.getGioitinh(),
+ for (Kysu it : listt) {
+ tblModel.addRow(new Object[]{
+ it.getMacb(), it.getTencb(), it.getNamsinh(), it.getGioitinh(),
it.getDiachi(), it.getNganhdt(), it.getLoaibang()
});
}
@@ -674,14 +688,47 @@ private void btnSortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST
} catch (Exception ex) {
Logger.getLogger(EngineerManagementPanel.class.getName()).log(Level.SEVERE, null, ex);
}
-
-
+
+
}//GEN-LAST:event_btnSortActionPerformed
+ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
+ int manv = Integer.parseInt(txtmaks.getText());
+ Random rand = new Random();
+ String mk = String.valueOf(rand.nextInt(100000000));
+ CanBoDao dao = new CanBoDao();
+ try {
+ if (dao.chagePassword(mk, manv)) {
+ MessageDialogHelper.showMessageDialog(parentForm, "Reset mật khẩu thành công!!\nMật khẩu mới: " + mk, "Thông báo");
+ }
+
+ } catch (Exception ex) {
+ MessageDialogHelper.showErrorDialog(parentForm, ex.getMessage(), "Lỗi");
+ }
+ }//GEN-LAST:event_jButton1ActionPerformed
+
+ private void btnExportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExportActionPerformed
+ try {
+ KySuDao dao = new KySuDao();
+ list = dao.getAllKysu(null, "");
+
+ if (list.size() > 0) {
+ ExportBase export = new ExportBase();
+ export.KySuExport(list);
+
+ MessageDialogHelper.showMessageDialog(parentForm, "Xuất file thành công", "Thông báo");
+ }
+
+ } catch (Exception ex) {
+ MessageDialogHelper.showErrorDialog(parentForm, ex.getMessage(), "Lỗi");
+ }
+ }//GEN-LAST:event_btnExportActionPerformed
+
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnAdd;
private javax.swing.JButton btnDelete;
+ private javax.swing.JButton btnExport;
private javax.swing.JButton btnSave;
private javax.swing.JButton btnSearch;
private javax.swing.JButton btnSort;
@@ -689,6 +736,7 @@ private void btnSortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST
private javax.swing.JComboBox cbField;
private javax.swing.JComboBox cbSort;
private javax.swing.ButtonGroup genderGroup;
+ private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel16;
private javax.swing.JLabel jLabel3;
@@ -697,11 +745,10 @@ private void btnSortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
+ private javax.swing.JLabel jLabel9;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
- private javax.swing.JSeparator jSeparator2;
private javax.swing.JSeparator jSeparator3;
- private javax.swing.JSeparator jSeparator4;
private javax.swing.JRadioButton rdNam;
private javax.swing.JRadioButton rdNu;
private javax.swing.JTable tblEngineer;
diff --git a/src/main/java/com/mycompany/qlcb/ui/LoginDialog.java b/src/main/java/com/mycompany/qlcb/ui/LoginDialog.java
index 07d506b..ca26fed 100644
--- a/src/main/java/com/mycompany/qlcb/ui/LoginDialog.java
+++ b/src/main/java/com/mycompany/qlcb/ui/LoginDialog.java
@@ -157,8 +157,7 @@ private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoginActionPerformed
StringBuilder sb = new StringBuilder();
DataValidator.validateEmpty(txtUsername, sb, "Tên đăng nhập không được để trống!!");
- DataValidator.validateEmpty(txtPassword, sb, "Mật khẩu không được để trống!!");
-
+ DataValidator.validateEmpty(txtPassword, sb, "Mật khẩu không được để trống!! " );
if (sb.length() > 0) {
MessageDialogHelper.showErrorDialog(this, sb.toString(), "Lỗi");
return;
@@ -167,11 +166,17 @@ private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
NguoiDungDao dao = new NguoiDungDao();
try {
nd = dao.checkLogin(txtUsername.getText(), new String(txtPassword.getPassword()));
-
+ System.out.println(nd.getTenDangNhap());
+ System.out.println(nd.getMatKhau());
+ System.out.println(nd.getVaiTro());
+
+
if (nd==null) {
MessageDialogHelper.showErrorDialog(this, "Tên đăng nhập hoặc mật khẩu sai!!", "Lỗi");
}
- else {
+ else if(nd.getTenDangNhap() == ""){
+ MessageDialogHelper.showErrorDialog(this, "Người dùng đã bị vô hiệu hóa\nVui lòng đăng nhập bằng tài khoản khác!", "Lỗi");
+ }else{
SharedData.nguoiDangNhap = nd;
// dong hop thoai
this.dispose();
diff --git a/src/main/java/com/mycompany/qlcb/ui/MainForm.form b/src/main/java/com/mycompany/qlcb/ui/MainForm.form
index 54b5839..f4d467a 100644
--- a/src/main/java/com/mycompany/qlcb/ui/MainForm.form
+++ b/src/main/java/com/mycompany/qlcb/ui/MainForm.form
@@ -113,6 +113,16 @@
+
+