package co.dc.aptiv;

import co.dc.aptiv.pojo.BillDetailPojo;
import co.dc.aptiv.pojo.BillPojo;
import co.dc.aptiv.pojo.MaterielPojo;
import co.dc.aptiv.pojo.UserPojo;
import co.dc.aptiv.utils.ResetJButton;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.swing.*;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.plaf.FontUIResource;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.*;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.regex.Pattern;

/**
 * @describe: 开始打印窗口
 * @author: liuxinglong
 * @version: 2018/4/17 15:21
 */
public class ScanFrame extends JFrame {

    private static final int SINGLE_SELECTION = 0;
    private Pattern pattern = Pattern.compile("[0-9]*");
    private static final Log log = LogFactory.getLog(ScanFrame.class);
    private JPanel contentPane;
    private UserPojo userPojo = new UserPojo();
    LoadingGlassPane glassPane = new LoadingGlassPane();
    /**
     * 物料选择框
     */
    public JComboBox comboBox_1;
    /**
     * 开始-停止-继续按钮
     */
    private ResetJButton buttonteam;
    /**
     * 联机模式按钮
     */
    private ResetJButton onlineButton;
    /**
     * 检测重码
     */
    private ResetJButton testCoincidentCode;
    /**
     * 按钮状态 0 关 1开
     */
    public int frameType = 0;
    /**
     * 打印信息
     */
    private ResetJButton buttonA;
    /**
     * label-当前打印
     */
    private JLabel labelnowf;
    private JPanel jPanelA;
    private Vector CellsVector_1 = new Vector();
    private Vector TitleVector_1 = new Vector();
    private JTable jt_1;
    private JScrollPane jsp_1;

    private JPanel panel_style;
    private JLabel label_content1;
    private JLabel label_content2;
    private JLabel label_content3;
    public JLabel label_scan1;
    public JLabel label_scan2;
    public JLabel label_scan3;
    private JLabel label_3;
    private JLabel label_4;
    private Timer timer1;
    private Timer timer2;
    /**
     * Create the frame.
     */


    /**
     * 物料pojo
     */
    private List<MaterielPojo> materielPojos = null;
    private MaterielPojo nowMaterielPojo2 = null;
    /**
     * 当前发送过去打印的有待验证的数据
     */
    public BillDetailPojo billDetailPojo = null;
    /**
     * 联机状态
     */
    public boolean onLine;

