MesClient.java 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533
  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. PlcUtil.changeEnable(s7PLC,false);
  343. }
  344. public static void resetScanA() {
  345. work_status = 0;
  346. check_quality_result = false;
  347. MesClient.finish_ok_bt.setEnabled(false);
  348. MesClient.mesQualityFlagA = false;
  349. product_sn.setText("");
  350. MesClient.pxstatus1.setText("A");
  351. // PlcUtil.changeEnable(s7PLC,false);
  352. MesClient.param1.setText("");
  353. MesClient.param2.setText("");
  354. MesClient.param3.setText("");
  355. MesClient.param4.setText("");
  356. MesClient.param5.setText("");
  357. MesClient.param21.setText("");
  358. MesClient.param22.setText("");
  359. MesClient.param23.setText("");
  360. MesClient.param24.setText("");
  361. MesClient.param25.setText("");
  362. MesClient.curSna = "";
  363. MesClient.tjFlaga = 0;
  364. MesClient.checkA = 0;
  365. // MesClient.batch_status = 0;
  366. // MesClient.textField.setText("");
  367. // MesClient.batch_scan_1.setEnabled(false);
  368. MesClient.formatScanType(1);
  369. // PlcUtil.changeEnable(MesClient.s7PLC,false);
  370. finish_ok_bt.setEnabled(false);
  371. finish_ng_bt.setEnabled(false);
  372. updateMaterailData(); // 更新物料
  373. // shiftUserCheck();
  374. }
  375. public static int userLoginHours;//用户登录所处小时
  376. public static JTextField textField;
  377. public static JTextField textField_1;
  378. public static JTextField txtfa;
  379. public static JLabel scan_type_text;
  380. public static JLabel page_text;
  381. //换班用户信息检查
  382. private static void shiftUserCheck() {
  383. LocalDateTime now = LocalDateTime.now();
  384. // 判断时间范围
  385. if (userLoginHours >= 8 && userLoginHours < 20) {
  386. int hour = now.getHour();
  387. if (hour >= 20 || hour < 8) {
  388. logoff();
  389. }
  390. } else {
  391. int hour = now.getHour();
  392. if (hour >= 8 && hour < 20) {
  393. logoff();
  394. }
  395. }
  396. }
  397. public static void resetScanB() {
  398. work_status2 = 0;
  399. check_quality_result2 = false;
  400. MesClient.finish_ng_bt.setEnabled(false);
  401. MesClient.mesQualityFlagB = false;
  402. product_sn2.setText("");
  403. // PlcUtil.changeEnable(s7PLC,false);
  404. MesClient.pxstatus2.setText("B");
  405. MesClient.param1.setText("");
  406. MesClient.param2.setText("");
  407. MesClient.param3.setText("");
  408. MesClient.param4.setText("");
  409. MesClient.param5.setText("");
  410. MesClient.param21.setText("");
  411. MesClient.param22.setText("");
  412. MesClient.param23.setText("");
  413. MesClient.param24.setText("");
  414. MesClient.param25.setText("");
  415. MesClient.curSnb = "";
  416. MesClient.tjFlagb = 0;
  417. MesClient.checkB = 0;
  418. // MesClient.batch_status2 = 0;
  419. // MesClient.textField_1.setText("");
  420. // MesClient.batch_scan_2.setEnabled(false);
  421. MesClient.formatScanType(1);
  422. // PlcUtil.changeEnable(MesClient.s7PLC,false);
  423. finish_ok_bt2.setEnabled(false);
  424. finish_ng_bt2.setEnabled(false);
  425. updateMaterailData(); // 更新物料
  426. // shiftUserCheck();
  427. }
  428. //閼惧嘲褰囬悽銊﹀煕20娴o拷
  429. public static void getUser() {
  430. user20 = user_menu.getText().toString();
  431. String space_tmp1 = "";
  432. if(user20.length()<20) {
  433. for(int i=0;i<20-user20.length();i++) {
  434. space_tmp1 = space_tmp1 + " ";
  435. }
  436. }
  437. user20 = user20 + space_tmp1;
  438. }
  439. //閼惧嘲褰嘼arcode閸愬懎顔�36娴o拷
  440. public static String getBarcode(String barcodeTmp) {
  441. String barcodeRet = barcodeTmp;
  442. if(barcodeTmp.equalsIgnoreCase("")) {
  443. return "";
  444. }else {
  445. if(barcodeTmp.length()<36) {
  446. String space = "";
  447. for(int i=0;i<36-barcodeTmp.length();i++) {
  448. space = space + " ";
  449. }
  450. barcodeRet = barcodeTmp + space;
  451. }
  452. }
  453. return barcodeRet;
  454. }
  455. public static void logoff() {
  456. welcomeWin.setVisible(true);
  457. mesClientFrame.setVisible(false);
  458. nettyClient = null;
  459. if(heartBeatTimer!=null) {
  460. heartBeatTimer.cancel();
  461. }
  462. if(heartBeatIconTimer!=null) {
  463. heartBeatIconTimer.cancel();
  464. }
  465. tcp_connect_flag = false;
  466. connect_request_flag = false;
  467. }
  468. public MesClient() {
  469. setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
  470. setTitle("MES系统客户端:"+mes_gw + "- " + mes_gw_des);
  471. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  472. setBounds(0, 0, 1024, 768);
  473. JMenuBar menuBar = new JMenuBar();
  474. menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
  475. setJMenuBar(menuBar);
  476. JMenu fileMenu = new JMenu("\u7528\u6237");
  477. fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
  478. fileMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  479. menuBar.add(fileMenu);
  480. JMenuItem exitMenuItem = new JMenuItem("退出");
  481. exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png")));
  482. exitMenuItem.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  483. fileMenu.add(exitMenuItem);
  484. exitMenuItem.addMouseListener(new MouseAdapter() {
  485. @Override
  486. public void mousePressed(MouseEvent e) {//閸欘亣鍏樺Λ锟藉ù瀣煂mousePressed娴滃娆�
  487. super.mouseClicked(e);
  488. //dispose();
  489. logoff();
  490. }
  491. });
  492. JMenu settingMenu = new JMenu("设置");
  493. //settingMenu.setVisible(false);
  494. settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
  495. settingMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  496. menuBar.add(settingMenu);
  497. JMenuItem resetTcpMenu = new JMenuItem("\u91CD\u8FDEMES");
  498. resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  499. resetTcpMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  500. resetTcpMenu.addMouseListener(new MouseAdapter() {
  501. @Override
  502. public void mousePressed(MouseEvent e) {
  503. super.mouseClicked(e);
  504. //闁插秷绻沵es
  505. nettyClient.future.channel().close();
  506. }
  507. });
  508. settingMenu.add(resetTcpMenu);
  509. JMenuItem resetTcpMenu_1 = new JMenuItem("\u91CD\u65B0\u626B\u7801-A");
  510. resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  511. resetTcpMenu_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  512. resetTcpMenu_1.addMouseListener(new MouseAdapter() {
  513. @Override
  514. public void mousePressed(MouseEvent e) {
  515. super.mouseClicked(e);
  516. resetScanA();
  517. PlcUtil.changeEnable(s7PLC,false);
  518. }
  519. });
  520. settingMenu.add(resetTcpMenu_1);
  521. JMenuItem resetTcpMenu_1_1 = new JMenuItem("\u91CD\u65B0\u626B\u7801-B");
  522. resetTcpMenu_1_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  523. resetTcpMenu_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  524. resetTcpMenu_1_1.addMouseListener(new MouseAdapter() {
  525. @Override
  526. public void mousePressed(MouseEvent e) {
  527. super.mouseClicked(e);
  528. resetScanB();
  529. PlcUtil.changeEnable(s7PLC,false);
  530. }
  531. });
  532. settingMenu.add(resetTcpMenu_1_1);
  533. JMenuItem resetTcpMenu_1sd = new JMenuItem("手动提交-A");
  534. resetTcpMenu_1sd.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  535. resetTcpMenu_1sd.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  536. resetTcpMenu_1sd.addMouseListener(new MouseAdapter() {
  537. @Override
  538. public void mousePressed(MouseEvent e) {
  539. super.mouseClicked(e);
  540. finish_ok_bt.setEnabled(true);
  541. finish_ng_bt.setEnabled(true);
  542. // MesClient.finish_ok_bt.setEnabled(true);
  543. // if(MesClient.work_status == 1){
  544. // Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn.getText(),"OK",MesClient.user20,"A");
  545. // if(!sendret){
  546. // MesClient.pxstatus1.setText("A:结果上传MES失败");
  547. // MesClient.tjStatusa = 1;
  548. // }
  549. // }
  550. }
  551. });
  552. // settingMenu.add(resetTcpMenu_1sd);
  553. JMenuItem resetTcpMenu_1_1sd = new JMenuItem("手动提交-B");
  554. resetTcpMenu_1_1sd.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  555. resetTcpMenu_1_1sd.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  556. resetTcpMenu_1_1sd.addMouseListener(new MouseAdapter() {
  557. @Override
  558. public void mousePressed(MouseEvent e) {
  559. super.mouseClicked(e);
  560. finish_ok_bt2.setEnabled(true);
  561. finish_ng_bt2.setEnabled(true);
  562. // MesClient.finish_ng_bt.setEnabled(true);
  563. // Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn2.getText(),"OK",MesClient.user20,"B");
  564. // if(!sendret){
  565. // MesClient.pxstatus2.setText("B:结果上传MES失败");
  566. // MesClient.tjStatusb = 1;
  567. // }
  568. }
  569. });
  570. // settingMenu.add(resetTcpMenu_1_1sd);
  571. contentPane = new JPanel();
  572. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  573. setContentPane(contentPane);
  574. contentPane.setLayout(new BorderLayout(0, 0));
  575. JToolBar toolBar = new JToolBar();
  576. contentPane.add(toolBar, BorderLayout.NORTH);
  577. JLabel equipment_statu_label = new JLabel("\u72B6\u6001\uFF1A");
  578. equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER);
  579. equipment_statu_label.setForeground(Color.BLACK);
  580. equipment_statu_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  581. equipment_statu_label.setBackground(Color.LIGHT_GRAY);
  582. toolBar.add(equipment_statu_label);
  583. status_menu = new JButton("设备未连接MES服务器");
  584. if(tcp_connect_flag) {
  585. status_menu.setText("已连接MES服务器");
  586. status_menu.setForeground(Color.GREEN);
  587. }else {
  588. status_menu.setText("未连接MES服务器");
  589. status_menu.setForeground(Color.DARK_GRAY);
  590. }
  591. status_menu.addActionListener(new ActionListener() {
  592. public void actionPerformed(ActionEvent e) {
  593. }
  594. });
  595. status_menu.setForeground(Color.GREEN);
  596. status_menu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  597. status_menu.setBackground(Color.BLACK);
  598. toolBar.add(status_menu);
  599. JLabel space_1 = new JLabel(" ");
  600. toolBar.add(space_1);
  601. JLabel heart_beat_status_label = new JLabel("\u5FC3\u8DF3\uFF1A");
  602. heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  603. heart_beat_status_label.setForeground(Color.BLACK);
  604. heart_beat_status_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  605. heart_beat_status_label.setBackground(Color.LIGHT_GRAY);
  606. toolBar.add(heart_beat_status_label);
  607. heart_beat_menu = new JButton("2024-02-20 23:20:10");
  608. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  609. heart_beat_menu.setForeground(Color.GREEN);
  610. heart_beat_menu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  611. heart_beat_menu.setBackground(Color.BLACK);
  612. toolBar.add(heart_beat_menu);
  613. JLabel space_2 = new JLabel(" ");
  614. toolBar.add(space_2);
  615. JLabel user_status_label = new JLabel("\u767B\u5F55\u7528\u6237\uFF1A");
  616. user_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  617. user_status_label.setForeground(Color.BLACK);
  618. user_status_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  619. user_status_label.setBackground(Color.LIGHT_GRAY);
  620. toolBar.add(user_status_label);
  621. user_menu = new JButton("JinJuShi");
  622. user_menu.setForeground(Color.GREEN);
  623. user_menu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  624. user_menu.setBackground(Color.BLACK);
  625. toolBar.add(user_menu);
  626. JLabel space_3 = new JLabel(" ");
  627. toolBar.add(space_3);
  628. JLabel space_4 = new JLabel(" ");
  629. toolBar.add(space_4);
  630. tabbedPane = new JTabbedPane(JTabbedPane.TOP);
  631. tabbedPane.setMinimumSize(new Dimension(400, 50));
  632. tabbedPane.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 22));
  633. contentPane.add(tabbedPane);
  634. //妫f牠銆�
  635. JPanel indexPanelA = new JPanel();
  636. indexScrollPaneA = new JScrollPane(indexPanelA);
  637. indexPanelA.setLayout(null);
  638. product_sn = new JTextField();
  639. product_sn.setText("");
  640. product_sn.setHorizontalAlignment(SwingConstants.CENTER);
  641. product_sn.setEditable(false);
  642. product_sn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  643. product_sn.setBounds(26, 152, 446, 70);
  644. indexPanelA.add(product_sn);
  645. product_sn.setColumns(10);
  646. // String[] hjtitles = new String[]{"閻掑﹥婧�1","閻掑﹥婧�2","閻掑﹥婧�3"};
  647. // String[] hjvals = new String[]{"HJ001","HJ002","HJ003"};
  648. // mesRadioHj = new MesRadio(hjtitles,hjvals);
  649. // mesRadioHj.setSize(500,50);
  650. // mesRadioHj.setBounds(190,170,500,50);
  651. // indexPanelA.add(mesRadioHj);
  652. finish_ok_bt = new JButton("OK");
  653. finish_ok_bt.setEnabled(false);
  654. finish_ok_bt.addActionListener(new ActionListener() {
  655. public void actionPerformed(ActionEvent e) {
  656. // if(work_status == 1 && check_quality_result){
  657. //
  658. //
  659. // }
  660. String sn = getBarcode(product_sn.getText());
  661. getUser();
  662. if(!sn.isEmpty()){
  663. String qret = "OK";
  664. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"A");
  665. if(!sendret){
  666. MesClient.pxstatus1.setText("A:结果上传MES失败");
  667. MesClient.tjStatusa = 1;
  668. }else{
  669. MesClient.pxstatus1.setText("A:提交成功");
  670. MesClient.status_menu.setText("A件提交成功");
  671. MesClient.resetScanA();
  672. }
  673. }
  674. }
  675. });
  676. finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  677. finish_ok_bt.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  678. finish_ok_bt.setBounds(50, 380, 160, 80);
  679. finish_ok_bt.setEnabled(false);
  680. // indexPanelA.add(finish_ok_bt);
  681. finish_ng_bt = new JButton("NG");
  682. finish_ng_bt.setEnabled(false);
  683. finish_ng_bt.addActionListener(new ActionListener() {
  684. public void actionPerformed(ActionEvent e) {
  685. // if(work_status == 1 && check_quality_result){
  686. //
  687. // String sn = getBarcode(product_sn.getText());
  688. // getUser();
  689. // String qret = "OK";
  690. // Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  691. // if(!sendret){
  692. // JOptionPane.showMessageDialog(mesClientFrame,"上传MES失败,请重试","提醒", JOptionPane.INFORMATION_MESSAGE);
  693. // return;
  694. // }
  695. // }
  696. String sn = getBarcode(product_sn2.getText());
  697. getUser();
  698. if(!sn.isEmpty()){
  699. String qret = "OK";
  700. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  701. if(!sendret){
  702. MesClient.pxstatus2.setText("B:结果上传MES失败");
  703. MesClient.tjStatusb = 1;
  704. }else{
  705. MesClient.pxstatus2.setText("B:提交成功");
  706. MesClient.status_menu.setText("B件提交成功");
  707. MesClient.resetScanB();
  708. }
  709. }
  710. }
  711. });
  712. finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  713. finish_ng_bt.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  714. finish_ng_bt.setBounds(280, 380, 160, 80);
  715. finish_ng_bt.setEnabled(false);
  716. // indexPanelA.add(finish_ng_bt);
  717. finish_ok_bt2 = new JButton("OK");
  718. finish_ok_bt2.setEnabled(false);
  719. finish_ok_bt2.addActionListener(new ActionListener() {
  720. public void actionPerformed(ActionEvent e) {
  721. // if(work_status == 1 && check_quality_result){
  722. //
  723. //
  724. // }
  725. String sn = getBarcode(product_sn.getText());
  726. getUser();
  727. if(!sn.isEmpty()){
  728. String qret = "OK";
  729. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  730. if(!sendret){
  731. MesClient.pxstatus2.setText("B:结果上传MES失败");
  732. MesClient.tjStatusb = 1;
  733. }else{
  734. MesClient.pxstatus2.setText("B:提交成功");
  735. MesClient.status_menu.setText("B件提交成功");
  736. MesClient.resetScanB();
  737. }
  738. }
  739. }
  740. });
  741. finish_ok_bt2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  742. finish_ok_bt2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  743. finish_ok_bt2.setBounds(550, 380, 160, 80);
  744. finish_ok_bt2.setEnabled(false);
  745. // indexPanelA.add(finish_ok_bt2);
  746. finish_ng_bt2 = new JButton("NG");
  747. finish_ng_bt2.setEnabled(false);
  748. finish_ng_bt2.addActionListener(new ActionListener() {
  749. public void actionPerformed(ActionEvent e) {
  750. // if(work_status == 1 && check_quality_result){
  751. //
  752. // String sn = getBarcode(product_sn.getText());
  753. // getUser();
  754. // String qret = "OK";
  755. // Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  756. // if(!sendret){
  757. // JOptionPane.showMessageDialog(mesClientFrame,"上传MES失败,请重试","提醒", JOptionPane.INFORMATION_MESSAGE);
  758. // return;
  759. // }
  760. // }
  761. String sn = getBarcode(product_sn2.getText());
  762. getUser();
  763. if(!sn.isEmpty()){
  764. String qret = "NG";
  765. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  766. if(!sendret){
  767. MesClient.pxstatus2.setText("B:结果上传MES失败");
  768. MesClient.tjStatusb = 1;
  769. }else{
  770. MesClient.pxstatus2.setText("B:提交成功");
  771. MesClient.status_menu.setText("B件提交成功");
  772. MesClient.resetScanB();
  773. }
  774. }
  775. }
  776. });
  777. finish_ng_bt2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  778. finish_ng_bt2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  779. finish_ng_bt2.setBounds(780, 380, 160, 80);
  780. finish_ng_bt2.setEnabled(false);
  781. // indexPanelA.add(finish_ng_bt2);
  782. JLabel lblNewLabel = new JLabel("电压");
  783. lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
  784. lblNewLabel.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  785. lblNewLabel.setBounds(26, 340, 100, 40);
  786. lblNewLabel.setVisible(false);
  787. indexPanelA.add(lblNewLabel);
  788. JLabel lblNewLabel_1 = new JLabel("电流");
  789. lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
  790. lblNewLabel_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  791. lblNewLabel_1.setBounds(226, 340, 100, 40);
  792. lblNewLabel_1.setVisible(false);
  793. indexPanelA.add(lblNewLabel_1);
  794. param1 = new JTextField();
  795. param1.setEnabled(false);
  796. param1.setEditable(false);
  797. param1.setHorizontalAlignment(SwingConstants.CENTER);
  798. param1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  799. param1.setBounds(136, 340, 70, 40);
  800. param1.setVisible(false);
  801. indexPanelA.add(param1);
  802. param1.setColumns(10);
  803. param2 = new JTextField();
  804. param2.setEnabled(false);
  805. param2.setEditable(false);
  806. param2.setHorizontalAlignment(SwingConstants.CENTER);
  807. param2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  808. param2.setColumns(10);
  809. param2.setBounds(345, 340, 70, 40);
  810. param2.setVisible(false);
  811. indexPanelA.add(param2);
  812. JLabel lblNewLabel_2 = new JLabel("送丝速度");
  813. lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT);
  814. lblNewLabel_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  815. lblNewLabel_2.setBounds(26, 401, 100, 40);
  816. lblNewLabel_2.setVisible(false);
  817. indexPanelA.add(lblNewLabel_2);
  818. param3 = new JTextField();
  819. param3.setEnabled(false);
  820. param3.setEditable(false);
  821. param3.setHorizontalAlignment(SwingConstants.CENTER);
  822. param3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  823. param3.setColumns(10);
  824. param3.setBounds(136, 401, 70, 40);
  825. param3.setVisible(false);
  826. indexPanelA.add(param3);
  827. JLabel lblNewLabel_1_1 = new JLabel("错误代码");
  828. lblNewLabel_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  829. lblNewLabel_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  830. lblNewLabel_1_1.setBounds(213, 401, 122, 40);
  831. lblNewLabel_1_1.setVisible(false);
  832. indexPanelA.add(lblNewLabel_1_1);
  833. param4 = new JTextField();
  834. param4.setEnabled(false);
  835. param4.setEditable(false);
  836. param4.setHorizontalAlignment(SwingConstants.CENTER);
  837. param4.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  838. param4.setColumns(10);
  839. param4.setBounds(345, 401, 70, 40);
  840. param4.setVisible(false);
  841. indexPanelA.add(param4);
  842. param5 = new JTextField();
  843. param5.setEnabled(false);
  844. param5.setEditable(false);
  845. param5.setHorizontalAlignment(SwingConstants.CENTER);
  846. param5.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  847. param5.setColumns(10);
  848. param5.setBounds(226, 470, 70, 40);
  849. param5.setVisible(false);
  850. indexPanelA.add(param5);
  851. JLabel lblNewLabel_1_1_1 = new JLabel("JOB号");
  852. lblNewLabel_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  853. lblNewLabel_1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  854. lblNewLabel_1_1_1.setBounds(106, 470, 122, 40);
  855. lblNewLabel_1_1_1.setVisible(false);
  856. indexPanelA.add(lblNewLabel_1_1_1);
  857. product_sn2 = new JTextField();
  858. product_sn2.setText("");
  859. product_sn2.setHorizontalAlignment(SwingConstants.CENTER);
  860. product_sn2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  861. product_sn2.setEditable(false);
  862. product_sn2.setColumns(10);
  863. product_sn2.setBounds(517, 152, 446, 70);
  864. indexPanelA.add(product_sn2);
  865. JSeparator separator = new JSeparator();
  866. separator.setBounds(450, 247, 0, 120);
  867. indexPanelA.add(separator);
  868. JSeparator separator_1 = new JSeparator();
  869. separator_1.setOrientation(SwingConstants.VERTICAL);
  870. separator_1.setBounds(495, 91, 23, 250);
  871. indexPanelA.add(separator_1);
  872. JLabel lblNewLabel_3 = new JLabel("电压");
  873. lblNewLabel_3.setHorizontalAlignment(SwingConstants.RIGHT);
  874. lblNewLabel_3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  875. lblNewLabel_3.setBounds(528, 340, 100, 40);
  876. lblNewLabel_3.setVisible(false);
  877. indexPanelA.add(lblNewLabel_3);
  878. param21 = new JTextField();
  879. param21.setEnabled(false);
  880. param21.setEditable(false);
  881. param21.setHorizontalAlignment(SwingConstants.CENTER);
  882. param21.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  883. param21.setColumns(10);
  884. param21.setBounds(638, 340, 70, 40);
  885. param21.setVisible(false);
  886. indexPanelA.add(param21);
  887. JLabel lblNewLabel_1_2 = new JLabel("电流");
  888. lblNewLabel_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
  889. lblNewLabel_1_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  890. lblNewLabel_1_2.setBounds(742, 340, 100, 40);
  891. lblNewLabel_1_2.setVisible(false);
  892. indexPanelA.add(lblNewLabel_1_2);
  893. param22 = new JTextField();
  894. param22.setEnabled(false);
  895. param22.setEditable(false);
  896. param22.setHorizontalAlignment(SwingConstants.CENTER);
  897. param22.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  898. param22.setColumns(10);
  899. param22.setBounds(852, 340, 70, 40);
  900. param22.setVisible(false);
  901. indexPanelA.add(param22);
  902. JLabel lblNewLabel_2_1 = new JLabel("送丝速度");
  903. lblNewLabel_2_1.setHorizontalAlignment(SwingConstants.RIGHT);
  904. lblNewLabel_2_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  905. lblNewLabel_2_1.setBounds(528, 401, 100, 40);
  906. lblNewLabel_2_1.setVisible(false);
  907. indexPanelA.add(lblNewLabel_2_1);
  908. param23 = new JTextField();
  909. param23.setEnabled(false);
  910. param23.setEditable(false);
  911. param23.setHorizontalAlignment(SwingConstants.CENTER);
  912. param23.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  913. param23.setColumns(10);
  914. param23.setBounds(638, 401, 70, 40);
  915. param23.setVisible(false);
  916. indexPanelA.add(param23);
  917. JLabel lblNewLabel_1_1_2 = new JLabel("错误代码");
  918. lblNewLabel_1_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
  919. lblNewLabel_1_1_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  920. lblNewLabel_1_1_2.setBounds(718, 401, 122, 40);
  921. lblNewLabel_1_1_2.setVisible(false);
  922. indexPanelA.add(lblNewLabel_1_1_2);
  923. param24 = new JTextField();
  924. param24.setEnabled(false);
  925. param24.setEditable(false);
  926. param24.setHorizontalAlignment(SwingConstants.CENTER);
  927. param24.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  928. param24.setColumns(10);
  929. param24.setBounds(852, 401, 70, 40);
  930. param24.setVisible(false);
  931. indexPanelA.add(param24);
  932. JLabel lblNewLabel_1_1_1_1 = new JLabel("JOB号");
  933. lblNewLabel_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  934. lblNewLabel_1_1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  935. lblNewLabel_1_1_1_1.setBounds(609, 470, 122, 40);
  936. lblNewLabel_1_1_1_1.setVisible(false);
  937. lblNewLabel_1_1_1_1.setVisible(false);
  938. indexPanelA.add(lblNewLabel_1_1_1_1);
  939. param25 = new JTextField();
  940. param25.setEnabled(false);
  941. param25.setEditable(false);
  942. param25.setHorizontalAlignment(SwingConstants.CENTER);
  943. param25.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  944. param25.setColumns(10);
  945. param25.setBounds(742, 470, 70, 40);
  946. param25.setVisible(false);
  947. indexPanelA.add(param25);
  948. pxstatus1 = new JLabel("A");
  949. pxstatus1.setForeground(new Color(255, 128, 64));
  950. pxstatus1.setHorizontalAlignment(SwingConstants.CENTER);
  951. pxstatus1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  952. pxstatus1.setBounds(26, 98, 446, 44);
  953. indexPanelA.add(pxstatus1);
  954. pxstatus2 = new JLabel("B");
  955. pxstatus2.setForeground(new Color(255, 128, 64));
  956. pxstatus2.setHorizontalAlignment(SwingConstants.CENTER);
  957. pxstatus2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  958. pxstatus2.setBounds(517, 98, 446, 44);
  959. indexPanelA.add(pxstatus2);
  960. JSeparator separator_2 = new JSeparator();
  961. separator_2.setBounds(10, 264, 973, 13);
  962. // indexPanelA.add(separator_2);
  963. JLabel lblNewLabel_4 = new JLabel("\u710A\u673A1");
  964. lblNewLabel_4.setHorizontalAlignment(SwingConstants.CENTER);
  965. lblNewLabel_4.setFont(new Font("微软雅黑", Font.PLAIN, 24));
  966. lblNewLabel_4.setBounds(170, 290, 156, 40);
  967. lblNewLabel_4.setVisible(false);
  968. // indexPanelA.add(lblNewLabel_4);
  969. JLabel lblNewLabel_4_1 = new JLabel("\u710A\u673A2");
  970. lblNewLabel_4_1.setHorizontalAlignment(SwingConstants.CENTER);
  971. lblNewLabel_4_1.setFont(new Font("微软雅黑", Font.PLAIN, 24));
  972. lblNewLabel_4_1.setBounds(670, 287, 156, 40);
  973. lblNewLabel_4_1.setVisible(false);
  974. // indexPanelA.add(lblNewLabel_4_1);
  975. JSeparator separator_1_1 = new JSeparator();
  976. separator_1_1.setOrientation(SwingConstants.VERTICAL);
  977. separator_1_1.setBounds(495, 278, 23, 232);
  978. indexPanelA.add(separator_1_1);
  979. textField = new JTextField();
  980. textField.setText("");
  981. textField.setHorizontalAlignment(SwingConstants.CENTER);
  982. textField.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  983. textField.setEditable(false);
  984. textField.setColumns(10);
  985. textField.setBounds(26, 333, 446, 70);
  986. // indexPanelA.add(textField);
  987. batch_scan_1 = new JButton("解绑");
  988. batch_scan_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/delete.png")));
  989. batch_scan_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  990. batch_scan_1.setEnabled(false);
  991. batch_scan_1.setVisible(false);
  992. batch_scan_1.setBounds(136, 430, 230, 80);
  993. batch_scan_1.addActionListener(new ActionListener() {
  994. public void actionPerformed(ActionEvent e) {
  995. if(MesClient.curPage.equals("B")){
  996. MesClient.setMenuStatus("该状态后梁无法解绑",-1);
  997. }else{
  998. String sn = MesClient.product_sn.getText().trim();
  999. String wsn = MesClient.textField.getText().trim();
  1000. JSONObject retObj = DataUtil.unBindWarehouseData(sn,wsn,user_menu.getText().trim(),"400007");
  1001. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1002. MesClient.setMenuStatus("后梁码解绑成功",0);
  1003. MesClient.formatScanType(2);
  1004. textField.setText("");
  1005. batch_scan_1.setEnabled(false);
  1006. PlcUtil.changeEnable(s7PLC,false);
  1007. }else{
  1008. MesClient.formatScanType(2);
  1009. batch_scan_1.setEnabled(true);
  1010. if(retObj.get("result")==null){
  1011. MesClient.setMenuStatus("请求失败,后梁码解绑失败,请重试",-1);
  1012. }else{
  1013. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  1014. MesClient.setMenuStatus(retObj.getString("message"),-1);
  1015. }
  1016. }
  1017. }
  1018. }
  1019. }
  1020. });
  1021. indexPanelA.add(batch_scan_1);
  1022. textField_1 = new JTextField();
  1023. textField_1.setText("");
  1024. textField_1.setHorizontalAlignment(SwingConstants.CENTER);
  1025. textField_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  1026. textField_1.setEditable(false);
  1027. textField_1.setColumns(10);
  1028. textField_1.setBounds(517, 333, 446, 70);
  1029. // indexPanelA.add(textField_1);
  1030. batch_scan_2 = new JButton("解绑");
  1031. batch_scan_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/delete.png")));
  1032. batch_scan_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  1033. batch_scan_2.setEnabled(false);
  1034. batch_scan_2.setVisible(false);
  1035. batch_scan_2.setBounds(633, 430, 230, 80);
  1036. batch_scan_2.addActionListener(new ActionListener() {
  1037. public void actionPerformed(ActionEvent e) {
  1038. if(MesClient.curPage.equals("A")){
  1039. MesClient.setMenuStatus("该状态后梁无法解绑",-1);
  1040. }else{
  1041. String sn = MesClient.product_sn2.getText().trim();
  1042. String wsn = MesClient.textField_1.getText().trim();
  1043. JSONObject retObj = DataUtil.unBindWarehouseData(sn,wsn,user_menu.getText().trim(),"400007");
  1044. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1045. MesClient.setMenuStatus("后梁码解绑成功",0);
  1046. MesClient.formatScanType(2);
  1047. textField_1.setText("");
  1048. batch_scan_2.setEnabled(false);
  1049. PlcUtil.changeEnable(s7PLC,false);
  1050. }else{
  1051. if(retObj.get("result")==null){
  1052. MesClient.setMenuStatus("请求失败,前梁码解绑失败,请重试",-1);
  1053. }else{
  1054. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  1055. MesClient.setMenuStatus(retObj.getString("message"),-1);
  1056. }
  1057. }
  1058. }
  1059. }
  1060. }
  1061. });
  1062. indexPanelA.add(batch_scan_2);
  1063. JLabel pxstatus1_1 = new JLabel("A后梁");
  1064. pxstatus1_1.setHorizontalAlignment(SwingConstants.CENTER);
  1065. pxstatus1_1.setForeground(new Color(0, 0, 0));
  1066. pxstatus1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  1067. pxstatus1_1.setBounds(26, 283, 446, 44);
  1068. // indexPanelA.add(pxstatus1_1);
  1069. JLabel pxstatus1_1_1 = new JLabel("B后梁");
  1070. pxstatus1_1_1.setHorizontalAlignment(SwingConstants.CENTER);
  1071. pxstatus1_1_1.setForeground(Color.BLACK);
  1072. pxstatus1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  1073. pxstatus1_1_1.setBounds(517, 283, 446, 44);
  1074. // indexPanelA.add(pxstatus1_1_1);
  1075. txtfa = new JTextField();
  1076. txtfa.setHorizontalAlignment(SwingConstants.LEFT);
  1077. txtfa.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  1078. txtfa.setColumns(10);
  1079. txtfa.setBounds(239, 10, 503, 60);
  1080. indexPanelA.add(txtfa);
  1081. txtfa.addActionListener(new ActionListener() {
  1082. public void actionPerformed(ActionEvent e) {
  1083. scanBarcode();
  1084. }
  1085. });
  1086. page_text = new JLabel("当前:A面");
  1087. page_text.setForeground(new Color(0, 255, 64));
  1088. page_text.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1089. page_text.setHorizontalAlignment(SwingConstants.RIGHT);
  1090. page_text.setBounds(97, 10, 132, 60);
  1091. indexPanelA.add(page_text);
  1092. scan_type_text = new JLabel("镭雕码");
  1093. scan_type_text.setForeground(new Color(255, 128, 64));
  1094. scan_type_text.setHorizontalAlignment(SwingConstants.LEFT);
  1095. scan_type_text.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1096. scan_type_text.setBounds(752, 10, 132, 60);
  1097. indexPanelA.add(scan_type_text);
  1098. tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
  1099. tabbedPane.setEnabledAt(0, true);
  1100. JPanel indexPanelGz = new JPanel();
  1101. searchScrollPaneGz = new JScrollPane(indexPanelGz);
  1102. indexPanelGz.setLayout(null);
  1103. indexPanelC = new JPanel();
  1104. searchScrollPaneDj = new JScrollPane(indexPanelC);
  1105. indexPanelC.setLayout(null);
  1106. tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
  1107. indexPanelB = new JPanel();
  1108. searchScrollPane = new JScrollPane(indexPanelB);
  1109. indexPanelB.setLayout(null);
  1110. tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
  1111. // bindBatchPanel();
  1112. tabbedPane.addChangeListener(new ChangeListener() {
  1113. @Override
  1114. public void stateChanged(ChangeEvent e) {
  1115. JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
  1116. int selectedIndex = tabbedPane.getSelectedIndex();
  1117. System.out.println("selectedIndex:"+selectedIndex);
  1118. if(selectedIndex == 1){
  1119. }
  1120. }
  1121. });
  1122. }
  1123. public static void formatScanType(int st){
  1124. scan_type = st;
  1125. if(scan_type == 1){
  1126. scan_type_text.setText("镭雕码");
  1127. }else if(scan_type == 2){
  1128. scan_type_text.setText("后梁码");
  1129. }else{
  1130. scan_type_text.setText("");
  1131. }
  1132. }
  1133. public static void scanBarcode() {
  1134. String scanBarcodeSn = txtfa.getText().trim();
  1135. txtfa.setText("");
  1136. System.out.println("scan_type:"+scan_type);
  1137. //刷新界面
  1138. mesClientFrame.repaint();
  1139. System.out.println("456");
  1140. System.out.println("156"+scan_type);
  1141. if(MesClient.scan_type == 1){ // 镭雕码
  1142. System.out.println("type1");
  1143. if(scanBarcodeSn.isEmpty()){
  1144. System.out.println("type2");
  1145. MesClient.setMenuStatus("镭雕码不能为空",1);
  1146. return;
  1147. }
  1148. if(MesClient.curPage.equals("A")){
  1149. System.out.println("typeA");
  1150. if(!product_sn.getText().isEmpty() && mesQualityFlagA){
  1151. MesClient.setMenuStatus("A面已存在工件码,勿重复扫码",1);
  1152. return;
  1153. }
  1154. product_sn.setText(scanBarcodeSn);
  1155. }else{
  1156. System.out.println("typeB");
  1157. if(!product_sn2.getText().isEmpty() && mesQualityFlagB){
  1158. MesClient.setMenuStatus("B面已存在工件码,勿重复扫码",1);
  1159. return;
  1160. }
  1161. product_sn2.setText(scanBarcodeSn);
  1162. }
  1163. MesClient.setMenuStatus("扫码成功",0);
  1164. //刷新界面
  1165. mesClientFrame.repaint();
  1166. System.out.println("123");
  1167. getUser();
  1168. // 查询工件质量
  1169. Boolean sendret = DataUtil.checkQuality(nettyClient,scanBarcodeSn,user20,MesClient.curPage);
  1170. if(!sendret){
  1171. MesClient.setMenuStatus("消息发送失败,请重试",1);
  1172. }
  1173. }
  1174. }
  1175. public static void setMenuStatus(String msg,int error){
  1176. if(error == 0){
  1177. MesClient.status_menu.setForeground(Color.GREEN);
  1178. }else{
  1179. MesClient.status_menu.setForeground(Color.RED);
  1180. }
  1181. MesClient.status_menu.setText(msg);
  1182. }
  1183. public static void getMaterailData(){
  1184. JSONObject retObj = DataUtil.getBindMaterail();
  1185. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1186. List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  1187. int i = 0;
  1188. rowData = new Object[arrs.size()][7];
  1189. for (BindMaterialResp bindMaterialResp:arrs){
  1190. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  1191. rowData[i][1] = bindMaterialResp.getBatchSn();
  1192. rowData[i][2] = bindMaterialResp.getLastTimes();
  1193. rowData[i][3] = "";
  1194. rowData[i][4] = bindMaterialResp.getCraft();
  1195. rowData[i][5] = bindMaterialResp.getMaterialId();
  1196. rowData[i][6] = bindMaterialResp.getType();
  1197. i++;
  1198. }
  1199. bindBatchPanel();
  1200. }
  1201. }
  1202. public static void updateMaterailData(){
  1203. JSONObject retObj = DataUtil.getBindMaterail();
  1204. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1205. List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  1206. int i = 0;
  1207. for (BindMaterialResp bindMaterialResp:arrs){
  1208. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  1209. rowData[i][1] = bindMaterialResp.getBatchSn();
  1210. rowData[i][2] = bindMaterialResp.getLastTimes();
  1211. rowData[i][3] = "";
  1212. rowData[i][4] = bindMaterialResp.getCraft();
  1213. rowData[i][5] = bindMaterialResp.getMaterialId();
  1214. rowData[i][6] = bindMaterialResp.getType();
  1215. i++;
  1216. }
  1217. MesClient.table.repaint();
  1218. }
  1219. }
  1220. // 绑定物料批次码
  1221. public static void scanBatchSn(BindMaterialResp bindMaterialResp) { // 扫码类型
  1222. //弹窗扫工件码
  1223. String scanBarcodeTitle = "请扫物料:"+bindMaterialResp.getMaterialTitle();
  1224. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  1225. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  1226. JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType());
  1227. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1228. MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0);
  1229. updateMaterailData();
  1230. }else{
  1231. if(retObj.get("result")==null){
  1232. MesClient.setMenuStatus("请求失败,请重试",-1);
  1233. }else{
  1234. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  1235. MesClient.setMenuStatus(retObj.getString("message"),-1);
  1236. }
  1237. }
  1238. }
  1239. }
  1240. }
  1241. public static void bindBatchPanel(){
  1242. JPanel indexPanelBB = new JPanel();
  1243. JPanel panel = new JPanel();
  1244. panel.setBounds(0, 0, 990, 550);
  1245. // panel.setBounds(81, 50, 810, 479);
  1246. indexPanelBB.add(panel);
  1247. panel.setLayout(new GridLayout(0, 1, 0, 0));
  1248. table = new JTable(rowData, columnNames){
  1249. public boolean isCellEditable(int row, int column) {
  1250. if(column == 3){
  1251. return true;
  1252. }
  1253. return false;
  1254. }
  1255. };
  1256. table.setRowHeight(40);
  1257. table.setEnabled(true);
  1258. table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  1259. table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
  1260. table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
  1261. JScrollPane scrollPane = new JScrollPane(table);
  1262. panel.add(scrollPane);
  1263. indexScrollPaneB = new JScrollPane(indexPanelBB);
  1264. indexPanelBB.setLayout(null);
  1265. tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
  1266. }
  1267. // 开启发送结果定时任务
  1268. public static void startUpdateQualityTimer(){
  1269. new Timer().schedule(new TimerTask() {
  1270. @Override
  1271. public void run() {
  1272. try {
  1273. JdbcUtils.getConn();
  1274. Statement statement = JdbcUtils.conn.createStatement();
  1275. String selectSql = "SELECT id, bw FROM submit_record\n" +
  1276. "WHERE state = 0 ORDER BY id DESC LIMIT 10";
  1277. String updateSql = "UPDATE submit_record \n" +
  1278. "SET state = '1'\n" +
  1279. "WHERE id = ";
  1280. ResultSet rs = statement.executeQuery(selectSql);
  1281. while(rs.next()){
  1282. int id = rs.getInt("id");
  1283. String bw = rs.getString("bw");
  1284. // 发送请求
  1285. String url = "http://"+MesClient.mes_server_ip+":8980/js/a/mes/mesProductRecord/updateQualityByTiming";
  1286. String s = HttpUtils.sendPostRequestJson(url, bw );
  1287. Boolean result = JSONObject.parseObject(s).getBoolean("result");
  1288. if(result) {
  1289. // 更改状态为 1
  1290. statement.executeUpdate(updateSql + id);
  1291. }
  1292. }
  1293. rs.close();
  1294. statement.close();
  1295. } catch (SQLException | IOException e) {
  1296. // throw new RuntimeException(e);
  1297. e.printStackTrace();
  1298. }
  1299. }
  1300. },1000, 5000);
  1301. }
  1302. public static void formatBatchSn(){
  1303. if((MesClient.batch_status == 1 && MesClient.tjFlaga == 1) || (MesClient.batch_status2 == 1 && MesClient.tjFlagb == 1)){
  1304. PlcUtil.changeEnable(MesClient.s7PLC,true);
  1305. }else{
  1306. PlcUtil.changeEnable(MesClient.s7PLC,false);
  1307. }
  1308. }
  1309. private static String checkSnType(String sn){
  1310. String str = sn.substring(9,12);
  1311. if(str.equals("113")){
  1312. return "MX11-2";
  1313. }else if(str.equals("119")){
  1314. return "MX11-2S";
  1315. }else{
  1316. return "";
  1317. }
  1318. }
  1319. // 检查工件是否匹配
  1320. private static Boolean checkSnAndBatch(String sn,String batchSn){
  1321. String gdStr1 = "151245P000012131001000"; // MX11-2
  1322. String gdStr2 = "151245P000017812001000"; // MX11-2S
  1323. String cate = sn.substring(0,22);
  1324. String ptype = checkSnType(batchSn);
  1325. if(ptype.equals("MX11-2") && cate.equals(gdStr1)){
  1326. return true;
  1327. }
  1328. if(ptype.equals("MX11-2S") && cate.equals(gdStr2)){
  1329. return true;
  1330. }
  1331. return false;
  1332. }
  1333. }