package com.mes.ui; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.github.s7connector.impl.utils.S7Utils; import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcp; import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType; import com.github.xingshuangs.iot.protocol.s7.service.S7PLC; import com.mes.component.MesRadio; import com.mes.component.MesWebView; import com.mes.component.MyDialog; import com.mes.netty.NettyClient; import com.mes.util.ConfigLoader; import com.mes.util.DateLocalUtils; import com.mes.util.EncodingUtil; import com.mes.util.HttpUtils; import com.mes.util.JdbcUtils; import javafx.embed.swing.JFXPanel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.swing.*; import javax.swing.border.EmptyBorder; import javax.swing.plaf.FontUIResource; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Properties; import java.util.Timer; import java.util.TimerTask; import java.util.List; public class MesClient extends JFrame { static { EncodingUtil.init(); } public static final Logger log = LoggerFactory.getLogger(MesClient.class); private static String Drivde = "org.sqlite.JDBC"; public static int mes_auth = 0; public static String mes_gw = ""; public static String mes_gw_des = ""; public static String mes_server_ip = ""; public static int mes_tcp_port = 3000; public static int mes_heart_beat_cycle = 10; public static int mes_heart_icon_cycle = 1; public static String mes_line_sn = ""; public static NettyClient nettyClient; public static boolean tcp_connect_flag = false; public static boolean connect_request_flag = false; //session public static String sessionid = ""; public static JPanel contentPane; public static JPanel indexPanelA; public static MesClient mesClientFrame; public static JTabbedPane tabbedPane; public static JScrollPane indexScrollPaneA; public static JScrollPane indexScrollPaneB; public static JScrollPane searchScrollPane; public static JScrollPane searchScrollPaneDj; public static JScrollPane searchScrollPaneGz; public static Boolean check_quality_result = false; public static Integer work_status = 0; public static Integer work_status2 = 0; public static Boolean check_quality_result2 = false; public static Integer batch_status = 0; //A面 1=已绑定 0=未绑定 public static Integer batch_status2 = 0; //B面 1=已绑定 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_ok_bt2; public static JButton finish_ng_bt; public static JButton finish_ng_bt2; public static JTextField product_sn; public static JLabel pxstatus1; public static JLabel pxstatus2; public static JButton batch_scan_1; public static JButton batch_scan_2; public static Integer tjFlag = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束 public static Integer tjFlaga = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束 public static Integer tjFlagb = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束 public static Integer tjStatusa = 0; // 1=提交失败 public static Integer tjStatusb = 0; // 1=提交失败 public static String curFlag = ""; // 当前工作的面板 public static String curSna = ""; public static String curSnb = ""; public static String curPage = ""; /** 最近一次镭雕扫码所在面(A/B),用于 MES 开工与 PLC 允许信号 */ public static String lastScanSide = "A"; public static Integer checkA = 0; public static Integer checkB = 0; public static Integer lastpage = 0; public static Boolean mesQualityFlagA = false; // true=可工作 public static Boolean mesQualityFlagB = false; // true=可工作 public static Boolean mesErrorFlagA = false; // true=提交MES失败,手动提交 public static Boolean mesErrorFlagB = false; // true=提交MES失败,手动提交 public static String user20 = ""; public static JFrame welcomeWin; public static JPanel indexPanelB; public static MesWebView jfxPanel = null; public static MesRadio mesRadioHj; public static JPanel indexPanelC; public static MesWebView jfxPanel2 = null; public static S7PLC s7PLC = new S7PLC(EPlcType.S1200, "192.168.7.100"); //100 B工位 public static List hjparams = new ArrayList<>(); public static JTable table; public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" }; public static Object[][] rowData = null; // public static Object[][] rowData = { // }; public static void main(String[] args) { initUiFont(); EventQueue.invokeLater(new Runnable() { @Override public void run() { try{ readProperty(); mesClientFrame = new MesClient(); mesClientFrame.setVisible(false); JdbcUtils.getConn(); welcomeWin = new LoginFarme(); welcomeWin.setVisible(true); getMaterailData(); //获取当前面 textFocus(); getPlcParam(); // upParams(); // getPlcParams(); }catch (Exception e){ e.printStackTrace(); } } }); } /** 优先使用系统中文字体,避免 jar 部署机器字体名不一致 */ private static Font resolveUiFont(int size) { String[] candidates = {"Microsoft YaHei UI", "微软雅黑", "Microsoft YaHei", "SimSun"}; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] available = ge.getAvailableFontFamilyNames(); java.util.Set set = new java.util.HashSet<>(); for (String name : available) { set.add(name); } for (String name : candidates) { if (set.contains(name)) { return new Font(name, Font.PLAIN, size); } } return new Font(Font.SANS_SERIF, Font.PLAIN, size); } /** 全局 UI 字体,避免登录页等使用 Dialog 字体时中文显示异常 */ private static void initUiFont() { Font baseFont = resolveUiFont(12); java.util.Enumeration keys = UIManager.getDefaults().keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object value = UIManager.get(key); if (value instanceof Font) { Font old = (Font) value; UIManager.put(key, new FontUIResource(baseFont.getName(), old.getStyle(), old.getSize())); } } } public static Timer cjTimerText; public static void textFocus() { if(cjTimerText!=null) { cjTimerText.cancel(); } cjTimerText = new Timer(); cjTimerText.schedule(new TimerTask() { public void run() { txtfa.requestFocusInWindow(); MesClient.curPage = PlcUtil.getCurAside(s7PLC); if(MesClient.curPage .equals("A")){ page_text.setText("当前:A面"); }else{ page_text.setText("当前:B面"); } } }, 1000,1000); } public static Timer cjTimer3; public static void upParams() { if(cjTimer3!=null) { cjTimer3.cancel(); } cjTimer3 = new Timer(); cjTimer3.schedule(new TimerTask() { public void run() { uploadPendingCmtParams(); } }, 1000,30*1000); } /** 立即上传本地未同步的焊接采样数据 */ public static void uploadPendingCmtParams() { try{ List prods = JdbcUtils.getCmtParams(); if(prods.isEmpty()){ return; } JSONObject retObj = DataUtil.upParams(JSON.toJSONString(prods)); if(retObj != null && retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) { for(CmtReq prodReq : prods){ JdbcUtils.updateProdSync(prodReq.getId(),1); } } }catch (Exception e){ e.printStackTrace(); } } /** 焊接报工后:先上传采样数据,再刷新工作记录页 */ public static void notifyWorkSubmitted() { uploadPendingCmtParams(); new Timer().schedule(new TimerTask() { @Override public void run() { refreshWorkRecord(); } }, 1000); } /** 刷新「工作记录」WebView */ public static void refreshWorkRecord() { if(jfxPanel == null || sessionid == null || sessionid.isEmpty()){ return; } String url = "http://" + mes_server_ip + ":8980/js/a/mes/mesProductRecord/work?__sid=" + sessionid + "&oprno=" + mes_gw + "&lineSn=" + mes_line_sn + "&t=" + System.currentTimeMillis(); jfxPanel.loadPageUrl(url); } public static String resolveOprnoForSubmit(String op) { return mes_gw + op; } /** 根据 MES 返回工位号或最近扫码面,判定 A/B(仅 OP080A / OP080B) */ public static String resolveScanSide(String oprno) { if (oprno != null) { String o = oprno.trim(); if (o.endsWith("B")) { return "B"; } if (o.endsWith("A")) { return "A"; } } if ("B".equals(lastScanSide)) { return "B"; } if ("B".equals(curPage)) { return "B"; } return "A"; } /** 焊接结束时落库未满 60 条的剩余采样 */ public static void flushHjparamsToDb(String oprno, String sn) { if (hjparams == null || hjparams.isEmpty() || sn == null || sn.isEmpty()) { return; } try { JdbcUtils.insertCmtData(oprno, mes_line_sn, sn, JSON.toJSONString(hjparams)); hjparams = new ArrayList<>(); } catch (Exception e) { e.printStackTrace(); } } private static final int TAB_WORK_RECORD = 2; public static Timer cjTimer; public static void getPlcParam() { if(cjTimer!=null) { cjTimer.cancel(); } cjTimer = new Timer(); cjTimer.schedule(new TimerTask() { public void run() { try{ if(!MesClient.sessionid.isEmpty()){ PlcUtil.getStatusA(s7PLC); } }catch (Exception e){ e.printStackTrace(); } try{ if(!MesClient.sessionid.isEmpty()){ PlcUtil.getStatusB(s7PLC); } }catch (Exception e){ e.printStackTrace(); } } // 运行中 500ms 轮询,降低漏检 PLC「焊接完成」短脉冲的概率(不改 PLC) }, 1000,500); } public static Timer cjTimer2; public static void getPlcParams() { if(cjTimer2!=null) { cjTimer2.cancel(); } cjTimer2 = new Timer(); cjTimer2.schedule(new TimerTask() { public void run() { try{ PlcUtil.getParamDyDl(s7PLC); }catch (Exception e){ e.printStackTrace(); } try{ PlcUtil.getTipLife(s7PLC); }catch (Exception e){ e.printStackTrace(); } } }, 1000,500); } //读配置文件 private static void readProperty() throws IOException{ Properties pro = ConfigLoader.loadProperties(); mes_gw = pro.getProperty("mes.gw").trim(); // mes_gw_des = pro.getProperty("mes.gw_des"); mes_server_ip = pro.getProperty("mes.server_ip").trim(); 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").trim(); mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw); System.out.println(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle); } // 初始化TCP public static void initTcpConnection() { try { if(nettyClient==null) { nettyClient = new NettyClient(); tcp_connect_flag = false; 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 JTextField param1; public static JTextField param2; public static JTextField param3; public static JTextField param4; public static JTextField param5; public static JTextField tipLifeA; public static JTextField tipLifeB; public static JTextField tipLifeC; public static volatile boolean tipAlarmAShown = false; public static volatile boolean tipAlarmBShown = false; public static volatile boolean tipAlarmCShown = false; public static int lastTipSyncAActual = Integer.MIN_VALUE; public static int lastTipSyncASet = Integer.MIN_VALUE; public static int lastTipSyncBActual = Integer.MIN_VALUE; public static int lastTipSyncBSet = Integer.MIN_VALUE; public static int lastTipSyncCActual = Integer.MIN_VALUE; public static int lastTipSyncCSet = Integer.MIN_VALUE; public static JTextField product_sn2; public static JTextField param21; public static JTextField param22; public static JTextField param23; public static JTextField param24; public static JTextField param25; // C枪 UI 控件 public static JTextField param31; public static JTextField param32; public static JTextField param33; public static JTextField param34; public static JTextField param35; // D枪 UI 控件 public static JTextField param41; public static JTextField param42; public static JTextField param43; public static JTextField param44; public static JTextField param45; 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) { 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){ // TCP未连接,尝试重连 if(!connect_request_flag) { connect_request_flag = true; DataUtil.synrTcp(nettyClient,mes_gw); } } } } }, 100,mes_heart_icon_cycle*1000); } // 设置TCP连接状态 public static void setTcpStatus() { if(tcp_connect_flag) { status_menu.setText("已连接MES服务器"); heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png"))); heart_beat_menu.repaint(); }else { status_menu.setText("未连接MES服务器"); heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png"))); heart_beat_menu.repaint(); } } public static void initWarehouseData(){ resetScanA(); resetScanB(); PlcUtil.changeEnable(s7PLC,false); } public static void resetScanA() { work_status = 0; check_quality_result = false; MesClient.finish_ok_bt.setEnabled(false); MesClient.mesQualityFlagA = false; product_sn.setText(""); MesClient.pxstatus1.setText("A"); // PlcUtil.changeEnable(s7PLC,false); MesClient.param1.setText(""); MesClient.param2.setText(""); MesClient.param3.setText(""); MesClient.param4.setText(""); MesClient.param5.setText(""); MesClient.param21.setText(""); MesClient.param22.setText(""); MesClient.param23.setText(""); MesClient.param24.setText(""); MesClient.param25.setText(""); // 清空 C枪 数据 if (param31 != null) param31.setText(""); if (param32 != null) param32.setText(""); if (param33 != null) param33.setText(""); if (param34 != null) param34.setText(""); if (param35 != null) param35.setText(""); // 清空 D枪 数据 if (param41 != null) param41.setText(""); if (param42 != null) param42.setText(""); if (param43 != null) param43.setText(""); if (param44 != null) param44.setText(""); if (param45 != null) param45.setText(""); MesClient.curSna = ""; MesClient.tjFlaga = 0; MesClient.checkA = 0; PlcUtil.resetRunDetectA(); MesClient.hjparams = new ArrayList<>(); // MesClient.batch_status = 0; // MesClient.textField.setText(""); // MesClient.batch_scan_1.setEnabled(false); MesClient.formatScanType(1); // PlcUtil.changeEnable(MesClient.s7PLC,false); finish_ok_bt.setEnabled(false); finish_ng_bt.setEnabled(false); updateMaterailData(); // 更新物料 shiftUserCheck(); } public static int userLoginHours;//用户登录所处小时 public static JTextField textField; public static JTextField textField_1; public static JTextField txtfa; public static JLabel scan_type_text; public static JLabel page_text; //换班用户信息检查 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() { work_status2 = 0; check_quality_result2 = false; MesClient.finish_ng_bt.setEnabled(false); MesClient.mesQualityFlagB = false; product_sn2.setText(""); // PlcUtil.changeEnable(s7PLC,false); MesClient.pxstatus2.setText("B"); MesClient.param1.setText(""); MesClient.param2.setText(""); MesClient.param3.setText(""); MesClient.param4.setText(""); MesClient.param5.setText(""); MesClient.param21.setText(""); MesClient.param22.setText(""); MesClient.param23.setText(""); MesClient.param24.setText(""); MesClient.param25.setText(""); // 清空 C枪 数据 if (param31 != null) param31.setText(""); if (param32 != null) param32.setText(""); if (param33 != null) param33.setText(""); if (param34 != null) param34.setText(""); if (param35 != null) param35.setText(""); // 清空 D枪 数据 if (param41 != null) param41.setText(""); if (param42 != null) param42.setText(""); if (param43 != null) param43.setText(""); if (param44 != null) param44.setText(""); if (param45 != null) param45.setText(""); MesClient.curSnb = ""; MesClient.tjFlagb = 0; MesClient.hjparams = new ArrayList<>(); MesClient.checkB = 0; PlcUtil.resetRunDetectB(); // MesClient.batch_status2 = 0; // MesClient.textField_1.setText(""); // MesClient.batch_scan_2.setEnabled(false); MesClient.formatScanType(1); // PlcUtil.changeEnable(MesClient.s7PLC,false); finish_ok_bt2.setEnabled(false); finish_ng_bt2.setEnabled(false); updateMaterailData(); // 更新物料 // shiftUserCheck(); } // 获取用户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; } 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 logoff() { welcomeWin.setVisible(true); mesClientFrame.setVisible(false); 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("MES系统客户端:"+mes_gw + "- " + mes_gw_des); 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("\u7528\u6237"); fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png"))); fileMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20)); menuBar.add(fileMenu); JMenuItem exitMenuItem = new JMenuItem("退出"); exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png"))); exitMenuItem.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22)); fileMenu.add(exitMenuItem); exitMenuItem.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { 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("Microsoft YaHei UI", Font.PLAIN, 20)); menuBar.add(settingMenu); JMenuItem resetTcpMenu = new JMenuItem("\u91CD\u8FDEMES"); resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png"))); resetTcpMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20)); resetTcpMenu.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { super.mouseClicked(e); nettyClient.future.channel().close(); } }); settingMenu.add(resetTcpMenu); JMenuItem resetTcpMenu_1 = new JMenuItem("\u91CD\u65B0\u626B\u7801-A"); resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png"))); resetTcpMenu_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20)); resetTcpMenu_1.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { super.mouseClicked(e); resetScanA(); PlcUtil.changeEnable(s7PLC,false); } }); settingMenu.add(resetTcpMenu_1); JMenuItem resetTcpMenu_1_1 = new JMenuItem("\u91CD\u65B0\u626B\u7801-B"); resetTcpMenu_1_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png"))); resetTcpMenu_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20)); resetTcpMenu_1_1.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { super.mouseClicked(e); resetScanB(); PlcUtil.changeEnable(s7PLC,false); } }); settingMenu.add(resetTcpMenu_1_1); JMenuItem resetTcpMenu_1sd = new JMenuItem("手动提交-A"); resetTcpMenu_1sd.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png"))); resetTcpMenu_1sd.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20)); resetTcpMenu_1sd.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { super.mouseClicked(e); // finish_ok_bt.setEnabled(true); // finish_ng_bt.setEnabled(true); // MesClient.finish_ok_bt.setEnabled(true); // if(MesClient.mesQualityFlagA == 1){ // Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn.getText(),"OK",MesClient.user20,"A"); // if(!sendret){ // MesClient.pxstatus1.setText("A:结果上传MES失败"); // MesClient.tjStatusa = 1; // } // } } }); // settingMenu.add(resetTcpMenu_1sd); JMenuItem resetTcpMenu_1_1sd = new JMenuItem("手动提交-B"); resetTcpMenu_1_1sd.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png"))); resetTcpMenu_1_1sd.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20)); resetTcpMenu_1_1sd.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { super.mouseClicked(e); finish_ok_bt2.setEnabled(true); finish_ng_bt2.setEnabled(true); // MesClient.finish_ng_bt.setEnabled(true); // Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn2.getText(),"OK",MesClient.user20,"B"); // if(!sendret){ // MesClient.pxstatus2.setText("B:结果上传MES失败"); // MesClient.tjStatusb = 1; // } } }); // settingMenu.add(resetTcpMenu_1_1sd); 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("\u72B6\u6001\uFF1A"); equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER); equipment_statu_label.setForeground(Color.BLACK); equipment_statu_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20)); equipment_statu_label.setBackground(Color.LIGHT_GRAY); toolBar.add(equipment_statu_label); status_menu = new JButton("设备未连接MES服务器"); if(tcp_connect_flag) { status_menu.setText("已连接MES服务器"); status_menu.setForeground(Color.GREEN); }else { status_menu.setText("未连接MES服务器"); 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("Microsoft YaHei UI", 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("\u5FC3\u8DF3\uFF1A"); heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER); heart_beat_status_label.setForeground(Color.BLACK); heart_beat_status_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20)); heart_beat_status_label.setBackground(Color.LIGHT_GRAY); toolBar.add(heart_beat_status_label); heart_beat_menu = new JButton("2024-02-20 23:20:10"); 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("Microsoft YaHei UI", 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("\u767B\u5F55\u7528\u6237\uFF1A"); user_status_label.setHorizontalAlignment(SwingConstants.CENTER); user_status_label.setForeground(Color.BLACK); user_status_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20)); user_status_label.setBackground(Color.LIGHT_GRAY); toolBar.add(user_status_label); user_menu = new JButton("JinJuShi"); user_menu.setForeground(Color.GREEN); user_menu.setFont(new Font("Microsoft YaHei UI", 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.setMinimumSize(new Dimension(400, 50)); tabbedPane.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 22)); contentPane.add(tabbedPane); indexPanelA = new JPanel(); indexPanelA.setLayout(null); indexPanelA.setPreferredSize(new Dimension(1000, 1000)); indexScrollPaneA = new JScrollPane(indexPanelA); indexScrollPaneA.getVerticalScrollBar().setUnitIncrement(20); indexScrollPaneA.setBorder(null); // --- 初始化内容 --- product_sn = new JTextField(); product_sn.setText(""); product_sn.setHorizontalAlignment(SwingConstants.CENTER); product_sn.setEditable(false); product_sn.setBorder(UIManager.getBorder("TextField.border")); // 显式设置边框 product_sn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22)); product_sn.setBounds(26, 152, 446, 70); indexPanelA.add(product_sn); product_sn.setColumns(10); // String[] hjtitles = new String[]{"閻掑﹥婧�1","閻掑﹥婧�2","閻掑﹥婧�3"}; // String[] hjvals = new String[]{"HJ001","HJ002","HJ003"}; // mesRadioHj = new MesRadio(hjtitles,hjvals); // mesRadioHj.setSize(500,50); // mesRadioHj.setBounds(190,170,500,50); // indexPanelA.add(mesRadioHj); finish_ok_bt = new JButton("OK"); finish_ok_bt.setEnabled(false); finish_ok_bt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // if(work_status == 1 && check_quality_result){ // // // } String sn = getBarcode(product_sn.getText()); getUser(); if(!sn.isEmpty()){ String qret = "OK"; Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"A"); if(!sendret){ MesClient.pxstatus1.setText("A:结果上传MES失败"); MesClient.tjStatusa = 1; }else{ MesClient.pxstatus1.setText("A:提交成功"); MesClient.status_menu.setText("A件提交成功"); MesClient.resetScanA(); MesClient.notifyWorkSubmitted(); } } } }); finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png"))); finish_ok_bt.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32)); finish_ok_bt.setBounds(50, 700, 160, 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) { // if(work_status == 1 && check_quality_result){ // // String sn = getBarcode(product_sn.getText()); // getUser(); // String qret = "OK"; // Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B"); // if(!sendret){ // JOptionPane.showMessageDialog(mesClientFrame,"上传MES失败,请重试","提醒", JOptionPane.INFORMATION_MESSAGE); // return; // } // } String sn = getBarcode(product_sn2.getText()); getUser(); if(!sn.isEmpty()){ String qret = "OK"; Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B"); if(!sendret){ MesClient.pxstatus2.setText("B:结果上传MES失败"); MesClient.tjStatusb = 1; }else{ MesClient.pxstatus2.setText("B:提交成功"); MesClient.status_menu.setText("B件提交成功"); MesClient.resetScanB(); MesClient.notifyWorkSubmitted(); } } } }); finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png"))); finish_ng_bt.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32)); finish_ng_bt.setBounds(280, 700, 160, 80); finish_ng_bt.setEnabled(false); // indexPanelA.add(finish_ng_bt); finish_ok_bt2 = new JButton("OK"); finish_ok_bt2.setEnabled(false); finish_ok_bt2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // if(work_status == 1 && check_quality_result){ // // // } String sn = getBarcode(product_sn.getText()); getUser(); if(!sn.isEmpty()){ String qret = "OK"; Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B"); if(!sendret){ MesClient.pxstatus2.setText("B:结果上传MES失败"); MesClient.tjStatusb = 1; }else{ MesClient.pxstatus2.setText("B:提交成功"); MesClient.status_menu.setText("B件提交成功"); MesClient.resetScanB(); MesClient.notifyWorkSubmitted(); } } } }); finish_ok_bt2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png"))); finish_ok_bt2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32)); finish_ok_bt2.setBounds(550, 700, 160, 80); finish_ok_bt2.setEnabled(false); // indexPanelA.add(finish_ok_bt2); finish_ng_bt2 = new JButton("NG"); finish_ng_bt2.setEnabled(false); finish_ng_bt2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // if(work_status == 1 && check_quality_result){ // // String sn = getBarcode(product_sn.getText()); // getUser(); // String qret = "OK"; // Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B"); // if(!sendret){ // JOptionPane.showMessageDialog(mesClientFrame,"上传MES失败,请重试","提醒", JOptionPane.INFORMATION_MESSAGE); // return; // } // } String sn = getBarcode(product_sn2.getText()); getUser(); if(!sn.isEmpty()){ String qret = "NG"; Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B"); if(!sendret){ MesClient.pxstatus2.setText("B:结果上传MES失败"); MesClient.tjStatusb = 1; }else{ MesClient.pxstatus2.setText("B:提交成功"); MesClient.status_menu.setText("B件提交成功"); MesClient.resetScanB(); MesClient.notifyWorkSubmitted(); } } } }); finish_ng_bt2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png"))); finish_ng_bt2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32)); finish_ng_bt2.setBounds(780, 700, 160, 80); finish_ng_bt2.setEnabled(false); // indexPanelA.add(finish_ng_bt2); product_sn2 = new JTextField(); product_sn2.setText(""); product_sn2.setHorizontalAlignment(SwingConstants.CENTER); product_sn2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22)); product_sn2.setEditable(false); product_sn2.setBorder(UIManager.getBorder("TextField.border")); // 显式设置边框 product_sn2.setColumns(10); product_sn2.setBounds(517, 152, 446, 70); indexPanelA.add(product_sn2); // --- A枪 区域 --- JLabel lblA_Title = new JLabel("焊枪 A"); lblA_Title.setFont(new Font("微软雅黑", Font.BOLD, 22)); lblA_Title.setBounds(26, 260, 100, 40); indexPanelA.add(lblA_Title); JLabel lblNewLabel = new JLabel("电压"); lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblNewLabel.setBounds(26, 300, 80, 40); indexPanelA.add(lblNewLabel); param1 = new JTextField(); param1.setEnabled(false); param1.setEditable(false); param1.setHorizontalAlignment(SwingConstants.CENTER); param1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param1.setBounds(116, 300, 70, 40); indexPanelA.add(param1); JLabel lblNewLabel_1 = new JLabel("电流"); lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblNewLabel_1.setBounds(206, 300, 80, 40); indexPanelA.add(lblNewLabel_1); param2 = new JTextField(); param2.setEnabled(false); param2.setEditable(false); param2.setHorizontalAlignment(SwingConstants.CENTER); param2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param2.setBounds(296, 300, 70, 40); indexPanelA.add(param2); JLabel lblNewLabel_2 = new JLabel("送丝"); lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblNewLabel_2.setBounds(26, 350, 80, 40); indexPanelA.add(lblNewLabel_2); param3 = new JTextField(); param3.setEnabled(false); param3.setEditable(false); param3.setHorizontalAlignment(SwingConstants.CENTER); param3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param3.setBounds(116, 350, 70, 40); indexPanelA.add(param3); JLabel lblNewLabel_1_1 = new JLabel("错误"); lblNewLabel_1_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblNewLabel_1_1.setBounds(206, 350, 80, 40); indexPanelA.add(lblNewLabel_1_1); param4 = new JTextField(); param4.setEnabled(false); param4.setEditable(false); param4.setHorizontalAlignment(SwingConstants.CENTER); param4.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param4.setBounds(296, 350, 70, 40); indexPanelA.add(param4); JLabel lblNewLabel_1_1_1 = new JLabel("JOB号"); lblNewLabel_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblNewLabel_1_1_1.setBounds(106, 400, 80, 40); indexPanelA.add(lblNewLabel_1_1_1); param5 = new JTextField(); param5.setEnabled(false); param5.setEditable(false); param5.setHorizontalAlignment(SwingConstants.CENTER); param5.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param5.setBounds(196, 400, 70, 40); indexPanelA.add(param5); JLabel lblTipA = new JLabel("导电嘴"); lblTipA.setHorizontalAlignment(SwingConstants.RIGHT); lblTipA.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16)); lblTipA.setBounds(276, 400, 70, 40); indexPanelA.add(lblTipA); tipLifeA = new JTextField("0/0"); tipLifeA.setEnabled(false); tipLifeA.setEditable(false); tipLifeA.setHorizontalAlignment(SwingConstants.CENTER); tipLifeA.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 16)); tipLifeA.setBounds(356, 400, 110, 40); tipLifeA.setToolTipText("实际数量/设定数量"); indexPanelA.add(tipLifeA); // --- B枪 区域 --- JLabel lblB_Title = new JLabel("焊枪 B"); lblB_Title.setFont(new Font("微软雅黑", Font.BOLD, 22)); lblB_Title.setBounds(517, 260, 100, 40); indexPanelA.add(lblB_Title); JLabel lblNewLabel_3 = new JLabel("电压"); lblNewLabel_3.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblNewLabel_3.setBounds(517, 300, 80, 40); indexPanelA.add(lblNewLabel_3); param21 = new JTextField(); param21.setEnabled(false); param21.setEditable(false); param21.setHorizontalAlignment(SwingConstants.CENTER); param21.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param21.setBounds(607, 300, 70, 40); indexPanelA.add(param21); JLabel lblNewLabel_1_2 = new JLabel("电流"); lblNewLabel_1_2.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_1_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblNewLabel_1_2.setBounds(697, 300, 80, 40); indexPanelA.add(lblNewLabel_1_2); param22 = new JTextField(); param22.setEnabled(false); param22.setEditable(false); param22.setHorizontalAlignment(SwingConstants.CENTER); param22.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param22.setBounds(787, 300, 70, 40); indexPanelA.add(param22); JLabel lblNewLabel_2_1 = new JLabel("送丝"); lblNewLabel_2_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_2_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblNewLabel_2_1.setBounds(517, 350, 80, 40); indexPanelA.add(lblNewLabel_2_1); param23 = new JTextField(); param23.setEnabled(false); param23.setEditable(false); param23.setHorizontalAlignment(SwingConstants.CENTER); param23.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param23.setBounds(607, 350, 70, 40); indexPanelA.add(param23); JLabel lblNewLabel_1_1_2 = new JLabel("错误"); lblNewLabel_1_1_2.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_1_1_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblNewLabel_1_1_2.setBounds(697, 350, 80, 40); indexPanelA.add(lblNewLabel_1_1_2); param24 = new JTextField(); param24.setEnabled(false); param24.setEditable(false); param24.setHorizontalAlignment(SwingConstants.CENTER); param24.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param24.setBounds(787, 350, 70, 40); indexPanelA.add(param24); JLabel lblNewLabel_1_1_1_1 = new JLabel("JOB号"); lblNewLabel_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT); lblNewLabel_1_1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblNewLabel_1_1_1_1.setBounds(597, 400, 80, 40); indexPanelA.add(lblNewLabel_1_1_1_1); param25 = new JTextField(); param25.setEnabled(false); param25.setEditable(false); param25.setHorizontalAlignment(SwingConstants.CENTER); param25.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param25.setBounds(687, 400, 70, 40); indexPanelA.add(param25); JLabel lblTipB = new JLabel("导电嘴"); lblTipB.setHorizontalAlignment(SwingConstants.RIGHT); lblTipB.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16)); lblTipB.setBounds(767, 400, 70, 40); indexPanelA.add(lblTipB); tipLifeB = new JTextField("0/0"); tipLifeB.setEnabled(false); tipLifeB.setEditable(false); tipLifeB.setHorizontalAlignment(SwingConstants.CENTER); tipLifeB.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 16)); tipLifeB.setBounds(847, 400, 110, 40); tipLifeB.setToolTipText("实际数量/设定数量"); indexPanelA.add(tipLifeB); // --- C枪 区域 --- JLabel lblC_Title = new JLabel("焊枪 C"); lblC_Title.setFont(new Font("微软雅黑", Font.BOLD, 22)); lblC_Title.setBounds(26, 480, 100, 40); indexPanelA.add(lblC_Title); JLabel lblDyC = new JLabel("电压"); lblDyC.setHorizontalAlignment(SwingConstants.RIGHT); lblDyC.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblDyC.setBounds(26, 520, 80, 40); indexPanelA.add(lblDyC); param31 = new JTextField(); param31.setEditable(false); param31.setHorizontalAlignment(SwingConstants.CENTER); param31.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param31.setBounds(116, 520, 70, 40); indexPanelA.add(param31); JLabel lblDlC = new JLabel("电流"); lblDlC.setHorizontalAlignment(SwingConstants.RIGHT); lblDlC.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblDlC.setBounds(206, 520, 80, 40); indexPanelA.add(lblDlC); param32 = new JTextField(); param32.setEditable(false); param32.setHorizontalAlignment(SwingConstants.CENTER); param32.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param32.setBounds(296, 520, 70, 40); indexPanelA.add(param32); JLabel lblSsC = new JLabel("送丝"); lblSsC.setHorizontalAlignment(SwingConstants.RIGHT); lblSsC.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblSsC.setBounds(26, 570, 80, 40); indexPanelA.add(lblSsC); param33 = new JTextField(); param33.setEditable(false); param33.setHorizontalAlignment(SwingConstants.CENTER); param33.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param33.setBounds(116, 570, 70, 40); indexPanelA.add(param33); JLabel lblCwC = new JLabel("错误"); lblCwC.setHorizontalAlignment(SwingConstants.RIGHT); lblCwC.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblCwC.setBounds(206, 570, 80, 40); indexPanelA.add(lblCwC); param34 = new JTextField(); param34.setEditable(false); param34.setHorizontalAlignment(SwingConstants.CENTER); param34.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param34.setBounds(296, 570, 70, 40); indexPanelA.add(param34); JLabel lblJobC = new JLabel("JOB号"); lblJobC.setHorizontalAlignment(SwingConstants.RIGHT); lblJobC.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblJobC.setBounds(106, 620, 80, 40); indexPanelA.add(lblJobC); param35 = new JTextField(); param35.setEditable(false); param35.setHorizontalAlignment(SwingConstants.CENTER); param35.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param35.setBounds(196, 620, 70, 40); indexPanelA.add(param35); JLabel lblTipC = new JLabel("导电嘴"); lblTipC.setHorizontalAlignment(SwingConstants.RIGHT); lblTipC.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16)); lblTipC.setBounds(276, 620, 70, 40); indexPanelA.add(lblTipC); tipLifeC = new JTextField("0/0"); tipLifeC.setEnabled(false); tipLifeC.setEditable(false); tipLifeC.setHorizontalAlignment(SwingConstants.CENTER); tipLifeC.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 16)); tipLifeC.setBounds(356, 620, 110, 40); tipLifeC.setToolTipText("实际数量/设定数量"); indexPanelA.add(tipLifeC); // --- D枪 区域 --- JLabel lblD_Title = new JLabel("焊枪 D"); lblD_Title.setFont(new Font("微软雅黑", Font.BOLD, 22)); lblD_Title.setBounds(517, 480, 100, 40); // indexPanelA.add(lblD_Title); JLabel lblDyD = new JLabel("电压"); lblDyD.setHorizontalAlignment(SwingConstants.RIGHT); lblDyD.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblDyD.setBounds(517, 520, 80, 40); // indexPanelA.add(lblDyD); param41 = new JTextField(); param41.setEditable(false); param41.setHorizontalAlignment(SwingConstants.CENTER); param41.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param41.setBounds(607, 520, 70, 40); // indexPanelA.add(param41); JLabel lblDlD = new JLabel("电流"); lblDlD.setHorizontalAlignment(SwingConstants.RIGHT); lblDlD.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblDlD.setBounds(697, 520, 80, 40); // indexPanelA.add(lblDlD); param42 = new JTextField(); param42.setEditable(false); param42.setHorizontalAlignment(SwingConstants.CENTER); param42.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param42.setBounds(787, 520, 70, 40); // indexPanelA.add(param42); JLabel lblSsD = new JLabel("送丝"); lblSsD.setHorizontalAlignment(SwingConstants.RIGHT); lblSsD.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblSsD.setBounds(517, 570, 80, 40); // indexPanelA.add(lblSsD); param43 = new JTextField(); param43.setEditable(false); param43.setHorizontalAlignment(SwingConstants.CENTER); param43.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param43.setBounds(607, 570, 70, 40); // indexPanelA.add(param43); JLabel lblCwD = new JLabel("错误"); lblCwD.setHorizontalAlignment(SwingConstants.RIGHT); lblCwD.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblCwD.setBounds(697, 570, 80, 40); // indexPanelA.add(lblCwD); param44 = new JTextField(); param44.setEditable(false); param44.setHorizontalAlignment(SwingConstants.CENTER); param44.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param44.setBounds(787, 570, 70, 40); // indexPanelA.add(param44); JLabel lblJobD = new JLabel("JOB号"); lblJobD.setHorizontalAlignment(SwingConstants.RIGHT); lblJobD.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); lblJobD.setBounds(597, 620, 80, 40); // indexPanelA.add(lblJobD); param45 = new JTextField(); param45.setEditable(false); param45.setHorizontalAlignment(SwingConstants.CENTER); param45.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18)); param45.setBounds(687, 620, 70, 40); // indexPanelA.add(param45); pxstatus1 = new JLabel("A"); pxstatus1.setForeground(new Color(255, 128, 64)); pxstatus1.setHorizontalAlignment(SwingConstants.CENTER); pxstatus1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20)); pxstatus1.setBounds(26, 98, 446, 44); indexPanelA.add(pxstatus1); pxstatus2 = new JLabel("B"); pxstatus2.setForeground(new Color(255, 128, 64)); pxstatus2.setHorizontalAlignment(SwingConstants.CENTER); pxstatus2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20)); pxstatus2.setBounds(517, 98, 446, 44); indexPanelA.add(pxstatus2); JSeparator separator_2 = new JSeparator(); separator_2.setBounds(10, 264, 973, 13); // indexPanelA.add(separator_2); JLabel lblNewLabel_4 = new JLabel("\u710A\u67331"); lblNewLabel_4.setHorizontalAlignment(SwingConstants.CENTER); lblNewLabel_4.setFont(new Font("微软雅黑", Font.PLAIN, 24)); lblNewLabel_4.setBounds(170, 290, 156, 40); lblNewLabel_4.setVisible(false); // indexPanelA.add(lblNewLabel_4); JLabel lblNewLabel_4_1 = new JLabel("\u710A\u67332"); lblNewLabel_4_1.setHorizontalAlignment(SwingConstants.CENTER); lblNewLabel_4_1.setFont(new Font("微软雅黑", Font.PLAIN, 24)); lblNewLabel_4_1.setBounds(670, 287, 156, 40); lblNewLabel_4_1.setVisible(false); // indexPanelA.add(lblNewLabel_4_1); JSeparator separator_1_1 = new JSeparator(); separator_1_1.setOrientation(SwingConstants.VERTICAL); separator_1_1.setBounds(495, 278, 23, 400); // 增加高度以覆盖 C/D 枪 indexPanelA.add(separator_1_1); textField = new JTextField(); textField.setText(""); textField.setHorizontalAlignment(SwingConstants.CENTER); textField.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22)); textField.setEditable(false); textField.setColumns(10); textField.setBounds(26, 333, 446, 70); // indexPanelA.add(textField); batch_scan_1 = new JButton("解绑"); batch_scan_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/delete.png"))); batch_scan_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32)); batch_scan_1.setEnabled(false); batch_scan_1.setVisible(false); batch_scan_1.setBounds(136, 430, 230, 80); batch_scan_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(MesClient.curPage.equals("B")){ MesClient.setMenuStatus("该状态后梁无法解绑",-1); }else{ String sn = MesClient.product_sn.getText().trim(); String wsn = MesClient.textField.getText().trim(); JSONObject retObj = DataUtil.unBindWarehouseData(sn,wsn,user_menu.getText().trim(),"400007"); if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) { MesClient.setMenuStatus("后梁码解绑成功",0); MesClient.formatScanType(2); textField.setText(""); batch_scan_1.setEnabled(false); PlcUtil.changeEnable(s7PLC,false); }else{ MesClient.formatScanType(2); batch_scan_1.setEnabled(true); if(retObj.get("result")==null){ MesClient.setMenuStatus("请求失败,后梁码解绑失败,请重试",-1); }else{ if(retObj.get("result").toString().equalsIgnoreCase("false")){ MesClient.setMenuStatus(retObj.getString("message"),-1); } } } } } }); indexPanelA.add(batch_scan_1); textField_1 = new JTextField(); textField_1.setText(""); textField_1.setHorizontalAlignment(SwingConstants.CENTER); textField_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22)); textField_1.setEditable(false); textField_1.setColumns(10); textField_1.setBounds(517, 333, 446, 70); // indexPanelA.add(textField_1); batch_scan_2 = new JButton("解绑"); batch_scan_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/delete.png"))); batch_scan_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32)); batch_scan_2.setEnabled(false); batch_scan_2.setVisible(false); batch_scan_2.setBounds(633, 430, 230, 80); batch_scan_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(MesClient.curPage.equals("A")){ MesClient.setMenuStatus("该状态后梁无法解绑",-1); }else{ String sn = MesClient.product_sn2.getText().trim(); String wsn = MesClient.textField_1.getText().trim(); JSONObject retObj = DataUtil.unBindWarehouseData(sn,wsn,user_menu.getText().trim(),"400007"); if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) { MesClient.setMenuStatus("后梁码解绑成功",0); MesClient.formatScanType(2); textField_1.setText(""); batch_scan_2.setEnabled(false); PlcUtil.changeEnable(s7PLC,false); }else{ if(retObj.get("result")==null){ MesClient.setMenuStatus("请求失败,前梁码解绑失败,请重试",-1); }else{ if(retObj.get("result").toString().equalsIgnoreCase("false")){ MesClient.setMenuStatus(retObj.getString("message"),-1); } } } } } }); indexPanelA.add(batch_scan_2); JLabel pxstatus1_1 = new JLabel("A后梁"); pxstatus1_1.setHorizontalAlignment(SwingConstants.CENTER); pxstatus1_1.setForeground(new Color(0, 0, 0)); pxstatus1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20)); pxstatus1_1.setBounds(26, 283, 446, 44); // indexPanelA.add(pxstatus1_1); JLabel pxstatus1_1_1 = new JLabel("B后梁"); pxstatus1_1_1.setHorizontalAlignment(SwingConstants.CENTER); pxstatus1_1_1.setForeground(Color.BLACK); pxstatus1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20)); pxstatus1_1_1.setBounds(517, 283, 446, 44); // indexPanelA.add(pxstatus1_1_1); txtfa = new JTextField(); txtfa.setHorizontalAlignment(SwingConstants.LEFT); txtfa.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22)); txtfa.setColumns(10); txtfa.setBounds(239, 10, 503, 60); indexPanelA.add(txtfa); txtfa.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scanBarcode(); } }); page_text = new JLabel("当前:A面"); page_text.setForeground(new Color(0, 255, 64)); page_text.setFont(new Font("微软雅黑", Font.PLAIN, 20)); page_text.setHorizontalAlignment(SwingConstants.RIGHT); page_text.setBounds(97, 10, 132, 60); indexPanelA.add(page_text); scan_type_text = new JLabel("镭雕码"); scan_type_text.setForeground(new Color(255, 128, 64)); scan_type_text.setHorizontalAlignment(SwingConstants.LEFT); scan_type_text.setFont(new Font("微软雅黑", Font.PLAIN, 20)); scan_type_text.setBounds(752, 10, 132, 60); indexPanelA.add(scan_type_text); tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null); tabbedPane.setEnabledAt(0, true); JPanel indexPanelGz = new JPanel(); searchScrollPaneGz = new JScrollPane(indexPanelGz); indexPanelGz.setLayout(null); indexPanelC = new JPanel(); searchScrollPaneDj = new JScrollPane(indexPanelC); indexPanelC.setLayout(null); tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null); indexPanelB = new JPanel(); searchScrollPane = new JScrollPane(indexPanelB); indexPanelB.setLayout(null); tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null); // bindBatchPanel(); tabbedPane.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JTabbedPane tabbedPane = (JTabbedPane) e.getSource(); int selectedIndex = tabbedPane.getSelectedIndex(); System.out.println("selectedIndex:"+selectedIndex); if(selectedIndex == TAB_WORK_RECORD){ refreshWorkRecord(); } } }); } public static void formatScanType(int st){ scan_type = st; if(scan_type == 1){ scan_type_text.setText("镭雕码"); }else if(scan_type == 2){ scan_type_text.setText("后梁码"); }else{ scan_type_text.setText(""); } } public static void scanBarcode() { String scanBarcodeSn = txtfa.getText().trim(); txtfa.setText(""); System.out.println("scan_type:"+scan_type); //刷新界面 mesClientFrame.repaint(); System.out.println("456"); System.out.println("156"+scan_type); if(MesClient.scan_type == 1){ // 镭雕码 System.out.println("type1"); if(scanBarcodeSn.isEmpty()){ System.out.println("type2"); MesClient.setMenuStatus("镭雕码不能为空",1); return; } if(MesClient.curPage.equals("A")){ System.out.println("typeA"); MesClient.lastScanSide = "A"; if(!product_sn.getText().isEmpty() && mesQualityFlagA){ MesClient.setMenuStatus("A面已存在工件码,勿重复扫码",1); return; } product_sn.setText(scanBarcodeSn); }else{ System.out.println("typeB"); MesClient.lastScanSide = "B"; if(!product_sn2.getText().isEmpty() && mesQualityFlagB){ MesClient.setMenuStatus("B面已存在工件码,勿重复扫码",1); return; } product_sn2.setText(scanBarcodeSn); } MesClient.setMenuStatus("扫码成功",0); //刷新界面 mesClientFrame.repaint(); System.out.println("123"); getUser(); // 查询工件质量 Boolean sendret = DataUtil.checkQuality(nettyClient,scanBarcodeSn,user20,MesClient.lastScanSide); if(!sendret){ MesClient.setMenuStatus("消息发送失败,请重试",1); } } } 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 getMaterailData(){ JSONObject retObj = DataUtil.getBindMaterail(); if (retObj == null) { log.warn("加载物料列表失败,请检查MES服务或网络连接"); return; } if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) { List arrs = retObj.getList("data",BindMaterialResp.class); if (arrs == null || arrs.isEmpty()) { return; } int i = 0; rowData = new Object[arrs.size()][7]; for (BindMaterialResp bindMaterialResp:arrs){ rowData[i][0] = bindMaterialResp.getMaterialTitle(); rowData[i][1] = bindMaterialResp.getBatchSn(); rowData[i][2] = bindMaterialResp.getLastTimes(); rowData[i][3] = ""; rowData[i][4] = bindMaterialResp.getCraft(); rowData[i][5] = bindMaterialResp.getMaterialId(); rowData[i][6] = bindMaterialResp.getType(); i++; } bindBatchPanel(); } } public static void updateMaterailData(){ JSONObject retObj = DataUtil.getBindMaterail(); if (retObj == null) { log.warn("更新物料列表失败,请检查MES服务或网络连接"); return; } if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) { List arrs = retObj.getList("data",BindMaterialResp.class); if (arrs == null || arrs.isEmpty() || rowData == null) { return; } int i = 0; for (BindMaterialResp bindMaterialResp:arrs){ rowData[i][0] = bindMaterialResp.getMaterialTitle(); rowData[i][1] = bindMaterialResp.getBatchSn(); rowData[i][2] = bindMaterialResp.getLastTimes(); rowData[i][3] = ""; rowData[i][4] = bindMaterialResp.getCraft(); rowData[i][5] = bindMaterialResp.getMaterialId(); rowData[i][6] = bindMaterialResp.getType(); i++; } MesClient.table.repaint(); } } // 绑定物料批次码 public static void scanBatchSn(BindMaterialResp bindMaterialResp) { // 扫码类型 //弹窗扫工件码 String scanBarcodeTitle = "请扫物料:"+bindMaterialResp.getMaterialTitle(); String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle); if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) { JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType()); if (retObj == null) { MesClient.setMenuStatus("请求失败,请重试",-1); return; } if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) { MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0); updateMaterailData(); }else{ if(retObj.get("result")==null){ MesClient.setMenuStatus("请求失败,请重试",-1); }else{ if(retObj.get("result").toString().equalsIgnoreCase("false")){ MesClient.setMenuStatus(retObj.getString("message"),-1); } } } } } public static void bindBatchPanel(){ JPanel indexPanelBB = new JPanel(); JPanel panel = new JPanel(); panel.setBounds(0, 0, 990, 550); // panel.setBounds(81, 50, 810, 479); indexPanelBB.add(panel); panel.setLayout(new GridLayout(0, 1, 0, 0)); table = new JTable(rowData, columnNames){ public boolean isCellEditable(int row, int column) { if(column == 3){ return true; } return false; } }; 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()); JScrollPane scrollPane = new JScrollPane(table); panel.add(scrollPane); indexScrollPaneB = new JScrollPane(indexPanelBB); indexPanelBB.setLayout(null); tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null); } // 开启发送结果定时任务 public static void startUpdateQualityTimer(){ new Timer().schedule(new TimerTask() { @Override public void run() { try { JdbcUtils.getConn(); Statement statement = JdbcUtils.conn.createStatement(); String selectSql = "SELECT id, bw FROM submit_record\n" + "WHERE state = 0 ORDER BY id DESC LIMIT 10"; String updateSql = "UPDATE submit_record \n" + "SET state = '1'\n" + "WHERE id = "; ResultSet rs = statement.executeQuery(selectSql); while(rs.next()){ int id = rs.getInt("id"); String bw = rs.getString("bw"); // 发送请求 String url = "http://"+MesClient.mes_server_ip+":8980/js/a/mes/mesProductRecord/updateQualityByTiming"; String s = HttpUtils.sendPostRequestJson(url, bw ); Boolean result = JSONObject.parseObject(s).getBoolean("result"); if(result) { // 更改状态为 1 statement.executeUpdate(updateSql + id); } } rs.close(); statement.close(); } catch (SQLException | IOException e) { // throw new RuntimeException(e); e.printStackTrace(); } } },1000, 5000); } public static void formatBatchSn(){ if((MesClient.batch_status == 1 && MesClient.tjFlaga == 1) || (MesClient.batch_status2 == 1 && MesClient.tjFlagb == 1)){ PlcUtil.changeEnable(MesClient.s7PLC,true); }else{ PlcUtil.changeEnable(MesClient.s7PLC,false); } } private static String checkSnType(String sn){ String str = sn.substring(9,12); if(str.equals("113")){ return "MX11-2"; }else if(str.equals("119")){ return "MX11-2S"; }else{ return ""; } } // 检查工件是否匹配 private static Boolean checkSnAndBatch(String sn,String batchSn){ String gdStr1 = "151245P000012131001000"; // MX11-2 String gdStr2 = "151245P000017812001000"; // MX11-2S String cate = sn.substring(0,22); String ptype = checkSnType(batchSn); if(ptype.equals("MX11-2") && cate.equals(gdStr1)){ return true; } if(ptype.equals("MX11-2S") && cate.equals(gdStr2)){ return true; } return false; } }