    public ScanFrame() {
        // 获取当前登录的用户信息
        userPojo = AptivApp.session;
        AptivApp.qrcodeService.setScanFrame(this);
        AptivApp.billService.setScanFrame(this);
        AptivApp.billDetailService.setScanFrame(this);
        AptivApp.printMina.setScanFrame(this);
        AptivApp.collectorMina.setScanFrame(this);
        AptivApp.plcMina.setScanFrame(this);
        glassPane.installAsGlassPane(this);
        setResizable(false);
        setUndecorated(true);
        setTitle("德尔福激光工控V1.2");
        setAlwaysOnTop(!isAlwaysOnTop());
        onLine = AptivApp.configuration.getBoolean("onlineStatus");
        /*
         * 统一所有子窗口设置字体样式
         */
        FontUIResource fontRes = new FontUIResource(new Font("微软雅黑", Font.PLAIN, 16));
        for (Enumeration<Object> keys = UIManager.getDefaults().keys(); keys.hasMoreElements(); ) {
            Object key = keys.nextElement();
            Object value = UIManager.get(key);
            if (value instanceof FontUIResource) {
                UIManager.put(key, fontRes);
            }
        }

        setBounds(100, 100, 1024, 768);
        setLocationRelativeTo(null);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        contentPane.setBackground(Color.white);
        setContentPane(contentPane);
        contentPane.setLayout(null);
        //head
        JPanel psnel1 = new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                Image image = new ImageIcon(MainFrame.class.getResource("/co/dc/aptiv/img/head.png")).getImage();
                g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);
            }
        };
        psnel1.setBounds(0, 0, 1024, 78);
        contentPane.add(psnel1);
        psnel1.setLayout(null);
        //返回按钮
        JButton btnNew_Button = new ResetJButton("/co/dc/aptiv/img/return-normal.png", "/co/dc/aptiv/img/return-hover.png", "/co/dc/aptiv/img/return-hover.png");
        btnNew_Button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                if (AptivApp.flag) {
                    JOptionPane.showMessageDialog(ScanFrame.this, "打印中，禁止返回。", "提示", JOptionPane.ERROR_MESSAGE);
                } else {
                    if (onLine) {
                        //发送独立指令给测试机
                        /*sendPLCCommand("D");*/
                    }
                    new MainFrame().setVisible(true);
                    ScanFrame.this.dispose();
                }
            }
        });
        btnNew_Button.setBounds(894, 0, 130, 53);
        psnel1.add(btnNew_Button);

        //激光机
        JLabel labelPdesc = new JLabel("激光机：");
        labelPdesc.setBounds(60, 125, 80, 15);
        contentPane.add(labelPdesc);

        label_scan1 = new JLabel();
        //设置指示灯状态
        changeLight(label_scan1, true);
        label_scan1.setBounds(130, 122, 25, 25);
        contentPane.add(label_scan1);

        //采集器
        JLabel labelPcode = new JLabel("采集器：");
        labelPcode.setBounds(230, 125, 80, 15);
        contentPane.add(labelPcode);

        label_scan2 = new JLabel();
        //设置指示灯状态
        changeLight(label_scan2, true);
        label_scan2.setBounds(300, 120, 25, 25);
        contentPane.add(label_scan2);

        //联机模式
        final JLabel online = new JLabel("联机模式：");
        online.setBounds(400, 125, 80, 15);
        contentPane.add(online);

        label_scan3 = new JLabel();
        //设置指示灯状态
        changeLight(label_scan3, false);
        label_scan3.setBounds(485, 120, 25, 25);
        contentPane.add(label_scan3);

        //物料
        JLabel label_1 = new JLabel("物   料：");
        label_1.setBounds(60, 200, 80, 15);
        contentPane.add(label_1);
        comboBox_1 = new JComboBox();
        comboBox_1.setBackground(Color.white);
        //物料下拉框初始化
        comboBox_1.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    int index = comboBox_1.getSelectedIndex();
                    if (index > 0) {
                        comboBox_1.setBackground(Color.white);
                        index--;
                        AptivApp.nowMaterielPojo = materielPojos.get(index);
                        log.info("选择物料：" + AptivApp.nowMaterielPojo.toString());
                    } else {
                        AptivApp.nowMaterielPojo = null;
                    }
                }
            }
        });
        comboBox_1.setBounds(140, 185, 250, 45);
        contentPane.add(comboBox_1);


        //打印按钮
        buttonteam = new ResetJButton("/co/dc/aptiv/img/start-btn-on.png", "/co/dc/aptiv/img/start-btn-hover.png", "/co/dc/aptiv/img/start-btn-hover.png");
        buttonteam.setBounds(830, 170, 124, 45);
        contentPane.add(buttonteam);
        //打印按钮点击事件
        buttonteam.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                //判断按钮开关状态
                if (!AptivApp.flag) {
                    //开始打印
                    startPrint();
                } else {
                    //停止打印
                    stopPrint();
                }
            }
        });

        //判断是否管理员权限
        if (userPojo.getRoleid() == 1) {
            //联机模式按钮
            onlineButton = new ResetJButton("/co/dc/aptiv/img/onlineMode.png", "/co/dc/aptiv/img/onlineMode-h.png", "/co/dc/aptiv/img/onlineMode-h.png");
            onlineButton.setBounds(830, 110, 124, 45);
            contentPane.add(onlineButton);
            //联机模式按钮点击事件
            onlineButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg0) {
                    //判断当前是否在打印状态
                    if (!AptivApp.flag) {
                        //当前联机状态
                        if (onLine) {
                            //发送独立指令给测试机
                            sendPLCCommand("D");
                        } else {
                            //发送联机指令给测试机
                            sendPLCCommand("L");
                        }
                    } else {
                        JOptionPane.showMessageDialog(ScanFrame.this, "打印期间不能变更联机模式。", "提示", JOptionPane.WARNING_MESSAGE);
                    }
                }
            });

            //重码检测按钮
            testCoincidentCode = new ResetJButton("/co/dc/aptiv/img/check.png", "/co/dc/aptiv/img/check-h.png", "/co/dc/aptiv/img/check-h.png");
            testCoincidentCode.setBounds(830, 230, 124, 45);
            contentPane.add(testCoincidentCode);
            //测试重码按钮点击事件
            testCoincidentCode.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg0) {
                    //判断按钮开关状态,只有停止打印了以后才能测试重码
                    if (!AptivApp.flag) {
                        AptivApp.collectorMina.sendByte(AptivApp.ccu.String2ASCII("S"));
                    } else {
                        JOptionPane.showMessageDialog(ScanFrame.this, "生产中，不能进行测试操作", "提示", JOptionPane.WARNING_MESSAGE);
                    }
                }
            });
        }


        //阴影
        JPanel panel_head = new JPanel() {
            private static final long serialVersionUID = 6853836362990936203L;

            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                Image image = new ImageIcon(getClass().getResource("img/headbottom-gb.png")).getImage();
                g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);
            }
        };
        panel_head.setBounds(0, 273, 1024, 89);
        panel_head.setLayout(null);
        contentPane.add(panel_head);

        //操作人员显示
        JLabel label = new JLabel(userPojo.getRolename() + ": " + userPojo.getLoginname());
        label.setForeground(Color.black);
        label.setFont(new Font("微软雅黑", Font.PLAIN, 16));
        label.setBounds(800, 50, 200, 34);
        panel_head.add(label);

        //加载两个tabs按钮
        buttonA = new ResetJButton("/co/dc/aptiv/img/01tab-btn-normal.png", "/co/dc/aptiv/img/01tab-btn-on.png", "/co/dc/aptiv/img/01tab-btn-on.png");
        buttonA.setBounds(60, 45, 142, 48);
        buttonA.settype();
        panel_head.add(buttonA);

        //buttonA点击事件--打印信息
        buttonA.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                if (!jPanelA.isVisible()) {
                    buttonA.settype();
                    jPanelA.setVisible(true);
                }
            }
        });

        /*
         * 		Atab的面板+面板内容
         */
        jPanelA = new JPanel();
        jPanelA.setVisible(true);
        jPanelA.setBackground(Color.white);
        jPanelA.setBounds(0, 362, 1024, 406);
        jPanelA.setLayout(null);
        contentPane.add(jPanelA);

        JLabel labellist = new JLabel("打印列表");
        labellist.setBounds(60, 20, 100, 15);
        jPanelA.add(labellist);

        this.TitleVector_1.add("序号");
        this.TitleVector_1.add("二维码");
        this.TitleVector_1.add("状态");
        jt_1 = new JTable(CellsVector_1, TitleVector_1) {
            @Override
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };
        jt_1.getColumnModel().getColumn(0).setPreferredWidth(20);
        jt_1.getColumnModel().getColumn(1).setPreferredWidth(100);
        jt_1.getColumnModel().getColumn(2).setPreferredWidth(40);

        jt_1.setSurrendersFocusOnKeystroke(true);
        //单选
        jt_1.setSelectionMode(SINGLE_SELECTION);
        //充满
