|
|
@@ -681,6 +681,19 @@ public class MesClient extends JFrame {
|
|
|
});
|
|
|
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);
|
|
|
@@ -1497,4 +1510,173 @@ 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(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);
|
|
|
+ }
|
|
|
}
|