MesClient.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. package com.mes.ui;
  2. import com.alibaba.fastjson2.JSON;
  3. import com.alibaba.fastjson2.JSONObject;
  4. import com.google.zxing.BarcodeFormat;
  5. import com.google.zxing.client.j2se.MatrixToImageWriter;
  6. import com.google.zxing.common.BitMatrix;
  7. import com.google.zxing.qrcode.QRCodeWriter;
  8. import com.mes.component.*;
  9. import com.mes.util.DateLocalUtils;
  10. import com.mes.util.JdbcUtils;
  11. import com.mes.util.TCPClient;
  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;
  14. import javax.swing.*;
  15. import javax.swing.border.EmptyBorder;
  16. import javax.swing.event.ChangeEvent;
  17. import javax.swing.event.ChangeListener;
  18. import java.awt.*;
  19. import java.awt.event.*;
  20. import java.awt.image.BufferedImage;
  21. import java.io.BufferedReader;
  22. import java.io.IOException;
  23. import java.io.InputStream;
  24. import java.io.InputStreamReader;
  25. import java.util.List;
  26. import java.util.Properties;
  27. import java.util.Timer;
  28. import java.util.TimerTask;
  29. public class MesClient extends JFrame {
  30. public static final Logger log = LoggerFactory.getLogger(MesClient.class);
  31. private static String Drivde = "org.sqlite.JDBC";
  32. public static int mes_auth = 0; // 权限级别 0=无权限 1=操作工人 2=管理员
  33. public static String mes_gw = ""; // 工位号
  34. public static String mes_gw_des = ""; // 工位名称
  35. public static String mes_server_ip = ""; // 服务器IP地址
  36. public static String mes_line_sn = ""; // 产线编号
  37. public static String mes_line_pos = "";
  38. //session
  39. public static String sessionid = "";
  40. public static int isLogin = 0;
  41. public static JPanel contentPane;
  42. public static MesClient mesClientFrame;
  43. public static JTabbedPane tabbedPane;
  44. public static JScrollPane indexScrollPaneA;
  45. public static JScrollPane indexScrollPaneB;
  46. public static JScrollPane indexScrollPaneC;
  47. public static JScrollPane indexScrollPaneD;
  48. // public static JScrollPane searchScrollPane; // 已弃用,改为使用 WorkRecordPanel
  49. public static String preSn20 = "";
  50. // OP050 待领取码与扫码框显示分开,所有发布/领取使用同一把锁。
  51. private static String preSn30 = "";
  52. public static synchronized void publishOp050Sn(String sn) {
  53. if (sn == null || (sn.trim().length() != 16 && sn.trim().length() != 19)) {
  54. return;
  55. }
  56. preSn30 = sn.trim();
  57. log.info("<OP050> 发布待领取码 sn={}", preSn30);
  58. }
  59. public static synchronized String takeOp050Sn(String station) {
  60. String sn = preSn30;
  61. preSn30 = "";
  62. if (!sn.isEmpty()) {
  63. log.info("<{}> 领取扫码 sn={},已清空公共待领取码", station, sn);
  64. }
  65. return sn;
  66. }
  67. public static Boolean check_quality_result = false;
  68. public static Integer work_status = 0;
  69. public static JButton heart_beat_menu;
  70. public static JButton status_menu;
  71. public static JButton user_menu;
  72. public static JFrame welcomeWin;
  73. // public static JPanel indexPanelWork; // 已弃用,改为使用 WorkRecordPanel
  74. public static MesWebView jfxPanel = null;
  75. public static JTable table;
  76. public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
  77. public static Object[][] rowData = null;
  78. public static TCPClient tcpClient1 = new TCPClient("192.168.90.51",9004);
  79. public static TCPClient tcpClient2 = new TCPClient("192.168.90.52",9004);
  80. public static TCPClient tcpClient3 = new TCPClient("192.168.90.53",9004); // 60B
  81. public static TCPClient tcpClient4 = new TCPClient("192.168.90.54",9004); // 70EFG
  82. public static int scanFlag1 = 0;
  83. public static int scanFlag2 = 0;
  84. public static int scanFlag3 = 0;
  85. public static int scanFlag4 = 0;
  86. public static String newSn = ""; // 最新二维码
  87. public static WorkJPanelOP10 workJPanelOP10A;
  88. public static WorkJPanelOP20 workJPanelOP20A;
  89. public static WorkJPanelOP20 workJPanelOP20C;
  90. public static WorkJPanelOP20 workJPanelOP20E; // FSW3
  91. public static WorkJPanelScan workJPanelScanA;
  92. public static WorkJPanelScan workJPanelScanB;
  93. public static WorkJPanelOP25 workJPanelOP25A;
  94. public static WorkJPanelOP30 workJPanelOP30A;
  95. public static WorkJPanelOP30 workJPanelOP30C;
  96. public static WorkJPanelOP30 workJPanelOP30E; // FSW3
  97. public static void main(String[] args) {
  98. EventQueue.invokeLater(new Runnable() {
  99. @Override
  100. public void run() {
  101. try{
  102. //读文件配置
  103. readProperty();
  104. JdbcUtils.getConn();
  105. // 显示界面
  106. mesClientFrame = new MesClient();
  107. mesClientFrame.setVisible(false);
  108. //
  109. welcomeWin = new LoginFarme();
  110. welcomeWin.setVisible(true);
  111. startHeartBeatTimer();
  112. }catch (Exception e){
  113. log.error(e.getMessage());
  114. }
  115. }
  116. });
  117. }
  118. //读配置文件
  119. private static void readProperty() throws IOException{
  120. String enconding = "UTF-8";
  121. InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
  122. Properties pro = new Properties();
  123. BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
  124. pro.load(br);
  125. mes_gw = pro.getProperty("mes.gw");
  126. mes_gw_des = pro.getProperty("mes.gw_des");
  127. mes_server_ip = pro.getProperty("mes.server_ip");
  128. // mes_tcp_port = Integer.parseInt(pro.getProperty("mes.tcp_port"));
  129. // mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle"));
  130. mes_line_sn = pro.getProperty("mes.line_sn");
  131. mes_line_pos = pro.getProperty("mes.line_pos");
  132. // mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
  133. // log.info(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
  134. }
  135. //启动心跳包程序
  136. public static java.util.Timer heartBeatIconTimer;
  137. public static boolean iconREDFlag = true;
  138. public static void startHeartBeatTimer() {
  139. //心跳显示图标
  140. if(heartBeatIconTimer!=null) {
  141. heartBeatIconTimer.cancel();
  142. }
  143. heartBeatIconTimer = new Timer();
  144. heartBeatIconTimer.schedule(new TimerTask() {
  145. public void run() {
  146. if(iconREDFlag) {
  147. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  148. iconREDFlag = false;
  149. }else {
  150. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  151. iconREDFlag = true;
  152. }
  153. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  154. heart_beat_menu.repaint();
  155. }
  156. }, 100,1000);
  157. }
  158. public static void initWarehouseData(){
  159. resetScanA();
  160. }
  161. public static void resetScanA() {
  162. MesClient.setMenuStatus("请扫工件码",0);
  163. }
  164. public static void logoff() {
  165. mesClientFrame.setVisible(false);
  166. //退出程序 退出登录
  167. System.exit(0);
  168. // nettyClient = null;
  169. }
  170. public MesClient() {
  171. setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
  172. setTitle("MES系统客户端:OP35-OP50");
  173. // setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  174. // setBounds(0, 0, 1920, 1080);
  175. setBounds(0, 0, 1024, 768);
  176. setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); // 防止默认的关闭操作
  177. // 添加窗口监听器
  178. addWindowListener(new WindowAdapter() {
  179. @Override
  180. public void windowClosing(WindowEvent e) {
  181. int choice = JOptionPane.showConfirmDialog(null, "确定要关闭窗口吗?", "关闭确认", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
  182. if (choice == JOptionPane.YES_OPTION) {
  183. // 如果用户点击“是”,则关闭窗口
  184. dispose(); // 释放窗口资源并关闭窗口
  185. System.exit(0);
  186. }
  187. }
  188. });
  189. JMenuBar menuBar = new JMenuBar();
  190. menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
  191. setJMenuBar(menuBar);
  192. JMenu fileMenu = new JMenu("用户");
  193. fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
  194. fileMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  195. menuBar.add(fileMenu);
  196. JMenuItem exitMenuItem = new JMenuItem("退出");
  197. exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png")));
  198. exitMenuItem.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  199. fileMenu.add(exitMenuItem);
  200. exitMenuItem.addMouseListener(new MouseAdapter() {
  201. @Override
  202. public void mousePressed(MouseEvent e) {//只能检测到mousePressed事件
  203. super.mouseClicked(e);
  204. //dispose();
  205. logoff();
  206. }
  207. });
  208. JMenu settingMenu = new JMenu("设置");
  209. //settingMenu.setVisible(false);
  210. settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
  211. settingMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  212. menuBar.add(settingMenu);
  213. contentPane = new JPanel();
  214. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  215. setContentPane(contentPane);
  216. contentPane.setLayout(new BorderLayout(0, 0));
  217. JToolBar toolBar = new JToolBar();
  218. contentPane.add(toolBar, BorderLayout.NORTH);
  219. JLabel equipment_statu_label = new JLabel("状态:");
  220. equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER);
  221. equipment_statu_label.setForeground(Color.BLACK);
  222. equipment_statu_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  223. equipment_statu_label.setBackground(Color.LIGHT_GRAY);
  224. // toolBar.add(equipment_statu_label);
  225. status_menu = new JButton("已连接MES服务器");
  226. status_menu.setForeground(Color.GREEN);
  227. status_menu.addActionListener(new ActionListener() {
  228. public void actionPerformed(ActionEvent e) {
  229. }
  230. });
  231. status_menu.setForeground(Color.GREEN);
  232. status_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  233. status_menu.setBackground(Color.BLACK);
  234. // toolBar.add(status_menu);
  235. JLabel space_1 = new JLabel(" ");
  236. toolBar.add(space_1);
  237. JLabel heart_beat_status_label = new JLabel("心跳:");
  238. heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  239. heart_beat_status_label.setForeground(Color.BLACK);
  240. heart_beat_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  241. heart_beat_status_label.setBackground(Color.LIGHT_GRAY);
  242. toolBar.add(heart_beat_status_label);
  243. heart_beat_menu = new JButton("");
  244. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  245. heart_beat_menu.setForeground(Color.GREEN);
  246. heart_beat_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  247. heart_beat_menu.setBackground(Color.BLACK);
  248. toolBar.add(heart_beat_menu);
  249. JLabel space_2 = new JLabel(" ");
  250. toolBar.add(space_2);
  251. JLabel user_status_label = new JLabel("登录用户:");
  252. user_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  253. user_status_label.setForeground(Color.BLACK);
  254. user_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  255. user_status_label.setBackground(Color.LIGHT_GRAY);
  256. toolBar.add(user_status_label);
  257. user_menu = new JButton("");
  258. user_menu.setForeground(Color.GREEN);
  259. user_menu.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  260. user_menu.setBackground(Color.BLACK);
  261. toolBar.add(user_menu);
  262. JLabel space_3 = new JLabel(" ");
  263. toolBar.add(space_3);
  264. JLabel space_4 = new JLabel(" ");
  265. toolBar.add(space_4);
  266. tabbedPane = new JTabbedPane(JTabbedPane.TOP);
  267. tabbedPane.setMinimumSize(new Dimension(400, 50));
  268. tabbedPane.setFont(new Font("宋体", Font.BOLD, 22));
  269. contentPane.add(tabbedPane);
  270. //首页
  271. JPanel indexPanelA = new JPanel();
  272. indexScrollPaneA = new JScrollPane(indexPanelA);
  273. indexPanelA.setLayout(new GridLayout(1,1, 5, 5));
  274. indexPanelA.setBackground(Color.LIGHT_GRAY);
  275. if(mes_line_pos.equals("east")){
  276. JPanel indexPanel1 = new JPanel();
  277. indexPanel1.setLayout(null);
  278. indexPanel1.setBackground(Color.WHITE);
  279. workJPanelOP10A = new WorkJPanelOP10("B");
  280. workJPanelOP10A.setBounds(10, 10, workJPanelOP10A.workWidth, workJPanelOP10A.workHeight);
  281. indexPanel1.add(workJPanelOP10A);
  282. indexPanelA.add(indexPanel1);
  283. }else{
  284. JPanel indexPanel1 = new JPanel();
  285. indexPanel1.setLayout(null);
  286. indexPanel1.setBackground(Color.WHITE);
  287. workJPanelOP10A = new WorkJPanelOP10("A");
  288. workJPanelOP10A.setBounds(10, 10, workJPanelOP10A.workWidth, workJPanelOP10A.workHeight);
  289. indexPanel1.add(workJPanelOP10A);
  290. indexPanelA.add(indexPanel1);
  291. }
  292. tabbedPane.addTab("OP35上料+打码", null, indexScrollPaneA, null);
  293. tabbedPane.setEnabledAt(0, true);
  294. JPanel indexPanelB = new JPanel();
  295. indexScrollPaneB = new JScrollPane(indexPanelB);
  296. indexPanelB.setLayout(new GridLayout(2,2, 5, 5));
  297. indexPanelB.setBackground(Color.LIGHT_GRAY);
  298. // FSW 子工位:西侧 A/B/E,东侧 C/D/F(E/F 为新增 FSW3)
  299. String[] fswPos = mes_line_pos.equals("east") ? new String[]{"C", "D", "F"} : new String[]{"A", "B", "E"};
  300. // OP40 反面FSW:FSW1=DB7000 FSW2=DB7001 FSW3=DB7004,扫码 DB7003
  301. workJPanelOP20A = new WorkJPanelOP20(fswPos[0]);
  302. indexPanelB.add(wrapCell(workJPanelOP20A, workJPanelOP20A.workWidth, workJPanelOP20A.workHeight));
  303. workJPanelOP20C = new WorkJPanelOP20(fswPos[1]);
  304. indexPanelB.add(wrapCell(workJPanelOP20C, workJPanelOP20C.workWidth, workJPanelOP20C.workHeight));
  305. workJPanelOP20E = new WorkJPanelOP20(fswPos[2]);
  306. indexPanelB.add(wrapCell(workJPanelOP20E, workJPanelOP20E.workWidth, workJPanelOP20E.workHeight));
  307. workJPanelScanA = new WorkJPanelScan("A");
  308. indexPanelB.add(wrapCell(workJPanelScanA, workJPanelScanA.workWidth, workJPanelScanA.workHeight));
  309. tabbedPane.addTab("OP40反面FSW", null, indexScrollPaneB, null);
  310. JPanel indexPanelC = new JPanel();
  311. indexScrollPaneC = new JScrollPane(indexPanelC);
  312. indexPanelC.setLayout(new GridLayout(1,1, 5, 5));
  313. indexPanelC.setBackground(Color.LIGHT_GRAY);
  314. if(mes_line_pos.equals("east")){
  315. JPanel indexPanel25A = new JPanel();
  316. indexPanel25A.setLayout(null);
  317. indexPanel25A.setBackground(Color.WHITE);
  318. workJPanelOP25A = new WorkJPanelOP25("B");
  319. workJPanelOP25A.setBounds(10, 10, workJPanelOP25A.workWidth, workJPanelOP25A.workHeight);
  320. indexPanel25A.add(workJPanelOP25A);
  321. indexPanelC.add(indexPanel25A);
  322. }else{
  323. JPanel indexPanel25A = new JPanel();
  324. indexPanel25A.setLayout(null);
  325. indexPanel25A.setBackground(Color.WHITE);
  326. workJPanelOP25A = new WorkJPanelOP25("A");
  327. workJPanelOP25A.setBounds(10, 10, workJPanelOP25A.workWidth, workJPanelOP25A.workHeight);
  328. indexPanel25A.add(workJPanelOP25A);
  329. indexPanelC.add(indexPanel25A);
  330. }
  331. tabbedPane.addTab("OP45打磨", null, indexScrollPaneC, null);
  332. JPanel indexPanelD = new JPanel();
  333. indexScrollPaneD = new JScrollPane(indexPanelD);
  334. indexPanelD.setLayout(new GridLayout(2,2, 5, 5));
  335. indexPanelD.setBackground(Color.LIGHT_GRAY);
  336. tabbedPane.setForegroundAt(2, Color.RED);
  337. // OP50 正面FSW:FSW1=DB7010 FSW2=DB7011 FSW3=DB7014,扫码 DB7013
  338. workJPanelOP30A = new WorkJPanelOP30(fswPos[0]);
  339. indexPanelD.add(wrapCell(workJPanelOP30A, workJPanelOP30A.workWidth, workJPanelOP30A.workHeight));
  340. workJPanelOP30C = new WorkJPanelOP30(fswPos[1]);
  341. indexPanelD.add(wrapCell(workJPanelOP30C, workJPanelOP30C.workWidth, workJPanelOP30C.workHeight));
  342. workJPanelOP30E = new WorkJPanelOP30(fswPos[2]);
  343. indexPanelD.add(wrapCell(workJPanelOP30E, workJPanelOP30E.workWidth, workJPanelOP30E.workHeight));
  344. workJPanelScanB = new WorkJPanelScan("B");
  345. indexPanelD.add(wrapCell(workJPanelScanB, workJPanelScanB.workWidth, workJPanelScanB.workHeight));
  346. tabbedPane.addTab("OP50正面FSW", null, indexScrollPaneD, null);
  347. // ========== 工作记录 Tab(改造:OP010/OP020/OP025/OP030子工位Tab + 所有工位) ==========
  348. // 旧代码已注释:
  349. // indexPanelWork = new JPanel();
  350. // searchScrollPane = new JScrollPane(indexPanelWork);
  351. // indexPanelWork.setLayout(null);
  352. // tabbedPane.addTab("工作记录", null, searchScrollPane, null);
  353. // 创建工作记录的子 TabbedPane
  354. JTabbedPane workRecordTabbedPane = new JTabbedPane(JTabbedPane.TOP);
  355. workRecordTabbedPane.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  356. // 定义所有子工位
  357. // OP035: A, B
  358. // OP040: A, B, C, D, E, F(E=西侧FSW3 F=东侧FSW3)
  359. // OP045: A, B
  360. // OP050: A, B, C, D, E, F
  361. String[][] stationGroups = {
  362. {"OP035", "A", "B"},
  363. {"OP040", "A", "B", "C", "D", "E", "F"},
  364. {"OP045", "A", "B"},
  365. {"OP050", "A", "B", "C", "D", "E", "F"}
  366. };
  367. // 计算总的工位数(用于数组大小)
  368. int totalStations = 0;
  369. for (String[] group : stationGroups) {
  370. totalStations += group.length - 1; // 减去第一个元素(基础工位号)
  371. }
  372. WorkRecordPanel[] workRecordPanels = new WorkRecordPanel[totalStations + 1]; // +1 for "所有工位"
  373. int panelIndex = 0;
  374. // 为每个子工位创建 Tab
  375. for (String[] group : stationGroups) {
  376. String baseOprno = group[0]; // 如 OP010
  377. for (int i = 1; i < group.length; i++) {
  378. String station = group[i]; // 如 A, B
  379. String oprno = baseOprno + station;
  380. workRecordPanels[panelIndex] = new WorkRecordPanel(oprno, mes_line_sn);
  381. workRecordTabbedPane.addTab(oprno, null, workRecordPanels[panelIndex], "查询" + oprno + "的工作记录");
  382. panelIndex++;
  383. }
  384. }
  385. // 最后添加"所有工位"Tab(查询整条产线所有工位,不限于OP010/OP020/OP025/OP030)
  386. workRecordPanels[totalStations] = new WorkRecordPanel(null, mes_line_sn);
  387. workRecordTabbedPane.addTab("所有工位", null, workRecordPanels[totalStations], "查询整条产线所有工位的工作记录");
  388. // 切换子Tab时自动刷新数据
  389. workRecordTabbedPane.addChangeListener(e -> {
  390. int selectedIndex = workRecordTabbedPane.getSelectedIndex();
  391. if (selectedIndex >= 0 && selectedIndex < workRecordPanels.length) {
  392. workRecordPanels[selectedIndex].refreshData();
  393. }
  394. });
  395. // 将子 TabbedPane 添加到主 TabbedPane
  396. tabbedPane.addTab("工作记录", null, workRecordTabbedPane, null);
  397. tabbedPane.addChangeListener(new ChangeListener() {
  398. @Override
  399. public void stateChanged(ChangeEvent e) {
  400. JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
  401. int selectedIndex = tabbedPane.getSelectedIndex();
  402. if(selectedIndex == 1){
  403. }
  404. }
  405. });
  406. }
  407. // 白底容器包一层工位面板,放进 GridLayout 单元格
  408. private static JPanel wrapCell(JPanel work, int w, int h) {
  409. JPanel cell = new JPanel();
  410. cell.setLayout(null);
  411. cell.setBackground(Color.WHITE);
  412. work.setBounds(10, 10, w, h);
  413. cell.add(work);
  414. return cell;
  415. }
  416. public static void setMenuStatus(String msg,int error){
  417. if(error == 0){
  418. MesClient.status_menu.setForeground(Color.GREEN);
  419. }else{
  420. MesClient.status_menu.setForeground(Color.RED);
  421. }
  422. MesClient.status_menu.setText(msg);
  423. }
  424. public static void createQRCode(String s,String title) {
  425. log.info("二维码:"+s);
  426. if(s == null || s.isEmpty()){
  427. return;
  428. }
  429. s = s.trim();
  430. try {
  431. BitMatrix bitMatrix = new QRCodeWriter().encode(s, BarcodeFormat.QR_CODE, 200, 200);
  432. BufferedImage qrImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
  433. JDialog qrDialog = new JDialog(mesClientFrame, title, Dialog.ModalityType.APPLICATION_MODAL);
  434. qrDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
  435. qrDialog.setSize(250, 250);
  436. qrDialog.setLocationRelativeTo(mesClientFrame);
  437. qrDialog.setResizable(false);
  438. JLabel qrLabel = new JLabel(new ImageIcon(qrImage));
  439. qrDialog.getContentPane().add(qrLabel, BorderLayout.CENTER);
  440. qrDialog.setVisible(true);
  441. log.info("已生成二维码");
  442. } catch (Exception e) {
  443. log.error("生成二维码失败", e);
  444. }
  445. }
  446. public static String scanQrcode1(){
  447. if(scanFlag1 == 1){
  448. return "";
  449. }
  450. scanFlag1 = 1;
  451. String sn = "";
  452. try{
  453. if (tcpClient1.socket == null || !tcpClient1.socket.isConnected() || tcpClient1.socket.isClosed()) {
  454. tcpClient1.connect();
  455. }
  456. log.error("扫码枪1正在进行扫码,请勿操作",0);
  457. sn = tcpClient1.receiveResponse();
  458. if (sn == null || sn.equals("")) {
  459. sn = "";
  460. }
  461. tcpClient1.close();
  462. }catch (Exception e) {
  463. e.printStackTrace();
  464. log.error("scanQrcode1:"+sn);
  465. tcpClient1.close();
  466. }
  467. MesClient.setMenuStatus(sn,0);
  468. scanFlag1 = 0;
  469. return sn;
  470. }
  471. public static String scanQrcode2(){
  472. if(scanFlag2 == 1){
  473. return "";
  474. }
  475. scanFlag2 = 1;
  476. String sn = "";
  477. try{
  478. if (tcpClient2.socket == null || !tcpClient2.socket.isConnected() || tcpClient2.socket.isClosed()) {
  479. tcpClient2.connect();
  480. }
  481. log.error("扫码枪2正在进行扫码,请勿操作",0);
  482. sn = tcpClient2.receiveResponse();
  483. if (sn == null || sn.equals("")) {
  484. sn = "";
  485. }
  486. tcpClient2.close();
  487. }catch (Exception e) {
  488. e.printStackTrace();
  489. log.error("scanQrcode2:"+sn);
  490. tcpClient2.close();
  491. }
  492. MesClient.setMenuStatus(sn,0);
  493. scanFlag2 = 0;
  494. return sn;
  495. }
  496. public static String scanQrcode3(){
  497. if(scanFlag3 == 1){
  498. return "";
  499. }
  500. scanFlag3 = 1;
  501. String sn = "";
  502. try{
  503. if (tcpClient3.socket == null || !tcpClient3.socket.isConnected() || tcpClient3.socket.isClosed()) {
  504. tcpClient3.connect();
  505. }
  506. log.error("扫码枪3正在进行扫码,请勿操作",0);
  507. sn = tcpClient3.receiveResponse();
  508. if (sn == null || sn.equals("")) {
  509. sn = "";
  510. }
  511. tcpClient3.close();
  512. }catch (Exception e) {
  513. e.printStackTrace();
  514. log.error("scanQrcode3:"+sn);
  515. tcpClient3.close();
  516. }
  517. MesClient.setMenuStatus(sn,0);
  518. scanFlag3 = 0;
  519. return sn;
  520. }
  521. public static String scanQrcode4(){
  522. if(scanFlag4 == 1){
  523. return "";
  524. }
  525. scanFlag4 = 1;
  526. String sn = "";
  527. try{
  528. if (tcpClient4.socket == null || !tcpClient4.socket.isConnected() || tcpClient4.socket.isClosed()) {
  529. tcpClient4.connect();
  530. }
  531. log.error("扫码枪4正在进行扫码,请勿操作",0);
  532. sn = tcpClient4.receiveResponse();
  533. if (sn == null || sn.equals("")) {
  534. sn = "";
  535. }
  536. tcpClient4.close();
  537. }catch (Exception e) {
  538. e.printStackTrace();
  539. log.error("scanQrcode4:"+sn);
  540. tcpClient4.close();
  541. }
  542. MesClient.setMenuStatus(sn,0);
  543. scanFlag4 = 0;
  544. return sn;
  545. }
  546. }