MesClient.java 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  1. package com.mes.ui;
  2. import com.alibaba.fastjson2.JSON;
  3. import com.alibaba.fastjson2.JSONObject;
  4. import com.mes.component.MesRadio;
  5. import com.mes.component.MesWebView;
  6. import com.mes.component.ProductTypePanel;
  7. import com.mes.netty.NettyClient;
  8. import com.mes.util.ClientVersionUtils;
  9. import com.mes.util.ClientUpgrade;
  10. import com.mes.util.*;
  11. import javax.swing.*;
  12. import javax.swing.border.EmptyBorder;
  13. import javax.swing.event.ChangeEvent;
  14. import javax.swing.event.ChangeListener;
  15. import java.awt.*;
  16. import java.awt.event.ActionEvent;
  17. import java.awt.event.ActionListener;
  18. import java.awt.event.MouseAdapter;
  19. import java.awt.event.MouseEvent;
  20. import java.io.BufferedReader;
  21. import java.io.IOException;
  22. import java.io.InputStream;
  23. import java.io.InputStreamReader;
  24. import java.time.LocalDateTime;
  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. private static String Drivde = "org.sqlite.JDBC";
  31. public static int mes_auth = 0; // 权限级别 0=无权限 1=操作工人 2=管理员
  32. public static String mes_gw = ""; // 工位号
  33. public static String mes_gw_des = ""; // 工位名称
  34. public static String mes_server_ip = ""; // 服务器IP地址
  35. public static int mes_tcp_port = 3000; // TCP服务端口
  36. public static int mes_heart_beat_cycle = 10; // 心跳周期
  37. public static int mes_heart_icon_cycle = 1;
  38. public static String mes_line_sn = "";
  39. public static String client_version = "0.0.0"; // 打包发布版本,需和后台 JAR 管理版本号对齐 // 产线编号
  40. public static String mes_serial_port = "COM1"; // 称重仪串口号
  41. public static int mes_serial_baud = 9600; // 称重仪波特率
  42. //新增字段
  43. public static ProductTypePanel productTypePanel;
  44. public static JLabel productTypeCurrentLabel;
  45. public static final int PRODUCT_SN_LENGTH = 32;
  46. public static final String PREFIX_ZJ = "000020021815-01000016"; //智界
  47. public static final String PREFIX_SJ = "000020022029-01000016"; //尚界
  48. public static final boolean PRODUCT_TYPE_SWITCH_ENABLED = false;
  49. public static final String PRODUCT_TYPE_SWITCH_PASSWORD = "503833";
  50. public static final String PRODUCT_TYPE_ZJ = ProductTypePanel.TYPE_ZJ;
  51. public static final String PRODUCT_TYPE_SJ = ProductTypePanel.TYPE_SJ;
  52. //TCP连接
  53. public static NettyClient nettyClient;
  54. //TCP连接状态
  55. public static boolean tcp_connect_flag = false;
  56. //TCP连接请求
  57. public static boolean connect_request_flag = false;
  58. public static boolean com_connect_flag = false;
  59. //session
  60. public static String sessionid = "";
  61. public static JPanel contentPane;
  62. public static MesClient mesClientFrame;
  63. public static JTabbedPane tabbedPane;
  64. public static JScrollPane indexScrollPaneA;
  65. public static JScrollPane searchScrollPane;
  66. public static JScrollPane searchScrollPaneDj;
  67. public static SerialPortUtils serialPortUtils;
  68. public static BluetoothUtils bluetoothUtils;
  69. public static ParamConfig paramConfig;
  70. public static Boolean check_quality_result = false;
  71. public static Integer work_status = 0;
  72. public static JButton heart_beat_menu;
  73. public static JButton status_menu;
  74. public static JButton user_menu;
  75. public static int scan_type = 0;
  76. public static JButton finish_ok_bt;
  77. // public static JButton finish_ng_bt;
  78. public static JButton batch_sn_bt;
  79. public static JTextField product_sn;
  80. public static JButton f_scan_data_bt_1;
  81. public static JButton is_js_btn;
  82. public static String comboBoxValue = "COM1";
  83. public static String user20 = "";
  84. public static String is_js_btn_val = "1";
  85. public static JFrame welcomeWin;
  86. public static JPanel indexPanelB;
  87. public static MesWebView jfxPanel = null;
  88. public static JPanel indexPanelC;
  89. public static MesWebView jfxPanel2 = null;
  90. public static MesRadio mesRadioHj;
  91. public static JTable table;
  92. public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
  93. public static Object[][] rowData = null;
  94. public static Timer cjTimer; //串口定时器
  95. public static Timer cjTimer2; //串口定时器2
  96. private static final String TARGET_DEVICE_ADDRESS = "001135390238";
  97. public static void main(String[] args) {
  98. if (ClientUpgrade.handleInstallArgs(args)) {
  99. return;
  100. }
  101. //EventQueue.invokeLater(new Runnable() )是SwingUtilities类中的一个静态方法,
  102. // 用于在事件调度线程中执行指定的Runnable。
  103. //事件调度线程是Swing的核心线程,负责处理所有Swing组件的事件。
  104. EventQueue.invokeLater(new Runnable() {
  105. @Override
  106. public void run() {
  107. try{
  108. //读文件配置(新增串口号和波特率)
  109. readProperty();
  110. if (ClientUpgrade.recoverIncompleteInstall()) {
  111. return;
  112. }
  113. ClientUpgrade.cleanupInstallLeftovers();
  114. ClientUpgrade.checkIfConfigured(null);
  115. //检查串口连接(定时器定时检查串口连接)
  116. checkComPort();
  117. // 显示界面
  118. mesClientFrame = new MesClient();
  119. mesClientFrame.setVisible(false);
  120. //连接数据库
  121. JdbcUtils.getConn();
  122. //显示登录界面
  123. welcomeWin = new LoginFarme();
  124. welcomeWin.setVisible(true);
  125. // getMaterailData();
  126. }catch (Exception e){
  127. e.printStackTrace();
  128. }
  129. }
  130. });
  131. }
  132. public static void initComPort() {
  133. //
  134. try {
  135. if (serialPortUtils != null) {
  136. serialPortUtils.closeSerialPort();
  137. serialPortUtils = null;
  138. }
  139. //初始化串口
  140. serialPortUtils = new SerialPortUtils();
  141. //创建串口参数配置
  142. paramConfig = new ParamConfig(mes_serial_port, mes_serial_baud, 0, 8, 1);
  143. //初始化串口
  144. serialPortUtils.init(paramConfig);
  145. System.out.println("初始化称重串口: " + mes_serial_port + ", 波特率: " + mes_serial_baud);
  146. } catch (Throwable e) {
  147. //串口连接失败标志
  148. com_connect_flag = false;
  149. //打印错误信息
  150. System.err.println("称重串口初始化失败: " + e.getMessage());
  151. e.printStackTrace();
  152. }
  153. }
  154. // 串口断开时定时重连
  155. public static void checkComPort() {
  156. //如果定时器不为空,则取消定时器
  157. if (MesClient.cjTimer2 != null) {
  158. MesClient.cjTimer2.cancel();
  159. }
  160. //创建新的定时器
  161. MesClient.cjTimer2 = new Timer();
  162. //定时器执行任务
  163. MesClient.cjTimer2.schedule(new TimerTask() {
  164. @Override
  165. public void run() {
  166. try {
  167. //如果串口连接标志为false,则重连串口
  168. if (!com_connect_flag) {
  169. System.out.println("称重串口断开,正在重连");
  170. initComPort(); //重连串口
  171. }
  172. } catch (Exception e) {
  173. e.printStackTrace();
  174. }
  175. }
  176. }, 2000, 2000); //线程本身并不阻塞
  177. initComPort(); //初始化串口
  178. }
  179. //读配置文件
  180. private static String parseClientVersion(String value) {
  181. if (value == null || value.trim().isEmpty()) {
  182. return "0.0.0";
  183. }
  184. return ClientVersionUtils.normalize(value.trim());
  185. }
  186. private static void readProperty() throws IOException{
  187. String enconding = "UTF-8";
  188. InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
  189. Properties pro = new Properties();
  190. BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
  191. pro.load(br);
  192. client_version = parseClientVersion(pro.getProperty("mes.client.version"));
  193. mes_gw = pro.getProperty("mes.gw");
  194. // mes_gw_des = pro.getProperty("mes.gw_des");
  195. mes_server_ip = pro.getProperty("mes.server_ip");
  196. mes_tcp_port = Integer.parseInt(pro.getProperty("mes.tcp_port"));
  197. mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle"));
  198. mes_line_sn = pro.getProperty("mes.line_sn");
  199. mes_serial_port = pro.getProperty("mes.serial.port", "COM1");
  200. mes_serial_baud = Integer.parseInt(pro.getProperty("mes.serial.baud", "9600"));
  201. mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
  202. System.out.println(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
  203. }
  204. // 初始化TCP
  205. public static void initTcpConnection() {
  206. try {
  207. if(nettyClient==null) {
  208. //初始化TCP连接
  209. nettyClient = new NettyClient();
  210. //TCP连接状态
  211. tcp_connect_flag = false;
  212. //设置TCP请求状态
  213. connect_request_flag = true;
  214. DataUtil.synrTcp(nettyClient,mes_gw);
  215. }
  216. } catch (Exception e) {
  217. // TODO Auto-generated catch block
  218. e.printStackTrace();
  219. }
  220. }
  221. //启动心跳包程序
  222. public static java.util.Timer heartBeatTimer;
  223. public static java.util.Timer heartBeatIconTimer;
  224. public static boolean iconREDFlag = true;
  225. public static JTextField weight_text;
  226. public static JTextField batch_sn_text;
  227. public static JLabel lblNewLabel;
  228. public static JLabel lblNewLabel_1;
  229. private static JComboBox comboBox;
  230. public static JButton finish_ok_bt_1;
  231. public static void startHeartBeatTimer() {
  232. if(heartBeatTimer!=null) {
  233. heartBeatTimer.cancel();
  234. }
  235. heartBeatTimer = new java.util.Timer();
  236. heartBeatTimer.schedule(new TimerTask() {
  237. public void run() {
  238. if(nettyClient!=null&&tcp_connect_flag) {
  239. //System.out.println("发送心跳报文");
  240. DataUtil.heartBeat(nettyClient,mes_gw);
  241. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  242. }
  243. }
  244. }, 100,mes_heart_beat_cycle*1000);
  245. //心跳显示图标
  246. if(heartBeatIconTimer!=null) {
  247. heartBeatIconTimer.cancel();
  248. }
  249. heartBeatIconTimer = new Timer();
  250. heartBeatIconTimer.schedule(new TimerTask() {
  251. public void run() {
  252. if(tcp_connect_flag) {
  253. if(iconREDFlag) {
  254. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  255. iconREDFlag = false;
  256. }else {
  257. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  258. iconREDFlag = true;
  259. }
  260. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  261. heart_beat_menu.repaint();
  262. }else {
  263. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  264. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  265. heart_beat_menu.repaint();
  266. //若未连接则尝试连接
  267. if(nettyClient!=null&&!tcp_connect_flag){
  268. System.out.println("TCP已断开");
  269. //TCP重新同步连接
  270. if(!connect_request_flag) {
  271. //System.out.println("TCP重新同步连接");
  272. //设置TCP请求状态,只重新同步连接一次
  273. connect_request_flag = true;
  274. DataUtil.synrTcp(nettyClient,mes_gw);
  275. }
  276. }
  277. }
  278. }
  279. }, 100,mes_heart_icon_cycle*1000);
  280. }
  281. //设置tcp连接状态显示
  282. public static void setTcpStatus() {
  283. if(tcp_connect_flag) {
  284. status_menu.setText("已连接MES服务器");
  285. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  286. heart_beat_menu.repaint();
  287. }else {
  288. status_menu.setText("未连接MES服务器");
  289. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  290. heart_beat_menu.repaint();
  291. }
  292. }
  293. public static void initWarehouseData(){
  294. loadProductTypeFromDb(); //新增
  295. resetScanA();
  296. }
  297. public static void resetScanA() {
  298. work_status = 0;
  299. check_quality_result = false;
  300. // MesClient.start_work_bt.setVisible(false);
  301. // MesClient.finish_ng_bt.setVisible(false);
  302. // MesClient.finish_ok_bt.setVisible(false);
  303. MesClient.finish_ok_bt.setEnabled(false);
  304. product_sn.setText("");
  305. batch_sn_text.setText("");
  306. weight_text.setText("");
  307. batch_sn_bt.setEnabled(false);
  308. weight_text.setEnabled(false);
  309. is_js_btn.setText("最后一台");
  310. is_js_btn_val = "1";
  311. is_js_btn.setBackground(null);
  312. finish_ok_bt.setEnabled(false);
  313. MesClient.finish_ok_bt_1.setText("称重");
  314. // MesClient.f_scan_data_bt_1.setEnabled(false);
  315. MesClient.f_scan_data_bt_1.setEnabled(true);
  316. // DataUtil.stopWork(sessionid);
  317. updateProductTypePanelEnabled(true);
  318. if (PRODUCT_TYPE_SWITCH_ENABLED) {
  319. MesClient.setMenuStatus("当前生产类型:" + getProductTypeName() + ",请扫工件码",0);
  320. } else {
  321. MesClient.setMenuStatus("请扫工件码",0);
  322. }
  323. // product_result_text.setText("");
  324. // work_status_text.setText("");
  325. // MesClient.setMenuStatus("涂胶已超过10分钟,已失效",-1);
  326. // updateMaterailData();
  327. shiftUserCheck();
  328. }
  329. public static int userLoginHours;//用户登录所处小时
  330. //换班用户信息检查
  331. private static void shiftUserCheck() {
  332. LocalDateTime now = LocalDateTime.now();
  333. // 判断时间范围
  334. if (userLoginHours >= 8 && userLoginHours < 20) {
  335. int hour = now.getHour();
  336. if (hour >= 20 || hour < 8) {
  337. logoff();
  338. }
  339. } else {
  340. int hour = now.getHour();
  341. if (hour >= 8 && hour < 20) {
  342. logoff();
  343. }
  344. }
  345. }
  346. public static void resetScanB() {
  347. }
  348. //获取用户20位
  349. public static void getUser() {
  350. user20 = user_menu.getText().toString();
  351. String space_tmp1 = "";
  352. if(user20.length()<20) {
  353. for(int i=0;i<20-user20.length();i++) {
  354. space_tmp1 = space_tmp1 + " ";
  355. }
  356. }
  357. user20 = user20 + space_tmp1;
  358. }
  359. //获取barcode内容36位
  360. public static String getBarcode(String barcodeTmp) {
  361. String barcodeRet = barcodeTmp;
  362. if(barcodeTmp.equalsIgnoreCase("")) {
  363. return "";
  364. }else {
  365. if(barcodeTmp.length()<36) {
  366. String space = "";
  367. for(int i=0;i<36-barcodeTmp.length();i++) {
  368. space = space + " ";
  369. }
  370. barcodeRet = barcodeTmp + space;
  371. }
  372. }
  373. return barcodeRet;
  374. }
  375. public static void scanBarcode() {
  376. if(work_status == 1){
  377. JOptionPane.showMessageDialog(mesClientFrame,"工作中,勿扫码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  378. return;
  379. }
  380. String scanBarcodeTitle = "";
  381. switch(scan_type) {
  382. case 1:
  383. product_sn.setText("");
  384. scanBarcodeTitle = "请扫工件码";
  385. break;
  386. }
  387. //弹窗扫工件码
  388. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  389. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  390. scanBarcode = scanBarcode.trim(); //生产类型新增
  391. //获取用户
  392. getUser();
  393. //获取扫码内容36位
  394. String barcode36 = getBarcode(scanBarcode);//处理36为码
  395. //工位号
  396. String gw = "";
  397. switch(scan_type) {
  398. case 1:
  399. product_sn.setText(scanBarcode);
  400. break;
  401. }
  402. //刷新界面
  403. mesClientFrame.repaint();
  404. //生产类型新增
  405. String validateMsg = validateProductSnMessage(scanBarcode);
  406. if (validateMsg != null) {
  407. check_quality_result = false;
  408. work_status = 0;
  409. MesClient.finish_ok_bt.setEnabled(false);
  410. // MesClient.finish_ng_bt.setEnabled(false);
  411. MesClient.f_scan_data_bt_1.setEnabled(true);
  412. updateProductTypePanelEnabled(true);
  413. MesClient.setMenuStatus(validateMsg, -1);
  414. return;
  415. }
  416. updateProductTypePanelEnabled(false);
  417. if(!tcp_connect_flag) {
  418. JOptionPane.showMessageDialog(mesClientFrame,"设备未连接Mes服务器","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  419. return;
  420. }
  421. // 查询工件质量
  422. Boolean sendret = DataUtil.checkQuality(nettyClient,barcode36,user20);
  423. if(!sendret){
  424. JOptionPane.showMessageDialog(mesClientFrame,"消息发送失败,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  425. return;
  426. }
  427. }else {
  428. JOptionPane.showMessageDialog(mesClientFrame,"请扫工件码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  429. return;
  430. }
  431. }
  432. public static void logoff() {
  433. // welcomeWin.setVisible(true);
  434. mesClientFrame.setVisible(false);
  435. //退出程序 退出登录
  436. System.exit(0);
  437. nettyClient = null;
  438. // if(heartBeatTimer!=null) {
  439. // heartBeatTimer.cancel();
  440. // }
  441. // if(heartBeatIconTimer!=null) {
  442. // heartBeatIconTimer.cancel();
  443. // }
  444. tcp_connect_flag = false;
  445. connect_request_flag = false;
  446. }
  447. public MesClient() {
  448. setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
  449. setTitle("MES系统客户端:"+mes_gw + "- " + mes_gw_des);
  450. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  451. setBounds(0, 0, 1024, 768);
  452. JMenuBar menuBar = new JMenuBar();
  453. menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
  454. setJMenuBar(menuBar);
  455. JMenu fileMenu = new JMenu("用户");
  456. fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
  457. fileMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  458. menuBar.add(fileMenu);
  459. JMenuItem exitMenuItem = new JMenuItem("退出");
  460. exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png")));
  461. exitMenuItem.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  462. fileMenu.add(exitMenuItem);
  463. exitMenuItem.addMouseListener(new MouseAdapter() {
  464. @Override
  465. public void mousePressed(MouseEvent e) {//只能检测到mousePressed事件
  466. super.mouseClicked(e);
  467. //dispose();
  468. logoff();
  469. }
  470. });
  471. JMenu settingMenu = new JMenu("设置");
  472. //settingMenu.setVisible(false);
  473. settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
  474. settingMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  475. menuBar.add(settingMenu);
  476. JMenuItem resetTcpMenu = new JMenuItem("\u91CD\u8FDEMES");
  477. resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  478. resetTcpMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  479. resetTcpMenu.addMouseListener(new MouseAdapter() {
  480. @Override
  481. public void mousePressed(MouseEvent e) {
  482. super.mouseClicked(e);
  483. //重连mes
  484. nettyClient.future.channel().close();
  485. }
  486. });
  487. settingMenu.add(resetTcpMenu);
  488. JMenuItem resetTcpMenu_1 = new JMenuItem("刷新工件");
  489. resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  490. resetTcpMenu_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  491. resetTcpMenu_1.addMouseListener(new MouseAdapter() {
  492. @Override
  493. public void mousePressed(MouseEvent e) {
  494. super.mouseClicked(e);
  495. resetScanA();
  496. }
  497. });
  498. settingMenu.add(resetTcpMenu_1);
  499. contentPane = new JPanel();
  500. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  501. setContentPane(contentPane);
  502. contentPane.setLayout(new BorderLayout(0, 0));
  503. JToolBar toolBar = new JToolBar();
  504. contentPane.add(toolBar, BorderLayout.NORTH);
  505. JLabel equipment_statu_label = new JLabel("状态:");
  506. equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER);
  507. equipment_statu_label.setForeground(Color.BLACK);
  508. equipment_statu_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  509. equipment_statu_label.setBackground(Color.LIGHT_GRAY);
  510. toolBar.add(equipment_statu_label);
  511. status_menu = new JButton("设备未连接MES服务器");
  512. if(tcp_connect_flag) {
  513. status_menu.setText("已连接MES服务器");
  514. status_menu.setForeground(Color.GREEN);
  515. }else {
  516. status_menu.setText("未连接MES服务器");
  517. status_menu.setForeground(Color.DARK_GRAY);
  518. }
  519. status_menu.addActionListener(new ActionListener() {
  520. public void actionPerformed(ActionEvent e) {
  521. }
  522. });
  523. status_menu.setForeground(Color.GREEN);
  524. status_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  525. status_menu.setBackground(Color.BLACK);
  526. toolBar.add(status_menu);
  527. JLabel space_1 = new JLabel(" ");
  528. toolBar.add(space_1);
  529. JLabel heart_beat_status_label = new JLabel("心跳:");
  530. heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  531. heart_beat_status_label.setForeground(Color.BLACK);
  532. heart_beat_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  533. heart_beat_status_label.setBackground(Color.LIGHT_GRAY);
  534. toolBar.add(heart_beat_status_label);
  535. heart_beat_menu = new JButton("2024-02-20 23:20:10");
  536. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  537. heart_beat_menu.setForeground(Color.GREEN);
  538. heart_beat_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  539. heart_beat_menu.setBackground(Color.BLACK);
  540. toolBar.add(heart_beat_menu);
  541. JLabel space_2 = new JLabel(" ");
  542. toolBar.add(space_2);
  543. JLabel user_status_label = new JLabel("登录用户:");
  544. user_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  545. user_status_label.setForeground(Color.BLACK);
  546. user_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  547. user_status_label.setBackground(Color.LIGHT_GRAY);
  548. toolBar.add(user_status_label);
  549. user_menu = new JButton("JinJuShi");
  550. user_menu.setForeground(Color.GREEN);
  551. user_menu.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  552. user_menu.setBackground(Color.BLACK);
  553. toolBar.add(user_menu);
  554. JLabel space_3 = new JLabel(" ");
  555. toolBar.add(space_3);
  556. JLabel space_4 = new JLabel(" ");
  557. toolBar.add(space_4);
  558. //删除
  559. /* comboBox = new JComboBox();
  560. comboBox.setBackground(Color.WHITE);
  561. comboBox.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  562. comboBox.setBounds(50, 10, 80, 21);
  563. comboBox.setMaximumSize(new Dimension(100, 40));
  564. comboBox.setMinimumSize(new Dimension(100, 30));
  565. comboBox.setPreferredSize(new Dimension(100, 30));
  566. comboBox.setModel(new DefaultComboBoxModel(new String[] {"COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8"}));
  567. comboBox.setSelectedItem("COM4");
  568. toolBar.add(comboBox);
  569. // 串口发生改变
  570. comboBox.addActionListener(new ActionListener() {
  571. @Override
  572. public void actionPerformed(ActionEvent e) {
  573. if (bluetoothUtils != null) {
  574. bluetoothUtils.closeConnection();
  575. }
  576. MesClient.initComPort();
  577. }
  578. });*/
  579. tabbedPane = new JTabbedPane(JTabbedPane.TOP);
  580. tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
  581. tabbedPane.setMinimumSize(new Dimension(400, 50));
  582. tabbedPane.setFont(new Font("宋体", Font.BOLD, 22));
  583. contentPane.add(tabbedPane);
  584. //首页
  585. JPanel indexPanelA = new JPanel();
  586. indexScrollPaneA = new JScrollPane(indexPanelA);
  587. indexPanelA.setLayout(null);
  588. product_sn = new JTextField();
  589. product_sn.setHorizontalAlignment(SwingConstants.CENTER);
  590. product_sn.setEditable(false);
  591. product_sn.setFont(new Font("微软雅黑", Font.PLAIN, 28));
  592. product_sn.setBounds(81, 70, 602, 70);
  593. indexPanelA.add(product_sn);
  594. product_sn.setColumns(10);
  595. f_scan_data_bt_1 = new JButton("扫码");
  596. f_scan_data_bt_1.addActionListener(new ActionListener() {
  597. public void actionPerformed(ActionEvent e) {
  598. scan_type = 1;
  599. scanBarcode();
  600. }
  601. });
  602. f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
  603. f_scan_data_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  604. f_scan_data_bt_1.setBounds(693, 70, 198, 70);
  605. indexPanelA.add(f_scan_data_bt_1);
  606. // String[] hjtitles = new String[]{"焊机1","焊机2","焊机3"};
  607. // String[] hjvals = new String[]{"HJ001","HJ002","HJ003"};
  608. // mesRadioHj = new MesRadio(hjtitles,hjvals);
  609. // mesRadioHj.setSize(500,50);
  610. // mesRadioHj.setBounds(190,170,500,50);
  611. // indexPanelA.add(mesRadioHj);
  612. finish_ok_bt = new JButton("打包");
  613. finish_ok_bt.setEnabled(false);
  614. finish_ok_bt.addActionListener(new ActionListener() {
  615. public void actionPerformed(ActionEvent e ) {
  616. if(work_status == 1 && check_quality_result) {
  617. if ( batch_sn_text.getText().equals("")){
  618. JOptionPane.showMessageDialog(mesClientFrame,"请先获取包装码!","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  619. return;
  620. }
  621. if (weight_text.getText().isEmpty()) {
  622. JOptionPane.showMessageDialog(mesClientFrame,"请先称重!","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  623. return;
  624. }
  625. String wig = weight_text.getText();
  626. String is_js = is_js_btn_val;
  627. String result = HttpUtils.sendRequest(
  628. "http://"+MesClient.mes_server_ip+":8980/js/a/mes/mesProductRecord/dp350?" +
  629. "sn=" + product_sn.getText() + "&oprno=" + mes_gw + "&batchSn=" +
  630. batch_sn_text.getText() + "&weight=" + wig + "&isJs=" + is_js + "&ucode=system"+"&lineSn="+mes_line_sn);
  631. weight_text.setText("");
  632. if (result != null && !result.equals("") && !result.equals("false")) {
  633. JSONObject ret = JSON.parseObject(result);
  634. if (ret.get("result").equals("true")) {
  635. MesClient.setMenuStatus("结果提交成功,请扫下一件",0);
  636. resetScanA();
  637. // cjTimer.cancel();
  638. // MesClient.weight_text.setText("");
  639. }else {
  640. JOptionPane.showMessageDialog(mesClientFrame, "结果提交失败,"+ret.get("message")+"!", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  641. MesClient.setMenuStatus("结果提交失败,请重试!",1);
  642. }
  643. }
  644. // String sn = getBarcode(product_sn.getText());
  645. // getUser();
  646. //
  647. // String qret = "OK";
  648. // Boolean sendret = DataUtil.sendQuality(nettyClient, sn, qret, user20);
  649. // if (!sendret) {
  650. // JOptionPane.showMessageDialog(mesClientFrame, "消息发送失败,请重试", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  651. // return;
  652. // }
  653. }
  654. }
  655. });
  656. finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  657. finish_ok_bt.setFont(new Font("微软雅黑", Font.PLAIN, 40));
  658. finish_ok_bt.setBounds(578, 405, 212, 92);
  659. indexPanelA.add(finish_ok_bt);
  660. //重量输入框(由串口定时器定时获取重量)
  661. weight_text = new JTextField();
  662. weight_text.setHorizontalAlignment(SwingConstants.CENTER);
  663. weight_text.setFont(new Font("微软雅黑", Font.PLAIN, 28));
  664. weight_text.setEditable(false);
  665. weight_text.setColumns(10);
  666. weight_text.setBounds(403, 300, 181, 70);
  667. weight_text.setText("");
  668. indexPanelA.add(weight_text);
  669. //包装码输入框
  670. batch_sn_text = new JTextField();
  671. batch_sn_text.setEditable(false);
  672. batch_sn_text.setHorizontalAlignment(SwingConstants.CENTER);
  673. batch_sn_text.setFont(new Font("微软雅黑", Font.PLAIN, 28));
  674. batch_sn_text.setColumns(10);
  675. batch_sn_text.setBounds(403, 192, 280, 70);
  676. indexPanelA.add(batch_sn_text);
  677. batch_sn_bt = new JButton("生成包装码");
  678. batch_sn_bt.setEnabled(false);
  679. batch_sn_bt.addActionListener(new ActionListener() {
  680. public void actionPerformed(ActionEvent e) {
  681. //生成包装码
  682. try {
  683. String result = HttpUtils.sendRequest("http://"+MesClient.mes_server_ip+":8980/js/a/mes/mesBatchSn/createBatchSn?lineSn="+mes_line_sn);
  684. JSONObject ret = JSON.parseObject(result);
  685. String TF = ret.getString("result");
  686. if (Boolean.parseBoolean(TF)){
  687. String batchSn = ret.getJSONObject("data").getString("batchSn");
  688. //赋值 禁用生成按钮
  689. batch_sn_text.setText(batchSn);
  690. MesClient.batch_sn_bt.setEnabled(false);
  691. MesClient.finish_ok_bt.setEnabled(true);
  692. setMenuStatus("生成包装码成功",0);
  693. // 打印包装码标签(文字 + 二维码)
  694. PrintUtil.printLabel(batchSn);
  695. }else{
  696. JOptionPane.showMessageDialog(mesClientFrame,"生成包装码失败!,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  697. }
  698. } catch (Exception ex) {
  699. ex.printStackTrace();
  700. JOptionPane.showMessageDialog(mesClientFrame,"生成包装码失败!,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  701. }
  702. // if (result!= null&&!result.equals("")&&!result.equals("false")) {
  703. // JSONObject ret = JSON.parseObject(result);
  704. // if (ret != null && ret.containsKey("data")) {
  705. // String batchSn = ret.getJSONObject("data").getString("batchSn");
  706. // if (batchSn == null || batchSn.equals("")) { // 包装码为null,激活生成包装码按钮
  707. // JOptionPane.showMessageDialog(mesClientFrame,"生成包装码失败!,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  708. // }else{
  709. // //赋值 禁用生成按钮
  710. // batch_sn_text.setText(batchSn);
  711. // MesClient.batch_sn_bt.setEnabled(false);
  712. // }
  713. // }
  714. //
  715. // }else{
  716. // JOptionPane.showMessageDialog(mesClientFrame,"生成包装码失败!,请重试","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  717. // }
  718. }
  719. });
  720. batch_sn_bt.setFont(new Font("微软雅黑", Font.PLAIN, 30));
  721. batch_sn_bt.setBounds(693, 192, 198, 70);
  722. indexPanelA.add(batch_sn_bt);
  723. //重量标签
  724. lblNewLabel = new JLabel("重量");
  725. lblNewLabel.setEnabled(false);
  726. lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
  727. lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 30));
  728. lblNewLabel.setBounds(238, 300, 117, 70);
  729. indexPanelA.add(lblNewLabel);
  730. lblNewLabel_1 = new JLabel("包装码");
  731. lblNewLabel_1.setEnabled(false);
  732. lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
  733. lblNewLabel_1.setFont(new Font("微软雅黑", Font.PLAIN, 30));
  734. lblNewLabel_1.setBounds(238, 192, 117, 70);
  735. indexPanelA.add(lblNewLabel_1);
  736. is_js_btn = new JButton("最后一台");
  737. is_js_btn.addActionListener(new ActionListener() {
  738. public void actionPerformed(ActionEvent e) {
  739. // if (is_js_btn.getText().equals("结束")){
  740. // is_js_btn.setText("开始");
  741. // }else if (is_js_btn.getText().equals("开始")){
  742. // is_js_btn.setText("结束");
  743. // }
  744. if (is_js_btn_val.equals("2")){
  745. is_js_btn.setBackground(null);
  746. is_js_btn_val = "1";
  747. }else{
  748. // is_js_btn.setText("结束");
  749. is_js_btn.setBackground(Color.GREEN);
  750. is_js_btn_val = "2";
  751. }
  752. }
  753. });
  754. is_js_btn.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  755. is_js_btn.setBounds(693, 300, 198, 70);
  756. indexPanelA.add(is_js_btn);
  757. //称重按钮,触发称重操作
  758. finish_ok_bt_1 = new JButton("称重");
  759. finish_ok_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  760. finish_ok_bt_1.addActionListener(new ActionListener() {
  761. public void actionPerformed(ActionEvent e) {
  762. if (!com_connect_flag || serialPortUtils == null) {
  763. JOptionPane.showMessageDialog(mesClientFrame, "称重串口未连接", "提示窗口", JOptionPane.INFORMATION_MESSAGE);
  764. return;
  765. }
  766. new Thread(() -> serialPortUtils.requestWeight()).start();
  767. }
  768. });
  769. finish_ok_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 40));
  770. finish_ok_bt_1.setEnabled(true);
  771. finish_ok_bt_1.setBounds(207, 405, 212, 92);
  772. indexPanelA.add(finish_ok_bt_1);
  773. tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
  774. tabbedPane.setEnabledAt(0, true);
  775. // searchScrollPane = new JScrollPane((Component) null);
  776. indexPanelC = new JPanel(new BorderLayout());
  777. if (PRODUCT_TYPE_SWITCH_ENABLED) {
  778. //新增的面板
  779. JPanel indexPanelProductType = new JPanel();
  780. indexPanelProductType.setLayout(null);
  781. JScrollPane productTypeScrollPane = new JScrollPane(indexPanelProductType);
  782. JLabel productTypeTitle = new JLabel("生产类型设置");
  783. productTypeTitle.setFont(new Font("微软雅黑", Font.BOLD, 28));
  784. productTypeTitle.setForeground(new Color(64, 64, 64));
  785. productTypeTitle.setHorizontalAlignment(SwingConstants.CENTER);
  786. productTypeTitle.setBounds(81, 80, 810, 50);
  787. indexPanelProductType.add(productTypeTitle);
  788. JLabel productTypeHint = new JLabel("请选择当前生产的工件类型,切换后将保存到本地并用于扫码校验");
  789. productTypeHint.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  790. productTypeHint.setForeground(new Color(140, 140, 140));
  791. productTypeHint.setHorizontalAlignment(SwingConstants.CENTER);
  792. productTypeHint.setBounds(81, 140, 810, 40);
  793. indexPanelProductType.add(productTypeHint);
  794. productTypePanel = new ProductTypePanel(PRODUCT_TYPE_SWITCH_PASSWORD);
  795. productTypePanel.setBounds(276, 210, 420, 72);
  796. productTypePanel.setOnChangeListener(() -> {
  797. if (work_status == 0) {
  798. saveProductTypeToDb();
  799. if (PRODUCT_TYPE_SWITCH_ENABLED) {
  800. setMenuStatus("当前生产类型:" + getProductTypeName() + ",请扫工件码",0);
  801. } else {
  802. setMenuStatus("请扫工件码",0);
  803. }
  804. }
  805. refreshProductTypeCurrentLabel();
  806. });
  807. indexPanelProductType.add(productTypePanel);
  808. productTypeCurrentLabel = new JLabel();
  809. productTypeCurrentLabel.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  810. productTypeCurrentLabel.setForeground(new Color(64, 64, 64));
  811. productTypeCurrentLabel.setHorizontalAlignment(SwingConstants.CENTER);
  812. productTypeCurrentLabel.setBounds(81, 310, 810, 40);
  813. refreshProductTypeCurrentLabel();
  814. indexPanelProductType.add(productTypeCurrentLabel);
  815. tabbedPane.addTab("生产类型", new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")), productTypeScrollPane, null);
  816. }
  817. tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexPanelC, null);
  818. indexPanelB = new JPanel();
  819. searchScrollPane = new JScrollPane(indexPanelB);
  820. indexPanelB.setLayout(null);
  821. tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
  822. tabbedPane.addChangeListener(new ChangeListener() {
  823. @Override
  824. public void stateChanged(ChangeEvent e) {
  825. JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
  826. int selectedIndex = tabbedPane.getSelectedIndex();
  827. System.out.println("selectedIndex:"+selectedIndex);
  828. if(selectedIndex == 1){
  829. }
  830. }
  831. });
  832. }
  833. private static String validateProductSnMessage(String sn) {
  834. if (sn == null || sn.isEmpty()) {
  835. return "工件码为空,请重试";
  836. }
  837. if (sn.length() != PRODUCT_SN_LENGTH) {
  838. return "工件码长度须为32位,当前" + sn.length() + "位";
  839. }
  840. if (!PRODUCT_TYPE_SWITCH_ENABLED) {
  841. return null;
  842. }
  843. String prefix = getProductSnPrefix();
  844. if (!sn.startsWith(prefix)) {
  845. return "工件码前缀与当前类型(" + getProductTypeName() + ")不匹配,当前工件码为" + getProductTypeNameBySn(sn);
  846. }
  847. return null;
  848. }
  849. private static void updateProductTypePanelEnabled(boolean enabled) {
  850. if (productTypePanel != null) {
  851. productTypePanel.setEnabled(enabled);
  852. }
  853. }
  854. public static void loadProductTypeFromDb() {
  855. if (productTypePanel == null) {
  856. return;
  857. }
  858. String savedType = JdbcUtils.getClientConfig(
  859. JdbcUtils.getProductTypeConfigKey(mes_gw),
  860. PRODUCT_TYPE_ZJ
  861. );
  862. if (PRODUCT_TYPE_SJ.equals(savedType)) {
  863. productTypePanel.setResult(PRODUCT_TYPE_SJ);
  864. } else {
  865. productTypePanel.setResult(PRODUCT_TYPE_ZJ);
  866. }
  867. refreshProductTypeCurrentLabel();
  868. }
  869. public static void refreshProductTypeCurrentLabel() {
  870. if (productTypeCurrentLabel != null) {
  871. productTypeCurrentLabel.setText("当前选择:" + getProductTypeName() + "(前缀 " + getProductSnPrefix() + ")");
  872. }
  873. }
  874. public static void saveProductTypeToDb() {
  875. if (productTypePanel == null) {
  876. return;
  877. }
  878. JdbcUtils.saveClientConfig(
  879. JdbcUtils.getProductTypeConfigKey(mes_gw),
  880. productTypePanel.getResult()
  881. );
  882. }
  883. public static String getProductSnPrefix() {
  884. if (productTypePanel != null && PRODUCT_TYPE_SJ.equals(productTypePanel.getResult())) {
  885. return PREFIX_SJ;
  886. }
  887. return PREFIX_ZJ;
  888. }
  889. public static String getProductTypeName() {
  890. if (productTypePanel != null) {
  891. return productTypePanel.getTypeName();
  892. }
  893. return "智界";
  894. }
  895. private static String getProductTypeNameBySn(String sn) {
  896. if (sn.startsWith(PREFIX_SJ)) {
  897. return "尚界";
  898. }
  899. if (sn.startsWith(PREFIX_ZJ)) {
  900. return "智界";
  901. }
  902. return "未知";
  903. }
  904. public static void setMenuStatus(String msg,int error){
  905. if(error == 0){
  906. MesClient.status_menu.setForeground(Color.GREEN);
  907. }else{
  908. MesClient.status_menu.setForeground(Color.RED);
  909. }
  910. MesClient.status_menu.setText(msg);
  911. }
  912. public static void getMaterailData(){
  913. JSONObject retObj = DataUtil.getBindMaterail();
  914. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  915. java.util.List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  916. int i = 0;
  917. rowData = new Object[arrs.size()][7];
  918. for (BindMaterialResp bindMaterialResp:arrs){
  919. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  920. rowData[i][1] = bindMaterialResp.getBatchSn();
  921. rowData[i][2] = bindMaterialResp.getLastTimes();
  922. rowData[i][3] = "";
  923. rowData[i][4] = bindMaterialResp.getCraft();
  924. rowData[i][5] = bindMaterialResp.getMaterialId();
  925. rowData[i][6] = bindMaterialResp.getType();
  926. i++;
  927. }
  928. bindBatchPanel();
  929. }
  930. }
  931. public static void updateMaterailData(){
  932. JSONObject retObj = DataUtil.getBindMaterail();
  933. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  934. List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  935. int i = 0;
  936. for (BindMaterialResp bindMaterialResp:arrs){
  937. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  938. rowData[i][1] = bindMaterialResp.getBatchSn();
  939. rowData[i][2] = bindMaterialResp.getLastTimes();
  940. rowData[i][3] = "";
  941. rowData[i][4] = bindMaterialResp.getCraft();
  942. rowData[i][5] = bindMaterialResp.getMaterialId();
  943. rowData[i][6] = bindMaterialResp.getType();
  944. i++;
  945. }
  946. MesClient.table.repaint();
  947. }
  948. }
  949. // 绑定物料批次码
  950. public static void scanBatchSn(BindMaterialResp bindMaterialResp) {
  951. //弹窗扫工件码
  952. String scanBarcodeTitle = "请扫物料:"+bindMaterialResp.getMaterialTitle();
  953. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  954. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  955. JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType());
  956. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  957. MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0);
  958. updateMaterailData();
  959. }else{
  960. if(retObj.get("result")==null){
  961. MesClient.setMenuStatus("请求失败,请重试",-1);
  962. }else{
  963. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  964. MesClient.setMenuStatus(retObj.getString("message"),-1);
  965. }
  966. }
  967. }
  968. }
  969. }
  970. public static void bindBatchPanel(){
  971. JPanel indexPanelBB = new JPanel();
  972. JPanel panel = new JPanel();
  973. panel.setBounds(0, 0, 990, 550);
  974. // panel.setBounds(81, 50, 810, 479);
  975. indexPanelBB.add(panel);
  976. panel.setLayout(new GridLayout(0, 1, 0, 0));
  977. table = new JTable(rowData, columnNames){
  978. public boolean isCellEditable(int row, int column) {
  979. if(column == 3){
  980. return true;
  981. }
  982. return false;
  983. }
  984. };
  985. table.setRowHeight(40);
  986. table.setEnabled(true);
  987. table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  988. table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
  989. table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
  990. JScrollPane scrollPane = new JScrollPane(table);
  991. panel.add(scrollPane);
  992. JScrollPane indexScrollPaneB = new JScrollPane(indexPanelBB);
  993. indexPanelBB.setLayout(null);
  994. tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
  995. }
  996. }