package com.mes.ui; import com.alibaba.fastjson2.JSONObject; import com.mes.component.MesRadio; import com.mes.component.MesWebView; import com.mes.netty.NettyClient; import com.mes.util.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.print.PrintService; import javax.print.PrintServiceLookup; import javax.swing.*; import javax.swing.border.EmptyBorder; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; import java.awt.*; import java.awt.event.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.time.LocalDateTime; import java.util.*; import java.util.List; import java.util.Timer; public class MesClient extends JFrame { public static final Logger log = LoggerFactory.getLogger(MesClient.class); private static String Drivde = "org.sqlite.JDBC"; public static int mes_auth = 0; // 权限级别 0=无权限 1=操作工人 2=管理员 public static String mes_gw = ""; // 工位号 public static String mes_gw_des = ""; // 工位名称 public static String mes_server_ip = ""; // 服务器IP地址 public static int mes_tcp_port = 3000; // TCP服务端口 public static int mes_heart_beat_cycle = 10; // 心跳周期 public static int mes_heart_icon_cycle = 1; public static String mes_line_sn = ""; // 产线编号 //TCP连接 public static NettyClient nettyClient; //TCP连接状态 public static boolean tcp_connect_flag = false; //TCP连接请求 public static boolean connect_request_flag = false; //session public static String sessionid = ""; public static JPanel contentPane; public static MesClient mesClientFrame; public static JTabbedPane tabbedPane; public static JScrollPane indexScrollPaneA; public static JScrollPane searchScrollPane; public static JScrollPane searchScrollPaneD; public static JScrollPane searchScrollPaneDj; public static JScrollPane searchScrollPaneTask; public static Boolean check_quality_result = false; public static Integer work_status = 0; public static JButton heart_beat_menu; public static JButton status_menu; public static JButton user_menu; public static int scan_type = 0; public static JButton finish_ok_bt; public static JButton finish_ng_bt; public static JTextField product_sn; public static JButton f_scan_data_bt_1; public static String user20 = ""; public static boolean mes_enable = true; // true=MES开启 public static JFrame welcomeWin; public static JPanel indexPanelB; public static MesWebView jfxPanel = null; public static JPanel indexPanelC; public static JPanel indexPanelD; public static MesWebView jfxPanel2 = null; public static MesWebView jfxPanel3 = null; public static MesRadio mesRadioHj; public static JLabel curTaskName; public static JTable table; public static Object[] columnNames = {"工件码", "测试日期", "压力", "泄露值","结果"}; // public static Object[][] rowData = null; // public static Object[][] rowData = { // {"151245P00001213100100024120700111","2024-12-09 12:30:30","60","60","60","200kPa","3ml/min","OK"}, // {"151245P00001213100100024120700112","2024-12-09 13:30:30","60","60","60","-200kPa","3ml/min","OK"}, // {"151245P00001213100100024120700113","2024-12-09 14:30:30","60","60","60","200kPa","3ml/min","OK"}, // {"151245P00001213100100024120700113","2024-12-09 14:30:30","60","60","60","200kPa","3ml/min","OK"}, // }; public static Object[][] rowData = new Object[12][5]; public static JLabel pageLabel; public static int pageNo=1 ; // 当前页 public static int totalPages; // 总页数 public static JTextField textField;//搜索框 public static JTable okngTable; public static Object[] okngColumnNames = {"样件", "工件码", "测试日期", "压力", "泄露值", "结果"}; public static Object[][] okngRowData = new Object[12][6]; public static JLabel okngPageLabel; public static int okngPageNo = 1; public static int okngTotalPages; public static JTextField okngTextField; private static final List okngSampleSns = new ArrayList<>(); private static final Map okngSampleType = new HashMap<>(); public static JTable table2; public static Object[] columnNames2 = { "任务名称" }; public static Object[][] rowData2 = {{""},{""},{""}}; public static Integer tjFlag = 0; public static String tjFlagText2 = "设备运行中"; public static String tjFlagText3 = "设备运行结束"; public static String tjFlagText4 = "结果已上传MES,请扫下一件"; public static String tjFlagText5 = "已扫码,等待设备运行"; public static String tjFlagTextErr = "结果上传MES失败,请重试"; public static SerialPortUtils serialPortUtils; public static JTextField printSn2; public static JTextField printTitle2; public static JTextField printValue2; public static JButton printBtn2; public static ConfigParam configParam; public static Integer isConfigEdit = 0; public static Integer mesStartFlag = 0; public static List taskParamList = new ArrayList<>(); public static TaskParam curTaskParam = null; public static TCPClient tcpClient1 = new TCPClient("192.168.18.182",9004); public static int scanFlag1 = 0; public static void main(String[] args) { if (LockUtil.getInstance().isAppActive() == true){ // JOptionPane.showMessageDialog(null, "已有一个程序在运行,程序退出"); return; } EventQueue.invokeLater(new Runnable() { @Override public void run() { try{ //读文件配置 readProperty(); // 显示界面 mesClientFrame = new MesClient(); mesClientFrame.setVisible(false); JdbcUtils.getConn(); welcomeWin = new LoginFarme(); welcomeWin.setVisible(true); formatConfigEdit(false); formatConfigData(); getTask(); serialPortUtils=new SerialPortUtils(configParam.getSerialPort(),configParam.getOprno(),configParam.getOprnoTitle(),configParam.getDevice()); // startDateTimer(); textFocus(); // resetScanA(); }catch (Exception e){ log.error(e.getMessage()); } } }); } public static Timer cjTimerText; public static void textFocus() { if(cjTimerText!=null) { cjTimerText.cancel(); } cjTimerText = new Timer(); cjTimerText.schedule(new TimerTask() { public void run() { if(work_status == 0){ product_sn.requestFocusInWindow(); } } }, 1000,1000); } public static java.util.Timer dateBeatTimer; public static void startDateTimer() { if (dateBeatTimer != null) { dateBeatTimer.cancel(); } dateBeatTimer = new java.util.Timer(); dateBeatTimer.schedule(new TimerTask() { public void run() { if (iconREDFlag) { heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png"))); iconREDFlag = false; } else { heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png"))); iconREDFlag = true; } heart_beat_menu.setText(DateLocalUtils.getCurrentTime()); heart_beat_menu.setForeground(Color.GREEN); heart_beat_menu.repaint(); } }, 100, 1* 1000); } //读配置文件 private static void readProperty() throws IOException{ String enconding = "UTF-8"; InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties"); Properties pro = new Properties(); BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding)); pro.load(br); mes_gw = pro.getProperty("mes.gw"); // mes_gw_des = pro.getProperty("mes.gw_des"); mes_server_ip = pro.getProperty("mes.server_ip"); mes_tcp_port = Integer.parseInt(pro.getProperty("mes.tcp_port")); mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle")); mes_line_sn = pro.getProperty("mes.line_sn"); mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw); log.info(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle); } // 初始化TCP public static void initTcpConnection() { try { if(nettyClient==null) { //初始化TCP连接 nettyClient = new NettyClient(); //TCP连接状态 tcp_connect_flag = false; //设置TCP请求状态 connect_request_flag = true; DataUtil.synrTcp(nettyClient,mes_gw); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } //启动心跳包程序 public static java.util.Timer heartBeatTimer; public static java.util.Timer heartBeatIconTimer; public static boolean iconREDFlag = true; public static void startHeartBeatTimer() { if(heartBeatTimer!=null) { heartBeatTimer.cancel(); } heartBeatTimer = new java.util.Timer(); heartBeatTimer.schedule(new TimerTask() { public void run() { if(nettyClient!=null&&tcp_connect_flag) { //log.info("发送心跳报文"); DataUtil.heartBeat(nettyClient,mes_gw); heart_beat_menu.setText(DateLocalUtils.getCurrentTime()); } } }, 100,mes_heart_beat_cycle*1000); //心跳显示图标 if(heartBeatIconTimer!=null) { heartBeatIconTimer.cancel(); } heartBeatIconTimer = new Timer(); heartBeatIconTimer.schedule(new TimerTask() { public void run() { if(tcp_connect_flag) { if(iconREDFlag) { heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png"))); iconREDFlag = false; }else { heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png"))); iconREDFlag = true; } heart_beat_menu.setText(DateLocalUtils.getCurrentTime()); heart_beat_menu.repaint(); }else { heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png"))); heart_beat_menu.setText(DateLocalUtils.getCurrentTime()); heart_beat_menu.repaint(); //若未连接则尝试连接 if(nettyClient!=null&&!tcp_connect_flag){ log.info("TCP已断开"); //TCP重新同步连接 if(!connect_request_flag) { //log.info("TCP重新同步连接"); //设置TCP请求状态,只重新同步连接一次 connect_request_flag = true; DataUtil.synrTcp(nettyClient,mes_gw); } } } } }, 100,mes_heart_icon_cycle*1000); } //设置tcp连接状态显示 public static void setTcpStatus() { if(tcp_connect_flag) { heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png"))); heart_beat_menu.repaint(); }else { heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png"))); heart_beat_menu.repaint(); } } public static void initWarehouseData(){ resetScanA(); } public static void resetScanA() { work_status = 0; check_quality_result = false; MesClient.finish_ok_bt.setEnabled(false); MesClient.finish_ng_bt.setEnabled(false); product_sn.setText(""); product_sn.setEditable(true); tjFlag = 0; mesStartFlag = 0; curTaskName.setText(""); // f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png"))); // f_scan_data_bt_1.setText("扫码"); // MesClient.f_scan_data_bt_1.setEnabled(true); MesClient.setMenuStatus("请扫工件码",0); // MesClient.result.setText("等待结果"); // MesClient.result.setForeground(Color.GRAY); } public static int userLoginHours;//用户登录所处小时 public static JTextField param1; public static JTextField param2; public static JTextField param3; public static JTextField param4; public static JLabel result; public static JTextField programNo; public static JTextField serialPort; public static JTextField baudRate; public static JTextField printName; public static JTextField labelName; public static JTextField labelx; public static JTextField labely; public static JTextField labelLineSpace; public static JTextField labelFont; public static JTextField stationNo; public static JComboBox stopBit; public static JComboBox checkBit; public static JComboBox dataBits; public static JComboBox printLabel; public static JComboBox leakage; public static JComboBox startMode; public static JButton saveBtn; public static JTextField productSnLength; public static JTextField productSnPre; public static JComboBox device; public static JTextField ngTime; public static JTextField ngNumber; public static JTextField ngUpgradeTime; public static JTextField oprno; public static JTextField oprnoTitle; public static JTextField lineSn; public static JLabel taskName; public static JTextField taskMaxNumA; public static JTextField taskMaxFoutA; public static JTextField taskMinFoutA; public static JTextField taskMaxSoutA; public static JTextField taskMinSoutA; public static JTextField taskMaxNumB; public static JTextField taskMaxFoutB; public static JTextField taskMinFoutB; public static JTextField taskMaxSoutB; public static JTextField taskMinSoutB; public static JComboBox taskLeakage; public static JTextField barcodeSpec; public static JTextField barcodeSpecStart; public static JTextField barcodeLength; public static void formatConfigEdit(Boolean ret){ programNo.setEnabled(ret); serialPort.setEnabled(ret); startMode.setEnabled(ret); baudRate.setEnabled(ret); printName.setEnabled(ret); labelName.setEnabled(ret); labelx.setEnabled(ret); labely.setEnabled(ret); labelLineSpace.setEnabled(ret); labelFont.setEnabled(ret); stationNo.setEnabled(ret); stopBit.setEnabled(ret); checkBit.setEnabled(ret); dataBits.setEnabled(ret); printLabel.setEnabled(ret); leakage.setEnabled(ret); productSnPre.setEnabled(ret); productSnLength.setEnabled(ret); device.setEnabled(ret); // ngTime.setEnabled(ret); // ngNumber.setEnabled(ret); // ngUpgradeTime.setEnabled(ret); oprno.setEnabled(ret); oprnoTitle.setEnabled(ret); lineSn.setEnabled(ret); } public static void formatConfigData(){ MesClient.configParam = JdbcUtils.getConfig(); log.info(configParam.toString()); if(configParam.getProgramNo() == null||configParam.getProgramNo().isEmpty()){ configParam.setProgramNo("1"); } programNo.setText(configParam.getProgramNo()); if(configParam.getStartMode() == null||configParam.getStartMode().isEmpty()){ configParam.setStartMode("手动启动"); } startMode.setSelectedItem(configParam.getStartMode()); if(configParam.getSerialPort() == null||configParam.getSerialPort().isEmpty()){ configParam.setSerialPort("COM1"); } serialPort.setText(configParam.getSerialPort()); if(configParam.getBaudRate() == null||configParam.getBaudRate().isEmpty()){ configParam.setBaudRate("38400"); } baudRate.setText(configParam.getBaudRate()); if(configParam.getDataBits() == null||configParam.getDataBits().isEmpty()){ configParam.setDataBits("8"); } dataBits.setSelectedItem(configParam.getDataBits()); if(configParam.getCheckBit() == null||configParam.getCheckBit().isEmpty()){ configParam.setCheckBit("NONE"); } checkBit.setSelectedItem(configParam.getCheckBit()); if(configParam.getStopBit() == null||configParam.getStopBit().isEmpty()){ configParam.setStopBit("1"); } stopBit.setSelectedItem(configParam.getStopBit()); if(configParam.getLeakage() == null||configParam.getLeakage().isEmpty()){ configParam.setLeakage("压降"); } leakage.setSelectedItem(configParam.getLeakage()); if(configParam.getPrintLabel() == null||configParam.getPrintLabel().isEmpty()){ configParam.setPrintLabel("否"); } printLabel.setSelectedItem(configParam.getPrintLabel()); if(configParam.getPrintName() == null||configParam.getPrintName().isEmpty()){ configParam.setPrintName(""); } printName.setText(configParam.getPrintName()); if(configParam.getLabelName() == null||configParam.getLabelName().isEmpty()){ configParam.setLabelName(""); } labelName.setText(configParam.getLabelName()); if(configParam.getLabelx() == null||configParam.getLabelx().isEmpty()){ configParam.setLabelx("30"); } labelx.setText(configParam.getLabelx()); if(configParam.getLabely() == null||configParam.getLabely().isEmpty()){ configParam.setLabely("30"); } labely.setText(configParam.getLabely()); if(configParam.getLabelLineSpace() == null||configParam.getLabelLineSpace().isEmpty()){ configParam.setLabelLineSpace("20"); } labelLineSpace.setText(configParam.getLabelLineSpace()); if(configParam.getLabelFont() == null||configParam.getLabelFont().isEmpty()){ configParam.setLabelFont("10"); } labelFont.setText(configParam.getLabelFont()); if(configParam.getStationNo() == null||configParam.getStationNo().isEmpty()){ configParam.setStationNo("1"); } stationNo.setText(configParam.getStationNo()); if(configParam.getProductSnPre() == null||configParam.getProductSnPre().isEmpty()){ configParam.setProductSnPre(""); } productSnPre.setText(configParam.getProductSnPre()); if(configParam.getProductSnLength() == null||configParam.getProductSnLength().isEmpty()){ configParam.setProductSnLength(""); } productSnLength.setText(configParam.getProductSnLength()); if(configParam.getDevice() == null||configParam.getDevice().isEmpty()){ configParam.setDevice("innomatec"); } device.setSelectedItem(configParam.getDevice()); // if(configParam.getNgTime() == null||configParam.getNgTime().isEmpty()){ // configParam.setNgTime(""); // } // ngTime.setText(configParam.getNgTime()); // // if(configParam.getNgNumber() == null||configParam.getNgNumber().isEmpty()){ // configParam.setNgNumber(""); // } // ngNumber.setText(configParam.getNgNumber()); // // if(configParam.getNgUpgradeTime() == null||configParam.getNgUpgradeTime().isEmpty()){ // configParam.setNgUpgradeTime(""); // } // ngUpgradeTime.setText(configParam.getNgUpgradeTime()); if(configParam.getOprno() == null||configParam.getOprno().isEmpty()){ configParam.setOprno(""); } oprno.setText(configParam.getOprno()); if(configParam.getOprnoTitle() == null||configParam.getOprnoTitle().isEmpty()){ configParam.setOprnoTitle(""); } oprnoTitle.setText(configParam.getOprnoTitle()); if(configParam.getLineSn() == null||configParam.getLineSn().isEmpty()){ configParam.setLineSn("XT"); } lineSn.setText(configParam.getLineSn()); if(!oprnoTitle.getText().isEmpty()){ String stationInfo = oprno.getText() +"-"+ oprnoTitle.getText(); welcomeWin.setTitle("气密检测客户端--"+stationInfo); mesClientFrame.setTitle("气密检测客户端--"+stationInfo); } } //换班用户信息检查 private static void shiftUserCheck() { LocalDateTime now = LocalDateTime.now(); // 判断时间范围 if (userLoginHours >= 8 && userLoginHours < 20) { int hour = now.getHour(); if (hour >= 20 || hour < 8) { logoff(); } } else { int hour = now.getHour(); if (hour >= 8 && hour < 20) { logoff(); } } } public static void resetScanB() { } //获取用户20位 public static void getUser() { user20 = user_menu.getText().toString(); String space_tmp1 = ""; if(user20.length()<20) { for(int i=0;i<20-user20.length();i++) { space_tmp1 = space_tmp1 + " "; } } user20 = user20 + space_tmp1; } //获取barcode内容36位 public static String getBarcode(String barcodeTmp) { String barcodeRet = barcodeTmp; if(barcodeTmp.equalsIgnoreCase("")) { return ""; }else { if(barcodeTmp.length()<36) { String space = ""; for(int i=0;i<36-barcodeTmp.length();i++) { space = space + " "; } barcodeRet = barcodeTmp + space; } } return barcodeRet; } public static void scanBarcode() { if (work_status == 1) { MesClient.serialPortUtils.start(); return; } } public static void scanBarcode2() { if(work_status == 1){ // MesClient.serialPortUtils.sendData("START"); return; } // String scanBarcode = product_sn.getText().trim(); String scanBarcode = MesClient.scanQrcode(); //刷新界面 mesClientFrame.repaint(); if(scanBarcode.isEmpty()){ MesClient.setMenuStatus("工件码不能为空",1); product_sn.setText(""); return; } MesClient.product_sn.setText(scanBarcode); // // 验证工件码前缀 // if(MesClient.configParam.getProductSnPre() != null && !MesClient.configParam.getProductSnPre().trim().isEmpty()) { // int preLen = MesClient.configParam.getProductSnPre().trim().length(); // if(preLen > scanBarcode.length()){ // MesClient.setMenuStatus("工件码前缀不符合要求",-1); // product_sn.setText(""); // return; // }else{ // String pre = scanBarcode.substring(0,preLen); // if(!pre.equals(MesClient.configParam.getProductSnPre().trim())){ // MesClient.setMenuStatus("工件码前缀不符合要求",-1); // product_sn.setText(""); // return; // } // } // } // // //验证工件码长度 // int snLen = MesClient.configParam.getProductSnLength() != null && MesClient.configParam.getProductSnLength().trim().isEmpty() ? 0 : Integer.valueOf(MesClient.configParam.getProductSnLength()); // if(snLen > 0 && snLen != scanBarcode.length()) { // MesClient.setMenuStatus("工件码长度不符合要求",-1); // product_sn.setText(""); // return; // } // // 验证NG // int isCheck = JdbcUtils.checkSnTimer(scanBarcode,configParam); // System.err.println("isCheck:" + isCheck); // if(isCheck == 1){ // int ngTime = Integer.valueOf(configParam.getNgTime()); // MesClient.setMenuStatus("工件码测试NG必须间隔"+ngTime+"分钟",-1); // product_sn.setText(""); // return; // } else if(isCheck == 2){ // int ngUpgradeTime = Integer.valueOf(configParam.getNgUpgradeTime()); // int ngNumber = Integer.valueOf(configParam.getNgNumber()); // MesClient.setMenuStatus("工件码测试NG"+ngNumber+"次,必须间隔"+ngUpgradeTime+"分钟",-1); // product_sn.setText(""); // return; // } if(checkProductSn(scanBarcode.trim())){ serialPortUtils.changeProgram(); // 切换程序 if(MesClient.mes_enable){ getUser(); // 查询工件质量 Boolean sendret = DataUtil.checkQuality(nettyClient,scanBarcode,user20); if(!sendret){ MesClient.setMenuStatus("消息发送失败,请重试",-1); return; } }else{ work_status = 1; MesClient.tjFlag = 1; MesClient.setMenuStatus("扫码成功,等待测试",0); product_sn.setEditable(false); if(MesClient.configParam.getStartMode().equals("自动启动")){ MesClient.serialPortUtils.start(); } MesClient.result.setText("等待结果"); MesClient.result.setForeground(Color.GRAY); } } // f_scan_data_bt_1.setIcon(null); // f_scan_data_bt_1.setText("启动"); } public static void scanBarcodeOld() { if(work_status == 1){ // MesClient.serialPortUtils.sendData("START"); return; } String scanBarcodeTitle = ""; switch(scan_type) { case 1: product_sn.setText(""); scanBarcodeTitle = "请扫工件码"; break; } //弹窗扫工件码 String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle); if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) { // 验证工件码前缀 if(MesClient.configParam.getProductSnPre() != null && !MesClient.configParam.getProductSnPre().trim().isEmpty()) { int preLen = MesClient.configParam.getProductSnPre().trim().length(); if(preLen > scanBarcode.length()){ MesClient.setMenuStatus("工件码前缀不符合要求",-1); return; }else{ String pre = scanBarcode.substring(0,preLen); if(!pre.equals(MesClient.configParam.getProductSnPre().trim())){ MesClient.setMenuStatus("工件码前缀不符合要求",-1); return; } } } //验证工件码长度 int snLen = MesClient.configParam.getProductSnLength() != null && MesClient.configParam.getProductSnLength().trim().isEmpty() ? 0 : Integer.valueOf(MesClient.configParam.getProductSnLength()); if(snLen > 0 && snLen != scanBarcode.length()) { MesClient.setMenuStatus("工件码长度不符合要求",-1); return; } //获取用户 getUser(); //获取扫码内容36位 String barcode36 = getBarcode(scanBarcode);//处理36为码 //工位号 String gw = ""; switch(scan_type) { case 1: product_sn.setText(scanBarcode); break; } //刷新界面 mesClientFrame.repaint(); work_status = 1; // f_scan_data_bt_1.setEnabled(false); MesClient.tjFlag = 1; MesClient.setMenuStatus("扫码成功,等待测试",0); if(MesClient.configParam.getStartMode().equals("自动启动")){ MesClient.serialPortUtils.start(); } f_scan_data_bt_1.setIcon(null); f_scan_data_bt_1.setText("扫码"); }else { JOptionPane.showMessageDialog(mesClientFrame,"请扫工件码","提示窗口", JOptionPane.INFORMATION_MESSAGE); return; } } public static void logoff() { // welcomeWin.setVisible(true); mesClientFrame.setVisible(false); //退出程序 退出登录 System.exit(0); nettyClient = null; // if(heartBeatTimer!=null) { // heartBeatTimer.cancel(); // } // if(heartBeatIconTimer!=null) { // heartBeatIconTimer.cancel(); // } tcp_connect_flag = false; connect_request_flag = false; } public MesClient() { setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png"))); setTitle("气密检测客户端"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(0, 0, 1024, 768); JMenuBar menuBar = new JMenuBar(); menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26)); setJMenuBar(menuBar); JMenu fileMenu = new JMenu("用户"); fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png"))); fileMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20)); menuBar.add(fileMenu); JMenuItem exitMenuItem = new JMenuItem("退出"); exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png"))); exitMenuItem.setFont(new Font("微软雅黑", Font.PLAIN, 22)); fileMenu.add(exitMenuItem); exitMenuItem.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) {//只能检测到mousePressed事件 super.mouseClicked(e); //dispose(); logoff(); } }); JMenu settingMenu = new JMenu("设置"); //settingMenu.setVisible(false); settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png"))); settingMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20)); menuBar.add(settingMenu); JMenuItem resetTcpMenu = new JMenuItem("重连MES"); resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png"))); resetTcpMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20)); resetTcpMenu.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { super.mouseClicked(e); //重连mes nettyClient.future.channel().close(); } }); // settingMenu.add(resetTcpMenu); JMenuItem resetTcpMenu_1 = new JMenuItem("刷新工件"); resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png"))); resetTcpMenu_1.setFont(new Font("微软雅黑", Font.PLAIN, 20)); resetTcpMenu_1.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { super.mouseClicked(e); resetScanA(); } }); settingMenu.add(resetTcpMenu_1); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(new BorderLayout(0, 0)); JToolBar toolBar = new JToolBar(); contentPane.add(toolBar, BorderLayout.NORTH); JLabel equipment_statu_label = new JLabel("状态:"); equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER); equipment_statu_label.setForeground(Color.BLACK); equipment_statu_label.setFont(new Font("微软雅黑", Font.PLAIN, 20)); equipment_statu_label.setBackground(Color.LIGHT_GRAY); toolBar.add(equipment_statu_label); status_menu = new JButton("设备未连接MES服务器"); if(tcp_connect_flag) { MesClient.setMenuStatus("已连接MES服务器",0); status_menu.setForeground(Color.GREEN); }else { MesClient.setMenuStatus("请扫工件码",-1); status_menu.setForeground(Color.DARK_GRAY); } status_menu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); status_menu.setForeground(Color.GREEN); status_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20)); status_menu.setBackground(Color.BLACK); toolBar.add(status_menu); JLabel space_1 = new JLabel(" "); toolBar.add(space_1); JLabel heart_beat_status_label = new JLabel("心跳:"); heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER); heart_beat_status_label.setForeground(Color.BLACK); heart_beat_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20)); heart_beat_status_label.setBackground(Color.LIGHT_GRAY); toolBar.add(heart_beat_status_label); heart_beat_menu = new JButton(""); heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png"))); heart_beat_menu.setForeground(Color.GREEN); heart_beat_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20)); heart_beat_menu.setBackground(Color.BLACK); toolBar.add(heart_beat_menu); JLabel space_2 = new JLabel(" "); toolBar.add(space_2); JLabel user_status_label = new JLabel("登录用户:"); user_status_label.setHorizontalAlignment(SwingConstants.CENTER); user_status_label.setForeground(Color.BLACK); user_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20)); user_status_label.setBackground(Color.LIGHT_GRAY); toolBar.add(user_status_label); user_menu = new JButton(""); user_menu.setForeground(Color.GREEN); user_menu.setFont(new Font("微软雅黑", Font.PLAIN, 22)); user_menu.setBackground(Color.BLACK); toolBar.add(user_menu); JLabel space_3 = new JLabel(" "); toolBar.add(space_3); JLabel space_4 = new JLabel(" "); toolBar.add(space_4); tabbedPane = new JTabbedPane(JTabbedPane.TOP); tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); tabbedPane.setMinimumSize(new Dimension(400, 50)); tabbedPane.setFont(new Font("宋体", Font.BOLD, 22)); contentPane.add(tabbedPane); //首页 JPanel indexPanelA = new JPanel(); indexScrollPaneA = new JScrollPane(indexPanelA); indexPanelA.setLayout(null); curTaskName = new JLabel("当前任务:"); curTaskName.setFont(new Font("微软雅黑", Font.PLAIN, 20)); curTaskName.setHorizontalAlignment(SwingConstants.CENTER); curTaskName.setBounds(81, 10, 800, 40); indexPanelA.add(curTaskName); product_sn = new JTextField(); product_sn.setHorizontalAlignment(SwingConstants.LEFT); product_sn.setEditable(true); product_sn.setFont(new Font("微软雅黑", Font.PLAIN, 28)); product_sn.setBounds(81, 70, 602, 70); indexPanelA.add(product_sn); product_sn.setColumns(10); product_sn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scan_type = 1; scanBarcode2(); } }); // f_scan_data_bt_1 = new JButton("扫码"); f_scan_data_bt_1 = new JButton("扫码"); f_scan_data_bt_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scan_type = 1; // scanBarcode(); scanBarcode2(); } }); // f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png"))); f_scan_data_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32)); f_scan_data_bt_1.setBounds(693, 70, 198, 70); indexPanelA.add(f_scan_data_bt_1); JLabel lblNewLabel = new JLabel("测试压"); lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20)); lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel.setBounds(137, 210, 140, 40); indexPanelA.add(lblNewLabel); param1 = new JTextField(); param1.setEditable(false); param1.setBounds(287, 210, 150, 40); indexPanelA.add(param1); param1.setColumns(10); JLabel lblNewLabel_1 = new JLabel("泄露值"); lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_1.setFont(new Font("微软雅黑", Font.PLAIN, 20)); lblNewLabel_1.setBounds(447, 210, 140, 40); indexPanelA.add(lblNewLabel_1); param2 = new JTextField(); param2.setEditable(false); param2.setColumns(10); param2.setBounds(597, 210, 150, 40); indexPanelA.add(param2); JLabel lblNewLabel_2 = new JLabel("测电阻电压"); lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_2.setFont(new Font("微软雅黑", Font.PLAIN, 20)); lblNewLabel_2.setBounds(137, 288, 140, 40); // indexPanelA.add(lblNewLabel_2); param3 = new JTextField(); param3.setEditable(false); param3.setColumns(10); param3.setBounds(287, 288, 150, 40); // indexPanelA.add(param3); JLabel lblNewLabel_1_1 = new JLabel("电阻"); lblNewLabel_1_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 20)); lblNewLabel_1_1.setBounds(447, 288, 140, 40); // indexPanelA.add(lblNewLabel_1_1); param4 = new JTextField(); param4.setEditable(false); param4.setColumns(10); param4.setBounds(597, 288, 150, 40); // indexPanelA.add(param4); result = new JLabel("等待结果") { @Override protected void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // 设置圆角背景和边框颜色 g2.setColor(new Color(255, 255, 255)); // 背景颜色 g2.fillRoundRect(0, 0, getWidth(), getHeight(), 20, 20); // 圆角矩形,圆角半径为20 g2.setColor(new Color(255, 255, 255)); // 边框颜色 g2.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, 20, 20); // 绘制边框 g2.dispose(); super.paintComponent(g); } }; // result.setForeground(Color.GREEN); // result.setForeground(Color.RED); result.setForeground(Color.GRAY); result.setHorizontalAlignment(SwingConstants.CENTER); result.setFont(new Font("微软雅黑", Font.BOLD, 50)); // result.setBounds(290, 392, 356, 89); result.setBounds(290, 332, 356, 89); indexPanelA.add(result); finish_ok_bt = new JButton("OK"); finish_ok_bt.setEnabled(false); finish_ok_bt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png"))); finish_ok_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32)); finish_ok_bt.setBounds(185, 291, 240, 80); finish_ok_bt.setEnabled(false); // indexPanelA.add(finish_ok_bt); finish_ng_bt = new JButton("NG"); finish_ng_bt.setEnabled(false); finish_ng_bt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png"))); finish_ng_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32)); finish_ng_bt.setBounds(508, 291, 240, 80); finish_ng_bt.setEnabled(false); // indexPanelA.add(finish_ng_bt); tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null); tabbedPane.setEnabledAt(0, true); indexPanelC = new JPanel(); searchScrollPaneDj = new JScrollPane(indexPanelC); // indexPanelC.setLayout(new GridLayout(0, 1, 0, 0)); indexPanelC.setLayout(null); JPanel panel2 = new JPanel(); panel2.setBounds(0, 0, 990, 50); // panel2.setLayout(new GridLayout(0, 1, 0, 0)); panel2.setLayout(null); //记录查询搜索框 textField = new JTextField(); textField.setFont(new Font("微软雅黑", Font.PLAIN, 16)); // textField.setEnabled(false); textField.setForeground(Color.BLACK); textField.setBounds(10, 5, 371, 40); panel2.add(textField); // textField.setColumns(20); indexPanelC.add(panel2); JButton btnNewButton = new JButton("搜索"); btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 20)); btnNewButton.setBounds(385, 5, 90, 40); panel2.add(btnNewButton); // 上一页按钮添加按钮事件监听 btnNewButton.addActionListener(e -> { JdbcUtils.getTestData(); }); JButton resetBtn = new JButton("重置"); resetBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20)); resetBtn.setBounds(475, 5, 90, 40); panel2.add(resetBtn); // 上一页按钮添加按钮事件监听 resetBtn.addActionListener(e -> { textField.setText(""); JdbcUtils.getTestData(); }); JButton resetBtn2 = new JButton("导出"); resetBtn2.setFont(new Font("微软雅黑", Font.PLAIN, 20)); resetBtn2.setBounds(565, 5, 90, 40); panel2.add(resetBtn2); // 上一页按钮添加按钮事件监听 resetBtn2.addActionListener(e -> { List lists = JdbcUtils.getTestDataAll(); Boolean ret = ExportUtil.export(lists); if(ret){ MesClient.setMenuStatus("导出成功,请在D盘中查看",0); }else{ MesClient.setMenuStatus("导出失败,请重试",-1); } }); JButton btnPrevious = new JButton("上一页"); btnPrevious.setFont(new Font("微软雅黑", Font.PLAIN, 18)); btnPrevious.setBounds(680, 5, 100, 40); panel2.add(btnPrevious); // 页码显示 pageLabel = new JLabel("0/0"); // 初始页码和总页数 pageLabel.setFont(new Font("微软雅黑", Font.PLAIN, 18)); pageLabel.setHorizontalAlignment(SwingConstants.CENTER); // 设置文本居中对齐 pageLabel.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1)); // 添加灰色边框 pageLabel.setBounds(780, 5, 100, 40); // 设置位置和大小 panel2.add(pageLabel); // “下一页”按钮 JButton btnNext = new JButton("下一页"); btnNext.setFont(new Font("微软雅黑", Font.PLAIN, 18)); btnNext.setBounds(880, 5, 100, 40); panel2.add(btnNext); // 分页逻辑变量 // 上一页按钮添加按钮事件监听 btnPrevious.addActionListener(e -> { if (pageNo > 1) { pageNo--; JdbcUtils.getTestData(); } }); btnNext.addActionListener(e -> { if (pageNo < totalPages) { pageNo++; JdbcUtils.getTestData(); } }); JPanel panel = new JPanel(); panel.setBounds(0, 49, 990, 518); panel.setLayout(new GridLayout(0, 1, 0, 0)); indexPanelC.add(panel); System.err.println(JSONObject.toJSONString(rowData)); System.err.println(columnNames.length); table = new JTable(rowData, columnNames) { public boolean isCellEditable(int row, int column) { return false; } }; // 添加 MouseListener 获取点击事件 table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if(e.getClickCount() == 1) { int row = table.rowAtPoint(e.getPoint()); // 获取点击的行号 int col = table.columnAtPoint(e.getPoint()); // 获取点击的列号 if (row >= 0 && col >= 0) { // 确保点击在数据区域内 Object value = table.getValueAt(row, col); // 获取点击单元格的数据 System.out.println("Clicked cell value: " + value); // 获取整行的数据 Object[] rowData = new Object[table.getColumnCount()]; for (int i = 0; i < table.getColumnCount(); i++) { rowData[i] = table.getValueAt(row, i); } log.info("Row data: " + java.util.Arrays.toString(rowData)); log.info("O:"+String.valueOf(rowData[0])); if(String.valueOf(rowData[0]) != null && !String.valueOf(rowData[0]).equals("null") && !String.valueOf(rowData[0]).isEmpty()){ // 显示一个简单的确认框 int result = JOptionPane.showConfirmDialog(null, "确定要打印标签吗?", "确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (result == JOptionPane.YES_OPTION) { System.out.println("用户点击了“是”"); PrintUtil.printLabel(String.valueOf(rowData[0]),String.valueOf(rowData[2]),String.valueOf(rowData[3]),String.valueOf(rowData[1])); } else if (result == JOptionPane.NO_OPTION) { System.out.println("用户点击了“否”"); } else if (result == JOptionPane.CLOSED_OPTION) { System.out.println("对话框被关闭"); } // TestParam testParam = JdbcUtils.getTestData(2); // System.out.println(testParam.toString()); // JSONObject retObj = DataUtil.qmResultData(testParam); // System.out.println(retObj.toString()); } } } } }); // 设置table的宽度为100% table.setRowHeight(40); table.setEnabled(true); table.setFont(new Font("微软雅黑", Font.PLAIN, 14)); // table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton()); // table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton()); // 设置第二列的长度为100像素 TableColumn column = table.getColumnModel().getColumn(0); column.setPreferredWidth(290); column = table.getColumnModel().getColumn(1); column.setPreferredWidth(160); CenterRenderer centerRenderer = new CenterRenderer(); for (int i = 0; i < table.getColumnCount(); i++) { table.getColumn(table.getColumnName(i)).setCellRenderer(centerRenderer); } // column = table.getColumnModel().getColumn(6); // column.setPreferredWidth(100); // column = table.getColumnModel().getColumn(7); // column.setPreferredWidth(100); JScrollPane scrollPane = new JScrollPane(table); panel.add(scrollPane); tabbedPane.addTab("记录查询", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null); initOkngRecordPanel(); indexPanelB = new JPanel(); searchScrollPane = new JScrollPane(indexPanelB); indexPanelB.setLayout(null); tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null); indexPanelD = new JPanel(); searchScrollPaneD = new JScrollPane(indexPanelD); indexPanelD.setLayout(null); PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); String[] printerNames = (printServices != null && printServices.length > 0) ? new String[printServices.length] : new String[]{"未知"}; for (int i = 0; i < printerNames.length; i++) { printerNames[i] = printServices[i].getName(); } JLabel lblNewLabel_3 = new JLabel("设备程序号"); lblNewLabel_3.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lblNewLabel_3.setBounds(10, 22, 120, 30); // indexPanelD.add(lblNewLabel_3); programNo = new JTextField(); programNo.setFont(new Font("微软雅黑", Font.PLAIN, 16)); programNo.setBounds(140, 22, 200, 30); // indexPanelD.add(programNo); programNo.setColumns(10); JLabel lblNewLabel_3_1 = new JLabel("设备启动方式"); lblNewLabel_3_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3_1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lblNewLabel_3_1.setBounds(10, 71, 120, 30); indexPanelD.add(lblNewLabel_3_1); startMode = new JComboBox(); startMode.setModel(new DefaultComboBoxModel(new String[] {"手动启动", "自动启动"})); startMode.setFont(new Font("微软雅黑", Font.PLAIN, 16)); startMode.setBounds(140, 71, 200, 30); indexPanelD.add(startMode); JLabel lblNewLabel_3_1_1 = new JLabel("串口号"); lblNewLabel_3_1_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lblNewLabel_3_1_1.setBounds(10, 123, 120, 30); indexPanelD.add(lblNewLabel_3_1_1); serialPort = new JTextField(); serialPort.setFont(new Font("微软雅黑", Font.PLAIN, 16)); serialPort.setColumns(10); serialPort.setBounds(140, 123, 200, 30); indexPanelD.add(serialPort); JLabel lblNewLabel_3_1_1_1 = new JLabel("波特率"); lblNewLabel_3_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lblNewLabel_3_1_1_1.setBounds(10, 176, 120, 30); indexPanelD.add(lblNewLabel_3_1_1_1); baudRate = new JTextField(); baudRate.setFont(new Font("微软雅黑", Font.PLAIN, 16)); baudRate.setColumns(10); baudRate.setBounds(140, 176, 200, 30); indexPanelD.add(baudRate); JLabel lblNewLabel_3_1_1_1_1 = new JLabel("数据位"); lblNewLabel_3_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lblNewLabel_3_1_1_1_1.setBounds(10, 229, 120, 30); indexPanelD.add(lblNewLabel_3_1_1_1_1); dataBits = new JComboBox(); dataBits.setModel(new DefaultComboBoxModel(new String[] {"5", "6", "7", "8"})); dataBits.setFont(new Font("微软雅黑", Font.PLAIN, 16)); dataBits.setBounds(140, 229, 200, 30); indexPanelD.add(dataBits); JLabel lblNewLabel_3_1_1_1_1_1 = new JLabel("校验位"); lblNewLabel_3_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lblNewLabel_3_1_1_1_1_1.setBounds(10, 282, 120, 30); indexPanelD.add(lblNewLabel_3_1_1_1_1_1); checkBit = new JComboBox(); checkBit.setModel(new DefaultComboBoxModel(new String[] {"NONE", "ODD", "EVEN", "MARK", "SPACE"})); checkBit.setFont(new Font("微软雅黑", Font.PLAIN, 16)); checkBit.setBounds(140, 282, 200, 30); indexPanelD.add(checkBit); JLabel lblNewLabel_3_1_1_1_1_1_1 = new JLabel("停止位"); lblNewLabel_3_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lblNewLabel_3_1_1_1_1_1_1.setBounds(10, 335, 120, 30); indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1); stopBit = new JComboBox(); stopBit.setModel(new DefaultComboBoxModel(new String[] {"1", "1.5", "2"})); stopBit.setFont(new Font("微软雅黑", Font.PLAIN, 16)); stopBit.setBounds(140, 335, 200, 30); indexPanelD.add(stopBit); JLabel lblNewLabel_3_1_1_1_1_1_1_1 = new JLabel("是否打印标签"); lblNewLabel_3_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lblNewLabel_3_1_1_1_1_1_1_1.setBounds(408, 22, 120, 30); indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1); printLabel = new JComboBox(); printLabel.setModel(new DefaultComboBoxModel(new String[] {"是", "否"})); printLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16)); printLabel.setBounds(536, 22, 200, 30); indexPanelD.add(printLabel); JLabel lblNewLabel_3_1_1_1_1_1_1_1_1 = new JLabel("打印机名称"); lblNewLabel_3_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lblNewLabel_3_1_1_1_1_1_1_1_1.setBounds(408, 71, 120, 30); indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1); printName = new JTextField(); printName.setFont(new Font("微软雅黑", Font.PLAIN, 16)); printName.setColumns(10); printName.setBounds(536, 71, 200, 30); indexPanelD.add(printName); JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1 = new JLabel("标签名称"); lblNewLabel_3_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lblNewLabel_3_1_1_1_1_1_1_1_1_1.setBounds(408, 123, 120, 30); // indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1); labelName = new JTextField(); labelName.setFont(new Font("微软雅黑", Font.PLAIN, 16)); labelName.setColumns(10); labelName.setBounds(536, 123, 200, 30); // indexPanelD.add(labelName); JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1 = new JLabel("标签偏移X"); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1.setBounds(408, 176, 120, 30); indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1); labelx = new JTextField(); labelx.setFont(new Font("微软雅黑", Font.PLAIN, 16)); labelx.setColumns(10); labelx.setBounds(536, 176, 200, 30); indexPanelD.add(labelx); JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1 = new JLabel("标签偏移Y"); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1.setBounds(408, 229, 120, 30); indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1); labely = new JTextField(); labely.setFont(new Font("微软雅黑", Font.PLAIN, 16)); labely.setColumns(10); labely.setBounds(536, 229, 200, 30); indexPanelD.add(labely); JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1 = new JLabel("标签行间距"); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1.setBounds(408, 282, 120, 30); indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1); labelLineSpace = new JTextField(); labelLineSpace.setFont(new Font("微软雅黑", Font.PLAIN, 16)); labelLineSpace.setColumns(10); labelLineSpace.setBounds(536, 282, 200, 30); indexPanelD.add(labelLineSpace); JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1 = new JLabel("标签字号"); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); // lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1.setBounds(408, 335, 120, 30); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1.setBounds(408, 123, 120, 30); indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1); labelFont = new JTextField(); labelFont.setFont(new Font("微软雅黑", Font.PLAIN, 16)); labelFont.setColumns(10); // labelFont.setBounds(536, 335, 200, 30); labelFont.setBounds(536, 123, 200, 30); indexPanelD.add(labelFont); JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_2 = new JLabel("MODBUS站号"); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_2.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_2.setFont(new Font("微软雅黑", Font.PLAIN, 16)); // lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_2.setBounds(408, 282, 120, 30); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_2.setBounds(408, 335, 120, 30); indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_2); stationNo = new JTextField(); stationNo.setFont(new Font("微软雅黑", Font.PLAIN, 16)); stationNo.setColumns(10); stationNo.setBounds(536, 335, 200, 30); indexPanelD.add(stationNo); saveBtn = new JButton("编辑配置"); saveBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20)); saveBtn.setBounds(787, 267, 156, 57); indexPanelD.add(saveBtn); saveBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(isConfigEdit == 0){ String pass = "503833"; //弹窗扫工件码 String scanBarcode = JOptionPane.showInputDialog(null, "请输入密码"); if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")&&scanBarcode.equals(pass)) { isConfigEdit = 1; formatConfigEdit(true); saveBtn.setText("保存配置"); }else{ MesClient.setMenuStatus("密码错误",-1); } }else{ formatConfigEdit(false); saveBtn.setText("编辑配置"); configParam.setProgramNo(programNo.getText()); configParam.setSerialPort(serialPort.getText()); configParam.setBaudRate(baudRate.getText()); configParam.setPrintName(printName.getText()); configParam.setLabelName(labelName.getText()); configParam.setLabelx(labelx.getText()); configParam.setLabely(labely.getText()); configParam.setLabelLineSpace(labelLineSpace.getText()); configParam.setLabelFont(labelFont.getText()); configParam.setStationNo(stationNo.getText()); configParam.setStopBit(stopBit.getSelectedItem().toString()); configParam.setCheckBit(checkBit.getSelectedItem().toString()); configParam.setStopBit(stopBit.getSelectedItem().toString()); configParam.setDataBits(dataBits.getSelectedItem().toString()); configParam.setPrintLabel(printLabel.getSelectedItem().toString()); configParam.setStartMode(startMode.getSelectedItem().toString()); configParam.setProductSnPre(productSnPre.getText().trim()); configParam.setProductSnLength(productSnLength.getText().trim()); configParam.setLeakage(leakage.getSelectedItem().toString()); configParam.setDevice(device.getSelectedItem().toString()); //9.1修改 // configParam.setNgTime(ngTime.getText()); // configParam.setNgNumber(ngNumber.getText()); // configParam.setNgUpgradeTime(ngUpgradeTime.getText()); configParam.setOprno(oprno.getText().trim()); configParam.setOprnoTitle(oprnoTitle.getText().trim()); configParam.setLineSn(lineSn.getText().trim()); System.out.println("configParam:"+JSONObject.toJSONString(configParam)); if(configParam.getId() != null && configParam.getId() > 0){ JdbcUtils.updateConfig(configParam.getId(),JSONObject.toJSONString(configParam)); }else{ JdbcUtils.insertConfig(JSONObject.toJSONString(configParam)); } isConfigEdit = 0; formatConfigData(); serialPortUtils.closePort(); serialPortUtils = new SerialPortUtils(configParam.getSerialPort(),configParam.getOprno(),configParam.getOprnoTitle(),configParam.getDevice()); } } }); JLabel lblNewLabel_3_1_1_1_1_1_1_2 = new JLabel("泄露值取值"); lblNewLabel_3_1_1_1_1_1_1_2.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3_1_1_1_1_1_1_2.setFont(new Font("微软雅黑", Font.PLAIN, 16)); // lblNewLabel_3_1_1_1_1_1_1_2.setBounds(10, 445, 120, 30); // lblNewLabel_3_1_1_1_1_1_1_2.setBounds(408, 390, 120, 30); lblNewLabel_3_1_1_1_1_1_1_2.setBounds(10, 390, 120, 30); indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_2); leakage = new JComboBox(); leakage.setModel(new DefaultComboBoxModel(new String[] {"压降", "泄漏率"})); leakage.setFont(new Font("微软雅黑", Font.PLAIN, 16)); // leakage.setBounds(140, 445, 200, 30); // leakage.setBounds(536, 390, 200, 30); leakage.setBounds(140, 390, 200, 30); indexPanelD.add(leakage); JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1 = new JLabel("工件码长度"); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1.setBounds(408, 390, 120, 30); // indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1); productSnLength = new JTextField(); productSnLength.setFont(new Font("微软雅黑", Font.PLAIN, 16)); productSnLength.setColumns(10); productSnLength.setBounds(536, 390, 200, 30); // indexPanelD.add(productSnLength); JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1 = new JLabel("工件码前缀"); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1.setBounds(10, 390, 120, 30); // indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1); productSnPre = new JTextField(); productSnPre.setFont(new Font("微软雅黑", Font.PLAIN, 16)); productSnPre.setColumns(10); productSnPre.setBounds(140, 390, 200, 30); // indexPanelD.add(productSnPre); JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2 = new JLabel("检测设备"); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2.setFont(new Font("微软雅黑", Font.PLAIN, 16)); // lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2.setBounds(408, 445, 120, 30); // lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2.setBounds(10, 390, 120, 30); lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2.setBounds(10, 22, 120, 30); indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2); device = new JComboBox(); device.setModel(new DefaultComboBoxModel(new String[] {"innomatec", "ateq"})); device.setFont(new Font("微软雅黑", Font.PLAIN, 16)); // device.setBounds(536, 445, 200, 30); // device.setBounds(140, 390, 200, 30); device.setBounds(140, 22, 200, 30); indexPanelD.add(device); JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_2 = new JLabel("工位号"); lblNewLabel_3_1_1_1_1_1_1_1_1_2.setHorizontalAlignment(SwingConstants.CENTER); lblNewLabel_3_1_1_1_1_1_1_1_1_2.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lblNewLabel_3_1_1_1_1_1_1_1_1_2.setBounds(762, 22, 200, 30); indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_2); // ngTime = new JTextField(); // ngTime.setFont(new Font("微软雅黑", Font.PLAIN, 16)); // ngTime.setColumns(10); // ngTime.setBounds(762, 54, 200, 30); // indexPanelD.add(ngTime); oprno = new JTextField(); oprno.setFont(new Font("微软雅黑", Font.PLAIN, 16)); oprno.setColumns(10); oprno.setBounds(762, 54, 200, 30); indexPanelD.add(oprno); JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_2_1 = new JLabel("工位名称"); lblNewLabel_3_1_1_1_1_1_1_1_1_2_1.setHorizontalAlignment(SwingConstants.CENTER); lblNewLabel_3_1_1_1_1_1_1_1_1_2_1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lblNewLabel_3_1_1_1_1_1_1_1_1_2_1.setBounds(762, 94, 200, 30); indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_2_1); // ngNumber = new JTextField(); // ngNumber.setFont(new Font("微软雅黑", Font.PLAIN, 16)); // ngNumber.setColumns(10); // ngNumber.setBounds(762, 123, 200, 30); // indexPanelD.add(ngNumber); oprnoTitle = new JTextField(); oprnoTitle.setFont(new Font("微软雅黑", Font.PLAIN, 16)); oprnoTitle.setColumns(10); oprnoTitle.setBounds(762, 123, 200, 30); indexPanelD.add(oprnoTitle); JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_2_1_1 = new JLabel("产线编号"); lblNewLabel_3_1_1_1_1_1_1_1_1_2_1_1.setHorizontalAlignment(SwingConstants.CENTER); lblNewLabel_3_1_1_1_1_1_1_1_1_2_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lblNewLabel_3_1_1_1_1_1_1_1_1_2_1_1.setBounds(762, 163, 200, 30); indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_2_1_1); // // ngUpgradeTime = new JTextField(); // ngUpgradeTime.setFont(new Font("微软雅黑", Font.PLAIN, 16)); // ngUpgradeTime.setColumns(10); // ngUpgradeTime.setBounds(762, 195, 200, 30); // indexPanelD.add(ngUpgradeTime); lineSn = new JTextField(); lineSn.setFont(new Font("微软雅黑", Font.PLAIN, 16)); lineSn.setColumns(10); lineSn.setBounds(762, 195, 200, 30); indexPanelD.add(lineSn); tabbedPane.addTab("软件设置", new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")), searchScrollPaneD, null); JPanel indexPanelTask = new JPanel(); searchScrollPaneTask = new JScrollPane(indexPanelTask); indexPanelTask.setLayout(null); JPanel panel22 = new JPanel(); panel22.setBounds(0, 0, 300, 530); indexPanelTask.add(panel22); panel22.setLayout(new GridLayout(0, 1, 0, 0)); table2 = new JTable(rowData2, columnNames2){ public boolean isCellEditable(int row, int column) { return false; } }; table2.setRowHeight(40); table2.setEnabled(true); table2.setFont(new Font("微软雅黑", Font.PLAIN, 14)); // 添加鼠标点击事件 table2.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { // 获取点击位置的行和列索引 int row = table2.rowAtPoint(e.getPoint()); int col = table2.columnAtPoint(e.getPoint()); // 检查点击是否有效(即是否真的在表格内) if (row >= 0 && col >= 0) { // 获取点击的单元格的值 Object value = table2.getValueAt(row, col); String val = String.valueOf(value); System.out.println("Clicked on row " + row + ", column " + col + ": " + value); // 在这里添加你的逻辑代码 for(TaskParam taskParam:taskParamList){ if(val.equals(taskParam.getTitle())){ MesClient.curTaskParam = taskParam; formatTaskParam(); break; } } } } }); // 自定义渲染器 DefaultTableCellRenderer centerRenderer2 = new DefaultTableCellRenderer(); centerRenderer2.setHorizontalAlignment(JLabel.CENTER); // 设置内容居中 table2.setDefaultRenderer(Object.class, centerRenderer2); // 应用到所有列 JScrollPane scrollPane2 = new JScrollPane(table2); panel22.add(scrollPane2); JButton addTask = new JButton("新增任务"); addTask.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String taskContent = JOptionPane.showInputDialog(null, "请输入任务名称").trim(); if(taskContent!=null&&!taskContent.equalsIgnoreCase("")) { String passContent = JOptionPane.showInputDialog(null, "请输入密码"); if(passContent!=null&&!passContent.equalsIgnoreCase("")) { if(passContent.equals("503833")){ int wyflag = 1; for(TaskParam taskParam:taskParamList){ if(taskParam.getTitle().equals(taskContent)){ wyflag = 0; break; } } if(wyflag == 0){ MesClient.setMenuStatus("任务名称已被占用",-1); return; } TaskParam taskParam = new TaskParam(); taskParam.setTitle(taskContent); JdbcUtils.insertTask(taskParam); getTask(); }else{ MesClient.setMenuStatus("密码错误",-1); } } } } }); addTask.setFont(new Font("微软雅黑", Font.PLAIN, 20)); addTask.setBounds(310, 10, 120, 40); indexPanelTask.add(addTask); JButton delTask = new JButton("删除任务"); delTask.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(MesClient.curTaskParam == null){ MesClient.setMenuStatus("请先选择任务",-1); return; } String passContent = JOptionPane.showInputDialog(null, "请输入密码"); if(passContent!=null&&!passContent.equalsIgnoreCase("")) { if(passContent.equals("503833")){ JdbcUtils.deleteTask(MesClient.curTaskParam.getId()); getTask(); MesClient.curTaskParam = null; formatTaskParam(); }else{ MesClient.setMenuStatus("密码错误",-1); } } } }); delTask.setFont(new Font("微软雅黑", Font.PLAIN, 20)); delTask.setBounds(440, 10, 120, 40); indexPanelTask.add(delTask); JButton saveTask = new JButton("保存任务"); saveTask.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(MesClient.curTaskParam == null){ MesClient.setMenuStatus("请先选择任务",-1); return; } String passContent = JOptionPane.showInputDialog(null, "请输入密码"); if(passContent!=null&&!passContent.equalsIgnoreCase("")) { if(passContent.equals("503833")){ MesClient.curTaskParam.setBarcodeSpecStart(barcodeSpecStart.getText().trim()); MesClient.curTaskParam.setBarcodeSpec(barcodeSpec.getText().trim()); MesClient.curTaskParam.setBarcodeLength(barcodeLength.getText().trim()); MesClient.curTaskParam.setTaskProgramNo(taskMaxNumA.getText().trim()); MesClient.curTaskParam.setTaskLabelName(taskMaxFoutA.getText().trim()); MesClient.curTaskParam.setTaskLeakage(taskLeakage.getSelectedItem().toString()); JdbcUtils.updateTask(MesClient.curTaskParam.getId(),MesClient.curTaskParam); getTask(); formatTaskParam(); }else{ MesClient.setMenuStatus("密码错误",-1); } } } }); saveTask.setFont(new Font("微软雅黑", Font.PLAIN, 20)); saveTask.setBounds(570, 10, 120, 40); indexPanelTask.add(saveTask); taskName = new JLabel(""); taskName.setFont(new Font("微软雅黑", Font.PLAIN, 20)); taskName.setBounds(700, 10, 283, 40); indexPanelTask.add(taskName); JLabel taskMaxNumLabelA = new JLabel("程序号"); taskMaxNumLabelA.setHorizontalAlignment(SwingConstants.CENTER); taskMaxNumLabelA.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskMaxNumLabelA.setBounds(310, 93, 110, 30); indexPanelTask.add(taskMaxNumLabelA); taskMaxNumA = new JTextField(); taskMaxNumA.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskMaxNumA.setBounds(422, 93, 110, 30); indexPanelTask.add(taskMaxNumA); taskMaxNumA.setColumns(10); JLabel taskMaxFoutLabelA = new JLabel("标签名称"); taskMaxFoutLabelA.setHorizontalAlignment(SwingConstants.CENTER); taskMaxFoutLabelA.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskMaxFoutLabelA.setBounds(310, 133, 110, 30); indexPanelTask.add(taskMaxFoutLabelA); taskMaxFoutA = new JTextField(); taskMaxFoutA.setColumns(10); taskMaxFoutA.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskMaxFoutA.setBounds(422, 133, 110, 30); indexPanelTask.add(taskMaxFoutA); JLabel taskMinFoutLabelA = new JLabel("泄漏值取值"); taskMinFoutLabelA.setHorizontalAlignment(SwingConstants.CENTER); taskMinFoutLabelA.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskMinFoutLabelA.setBounds(310, 173, 110, 30); indexPanelTask.add(taskMinFoutLabelA); taskLeakage = new JComboBox(); taskLeakage.setModel(new DefaultComboBoxModel(new String[] {"压降", "泄漏率"})); taskLeakage.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskLeakage.setBounds(422, 173, 110, 30); indexPanelTask.add(taskLeakage); // taskMinFoutA = new JTextField(); // taskMinFoutA.setColumns(10); // taskMinFoutA.setFont(new Font("微软雅黑", Font.PLAIN, 16)); // taskMinFoutA.setBounds(422, 173, 110, 30); // indexPanelTask.add(taskMinFoutA); JLabel taskMaxSoutLabelA = new JLabel("A枪最大行程"); taskMaxSoutLabelA.setHorizontalAlignment(SwingConstants.CENTER); taskMaxSoutLabelA.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskMaxSoutLabelA.setBounds(310, 213, 110, 30); // indexPanelTask.add(taskMaxSoutLabelA); taskMaxSoutA = new JTextField(); taskMaxSoutA.setColumns(10); taskMaxSoutA.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskMaxSoutA.setBounds(422, 213, 110, 30); // indexPanelTask.add(taskMaxSoutA); JLabel taskMinSoutLabelA = new JLabel("A枪最小行程"); taskMinSoutLabelA.setHorizontalAlignment(SwingConstants.CENTER); taskMinSoutLabelA.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskMinSoutLabelA.setBounds(310, 253, 110, 30); // indexPanelTask.add(taskMinSoutLabelA); taskMinSoutA = new JTextField(); taskMinSoutA.setColumns(10); taskMinSoutA.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskMinSoutA.setBounds(422, 253, 110, 30); // indexPanelTask.add(taskMinSoutA); JLabel taskMaxNumLabelB = new JLabel("B枪预算数量"); taskMaxNumLabelB.setHorizontalAlignment(SwingConstants.CENTER); taskMaxNumLabelB.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskMaxNumLabelB.setBounds(580, 93, 110, 30); // indexPanelTask.add(taskMaxNumLabelB); taskMaxNumB = new JTextField(); taskMaxNumB.setColumns(10); taskMaxNumB.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskMaxNumB.setBounds(692, 93, 110, 30); // indexPanelTask.add(taskMaxNumB); JLabel taskMaxFoutLabelB = new JLabel("B枪最大拉力"); taskMaxFoutLabelB.setHorizontalAlignment(SwingConstants.CENTER); taskMaxFoutLabelB.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskMaxFoutLabelB.setBounds(580, 133, 110, 30); // indexPanelTask.add(taskMaxFoutLabelB); taskMaxFoutB = new JTextField(); taskMaxFoutB.setColumns(10); taskMaxFoutB.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskMaxFoutB.setBounds(692, 133, 110, 30); // indexPanelTask.add(taskMaxFoutB); JLabel taskMinFoutLabelB = new JLabel("B枪最小拉力"); taskMinFoutLabelB.setHorizontalAlignment(SwingConstants.CENTER); taskMinFoutLabelB.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskMinFoutLabelB.setBounds(580, 173, 110, 30); // indexPanelTask.add(taskMinFoutLabelB); taskMinFoutB = new JTextField(); taskMinFoutB.setColumns(10); taskMinFoutB.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskMinFoutB.setBounds(692, 173, 110, 30); // indexPanelTask.add(taskMinFoutB); JLabel taskMaxSoutLabelB = new JLabel("B枪最大行程"); taskMaxSoutLabelB.setHorizontalAlignment(SwingConstants.CENTER); taskMaxSoutLabelB.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskMaxSoutLabelB.setBounds(580, 213, 110, 30); // indexPanelTask.add(taskMaxSoutLabelB); taskMaxSoutB = new JTextField(); taskMaxSoutB.setColumns(10); taskMaxSoutB.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskMaxSoutB.setBounds(692, 213, 110, 30); // indexPanelTask.add(taskMaxSoutB); JLabel taskMinSoutLabelB = new JLabel("B枪最小行程"); taskMinSoutLabelB.setHorizontalAlignment(SwingConstants.CENTER); taskMinSoutLabelB.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskMinSoutLabelB.setBounds(580, 253, 110, 30); // indexPanelTask.add(taskMinSoutLabelB); taskMinSoutB = new JTextField(); taskMinSoutB.setColumns(10); taskMinSoutB.setFont(new Font("微软雅黑", Font.PLAIN, 16)); taskMinSoutB.setBounds(692, 253, 110, 30); // indexPanelTask.add(taskMinSoutB); JLabel barcodeSpecLabel = new JLabel("条码固定位"); barcodeSpecLabel.setHorizontalAlignment(SwingConstants.CENTER); barcodeSpecLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16)); barcodeSpecLabel.setBounds(310, 293, 110, 30); indexPanelTask.add(barcodeSpecLabel); barcodeSpec = new JTextField(); barcodeSpec.setColumns(10); barcodeSpec.setFont(new Font("微软雅黑", Font.PLAIN, 16)); barcodeSpec.setBounds(422, 293, 110, 30); indexPanelTask.add(barcodeSpec); JLabel barcodeSpecStartLabel = new JLabel("起始位数"); barcodeSpecStartLabel.setHorizontalAlignment(SwingConstants.CENTER); barcodeSpecStartLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16)); barcodeSpecStartLabel.setBounds(310, 333, 110, 30); indexPanelTask.add(barcodeSpecStartLabel); barcodeSpecStart = new JTextField(); barcodeSpecStart.setColumns(10); barcodeSpecStart.setFont(new Font("微软雅黑", Font.PLAIN, 16)); barcodeSpecStart.setBounds(422, 333, 110, 30); indexPanelTask.add(barcodeSpecStart); JLabel barcodeLengthLabel = new JLabel("条码长度"); barcodeLengthLabel.setHorizontalAlignment(SwingConstants.CENTER); barcodeLengthLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16)); barcodeLengthLabel.setBounds(310, 373, 110, 30); indexPanelTask.add(barcodeLengthLabel); barcodeLength = new JTextField(); barcodeLength.setColumns(10); barcodeLength.setFont(new Font("微软雅黑", Font.PLAIN, 16)); barcodeLength.setBounds(422, 373, 110, 30); indexPanelTask.add(barcodeLength); tabbedPane.addTab("任务设置", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneTask, null); tabbedPane.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JTabbedPane tabbedPane = (JTabbedPane) e.getSource(); int selectedIndex = tabbedPane.getSelectedIndex(); if (selectedIndex == tabbedPane.indexOfTab("OKNG样件")) { loadOkngRecordData(); } if(selectedIndex == 1){ } JdbcUtils.getTestData(); } }); } private static void initOkngRecordPanel() { JPanel container = new JPanel(); container.setLayout(null); JScrollPane scrollPane = new JScrollPane(container); JPanel top = new JPanel(); top.setBounds(0, 0, 990, 50); top.setLayout(null); container.add(top); okngTextField = new JTextField(); okngTextField.setFont(new Font("微软雅黑", Font.PLAIN, 16)); okngTextField.setForeground(Color.BLACK); okngTextField.setBounds(10, 5, 371, 40); top.add(okngTextField); JButton searchBtn = new JButton("搜索"); searchBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20)); searchBtn.setBounds(385, 5, 90, 40); top.add(searchBtn); searchBtn.addActionListener(e -> { okngPageNo = 1; loadOkngRecordData(); }); JButton resetBtn = new JButton("重置"); resetBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20)); resetBtn.setBounds(475, 5, 90, 40); top.add(resetBtn); resetBtn.addActionListener(e -> { okngTextField.setText(""); okngPageNo = 1; loadOkngRecordData(); }); JButton btnPrevious = new JButton("上一页"); btnPrevious.setFont(new Font("微软雅黑", Font.PLAIN, 18)); btnPrevious.setBounds(680, 5, 100, 40); top.add(btnPrevious); btnPrevious.addActionListener(e -> { if (okngPageNo > 1) { okngPageNo--; loadOkngRecordData(); } }); okngPageLabel = new JLabel("0/0"); okngPageLabel.setFont(new Font("微软雅黑", Font.PLAIN, 18)); okngPageLabel.setHorizontalAlignment(SwingConstants.CENTER); okngPageLabel.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1)); okngPageLabel.setBounds(780, 5, 100, 40); top.add(okngPageLabel); JButton btnNext = new JButton("下一页"); btnNext.setFont(new Font("微软雅黑", Font.PLAIN, 18)); btnNext.setBounds(880, 5, 100, 40); top.add(btnNext); btnNext.addActionListener(e -> { if (okngPageNo < okngTotalPages) { okngPageNo++; loadOkngRecordData(); } }); JPanel tablePanel = new JPanel(); tablePanel.setBounds(0, 49, 990, 518); tablePanel.setLayout(new GridLayout(0, 1, 0, 0)); container.add(tablePanel); okngTable = new JTable(okngRowData, okngColumnNames) { public boolean isCellEditable(int row, int column) { return false; } }; okngTable.setRowHeight(40); okngTable.setFont(new Font("微软雅黑", Font.PLAIN, 14)); CenterRenderer centerRenderer = new CenterRenderer(); for (int i = 0; i < okngTable.getColumnCount(); i++) { okngTable.getColumn(okngTable.getColumnName(i)).setCellRenderer(centerRenderer); } tablePanel.add(new JScrollPane(okngTable)); tabbedPane.addTab("OKNG样件", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), scrollPane, null); } private static void loadOkngRecordData() { for (int i = 0; i < okngRowData.length; i++) { for (int j = 0; j < okngRowData[i].length; j++) { okngRowData[i][j] = null; } } boolean loaded = refreshOkngSamples(); int pageSize = 12; String snLike = okngTextField == null ? "" : okngTextField.getText(); if (!loaded) { okngTotalPages = 0; if (okngPageLabel != null) { okngPageLabel.setText("失败"); } if (okngTable != null) { okngTable.repaint(); } return; } int totalItems = JdbcUtils.countTestRecordBySns(okngSampleSns, snLike); if (totalItems <= 0) { okngTotalPages = 0; if (okngPageLabel != null) { okngPageLabel.setText(okngSampleSns.isEmpty() ? "未配置" : "0/0"); } if (okngTable != null) { okngTable.repaint(); } return; } okngTotalPages = (int) Math.ceil((double) totalItems / (double) pageSize); if (okngPageNo > okngTotalPages) { okngPageNo = okngTotalPages; } if (okngPageNo < 1) { okngPageNo = 1; } if (okngPageLabel != null) { okngPageLabel.setText(okngPageNo + "/" + okngTotalPages); } int offset = (okngPageNo - 1) * pageSize; List rows = JdbcUtils.queryTestRecordBySns(okngSampleSns, snLike, pageSize, offset); int rowIndex = 0; for (String[] row : rows) { if (rowIndex >= okngRowData.length) { break; } okngRowData[rowIndex][0] = okngSampleType.getOrDefault(row[0], ""); okngRowData[rowIndex][1] = row[0]; okngRowData[rowIndex][2] = row[1]; okngRowData[rowIndex][3] = row[2]; okngRowData[rowIndex][4] = row[3]; okngRowData[rowIndex][5] = row[4]; rowIndex++; } if (okngTable != null) { okngTable.repaint(); } } private static boolean refreshOkngSamples() { okngSampleSns.clear(); okngSampleType.clear(); String oprno = ""; String lineSn = ""; try { InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties"); Properties pro = new Properties(); BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8")); pro.load(br); oprno = pro.getProperty("mes.gw"); lineSn = pro.getProperty("mes.line_sn"); br.close(); } catch (Exception e) { log.error("读取工位配置失败", e); return false; } JSONObject ret = DataUtil.getQmSampleSns(oprno == null ? "" : oprno.trim(), lineSn == null ? "" : lineSn.trim()); if (ret == null || !"true".equalsIgnoreCase(String.valueOf(ret.get("result")))) { return false; } JSONObject data = ret.getJSONObject("data"); if (data == null) { return true; } addOkngSamples(data.getString("ok"), "OK件"); addOkngSamples(data.getString("ng"), "NG件"); return true; } private static void addOkngSamples(String sns, String type) { if (sns == null || sns.trim().isEmpty()) { return; } for (String sn : sns.split(",", -1)) { String code = sn.trim(); if (code.isEmpty()) { continue; } if (!okngSampleSns.contains(code)) { okngSampleSns.add(code); } String old = okngSampleType.get(code); if (old == null) { okngSampleType.put(code, type); } else if (!old.equals(type) && !old.contains(type)) { okngSampleType.put(code, old + "/" + type); } } } public static void setMenuStatus(String msg,int error){ if(error == 0){ MesClient.status_menu.setForeground(Color.GREEN); }else{ MesClient.status_menu.setForeground(Color.RED); } MesClient.status_menu.setText(msg); } public static void getTask(){ taskParamList = JdbcUtils.getTask(); System.out.println("taskParamList:"+taskParamList.size()); if(taskParamList.size() > 0){ int i = 0; rowData2 = new Object[taskParamList.size()][1]; for(TaskParam taskParam:taskParamList){ rowData2[i][0] = taskParam.getTitle(); i++; } }else{ rowData2[0][0] = ""; } System.out.println("rowData2:"+JSONObject.toJSONString(rowData2)); DefaultTableModel model = new DefaultTableModel(rowData2, columnNames2); table2.setModel(model); MesClient.table2.repaint(); } public static void formatTaskParam(){ if(MesClient.curTaskParam != null){ taskName.setText(MesClient.curTaskParam.getTitle()); if(MesClient.curTaskParam.getTaskProgramNo() == null || MesClient.curTaskParam.getTaskProgramNo().equals("")){ MesClient.curTaskParam.setTaskProgramNo(""); } taskMaxNumA.setText(MesClient.curTaskParam.getTaskProgramNo()); if(MesClient.curTaskParam.getTaskLabelName() == null || MesClient.curTaskParam.getTaskLabelName().equals("")){ MesClient.curTaskParam.setTaskLabelName(""); } taskMaxFoutA.setText(MesClient.curTaskParam.getTaskLabelName()); if(MesClient.curTaskParam.getTaskLeakage() == null || MesClient.curTaskParam.getTaskLeakage().equals("")){ MesClient.curTaskParam.setTaskLeakage("压降"); } taskLeakage.setSelectedItem(MesClient.curTaskParam.getTaskLeakage()); if(MesClient.curTaskParam.getBarcodeSpec() == null || MesClient.curTaskParam.getBarcodeSpec().equals("")){ MesClient.curTaskParam.setBarcodeSpec(""); } barcodeSpec.setText(MesClient.curTaskParam.getBarcodeSpec()); if(MesClient.curTaskParam.getBarcodeSpecStart() == null || MesClient.curTaskParam.getBarcodeSpecStart().equals("")){ MesClient.curTaskParam.setBarcodeSpecStart(""); } barcodeSpecStart.setText(MesClient.curTaskParam.getBarcodeSpecStart()); if(MesClient.curTaskParam.getBarcodeLength() == null || MesClient.curTaskParam.getBarcodeLength().equals("")){ MesClient.curTaskParam.setBarcodeLength(""); } barcodeLength.setText(MesClient.curTaskParam.getBarcodeLength()); }else{ taskName.setText(""); taskMaxNumA.setText(""); taskMaxNumB.setText(""); taskMaxFoutA.setText(""); taskMaxFoutB.setText(""); taskMaxSoutA.setText(""); taskMaxSoutB.setText(""); taskMinFoutA.setText(""); taskMinFoutB.setText(""); taskMinSoutA.setText(""); taskMinSoutB.setText(""); barcodeLength.setText(""); barcodeSpec.setText(""); barcodeSpecStart.setText(""); } } // 检查工件码的正确性 public static boolean checkProductSn(String sn){ curTaskName.setText(""); if(taskParamList.size() <= 0){ MesClient.setMenuStatus("未设置任务",-1); return false; } try{ for(TaskParam taskParam : taskParamList){ if(taskParam.getBarcodeSpec()!=null&&!taskParam.getBarcodeSpec().equals("null")&&taskParam.getBarcodeSpecStart()!=null&&!taskParam.getBarcodeSpecStart().equals("null")&&taskParam.getBarcodeLength()!=null&&!taskParam.getBarcodeLength().equals("null")) { Boolean ret = CommonUtils.checkSnByModel(sn,taskParam.getBarcodeSpec(),Integer.valueOf(taskParam.getBarcodeSpecStart()),Integer.valueOf(taskParam.getBarcodeLength())); if(ret){ configParam.setLabelName(taskParam.getTaskLabelName()); configParam.setLeakage(taskParam.getTaskLeakage()); configParam.setProgramNo(taskParam.getTaskProgramNo()); curTaskName.setText("当前任务:"+taskParam.getTitle()); // configParam.setDeviceMaxNumValA(taskParam.getTaskMaxNumA()); // configParam.setMaxFoutValA(taskParam.getTaskMaxFoutA()); // configParam.setMaxSoutValA(taskParam.getTaskMaxSoutA()); // configParam.setMinFoutValA(taskParam.getTaskMinFoutA()); // configParam.setMinSoutValA(taskParam.getTaskMinSoutA()); // // configParam.setDeviceMaxNumValB(taskParam.getTaskMaxNumB()); // configParam.setMaxFoutValB(taskParam.getTaskMaxFoutB()); // configParam.setMaxSoutValB(taskParam.getTaskMaxSoutB()); // configParam.setMinFoutValB(taskParam.getTaskMinFoutB()); // configParam.setMinSoutValB(taskParam.getTaskMinSoutB()); return true; } } } }catch (Exception e){ e.printStackTrace(); } MesClient.setMenuStatus("该类型工件未设置任务",-1); return false; } public static String scanQrcode(){ if(scanFlag1 == 1){ return ""; } scanFlag1 = 1; String sn = ""; try{ if (tcpClient1.socket == null || !tcpClient1.socket.isConnected() || tcpClient1.socket.isClosed()) { tcpClient1.connect(); } log.error("扫码枪1正在进行扫码,请勿操作",0); sn = tcpClient1.receiveResponse(); if (sn == null || sn.equals("")) { sn = ""; } tcpClient1.close(); }catch (Exception e) { e.printStackTrace(); log.error("scanQrcode1:"+sn); tcpClient1.close(); } scanFlag1 = 0; return sn; } }