MesClient.java 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531
  1. package com.mes.ui;
  2. import com.alibaba.fastjson2.JSON;
  3. import com.alibaba.fastjson2.JSONArray;
  4. import com.alibaba.fastjson2.JSONObject;
  5. import com.github.s7connector.impl.utils.S7Utils;
  6. import com.github.xingshuangs.iot.protocol.modbus.service.ModbusTcp;
  7. import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
  8. import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
  9. import com.mes.component.MesRadio;
  10. import com.mes.component.MesWebView;
  11. import com.mes.component.MyDialog;
  12. import com.mes.netty.NettyClient;
  13. import com.mes.util.DateLocalUtils;
  14. import com.mes.util.HttpUtils;
  15. import com.mes.util.JdbcUtils;
  16. import javafx.embed.swing.JFXPanel;
  17. import org.slf4j.Logger;
  18. import org.slf4j.LoggerFactory;
  19. import javax.swing.*;
  20. import javax.swing.border.EmptyBorder;
  21. import javax.swing.event.ChangeEvent;
  22. import javax.swing.event.ChangeListener;
  23. import java.awt.*;
  24. import java.awt.event.ActionEvent;
  25. import java.awt.event.ActionListener;
  26. import java.awt.event.MouseAdapter;
  27. import java.awt.event.MouseEvent;
  28. import java.io.BufferedReader;
  29. import java.io.IOException;
  30. import java.io.InputStream;
  31. import java.io.InputStreamReader;
  32. import java.sql.ResultSet;
  33. import java.sql.SQLException;
  34. import java.sql.Statement;
  35. import java.time.LocalDateTime;
  36. import java.util.ArrayList;
  37. import java.util.Properties;
  38. import java.util.Timer;
  39. import java.util.TimerTask;
  40. import java.util.List;
  41. public class MesClient extends JFrame {
  42. public static final Logger log = LoggerFactory.getLogger(MesClient.class);
  43. private static String Drivde = "org.sqlite.JDBC";
  44. public static int mes_auth = 0;
  45. public static String mes_gw = "";
  46. public static String mes_gw_des = "";
  47. public static String mes_server_ip = "";
  48. public static int mes_tcp_port = 3000;
  49. public static int mes_heart_beat_cycle = 10;
  50. public static int mes_heart_icon_cycle = 1;
  51. public static String mes_line_sn = "";
  52. public static String mes_gwflag = ""; // 工位标识
  53. public static NettyClient nettyClient;
  54. public static boolean tcp_connect_flag = false;
  55. public static boolean connect_request_flag = false;
  56. //session
  57. public static String sessionid = "";
  58. public static JPanel contentPane;
  59. public static MesClient mesClientFrame;
  60. public static JTabbedPane tabbedPane;
  61. public static JScrollPane indexScrollPaneA;
  62. public static JScrollPane indexScrollPaneB;
  63. public static JScrollPane searchScrollPane;
  64. public static JScrollPane searchScrollPaneDj;
  65. public static JScrollPane searchScrollPaneGz;
  66. public static Boolean check_quality_result = false;
  67. public static Integer work_status = 0;
  68. public static Integer work_status2 = 0;
  69. public static Boolean check_quality_result2 = false;
  70. public static Integer batch_status = 0; //A面 1=已绑定 0=未绑定
  71. public static Integer batch_status2 = 0; //B面 1=已绑定 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_ok_bt2;
  78. public static JButton finish_ng_bt;
  79. public static JButton finish_ng_bt2;
  80. public static JTextField product_sn;
  81. public static JLabel pxstatus1;
  82. public static JLabel pxstatus2;
  83. public static JButton batch_scan_1;
  84. public static JButton batch_scan_2;
  85. public static Integer tjFlag = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束
  86. public static Integer tjFlaga = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束
  87. public static Integer tjFlagb = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束
  88. public static Integer tjStatusa = 0; // 1=提交失败
  89. public static Integer tjStatusb = 0; // 1=提交失败
  90. public static String curFlag = ""; // 当前工作的面板
  91. public static String curSna = "";
  92. public static String curSnb = "";
  93. public static String curPage = "";
  94. public static Integer checkA = 0;
  95. public static Integer checkB = 0;
  96. public static Integer lastpage = 0;
  97. public static Boolean mesQualityFlagA = false; // true=可工作
  98. public static Boolean mesQualityFlagB = false; // true=可工作
  99. public static Boolean mesErrorFlagA = false; // true=提交MES失败,手动提交
  100. public static Boolean mesErrorFlagB = false; // true=提交MES失败,手动提交
  101. public static String user20 = "";
  102. public static JFrame welcomeWin;
  103. public static JPanel indexPanelB;
  104. public static MesWebView jfxPanel = null;
  105. public static MesRadio mesRadioHj;
  106. public static JPanel indexPanelC;
  107. public static MesWebView jfxPanel2 = null;
  108. public static S7PLC s7PLC = new S7PLC(EPlcType.S1200, "192.168.7.100"); //100 B工位 新设备
  109. public static List<String> hjparams = new ArrayList<>();
  110. public static JTable table;
  111. public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
  112. public static Object[][] rowData = null;
  113. // public static Object[][] rowData = {
  114. // };
  115. public static void main(String[] args) {
  116. EventQueue.invokeLater(new Runnable() {
  117. @Override
  118. public void run() {
  119. try{
  120. //鐠囩粯鏋冩禒鍫曞帳缂冿拷
  121. readProperty();
  122. // 閺勫墽銇氶悾宀勬桨
  123. mesClientFrame = new MesClient();
  124. mesClientFrame.setVisible(false);
  125. JdbcUtils.getConn();
  126. welcomeWin = new LoginFarme();
  127. welcomeWin.setVisible(true);
  128. getMaterailData();
  129. //获取当前面
  130. textFocus();
  131. getPlcParam();
  132. //
  133. upParams();
  134. //
  135. getPlcParams();
  136. }catch (Exception e){
  137. e.printStackTrace();
  138. }
  139. }
  140. });
  141. }
  142. public static Timer cjTimerText;
  143. public static void textFocus() {
  144. if(cjTimerText!=null) {
  145. cjTimerText.cancel();
  146. }
  147. cjTimerText = new Timer();
  148. cjTimerText.schedule(new TimerTask() {
  149. public void run() {
  150. txtfa.requestFocusInWindow();
  151. MesClient.curPage = PlcUtil.getCurAside(s7PLC);
  152. if(MesClient.curPage .equals("A")){
  153. page_text.setText("当前:A面");
  154. }else{
  155. page_text.setText("当前:B面");
  156. }
  157. }
  158. }, 1000,1000);
  159. }
  160. public static Timer cjTimer3;
  161. public static void upParams() {
  162. if(cjTimer3!=null) {
  163. cjTimer3.cancel();
  164. }
  165. cjTimer3 = new Timer();
  166. cjTimer3.schedule(new TimerTask() {
  167. public void run() {
  168. try{
  169. List<CmtReq> prods = JdbcUtils.getCmtParams();
  170. System.out.println("prods:"+ JSON.toJSONString(prods));
  171. if(prods.size() > 0){
  172. // 定时上传参数
  173. JSONObject retObj = DataUtil.upParams(JSON.toJSONString(prods));
  174. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  175. // 更新sqlite已同步
  176. for(CmtReq prodReq:prods){
  177. JdbcUtils.updateProdSync(prodReq.getId(),1);
  178. }
  179. }
  180. }
  181. }catch (Exception e){
  182. e.printStackTrace();
  183. }
  184. }
  185. }, 1000,30*1000);
  186. }
  187. public static Timer cjTimer;
  188. public static void getPlcParam() {
  189. if(cjTimer!=null) {
  190. cjTimer.cancel();
  191. }
  192. cjTimer = new Timer();
  193. cjTimer.schedule(new TimerTask() {
  194. public void run() {
  195. try{
  196. if(!MesClient.sessionid.isEmpty()){
  197. PlcUtil.getStatusA(s7PLC);
  198. }
  199. }catch (Exception e){
  200. e.printStackTrace();
  201. }
  202. try{
  203. if(!MesClient.sessionid.isEmpty()){
  204. PlcUtil.getStatusB(s7PLC);
  205. }
  206. }catch (Exception e){
  207. e.printStackTrace();
  208. }
  209. }
  210. }, 1000,2000);
  211. }
  212. public static Timer cjTimer2;
  213. public static void getPlcParams() {
  214. if(cjTimer2!=null) {
  215. cjTimer2.cancel();
  216. }
  217. cjTimer2 = new Timer();
  218. cjTimer2.schedule(new TimerTask() {
  219. public void run() {
  220. try{
  221. PlcUtil.getParamDyDl(s7PLC);
  222. }catch (Exception e){
  223. e.printStackTrace();
  224. }
  225. }
  226. }, 1000,1000);
  227. }
  228. //鐠囧鍘ょ純顔芥瀮娴狅拷
  229. private static void readProperty() throws IOException{
  230. String enconding = "UTF-8";
  231. InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
  232. Properties pro = new Properties();
  233. BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
  234. pro.load(br);
  235. mes_gw = pro.getProperty("mes.gw");
  236. // mes_gw_des = pro.getProperty("mes.gw_des");
  237. mes_server_ip = pro.getProperty("mes.server_ip");
  238. mes_tcp_port = Integer.parseInt(pro.getProperty("mes.tcp_port"));
  239. mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle"));
  240. mes_line_sn = pro.getProperty("mes.line_sn");
  241. mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
  242. mes_gwflag = pro.getProperty("mes.gwflag");
  243. System.out.println(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
  244. }
  245. // 閸掓繂顫愰崠鏈P
  246. public static void initTcpConnection() {
  247. try {
  248. if(nettyClient==null) {
  249. //閸掓繂顫愰崠鏈P鏉╃偞甯�
  250. nettyClient = new NettyClient();
  251. //TCP鏉╃偞甯撮悩鑸碉拷锟�
  252. tcp_connect_flag = false;
  253. //鐠佸墽鐤員CP鐠囬攱鐪伴悩鑸碉拷锟�
  254. connect_request_flag = true;
  255. DataUtil.synrTcp(nettyClient,mes_gw);
  256. }
  257. } catch (Exception e) {
  258. // TODO Auto-generated catch block
  259. e.printStackTrace();
  260. }
  261. }
  262. //閸氼垰濮╄箛鍐儲閸栧懐鈻兼惔锟�
  263. public static java.util.Timer heartBeatTimer;
  264. public static java.util.Timer heartBeatIconTimer;
  265. public static boolean iconREDFlag = true;
  266. public static JTextField param1;
  267. public static JTextField param2;
  268. public static JTextField param3;
  269. public static JTextField param4;
  270. public static JTextField param5;
  271. public static JTextField product_sn2;
  272. public static JTextField param21;
  273. public static JTextField param22;
  274. public static JTextField param23;
  275. public static JTextField param24;
  276. public static JTextField param25;
  277. public static void startHeartBeatTimer() {
  278. if(heartBeatTimer!=null) {
  279. heartBeatTimer.cancel();
  280. }
  281. heartBeatTimer = new java.util.Timer();
  282. heartBeatTimer.schedule(new TimerTask() {
  283. public void run() {
  284. if(nettyClient!=null&&tcp_connect_flag) {
  285. //System.out.println("閸欐垿锟戒礁绺剧捄铏Г閺傦拷");
  286. DataUtil.heartBeat(nettyClient,mes_gw);
  287. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  288. }
  289. }
  290. }, 100,mes_heart_beat_cycle*1000);
  291. //韫囧啳鐑﹂弰鍓с仛閸ョ偓鐖�
  292. if(heartBeatIconTimer!=null) {
  293. heartBeatIconTimer.cancel();
  294. }
  295. heartBeatIconTimer = new Timer();
  296. heartBeatIconTimer.schedule(new TimerTask() {
  297. public void run() {
  298. if(tcp_connect_flag) {
  299. if(iconREDFlag) {
  300. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  301. iconREDFlag = false;
  302. }else {
  303. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  304. iconREDFlag = true;
  305. }
  306. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  307. heart_beat_menu.repaint();
  308. }else {
  309. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  310. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  311. heart_beat_menu.repaint();
  312. //閼汇儲婀潻鐐村复閸掓瑥鐨剧拠鏇$箾閹猴拷
  313. if(nettyClient!=null&&!tcp_connect_flag){
  314. System.out.println("TCP瀹稿弶鏌囧锟�");
  315. //TCP闁插秵鏌婇崥灞绢劄鏉╃偞甯�
  316. if(!connect_request_flag) {
  317. //System.out.println("TCP闁插秵鏌婇崥灞绢劄鏉╃偞甯�");
  318. //鐠佸墽鐤員CP鐠囬攱鐪伴悩鑸碉拷锟�,閸欘亪鍣搁弬鏉挎倱濮濄儴绻涢幒銉ょ濞嗭拷
  319. connect_request_flag = true;
  320. DataUtil.synrTcp(nettyClient,mes_gw);
  321. }
  322. }
  323. }
  324. }
  325. }, 100,mes_heart_icon_cycle*1000);
  326. }
  327. //鐠佸墽鐤唗cp鏉╃偞甯撮悩鑸碉拷浣规▔缁�锟�
  328. public static void setTcpStatus() {
  329. if(tcp_connect_flag) {
  330. status_menu.setText("已连接MES服务器");
  331. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  332. heart_beat_menu.repaint();
  333. }else {
  334. status_menu.setText("未连接MES服务器");
  335. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  336. heart_beat_menu.repaint();
  337. }
  338. }
  339. public static void initWarehouseData(){
  340. resetScanA();
  341. resetScanB();
  342. }
  343. public static void resetScanA() {
  344. work_status = 0;
  345. check_quality_result = false;
  346. MesClient.finish_ok_bt.setEnabled(false);
  347. MesClient.mesQualityFlagA = false;
  348. product_sn.setText("");
  349. MesClient.pxstatus1.setText("A");
  350. PlcUtil.changeEnable(s7PLC,false);
  351. MesClient.param1.setText("");
  352. MesClient.param2.setText("");
  353. MesClient.param3.setText("");
  354. MesClient.param4.setText("");
  355. MesClient.param5.setText("");
  356. MesClient.param21.setText("");
  357. MesClient.param22.setText("");
  358. MesClient.param23.setText("");
  359. MesClient.param24.setText("");
  360. MesClient.param25.setText("");
  361. MesClient.curSna = "";
  362. MesClient.tjFlaga = 0;
  363. MesClient.checkA = 0;
  364. // MesClient.batch_status = 0;
  365. // MesClient.textField.setText("");
  366. // MesClient.batch_scan_1.setEnabled(false);
  367. MesClient.formatScanType(1);
  368. // PlcUtil.changeEnable(MesClient.s7PLC,false);
  369. finish_ok_bt.setEnabled(false);
  370. finish_ng_bt.setEnabled(false);
  371. updateMaterailData(); // 更新物料
  372. shiftUserCheck();
  373. }
  374. public static int userLoginHours;//用户登录所处小时
  375. public static JTextField textField;
  376. public static JTextField textField_1;
  377. public static JTextField txtfa;
  378. public static JLabel scan_type_text;
  379. public static JLabel page_text;
  380. //换班用户信息检查
  381. private static void shiftUserCheck() {
  382. LocalDateTime now = LocalDateTime.now();
  383. // 判断时间范围
  384. if (userLoginHours >= 8 && userLoginHours < 20) {
  385. int hour = now.getHour();
  386. if (hour >= 20 || hour < 8) {
  387. logoff();
  388. }
  389. } else {
  390. int hour = now.getHour();
  391. if (hour >= 8 && hour < 20) {
  392. logoff();
  393. }
  394. }
  395. }
  396. public static void resetScanB() {
  397. work_status2 = 0;
  398. check_quality_result2 = false;
  399. MesClient.finish_ng_bt.setEnabled(false);
  400. MesClient.mesQualityFlagB = false;
  401. product_sn2.setText("");
  402. PlcUtil.changeEnable(s7PLC,false);
  403. MesClient.pxstatus2.setText("B");
  404. MesClient.param1.setText("");
  405. MesClient.param2.setText("");
  406. MesClient.param3.setText("");
  407. MesClient.param4.setText("");
  408. MesClient.param5.setText("");
  409. MesClient.param21.setText("");
  410. MesClient.param22.setText("");
  411. MesClient.param23.setText("");
  412. MesClient.param24.setText("");
  413. MesClient.param25.setText("");
  414. MesClient.curSnb = "";
  415. MesClient.tjFlagb = 0;
  416. MesClient.checkB = 0;
  417. // MesClient.batch_status2 = 0;
  418. // MesClient.textField_1.setText("");
  419. // MesClient.batch_scan_2.setEnabled(false);
  420. MesClient.formatScanType(1);
  421. // PlcUtil.changeEnable(MesClient.s7PLC,false);
  422. finish_ok_bt2.setEnabled(false);
  423. finish_ng_bt2.setEnabled(false);
  424. updateMaterailData(); // 更新物料
  425. // shiftUserCheck();
  426. }
  427. //閼惧嘲褰囬悽銊﹀煕20娴o拷
  428. public static void getUser() {
  429. user20 = user_menu.getText().toString();
  430. String space_tmp1 = "";
  431. if(user20.length()<20) {
  432. for(int i=0;i<20-user20.length();i++) {
  433. space_tmp1 = space_tmp1 + " ";
  434. }
  435. }
  436. user20 = user20 + space_tmp1;
  437. }
  438. //閼惧嘲褰嘼arcode閸愬懎顔�36娴o拷
  439. public static String getBarcode(String barcodeTmp) {
  440. String barcodeRet = barcodeTmp;
  441. if(barcodeTmp.equalsIgnoreCase("")) {
  442. return "";
  443. }else {
  444. if(barcodeTmp.length()<36) {
  445. String space = "";
  446. for(int i=0;i<36-barcodeTmp.length();i++) {
  447. space = space + " ";
  448. }
  449. barcodeRet = barcodeTmp + space;
  450. }
  451. }
  452. return barcodeRet;
  453. }
  454. public static void logoff() {
  455. welcomeWin.setVisible(true);
  456. mesClientFrame.setVisible(false);
  457. nettyClient = null;
  458. if(heartBeatTimer!=null) {
  459. heartBeatTimer.cancel();
  460. }
  461. if(heartBeatIconTimer!=null) {
  462. heartBeatIconTimer.cancel();
  463. }
  464. tcp_connect_flag = false;
  465. connect_request_flag = false;
  466. }
  467. public MesClient() {
  468. setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
  469. setTitle("MES系统客户端:"+mes_gw + "- " + mes_gw_des);
  470. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  471. setBounds(0, 0, 1024, 768);
  472. JMenuBar menuBar = new JMenuBar();
  473. menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
  474. setJMenuBar(menuBar);
  475. JMenu fileMenu = new JMenu("\u7528\u6237");
  476. fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
  477. fileMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  478. menuBar.add(fileMenu);
  479. JMenuItem exitMenuItem = new JMenuItem("退出");
  480. exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png")));
  481. exitMenuItem.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  482. fileMenu.add(exitMenuItem);
  483. exitMenuItem.addMouseListener(new MouseAdapter() {
  484. @Override
  485. public void mousePressed(MouseEvent e) {//閸欘亣鍏樺Λ锟藉ù瀣煂mousePressed娴滃娆�
  486. super.mouseClicked(e);
  487. //dispose();
  488. logoff();
  489. }
  490. });
  491. JMenu settingMenu = new JMenu("设置");
  492. //settingMenu.setVisible(false);
  493. settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
  494. settingMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  495. menuBar.add(settingMenu);
  496. JMenuItem resetTcpMenu = new JMenuItem("\u91CD\u8FDEMES");
  497. resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  498. resetTcpMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  499. resetTcpMenu.addMouseListener(new MouseAdapter() {
  500. @Override
  501. public void mousePressed(MouseEvent e) {
  502. super.mouseClicked(e);
  503. //闁插秷绻沵es
  504. nettyClient.future.channel().close();
  505. }
  506. });
  507. settingMenu.add(resetTcpMenu);
  508. JMenuItem resetTcpMenu_1 = new JMenuItem("\u91CD\u65B0\u626B\u7801-A");
  509. resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  510. resetTcpMenu_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  511. resetTcpMenu_1.addMouseListener(new MouseAdapter() {
  512. @Override
  513. public void mousePressed(MouseEvent e) {
  514. super.mouseClicked(e);
  515. resetScanA();
  516. }
  517. });
  518. settingMenu.add(resetTcpMenu_1);
  519. JMenuItem resetTcpMenu_1_1 = new JMenuItem("\u91CD\u65B0\u626B\u7801-B");
  520. resetTcpMenu_1_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  521. resetTcpMenu_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  522. resetTcpMenu_1_1.addMouseListener(new MouseAdapter() {
  523. @Override
  524. public void mousePressed(MouseEvent e) {
  525. super.mouseClicked(e);
  526. resetScanB();
  527. }
  528. });
  529. settingMenu.add(resetTcpMenu_1_1);
  530. JMenuItem resetTcpMenu_1sd = new JMenuItem("手动提交-A");
  531. resetTcpMenu_1sd.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  532. resetTcpMenu_1sd.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  533. resetTcpMenu_1sd.addMouseListener(new MouseAdapter() {
  534. @Override
  535. public void mousePressed(MouseEvent e) {
  536. super.mouseClicked(e);
  537. finish_ok_bt.setEnabled(true);
  538. finish_ng_bt.setEnabled(true);
  539. // MesClient.finish_ok_bt.setEnabled(true);
  540. // if(MesClient.work_status == 1){
  541. // Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn.getText(),"OK",MesClient.user20,"A");
  542. // if(!sendret){
  543. // MesClient.pxstatus1.setText("A:结果上传MES失败");
  544. // MesClient.tjStatusa = 1;
  545. // }
  546. // }
  547. }
  548. });
  549. settingMenu.add(resetTcpMenu_1sd);
  550. JMenuItem resetTcpMenu_1_1sd = new JMenuItem("手动提交-B");
  551. resetTcpMenu_1_1sd.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  552. resetTcpMenu_1_1sd.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  553. resetTcpMenu_1_1sd.addMouseListener(new MouseAdapter() {
  554. @Override
  555. public void mousePressed(MouseEvent e) {
  556. super.mouseClicked(e);
  557. finish_ok_bt2.setEnabled(true);
  558. finish_ng_bt2.setEnabled(true);
  559. // MesClient.finish_ng_bt.setEnabled(true);
  560. // Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn2.getText(),"OK",MesClient.user20,"B");
  561. // if(!sendret){
  562. // MesClient.pxstatus2.setText("B:结果上传MES失败");
  563. // MesClient.tjStatusb = 1;
  564. // }
  565. }
  566. });
  567. settingMenu.add(resetTcpMenu_1_1sd);
  568. contentPane = new JPanel();
  569. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  570. setContentPane(contentPane);
  571. contentPane.setLayout(new BorderLayout(0, 0));
  572. JToolBar toolBar = new JToolBar();
  573. contentPane.add(toolBar, BorderLayout.NORTH);
  574. JLabel equipment_statu_label = new JLabel("\u72B6\u6001\uFF1A");
  575. equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER);
  576. equipment_statu_label.setForeground(Color.BLACK);
  577. equipment_statu_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  578. equipment_statu_label.setBackground(Color.LIGHT_GRAY);
  579. toolBar.add(equipment_statu_label);
  580. status_menu = new JButton("设备未连接MES服务器");
  581. if(tcp_connect_flag) {
  582. status_menu.setText("已连接MES服务器");
  583. status_menu.setForeground(Color.GREEN);
  584. }else {
  585. status_menu.setText("未连接MES服务器");
  586. status_menu.setForeground(Color.DARK_GRAY);
  587. }
  588. status_menu.addActionListener(new ActionListener() {
  589. public void actionPerformed(ActionEvent e) {
  590. }
  591. });
  592. status_menu.setForeground(Color.GREEN);
  593. status_menu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  594. status_menu.setBackground(Color.BLACK);
  595. toolBar.add(status_menu);
  596. JLabel space_1 = new JLabel(" ");
  597. toolBar.add(space_1);
  598. JLabel heart_beat_status_label = new JLabel("\u5FC3\u8DF3\uFF1A");
  599. heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  600. heart_beat_status_label.setForeground(Color.BLACK);
  601. heart_beat_status_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  602. heart_beat_status_label.setBackground(Color.LIGHT_GRAY);
  603. toolBar.add(heart_beat_status_label);
  604. heart_beat_menu = new JButton("2024-02-20 23:20:10");
  605. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  606. heart_beat_menu.setForeground(Color.GREEN);
  607. heart_beat_menu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  608. heart_beat_menu.setBackground(Color.BLACK);
  609. toolBar.add(heart_beat_menu);
  610. JLabel space_2 = new JLabel(" ");
  611. toolBar.add(space_2);
  612. JLabel user_status_label = new JLabel("\u767B\u5F55\u7528\u6237\uFF1A");
  613. user_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  614. user_status_label.setForeground(Color.BLACK);
  615. user_status_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  616. user_status_label.setBackground(Color.LIGHT_GRAY);
  617. toolBar.add(user_status_label);
  618. user_menu = new JButton("JinJuShi");
  619. user_menu.setForeground(Color.GREEN);
  620. user_menu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  621. user_menu.setBackground(Color.BLACK);
  622. toolBar.add(user_menu);
  623. JLabel space_3 = new JLabel(" ");
  624. toolBar.add(space_3);
  625. JLabel space_4 = new JLabel(" ");
  626. toolBar.add(space_4);
  627. tabbedPane = new JTabbedPane(JTabbedPane.TOP);
  628. tabbedPane.setMinimumSize(new Dimension(400, 50));
  629. tabbedPane.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 22));
  630. contentPane.add(tabbedPane);
  631. //妫f牠銆�
  632. JPanel indexPanelA = new JPanel();
  633. indexScrollPaneA = new JScrollPane(indexPanelA);
  634. indexPanelA.setLayout(null);
  635. product_sn = new JTextField();
  636. product_sn.setText("");
  637. product_sn.setHorizontalAlignment(SwingConstants.CENTER);
  638. product_sn.setEditable(false);
  639. product_sn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  640. product_sn.setBounds(26, 152, 446, 70);
  641. indexPanelA.add(product_sn);
  642. product_sn.setColumns(10);
  643. // String[] hjtitles = new String[]{"閻掑﹥婧�1","閻掑﹥婧�2","閻掑﹥婧�3"};
  644. // String[] hjvals = new String[]{"HJ001","HJ002","HJ003"};
  645. // mesRadioHj = new MesRadio(hjtitles,hjvals);
  646. // mesRadioHj.setSize(500,50);
  647. // mesRadioHj.setBounds(190,170,500,50);
  648. // indexPanelA.add(mesRadioHj);
  649. finish_ok_bt = new JButton("OK");
  650. finish_ok_bt.setEnabled(false);
  651. finish_ok_bt.addActionListener(new ActionListener() {
  652. public void actionPerformed(ActionEvent e) {
  653. // if(work_status == 1 && check_quality_result){
  654. //
  655. //
  656. // }
  657. String sn = getBarcode(product_sn.getText());
  658. getUser();
  659. if(!sn.isEmpty()){
  660. String qret = "OK";
  661. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"A");
  662. if(!sendret){
  663. MesClient.pxstatus1.setText("A:结果上传MES失败");
  664. MesClient.tjStatusa = 1;
  665. }else{
  666. MesClient.pxstatus1.setText("A:提交成功");
  667. MesClient.status_menu.setText("A件提交成功");
  668. MesClient.resetScanA();
  669. }
  670. }
  671. }
  672. });
  673. finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  674. finish_ok_bt.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  675. finish_ok_bt.setBounds(50, 380, 160, 80);
  676. finish_ok_bt.setEnabled(false);
  677. // indexPanelA.add(finish_ok_bt);
  678. finish_ng_bt = new JButton("NG");
  679. finish_ng_bt.setEnabled(false);
  680. finish_ng_bt.addActionListener(new ActionListener() {
  681. public void actionPerformed(ActionEvent e) {
  682. // if(work_status == 1 && check_quality_result){
  683. //
  684. // String sn = getBarcode(product_sn.getText());
  685. // getUser();
  686. // String qret = "OK";
  687. // Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  688. // if(!sendret){
  689. // JOptionPane.showMessageDialog(mesClientFrame,"上传MES失败,请重试","提醒", JOptionPane.INFORMATION_MESSAGE);
  690. // return;
  691. // }
  692. // }
  693. String sn = getBarcode(product_sn2.getText());
  694. getUser();
  695. if(!sn.isEmpty()){
  696. String qret = "OK";
  697. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  698. if(!sendret){
  699. MesClient.pxstatus2.setText("B:结果上传MES失败");
  700. MesClient.tjStatusb = 1;
  701. }else{
  702. MesClient.pxstatus2.setText("B:提交成功");
  703. MesClient.status_menu.setText("B件提交成功");
  704. MesClient.resetScanB();
  705. }
  706. }
  707. }
  708. });
  709. finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  710. finish_ng_bt.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  711. finish_ng_bt.setBounds(280, 380, 160, 80);
  712. finish_ng_bt.setEnabled(false);
  713. // indexPanelA.add(finish_ng_bt);
  714. finish_ok_bt2 = new JButton("OK");
  715. finish_ok_bt2.setEnabled(false);
  716. finish_ok_bt2.addActionListener(new ActionListener() {
  717. public void actionPerformed(ActionEvent e) {
  718. // if(work_status == 1 && check_quality_result){
  719. //
  720. //
  721. // }
  722. String sn = getBarcode(product_sn.getText());
  723. getUser();
  724. if(!sn.isEmpty()){
  725. String qret = "OK";
  726. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  727. if(!sendret){
  728. MesClient.pxstatus2.setText("B:结果上传MES失败");
  729. MesClient.tjStatusb = 1;
  730. }else{
  731. MesClient.pxstatus2.setText("B:提交成功");
  732. MesClient.status_menu.setText("B件提交成功");
  733. MesClient.resetScanB();
  734. }
  735. }
  736. }
  737. });
  738. finish_ok_bt2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  739. finish_ok_bt2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  740. finish_ok_bt2.setBounds(550, 380, 160, 80);
  741. finish_ok_bt2.setEnabled(false);
  742. // indexPanelA.add(finish_ok_bt2);
  743. finish_ng_bt2 = new JButton("NG");
  744. finish_ng_bt2.setEnabled(false);
  745. finish_ng_bt2.addActionListener(new ActionListener() {
  746. public void actionPerformed(ActionEvent e) {
  747. // if(work_status == 1 && check_quality_result){
  748. //
  749. // String sn = getBarcode(product_sn.getText());
  750. // getUser();
  751. // String qret = "OK";
  752. // Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  753. // if(!sendret){
  754. // JOptionPane.showMessageDialog(mesClientFrame,"上传MES失败,请重试","提醒", JOptionPane.INFORMATION_MESSAGE);
  755. // return;
  756. // }
  757. // }
  758. String sn = getBarcode(product_sn2.getText());
  759. getUser();
  760. if(!sn.isEmpty()){
  761. String qret = "NG";
  762. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  763. if(!sendret){
  764. MesClient.pxstatus2.setText("B:结果上传MES失败");
  765. MesClient.tjStatusb = 1;
  766. }else{
  767. MesClient.pxstatus2.setText("B:提交成功");
  768. MesClient.status_menu.setText("B件提交成功");
  769. MesClient.resetScanB();
  770. }
  771. }
  772. }
  773. });
  774. finish_ng_bt2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  775. finish_ng_bt2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  776. finish_ng_bt2.setBounds(780, 380, 160, 80);
  777. finish_ng_bt2.setEnabled(false);
  778. indexPanelA.add(finish_ng_bt2);
  779. JLabel lblNewLabel = new JLabel("电压");
  780. lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
  781. lblNewLabel.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  782. lblNewLabel.setBounds(26, 340, 100, 40);
  783. lblNewLabel.setVisible(false);
  784. indexPanelA.add(lblNewLabel);
  785. JLabel lblNewLabel_1 = new JLabel("电流");
  786. lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
  787. lblNewLabel_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  788. lblNewLabel_1.setBounds(226, 340, 100, 40);
  789. lblNewLabel_1.setVisible(false);
  790. indexPanelA.add(lblNewLabel_1);
  791. param1 = new JTextField();
  792. param1.setEnabled(false);
  793. param1.setEditable(false);
  794. param1.setHorizontalAlignment(SwingConstants.CENTER);
  795. param1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  796. param1.setBounds(136, 340, 70, 40);
  797. param1.setVisible(false);
  798. indexPanelA.add(param1);
  799. param1.setColumns(10);
  800. param2 = new JTextField();
  801. param2.setEnabled(false);
  802. param2.setEditable(false);
  803. param2.setHorizontalAlignment(SwingConstants.CENTER);
  804. param2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  805. param2.setColumns(10);
  806. param2.setBounds(345, 340, 70, 40);
  807. param2.setVisible(false);
  808. indexPanelA.add(param2);
  809. JLabel lblNewLabel_2 = new JLabel("送丝速度");
  810. lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT);
  811. lblNewLabel_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  812. lblNewLabel_2.setBounds(26, 401, 100, 40);
  813. lblNewLabel_2.setVisible(false);
  814. indexPanelA.add(lblNewLabel_2);
  815. param3 = new JTextField();
  816. param3.setEnabled(false);
  817. param3.setEditable(false);
  818. param3.setHorizontalAlignment(SwingConstants.CENTER);
  819. param3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  820. param3.setColumns(10);
  821. param3.setBounds(136, 401, 70, 40);
  822. param3.setVisible(false);
  823. indexPanelA.add(param3);
  824. JLabel lblNewLabel_1_1 = new JLabel("错误代码");
  825. lblNewLabel_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  826. lblNewLabel_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  827. lblNewLabel_1_1.setBounds(213, 401, 122, 40);
  828. lblNewLabel_1_1.setVisible(false);
  829. indexPanelA.add(lblNewLabel_1_1);
  830. param4 = new JTextField();
  831. param4.setEnabled(false);
  832. param4.setEditable(false);
  833. param4.setHorizontalAlignment(SwingConstants.CENTER);
  834. param4.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  835. param4.setColumns(10);
  836. param4.setBounds(345, 401, 70, 40);
  837. param4.setVisible(false);
  838. indexPanelA.add(param4);
  839. param5 = new JTextField();
  840. param5.setEnabled(false);
  841. param5.setEditable(false);
  842. param5.setHorizontalAlignment(SwingConstants.CENTER);
  843. param5.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  844. param5.setColumns(10);
  845. param5.setBounds(226, 470, 70, 40);
  846. param5.setVisible(false);
  847. indexPanelA.add(param5);
  848. JLabel lblNewLabel_1_1_1 = new JLabel("JOB号");
  849. lblNewLabel_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  850. lblNewLabel_1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  851. lblNewLabel_1_1_1.setBounds(106, 470, 122, 40);
  852. lblNewLabel_1_1_1.setVisible(false);
  853. indexPanelA.add(lblNewLabel_1_1_1);
  854. product_sn2 = new JTextField();
  855. product_sn2.setText("");
  856. product_sn2.setHorizontalAlignment(SwingConstants.CENTER);
  857. product_sn2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  858. product_sn2.setEditable(false);
  859. product_sn2.setColumns(10);
  860. product_sn2.setBounds(517, 152, 446, 70);
  861. indexPanelA.add(product_sn2);
  862. JSeparator separator = new JSeparator();
  863. separator.setBounds(450, 247, 0, 120);
  864. indexPanelA.add(separator);
  865. JSeparator separator_1 = new JSeparator();
  866. separator_1.setOrientation(SwingConstants.VERTICAL);
  867. separator_1.setBounds(495, 91, 23, 250);
  868. indexPanelA.add(separator_1);
  869. JLabel lblNewLabel_3 = new JLabel("电压");
  870. lblNewLabel_3.setHorizontalAlignment(SwingConstants.RIGHT);
  871. lblNewLabel_3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  872. lblNewLabel_3.setBounds(528, 340, 100, 40);
  873. lblNewLabel_3.setVisible(false);
  874. indexPanelA.add(lblNewLabel_3);
  875. param21 = new JTextField();
  876. param21.setEnabled(false);
  877. param21.setEditable(false);
  878. param21.setHorizontalAlignment(SwingConstants.CENTER);
  879. param21.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  880. param21.setColumns(10);
  881. param21.setBounds(638, 340, 70, 40);
  882. param21.setVisible(false);
  883. indexPanelA.add(param21);
  884. JLabel lblNewLabel_1_2 = new JLabel("电流");
  885. lblNewLabel_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
  886. lblNewLabel_1_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  887. lblNewLabel_1_2.setBounds(742, 340, 100, 40);
  888. lblNewLabel_1_2.setVisible(false);
  889. indexPanelA.add(lblNewLabel_1_2);
  890. param22 = new JTextField();
  891. param22.setEnabled(false);
  892. param22.setEditable(false);
  893. param22.setHorizontalAlignment(SwingConstants.CENTER);
  894. param22.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  895. param22.setColumns(10);
  896. param22.setBounds(852, 340, 70, 40);
  897. param22.setVisible(false);
  898. indexPanelA.add(param22);
  899. JLabel lblNewLabel_2_1 = new JLabel("送丝速度");
  900. lblNewLabel_2_1.setHorizontalAlignment(SwingConstants.RIGHT);
  901. lblNewLabel_2_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  902. lblNewLabel_2_1.setBounds(528, 401, 100, 40);
  903. lblNewLabel_2_1.setVisible(false);
  904. indexPanelA.add(lblNewLabel_2_1);
  905. param23 = new JTextField();
  906. param23.setEnabled(false);
  907. param23.setEditable(false);
  908. param23.setHorizontalAlignment(SwingConstants.CENTER);
  909. param23.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  910. param23.setColumns(10);
  911. param23.setBounds(638, 401, 70, 40);
  912. param23.setVisible(false);
  913. indexPanelA.add(param23);
  914. JLabel lblNewLabel_1_1_2 = new JLabel("错误代码");
  915. lblNewLabel_1_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
  916. lblNewLabel_1_1_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  917. lblNewLabel_1_1_2.setBounds(718, 401, 122, 40);
  918. lblNewLabel_1_1_2.setVisible(false);
  919. indexPanelA.add(lblNewLabel_1_1_2);
  920. param24 = new JTextField();
  921. param24.setEnabled(false);
  922. param24.setEditable(false);
  923. param24.setHorizontalAlignment(SwingConstants.CENTER);
  924. param24.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  925. param24.setColumns(10);
  926. param24.setBounds(852, 401, 70, 40);
  927. param24.setVisible(false);
  928. indexPanelA.add(param24);
  929. JLabel lblNewLabel_1_1_1_1 = new JLabel("JOB号");
  930. lblNewLabel_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  931. lblNewLabel_1_1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  932. lblNewLabel_1_1_1_1.setBounds(609, 470, 122, 40);
  933. lblNewLabel_1_1_1_1.setVisible(false);
  934. lblNewLabel_1_1_1_1.setVisible(false);
  935. indexPanelA.add(lblNewLabel_1_1_1_1);
  936. param25 = new JTextField();
  937. param25.setEnabled(false);
  938. param25.setEditable(false);
  939. param25.setHorizontalAlignment(SwingConstants.CENTER);
  940. param25.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  941. param25.setColumns(10);
  942. param25.setBounds(742, 470, 70, 40);
  943. param25.setVisible(false);
  944. indexPanelA.add(param25);
  945. pxstatus1 = new JLabel("A");
  946. pxstatus1.setForeground(new Color(255, 128, 64));
  947. pxstatus1.setHorizontalAlignment(SwingConstants.CENTER);
  948. pxstatus1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  949. pxstatus1.setBounds(26, 98, 446, 44);
  950. indexPanelA.add(pxstatus1);
  951. pxstatus2 = new JLabel("B");
  952. pxstatus2.setForeground(new Color(255, 128, 64));
  953. pxstatus2.setHorizontalAlignment(SwingConstants.CENTER);
  954. pxstatus2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  955. pxstatus2.setBounds(517, 98, 446, 44);
  956. indexPanelA.add(pxstatus2);
  957. JSeparator separator_2 = new JSeparator();
  958. separator_2.setBounds(10, 264, 973, 13);
  959. // indexPanelA.add(separator_2);
  960. JLabel lblNewLabel_4 = new JLabel("\u710A\u673A1");
  961. lblNewLabel_4.setHorizontalAlignment(SwingConstants.CENTER);
  962. lblNewLabel_4.setFont(new Font("微软雅黑", Font.PLAIN, 24));
  963. lblNewLabel_4.setBounds(170, 290, 156, 40);
  964. lblNewLabel_4.setVisible(false);
  965. // indexPanelA.add(lblNewLabel_4);
  966. JLabel lblNewLabel_4_1 = new JLabel("\u710A\u673A2");
  967. lblNewLabel_4_1.setHorizontalAlignment(SwingConstants.CENTER);
  968. lblNewLabel_4_1.setFont(new Font("微软雅黑", Font.PLAIN, 24));
  969. lblNewLabel_4_1.setBounds(670, 287, 156, 40);
  970. lblNewLabel_4_1.setVisible(false);
  971. // indexPanelA.add(lblNewLabel_4_1);
  972. JSeparator separator_1_1 = new JSeparator();
  973. separator_1_1.setOrientation(SwingConstants.VERTICAL);
  974. separator_1_1.setBounds(495, 278, 23, 232);
  975. indexPanelA.add(separator_1_1);
  976. textField = new JTextField();
  977. textField.setText("");
  978. textField.setHorizontalAlignment(SwingConstants.CENTER);
  979. textField.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  980. textField.setEditable(false);
  981. textField.setColumns(10);
  982. textField.setBounds(26, 333, 446, 70);
  983. // indexPanelA.add(textField);
  984. batch_scan_1 = new JButton("解绑");
  985. batch_scan_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/delete.png")));
  986. batch_scan_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  987. batch_scan_1.setEnabled(false);
  988. batch_scan_1.setVisible(false);
  989. batch_scan_1.setBounds(136, 430, 230, 80);
  990. batch_scan_1.addActionListener(new ActionListener() {
  991. public void actionPerformed(ActionEvent e) {
  992. if(MesClient.curPage.equals("B")){
  993. MesClient.setMenuStatus("该状态后梁无法解绑",-1);
  994. }else{
  995. String sn = MesClient.product_sn.getText().trim();
  996. String wsn = MesClient.textField.getText().trim();
  997. JSONObject retObj = DataUtil.unBindWarehouseData(sn,wsn,user_menu.getText().trim(),"400007");
  998. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  999. MesClient.setMenuStatus("后梁码解绑成功",0);
  1000. MesClient.formatScanType(2);
  1001. textField.setText("");
  1002. batch_scan_1.setEnabled(false);
  1003. PlcUtil.changeEnable(s7PLC,false);
  1004. }else{
  1005. MesClient.formatScanType(2);
  1006. batch_scan_1.setEnabled(true);
  1007. if(retObj.get("result")==null){
  1008. MesClient.setMenuStatus("请求失败,后梁码解绑失败,请重试",-1);
  1009. }else{
  1010. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  1011. MesClient.setMenuStatus(retObj.getString("message"),-1);
  1012. }
  1013. }
  1014. }
  1015. }
  1016. }
  1017. });
  1018. indexPanelA.add(batch_scan_1);
  1019. textField_1 = new JTextField();
  1020. textField_1.setText("");
  1021. textField_1.setHorizontalAlignment(SwingConstants.CENTER);
  1022. textField_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  1023. textField_1.setEditable(false);
  1024. textField_1.setColumns(10);
  1025. textField_1.setBounds(517, 333, 446, 70);
  1026. // indexPanelA.add(textField_1);
  1027. batch_scan_2 = new JButton("解绑");
  1028. batch_scan_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/delete.png")));
  1029. batch_scan_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  1030. batch_scan_2.setEnabled(false);
  1031. batch_scan_2.setVisible(false);
  1032. batch_scan_2.setBounds(633, 430, 230, 80);
  1033. batch_scan_2.addActionListener(new ActionListener() {
  1034. public void actionPerformed(ActionEvent e) {
  1035. if(MesClient.curPage.equals("A")){
  1036. MesClient.setMenuStatus("该状态后梁无法解绑",-1);
  1037. }else{
  1038. String sn = MesClient.product_sn2.getText().trim();
  1039. String wsn = MesClient.textField_1.getText().trim();
  1040. JSONObject retObj = DataUtil.unBindWarehouseData(sn,wsn,user_menu.getText().trim(),"400007");
  1041. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1042. MesClient.setMenuStatus("后梁码解绑成功",0);
  1043. MesClient.formatScanType(2);
  1044. textField_1.setText("");
  1045. batch_scan_2.setEnabled(false);
  1046. PlcUtil.changeEnable(s7PLC,false);
  1047. }else{
  1048. if(retObj.get("result")==null){
  1049. MesClient.setMenuStatus("请求失败,前梁码解绑失败,请重试",-1);
  1050. }else{
  1051. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  1052. MesClient.setMenuStatus(retObj.getString("message"),-1);
  1053. }
  1054. }
  1055. }
  1056. }
  1057. }
  1058. });
  1059. indexPanelA.add(batch_scan_2);
  1060. JLabel pxstatus1_1 = new JLabel("A后梁");
  1061. pxstatus1_1.setHorizontalAlignment(SwingConstants.CENTER);
  1062. pxstatus1_1.setForeground(new Color(0, 0, 0));
  1063. pxstatus1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  1064. pxstatus1_1.setBounds(26, 283, 446, 44);
  1065. // indexPanelA.add(pxstatus1_1);
  1066. JLabel pxstatus1_1_1 = new JLabel("B后梁");
  1067. pxstatus1_1_1.setHorizontalAlignment(SwingConstants.CENTER);
  1068. pxstatus1_1_1.setForeground(Color.BLACK);
  1069. pxstatus1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  1070. pxstatus1_1_1.setBounds(517, 283, 446, 44);
  1071. // indexPanelA.add(pxstatus1_1_1);
  1072. txtfa = new JTextField();
  1073. txtfa.setHorizontalAlignment(SwingConstants.LEFT);
  1074. txtfa.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  1075. txtfa.setColumns(10);
  1076. txtfa.setBounds(239, 10, 503, 60);
  1077. indexPanelA.add(txtfa);
  1078. txtfa.addActionListener(new ActionListener() {
  1079. public void actionPerformed(ActionEvent e) {
  1080. scanBarcode();
  1081. }
  1082. });
  1083. page_text = new JLabel("当前:A面");
  1084. page_text.setForeground(new Color(0, 255, 64));
  1085. page_text.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1086. page_text.setHorizontalAlignment(SwingConstants.RIGHT);
  1087. page_text.setBounds(97, 10, 132, 60);
  1088. indexPanelA.add(page_text);
  1089. scan_type_text = new JLabel("镭雕码");
  1090. scan_type_text.setForeground(new Color(255, 128, 64));
  1091. scan_type_text.setHorizontalAlignment(SwingConstants.LEFT);
  1092. scan_type_text.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1093. scan_type_text.setBounds(752, 10, 132, 60);
  1094. indexPanelA.add(scan_type_text);
  1095. tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
  1096. tabbedPane.setEnabledAt(0, true);
  1097. JPanel indexPanelGz = new JPanel();
  1098. searchScrollPaneGz = new JScrollPane(indexPanelGz);
  1099. indexPanelGz.setLayout(null);
  1100. indexPanelC = new JPanel();
  1101. searchScrollPaneDj = new JScrollPane(indexPanelC);
  1102. indexPanelC.setLayout(null);
  1103. tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
  1104. indexPanelB = new JPanel();
  1105. searchScrollPane = new JScrollPane(indexPanelB);
  1106. indexPanelB.setLayout(null);
  1107. tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
  1108. // bindBatchPanel();
  1109. tabbedPane.addChangeListener(new ChangeListener() {
  1110. @Override
  1111. public void stateChanged(ChangeEvent e) {
  1112. JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
  1113. int selectedIndex = tabbedPane.getSelectedIndex();
  1114. System.out.println("selectedIndex:"+selectedIndex);
  1115. if(selectedIndex == 1){
  1116. }
  1117. }
  1118. });
  1119. }
  1120. public static void formatScanType(int st){
  1121. scan_type = st;
  1122. if(scan_type == 1){
  1123. scan_type_text.setText("镭雕码");
  1124. }else if(scan_type == 2){
  1125. scan_type_text.setText("后梁码");
  1126. }else{
  1127. scan_type_text.setText("");
  1128. }
  1129. }
  1130. public static void scanBarcode() {
  1131. String scanBarcodeSn = txtfa.getText().trim();
  1132. txtfa.setText("");
  1133. System.out.println("scan_type:"+scan_type);
  1134. //刷新界面
  1135. mesClientFrame.repaint();
  1136. System.out.println("456");
  1137. System.out.println("156"+scan_type);
  1138. if(MesClient.scan_type == 1){ // 镭雕码
  1139. System.out.println("type1");
  1140. if(scanBarcodeSn.isEmpty()){
  1141. System.out.println("type2");
  1142. MesClient.setMenuStatus("镭雕码不能为空",1);
  1143. return;
  1144. }
  1145. if(MesClient.curPage.equals("A")){
  1146. System.out.println("typeA");
  1147. if(!product_sn.getText().isEmpty() && mesQualityFlagA){
  1148. MesClient.setMenuStatus("A面已存在工件码,勿重复扫码",1);
  1149. return;
  1150. }
  1151. product_sn.setText(scanBarcodeSn);
  1152. }else{
  1153. System.out.println("typeB");
  1154. if(!product_sn2.getText().isEmpty() && mesQualityFlagB){
  1155. MesClient.setMenuStatus("B面已存在工件码,勿重复扫码",1);
  1156. return;
  1157. }
  1158. product_sn2.setText(scanBarcodeSn);
  1159. }
  1160. MesClient.setMenuStatus("扫码成功",0);
  1161. //刷新界面
  1162. mesClientFrame.repaint();
  1163. System.out.println("123");
  1164. getUser();
  1165. // 查询工件质量
  1166. Boolean sendret = DataUtil.checkQuality(nettyClient,scanBarcodeSn,user20,MesClient.curPage);
  1167. if(!sendret){
  1168. MesClient.setMenuStatus("消息发送失败,请重试",1);
  1169. }
  1170. }
  1171. }
  1172. public static void setMenuStatus(String msg,int error){
  1173. if(error == 0){
  1174. MesClient.status_menu.setForeground(Color.GREEN);
  1175. }else{
  1176. MesClient.status_menu.setForeground(Color.RED);
  1177. }
  1178. MesClient.status_menu.setText(msg);
  1179. }
  1180. public static void getMaterailData(){
  1181. JSONObject retObj = DataUtil.getBindMaterail();
  1182. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1183. List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  1184. int i = 0;
  1185. rowData = new Object[arrs.size()][7];
  1186. for (BindMaterialResp bindMaterialResp:arrs){
  1187. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  1188. rowData[i][1] = bindMaterialResp.getBatchSn();
  1189. rowData[i][2] = bindMaterialResp.getLastTimes();
  1190. rowData[i][3] = "";
  1191. rowData[i][4] = bindMaterialResp.getCraft();
  1192. rowData[i][5] = bindMaterialResp.getMaterialId();
  1193. rowData[i][6] = bindMaterialResp.getType();
  1194. i++;
  1195. }
  1196. bindBatchPanel();
  1197. }
  1198. }
  1199. public static void updateMaterailData(){
  1200. JSONObject retObj = DataUtil.getBindMaterail();
  1201. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1202. List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  1203. int i = 0;
  1204. for (BindMaterialResp bindMaterialResp:arrs){
  1205. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  1206. rowData[i][1] = bindMaterialResp.getBatchSn();
  1207. rowData[i][2] = bindMaterialResp.getLastTimes();
  1208. rowData[i][3] = "";
  1209. rowData[i][4] = bindMaterialResp.getCraft();
  1210. rowData[i][5] = bindMaterialResp.getMaterialId();
  1211. rowData[i][6] = bindMaterialResp.getType();
  1212. i++;
  1213. }
  1214. MesClient.table.repaint();
  1215. }
  1216. }
  1217. // 绑定物料批次码
  1218. public static void scanBatchSn(BindMaterialResp bindMaterialResp) { // 扫码类型
  1219. //弹窗扫工件码
  1220. String scanBarcodeTitle = "请扫物料:"+bindMaterialResp.getMaterialTitle();
  1221. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  1222. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  1223. JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType());
  1224. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1225. MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0);
  1226. updateMaterailData();
  1227. }else{
  1228. if(retObj.get("result")==null){
  1229. MesClient.setMenuStatus("请求失败,请重试",-1);
  1230. }else{
  1231. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  1232. MesClient.setMenuStatus(retObj.getString("message"),-1);
  1233. }
  1234. }
  1235. }
  1236. }
  1237. }
  1238. public static void bindBatchPanel(){
  1239. JPanel indexPanelBB = new JPanel();
  1240. JPanel panel = new JPanel();
  1241. panel.setBounds(0, 0, 990, 550);
  1242. // panel.setBounds(81, 50, 810, 479);
  1243. indexPanelBB.add(panel);
  1244. panel.setLayout(new GridLayout(0, 1, 0, 0));
  1245. table = new JTable(rowData, columnNames){
  1246. public boolean isCellEditable(int row, int column) {
  1247. if(column == 3){
  1248. return true;
  1249. }
  1250. return false;
  1251. }
  1252. };
  1253. table.setRowHeight(40);
  1254. table.setEnabled(true);
  1255. table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  1256. table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
  1257. table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
  1258. JScrollPane scrollPane = new JScrollPane(table);
  1259. panel.add(scrollPane);
  1260. indexScrollPaneB = new JScrollPane(indexPanelBB);
  1261. indexPanelBB.setLayout(null);
  1262. tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
  1263. }
  1264. // 开启发送结果定时任务
  1265. public static void startUpdateQualityTimer(){
  1266. new Timer().schedule(new TimerTask() {
  1267. @Override
  1268. public void run() {
  1269. try {
  1270. JdbcUtils.getConn();
  1271. Statement statement = JdbcUtils.conn.createStatement();
  1272. String selectSql = "SELECT id, bw FROM submit_record\n" +
  1273. "WHERE state = 0 ORDER BY id DESC LIMIT 10";
  1274. String updateSql = "UPDATE submit_record \n" +
  1275. "SET state = '1'\n" +
  1276. "WHERE id = ";
  1277. ResultSet rs = statement.executeQuery(selectSql);
  1278. while(rs.next()){
  1279. int id = rs.getInt("id");
  1280. String bw = rs.getString("bw");
  1281. // 发送请求
  1282. String url = "http://"+MesClient.mes_server_ip+":8980/js/a/mes/mesProductRecord/updateQualityByTiming";
  1283. String s = HttpUtils.sendPostRequestJson(url, bw );
  1284. Boolean result = JSONObject.parseObject(s).getBoolean("result");
  1285. if(result) {
  1286. // 更改状态为 1
  1287. statement.executeUpdate(updateSql + id);
  1288. }
  1289. }
  1290. rs.close();
  1291. statement.close();
  1292. } catch (SQLException | IOException e) {
  1293. // throw new RuntimeException(e);
  1294. e.printStackTrace();
  1295. }
  1296. }
  1297. },1000, 5000);
  1298. }
  1299. public static void formatBatchSn(){
  1300. if((MesClient.batch_status == 1 && MesClient.tjFlaga == 1) || (MesClient.batch_status2 == 1 && MesClient.tjFlagb == 1)){
  1301. PlcUtil.changeEnable(MesClient.s7PLC,true);
  1302. }else{
  1303. PlcUtil.changeEnable(MesClient.s7PLC,false);
  1304. }
  1305. }
  1306. private static String checkSnType(String sn){
  1307. String str = sn.substring(9,12);
  1308. if(str.equals("113")){
  1309. return "MX11-2";
  1310. }else if(str.equals("119")){
  1311. return "MX11-2S";
  1312. }else{
  1313. return "";
  1314. }
  1315. }
  1316. // 检查工件是否匹配
  1317. private static Boolean checkSnAndBatch(String sn,String batchSn){
  1318. String gdStr1 = "151245P000012131001000"; // MX11-2
  1319. String gdStr2 = "151245P000017812001000"; // MX11-2S
  1320. String cate = sn.substring(0,22);
  1321. String ptype = checkSnType(batchSn);
  1322. if(ptype.equals("MX11-2") && cate.equals(gdStr1)){
  1323. return true;
  1324. }
  1325. if(ptype.equals("MX11-2S") && cate.equals(gdStr2)){
  1326. return true;
  1327. }
  1328. return false;
  1329. }
  1330. }