|
|
@@ -191,9 +191,6 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
textFocus();
|
|
|
|
|
|
- // 预热打印模块(后台异步,不阻塞启动)
|
|
|
- com.mes.print.PrintHelper.warmUpAsync();
|
|
|
-
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
@@ -240,9 +237,13 @@ public class MesClient extends JFrame {
|
|
|
cjTimer.schedule(new TimerTask() {
|
|
|
public void run() {
|
|
|
try{
|
|
|
- // 只监控 B 面
|
|
|
+ // 只轮询本机负责的面
|
|
|
if(!MesClient.sessionid.isEmpty()){
|
|
|
- PlcUtil.getStatusB(s7PLC);
|
|
|
+ if("B".equals(side())){
|
|
|
+ PlcUtil.getStatusB(s7PLC);
|
|
|
+ }else{
|
|
|
+ PlcUtil.getStatusA(s7PLC);
|
|
|
+ }
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
@@ -259,28 +260,8 @@ public class MesClient extends JFrame {
|
|
|
cjTimerText = new Timer();
|
|
|
cjTimerText.schedule(new TimerTask() {
|
|
|
public void run() {
|
|
|
+ // 面别由配置固定,不再读转台到位信号,这里只保持扫码框焦点
|
|
|
textField.requestFocusInWindow();
|
|
|
-
|
|
|
- String page = PlcUtil.getCurAside(s7PLC);
|
|
|
- if(page != null && page.equals("B")){
|
|
|
- // B 面可扫码:绿色背景
|
|
|
- lblNewLabel_5.setText("当前:B面(可扫码)");
|
|
|
- lblNewLabel_5.setForeground(new Color(0, 128, 0));
|
|
|
- if(product_sn2.getText().isEmpty() || product_sn2.getText().contains("请等待")){
|
|
|
- product_sn2.setText("OP060 - 请扫码");
|
|
|
- product_sn2.setBackground(new Color(144, 238, 144)); // 浅绿色
|
|
|
- product_sn2.setForeground(Color.BLACK);
|
|
|
- }
|
|
|
- }else{
|
|
|
- // A 面等待转台:灰色背景
|
|
|
- lblNewLabel_5.setText("当前:A面(等待转台)");
|
|
|
- lblNewLabel_5.setForeground(Color.GRAY);
|
|
|
- if(product_sn2.getText().isEmpty() || product_sn2.getText().contains("请扫码") || product_sn2.getText().contains("请等待")){
|
|
|
- product_sn2.setText("请等待转到B面扫码");
|
|
|
- product_sn2.setBackground(Color.LIGHT_GRAY);
|
|
|
- product_sn2.setForeground(Color.DARK_GRAY);
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
}, 1000,1000);
|
|
|
}
|
|
|
@@ -323,6 +304,14 @@ public class MesClient extends JFrame {
|
|
|
System.out.println(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 本机负责的面:由 config 的 mes.gwflag 决定,只认 A / B
|
|
|
+ * 该值同时是 PLC 点位面别和 MES 工序号后缀(OP120A / OP120B)
|
|
|
+ */
|
|
|
+ public static String side() {
|
|
|
+ return "B".equals(mes_gwflag) ? "B" : "A";
|
|
|
+ }
|
|
|
+
|
|
|
// 閸掓繂顫愰崠鏈P
|
|
|
public static void initTcpConnection() {
|
|
|
try {
|
|
|
@@ -414,7 +403,41 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
|
|
|
public static void initWarehouseData(){
|
|
|
- resetScanB();
|
|
|
+ // 只复位本机负责的面
|
|
|
+ if("B".equals(side())){
|
|
|
+ resetScanB();
|
|
|
+ }else{
|
|
|
+ resetScanA();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void resetScanA() {
|
|
|
+ work_status = 0;
|
|
|
+ check_quality_result = false;
|
|
|
+ MesClient.finish_ok_bt.setEnabled(true);
|
|
|
+ MesClient.mesQualityFlagA = false;
|
|
|
+ product_sn.setText("");
|
|
|
+
|
|
|
+ MesClient.pxstatus1.setText("A");
|
|
|
+ MesClient.param1.setText("");
|
|
|
+ MesClient.param2.setText("");
|
|
|
+ MesClient.param3.setText("");
|
|
|
+ MesClient.param4.setText("");
|
|
|
+ MesClient.param5.setText("");
|
|
|
+
|
|
|
+ MesClient.param21.setText("");
|
|
|
+ MesClient.param22.setText("");
|
|
|
+ MesClient.param23.setText("");
|
|
|
+ MesClient.param24.setText("");
|
|
|
+ MesClient.param25.setText("");
|
|
|
+ MesClient.curFlag = "";
|
|
|
+ MesClient.curSna = "";
|
|
|
+ MesClient.tjFlaga = 0;
|
|
|
+ PlcUtil.changeEnable(s7PLC, false, "A");
|
|
|
+
|
|
|
+ updateMaterailData(); // 更新物料
|
|
|
+
|
|
|
+ shiftUserCheck();
|
|
|
}
|
|
|
|
|
|
public static int userLoginHours;//用户登录所处小时
|
|
|
@@ -442,18 +465,7 @@ public class MesClient extends JFrame {
|
|
|
check_quality_result2 = false;
|
|
|
MesClient.finish_ng_bt.setEnabled(true);
|
|
|
MesClient.mesQualityFlagB = false;
|
|
|
-
|
|
|
- // 清空后根据转台位置恢复提示
|
|
|
- String page = PlcUtil.getCurAside(s7PLC);
|
|
|
- if(page != null && page.equals("B")){
|
|
|
- product_sn2.setText("OP060 - 请扫码");
|
|
|
- product_sn2.setBackground(new Color(144, 238, 144)); // 浅绿色
|
|
|
- product_sn2.setForeground(Color.BLACK);
|
|
|
- }else{
|
|
|
- product_sn2.setText("请等待转到B面扫码");
|
|
|
- product_sn2.setBackground(Color.LIGHT_GRAY);
|
|
|
- product_sn2.setForeground(Color.DARK_GRAY);
|
|
|
- }
|
|
|
+ product_sn2.setText("");
|
|
|
|
|
|
MesClient.pxstatus2.setText("B");
|
|
|
|
|
|
@@ -566,6 +578,18 @@ public class MesClient extends JFrame {
|
|
|
});
|
|
|
settingMenu.add(resetTcpMenu);
|
|
|
|
|
|
+ JMenuItem resetTcpMenu_1 = new JMenuItem("\u91CD\u65B0\u626B\u7801-A");
|
|
|
+ resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
|
|
|
+ resetTcpMenu_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
|
|
|
+ resetTcpMenu_1.addMouseListener(new MouseAdapter() {
|
|
|
+ @Override
|
|
|
+ public void mousePressed(MouseEvent e) {
|
|
|
+ super.mouseClicked(e);
|
|
|
+ resetScanA();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ settingMenu.add(resetTcpMenu_1);
|
|
|
+
|
|
|
JMenuItem resetTcpMenu_1_1 = new JMenuItem("\u91CD\u65B0\u626B\u7801-B");
|
|
|
resetTcpMenu_1_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
|
|
|
resetTcpMenu_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
|
|
|
@@ -614,8 +638,7 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
if(!sn.isEmpty()){
|
|
|
String qret = "OK";
|
|
|
- String oprno = mes_gw + mes_gwflag; // OP060A
|
|
|
- Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,oprno);
|
|
|
+ Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
|
|
|
if(!sendret){
|
|
|
MesClient.setMenuStatus("上传MES失败,请重试",-1);
|
|
|
}
|
|
|
@@ -625,43 +648,6 @@ public class MesClient extends JFrame {
|
|
|
});
|
|
|
settingMenu.add(resetTcpMenu_1_1sd);
|
|
|
|
|
|
- // 打印机设置菜单
|
|
|
- JMenuItem printerSettingMenu = new JMenuItem("打印机设置");
|
|
|
- printerSettingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
|
|
|
- printerSettingMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
|
|
|
- printerSettingMenu.addMouseListener(new MouseAdapter() {
|
|
|
- @Override
|
|
|
- public void mousePressed(MouseEvent e) {
|
|
|
- super.mouseClicked(e);
|
|
|
- try {
|
|
|
- // 调用打印机设置对话框
|
|
|
- com.mes.print.ui.PrinterSettingDialog dialog =
|
|
|
- new com.mes.print.ui.PrinterSettingDialog(MesClient.this);
|
|
|
- dialog.setVisible(true);
|
|
|
- } catch (Exception ex) {
|
|
|
- JOptionPane.showMessageDialog(MesClient.this,
|
|
|
- "打开打印机设置失败: " + ex.getMessage(),
|
|
|
- "错误",
|
|
|
- JOptionPane.ERROR_MESSAGE);
|
|
|
- ex.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- settingMenu.add(printerSettingMenu);
|
|
|
-
|
|
|
- // 测试打印菜单
|
|
|
- JMenuItem testPrintMenu = new JMenuItem("测试打印");
|
|
|
- testPrintMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
|
|
|
- testPrintMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
|
|
|
- testPrintMenu.addMouseListener(new MouseAdapter() {
|
|
|
- @Override
|
|
|
- public void mousePressed(MouseEvent e) {
|
|
|
- super.mouseClicked(e);
|
|
|
- showTestPrintDialog();
|
|
|
- }
|
|
|
- });
|
|
|
- settingMenu.add(testPrintMenu);
|
|
|
-
|
|
|
contentPane = new JPanel();
|
|
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
|
setContentPane(contentPane);
|
|
|
@@ -743,13 +729,21 @@ public class MesClient extends JFrame {
|
|
|
indexPanelA.setLayout(null);
|
|
|
|
|
|
product_sn = new JTextField();
|
|
|
- product_sn.setText("OP050工位(不监控)");
|
|
|
+ product_sn.setText("");
|
|
|
product_sn.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
product_sn.setEditable(false);
|
|
|
- product_sn.setEnabled(false); // 禁用
|
|
|
- product_sn.setBackground(Color.LIGHT_GRAY); // 灰色背景
|
|
|
- product_sn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
|
|
|
+ product_sn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
|
|
|
product_sn.setBounds(26, 144, 446, 70);
|
|
|
+ // 添加鼠标点击事件,点击显示二维码
|
|
|
+ product_sn.addMouseListener(new MouseAdapter() {
|
|
|
+ @Override
|
|
|
+ public void mouseClicked(MouseEvent e) {
|
|
|
+ String sn = product_sn.getText();
|
|
|
+ if(sn != null && !sn.trim().isEmpty()){
|
|
|
+ new com.mes.component.QRCodeDialog(mesClientFrame, "A面工件码二维码", sn);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
indexPanelA.add(product_sn);
|
|
|
product_sn.setColumns(10);
|
|
|
|
|
|
@@ -883,19 +877,18 @@ public class MesClient extends JFrame {
|
|
|
indexPanelA.add(lblNewLabel_1_1_1);
|
|
|
|
|
|
product_sn2 = new JTextField();
|
|
|
- product_sn2.setText("请等待转到B面扫码");
|
|
|
+ product_sn2.setText("");
|
|
|
product_sn2.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
- product_sn2.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 22));
|
|
|
+ product_sn2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
|
|
|
product_sn2.setEditable(false);
|
|
|
product_sn2.setColumns(10);
|
|
|
product_sn2.setBounds(517, 144, 446, 70);
|
|
|
- product_sn2.setBackground(Color.LIGHT_GRAY); // 默认灰色,等待转台
|
|
|
// 添加鼠标点击事件,点击显示二维码
|
|
|
product_sn2.addMouseListener(new MouseAdapter() {
|
|
|
@Override
|
|
|
public void mouseClicked(MouseEvent e) {
|
|
|
String sn = product_sn2.getText();
|
|
|
- if(sn != null && !sn.trim().isEmpty() && !sn.contains("请等待")){
|
|
|
+ if(sn != null && !sn.trim().isEmpty()){
|
|
|
new com.mes.component.QRCodeDialog(mesClientFrame, "B面工件码二维码", sn);
|
|
|
}
|
|
|
}
|
|
|
@@ -1021,18 +1014,18 @@ public class MesClient extends JFrame {
|
|
|
textField.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
textField.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
|
|
|
textField.setColumns(10);
|
|
|
- textField.setBounds(400, 10, 510, 50); // 向右移动,给状态标签留空间
|
|
|
+ textField.setBounds(264, 10, 510, 50);
|
|
|
textField.addActionListener(new ActionListener() {
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
scanBarcode();
|
|
|
}
|
|
|
});
|
|
|
indexPanelA.add(textField);
|
|
|
-
|
|
|
- lblNewLabel_5 = new JLabel("等待检测转台位置...");
|
|
|
- lblNewLabel_5.setForeground(Color.GRAY);
|
|
|
- lblNewLabel_5.setFont(new Font("微软雅黑", Font.BOLD, 20));
|
|
|
- lblNewLabel_5.setBounds(126, 10, 360, 50);
|
|
|
+
|
|
|
+ lblNewLabel_5 = new JLabel("本机:" + side() + "面");
|
|
|
+ lblNewLabel_5.setForeground(new Color(0, 128, 64));
|
|
|
+ lblNewLabel_5.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
+ lblNewLabel_5.setBounds(136, 10, 113, 50);
|
|
|
indexPanelA.add(lblNewLabel_5);
|
|
|
|
|
|
tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
|
|
|
@@ -1312,32 +1305,29 @@ public class MesClient extends JFrame {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 检查转台位置,只有在 B 面才允许扫码
|
|
|
- String page = PlcUtil.getCurAside(s7PLC);
|
|
|
- if(page == null || !page.equals("B")){
|
|
|
- MesClient.setMenuStatus("请等待转到 B 面",1);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 固定走 B 面逻辑
|
|
|
- if(!product_sn2.getText().isEmpty() && !product_sn2.getText().contains("请扫码") && !product_sn2.getText().contains("请等待") && mesQualityFlagB){
|
|
|
- MesClient.setMenuStatus("B面已存在工件码,勿重复扫码",1);
|
|
|
- return;
|
|
|
+ // 面别由配置固定,扫到的码只落本机负责的面
|
|
|
+ String page = side();
|
|
|
+ if(page.equals("A")){
|
|
|
+ if(!product_sn.getText().isEmpty() && mesQualityFlagA){
|
|
|
+ MesClient.setMenuStatus("A面已存在工件码,勿重复扫码",1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ product_sn.setText(sn);
|
|
|
+ }else{
|
|
|
+ if(!product_sn2.getText().isEmpty() && mesQualityFlagB){
|
|
|
+ MesClient.setMenuStatus("B面已存在工件码,勿重复扫码",1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ product_sn2.setText(sn);
|
|
|
}
|
|
|
|
|
|
- // 显示工件码,恢复白色背景
|
|
|
- product_sn2.setText(sn);
|
|
|
- product_sn2.setBackground(Color.WHITE);
|
|
|
- product_sn2.setForeground(Color.BLACK);
|
|
|
-
|
|
|
MesClient.setMenuStatus("扫码成功",0);
|
|
|
|
|
|
//刷新界面
|
|
|
mesClientFrame.repaint();
|
|
|
getUser();
|
|
|
- // 查询工件质量,传入完整工序号
|
|
|
- String oprno = mes_gw + mes_gwflag; // OP060A
|
|
|
- Boolean sendret = DataUtil.checkQuality(nettyClient,sn,user20,oprno);
|
|
|
+ // 查询工件质量
|
|
|
+ Boolean sendret = DataUtil.checkQuality(nettyClient,sn,user20,page);
|
|
|
if(!sendret){
|
|
|
MesClient.setMenuStatus("消息发送失败,请重试",1);
|
|
|
}
|
|
|
@@ -1346,7 +1336,7 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
public static void scanBarcodeOld() {
|
|
|
String scanBarcodeTitle = "请扫工件码";
|
|
|
- String page = PlcUtil.getCurAside(s7PLC);
|
|
|
+ String page = side();
|
|
|
if(page.equals("A")){
|
|
|
product_sn.setText("");
|
|
|
}else{
|
|
|
@@ -1475,173 +1465,4 @@ public class MesClient extends JFrame {
|
|
|
log.info("异步任务执行完毕");
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 显示测试打印对话框
|
|
|
- */
|
|
|
- private void showTestPrintDialog() {
|
|
|
- JDialog dialog = new JDialog(this, "测试打印", true);
|
|
|
- dialog.setSize(450, 280);
|
|
|
- dialog.setLocationRelativeTo(this);
|
|
|
-
|
|
|
- JPanel panel = new JPanel();
|
|
|
- panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
|
|
- panel.setBorder(new EmptyBorder(20, 20, 20, 20));
|
|
|
-
|
|
|
- // 输入框
|
|
|
- JPanel inputPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
|
|
- JLabel label = new JLabel("客户码(二维码):");
|
|
|
- label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
|
|
|
- JTextField snField = new JTextField("+KB60IS3031T729002101", 22);
|
|
|
- snField.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
|
|
|
- snField.setPreferredSize(new Dimension(250, 35));
|
|
|
- inputPanel.add(label);
|
|
|
- inputPanel.add(snField);
|
|
|
- panel.add(inputPanel);
|
|
|
-
|
|
|
- panel.add(Box.createVerticalStrut(15));
|
|
|
-
|
|
|
- // 结果显示
|
|
|
- JLabel resultLabel = new JLabel(" ");
|
|
|
- resultLabel.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 14));
|
|
|
- resultLabel.setForeground(Color.BLUE);
|
|
|
- panel.add(resultLabel);
|
|
|
-
|
|
|
- panel.add(Box.createVerticalStrut(25));
|
|
|
-
|
|
|
- // 按钮面板
|
|
|
- JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 15, 0));
|
|
|
-
|
|
|
- // 查询按钮
|
|
|
- JButton queryBtn = new JButton("查询钢印码");
|
|
|
- queryBtn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
|
|
|
-
|
|
|
- // 预览按钮(初始禁用)
|
|
|
- JButton previewBtn = new JButton("预览效果");
|
|
|
- previewBtn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
|
|
|
- previewBtn.setEnabled(false);
|
|
|
-
|
|
|
- // 打印按钮(初始禁用)
|
|
|
- JButton printBtn = new JButton("打印");
|
|
|
- printBtn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
|
|
|
- printBtn.setEnabled(false);
|
|
|
-
|
|
|
- JButton closeBtn = new JButton("关闭");
|
|
|
- closeBtn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
|
|
|
- closeBtn.addActionListener(e -> dialog.dispose());
|
|
|
-
|
|
|
- // 用于保存查询到的数据
|
|
|
- final String[] queriedData = new String[2]; // [0]=customerSn, [1]=steelSn
|
|
|
-
|
|
|
- // 查询按钮逻辑
|
|
|
- queryBtn.addActionListener(e -> {
|
|
|
- String customerSn = snField.getText().trim();
|
|
|
- if (customerSn.isEmpty()) {
|
|
|
- JOptionPane.showMessageDialog(dialog, "请输入客户码", "提示", JOptionPane.WARNING_MESSAGE);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- queryBtn.setEnabled(false);
|
|
|
- previewBtn.setEnabled(false);
|
|
|
- printBtn.setEnabled(false);
|
|
|
- resultLabel.setText("正在查询钢印码...");
|
|
|
- resultLabel.setForeground(Color.BLUE);
|
|
|
-
|
|
|
- new Thread(() -> {
|
|
|
- try {
|
|
|
- String steelSn = DataUtil.getSteelSn(customerSn);
|
|
|
-
|
|
|
- javax.swing.SwingUtilities.invokeLater(() -> {
|
|
|
- if (steelSn != null && !steelSn.isEmpty()) {
|
|
|
- queriedData[0] = customerSn;
|
|
|
- queriedData[1] = steelSn;
|
|
|
- resultLabel.setText("查询成功!钢印码: " + steelSn);
|
|
|
- resultLabel.setForeground(new Color(0, 150, 0));
|
|
|
- previewBtn.setEnabled(true);
|
|
|
- printBtn.setEnabled(true);
|
|
|
- } else {
|
|
|
- resultLabel.setText("未找到该客户码对应的钢印码");
|
|
|
- resultLabel.setForeground(Color.RED);
|
|
|
- }
|
|
|
- queryBtn.setEnabled(true);
|
|
|
- });
|
|
|
- } catch (Exception ex) {
|
|
|
- javax.swing.SwingUtilities.invokeLater(() -> {
|
|
|
- resultLabel.setText("查询失败: " + ex.getMessage());
|
|
|
- resultLabel.setForeground(Color.RED);
|
|
|
- queryBtn.setEnabled(true);
|
|
|
- });
|
|
|
- }
|
|
|
- }).start();
|
|
|
- });
|
|
|
-
|
|
|
- // 预览按钮逻辑
|
|
|
- previewBtn.addActionListener(e -> {
|
|
|
- if (queriedData[0] == null || queriedData[1] == null) {
|
|
|
- JOptionPane.showMessageDialog(dialog, "请先查询钢印码", "提示", JOptionPane.WARNING_MESSAGE);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- previewBtn.setEnabled(false);
|
|
|
- resultLabel.setText("正在生成预览 PDF...");
|
|
|
- resultLabel.setForeground(Color.BLUE);
|
|
|
-
|
|
|
- new Thread(() -> {
|
|
|
- try {
|
|
|
- com.mes.print.model.FlowCardData previewData = new com.mes.print.model.FlowCardData();
|
|
|
- previewData.setSn(queriedData[0]);
|
|
|
- previewData.setSteelSn(queriedData[1]);
|
|
|
- com.mes.print.Printer.previewFlowCard(previewData);
|
|
|
-
|
|
|
- javax.swing.SwingUtilities.invokeLater(() -> {
|
|
|
- resultLabel.setText("预览已打开(PDF 文件已用默认程序打开)");
|
|
|
- resultLabel.setForeground(new Color(0, 150, 0));
|
|
|
- previewBtn.setEnabled(true);
|
|
|
- });
|
|
|
- } catch (Exception ex) {
|
|
|
- javax.swing.SwingUtilities.invokeLater(() -> {
|
|
|
- resultLabel.setText("预览失败: " + ex.getMessage());
|
|
|
- resultLabel.setForeground(Color.RED);
|
|
|
- previewBtn.setEnabled(true);
|
|
|
- ex.printStackTrace();
|
|
|
- });
|
|
|
- }
|
|
|
- }).start();
|
|
|
- });
|
|
|
-
|
|
|
- // 打印按钮逻辑
|
|
|
- printBtn.addActionListener(e -> {
|
|
|
- if (queriedData[0] == null || queriedData[1] == null) {
|
|
|
- JOptionPane.showMessageDialog(dialog, "请先查询钢印码", "提示", JOptionPane.WARNING_MESSAGE);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- printBtn.setEnabled(false);
|
|
|
- resultLabel.setText("正在打印...");
|
|
|
- resultLabel.setForeground(Color.BLUE);
|
|
|
-
|
|
|
- new Thread(() -> {
|
|
|
- boolean success = com.mes.print.PrintHelper.printFlowCard(queriedData[0], queriedData[1]);
|
|
|
- javax.swing.SwingUtilities.invokeLater(() -> {
|
|
|
- if (success) {
|
|
|
- resultLabel.setText("打印成功!");
|
|
|
- resultLabel.setForeground(new Color(0, 150, 0));
|
|
|
- } else {
|
|
|
- resultLabel.setText("打印失败,请检查打印机");
|
|
|
- resultLabel.setForeground(Color.RED);
|
|
|
- }
|
|
|
- printBtn.setEnabled(true);
|
|
|
- });
|
|
|
- }).start();
|
|
|
- });
|
|
|
-
|
|
|
- buttonPanel.add(queryBtn);
|
|
|
- buttonPanel.add(previewBtn);
|
|
|
- buttonPanel.add(printBtn);
|
|
|
- buttonPanel.add(closeBtn);
|
|
|
- panel.add(buttonPanel);
|
|
|
-
|
|
|
- dialog.add(panel);
|
|
|
- dialog.setVisible(true);
|
|
|
- }
|
|
|
}
|