Bläddra i källkod

关闭客户端和复位时,加入确认按键

wangxichen 4 dagar sedan
förälder
incheckning
45439a25b6
2 ändrade filer med 99 tillägg och 5 borttagningar
  1. 11 1
      src/com/mes/ui/LoginFarme.java
  2. 88 4
      src/com/mes/ui/MesClient.java

+ 11 - 1
src/com/mes/ui/LoginFarme.java

@@ -10,6 +10,8 @@ import javax.swing.*;
 import java.awt.*;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
 import java.time.LocalDateTime;
 
 public class LoginFarme extends JFrame {
@@ -25,7 +27,15 @@ public class LoginFarme extends JFrame {
         setTitle("MES系统客户端:"+MesClient.mes_gw+" - "+MesClient.mes_gw_des);
 
         ImageIcon bg = new ImageIcon(MesClient.class.getResource("/background.png"));
-        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
+        addWindowListener(new WindowAdapter() {
+            @Override
+            public void windowClosing(WindowEvent e) {
+                if (MesClient.confirmClose(LoginFarme.this)) {
+                    System.exit(0);
+                }
+            }
+        });
         JLabel imgLabel = new JLabel(bg);//将背景图放在标签里。
         getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));//注意这里是关键,将背景标签添加到jfram的LayeredPane面板里。
         imgLabel.setBounds(0,0,bg.getIconWidth(), bg.getIconHeight());//设置背景标签的位置

+ 88 - 4
src/com/mes/ui/MesClient.java

@@ -24,6 +24,8 @@ import java.awt.event.ComponentAdapter;
 import java.awt.event.ComponentEvent;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
@@ -396,6 +398,10 @@ public class MesClient extends JFrame {
         updateManualSubmitButtons();
     }
     private static void requestUnbindSteelSn(String steelSn) {
+        requestUnbindSteelSn(steelSn, manualSteelSnInput);
+    }
+
+    private static void requestUnbindSteelSn(String steelSn, final JTextField steelSnInputToClear) {
         if (steelSn == null || steelSn.trim().length() != 11) {
             setMenuStatus("请输入11位钢印码", 1);
             updateManualSubmitButtons();
@@ -419,7 +425,9 @@ public class MesClient extends JFrame {
                         if (retObj != null && retObj.get("result") != null
                                 && "true".equalsIgnoreCase(retObj.get("result").toString())) {
                             setMenuStatus(retObj.getString("message"), 0);
-                            manualSteelSnInput.setText("");
+                            if (steelSnInputToClear != null) {
+                                steelSnInputToClear.setText("");
+                            }
                             product_sn.setText("");
                         } else {
                             String msg = retObj != null && retObj.get("message") != null
@@ -578,10 +586,23 @@ public class MesClient extends JFrame {
         connect_request_flag = false;
     }
 
+    public static boolean confirmClose(Component parent) {
+        return JOptionPane.showConfirmDialog(parent, "确定要关闭MES系统客户端吗?", "确认关闭",
+                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION;
+    }
+
     public MesClient() {
         setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
         setTitle("MES系统客户端:"+mes_gw + "- " + mes_gw_des);
-        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
+        addWindowListener(new WindowAdapter() {
+            @Override
+            public void windowClosing(WindowEvent e) {
+                if (confirmClose(MesClient.this)) {
+                    System.exit(0);
+                }
+            }
+        });
         setBounds(0, 0, 1024, 768);
         
         // 确保标题栏正确显示
@@ -735,8 +756,13 @@ public class MesClient extends JFrame {
         laser_reset_bt = new JButton("复位");
         laser_reset_bt.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
-                laserFlowManager.manualReset();
-                resetManualSubmitPanel(true);
+                int result = JOptionPane.showConfirmDialog(MesClient.this,
+                        "复位会取消当前镭雕流程,确定要继续吗?", "确认复位",
+                        JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
+                if (result == JOptionPane.YES_OPTION) {
+                    laserFlowManager.manualReset();
+                    resetManualSubmitPanel(true);
+                }
             }
         });
         laser_reset_bt.setFont(new Font("微软雅黑", Font.PLAIN, 24));
@@ -995,6 +1021,64 @@ public class MesClient extends JFrame {
         tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
         tabbedPane.setEnabledAt(0, true);
 
+        JPanel unbindPanel = new JPanel();
+        JScrollPane unbindScrollPane = new JScrollPane(unbindPanel);
+        unbindPanel.setLayout(null);
+
+        JLabel unbindTitle = new JLabel("钢印码解绑");
+        unbindTitle.setHorizontalAlignment(SwingConstants.CENTER);
+        unbindTitle.setForeground(Color.BLACK);
+        unbindTitle.setFont(new Font("微软雅黑", Font.PLAIN, 28));
+        unbindTitle.setBounds(260, 80, 420, 50);
+        unbindPanel.add(unbindTitle);
+
+        JLabel unbindInputLabel = new JLabel("钢印码");
+        unbindInputLabel.setHorizontalAlignment(SwingConstants.RIGHT);
+        unbindInputLabel.setForeground(Color.BLACK);
+        unbindInputLabel.setFont(new Font("微软雅黑", Font.PLAIN, 22));
+        unbindInputLabel.setBounds(170, 170, 120, 50);
+        unbindPanel.add(unbindInputLabel);
+
+        final JTextField unbindSteelSnInput = new JTextField();
+        unbindSteelSnInput.setHorizontalAlignment(SwingConstants.CENTER);
+        unbindSteelSnInput.setFont(new Font("微软雅黑", Font.PLAIN, 24));
+        unbindSteelSnInput.setToolTipText("输入11位钢印码");
+        unbindSteelSnInput.setBounds(320, 170, 340, 50);
+        unbindPanel.add(unbindSteelSnInput);
+
+        final JButton unbindSteelSnBt = new JButton("解绑钢印码");
+        unbindSteelSnBt.setEnabled(false);
+        unbindSteelSnBt.setFont(new Font("微软雅黑", Font.PLAIN, 24));
+        unbindSteelSnBt.setBounds(320, 250, 220, 60);
+        unbindSteelSnBt.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                requestUnbindSteelSn(unbindSteelSnInput.getText(), unbindSteelSnInput);
+            }
+        });
+        unbindPanel.add(unbindSteelSnBt);
+
+        unbindSteelSnInput.getDocument().addDocumentListener(new DocumentListener() {
+            private void update() {
+                boolean ready = unbindSteelSnInput.getText().trim().length() == 11;
+                boolean laserBusy = laserFlowManager != null && laserFlowManager.isWaitingComplete();
+                unbindSteelSnBt.setEnabled(ready && !laserBusy);
+            }
+
+            public void insertUpdate(DocumentEvent e) {
+                update();
+            }
+
+            public void removeUpdate(DocumentEvent e) {
+                update();
+            }
+
+            public void changedUpdate(DocumentEvent e) {
+                update();
+            }
+        });
+
+        tabbedPane.addTab("钢印解绑", new ImageIcon(MesClient.class.getResource("/bg/delete.png")), unbindScrollPane, null);
+
 //		searchScrollPane = new JScrollPane((Component) null);
 
         indexPanelC = new JPanel();