//        jt_1.setFillsViewportHeight(true);
        //行的高度
        jt_1.setRowHeight(30);
        //得到表头
        JTableHeader header = jt_1.getTableHeader();
        //设置表头的高度
        header.setPreferredSize(new Dimension(header.getWidth(), 30));
        DefaultTableCellRenderer hr = (DefaultTableCellRenderer) header.getDefaultRenderer();
        //表头内容居左
        hr.setHorizontalAlignment(DefaultTableCellRenderer.LEFT);
        jsp_1 = new JScrollPane(jt_1, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        jsp_1.setViewportBorder(new CompoundBorder());
        jsp_1.setBounds(60, 45, 450, 270);
        jPanelA.add(jsp_1);

        //准备打印
        JLabel labelnow = new JLabel("准备打印");
        labelnow.setBounds(650, 20, 100, 15);
        jPanelA.add(labelnow);
        labelnowf = new JLabel();
        loadCode();
        labelnowf.setBounds(650, 45, 300, 100);
        labelnowf.setBorder(BorderFactory.createEtchedBorder());
        jPanelA.add(labelnowf);

        //任务统计
        JLabel labelnowalert = new JLabel("任务统计");
        labelnowalert.setBounds(650, 180, 100, 15);
        jPanelA.add(labelnowalert);

        //效果图用背景图片写入，文字浮动打在图片上
        panel_style = new JPanel() {
            private static final long serialVersionUID = 6853836362990936203L;

            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
            }
        };
        panel_style.setBounds(650, 205, 300, 110);
        panel_style.setLayout(null);
        panel_style.setBorder(BorderFactory.createEtchedBorder());
        label_content1 = new JLabel();
        label_content2 = new JLabel();
        label_content3 = new JLabel();
        loadDate(0, 0, 0);
        label_content1.setBounds(10, 15, 200, 20);
        label_content2.setBounds(10, 45, 200, 20);
        label_content3.setBounds(10, 75, 200, 20);
        panel_style.add(label_content1);
        panel_style.add(label_content2);
        panel_style.add(label_content3);
        jPanelA.add(panel_style);

        //线
        JLabel line = new JLabel("—————————————————————————————————————————————————————");
        line.setBounds(60, 335, 1024, 15);
        jPanelA.add(line);

        //今日任务统计
        label_3 = new JLabel();
        todayCount();
        label_3.setBounds(60, 320, 450, 100);
        jPanelA.add(label_3);

        //警告
        label_4 = new JLabel();
        warning("运行正常", 0);
        label_4.setBounds(650, 320, 300, 100);
        jPanelA.add(label_4);


        //初始化界面
        viewChange();
    }


    /**
     * 初始化界面
     */
    public void viewChange() {
        //加载物料
        materielPojos = AptivApp.materielService.listAll();
        if (materielPojos != null && materielPojos.size() > 0) {
            comboBox_1.removeAllItems();
            comboBox_1.addItem("点击选择物料。");
            for (int i = 0; i < materielPojos.size(); i++) {
                comboBox_1.addItem(materielPojos.get(i).getDpn());
            }
        } else {
            this.comboBox_1.addItem("请到【物料管理】界面创建物料。");
            comboBox_1.setBackground(Color.red);
        }

        //每隔5秒检测一次激光机、采集器连接状态
        timer1 = new Timer(1000 * 5, new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                if (!AptivApp.printMina.isConnect() || !AptivApp.collectorMina.isConnect()) {
                    changeLight(label_scan1, AptivApp.printMina.isConnect());
                    changeLight(label_scan2, AptivApp.collectorMina.isConnect());
                    warning("激光机或采集器连接断开，请停止打印并检查！", 1);
                } else if (onLine && !AptivApp.testMachineCollectorMina.isConnect()) {
                    changeLight(label_scan3, AptivApp.testMachineCollectorMina.isConnect());
                    warning("测试机连接断开，请检查测试机状态！", 1);
                } else {
                    changeLight(label_scan1, AptivApp.printMina.isConnect());
                    changeLight(label_scan2, AptivApp.collectorMina.isConnect());
                    changeLight(label_scan3, onLine);
                    warning("运行正常", 0);
                }
            }
        });
        timer1.start();

        //每隔1分钟统计一次状态
        timer2 = new Timer(1000 * 60, new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                todayCount();
            }
        });
        timer2.start();

        if (onLine) {
            //发送指令给测试机
            /* sendPLCCommand("L");*/
            AptivApp.testMachineCollectorMina.startConnection();
            //设置指示灯状态
            changeLight(label_scan3, onLine);
            comboBox_1.setEnabled(!onLine);
            comboBox_1.setSelectedIndex(0);
            comboBox_1.updateUI();
        }

    }

    /**
     * 开始打印
     */
    private void startPrint() {
        if (!onLine && AptivApp.nowMaterielPojo == null) {
            JOptionPane.showMessageDialog(ScanFrame.this, "请选择需要查询的物料。", "提示", JOptionPane.WARNING_MESSAGE);
        } else {
            log.info("开始打印");
            comboBox_1.setEnabled(false);
            AptivApp.flag = true;
            //发送开始指令给PLC
            sendPLCCommand("S");
            //设置按钮
            setButton(AptivApp.flag);
            //创建订单
            AptivApp.billPojo = AptivApp.billService.addBill(AptivApp.nowMaterielPojo == null || onLine == true ? 0 : AptivApp.nowMaterielPojo.getId());
            //判断当前模式,非联机模式则自动发码
            if (!onLine) {
                int codeFlag = AptivApp.qrcodeService.sendQrCode();
                if (codeFlag != 1) {
                    log.info("发送码给激光机异常");
                    alertMsg(1, "生产码异常，请停止打印并联系管理员！");
                }
            }
        }
    }

    /**
     * 结束打印
     */
    public void stopPrint() {
        int val = JOptionPane.showConfirmDialog(ScanFrame.this, "确定结束打印吗？", "提示", 2);
        if (val == JOptionPane.YES_OPTION) {
            //清空激光机的数据
            AptivApp.qrcodeService.resetLaserMachine();
            AptivApp.flag = false;
            //发送停止指令给PLC
            sendPLCCommand("E");
//            AptivApp.printStatus = true;
//            AptivApp.scanStatus = false;
            AptivApp.billPojo = null;
            this.CellsVector_1.clear();
            this.jt_1.updateUI();
            AptivApp.qrCode = null;
            loadCode();
            loadDate(0, 0, 0);
            //设置按钮
            setButton(AptivApp.flag);
            if (!onLine) {
                comboBox_1.setEnabled(true);
            }
            log.info("结束打印");
        }
    }


    /**
     * 当前打印并采集统计表格
     */
    public void loadjtable1(BillDetailPojo bd) {
        Vector v = new Vector();
        v.add(bd.getId());
        v.add(bd.getQrCode());
        v.add(bd.getState() == 0 ? "不合格" : "合格");
        this.CellsVector_1.insertElementAt(v, 0);
        this.jt_1.updateUI();
        this.jt_1.clearSelection();
    }

    /**
     * 判断是否为数字
     *
     * @param str
     * @return
     */
    public boolean isNumber(String str) {
        return pattern.matcher(str).matches();
    }


    /**
     * 设置指示灯状态
     *
     * @param status 1-绿灯  2-红灯
     */
    JLabel preJLabel = new JLabel();

    public void changeLight(JComponent component, boolean status) {
        preJLabel = (JLabel) component;
        //绿灯
        if (status) {
            preJLabel.setIcon(new ImageIcon(ScanFrame.class.getResource("img/green.png")));
        } else {//红灯
            preJLabel.setIcon(new ImageIcon(ScanFrame.class.getResource("img/red.png")));
        }
    }

    /**
     * 当前打印的码
     */
    public void loadCode() {
        labelnowf.setText("<html>&nbsp;&nbsp;&nbsp;" + (AptivApp.qrCode == null ? "  未开始" : AptivApp.qrCode) + "</html>");
    }

    /**
     * 当前任务统计
     *
     * @param number
     * @param qualifiedNum
     * @param unqualifiedNum
     */
    public void loadDate(int number, int qualifiedNum, int unqualifiedNum) {
        label_content1.setText("<html>&nbsp;&nbsp;打印总数：" + number + "</html>");
        label_content2.setText("<html>&nbsp;&nbsp;合&nbsp;&nbsp;格&nbsp;数：" + qualifiedNum + "</html>");
        label_content3.setText("<html>&nbsp;&nbsp;不合格数：" + unqualifiedNum + "</html>");
    }

    /**
     * 今日任务统计
     */
    public void todayCount() {
        Map<String, Object> map = AptivApp.qrcodeService.countDayData();
        label_3.setText("<html> 今日任务统计：总数&nbsp;&nbsp;" + (map.get("SUM(number)") == null ? 0 : map.get("SUM(number)")) + "&nbsp;&nbsp;&nbsp;&nbsp;合格&nbsp;&nbsp;" + (map.get("sum(qualifiedNum)") == null ? 0 : map.get("sum(qualifiedNum)")) + "&nbsp;&nbsp;&nbsp;&nbsp;不合格&nbsp;&nbsp;" + (map.get("sum(UnqualifiedNum)") == null ? 0 : map.get("sum(UnqualifiedNum)")) + "</html>");
    }

    /**
     * 警告信息
     *
     * @param msg
     * @param type
     */
    public void warning(String msg, int type) {
        log.info("程序警告信息:警告类型=" + type + ",警告信息=" + msg);
        label_4.setIcon(new ImageIcon(ScanFrame.class.getResource(type == 0 ? "img/warn-yellow.png" : "img/warn-red.png")));
        label_4.setText("<html>&nbsp;" + msg + "</html>");
    }

    /**
     * 设置按钮
     *
     * @param type
     */
    private void setButton(boolean type) {
        buttonteam.setnormal(type ? "/co/dc/aptiv/img/stop-btn-one.png" : "/co/dc/aptiv/img/start-btn-on.png");
        buttonteam.setenter(type ? "/co/dc/aptiv/img/stop-btn-one-h.png" : "/co/dc/aptiv/img/start-btn-hover.png");
        buttonteam.setpress(type ? "/co/dc/aptiv/img/stop-btn-one-h.png" : "/co/dc/aptiv/img/start-btn-hover.png");
    }

    /**
     * 弹出提示信息
     *
     * @param type 0 提示 1 警告
     * @param msg  信息
     */
    public void alertMsg(int type, String msg) {
        log.info("程序提示信息:提示类型=" + type + ",提示信息=" + msg);
        JOptionPane.showMessageDialog(ScanFrame.this, msg, type == 0 ? "提示" : "警告", JOptionPane.WARNING_MESSAGE);
    }

    private void createNewScanFrame() {
        new ScanFrame().setVisible(true);
        this.dispose();
    }

    /**
     * 联机模式时用于显示当前测试机传过来的物料号
     */
    public void setComboBox_1() {
        comboBox_1.setSelectedItem(AptivApp.nowMaterielPojo.getDpn());
        comboBox_1.updateUI();
    }


    /**
     * 保存修改后的配置文件
     */
    public void saveOlineStatus() {
        try {
            OutputStream os = new FileOutputStream(new File(System.getProperty("exe.path")));
            AptivApp.configuration.save(os);
            os.close();
            log.info("保存修改后的配置文件");
        } catch (ConfigurationException e) {
            log.error("配置文件保存异常" + e);
            e.printStackTrace();
        } catch (IOException e) {
            log.error("保存配置文件IO异常" + e);
            e.printStackTrace();
        }
    }

    /**
     * 发送指令给测试机
     *
     * @param command
     */
    private void sendPLCCommand(String command) {
        int status = AptivApp.plcMina.sendByte(AptivApp.ccu.String2ASCII(command));
        log.info("发送指令给PLC,指令= " + command);
        if (status != 1) {
            JOptionPane.showMessageDialog(ScanFrame.this, status > 0 ? "测试机" + command + "指令发送超时" : "测试机" + command + "指令发送异常", "提示", JOptionPane.WARNING_MESSAGE);
        }
    }
}
