MesClient.java 106 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515
  1. package com.mes.ui;
  2. import com.alibaba.fastjson2.JSONObject;
  3. import com.mes.component.MesRadio;
  4. import com.mes.component.MesWebView;
  5. import com.mes.component.ProductTypePanel;
  6. import com.mes.netty.NettyClient;
  7. import com.mes.util.ClientVersionUtils;
  8. import com.mes.util.ClientUpgrade;
  9. import com.mes.util.*;
  10. import org.slf4j.Logger;
  11. import org.slf4j.LoggerFactory;
  12. import javax.print.PrintService;
  13. import javax.print.PrintServiceLookup;
  14. import javax.swing.*;
  15. import javax.swing.border.EmptyBorder;
  16. import javax.swing.event.ChangeEvent;
  17. import javax.swing.event.ChangeListener;
  18. import javax.swing.table.DefaultTableCellRenderer;
  19. import javax.swing.table.DefaultTableModel;
  20. import javax.swing.table.TableColumn;
  21. import java.awt.*;
  22. import java.awt.event.*;
  23. import java.io.BufferedReader;
  24. import java.io.IOException;
  25. import java.io.InputStream;
  26. import java.io.InputStreamReader;
  27. import java.time.LocalDateTime;
  28. import java.util.*;
  29. import java.util.List;
  30. import java.util.Timer;
  31. public class MesClient extends JFrame {
  32. public static final Logger log = LoggerFactory.getLogger(MesClient.class);
  33. private static String Drivde = "org.sqlite.JDBC";
  34. public static int mes_auth = 0; // 权限级别 0=无权限 1=操作工人 2=管理员
  35. public static String mes_gw = "OP280A"; // 工位号
  36. public static String mes_gw_des = ""; // 工位名称
  37. public static String mes_server_ip = ""; // 服务器IP地址
  38. public static int mes_tcp_port = 3000; // TCP服务端口
  39. public static int mes_heart_beat_cycle = 10; // 心跳周期
  40. public static int mes_heart_icon_cycle = 1;
  41. public static String mes_line_sn = "";
  42. public static String client_version = "0.0.0"; // 打包发布版本,需和后台 JAR 管理版本号对齐 // 产线编号
  43. //TCP连接
  44. public static NettyClient nettyClient;
  45. //TCP连接状态
  46. public static boolean tcp_connect_flag = false;
  47. //TCP连接请求
  48. public static boolean connect_request_flag = false;
  49. //session
  50. public static String sessionid = "";
  51. public static JPanel contentPane;
  52. public static MesClient mesClientFrame;
  53. public static JTabbedPane tabbedPane;
  54. public static JScrollPane indexScrollPaneA;
  55. public static JScrollPane searchScrollPane;
  56. public static JScrollPane searchScrollPaneD;
  57. public static JScrollPane searchScrollPaneDj;
  58. public static JScrollPane searchScrollPaneTask;
  59. public static Boolean check_quality_result = false;
  60. public static Integer work_status = 0;
  61. public static JButton heart_beat_menu;
  62. public static JButton status_menu;
  63. public static JButton user_menu;
  64. public static int scan_type = 0;
  65. public static JButton finish_ok_bt;
  66. public static JButton finish_ng_bt;
  67. public static JTextField product_sn;
  68. public static JButton f_scan_data_bt_1;
  69. //新增字段
  70. public static ProductTypePanel productTypePanel;
  71. public static JLabel productTypeCurrentLabel;
  72. public static final int PRODUCT_SN_LENGTH = 32;
  73. public static final String PREFIX_ZJ = "000020021815-01000016"; //智界
  74. public static final String PREFIX_SJ = "000020022029-01000016"; //尚界
  75. public static final String PRODUCT_TYPE_SWITCH_PASSWORD = "503833";
  76. public static final String PRODUCT_TYPE_ZJ = ProductTypePanel.TYPE_ZJ;
  77. public static final String PRODUCT_TYPE_SJ = ProductTypePanel.TYPE_SJ;
  78. public static String user20 = "";
  79. public static boolean mes_enable = true; // true=MES开启
  80. public static JFrame welcomeWin;
  81. public static JPanel indexPanelB;
  82. public static MesWebView jfxPanel = null;
  83. public static JPanel indexPanelC;
  84. public static JPanel indexPanelD;
  85. public static MesWebView jfxPanel2 = null;
  86. public static MesWebView jfxPanel3 = null;
  87. public static MesRadio mesRadioHj;
  88. public static JLabel curTaskName;
  89. public static JTable table;
  90. public static Object[] columnNames = {"工件码", "测试日期", "压力", "泄露值","结果"};
  91. // public static Object[][] rowData = null;
  92. // public static Object[][] rowData = {
  93. // {"151245P00001213100100024120700111","2024-12-09 12:30:30","60","60","60","200kPa","3ml/min","OK"},
  94. // {"151245P00001213100100024120700112","2024-12-09 13:30:30","60","60","60","-200kPa","3ml/min","OK"},
  95. // {"151245P00001213100100024120700113","2024-12-09 14:30:30","60","60","60","200kPa","3ml/min","OK"},
  96. // {"151245P00001213100100024120700113","2024-12-09 14:30:30","60","60","60","200kPa","3ml/min","OK"},
  97. // };
  98. public static Object[][] rowData = new Object[12][5];
  99. public static JLabel pageLabel;
  100. public static int pageNo=1 ; // 当前页
  101. public static int totalPages; // 总页数
  102. public static JTextField textField;//搜索框
  103. public static JTable table2;
  104. public static Object[] columnNames2 = { "任务名称" };
  105. public static Object[][] rowData2 = {{""},{""},{""}};
  106. public static JTable materialTable;
  107. public static Object[] materialColumnNames = { "物料名称", "绑定批次", "剩余次数", "操作" };
  108. public static Object[][] materialRowData = null;
  109. public static Integer tjFlag = 0;
  110. public static String tjFlagText2 = "设备运行中";
  111. public static String tjFlagText3 = "设备运行结束";
  112. public static String tjFlagText4 = "结果已上传MES,请扫下一件";
  113. public static String tjFlagText5 = "已扫码,等待设备运行";
  114. public static String tjFlagTextErr = "结果上传MES失败,请重试";
  115. public static SerialPortUtils serialPortUtils;
  116. public static JTextField printSn2;
  117. public static JTextField printTitle2;
  118. public static JTextField printValue2;
  119. public static JButton printBtn2;
  120. public static ConfigParam configParam;
  121. public static Integer isConfigEdit = 0;
  122. public static Integer mesStartFlag = 0;
  123. /** MES开启时,仪器判NG后暂存,待工人填写漏点点位再上传 */
  124. public static TestParam pendingNgTestParam = null;
  125. public static List<TaskParam> taskParamList = new ArrayList<>();
  126. public static TaskParam curTaskParam = null;
  127. public static void main(String[] args) {
  128. if (ClientUpgrade.handleInstallArgs(args)) {
  129. return;
  130. }
  131. if (LockUtil.getInstance().isAppActive() == true){
  132. // JOptionPane.showMessageDialog(null, "已有一个程序在运行,程序退出");
  133. return;
  134. }
  135. EventQueue.invokeLater(new Runnable() {
  136. @Override
  137. public void run() {
  138. try{
  139. //读文件配置
  140. readProperty();
  141. if (ClientUpgrade.recoverIncompleteInstall()) {
  142. return;
  143. }
  144. ClientUpgrade.cleanupInstallLeftovers();
  145. ClientUpgrade.checkIfConfigured(null);
  146. // 显示界面
  147. mesClientFrame = new MesClient();
  148. mesClientFrame.setVisible(false);
  149. JdbcUtils.getConn();
  150. welcomeWin = new LoginFarme();
  151. welcomeWin.setVisible(true);
  152. formatConfigEdit(false);
  153. formatConfigData();
  154. getTask();
  155. serialPortUtils=new SerialPortUtils(configParam.getSerialPort(),getEffectiveOprno(),configParam.getOprnoTitle(),configParam.getDevice());
  156. // startDateTimer();
  157. textFocus();
  158. // resetScanA();
  159. }catch (Exception e){
  160. log.error(e.getMessage());
  161. }
  162. }
  163. });
  164. }
  165. public static Timer cjTimerText;
  166. public static void textFocus() {
  167. if(cjTimerText!=null) {
  168. cjTimerText.cancel();
  169. }
  170. cjTimerText = new Timer();
  171. cjTimerText.schedule(new TimerTask() {
  172. public void run() {
  173. if(work_status == 0){
  174. product_sn.requestFocusInWindow();
  175. }
  176. }
  177. }, 1000,1000);
  178. }
  179. public static java.util.Timer dateBeatTimer;
  180. public static void startDateTimer() {
  181. if (dateBeatTimer != null) {
  182. dateBeatTimer.cancel();
  183. }
  184. dateBeatTimer = new java.util.Timer();
  185. dateBeatTimer.schedule(new TimerTask() {
  186. public void run() {
  187. if (iconREDFlag) {
  188. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  189. iconREDFlag = false;
  190. } else {
  191. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  192. iconREDFlag = true;
  193. }
  194. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  195. heart_beat_menu.setForeground(Color.GREEN);
  196. heart_beat_menu.repaint();
  197. }
  198. }, 100, 1* 1000);
  199. }
  200. //读配置文件
  201. private static String parseClientVersion(String value) {
  202. if (value == null || value.trim().isEmpty()) {
  203. return "0.0.0";
  204. }
  205. return ClientVersionUtils.normalize(value.trim());
  206. }
  207. private static void readProperty() throws IOException{
  208. String enconding = "UTF-8";
  209. InputStream is = ClassLoader.getSystemResourceAsStream("config/config.properties");
  210. Properties pro = new Properties();
  211. BufferedReader br = new BufferedReader(new InputStreamReader(is, enconding));
  212. pro.load(br);
  213. client_version = parseClientVersion(pro.getProperty("mes.client.version"));
  214. mes_server_ip = pro.getProperty("mes.server_ip");
  215. mes_tcp_port = Integer.parseInt(pro.getProperty("mes.tcp_port"));
  216. mes_heart_beat_cycle = Integer.parseInt(pro.getProperty("mes.heart_beat_cycle"));
  217. String gw = pro.getProperty("mes.gw");
  218. if (gw != null && !gw.trim().isEmpty()) {
  219. mes_gw = gw.trim();
  220. }
  221. String lineSn = pro.getProperty("mes.line_sn");
  222. if (lineSn != null && !lineSn.trim().isEmpty()) {
  223. mes_line_sn = lineSn.trim();
  224. }
  225. mes_gw_des = OprnoUtil.getGwDes(mes_line_sn, mes_gw);
  226. log.info(mes_gw + ";" + mes_line_sn + ";" + mes_server_ip + ";" + mes_tcp_port + ";" + mes_heart_beat_cycle);
  227. }
  228. // 初始化TCP
  229. public static void initTcpConnection() {
  230. try {
  231. if(nettyClient==null) {
  232. //初始化TCP连接
  233. nettyClient = new NettyClient();
  234. //TCP连接状态
  235. tcp_connect_flag = false;
  236. //设置TCP请求状态
  237. connect_request_flag = true;
  238. DataUtil.synrTcp(nettyClient);
  239. }
  240. } catch (Exception e) {
  241. // TODO Auto-generated catch block
  242. e.printStackTrace();
  243. }
  244. }
  245. //启动心跳包程序
  246. public static java.util.Timer heartBeatTimer;
  247. public static java.util.Timer heartBeatIconTimer;
  248. public static boolean iconREDFlag = true;
  249. public static void startHeartBeatTimer() {
  250. if(heartBeatTimer!=null) {
  251. heartBeatTimer.cancel();
  252. }
  253. heartBeatTimer = new java.util.Timer();
  254. heartBeatTimer.schedule(new TimerTask() {
  255. public void run() {
  256. if(nettyClient!=null&&tcp_connect_flag) {
  257. //log.info("发送心跳报文");
  258. DataUtil.heartBeat(nettyClient);
  259. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  260. }
  261. }
  262. }, 100,mes_heart_beat_cycle*1000);
  263. //心跳显示图标
  264. if(heartBeatIconTimer!=null) {
  265. heartBeatIconTimer.cancel();
  266. }
  267. heartBeatIconTimer = new Timer();
  268. heartBeatIconTimer.schedule(new TimerTask() {
  269. public void run() {
  270. if(tcp_connect_flag) {
  271. if(iconREDFlag) {
  272. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  273. iconREDFlag = false;
  274. }else {
  275. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  276. iconREDFlag = true;
  277. }
  278. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  279. heart_beat_menu.repaint();
  280. }else {
  281. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  282. heart_beat_menu.setText(DateLocalUtils.getCurrentTime());
  283. heart_beat_menu.repaint();
  284. //若未连接则尝试连接
  285. if(nettyClient!=null&&!tcp_connect_flag){
  286. log.info("TCP已断开");
  287. //TCP重新同步连接
  288. if(!connect_request_flag) {
  289. //log.info("TCP重新同步连接");
  290. //设置TCP请求状态,只重新同步连接一次
  291. connect_request_flag = true;
  292. DataUtil.synrTcp(nettyClient);
  293. }
  294. }
  295. }
  296. }
  297. }, 100,mes_heart_icon_cycle*1000);
  298. }
  299. //设置tcp连接状态显示
  300. public static void setTcpStatus() {
  301. if(tcp_connect_flag) {
  302. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  303. heart_beat_menu.repaint();
  304. }else {
  305. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/grey_dot.png")));
  306. heart_beat_menu.repaint();
  307. }
  308. }
  309. public static void initWarehouseData(){
  310. loadProductTypeFromDb(); //新增
  311. resetScanA();
  312. }
  313. public static void resetScanA() {
  314. work_status = 0;
  315. check_quality_result = false;
  316. pendingNgTestParam = null;
  317. MesClient.finish_ok_bt.setEnabled(false);
  318. MesClient.finish_ng_bt.setEnabled(false);
  319. MesClient.finish_ng_bt.setVisible(false);
  320. product_sn.setText("");
  321. product_sn.setEditable(true);
  322. tjFlag = 0;
  323. mesStartFlag = 0;
  324. curTaskName.setText("");
  325. // f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
  326. // f_scan_data_bt_1.setText("扫码");
  327. // MesClient.f_scan_data_bt_1.setEnabled(true);
  328. MesClient.setMenuStatus("请扫工件码",0);
  329. updateMaterailData();
  330. if (MesClient.result != null) {
  331. MesClient.result.setText("");
  332. MesClient.result.setVisible(false);
  333. }
  334. }
  335. /**
  336. * 本地存库后提交MES,成功则复位扫码。
  337. * NG 且未填漏点(MES开启)时暂存并点亮 NG 按钮,不入库不上传。
  338. */
  339. public static boolean afterTestSaveAndUpload(TestParam testParam) {
  340. try {
  341. String testDate = testParam.getCreateTime();
  342. if (testDate == null || testDate.isEmpty()) {
  343. testDate = DateLocalUtils.getCurrentTime();
  344. testParam.setCreateTime(testDate);
  345. }
  346. if (testParam.getOprno() == null || testParam.getOprno().isEmpty()) {
  347. testParam.setOprno(getEffectiveOprno());
  348. }
  349. if (testParam.getLineSn() == null || testParam.getLineSn().isEmpty()) {
  350. testParam.setLineSn(getEffectiveLineSn());
  351. }
  352. boolean isNg = testParam.getResult() != null && testParam.getResult().equalsIgnoreCase("NG");
  353. boolean leakEmpty = testParam.getNgLeakPoints() == null || testParam.getNgLeakPoints().trim().isEmpty();
  354. if (mes_enable && isNg && leakEmpty) {
  355. pendingNgTestParam = testParam;
  356. MesClient.finish_ng_bt.setVisible(true);
  357. MesClient.finish_ng_bt.setEnabled(true);
  358. MesClient.setMenuStatus("气密 NG,请选择漏点点位", -1);
  359. if (SwingUtilities.isEventDispatchThread()) {
  360. submitPendingNgWithLeakPoints();
  361. } else {
  362. SwingUtilities.invokeLater(MesClient::submitPendingNgWithLeakPoints);
  363. }
  364. return false;
  365. }
  366. JdbcUtils.insertTestRecord(testParam);
  367. if (mes_enable) {
  368. JSONObject retObj = DataUtil.qmResultData(testParam);
  369. if (retObj != null && retObj.get("result") != null && retObj.get("result").toString().equalsIgnoreCase("true")) {
  370. pendingNgTestParam = null;
  371. MesClient.resetScanA();
  372. MesClient.setMenuStatus("测试结果上传成功,请扫下一件", 0);
  373. try { JdbcUtils.getTestData(); } catch (Exception ignore) {}
  374. if (MesClient.configParam.getPrintLabel().equals("是") && "OK".equals(testParam.getResult())) {
  375. PrintUtil.printLabel(testParam.getSn(),
  376. (testParam.getParam1() != null ? testParam.getParam1() : "") + (testParam.getParam2() != null ? testParam.getParam2() : ""),
  377. (testParam.getParam3() != null ? testParam.getParam3() : "") + (testParam.getParam4() != null ? testParam.getParam4() : ""),
  378. testDate);
  379. }
  380. return true;
  381. } else {
  382. MesClient.mesStartFlag = 0;
  383. MesClient.setMenuStatus("测试结果上传失败,请重试", -1);
  384. return false;
  385. }
  386. } else {
  387. pendingNgTestParam = null;
  388. MesClient.resetScanA();
  389. try { JdbcUtils.getTestData(); } catch (Exception ignore) {}
  390. if (MesClient.configParam.getPrintLabel().equals("是") && "OK".equals(testParam.getResult())) {
  391. PrintUtil.printLabel(testParam.getSn(),
  392. (testParam.getParam1() != null ? testParam.getParam1() : "") + (testParam.getParam2() != null ? testParam.getParam2() : ""),
  393. (testParam.getParam3() != null ? testParam.getParam3() : "") + (testParam.getParam4() != null ? testParam.getParam4() : ""),
  394. testDate);
  395. }
  396. return true;
  397. }
  398. } catch (Exception e) {
  399. log.error("保存上传测试结果失败", e);
  400. MesClient.setMenuStatus("测试结果保存失败,请重试", -1);
  401. return false;
  402. }
  403. }
  404. /** 工人点击 NG 后:打开漏点页并上传 */
  405. public static void submitPendingNgWithLeakPoints() {
  406. if (pendingNgTestParam == null) {
  407. MesClient.setMenuStatus("无待填写的气密NG数据", -1);
  408. return;
  409. }
  410. String ngLeakPoints = LeakNgPointDialog.showDialog(mesClientFrame);
  411. if (ngLeakPoints == null) {
  412. MesClient.finish_ng_bt.setVisible(true);
  413. MesClient.finish_ng_bt.setEnabled(true);
  414. MesClient.setMenuStatus("气密 NG,请选择漏点点位", -1);
  415. return;
  416. }
  417. pendingNgTestParam.setNgLeakPoints(ngLeakPoints);
  418. afterTestSaveAndUpload(pendingNgTestParam);
  419. }
  420. public static int userLoginHours;//用户登录所处小时
  421. public static JTextField param1;
  422. public static JTextField param2;
  423. public static JTextField param3;
  424. public static JTextField param4;
  425. public static JLabel result;
  426. public static JTextField programNo;
  427. public static JTextField serialPort;
  428. public static JTextField baudRate;
  429. public static JTextField printName;
  430. public static JTextField labelName;
  431. public static JTextField labelx;
  432. public static JTextField labely;
  433. public static JTextField labelLineSpace;
  434. public static JTextField labelFont;
  435. public static JTextField stationNo;
  436. public static JComboBox stopBit;
  437. public static JComboBox checkBit;
  438. public static JComboBox dataBits;
  439. public static JComboBox printLabel;
  440. public static JComboBox leakage;
  441. public static JComboBox startMode;
  442. public static JButton saveBtn;
  443. public static JTextField productSnLength;
  444. public static JTextField productSnPre;
  445. public static JComboBox device;
  446. public static JTextField ngTime;
  447. public static JTextField ngNumber;
  448. public static JTextField ngUpgradeTime;
  449. public static JTextField oprno;
  450. public static JTextField oprnoTitle;
  451. public static JTextField lineSn;
  452. public static JLabel taskName;
  453. public static JTextField taskMaxNumA;
  454. public static JTextField taskMaxFoutA;
  455. public static JTextField taskMinFoutA;
  456. public static JTextField taskMaxSoutA;
  457. public static JTextField taskMinSoutA;
  458. public static JTextField taskMaxNumB;
  459. public static JTextField taskMaxFoutB;
  460. public static JTextField taskMinFoutB;
  461. public static JTextField taskMaxSoutB;
  462. public static JTextField taskMinSoutB;
  463. public static JComboBox taskLeakage;
  464. public static JTextField barcodeSpec;
  465. public static JTextField barcodeSpecStart;
  466. public static JTextField barcodeLength;
  467. public static void formatConfigEdit(Boolean ret){
  468. programNo.setEnabled(ret);
  469. serialPort.setEnabled(ret);
  470. startMode.setEnabled(ret);
  471. baudRate.setEnabled(ret);
  472. printName.setEnabled(ret);
  473. labelName.setEnabled(ret);
  474. labelx.setEnabled(ret);
  475. labely.setEnabled(ret);
  476. labelLineSpace.setEnabled(ret);
  477. labelFont.setEnabled(ret);
  478. stationNo.setEnabled(ret);
  479. stopBit.setEnabled(ret);
  480. checkBit.setEnabled(ret);
  481. dataBits.setEnabled(ret);
  482. printLabel.setEnabled(ret);
  483. leakage.setEnabled(ret);
  484. productSnPre.setEnabled(ret);
  485. productSnLength.setEnabled(ret);
  486. device.setEnabled(ret);
  487. // ngTime.setEnabled(ret);
  488. // ngNumber.setEnabled(ret);
  489. // ngUpgradeTime.setEnabled(ret);
  490. oprno.setEnabled(ret);
  491. oprnoTitle.setEnabled(ret);
  492. lineSn.setEnabled(ret);
  493. }
  494. public static void formatConfigData(){
  495. MesClient.configParam = JdbcUtils.getConfig();
  496. log.info(configParam.toString());
  497. if(configParam.getProgramNo() == null||configParam.getProgramNo().isEmpty()){
  498. configParam.setProgramNo("1");
  499. }
  500. programNo.setText(configParam.getProgramNo());
  501. if(configParam.getStartMode() == null||configParam.getStartMode().isEmpty()){
  502. configParam.setStartMode("手动启动");
  503. }
  504. startMode.setSelectedItem(configParam.getStartMode());
  505. if(configParam.getSerialPort() == null||configParam.getSerialPort().isEmpty()){
  506. configParam.setSerialPort("COM1");
  507. }
  508. serialPort.setText(configParam.getSerialPort());
  509. if(configParam.getBaudRate() == null||configParam.getBaudRate().isEmpty()){
  510. configParam.setBaudRate("38400");
  511. }
  512. baudRate.setText(configParam.getBaudRate());
  513. if(configParam.getDataBits() == null||configParam.getDataBits().isEmpty()){
  514. configParam.setDataBits("8");
  515. }
  516. dataBits.setSelectedItem(configParam.getDataBits());
  517. if(configParam.getCheckBit() == null||configParam.getCheckBit().isEmpty()){
  518. configParam.setCheckBit("NONE");
  519. }
  520. checkBit.setSelectedItem(configParam.getCheckBit());
  521. if(configParam.getStopBit() == null||configParam.getStopBit().isEmpty()){
  522. configParam.setStopBit("1");
  523. }
  524. stopBit.setSelectedItem(configParam.getStopBit());
  525. if(configParam.getLeakage() == null||configParam.getLeakage().isEmpty()){
  526. configParam.setLeakage("压降");
  527. }
  528. leakage.setSelectedItem(configParam.getLeakage());
  529. if(configParam.getPrintLabel() == null||configParam.getPrintLabel().isEmpty()){
  530. configParam.setPrintLabel("否");
  531. }
  532. printLabel.setSelectedItem(configParam.getPrintLabel());
  533. if(configParam.getPrintName() == null||configParam.getPrintName().isEmpty()){
  534. configParam.setPrintName("");
  535. }
  536. printName.setText(configParam.getPrintName());
  537. if(configParam.getLabelName() == null||configParam.getLabelName().isEmpty()){
  538. configParam.setLabelName("");
  539. }
  540. labelName.setText(configParam.getLabelName());
  541. if(configParam.getLabelx() == null||configParam.getLabelx().isEmpty()){
  542. configParam.setLabelx("30");
  543. }
  544. labelx.setText(configParam.getLabelx());
  545. if(configParam.getLabely() == null||configParam.getLabely().isEmpty()){
  546. configParam.setLabely("30");
  547. }
  548. labely.setText(configParam.getLabely());
  549. if(configParam.getLabelLineSpace() == null||configParam.getLabelLineSpace().isEmpty()){
  550. configParam.setLabelLineSpace("20");
  551. }
  552. labelLineSpace.setText(configParam.getLabelLineSpace());
  553. if(configParam.getLabelFont() == null||configParam.getLabelFont().isEmpty()){
  554. configParam.setLabelFont("10");
  555. }
  556. labelFont.setText(configParam.getLabelFont());
  557. if(configParam.getStationNo() == null||configParam.getStationNo().isEmpty()){
  558. configParam.setStationNo("1");
  559. }
  560. stationNo.setText(configParam.getStationNo());
  561. if(configParam.getProductSnPre() == null||configParam.getProductSnPre().isEmpty()){
  562. configParam.setProductSnPre("");
  563. }
  564. productSnPre.setText(configParam.getProductSnPre());
  565. if(configParam.getProductSnLength() == null||configParam.getProductSnLength().isEmpty()){
  566. configParam.setProductSnLength("");
  567. }
  568. productSnLength.setText(configParam.getProductSnLength());
  569. if(configParam.getDevice() == null||configParam.getDevice().isEmpty()){
  570. configParam.setDevice("innomatec");
  571. }
  572. device.setSelectedItem(configParam.getDevice());
  573. // if(configParam.getNgTime() == null||configParam.getNgTime().isEmpty()){
  574. // configParam.setNgTime("");
  575. // }
  576. // ngTime.setText(configParam.getNgTime());
  577. //
  578. // if(configParam.getNgNumber() == null||configParam.getNgNumber().isEmpty()){
  579. // configParam.setNgNumber("");
  580. // }
  581. // ngNumber.setText(configParam.getNgNumber());
  582. //
  583. // if(configParam.getNgUpgradeTime() == null||configParam.getNgUpgradeTime().isEmpty()){
  584. // configParam.setNgUpgradeTime("");
  585. // }
  586. // ngUpgradeTime.setText(configParam.getNgUpgradeTime());
  587. if(configParam.getOprno() == null||configParam.getOprno().isEmpty()){
  588. configParam.setOprno(mes_gw != null ? mes_gw : "");
  589. }
  590. oprno.setText(configParam.getOprno());
  591. if(configParam.getOprnoTitle() == null||configParam.getOprnoTitle().isEmpty()){
  592. configParam.setOprnoTitle("");
  593. }
  594. oprnoTitle.setText(configParam.getOprnoTitle());
  595. if(configParam.getLineSn() == null||configParam.getLineSn().isEmpty()){
  596. configParam.setLineSn(mes_line_sn != null && !mes_line_sn.isEmpty() ? mes_line_sn : "XT");
  597. }
  598. lineSn.setText(configParam.getLineSn());
  599. if(!oprnoTitle.getText().isEmpty()){
  600. String stationInfo = oprno.getText() +"-"+ oprnoTitle.getText();
  601. welcomeWin.setTitle("气密检测客户端--"+stationInfo);
  602. mesClientFrame.setTitle("气密检测客户端--"+stationInfo);
  603. }
  604. syncStationFromConfig();
  605. }
  606. private static void syncStationFromConfig() {
  607. if (configParam == null) {
  608. return;
  609. }
  610. if (configParam.getOprno() != null) {
  611. mes_gw = configParam.getOprno();
  612. }
  613. if (configParam.getLineSn() != null && !configParam.getLineSn().isEmpty()) {
  614. mes_line_sn = configParam.getLineSn();
  615. }
  616. mes_gw_des = OprnoUtil.getGwDes(mes_line_sn, mes_gw);
  617. }
  618. public static String getEffectiveOprno() {
  619. if (configParam != null) {
  620. String oprno = configParam.getOprno();
  621. if (oprno != null && !oprno.trim().isEmpty()) {
  622. return oprno.trim();
  623. }
  624. }
  625. if (mes_gw != null && !mes_gw.trim().isEmpty()) {
  626. return mes_gw.trim();
  627. }
  628. return "";
  629. }
  630. public static String getEffectiveLineSn() {
  631. if (configParam != null) {
  632. String lineSn = configParam.getLineSn();
  633. if (lineSn != null && !lineSn.trim().isEmpty()) {
  634. return lineSn.trim();
  635. }
  636. }
  637. if (mes_line_sn != null && !mes_line_sn.trim().isEmpty()) {
  638. return mes_line_sn.trim();
  639. }
  640. return "XT";
  641. }
  642. //换班用户信息检查
  643. private static void shiftUserCheck() {
  644. LocalDateTime now = LocalDateTime.now();
  645. // 判断时间范围
  646. if (userLoginHours >= 8 && userLoginHours < 20) {
  647. int hour = now.getHour();
  648. if (hour >= 20 || hour < 8) {
  649. logoff();
  650. }
  651. } else {
  652. int hour = now.getHour();
  653. if (hour >= 8 && hour < 20) {
  654. logoff();
  655. }
  656. }
  657. }
  658. public static void resetScanB() {
  659. }
  660. //获取用户20位
  661. public static void getUser() {
  662. user20 = user_menu.getText().toString();
  663. String space_tmp1 = "";
  664. if(user20.length()<20) {
  665. for(int i=0;i<20-user20.length();i++) {
  666. space_tmp1 = space_tmp1 + " ";
  667. }
  668. }
  669. user20 = user20 + space_tmp1;
  670. }
  671. //获取barcode内容36位
  672. public static String getBarcode(String barcodeTmp) {
  673. String barcodeRet = barcodeTmp;
  674. if(barcodeTmp.equalsIgnoreCase("")) {
  675. return "";
  676. }else {
  677. if(barcodeTmp.length()<36) {
  678. String space = "";
  679. for(int i=0;i<36-barcodeTmp.length();i++) {
  680. space = space + " ";
  681. }
  682. barcodeRet = barcodeTmp + space;
  683. }
  684. }
  685. return barcodeRet;
  686. }
  687. public static void scanBarcode() {
  688. if (work_status == 1) {
  689. MesClient.serialPortUtils.start();
  690. return;
  691. }
  692. }
  693. public static void scanBarcode2() {
  694. if(work_status == 1){
  695. // MesClient.serialPortUtils.sendData("START");
  696. return;
  697. }
  698. String scanBarcode = product_sn.getText().trim();
  699. //刷新界面
  700. mesClientFrame.repaint();
  701. //生产类型新增
  702. String validateMsg = validateProductSnMessage(scanBarcode);
  703. if (validateMsg != null) {
  704. check_quality_result = false;
  705. work_status = 0;
  706. MesClient.finish_ok_bt.setEnabled(false);
  707. MesClient.finish_ng_bt.setEnabled(false);
  708. MesClient.f_scan_data_bt_1.setEnabled(true);
  709. updateProductTypePanelEnabled(true);
  710. MesClient.setMenuStatus(validateMsg, -1);
  711. return;
  712. }
  713. updateProductTypePanelEnabled(false);
  714. if(scanBarcode.isEmpty()){
  715. MesClient.setMenuStatus("工件码不能为空",1);
  716. product_sn.setText("");
  717. return;
  718. }
  719. // // 验证工件码前缀
  720. // if(MesClient.configParam.getProductSnPre() != null && !MesClient.configParam.getProductSnPre().trim().isEmpty()) {
  721. // int preLen = MesClient.configParam.getProductSnPre().trim().length();
  722. // if(preLen > scanBarcode.length()){
  723. // MesClient.setMenuStatus("工件码前缀不符合要求",-1);
  724. // product_sn.setText("");
  725. // return;
  726. // }else{
  727. // String pre = scanBarcode.substring(0,preLen);
  728. // if(!pre.equals(MesClient.configParam.getProductSnPre().trim())){
  729. // MesClient.setMenuStatus("工件码前缀不符合要求",-1);
  730. // product_sn.setText("");
  731. // return;
  732. // }
  733. // }
  734. // }
  735. //
  736. // //验证工件码长度
  737. // int snLen = MesClient.configParam.getProductSnLength() != null && MesClient.configParam.getProductSnLength().trim().isEmpty() ? 0 : Integer.valueOf(MesClient.configParam.getProductSnLength());
  738. // if(snLen > 0 && snLen != scanBarcode.length()) {
  739. // MesClient.setMenuStatus("工件码长度不符合要求",-1);
  740. // product_sn.setText("");
  741. // return;
  742. // }
  743. // // 验证NG
  744. // int isCheck = JdbcUtils.checkSnTimer(scanBarcode,configParam);
  745. // System.err.println("isCheck:" + isCheck);
  746. // if(isCheck == 1){
  747. // int ngTime = Integer.valueOf(configParam.getNgTime());
  748. // MesClient.setMenuStatus("工件码测试NG必须间隔"+ngTime+"分钟",-1);
  749. // product_sn.setText("");
  750. // return;
  751. // } else if(isCheck == 2){
  752. // int ngUpgradeTime = Integer.valueOf(configParam.getNgUpgradeTime());
  753. // int ngNumber = Integer.valueOf(configParam.getNgNumber());
  754. // MesClient.setMenuStatus("工件码测试NG"+ngNumber+"次,必须间隔"+ngUpgradeTime+"分钟",-1);
  755. // product_sn.setText("");
  756. // return;
  757. // }
  758. if(checkProductSn(scanBarcode.trim())){
  759. serialPortUtils.changeProgram(); // 切换程序
  760. if(MesClient.mes_enable){
  761. getUser();
  762. // 查询工件质量
  763. Boolean sendret = DataUtil.checkQuality(nettyClient,scanBarcode,user20);
  764. if(!sendret){
  765. MesClient.setMenuStatus("消息发送失败,请重试",-1);
  766. return;
  767. }
  768. }else{
  769. work_status = 1;
  770. MesClient.tjFlag = 1;
  771. MesClient.setMenuStatus("扫码成功,等待测试",0);
  772. product_sn.setEditable(false);
  773. if(MesClient.configParam.getStartMode().equals("自动启动")){
  774. MesClient.serialPortUtils.start();
  775. }
  776. MesClient.result.setVisible(true);
  777. MesClient.result.setText("等待结果");
  778. MesClient.result.setForeground(Color.GRAY);
  779. }
  780. }
  781. // f_scan_data_bt_1.setIcon(null);
  782. // f_scan_data_bt_1.setText("启动");
  783. }
  784. public static void scanBarcodeOld() {
  785. if(work_status == 1){
  786. // MesClient.serialPortUtils.sendData("START");
  787. return;
  788. }
  789. String scanBarcodeTitle = "";
  790. switch(scan_type) {
  791. case 1:
  792. product_sn.setText("");
  793. scanBarcodeTitle = "请扫工件码";
  794. break;
  795. }
  796. //弹窗扫工件码
  797. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  798. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  799. // 验证工件码前缀
  800. if(MesClient.configParam.getProductSnPre() != null && !MesClient.configParam.getProductSnPre().trim().isEmpty()) {
  801. int preLen = MesClient.configParam.getProductSnPre().trim().length();
  802. if(preLen > scanBarcode.length()){
  803. MesClient.setMenuStatus("工件码前缀不符合要求",-1);
  804. return;
  805. }else{
  806. String pre = scanBarcode.substring(0,preLen);
  807. if(!pre.equals(MesClient.configParam.getProductSnPre().trim())){
  808. MesClient.setMenuStatus("工件码前缀不符合要求",-1);
  809. return;
  810. }
  811. }
  812. }
  813. //验证工件码长度
  814. int snLen = MesClient.configParam.getProductSnLength() != null && MesClient.configParam.getProductSnLength().trim().isEmpty() ? 0 : Integer.valueOf(MesClient.configParam.getProductSnLength());
  815. if(snLen > 0 && snLen != scanBarcode.length()) {
  816. MesClient.setMenuStatus("工件码长度不符合要求",-1);
  817. return;
  818. }
  819. //获取用户
  820. getUser();
  821. //获取扫码内容36位
  822. String barcode36 = getBarcode(scanBarcode);//处理36为码
  823. //工位号
  824. String gw = "";
  825. switch(scan_type) {
  826. case 1:
  827. product_sn.setText(scanBarcode);
  828. break;
  829. }
  830. //刷新界面
  831. mesClientFrame.repaint();
  832. work_status = 1;
  833. // f_scan_data_bt_1.setEnabled(false);
  834. MesClient.tjFlag = 1;
  835. MesClient.setMenuStatus("扫码成功,等待测试",0);
  836. if(MesClient.configParam.getStartMode().equals("自动启动")){
  837. MesClient.serialPortUtils.start();
  838. }
  839. f_scan_data_bt_1.setIcon(null);
  840. f_scan_data_bt_1.setText("启动");
  841. }else {
  842. JOptionPane.showMessageDialog(mesClientFrame,"请扫工件码","提示窗口", JOptionPane.INFORMATION_MESSAGE);
  843. return;
  844. }
  845. }
  846. public static void logoff() {
  847. // welcomeWin.setVisible(true);
  848. mesClientFrame.setVisible(false);
  849. //退出程序 退出登录
  850. System.exit(0);
  851. nettyClient = null;
  852. // if(heartBeatTimer!=null) {
  853. // heartBeatTimer.cancel();
  854. // }
  855. // if(heartBeatIconTimer!=null) {
  856. // heartBeatIconTimer.cancel();
  857. // }
  858. tcp_connect_flag = false;
  859. connect_request_flag = false;
  860. }
  861. public MesClient() {
  862. setIconImage(Toolkit.getDefaultToolkit().getImage(MesClient.class.getResource("/bg/logo.png")));
  863. setTitle("气密检测客户端");
  864. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  865. setBounds(0, 0, 1024, 768);
  866. JMenuBar menuBar = new JMenuBar();
  867. menuBar.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
  868. setJMenuBar(menuBar);
  869. JMenu fileMenu = new JMenu("用户");
  870. fileMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/user.png")));
  871. fileMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  872. menuBar.add(fileMenu);
  873. JMenuItem exitMenuItem = new JMenuItem("退出");
  874. exitMenuItem.setIcon(new ImageIcon(MesClient.class.getResource("/bg/logoff.png")));
  875. exitMenuItem.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  876. fileMenu.add(exitMenuItem);
  877. exitMenuItem.addMouseListener(new MouseAdapter() {
  878. @Override
  879. public void mousePressed(MouseEvent e) {//只能检测到mousePressed事件
  880. super.mouseClicked(e);
  881. //dispose();
  882. logoff();
  883. }
  884. });
  885. JMenu settingMenu = new JMenu("设置");
  886. //settingMenu.setVisible(false);
  887. settingMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")));
  888. settingMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  889. menuBar.add(settingMenu);
  890. JMenuItem resetTcpMenu = new JMenuItem("重连MES");
  891. resetTcpMenu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  892. resetTcpMenu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  893. resetTcpMenu.addMouseListener(new MouseAdapter() {
  894. @Override
  895. public void mousePressed(MouseEvent e) {
  896. super.mouseClicked(e);
  897. //重连mes
  898. nettyClient.future.channel().close();
  899. }
  900. });
  901. // settingMenu.add(resetTcpMenu);
  902. JMenuItem resetTcpMenu_1 = new JMenuItem("刷新工件");
  903. resetTcpMenu_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/reset_logo.png")));
  904. resetTcpMenu_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  905. resetTcpMenu_1.addMouseListener(new MouseAdapter() {
  906. @Override
  907. public void mousePressed(MouseEvent e) {
  908. super.mouseClicked(e);
  909. resetScanA();
  910. }
  911. });
  912. settingMenu.add(resetTcpMenu_1);
  913. contentPane = new JPanel();
  914. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  915. setContentPane(contentPane);
  916. contentPane.setLayout(new BorderLayout(0, 0));
  917. JToolBar toolBar = new JToolBar();
  918. contentPane.add(toolBar, BorderLayout.NORTH);
  919. JLabel equipment_statu_label = new JLabel("状态:");
  920. equipment_statu_label.setHorizontalAlignment(SwingConstants.CENTER);
  921. equipment_statu_label.setForeground(Color.BLACK);
  922. equipment_statu_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  923. equipment_statu_label.setBackground(Color.LIGHT_GRAY);
  924. toolBar.add(equipment_statu_label);
  925. status_menu = new JButton("设备未连接MES服务器");
  926. if(tcp_connect_flag) {
  927. MesClient.setMenuStatus("已连接MES服务器",0);
  928. status_menu.setForeground(Color.GREEN);
  929. }else {
  930. MesClient.setMenuStatus("请扫工件码",-1);
  931. status_menu.setForeground(Color.DARK_GRAY);
  932. }
  933. status_menu.addActionListener(new ActionListener() {
  934. public void actionPerformed(ActionEvent e) {
  935. }
  936. });
  937. status_menu.setForeground(Color.GREEN);
  938. status_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  939. status_menu.setBackground(Color.BLACK);
  940. toolBar.add(status_menu);
  941. JLabel space_1 = new JLabel(" ");
  942. toolBar.add(space_1);
  943. JLabel heart_beat_status_label = new JLabel("心跳:");
  944. heart_beat_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  945. heart_beat_status_label.setForeground(Color.BLACK);
  946. heart_beat_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  947. heart_beat_status_label.setBackground(Color.LIGHT_GRAY);
  948. toolBar.add(heart_beat_status_label);
  949. heart_beat_menu = new JButton("");
  950. heart_beat_menu.setIcon(new ImageIcon(MesClient.class.getResource("/bg/green_dot.png")));
  951. heart_beat_menu.setForeground(Color.GREEN);
  952. heart_beat_menu.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  953. heart_beat_menu.setBackground(Color.BLACK);
  954. toolBar.add(heart_beat_menu);
  955. JLabel space_2 = new JLabel(" ");
  956. toolBar.add(space_2);
  957. JLabel user_status_label = new JLabel("登录用户:");
  958. user_status_label.setHorizontalAlignment(SwingConstants.CENTER);
  959. user_status_label.setForeground(Color.BLACK);
  960. user_status_label.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  961. user_status_label.setBackground(Color.LIGHT_GRAY);
  962. toolBar.add(user_status_label);
  963. user_menu = new JButton("");
  964. user_menu.setForeground(Color.GREEN);
  965. user_menu.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  966. user_menu.setBackground(Color.BLACK);
  967. toolBar.add(user_menu);
  968. JLabel space_3 = new JLabel(" ");
  969. toolBar.add(space_3);
  970. JLabel space_4 = new JLabel(" ");
  971. toolBar.add(space_4);
  972. tabbedPane = new JTabbedPane(JTabbedPane.TOP);
  973. tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
  974. tabbedPane.setMinimumSize(new Dimension(400, 50));
  975. tabbedPane.setFont(new Font("宋体", Font.BOLD, 22));
  976. contentPane.add(tabbedPane);
  977. //首页
  978. JPanel indexPanelA = new JPanel();
  979. indexScrollPaneA = new JScrollPane(indexPanelA);
  980. indexPanelA.setLayout(null);
  981. curTaskName = new JLabel("当前任务:");
  982. curTaskName.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  983. curTaskName.setHorizontalAlignment(SwingConstants.CENTER);
  984. curTaskName.setBounds(81, 10, 800, 40);
  985. indexPanelA.add(curTaskName);
  986. product_sn = new JTextField();
  987. product_sn.setHorizontalAlignment(SwingConstants.LEFT);
  988. product_sn.setEditable(true);
  989. product_sn.setFont(new Font("微软雅黑", Font.PLAIN, 28));
  990. product_sn.setBounds(81, 70, 602, 70);
  991. indexPanelA.add(product_sn);
  992. product_sn.setColumns(10);
  993. product_sn.addActionListener(new ActionListener() {
  994. public void actionPerformed(ActionEvent e) {
  995. scan_type = 1;
  996. scanBarcode2();
  997. }
  998. });
  999. // f_scan_data_bt_1 = new JButton("扫码");
  1000. f_scan_data_bt_1 = new JButton("启动");
  1001. f_scan_data_bt_1.addActionListener(new ActionListener() {
  1002. public void actionPerformed(ActionEvent e) {
  1003. scan_type = 1;
  1004. scanBarcode();
  1005. }
  1006. });
  1007. // f_scan_data_bt_1.setIcon(new ImageIcon(MesClient.class.getResource("/bg/scan_barcode.png")));
  1008. f_scan_data_bt_1.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  1009. f_scan_data_bt_1.setBounds(693, 70, 198, 70);
  1010. indexPanelA.add(f_scan_data_bt_1);
  1011. JLabel lblNewLabel = new JLabel("测试压");
  1012. lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1013. lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
  1014. lblNewLabel.setBounds(137, 210, 140, 40);
  1015. indexPanelA.add(lblNewLabel);
  1016. param1 = new JTextField();
  1017. param1.setEditable(false);
  1018. param1.setBounds(287, 210, 150, 40);
  1019. indexPanelA.add(param1);
  1020. param1.setColumns(10);
  1021. JLabel lblNewLabel_1 = new JLabel("泄露值");
  1022. lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1023. lblNewLabel_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1024. lblNewLabel_1.setBounds(447, 210, 140, 40);
  1025. indexPanelA.add(lblNewLabel_1);
  1026. param2 = new JTextField();
  1027. param2.setEditable(false);
  1028. param2.setColumns(10);
  1029. param2.setBounds(597, 210, 150, 40);
  1030. indexPanelA.add(param2);
  1031. JLabel lblNewLabel_2 = new JLabel("测电阻电压");
  1032. lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT);
  1033. lblNewLabel_2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1034. lblNewLabel_2.setBounds(137, 288, 140, 40);
  1035. // indexPanelA.add(lblNewLabel_2);
  1036. param3 = new JTextField();
  1037. param3.setEditable(false);
  1038. param3.setColumns(10);
  1039. param3.setBounds(287, 288, 150, 40);
  1040. // indexPanelA.add(param3);
  1041. JLabel lblNewLabel_1_1 = new JLabel("电阻");
  1042. lblNewLabel_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1043. lblNewLabel_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1044. lblNewLabel_1_1.setBounds(447, 288, 140, 40);
  1045. // indexPanelA.add(lblNewLabel_1_1);
  1046. param4 = new JTextField();
  1047. param4.setEditable(false);
  1048. param4.setColumns(10);
  1049. param4.setBounds(597, 288, 150, 40);
  1050. // indexPanelA.add(param4);
  1051. result = new JLabel("等待结果") {
  1052. @Override
  1053. protected void paintComponent(Graphics g) {
  1054. Graphics2D g2 = (Graphics2D) g.create();
  1055. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  1056. // 设置圆角背景和边框颜色
  1057. g2.setColor(new Color(255, 255, 255)); // 背景颜色
  1058. g2.fillRoundRect(0, 0, getWidth(), getHeight(), 20, 20); // 圆角矩形,圆角半径为20
  1059. g2.setColor(new Color(255, 255, 255)); // 边框颜色
  1060. g2.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, 20, 20); // 绘制边框
  1061. g2.dispose();
  1062. super.paintComponent(g);
  1063. }
  1064. };
  1065. // result.setForeground(Color.GREEN);
  1066. // result.setForeground(Color.RED);
  1067. result.setForeground(Color.GRAY);
  1068. result.setHorizontalAlignment(SwingConstants.CENTER);
  1069. result.setFont(new Font("微软雅黑", Font.BOLD, 50));
  1070. // result.setBounds(290, 392, 356, 89);
  1071. result.setBounds(290, 332, 356, 89);
  1072. result.setVisible(false);
  1073. indexPanelA.add(result);
  1074. finish_ok_bt = new JButton("OK");
  1075. finish_ok_bt.setEnabled(false);
  1076. finish_ok_bt.addActionListener(new ActionListener() {
  1077. public void actionPerformed(ActionEvent e) {
  1078. String sn = getBarcode(product_sn.getText());
  1079. if(sn.isEmpty()){
  1080. MesClient.setMenuStatus("工件码为空,请重试",-1);
  1081. return;
  1082. }
  1083. //生产类型新增
  1084. String validateMsg = validateProductSnMessage(sn);
  1085. if (validateMsg != null) {
  1086. MesClient.setMenuStatus(validateMsg, -1);
  1087. return;
  1088. }
  1089. }
  1090. });
  1091. finish_ok_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ok_bg.png")));
  1092. finish_ok_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  1093. finish_ok_bt.setBounds(185, 291, 240, 80);
  1094. finish_ok_bt.setEnabled(false);
  1095. // indexPanelA.add(finish_ok_bt);
  1096. finish_ng_bt = new JButton("NG");
  1097. finish_ng_bt.setEnabled(false);
  1098. finish_ng_bt.setVisible(false);
  1099. finish_ng_bt.addActionListener(new ActionListener() {
  1100. public void actionPerformed(ActionEvent e) {
  1101. submitPendingNgWithLeakPoints();
  1102. }
  1103. });
  1104. finish_ng_bt.setIcon(new ImageIcon(MesClient.class.getResource("/bg/ng_bg.png")));
  1105. finish_ng_bt.setFont(new Font("微软雅黑", Font.PLAIN, 32));
  1106. finish_ng_bt.setBounds(508, 291, 240, 80);
  1107. finish_ng_bt.setEnabled(false);
  1108. indexPanelA.add(finish_ng_bt);
  1109. tabbedPane.addTab("工作面板", new ImageIcon(MesClient.class.getResource("/bg/a_side.png")), indexScrollPaneA, null);
  1110. tabbedPane.setEnabledAt(0, true);
  1111. indexPanelC = new JPanel();
  1112. searchScrollPaneDj = new JScrollPane(indexPanelC);
  1113. // indexPanelC.setLayout(new GridLayout(0, 1, 0, 0));
  1114. indexPanelC.setLayout(null);
  1115. JPanel panel2 = new JPanel();
  1116. panel2.setBounds(0, 0, 990, 50);
  1117. // panel2.setLayout(new GridLayout(0, 1, 0, 0));
  1118. panel2.setLayout(null);
  1119. //记录查询搜索框
  1120. textField = new JTextField();
  1121. textField.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1122. // textField.setEnabled(false);
  1123. textField.setForeground(Color.BLACK);
  1124. textField.setBounds(10, 5, 371, 40);
  1125. panel2.add(textField);
  1126. // textField.setColumns(20);
  1127. indexPanelC.add(panel2);
  1128. JButton btnNewButton = new JButton("搜索");
  1129. btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1130. btnNewButton.setBounds(385, 5, 90, 40);
  1131. panel2.add(btnNewButton);
  1132. // 上一页按钮添加按钮事件监听
  1133. btnNewButton.addActionListener(e -> {
  1134. JdbcUtils.getTestData();
  1135. });
  1136. JButton resetBtn = new JButton("重置");
  1137. resetBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1138. resetBtn.setBounds(475, 5, 90, 40);
  1139. panel2.add(resetBtn);
  1140. // 上一页按钮添加按钮事件监听
  1141. resetBtn.addActionListener(e -> {
  1142. textField.setText("");
  1143. JdbcUtils.getTestData();
  1144. });
  1145. JButton resetBtn2 = new JButton("导出");
  1146. resetBtn2.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1147. resetBtn2.setBounds(565, 5, 90, 40);
  1148. panel2.add(resetBtn2);
  1149. // 上一页按钮添加按钮事件监听
  1150. resetBtn2.addActionListener(e -> {
  1151. List<QmData> lists = JdbcUtils.getTestDataAll();
  1152. Boolean ret = ExportUtil.export(lists);
  1153. if(ret){
  1154. MesClient.setMenuStatus("导出成功,请在D盘中查看",0);
  1155. }else{
  1156. MesClient.setMenuStatus("导出失败,请重试",-1);
  1157. }
  1158. });
  1159. JButton btnPrevious = new JButton("上一页");
  1160. btnPrevious.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  1161. btnPrevious.setBounds(680, 5, 100, 40);
  1162. panel2.add(btnPrevious);
  1163. // 页码显示
  1164. pageLabel = new JLabel("0/0"); // 初始页码和总页数
  1165. pageLabel.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  1166. pageLabel.setHorizontalAlignment(SwingConstants.CENTER); // 设置文本居中对齐
  1167. pageLabel.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1)); // 添加灰色边框
  1168. pageLabel.setBounds(780, 5, 100, 40); // 设置位置和大小
  1169. panel2.add(pageLabel);
  1170. // “下一页”按钮
  1171. JButton btnNext = new JButton("下一页");
  1172. btnNext.setFont(new Font("微软雅黑", Font.PLAIN, 18));
  1173. btnNext.setBounds(880, 5, 100, 40);
  1174. panel2.add(btnNext);
  1175. // 分页逻辑变量
  1176. // 上一页按钮添加按钮事件监听
  1177. btnPrevious.addActionListener(e -> {
  1178. if (pageNo > 1) {
  1179. pageNo--;
  1180. JdbcUtils.getTestData();
  1181. }
  1182. });
  1183. btnNext.addActionListener(e -> {
  1184. if (pageNo < totalPages) {
  1185. pageNo++;
  1186. JdbcUtils.getTestData();
  1187. }
  1188. });
  1189. JPanel panel = new JPanel();
  1190. panel.setBounds(0, 49, 990, 518);
  1191. panel.setLayout(new GridLayout(0, 1, 0, 0));
  1192. indexPanelC.add(panel);
  1193. System.err.println(JSONObject.toJSONString(rowData));
  1194. System.err.println(columnNames.length);
  1195. table = new JTable(rowData, columnNames) {
  1196. public boolean isCellEditable(int row, int column) {
  1197. return false;
  1198. }
  1199. };
  1200. // 添加 MouseListener 获取点击事件
  1201. table.addMouseListener(new MouseAdapter() {
  1202. @Override
  1203. public void mouseClicked(MouseEvent e) {
  1204. if(e.getClickCount() == 1) {
  1205. int row = table.rowAtPoint(e.getPoint()); // 获取点击的行号
  1206. int col = table.columnAtPoint(e.getPoint()); // 获取点击的列号
  1207. if (row >= 0 && col >= 0) { // 确保点击在数据区域内
  1208. Object value = table.getValueAt(row, col); // 获取点击单元格的数据
  1209. System.out.println("Clicked cell value: " + value);
  1210. // 获取整行的数据
  1211. Object[] rowData = new Object[table.getColumnCount()];
  1212. for (int i = 0; i < table.getColumnCount(); i++) {
  1213. rowData[i] = table.getValueAt(row, i);
  1214. }
  1215. log.info("Row data: " + java.util.Arrays.toString(rowData));
  1216. log.info("O:"+String.valueOf(rowData[0]));
  1217. if(String.valueOf(rowData[0]) != null && !String.valueOf(rowData[0]).equals("null") && !String.valueOf(rowData[0]).isEmpty()){
  1218. // 显示一个简单的确认框
  1219. int result = JOptionPane.showConfirmDialog(null, "确定要打印标签吗?", "确认",
  1220. JOptionPane.YES_NO_OPTION,
  1221. JOptionPane.QUESTION_MESSAGE);
  1222. if (result == JOptionPane.YES_OPTION) {
  1223. System.out.println("用户点击了“是”");
  1224. PrintUtil.printLabel(String.valueOf(rowData[0]),String.valueOf(rowData[2]),String.valueOf(rowData[3]),String.valueOf(rowData[1]));
  1225. } else if (result == JOptionPane.NO_OPTION) {
  1226. System.out.println("用户点击了“否”");
  1227. } else if (result == JOptionPane.CLOSED_OPTION) {
  1228. System.out.println("对话框被关闭");
  1229. }
  1230. // TestParam testParam = JdbcUtils.getTestData(2);
  1231. // System.out.println(testParam.toString());
  1232. // JSONObject retObj = DataUtil.qmResultData(testParam);
  1233. // System.out.println(retObj.toString());
  1234. }
  1235. }
  1236. }
  1237. }
  1238. });
  1239. // 设置table的宽度为100%
  1240. table.setRowHeight(40);
  1241. table.setEnabled(true);
  1242. table.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  1243. // table.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
  1244. // table.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
  1245. // 设置第二列的长度为100像素
  1246. TableColumn column = table.getColumnModel().getColumn(0);
  1247. column.setPreferredWidth(290);
  1248. column = table.getColumnModel().getColumn(1);
  1249. column.setPreferredWidth(160);
  1250. CenterRenderer centerRenderer = new CenterRenderer();
  1251. for (int i = 0; i < table.getColumnCount(); i++) {
  1252. table.getColumn(table.getColumnName(i)).setCellRenderer(centerRenderer);
  1253. }
  1254. // column = table.getColumnModel().getColumn(6);
  1255. // column.setPreferredWidth(100);
  1256. // column = table.getColumnModel().getColumn(7);
  1257. // column.setPreferredWidth(100);
  1258. JScrollPane scrollPane = new JScrollPane(table);
  1259. panel.add(scrollPane);
  1260. tabbedPane.addTab("记录查询", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneDj, null);
  1261. indexPanelB = new JPanel();
  1262. searchScrollPane = new JScrollPane(indexPanelB);
  1263. indexPanelB.setLayout(null);
  1264. //新增的面板
  1265. JPanel indexPanelProductType = new JPanel();
  1266. indexPanelProductType.setLayout(null);
  1267. JScrollPane productTypeScrollPane = new JScrollPane(indexPanelProductType);
  1268. JLabel productTypeTitle = new JLabel("生产类型设置");
  1269. productTypeTitle.setFont(new Font("微软雅黑", Font.BOLD, 28));
  1270. productTypeTitle.setForeground(new Color(64, 64, 64));
  1271. productTypeTitle.setHorizontalAlignment(SwingConstants.CENTER);
  1272. productTypeTitle.setBounds(81, 80, 810, 50);
  1273. indexPanelProductType.add(productTypeTitle);
  1274. JLabel productTypeHint = new JLabel("请选择当前生产的工件类型,切换后将保存到本地并用于扫码校验");
  1275. productTypeHint.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1276. productTypeHint.setForeground(new Color(140, 140, 140));
  1277. productTypeHint.setHorizontalAlignment(SwingConstants.CENTER);
  1278. productTypeHint.setBounds(81, 140, 810, 40);
  1279. indexPanelProductType.add(productTypeHint);
  1280. productTypePanel = new ProductTypePanel(PRODUCT_TYPE_SWITCH_PASSWORD);
  1281. productTypePanel.setBounds(276, 210, 420, 72);
  1282. productTypePanel.setOnChangeListener(() -> {
  1283. if (work_status == 0) {
  1284. saveProductTypeToDb();
  1285. setMenuStatus("当前生产类型:" + getProductTypeName() + ",请扫工件码", 0);
  1286. }
  1287. refreshProductTypeCurrentLabel();
  1288. });
  1289. indexPanelProductType.add(productTypePanel);
  1290. productTypeCurrentLabel = new JLabel();
  1291. productTypeCurrentLabel.setFont(new Font("微软雅黑", Font.PLAIN, 22));
  1292. productTypeCurrentLabel.setForeground(new Color(64, 64, 64));
  1293. productTypeCurrentLabel.setHorizontalAlignment(SwingConstants.CENTER);
  1294. productTypeCurrentLabel.setBounds(81, 310, 810, 40);
  1295. refreshProductTypeCurrentLabel();
  1296. indexPanelProductType.add(productTypeCurrentLabel);
  1297. tabbedPane.addTab("生产类型", new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")), productTypeScrollPane, null);
  1298. tabbedPane.addTab("开班点检", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPane, null);
  1299. indexPanelD = new JPanel();
  1300. searchScrollPaneD = new JScrollPane(indexPanelD);
  1301. indexPanelD.setLayout(null);
  1302. PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
  1303. String[] printerNames = (printServices != null && printServices.length > 0) ?
  1304. new String[printServices.length] : new String[]{"未知"};
  1305. for (int i = 0; i < printerNames.length; i++) {
  1306. printerNames[i] = printServices[i].getName();
  1307. }
  1308. JLabel lblNewLabel_3 = new JLabel("设备程序号");
  1309. lblNewLabel_3.setHorizontalAlignment(SwingConstants.RIGHT);
  1310. lblNewLabel_3.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1311. lblNewLabel_3.setBounds(10, 22, 120, 30);
  1312. // indexPanelD.add(lblNewLabel_3);
  1313. programNo = new JTextField();
  1314. programNo.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1315. programNo.setBounds(140, 22, 200, 30);
  1316. // indexPanelD.add(programNo);
  1317. programNo.setColumns(10);
  1318. JLabel lblNewLabel_3_1 = new JLabel("设备启动方式");
  1319. lblNewLabel_3_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1320. lblNewLabel_3_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1321. lblNewLabel_3_1.setBounds(10, 71, 120, 30);
  1322. indexPanelD.add(lblNewLabel_3_1);
  1323. startMode = new JComboBox();
  1324. startMode.setModel(new DefaultComboBoxModel(new String[] {"手动启动", "自动启动"}));
  1325. startMode.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1326. startMode.setBounds(140, 71, 200, 30);
  1327. indexPanelD.add(startMode);
  1328. JLabel lblNewLabel_3_1_1 = new JLabel("串口号");
  1329. lblNewLabel_3_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1330. lblNewLabel_3_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1331. lblNewLabel_3_1_1.setBounds(10, 123, 120, 30);
  1332. indexPanelD.add(lblNewLabel_3_1_1);
  1333. serialPort = new JTextField();
  1334. serialPort.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1335. serialPort.setColumns(10);
  1336. serialPort.setBounds(140, 123, 200, 30);
  1337. indexPanelD.add(serialPort);
  1338. JLabel lblNewLabel_3_1_1_1 = new JLabel("波特率");
  1339. lblNewLabel_3_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1340. lblNewLabel_3_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1341. lblNewLabel_3_1_1_1.setBounds(10, 176, 120, 30);
  1342. indexPanelD.add(lblNewLabel_3_1_1_1);
  1343. baudRate = new JTextField();
  1344. baudRate.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1345. baudRate.setColumns(10);
  1346. baudRate.setBounds(140, 176, 200, 30);
  1347. indexPanelD.add(baudRate);
  1348. JLabel lblNewLabel_3_1_1_1_1 = new JLabel("数据位");
  1349. lblNewLabel_3_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1350. lblNewLabel_3_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1351. lblNewLabel_3_1_1_1_1.setBounds(10, 229, 120, 30);
  1352. indexPanelD.add(lblNewLabel_3_1_1_1_1);
  1353. dataBits = new JComboBox();
  1354. dataBits.setModel(new DefaultComboBoxModel(new String[] {"5", "6", "7", "8"}));
  1355. dataBits.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1356. dataBits.setBounds(140, 229, 200, 30);
  1357. indexPanelD.add(dataBits);
  1358. JLabel lblNewLabel_3_1_1_1_1_1 = new JLabel("校验位");
  1359. lblNewLabel_3_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1360. lblNewLabel_3_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1361. lblNewLabel_3_1_1_1_1_1.setBounds(10, 282, 120, 30);
  1362. indexPanelD.add(lblNewLabel_3_1_1_1_1_1);
  1363. checkBit = new JComboBox();
  1364. checkBit.setModel(new DefaultComboBoxModel(new String[] {"NONE", "ODD", "EVEN", "MARK", "SPACE"}));
  1365. checkBit.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1366. checkBit.setBounds(140, 282, 200, 30);
  1367. indexPanelD.add(checkBit);
  1368. JLabel lblNewLabel_3_1_1_1_1_1_1 = new JLabel("停止位");
  1369. lblNewLabel_3_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1370. lblNewLabel_3_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1371. lblNewLabel_3_1_1_1_1_1_1.setBounds(10, 335, 120, 30);
  1372. indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1);
  1373. stopBit = new JComboBox();
  1374. stopBit.setModel(new DefaultComboBoxModel(new String[] {"1", "1.5", "2"}));
  1375. stopBit.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1376. stopBit.setBounds(140, 335, 200, 30);
  1377. indexPanelD.add(stopBit);
  1378. JLabel lblNewLabel_3_1_1_1_1_1_1_1 = new JLabel("是否打印标签");
  1379. lblNewLabel_3_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1380. lblNewLabel_3_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1381. lblNewLabel_3_1_1_1_1_1_1_1.setBounds(408, 22, 120, 30);
  1382. indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1);
  1383. printLabel = new JComboBox();
  1384. printLabel.setModel(new DefaultComboBoxModel(new String[] {"是", "否"}));
  1385. printLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1386. printLabel.setBounds(536, 22, 200, 30);
  1387. indexPanelD.add(printLabel);
  1388. JLabel lblNewLabel_3_1_1_1_1_1_1_1_1 = new JLabel("打印机名称");
  1389. lblNewLabel_3_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1390. lblNewLabel_3_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1391. lblNewLabel_3_1_1_1_1_1_1_1_1.setBounds(408, 71, 120, 30);
  1392. indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1);
  1393. printName = new JTextField();
  1394. printName.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1395. printName.setColumns(10);
  1396. printName.setBounds(536, 71, 200, 30);
  1397. indexPanelD.add(printName);
  1398. JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1 = new JLabel("标签名称");
  1399. lblNewLabel_3_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1400. lblNewLabel_3_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1401. lblNewLabel_3_1_1_1_1_1_1_1_1_1.setBounds(408, 123, 120, 30);
  1402. // indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1);
  1403. labelName = new JTextField();
  1404. labelName.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1405. labelName.setColumns(10);
  1406. labelName.setBounds(536, 123, 200, 30);
  1407. // indexPanelD.add(labelName);
  1408. JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1 = new JLabel("标签偏移X");
  1409. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1410. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1411. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1.setBounds(408, 176, 120, 30);
  1412. indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1);
  1413. labelx = new JTextField();
  1414. labelx.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1415. labelx.setColumns(10);
  1416. labelx.setBounds(536, 176, 200, 30);
  1417. indexPanelD.add(labelx);
  1418. JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1 = new JLabel("标签偏移Y");
  1419. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1420. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1421. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1.setBounds(408, 229, 120, 30);
  1422. indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1);
  1423. labely = new JTextField();
  1424. labely.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1425. labely.setColumns(10);
  1426. labely.setBounds(536, 229, 200, 30);
  1427. indexPanelD.add(labely);
  1428. JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1 = new JLabel("标签行间距");
  1429. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1430. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1431. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1.setBounds(408, 282, 120, 30);
  1432. indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1);
  1433. labelLineSpace = new JTextField();
  1434. labelLineSpace.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1435. labelLineSpace.setColumns(10);
  1436. labelLineSpace.setBounds(536, 282, 200, 30);
  1437. indexPanelD.add(labelLineSpace);
  1438. JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1 = new JLabel("标签字号");
  1439. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1440. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1441. // lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1.setBounds(408, 335, 120, 30);
  1442. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1.setBounds(408, 123, 120, 30);
  1443. indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1);
  1444. labelFont = new JTextField();
  1445. labelFont.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1446. labelFont.setColumns(10);
  1447. // labelFont.setBounds(536, 335, 200, 30);
  1448. labelFont.setBounds(536, 123, 200, 30);
  1449. indexPanelD.add(labelFont);
  1450. JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_2 = new JLabel("MODBUS站号");
  1451. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
  1452. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1453. // lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_2.setBounds(408, 282, 120, 30);
  1454. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_2.setBounds(408, 335, 120, 30);
  1455. indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_2);
  1456. stationNo = new JTextField();
  1457. stationNo.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1458. stationNo.setColumns(10);
  1459. stationNo.setBounds(536, 335, 200, 30);
  1460. indexPanelD.add(stationNo);
  1461. saveBtn = new JButton("编辑配置");
  1462. saveBtn.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1463. saveBtn.setBounds(787, 267, 156, 57);
  1464. indexPanelD.add(saveBtn);
  1465. saveBtn.addActionListener(new ActionListener() {
  1466. public void actionPerformed(ActionEvent e) {
  1467. if(isConfigEdit == 0){
  1468. String pass = "503833";
  1469. //弹窗扫工件码
  1470. String scanBarcode = JOptionPane.showInputDialog(null, "请输入密码");
  1471. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")&&scanBarcode.equals(pass)) {
  1472. isConfigEdit = 1;
  1473. formatConfigEdit(true);
  1474. saveBtn.setText("保存配置");
  1475. }else{
  1476. MesClient.setMenuStatus("密码错误",-1);
  1477. }
  1478. }else{
  1479. formatConfigEdit(false);
  1480. saveBtn.setText("编辑配置");
  1481. configParam.setProgramNo(programNo.getText());
  1482. configParam.setSerialPort(serialPort.getText());
  1483. configParam.setBaudRate(baudRate.getText());
  1484. configParam.setPrintName(printName.getText());
  1485. configParam.setLabelName(labelName.getText());
  1486. configParam.setLabelx(labelx.getText());
  1487. configParam.setLabely(labely.getText());
  1488. configParam.setLabelLineSpace(labelLineSpace.getText());
  1489. configParam.setLabelFont(labelFont.getText());
  1490. configParam.setStationNo(stationNo.getText());
  1491. configParam.setStopBit(stopBit.getSelectedItem().toString());
  1492. configParam.setCheckBit(checkBit.getSelectedItem().toString());
  1493. configParam.setStopBit(stopBit.getSelectedItem().toString());
  1494. configParam.setDataBits(dataBits.getSelectedItem().toString());
  1495. configParam.setPrintLabel(printLabel.getSelectedItem().toString());
  1496. configParam.setStartMode(startMode.getSelectedItem().toString());
  1497. configParam.setProductSnPre(productSnPre.getText().trim());
  1498. configParam.setProductSnLength(productSnLength.getText().trim());
  1499. configParam.setLeakage(leakage.getSelectedItem().toString());
  1500. configParam.setDevice(device.getSelectedItem().toString());
  1501. //9.1修改
  1502. // configParam.setNgTime(ngTime.getText());
  1503. // configParam.setNgNumber(ngNumber.getText());
  1504. // configParam.setNgUpgradeTime(ngUpgradeTime.getText());
  1505. configParam.setOprno(oprno.getText().trim());
  1506. configParam.setOprnoTitle(oprnoTitle.getText().trim());
  1507. configParam.setLineSn(lineSn.getText().trim());
  1508. System.out.println("configParam:"+JSONObject.toJSONString(configParam));
  1509. if(configParam.getId() != null && configParam.getId() > 0){
  1510. JdbcUtils.updateConfig(configParam.getId(),JSONObject.toJSONString(configParam));
  1511. }else{
  1512. JdbcUtils.insertConfig(JSONObject.toJSONString(configParam));
  1513. }
  1514. isConfigEdit = 0;
  1515. // MesClient.indexPanelB.removeAll();
  1516. // System.out.println("indexPanelB:"+MesClient.indexPanelB.getComponentCount());
  1517. // MesClient.jfxPanel2 = null;
  1518. // if(MesClient.jfxPanel2 == null){
  1519. // String url = "http://"+ MesClient.mes_server_ip+":8980/js/a/mes/mesProcessCheckRecord/ulist?ucode="+MesClient.user_menu.getText()+"&oprno="+MesClient.configParam.getOprno()+"&lineSn="+MesClient.mes_line_sn;
  1520. // MesClient.jfxPanel2 = new MesWebView(url);
  1521. // MesClient.jfxPanel2.setSize(990, 550);
  1522. // MesClient.indexPanelB.add(MesClient.jfxPanel2);
  1523. // System.out.println("indexPanelBB:"+MesClient.indexPanelB.getComponentCount());
  1524. // MesClient.indexPanelB.revalidate(); // 重新验证布局(如果需要)
  1525. // MesClient.indexPanelB.repaint();
  1526. // System.out.println("indexPanelCC:"+MesClient.indexPanelB.getComponentCount());
  1527. // }
  1528. formatConfigData();
  1529. serialPortUtils.closePort();
  1530. serialPortUtils = new SerialPortUtils(configParam.getSerialPort(),getEffectiveOprno(),configParam.getOprnoTitle(),configParam.getDevice());
  1531. }
  1532. }
  1533. });
  1534. JLabel lblNewLabel_3_1_1_1_1_1_1_2 = new JLabel("泄露值取值");
  1535. lblNewLabel_3_1_1_1_1_1_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
  1536. lblNewLabel_3_1_1_1_1_1_1_2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1537. // lblNewLabel_3_1_1_1_1_1_1_2.setBounds(10, 445, 120, 30);
  1538. // lblNewLabel_3_1_1_1_1_1_1_2.setBounds(408, 390, 120, 30);
  1539. lblNewLabel_3_1_1_1_1_1_1_2.setBounds(10, 390, 120, 30);
  1540. indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_2);
  1541. leakage = new JComboBox();
  1542. leakage.setModel(new DefaultComboBoxModel(new String[] {"压降", "泄漏率"}));
  1543. leakage.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1544. // leakage.setBounds(140, 445, 200, 30);
  1545. // leakage.setBounds(536, 390, 200, 30);
  1546. leakage.setBounds(140, 390, 200, 30);
  1547. indexPanelD.add(leakage);
  1548. JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1 = new JLabel("工件码长度");
  1549. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1550. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1551. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1.setBounds(408, 390, 120, 30);
  1552. // indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1);
  1553. productSnLength = new JTextField();
  1554. productSnLength.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1555. productSnLength.setColumns(10);
  1556. productSnLength.setBounds(536, 390, 200, 30);
  1557. // indexPanelD.add(productSnLength);
  1558. JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1 = new JLabel("工件码前缀");
  1559. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
  1560. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1561. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1.setBounds(10, 390, 120, 30);
  1562. // indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_1);
  1563. productSnPre = new JTextField();
  1564. productSnPre.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1565. productSnPre.setColumns(10);
  1566. productSnPre.setBounds(140, 390, 200, 30);
  1567. // indexPanelD.add(productSnPre);
  1568. JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2 = new JLabel("检测设备");
  1569. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2.setHorizontalAlignment(SwingConstants.RIGHT);
  1570. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1571. // lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2.setBounds(408, 445, 120, 30);
  1572. // lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2.setBounds(10, 390, 120, 30);
  1573. lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2.setBounds(10, 22, 120, 30);
  1574. indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_1_1_1_1_1_1_2);
  1575. device = new JComboBox();
  1576. device.setModel(new DefaultComboBoxModel(new String[] {"innomatec", "ateq"}));
  1577. device.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1578. // device.setBounds(536, 445, 200, 30);
  1579. // device.setBounds(140, 390, 200, 30);
  1580. device.setBounds(140, 22, 200, 30);
  1581. indexPanelD.add(device);
  1582. JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_2 = new JLabel("工位号");
  1583. lblNewLabel_3_1_1_1_1_1_1_1_1_2.setHorizontalAlignment(SwingConstants.CENTER);
  1584. lblNewLabel_3_1_1_1_1_1_1_1_1_2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1585. lblNewLabel_3_1_1_1_1_1_1_1_1_2.setBounds(762, 22, 200, 30);
  1586. indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_2);
  1587. // ngTime = new JTextField();
  1588. // ngTime.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1589. // ngTime.setColumns(10);
  1590. // ngTime.setBounds(762, 54, 200, 30);
  1591. // indexPanelD.add(ngTime);
  1592. oprno = new JTextField();
  1593. oprno.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1594. oprno.setColumns(10);
  1595. oprno.setBounds(762, 54, 200, 30);
  1596. indexPanelD.add(oprno);
  1597. JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_2_1 = new JLabel("工位名称");
  1598. lblNewLabel_3_1_1_1_1_1_1_1_1_2_1.setHorizontalAlignment(SwingConstants.CENTER);
  1599. lblNewLabel_3_1_1_1_1_1_1_1_1_2_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1600. lblNewLabel_3_1_1_1_1_1_1_1_1_2_1.setBounds(762, 94, 200, 30);
  1601. indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_2_1);
  1602. // ngNumber = new JTextField();
  1603. // ngNumber.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1604. // ngNumber.setColumns(10);
  1605. // ngNumber.setBounds(762, 123, 200, 30);
  1606. // indexPanelD.add(ngNumber);
  1607. oprnoTitle = new JTextField();
  1608. oprnoTitle.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1609. oprnoTitle.setColumns(10);
  1610. oprnoTitle.setBounds(762, 123, 200, 30);
  1611. indexPanelD.add(oprnoTitle);
  1612. JLabel lblNewLabel_3_1_1_1_1_1_1_1_1_2_1_1 = new JLabel("产线编号");
  1613. lblNewLabel_3_1_1_1_1_1_1_1_1_2_1_1.setHorizontalAlignment(SwingConstants.CENTER);
  1614. lblNewLabel_3_1_1_1_1_1_1_1_1_2_1_1.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1615. lblNewLabel_3_1_1_1_1_1_1_1_1_2_1_1.setBounds(762, 163, 200, 30);
  1616. indexPanelD.add(lblNewLabel_3_1_1_1_1_1_1_1_1_2_1_1);
  1617. //
  1618. // ngUpgradeTime = new JTextField();
  1619. // ngUpgradeTime.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1620. // ngUpgradeTime.setColumns(10);
  1621. // ngUpgradeTime.setBounds(762, 195, 200, 30);
  1622. // indexPanelD.add(ngUpgradeTime);
  1623. lineSn = new JTextField();
  1624. lineSn.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1625. lineSn.setColumns(10);
  1626. lineSn.setBounds(762, 195, 200, 30);
  1627. indexPanelD.add(lineSn);
  1628. tabbedPane.addTab("软件设置", new ImageIcon(MesClient.class.getResource("/bg/menu_setting.png")), searchScrollPaneD, null);
  1629. JPanel indexPanelTask = new JPanel();
  1630. searchScrollPaneTask = new JScrollPane(indexPanelTask);
  1631. indexPanelTask.setLayout(null);
  1632. JPanel panel22 = new JPanel();
  1633. panel22.setBounds(0, 0, 300, 530);
  1634. indexPanelTask.add(panel22);
  1635. panel22.setLayout(new GridLayout(0, 1, 0, 0));
  1636. table2 = new JTable(rowData2, columnNames2){
  1637. public boolean isCellEditable(int row, int column) {
  1638. return false;
  1639. }
  1640. };
  1641. table2.setRowHeight(40);
  1642. table2.setEnabled(true);
  1643. table2.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  1644. // 添加鼠标点击事件
  1645. table2.addMouseListener(new MouseAdapter() {
  1646. @Override
  1647. public void mouseClicked(MouseEvent e) {
  1648. // 获取点击位置的行和列索引
  1649. int row = table2.rowAtPoint(e.getPoint());
  1650. int col = table2.columnAtPoint(e.getPoint());
  1651. // 检查点击是否有效(即是否真的在表格内)
  1652. if (row >= 0 && col >= 0) {
  1653. // 获取点击的单元格的值
  1654. Object value = table2.getValueAt(row, col);
  1655. String val = String.valueOf(value);
  1656. System.out.println("Clicked on row " + row + ", column " + col + ": " + value);
  1657. // 在这里添加你的逻辑代码
  1658. for(TaskParam taskParam:taskParamList){
  1659. if(val.equals(taskParam.getTitle())){
  1660. MesClient.curTaskParam = taskParam;
  1661. formatTaskParam();
  1662. break;
  1663. }
  1664. }
  1665. }
  1666. }
  1667. });
  1668. // 自定义渲染器
  1669. DefaultTableCellRenderer centerRenderer2 = new DefaultTableCellRenderer();
  1670. centerRenderer2.setHorizontalAlignment(JLabel.CENTER); // 设置内容居中
  1671. table2.setDefaultRenderer(Object.class, centerRenderer2); // 应用到所有列
  1672. JScrollPane scrollPane2 = new JScrollPane(table2);
  1673. panel22.add(scrollPane2);
  1674. JButton addTask = new JButton("新增任务");
  1675. addTask.addActionListener(new ActionListener() {
  1676. public void actionPerformed(ActionEvent e) {
  1677. String taskContent = JOptionPane.showInputDialog(null, "请输入任务名称").trim();
  1678. if(taskContent!=null&&!taskContent.equalsIgnoreCase("")) {
  1679. String passContent = JOptionPane.showInputDialog(null, "请输入密码");
  1680. if(passContent!=null&&!passContent.equalsIgnoreCase("")) {
  1681. if(passContent.equals("503833")){
  1682. int wyflag = 1;
  1683. for(TaskParam taskParam:taskParamList){
  1684. if(taskParam.getTitle().equals(taskContent)){
  1685. wyflag = 0;
  1686. break;
  1687. }
  1688. }
  1689. if(wyflag == 0){
  1690. MesClient.setMenuStatus("任务名称已被占用",-1);
  1691. return;
  1692. }
  1693. TaskParam taskParam = new TaskParam();
  1694. taskParam.setTitle(taskContent);
  1695. JdbcUtils.insertTask(taskParam);
  1696. getTask();
  1697. }else{
  1698. MesClient.setMenuStatus("密码错误",-1);
  1699. }
  1700. }
  1701. }
  1702. }
  1703. });
  1704. addTask.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1705. addTask.setBounds(310, 10, 120, 40);
  1706. indexPanelTask.add(addTask);
  1707. JButton delTask = new JButton("删除任务");
  1708. delTask.addActionListener(new ActionListener() {
  1709. public void actionPerformed(ActionEvent e) {
  1710. if(MesClient.curTaskParam == null){
  1711. MesClient.setMenuStatus("请先选择任务",-1);
  1712. return;
  1713. }
  1714. String passContent = JOptionPane.showInputDialog(null, "请输入密码");
  1715. if(passContent!=null&&!passContent.equalsIgnoreCase("")) {
  1716. if(passContent.equals("503833")){
  1717. JdbcUtils.deleteTask(MesClient.curTaskParam.getId());
  1718. getTask();
  1719. MesClient.curTaskParam = null;
  1720. formatTaskParam();
  1721. }else{
  1722. MesClient.setMenuStatus("密码错误",-1);
  1723. }
  1724. }
  1725. }
  1726. });
  1727. delTask.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1728. delTask.setBounds(440, 10, 120, 40);
  1729. indexPanelTask.add(delTask);
  1730. JButton saveTask = new JButton("保存任务");
  1731. saveTask.addActionListener(new ActionListener() {
  1732. public void actionPerformed(ActionEvent e) {
  1733. if(MesClient.curTaskParam == null){
  1734. MesClient.setMenuStatus("请先选择任务",-1);
  1735. return;
  1736. }
  1737. String passContent = JOptionPane.showInputDialog(null, "请输入密码");
  1738. if(passContent!=null&&!passContent.equalsIgnoreCase("")) {
  1739. if(passContent.equals("503833")){
  1740. MesClient.curTaskParam.setBarcodeSpecStart(barcodeSpecStart.getText().trim());
  1741. MesClient.curTaskParam.setBarcodeSpec(barcodeSpec.getText().trim());
  1742. MesClient.curTaskParam.setBarcodeLength(barcodeLength.getText().trim());
  1743. MesClient.curTaskParam.setTaskProgramNo(taskMaxNumA.getText().trim());
  1744. MesClient.curTaskParam.setTaskLabelName(taskMaxFoutA.getText().trim());
  1745. MesClient.curTaskParam.setTaskLeakage(taskLeakage.getSelectedItem().toString());
  1746. JdbcUtils.updateTask(MesClient.curTaskParam.getId(),MesClient.curTaskParam);
  1747. getTask();
  1748. formatTaskParam();
  1749. }else{
  1750. MesClient.setMenuStatus("密码错误",-1);
  1751. }
  1752. }
  1753. }
  1754. });
  1755. saveTask.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1756. saveTask.setBounds(570, 10, 120, 40);
  1757. indexPanelTask.add(saveTask);
  1758. taskName = new JLabel("");
  1759. taskName.setFont(new Font("微软雅黑", Font.PLAIN, 20));
  1760. taskName.setBounds(700, 10, 283, 40);
  1761. indexPanelTask.add(taskName);
  1762. JLabel taskMaxNumLabelA = new JLabel("程序号");
  1763. taskMaxNumLabelA.setHorizontalAlignment(SwingConstants.CENTER);
  1764. taskMaxNumLabelA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1765. taskMaxNumLabelA.setBounds(310, 93, 110, 30);
  1766. indexPanelTask.add(taskMaxNumLabelA);
  1767. taskMaxNumA = new JTextField();
  1768. taskMaxNumA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1769. taskMaxNumA.setBounds(422, 93, 110, 30);
  1770. indexPanelTask.add(taskMaxNumA);
  1771. taskMaxNumA.setColumns(10);
  1772. JLabel taskMaxFoutLabelA = new JLabel("标签名称");
  1773. taskMaxFoutLabelA.setHorizontalAlignment(SwingConstants.CENTER);
  1774. taskMaxFoutLabelA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1775. taskMaxFoutLabelA.setBounds(310, 133, 110, 30);
  1776. indexPanelTask.add(taskMaxFoutLabelA);
  1777. taskMaxFoutA = new JTextField();
  1778. taskMaxFoutA.setColumns(10);
  1779. taskMaxFoutA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1780. taskMaxFoutA.setBounds(422, 133, 110, 30);
  1781. indexPanelTask.add(taskMaxFoutA);
  1782. JLabel taskMinFoutLabelA = new JLabel("泄漏值取值");
  1783. taskMinFoutLabelA.setHorizontalAlignment(SwingConstants.CENTER);
  1784. taskMinFoutLabelA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1785. taskMinFoutLabelA.setBounds(310, 173, 110, 30);
  1786. indexPanelTask.add(taskMinFoutLabelA);
  1787. taskLeakage = new JComboBox();
  1788. taskLeakage.setModel(new DefaultComboBoxModel(new String[] {"压降", "泄漏率"}));
  1789. taskLeakage.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1790. taskLeakage.setBounds(422, 173, 110, 30);
  1791. indexPanelTask.add(taskLeakage);
  1792. // taskMinFoutA = new JTextField();
  1793. // taskMinFoutA.setColumns(10);
  1794. // taskMinFoutA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1795. // taskMinFoutA.setBounds(422, 173, 110, 30);
  1796. // indexPanelTask.add(taskMinFoutA);
  1797. JLabel taskMaxSoutLabelA = new JLabel("A枪最大行程");
  1798. taskMaxSoutLabelA.setHorizontalAlignment(SwingConstants.CENTER);
  1799. taskMaxSoutLabelA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1800. taskMaxSoutLabelA.setBounds(310, 213, 110, 30);
  1801. // indexPanelTask.add(taskMaxSoutLabelA);
  1802. taskMaxSoutA = new JTextField();
  1803. taskMaxSoutA.setColumns(10);
  1804. taskMaxSoutA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1805. taskMaxSoutA.setBounds(422, 213, 110, 30);
  1806. // indexPanelTask.add(taskMaxSoutA);
  1807. JLabel taskMinSoutLabelA = new JLabel("A枪最小行程");
  1808. taskMinSoutLabelA.setHorizontalAlignment(SwingConstants.CENTER);
  1809. taskMinSoutLabelA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1810. taskMinSoutLabelA.setBounds(310, 253, 110, 30);
  1811. // indexPanelTask.add(taskMinSoutLabelA);
  1812. taskMinSoutA = new JTextField();
  1813. taskMinSoutA.setColumns(10);
  1814. taskMinSoutA.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1815. taskMinSoutA.setBounds(422, 253, 110, 30);
  1816. // indexPanelTask.add(taskMinSoutA);
  1817. JLabel taskMaxNumLabelB = new JLabel("B枪预算数量");
  1818. taskMaxNumLabelB.setHorizontalAlignment(SwingConstants.CENTER);
  1819. taskMaxNumLabelB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1820. taskMaxNumLabelB.setBounds(580, 93, 110, 30);
  1821. // indexPanelTask.add(taskMaxNumLabelB);
  1822. taskMaxNumB = new JTextField();
  1823. taskMaxNumB.setColumns(10);
  1824. taskMaxNumB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1825. taskMaxNumB.setBounds(692, 93, 110, 30);
  1826. // indexPanelTask.add(taskMaxNumB);
  1827. JLabel taskMaxFoutLabelB = new JLabel("B枪最大拉力");
  1828. taskMaxFoutLabelB.setHorizontalAlignment(SwingConstants.CENTER);
  1829. taskMaxFoutLabelB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1830. taskMaxFoutLabelB.setBounds(580, 133, 110, 30);
  1831. // indexPanelTask.add(taskMaxFoutLabelB);
  1832. taskMaxFoutB = new JTextField();
  1833. taskMaxFoutB.setColumns(10);
  1834. taskMaxFoutB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1835. taskMaxFoutB.setBounds(692, 133, 110, 30);
  1836. // indexPanelTask.add(taskMaxFoutB);
  1837. JLabel taskMinFoutLabelB = new JLabel("B枪最小拉力");
  1838. taskMinFoutLabelB.setHorizontalAlignment(SwingConstants.CENTER);
  1839. taskMinFoutLabelB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1840. taskMinFoutLabelB.setBounds(580, 173, 110, 30);
  1841. // indexPanelTask.add(taskMinFoutLabelB);
  1842. taskMinFoutB = new JTextField();
  1843. taskMinFoutB.setColumns(10);
  1844. taskMinFoutB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1845. taskMinFoutB.setBounds(692, 173, 110, 30);
  1846. // indexPanelTask.add(taskMinFoutB);
  1847. JLabel taskMaxSoutLabelB = new JLabel("B枪最大行程");
  1848. taskMaxSoutLabelB.setHorizontalAlignment(SwingConstants.CENTER);
  1849. taskMaxSoutLabelB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1850. taskMaxSoutLabelB.setBounds(580, 213, 110, 30);
  1851. // indexPanelTask.add(taskMaxSoutLabelB);
  1852. taskMaxSoutB = new JTextField();
  1853. taskMaxSoutB.setColumns(10);
  1854. taskMaxSoutB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1855. taskMaxSoutB.setBounds(692, 213, 110, 30);
  1856. // indexPanelTask.add(taskMaxSoutB);
  1857. JLabel taskMinSoutLabelB = new JLabel("B枪最小行程");
  1858. taskMinSoutLabelB.setHorizontalAlignment(SwingConstants.CENTER);
  1859. taskMinSoutLabelB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1860. taskMinSoutLabelB.setBounds(580, 253, 110, 30);
  1861. // indexPanelTask.add(taskMinSoutLabelB);
  1862. taskMinSoutB = new JTextField();
  1863. taskMinSoutB.setColumns(10);
  1864. taskMinSoutB.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1865. taskMinSoutB.setBounds(692, 253, 110, 30);
  1866. // indexPanelTask.add(taskMinSoutB);
  1867. JLabel barcodeSpecLabel = new JLabel("条码固定位");
  1868. barcodeSpecLabel.setHorizontalAlignment(SwingConstants.CENTER);
  1869. barcodeSpecLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1870. barcodeSpecLabel.setBounds(310, 293, 110, 30);
  1871. indexPanelTask.add(barcodeSpecLabel);
  1872. barcodeSpec = new JTextField();
  1873. barcodeSpec.setColumns(10);
  1874. barcodeSpec.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1875. barcodeSpec.setBounds(422, 293, 110, 30);
  1876. indexPanelTask.add(barcodeSpec);
  1877. JLabel barcodeSpecStartLabel = new JLabel("起始位数");
  1878. barcodeSpecStartLabel.setHorizontalAlignment(SwingConstants.CENTER);
  1879. barcodeSpecStartLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1880. barcodeSpecStartLabel.setBounds(310, 333, 110, 30);
  1881. indexPanelTask.add(barcodeSpecStartLabel);
  1882. barcodeSpecStart = new JTextField();
  1883. barcodeSpecStart.setColumns(10);
  1884. barcodeSpecStart.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1885. barcodeSpecStart.setBounds(422, 333, 110, 30);
  1886. indexPanelTask.add(barcodeSpecStart);
  1887. JLabel barcodeLengthLabel = new JLabel("条码长度");
  1888. barcodeLengthLabel.setHorizontalAlignment(SwingConstants.CENTER);
  1889. barcodeLengthLabel.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1890. barcodeLengthLabel.setBounds(310, 373, 110, 30);
  1891. indexPanelTask.add(barcodeLengthLabel);
  1892. barcodeLength = new JTextField();
  1893. barcodeLength.setColumns(10);
  1894. barcodeLength.setFont(new Font("微软雅黑", Font.PLAIN, 16));
  1895. barcodeLength.setBounds(422, 373, 110, 30);
  1896. indexPanelTask.add(barcodeLength);
  1897. tabbedPane.addTab("任务设置", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), searchScrollPaneTask, null);
  1898. tabbedPane.addChangeListener(new ChangeListener() {
  1899. @Override
  1900. public void stateChanged(ChangeEvent e) {
  1901. JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
  1902. int selectedIndex = tabbedPane.getSelectedIndex();
  1903. if(selectedIndex == 1){
  1904. }
  1905. JdbcUtils.getTestData();
  1906. }
  1907. });
  1908. }
  1909. private static String validateProductSnMessage(String sn) {
  1910. if (sn == null || sn.isEmpty()) {
  1911. return "工件码为空,请重试";
  1912. }
  1913. if (sn.length() != PRODUCT_SN_LENGTH) {
  1914. return "工件码长度须为32位,当前" + sn.length() + "位";
  1915. }
  1916. String prefix = getProductSnPrefix();
  1917. if (!sn.startsWith(prefix)) {
  1918. return "工件码前缀与当前类型(" + getProductTypeName() + ")不匹配,当前工件码为" + getProductTypeNameBySn(sn);
  1919. }
  1920. return null;
  1921. }
  1922. private static void updateProductTypePanelEnabled(boolean enabled) {
  1923. if (productTypePanel != null) {
  1924. productTypePanel.setEnabled(enabled);
  1925. }
  1926. }
  1927. public static void loadProductTypeFromDb() {
  1928. if (productTypePanel == null) {
  1929. return;
  1930. }
  1931. String savedType = JdbcUtils.getClientConfig(
  1932. JdbcUtils.getProductTypeConfigKey(mes_gw),
  1933. PRODUCT_TYPE_ZJ
  1934. );
  1935. if (PRODUCT_TYPE_SJ.equals(savedType)) {
  1936. productTypePanel.setResult(PRODUCT_TYPE_SJ);
  1937. } else {
  1938. productTypePanel.setResult(PRODUCT_TYPE_ZJ);
  1939. }
  1940. refreshProductTypeCurrentLabel();
  1941. }
  1942. public static void refreshProductTypeCurrentLabel() {
  1943. if (productTypeCurrentLabel != null) {
  1944. productTypeCurrentLabel.setText("当前选择:" + getProductTypeName() + "(前缀 " + getProductSnPrefix() + ")");
  1945. }
  1946. }
  1947. public static void saveProductTypeToDb() {
  1948. if (productTypePanel == null) {
  1949. return;
  1950. }
  1951. JdbcUtils.saveClientConfig(
  1952. JdbcUtils.getProductTypeConfigKey(mes_gw),
  1953. productTypePanel.getResult()
  1954. );
  1955. }
  1956. public static String getProductSnPrefix() {
  1957. if (productTypePanel != null && PRODUCT_TYPE_SJ.equals(productTypePanel.getResult())) {
  1958. return PREFIX_SJ;
  1959. }
  1960. return PREFIX_ZJ;
  1961. }
  1962. public static String getProductTypeName() {
  1963. if (productTypePanel != null) {
  1964. return productTypePanel.getTypeName();
  1965. }
  1966. return "智界";
  1967. }
  1968. private static String getProductTypeNameBySn(String sn) {
  1969. if (sn.startsWith(PREFIX_SJ)) {
  1970. return "尚界";
  1971. }
  1972. if (sn.startsWith(PREFIX_ZJ)) {
  1973. return "智界";
  1974. }
  1975. return "未知";
  1976. }
  1977. public static void setMenuStatus(String msg,int error){
  1978. if(error == 0){
  1979. MesClient.status_menu.setForeground(Color.GREEN);
  1980. }else{
  1981. MesClient.status_menu.setForeground(Color.RED);
  1982. }
  1983. MesClient.status_menu.setText(msg);
  1984. }
  1985. public static void getTask(){
  1986. taskParamList = JdbcUtils.getTask();
  1987. System.out.println("taskParamList:"+taskParamList.size());
  1988. if(taskParamList.size() > 0){
  1989. int i = 0;
  1990. rowData2 = new Object[taskParamList.size()][1];
  1991. for(TaskParam taskParam:taskParamList){
  1992. rowData2[i][0] = taskParam.getTitle();
  1993. i++;
  1994. }
  1995. }else{
  1996. rowData2[0][0] = "";
  1997. }
  1998. System.out.println("rowData2:"+JSONObject.toJSONString(rowData2));
  1999. DefaultTableModel model = new DefaultTableModel(rowData2, columnNames2);
  2000. table2.setModel(model);
  2001. MesClient.table2.repaint();
  2002. }
  2003. public static void formatTaskParam(){
  2004. if(MesClient.curTaskParam != null){
  2005. taskName.setText(MesClient.curTaskParam.getTitle());
  2006. if(MesClient.curTaskParam.getTaskProgramNo() == null || MesClient.curTaskParam.getTaskProgramNo().equals("")){
  2007. MesClient.curTaskParam.setTaskProgramNo("");
  2008. }
  2009. taskMaxNumA.setText(MesClient.curTaskParam.getTaskProgramNo());
  2010. if(MesClient.curTaskParam.getTaskLabelName() == null || MesClient.curTaskParam.getTaskLabelName().equals("")){
  2011. MesClient.curTaskParam.setTaskLabelName("");
  2012. }
  2013. taskMaxFoutA.setText(MesClient.curTaskParam.getTaskLabelName());
  2014. if(MesClient.curTaskParam.getTaskLeakage() == null || MesClient.curTaskParam.getTaskLeakage().equals("")){
  2015. MesClient.curTaskParam.setTaskLeakage("压降");
  2016. }
  2017. taskLeakage.setSelectedItem(MesClient.curTaskParam.getTaskLeakage());
  2018. if(MesClient.curTaskParam.getBarcodeSpec() == null || MesClient.curTaskParam.getBarcodeSpec().equals("")){
  2019. MesClient.curTaskParam.setBarcodeSpec("");
  2020. }
  2021. barcodeSpec.setText(MesClient.curTaskParam.getBarcodeSpec());
  2022. if(MesClient.curTaskParam.getBarcodeSpecStart() == null || MesClient.curTaskParam.getBarcodeSpecStart().equals("")){
  2023. MesClient.curTaskParam.setBarcodeSpecStart("");
  2024. }
  2025. barcodeSpecStart.setText(MesClient.curTaskParam.getBarcodeSpecStart());
  2026. if(MesClient.curTaskParam.getBarcodeLength() == null || MesClient.curTaskParam.getBarcodeLength().equals("")){
  2027. MesClient.curTaskParam.setBarcodeLength("");
  2028. }
  2029. barcodeLength.setText(MesClient.curTaskParam.getBarcodeLength());
  2030. }else{
  2031. taskName.setText("");
  2032. taskMaxNumA.setText("");
  2033. taskMaxNumB.setText("");
  2034. taskMaxFoutA.setText("");
  2035. taskMaxFoutB.setText("");
  2036. taskMaxSoutA.setText("");
  2037. taskMaxSoutB.setText("");
  2038. taskMinFoutA.setText("");
  2039. taskMinFoutB.setText("");
  2040. taskMinSoutA.setText("");
  2041. taskMinSoutB.setText("");
  2042. barcodeLength.setText("");
  2043. barcodeSpec.setText("");
  2044. barcodeSpecStart.setText("");
  2045. }
  2046. }
  2047. // 检查工件码的正确性
  2048. public static boolean checkProductSn(String sn){
  2049. curTaskName.setText("");
  2050. if(taskParamList.size() <= 0){
  2051. MesClient.setMenuStatus("未设置任务",-1);
  2052. return false;
  2053. }
  2054. try{
  2055. for(TaskParam taskParam : taskParamList){
  2056. if(taskParam.getBarcodeSpec()!=null&&!taskParam.getBarcodeSpec().equals("null")&&taskParam.getBarcodeSpecStart()!=null&&!taskParam.getBarcodeSpecStart().equals("null")&&taskParam.getBarcodeLength()!=null&&!taskParam.getBarcodeLength().equals("null")) {
  2057. Boolean ret = CommonUtils.checkSnByModel(sn,taskParam.getBarcodeSpec(),Integer.valueOf(taskParam.getBarcodeSpecStart()),Integer.valueOf(taskParam.getBarcodeLength()));
  2058. if(ret){
  2059. configParam.setLabelName(taskParam.getTaskLabelName());
  2060. configParam.setLeakage(taskParam.getTaskLeakage());
  2061. configParam.setProgramNo(taskParam.getTaskProgramNo());
  2062. curTaskName.setText("当前任务:"+taskParam.getTitle());
  2063. // configParam.setDeviceMaxNumValA(taskParam.getTaskMaxNumA());
  2064. // configParam.setMaxFoutValA(taskParam.getTaskMaxFoutA());
  2065. // configParam.setMaxSoutValA(taskParam.getTaskMaxSoutA());
  2066. // configParam.setMinFoutValA(taskParam.getTaskMinFoutA());
  2067. // configParam.setMinSoutValA(taskParam.getTaskMinSoutA());
  2068. //
  2069. // configParam.setDeviceMaxNumValB(taskParam.getTaskMaxNumB());
  2070. // configParam.setMaxFoutValB(taskParam.getTaskMaxFoutB());
  2071. // configParam.setMaxSoutValB(taskParam.getTaskMaxSoutB());
  2072. // configParam.setMinFoutValB(taskParam.getTaskMinFoutB());
  2073. // configParam.setMinSoutValB(taskParam.getTaskMinSoutB());
  2074. return true;
  2075. }
  2076. }
  2077. }
  2078. }catch (Exception e){
  2079. e.printStackTrace();
  2080. }
  2081. MesClient.setMenuStatus("该类型工件未设置任务",-1);
  2082. return false;
  2083. }
  2084. public static void getMaterailData(){
  2085. try{
  2086. JSONObject retObj = DataUtil.getBindMaterail();
  2087. if(retObj == null){
  2088. return;
  2089. }
  2090. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  2091. List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  2092. int i = 0;
  2093. materialRowData = new Object[arrs.size()][7];
  2094. for (BindMaterialResp bindMaterialResp:arrs){
  2095. materialRowData[i][0] = bindMaterialResp.getMaterialTitle();
  2096. materialRowData[i][1] = bindMaterialResp.getBatchSn();
  2097. materialRowData[i][2] = bindMaterialResp.getLastTimes();
  2098. materialRowData[i][3] = "";
  2099. materialRowData[i][4] = bindMaterialResp.getCraft();
  2100. materialRowData[i][5] = bindMaterialResp.getMaterialId();
  2101. materialRowData[i][6] = bindMaterialResp.getType();
  2102. i++;
  2103. }
  2104. bindBatchPanel();
  2105. }
  2106. }catch (Exception e){
  2107. log.info(e.getMessage());
  2108. }
  2109. }
  2110. public static void updateMaterailData(){
  2111. try{
  2112. if(materialRowData == null){
  2113. return;
  2114. }
  2115. JSONObject retObj = DataUtil.getBindMaterail();
  2116. if(retObj == null){
  2117. return;
  2118. }
  2119. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  2120. List<BindMaterialResp> arrs = retObj.getList("data",BindMaterialResp.class);
  2121. int i = 0;
  2122. for (BindMaterialResp bindMaterialResp:arrs){
  2123. materialRowData[i][0] = bindMaterialResp.getMaterialTitle();
  2124. materialRowData[i][1] = bindMaterialResp.getBatchSn();
  2125. materialRowData[i][2] = bindMaterialResp.getLastTimes();
  2126. materialRowData[i][3] = "";
  2127. materialRowData[i][4] = bindMaterialResp.getCraft();
  2128. materialRowData[i][5] = bindMaterialResp.getMaterialId();
  2129. materialRowData[i][6] = bindMaterialResp.getType();
  2130. i++;
  2131. }
  2132. if(materialTable != null){
  2133. materialTable.repaint();
  2134. }
  2135. }
  2136. }catch (Exception e){
  2137. log.info(e.getMessage());
  2138. }
  2139. }
  2140. public static void scanBatchSn(BindMaterialResp bindMaterialResp) {
  2141. String scanBarcodeTitle = "请扫物料:"+bindMaterialResp.getMaterialTitle();
  2142. String scanBarcode = JOptionPane.showInputDialog(null, scanBarcodeTitle);
  2143. if(scanBarcode!=null&&!scanBarcode.equalsIgnoreCase("")) {
  2144. JSONObject retObj = DataUtil.saveBindMaterail(scanBarcode,bindMaterialResp.getCraft(),bindMaterialResp.getMaterialId(),bindMaterialResp.getType());
  2145. if(retObj.get("result")!=null&&retObj.get("result").toString().equalsIgnoreCase("true")) {
  2146. MesClient.setMenuStatus("扫物料:"+bindMaterialResp.getMaterialTitle()+"成功",0);
  2147. updateMaterailData();
  2148. }else{
  2149. if(retObj.get("result")==null){
  2150. MesClient.setMenuStatus("请求失败,请重试",-1);
  2151. }else{
  2152. if(retObj.get("result").toString().equalsIgnoreCase("false")){
  2153. MesClient.setMenuStatus(retObj.getString("message"),-1);
  2154. }
  2155. }
  2156. }
  2157. }
  2158. }
  2159. public static void bindBatchPanel(){
  2160. JPanel indexPanelBB = new JPanel();
  2161. JPanel panel = new JPanel();
  2162. panel.setBounds(0, 0, 990, 550);
  2163. indexPanelBB.add(panel);
  2164. panel.setLayout(new GridLayout(0, 1, 0, 0));
  2165. materialTable = new JTable(materialRowData, materialColumnNames){
  2166. public boolean isCellEditable(int row, int column) {
  2167. if(column == 3){
  2168. return true;
  2169. }
  2170. return false;
  2171. }
  2172. };
  2173. materialTable.setRowHeight(40);
  2174. materialTable.setEnabled(true);
  2175. materialTable.setFont(new Font("微软雅黑", Font.PLAIN, 14));
  2176. materialTable.getColumnModel().getColumn(3).setCellRenderer(new TableCellRendererButton());
  2177. materialTable.getColumnModel().getColumn(3).setCellEditor(new TableCellEditorButton());
  2178. JScrollPane scrollPane = new JScrollPane(materialTable);
  2179. panel.add(scrollPane);
  2180. JScrollPane indexScrollPaneB = new JScrollPane(indexPanelBB);
  2181. indexPanelBB.setLayout(null);
  2182. tabbedPane.addTab("绑定物料", new ImageIcon(MesClient.class.getResource("/bg/menu_data_preprocess.png")), indexScrollPaneB, null);
  2183. }
  2184. }