MesClient.java 73 KB

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