MesClient.java 96 KB

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