From a6292aefb320366608488d333bdb3c73966d00d6 Mon Sep 17 00:00:00 2001 From: lds217 Date: Sat, 25 Jan 2025 20:29:35 -0500 Subject: [PATCH] fire emergency --- .../CheckUpPage/AddDialog/AddDialog.java | 3 +- .../ui/component/CheckUpPage/CheckUpPage.java | 33 ++++++++++++---- .../java/BsK/common/util/date/DateUtils.java | 39 +++++++++++++++++++ .../server/network/handler/ServerHandler.java | 6 ++- 4 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 src/main/java/BsK/common/util/date/DateUtils.java diff --git a/src/main/java/BsK/client/ui/component/CheckUpPage/AddDialog/AddDialog.java b/src/main/java/BsK/client/ui/component/CheckUpPage/AddDialog/AddDialog.java index 5ab25f4..ad22e2a 100644 --- a/src/main/java/BsK/client/ui/component/CheckUpPage/AddDialog/AddDialog.java +++ b/src/main/java/BsK/client/ui/component/CheckUpPage/AddDialog/AddDialog.java @@ -42,6 +42,7 @@ public class AddDialog extends JDialog { void getRecentPatientHandler(GetRecentPatientResponse response) { log.info("Received GetRecentPatientResponse"); patientData = response.getPatientData(); + patientTableModel.setDataVector(patientData, patientColumns); } @@ -49,7 +50,7 @@ public class AddDialog extends JDialog { super(parent, "Add Patient", true); // Set size of the dialog - setSize(1000, 600); + setSize(1000, 400); setResizable(true); // Send request to get the latest 20 patients in the database diff --git a/src/main/java/BsK/client/ui/component/CheckUpPage/CheckUpPage.java b/src/main/java/BsK/client/ui/component/CheckUpPage/CheckUpPage.java index 123f292..b33dc26 100644 --- a/src/main/java/BsK/client/ui/component/CheckUpPage/CheckUpPage.java +++ b/src/main/java/BsK/client/ui/component/CheckUpPage/CheckUpPage.java @@ -3,6 +3,7 @@ package BsK.client.ui.component.CheckUpPage; import BsK.client.LocalStorage; import BsK.client.network.handler.ClientHandler; import BsK.client.network.handler.ResponseListener; +import BsK.client.ui.component.CheckUpPage.AddDialog.AddDialog; import BsK.client.ui.component.CheckUpPage.MedicineDialog.MedicineDialog; import BsK.client.ui.component.CheckUpPage.PrintDialog.MedicineInvoice; import BsK.client.ui.component.CheckUpPage.ServiceDialog.ServiceDialog; @@ -54,8 +55,11 @@ public class CheckUpPage extends JPanel { private String[] doctorOptions; private MedicineDialog medDialog = null; private ServiceDialog serDialog = null; + private AddDialog addDialog = null; private int previousSelectedRow = -1; private boolean saved = false; + + boolean returnCell = false; public void updateQueue() { ClientHandler.addResponseListener(GetCheckUpQueueResponse.class, checkUpQueueListener); @@ -207,6 +211,7 @@ public class CheckUpPage extends JPanel { RoundedPanel rightTopPanel = new RoundedPanel(20, Color.WHITE, false); RoundedPanel rightBottomPanel = new RoundedPanel(20, Color.WHITE, false); + JPanel topPanel = new JPanel(new BorderLayout()); JLabel titleText1 = new JLabel(); titleText1.setText("Check Up Queue 1"); @@ -215,10 +220,28 @@ public class CheckUpPage extends JPanel { titleText1.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); // Padding + JButton rightButton = new JButton(" ADD "); + rightButton.setBackground(new Color(63, 81, 181)); + rightButton.setForeground(Color.WHITE); + rightButton.setFocusPainted(false); + rightButton.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20)); // Padding + rightButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + + rightButton.addActionListener(e -> { + if(addDialog == null) { + addDialog = new AddDialog(mainFrame); + } + addDialog.setVisible(true); + }); + + topPanel.add(titleText1, BorderLayout.WEST); + topPanel.add(rightButton, BorderLayout.EAST); + leftPanel.setLayout(new BorderLayout()); - leftPanel.add(titleText1, BorderLayout.NORTH); + leftPanel.add(topPanel, BorderLayout.NORTH); leftPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 10)); + rightBottomPanel.setLayout(new BorderLayout()); rightBottomPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 10)); @@ -460,7 +483,7 @@ public class CheckUpPage extends JPanel { iconPanel.setLayout(new GridLayout(1, 5)); iconPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); // Padding iconPanel.setBackground(Color.WHITE); - String[] iconName = {"add", "save", "service", "medicine", "printer"}; + String[] iconName = {"save", "service", "medicine", "printer"}; for (String name : iconName) { ImageIcon originalIcon = new ImageIcon("src/main/java/BsK/client/ui/assets/icon/" + name + ".png"); Image scaledImage = originalIcon.getImage().getScaledInstance(32, 32, Image.SCALE_SMOOTH); // Resize to 32x32 @@ -472,10 +495,6 @@ public class CheckUpPage extends JPanel { @Override public void mouseClicked(MouseEvent e) { switch (name) { - case "add": - // Add action - JOptionPane.showMessageDialog(null, "Add action triggered"); - break; case "service": // If there is no user selected, show a warning message if (checkupIdField.getText().isEmpty()) { @@ -680,8 +699,6 @@ public class CheckUpPage extends JPanel { customerWeightSpinner.setValue(Double.parseDouble(customerWeight)); customerHeightSpinner.setValue(Double.parseDouble(customerHeight)); - - NetworkUtil.sendPacket(ClientHandler.ctx.channel(), new GetCustomerHistoryRequest(Integer.parseInt(queue[selectedRow][9]))); } diff --git a/src/main/java/BsK/common/util/date/DateUtils.java b/src/main/java/BsK/common/util/date/DateUtils.java new file mode 100644 index 0000000..6c7282a --- /dev/null +++ b/src/main/java/BsK/common/util/date/DateUtils.java @@ -0,0 +1,39 @@ +package BsK.common.util.date; + +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; + +public class DateUtils { + /** + * Extracts the year from a given timestamp string in milliseconds. + * + * @param timestampStr the timestamp as a string (e.g., "1085875200000") + * @return the year as an integer, or -1 if the input is invalid + */ + public static int extractYearFromTimestamp(String timestampStr) { + try { + // Parse the string to a long value + long timestamp = Long.parseLong(timestampStr); + // Convert the timestamp to a LocalDateTime + LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()); + return dateTime.getYear(); // Return the year + } catch (NumberFormatException e) { + // Handle invalid input + System.err.println("Invalid timestamp: " + timestampStr); + return -1; // Return -1 to indicate an error + } + } + + public static void main(String[] args) { + // Test the method with valid and invalid input + String validTimestamp = "1085875200000"; + String invalidTimestamp = "invalid"; + + int validYear = DateUtils.extractYearFromTimestamp(validTimestamp); + System.out.println("Year: " + validYear); // Output: Year: 2004 + + int invalidYear = DateUtils.extractYearFromTimestamp(invalidTimestamp); + System.out.println("Year: " + invalidYear); // Output: Year: -1 + } +} diff --git a/src/main/java/BsK/server/network/handler/ServerHandler.java b/src/main/java/BsK/server/network/handler/ServerHandler.java index 43e979a..ce7c9e2 100644 --- a/src/main/java/BsK/server/network/handler/ServerHandler.java +++ b/src/main/java/BsK/server/network/handler/ServerHandler.java @@ -5,6 +5,7 @@ import BsK.common.packet.PacketSerializer; import BsK.common.packet.req.*; import BsK.common.packet.res.*; import BsK.common.packet.res.ErrorResponse.Error; +import BsK.common.util.date.DateUtils; import BsK.server.network.manager.SessionManager; import BsK.server.network.util.UserUtil; import io.netty.channel.ChannelHandlerContext; @@ -321,12 +322,13 @@ public class ServerHandler extends SimpleChannelInboundHandler