MesClient.java 90 KB

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