MesClient.java 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876
  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.ConfigLoader;
  14. import com.mes.util.DateLocalUtils;
  15. import com.mes.util.EncodingUtil;
  16. import com.mes.util.HttpUtils;
  17. import com.mes.util.JdbcUtils;
  18. import javafx.embed.swing.JFXPanel;
  19. import org.slf4j.Logger;
  20. import org.slf4j.LoggerFactory;
  21. import javax.swing.*;
  22. import javax.swing.border.EmptyBorder;
  23. import javax.swing.plaf.FontUIResource;
  24. import javax.swing.event.ChangeEvent;
  25. import javax.swing.event.ChangeListener;
  26. import java.awt.*;
  27. import java.awt.event.ActionEvent;
  28. import java.awt.event.ActionListener;
  29. import java.awt.event.MouseAdapter;
  30. import java.awt.event.MouseEvent;
  31. import java.io.BufferedReader;
  32. import java.io.IOException;
  33. import java.io.InputStream;
  34. import java.io.InputStreamReader;
  35. import java.sql.ResultSet;
  36. import java.sql.SQLException;
  37. import java.sql.Statement;
  38. import java.time.LocalDateTime;
  39. import java.util.ArrayList;
  40. import java.util.Properties;
  41. import java.util.Timer;
  42. import java.util.TimerTask;
  43. import java.util.List;
  44. public class MesClient extends JFrame {
  45. static {
  46. EncodingUtil.init();
  47. }
  48. public static final Logger log = LoggerFactory.getLogger(MesClient.class);
  49. private static String Drivde = "org.sqlite.JDBC";
  50. public static int mes_auth = 0;
  51. public static String mes_gw = "";
  52. public static String mes_gw_des = "";
  53. public static String mes_server_ip = "";
  54. public static int mes_tcp_port = 3000;
  55. public static int mes_heart_beat_cycle = 10;
  56. public static int mes_heart_icon_cycle = 1;
  57. public static String mes_line_sn = "";
  58. public static NettyClient nettyClient;
  59. public static boolean tcp_connect_flag = false;
  60. public static boolean connect_request_flag = false;
  61. //session
  62. public static String sessionid = "";
  63. public static JPanel contentPane;
  64. public static JPanel indexPanelA;
  65. public static MesClient mesClientFrame;
  66. public static JTabbedPane tabbedPane;
  67. public static JScrollPane indexScrollPaneA;
  68. public static JScrollPane indexScrollPaneB;
  69. public static JScrollPane searchScrollPane;
  70. public static JScrollPane searchScrollPaneDj;
  71. public static JScrollPane searchScrollPaneGz;
  72. public static Boolean check_quality_result = false;
  73. public static Integer work_status = 0;
  74. public static Integer work_status2 = 0;
  75. public static Boolean check_quality_result2 = false;
  76. public static Integer batch_status = 0; //A面 1=已绑定 0=未绑定
  77. public static Integer batch_status2 = 0; //B面 1=已绑定 0=未绑定
  78. public static JButton heart_beat_menu;
  79. public static JButton status_menu;
  80. public static JButton user_menu;
  81. public static int scan_type = 0;
  82. public static JButton finish_ok_bt;
  83. public static JButton finish_ok_bt2;
  84. public static JButton finish_ng_bt;
  85. public static JButton finish_ng_bt2;
  86. public static JTextField product_sn;
  87. public static JLabel pxstatus1;
  88. public static JLabel pxstatus2;
  89. public static JButton batch_scan_1;
  90. public static JButton batch_scan_2;
  91. public static Integer tjFlag = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束
  92. public static Integer tjFlaga = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束
  93. public static Integer tjFlagb = 0; // 0=未开始 1=已扫码,设备未启动 2=设备运行中 3=设备运行结束
  94. public static Integer tjStatusa = 0; // 1=提交失败
  95. public static Integer tjStatusb = 0; // 1=提交失败
  96. public static String curFlag = ""; // 当前工作的面板
  97. public static String curSna = "";
  98. public static String curSnb = "";
  99. public static String curPage = "";
  100. /** 最近一次镭雕扫码所在面(A/B),用于 MES 开工与 PLC 允许信号 */
  101. public static String lastScanSide = "A";
  102. public static Integer checkA = 0;
  103. public static Integer checkB = 0;
  104. public static Integer lastpage = 0;
  105. public static Boolean mesQualityFlagA = false; // true=可工作
  106. public static Boolean mesQualityFlagB = false; // true=可工作
  107. public static Boolean mesErrorFlagA = false; // true=提交MES失败,手动提交
  108. public static Boolean mesErrorFlagB = false; // true=提交MES失败,手动提交
  109. public static String user20 = "";
  110. public static JFrame welcomeWin;
  111. public static JPanel indexPanelB;
  112. public static MesWebView jfxPanel = null;
  113. public static MesRadio mesRadioHj;
  114. public static JPanel indexPanelC;
  115. public static MesWebView jfxPanel2 = null;
  116. public static S7PLC s7PLC = new S7PLC(EPlcType.S1200, "192.168.7.100"); //100 B工位
  117. public static List<String> hjparams = new ArrayList<>();
  118. public static JTable table;
  119. public static Object[] columnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
  120. public static Object[][] rowData = null;
  121. // public static Object[][] rowData = {
  122. // };
  123. public static void main(String[] args) {
  124. initUiFont();
  125. EventQueue.invokeLater(new Runnable() {
  126. @Override
  127. public void run() {
  128. try{
  129. readProperty();
  130. mesClientFrame = new MesClient();
  131. mesClientFrame.setVisible(false);
  132. JdbcUtils.getConn();
  133. welcomeWin = new LoginFarme();
  134. welcomeWin.setVisible(true);
  135. getMaterailData();
  136. //获取当前面
  137. textFocus();
  138. getPlcParam();
  139. //
  140. upParams();
  141. //
  142. getPlcParams();
  143. }catch (Exception e){
  144. e.printStackTrace();
  145. }
  146. }
  147. });
  148. }
  149. /** 优先使用系统中文字体,避免 jar 部署机器字体名不一致 */
  150. private static Font resolveUiFont(int size) {
  151. String[] candidates = {"Microsoft YaHei UI", "微软雅黑", "Microsoft YaHei", "SimSun"};
  152. GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
  153. String[] available = ge.getAvailableFontFamilyNames();
  154. java.util.Set<String> set = new java.util.HashSet<>();
  155. for (String name : available) {
  156. set.add(name);
  157. }
  158. for (String name : candidates) {
  159. if (set.contains(name)) {
  160. return new Font(name, Font.PLAIN, size);
  161. }
  162. }
  163. return new Font(Font.SANS_SERIF, Font.PLAIN, size);
  164. }
  165. /** 全局 UI 字体,避免登录页等使用 Dialog 字体时中文显示异常 */
  166. private static void initUiFont() {
  167. Font baseFont = resolveUiFont(12);
  168. java.util.Enumeration<Object> keys = UIManager.getDefaults().keys();
  169. while (keys.hasMoreElements()) {
  170. Object key = keys.nextElement();
  171. Object value = UIManager.get(key);
  172. if (value instanceof Font) {
  173. Font old = (Font) value;
  174. UIManager.put(key, new FontUIResource(baseFont.getName(), old.getStyle(), old.getSize()));
  175. }
  176. }
  177. }
  178. public static Timer cjTimerText;
  179. public static void textFocus() {
  180. if(cjTimerText!=null) {
  181. cjTimerText.cancel();
  182. }
  183. cjTimerText = new Timer();
  184. cjTimerText.schedule(new TimerTask() {
  185. public void run() {
  186. txtfa.requestFocusInWindow();
  187. MesClient.curPage = PlcUtil.getCurAside(s7PLC);
  188. if(MesClient.curPage .equals("A")){
  189. page_text.setText("当前:A面");
  190. }else{
  191. page_text.setText("当前:B面");
  192. }
  193. }
  194. }, 1000,1000);
  195. }
  196. public static Timer cjTimer3;
  197. public static void upParams() {
  198. if(cjTimer3!=null) {
  199. cjTimer3.cancel();
  200. }
  201. cjTimer3 = new Timer();
  202. cjTimer3.schedule(new TimerTask() {
  203. public void run() {
  204. uploadPendingCmtParams();
  205. }
  206. }, 1000,30*1000);
  207. }
  208. /** 立即上传本地未同步的焊接采样数据 */
  209. public static void uploadPendingCmtParams() {
  210. try{
  211. List<CmtReq> prods = JdbcUtils.getCmtParams();
  212. if(prods.isEmpty()){
  213. return;
  214. }
  215. JSONObject retObj = DataUtil.upParams(JSON.toJSONString(prods));
  216. if(retObj != null && retObj.get("result") != null
  217. && retObj.get("result").toString().equalsIgnoreCase("true")) {
  218. for(CmtReq prodReq : prods){
  219. JdbcUtils.updateProdSync(prodReq.getId(),1);
  220. }
  221. }
  222. }catch (Exception e){
  223. e.printStackTrace();
  224. }
  225. }
  226. /** 焊接报工后:先上传采样数据,再刷新工作记录页 */
  227. public static void notifyWorkSubmitted() {
  228. uploadPendingCmtParams();
  229. new Timer().schedule(new TimerTask() {
  230. @Override
  231. public void run() {
  232. refreshWorkRecord();
  233. }
  234. }, 1000);
  235. }
  236. /** 刷新「工作记录」WebView */
  237. public static void refreshWorkRecord() {
  238. if(jfxPanel == null || sessionid == null || sessionid.isEmpty()){
  239. return;
  240. }
  241. String url = "http://" + mes_server_ip + ":8980/js/a/mes/mesProductRecord/work?__sid="
  242. + sessionid + "&oprno=" + mes_gw + "&lineSn=" + mes_line_sn
  243. + "&t=" + System.currentTimeMillis();
  244. jfxPanel.loadPageUrl(url);
  245. }
  246. public static String resolveOprnoForSubmit(String op) {
  247. return mes_gw + op;
  248. }
  249. /** 根据 MES 返回工位号或最近扫码面,判定 A/B(仅 OP080A / OP080B) */
  250. public static String resolveScanSide(String oprno) {
  251. if (oprno != null) {
  252. String o = oprno.trim();
  253. if (o.endsWith("B")) {
  254. return "B";
  255. }
  256. if (o.endsWith("A")) {
  257. return "A";
  258. }
  259. }
  260. if ("B".equals(lastScanSide)) {
  261. return "B";
  262. }
  263. if ("B".equals(curPage)) {
  264. return "B";
  265. }
  266. return "A";
  267. }
  268. /** 焊接结束时落库未满 60 条的剩余采样 */
  269. public static void flushHjparamsToDb(String oprno, String sn) {
  270. if (hjparams == null || hjparams.isEmpty() || sn == null || sn.isEmpty()) {
  271. return;
  272. }
  273. try {
  274. JdbcUtils.insertCmtData(oprno, mes_line_sn, sn, JSON.toJSONString(hjparams));
  275. hjparams = new ArrayList<>();
  276. } catch (Exception e) {
  277. e.printStackTrace();
  278. }
  279. }
  280. private static final int TAB_WORK_RECORD = 2;
  281. public static Timer cjTimer;
  282. public static void getPlcParam() {
  283. if(cjTimer!=null) {
  284. cjTimer.cancel();
  285. }
  286. cjTimer = new Timer();
  287. cjTimer.schedule(new TimerTask() {
  288. public void run() {
  289. try{
  290. if(!MesClient.sessionid.isEmpty()){
  291. PlcUtil.getStatusA(s7PLC);
  292. }
  293. }catch (Exception e){
  294. e.printStackTrace();
  295. }
  296. try{
  297. if(!MesClient.sessionid.isEmpty()){
  298. PlcUtil.getStatusB(s7PLC);
  299. }
  300. }catch (Exception e){
  301. e.printStackTrace();
  302. }
  303. }
  304. // 运行中 500ms 轮询,降低漏检 PLC「焊接完成」短脉冲的概率(不改 PLC)
  305. }, 1000,500);
  306. }
  307. public static Timer cjTimer2;
  308. public static void getPlcParams() {
  309. if(cjTimer2!=null) {
  310. cjTimer2.cancel();
  311. }
  312. cjTimer2 = new Timer();
  313. cjTimer2.schedule(new TimerTask() {
  314. public void run() {
  315. try{
  316. PlcUtil.getParamDyDl(s7PLC);
  317. }catch (Exception e){
  318. e.printStackTrace();
  319. }
  320. try{
  321. PlcUtil.getTipLife(s7PLC);
  322. }catch (Exception e){
  323. e.printStackTrace();
  324. }
  325. }
  326. }, 1000,500);
  327. }
  328. //读配置文件
  329. private static void readProperty() throws IOException{
  330. Properties pro = ConfigLoader.loadProperties();
  331. mes_gw = pro.getProperty("mes.gw").trim();
  332. // mes_gw_des = pro.getProperty("mes.gw_des");
  333. mes_server_ip = pro.getProperty("mes.server_ip").trim();
  334. mes_tcp_port = Integer.parseInt(pro.getProperty("mes.tcp_port"));
  335. mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle"));
  336. mes_line_sn = pro.getProperty("mes.line_sn").trim();
  337. mes_gw_des = OprnoUtil.getGwDes(mes_line_sn,mes_gw);
  338. System.out.println(mes_gw + ";" + mes_gw_des + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
  339. }
  340. // 初始化TCP
  341. public static void initTcpConnection() {
  342. try {
  343. if(nettyClient==null) {
  344. nettyClient = new NettyClient();
  345. tcp_connect_flag = false;
  346. connect_request_flag = true;
  347. DataUtil.synrTcp(nettyClient,mes_gw);
  348. }
  349. } catch (Exception e) {
  350. // TODO Auto-generated catch block
  351. e.printStackTrace();
  352. }
  353. }
  354. public static java.util.Timer heartBeatTimer;
  355. public static java.util.Timer heartBeatIconTimer;
  356. public static boolean iconREDFlag = true;
  357. public static JTextField param1;
  358. public static JTextField param2;
  359. public static JTextField param3;
  360. public static JTextField param4;
  361. public static JTextField param5;
  362. public static JTextField tipLifeA;
  363. public static JTextField tipLifeB;
  364. public static JTextField tipLifeC;
  365. public static volatile boolean tipAlarmAShown = false;
  366. public static volatile boolean tipAlarmBShown = false;
  367. public static volatile boolean tipAlarmCShown = false;
  368. public static int lastTipSyncAActual = Integer.MIN_VALUE;
  369. public static int lastTipSyncASet = Integer.MIN_VALUE;
  370. public static int lastTipSyncBActual = Integer.MIN_VALUE;
  371. public static int lastTipSyncBSet = Integer.MIN_VALUE;
  372. public static int lastTipSyncCActual = Integer.MIN_VALUE;
  373. public static int lastTipSyncCSet = Integer.MIN_VALUE;
  374. public static JTextField product_sn2;
  375. public static JTextField param21;
  376. public static JTextField param22;
  377. public static JTextField param23;
  378. public static JTextField param24;
  379. public static JTextField param25;
  380. // C枪 UI 控件
  381. public static JTextField param31;
  382. public static JTextField param32;
  383. public static JTextField param33;
  384. public static JTextField param34;
  385. public static JTextField param35;
  386. // D枪 UI 控件
  387. public static JTextField param41;
  388. public static JTextField param42;
  389. public static JTextField param43;
  390. public static JTextField param44;
  391. public static JTextField param45;
  392. public static void startHeartBeatTimer() {
  393. if(heartBeatTimer!=null) {
  394. heartBeatTimer.cancel();
  395. }
  396. heartBeatTimer = new java.util.Timer();
  397. heartBeatTimer.schedule(new TimerTask() {
  398. public void run() {
  399. if(nettyClient!=null&&tcp_connect_flag) {
  400. DataUtil.heartBeat(nettyClient,mes_gw);
  401. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  402. }
  403. }
  404. }, 100,mes_heart_beat_cycle*1000);
  405. if(heartBeatIconTimer!=null) {
  406. heartBeatIconTimer.cancel();
  407. }
  408. heartBeatIconTimer = new Timer();
  409. heartBeatIconTimer.schedule(new TimerTask() {
  410. public void run() {
  411. if(tcp_connect_flag) {
  412. if(iconREDFlag) {
  413. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  414. iconREDFlag = false;
  415. }else {
  416. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  417. iconREDFlag = true;
  418. }
  419. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  420. heart_beat_menu.repaint();
  421. }else {
  422. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  423. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  424. heart_beat_menu.repaint();
  425. if(nettyClient!=null&&!tcp_connect_flag){
  426. // TCP未连接,尝试重连
  427. if(!connect_request_flag) {
  428. connect_request_flag = true;
  429. DataUtil.synrTcp(nettyClient,mes_gw);
  430. }
  431. }
  432. }
  433. }
  434. }, 100,mes_heart_icon_cycle*1000);
  435. }
  436. // 设置TCP连接状态
  437. public static void setTcpStatus() {
  438. if(tcp_connect_flag) {
  439. status_menu.setText("已连接MES服务器");
  440. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  441. heart_beat_menu.repaint();
  442. }else {
  443. status_menu.setText("未连接MES服务器");
  444. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  445. heart_beat_menu.repaint();
  446. }
  447. }
  448. public static void initWarehouseData(){
  449. resetScanA();
  450. resetScanB();
  451. PlcUtil.changeEnable(s7PLC,false);
  452. }
  453. public static void resetScanA() {
  454. work_status = 0;
  455. check_quality_result = false;
  456. MesClient.finish_ok_bt.setEnabled(false);
  457. MesClient.mesQualityFlagA = false;
  458. product_sn.setText("");
  459. MesClient.pxstatus1.setText("A");
  460. // PlcUtil.changeEnable(s7PLC,false);
  461. MesClient.param1.setText("");
  462. MesClient.param2.setText("");
  463. MesClient.param3.setText("");
  464. MesClient.param4.setText("");
  465. MesClient.param5.setText("");
  466. MesClient.param21.setText("");
  467. MesClient.param22.setText("");
  468. MesClient.param23.setText("");
  469. MesClient.param24.setText("");
  470. MesClient.param25.setText("");
  471. // 清空 C枪 数据
  472. if (param31 != null) param31.setText("");
  473. if (param32 != null) param32.setText("");
  474. if (param33 != null) param33.setText("");
  475. if (param34 != null) param34.setText("");
  476. if (param35 != null) param35.setText("");
  477. // 清空 D枪 数据
  478. if (param41 != null) param41.setText("");
  479. if (param42 != null) param42.setText("");
  480. if (param43 != null) param43.setText("");
  481. if (param44 != null) param44.setText("");
  482. if (param45 != null) param45.setText("");
  483. MesClient.curSna = "";
  484. MesClient.tjFlaga = 0;
  485. MesClient.checkA = 0;
  486. PlcUtil.resetRunDetectA();
  487. MesClient.hjparams = new ArrayList<>();
  488. // MesClient.batch_status = 0;
  489. // MesClient.textField.setText("");
  490. // MesClient.batch_scan_1.setEnabled(false);
  491. MesClient.formatScanType(1);
  492. // PlcUtil.changeEnable(MesClient.s7PLC,false);
  493. finish_ok_bt.setEnabled(false);
  494. finish_ng_bt.setEnabled(false);
  495. updateMaterailData(); // 更新物料
  496. shiftUserCheck();
  497. }
  498. public static int userLoginHours;//用户登录所处小时
  499. public static JTextField textField;
  500. public static JTextField textField_1;
  501. public static JTextField txtfa;
  502. public static JLabel scan_type_text;
  503. public static JLabel page_text;
  504. //换班用户信息检查
  505. private static void shiftUserCheck() {
  506. LocalDateTime now = LocalDateTime.now();
  507. // 判断时间范围
  508. if (userLoginHours >= 8 && userLoginHours < 20) {
  509. int hour = now.getHour();
  510. if (hour >= 20 || hour < 8) {
  511. logoff();
  512. }
  513. } else {
  514. int hour = now.getHour();
  515. if (hour >= 8 && hour < 20) {
  516. logoff();
  517. }
  518. }
  519. }
  520. public static void resetScanB() {
  521. work_status2 = 0;
  522. check_quality_result2 = false;
  523. MesClient.finish_ng_bt.setEnabled(false);
  524. MesClient.mesQualityFlagB = false;
  525. product_sn2.setText("");
  526. // PlcUtil.changeEnable(s7PLC,false);
  527. MesClient.pxstatus2.setText("B");
  528. MesClient.param1.setText("");
  529. MesClient.param2.setText("");
  530. MesClient.param3.setText("");
  531. MesClient.param4.setText("");
  532. MesClient.param5.setText("");
  533. MesClient.param21.setText("");
  534. MesClient.param22.setText("");
  535. MesClient.param23.setText("");
  536. MesClient.param24.setText("");
  537. MesClient.param25.setText("");
  538. // 清空 C枪 数据
  539. if (param31 != null) param31.setText("");
  540. if (param32 != null) param32.setText("");
  541. if (param33 != null) param33.setText("");
  542. if (param34 != null) param34.setText("");
  543. if (param35 != null) param35.setText("");
  544. // 清空 D枪 数据
  545. if (param41 != null) param41.setText("");
  546. if (param42 != null) param42.setText("");
  547. if (param43 != null) param43.setText("");
  548. if (param44 != null) param44.setText("");
  549. if (param45 != null) param45.setText("");
  550. MesClient.curSnb = "";
  551. MesClient.tjFlagb = 0;
  552. MesClient.hjparams = new ArrayList<>();
  553. MesClient.checkB = 0;
  554. PlcUtil.resetRunDetectB();
  555. // MesClient.batch_status2 = 0;
  556. // MesClient.textField_1.setText("");
  557. // MesClient.batch_scan_2.setEnabled(false);
  558. MesClient.formatScanType(1);
  559. // PlcUtil.changeEnable(MesClient.s7PLC,false);
  560. finish_ok_bt2.setEnabled(false);
  561. finish_ng_bt2.setEnabled(false);
  562. updateMaterailData(); // 更新物料
  563. // shiftUserCheck();
  564. }
  565. // 获取用户20位
  566. public static void getUser() {
  567. user20 = user_menu.getText().toString();
  568. String space_tmp1 = "";
  569. if(user20.length()<20) {
  570. for(int i=0;i<20-user20.length();i++) {
  571. space_tmp1 = space_tmp1 + " ";
  572. }
  573. }
  574. user20 = user20 + space_tmp1;
  575. }
  576. public static String getBarcode(String barcodeTmp) {
  577. String barcodeRet = barcodeTmp;
  578. if(barcodeTmp.equalsIgnoreCase("")) {
  579. return "";
  580. }else {
  581. if(barcodeTmp.length()<36) {
  582. String space = "";
  583. for(int i=0;i<36-barcodeTmp.length();i++) {
  584. space = space + " ";
  585. }
  586. barcodeRet = barcodeTmp + space;
  587. }
  588. }
  589. return barcodeRet;
  590. }
  591. public static void logoff() {
  592. welcomeWin.setVisible(true);
  593. mesClientFrame.setVisible(false);
  594. nettyClient = null;
  595. if(heartBeatTimer!=null) {
  596. heartBeatTimer.cancel();
  597. }
  598. if(heartBeatIconTimer!=null) {
  599. heartBeatIconTimer.cancel();
  600. }
  601. tcp_connect_flag = false;
  602. connect_request_flag = false;
  603. }
  604. public MesClient() {
  605. setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
  606. setTitle("MES系统客户端:"+mes_gw + "- " + mes_gw_des);
  607. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  608. setBounds(0, 0, 1024, 768);
  609. JMenuBar menuBar = new JMenuBar();
  610. menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
  611. setJMenuBar(menuBar);
  612. JMenu fileMenu = new JMenu("\u7528\u6237");
  613. fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
  614. fileMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  615. menuBar.add(fileMenu);
  616. JMenuItem exitMenuItem = new JMenuItem("退出");
  617. exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png")));
  618. exitMenuItem.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  619. fileMenu.add(exitMenuItem);
  620. exitMenuItem.addMouseListener(new MouseAdapter() {
  621. @Override
  622. public void mousePressed(MouseEvent e) {
  623. super.mouseClicked(e);
  624. //dispose();
  625. logoff();
  626. }
  627. });
  628. JMenu settingMenu = new JMenu("设置");
  629. //settingMenu.setVisible(false);
  630. settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
  631. settingMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  632. menuBar.add(settingMenu);
  633. JMenuItem resetTcpMenu = new JMenuItem("\u91CD\u8FDEMES");
  634. resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  635. resetTcpMenu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  636. resetTcpMenu.addMouseListener(new MouseAdapter() {
  637. @Override
  638. public void mousePressed(MouseEvent e) {
  639. super.mouseClicked(e);
  640. nettyClient.future.channel().close();
  641. }
  642. });
  643. settingMenu.add(resetTcpMenu);
  644. JMenuItem resetTcpMenu_1 = new JMenuItem("\u91CD\u65B0\u626B\u7801-A");
  645. resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  646. resetTcpMenu_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  647. resetTcpMenu_1.addMouseListener(new MouseAdapter() {
  648. @Override
  649. public void mousePressed(MouseEvent e) {
  650. super.mouseClicked(e);
  651. resetScanA();
  652. PlcUtil.changeEnable(s7PLC,false);
  653. }
  654. });
  655. settingMenu.add(resetTcpMenu_1);
  656. JMenuItem resetTcpMenu_1_1 = new JMenuItem("\u91CD\u65B0\u626B\u7801-B");
  657. resetTcpMenu_1_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  658. resetTcpMenu_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  659. resetTcpMenu_1_1.addMouseListener(new MouseAdapter() {
  660. @Override
  661. public void mousePressed(MouseEvent e) {
  662. super.mouseClicked(e);
  663. resetScanB();
  664. PlcUtil.changeEnable(s7PLC,false);
  665. }
  666. });
  667. settingMenu.add(resetTcpMenu_1_1);
  668. JMenuItem resetTcpMenu_1sd = new JMenuItem("手动提交-A");
  669. resetTcpMenu_1sd.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  670. resetTcpMenu_1sd.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  671. resetTcpMenu_1sd.addMouseListener(new MouseAdapter() {
  672. @Override
  673. public void mousePressed(MouseEvent e) {
  674. super.mouseClicked(e);
  675. // finish_ok_bt.setEnabled(true);
  676. // finish_ng_bt.setEnabled(true);
  677. // MesClient.finish_ok_bt.setEnabled(true);
  678. // if(MesClient.mesQualityFlagA == 1){
  679. // Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn.getText(),"OK",MesClient.user20,"A");
  680. // if(!sendret){
  681. // MesClient.pxstatus1.setText("A:结果上传MES失败");
  682. // MesClient.tjStatusa = 1;
  683. // }
  684. // }
  685. }
  686. });
  687. // settingMenu.add(resetTcpMenu_1sd);
  688. JMenuItem resetTcpMenu_1_1sd = new JMenuItem("手动提交-B");
  689. resetTcpMenu_1_1sd.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  690. resetTcpMenu_1_1sd.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  691. resetTcpMenu_1_1sd.addMouseListener(new MouseAdapter() {
  692. @Override
  693. public void mousePressed(MouseEvent e) {
  694. super.mouseClicked(e);
  695. finish_ok_bt2.setEnabled(true);
  696. finish_ng_bt2.setEnabled(true);
  697. // MesClient.finish_ng_bt.setEnabled(true);
  698. // Boolean sendret = DataUtil.sendQuality(MesClient.nettyClient,MesClient.product_sn2.getText(),"OK",MesClient.user20,"B");
  699. // if(!sendret){
  700. // MesClient.pxstatus2.setText("B:结果上传MES失败");
  701. // MesClient.tjStatusb = 1;
  702. // }
  703. }
  704. });
  705. // settingMenu.add(resetTcpMenu_1_1sd);
  706. contentPane = new JPanel();
  707. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  708. setContentPane(contentPane);
  709. contentPane.setLayout(new BorderLayout(0, 0));
  710. JToolBar toolBar = new JToolBar();
  711. contentPane.add(toolBar, BorderLayout.NORTH);
  712. JLabel equipment_statu_label = new JLabel("\u72B6\u6001\uFF1A");
  713. equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER);
  714. equipment_statu_label.setForeground(Color.BLACK);
  715. equipment_statu_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  716. equipment_statu_label.setBackground(Color.LIGHT_GRAY);
  717. toolBar.add(equipment_statu_label);
  718. status_menu = new JButton("设备未连接MES服务器");
  719. if(tcp_connect_flag) {
  720. status_menu.setText("已连接MES服务器");
  721. status_menu.setForeground(Color.GREEN);
  722. }else {
  723. status_menu.setText("未连接MES服务器");
  724. status_menu.setForeground(Color.DARK_GRAY);
  725. }
  726. status_menu.addActionListener(new ActionListener() {
  727. public void actionPerformed(ActionEvent e) {
  728. }
  729. });
  730. status_menu.setForeground(Color.GREEN);
  731. status_menu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  732. status_menu.setBackground(Color.BLACK);
  733. toolBar.add(status_menu);
  734. JLabel space_1 = new JLabel(" ");
  735. toolBar.add(space_1);
  736. JLabel heart_beat_status_label = new JLabel("\u5FC3\u8DF3\uFF1A");
  737. heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  738. heart_beat_status_label.setForeground(Color.BLACK);
  739. heart_beat_status_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  740. heart_beat_status_label.setBackground(Color.LIGHT_GRAY);
  741. toolBar.add(heart_beat_status_label);
  742. heart_beat_menu = new JButton("2024-02-20 23:20:10");
  743. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  744. heart_beat_menu.setForeground(Color.GREEN);
  745. heart_beat_menu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  746. heart_beat_menu.setBackground(Color.BLACK);
  747. toolBar.add(heart_beat_menu);
  748. JLabel space_2 = new JLabel(" ");
  749. toolBar.add(space_2);
  750. JLabel user_status_label = new JLabel("\u767B\u5F55\u7528\u6237\uFF1A");
  751. user_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  752. user_status_label.setForeground(Color.BLACK);
  753. user_status_label.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  754. user_status_label.setBackground(Color.LIGHT_GRAY);
  755. toolBar.add(user_status_label);
  756. user_menu = new JButton("JinJuShi");
  757. user_menu.setForeground(Color.GREEN);
  758. user_menu.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  759. user_menu.setBackground(Color.BLACK);
  760. toolBar.add(user_menu);
  761. JLabel space_3 = new JLabel(" ");
  762. toolBar.add(space_3);
  763. JLabel space_4 = new JLabel(" ");
  764. toolBar.add(space_4);
  765. tabbedPane = new JTabbedPane(JTabbedPane.TOP);
  766. tabbedPane.setMinimumSize(new Dimension(400, 50));
  767. tabbedPane.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 22));
  768. contentPane.add(tabbedPane);
  769. indexPanelA = new JPanel();
  770. indexPanelA.setLayout(null);
  771. indexPanelA.setPreferredSize(new Dimension(1000, 1000));
  772. indexScrollPaneA = new JScrollPane(indexPanelA);
  773. indexScrollPaneA.getVerticalScrollBar().setUnitIncrement(20);
  774. indexScrollPaneA.setBorder(null);
  775. // --- 初始化内容 ---
  776. product_sn = new JTextField();
  777. product_sn.setText("");
  778. product_sn.setHorizontalAlignment(SwingConstants.CENTER);
  779. product_sn.setEditable(false);
  780. product_sn.setBorder(UIManager.getBorder("TextField.border")); // 显式设置边框
  781. product_sn.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  782. product_sn.setBounds(26, 152, 446, 70);
  783. indexPanelA.add(product_sn);
  784. product_sn.setColumns(10);
  785. // String[] hjtitles = new String[]{"閻掑﹥婧�1","閻掑﹥婧�2","閻掑﹥婧�3"};
  786. // String[] hjvals = new String[]{"HJ001","HJ002","HJ003"};
  787. // mesRadioHj = new MesRadio(hjtitles,hjvals);
  788. // mesRadioHj.setSize(500,50);
  789. // mesRadioHj.setBounds(190,170,500,50);
  790. // indexPanelA.add(mesRadioHj);
  791. finish_ok_bt = new JButton("OK");
  792. finish_ok_bt.setEnabled(false);
  793. finish_ok_bt.addActionListener(new ActionListener() {
  794. public void actionPerformed(ActionEvent e) {
  795. // if(work_status == 1 && check_quality_result){
  796. //
  797. //
  798. // }
  799. String sn = getBarcode(product_sn.getText());
  800. getUser();
  801. if(!sn.isEmpty()){
  802. String qret = "OK";
  803. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"A");
  804. if(!sendret){
  805. MesClient.pxstatus1.setText("A:结果上传MES失败");
  806. MesClient.tjStatusa = 1;
  807. }else{
  808. MesClient.pxstatus1.setText("A:提交成功");
  809. MesClient.status_menu.setText("A件提交成功");
  810. MesClient.resetScanA();
  811. MesClient.notifyWorkSubmitted();
  812. }
  813. }
  814. }
  815. });
  816. finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  817. finish_ok_bt.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  818. finish_ok_bt.setBounds(50, 700, 160, 80);
  819. finish_ok_bt.setEnabled(false);
  820. // indexPanelA.add(finish_ok_bt);
  821. finish_ng_bt = new JButton("NG");
  822. finish_ng_bt.setEnabled(false);
  823. finish_ng_bt.addActionListener(new ActionListener() {
  824. public void actionPerformed(ActionEvent e) {
  825. // if(work_status == 1 && check_quality_result){
  826. //
  827. // String sn = getBarcode(product_sn.getText());
  828. // getUser();
  829. // String qret = "OK";
  830. // Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  831. // if(!sendret){
  832. // JOptionPane.showMessageDialog(mesClientFrame,"上传MES失败,请重试","提醒", JOptionPane.INFORMATION_MESSAGE);
  833. // return;
  834. // }
  835. // }
  836. String sn = getBarcode(product_sn2.getText());
  837. getUser();
  838. if(!sn.isEmpty()){
  839. String qret = "OK";
  840. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  841. if(!sendret){
  842. MesClient.pxstatus2.setText("B:结果上传MES失败");
  843. MesClient.tjStatusb = 1;
  844. }else{
  845. MesClient.pxstatus2.setText("B:提交成功");
  846. MesClient.status_menu.setText("B件提交成功");
  847. MesClient.resetScanB();
  848. MesClient.notifyWorkSubmitted();
  849. }
  850. }
  851. }
  852. });
  853. finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  854. finish_ng_bt.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  855. finish_ng_bt.setBounds(280, 700, 160, 80);
  856. finish_ng_bt.setEnabled(false);
  857. // indexPanelA.add(finish_ng_bt);
  858. finish_ok_bt2 = new JButton("OK");
  859. finish_ok_bt2.setEnabled(false);
  860. finish_ok_bt2.addActionListener(new ActionListener() {
  861. public void actionPerformed(ActionEvent e) {
  862. // if(work_status == 1 && check_quality_result){
  863. //
  864. //
  865. // }
  866. String sn = getBarcode(product_sn.getText());
  867. getUser();
  868. if(!sn.isEmpty()){
  869. String qret = "OK";
  870. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  871. if(!sendret){
  872. MesClient.pxstatus2.setText("B:结果上传MES失败");
  873. MesClient.tjStatusb = 1;
  874. }else{
  875. MesClient.pxstatus2.setText("B:提交成功");
  876. MesClient.status_menu.setText("B件提交成功");
  877. MesClient.resetScanB();
  878. MesClient.notifyWorkSubmitted();
  879. }
  880. }
  881. }
  882. });
  883. finish_ok_bt2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  884. finish_ok_bt2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  885. finish_ok_bt2.setBounds(550, 700, 160, 80);
  886. finish_ok_bt2.setEnabled(false);
  887. // indexPanelA.add(finish_ok_bt2);
  888. finish_ng_bt2 = new JButton("NG");
  889. finish_ng_bt2.setEnabled(false);
  890. finish_ng_bt2.addActionListener(new ActionListener() {
  891. public void actionPerformed(ActionEvent e) {
  892. // if(work_status == 1 && check_quality_result){
  893. //
  894. // String sn = getBarcode(product_sn.getText());
  895. // getUser();
  896. // String qret = "OK";
  897. // Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  898. // if(!sendret){
  899. // JOptionPane.showMessageDialog(mesClientFrame,"上传MES失败,请重试","提醒", JOptionPane.INFORMATION_MESSAGE);
  900. // return;
  901. // }
  902. // }
  903. String sn = getBarcode(product_sn2.getText());
  904. getUser();
  905. if(!sn.isEmpty()){
  906. String qret = "NG";
  907. Boolean sendret = DataUtil.sendQuality(nettyClient,sn,qret,user20,"B");
  908. if(!sendret){
  909. MesClient.pxstatus2.setText("B:结果上传MES失败");
  910. MesClient.tjStatusb = 1;
  911. }else{
  912. MesClient.pxstatus2.setText("B:提交成功");
  913. MesClient.status_menu.setText("B件提交成功");
  914. MesClient.resetScanB();
  915. MesClient.notifyWorkSubmitted();
  916. }
  917. }
  918. }
  919. });
  920. finish_ng_bt2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  921. finish_ng_bt2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  922. finish_ng_bt2.setBounds(780, 700, 160, 80);
  923. finish_ng_bt2.setEnabled(false);
  924. // indexPanelA.add(finish_ng_bt2);
  925. product_sn2 = new JTextField();
  926. product_sn2.setText("");
  927. product_sn2.setHorizontalAlignment(SwingConstants.CENTER);
  928. product_sn2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  929. product_sn2.setEditable(false);
  930. product_sn2.setBorder(UIManager.getBorder("TextField.border")); // 显式设置边框
  931. product_sn2.setColumns(10);
  932. product_sn2.setBounds(517, 152, 446, 70);
  933. indexPanelA.add(product_sn2);
  934. // --- A枪 区域 ---
  935. JLabel lblA_Title = new JLabel("焊枪 A");
  936. lblA_Title.setFont(new Font("微软雅黑", Font.BOLD, 22));
  937. lblA_Title.setBounds(26, 260, 100, 40);
  938. indexPanelA.add(lblA_Title);
  939. JLabel lblNewLabel = new JLabel("电压");
  940. lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
  941. lblNewLabel.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  942. lblNewLabel.setBounds(26, 300, 80, 40);
  943. indexPanelA.add(lblNewLabel);
  944. param1 = new JTextField();
  945. param1.setEnabled(false);
  946. param1.setEditable(false);
  947. param1.setHorizontalAlignment(SwingConstants.CENTER);
  948. param1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  949. param1.setBounds(116, 300, 70, 40);
  950. indexPanelA.add(param1);
  951. JLabel lblNewLabel_1 = new JLabel("电流");
  952. lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
  953. lblNewLabel_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  954. lblNewLabel_1.setBounds(206, 300, 80, 40);
  955. indexPanelA.add(lblNewLabel_1);
  956. param2 = new JTextField();
  957. param2.setEnabled(false);
  958. param2.setEditable(false);
  959. param2.setHorizontalAlignment(SwingConstants.CENTER);
  960. param2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  961. param2.setBounds(296, 300, 70, 40);
  962. indexPanelA.add(param2);
  963. JLabel lblNewLabel_2 = new JLabel("送丝");
  964. lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT);
  965. lblNewLabel_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  966. lblNewLabel_2.setBounds(26, 350, 80, 40);
  967. indexPanelA.add(lblNewLabel_2);
  968. param3 = new JTextField();
  969. param3.setEnabled(false);
  970. param3.setEditable(false);
  971. param3.setHorizontalAlignment(SwingConstants.CENTER);
  972. param3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  973. param3.setBounds(116, 350, 70, 40);
  974. indexPanelA.add(param3);
  975. JLabel lblNewLabel_1_1 = new JLabel("错误");
  976. lblNewLabel_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  977. lblNewLabel_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  978. lblNewLabel_1_1.setBounds(206, 350, 80, 40);
  979. indexPanelA.add(lblNewLabel_1_1);
  980. param4 = new JTextField();
  981. param4.setEnabled(false);
  982. param4.setEditable(false);
  983. param4.setHorizontalAlignment(SwingConstants.CENTER);
  984. param4.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  985. param4.setBounds(296, 350, 70, 40);
  986. indexPanelA.add(param4);
  987. JLabel lblNewLabel_1_1_1 = new JLabel("JOB号");
  988. lblNewLabel_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  989. lblNewLabel_1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  990. lblNewLabel_1_1_1.setBounds(106, 400, 80, 40);
  991. indexPanelA.add(lblNewLabel_1_1_1);
  992. param5 = new JTextField();
  993. param5.setEnabled(false);
  994. param5.setEditable(false);
  995. param5.setHorizontalAlignment(SwingConstants.CENTER);
  996. param5.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  997. param5.setBounds(196, 400, 70, 40);
  998. indexPanelA.add(param5);
  999. JLabel lblTipA = new JLabel("导电嘴");
  1000. lblTipA.setHorizontalAlignment(SwingConstants.RIGHT);
  1001. lblTipA.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
  1002. lblTipA.setBounds(276, 400, 70, 40);
  1003. indexPanelA.add(lblTipA);
  1004. tipLifeA = new JTextField("0/0");
  1005. tipLifeA.setEnabled(false);
  1006. tipLifeA.setEditable(false);
  1007. tipLifeA.setHorizontalAlignment(SwingConstants.CENTER);
  1008. tipLifeA.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 16));
  1009. tipLifeA.setBounds(356, 400, 110, 40);
  1010. tipLifeA.setToolTipText("实际数量/设定数量");
  1011. indexPanelA.add(tipLifeA);
  1012. // --- B枪 区域 ---
  1013. JLabel lblB_Title = new JLabel("焊枪 B");
  1014. lblB_Title.setFont(new Font("微软雅黑", Font.BOLD, 22));
  1015. lblB_Title.setBounds(517, 260, 100, 40);
  1016. indexPanelA.add(lblB_Title);
  1017. JLabel lblNewLabel_3 = new JLabel("电压");
  1018. lblNewLabel_3.setHorizontalAlignment(SwingConstants.RIGHT);
  1019. lblNewLabel_3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1020. lblNewLabel_3.setBounds(517, 300, 80, 40);
  1021. indexPanelA.add(lblNewLabel_3);
  1022. param21 = new JTextField();
  1023. param21.setEnabled(false);
  1024. param21.setEditable(false);
  1025. param21.setHorizontalAlignment(SwingConstants.CENTER);
  1026. param21.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1027. param21.setBounds(607, 300, 70, 40);
  1028. indexPanelA.add(param21);
  1029. JLabel lblNewLabel_1_2 = new JLabel("电流");
  1030. lblNewLabel_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
  1031. lblNewLabel_1_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1032. lblNewLabel_1_2.setBounds(697, 300, 80, 40);
  1033. indexPanelA.add(lblNewLabel_1_2);
  1034. param22 = new JTextField();
  1035. param22.setEnabled(false);
  1036. param22.setEditable(false);
  1037. param22.setHorizontalAlignment(SwingConstants.CENTER);
  1038. param22.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1039. param22.setBounds(787, 300, 70, 40);
  1040. indexPanelA.add(param22);
  1041. JLabel lblNewLabel_2_1 = new JLabel("送丝");
  1042. lblNewLabel_2_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1043. lblNewLabel_2_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1044. lblNewLabel_2_1.setBounds(517, 350, 80, 40);
  1045. indexPanelA.add(lblNewLabel_2_1);
  1046. param23 = new JTextField();
  1047. param23.setEnabled(false);
  1048. param23.setEditable(false);
  1049. param23.setHorizontalAlignment(SwingConstants.CENTER);
  1050. param23.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1051. param23.setBounds(607, 350, 70, 40);
  1052. indexPanelA.add(param23);
  1053. JLabel lblNewLabel_1_1_2 = new JLabel("错误");
  1054. lblNewLabel_1_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
  1055. lblNewLabel_1_1_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1056. lblNewLabel_1_1_2.setBounds(697, 350, 80, 40);
  1057. indexPanelA.add(lblNewLabel_1_1_2);
  1058. param24 = new JTextField();
  1059. param24.setEnabled(false);
  1060. param24.setEditable(false);
  1061. param24.setHorizontalAlignment(SwingConstants.CENTER);
  1062. param24.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1063. param24.setBounds(787, 350, 70, 40);
  1064. indexPanelA.add(param24);
  1065. JLabel lblNewLabel_1_1_1_1 = new JLabel("JOB号");
  1066. lblNewLabel_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1067. lblNewLabel_1_1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1068. lblNewLabel_1_1_1_1.setBounds(597, 400, 80, 40);
  1069. indexPanelA.add(lblNewLabel_1_1_1_1);
  1070. param25 = new JTextField();
  1071. param25.setEnabled(false);
  1072. param25.setEditable(false);
  1073. param25.setHorizontalAlignment(SwingConstants.CENTER);
  1074. param25.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1075. param25.setBounds(687, 400, 70, 40);
  1076. indexPanelA.add(param25);
  1077. JLabel lblTipB = new JLabel("导电嘴");
  1078. lblTipB.setHorizontalAlignment(SwingConstants.RIGHT);
  1079. lblTipB.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
  1080. lblTipB.setBounds(767, 400, 70, 40);
  1081. indexPanelA.add(lblTipB);
  1082. tipLifeB = new JTextField("0/0");
  1083. tipLifeB.setEnabled(false);
  1084. tipLifeB.setEditable(false);
  1085. tipLifeB.setHorizontalAlignment(SwingConstants.CENTER);
  1086. tipLifeB.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 16));
  1087. tipLifeB.setBounds(847, 400, 110, 40);
  1088. tipLifeB.setToolTipText("实际数量/设定数量");
  1089. indexPanelA.add(tipLifeB);
  1090. // --- C枪 区域 ---
  1091. JLabel lblC_Title = new JLabel("焊枪 C");
  1092. lblC_Title.setFont(new Font("微软雅黑", Font.BOLD, 22));
  1093. lblC_Title.setBounds(26, 480, 100, 40);
  1094. indexPanelA.add(lblC_Title);
  1095. JLabel lblDyC = new JLabel("电压");
  1096. lblDyC.setHorizontalAlignment(SwingConstants.RIGHT);
  1097. lblDyC.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1098. lblDyC.setBounds(26, 520, 80, 40);
  1099. indexPanelA.add(lblDyC);
  1100. param31 = new JTextField();
  1101. param31.setEditable(false);
  1102. param31.setHorizontalAlignment(SwingConstants.CENTER);
  1103. param31.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1104. param31.setBounds(116, 520, 70, 40);
  1105. indexPanelA.add(param31);
  1106. JLabel lblDlC = new JLabel("电流");
  1107. lblDlC.setHorizontalAlignment(SwingConstants.RIGHT);
  1108. lblDlC.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1109. lblDlC.setBounds(206, 520, 80, 40);
  1110. indexPanelA.add(lblDlC);
  1111. param32 = new JTextField();
  1112. param32.setEditable(false);
  1113. param32.setHorizontalAlignment(SwingConstants.CENTER);
  1114. param32.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1115. param32.setBounds(296, 520, 70, 40);
  1116. indexPanelA.add(param32);
  1117. JLabel lblSsC = new JLabel("送丝");
  1118. lblSsC.setHorizontalAlignment(SwingConstants.RIGHT);
  1119. lblSsC.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1120. lblSsC.setBounds(26, 570, 80, 40);
  1121. indexPanelA.add(lblSsC);
  1122. param33 = new JTextField();
  1123. param33.setEditable(false);
  1124. param33.setHorizontalAlignment(SwingConstants.CENTER);
  1125. param33.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1126. param33.setBounds(116, 570, 70, 40);
  1127. indexPanelA.add(param33);
  1128. JLabel lblCwC = new JLabel("错误");
  1129. lblCwC.setHorizontalAlignment(SwingConstants.RIGHT);
  1130. lblCwC.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1131. lblCwC.setBounds(206, 570, 80, 40);
  1132. indexPanelA.add(lblCwC);
  1133. param34 = new JTextField();
  1134. param34.setEditable(false);
  1135. param34.setHorizontalAlignment(SwingConstants.CENTER);
  1136. param34.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1137. param34.setBounds(296, 570, 70, 40);
  1138. indexPanelA.add(param34);
  1139. JLabel lblJobC = new JLabel("JOB号");
  1140. lblJobC.setHorizontalAlignment(SwingConstants.RIGHT);
  1141. lblJobC.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1142. lblJobC.setBounds(106, 620, 80, 40);
  1143. indexPanelA.add(lblJobC);
  1144. param35 = new JTextField();
  1145. param35.setEditable(false);
  1146. param35.setHorizontalAlignment(SwingConstants.CENTER);
  1147. param35.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1148. param35.setBounds(196, 620, 70, 40);
  1149. indexPanelA.add(param35);
  1150. JLabel lblTipC = new JLabel("导电嘴");
  1151. lblTipC.setHorizontalAlignment(SwingConstants.RIGHT);
  1152. lblTipC.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16));
  1153. lblTipC.setBounds(276, 620, 70, 40);
  1154. indexPanelA.add(lblTipC);
  1155. tipLifeC = new JTextField("0/0");
  1156. tipLifeC.setEnabled(false);
  1157. tipLifeC.setEditable(false);
  1158. tipLifeC.setHorizontalAlignment(SwingConstants.CENTER);
  1159. tipLifeC.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 16));
  1160. tipLifeC.setBounds(356, 620, 110, 40);
  1161. tipLifeC.setToolTipText("实际数量/设定数量");
  1162. indexPanelA.add(tipLifeC);
  1163. // --- D枪 区域 ---
  1164. JLabel lblD_Title = new JLabel("焊枪 D");
  1165. lblD_Title.setFont(new Font("微软雅黑", Font.BOLD, 22));
  1166. lblD_Title.setBounds(517, 480, 100, 40);
  1167. // indexPanelA.add(lblD_Title);
  1168. JLabel lblDyD = new JLabel("电压");
  1169. lblDyD.setHorizontalAlignment(SwingConstants.RIGHT);
  1170. lblDyD.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1171. lblDyD.setBounds(517, 520, 80, 40);
  1172. // indexPanelA.add(lblDyD);
  1173. param41 = new JTextField();
  1174. param41.setEditable(false);
  1175. param41.setHorizontalAlignment(SwingConstants.CENTER);
  1176. param41.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1177. param41.setBounds(607, 520, 70, 40);
  1178. // indexPanelA.add(param41);
  1179. JLabel lblDlD = new JLabel("电流");
  1180. lblDlD.setHorizontalAlignment(SwingConstants.RIGHT);
  1181. lblDlD.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1182. lblDlD.setBounds(697, 520, 80, 40);
  1183. // indexPanelA.add(lblDlD);
  1184. param42 = new JTextField();
  1185. param42.setEditable(false);
  1186. param42.setHorizontalAlignment(SwingConstants.CENTER);
  1187. param42.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1188. param42.setBounds(787, 520, 70, 40);
  1189. // indexPanelA.add(param42);
  1190. JLabel lblSsD = new JLabel("送丝");
  1191. lblSsD.setHorizontalAlignment(SwingConstants.RIGHT);
  1192. lblSsD.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1193. lblSsD.setBounds(517, 570, 80, 40);
  1194. // indexPanelA.add(lblSsD);
  1195. param43 = new JTextField();
  1196. param43.setEditable(false);
  1197. param43.setHorizontalAlignment(SwingConstants.CENTER);
  1198. param43.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1199. param43.setBounds(607, 570, 70, 40);
  1200. // indexPanelA.add(param43);
  1201. JLabel lblCwD = new JLabel("错误");
  1202. lblCwD.setHorizontalAlignment(SwingConstants.RIGHT);
  1203. lblCwD.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1204. lblCwD.setBounds(697, 570, 80, 40);
  1205. // indexPanelA.add(lblCwD);
  1206. param44 = new JTextField();
  1207. param44.setEditable(false);
  1208. param44.setHorizontalAlignment(SwingConstants.CENTER);
  1209. param44.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1210. param44.setBounds(787, 570, 70, 40);
  1211. // indexPanelA.add(param44);
  1212. JLabel lblJobD = new JLabel("JOB号");
  1213. lblJobD.setHorizontalAlignment(SwingConstants.RIGHT);
  1214. lblJobD.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1215. lblJobD.setBounds(597, 620, 80, 40);
  1216. // indexPanelA.add(lblJobD);
  1217. param45 = new JTextField();
  1218. param45.setEditable(false);
  1219. param45.setHorizontalAlignment(SwingConstants.CENTER);
  1220. param45.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 18));
  1221. param45.setBounds(687, 620, 70, 40);
  1222. // indexPanelA.add(param45);
  1223. pxstatus1 = new JLabel("A");
  1224. pxstatus1.setForeground(new Color(255, 128, 64));
  1225. pxstatus1.setHorizontalAlignment(SwingConstants.CENTER);
  1226. pxstatus1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  1227. pxstatus1.setBounds(26, 98, 446, 44);
  1228. indexPanelA.add(pxstatus1);
  1229. pxstatus2 = new JLabel("B");
  1230. pxstatus2.setForeground(new Color(255, 128, 64));
  1231. pxstatus2.setHorizontalAlignment(SwingConstants.CENTER);
  1232. pxstatus2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  1233. pxstatus2.setBounds(517, 98, 446, 44);
  1234. indexPanelA.add(pxstatus2);
  1235. JSeparator separator_2 = new JSeparator();
  1236. separator_2.setBounds(10, 264, 973, 13);
  1237. // indexPanelA.add(separator_2);
  1238. JLabel lblNewLabel_4 = new JLabel("\u710A\u67331");
  1239. lblNewLabel_4.setHorizontalAlignment(SwingConstants.CENTER);
  1240. lblNewLabel_4.setFont(new Font("微软雅黑", Font.PLAIN, 24));
  1241. lblNewLabel_4.setBounds(170, 290, 156, 40);
  1242. lblNewLabel_4.setVisible(false);
  1243. // indexPanelA.add(lblNewLabel_4);
  1244. JLabel lblNewLabel_4_1 = new JLabel("\u710A\u67332");
  1245. lblNewLabel_4_1.setHorizontalAlignment(SwingConstants.CENTER);
  1246. lblNewLabel_4_1.setFont(new Font("微软雅黑", Font.PLAIN, 24));
  1247. lblNewLabel_4_1.setBounds(670, 287, 156, 40);
  1248. lblNewLabel_4_1.setVisible(false);
  1249. // indexPanelA.add(lblNewLabel_4_1);
  1250. JSeparator separator_1_1 = new JSeparator();
  1251. separator_1_1.setOrientation(SwingConstants.VERTICAL);
  1252. separator_1_1.setBounds(495, 278, 23, 400); // 增加高度以覆盖 C/D 枪
  1253. indexPanelA.add(separator_1_1);
  1254. textField = new JTextField();
  1255. textField.setText("");
  1256. textField.setHorizontalAlignment(SwingConstants.CENTER);
  1257. textField.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  1258. textField.setEditable(false);
  1259. textField.setColumns(10);
  1260. textField.setBounds(26, 333, 446, 70);
  1261. // indexPanelA.add(textField);
  1262. batch_scan_1 = new JButton("解绑");
  1263. batch_scan_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/delete.png")));
  1264. batch_scan_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  1265. batch_scan_1.setEnabled(false);
  1266. batch_scan_1.setVisible(false);
  1267. batch_scan_1.setBounds(136, 430, 230, 80);
  1268. batch_scan_1.addActionListener(new ActionListener() {
  1269. public void actionPerformed(ActionEvent e) {
  1270. if(MesClient.curPage.equals("B")){
  1271. MesClient.setMenuStatus("该状态后梁无法解绑",-1);
  1272. }else{
  1273. String sn = MesClient.product_sn.getText().trim();
  1274. String wsn = MesClient.textField.getText().trim();
  1275. JSONObject retObj = DataUtil.unBindWarehouseData(sn,wsn,user_menu.getText().trim(),"400007");
  1276. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1277. MesClient.setMenuStatus("后梁码解绑成功",0);
  1278. MesClient.formatScanType(2);
  1279. textField.setText("");
  1280. batch_scan_1.setEnabled(false);
  1281. PlcUtil.changeEnable(s7PLC,false);
  1282. }else{
  1283. MesClient.formatScanType(2);
  1284. batch_scan_1.setEnabled(true);
  1285. if(retObj.get("result")==null){
  1286. MesClient.setMenuStatus("请求失败,后梁码解绑失败,请重试",-1);
  1287. }else{
  1288. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  1289. MesClient.setMenuStatus(retObj.getString("message"),-1);
  1290. }
  1291. }
  1292. }
  1293. }
  1294. }
  1295. });
  1296. indexPanelA.add(batch_scan_1);
  1297. textField_1 = new JTextField();
  1298. textField_1.setText("");
  1299. textField_1.setHorizontalAlignment(SwingConstants.CENTER);
  1300. textField_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  1301. textField_1.setEditable(false);
  1302. textField_1.setColumns(10);
  1303. textField_1.setBounds(517, 333, 446, 70);
  1304. // indexPanelA.add(textField_1);
  1305. batch_scan_2 = new JButton("解绑");
  1306. batch_scan_2.setIcon(new ImageIcon(MesClient.class.getResource("/bg/delete.png")));
  1307. batch_scan_2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 32));
  1308. batch_scan_2.setEnabled(false);
  1309. batch_scan_2.setVisible(false);
  1310. batch_scan_2.setBounds(633, 430, 230, 80);
  1311. batch_scan_2.addActionListener(new ActionListener() {
  1312. public void actionPerformed(ActionEvent e) {
  1313. if(MesClient.curPage.equals("A")){
  1314. MesClient.setMenuStatus("该状态后梁无法解绑",-1);
  1315. }else{
  1316. String sn = MesClient.product_sn2.getText().trim();
  1317. String wsn = MesClient.textField_1.getText().trim();
  1318. JSONObject retObj = DataUtil.unBindWarehouseData(sn,wsn,user_menu.getText().trim(),"400007");
  1319. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1320. MesClient.setMenuStatus("后梁码解绑成功",0);
  1321. MesClient.formatScanType(2);
  1322. textField_1.setText("");
  1323. batch_scan_2.setEnabled(false);
  1324. PlcUtil.changeEnable(s7PLC,false);
  1325. }else{
  1326. if(retObj.get("result")==null){
  1327. MesClient.setMenuStatus("请求失败,前梁码解绑失败,请重试",-1);
  1328. }else{
  1329. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  1330. MesClient.setMenuStatus(retObj.getString("message"),-1);
  1331. }
  1332. }
  1333. }
  1334. }
  1335. }
  1336. });
  1337. indexPanelA.add(batch_scan_2);
  1338. JLabel pxstatus1_1 = new JLabel("A后梁");
  1339. pxstatus1_1.setHorizontalAlignment(SwingConstants.CENTER);
  1340. pxstatus1_1.setForeground(new Color(0, 0, 0));
  1341. pxstatus1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  1342. pxstatus1_1.setBounds(26, 283, 446, 44);
  1343. // indexPanelA.add(pxstatus1_1);
  1344. JLabel pxstatus1_1_1 = new JLabel("B后梁");
  1345. pxstatus1_1_1.setHorizontalAlignment(SwingConstants.CENTER);
  1346. pxstatus1_1_1.setForeground(Color.BLACK);
  1347. pxstatus1_1_1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 20));
  1348. pxstatus1_1_1.setBounds(517, 283, 446, 44);
  1349. // indexPanelA.add(pxstatus1_1_1);
  1350. txtfa = new JTextField();
  1351. txtfa.setHorizontalAlignment(SwingConstants.LEFT);
  1352. txtfa.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
  1353. txtfa.setColumns(10);
  1354. txtfa.setBounds(239, 10, 503, 60);
  1355. indexPanelA.add(txtfa);
  1356. txtfa.addActionListener(new ActionListener() {
  1357. public void actionPerformed(ActionEvent e) {
  1358. scanBarcode();
  1359. }
  1360. });
  1361. page_text = new JLabel("当前:A面");
  1362. page_text.setForeground(new Color(0, 255, 64));
  1363. page_text.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1364. page_text.setHorizontalAlignment(SwingConstants.RIGHT);
  1365. page_text.setBounds(97, 10, 132, 60);
  1366. indexPanelA.add(page_text);
  1367. scan_type_text = new JLabel("镭雕码");
  1368. scan_type_text.setForeground(new Color(255, 128, 64));
  1369. scan_type_text.setHorizontalAlignment(SwingConstants.LEFT);
  1370. scan_type_text.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1371. scan_type_text.setBounds(752, 10, 132, 60);
  1372. indexPanelA.add(scan_type_text);
  1373. tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
  1374. tabbedPane.setEnabledAt(0, true);
  1375. JPanel indexPanelGz = new JPanel();
  1376. searchScrollPaneGz = new JScrollPane(indexPanelGz);
  1377. indexPanelGz.setLayout(null);
  1378. indexPanelC = new JPanel();
  1379. searchScrollPaneDj = new JScrollPane(indexPanelC);
  1380. indexPanelC.setLayout(null);
  1381. tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
  1382. indexPanelB = new JPanel();
  1383. searchScrollPane = new JScrollPane(indexPanelB);
  1384. indexPanelB.setLayout(null);
  1385. tabbedPane.addTab("工作记录", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
  1386. // bindBatchPanel();
  1387. tabbedPane.addChangeListener(new ChangeListener() {
  1388. @Override
  1389. public void stateChanged(ChangeEvent e) {
  1390. JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
  1391. int selectedIndex = tabbedPane.getSelectedIndex();
  1392. System.out.println("selectedIndex:"+selectedIndex);
  1393. if(selectedIndex == TAB_WORK_RECORD){
  1394. refreshWorkRecord();
  1395. }
  1396. }
  1397. });
  1398. }
  1399. public static void formatScanType(int st){
  1400. scan_type = st;
  1401. if(scan_type == 1){
  1402. scan_type_text.setText("镭雕码");
  1403. }else if(scan_type == 2){
  1404. scan_type_text.setText("后梁码");
  1405. }else{
  1406. scan_type_text.setText("");
  1407. }
  1408. }
  1409. public static void scanBarcode() {
  1410. String scanBarcodeSn = txtfa.getText().trim();
  1411. txtfa.setText("");
  1412. System.out.println("scan_type:"+scan_type);
  1413. //刷新界面
  1414. mesClientFrame.repaint();
  1415. System.out.println("456");
  1416. System.out.println("156"+scan_type);
  1417. if(MesClient.scan_type == 1){ // 镭雕码
  1418. System.out.println("type1");
  1419. if(scanBarcodeSn.isEmpty()){
  1420. System.out.println("type2");
  1421. MesClient.setMenuStatus("镭雕码不能为空",1);
  1422. return;
  1423. }
  1424. if(MesClient.curPage.equals("A")){
  1425. System.out.println("typeA");
  1426. MesClient.lastScanSide = "A";
  1427. if(!product_sn.getText().isEmpty() && mesQualityFlagA){
  1428. MesClient.setMenuStatus("A面已存在工件码,勿重复扫码",1);
  1429. return;
  1430. }
  1431. product_sn.setText(scanBarcodeSn);
  1432. }else{
  1433. System.out.println("typeB");
  1434. MesClient.lastScanSide = "B";
  1435. if(!product_sn2.getText().isEmpty() && mesQualityFlagB){
  1436. MesClient.setMenuStatus("B面已存在工件码,勿重复扫码",1);
  1437. return;
  1438. }
  1439. product_sn2.setText(scanBarcodeSn);
  1440. }
  1441. MesClient.setMenuStatus("扫码成功",0);
  1442. //刷新界面
  1443. mesClientFrame.repaint();
  1444. System.out.println("123");
  1445. getUser();
  1446. // 查询工件质量
  1447. Boolean sendret = DataUtil.checkQuality(nettyClient,scanBarcodeSn,user20,MesClient.lastScanSide);
  1448. if(!sendret){
  1449. MesClient.setMenuStatus("消息发送失败,请重试",1);
  1450. }
  1451. }
  1452. }
  1453. public static void setMenuStatus(String msg,int error){
  1454. if(error == 0){
  1455. MesClient.status_menu.setForeground(Color.GREEN);
  1456. }else{
  1457. MesClient.status_menu.setForeground(Color.RED);
  1458. }
  1459. MesClient.status_menu.setText(msg);
  1460. }
  1461. public static void getMaterailData(){
  1462. JSONObject retObj = DataUtil.getBindMaterail();
  1463. if (retObj == null) {
  1464. log.warn("加载物料列表失败,请检查MES服务或网络连接");
  1465. return;
  1466. }
  1467. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1468. List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  1469. if (arrs == null || arrs.isEmpty()) {
  1470. return;
  1471. }
  1472. int i = 0;
  1473. rowData = new Object[arrs.size()][7];
  1474. for (BindMaterialResp bindMaterialResp:arrs){
  1475. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  1476. rowData[i][1] = bindMaterialResp.getBatchSn();
  1477. rowData[i][2] = bindMaterialResp.getLastTimes();
  1478. rowData[i][3] = "";
  1479. rowData[i][4] = bindMaterialResp.getCraft();
  1480. rowData[i][5] = bindMaterialResp.getMaterialId();
  1481. rowData[i][6] = bindMaterialResp.getType();
  1482. i++;
  1483. }
  1484. bindBatchPanel();
  1485. }
  1486. }
  1487. public static void updateMaterailData(){
  1488. JSONObject retObj = DataUtil.getBindMaterail();
  1489. if (retObj == null) {
  1490. log.warn("更新物料列表失败,请检查MES服务或网络连接");
  1491. return;
  1492. }
  1493. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1494. List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  1495. if (arrs == null || arrs.isEmpty() || rowData == null) {
  1496. return;
  1497. }
  1498. int i = 0;
  1499. for (BindMaterialResp bindMaterialResp:arrs){
  1500. rowData[i][0] = bindMaterialResp.getMaterialTitle();
  1501. rowData[i][1] = bindMaterialResp.getBatchSn();
  1502. rowData[i][2] = bindMaterialResp.getLastTimes();
  1503. rowData[i][3] = "";
  1504. rowData[i][4] = bindMaterialResp.getCraft();
  1505. rowData[i][5] = bindMaterialResp.getMaterialId();
  1506. rowData[i][6] = bindMaterialResp.getType();
  1507. i++;
  1508. }
  1509. MesClient.table.repaint();
  1510. }
  1511. }
  1512. // 绑定物料批次码
  1513. public static void scanBatchSn(BindMaterialResp bindMaterialResp) { // 扫码类型
  1514. //弹窗扫工件码
  1515. String scanBarcodeTitle = "请扫物料:"+bindMaterialResp.getMaterialTitle();
  1516. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  1517. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  1518. JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType());
  1519. if (retObj == null) {
  1520. MesClient.setMenuStatus("请求失败,请重试",-1);
  1521. return;
  1522. }
  1523. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  1524. MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0);
  1525. updateMaterailData();
  1526. }else{
  1527. if(retObj.get("result")==null){
  1528. MesClient.setMenuStatus("请求失败,请重试",-1);
  1529. }else{
  1530. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  1531. MesClient.setMenuStatus(retObj.getString("message"),-1);
  1532. }
  1533. }
  1534. }
  1535. }
  1536. }
  1537. public static void bindBatchPanel(){
  1538. JPanel indexPanelBB = new JPanel();
  1539. JPanel panel = new JPanel();
  1540. panel.setBounds(0, 0, 990, 550);
  1541. // panel.setBounds(81, 50, 810, 479);
  1542. indexPanelBB.add(panel);
  1543. panel.setLayout(new GridLayout(0, 1, 0, 0));
  1544. table = new JTable(rowData, columnNames){
  1545. public boolean isCellEditable(int row, int column) {
  1546. if(column == 3){
  1547. return true;
  1548. }
  1549. return false;
  1550. }
  1551. };
  1552. table.setRowHeight(40);
  1553. table.setEnabled(true);
  1554. table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  1555. table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
  1556. table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
  1557. JScrollPane scrollPane = new JScrollPane(table);
  1558. panel.add(scrollPane);
  1559. indexScrollPaneB = new JScrollPane(indexPanelBB);
  1560. indexPanelBB.setLayout(null);
  1561. tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
  1562. }
  1563. // 开启发送结果定时任务
  1564. public static void startUpdateQualityTimer(){
  1565. new Timer().schedule(new TimerTask() {
  1566. @Override
  1567. public void run() {
  1568. try {
  1569. JdbcUtils.getConn();
  1570. Statement statement = JdbcUtils.conn.createStatement();
  1571. String selectSql = "SELECT id, bw FROM submit_record\n" +
  1572. "WHERE state = 0 ORDER BY id DESC LIMIT 10";
  1573. String updateSql = "UPDATE submit_record \n" +
  1574. "SET state = '1'\n" +
  1575. "WHERE id = ";
  1576. ResultSet rs = statement.executeQuery(selectSql);
  1577. while(rs.next()){
  1578. int id = rs.getInt("id");
  1579. String bw = rs.getString("bw");
  1580. // 发送请求
  1581. String url = "http://"+MesClient.mes_server_ip+":8980/js/a/mes/mesProductRecord/updateQualityByTiming";
  1582. String s = HttpUtils.sendPostRequestJson(url, bw );
  1583. Boolean result = JSONObject.parseObject(s).getBoolean("result");
  1584. if(result) {
  1585. // 更改状态为 1
  1586. statement.executeUpdate(updateSql + id);
  1587. }
  1588. }
  1589. rs.close();
  1590. statement.close();
  1591. } catch (SQLException | IOException e) {
  1592. // throw new RuntimeException(e);
  1593. e.printStackTrace();
  1594. }
  1595. }
  1596. },1000, 5000);
  1597. }
  1598. public static void formatBatchSn(){
  1599. if((MesClient.batch_status == 1 && MesClient.tjFlaga == 1) || (MesClient.batch_status2 == 1 && MesClient.tjFlagb == 1)){
  1600. PlcUtil.changeEnable(MesClient.s7PLC,true);
  1601. }else{
  1602. PlcUtil.changeEnable(MesClient.s7PLC,false);
  1603. }
  1604. }
  1605. private static String checkSnType(String sn){
  1606. String str = sn.substring(9,12);
  1607. if(str.equals("113")){
  1608. return "MX11-2";
  1609. }else if(str.equals("119")){
  1610. return "MX11-2S";
  1611. }else{
  1612. return "";
  1613. }
  1614. }
  1615. // 检查工件是否匹配
  1616. private static Boolean checkSnAndBatch(String sn,String batchSn){
  1617. String gdStr1 = "151245P000012131001000"; // MX11-2
  1618. String gdStr2 = "151245P000017812001000"; // MX11-2S
  1619. String cate = sn.substring(0,22);
  1620. String ptype = checkSnType(batchSn);
  1621. if(ptype.equals("MX11-2") && cate.equals(gdStr1)){
  1622. return true;
  1623. }
  1624. if(ptype.equals("MX11-2S") && cate.equals(gdStr2)){
  1625. return true;
  1626. }
  1627. return false;
  1628. }
  1629. }