wangxichen 5 giorni fa
parent
commit
bc4c317142
2 ha cambiato i file con 88 aggiunte e 24 eliminazioni
  1. 3 0
      src/com/mes/laser/LaserFlowManager.java
  2. 85 24
      src/com/mes/ui/MesClient.java

+ 3 - 0
src/com/mes/laser/LaserFlowManager.java

@@ -83,6 +83,9 @@ public class LaserFlowManager {
         completeServer.start(localPort);
     }
 
+    public boolean isWaitingComplete() {
+        return waitingComplete;
+    }
     public void stopCompleteServer() {
         if (completeServer != null) {
             completeServer.stop();

+ 85 - 24
src/com/mes/ui/MesClient.java

@@ -15,6 +15,8 @@ import javax.swing.*;
 import javax.swing.border.EmptyBorder;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
 import java.awt.*;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
@@ -102,6 +104,11 @@ public class MesClient extends JFrame {
     public static JButton laser_get_code_bt; // 获取镭雕码按钮
     public static JButton laser_reset_bt; // 人工复位按钮
     public static LaserFlowManager laserFlowManager;
+    public static JTextField manualSteelSnInput;
+    public static JButton manualGetCodeBt;
+    public static JButton manualFinishOkBt;
+    private static boolean manualWaitingComplete = false;
+    private static boolean manualCompleting = false;
 
     public static void main(String[] args) {
         if (LockUtil.getInstance().isAppActive() == true){
@@ -358,6 +365,29 @@ public class MesClient extends JFrame {
         MesClient.status_menu.setText(msg);
     }
 
+
+    private static boolean isManualSteelSnReady() {
+        return manualSteelSnInput != null && manualSteelSnInput.getText().trim().length() == 11;
+    }
+
+    private static void updateManualSubmitButtons() {
+        boolean ready = isManualSteelSnReady();
+        if (manualGetCodeBt != null) {
+            manualGetCodeBt.setEnabled(!manualWaitingComplete && ready);
+        }
+        if (manualFinishOkBt != null) {
+            manualFinishOkBt.setEnabled(manualWaitingComplete && !manualCompleting);
+        }
+    }
+
+    private static void resetManualSubmitPanel(boolean clearInput) {
+        manualWaitingComplete = false;
+        manualCompleting = false;
+        if (clearInput && manualSteelSnInput != null) {
+            manualSteelSnInput.setText("");
+        }
+        updateManualSubmitButtons();
+    }
     public static void scanBarcode() {
         String scanBarcodeTitle = "";
         switch(scan_type) {
@@ -466,6 +496,9 @@ public class MesClient extends JFrame {
                     if(laser_get_code_bt != null){
                         laser_get_code_bt.setEnabled(!lock);
                     }
+                    if (!lock && manualWaitingComplete) {
+                        resetManualSubmitPanel(true);
+                    }
                 });
             }
 
@@ -659,6 +692,7 @@ public class MesClient extends JFrame {
         laser_reset_bt.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 laserFlowManager.manualReset();
+                resetManualSubmitPanel(true);
             }
         });
         laser_reset_bt.setFont(new Font("微软雅黑", Font.PLAIN, 24));
@@ -789,59 +823,86 @@ public class MesClient extends JFrame {
         finish_ng_bt.setVisible(false);
         indexPanelA.add(finish_ng_bt);
 
-        // ===== 调试面板:供应商真实接口未接通前,用于模拟镭雕软件回传的各阶段信号 =====
-        JLabel debugTitle = new JLabel("调试面板(模拟镭雕软件信号)");
+        // ===== 手动提交面板 =====
+        JLabel debugTitle = new JLabel("手动提交");
         debugTitle.setFont(new Font("微软雅黑", Font.PLAIN, 16));
         debugTitle.setForeground(Color.GRAY);
         debugTitle.setBounds(760, 40, 260, 30);
         indexPanelA.add(debugTitle);
 
-        JTextField debugSteelSnInput = new JTextField();
-        debugSteelSnInput.setFont(new Font("微软雅黑", Font.PLAIN, 16));
-        debugSteelSnInput.setBounds(760, 80, 220, 40);
-        debugSteelSnInput.setToolTipText("输入测试用钢印码,留空则自动生成");
-        indexPanelA.add(debugSteelSnInput);
+        manualSteelSnInput = new JTextField();
+        manualSteelSnInput.setFont(new Font("微软雅黑", Font.PLAIN, 16));
+        manualSteelSnInput.setBounds(760, 80, 220, 40);
+        manualSteelSnInput.setToolTipText("输入11位钢印码");
+        manualSteelSnInput.getDocument().addDocumentListener(new DocumentListener() {
+            public void insertUpdate(DocumentEvent e) {
+                updateManualSubmitButtons();
+            }
+
+            public void removeUpdate(DocumentEvent e) {
+                updateManualSubmitButtons();
+            }
+
+            public void changedUpdate(DocumentEvent e) {
+                updateManualSubmitButtons();
+            }
+        });
+        indexPanelA.add(manualSteelSnInput);
 
-        JButton debugSimGetCodeBtn = new JButton("模拟获取镭雕码");
-        debugSimGetCodeBtn.addActionListener(new ActionListener() {
+        manualGetCodeBt = new JButton("模拟获取镭雕码");
+        manualGetCodeBt.setEnabled(false);
+        manualGetCodeBt.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
-                laserFlowManager.simulateGetCode(debugSteelSnInput.getText());
+                if (!isManualSteelSnReady()) {
+                    MesClient.setMenuStatus("请输入11位钢印码", 1);
+                    updateManualSubmitButtons();
+                    return;
+                }
+                if (laserFlowManager.isWaitingComplete()) {
+                    MesClient.setMenuStatus("镭雕进行中,请先完成或复位", 1);
+                    return;
+                }
+                manualWaitingComplete = true;
+                manualCompleting = false;
+                laserFlowManager.simulateGetCode(manualSteelSnInput.getText());
+                updateManualSubmitButtons();
             }
         });
-        debugSimGetCodeBtn.setFont(new Font("微软雅黑", Font.PLAIN, 16));
-        debugSimGetCodeBtn.setBounds(760, 130, 220, 50);
-        indexPanelA.add(debugSimGetCodeBtn);
+        manualGetCodeBt.setFont(new Font("微软雅黑", Font.PLAIN, 16));
+        manualGetCodeBt.setBounds(760, 130, 220, 50);
+        indexPanelA.add(manualGetCodeBt);
 
-        JButton debugSimOkBtn = new JButton("模拟完成信号(OK)");
-        debugSimOkBtn.addActionListener(new ActionListener() {
+        manualFinishOkBt = new JButton("模拟完成信号(OK)");
+        manualFinishOkBt.setEnabled(false);
+        manualFinishOkBt.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
+                manualCompleting = true;
+                updateManualSubmitButtons();
                 laserFlowManager.simulateComplete("OK", "");
             }
         });
-        debugSimOkBtn.setFont(new Font("微软雅黑", Font.PLAIN, 16));
-        debugSimOkBtn.setBounds(760, 190, 220, 50);
-        indexPanelA.add(debugSimOkBtn);
+        manualFinishOkBt.setFont(new Font("微软雅黑", Font.PLAIN, 16));
+        manualFinishOkBt.setBounds(760, 190, 220, 50);
+        indexPanelA.add(manualFinishOkBt);
 
         JButton debugSimNgBtn = new JButton("模拟完成信号(NG)");
+        debugSimNgBtn.setVisible(false);
         debugSimNgBtn.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 laserFlowManager.simulateComplete("NG", "模拟打码失败");
             }
         });
-        debugSimNgBtn.setFont(new Font("微软雅黑", Font.PLAIN, 16));
-        debugSimNgBtn.setBounds(760, 250, 220, 50);
         indexPanelA.add(debugSimNgBtn);
 
         JButton debugGenSnBtn = new JButton("测试生成客户编码");
+        debugGenSnBtn.setVisible(false);
         debugGenSnBtn.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
-                laserFlowManager.manualGenCustomerSn(debugSteelSnInput.getText());
+                laserFlowManager.manualGenCustomerSn(manualSteelSnInput.getText());
             }
         });
-        debugGenSnBtn.setFont(new Font("微软雅黑", Font.PLAIN, 16));
-        debugGenSnBtn.setBounds(760, 310, 220, 50);
         indexPanelA.add(debugGenSnBtn);
-        // ===== 调试面板结束 =====
+        // ===== 手动提交面板结束 =====
 
         JButton modbusBtn = new JButton("关");
         modbusBtn.addActionListener(new ActionListener() {