diff --git a/src/main/java/com/pharmacy/views/CustomerPage.java b/src/main/java/com/pharmacy/views/CustomerPage.java
index 1c4b109..4f9d17e 100644
--- a/src/main/java/com/pharmacy/views/CustomerPage.java
+++ b/src/main/java/com/pharmacy/views/CustomerPage.java
@@ -12,15 +12,12 @@
public class CustomerPage extends javax.swing.JPanel {
- CustomerController customerController;
- int id;
+ private final int id;
public CustomerPage(int id) {
this.id = id;
initComponents();
-
- customerController = new CustomerController(id);
loadDataSet();
}
@@ -326,7 +323,7 @@ private void updateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
customerModel.setPhone(phoneText.getText());
EventQueue.invokeLater(() -> {
- customerController.updateCustomer(customerModel);
+ new CustomerController(id).updateCustomer(customerModel);
loadDataSet();
});
}
@@ -343,11 +340,13 @@ private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
"Confirmation",
JOptionPane.YES_NO_OPTION);
if (opt == JOptionPane.YES_OPTION) {
- int customerId = (int) custTable.getValueAt(custTable.getSelectedRow(), 0);
- String customerName = (String) custTable.getValueAt(custTable.getSelectedRow(), 2);
+ EventQueue.invokeLater(() -> {
+ int customerId = (int) custTable.getValueAt(custTable.getSelectedRow(), 0);
+ String customerName = (String) custTable.getValueAt(custTable.getSelectedRow(), 2);
+ new CustomerController(id).deleteCustomer(customerId, customerName);
- customerController.deleteCustomer(customerId, customerName);
- loadDataSet();
+ loadDataSet();
+ });
}
}
}//GEN-LAST:event_deleteButtonActionPerformed
@@ -377,7 +376,7 @@ private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN
loadDataSet();
}//GEN-LAST:event_refreshButtonActionPerformed
- public void processColums() {
+ public void processColumns() {
// hide pid
custTable.getColumnModel().getColumn(0).setMinWidth(0);
custTable.getColumnModel().getColumn(0).setMaxWidth(0);
@@ -386,8 +385,8 @@ public void processColums() {
public void loadDataSet() {
EventQueue.invokeLater(() -> {
try {
- custTable.setModel(new DataTableModel().buildTableModel(customerController.getCustomers()));
- processColums();
+ custTable.setModel(new DataTableModel().buildTableModel(new CustomerController(id).getCustomers()));
+ processColumns();
} catch (SQLException e) {
e.printStackTrace();
}
@@ -397,8 +396,8 @@ public void loadDataSet() {
public void loadSearchData(String text) {
EventQueue.invokeLater(() -> {
try {
- custTable.setModel(new DataTableModel().buildTableModel(customerController.getCustomerSearch(text)));
- processColums();
+ custTable.setModel(new DataTableModel().buildTableModel(new CustomerController(id).getCustomerSearch(text)));
+ processColumns();
} catch (SQLException e) {
e.printStackTrace();
}
diff --git a/src/main/java/com/pharmacy/views/Dashboard.java b/src/main/java/com/pharmacy/views/Dashboard.java
index 38b8e0d..670f72d 100644
--- a/src/main/java/com/pharmacy/views/Dashboard.java
+++ b/src/main/java/com/pharmacy/views/Dashboard.java
@@ -12,12 +12,12 @@
public class Dashboard extends javax.swing.JFrame {
- UserModel userModel;
- CardLayout layout;
+ private final CardLayout layout;
- String username;
- LocalDateTime outTime;
- int id;
+ private final String username;
+ private LocalDateTime outTime;
+
+ private final UserModel userModel;
public Dashboard(String username, String userType, UserModel userModel) {
initComponents();
@@ -38,7 +38,7 @@ public Dashboard(String username, String userType, UserModel userModel) {
// TODO: Inherit `id` from login instead to reduce
// the number of queries to the database
- id = new UserController(id).getUserId(username);
+ int id = new UserController(0).getUserId(username);
// Panel Layout set to Card Layout to allow switching between different sections
displayPanel.setLayout(layout);
diff --git a/src/main/java/com/pharmacy/views/HomePage.java b/src/main/java/com/pharmacy/views/HomePage.java
index e19c7fe..43f95d4 100644
--- a/src/main/java/com/pharmacy/views/HomePage.java
+++ b/src/main/java/com/pharmacy/views/HomePage.java
@@ -2,40 +2,34 @@
import com.pharmacy.controllers.UserController;
import com.pharmacy.models.UserModel;
-
-import javax.swing.JOptionPane;
import java.awt.Cursor;
import java.awt.EventQueue;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
+import javax.swing.JOptionPane;
// Welcome page for the application
public class HomePage extends javax.swing.JPanel {
- ResultSet resultSet = null;
-
- UserController userController;
- UserModel userModel;
-
- String username;
- int id;
+ private final UserModel userModel;
+ private final String username;
+ private final int id;
/**
* Creates new form HomePage
*/
public HomePage(String username, int logId) {
- this.username = username;
this.id = logId;
+ this.username = username;
userModel = new UserModel();
initComponents();
- userController = new UserController(id);
getUser();
greetUser(userModel.getName());
- setupDateTime();
+ displayDateTime();
}
/**
@@ -203,7 +197,7 @@ private void updateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
updatedUserModel.setUsername(usernameText.getText());
EventQueue.invokeLater(() -> {
- userController.updateUser(updatedUserModel);
+ new UserController(id).updateUser(updatedUserModel);
});
}
}//GEN-LAST:event_updateButtonActionPerformed
@@ -218,14 +212,14 @@ private void changePasswordActionPerformed(java.awt.event.ActionEvent evt) {//GE
if (verify != null) {
// password contains the decrypted password
- boolean match = userController.matchPasswords(username, verify);
+ boolean match = new UserController(id).matchPasswords(username, verify);
// if matches, change password to the new one
if (match) {
String newPassword = JOptionPane.showInputDialog(this, "Enter new password for " + username + ":", "Change Password", JOptionPane.PLAIN_MESSAGE);
if (newPassword != null) {
- userController.updatePass(userModel.getId(), userModel.getUsername(), newPassword);
+ new UserController(id).updatePass(userModel.getId(), userModel.getUsername(), newPassword);
JOptionPane.showMessageDialog(this, "Password changed successfully.", "Success", JOptionPane.INFORMATION_MESSAGE);
}
} else {
@@ -239,8 +233,10 @@ private void changePasswordActionPerformed(java.awt.event.ActionEvent evt) {//GE
}//GEN-LAST:event_changePasswordActionPerformed
private void getUser() {
- try {
- resultSet = userController.findUser(username);
+ ResultSet resultSet = new UserController(id).findUser(username);
+
+ try (resultSet) {
+ assert resultSet != null;
if (resultSet.next()) {
// save to user model
@@ -259,7 +255,10 @@ private void getUser() {
}
}
- private void setupDateTime() {
+ /**
+ * Display date and time in the top right corner
+ */
+ private void displayDateTime() {
// set date and time
new Thread(() -> {
while (true) {
@@ -288,7 +287,6 @@ private void greetUser(String name) {
}
}
-
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton changePassword;
private javax.swing.JLabel dateLabel;
diff --git a/src/main/java/com/pharmacy/views/LoginPage.form b/src/main/java/com/pharmacy/views/LoginPage.form
index b362fee..34deacb 100644
--- a/src/main/java/com/pharmacy/views/LoginPage.form
+++ b/src/main/java/com/pharmacy/views/LoginPage.form
@@ -153,7 +153,7 @@
-
+
diff --git a/src/main/java/com/pharmacy/views/LoginPage.java b/src/main/java/com/pharmacy/views/LoginPage.java
index 321c6d1..36d3f33 100644
--- a/src/main/java/com/pharmacy/views/LoginPage.java
+++ b/src/main/java/com/pharmacy/views/LoginPage.java
@@ -84,7 +84,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
jLabel4.setFont(new java.awt.Font("Liberation Sans", 0, 14)); // NOI18N
jLabel4.setForeground(new java.awt.Color(153, 153, 153));
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
- jLabel4.setText("© D&D Pharmacy System v2.0.0");
+ jLabel4.setText("© D&D Pharmacy System v3.1.0");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
diff --git a/src/main/java/com/pharmacy/views/MedicinePage.java b/src/main/java/com/pharmacy/views/MedicinePage.java
index 0ba6eb3..1daa51a 100644
--- a/src/main/java/com/pharmacy/views/MedicinePage.java
+++ b/src/main/java/com/pharmacy/views/MedicinePage.java
@@ -6,32 +6,30 @@
import com.pharmacy.utils.DataTableModel;
import com.pharmacy.utils.StringFormatting;
import com.pharmacy.views.dialogs.AddMedicineDialog;
-
-import javax.swing.JOptionPane;
-import javax.swing.SwingConstants;
-import javax.swing.table.DefaultTableCellRenderer;
import java.awt.Cursor;
import java.awt.EventQueue;
import java.sql.SQLException;
import java.util.Objects;
+import javax.swing.JOptionPane;
+import javax.swing.SwingConstants;
+import javax.swing.table.DefaultTableCellRenderer;
public class MedicinePage extends javax.swing.JPanel {
- Dashboard dashboard;
- MedicineModel medicineModel;
- MedicineController medicineController;
+ private final Dashboard dashboard;
- int id;
+ private final int id;
public MedicinePage(Dashboard dashboard, int id) {
this.id = id;
this.dashboard = dashboard;
initComponents();
-
- medicineController = new MedicineController(id);
loadDataSet();
- loadComboBox();
+
+ // We're not using invokeLater inside combobox since
+ // suppComboBoxPopupMenuWillBecomeVisible will be stuck and not show
+ EventQueue.invokeLater(this::loadComboBox);
}
/**
@@ -372,7 +370,8 @@ private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
if (medicineTable.getSelectedRow() < 0)
JOptionPane.showMessageDialog(this, "Please select medicine from the table.");
else {
- medicineModel = new MedicineModel();
+ MedicineModel medicineModel = new MedicineModel();
+
if (nameText.getText().equals("") || costText.getText().equals("")
|| sellText.getText().equals("") || quantityText.getText().equals("")) {
JOptionPane.showMessageDialog(this, "Please enter all the required details.");
@@ -390,7 +389,7 @@ private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
medicineModel.setSuppliedBy(Objects.requireNonNull(suppCombo.getSelectedItem()).toString());
EventQueue.invokeLater(() -> {
- medicineController.updateMedicine(medicineModel);
+ new MedicineController(id).updateMedicine(medicineModel);
loadDataSet();
});
}
@@ -410,8 +409,9 @@ private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
"Are you sure you want to delete this medicine?",
"Confirmation",
JOptionPane.YES_NO_OPTION);
+
if (opt == JOptionPane.YES_OPTION) {
- medicineController.deleteMedicine(
+ new MedicineController(id).deleteMedicine(
(Integer) medicineTable.getValueAt(
medicineTable.getSelectedRow(), 0));
loadDataSet();
@@ -482,12 +482,12 @@ private void processColumns() {
// resize column widths
medicineTable.getColumnModel().getColumn(1).setPreferredWidth(111);
- medicineTable.getColumnModel().getColumn(2).setPreferredWidth(121);
- medicineTable.getColumnModel().getColumn(3).setPreferredWidth(151);
+ medicineTable.getColumnModel().getColumn(2).setPreferredWidth(131);
+ medicineTable.getColumnModel().getColumn(3).setPreferredWidth(161);
medicineTable.getColumnModel().getColumn(4).setPreferredWidth(81);
medicineTable.getColumnModel().getColumn(5).setPreferredWidth(81);
medicineTable.getColumnModel().getColumn(6).setPreferredWidth(81);
- medicineTable.getColumnModel().getColumn(7).setPreferredWidth(101);
+ medicineTable.getColumnModel().getColumn(7).setPreferredWidth(111);
medicineTable.getColumnModel().getColumn(8).setPreferredWidth(121);
medicineTable.getColumnModel().getColumn(9).setPreferredWidth(171);
}
@@ -496,7 +496,7 @@ private void processColumns() {
public void loadDataSet() {
EventQueue.invokeLater(() -> {
try {
- medicineTable.setModel(new DataTableModel().buildTableModel(medicineController.getMedicines()));
+ medicineTable.setModel(new DataTableModel().buildTableModel(new MedicineController(id).getMedicines()));
processColumns();
loadComboBox();
@@ -510,7 +510,7 @@ public void loadDataSet() {
public void loadSearchData(String text) {
EventQueue.invokeLater(() -> {
try {
- medicineTable.setModel(new DataTableModel().buildTableModel(medicineController.getMedicineSearch(text)));
+ medicineTable.setModel(new DataTableModel().buildTableModel(new MedicineController(id).getMedicineSearch(text)));
processColumns();
} catch (SQLException throwables) {
diff --git a/src/main/java/com/pharmacy/views/RestockPage.java b/src/main/java/com/pharmacy/views/RestockPage.java
index 54a64ff..042c6c7 100644
--- a/src/main/java/com/pharmacy/views/RestockPage.java
+++ b/src/main/java/com/pharmacy/views/RestockPage.java
@@ -8,30 +8,24 @@
import java.awt.EventQueue;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.Objects;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
public class RestockPage extends javax.swing.JPanel {
- MedicineModel medicineModel;
- MedicineController medicineController;
- SupplierController supplierController;
+ private final Dashboard dashboard;
- Dashboard dashboard;
-
- int quantity;
- String medCode = null;
- int id;
+ private int quantity;
+ private String medCode = null;
+ private final int id;
public RestockPage(Dashboard dashboard, int id) {
this.id = id;
this.dashboard = dashboard;
initComponents();
-
- medicineController = new MedicineController(id);
- supplierController = new SupplierController(id);
loadDataSet();
// We're not using invokeLater inside combobox since
@@ -333,40 +327,41 @@ private void addSuppButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN
}//GEN-LAST:event_addSuppButtonActionPerformed
private void purchaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_purchaseButtonActionPerformed
- medicineModel = new MedicineModel();
+ MedicineModel medicineModel = new MedicineModel();
if (codeText.getText().equals("") || dateInput.getDate() == null
|| quantityText.getText().equals("")) {
JOptionPane.showMessageDialog(this, "Please enter all the required details.");
} else {
// store purchase info
- try {
- ResultSet resultSet = medicineController.getMedicineName(codeText.getText());
+ EventQueue.invokeLater(() -> {
+ ResultSet resultSet = new MedicineController(id).getMedicineName(codeText.getText());
assert resultSet != null;
- if (resultSet.next()) {
- double costPrice = Double.parseDouble(costText.getText());
- double totalCost = costPrice * Integer.parseInt(quantityText.getText());
-
- medicineModel.setSupplierCode(supplierController.getSupplierCode(suppComboBox.getSelectedItem().toString()));
- medicineModel.setMedicineCode(codeText.getText());
- medicineModel.setDate(dateInput.getDate());
- medicineModel.setQuantity(Integer.parseInt(quantityText.getText()));
- medicineModel.setTotalCost(totalCost);
-
- EventQueue.invokeLater(() -> {
- medicineController.addRestockInfo(medicineModel);
+ try {
+ if (resultSet.next()) {
+ String supplierName = new SupplierController(id).getSupplierCode(Objects.requireNonNull(suppComboBox.getSelectedItem()).toString());
+ double costPrice = Double.parseDouble(costText.getText());
+ double totalCost = costPrice * Integer.parseInt(quantityText.getText());
+
+ medicineModel.setSupplierCode(supplierName);
+ medicineModel.setMedicineCode(codeText.getText());
+ medicineModel.setDate(dateInput.getDate());
+ medicineModel.setQuantity(Integer.parseInt(quantityText.getText()));
+ medicineModel.setTotalCost(totalCost);
+
+ new MedicineController(id).addRestockInfo(medicineModel);
loadDataSet();
- });
- } else {
- // if no medicine has been found
- JOptionPane.showMessageDialog(this, """
- This seems to be a new medicine that hasn't been added yet.
- Please add this medicine in the "Products" section before proceeding.""");
+ } else {
+ // if no medicine has been found
+ JOptionPane.showMessageDialog(this, """
+ This seems to be a new medicine that hasn't been added yet.
+ Please add this medicine in the "Products" section before proceeding.""");
+ }
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
}
- } catch (SQLException e) {
- e.printStackTrace();
- }
+ });
}
}//GEN-LAST:event_purchaseButtonActionPerformed
@@ -379,10 +374,11 @@ private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
"Are you sure you want to delete this purchase?",
"Confirmation",
JOptionPane.YES_NO_OPTION);
+
if (opt == JOptionPane.YES_OPTION) {
EventQueue.invokeLater(() -> {
- medicineController.deleteRestockInfo((int) purchaseTable.getValueAt(purchaseTable.getSelectedRow(), 0));
- medicineController.reduceMedicineStock(medCode, quantity);
+ new MedicineController(id).deleteRestockInfo((int) purchaseTable.getValueAt(purchaseTable.getSelectedRow(), 0));
+ new MedicineController(id).reduceMedicineStock(medCode, quantity);
loadDataSet();
});
}
@@ -416,8 +412,10 @@ private void purchaseTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIR
}//GEN-LAST:event_purchaseTableMouseClicked
private void codeTextKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_codeTextKeyReleased
+ ResultSet resultSet;
+
try {
- ResultSet resultSet = medicineController.getMedFromCode(codeText.getText());
+ resultSet = new MedicineController(id).getMedFromCode(codeText.getText());
assert resultSet != null;
if (resultSet.next()) {
@@ -432,7 +430,6 @@ private void codeTextKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event
} catch (SQLException e) {
e.printStackTrace();
}
-
}//GEN-LAST:event_codeTextKeyReleased
private void suppComboBoxPopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_suppComboBoxPopupMenuWillBecomeVisible
@@ -451,6 +448,7 @@ private void suppComboBoxPopupMenuWillBecomeVisible(javax.swing.event.PopupMenuE
// Method to load and update combo box containing supplier names
public void loadComboBox() {
try {
+ SupplierController supplierController = new SupplierController(id);
suppComboBox.setModel(supplierController.setComboItems(supplierController.getSuppliers()));
} catch (SQLException e) {
e.printStackTrace();
@@ -461,7 +459,7 @@ public void loadComboBox() {
public void loadDataSet() {
EventQueue.invokeLater(() -> {
try {
- purchaseTable.setModel(new DataTableModel().buildTableModel(medicineController.getRestockInfo()));
+ purchaseTable.setModel(new DataTableModel().buildTableModel(new MedicineController(id).getRestockInfo()));
} catch (SQLException throwables) {
throwables.printStackTrace();
}
@@ -472,7 +470,7 @@ public void loadDataSet() {
public void loadSearchData(String text) {
EventQueue.invokeLater(() -> {
try {
- purchaseTable.setModel(new DataTableModel().buildTableModel(medicineController.getRestockSearch(text)));
+ purchaseTable.setModel(new DataTableModel().buildTableModel(new MedicineController(id).getRestockSearch(text)));
} catch (SQLException e) {
e.printStackTrace();
}
diff --git a/src/main/java/com/pharmacy/views/SupplierPage.java b/src/main/java/com/pharmacy/views/SupplierPage.java
index 2067f62..7df6d63 100644
--- a/src/main/java/com/pharmacy/views/SupplierPage.java
+++ b/src/main/java/com/pharmacy/views/SupplierPage.java
@@ -4,24 +4,20 @@
import com.pharmacy.models.SupplierModel;
import com.pharmacy.utils.DataTableModel;
import com.pharmacy.views.dialogs.AddSupplierDialog;
-
+import java.awt.EventQueue;
+import java.sql.SQLException;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
-import java.awt.EventQueue;
-import java.sql.SQLException;
public class SupplierPage extends javax.swing.JPanel {
- SupplierController supplierController;
private final int id;
public SupplierPage(int id) {
this.id = id;
initComponents();
-
- supplierController = new SupplierController(id);
loadDataSet();
}
@@ -283,8 +279,10 @@ private void suppTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:e
int col = suppTable.getColumnCount();
Object[] data = new Object[col];
- for (int i = 0; i < col; i++)
+ for (int i = 0; i < col; i++) {
data[i] = suppTable.getValueAt(row, i);
+ }
+
codeText.setText((String) data[0]);
nameText.setText((String) data[1]);
locationText.setText((String) data[2]);
@@ -315,7 +313,7 @@ private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
supplierModel.setPhone(phoneText.getText());
EventQueue.invokeLater(() -> {
- supplierController.updateSupplier(supplierModel, code);
+ new SupplierController(id).updateSupplier(supplierModel, code);
loadDataSet();
});
}
@@ -333,7 +331,10 @@ private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
JOptionPane.YES_NO_OPTION);
if (opt == JOptionPane.YES_OPTION) {
EventQueue.invokeLater(() -> {
- supplierController.deleteSupplier(suppTable.getValueAt(suppTable.getSelectedRow(), 0).toString(), suppTable.getValueAt(suppTable.getSelectedRow(), 1).toString());
+ String code = suppTable.getValueAt(suppTable.getSelectedRow(), 0).toString();
+ String name = suppTable.getValueAt(suppTable.getSelectedRow(), 1).toString();
+
+ new SupplierController(id).deleteSupplier(code, name);
loadDataSet();
});
}
@@ -341,8 +342,7 @@ private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
}//GEN-LAST:event_deleteButtonActionPerformed
private void searchTextKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchTextKeyReleased
- String text = searchText.getText();
- loadSearchData(text);
+ loadSearchData(searchText.getText());
}//GEN-LAST:event_searchTextKeyReleased
@@ -350,7 +350,7 @@ private void searchTextKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:eve
public void loadDataSet() {
EventQueue.invokeLater(() -> {
try {
- suppTable.setModel(new DataTableModel().buildTableModel(supplierController.getSuppliers()));
+ suppTable.setModel(new DataTableModel().buildTableModel(new SupplierController(id).getSuppliers()));
} catch (SQLException e) {
e.printStackTrace();
}
@@ -361,7 +361,7 @@ public void loadDataSet() {
public void loadSearchData(String text) {
EventQueue.invokeLater(() -> {
try {
- suppTable.setModel(new DataTableModel().buildTableModel(supplierController.searchSuppliers(text)));
+ suppTable.setModel(new DataTableModel().buildTableModel(new SupplierController(id).searchSuppliers(text)));
} catch (SQLException e) {
e.printStackTrace();
}
diff --git a/src/main/java/com/pharmacy/views/UsersPage.java b/src/main/java/com/pharmacy/views/UsersPage.java
index 598aa4a..7a83d60 100644
--- a/src/main/java/com/pharmacy/views/UsersPage.java
+++ b/src/main/java/com/pharmacy/views/UsersPage.java
@@ -12,15 +12,12 @@
public class UsersPage extends javax.swing.JPanel {
- UserController userController;
- int id;
+ private final int id;
public UsersPage(int id) {
this.id = id;
initComponents();
-
- userController = new UserController(id);
loadDataSet();
}
@@ -324,7 +321,7 @@ private void updateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
userModel.setType(userType);
EventQueue.invokeLater(() -> {
- userController.updateUser(userModel);
+ new UserController(id).updateUser(userModel);
loadDataSet();
});
}
@@ -350,7 +347,7 @@ private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
if (opt == JOptionPane.YES_OPTION) {
EventQueue.invokeLater(() -> {
- userController.deleteUser((Integer) userTable.getValueAt(userTable.getSelectedRow(), 0), username);
+ new UserController(id).deleteUser((Integer) userTable.getValueAt(userTable.getSelectedRow(), 0), username);
loadDataSet();
});
}
@@ -399,7 +396,7 @@ private void changePasswordActionPerformed(java.awt.event.ActionEvent evt) {//GE
if (password != null) {
EventQueue.invokeLater(() -> {
- userController.updatePass(selectedId, selectedUsername, password);
+ new UserController(id).updatePass(selectedId, selectedUsername, password);
JOptionPane.showMessageDialog(this, "Password changed successfully.", "Success", JOptionPane.INFORMATION_MESSAGE);
});
}
@@ -421,7 +418,7 @@ private void processColumns() {
public void loadSearchData(String text) {
EventQueue.invokeLater(() -> {
try {
- userTable.setModel(new DataTableModel().buildTableModel(userController.searchUsers(text)));
+ userTable.setModel(new DataTableModel().buildTableModel(new UserController(id).searchUsers(text)));
processColumns();
} catch (SQLException e) {
@@ -433,7 +430,7 @@ public void loadSearchData(String text) {
public final void loadDataSet() {
EventQueue.invokeLater(() -> {
try {
- userTable.setModel(new DataTableModel().buildTableModel(userController.getUsers()));
+ userTable.setModel(new DataTableModel().buildTableModel(new UserController(id).getUsers()));
processColumns();
} catch (SQLException ex) {