|
|
@@ -2,13 +2,13 @@ package com.mes.ui;
|
|
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.mes.component.GunPanel;
|
|
|
import com.mes.component.MesRadio;
|
|
|
import com.mes.component.MesWebView;
|
|
|
import com.mes.netty.NettyClient;
|
|
|
import com.mes.util.DateLocalUtils;
|
|
|
import com.mes.util.JdbcUtils;
|
|
|
-import com.mes.ygsl.YgslClient;
|
|
|
-import com.mes.ygsl.YgslClient2;
|
|
|
+import com.mes.ygsl.YgslConfig;
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
import io.netty.buffer.Unpooled;
|
|
|
import javafx.embed.swing.JFXPanel;
|
|
|
@@ -91,45 +91,13 @@ public class MesClient extends JFrame {
|
|
|
public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
|
|
|
public static Object[][] rowData = null;
|
|
|
|
|
|
- //TCP连接
|
|
|
- public static YgslClient ygslClient;
|
|
|
- //TCP连接状态
|
|
|
- public static boolean ygsl_tcp_connect_flag = false;
|
|
|
- //TCP连接请求
|
|
|
- public static boolean ygsl_connect_request_flag = false;
|
|
|
-
|
|
|
- //TCP连接
|
|
|
- public static YgslClient2 ygslClient2;
|
|
|
- //TCP连接状态
|
|
|
- public static boolean ygsl_tcp_connect_flag2 = false;
|
|
|
- //TCP连接请求
|
|
|
- public static boolean ygsl_connect_request_flag2 = false;
|
|
|
-
|
|
|
- public static Integer ygslNum = 1; // 1=单枪 2=双枪
|
|
|
-
|
|
|
-
|
|
|
- public static String namea = "A"; // A枪名称 M5
|
|
|
- public static Integer maxa = 12; // A枪任务数 360=12 290=89
|
|
|
- public static Integer cura = 0; // A枪当前数
|
|
|
- public static Integer resulta = 0; // A枪结果 0=NG 1=OK
|
|
|
- public static List<String> atids = new ArrayList<>();
|
|
|
- public static List<String> btids = new ArrayList<>();
|
|
|
-
|
|
|
- public static String nameb = "B"; // B枪名称 M8
|
|
|
- public static Integer maxb = 1; // B枪任务数
|
|
|
- public static Integer curb = 0; // B枪当前数
|
|
|
- public static Integer resultb = 0; // B枪结果 0=NG 1=OK
|
|
|
- public static JLabel schedulea;
|
|
|
- public static JLabel scheduleb;
|
|
|
- public static JLabel torquea;
|
|
|
- public static JLabel torqueb;
|
|
|
- public static JLabel anglea;
|
|
|
- public static JLabel angleb;
|
|
|
-
|
|
|
+ public static List<GunPanel> gunPanels = new ArrayList<>();
|
|
|
+ public static JPanel gunPanelContainer;
|
|
|
public static JLabel pzlabel;
|
|
|
|
|
|
- public static JButton ygslm8;
|
|
|
- public static JButton ygslm6;
|
|
|
+ public static java.util.Timer submitCheckTimer;
|
|
|
+
|
|
|
+ public static boolean autoSubmitEnabled = true;
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
@@ -163,6 +131,8 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
checkpz();
|
|
|
|
|
|
+ startSubmitCheckTimer();
|
|
|
+
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
@@ -170,6 +140,88 @@ public class MesClient extends JFrame {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ public static void initGunPanels() {
|
|
|
+ gunPanels.clear();
|
|
|
+
|
|
|
+ System.out.println("initGunPanels - gunPanelContainer: " + gunPanelContainer);
|
|
|
+
|
|
|
+ List<YgslConfig> configs = JdbcUtils.getEnabledYgslConfigs();
|
|
|
+ System.out.println("initGunPanels - 获取到配置: " + configs.size() + " 把枪");
|
|
|
+ for (YgslConfig config : configs) {
|
|
|
+ GunPanel gunPanel = new GunPanel(config);
|
|
|
+ gunPanel.setTaskCompletedListener(new GunPanel.OnTaskCompletedListener() {
|
|
|
+ @Override
|
|
|
+ public void onTaskCompleted(GunPanel panel) {
|
|
|
+ checkAllGunsCompleted();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ gunPanels.add(gunPanel);
|
|
|
+
|
|
|
+ if (gunPanelContainer != null) {
|
|
|
+ gunPanelContainer.add(gunPanel);
|
|
|
+ gunPanelContainer.revalidate();
|
|
|
+ gunPanelContainer.repaint();
|
|
|
+ gunPanel.connect();
|
|
|
+ System.out.println("已添加枪到容器: " + config.getGunName());
|
|
|
+ } else {
|
|
|
+ System.out.println("gunPanelContainer 为空,无法添加!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println("已加载 " + gunPanels.size() + " 把扭力枪");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void startSubmitCheckTimer() {
|
|
|
+ if (submitCheckTimer != null) {
|
|
|
+ submitCheckTimer.cancel();
|
|
|
+ }
|
|
|
+ submitCheckTimer = new Timer();
|
|
|
+ submitCheckTimer.schedule(new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ checkAllGunsCompleted();
|
|
|
+ }
|
|
|
+ }, 1000, 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void checkAllGunsCompleted() {
|
|
|
+ if (work_status != 1 || !check_quality_result) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!autoSubmitEnabled) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean allCompleted = true;
|
|
|
+ for (GunPanel panel : gunPanels) {
|
|
|
+ if (!panel.isTaskCompleted()) {
|
|
|
+ allCompleted = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (allCompleted) {
|
|
|
+ final boolean submitSuccess = submitQualityResult();
|
|
|
+ SwingUtilities.invokeLater(() -> {
|
|
|
+ if (submitSuccess) {
|
|
|
+ setMenuStatus("所有任务完成,结果已提交", 0);
|
|
|
+ resetScanA();
|
|
|
+ scanBarcode();
|
|
|
+ } else {
|
|
|
+ setMenuStatus("结果提交失败,请重试", -1);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean submitQualityResult() {
|
|
|
+ String sn = getBarcode(product_sn.getText());
|
|
|
+ getUser();
|
|
|
+ String qret = "OK";
|
|
|
+ return DataUtil.sendQuality(nettyClient, sn, qret, user20);
|
|
|
+ }
|
|
|
+
|
|
|
//读配置文件
|
|
|
private static void readProperty() throws IOException{
|
|
|
String enconding = "UTF-8";
|
|
|
@@ -270,83 +322,7 @@ public class MesClient extends JFrame {
|
|
|
}
|
|
|
|
|
|
|
|
|
- // 初始化TCP
|
|
|
- public static void initYgslTcpConnection() {
|
|
|
- try {
|
|
|
- if(ygslClient==null) {
|
|
|
- //初始化TCP连接
|
|
|
- ygslClient = new YgslClient();
|
|
|
-// //TCP连接状态
|
|
|
-// ygsl_tcp_connect_flag = false;
|
|
|
-// //设置TCP请求状态
|
|
|
-// ygsl_connect_request_flag = true;
|
|
|
-
|
|
|
- try{
|
|
|
- ygslClient.run();
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(MesClient.ygslNum == 2){
|
|
|
- if(ygslClient2==null) {
|
|
|
- //初始化TCP连接
|
|
|
- ygslClient2 = new YgslClient2();
|
|
|
-// //TCP连接状态
|
|
|
-// ygsl_tcp_connect_flag2 = false;
|
|
|
-// //设置TCP请求状态
|
|
|
-// ygsl_connect_request_flag2 = true;
|
|
|
-
|
|
|
- try{
|
|
|
- ygslClient2.run();
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- // TODO Auto-generated catch block
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //启动心跳包程序
|
|
|
- public static java.util.Timer heartYgslBeatTimer;
|
|
|
- public static java.util.Timer heartYgslBeatIconTimer;
|
|
|
- public static boolean iconYgslREDFlag = true;
|
|
|
public static void startYgslHeartBeatTimer() {
|
|
|
- if(heartYgslBeatTimer!=null) {
|
|
|
- heartYgslBeatTimer.cancel();
|
|
|
- }
|
|
|
- heartYgslBeatTimer = new java.util.Timer();
|
|
|
- heartYgslBeatTimer.schedule(new TimerTask() {
|
|
|
- public void run() {
|
|
|
- if(ygslClient!=null && ygsl_tcp_connect_flag) {
|
|
|
- System.out.println("发送心跳报文ygsl");
|
|
|
- YgslUtil.comHeart(ygslClient);
|
|
|
- }else{
|
|
|
- System.out.println("发送心跳报文ygsl离线");
|
|
|
- MesClient.ygsl_tcp_connect_flag = false;
|
|
|
- MesClient.ygsl_connect_request_flag = true;
|
|
|
- MesClient.ygslClient = null;
|
|
|
- MesClient.initYgslTcpConnection();
|
|
|
- }
|
|
|
-
|
|
|
- if(MesClient.ygslNum == 2){
|
|
|
- if(ygslClient2!=null && ygsl_tcp_connect_flag2) {
|
|
|
- System.out.println("发送心跳报文ygsl2");
|
|
|
- YgslUtil2.comHeart(ygslClient2);
|
|
|
- }else{
|
|
|
- System.out.println("发送心跳报文ygsl2离线");
|
|
|
-
|
|
|
- MesClient.ygsl_tcp_connect_flag2 = false;
|
|
|
- MesClient.ygsl_connect_request_flag2 = true;
|
|
|
- MesClient.ygslClient2 = null;
|
|
|
- MesClient.initYgslTcpConnection();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }, 100,3*1000);
|
|
|
}
|
|
|
|
|
|
//设置tcp连接状态显示
|
|
|
@@ -366,58 +342,6 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
public static java.util.Timer cjTimer5;
|
|
|
public static void deviceOnline() {
|
|
|
- if(cjTimer5!=null) {
|
|
|
- cjTimer5.cancel();
|
|
|
- }
|
|
|
- cjTimer5 = new Timer();
|
|
|
- cjTimer5.schedule(new TimerTask() {
|
|
|
- public void run() {
|
|
|
- try{
|
|
|
- if(ygslClient!=null && ygsl_tcp_connect_flag) {
|
|
|
- ygslm8.setText("扭力枪:在线");
|
|
|
- ygslm8.setBackground(Color.GREEN);
|
|
|
- ygslm8.setForeground(Color.WHITE);
|
|
|
- }else{
|
|
|
- ygslm8.setText("扭力枪:离线");
|
|
|
- ygslm8.setBackground(Color.RED);
|
|
|
- ygslm8.setForeground(Color.WHITE);
|
|
|
- }
|
|
|
-
|
|
|
-// if(ygslClient2!=null && ygsl_tcp_connect_flag2) {
|
|
|
-// ygslm6.setText("M8扭力枪:在线");
|
|
|
-// ygslm6.setBackground(Color.GREEN);
|
|
|
-// ygslm6.setForeground(Color.WHITE);
|
|
|
-// }else{
|
|
|
-// ygslm6.setText("M8扭力枪:离线");
|
|
|
-// ygslm6.setBackground(Color.RED);
|
|
|
-// ygslm6.setForeground(Color.WHITE);
|
|
|
-// }
|
|
|
-
|
|
|
- if(work_status == 1 && pz_status == 1){
|
|
|
- if(MesClient.cura >= MesClient.maxa){
|
|
|
- YgslUtil.disableTool(MesClient.ygslClient);
|
|
|
- }else{
|
|
|
- YgslUtil.enableTool(MesClient.ygslClient);
|
|
|
- }
|
|
|
- if(MesClient.ygslNum == 2){
|
|
|
- if(MesClient.curb >= MesClient.maxb){
|
|
|
- YgslUtil2.disableTool(MesClient.ygslClient2);
|
|
|
- }else{
|
|
|
- YgslUtil2.enableTool(MesClient.ygslClient2);
|
|
|
- }
|
|
|
- }
|
|
|
- }else{
|
|
|
- YgslUtil.disableTool(MesClient.ygslClient);
|
|
|
- if(MesClient.ygslNum == 2){
|
|
|
- YgslUtil2.disableTool(MesClient.ygslClient2);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }, 1000,1000);
|
|
|
}
|
|
|
|
|
|
public static java.util.Timer cjTimer2;
|
|
|
@@ -487,28 +411,18 @@ public class MesClient extends JFrame {
|
|
|
MesClient.f_scan_data_bt_1.setEnabled(true);
|
|
|
MesClient.setMenuStatus("请扫工件码",0);
|
|
|
|
|
|
- atids.clear();
|
|
|
- btids.clear();
|
|
|
-
|
|
|
- MesClient.cura = 0;
|
|
|
- MesClient.curb = 0;
|
|
|
- MesClient.torquea.setText("");
|
|
|
- MesClient.torqueb.setText("");
|
|
|
- MesClient.anglea.setText("");
|
|
|
- MesClient.angleb.setText("");
|
|
|
- MesClient.schedulea.setText(MesClient.cura+"/"+MesClient.maxa);
|
|
|
- MesClient.scheduleb.setText(MesClient.curb+"/"+MesClient.maxb);
|
|
|
+ for (GunPanel panel : gunPanels) {
|
|
|
+ panel.reset();
|
|
|
+ panel.disableTool();
|
|
|
+ }
|
|
|
|
|
|
pzlabel.setVisible(false);
|
|
|
if(mes_gw.equals("OP290")){
|
|
|
- pz_status = 0; // 拍照状态
|
|
|
+ pz_status = 0;
|
|
|
}else{
|
|
|
- pz_status = 1; // 拍照状态
|
|
|
+ pz_status = 1;
|
|
|
}
|
|
|
|
|
|
- YgslUtil.disableTool(ygslClient);
|
|
|
- YgslUtil2.disableTool(ygslClient2);
|
|
|
-
|
|
|
updateMaterailData();
|
|
|
shiftUserCheck();
|
|
|
}
|
|
|
@@ -859,152 +773,11 @@ public class MesClient extends JFrame {
|
|
|
finish_ng_bt.setEnabled(false);
|
|
|
indexPanelA.add(finish_ng_bt);
|
|
|
|
|
|
-
|
|
|
- ygslm8 = new JButton("扭力枪:离线");
|
|
|
- ygslm8.addActionListener(new ActionListener() {
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
-// YgslUtil.comStart(ygslClient);
|
|
|
- MesClient.initYgslTcpConnection();
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- ygslm8.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
- ygslm8.setBounds(30, 171, 160, 40);
|
|
|
- ygslm8.setBackground(Color.RED);
|
|
|
- ygslm8.setForeground(Color.WHITE);
|
|
|
- indexPanelA.add(ygslm8);
|
|
|
-
|
|
|
- ygslm6 = new JButton("M5扭力枪:离线");
|
|
|
- ygslm6.addActionListener(new ActionListener() {
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
-// YgslUtil.comStart(ygslClient);
|
|
|
- MesClient.initYgslTcpConnection();
|
|
|
-// YgslUtil2.jobIdUpload(MesClient.ygslClient2);
|
|
|
- }
|
|
|
- });
|
|
|
- ygslm6.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
- ygslm6.setBounds(30, 221, 160, 40);
|
|
|
- ygslm6.setBackground(Color.RED);
|
|
|
- ygslm6.setForeground(Color.WHITE);
|
|
|
-// indexPanelA.add(ygslm6);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- JButton ygslstart = new JButton("comStart");
|
|
|
- ygslstart.addActionListener(new ActionListener() {
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
-// YgslUtil.comStart(ygslClient);
|
|
|
- YgslUtil.pSet(MesClient.ygslClient);
|
|
|
- }
|
|
|
- });
|
|
|
- ygslstart.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
- ygslstart.setBounds(250, 171, 140, 40);
|
|
|
-// indexPanelA.add(ygslstart);
|
|
|
-
|
|
|
- JButton ygslstop = new JButton("comStop");
|
|
|
- ygslstop.addActionListener(new ActionListener() {
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
-// YgslUtil.comStop(ygslClient);
|
|
|
- YgslUtil.jobIdUpload(MesClient.ygslClient);
|
|
|
- }
|
|
|
- });
|
|
|
- ygslstop.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
- ygslstop.setBounds(150, 221, 140, 40);
|
|
|
-// indexPanelA.add(ygslstop);
|
|
|
-
|
|
|
- JButton ygslenable = new JButton("enableTool");
|
|
|
- ygslenable.addActionListener(new ActionListener() {
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
- YgslUtil.enableTool(ygslClient);
|
|
|
- }
|
|
|
- });
|
|
|
- ygslenable.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
- ygslenable.setBounds(50, 271, 140, 40);
|
|
|
-// indexPanelA.add(ygslenable);
|
|
|
-
|
|
|
- JButton ygsldisable = new JButton("disableTool");
|
|
|
- ygsldisable.addActionListener(new ActionListener() {
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
- YgslUtil.disableTool(ygslClient);
|
|
|
- }
|
|
|
- });
|
|
|
- ygsldisable.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
- ygsldisable.setBounds(50, 321, 140, 40);
|
|
|
-// indexPanelA.add(ygsldisable);
|
|
|
-
|
|
|
- JButton ygsllast = new JButton("lastTightening");
|
|
|
- ygsllast.addActionListener(new ActionListener() {
|
|
|
- public void actionPerformed(ActionEvent e) {
|
|
|
- YgslUtil.lastTighteningResultSubscribe(ygslClient);
|
|
|
- }
|
|
|
- });
|
|
|
- ygsllast.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
- ygsllast.setBounds(690, 171, 140, 40);
|
|
|
-// indexPanelA.add(ygsllast);
|
|
|
-
|
|
|
- JLabel lblNewLabel = new JLabel("M6");
|
|
|
- lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
- lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 28));
|
|
|
- lblNewLabel.setBounds(185, 180, 261, 30);
|
|
|
- indexPanelA.add(lblNewLabel);
|
|
|
-
|
|
|
- schedulea = new JLabel("0/89");
|
|
|
- schedulea.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
- schedulea.setFont(new Font("微软雅黑", Font.PLAIN, 28));
|
|
|
- schedulea.setBounds(474, 180, 203, 30);
|
|
|
- indexPanelA.add(schedulea);
|
|
|
-
|
|
|
- JLabel lblB = new JLabel("M8");
|
|
|
- lblB.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
- lblB.setFont(new Font("微软雅黑", Font.PLAIN, 28));
|
|
|
- lblB.setBounds(185, 303, 261, 30);
|
|
|
-// indexPanelA.add(lblB);
|
|
|
-
|
|
|
- scheduleb = new JLabel("1/1");
|
|
|
- scheduleb.setHorizontalAlignment(SwingConstants.LEFT);
|
|
|
- scheduleb.setFont(new Font("微软雅黑", Font.PLAIN, 28));
|
|
|
- scheduleb.setBounds(474, 303, 203, 30);
|
|
|
-// indexPanelA.add(scheduleb);
|
|
|
-
|
|
|
- JLabel lblNewLabel_2 = new JLabel("扭力:");
|
|
|
- lblNewLabel_2.setFont(new Font("微软雅黑", Font.PLAIN, 22));
|
|
|
- lblNewLabel_2.setBounds(311, 230, 67, 30);
|
|
|
- indexPanelA.add(lblNewLabel_2);
|
|
|
-
|
|
|
- JLabel lblNewLabel_2_1 = new JLabel("角度:");
|
|
|
- lblNewLabel_2_1.setFont(new Font("微软雅黑", Font.PLAIN, 22));
|
|
|
- lblNewLabel_2_1.setBounds(495, 230, 72, 30);
|
|
|
- indexPanelA.add(lblNewLabel_2_1);
|
|
|
-
|
|
|
- torquea = new JLabel("");
|
|
|
- torquea.setFont(new Font("微软雅黑", Font.PLAIN, 22));
|
|
|
- torquea.setBounds(370, 230, 115, 30);
|
|
|
- indexPanelA.add(torquea);
|
|
|
-
|
|
|
- anglea = new JLabel("");
|
|
|
- anglea.setFont(new Font("微软雅黑", Font.PLAIN, 22));
|
|
|
- anglea.setBounds(555, 230, 115, 30);
|
|
|
- indexPanelA.add(anglea);
|
|
|
-
|
|
|
- JLabel lblNewLabel_2_3 = new JLabel("扭力:");
|
|
|
- lblNewLabel_2_3.setFont(new Font("微软雅黑", Font.PLAIN, 22));
|
|
|
- lblNewLabel_2_3.setBounds(311, 342, 67, 30);
|
|
|
-// indexPanelA.add(lblNewLabel_2_3);
|
|
|
-
|
|
|
- torqueb = new JLabel("");
|
|
|
- torqueb.setFont(new Font("微软雅黑", Font.PLAIN, 22));
|
|
|
- torqueb.setBounds(370, 342, 115, 30);
|
|
|
-// indexPanelA.add(torqueb);
|
|
|
-
|
|
|
- JLabel lblNewLabel_2_1_1 = new JLabel("角度:");
|
|
|
- lblNewLabel_2_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 22));
|
|
|
- lblNewLabel_2_1_1.setBounds(495, 342, 72, 30);
|
|
|
-// indexPanelA.add(lblNewLabel_2_1_1);
|
|
|
-
|
|
|
- angleb = new JLabel("");
|
|
|
- angleb.setFont(new Font("微软雅黑", Font.PLAIN, 22));
|
|
|
- angleb.setBounds(555, 342, 115, 30);
|
|
|
-// indexPanelA.add(angleb);
|
|
|
+ gunPanelContainer = new JPanel();
|
|
|
+ gunPanelContainer.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
|
|
|
+ gunPanelContainer.setBounds(20, 160, 750, 220);
|
|
|
+ gunPanelContainer.setOpaque(false);
|
|
|
+ indexPanelA.add(gunPanelContainer);
|
|
|
|
|
|
tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
|
|
|
tabbedPane.setEnabledAt(0, true);
|
|
|
@@ -1024,6 +797,14 @@ public class MesClient extends JFrame {
|
|
|
|
|
|
tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
|
|
|
|
|
|
+ // 增加工具配置页面
|
|
|
+ JPanel indexConfigPanel = new JPanel();
|
|
|
+ indexConfigPanel.setLayout(null);
|
|
|
+ tabbedPane.addTab("工具配置", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexConfigPanel, null);
|
|
|
+
|
|
|
+ initGunConfigPanel(indexConfigPanel);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
tabbedPane.addChangeListener(new ChangeListener() {
|
|
|
@Override
|
|
|
@@ -1143,4 +924,296 @@ public class MesClient extends JFrame {
|
|
|
indexPanelBB.setLayout(null);
|
|
|
tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
|
|
|
}
|
|
|
+
|
|
|
+ private static JTable configTable;
|
|
|
+ private static JButton addGunButton;
|
|
|
+ private static JButton saveConfigButton;
|
|
|
+
|
|
|
+ public static void initGunConfigPanel(JPanel panel) {
|
|
|
+ JLabel titleLabel = new JLabel("扭力枪配置管理");
|
|
|
+ titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 24));
|
|
|
+ titleLabel.setBounds(350, 20, 300, 40);
|
|
|
+ panel.add(titleLabel);
|
|
|
+
|
|
|
+ String[] columnNames = {"枪号", "名称", "IP地址", "端口", "任务数", "启用", "自动提交"};
|
|
|
+ List<YgslConfig> configs = JdbcUtils.getYgslConfigs();
|
|
|
+ Object[][] data = new Object[configs.size()][7];
|
|
|
+ for (int i = 0; i < configs.size(); i++) {
|
|
|
+ YgslConfig config = configs.get(i);
|
|
|
+ data[i][0] = config.getGunIndex();
|
|
|
+ data[i][1] = config.getGunName();
|
|
|
+ data[i][2] = config.getIpAddress();
|
|
|
+ data[i][3] = config.getPort();
|
|
|
+ data[i][4] = config.getTaskCount();
|
|
|
+ data[i][5] = config.getEnabled() == 1 ? "是" : "否";
|
|
|
+ data[i][6] = config.getAutoSubmit() == 1 ? "是" : "否";
|
|
|
+ }
|
|
|
+
|
|
|
+ configTable = new JTable(data, columnNames);
|
|
|
+ configTable.setRowHeight(35);
|
|
|
+ configTable.setFont(new Font("微软雅黑", Font.PLAIN, 14));
|
|
|
+ configTable.getTableHeader().setFont(new Font("微软雅黑", Font.BOLD, 14));
|
|
|
+
|
|
|
+ JScrollPane scrollPane = new JScrollPane(configTable);
|
|
|
+ scrollPane.setBounds(50, 70, 900, 400);
|
|
|
+ panel.add(scrollPane);
|
|
|
+
|
|
|
+ addGunButton = new JButton("添加枪");
|
|
|
+ addGunButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ addGunButton.setBounds(150, 490, 120, 40);
|
|
|
+ addGunButton.addActionListener(new ActionListener() {
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ addNewGun(panel);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ panel.add(addGunButton);
|
|
|
+
|
|
|
+ saveConfigButton = new JButton("保存配置");
|
|
|
+ saveConfigButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ saveConfigButton.setBounds(300, 490, 120, 40);
|
|
|
+ saveConfigButton.addActionListener(new ActionListener() {
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ saveGunConfigs();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ panel.add(saveConfigButton);
|
|
|
+
|
|
|
+ JButton deleteButton = new JButton("删除选中");
|
|
|
+ deleteButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+ deleteButton.setBounds(450, 490, 120, 40);
|
|
|
+ deleteButton.addActionListener(new ActionListener() {
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ int selectedRow = configTable.getSelectedRow();
|
|
|
+ if (selectedRow >= 0) {
|
|
|
+ int confirm = JOptionPane.showConfirmDialog(mesClientFrame, "确定要删除选中的配置吗?", "确认删除", JOptionPane.YES_NO_OPTION);
|
|
|
+ if (confirm == JOptionPane.YES_OPTION) {
|
|
|
+ List<YgslConfig> allConfigs = JdbcUtils.getYgslConfigs();
|
|
|
+ if (selectedRow < allConfigs.size()) {
|
|
|
+ JdbcUtils.deleteYgslConfig(allConfigs.get(selectedRow).getId());
|
|
|
+ reloadGunConfigs(panel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame, "请先选中一行", "提示", JOptionPane.INFORMATION_MESSAGE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ panel.add(deleteButton);
|
|
|
+
|
|
|
+ configTable.addMouseListener(new MouseAdapter() {
|
|
|
+ public void mouseDoubleClick(MouseEvent e) {
|
|
|
+ int row = configTable.getSelectedRow();
|
|
|
+ if (row >= 0) {
|
|
|
+ editGunConfig(row, panel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void editGunConfig(int row, JPanel panel) {
|
|
|
+ List<YgslConfig> configs = JdbcUtils.getYgslConfigs();
|
|
|
+ if (row >= configs.size()) return;
|
|
|
+
|
|
|
+ YgslConfig config = configs.get(row);
|
|
|
+
|
|
|
+ JDialog dialog = new JDialog(mesClientFrame, "编辑扭力枪", true);
|
|
|
+ dialog.setSize(400, 400);
|
|
|
+ dialog.setLocationRelativeTo(mesClientFrame);
|
|
|
+ dialog.setLayout(null);
|
|
|
+
|
|
|
+ JLabel idLabel = new JLabel("ID: " + config.getId());
|
|
|
+ idLabel.setBounds(50, 20, 300, 30);
|
|
|
+ dialog.add(idLabel);
|
|
|
+
|
|
|
+ JLabel nameLabel = new JLabel("枪号:");
|
|
|
+ nameLabel.setBounds(50, 60, 80, 30);
|
|
|
+ dialog.add(nameLabel);
|
|
|
+ JTextField nameField = new JTextField(String.valueOf(config.getGunIndex()));
|
|
|
+ nameField.setBounds(140, 60, 180, 30);
|
|
|
+ dialog.add(nameField);
|
|
|
+
|
|
|
+ JLabel gunNameLabel = new JLabel("名称:");
|
|
|
+ gunNameLabel.setBounds(50, 100, 80, 30);
|
|
|
+ dialog.add(gunNameLabel);
|
|
|
+ JTextField gunNameField = new JTextField(config.getGunName());
|
|
|
+ gunNameField.setBounds(140, 100, 180, 30);
|
|
|
+ dialog.add(gunNameField);
|
|
|
+
|
|
|
+ JLabel ipLabel = new JLabel("IP地址:");
|
|
|
+ ipLabel.setBounds(50, 140, 80, 30);
|
|
|
+ dialog.add(ipLabel);
|
|
|
+ JTextField ipField = new JTextField(config.getIpAddress());
|
|
|
+ ipField.setBounds(140, 140, 180, 30);
|
|
|
+ dialog.add(ipField);
|
|
|
+
|
|
|
+ JLabel portLabel = new JLabel("端口:");
|
|
|
+ portLabel.setBounds(50, 180, 80, 30);
|
|
|
+ dialog.add(portLabel);
|
|
|
+ JTextField portField = new JTextField(String.valueOf(config.getPort()));
|
|
|
+ portField.setBounds(140, 180, 180, 30);
|
|
|
+ dialog.add(portField);
|
|
|
+
|
|
|
+ JLabel taskLabel = new JLabel("任务数:");
|
|
|
+ taskLabel.setBounds(50, 220, 80, 30);
|
|
|
+ dialog.add(taskLabel);
|
|
|
+ JTextField taskField = new JTextField(String.valueOf(config.getTaskCount()));
|
|
|
+ taskField.setBounds(140, 220, 180, 30);
|
|
|
+ dialog.add(taskField);
|
|
|
+
|
|
|
+ JLabel enabledLabel = new JLabel("启用:");
|
|
|
+ enabledLabel.setBounds(50, 260, 80, 30);
|
|
|
+ dialog.add(enabledLabel);
|
|
|
+ JComboBox<String> enabledBox = new JComboBox<>(new String[]{"否", "是"});
|
|
|
+ enabledBox.setBounds(140, 260, 180, 30);
|
|
|
+ enabledBox.setSelectedIndex(config.getEnabled() == 1 ? 1 : 0);
|
|
|
+ dialog.add(enabledBox);
|
|
|
+
|
|
|
+ JButton okButton = new JButton("保存");
|
|
|
+ okButton.setBounds(100, 310, 80, 30);
|
|
|
+ okButton.addActionListener(new ActionListener() {
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ try {
|
|
|
+ config.setGunIndex(Integer.parseInt(nameField.getText()));
|
|
|
+ config.setGunName(gunNameField.getText());
|
|
|
+ config.setIpAddress(ipField.getText());
|
|
|
+ config.setPort(Integer.parseInt(portField.getText()));
|
|
|
+ config.setTaskCount(Integer.parseInt(taskField.getText()));
|
|
|
+ config.setEnabled(enabledBox.getSelectedIndex() == 1 ? 1 : 0);
|
|
|
+
|
|
|
+ JdbcUtils.updateYgslConfig(config);
|
|
|
+ dialog.dispose();
|
|
|
+ reloadGunConfigs(panel);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ JOptionPane.showMessageDialog(dialog, "输入格式错误,请检查", "错误", JOptionPane.ERROR_MESSAGE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ dialog.add(okButton);
|
|
|
+
|
|
|
+ JButton cancelButton = new JButton("取消");
|
|
|
+ cancelButton.setBounds(200, 310, 80, 30);
|
|
|
+ cancelButton.addActionListener(new ActionListener() {
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ dialog.dispose();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ dialog.add(cancelButton);
|
|
|
+
|
|
|
+ dialog.setVisible(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void addNewGun(JPanel panel) {
|
|
|
+ JDialog dialog = new JDialog(mesClientFrame, "添加扭力枪", true);
|
|
|
+ dialog.setSize(400, 350);
|
|
|
+ dialog.setLocationRelativeTo(mesClientFrame);
|
|
|
+ dialog.setLayout(null);
|
|
|
+
|
|
|
+ JLabel nameLabel = new JLabel("枪号:");
|
|
|
+ nameLabel.setBounds(50, 30, 80, 30);
|
|
|
+ dialog.add(nameLabel);
|
|
|
+ JTextField nameField = new JTextField();
|
|
|
+ nameField.setBounds(140, 30, 180, 30);
|
|
|
+ dialog.add(nameField);
|
|
|
+
|
|
|
+ JLabel gunNameLabel = new JLabel("名称:");
|
|
|
+ gunNameLabel.setBounds(50, 80, 80, 30);
|
|
|
+ dialog.add(gunNameLabel);
|
|
|
+ JTextField gunNameField = new JTextField("M5");
|
|
|
+ gunNameField.setBounds(140, 80, 180, 30);
|
|
|
+ dialog.add(gunNameField);
|
|
|
+
|
|
|
+ JLabel ipLabel = new JLabel("IP地址:");
|
|
|
+ ipLabel.setBounds(50, 130, 80, 30);
|
|
|
+ dialog.add(ipLabel);
|
|
|
+ JTextField ipField = new JTextField("192.168.5.100");
|
|
|
+ ipField.setBounds(140, 130, 180, 30);
|
|
|
+ dialog.add(ipField);
|
|
|
+
|
|
|
+ JLabel portLabel = new JLabel("端口:");
|
|
|
+ portLabel.setBounds(50, 180, 80, 30);
|
|
|
+ dialog.add(portLabel);
|
|
|
+ JTextField portField = new JTextField("4545");
|
|
|
+ portField.setBounds(140, 180, 180, 30);
|
|
|
+ dialog.add(portField);
|
|
|
+
|
|
|
+ JLabel taskLabel = new JLabel("任务数:");
|
|
|
+ taskLabel.setBounds(50, 230, 80, 30);
|
|
|
+ dialog.add(taskLabel);
|
|
|
+ JTextField taskField = new JTextField("12");
|
|
|
+ taskField.setBounds(140, 230, 180, 30);
|
|
|
+ dialog.add(taskField);
|
|
|
+
|
|
|
+ JButton okButton = new JButton("确定");
|
|
|
+ okButton.setBounds(100, 280, 80, 30);
|
|
|
+ okButton.addActionListener(new ActionListener() {
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ try {
|
|
|
+ int gunIndex = Integer.parseInt(nameField.getText());
|
|
|
+ String gunName = gunNameField.getText();
|
|
|
+ String ip = ipField.getText();
|
|
|
+ int port = Integer.parseInt(portField.getText());
|
|
|
+ int taskCount = Integer.parseInt(taskField.getText());
|
|
|
+
|
|
|
+ YgslConfig config = new YgslConfig(gunIndex, gunName, ip, port, taskCount);
|
|
|
+ JdbcUtils.insertYgslConfig(config);
|
|
|
+
|
|
|
+ dialog.dispose();
|
|
|
+ reloadGunConfigs(panel);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ JOptionPane.showMessageDialog(dialog, "输入格式错误,请检查", "错误", JOptionPane.ERROR_MESSAGE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ dialog.add(okButton);
|
|
|
+
|
|
|
+ JButton cancelButton = new JButton("取消");
|
|
|
+ cancelButton.setBounds(200, 280, 80, 30);
|
|
|
+ cancelButton.addActionListener(new ActionListener() {
|
|
|
+ @Override
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
+ dialog.dispose();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ dialog.add(cancelButton);
|
|
|
+
|
|
|
+ dialog.setVisible(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void saveGunConfigs() {
|
|
|
+ try {
|
|
|
+ List<YgslConfig> configs = JdbcUtils.getYgslConfigs();
|
|
|
+ int rowCount = configTable.getRowCount();
|
|
|
+
|
|
|
+ for (int i = 0; i < rowCount && i < configs.size(); i++) {
|
|
|
+ YgslConfig config = configs.get(i);
|
|
|
+ config.setGunIndex((Integer) configTable.getValueAt(i, 0));
|
|
|
+ config.setGunName((String) configTable.getValueAt(i, 1));
|
|
|
+ config.setIpAddress((String) configTable.getValueAt(i, 2));
|
|
|
+ config.setPort((Integer) configTable.getValueAt(i, 3));
|
|
|
+ config.setTaskCount((Integer) configTable.getValueAt(i, 4));
|
|
|
+ config.setEnabled(((String) configTable.getValueAt(i, 5)).equals("是") ? 1 : 0);
|
|
|
+ config.setAutoSubmit(((String) configTable.getValueAt(i, 6)).equals("是") ? 1 : 0);
|
|
|
+
|
|
|
+ JdbcUtils.updateYgslConfig(config);
|
|
|
+ }
|
|
|
+
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame, "配置保存成功!重启后生效", "提示", JOptionPane.INFORMATION_MESSAGE);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ JOptionPane.showMessageDialog(mesClientFrame, "保存失败:" + e.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void reloadGunConfigs(JPanel panel) {
|
|
|
+ panel.removeAll();
|
|
|
+ initGunConfigPanel(panel);
|
|
|
+ panel.revalidate();
|
|
|
+ panel.repaint();
|
|
|
+ }
|
|
|
}
|